xref: /illumos-gate/usr/src/boot/include/net/if.h (revision 199767f8)
1*199767f8SToomas Soome /*-
2*199767f8SToomas Soome  * Copyright (c) 1982, 1986, 1989, 1993
3*199767f8SToomas Soome  *	The Regents of the University of California.  All rights reserved.
4*199767f8SToomas Soome  *
5*199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
6*199767f8SToomas Soome  * modification, are permitted provided that the following conditions
7*199767f8SToomas Soome  * are met:
8*199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
9*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
10*199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
11*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
12*199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
13*199767f8SToomas Soome  * 4. Neither the name of the University nor the names of its contributors
14*199767f8SToomas Soome  *    may be used to endorse or promote products derived from this software
15*199767f8SToomas Soome  *    without specific prior written permission.
16*199767f8SToomas Soome  *
27*199767f8SToomas Soome  * SUCH DAMAGE.
28*199767f8SToomas Soome  *
29*199767f8SToomas Soome  *	@(#)if.h	8.1 (Berkeley) 6/10/93
30*199767f8SToomas Soome  * $FreeBSD$
31*199767f8SToomas Soome  */
32*199767f8SToomas Soome 
33*199767f8SToomas Soome #ifndef _NET_IF_H_
34*199767f8SToomas Soome #define	_NET_IF_H_
35*199767f8SToomas Soome 
36*199767f8SToomas Soome #include <sys/cdefs.h>
37*199767f8SToomas Soome 
38*199767f8SToomas Soome #if __BSD_VISIBLE
39*199767f8SToomas Soome /*
40*199767f8SToomas Soome  * <net/if.h> does not depend on <sys/time.h> on most other systems.  This
41*199767f8SToomas Soome  * helps userland compatibility.  (struct timeval ifi_lastchange)
42*199767f8SToomas Soome  * The same holds for <sys/socket.h>.  (struct sockaddr ifru_addr)
43*199767f8SToomas Soome  */
44*199767f8SToomas Soome #ifndef _KERNEL
45*199767f8SToomas Soome #include <sys/time.h>
46*199767f8SToomas Soome #include <sys/socket.h>
47*199767f8SToomas Soome #endif
48*199767f8SToomas Soome #endif
49*199767f8SToomas Soome 
50*199767f8SToomas Soome /*
51*199767f8SToomas Soome  * Length of interface external name, including terminating '\0'.
52*199767f8SToomas Soome  * Note: this is the same size as a generic device's external name.
53*199767f8SToomas Soome  */
54*199767f8SToomas Soome #define		IF_NAMESIZE	16
55*199767f8SToomas Soome #if __BSD_VISIBLE
56*199767f8SToomas Soome #define		IFNAMSIZ	IF_NAMESIZE
57*199767f8SToomas Soome #define		IF_MAXUNIT	0x7fff	/* historical value */
58*199767f8SToomas Soome #endif
59*199767f8SToomas Soome #if __BSD_VISIBLE
60*199767f8SToomas Soome 
61*199767f8SToomas Soome /*
62*199767f8SToomas Soome  * Structure used to query names of interface cloners.
63*199767f8SToomas Soome  */
64*199767f8SToomas Soome 
65*199767f8SToomas Soome struct if_clonereq {
66*199767f8SToomas Soome 	int	ifcr_total;		/* total cloners (out) */
67*199767f8SToomas Soome 	int	ifcr_count;		/* room for this many in user buffer */
68*199767f8SToomas Soome 	char	*ifcr_buffer;		/* buffer for cloner names */
69*199767f8SToomas Soome };
70*199767f8SToomas Soome 
71*199767f8SToomas Soome /*
72*199767f8SToomas Soome  * Structure describing information about an interface
73*199767f8SToomas Soome  * which may be of interest to management entities.
74*199767f8SToomas Soome  */
75*199767f8SToomas Soome struct if_data {
76*199767f8SToomas Soome 	/* generic interface information */
77*199767f8SToomas Soome 	uint8_t	ifi_type;		/* ethernet, tokenring, etc */
78*199767f8SToomas Soome 	uint8_t	ifi_physical;		/* e.g., AUI, Thinnet, 10base-T, etc */
79*199767f8SToomas Soome 	uint8_t	ifi_addrlen;		/* media address length */
80*199767f8SToomas Soome 	uint8_t	ifi_hdrlen;		/* media header length */
81*199767f8SToomas Soome 	uint8_t	ifi_link_state;		/* current link state */
82*199767f8SToomas Soome 	uint8_t	ifi_vhid;		/* carp vhid */
83*199767f8SToomas Soome 	uint16_t	ifi_datalen;	/* length of this data struct */
84*199767f8SToomas Soome 	uint32_t	ifi_mtu;	/* maximum transmission unit */
85*199767f8SToomas Soome 	uint32_t	ifi_metric;	/* routing metric (external only) */
86*199767f8SToomas Soome 	uint64_t	ifi_baudrate;	/* linespeed */
87*199767f8SToomas Soome 	/* volatile statistics */
88*199767f8SToomas Soome 	uint64_t	ifi_ipackets;	/* packets received on interface */
89*199767f8SToomas Soome 	uint64_t	ifi_ierrors;	/* input errors on interface */
90*199767f8SToomas Soome 	uint64_t	ifi_opackets;	/* packets sent on interface */
91*199767f8SToomas Soome 	uint64_t	ifi_oerrors;	/* output errors on interface */
92*199767f8SToomas Soome 	uint64_t	ifi_collisions;	/* collisions on csma interfaces */
93*199767f8SToomas Soome 	uint64_t	ifi_ibytes;	/* total number of octets received */
94*199767f8SToomas Soome 	uint64_t	ifi_obytes;	/* total number of octets sent */
95*199767f8SToomas Soome 	uint64_t	ifi_imcasts;	/* packets received via multicast */
96*199767f8SToomas Soome 	uint64_t	ifi_omcasts;	/* packets sent via multicast */
97*199767f8SToomas Soome 	uint64_t	ifi_iqdrops;	/* dropped on input */
98*199767f8SToomas Soome 	uint64_t	ifi_oqdrops;	/* dropped on output */
99*199767f8SToomas Soome 	uint64_t	ifi_noproto;	/* destined for unsupported protocol */
100*199767f8SToomas Soome 	uint64_t	ifi_hwassist;	/* HW offload capabilities, see IFCAP */
101*199767f8SToomas Soome 
102*199767f8SToomas Soome 	/* Unions are here to make sizes MI. */
103*199767f8SToomas Soome 	union {				/* uptime at attach or stat reset */
104*199767f8SToomas Soome 		time_t		tt;
105*199767f8SToomas Soome 		uint64_t	ph;
106*199767f8SToomas Soome 	} __ifi_epoch;
107*199767f8SToomas Soome #define	ifi_epoch	__ifi_epoch.tt
108*199767f8SToomas Soome 	union {				/* time of last administrative change */
109*199767f8SToomas Soome 		struct timeval	tv;
110*199767f8SToomas Soome 		struct {
111*199767f8SToomas Soome 			uint64_t ph1;
112*199767f8SToomas Soome 			uint64_t ph2;
113*199767f8SToomas Soome 		} ph;
114*199767f8SToomas Soome 	} __ifi_lastchange;
115*199767f8SToomas Soome #define	ifi_lastchange	__ifi_lastchange.tv
116*199767f8SToomas Soome };
117*199767f8SToomas Soome 
118*199767f8SToomas Soome /*-
119*199767f8SToomas Soome  * Interface flags are of two types: network stack owned flags, and driver
120*199767f8SToomas Soome  * owned flags.  Historically, these values were stored in the same ifnet
121*199767f8SToomas Soome  * flags field, but with the advent of fine-grained locking, they have been
122*199767f8SToomas Soome  * broken out such that the network stack is responsible for synchronizing
123*199767f8SToomas Soome  * the stack-owned fields, and the device driver the device-owned fields.
124*199767f8SToomas Soome  * Both halves can perform lockless reads of the other half's field, subject
125*199767f8SToomas Soome  * to accepting the involved races.
126*199767f8SToomas Soome  *
127*199767f8SToomas Soome  * Both sets of flags come from the same number space, and should not be
128*199767f8SToomas Soome  * permitted to conflict, as they are exposed to user space via a single
129*199767f8SToomas Soome  * field.
130*199767f8SToomas Soome  *
131*199767f8SToomas Soome  * The following symbols identify read and write requirements for fields:
132*199767f8SToomas Soome  *
133*199767f8SToomas Soome  * (i) if_flags field set by device driver before attach, read-only there
134*199767f8SToomas Soome  *     after.
135*199767f8SToomas Soome  * (n) if_flags field written only by the network stack, read by either the
136*199767f8SToomas Soome  *     stack or driver.
137*199767f8SToomas Soome  * (d) if_drv_flags field written only by the device driver, read by either
138*199767f8SToomas Soome  *     the stack or driver.
139*199767f8SToomas Soome  */
140*199767f8SToomas Soome #define	IFF_UP		0x1		/* (n) interface is up */
141*199767f8SToomas Soome #define	IFF_BROADCAST	0x2		/* (i) broadcast address valid */
142*199767f8SToomas Soome #define	IFF_DEBUG	0x4		/* (n) turn on debugging */
143*199767f8SToomas Soome #define	IFF_LOOPBACK	0x8		/* (i) is a loopback net */
144*199767f8SToomas Soome #define	IFF_POINTOPOINT	0x10		/* (i) is a point-to-point link */
145*199767f8SToomas Soome /*			0x20		   was IFF_SMART */
146*199767f8SToomas Soome #define	IFF_DRV_RUNNING	0x40		/* (d) resources allocated */
147*199767f8SToomas Soome #define	IFF_NOARP	0x80		/* (n) no address resolution protocol */
148*199767f8SToomas Soome #define	IFF_PROMISC	0x100		/* (n) receive all packets */
149*199767f8SToomas Soome #define	IFF_ALLMULTI	0x200		/* (n) receive all multicast packets */
150*199767f8SToomas Soome #define	IFF_DRV_OACTIVE	0x400		/* (d) tx hardware queue is full */
151*199767f8SToomas Soome #define	IFF_SIMPLEX	0x800		/* (i) can't hear own transmissions */
152*199767f8SToomas Soome #define	IFF_LINK0	0x1000		/* per link layer defined bit */
153*199767f8SToomas Soome #define	IFF_LINK1	0x2000		/* per link layer defined bit */
154*199767f8SToomas Soome #define	IFF_LINK2	0x4000		/* per link layer defined bit */
155*199767f8SToomas Soome #define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
156*199767f8SToomas Soome #define	IFF_MULTICAST	0x8000		/* (i) supports multicast */
157*199767f8SToomas Soome #define	IFF_CANTCONFIG	0x10000		/* (i) unconfigurable using ioctl(2) */
158*199767f8SToomas Soome #define	IFF_PPROMISC	0x20000		/* (n) user-requested promisc mode */
159*199767f8SToomas Soome #define	IFF_MONITOR	0x40000		/* (n) user-requested monitor mode */
160*199767f8SToomas Soome #define	IFF_STATICARP	0x80000		/* (n) static ARP */
161*199767f8SToomas Soome #define	IFF_DYING	0x200000	/* (n) interface is winding down */
162*199767f8SToomas Soome #define	IFF_RENAMING	0x400000	/* (n) interface is being renamed */
163*199767f8SToomas Soome /*
164*199767f8SToomas Soome  * Old names for driver flags so that user space tools can continue to use
165*199767f8SToomas Soome  * the old (portable) names.
166*199767f8SToomas Soome  */
167*199767f8SToomas Soome #ifndef _KERNEL
168*199767f8SToomas Soome #define	IFF_RUNNING	IFF_DRV_RUNNING
169*199767f8SToomas Soome #define	IFF_OACTIVE	IFF_DRV_OACTIVE
170*199767f8SToomas Soome #endif
171*199767f8SToomas Soome 
172*199767f8SToomas Soome /* flags set internally only: */
173*199767f8SToomas Soome #define	IFF_CANTCHANGE \
176*199767f8SToomas Soome 	    IFF_DYING|IFF_CANTCONFIG)
177*199767f8SToomas Soome 
178*199767f8SToomas Soome /*
179*199767f8SToomas Soome  * Values for if_link_state.
180*199767f8SToomas Soome  */
181*199767f8SToomas Soome #define	LINK_STATE_UNKNOWN	0	/* link invalid/unknown */
182*199767f8SToomas Soome #define	LINK_STATE_DOWN		1	/* link is down */
183*199767f8SToomas Soome #define	LINK_STATE_UP		2	/* link is up */
184*199767f8SToomas Soome 
185*199767f8SToomas Soome /*
186*199767f8SToomas Soome  * Some convenience macros used for setting ifi_baudrate.
187*199767f8SToomas Soome  * XXX 1000 vs. 1024? --thorpej@netbsd.org
188*199767f8SToomas Soome  */
189*199767f8SToomas Soome #define	IF_Kbps(x)	((uintmax_t)(x) * 1000)	/* kilobits/sec. */
190*199767f8SToomas Soome #define	IF_Mbps(x)	(IF_Kbps((x) * 1000))	/* megabits/sec. */
191*199767f8SToomas Soome #define	IF_Gbps(x)	(IF_Mbps((x) * 1000))	/* gigabits/sec. */
192*199767f8SToomas Soome 
193*199767f8SToomas Soome /*
194*199767f8SToomas Soome  * Capabilities that interfaces can advertise.
195*199767f8SToomas Soome  *
196*199767f8SToomas Soome  * struct ifnet.if_capabilities
197*199767f8SToomas Soome  *   contains the optional features & capabilities a particular interface
198*199767f8SToomas Soome  *   supports (not only the driver but also the detected hw revision).
199*199767f8SToomas Soome  *   Capabilities are defined by IFCAP_* below.
200*199767f8SToomas Soome  * struct ifnet.if_capenable
201*199767f8SToomas Soome  *   contains the enabled (either by default or through ifconfig) optional
202*199767f8SToomas Soome  *   features & capabilities on this interface.
203*199767f8SToomas Soome  *   Capabilities are defined by IFCAP_* below.
204*199767f8SToomas Soome  * struct if_data.ifi_hwassist in mbuf CSUM_ flag form, controlled by above
205*199767f8SToomas Soome  *   contains the enabled optional feature & capabilites that can be used
206*199767f8SToomas Soome  *   individually per packet and are specified in the mbuf pkthdr.csum_flags
207*199767f8SToomas Soome  *   field.  IFCAP_* and CSUM_* do not match one to one and CSUM_* may be
208*199767f8SToomas Soome  *   more detailed or differenciated than IFCAP_*.
209*199767f8SToomas Soome  *   Hwassist features are defined CSUM_* in sys/mbuf.h
210*199767f8SToomas Soome  *
211*199767f8SToomas Soome  * Capabilities that cannot be arbitrarily changed with ifconfig/ioctl
212*199767f8SToomas Soome  * are listed in IFCAP_CANTCHANGE, similar to IFF_CANTCHANGE.
213*199767f8SToomas Soome  * This is not strictly necessary because the common code never
214*199767f8SToomas Soome  * changes capabilities, and it is left to the individual driver
215*199767f8SToomas Soome  * to do the right thing. However, having the filter here
216*199767f8SToomas Soome  * avoids replication of the same code in all individual drivers.
217*199767f8SToomas Soome  */
218*199767f8SToomas Soome #define	IFCAP_RXCSUM		0x00001  /* can offload checksum on RX */
219*199767f8SToomas Soome #define	IFCAP_TXCSUM		0x00002  /* can offload checksum on TX */
220*199767f8SToomas Soome #define	IFCAP_NETCONS		0x00004  /* can be a network console */
221*199767f8SToomas Soome #define	IFCAP_VLAN_MTU		0x00008	/* VLAN-compatible MTU */
222*199767f8SToomas Soome #define	IFCAP_VLAN_HWTAGGING	0x00010	/* hardware VLAN tag support */
223*199767f8SToomas Soome #define	IFCAP_JUMBO_MTU		0x00020	/* 9000 byte MTU supported */
224*199767f8SToomas Soome #define	IFCAP_POLLING		0x00040	/* driver supports polling */
225*199767f8SToomas Soome #define	IFCAP_VLAN_HWCSUM	0x00080	/* can do IFCAP_HWCSUM on VLANs */
226*199767f8SToomas Soome #define	IFCAP_TSO4		0x00100	/* can do TCP Segmentation Offload */
227*199767f8SToomas Soome #define	IFCAP_TSO6		0x00200	/* can do TCP6 Segmentation Offload */
228*199767f8SToomas Soome #define	IFCAP_LRO		0x00400	/* can do Large Receive Offload */
229*199767f8SToomas Soome #define	IFCAP_WOL_UCAST		0x00800	/* wake on any unicast frame */
230*199767f8SToomas Soome #define	IFCAP_WOL_MCAST		0x01000	/* wake on any multicast frame */
231*199767f8SToomas Soome #define	IFCAP_WOL_MAGIC		0x02000	/* wake on any Magic Packet */
232*199767f8SToomas Soome #define	IFCAP_TOE4		0x04000	/* interface can offload TCP */
233*199767f8SToomas Soome #define	IFCAP_TOE6		0x08000	/* interface can offload TCP6 */
234*199767f8SToomas Soome #define	IFCAP_VLAN_HWFILTER	0x10000 /* interface hw can filter vlan tag */
235*199767f8SToomas Soome #define	IFCAP_POLLING_NOCOUNT	0x20000 /* polling ticks cannot be fragmented */
236*199767f8SToomas Soome #define	IFCAP_VLAN_HWTSO	0x40000 /* can do IFCAP_TSO on VLANs */
237*199767f8SToomas Soome #define	IFCAP_LINKSTATE		0x80000 /* the runtime link state is dynamic */
238*199767f8SToomas Soome #define	IFCAP_NETMAP		0x100000 /* netmap mode supported/enabled */
239*199767f8SToomas Soome #define	IFCAP_RXCSUM_IPV6	0x200000  /* can offload checksum on IPv6 RX */
240*199767f8SToomas Soome #define	IFCAP_TXCSUM_IPV6	0x400000  /* can offload checksum on IPv6 TX */
241*199767f8SToomas Soome #define	IFCAP_HWSTATS		0x800000 /* manages counters internally */
242*199767f8SToomas Soome 
243*199767f8SToomas Soome #define IFCAP_HWCSUM_IPV6	(IFCAP_RXCSUM_IPV6 | IFCAP_TXCSUM_IPV6)
244*199767f8SToomas Soome 
245*199767f8SToomas Soome #define IFCAP_HWCSUM	(IFCAP_RXCSUM | IFCAP_TXCSUM)
246*199767f8SToomas Soome #define	IFCAP_TSO	(IFCAP_TSO4 | IFCAP_TSO6)
248*199767f8SToomas Soome #define	IFCAP_TOE	(IFCAP_TOE4 | IFCAP_TOE6)
249*199767f8SToomas Soome 
250*199767f8SToomas Soome #define	IFCAP_CANTCHANGE	(IFCAP_NETMAP)
251*199767f8SToomas Soome 
252*199767f8SToomas Soome #define	IFQ_MAXLEN	50
253*199767f8SToomas Soome #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
254*199767f8SToomas Soome 
255*199767f8SToomas Soome /*
256*199767f8SToomas Soome  * Message format for use in obtaining information about interfaces
257*199767f8SToomas Soome  * from getkerninfo and the routing socket
258*199767f8SToomas Soome  * For the new, extensible interface see struct if_msghdrl below.
259*199767f8SToomas Soome  */
260*199767f8SToomas Soome struct if_msghdr {
261*199767f8SToomas Soome 	u_short	ifm_msglen;	/* to skip over non-understood messages */
262*199767f8SToomas Soome 	u_char	ifm_version;	/* future binary compatibility */
263*199767f8SToomas Soome 	u_char	ifm_type;	/* message type */
264*199767f8SToomas Soome 	int	ifm_addrs;	/* like rtm_addrs */
265*199767f8SToomas Soome 	int	ifm_flags;	/* value of if_flags */
266*199767f8SToomas Soome 	u_short	ifm_index;	/* index for associated ifp */
267*199767f8SToomas Soome 	struct	if_data ifm_data;/* statistics and other data about if */
268*199767f8SToomas Soome };
269*199767f8SToomas Soome 
270*199767f8SToomas Soome /*
271*199767f8SToomas Soome  * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
272*199767f8SToomas Soome  * extensible after ifm_data_off or within ifm_data.  Both the if_msghdr and
273*199767f8SToomas Soome  * if_data now have a member field detailing the struct length in addition to
274*199767f8SToomas Soome  * the routing message length.  Macros are provided to find the start of
275*199767f8SToomas Soome  * ifm_data and the start of the socket address strucutres immediately following
276*199767f8SToomas Soome  * struct if_msghdrl given a pointer to struct if_msghdrl.
277*199767f8SToomas Soome  */
278*199767f8SToomas Soome #define	IF_MSGHDRL_IFM_DATA(_l) \
279*199767f8SToomas Soome     (struct if_data *)((char *)(_l) + (_l)->ifm_data_off)
280*199767f8SToomas Soome #define	IF_MSGHDRL_RTA(_l) \
281*199767f8SToomas Soome     (void *)((uintptr_t)(_l) + (_l)->ifm_len)
282*199767f8SToomas Soome struct if_msghdrl {
283*199767f8SToomas Soome 	u_short	ifm_msglen;	/* to skip over non-understood messages */
284*199767f8SToomas Soome 	u_char	ifm_version;	/* future binary compatibility */
285*199767f8SToomas Soome 	u_char	ifm_type;	/* message type */
286*199767f8SToomas Soome 	int	ifm_addrs;	/* like rtm_addrs */
287*199767f8SToomas Soome 	int	ifm_flags;	/* value of if_flags */
288*199767f8SToomas Soome 	u_short	ifm_index;	/* index for associated ifp */
289*199767f8SToomas Soome 	u_short _ifm_spare1;	/* spare space to grow if_index, see if_var.h */
290*199767f8SToomas Soome 	u_short	ifm_len;	/* length of if_msghdrl incl. if_data */
291*199767f8SToomas Soome 	u_short	ifm_data_off;	/* offset of if_data from beginning */
292*199767f8SToomas Soome 	struct	if_data ifm_data;/* statistics and other data about if */
293*199767f8SToomas Soome };
294*199767f8SToomas Soome 
295*199767f8SToomas Soome /*
296*199767f8SToomas Soome  * Message format for use in obtaining information about interface addresses
297*199767f8SToomas Soome  * from getkerninfo and the routing socket
298*199767f8SToomas Soome  * For the new, extensible interface see struct ifa_msghdrl below.
299*199767f8SToomas Soome  */
300*199767f8SToomas Soome struct ifa_msghdr {
301*199767f8SToomas Soome 	u_short	ifam_msglen;	/* to skip over non-understood messages */
302*199767f8SToomas Soome 	u_char	ifam_version;	/* future binary compatibility */
303*199767f8SToomas Soome 	u_char	ifam_type;	/* message type */
304*199767f8SToomas Soome 	int	ifam_addrs;	/* like rtm_addrs */
305*199767f8SToomas Soome 	int	ifam_flags;	/* value of ifa_flags */
306*199767f8SToomas Soome 	u_short	ifam_index;	/* index for associated ifp */
307*199767f8SToomas Soome 	int	ifam_metric;	/* value of ifa_ifp->if_metric */
308*199767f8SToomas Soome };
309*199767f8SToomas Soome 
310*199767f8SToomas Soome /*
311*199767f8SToomas Soome  * The 'l' version shall be used by new interfaces, like NET_RT_IFLISTL.  It is
312*199767f8SToomas Soome  * extensible after ifam_metric or within ifam_data.  Both the ifa_msghdrl and
313*199767f8SToomas Soome  * if_data now have a member field detailing the struct length in addition to
314*199767f8SToomas Soome  * the routing message length.  Macros are provided to find the start of
315*199767f8SToomas Soome  * ifm_data and the start of the socket address strucutres immediately following
316*199767f8SToomas Soome  * struct ifa_msghdrl given a pointer to struct ifa_msghdrl.
317*199767f8SToomas Soome  */
318*199767f8SToomas Soome #define	IFA_MSGHDRL_IFAM_DATA(_l) \
319*199767f8SToomas Soome     (struct if_data *)((char *)(_l) + (_l)->ifam_data_off)
320*199767f8SToomas Soome #define	IFA_MSGHDRL_RTA(_l) \
321*199767f8SToomas Soome     (void *)((uintptr_t)(_l) + (_l)->ifam_len)
322*199767f8SToomas Soome struct ifa_msghdrl {
323*199767f8SToomas Soome 	u_short	ifam_msglen;	/* to skip over non-understood messages */
324*199767f8SToomas Soome 	u_char	ifam_version;	/* future binary compatibility */
325*199767f8SToomas Soome 	u_char	ifam_type;	/* message type */
326*199767f8SToomas Soome 	int	ifam_addrs;	/* like rtm_addrs */
327*199767f8SToomas Soome 	int	ifam_flags;	/* value of ifa_flags */
328*199767f8SToomas Soome 	u_short	ifam_index;	/* index for associated ifp */
329*199767f8SToomas Soome 	u_short _ifam_spare1;	/* spare space to grow if_index, see if_var.h */
330*199767f8SToomas Soome 	u_short	ifam_len;	/* length of ifa_msghdrl incl. if_data */
331*199767f8SToomas Soome 	u_short	ifam_data_off;	/* offset of if_data from beginning */
332*199767f8SToomas Soome 	int	ifam_metric;	/* value of ifa_ifp->if_metric */
333*199767f8SToomas Soome 	struct	if_data ifam_data;/* statistics and other data about if or
334*199767f8SToomas Soome 				 * address */
335*199767f8SToomas Soome };
336*199767f8SToomas Soome 
337*199767f8SToomas Soome /*
338*199767f8SToomas Soome  * Message format for use in obtaining information about multicast addresses
339*199767f8SToomas Soome  * from the routing socket
340*199767f8SToomas Soome  */
341*199767f8SToomas Soome struct ifma_msghdr {
342*199767f8SToomas Soome 	u_short	ifmam_msglen;	/* to skip over non-understood messages */
343*199767f8SToomas Soome 	u_char	ifmam_version;	/* future binary compatibility */
344*199767f8SToomas Soome 	u_char	ifmam_type;	/* message type */
345*199767f8SToomas Soome 	int	ifmam_addrs;	/* like rtm_addrs */
346*199767f8SToomas Soome 	int	ifmam_flags;	/* value of ifa_flags */
347*199767f8SToomas Soome 	u_short	ifmam_index;	/* index for associated ifp */
348*199767f8SToomas Soome };
349*199767f8SToomas Soome 
350*199767f8SToomas Soome /*
351*199767f8SToomas Soome  * Message format announcing the arrival or departure of a network interface.
352*199767f8SToomas Soome  */
353*199767f8SToomas Soome struct if_announcemsghdr {
354*199767f8SToomas Soome 	u_short	ifan_msglen;	/* to skip over non-understood messages */
355*199767f8SToomas Soome 	u_char	ifan_version;	/* future binary compatibility */
356*199767f8SToomas Soome 	u_char	ifan_type;	/* message type */
357*199767f8SToomas Soome 	u_short	ifan_index;	/* index for associated ifp */
358*199767f8SToomas Soome 	char	ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
359*199767f8SToomas Soome 	u_short	ifan_what;	/* what type of announcement */
360*199767f8SToomas Soome };
361*199767f8SToomas Soome 
362*199767f8SToomas Soome #define	IFAN_ARRIVAL	0	/* interface arrival */
363*199767f8SToomas Soome #define	IFAN_DEPARTURE	1	/* interface departure */
364*199767f8SToomas Soome 
365*199767f8SToomas Soome /*
366*199767f8SToomas Soome  * Buffer with length to be used in SIOCGIFDESCR/SIOCSIFDESCR requests
367*199767f8SToomas Soome  */
368*199767f8SToomas Soome struct ifreq_buffer {
369*199767f8SToomas Soome 	size_t	length;
370*199767f8SToomas Soome 	void	*buffer;
371*199767f8SToomas Soome };
372*199767f8SToomas Soome 
373*199767f8SToomas Soome /*
374*199767f8SToomas Soome  * Interface request structure used for socket
375*199767f8SToomas Soome  * ioctl's.  All interface ioctl's must have parameter
376*199767f8SToomas Soome  * definitions which begin with ifr_name.  The
377*199767f8SToomas Soome  * remainder may be interface specific.
378*199767f8SToomas Soome  */
379*199767f8SToomas Soome struct	ifreq {
380*199767f8SToomas Soome 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
381*199767f8SToomas Soome 	union {
382*199767f8SToomas Soome 		struct	sockaddr ifru_addr;
383*199767f8SToomas Soome 		struct	sockaddr ifru_dstaddr;
384*199767f8SToomas Soome 		struct	sockaddr ifru_broadaddr;
385*199767f8SToomas Soome 		struct	ifreq_buffer ifru_buffer;
386*199767f8SToomas Soome 		short	ifru_flags[2];
387*199767f8SToomas Soome 		short	ifru_index;
388*199767f8SToomas Soome 		int	ifru_jid;
389*199767f8SToomas Soome 		int	ifru_metric;
390*199767f8SToomas Soome 		int	ifru_mtu;
391*199767f8SToomas Soome 		int	ifru_phys;
392*199767f8SToomas Soome 		int	ifru_media;
393*199767f8SToomas Soome 		caddr_t	ifru_data;
394*199767f8SToomas Soome 		int	ifru_cap[2];
395*199767f8SToomas Soome 		u_int	ifru_fib;
396*199767f8SToomas Soome 	} ifr_ifru;
397*199767f8SToomas Soome #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
398*199767f8SToomas Soome #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
399*199767f8SToomas Soome #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
400*199767f8SToomas Soome #define	ifr_buffer	ifr_ifru.ifru_buffer	/* user supplied buffer with its length */
401*199767f8SToomas Soome #define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
402*199767f8SToomas Soome #define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
403*199767f8SToomas Soome #define	ifr_jid		ifr_ifru.ifru_jid	/* jail/vnet */
404*199767f8SToomas Soome #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
405*199767f8SToomas Soome #define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
406*199767f8SToomas Soome #define ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
407*199767f8SToomas Soome #define ifr_media	ifr_ifru.ifru_media	/* physical media */
408*199767f8SToomas Soome #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
409*199767f8SToomas Soome #define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
410*199767f8SToomas Soome #define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
411*199767f8SToomas Soome #define	ifr_index	ifr_ifru.ifru_index	/* interface index */
412*199767f8SToomas Soome #define	ifr_fib		ifr_ifru.ifru_fib	/* interface fib */
413*199767f8SToomas Soome };
414*199767f8SToomas Soome 
415*199767f8SToomas Soome #define	_SIZEOF_ADDR_IFREQ(ifr) \
416*199767f8SToomas Soome 	((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
417*199767f8SToomas Soome 	 (sizeof(struct ifreq) - sizeof(struct sockaddr) + \
418*199767f8SToomas Soome 	  (ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
419*199767f8SToomas Soome 
420*199767f8SToomas Soome struct ifaliasreq {
421*199767f8SToomas Soome 	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
422*199767f8SToomas Soome 	struct	sockaddr ifra_addr;
423*199767f8SToomas Soome 	struct	sockaddr ifra_broadaddr;
424*199767f8SToomas Soome 	struct	sockaddr ifra_mask;
425*199767f8SToomas Soome 	int	ifra_vhid;
426*199767f8SToomas Soome };
427*199767f8SToomas Soome 
428*199767f8SToomas Soome /* 9.x compat */
429*199767f8SToomas Soome struct oifaliasreq {
430*199767f8SToomas Soome 	char	ifra_name[IFNAMSIZ];
431*199767f8SToomas Soome 	struct	sockaddr ifra_addr;
432*199767f8SToomas Soome 	struct	sockaddr ifra_broadaddr;
433*199767f8SToomas Soome 	struct	sockaddr ifra_mask;
434*199767f8SToomas Soome };
435*199767f8SToomas Soome 
436*199767f8SToomas Soome struct ifmediareq {
437*199767f8SToomas Soome 	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
438*199767f8SToomas Soome 	int	ifm_current;		/* current media options */
439*199767f8SToomas Soome 	int	ifm_mask;		/* don't care mask */
440*199767f8SToomas Soome 	int	ifm_status;		/* media status */
441*199767f8SToomas Soome 	int	ifm_active;		/* active options */
442*199767f8SToomas Soome 	int	ifm_count;		/* # entries in ifm_ulist array */
443*199767f8SToomas Soome 	int	*ifm_ulist;		/* media words */
444*199767f8SToomas Soome };
445*199767f8SToomas Soome 
446*199767f8SToomas Soome struct  ifdrv {
447*199767f8SToomas Soome 	char            ifd_name[IFNAMSIZ];     /* if name, e.g. "en0" */
448*199767f8SToomas Soome 	unsigned long   ifd_cmd;
449*199767f8SToomas Soome 	size_t          ifd_len;
450*199767f8SToomas Soome 	void            *ifd_data;
451*199767f8SToomas Soome };
452*199767f8SToomas Soome 
453*199767f8SToomas Soome /*
454*199767f8SToomas Soome  * Structure used to retrieve aux status data from interfaces.
455*199767f8SToomas Soome  * Kernel suppliers to this interface should respect the formatting
456*199767f8SToomas Soome  * needed by ifconfig(8): each line starts with a TAB and ends with
457*199767f8SToomas Soome  * a newline.  The canonical example to copy and paste is in if_tun.c.
458*199767f8SToomas Soome  */
459*199767f8SToomas Soome 
460*199767f8SToomas Soome #define	IFSTATMAX	800		/* 10 lines of text */
461*199767f8SToomas Soome struct ifstat {
462*199767f8SToomas Soome 	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
463*199767f8SToomas Soome 	char	ascii[IFSTATMAX + 1];
464*199767f8SToomas Soome };
465*199767f8SToomas Soome 
466*199767f8SToomas Soome /*
467*199767f8SToomas Soome  * Structure used in SIOCGIFCONF request.
468*199767f8SToomas Soome  * Used to retrieve interface configuration
469*199767f8SToomas Soome  * for machine (useful for programs which
470*199767f8SToomas Soome  * must know all networks accessible).
471*199767f8SToomas Soome  */
472*199767f8SToomas Soome struct	ifconf {
473*199767f8SToomas Soome 	int	ifc_len;		/* size of associated buffer */
474*199767f8SToomas Soome 	union {
475*199767f8SToomas Soome 		caddr_t	ifcu_buf;
476*199767f8SToomas Soome 		struct	ifreq *ifcu_req;
477*199767f8SToomas Soome 	} ifc_ifcu;
478*199767f8SToomas Soome #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
479*199767f8SToomas Soome #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
480*199767f8SToomas Soome };
481*199767f8SToomas Soome 
482*199767f8SToomas Soome /*
483*199767f8SToomas Soome  * interface groups
484*199767f8SToomas Soome  */
485*199767f8SToomas Soome 
486*199767f8SToomas Soome #define	IFG_ALL		"all"		/* group contains all interfaces */
487*199767f8SToomas Soome /* XXX: will we implement this? */
488*199767f8SToomas Soome #define	IFG_EGRESS	"egress"	/* if(s) default route(s) point to */
489*199767f8SToomas Soome 
490*199767f8SToomas Soome struct ifg_req {
491*199767f8SToomas Soome 	union {
492*199767f8SToomas Soome 		char			 ifgrqu_group[IFNAMSIZ];
493*199767f8SToomas Soome 		char			 ifgrqu_member[IFNAMSIZ];
494*199767f8SToomas Soome 	} ifgrq_ifgrqu;
495*199767f8SToomas Soome #define	ifgrq_group	ifgrq_ifgrqu.ifgrqu_group
496*199767f8SToomas Soome #define	ifgrq_member	ifgrq_ifgrqu.ifgrqu_member
497*199767f8SToomas Soome };
498*199767f8SToomas Soome 
499*199767f8SToomas Soome /*
500*199767f8SToomas Soome  * Used to lookup groups for an interface
501*199767f8SToomas Soome  */
502*199767f8SToomas Soome struct ifgroupreq {
503*199767f8SToomas Soome 	char	ifgr_name[IFNAMSIZ];
504*199767f8SToomas Soome 	u_int	ifgr_len;
505*199767f8SToomas Soome 	union {
506*199767f8SToomas Soome 		char	ifgru_group[IFNAMSIZ];
507*199767f8SToomas Soome 		struct	ifg_req *ifgru_groups;
508*199767f8SToomas Soome 	} ifgr_ifgru;
509*199767f8SToomas Soome #define ifgr_group	ifgr_ifgru.ifgru_group
510*199767f8SToomas Soome #define ifgr_groups	ifgr_ifgru.ifgru_groups
511*199767f8SToomas Soome };
512*199767f8SToomas Soome 
513*199767f8SToomas Soome /*
514*199767f8SToomas Soome  * Structure used to request i2c data
515*199767f8SToomas Soome  * from interface transceivers.
516*199767f8SToomas Soome  */
517*199767f8SToomas Soome struct ifi2creq {
518*199767f8SToomas Soome 	uint8_t dev_addr;	/* i2c address (0xA0, 0xA2) */
519*199767f8SToomas Soome 	uint8_t offset;		/* read offset */
520*199767f8SToomas Soome 	uint8_t len;		/* read length */
521*199767f8SToomas Soome 	uint8_t spare0;
522*199767f8SToomas Soome 	uint32_t spare1;
523*199767f8SToomas Soome 	uint8_t data[8];	/* read buffer */
524*199767f8SToomas Soome };
525*199767f8SToomas Soome 
526*199767f8SToomas Soome #endif /* __BSD_VISIBLE */
527*199767f8SToomas Soome 
528*199767f8SToomas Soome #ifdef _KERNEL
529*199767f8SToomas Soome #ifdef MALLOC_DECLARE
530*199767f8SToomas Soome MALLOC_DECLARE(M_IFADDR);
531*199767f8SToomas Soome MALLOC_DECLARE(M_IFMADDR);
532*199767f8SToomas Soome #endif
533*199767f8SToomas Soome #endif
534*199767f8SToomas Soome 
535*199767f8SToomas Soome #ifndef _KERNEL
536*199767f8SToomas Soome struct if_nameindex {
537*199767f8SToomas Soome 	unsigned int	if_index;	/* 1, 2, ... */
538*199767f8SToomas Soome 	char		*if_name;	/* null terminated name: "le0", ... */
539*199767f8SToomas Soome };
540*199767f8SToomas Soome 
541*199767f8SToomas Soome __BEGIN_DECLS
542*199767f8SToomas Soome void			 if_freenameindex(struct if_nameindex *);
543*199767f8SToomas Soome char			*if_indextoname(unsigned int, char *);
544*199767f8SToomas Soome struct if_nameindex	*if_nameindex(void);
545*199767f8SToomas Soome unsigned int		 if_nametoindex(const char *);
546*199767f8SToomas Soome __END_DECLS
547*199767f8SToomas Soome #endif
548*199767f8SToomas Soome #endif /* !_NET_IF_H_ */