xref: /csrg-svn/sys/net/if.h (revision 11576)
1*11576Ssam /*	if.h	4.17	83/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:
126333Ssam  *	(*ifp->if_output)(ifp, m, dst)
136333Ssam  * Here m is the mbuf chain to be sent and dst is the destination address.
146333Ssam  * The output routine encapsulates the supplied datagram if necessary,
156333Ssam  * 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  *
226333Ssam  * 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
256333Ssam  * 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.)
327161Ssam  *
337161Ssam  * EVENTUALLY PURGE if_net AND if_host FROM STRUCTURE
344945Swnj  */
354945Swnj struct ifnet {
365171Swnj 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
374945Swnj 	short	if_unit;		/* sub-unit for lower level driver */
384945Swnj 	short	if_mtu;			/* maximum transmission unit */
397161Ssam 	int	if_net;			/* network number of interface */
406333Ssam 	short	if_flags;		/* up/down, broadcast, etc. */
417264Ssam 	short	if_timer;		/* time 'til if_watchdog called */
425083Swnj 	int	if_host[2];		/* local net host number */
436924Swnj 	struct	sockaddr if_addr;	/* address of interface */
446924Swnj 	union {
456924Swnj 		struct	sockaddr ifu_broadaddr;
466924Swnj 		struct	sockaddr ifu_dstaddr;
476924Swnj 	} if_ifu;
486924Swnj #define	if_broadaddr	if_ifu.ifu_broadaddr	/* broadcast address */
496924Swnj #define	if_dstaddr	if_ifu.ifu_dstaddr	/* other end of p-to-p link */
505104Swnj 	struct	ifqueue {
515104Swnj 		struct	mbuf *ifq_head;
525104Swnj 		struct	mbuf *ifq_tail;
536207Swnj 		int	ifq_len;
546207Swnj 		int	ifq_maxlen;
556207Swnj 		int	ifq_drops;
565104Swnj 	} if_snd;			/* output queue */
575104Swnj /* procedure handles */
585104Swnj 	int	(*if_init)();		/* init routine */
595083Swnj 	int	(*if_output)();		/* output routine */
608972Sroot 	int	(*if_reset)();		/* bus reset routine */
617264Ssam 	int	(*if_watchdog)();	/* timer routine */
625104Swnj /* generic interface statistics */
635171Swnj 	int	if_ipackets;		/* packets received on interface */
645171Swnj 	int	if_ierrors;		/* input errors on interface */
655171Swnj 	int	if_opackets;		/* packets sent on interface */
665171Swnj 	int	if_oerrors;		/* output errors on interface */
675104Swnj 	int	if_collisions;		/* collisions on csma interfaces */
685104Swnj /* end statistics */
694951Swnj 	struct	ifnet *if_next;
704945Swnj };
714945Swnj 
726333Ssam #define	IFF_UP		0x1		/* interface is up */
736333Ssam #define	IFF_BROADCAST	0x2		/* broadcast address valid */
746333Ssam #define	IFF_DEBUG	0x4		/* turn on debugging */
756924Swnj #define	IFF_ROUTE	0x8		/* routing entry installed */
766924Swnj #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
776333Ssam 
785104Swnj /*
795104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
805104Swnj  * input routines have queues of messages stored on ifqueue structures
815104Swnj  * (defined above).  Entries are added to and deleted from these structures
825104Swnj  * by these macros, which should be called with ipl raised to splimp().
835104Swnj  */
846207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
856207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
865083Swnj #define	IF_ENQUEUE(ifq, m) { \
875083Swnj 	(m)->m_act = 0; \
885083Swnj 	if ((ifq)->ifq_tail == 0) \
895160Swnj 		(ifq)->ifq_head = m; \
905083Swnj 	else \
915083Swnj 		(ifq)->ifq_tail->m_act = m; \
925160Swnj 	(ifq)->ifq_tail = m; \
936207Swnj 	(ifq)->ifq_len++; \
945083Swnj }
955613Swnj #define	IF_PREPEND(ifq, m) { \
965613Swnj 	(m)->m_act = (ifq)->ifq_head; \
976087Sroot 	if ((ifq)->ifq_tail == 0) \
986087Sroot 		(ifq)->ifq_tail = (m); \
995613Swnj 	(ifq)->ifq_head = (m); \
1006207Swnj 	(ifq)->ifq_len++; \
1015613Swnj }
1025083Swnj #define	IF_DEQUEUE(ifq, m) { \
1035083Swnj 	(m) = (ifq)->ifq_head; \
1045083Swnj 	if (m) { \
1055083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
1065083Swnj 			(ifq)->ifq_tail = 0; \
1075083Swnj 		(m)->m_act = 0; \
1086207Swnj 		(ifq)->ifq_len--; \
1095083Swnj 	} \
1105083Swnj }
1114945Swnj 
1126207Swnj #define	IFQ_MAXLEN	50
1137264Ssam #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1146207Swnj 
115*11576Ssam /*
116*11576Ssam  * Interface request structure used by socket
117*11576Ssam  * ioctl's SIOCSIFxxxx (set interface parameter)
118*11576Ssam  * and SIOCGIFxxxx (get parameter).
119*11576Ssam  */
120*11576Ssam struct	ifreq {
121*11576Ssam 	char	ifr_name[16];		/* name of interface (e.g. "ec0") */
122*11576Ssam 	union {
123*11576Ssam 		struct	sockaddr ifru_addr;
124*11576Ssam 		struct	sockaddr ifru_dstaddr;
125*11576Ssam 		short	ifru_flags;
126*11576Ssam 	} ifr_ifru;
127*11576Ssam #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
128*11576Ssam #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
129*11576Ssam #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
130*11576Ssam };
131*11576Ssam 
132*11576Ssam /*
133*11576Ssam  * Structure used in SIOCGIFCONF request.
134*11576Ssam  * Used to retrieve interface configuration
135*11576Ssam  * for machine (useful for programs which
136*11576Ssam  * must know all networks accessible).
137*11576Ssam  */
138*11576Ssam struct	ifconf {
139*11576Ssam 	int	ifc_len;		/* size of associated buffer */
140*11576Ssam 	union {
141*11576Ssam 		caddr_t	ifcu_buf;
142*11576Ssam 		struct	ifreq *ifcu_req;
143*11576Ssam 	} ifc_ifcu;
144*11576Ssam #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
145*11576Ssam #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
146*11576Ssam };
147*11576Ssam 
1484945Swnj #ifdef KERNEL
1495083Swnj #ifdef INET
1505083Swnj struct	ifqueue	ipintrq;		/* ip packet input queue */
1515083Swnj #endif
1526333Ssam struct	ifqueue rawintrq;		/* raw packet input queue */
1534945Swnj struct	ifnet *ifnet;
1546333Ssam struct	ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
1556333Ssam struct	ifnet *if_ifonnetof();
1565104Swnj struct	in_addr if_makeaddr();
1574945Swnj #endif
158