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