Home | History | Annotate | Line # | Download | only in net
if.h revision 1.64
      1 /*	$NetBSD: if.h,v 1.64 2001/01/17 04:05:42 itojun Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by William Studnemund and Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1982, 1986, 1989, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)if.h	8.3 (Berkeley) 2/9/95
     72  */
     73 
     74 #ifndef _NET_IF_H_
     75 #define _NET_IF_H_
     76 
     77 #if !defined(_XOPEN_SOURCE)
     78 
     79 #include <sys/queue.h>
     80 #include <net/dlt.h>
     81 
     82 /*
     83  * Always include ALTQ glue here -- we use the ALTQ interface queue
     84  * structure even when ALTQ is not configured into the kernel so that
     85  * the size of struct ifnet does not changed based on the option.  The
     86  * ALTQ queue structure is API-compatible with the legacy ifqueue.
     87  */
     88 #include <altq/if_altq.h>
     89 
     90 /*
     91  * Structures defining a network interface, providing a packet
     92  * transport mechanism (ala level 0 of the PUP protocols).
     93  *
     94  * Each interface accepts output datagrams of a specified maximum
     95  * length, and provides higher level routines with input datagrams
     96  * received from its medium.
     97  *
     98  * Output occurs when the routine if_output is called, with four parameters:
     99  *	(*ifp->if_output)(ifp, m, dst, rt)
    100  * Here m is the mbuf chain to be sent and dst is the destination address.
    101  * The output routine encapsulates the supplied datagram if necessary,
    102  * and then transmits it on its medium.
    103  *
    104  * On input, each interface unwraps the data received by it, and either
    105  * places it on the input queue of a internetwork datagram routine
    106  * and posts the associated software interrupt, or passes the datagram to a raw
    107  * packet input routine.
    108  *
    109  * Routines exist for locating interfaces by their addresses
    110  * or for locating a interface on a certain network, as well as more general
    111  * routing and gateway routines maintaining information used to locate
    112  * interfaces.  These routines live in the files if.c and route.c
    113  */
    114 /*  XXX fast fix for SNMP, going away soon */
    115 #include <sys/time.h>
    116 
    117 #if defined(_KERNEL) && !defined(_LKM)
    118 #include "opt_compat_netbsd.h"
    119 #endif
    120 
    121 struct mbuf;
    122 struct proc;
    123 struct rtentry;
    124 struct socket;
    125 struct ether_header;
    126 struct ifnet;
    127 
    128 /*
    129  * Length of interface external name, including terminating '\0'.
    130  * Note: this is the same size as a generic device's external name.
    131  */
    132 #define	IFNAMSIZ	16
    133 #define	IF_NAMESIZE	IFNAMSIZ
    134 
    135 /*
    136  * Structure describing a `cloning' interface.
    137  */
    138 struct if_clone {
    139 	LIST_ENTRY(if_clone) ifc_list;	/* on list of cloners */
    140 	const char *ifc_name;		/* name of device, e.g. `gif' */
    141 	size_t ifc_namelen;		/* length of name */
    142 
    143 	int	(*ifc_create)(struct if_clone *, int);
    144 	void	(*ifc_destroy)(struct ifnet *);
    145 };
    146 
    147 #define	IF_CLONE_INITIALIZER(name, create, destroy)			\
    148 	{ { 0 }, name, sizeof(name) - 1, create, destroy }
    149 
    150 /*
    151  * Structure used to query names of interface cloners.
    152  */
    153 struct if_clonereq {
    154 	int	ifcr_total;		/* total cloners (out) */
    155 	int	ifcr_count;		/* room for this many in user buffer */
    156 	char	*ifcr_buffer;		/* buffer for cloner names */
    157 };
    158 
    159 /*
    160  * Structure defining statistics and other data kept regarding a network
    161  * interface.
    162  */
    163 struct if_data {
    164 	/* generic interface information */
    165 	u_char	ifi_type;		/* ethernet, tokenring, etc. */
    166 	u_char	ifi_addrlen;		/* media address length */
    167 	u_char	ifi_hdrlen;		/* media header length */
    168 	int	ifi_link_state;		/* current link state */
    169 	u_quad_t ifi_mtu;		/* maximum transmission unit */
    170 	u_quad_t ifi_metric;		/* routing metric (external only) */
    171 	u_quad_t ifi_baudrate;		/* linespeed */
    172 	/* volatile statistics */
    173 	u_quad_t ifi_ipackets;		/* packets received on interface */
    174 	u_quad_t ifi_ierrors;		/* input errors on interface */
    175 	u_quad_t ifi_opackets;		/* packets sent on interface */
    176 	u_quad_t ifi_oerrors;		/* output errors on interface */
    177 	u_quad_t ifi_collisions;	/* collisions on csma interfaces */
    178 	u_quad_t ifi_ibytes;		/* total number of octets received */
    179 	u_quad_t ifi_obytes;		/* total number of octets sent */
    180 	u_quad_t ifi_imcasts;		/* packets received via multicast */
    181 	u_quad_t ifi_omcasts;		/* packets sent via multicast */
    182 	u_quad_t ifi_iqdrops;		/* dropped on input, this interface */
    183 	u_quad_t ifi_noproto;		/* destined for unsupported protocol */
    184 	struct	timeval ifi_lastchange;	/* last updated */
    185 };
    186 
    187 /*
    188  * Values for if_link_state.
    189  */
    190 #define	LINK_STATE_UNKNOWN	0	/* link invalid/unknown */
    191 #define	LINK_STATE_DOWN		1	/* link is down */
    192 #define	LINK_STATE_UP		2	/* link is up */
    193 
    194 #if defined(_KERNEL) && defined(COMPAT_14)
    195 /* Pre-1.5 if_data struct */
    196 struct if_data14 {
    197 	/* generic interface information */
    198 	u_char	ifi_type;		/* ethernet, tokenring, etc. */
    199 	u_char	ifi_addrlen;		/* media address length */
    200 	u_char	ifi_hdrlen;		/* media header length */
    201 	u_long	ifi_mtu;		/* maximum transmission unit */
    202 	u_long	ifi_metric;		/* routing metric (external only) */
    203 	u_long	ifi_baudrate;		/* linespeed */
    204 	/* volatile statistics */
    205 	u_long	ifi_ipackets;		/* packets received on interface */
    206 	u_long	ifi_ierrors;		/* input errors on interface */
    207 	u_long	ifi_opackets;		/* packets sent on interface */
    208 	u_long	ifi_oerrors;		/* output errors on interface */
    209 	u_long	ifi_collisions;		/* collisions on csma interfaces */
    210 	u_long	ifi_ibytes;		/* total number of octets received */
    211 	u_long	ifi_obytes;		/* total number of octets sent */
    212 	u_long	ifi_imcasts;		/* packets received via multicast */
    213 	u_long	ifi_omcasts;		/* packets sent via multicast */
    214 	u_long	ifi_iqdrops;		/* dropped on input, this interface */
    215 	u_long	ifi_noproto;		/* destined for unsupported protocol */
    216 	struct	timeval ifi_lastchange;	/* last updated */
    217 };
    218 #endif /* _KERNEL && COMPAT_14 */
    219 
    220 /*
    221  * Structure defining a queue for a network interface.
    222  */
    223 struct ifqueue {
    224 	struct	mbuf *ifq_head;
    225 	struct	mbuf *ifq_tail;
    226 	int	ifq_len;
    227 	int	ifq_maxlen;
    228 	int	ifq_drops;
    229 };
    230 
    231 /*
    232  * Structure defining a queue for a network interface.
    233  *
    234  * (Would like to call this struct ``if'', but C isn't PL/1.)
    235  */
    236 TAILQ_HEAD(ifnet_head, ifnet);		/* the actual queue head */
    237 
    238 struct ifnet {				/* and the entries */
    239 	void	*if_softc;		/* lower-level data for this if */
    240 	TAILQ_ENTRY(ifnet) if_list;	/* all struct ifnets are chained */
    241 	TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
    242 	char	if_xname[IFNAMSIZ];	/* external name (name + unit) */
    243 	int	if_pcount;		/* number of promiscuous listeners */
    244 	caddr_t	if_bpf;			/* packet filter structure */
    245 	u_short	if_index;		/* numeric abbreviation for this if */
    246 	short	if_timer;		/* time 'til if_watchdog called */
    247 	short	if_flags;		/* up/down, broadcast, etc. */
    248 	short	if__pad1;		/* be nice to m68k ports */
    249 	struct	if_data if_data;	/* statistics and other data about if */
    250 	/*
    251 	 * Procedure handles.  If you add more of these, don't forget the
    252 	 * corresponding NULL stub in if.c.
    253 	 */
    254 	int	(*if_output)		/* output routine (enqueue) */
    255 		__P((struct ifnet *, struct mbuf *, struct sockaddr *,
    256 		     struct rtentry *));
    257 	void	(*if_input)		/* input routine (from h/w driver) */
    258 		__P((struct ifnet *, struct mbuf *));
    259 	void	(*if_start)		/* initiate output routine */
    260 		__P((struct ifnet *));
    261 	int	(*if_ioctl)		/* ioctl routine */
    262 		__P((struct ifnet *, u_long, caddr_t));
    263 	int	(*if_init)		/* init routine */
    264 		__P((struct ifnet *));
    265 	void	(*if_stop)		/* stop routine */
    266 		__P((struct ifnet *, int));
    267 	void	(*if_watchdog)		/* timer routine */
    268 		__P((struct ifnet *));
    269 	void	(*if_drain)		/* routine to release resources */
    270 		__P((struct ifnet *));
    271 	struct ifaltq if_snd;		/* output queue (includes altq) */
    272 	struct	sockaddr_dl *if_sadl;	/* pointer to our sockaddr_dl */
    273 	u_int8_t *if_broadcastaddr;	/* linklevel broadcast bytestring */
    274 	struct ifprefix *if_prefixlist; /* linked list of prefixes per if */
    275 	void	*if_bridge;		/* bridge glue */
    276 	int	if_dlt;			/* data link type (<net/dlt.h>) */
    277 };
    278 #define	if_mtu		if_data.ifi_mtu
    279 #define	if_type		if_data.ifi_type
    280 #define	if_addrlen	if_data.ifi_addrlen
    281 #define	if_hdrlen	if_data.ifi_hdrlen
    282 #define	if_metric	if_data.ifi_metric
    283 #define	if_link_state	if_data.ifi_link_state
    284 #define	if_baudrate	if_data.ifi_baudrate
    285 #define	if_ipackets	if_data.ifi_ipackets
    286 #define	if_ierrors	if_data.ifi_ierrors
    287 #define	if_opackets	if_data.ifi_opackets
    288 #define	if_oerrors	if_data.ifi_oerrors
    289 #define	if_collisions	if_data.ifi_collisions
    290 #define	if_ibytes	if_data.ifi_ibytes
    291 #define	if_obytes	if_data.ifi_obytes
    292 #define	if_imcasts	if_data.ifi_imcasts
    293 #define	if_omcasts	if_data.ifi_omcasts
    294 #define	if_iqdrops	if_data.ifi_iqdrops
    295 #define	if_noproto	if_data.ifi_noproto
    296 #define	if_lastchange	if_data.ifi_lastchange
    297 
    298 #define	IFF_UP		0x1		/* interface is up */
    299 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
    300 #define	IFF_DEBUG	0x4		/* turn on debugging */
    301 #define	IFF_LOOPBACK	0x8		/* is a loopback net */
    302 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
    303 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
    304 #define	IFF_RUNNING	0x40		/* resources allocated */
    305 #define	IFF_NOARP	0x80		/* no address resolution protocol */
    306 #define	IFF_PROMISC	0x100		/* receive all packets */
    307 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
    308 #define	IFF_OACTIVE	0x400		/* transmission in progress */
    309 #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
    310 #define	IFF_LINK0	0x1000		/* per link layer defined bit */
    311 #define	IFF_LINK1	0x2000		/* per link layer defined bit */
    312 #define	IFF_LINK2	0x4000		/* per link layer defined bit */
    313 #define	IFF_MULTICAST	0x8000		/* supports multicast */
    314 
    315 /* flags set internally only: */
    316 #define	IFF_CANTCHANGE \
    317 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
    318 	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC)
    319 
    320 /*
    321  * Some convenience macros used for setting ifi_baudrate.
    322  * XXX 1000 vs. 1024? --thorpej (at) netbsd.org
    323  */
    324 #define	IF_Kbps(x)	((x) * 1000)		/* kilobits/sec. */
    325 #define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
    326 #define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
    327 
    328 /*
    329  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
    330  * input routines have queues of messages stored on ifqueue structures
    331  * (defined above).  Entries are added to and deleted from these structures
    332  * by these macros, which should be called with ipl raised to splimp().
    333  */
    334 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
    335 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
    336 #define	IF_ENQUEUE(ifq, m) { \
    337 	(m)->m_nextpkt = 0; \
    338 	if ((ifq)->ifq_tail == 0) \
    339 		(ifq)->ifq_head = m; \
    340 	else \
    341 		(ifq)->ifq_tail->m_nextpkt = m; \
    342 	(ifq)->ifq_tail = m; \
    343 	(ifq)->ifq_len++; \
    344 }
    345 #define	IF_PREPEND(ifq, m) { \
    346 	(m)->m_nextpkt = (ifq)->ifq_head; \
    347 	if ((ifq)->ifq_tail == 0) \
    348 		(ifq)->ifq_tail = (m); \
    349 	(ifq)->ifq_head = (m); \
    350 	(ifq)->ifq_len++; \
    351 }
    352 #define	IF_DEQUEUE(ifq, m) { \
    353 	(m) = (ifq)->ifq_head; \
    354 	if (m) { \
    355 		if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
    356 			(ifq)->ifq_tail = 0; \
    357 		(m)->m_nextpkt = 0; \
    358 		(ifq)->ifq_len--; \
    359 	} \
    360 }
    361 #define	IF_POLL(ifq, m)		((m) = (ifq)->ifq_head)
    362 #define	IF_PURGE(ifq)							\
    363 do {									\
    364 	struct mbuf *__m0;						\
    365 									\
    366 	for (;;) {							\
    367 		IF_DEQUEUE((ifq), __m0);				\
    368 		if (__m0 == NULL)					\
    369 			break;						\
    370 		else							\
    371 			m_freem(__m0);					\
    372 	}								\
    373 } while (0)
    374 #define	IF_IS_EMPTY(ifq)	((ifq)->ifq_len == 0)
    375 
    376 #define	IFQ_MAXLEN	50
    377 #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
    378 
    379 /*
    380  * Structure defining statistics and other data kept regarding an address
    381  * on a network interface.
    382  */
    383 struct ifaddr_data {
    384 	int64_t	ifad_inbytes;
    385 	int64_t	ifad_outbytes;
    386 };
    387 
    388 /*
    389  * The ifaddr structure contains information about one address
    390  * of an interface.  They are maintained by the different address families,
    391  * are allocated and attached when an address is set, and are linked
    392  * together so all addresses for an interface can be located.
    393  */
    394 struct rt_addrinfo;
    395 struct ifaddr {
    396 	struct	sockaddr *ifa_addr;	/* address of interface */
    397 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
    398 #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
    399 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
    400 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
    401 	TAILQ_ENTRY(ifaddr) ifa_list;	/* list of addresses for interface */
    402 	struct	ifaddr_data	ifa_data;	/* statistics on the address */
    403 	void	(*ifa_rtrequest)	/* check or clean routes (+ or -)'d */
    404 		    __P((int, struct rtentry *, struct rt_addrinfo *));
    405 	u_int	ifa_flags;		/* mostly rt_flags for cloning */
    406 	int	ifa_refcnt;		/* count of references */
    407 	int	ifa_metric;		/* cost of going out this interface */
    408 };
    409 #define	IFA_ROUTE	RTF_UP		/* route installed */
    410 
    411 /*
    412  * The prefix structure contains information about one prefix
    413  * of an interface.  They are maintained by the different address families,
    414  * are allocated and attached when an prefix or an address is set,
    415  * and are linked together so all prfefixes for an interface can be located.
    416  */
    417 struct ifprefix {
    418 	struct	sockaddr *ifpr_prefix;	/* prefix of interface */
    419 	struct	ifnet *ifpr_ifp;	/* back-pointer to interface */
    420 	struct ifprefix *ifpr_next;
    421 	u_char	ifpr_plen;		/* prefix length in bits */
    422 	u_char	ifpr_type;		/* protocol dependent prefix type */
    423 };
    424 
    425 /*
    426  * Message format for use in obtaining information about interfaces
    427  * from sysctl and the routing socket.
    428  */
    429 struct if_msghdr {
    430 	u_short	ifm_msglen;	/* to skip over non-understood messages */
    431 	u_char	ifm_version;	/* future binary compatability */
    432 	u_char	ifm_type;	/* message type */
    433 	int	ifm_addrs;	/* like rtm_addrs */
    434 	int	ifm_flags;	/* value of if_flags */
    435 	u_short	ifm_index;	/* index for associated ifp */
    436 	struct	if_data ifm_data;/* statistics and other data about if */
    437 };
    438 
    439 #if defined(_KERNEL) && defined(COMPAT_14)
    440 /* pre-1.5 if_msghdr (ifm_data changed) */
    441 struct if_msghdr14 {
    442 	u_short	ifm_msglen;	/* to skip over non-understood messages */
    443 	u_char	ifm_version;	/* future binary compatability */
    444 	u_char	ifm_type;	/* message type */
    445 	int	ifm_addrs;	/* like rtm_addrs */
    446 	int	ifm_flags;	/* value of if_flags */
    447 	u_short	ifm_index;	/* index for associated ifp */
    448 	struct	if_data14 ifm_data; /* statistics and other data about if */
    449 };
    450 #endif /* _KERNEL && COMPAT_14 */
    451 
    452 /*
    453  * Message format for use in obtaining information about interface addresses
    454  * from sysctl and the routing socket.
    455  */
    456 struct ifa_msghdr {
    457 	u_short	ifam_msglen;	/* to skip over non-understood messages */
    458 	u_char	ifam_version;	/* future binary compatability */
    459 	u_char	ifam_type;	/* message type */
    460 	int	ifam_addrs;	/* like rtm_addrs */
    461 	int	ifam_flags;	/* value of ifa_flags */
    462 	u_short	ifam_index;	/* index for associated ifp */
    463 	int	ifam_metric;	/* value of ifa_metric */
    464 };
    465 
    466 /*
    467  * Message format announcing the arrival or departure of a network interface.
    468  */
    469 struct if_announcemsghdr {
    470 	u_short	ifan_msglen;	/* to skip over non-understood messages */
    471 	u_char	ifan_version;	/* future binary compatibility */
    472 	u_char	ifan_type;	/* message type */
    473 	u_short	ifan_index;	/* index for associated ifp */
    474 	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
    475 	u_short	ifan_what;	/* what type of announcement */
    476 };
    477 
    478 #define	IFAN_ARRIVAL	0	/* interface arrival */
    479 #define	IFAN_DEPARTURE	1	/* interface departure */
    480 
    481 /*
    482  * Interface request structure used for socket
    483  * ioctl's.  All interface ioctl's must have parameter
    484  * definitions which begin with ifr_name.  The
    485  * remainder may be interface specific.
    486  */
    487 struct	ifreq {
    488 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
    489 	union {
    490 		struct	sockaddr ifru_addr;
    491 		struct	sockaddr ifru_dstaddr;
    492 		struct	sockaddr ifru_broadaddr;
    493 		short	ifru_flags;
    494 		int	ifru_metric;
    495 		int	ifru_mtu;
    496 		int	ifru_dlt;
    497 		u_int	ifru_value;
    498 		caddr_t	ifru_data;
    499 	} ifr_ifru;
    500 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
    501 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
    502 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
    503 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
    504 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
    505 #define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
    506 #define	ifr_dlt		ifr_ifru.ifru_dlt	/* data link type (DLT_*) */
    507 #define	ifr_value	ifr_ifru.ifru_value	/* generic value */
    508 #define	ifr_media	ifr_ifru.ifru_metric	/* media options (overload) */
    509 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
    510 };
    511 
    512 struct ifaliasreq {
    513 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
    514 	struct	sockaddr ifra_addr;
    515 	struct	sockaddr ifra_dstaddr;
    516 #define	ifra_broadaddr	ifra_dstaddr
    517 	struct	sockaddr ifra_mask;
    518 };
    519 
    520 struct ifmediareq {
    521 	char	ifm_name[IFNAMSIZ];		/* if name, e.g. "en0" */
    522 	int	ifm_current;			/* current media options */
    523 	int	ifm_mask;			/* don't care mask */
    524 	int	ifm_status;			/* media status */
    525 	int	ifm_active;			/* active options */
    526 	int	ifm_count;			/* # entries in ifm_ulist
    527 						   array */
    528 	int	*ifm_ulist;			/* media words */
    529 };
    530 
    531 
    532 struct  ifdrv {
    533 	char		ifd_name[IFNAMSIZ];	/* if name, e.g. "en0" */
    534 	unsigned long	ifd_cmd;
    535 	size_t		ifd_len;
    536 	void		*ifd_data;
    537 };
    538 
    539 /*
    540  * Structure used in SIOCGIFCONF request.
    541  * Used to retrieve interface configuration
    542  * for machine (useful for programs which
    543  * must know all networks accessible).
    544  */
    545 struct	ifconf {
    546 	int	ifc_len;		/* size of associated buffer */
    547 	union {
    548 		caddr_t	ifcu_buf;
    549 		struct	ifreq *ifcu_req;
    550 	} ifc_ifcu;
    551 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
    552 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
    553 };
    554 
    555 /*
    556  * Structure for SIOC[AGD]LIFADDR
    557  */
    558 struct if_laddrreq {
    559 	char iflr_name[IFNAMSIZ];
    560 	unsigned int flags;
    561 #define IFLR_PREFIX	0x8000	/* in: prefix given  out: kernel fills id */
    562 	unsigned int prefixlen;		/* in/out */
    563 	struct sockaddr_storage addr;	/* in/out */
    564 	struct sockaddr_storage dstaddr; /* out */
    565 };
    566 
    567 #include <net/if_arp.h>
    568 
    569 #endif /* !_XOPEN_SOURCE */
    570 
    571 #ifdef _KERNEL
    572 #ifdef IFAREF_DEBUG
    573 #define	IFAREF(ifa)							\
    574 do {									\
    575 	printf("IFAREF: %s:%d %p -> %d\n", __FILE__, __LINE__,		\
    576 	    (ifa), ++(ifa)->ifa_refcnt);				\
    577 } while (0)
    578 
    579 #define	IFAFREE(ifa)							\
    580 do {									\
    581 	if ((ifa)->ifa_refcnt <= 0)					\
    582 		panic("%s:%d: %p ifa_refcnt <= 0", __FILE__,		\
    583 		    __LINE__, (ifa));					\
    584 	printf("IFAFREE: %s:%d %p -> %d\n", __FILE__, __LINE__,		\
    585 	    (ifa), --(ifa)->ifa_refcnt);				\
    586 	if ((ifa)->ifa_refcnt == 0)					\
    587 		ifafree(ifa);						\
    588 } while (0)
    589 #else
    590 #define	IFAREF(ifa)	(ifa)->ifa_refcnt++
    591 
    592 #ifdef DIAGNOSTIC
    593 #define	IFAFREE(ifa)							\
    594 do {									\
    595 	if ((ifa)->ifa_refcnt <= 0)					\
    596 		panic("%s:%d: %p ifa_refcnt <= 0", __FILE__,		\
    597 		    __LINE__, (ifa));					\
    598 	if (--(ifa)->ifa_refcnt == 0)					\
    599 		ifafree(ifa);						\
    600 } while (0)
    601 #else
    602 #define	IFAFREE(ifa)							\
    603 do {									\
    604 	if (--(ifa)->ifa_refcnt == 0)					\
    605 		ifafree(ifa);						\
    606 } while (0)
    607 #endif /* DIAGNOSTIC */
    608 #endif /* IFAREF_DEBUG */
    609 
    610 #ifdef ALTQ
    611 #define	ALTQ_DECL(x)		x
    612 
    613 #define IFQ_ENQUEUE(ifq, m, pattr, err)					\
    614 do {									\
    615 	if (ALTQ_IS_ENABLED((ifq)))					\
    616 		ALTQ_ENQUEUE((ifq), (m), (pattr), (err));		\
    617 	else {								\
    618 		if (IF_QFULL((ifq))) {					\
    619 			m_freem((m));					\
    620 			(err) = ENOBUFS;				\
    621 		} else {						\
    622 			IF_ENQUEUE((ifq), (m));				\
    623 			(err) = 0;					\
    624 		}							\
    625 	}								\
    626 	if ((err))							\
    627 		(ifq)->ifq_drops++;					\
    628 } while (0)
    629 
    630 #define IFQ_DEQUEUE(ifq, m)						\
    631 do {									\
    632 	if (TBR_IS_ENABLED((ifq)))					\
    633 		(m) = tbr_dequeue((ifq), ALTDQ_REMOVE);			\
    634 	else if (ALTQ_IS_ENABLED((ifq)))				\
    635 		ALTQ_DEQUEUE((ifq), (m));				\
    636 	else								\
    637 		IF_DEQUEUE((ifq), (m));					\
    638 } while (0)
    639 
    640 #define	IFQ_POLL(ifq, m)						\
    641 do {									\
    642 	if (TBR_IS_ENABLED((ifq)))					\
    643 		(m) = tbr_dequeue((ifq), ALTDQ_POLL);			\
    644 	else if (ALTQ_IS_ENABLED((ifq)))				\
    645 		ALTQ_POLL((ifq), (m));					\
    646 	else								\
    647 		IF_POLL((ifq), (m));					\
    648 } while (0)
    649 
    650 #define	IFQ_PURGE(ifq)							\
    651 do {									\
    652 	if (ALTQ_IS_ENABLED((ifq)))					\
    653 		ALTQ_PURGE((ifq));					\
    654 	else								\
    655 		IF_PURGE((ifq));					\
    656 } while (0)
    657 
    658 #define	IFQ_SET_READY(ifq)						\
    659 do {									\
    660 	(ifq)->altq_flags |= ALTQF_READY;				\
    661 } while (0)
    662 
    663 #define	IFQ_CLASSIFY(ifq, m, af, pa)					\
    664 do {									\
    665 	if (ALTQ_IS_ENABLED((ifq))) {					\
    666 		if (ALTQ_NEEDS_CLASSIFY((ifq)))				\
    667 			(pa)->pattr_class = (*(ifq)->altq_classify)	\
    668 				((ifq)->altq_clfier, (m), (af));	\
    669 		(pa)->pattr_af = (af);					\
    670 		(pa)->pattr_hdr = mtod((m), caddr_t);			\
    671 	}								\
    672 } while (0)
    673 #else /* ! ALTQ */
    674 #define	ALTQ_DECL(x)		/* nothing */
    675 
    676 #define	IFQ_ENQUEUE(ifq, m, pattr, err)					\
    677 do {									\
    678 	if (IF_QFULL((ifq))) {						\
    679 		m_freem((m));						\
    680 		(err) = ENOBUFS;					\
    681 	} else {							\
    682 		IF_ENQUEUE((ifq), (m));					\
    683 		(err) = 0;						\
    684 	}								\
    685 	if ((err))							\
    686 		(ifq)->ifq_drops++;					\
    687 } while (0)
    688 
    689 #define	IFQ_DEQUEUE(ifq, m)	IF_DEQUEUE((ifq), (m))
    690 
    691 #define	IFQ_POLL(ifq, m)	IF_POLL((ifq), (m))
    692 
    693 #define	IFQ_PURGE(ifq)		IF_PURGE((ifq))
    694 
    695 #define	IFQ_SET_READY(ifq)	/* nothing */
    696 
    697 #define	IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */
    698 
    699 #endif /* ALTQ */
    700 
    701 #define	IFQ_IS_EMPTY(ifq)		IF_IS_EMPTY((ifq))
    702 #define	IFQ_INC_LEN(ifq)		((ifq)->ifq_len++)
    703 #define	IFQ_DEC_LEN(ifq)		(--(ifq)->ifq_len)
    704 #define	IFQ_INC_DROPS(ifq)		((ifq)->ifq_drops++)
    705 #define	IFQ_SET_MAXLEN(ifq, len)	((ifq)->ifq_maxlen = (len))
    706 
    707 struct ifnet_head ifnet;
    708 extern struct ifnet **ifindex2ifnet;
    709 #if 0
    710 struct ifnet loif[];
    711 #endif
    712 extern int if_index;
    713 
    714 void	ether_ifattach __P((struct ifnet *, const u_int8_t *));
    715 void	ether_ifdetach __P((struct ifnet *));
    716 char	*ether_sprintf __P((const u_char *));
    717 
    718 void	if_alloc_sadl __P((struct ifnet *));
    719 void	if_free_sadl __P((struct ifnet *));
    720 void	if_attach __P((struct ifnet *));
    721 void	if_deactivate __P((struct ifnet *));
    722 void	if_detach __P((struct ifnet *));
    723 void	if_down __P((struct ifnet *));
    724 void	if_slowtimo __P((void *));
    725 void	if_up __P((struct ifnet *));
    726 int	ifconf __P((u_long, caddr_t));
    727 void	ifinit __P((void));
    728 int	ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
    729 int	ifpromisc __P((struct ifnet *, int));
    730 struct	ifnet *ifunit __P((const char *));
    731 
    732 struct	ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
    733 struct	ifaddr *ifa_ifwithaf __P((int));
    734 struct	ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
    735 struct	ifaddr *ifa_ifwithnet __P((struct sockaddr *));
    736 struct	ifaddr *ifa_ifwithladdr __P((struct sockaddr *));
    737 struct	ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
    738 					struct sockaddr *));
    739 struct	ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
    740 void	ifafree __P((struct ifaddr *));
    741 void	link_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
    742 
    743 void	if_clone_attach __P((struct if_clone *));
    744 void	if_clone_detach __P((struct if_clone *));
    745 
    746 int	if_clone_create __P((const char *));
    747 int	if_clone_destroy __P((const char *));
    748 
    749 int	loioctl __P((struct ifnet *, u_long, caddr_t));
    750 void	loopattach __P((int));
    751 int	looutput __P((struct ifnet *,
    752 	   struct mbuf *, struct sockaddr *, struct rtentry *));
    753 void	lortrequest __P((int, struct rtentry *, struct rt_addrinfo *));
    754 
    755 /*
    756  * These are exported because they're an easy way to tell if
    757  * an interface is going away without having to burn a flag.
    758  */
    759 int	if_nulloutput __P((struct ifnet *, struct mbuf *,
    760 	    struct sockaddr *, struct rtentry *));
    761 void	if_nullinput __P((struct ifnet *, struct mbuf *));
    762 void	if_nullstart __P((struct ifnet *));
    763 int	if_nullioctl __P((struct ifnet *, u_long, caddr_t));
    764 int	if_nullinit __P((struct ifnet *));
    765 void	if_nullstop __P((struct ifnet *, int));
    766 void	if_nullwatchdog __P((struct ifnet *));
    767 void	if_nulldrain __P((struct ifnet *));
    768 #else
    769 struct if_nameindex {
    770 	unsigned int	if_index;	/* 1, 2, ... */
    771 	char		*if_name;	/* null terminated name: "le0", ... */
    772 };
    773 
    774 #include <sys/cdefs.h>
    775 __BEGIN_DECLS
    776 unsigned int if_nametoindex __P((const char *));
    777 char *	if_indextoname __P((unsigned int, char *));
    778 struct	if_nameindex * if_nameindex __P((void));
    779 void	if_freenameindex __P((struct if_nameindex *));
    780 __END_DECLS
    781 #endif /* _KERNEL */
    782 #endif /* !_NET_IF_H_ */
    783