xref: /csrg-svn/sys/net/if.h (revision 37472)
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*37472Ssklower  *	@(#)if.h	7.5 (Berkeley) 04/22/89
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 */
6735795Skarels 	int	(*if_output)();		/* output routine (enqueue) */
6835795Skarels 	int	(*if_start)();		/* initiate output routine */
6935795Skarels 	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;
81*37472Ssklower 	u_char	if_type;		/* ethernet, tokenring, etc */
82*37472Ssklower 	u_char	if_addrlen;		/* media address length */
83*37472Ssklower 	u_char	if_hdrlen;		/* media header length */
844945Swnj };
854945Swnj 
866333Ssam #define	IFF_UP		0x1		/* interface is up */
876333Ssam #define	IFF_BROADCAST	0x2		/* broadcast address valid */
886333Ssam #define	IFF_DEBUG	0x4		/* turn on debugging */
8926092Skarels #define	IFF_LOOPBACK	0x8		/* is a loopback net */
906924Swnj #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
9113049Ssam #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
9213053Ssam #define	IFF_RUNNING	0x40		/* resources allocated */
9314866Ssam #define	IFF_NOARP	0x80		/* no address resolution protocol */
9428153Skarels /* next two not supported now, but reserved: */
9528153Skarels #define	IFF_PROMISC	0x100		/* receive all packets */
9628153Skarels #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
9735795Skarels #define	IFF_OACTIVE	0x400		/* transmission in progress */
9835795Skarels #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
9935795Skarels 
10026092Skarels /* flags set internally only: */
10135795Skarels #define	IFF_CANTCHANGE	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE)
1026333Ssam 
1035104Swnj /*
1045104Swnj  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
1055104Swnj  * input routines have queues of messages stored on ifqueue structures
1065104Swnj  * (defined above).  Entries are added to and deleted from these structures
1075104Swnj  * by these macros, which should be called with ipl raised to splimp().
1085104Swnj  */
1096207Swnj #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
1106207Swnj #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
1115083Swnj #define	IF_ENQUEUE(ifq, m) { \
1125083Swnj 	(m)->m_act = 0; \
1135083Swnj 	if ((ifq)->ifq_tail == 0) \
1145160Swnj 		(ifq)->ifq_head = m; \
1155083Swnj 	else \
1165083Swnj 		(ifq)->ifq_tail->m_act = m; \
1175160Swnj 	(ifq)->ifq_tail = m; \
1186207Swnj 	(ifq)->ifq_len++; \
1195083Swnj }
1205613Swnj #define	IF_PREPEND(ifq, m) { \
1215613Swnj 	(m)->m_act = (ifq)->ifq_head; \
1226087Sroot 	if ((ifq)->ifq_tail == 0) \
1236087Sroot 		(ifq)->ifq_tail = (m); \
1245613Swnj 	(ifq)->ifq_head = (m); \
1256207Swnj 	(ifq)->ifq_len++; \
1265613Swnj }
1275083Swnj #define	IF_DEQUEUE(ifq, m) { \
1285083Swnj 	(m) = (ifq)->ifq_head; \
1295083Swnj 	if (m) { \
1305083Swnj 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
1315083Swnj 			(ifq)->ifq_tail = 0; \
1325083Swnj 		(m)->m_act = 0; \
1336207Swnj 		(ifq)->ifq_len--; \
1345083Swnj 	} \
1355083Swnj }
1364945Swnj 
1376207Swnj #define	IFQ_MAXLEN	50
1387264Ssam #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
1396207Swnj 
14011576Ssam /*
14118408Skarels  * The ifaddr structure contains information about one address
14218408Skarels  * of an interface.  They are maintained by the different address families,
14318408Skarels  * are allocated and attached when an address is set, and are linked
14418408Skarels  * together so all addresses for an interface can be located.
14518408Skarels  */
14618408Skarels struct ifaddr {
147*37472Ssklower 	struct	sockaddr *ifa_addr;	/* address of interface */
148*37472Ssklower 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
149*37472Ssklower #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
150*37472Ssklower 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
15118408Skarels 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
15218408Skarels 	struct	ifaddr *ifa_next;	/* next address for interface */
15318408Skarels };
15418408Skarels /*
15513049Ssam  * Interface request structure used for socket
15613049Ssam  * ioctl's.  All interface ioctl's must have parameter
15713049Ssam  * definitions which begin with ifr_name.  The
15813049Ssam  * remainder may be interface specific.
15911576Ssam  */
16011576Ssam struct	ifreq {
16113049Ssam #define	IFNAMSIZ	16
16213049Ssam 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
16311576Ssam 	union {
16411576Ssam 		struct	sockaddr ifru_addr;
16511576Ssam 		struct	sockaddr ifru_dstaddr;
16616387Skarels 		struct	sockaddr ifru_broadaddr;
16711576Ssam 		short	ifru_flags;
16826092Skarels 		int	ifru_metric;
16913049Ssam 		caddr_t	ifru_data;
17011576Ssam 	} ifr_ifru;
17111576Ssam #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
17211576Ssam #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
17316387Skarels #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
17411576Ssam #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
17526092Skarels #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
17613049Ssam #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
17711576Ssam };
17811576Ssam 
179*37472Ssklower struct ifaliasreq {
180*37472Ssklower 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
181*37472Ssklower 	struct	sockaddr ifra_addr;
182*37472Ssklower 	struct	sockaddr ifra_broadaddr;
183*37472Ssklower 	struct	sockaddr ifra_mask;
184*37472Ssklower };
185*37472Ssklower 
18611576Ssam /*
18711576Ssam  * Structure used in SIOCGIFCONF request.
18811576Ssam  * Used to retrieve interface configuration
18911576Ssam  * for machine (useful for programs which
19011576Ssam  * must know all networks accessible).
19111576Ssam  */
19211576Ssam struct	ifconf {
19311576Ssam 	int	ifc_len;		/* size of associated buffer */
19411576Ssam 	union {
19511576Ssam 		caddr_t	ifcu_buf;
19611576Ssam 		struct	ifreq *ifcu_req;
19711576Ssam 	} ifc_ifcu;
19811576Ssam #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
19911576Ssam #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
20011576Ssam };
20111576Ssam 
2024945Swnj #ifdef KERNEL
20325971Skarels #include "../net/if_arp.h"
2046333Ssam struct	ifqueue rawintrq;		/* raw packet input queue */
2054945Swnj struct	ifnet *ifnet;
20628943Skarels struct	ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
20727197Skarels struct	ifaddr *ifa_ifwithdstaddr();
20825971Skarels #else KERNEL
20925971Skarels #include <net/if_arp.h>
21025971Skarels #endif KERNEL
211