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