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