xref: /csrg-svn/sys/net/if.h (revision 18408)
1*18408Skarels /*	if.h	6.6	85/03/19	*/
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.)
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 */
376333Ssam 	short	if_flags;		/* up/down, broadcast, etc. */
387264Ssam 	short	if_timer;		/* time 'til if_watchdog called */
39*18408Skarels 	struct	ifaddr *if_addrlist;	/* linked list of addresses per if */
405104Swnj 	struct	ifqueue {
415104Swnj 		struct	mbuf *ifq_head;
425104Swnj 		struct	mbuf *ifq_tail;
436207Swnj 		int	ifq_len;
446207Swnj 		int	ifq_maxlen;
456207Swnj 		int	ifq_drops;
465104Swnj 	} if_snd;			/* output queue */
475104Swnj /* procedure handles */
485104Swnj 	int	(*if_init)();		/* init routine */
495083Swnj 	int	(*if_output)();		/* output routine */
5013049Ssam 	int	(*if_ioctl)();		/* ioctl routine */
518972Sroot 	int	(*if_reset)();		/* bus reset routine */
527264Ssam 	int	(*if_watchdog)();	/* timer 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 
636333Ssam #define	IFF_UP		0x1		/* interface is up */
646333Ssam #define	IFF_BROADCAST	0x2		/* broadcast address valid */
656333Ssam #define	IFF_DEBUG	0x4		/* turn on debugging */
66*18408Skarels /* was	IFF_ROUTE	0x8		/* routing entry installed */
676924Swnj #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
6813049Ssam #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
6913053Ssam #define	IFF_RUNNING	0x40		/* resources allocated */
7014866Ssam #define	IFF_NOARP	0x80		/* no address resolution protocol */
71*18408Skarels 					/* flags set internally only: */
72*18408Skarels #define	IFF_CANTCHANGE	(IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
736333Ssam 
745104Swnj /*
755104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
765104Swnj  * input routines have queues of messages stored on ifqueue structures
775104Swnj  * (defined above).  Entries are added to and deleted from these structures
785104Swnj  * by these macros, which should be called with ipl raised to splimp().
795104Swnj  */
806207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
816207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
825083Swnj #define	IF_ENQUEUE(ifq, m) { \
835083Swnj 	(m)->m_act = 0; \
845083Swnj 	if ((ifq)->ifq_tail == 0) \
855160Swnj 		(ifq)->ifq_head = m; \
865083Swnj 	else \
875083Swnj 		(ifq)->ifq_tail->m_act = m; \
885160Swnj 	(ifq)->ifq_tail = m; \
896207Swnj 	(ifq)->ifq_len++; \
905083Swnj }
915613Swnj #define	IF_PREPEND(ifq, m) { \
925613Swnj 	(m)->m_act = (ifq)->ifq_head; \
936087Sroot 	if ((ifq)->ifq_tail == 0) \
946087Sroot 		(ifq)->ifq_tail = (m); \
955613Swnj 	(ifq)->ifq_head = (m); \
966207Swnj 	(ifq)->ifq_len++; \
975613Swnj }
985083Swnj #define	IF_DEQUEUE(ifq, m) { \
995083Swnj 	(m) = (ifq)->ifq_head; \
1005083Swnj 	if (m) { \
1015083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
1025083Swnj 			(ifq)->ifq_tail = 0; \
1035083Swnj 		(m)->m_act = 0; \
1046207Swnj 		(ifq)->ifq_len--; \
1055083Swnj 	} \
1065083Swnj }
1074945Swnj 
1086207Swnj #define	IFQ_MAXLEN	50
1097264Ssam #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1106207Swnj 
11111576Ssam /*
112*18408Skarels  * The ifaddr structure contains information about one address
113*18408Skarels  * of an interface.  They are maintained by the different address families,
114*18408Skarels  * are allocated and attached when an address is set, and are linked
115*18408Skarels  * together so all addresses for an interface can be located.
116*18408Skarels  */
117*18408Skarels struct ifaddr {
118*18408Skarels 	struct	sockaddr ifa_addr;	/* address of interface */
119*18408Skarels 	union {
120*18408Skarels 		struct	sockaddr ifu_broadaddr;
121*18408Skarels 		struct	sockaddr ifu_dstaddr;
122*18408Skarels 	} ifa_ifu;
123*18408Skarels #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
124*18408Skarels #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
125*18408Skarels 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
126*18408Skarels 	struct	ifaddr *ifa_next;	/* next address for interface */
127*18408Skarels };
128*18408Skarels 
129*18408Skarels /*
13013049Ssam  * Interface request structure used for socket
13113049Ssam  * ioctl's.  All interface ioctl's must have parameter
13213049Ssam  * definitions which begin with ifr_name.  The
13313049Ssam  * remainder may be interface specific.
13411576Ssam  */
13511576Ssam struct	ifreq {
13613049Ssam #define	IFNAMSIZ	16
13713049Ssam 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
13811576Ssam 	union {
13911576Ssam 		struct	sockaddr ifru_addr;
14011576Ssam 		struct	sockaddr ifru_dstaddr;
14116387Skarels 		struct	sockaddr ifru_broadaddr;
14211576Ssam 		short	ifru_flags;
14313049Ssam 		caddr_t	ifru_data;
14411576Ssam 	} ifr_ifru;
14511576Ssam #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
14611576Ssam #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
14716387Skarels #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
14811576Ssam #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
14913049Ssam #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
15011576Ssam };
15111576Ssam 
15211576Ssam /*
15311576Ssam  * Structure used in SIOCGIFCONF request.
15411576Ssam  * Used to retrieve interface configuration
15511576Ssam  * for machine (useful for programs which
15611576Ssam  * must know all networks accessible).
15711576Ssam  */
15811576Ssam struct	ifconf {
15911576Ssam 	int	ifc_len;		/* size of associated buffer */
16011576Ssam 	union {
16111576Ssam 		caddr_t	ifcu_buf;
16211576Ssam 		struct	ifreq *ifcu_req;
16311576Ssam 	} ifc_ifcu;
16411576Ssam #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
16511576Ssam #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
16611576Ssam };
16711576Ssam 
16816209Skarels /*
16916209Skarels  * ARP ioctl request
17016209Skarels  */
17116209Skarels struct arpreq {
17216209Skarels 	struct sockaddr	arp_pa;		/* protocol address */
17316209Skarels 	struct sockaddr	arp_ha;		/* hardware address */
17416209Skarels 	int	arp_flags;		/* flags */
17516209Skarels };
17616209Skarels /*  arp_flags and at_flags field values */
17716209Skarels #define	ATF_INUSE	1	/* entry in use */
17816209Skarels #define ATF_COM		2	/* completed entry (enaddr valid) */
17916209Skarels #define	ATF_PERM	4	/* permanent entry */
18016209Skarels #define	ATF_PUBL	8	/* publish entry (respond for other host) */
18116209Skarels 
1824945Swnj #ifdef KERNEL
1835083Swnj #ifdef INET
1845083Swnj struct	ifqueue	ipintrq;		/* ip packet input queue */
1855083Swnj #endif
1866333Ssam struct	ifqueue rawintrq;		/* raw packet input queue */
1874945Swnj struct	ifnet *ifnet;
188*18408Skarels struct	ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet(), *ifa_ifwithaf();
1894945Swnj #endif
190