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