xref: /csrg-svn/sys/net/if.h (revision 6087)
1*6087Sroot /*	if.h	4.8	82/03/09	*/
24945Swnj 
34945Swnj /*
45104Swnj  * Structures defining a network interface, providing a packet
55104Swnj  * transport mechanism (ala level 0 of the PUP protocols).
65104Swnj  *
75104Swnj  * Each interface accepts output datagrams of a specified maximum
85104Swnj  * length, and provides higher level routines with input datagrams
95104Swnj  * received from its medium.
105104Swnj  *
115104Swnj  * Output occurs when the routine if_output is called, with three parameters:
125104Swnj  *	(*ifp->if_output)(ifp, m, pf)
135104Swnj  * Here m is the mbuf chain to be sent and pf is the protocol family
145104Swnj  * of the internetwork datagram format in which the data is wrapped
155104Swnj  * (e.g. PF_PUP or PF_INET).  The output routine encapsulates the
165104Swnj  * supplied datagram if necessary, and then transmits it on its medium.
175104Swnj  *
185104Swnj  * On input, each interface unwraps the data received by it, and either
195104Swnj  * places it on the input queue of a internetwork datagram routine
205104Swnj  * and posts the associated software interrupt, or passes the datagram to a raw
215104Swnj  * packet input routine.
225104Swnj  *
235104Swnj  * Routines exist for locating interfaces by their internet addresses
245104Swnj  * or for locating a interface on a certain network, as well as more general
255104Swnj  * routing and gateway routines maintaining information used to locate
265104Swnj  * interfaces.  These routines live in the files if.c and ip_ggp.c.
275083Swnj  */
285083Swnj 
295083Swnj /*
305083Swnj  * Structure defining a queue for a network interface.
314945Swnj  *
324945Swnj  * (Would like to call this struct ``if'', but C isn't PL/1.)
334945Swnj  */
344945Swnj struct ifnet {
355171Swnj 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
364945Swnj 	short	if_unit;		/* sub-unit for lower level driver */
374945Swnj 	short	if_mtu;			/* maximum transmission unit */
384945Swnj 	short	if_net;			/* network number of interface */
395083Swnj 	int	if_host[2];		/* local net host number */
404945Swnj 	struct	in_addr if_addr;	/* internet address of interface */
41*6087Sroot 	struct	in_addr if_broadaddr;	/* broadcast address of interface */
425104Swnj 	struct	ifqueue {
435104Swnj 		struct	mbuf *ifq_head;
445104Swnj 		struct	mbuf *ifq_tail;
455104Swnj 	} if_snd;			/* output queue */
465104Swnj /* procedure handles */
475104Swnj 	int	(*if_init)();		/* init routine */
485083Swnj 	int	(*if_output)();		/* output routine */
495083Swnj 	int	(*if_ubareset)();	/* uba reset routine */
505104Swnj /* generic interface statistics */
515171Swnj 	int	if_ipackets;		/* packets received on interface */
525171Swnj 	int	if_ierrors;		/* input errors on interface */
535171Swnj 	int	if_opackets;		/* packets sent on interface */
545171Swnj 	int	if_oerrors;		/* output errors on interface */
555104Swnj 	int	if_collisions;		/* collisions on csma interfaces */
565104Swnj /* end statistics */
574951Swnj 	struct	ifnet *if_next;
584945Swnj };
594945Swnj 
605104Swnj /*
615104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
625104Swnj  * input routines have queues of messages stored on ifqueue structures
635104Swnj  * (defined above).  Entries are added to and deleted from these structures
645104Swnj  * by these macros, which should be called with ipl raised to splimp().
655104Swnj  */
665083Swnj #define	IF_ENQUEUE(ifq, m) { \
675083Swnj 	(m)->m_act = 0; \
685083Swnj 	if ((ifq)->ifq_tail == 0) \
695160Swnj 		(ifq)->ifq_head = m; \
705083Swnj 	else \
715083Swnj 		(ifq)->ifq_tail->m_act = m; \
725160Swnj 	(ifq)->ifq_tail = m; \
735083Swnj }
745613Swnj #define	IF_PREPEND(ifq, m) { \
755613Swnj 	(m)->m_act = (ifq)->ifq_head; \
76*6087Sroot 	if ((ifq)->ifq_tail == 0) \
77*6087Sroot 		(ifq)->ifq_tail = (m); \
785613Swnj 	(ifq)->ifq_head = (m); \
795613Swnj }
805083Swnj #define	IF_DEQUEUE(ifq, m) { \
815083Swnj 	(m) = (ifq)->ifq_head; \
825083Swnj 	if (m) { \
835083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
845083Swnj 			(ifq)->ifq_tail = 0; \
855083Swnj 		(m)->m_act = 0; \
865083Swnj 	} \
875083Swnj }
884945Swnj 
894945Swnj #ifdef KERNEL
905083Swnj #ifdef INET
915083Swnj struct	ifqueue	ipintrq;		/* ip packet input queue */
925083Swnj #endif
935104Swnj struct	ifqueue rawintrq;		/* raw packet input queue */
944945Swnj struct	ifnet *ifnet;
955083Swnj struct	ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor();
965104Swnj struct	in_addr if_makeaddr();
974945Swnj #endif
98