xref: /csrg-svn/sys/net/if.h (revision 35795)
123158Smckusick /*
229062Smckusick  * Copyright (c) 1982, 1986 Regents of the University of California.
333183Sbostic  * All rights reserved.
423158Smckusick  *
533183Sbostic  * Redistribution and use in source and binary forms are permitted
634844Sbostic  * provided that the above copyright notice and this paragraph are
734844Sbostic  * duplicated in all such forms and that any documentation,
834844Sbostic  * advertising materials, and other materials related to such
934844Sbostic  * distribution and use acknowledge that the software was developed
1034844Sbostic  * by the University of California, Berkeley.  The name of the
1134844Sbostic  * University may not be used to endorse or promote products derived
1234844Sbostic  * from this software without specific prior written permission.
1334844Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434844Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534844Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1633183Sbostic  *
17*35795Skarels  *	@(#)if.h	7.4 (Berkeley) 10/12/88
1823158Smckusick  */
194945Swnj 
204945Swnj /*
215104Swnj  * Structures defining a network interface, providing a packet
225104Swnj  * transport mechanism (ala level 0 of the PUP protocols).
235104Swnj  *
245104Swnj  * Each interface accepts output datagrams of a specified maximum
255104Swnj  * length, and provides higher level routines with input datagrams
265104Swnj  * received from its medium.
275104Swnj  *
285104Swnj  * Output occurs when the routine if_output is called, with three parameters:
296333Ssam  *	(*ifp->if_output)(ifp, m, dst)
306333Ssam  * Here m is the mbuf chain to be sent and dst is the destination address.
316333Ssam  * The output routine encapsulates the supplied datagram if necessary,
326333Ssam  * and then transmits it on its medium.
335104Swnj  *
345104Swnj  * On input, each interface unwraps the data received by it, and either
355104Swnj  * places it on the input queue of a internetwork datagram routine
365104Swnj  * and posts the associated software interrupt, or passes the datagram to a raw
375104Swnj  * packet input routine.
385104Swnj  *
396333Ssam  * Routines exist for locating interfaces by their addresses
405104Swnj  * or for locating a interface on a certain network, as well as more general
415104Swnj  * routing and gateway routines maintaining information used to locate
426333Ssam  * interfaces.  These routines live in the files if.c and route.c
435083Swnj  */
445083Swnj 
455083Swnj /*
465083Swnj  * Structure defining a queue for a network interface.
474945Swnj  *
484945Swnj  * (Would like to call this struct ``if'', but C isn't PL/1.)
494945Swnj  */
504945Swnj struct ifnet {
515171Swnj 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
524945Swnj 	short	if_unit;		/* sub-unit for lower level driver */
534945Swnj 	short	if_mtu;			/* maximum transmission unit */
546333Ssam 	short	if_flags;		/* up/down, broadcast, etc. */
557264Ssam 	short	if_timer;		/* time 'til if_watchdog called */
5626092Skarels 	int	if_metric;		/* routing metric (external only) */
5718408Skarels 	struct	ifaddr *if_addrlist;	/* linked list of addresses per if */
585104Swnj 	struct	ifqueue {
595104Swnj 		struct	mbuf *ifq_head;
605104Swnj 		struct	mbuf *ifq_tail;
616207Swnj 		int	ifq_len;
626207Swnj 		int	ifq_maxlen;
636207Swnj 		int	ifq_drops;
645104Swnj 	} if_snd;			/* output queue */
655104Swnj /* procedure handles */
665104Swnj 	int	(*if_init)();		/* init routine */
67*35795Skarels 	int	(*if_output)();		/* output routine (enqueue) */
68*35795Skarels 	int	(*if_start)();		/* initiate output routine */
69*35795Skarels 	int	(*if_done)();		/* output complete routine */
7013049Ssam 	int	(*if_ioctl)();		/* ioctl routine */
718972Sroot 	int	(*if_reset)();		/* bus reset routine */
727264Ssam 	int	(*if_watchdog)();	/* timer routine */
735104Swnj /* generic interface statistics */
745171Swnj 	int	if_ipackets;		/* packets received on interface */
755171Swnj 	int	if_ierrors;		/* input errors on interface */
765171Swnj 	int	if_opackets;		/* packets sent on interface */
775171Swnj 	int	if_oerrors;		/* output errors on interface */
785104Swnj 	int	if_collisions;		/* collisions on csma interfaces */
795104Swnj /* end statistics */
804951Swnj 	struct	ifnet *if_next;
814945Swnj };
824945Swnj 
836333Ssam #define	IFF_UP		0x1		/* interface is up */
846333Ssam #define	IFF_BROADCAST	0x2		/* broadcast address valid */
856333Ssam #define	IFF_DEBUG	0x4		/* turn on debugging */
8626092Skarels #define	IFF_LOOPBACK	0x8		/* is a loopback net */
876924Swnj #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
8813049Ssam #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
8913053Ssam #define	IFF_RUNNING	0x40		/* resources allocated */
9014866Ssam #define	IFF_NOARP	0x80		/* no address resolution protocol */
9128153Skarels /* next two not supported now, but reserved: */
9228153Skarels #define	IFF_PROMISC	0x100		/* receive all packets */
9328153Skarels #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
94*35795Skarels #define	IFF_OACTIVE	0x400		/* transmission in progress */
95*35795Skarels #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
96*35795Skarels 
9726092Skarels /* flags set internally only: */
98*35795Skarels #define	IFF_CANTCHANGE	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE)
996333Ssam 
1005104Swnj /*
1015104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
1025104Swnj  * input routines have queues of messages stored on ifqueue structures
1035104Swnj  * (defined above).  Entries are added to and deleted from these structures
1045104Swnj  * by these macros, which should be called with ipl raised to splimp().
1055104Swnj  */
1066207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1076207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
1085083Swnj #define	IF_ENQUEUE(ifq, m) { \
1095083Swnj 	(m)->m_act = 0; \
1105083Swnj 	if ((ifq)->ifq_tail == 0) \
1115160Swnj 		(ifq)->ifq_head = m; \
1125083Swnj 	else \
1135083Swnj 		(ifq)->ifq_tail->m_act = m; \
1145160Swnj 	(ifq)->ifq_tail = m; \
1156207Swnj 	(ifq)->ifq_len++; \
1165083Swnj }
1175613Swnj #define	IF_PREPEND(ifq, m) { \
1185613Swnj 	(m)->m_act = (ifq)->ifq_head; \
1196087Sroot 	if ((ifq)->ifq_tail == 0) \
1206087Sroot 		(ifq)->ifq_tail = (m); \
1215613Swnj 	(ifq)->ifq_head = (m); \
1226207Swnj 	(ifq)->ifq_len++; \
1235613Swnj }
1245083Swnj #define	IF_DEQUEUE(ifq, m) { \
1255083Swnj 	(m) = (ifq)->ifq_head; \
1265083Swnj 	if (m) { \
1275083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
1285083Swnj 			(ifq)->ifq_tail = 0; \
1295083Swnj 		(m)->m_act = 0; \
1306207Swnj 		(ifq)->ifq_len--; \
1315083Swnj 	} \
1325083Swnj }
1334945Swnj 
1346207Swnj #define	IFQ_MAXLEN	50
1357264Ssam #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1366207Swnj 
13711576Ssam /*
13818408Skarels  * The ifaddr structure contains information about one address
13918408Skarels  * of an interface.  They are maintained by the different address families,
14018408Skarels  * are allocated and attached when an address is set, and are linked
14118408Skarels  * together so all addresses for an interface can be located.
14218408Skarels  */
14318408Skarels struct ifaddr {
14418408Skarels 	struct	sockaddr ifa_addr;	/* address of interface */
14518408Skarels 	union {
14618408Skarels 		struct	sockaddr ifu_broadaddr;
14718408Skarels 		struct	sockaddr ifu_dstaddr;
14818408Skarels 	} ifa_ifu;
14918408Skarels #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
15018408Skarels #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
15118408Skarels 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
15218408Skarels 	struct	ifaddr *ifa_next;	/* next address for interface */
15318408Skarels };
15418408Skarels 
15518408Skarels /*
15613049Ssam  * Interface request structure used for socket
15713049Ssam  * ioctl's.  All interface ioctl's must have parameter
15813049Ssam  * definitions which begin with ifr_name.  The
15913049Ssam  * remainder may be interface specific.
16011576Ssam  */
16111576Ssam struct	ifreq {
16213049Ssam #define	IFNAMSIZ	16
16313049Ssam 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
16411576Ssam 	union {
16511576Ssam 		struct	sockaddr ifru_addr;
16611576Ssam 		struct	sockaddr ifru_dstaddr;
16716387Skarels 		struct	sockaddr ifru_broadaddr;
16811576Ssam 		short	ifru_flags;
16926092Skarels 		int	ifru_metric;
17013049Ssam 		caddr_t	ifru_data;
17111576Ssam 	} ifr_ifru;
17211576Ssam #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
17311576Ssam #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
17416387Skarels #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
17511576Ssam #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
17626092Skarels #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
17713049Ssam #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
17811576Ssam };
17911576Ssam 
18011576Ssam /*
18111576Ssam  * Structure used in SIOCGIFCONF request.
18211576Ssam  * Used to retrieve interface configuration
18311576Ssam  * for machine (useful for programs which
18411576Ssam  * must know all networks accessible).
18511576Ssam  */
18611576Ssam struct	ifconf {
18711576Ssam 	int	ifc_len;		/* size of associated buffer */
18811576Ssam 	union {
18911576Ssam 		caddr_t	ifcu_buf;
19011576Ssam 		struct	ifreq *ifcu_req;
19111576Ssam 	} ifc_ifcu;
19211576Ssam #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
19311576Ssam #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
19411576Ssam };
19511576Ssam 
1964945Swnj #ifdef KERNEL
19725971Skarels #include "../net/if_arp.h"
1986333Ssam struct	ifqueue rawintrq;		/* raw packet input queue */
1994945Swnj struct	ifnet *ifnet;
20028943Skarels struct	ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
20127197Skarels struct	ifaddr *ifa_ifwithdstaddr();
20225971Skarels #else KERNEL
20325971Skarels #include <net/if_arp.h>
20425971Skarels #endif KERNEL
205