xref: /openbsd-src/sys/net/if.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*	$OpenBSD: if.h,v 1.128 2011/07/08 18:48:51 henning Exp $	*/
2 /*	$NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $	*/
3 
4 /*
5  * Copyright (c) 1982, 1986, 1989, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)if.h	8.1 (Berkeley) 6/10/93
33  */
34 
35 #ifndef _NET_IF_H_
36 #define _NET_IF_H_
37 
38 #include <sys/queue.h>
39 #include <sys/tree.h>
40 
41 /*
42  * Always include ALTQ glue here -- we use the ALTQ interface queue
43  * structure even when ALTQ is not configured into the kernel so that
44  * the size of struct ifnet does not changed based on the option.  The
45  * ALTQ queue structure is API-compatible with the legacy ifqueue.
46  */
47 #include <altq/if_altq.h>
48 
49 /*
50  * Structures defining a network interface, providing a packet
51  * transport mechanism (ala level 0 of the PUP protocols).
52  *
53  * Each interface accepts output datagrams of a specified maximum
54  * length, and provides higher level routines with input datagrams
55  * received from its medium.
56  *
57  * Output occurs when the routine if_output is called, with four parameters:
58  *	(*ifp->if_output)(ifp, m, dst, rt)
59  * Here m is the mbuf chain to be sent and dst is the destination address.
60  * The output routine encapsulates the supplied datagram if necessary,
61  * and then transmits it on its medium.
62  *
63  * On input, each interface unwraps the data received by it, and either
64  * places it on the input queue of an internetwork datagram routine
65  * and posts the associated software interrupt, or passes the datagram to a raw
66  * packet input routine.
67  *
68  * Routines exist for locating interfaces by their addresses
69  * or for locating an interface on a certain network, as well as more general
70  * routing and gateway routines maintaining information used to locate
71  * interfaces.  These routines live in the files if.c and route.c
72  */
73 /*  XXX fast fix for SNMP, going away soon */
74 #include <sys/time.h>
75 
76 struct mbuf;
77 struct proc;
78 struct rtentry;
79 struct socket;
80 struct ether_header;
81 struct arpcom;
82 struct rt_addrinfo;
83 struct ifnet;
84 
85 /*
86  * Structure describing a `cloning' interface.
87  */
88 struct if_clone {
89 	LIST_ENTRY(if_clone) ifc_list;	/* on list of cloners */
90 	const char *ifc_name;		/* name of device, e.g. `gif' */
91 	size_t ifc_namelen;		/* length of name */
92 
93 	int	(*ifc_create)(struct if_clone *, int);
94 	int	(*ifc_destroy)(struct ifnet *);
95 };
96 
97 #define	IF_CLONE_INITIALIZER(name, create, destroy)			\
98 	{ { 0 }, name, sizeof(name) - 1, create, destroy }
99 
100 /*
101  * Structure used to query names of interface cloners.
102  */
103 struct if_clonereq {
104 	int	ifcr_total;		/* total cloners (out) */
105 	int	ifcr_count;		/* room for this many in user buffer */
106 	char	*ifcr_buffer;		/* buffer for cloner names */
107 };
108 
109 #define MCLPOOLS	7		/* number of cluster pools */
110 
111 struct mclpool {
112 	u_int	mcl_grown;
113 	u_short	mcl_alive;
114 	u_short mcl_hwm;
115 	u_short mcl_cwm;
116 	u_short mcl_lwm;
117 };
118 
119 /*
120  * Structure defining statistics and other data kept regarding a network
121  * interface.
122  */
123 struct	if_data {
124 	/* generic interface information */
125 	u_char		ifi_type;		/* ethernet, tokenring, etc. */
126 	u_char		ifi_addrlen;		/* media address length */
127 	u_char		ifi_hdrlen;		/* media header length */
128 	u_char		ifi_link_state;		/* current link state */
129 	u_int32_t	ifi_mtu;		/* maximum transmission unit */
130 	u_int32_t	ifi_metric;		/* routing metric (external only) */
131 	u_int32_t	ifi_pad;
132 	u_int64_t	ifi_baudrate;		/* linespeed */
133 	/* volatile statistics */
134 	u_int64_t	ifi_ipackets;		/* packets received on interface */
135 	u_int64_t	ifi_ierrors;		/* input errors on interface */
136 	u_int64_t	ifi_opackets;		/* packets sent on interface */
137 	u_int64_t	ifi_oerrors;		/* output errors on interface */
138 	u_int64_t	ifi_collisions;		/* collisions on csma interfaces */
139 	u_int64_t	ifi_ibytes;		/* total number of octets received */
140 	u_int64_t	ifi_obytes;		/* total number of octets sent */
141 	u_int64_t	ifi_imcasts;		/* packets received via multicast */
142 	u_int64_t	ifi_omcasts;		/* packets sent via multicast */
143 	u_int64_t	ifi_iqdrops;		/* dropped on input, this interface */
144 	u_int64_t	ifi_noproto;		/* destined for unsupported protocol */
145 	struct	timeval ifi_lastchange;	/* last operational state change */
146 
147 	struct mclpool	ifi_mclpool[MCLPOOLS];
148 };
149 
150 #define IFQ_NQUEUES	ALTQ_IFQ_NQUEUES
151 #define IFQ_MAXPRIO	IFQ_NQUEUES - 1
152 #define IFQ_DEFPRIO	3
153 
154 /*
155  * Structure defining a queue for a network interface.
156  * XXX keep in sync with struct ifaltq.
157  */
158 struct	ifqueue {
159 	struct {
160 		struct	mbuf *head;
161 		struct	mbuf *tail;
162 	}	ifq_q[IFQ_NQUEUES];
163 	int	ifq_len;
164 	int	ifq_maxlen;
165 	int	ifq_drops;
166 	struct	timeout *ifq_congestion;
167 };
168 
169 /*
170  * Values for if_link_state.
171  */
172 #define LINK_STATE_UNKNOWN	0	/* link unknown */
173 #define LINK_STATE_INVALID	1	/* link invalid */
174 #define LINK_STATE_DOWN		2	/* link is down */
175 #define LINK_STATE_KALIVE_DOWN	3	/* keepalive reports down */
176 #define LINK_STATE_UP		4	/* link is up */
177 #define LINK_STATE_HALF_DUPLEX	5	/* link is up and half duplex */
178 #define LINK_STATE_FULL_DUPLEX	6	/* link is up and full duplex */
179 
180 #define LINK_STATE_IS_UP(_s)	\
181 		((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN)
182 
183 /*
184  * Status bit descriptions for the various interface types.
185  */
186 struct if_status_description {
187 	u_char	ifs_type;
188 	u_char	ifs_state;
189 	const char *ifs_string;
190 };
191 
192 #define LINK_STATE_DESC_MATCH(_ifs, _t, _s)				\
193 	(((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) &&		\
194 	    (_ifs)->ifs_state == (_s))
195 
196 
197 
198 #define LINK_STATE_DESCRIPTIONS {					\
199 	{ IFT_ETHER, LINK_STATE_DOWN, "no carrier" },			\
200 									\
201 	{ IFT_IEEE80211, LINK_STATE_DOWN, "no network" },		\
202 									\
203 	{ IFT_PPP, LINK_STATE_DOWN, "no carrier" },			\
204 									\
205 	{ IFT_CARP, LINK_STATE_DOWN, "backup" },			\
206 	{ IFT_CARP, LINK_STATE_UP, "master" },				\
207 	{ IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" },			\
208 	{ IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" },			\
209 									\
210 	{ 0, LINK_STATE_UP, "active" },					\
211 	{ 0, LINK_STATE_HALF_DUPLEX, "active" },			\
212 	{ 0, LINK_STATE_FULL_DUPLEX, "active" },			\
213 									\
214 	{ 0, LINK_STATE_UNKNOWN, "unknown" },				\
215 	{ 0, LINK_STATE_INVALID, "invalid" },				\
216 	{ 0, LINK_STATE_DOWN, "down" },					\
217 	{ 0, LINK_STATE_KALIVE_DOWN, "keepalive down" },		\
218 	{ 0, 0, NULL }							\
219 }
220 
221 /*
222  * Structure defining a queue for a network interface.
223  *
224  * (Would like to call this struct ``if'', but C isn't PL/1.)
225  */
226 TAILQ_HEAD(ifnet_head, ifnet);		/* the actual queue head */
227 
228 /*
229  * Length of interface external name, including terminating '\0'.
230  * Note: this is the same size as a generic device's external name.
231  */
232 #define	IFNAMSIZ	16
233 #define	IF_NAMESIZE	IFNAMSIZ
234 
235 /*
236  * Length of interface description, including terminating '\0'.
237  */
238 #define	IFDESCRSIZE	64
239 
240 struct ifnet {				/* and the entries */
241 	void	*if_softc;		/* lower-level data for this if */
242 	TAILQ_ENTRY(ifnet) if_list;	/* all struct ifnets are chained */
243 	TAILQ_ENTRY(ifnet) if_txlist;	/* list of ifnets ready to tx */
244 	TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
245 	TAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if */
246 	struct hook_desc_head *if_addrhooks; /* address change callbacks */
247 	struct hook_desc_head *if_linkstatehooks; /* link change callbacks */
248 	struct hook_desc_head *if_detachhooks; /* detach callbacks */
249 	char	if_xname[IFNAMSIZ];	/* external name (name + unit) */
250 	int	if_pcount;		/* number of promiscuous listeners */
251 	caddr_t	if_bpf;			/* packet filter structure */
252 	caddr_t	if_bridge;		/* bridge structure */
253 	caddr_t	if_tp;			/* used by trunk ports */
254 	caddr_t	if_pf_kif;		/* pf interface abstraction */
255 	union {
256 		caddr_t	carp_s;		/* carp structure (used by !carp ifs) */
257 		struct ifnet *carp_d;	/* ptr to carpdev (used by carp ifs) */
258 	} if_carp_ptr;
259 #define if_carp		if_carp_ptr.carp_s
260 #define if_carpdev	if_carp_ptr.carp_d
261 	u_short	if_index;		/* numeric abbreviation for this if */
262 	short	if_timer;		/* time 'til if_watchdog called */
263 	short	if_flags;		/* up/down, broadcast, etc. */
264 	int	if_xflags;		/* extra softnet flags */
265 	struct	if_data if_data;	/* stats and other data about if */
266 	u_int32_t if_hardmtu;		/* maximum MTU device supports */
267 	int	if_capabilities;	/* interface capabilities */
268 	u_int	if_rdomain;		/* routing instance */
269 	char	if_description[IFDESCRSIZE]; /* interface description */
270 	u_short	if_rtlabelid;		/* next route label */
271 	u_int8_t if_priority;
272 
273 	/* procedure handles */
274 					/* output routine (enqueue) */
275 	int	(*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
276 		     struct rtentry *);
277 
278 					/* link level output function */
279 	int	(*if_ll_output)(struct ifnet *, struct mbuf *,
280 		    struct sockaddr *, struct rtentry *);
281 					/* initiate output routine */
282 	void	(*if_start)(struct ifnet *);
283 					/* ioctl routine */
284 	int	(*if_ioctl)(struct ifnet *, u_long, caddr_t);
285 					/* stop routine */
286 	int	(*if_stop)(struct ifnet *, int);
287 					/* timer routine */
288 	void	(*if_watchdog)(struct ifnet *);
289 	int	(*if_wol)(struct ifnet *, int);
290 	struct	ifaltq if_snd;		/* output queue (includes altq) */
291 	struct sockaddr_dl *if_sadl;	/* pointer to our sockaddr_dl */
292 
293 	void	*if_afdata[AF_MAX];
294 };
295 #define	if_mtu		if_data.ifi_mtu
296 #define	if_type		if_data.ifi_type
297 #define	if_addrlen	if_data.ifi_addrlen
298 #define	if_hdrlen	if_data.ifi_hdrlen
299 #define	if_metric	if_data.ifi_metric
300 #define	if_link_state	if_data.ifi_link_state
301 #define	if_baudrate	if_data.ifi_baudrate
302 #define	if_ipackets	if_data.ifi_ipackets
303 #define	if_ierrors	if_data.ifi_ierrors
304 #define	if_opackets	if_data.ifi_opackets
305 #define	if_oerrors	if_data.ifi_oerrors
306 #define	if_collisions	if_data.ifi_collisions
307 #define	if_ibytes	if_data.ifi_ibytes
308 #define	if_obytes	if_data.ifi_obytes
309 #define	if_imcasts	if_data.ifi_imcasts
310 #define	if_omcasts	if_data.ifi_omcasts
311 #define	if_iqdrops	if_data.ifi_iqdrops
312 #define	if_noproto	if_data.ifi_noproto
313 #define	if_lastchange	if_data.ifi_lastchange
314 
315 #define	IFF_UP		0x1		/* interface is up */
316 #define	IFF_BROADCAST	0x2		/* broadcast address valid */
317 #define	IFF_DEBUG	0x4		/* turn on debugging */
318 #define	IFF_LOOPBACK	0x8		/* is a loopback net */
319 #define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
320 #define	IFF_NOTRAILERS	0x20		/* avoid use of trailers */
321 #define	IFF_RUNNING	0x40		/* resources allocated */
322 #define	IFF_NOARP	0x80		/* no address resolution protocol */
323 #define	IFF_PROMISC	0x100		/* receive all packets */
324 #define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
325 #define	IFF_OACTIVE	0x400		/* transmission in progress */
326 #define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
327 #define	IFF_LINK0	0x1000		/* per link layer defined bit */
328 #define	IFF_LINK1	0x2000		/* per link layer defined bit */
329 #define	IFF_LINK2	0x4000		/* per link layer defined bit */
330 #define	IFF_MULTICAST	0x8000		/* supports multicast */
331 
332 /* flags set internally only: */
333 #define	IFF_CANTCHANGE \
334 	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
335 	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
336 
337 #define IFXF_TXREADY		0x1		/* interface is ready to tx */
338 #define	IFXF_NOINET6		0x2		/* don't do inet6 */
339 #define	IFXF_INET6_PRIVACY	0x4		/* autoconf privacy extension */
340 #define	IFXF_MPLS		0x8		/* supports MPLS */
341 #define	IFXF_WOL		0x10		/* wake on lan enabled */
342 
343 #define	IFXF_CANTCHANGE \
344 	(IFXF_TXREADY)
345 
346 /*
347  * Some convenience macros used for setting ifi_baudrate.
348  */
349 #define	IF_Kbps(x)	((x) * 1000ULL)			/* kilobits/sec. */
350 #define	IF_Mbps(x)	(IF_Kbps((x) * 1000ULL))	/* megabits/sec. */
351 #define	IF_Gbps(x)	(IF_Mbps((x) * 1000ULL))	/* gigabits/sec. */
352 
353 /* Capabilities that interfaces can advertise. */
354 #define	IFCAP_CSUM_IPv4		0x00000001	/* can do IPv4 header csum */
355 #define	IFCAP_CSUM_TCPv4	0x00000002	/* can do IPv4/TCP csum */
356 #define	IFCAP_CSUM_UDPv4	0x00000004	/* can do IPv4/UDP csum */
357 #define	IFCAP_IPSEC		0x00000008	/* can do IPsec */
358 #define	IFCAP_VLAN_MTU		0x00000010	/* VLAN-compatible MTU */
359 #define	IFCAP_VLAN_HWTAGGING	0x00000020	/* hardware VLAN tag support */
360 #define	IFCAP_IPCOMP		0x00000040	/* can do IPcomp */
361 #define	IFCAP_CSUM_TCPv6	0x00000080	/* can do IPv6/TCP checksums */
362 #define	IFCAP_CSUM_UDPv6	0x00000100	/* can do IPv6/UDP checksums */
363 #define	IFCAP_CSUM_TCPv4_Rx	0x00000200	/* can do IPv4/TCP (Rx only) */
364 #define	IFCAP_CSUM_UDPv4_Rx	0x00000400	/* can do IPv4/UDP (Rx only) */
365 #define	IFCAP_WOL		0x00008000	/* can do wake on lan */
366 
367 /*
368  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
369  * input routines have queues of messages stored on ifqueue structures
370  * (defined above).  Entries are added to and deleted from these structures
371  * by these macros, which should be called with ipl raised to splnet().
372  */
373 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
374 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
375 #define	IF_ENQUEUE(ifq, m)						\
376 do {									\
377 	(m)->m_nextpkt = NULL;						\
378 	if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL)		\
379 		(ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = m;		\
380 	else								\
381 		(ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail->m_nextpkt = m; \
382 	(ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = m;			\
383 	(ifq)->ifq_len++;						\
384 } while (/* CONSTCOND */0)
385 #define	IF_PREPEND(ifq, m)						\
386 do {									\
387 	(m)->m_nextpkt = (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head;	\
388 	if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL)		\
389 		(ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = (m);		\
390 	(ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = (m);			\
391 	(ifq)->ifq_len++;						\
392 } while (/* CONSTCOND */0)
393 
394 #define	IF_POLL(ifq, m)							\
395 do {									\
396 	int	if_dequeue_prio = IFQ_MAXPRIO;				\
397 	do {								\
398 		(m) = (ifq)->ifq_q[if_dequeue_prio].head;		\
399 	} while (!(m) && --if_dequeue_prio >= 0); 			\
400 } while (/* CONSTCOND */0)
401 
402 #define	IF_DEQUEUE(ifq, m)						\
403 do {									\
404 	int	if_dequeue_prio = IFQ_MAXPRIO;				\
405 	do {								\
406 		(m) = (ifq)->ifq_q[if_dequeue_prio].head;		\
407 		if (m) {						\
408 			if (((ifq)->ifq_q[if_dequeue_prio].head =	\
409 			    (m)->m_nextpkt) == NULL)			\
410 				(ifq)->ifq_q[if_dequeue_prio].tail = NULL; \
411 			(m)->m_nextpkt = NULL;				\
412 			(ifq)->ifq_len--;				\
413 		}							\
414 	} while (!(m) && --if_dequeue_prio >= 0);			\
415 } while (/* CONSTCOND */0)
416 
417 #define	IF_INPUT_ENQUEUE(ifq, m)					\
418 do {									\
419 	if (IF_QFULL(ifq)) {						\
420 		IF_DROP(ifq);						\
421 		m_freem(m);						\
422 		if (!(ifq)->ifq_congestion)				\
423 			if_congestion(ifq);				\
424 	} else								\
425 		IF_ENQUEUE(ifq, m);					\
426 } while (/* CONSTCOND */0)
427 
428 #define	IF_PURGE(ifq)							\
429 do {									\
430 	struct mbuf *__m0;						\
431 									\
432 	for (;;) {							\
433 		IF_DEQUEUE((ifq), __m0);				\
434 		if (__m0 == NULL)					\
435 			break;						\
436 		else							\
437 			m_freem(__m0);					\
438 	}								\
439 } while (/* CONSTCOND */0)
440 #define	IF_LEN(ifq)		((ifq)->ifq_len)
441 #define	IF_IS_EMPTY(ifq)	((ifq)->ifq_len == 0)
442 
443 #define	IFQ_MAXLEN	256
444 #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
445 
446 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
447 #define IFQCTL_LEN 1
448 #define IFQCTL_MAXLEN 2
449 #define IFQCTL_DROPS 3
450 #define IFQCTL_CONGESTION 4
451 #define IFQCTL_MAXID 5
452 
453 /* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */
454 #define CTL_IFQ_NAMES  { \
455 	{ 0, 0 }, \
456 	{ "len", CTLTYPE_INT }, \
457 	{ "maxlen", CTLTYPE_INT }, \
458 	{ "drops", CTLTYPE_INT }, \
459 	{ "congestion", CTLTYPE_INT }, \
460 }
461 
462 /*
463  * The ifaddr structure contains information about one address
464  * of an interface.  They are maintained by the different address families,
465  * are allocated and attached when an address is set, and are linked
466  * together so all addresses for an interface can be located.
467  */
468 struct ifaddr {
469 	struct	sockaddr *ifa_addr;	/* address of interface */
470 	struct	sockaddr *ifa_dstaddr;	/* other end of p-to-p link */
471 #define	ifa_broadaddr	ifa_dstaddr	/* broadcast address interface */
472 	struct	sockaddr *ifa_netmask;	/* used to determine subnet */
473 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
474 	TAILQ_ENTRY(ifaddr) ifa_list;	/* list of addresses for interface */
475 					/* check or clean routes (+ or -)'d */
476 	void	(*ifa_rtrequest)(int, struct rtentry *, struct rt_addrinfo *);
477 	u_int	ifa_flags;		/* mostly rt_flags for cloning */
478 	u_int	ifa_refcnt;		/* count of references */
479 	int	ifa_metric;		/* cost of going out this interface */
480 };
481 #define	IFA_ROUTE	RTF_UP		/* route installed */
482 
483 struct ifaddr_item {
484 	RB_ENTRY(ifaddr_item)	 ifai_entry;
485 	struct sockaddr		*ifai_addr;
486 	struct ifaddr		*ifai_ifa;
487 	struct ifaddr_item	*ifai_next;
488 	u_int			 ifai_rdomain;
489 };
490 
491 /*
492  * Message format for use in obtaining information about interfaces
493  * from sysctl and the routing socket.
494  */
495 struct if_msghdr {
496 	u_short	ifm_msglen;	/* to skip over non-understood messages */
497 	u_char	ifm_version;	/* future binary compatibility */
498 	u_char	ifm_type;	/* message type */
499 	u_short ifm_hdrlen;	/* sizeof(if_msghdr) to skip over the header */
500 	u_short	ifm_index;	/* index for associated ifp */
501 	u_short	ifm_tableid;	/* routing table id */
502 	u_char	ifm_pad1;
503 	u_char	ifm_pad2;
504 	int	ifm_addrs;	/* like rtm_addrs */
505 	int	ifm_flags;	/* value of if_flags */
506 	int	ifm_xflags;
507 	struct	if_data ifm_data;/* statistics and other data about if */
508 };
509 
510 /*
511  * Message format for use in obtaining information about interface addresses
512  * from sysctl and the routing socket.
513  */
514 struct ifa_msghdr {
515 	u_short	ifam_msglen;	/* to skip over non-understood messages */
516 	u_char	ifam_version;	/* future binary compatibility */
517 	u_char	ifam_type;	/* message type */
518 	u_short ifam_hdrlen;	/* sizeof(ifa_msghdr) to skip over the header */
519 	u_short	ifam_index;	/* index for associated ifp */
520 	u_short	ifam_tableid;	/* routing table id */
521 	u_char	ifam_pad1;
522 	u_char	ifam_pad2;
523 	int	ifam_addrs;	/* like rtm_addrs */
524 	int	ifam_flags;	/* value of ifa_flags */
525 	int	ifam_metric;	/* value of ifa_metric */
526 };
527 
528 
529 /*
530  * Message format announcing the arrival or departure of a network interface.
531  */
532 struct if_announcemsghdr {
533 	u_short	ifan_msglen;	/* to skip over non-understood messages */
534 	u_char	ifan_version;	/* future binary compatibility */
535 	u_char	ifan_type;	/* message type */
536 	u_short ifan_hdrlen;	/* sizeof(ifa_msghdr) to skip over the header */
537 	u_short	ifan_index;	/* index for associated ifp */
538 	u_short	ifan_what;	/* what type of announcement */
539 	char	ifan_name[IFNAMSIZ];	/* if name, e.g. "en0" */
540 };
541 
542 #define IFAN_ARRIVAL	0	/* interface arrival */
543 #define IFAN_DEPARTURE	1	/* interface departure */
544 
545 /*
546  * interface groups
547  */
548 
549 #define	IFG_ALL		"all"		/* group contains all interfaces */
550 #define	IFG_EGRESS	"egress"	/* if(s) default route(s) point to */
551 
552 struct ifg_group {
553 	char				 ifg_group[IFNAMSIZ];
554 	u_int				 ifg_refcnt;
555 	caddr_t				 ifg_pf_kif;
556 	int				 ifg_carp_demoted;
557 	TAILQ_HEAD(, ifg_member)	 ifg_members;
558 	TAILQ_ENTRY(ifg_group)		 ifg_next;
559 };
560 
561 struct ifg_member {
562 	TAILQ_ENTRY(ifg_member)	 ifgm_next;
563 	struct ifnet		*ifgm_ifp;
564 };
565 
566 struct ifg_list {
567 	struct ifg_group	*ifgl_group;
568 	TAILQ_ENTRY(ifg_list)	 ifgl_next;
569 };
570 
571 struct ifg_req {
572 	union {
573 		char			 ifgrqu_group[IFNAMSIZ];
574 		char			 ifgrqu_member[IFNAMSIZ];
575 	} ifgrq_ifgrqu;
576 #define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
577 #define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
578 };
579 
580 struct ifg_attrib {
581 	int	ifg_carp_demoted;
582 };
583 
584 /*
585  * Used to lookup groups for an interface
586  */
587 struct ifgroupreq {
588 	char	ifgr_name[IFNAMSIZ];
589 	u_int	ifgr_len;
590 	union {
591 		char			 ifgru_group[IFNAMSIZ];
592 		struct	ifg_req		*ifgru_groups;
593 		struct	ifg_attrib	 ifgru_attrib;
594 	} ifgr_ifgru;
595 #define ifgr_group	ifgr_ifgru.ifgru_group
596 #define ifgr_groups	ifgr_ifgru.ifgru_groups
597 #define ifgr_attrib	ifgr_ifgru.ifgru_attrib
598 };
599 
600 /*
601  * Interface request structure used for socket
602  * ioctl's.  All interface ioctl's must have parameter
603  * definitions which begin with ifr_name.  The
604  * remainder may be interface specific.
605  */
606 struct	ifreq {
607 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
608 	union {
609 		struct	sockaddr ifru_addr;
610 		struct	sockaddr ifru_dstaddr;
611 		struct	sockaddr ifru_broadaddr;
612 		short	ifru_flags;
613 		int	ifru_metric;
614 		caddr_t	ifru_data;
615 	} ifr_ifru;
616 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
617 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
618 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
619 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
620 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
621 #define	ifr_mtu		ifr_ifru.ifru_metric	/* mtu (overload) */
622 #define	ifr_media	ifr_ifru.ifru_metric	/* media options (overload) */
623 #define	ifr_rdomainid	ifr_ifru.ifru_metric	/* VRF instance (overload) */
624 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
625 };
626 
627 struct ifaliasreq {
628 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
629 	struct	sockaddr ifra_addr;
630 	struct	sockaddr ifra_dstaddr;
631 #define	ifra_broadaddr	ifra_dstaddr
632 	struct	sockaddr ifra_mask;
633 };
634 
635 struct ifmediareq {
636 	char	ifm_name[IFNAMSIZ];		/* if name, e.g. "en0" */
637 	int	ifm_current;			/* current media options */
638 	int	ifm_mask;			/* don't care mask */
639 	int	ifm_status;			/* media status */
640 	int	ifm_active;			/* active options */
641 	int	ifm_count;			/* # entries in ifm_ulist
642 							array */
643 	int	*ifm_ulist;			/* media words */
644 };
645 
646 struct ifkalivereq {
647 	char	ikar_name[IFNAMSIZ];		/* if name, e.g. "en0" */
648 	int	ikar_timeo;
649 	int	ikar_cnt;
650 };
651 
652 /*
653  * Structure used in SIOCGIFCONF request.
654  * Used to retrieve interface configuration
655  * for machine (useful for programs which
656  * must know all networks accessible).
657  */
658 struct	ifconf {
659 	int	ifc_len;		/* size of associated buffer */
660 	union {
661 		caddr_t	ifcu_buf;
662 		struct	ifreq *ifcu_req;
663 	} ifc_ifcu;
664 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
665 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
666 };
667 
668 /*
669  * Structure for SIOC[AGD]LIFADDR
670  */
671 struct if_laddrreq {
672 	char iflr_name[IFNAMSIZ];
673 	unsigned int flags;
674 #define IFLR_PREFIX	0x8000	/* in: prefix given  out: kernel fills id */
675 	unsigned int prefixlen;		/* in/out */
676 	struct sockaddr_storage addr;	/* in/out */
677 	struct sockaddr_storage dstaddr; /* out */
678 };
679 
680 struct if_nameindex {
681 	unsigned int	if_index;
682 	char		*if_name;
683 };
684 
685 #ifndef _KERNEL
686 __BEGIN_DECLS
687 unsigned int if_nametoindex(const char *);
688 char	*if_indextoname(unsigned int, char *);
689 struct	if_nameindex *if_nameindex(void);
690 void	if_freenameindex(struct if_nameindex *);
691 __END_DECLS
692 #endif
693 
694 #include <net/if_arp.h>
695 
696 #ifdef _KERNEL
697 #define	IFAFREE(ifa) \
698 do { \
699 	if ((ifa)->ifa_refcnt <= 0) \
700 		ifafree(ifa); \
701 	else \
702 		(ifa)->ifa_refcnt--; \
703 } while (/* CONSTCOND */0)
704 
705 #ifdef ALTQ
706 
707 #define	IFQ_ENQUEUE(ifq, m, pattr, err)					\
708 do {									\
709 	if (ALTQ_IS_ENABLED((ifq))) {					\
710 		m->m_pkthdr.pf.prio = IFQ_MAXPRIO;			\
711 		ALTQ_ENQUEUE((ifq), (m), (pattr), (err));		\
712 	} else {							\
713 		if (IF_QFULL((ifq))) {					\
714 			m_freem((m));					\
715 			(err) = ENOBUFS;				\
716 		} else {						\
717 			IF_ENQUEUE((ifq), (m));				\
718 			(err) = 0;					\
719 		}							\
720 	}								\
721 	if ((err))							\
722 		(ifq)->ifq_drops++;					\
723 } while (/* CONSTCOND */0)
724 
725 #define	IFQ_DEQUEUE(ifq, m)						\
726 do {									\
727 	if (TBR_IS_ENABLED((ifq)))					\
728 		(m) = tbr_dequeue((ifq), ALTDQ_REMOVE);			\
729 	else if (ALTQ_IS_ENABLED((ifq)))				\
730 		ALTQ_DEQUEUE((ifq), (m));				\
731 	else								\
732 		IF_DEQUEUE((ifq), (m));					\
733 } while (/* CONSTCOND */0)
734 
735 #define	IFQ_POLL(ifq, m)						\
736 do {									\
737 	if (TBR_IS_ENABLED((ifq)))					\
738 		(m) = tbr_dequeue((ifq), ALTDQ_POLL);			\
739 	else if (ALTQ_IS_ENABLED((ifq)))				\
740 		ALTQ_POLL((ifq), (m));					\
741 	else								\
742 		IF_POLL((ifq), (m));					\
743 } while (/* CONSTCOND */0)
744 
745 #define	IFQ_PURGE(ifq)							\
746 do {									\
747 	if (ALTQ_IS_ENABLED((ifq)))					\
748 		ALTQ_PURGE((ifq));					\
749 	else								\
750 		IF_PURGE((ifq));					\
751 } while (/* CONSTCOND */0)
752 
753 #define	IFQ_SET_READY(ifq)						\
754 do {									\
755 	((ifq)->altq_flags |= ALTQF_READY);				\
756 } while (/* CONSTCOND */0)
757 
758 #else /* !ALTQ */
759 
760 #define	IFQ_ENQUEUE(ifq, m, pattr, err)					\
761 do {									\
762 	if (IF_QFULL((ifq))) {						\
763 		m_freem((m));						\
764 		(err) = ENOBUFS;					\
765 	} else {							\
766 		IF_ENQUEUE((ifq), (m));					\
767 		(err) = 0;						\
768 	}								\
769 	if ((err))							\
770 		(ifq)->ifq_drops++;					\
771 } while (/* CONSTCOND */0)
772 
773 #define	IFQ_DEQUEUE(ifq, m)	IF_DEQUEUE((ifq), (m))
774 
775 #define	IFQ_POLL(ifq, m)	IF_POLL((ifq), (m))
776 
777 #define	IFQ_PURGE(ifq)		IF_PURGE((ifq))
778 
779 #define	IFQ_SET_READY(ifq)	/* nothing */
780 
781 #endif /* ALTQ */
782 
783 #define	IFQ_LEN(ifq)			IF_LEN(ifq)
784 #define	IFQ_IS_EMPTY(ifq)		((ifq)->ifq_len == 0)
785 #define	IFQ_INC_LEN(ifq)		((ifq)->ifq_len++)
786 #define	IFQ_DEC_LEN(ifq)		(--(ifq)->ifq_len)
787 #define	IFQ_INC_DROPS(ifq)		((ifq)->ifq_drops++)
788 #define	IFQ_SET_MAXLEN(ifq, len)	((ifq)->ifq_maxlen = (len))
789 
790 /* default interface priorities */
791 #define IF_WIRED_DEFAULT_PRIORITY 0
792 #define IF_WIRELESS_DEFAULT_PRIORITY 4
793 
794 extern int ifqmaxlen;
795 extern struct ifnet_head ifnet;
796 extern struct ifnet **ifindex2ifnet;
797 extern struct ifnet *lo0ifp;
798 extern int if_indexlim;
799 
800 #define	ether_input_mbuf(ifp, m)        ether_input((ifp), NULL, (m))
801 
802 void	ether_ifattach(struct ifnet *);
803 void	ether_ifdetach(struct ifnet *);
804 int	ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t);
805 void	ether_input(struct ifnet *, struct ether_header *, struct mbuf *);
806 int	ether_output(struct ifnet *,
807 	    struct mbuf *, struct sockaddr *, struct rtentry *);
808 char	*ether_sprintf(u_char *);
809 
810 void	if_alloc_sadl(struct ifnet *);
811 void	if_free_sadl(struct ifnet *);
812 void	if_attach(struct ifnet *);
813 void	if_attachdomain(void);
814 void	if_attachtail(struct ifnet *);
815 void	if_attachhead(struct ifnet *);
816 void	if_detach(struct ifnet *);
817 void	if_down(struct ifnet *);
818 void	if_downall(void);
819 void	if_link_state_change(struct ifnet *);
820 void	if_slowtimo(void *);
821 void	if_up(struct ifnet *);
822 int	ifconf(u_long, caddr_t);
823 void	ifinit(void);
824 int	ifioctl(struct socket *, u_long, caddr_t, struct proc *);
825 int	ifpromisc(struct ifnet *, int);
826 struct	ifg_group *if_creategroup(const char *);
827 int	if_addgroup(struct ifnet *, const char *);
828 int	if_delgroup(struct ifnet *, const char *);
829 void	if_group_routechange(struct sockaddr *, struct sockaddr *);
830 struct	ifnet *ifunit(const char *);
831 void	if_start(struct ifnet *);
832 void	ifnewlladdr(struct ifnet *);
833 
834 struct	ifaddr *ifa_ifwithaddr(struct sockaddr *, u_int);
835 struct	ifaddr *ifa_ifwithaf(int, u_int);
836 struct	ifaddr *ifa_ifwithdstaddr(struct sockaddr *, u_int);
837 struct	ifaddr *ifa_ifwithnet(struct sockaddr *, u_int);
838 struct	ifaddr *ifa_ifwithroute(int, struct sockaddr *,
839 					struct sockaddr *, u_int);
840 struct	ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
841 void	ifafree(struct ifaddr *);
842 void	link_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
843 
844 void	if_clone_attach(struct if_clone *);
845 void	if_clone_detach(struct if_clone *);
846 
847 int	if_clone_create(const char *);
848 int	if_clone_destroy(const char *);
849 
850 void	if_congestion(struct ifqueue *);
851 int     sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t,
852 	    struct ifqueue *);
853 
854 int	loioctl(struct ifnet *, u_long, caddr_t);
855 void	loopattach(int);
856 int	looutput(struct ifnet *,
857 	    struct mbuf *, struct sockaddr *, struct rtentry *);
858 void	lortrequest(int, struct rtentry *, struct rt_addrinfo *);
859 void	ifa_add(struct ifnet *, struct ifaddr *);
860 void	ifa_del(struct ifnet *, struct ifaddr *);
861 void	ifa_update_broadaddr(struct ifnet *, struct ifaddr *,
862 	    struct sockaddr *);
863 #endif /* _KERNEL */
864 #endif /* _NET_IF_H_ */
865