xref: /csrg-svn/sys/net/if.h (revision 6207)
1*6207Swnj /*	if.h	4.9	82/03/15	*/
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 */
416087Sroot 	struct	in_addr if_broadaddr;	/* broadcast address of interface */
425104Swnj 	struct	ifqueue {
435104Swnj 		struct	mbuf *ifq_head;
445104Swnj 		struct	mbuf *ifq_tail;
45*6207Swnj 		int	ifq_len;
46*6207Swnj 		int	ifq_maxlen;
47*6207Swnj 		int	ifq_drops;
485104Swnj 	} if_snd;			/* output queue */
495104Swnj /* procedure handles */
505104Swnj 	int	(*if_init)();		/* init routine */
515083Swnj 	int	(*if_output)();		/* output routine */
525083Swnj 	int	(*if_ubareset)();	/* uba reset routine */
535104Swnj /* generic interface statistics */
545171Swnj 	int	if_ipackets;		/* packets received on interface */
555171Swnj 	int	if_ierrors;		/* input errors on interface */
565171Swnj 	int	if_opackets;		/* packets sent on interface */
575171Swnj 	int	if_oerrors;		/* output errors on interface */
585104Swnj 	int	if_collisions;		/* collisions on csma interfaces */
595104Swnj /* end statistics */
604951Swnj 	struct	ifnet *if_next;
614945Swnj };
624945Swnj 
635104Swnj /*
645104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
655104Swnj  * input routines have queues of messages stored on ifqueue structures
665104Swnj  * (defined above).  Entries are added to and deleted from these structures
675104Swnj  * by these macros, which should be called with ipl raised to splimp().
685104Swnj  */
69*6207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
70*6207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
715083Swnj #define	IF_ENQUEUE(ifq, m) { \
725083Swnj 	(m)->m_act = 0; \
735083Swnj 	if ((ifq)->ifq_tail == 0) \
745160Swnj 		(ifq)->ifq_head = m; \
755083Swnj 	else \
765083Swnj 		(ifq)->ifq_tail->m_act = m; \
775160Swnj 	(ifq)->ifq_tail = m; \
78*6207Swnj 	(ifq)->ifq_len++; \
795083Swnj }
805613Swnj #define	IF_PREPEND(ifq, m) { \
815613Swnj 	(m)->m_act = (ifq)->ifq_head; \
826087Sroot 	if ((ifq)->ifq_tail == 0) \
836087Sroot 		(ifq)->ifq_tail = (m); \
845613Swnj 	(ifq)->ifq_head = (m); \
85*6207Swnj 	(ifq)->ifq_len++; \
865613Swnj }
875083Swnj #define	IF_DEQUEUE(ifq, m) { \
885083Swnj 	(m) = (ifq)->ifq_head; \
895083Swnj 	if (m) { \
905083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
915083Swnj 			(ifq)->ifq_tail = 0; \
925083Swnj 		(m)->m_act = 0; \
93*6207Swnj 		(ifq)->ifq_len--; \
945083Swnj 	} \
955083Swnj }
964945Swnj 
97*6207Swnj #define	IFQ_MAXLEN	50
98*6207Swnj 
994945Swnj #ifdef KERNEL
1005083Swnj #ifdef INET
1015083Swnj struct	ifqueue	ipintrq;		/* ip packet input queue */
1025083Swnj #endif
1035104Swnj struct	ifqueue rawintrq;		/* raw packet input queue */
1044945Swnj struct	ifnet *ifnet;
1055083Swnj struct	ifnet *if_ifwithaddr(), *if_ifonnetof(), *if_gatewayfor();
1065104Swnj struct	in_addr if_makeaddr();
1074945Swnj #endif
108