xref: /illumos-gate/usr/src/uts/common/net/if.h (revision 15c07adc1c7b828006b5e3c4d528b92229d6bd23)
1 /*
2  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
3  */
4 
5 /*
6  * Copyright (c) 1982, 1986 Regents of the University of California.
7  * All rights reserved.  The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 #ifndef	_NET_IF_H
12 #define	_NET_IF_H
13 
14 /* if.h 1.26 90/05/29 SMI; from UCB 7.1 6/4/86		*/
15 
16 #include <sys/feature_tests.h>
17 
18 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #if defined(_LP64)
22 #include <sys/types32.h>
23 #endif
24 #endif
25 
26 #ifdef	__cplusplus
27 extern "C" {
28 #endif
29 
30 /*
31  * Structures defining a network interface, providing a packet
32  * transport mechanism (ala level 0 of the PUP protocols).
33  *
34  * Each interface accepts output datagrams of a specified maximum
35  * length, and provides higher level routines with input datagrams
36  * received from its medium.
37  *
38  * Output occurs when the routine if_output is called, with three parameters:
39  *	(*ifp->if_output)(ifp, m, dst)
40  * Here m is the mbuf chain to be sent and dst is the destination address.
41  * The output routine encapsulates the supplied datagram if necessary,
42  * and then transmits it on its medium.
43  *
44  * On input, each interface unwraps the data received by it, and either
45  * places it on the input queue of a internetwork datagram routine
46  * and posts the associated software interrupt, or passes the datagram to a raw
47  * packet input routine.
48  *
49  * Routines exist for locating interfaces by their addresses
50  * or for locating a interface on a certain network, as well as more general
51  * routing and gateway routines maintaining information used to locate
52  * interfaces.  These routines live in the files if.c and route.c
53  */
54 
55 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
56 
57 /*
58  * Structure defining a queue for a network interface.
59  *
60  * (Would like to call this struct ``if'', but C isn't PL/1.)
61  */
62 struct ifnet {
63 	char	*if_name;		/* name, e.g. ``en'' or ``lo'' */
64 	short	if_unit;		/* sub-unit for lower level driver */
65 	short	if_mtu;			/* maximum transmission unit */
66 	short	if_flags;		/* up/down, broadcast, etc. */
67 	short	if_timer;		/* time 'til if_watchdog called */
68 	ushort_t if_promisc;		/* net # of requests for promisc mode */
69 	int	if_metric;		/* routing metric (external only) */
70 	struct	ifaddr *if_addrlist;	/* linked list of addresses per if */
71 	struct	ifqueue {
72 		struct	mbuf *ifq_head;
73 		struct	mbuf *ifq_tail;
74 		int	ifq_len;
75 		int	ifq_maxlen;
76 		int	ifq_drops;
77 	} if_snd;			/* output queue */
78 /* procedure handles */
79 	int	(*if_init)();		/* init routine */
80 	int	(*if_output)();		/* output routine */
81 	int	(*if_ioctl)();		/* ioctl routine */
82 	int	(*if_reset)();		/* bus reset routine */
83 	int	(*if_watchdog)();	/* timer routine */
84 /* generic interface statistics */
85 	int	if_ipackets;		/* packets received on interface */
86 	int	if_ierrors;		/* input errors on interface */
87 	int	if_opackets;		/* packets sent on interface */
88 	int	if_oerrors;		/* output errors on interface */
89 	int	if_collisions;		/* collisions on csma interfaces */
90 /* end statistics */
91 	struct	ifnet *if_next;
92 	struct	ifnet *if_upper;	/* next layer up */
93 	struct	ifnet *if_lower;	/* next layer down */
94 	int	(*if_input)();		/* input routine */
95 	int	(*if_ctlin)();		/* control input routine */
96 	int	(*if_ctlout)();		/* control output routine */
97 	struct map *if_memmap;		/* rmap for interface specific memory */
98 };
99 
100 /*
101  * NOTE : These flags are not directly used within IP.
102  * ip_if.h has definitions derived from this which is used within IP.
103  * If you define a flag here, you need to define one in ip_if.h before
104  * using the new flag in IP. Don't use these flags directly in IP.
105  */
106 #define	IFF_UP		0x0000000001	/* address is up */
107 #define	IFF_BROADCAST	0x0000000002	/* broadcast address valid */
108 #define	IFF_DEBUG	0x0000000004	/* turn on debugging */
109 #define	IFF_LOOPBACK	0x0000000008	/* is a loopback net */
110 
111 #define	IFF_POINTOPOINT	0x0000000010	/* interface is point-to-point link */
112 #define	IFF_NOTRAILERS	0x0000000020	/* avoid use of trailers */
113 #define	IFF_RUNNING	0x0000000040	/* resources allocated */
114 #define	IFF_NOARP	0x0000000080	/* no address resolution protocol */
115 
116 #define	IFF_PROMISC	0x0000000100	/* receive all packets */
117 #define	IFF_ALLMULTI	0x0000000200	/* receive all multicast packets */
118 #define	IFF_INTELLIGENT	0x0000000400	/* protocol code on board */
119 /*
120  * The IFF_MULTICAST flag indicates that the network can support the
121  * transmission and reception of higher-level (e.g., IP) multicast packets.
122  * It is independent of hardware support for multicasting; for example,
123  * point-to-point links or pure broadcast networks may well support
124  * higher-level multicasts.
125  */
126 #define	IFF_MULTICAST	0x0000000800	/* supports multicast */
127 
128 #define	IFF_MULTI_BCAST	0x0000001000	/* multicast using broadcast address */
129 #define	IFF_UNNUMBERED	0x0000002000	/* non-unique address */
130 #define	IFF_DHCPRUNNING	0x0000004000	/* DHCP controls this interface */
131 #define	IFF_PRIVATE	0x0000008000	/* do not advertise */
132 
133 /*
134  * The following flags can't be grabbed or altered by SIOC[GS]IFFLAGS.
135  * Should use SIOC[GS]LIFFLAGS which has a larger flags field.
136  */
137 #define	IFF_NOXMIT	0x0000010000	/* Do not transmit packets */
138 #define	IFF_NOLOCAL	0x0000020000	/* No address - just on-link subnet */
139 #define	IFF_DEPRECATED	0x0000040000	/* Address is deprecated */
140 #define	IFF_ADDRCONF	0x0000080000	/* address from stateless addrconf */
141 
142 #define	IFF_ROUTER	0x0000100000	/* router on this interface */
143 #define	IFF_NONUD	0x0000200000	/* No NUD on this interface */
144 #define	IFF_ANYCAST	0x0000400000	/* Anycast address */
145 #define	IFF_NORTEXCH	0x0000800000	/* Do not exchange routing info */
146 
147 #define	IFF_IPV4	0x0001000000	/* IPv4 interface */
148 #define	IFF_IPV6	0x0002000000	/* IPv6 interface */
149 #define	IFF_NOACCEPT	0x0004000000	/* no-accept mode VRRP ill */
150 #define	IFF_NOFAILOVER	0x0008000000	/* in.mpathd(1M) test address */
151 
152 #define	IFF_FAILED	0x0010000000	/* Interface has failed */
153 #define	IFF_STANDBY	0x0020000000	/* Interface is a hot-spare */
154 #define	IFF_INACTIVE	0x0040000000	/* Functioning but not used for data */
155 #define	IFF_OFFLINE	0x0080000000	/* Interface is offline */
156 
157 /*
158  * The IFF_XRESOLV flag is an evolving interface and is subject
159  * to change without notice.
160  */
161 #define	IFF_XRESOLV	0x0100000000ll	/* IPv6 external resolver */
162 #define	IFF_COS_ENABLED	0x0200000000ll	/* If interface supports CoS marking */
163 #define	IFF_PREFERRED	0x0400000000ll	/* Prefer as source address */
164 #define	IFF_TEMPORARY	0x0800000000ll	/* RFC3041 */
165 
166 #define	IFF_FIXEDMTU	0x1000000000ll	/* MTU manually set with SIOCSLIFMTU */
167 #define	IFF_VIRTUAL	0x2000000000ll	/* Does not send or receive packets */
168 #define	IFF_DUPLICATE	0x4000000000ll	/* Local address already in use */
169 #define	IFF_IPMP	0x8000000000ll	/* IPMP IP interface */
170 #define	IFF_VRRP	0x10000000000ll	/* Managed by VRRP */
171 
172 #define	IFF_NOLINKLOCAL	0x20000000000ll	/* No default linklocal */
173 #define	IFF_L3PROTECT	0x40000000000ll	/* Layer-3 protection enforced */
174 
175 /* flags that cannot be changed by userland on any interface */
176 #define	IFF_CANTCHANGE \
177 	(IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING | IFF_PROMISC | \
178 	IFF_MULTICAST | IFF_MULTI_BCAST | IFF_UNNUMBERED | IFF_IPV4 | \
179 	IFF_IPV6 | IFF_IPMP | IFF_FIXEDMTU | IFF_VIRTUAL | \
180 	IFF_LOOPBACK | IFF_ALLMULTI | IFF_DUPLICATE | IFF_COS_ENABLED | \
181 	IFF_VRRP | IFF_NOLINKLOCAL | IFF_L3PROTECT)
182 
183 /* flags that cannot be changed by userland on an IPMP interface */
184 #define	IFF_IPMP_CANTCHANGE 	IFF_FAILED
185 
186 /* flags that can never be set on an IPMP interface */
187 #define	IFF_IPMP_INVALID	(IFF_STANDBY | IFF_INACTIVE | IFF_OFFLINE | \
188 	IFF_NOFAILOVER | IFF_NOARP | IFF_NONUD | IFF_XRESOLV | IFF_NOACCEPT)
189 
190 /*
191  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
192  * input routines have queues of messages stored on ifqueue structures
193  * (defined above).  Entries are added to and deleted from these structures
194  * by these macros, which should be called with ipl raised to splimp().
195  */
196 #define	IF_QFULL(ifq)		((ifq)->ifq_len >= (ifq)->ifq_maxlen)
197 #define	IF_DROP(ifq)		((ifq)->ifq_drops++)
198 #define	IF_ENQUEUE(ifq, m) { \
199 	(m)->m_act = 0; \
200 	if ((ifq)->ifq_tail == 0) \
201 		(ifq)->ifq_head = m; \
202 	else \
203 		(ifq)->ifq_tail->m_act = m; \
204 	(ifq)->ifq_tail = m; \
205 	(ifq)->ifq_len++; \
206 }
207 #define	IF_PREPEND(ifq, m) { \
208 	(m)->m_act = (ifq)->ifq_head; \
209 	if ((ifq)->ifq_tail == 0) \
210 		(ifq)->ifq_tail = (m); \
211 	(ifq)->ifq_head = (m); \
212 	(ifq)->ifq_len++; \
213 }
214 
215 /*
216  * Packets destined for level-1 protocol input routines
217  * have a pointer to the receiving interface prepended to the data.
218  * IF_DEQUEUEIF extracts and returns this pointer when dequeuing the packet.
219  * IF_ADJ should be used otherwise to adjust for its presence.
220  */
221 #define	IF_ADJ(m) { \
222 	(m)->m_off += sizeof (struct ifnet *); \
223 	(m)->m_len -= sizeof (struct ifnet *); \
224 	if ((m)->m_len == 0) { \
225 		struct mbuf *n; \
226 		MFREE((m), n); \
227 		(m) = n; \
228 	} \
229 }
230 #define	IF_DEQUEUEIF(ifq, m, ifp) { \
231 	(m) = (ifq)->ifq_head; \
232 	if (m) { \
233 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
234 			(ifq)->ifq_tail = 0; \
235 		(m)->m_act = 0; \
236 		(ifq)->ifq_len--; \
237 		(ifp) = *(mtod((m), struct ifnet **)); \
238 		IF_ADJ(m); \
239 	} \
240 }
241 #define	IF_DEQUEUE(ifq, m) { \
242 	(m) = (ifq)->ifq_head; \
243 	if (m) { \
244 		if (((ifq)->ifq_head = (m)->m_act) == 0) \
245 			(ifq)->ifq_tail = 0; \
246 		(m)->m_act = 0; \
247 		(ifq)->ifq_len--; \
248 	} \
249 }
250 
251 #define	IFQ_MAXLEN	50
252 #define	IFNET_SLOWHZ	1		/* granularity is 1 second */
253 
254 /*
255  * The ifaddr structure contains information about one address
256  * of an interface.  They are maintained by the different address families,
257  * are allocated and attached when an address is set, and are linked
258  * together so all addresses for an interface can be located.
259  */
260 struct ifaddr {
261 	struct	sockaddr ifa_addr;	/* address of interface */
262 	union {
263 		struct	sockaddr ifu_broadaddr;
264 		struct	sockaddr ifu_dstaddr;
265 	} ifa_ifu;
266 #define	ifa_broadaddr	ifa_ifu.ifu_broadaddr	/* broadcast address */
267 #define	ifa_dstaddr	ifa_ifu.ifu_dstaddr	/* other end of p-to-p link */
268 	struct	ifnet *ifa_ifp;		/* back-pointer to interface */
269 	struct	ifaddr *ifa_next;	/* next address for interface */
270 };
271 
272 /*
273  * For SIOCLIF*ND ioctls.
274  *
275  * The lnr_state_* fields use the ND_* neighbor reachability states.
276  * The 3 different fields are for use with SIOCLIFSETND to cover the cases
277  * when
278  *	A new entry is created
279  *	The entry already exists and the link-layer address is the same
280  *	The entry already exists and the link-layer address differs
281  *
282  * Use ND_UNCHANGED to not change any state.
283  */
284 #define	ND_MAX_HDW_LEN	64
285 typedef struct lif_nd_req {
286 	struct sockaddr_storage	lnr_addr;
287 	uint8_t			lnr_state_create;	/* When creating */
288 	uint8_t			lnr_state_same_lla;	/* Update same addr */
289 	uint8_t			lnr_state_diff_lla;	/* Update w/ diff. */
290 	int			lnr_hdw_len;
291 	int			lnr_flags;		/* See below */
292 	/* padding because ia32 "long long"s are only 4-byte aligned. */
293 	int			lnr_pad0;
294 	char			lnr_hdw_addr[ND_MAX_HDW_LEN];
295 } lif_nd_req_t;
296 
297 /*
298  * Neighbor reachability states
299  * Used with SIOCLIF*ND ioctls.
300  */
301 #define	ND_UNCHANGED	0	/* For ioctls that don't modify state */
302 #define	ND_INCOMPLETE	1	/* addr resolution in progress */
303 #define	ND_REACHABLE	2	/* have recently been reachable */
304 #define	ND_STALE	3	/* may be unreachable, don't do anything */
305 #define	ND_DELAY	4	/* wait for upper layer hint */
306 #define	ND_PROBE	5	/* send probes */
307 #define	ND_UNREACHABLE	6	/* delete this route */
308 #define	ND_INITIAL	7	/* ipv4: arp resolution has not been sent yet */
309 
310 #define	ND_STATE_VALID_MIN	0
311 #define	ND_STATE_VALID_MAX	7
312 
313 /*
314  * lnr_flags value of lif_nd_req.
315  * Used with SIOCLIF*ND ioctls.
316  */
317 #define	NDF_ISROUTER_ON		0x1
318 #define	NDF_ISROUTER_OFF	0x2
319 #define	NDF_ANYCAST_ON		0x4
320 #define	NDF_ANYCAST_OFF		0x8
321 #define	NDF_PROXY_ON		0x10
322 #define	NDF_PROXY_OFF		0x20
323 /*
324  * the NDF_STATIC entry ensures that an NCE will not be deleted, and is
325  * used by non-ON applications like IPv6 test suites.
326  */
327 #define	NDF_STATIC		0x40
328 
329 /* For SIOC[GS]LIFLNKINFO */
330 typedef struct lif_ifinfo_req {
331 	uint8_t		lir_maxhops;
332 	uint32_t	lir_reachtime;		/* Reachable time in msec */
333 	uint32_t	lir_reachretrans;	/* Retransmission timer msec */
334 	uint32_t	lir_maxmtu;
335 } lif_ifinfo_req_t;
336 
337 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
338 
339 /*
340  * Maximum lengths of interface name and IPMP group name; these are the same
341  * for historical reasons.  Note that the actual maximum length of a name is
342  * one byte less than these constants since the kernel always sets the final
343  * byte of lifr_name and lifr_groupname to NUL.
344  */
345 #define	_LIFNAMSIZ	32
346 
347 #if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
348 
349 #define	LIFNAMSIZ	_LIFNAMSIZ
350 #define	LIFGRNAMSIZ	LIFNAMSIZ
351 
352 /*
353  * Interface request structure used for socket
354  * ioctl's.  All interface ioctl's must have parameter
355  * definitions which begin with ifr_name.  The
356  * remainder may be interface specific.
357  * Note: This data structure uses 64bit type uint64_t which is not
358  *	 a valid type for strict ANSI/ISO C compilation for ILP32.
359  *	 Applications with ioctls using this structure that insist on
360  *	 building with strict ANSI/ISO C (-Xc) will need to be LP64.
361  */
362 #if defined(_INT64_TYPE)
363 struct	lifreq {
364 	char	lifr_name[LIFNAMSIZ];		/* if name, e.g. "en0" */
365 	union {
366 		int	lifru_addrlen;		/* for subnet/token etc */
367 		uint_t	lifru_ppa;		/* SIOCSLIFNAME */
368 	} lifr_lifru1;
369 #define	lifr_addrlen	lifr_lifru1.lifru_addrlen
370 #define	lifr_ppa	lifr_lifru1.lifru_ppa	/* Driver's ppa */
371 	uint_t		lifr_type;		/* IFT_ETHER, ... */
372 	union {
373 		struct	sockaddr_storage lifru_addr;
374 		struct	sockaddr_storage lifru_dstaddr;
375 		struct	sockaddr_storage lifru_broadaddr;
376 		struct	sockaddr_storage lifru_token;	/* With lifr_addrlen */
377 		struct	sockaddr_storage lifru_subnet;	/* With lifr_addrlen */
378 		int	lifru_index;		/* interface index */
379 		uint64_t lifru_flags;		/* Flags for SIOC?LIFFLAGS */
380 		int	lifru_metric;
381 		uint_t	lifru_mtu;
382 		int	lif_muxid[2];		/* mux id's for arp and ip */
383 		struct lif_nd_req	lifru_nd_req; /* SIOCLIF*ND */
384 		struct lif_ifinfo_req	lifru_ifinfo_req;
385 		char	lifru_groupname[LIFGRNAMSIZ]; /* SIOC[GS]LIFGROUPNAME */
386 		char	lifru_binding[LIFNAMSIZ]; /* SIOCGLIFBINDING */
387 		zoneid_t lifru_zoneid;		/* SIOC[GS]LIFZONE */
388 		uint_t	lifru_dadstate;		/* SIOCGLIFDADSTATE */
389 	} lifr_lifru;
390 
391 #define	lifr_addr	lifr_lifru.lifru_addr	/* address */
392 #define	lifr_dstaddr	lifr_lifru.lifru_dstaddr /* other end of p-to-p link */
393 #define	lifr_broadaddr	lifr_lifru.lifru_broadaddr /* broadcast address */
394 #define	lifr_token	lifr_lifru.lifru_token	/* address token */
395 #define	lifr_subnet	lifr_lifru.lifru_subnet	/* subnet prefix */
396 #define	lifr_index	lifr_lifru.lifru_index	/* interface index */
397 #define	lifr_flags	lifr_lifru.lifru_flags	/* flags */
398 #define	lifr_metric	lifr_lifru.lifru_metric	/* metric */
399 #define	lifr_mtu	lifr_lifru.lifru_mtu	/* mtu */
400 #define	lifr_ip_muxid	lifr_lifru.lif_muxid[0]
401 #define	lifr_arp_muxid	lifr_lifru.lif_muxid[1]
402 #define	lifr_nd		lifr_lifru.lifru_nd_req	/* SIOCLIF*ND */
403 #define	lifr_ifinfo	lifr_lifru.lifru_ifinfo_req /* SIOC[GS]LIFLNKINFO */
404 #define	lifr_groupname	lifr_lifru.lifru_groupname
405 #define	lifr_binding	lifr_lifru.lifru_binding
406 #define	lifr_zoneid	lifr_lifru.lifru_zoneid
407 #define	lifr_dadstate	lifr_lifru.lifru_dadstate
408 };
409 #endif /* defined(_INT64_TYPE) */
410 
411 /*
412  * Argument structure for SIOCT* address testing ioctls.
413  */
414 struct sioc_addrreq {
415 	struct sockaddr_storage	sa_addr;	/* Address to test */
416 	int			sa_res;		/* Result - 0/1 */
417 	int			sa_pad;
418 };
419 
420 /*
421  * Argument structure used by mrouted to get src-grp pkt counts using
422  * SIOCGETLSGCNT. See <netinet/ip_mroute.h>.
423  */
424 struct sioc_lsg_req {
425 	struct sockaddr_storage	slr_src;
426 	struct sockaddr_storage	slr_grp;
427 	uint_t			slr_pktcnt;
428 	uint_t			slr_bytecnt;
429 	uint_t			slr_wrong_if;
430 	uint_t			slr_pad;
431 };
432 
433 /* Argument structure for SIOCGLIFDADSTATE ioctl */
434 typedef enum {
435 	DAD_IN_PROGRESS	= 0x1,
436 	DAD_DONE	= 0x2
437 } glif_dad_state_t;
438 
439 /*
440  * OBSOLETE: Replaced by struct lifreq. Supported for compatibility.
441  *
442  * Interface request structure used for socket
443  * ioctl's.  All interface ioctl's must have parameter
444  * definitions which begin with ifr_name.  The
445  * remainder may be interface specific.
446  */
447 struct	ifreq {
448 #define	IFNAMSIZ	16
449 	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
450 	union {
451 		struct	sockaddr ifru_addr;
452 		struct	sockaddr ifru_dstaddr;
453 		char	ifru_oname[IFNAMSIZ];	/* other if name */
454 		struct	sockaddr ifru_broadaddr;
455 		int	ifru_index;		/* interface index */
456 		uint_t	ifru_mtu;
457 		short	ifru_flags;
458 		int	ifru_metric;
459 		char	ifru_data[1];		/* interface dependent data */
460 		char	ifru_enaddr[6];
461 		int	if_muxid[2];		/* mux id's for arp and ip */
462 
463 		/* Struct for flags/ppa */
464 		struct ifr_ppaflags {
465 			short ifrup_flags;	/* Space of ifru_flags. */
466 			short ifrup_filler;
467 			uint_t ifrup_ppa;
468 		} ifru_ppaflags;
469 
470 		/* Struct for FDDI ioctl's */
471 		struct ifr_dnld_reqs {
472 			uint32_t	v_addr;
473 			uint32_t	m_addr;
474 			uint32_t	ex_addr;
475 			uint32_t	size;
476 		} ifru_dnld_req;
477 
478 		/* Struct for FDDI stats */
479 		struct ifr_fddi_stats {
480 			uint32_t stat_size;
481 			uint32_t fddi_stats;
482 		} ifru_fddi_stat;
483 
484 		struct ifr_netmapents {
485 			uint32_t map_ent_size,	/* size of netmap structure */
486 				entry_number;	/* index into netmap list */
487 			uint32_t fddi_map_ent;	/* pointer to user structure */
488 		} ifru_netmapent;
489 
490 		/* Field for generic ioctl for fddi */
491 
492 		struct ifr_fddi_gen_struct {
493 			uint32_t ifru_fddi_gioctl; /* field for gen ioctl */
494 			uint32_t ifru_fddi_gaddr;  /* Generic ptr to a field */
495 		} ifru_fddi_gstruct;
496 
497 	} ifr_ifru;
498 
499 #define	ifr_addr	ifr_ifru.ifru_addr	/* address */
500 #define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
501 #define	ifr_oname	ifr_ifru.ifru_oname	/* other if name */
502 #define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
503 #define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
504 #define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
505 #define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
506 #define	ifr_enaddr	ifr_ifru.ifru_enaddr	/* ethernet address */
507 #define	ifr_index	ifr_ifru.ifru_index	/* interface index */
508 #define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
509 /* For setting ppa */
510 #define	ifr_ppa		ifr_ifru.ifru_ppaflags.ifrup_ppa
511 
512 /* FDDI specific */
513 #define	ifr_dnld_req	ifr_ifru.ifru_dnld_req
514 #define	ifr_fddi_stat	ifr_ifru.ifru_fddi_stat
515 #define	ifr_fddi_netmap	ifr_ifru.ifru_netmapent	/* FDDI network map entries */
516 #define	ifr_fddi_gstruct ifr_ifru.ifru_fddi_gstruct
517 
518 #define	ifr_ip_muxid	ifr_ifru.if_muxid[0]
519 #define	ifr_arp_muxid	ifr_ifru.if_muxid[1]
520 };
521 
522 /* Used by SIOCGLIFNUM. Uses same flags as in struct lifconf */
523 struct lifnum {
524 	sa_family_t	lifn_family;
525 	int		lifn_flags;	/* request specific interfaces */
526 	int		lifn_count;	/* Result */
527 };
528 
529 /*
530  * Structure used in SIOCGLIFCONF request.
531  * Used to retrieve interface configuration
532  * for machine (useful for programs which
533  * must know all networks accessible) for a given address family.
534  * Using AF_UNSPEC will retrieve all address families.
535  */
536 struct	lifconf {
537 	sa_family_t	lifc_family;
538 	int		lifc_flags;	/* request specific interfaces */
539 	int		lifc_len;	/* size of associated buffer */
540 	union {
541 		caddr_t	lifcu_buf;
542 		struct	lifreq *lifcu_req;
543 	} lifc_lifcu;
544 #define	lifc_buf lifc_lifcu.lifcu_buf	/* buffer address */
545 #define	lifc_req lifc_lifcu.lifcu_req	/* array of structures returned */
546 };
547 
548 /*
549  * Structure used in SIOCGLIFSRCOF to get the interface
550  * configuration list for those interfaces that use an address
551  * hosted on the interface (set in lifs_ifindex), as the source
552  * address.
553  */
554 struct lifsrcof {
555 	uint_t	lifs_ifindex;	/* interface of interest */
556 	size_t  lifs_maxlen;	/* size of buffer: input */
557 	size_t  lifs_len;	/* size of buffer: output */
558 	union {
559 		caddr_t	lifsu_buf;
560 		struct	lifreq *lifsu_req;
561 	} lifs_lifsu;
562 #define	lifs_buf lifs_lifsu.lifsu_buf /* buffer address */
563 #define	lifs_req lifs_lifsu.lifsu_req /* array returned */
564 };
565 
566 /* Flags */
567 #define	LIFC_NOXMIT	0x01		/* Include IFF_NOXMIT interfaces */
568 #define	LIFC_EXTERNAL_SOURCE	0x02	/* Exclude the interfaces which can't */
569 					/* be used to communicate outside the */
570 					/* node (exclude interfaces which are */
571 					/* IFF_NOXMIT, IFF_NOLOCAL, */
572 					/* IFF_LOOPBACK, IFF_DEPRECATED, or */
573 					/* not IFF_UP). Has priority over */
574 					/* LIFC_NOXMIT. */
575 #define	LIFC_TEMPORARY	0x04		/* Include IFF_TEMPORARY interfaces */
576 #define	LIFC_ALLZONES	0x08		/* Include all zones */
577 					/* (must be issued from global zone) */
578 #define	LIFC_UNDER_IPMP	0x10		/* Include underlying IPMP interfaces */
579 #define	LIFC_ENABLED	0x20		/* Include only IFF_UP interfaces */
580 
581 #if defined(_SYSCALL32)
582 
583 struct	lifconf32 {
584 	sa_family_t	lifc_family;
585 	int		lifc_flags;	/* request specific interfaces */
586 	int32_t	lifc_len;		/* size of associated buffer */
587 	union {
588 		caddr32_t lifcu_buf;
589 		caddr32_t lifcu_req;
590 	} lifc_lifcu;
591 };
592 
593 struct lifsrcof32 {
594 	uint_t	lifs_ifindex;	/* interface of interest */
595 	size32_t  lifs_maxlen;	/* size of buffer: input */
596 	size32_t  lifs_len;	/* size of buffer: output */
597 	union {
598 		caddr32_t lifsu_buf;
599 		caddr32_t lifsu_req;
600 	} lifs_lifsu;
601 };
602 
603 #endif	/* _SYSCALL32 */
604 
605 /*
606  * IPMP group information, for use with SIOCGLIFGROUPINFO.
607  */
608 typedef struct lifgroupinfo {
609 	char		gi_grname[LIFGRNAMSIZ];	/* group name (set by caller) */
610 	char		gi_grifname[LIFNAMSIZ];	/* IPMP meta-interface name */
611 	char		gi_m4ifname[LIFNAMSIZ];	/* v4 mcast interface name */
612 	char		gi_m6ifname[LIFNAMSIZ];	/* v6 mcast interface name */
613 	char		gi_bcifname[LIFNAMSIZ];	/* v4 bcast interface name */
614 	boolean_t	gi_v4;			/* group is plumbed for v4 */
615 	boolean_t	gi_v6; 			/* group is plumbed for v6 */
616 	uint_t		gi_nv4;			/* # of underlying v4 if's */
617 	uint_t		gi_nv6;			/* # of underlying v6 if's */
618 	uint_t		gi_mactype; 		/* DLPI mac type of group */
619 } lifgroupinfo_t;
620 
621 /*
622  * OBSOLETE: Structure used in SIOCGIFCONF request.
623  * Used to retrieve interface configuration
624  * for machine (useful for programs which
625  * must know all networks accessible).
626  */
627 struct	ifconf {
628 	int	ifc_len;		/* size of associated buffer */
629 	union {
630 		caddr_t	ifcu_buf;
631 		struct	ifreq *ifcu_req;
632 	} ifc_ifcu;
633 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
634 #define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
635 };
636 
637 #if defined(_SYSCALL32)
638 
639 struct	ifconf32 {
640 	int32_t	ifc_len;		/* size of associated buffer */
641 	union {
642 		caddr32_t ifcu_buf;
643 		caddr32_t ifcu_req;
644 	} ifc_ifcu;
645 };
646 
647 #endif	/* _SYSCALL32 */
648 
649 typedef struct if_data {
650 				/* generic interface information */
651 	uchar_t	ifi_type;	/* ethernet, tokenring, etc */
652 	uchar_t	ifi_addrlen;	/* media address length */
653 	uchar_t	ifi_hdrlen;	/* media header length */
654 	uint_t	ifi_mtu;	/* maximum transmission unit */
655 	uint_t	ifi_metric;	/* routing metric (external only) */
656 	uint_t	ifi_baudrate;	/* linespeed */
657 				/* volatile statistics */
658 	uint_t	ifi_ipackets;	/* packets received on interface */
659 	uint_t	ifi_ierrors;	/* input errors on interface */
660 	uint_t	ifi_opackets;	/* packets sent on interface */
661 	uint_t	ifi_oerrors;	/* output errors on interface */
662 	uint_t	ifi_collisions;	/* collisions on csma interfaces */
663 	uint_t	ifi_ibytes;	/* total number of octets received */
664 	uint_t	ifi_obytes;	/* total number of octets sent */
665 	uint_t	ifi_imcasts;	/* packets received via multicast */
666 	uint_t	ifi_omcasts;	/* packets sent via multicast */
667 	uint_t	ifi_iqdrops;	/* dropped on input, this interface */
668 	uint_t	ifi_noproto;	/* destined for unsupported protocol */
669 #if defined(_LP64)
670 	struct	timeval32 ifi_lastchange; /* last updated */
671 #else
672 	struct	timeval ifi_lastchange; /* last updated */
673 #endif
674 } if_data_t;
675 
676 /*
677  * Message format for use in obtaining information about interfaces
678  * from the routing socket
679  */
680 typedef struct if_msghdr {
681 	ushort_t ifm_msglen;	/* to skip over non-understood messages */
682 	uchar_t	ifm_version;	/* future binary compatibility */
683 	uchar_t	ifm_type;	/* message type */
684 	int	ifm_addrs;	/* like rtm_addrs */
685 	int	ifm_flags;	/* value of if_flags */
686 	ushort_t ifm_index;	/* index for associated ifp */
687 	struct	if_data ifm_data; /* statistics and other data about if */
688 } if_msghdr_t;
689 
690 /*
691  * Message format for use in obtaining information about interface addresses
692  * from the routing socket
693  */
694 typedef struct ifa_msghdr {
695 	ushort_t ifam_msglen;	/* to skip over non-understood messages */
696 	uchar_t	ifam_version;	/* future binary compatibility */
697 	uchar_t	ifam_type;	/* message type */
698 	int	ifam_addrs;	/* like rtm_addrs */
699 	int	ifam_flags;	/* route flags */
700 	ushort_t ifam_index;	/* index for associated ifp */
701 	int	ifam_metric;	/* value of ipif_metric */
702 } ifa_msghdr_t;
703 
704 #endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
705 
706 /*
707  * The if_nameindex structure holds the interface index value about
708  * a single interface. An array of this structure is used to return
709  * all interfaces and indexes.
710  */
711 struct if_nameindex {
712 	unsigned 	if_index;	/* positive interface index */
713 	char		*if_name;	/* if name, e.g. "en0" */
714 };
715 
716 /* Interface index identification API definitions */
717 extern	unsigned 		if_nametoindex(const char *);
718 extern	char			*if_indextoname(unsigned, char *);
719 extern	struct if_nameindex	*if_nameindex(void);
720 extern	void			if_freenameindex(struct if_nameindex *);
721 
722 #define	IF_NAMESIZE	_LIFNAMSIZ
723 /*
724  * If changing IF_MAX_INDEX to a value greater than UINT16_MAX, check if
725  * struct sockaddr_dl needs to be modified as the interface index is placed
726  * in this structure by the kernel.
727  */
728 #define	IF_INDEX_MAX	UINT16_MAX
729 
730 #ifdef	__cplusplus
731 }
732 #endif
733 
734 #endif	/* _NET_IF_H */
735