xref: /csrg-svn/sys/net/if.h (revision 6333)
1*6333Ssam /*	if.h	4.11	82/03/28	*/
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:
12*6333Ssam  *	(*ifp->if_output)(ifp, m, dst)
13*6333Ssam  * Here m is the mbuf chain to be sent and dst is the destination address.
14*6333Ssam  * The output routine encapsulates the supplied datagram if necessary,
15*6333Ssam  * and then transmits it on its medium.
165104Swnj  *
175104Swnj  * On input, each interface unwraps the data received by it, and either
185104Swnj  * places it on the input queue of a internetwork datagram routine
195104Swnj  * and posts the associated software interrupt, or passes the datagram to a raw
205104Swnj  * packet input routine.
215104Swnj  *
22*6333Ssam  * Routines exist for locating interfaces by their addresses
235104Swnj  * or for locating a interface on a certain network, as well as more general
245104Swnj  * routing and gateway routines maintaining information used to locate
25*6333Ssam  * interfaces.  These routines live in the files if.c and route.c
265083Swnj  */
275083Swnj 
285083Swnj /*
295083Swnj  * Structure defining a queue for a network interface.
304945Swnj  *
314945Swnj  * (Would like to call this struct ``if'', but C isn't PL/1.)
324945Swnj  */
334945Swnj struct ifnet {
345171Swnj 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
354945Swnj 	short	if_unit;		/* sub-unit for lower level driver */
364945Swnj 	short	if_mtu;			/* maximum transmission unit */
374945Swnj 	short	if_net;			/* network number of interface */
38*6333Ssam 	short	if_flags;		/* up/down, broadcast, etc. */
395083Swnj 	int	if_host[2];		/* local net host number */
40*6333Ssam 	struct	sockaddr if_addr;	/* internet address of interface */
41*6333Ssam 	struct	sockaddr if_broadaddr;	/* broadcast address of interface */
425104Swnj 	struct	ifqueue {
435104Swnj 		struct	mbuf *ifq_head;
445104Swnj 		struct	mbuf *ifq_tail;
456207Swnj 		int	ifq_len;
466207Swnj 		int	ifq_maxlen;
476207Swnj 		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 
63*6333Ssam #define	IFF_UP		0x1		/* interface is up */
64*6333Ssam #define	IFF_BROADCAST	0x2		/* broadcast address valid */
65*6333Ssam #define	IFF_DEBUG	0x4		/* turn on debugging */
66*6333Ssam 
675104Swnj /*
685104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
695104Swnj  * input routines have queues of messages stored on ifqueue structures
705104Swnj  * (defined above).  Entries are added to and deleted from these structures
715104Swnj  * by these macros, which should be called with ipl raised to splimp().
725104Swnj  */
736207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
746207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
755083Swnj #define	IF_ENQUEUE(ifq, m) { \
765083Swnj 	(m)->m_act = 0; \
775083Swnj 	if ((ifq)->ifq_tail == 0) \
785160Swnj 		(ifq)->ifq_head = m; \
795083Swnj 	else \
805083Swnj 		(ifq)->ifq_tail->m_act = m; \
815160Swnj 	(ifq)->ifq_tail = m; \
826207Swnj 	(ifq)->ifq_len++; \
835083Swnj }
845613Swnj #define	IF_PREPEND(ifq, m) { \
855613Swnj 	(m)->m_act = (ifq)->ifq_head; \
866087Sroot 	if ((ifq)->ifq_tail == 0) \
876087Sroot 		(ifq)->ifq_tail = (m); \
885613Swnj 	(ifq)->ifq_head = (m); \
896207Swnj 	(ifq)->ifq_len++; \
905613Swnj }
915083Swnj #define	IF_DEQUEUE(ifq, m) { \
925083Swnj 	(m) = (ifq)->ifq_head; \
935083Swnj 	if (m) { \
945083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
955083Swnj 			(ifq)->ifq_tail = 0; \
965083Swnj 		(m)->m_act = 0; \
976207Swnj 		(ifq)->ifq_len--; \
985083Swnj 	} \
995083Swnj }
1004945Swnj 
1016207Swnj #define	IFQ_MAXLEN	50
1026207Swnj 
1034945Swnj #ifdef KERNEL
1045083Swnj #ifdef INET
1055083Swnj struct	ifqueue	ipintrq;		/* ip packet input queue */
1065083Swnj #endif
107*6333Ssam struct	ifqueue rawintrq;		/* raw packet input queue */
1084945Swnj struct	ifnet *ifnet;
109*6333Ssam struct	ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
110*6333Ssam struct	ifnet *if_ifonnetof();
1115104Swnj struct	in_addr if_makeaddr();
1124945Swnj #endif
113