1/*
2 * Copyright (c) 2000-2014 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28/*
29 * Copyright (c) 1982, 1986, 1989, 1993
30 *	The Regents of the University of California.  All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 *    notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 *    notice, this list of conditions and the following disclaimer in the
39 *    documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 *    must display the following acknowledgement:
42 *	This product includes software developed by the University of
43 *	California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 *    may be used to endorse or promote products derived from this software
46 *    without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 *	@(#)if.h	8.1 (Berkeley) 6/10/93
61 */
62
63#ifndef _NET_IF_H_
64#define	_NET_IF_H_
65
66#include <sys/cdefs.h>
67
68#define	IF_NAMESIZE	16
69
70#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
71#include <sys/appleapiopts.h>
72#ifdef __APPLE__
73/*
74 * Define Data-Link event subclass, and associated
75 * events.
76 */
77
78#define	KEV_DL_SUBCLASS 2
79
80#define	KEV_DL_SIFFLAGS				1
81#define	KEV_DL_SIFMETRICS			2
82#define	KEV_DL_SIFMTU				3
83#define	KEV_DL_SIFPHYS				4
84#define	KEV_DL_SIFMEDIA				5
85#define	KEV_DL_SIFGENERIC			6
86#define	KEV_DL_ADDMULTI				7
87#define	KEV_DL_DELMULTI				8
88#define	KEV_DL_IF_ATTACHED			9
89#define	KEV_DL_IF_DETACHING			10
90#define	KEV_DL_IF_DETACHED			11
91#define	KEV_DL_LINK_OFF				12
92#define	KEV_DL_LINK_ON				13
93#define	KEV_DL_PROTO_ATTACHED			14
94#define	KEV_DL_PROTO_DETACHED			15
95#define	KEV_DL_LINK_ADDRESS_CHANGED		16
96#define	KEV_DL_WAKEFLAGS_CHANGED		17
97#define	KEV_DL_IF_IDLE_ROUTE_REFCNT		18
98#define	KEV_DL_IFCAP_CHANGED			19
99#define	KEV_DL_LINK_QUALITY_METRIC_CHANGED	20
100#define	KEV_DL_NODE_PRESENCE			21
101#define	KEV_DL_NODE_ABSENCE			22
102#define	KEV_DL_MASTER_ELECTED			23
103#define	KEV_DL_ISSUES				24
104#define	KEV_DL_IFDELEGATE_CHANGED		25
105#define	KEV_DL_AWDL_RESTRICTED			26
106#define	KEV_DL_AWDL_UNRESTRICTED		27
107
108#include <net/if_var.h>
109#include <sys/types.h>
110#include <sys/socket.h>
111
112#ifdef PRIVATE
113#include <net/if_dl.h>
114#include <netinet/in.h>
115#endif
116#endif
117
118struct if_clonereq {
119	int	ifcr_total;		/* total cloners (out) */
120	int	ifcr_count;		/* room for this many in user buffer */
121	char	*ifcr_buffer;		/* buffer for cloner names */
122};
123
124#ifdef KERNEL_PRIVATE
125#define	IF_MAXUNIT	0x7fff	/* historical value */
126
127struct if_clonereq64 {
128	int	ifcr_total;		/* total cloners (out) */
129	int	ifcr_count;		/* room for this many in user buffer */
130	user64_addr_t ifcru_buffer	__attribute__((aligned(8)));
131};
132
133struct if_clonereq32 {
134	int	ifcr_total;		/* total cloners (out) */
135	int	ifcr_count;		/* room for this many in user buffer */
136	user32_addr_t ifcru_buffer;
137};
138#endif /* KERNEL_PRIVATE */
139
140#define	IFF_UP		0x1		/* interface is up */
141#define	IFF_BROADCAST	0x2		/* broadcast address valid */
142#define	IFF_DEBUG	0x4		/* turn on debugging */
143#define	IFF_LOOPBACK	0x8		/* is a loopback net */
144#define	IFF_POINTOPOINT	0x10		/* interface is point-to-point link */
145#define	IFF_NOTRAILERS	0x20		/* obsolete: avoid use of trailers */
146#define	IFF_RUNNING	0x40		/* resources allocated */
147#define	IFF_NOARP	0x80		/* no address resolution protocol */
148#define	IFF_PROMISC	0x100		/* receive all packets */
149#define	IFF_ALLMULTI	0x200		/* receive all multicast packets */
150#define	IFF_OACTIVE	0x400		/* transmission in progress */
151#define	IFF_SIMPLEX	0x800		/* can't hear own transmissions */
152#define	IFF_LINK0	0x1000		/* per link layer defined bit */
153#define	IFF_LINK1	0x2000		/* per link layer defined bit */
154#define	IFF_LINK2	0x4000		/* per link layer defined bit */
155#define	IFF_ALTPHYS	IFF_LINK2	/* use alternate physical connection */
156#define	IFF_MULTICAST	0x8000		/* supports multicast */
157
158#ifdef PRIVATE
159/* extended flags definitions:  (all bits reserved for internal/future use) */
160#define	IFEF_AUTOCONFIGURING	0x00000001	/* allow BOOTP/DHCP replies to enter */
161#define	IFEF_IPV6_DISABLED	0x00000020	/* coupled to ND6_IFF_IFDISABLED */
162#define	IFEF_ACCEPT_RTADV	0x00000040	/* accepts IPv6 RA on the interface */
163#define	IFEF_TXSTART		0x00000080	/* has start callback */
164#define	IFEF_RXPOLL		0x00000100	/* supports opportunistic input poll */
165#define	IFEF_VLAN		0x00000200	/* interface has one or more vlans */
166#define	IFEF_BOND		0x00000400	/* interface is part of bond */
167#define	IFEF_ARPLL		0x00000800	/* ARP for IPv4LL addresses */
168#define	IFEF_NOWINDOWSCALE	0x00001000	/* Don't scale TCP window on iface */
169#define	IFEF_NOAUTOIPV6LL	0x00002000	/* Need explicit IPv6 LL address */
170#define	IFEF_EXPENSIVE		0x00004000	/* Data access has a cost */
171#define	IFEF_IPV4_ROUTER	0x00008000	/* interior when in IPv4 router mode */
172#define	IFEF_IPV6_ROUTER	0x00010000	/* interior when in IPv6 router mode */
173#define	IFEF_LOCALNET_PRIVATE	0x00020000	/* local private network */
174#define	IFEF_SERVICE_TRIGGERED	IFEF_LOCALNET_PRIVATE
175#define	IFEF_IPV6_ND6ALT	0x00040000	/* alternative. KPI for ND6 */
176#define	IFEF_RESTRICTED_RECV	0x00080000	/* interface restricts inbound pkts */
177#define	IFEF_AWDL		0x00100000	/* Apple Wireless Direct Link */
178#define	IFEF_NOACKPRI		0x00200000	/* No TCP ACK prioritization */
179#define	IFEF_AWDL_RESTRICTED	0x00400000	/* Restricted AWDL mode */
180#define	IFEF_2KCL		0x00800000	/* prefers 2K cluster (socket based tunnel) */
181#define	IFEF_SENDLIST		0x10000000	/* Supports tx packet lists */
182#define	IFEF_DIRECTLINK		0x20000000	/* point-to-point topology */
183#define	_IFEF_INUSE		0x40000000	/* deprecated */
184#define	IFEF_UPDOWNCHANGE	0x80000000	/* up/down state is changing */
185#ifdef XNU_KERNEL_PRIVATE
186/*
187 * Current requirements for an AWDL interface.  Setting/clearing IFEF_AWDL
188 * will also trigger the setting/clearing of the rest of the flags.  Once
189 * IFEF_AWDL is set, the rest of flags cannot be cleared, by definition.
190 */
191#define	IFEF_AWDL_MASK \
192	(IFEF_LOCALNET_PRIVATE | IFEF_IPV6_ND6ALT | IFEF_RESTRICTED_RECV | \
193	IFEF_AWDL)
194#endif /* XNU_KERNEL_PRIVATE */
195#endif /* PRIVATE */
196
197#ifdef KERNEL_PRIVATE
198/*
199 * !!! NOTE !!!
200 *
201 * if_idle_flags definitions: (all bits are reserved for internal/future
202 * use). Setting these flags MUST be done via the ifnet_set_idle_flags()
203 * KPI due to the associated reference counting.  Clearing them may be done by
204 * calling the KPI, otherwise implicitly at interface detach time.  Setting
205 * the if_idle_flags field to a non-zero value will cause the networking
206 * stack to aggressively purge expired objects (routes, etc.)
207 */
208#define	IFRF_IDLE_NOTIFY	0x1	/* Generate notifications on idle */
209
210/* flags set internally only: */
211#define	IFF_CANTCHANGE \
212	(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
213	    IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
214#endif /* KERNEL_PRIVATE */
215
216/*
217 * Capabilities that interfaces can advertise.
218 *
219 * struct ifnet.if_capabilities
220 *   contains the optional features & capabilities a particular interface
221 *   supports (not only the driver but also the detected hw revision).
222 *   Capabilities are defined by IFCAP_* below.
223 * struct ifnet.if_capenable
224 *   contains the enabled (either by default or through ifconfig) optional
225 *   features & capabilities on this interface.
226 *   Capabilities are defined by IFCAP_* below.
227 * struct if_data.ifi_hwassist in IFNET_* form, defined in net/kpi_interface.h,
228 *   contains the enabled optional features & capabilites that can be used
229 *   individually per packet and are specified in the mbuf pkthdr.csum_flags
230 *   field.  IFCAP_* and IFNET_* do not match one to one and IFNET_* may be
231 *   more detailed or differenciated than IFCAP_*.
232 *   IFNET_* hwassist flags have corresponding CSUM_* in sys/mbuf.h
233 */
234#define	IFCAP_RXCSUM		0x00001	/* can offload checksum on RX */
235#define	IFCAP_TXCSUM		0x00002	/* can offload checksum on TX */
236#define	IFCAP_VLAN_MTU		0x00004	/* VLAN-compatible MTU */
237#define	IFCAP_VLAN_HWTAGGING	0x00008	/* hardware VLAN tag support */
238#define	IFCAP_JUMBO_MTU		0x00010	/* 9000 byte MTU supported */
239#define	IFCAP_TSO4		0x00020	/* can do TCP Segmentation Offload */
240#define	IFCAP_TSO6		0x00040	/* can do TCP6 Segmentation Offload */
241#define	IFCAP_LRO		0x00080	/* can do Large Receive Offload */
242#define	IFCAP_AV		0x00100	/* can do 802.1 AV Bridging */
243#define	IFCAP_TXSTATUS		0x00200	/* can return linklevel xmit status */
244
245#define	IFCAP_HWCSUM	(IFCAP_RXCSUM | IFCAP_TXCSUM)
246#define	IFCAP_TSO	(IFCAP_TSO4 | IFCAP_TSO6)
247
248#define	IFCAP_VALID (IFCAP_HWCSUM | IFCAP_TSO | IFCAP_LRO | IFCAP_VLAN_MTU | \
249	IFCAP_VLAN_HWTAGGING | IFCAP_JUMBO_MTU | IFCAP_AV | IFCAP_TXSTATUS)
250
251#define	IFQ_MAXLEN	128
252#define	IFNET_SLOWHZ	1	/* granularity is 1 second */
253#define	IFQ_TARGET_DELAY	(10ULL * 1000 * 1000)	/* 10 ms */
254#define	IFQ_UPDATE_INTERVAL	(100ULL * 1000 * 1000)	/* 100 ms */
255
256/*
257 * Message format for use in obtaining information about interfaces
258 * from sysctl and the routing socket
259 */
260struct if_msghdr {
261	unsigned short	ifm_msglen;	/* to skip non-understood messages */
262	unsigned char	ifm_version;	/* future binary compatability */
263	unsigned char	ifm_type;	/* message type */
264	int		ifm_addrs;	/* like rtm_addrs */
265	int		ifm_flags;	/* value of if_flags */
266	unsigned short	ifm_index;	/* index for associated ifp */
267	struct	if_data ifm_data;	/* statistics and other data about if */
268};
269
270/*
271 * Message format for use in obtaining information about interface addresses
272 * from sysctl and the routing socket
273 */
274struct ifa_msghdr {
275	unsigned short	ifam_msglen;	/* to skip non-understood messages */
276	unsigned char	ifam_version;	/* future binary compatability */
277	unsigned char	ifam_type;	/* message type */
278	int		ifam_addrs;	/* like rtm_addrs */
279	int		ifam_flags;	/* value of ifa_flags */
280	unsigned short	ifam_index;	/* index for associated ifp */
281	int		ifam_metric;	/* value of ifa_metric */
282};
283
284/*
285 * Message format for use in obtaining information about multicast addresses
286 * from the routing socket
287 */
288struct ifma_msghdr {
289	unsigned short	ifmam_msglen;	/* to skip non-understood messages */
290	unsigned char	ifmam_version;	/* future binary compatability */
291	unsigned char	ifmam_type;	/* message type */
292	int		ifmam_addrs;	/* like rtm_addrs */
293	int		ifmam_flags;	/* value of ifa_flags */
294	unsigned short	ifmam_index;	/* index for associated ifp */
295};
296
297/*
298 * Message format for use in obtaining information about interfaces
299 * from sysctl
300 */
301struct if_msghdr2 {
302	u_short	ifm_msglen;	/* to skip over non-understood messages */
303	u_char	ifm_version;	/* future binary compatability */
304	u_char	ifm_type;	/* message type */
305	int	ifm_addrs;	/* like rtm_addrs */
306	int	ifm_flags;	/* value of if_flags */
307	u_short	ifm_index;	/* index for associated ifp */
308	int	ifm_snd_len;	/* instantaneous length of send queue */
309	int	ifm_snd_maxlen;	/* maximum length of send queue */
310	int	ifm_snd_drops;	/* number of drops in send queue */
311	int	ifm_timer;	/* time until if_watchdog called */
312	struct if_data64	ifm_data;	/* statistics and other data */
313};
314
315/*
316 * Message format for use in obtaining information about multicast addresses
317 * from sysctl
318 */
319struct ifma_msghdr2 {
320	u_short	ifmam_msglen;	/* to skip over non-understood messages */
321	u_char	ifmam_version;	/* future binary compatability */
322	u_char	ifmam_type;	/* message type */
323	int	ifmam_addrs;	/* like rtm_addrs */
324	int	ifmam_flags;	/* value of ifa_flags */
325	u_short	ifmam_index;	/* index for associated ifp */
326	int32_t ifmam_refcount;
327};
328
329/*
330 * ifdevmtu: interface device mtu
331 *    Used with SIOCGIFDEVMTU to get the current mtu in use by the device,
332 *    as well as the minimum and maximum mtu allowed by the device.
333 */
334struct ifdevmtu {
335	int	ifdm_current;
336	int	ifdm_min;
337	int	ifdm_max;
338};
339
340#pragma pack(4)
341
342/*
343 ifkpi: interface kpi ioctl
344 Used with SIOCSIFKPI and SIOCGIFKPI.
345
346 ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From
347 	user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket.
348 ifk_type - The type. Types are specific to each module id.
349 ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes.
350
351 Copying data between user space and kernel space is done using copyin
352 and copyout. A process may be running in 64bit mode. In such a case,
353 the pointer will be a 64bit pointer, not a 32bit pointer. The following
354 sample is a safe way to copy the data in to the kernel from either a
355 32bit or 64bit process:
356
357 user_addr_t tmp_ptr;
358 if (IS_64BIT_PROCESS(current_proc())) {
359 	tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64);
360 }
361 else {
362 	tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr);
363 }
364 error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer);
365 */
366
367struct ifkpi {
368	unsigned int	ifk_module_id;
369	unsigned int	ifk_type;
370	union {
371		void		*ifk_ptr;
372		int		ifk_value;
373#ifdef KERNEL
374		u_int64_t	ifk_ptr64;
375#endif /* KERNEL */
376	} ifk_data;
377};
378
379/* Wake capabilities of a interface */
380#define	IF_WAKE_ON_MAGIC_PACKET 	0x01
381#ifdef KERNEL_PRIVATE
382#define	IF_WAKE_VALID_FLAGS IF_WAKE_ON_MAGIC_PACKET
383#endif /* KERNEL_PRIVATE */
384
385
386#pragma pack()
387
388/*
389 * Interface request structure used for socket
390 * ioctl's.  All interface ioctl's must have parameter
391 * definitions which begin with ifr_name.  The
392 * remainder may be interface specific.
393 */
394struct	ifreq {
395#ifndef IFNAMSIZ
396#define	IFNAMSIZ	IF_NAMESIZE
397#endif
398	char	ifr_name[IFNAMSIZ];		/* if name, e.g. "en0" */
399	union {
400		struct	sockaddr ifru_addr;
401		struct	sockaddr ifru_dstaddr;
402		struct	sockaddr ifru_broadaddr;
403		short	ifru_flags;
404		int	ifru_metric;
405		int	ifru_mtu;
406		int	ifru_phys;
407		int	ifru_media;
408		int	ifru_intval;
409		caddr_t	ifru_data;
410#ifdef KERNEL_PRIVATE
411		u_int64_t ifru_data64;	/* 64-bit ifru_data */
412#endif /* KERNEL_PRIVATE */
413		struct	ifdevmtu ifru_devmtu;
414		struct	ifkpi	ifru_kpi;
415		u_int32_t ifru_wake_flags;
416		u_int32_t ifru_route_refcnt;
417#ifdef PRIVATE
418		int	ifru_link_quality_metric;
419#endif /* PRIVATE */
420		int	ifru_cap[2];
421#ifdef PRIVATE
422		struct {
423			uint32_t	ifo_flags;
424#define	IFRIFOF_BLOCK_OPPORTUNISTIC	0x00000001
425			uint32_t	ifo_inuse;
426		} ifru_opportunistic;
427		u_int64_t ifru_eflags;
428		struct {
429			int32_t		ifl_level;
430			uint32_t	ifl_flags;
431#define	IFRLOGF_DLIL			0x00000001
432#define	IFRLOGF_FAMILY			0x00010000
433#define	IFRLOGF_DRIVER			0x01000000
434#define	IFRLOGF_FIRMWARE		0x10000000
435			int32_t		ifl_category;
436#define	IFRLOGCAT_CONNECTIVITY		1
437#define	IFRLOGCAT_QUALITY		2
438#define	IFRLOGCAT_PERFORMANCE		3
439			int32_t		ifl_subcategory;
440		} ifru_log;
441		u_int32_t ifru_delegated;
442		struct {
443			uint32_t	ift_type;
444			uint32_t	ift_family;
445#define	IFRTYPE_FAMILY_ANY		0
446#define	IFRTYPE_FAMILY_LOOPBACK		1
447#define	IFRTYPE_FAMILY_ETHERNET		2
448#define	IFRTYPE_FAMILY_SLIP		3
449#define	IFRTYPE_FAMILY_TUN		4
450#define	IFRTYPE_FAMILY_VLAN		5
451#define	IFRTYPE_FAMILY_PPP		6
452#define	IFRTYPE_FAMILY_PVC		7
453#define	IFRTYPE_FAMILY_DISC		8
454#define	IFRTYPE_FAMILY_MDECAP		9
455#define	IFRTYPE_FAMILY_GIF		10
456#define	IFRTYPE_FAMILY_FAITH		11
457#define	IFRTYPE_FAMILY_STF		12
458#define	IFRTYPE_FAMILY_FIREWIRE		13
459#define	IFRTYPE_FAMILY_BOND		14
460#define	IFRTYPE_FAMILY_CELLULAR		15
461			uint32_t	ift_subfamily;
462#define	IFRTYPE_SUBFAMILY_ANY		0
463#define	IFRTYPE_SUBFAMILY_USB		1
464#define	IFRTYPE_SUBFAMILY_BLUETOOTH	2
465#define	IFRTYPE_SUBFAMILY_WIFI		3
466#define	IFRTYPE_SUBFAMILY_THUNDERBOLT	4
467#define	IFRTYPE_SUBFAMILY_RESERVED	5
468		} ifru_type;
469		u_int32_t ifru_expensive;
470		u_int32_t ifru_awdl_restricted;
471		u_int32_t ifru_2kcl;
472#endif /* PRIVATE */
473	} ifr_ifru;
474#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
475#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
476#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
477#ifdef __APPLE__
478#define	ifr_flags	ifr_ifru.ifru_flags	/* flags */
479#else
480#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags */
481#define	ifr_prevflags	ifr_ifru.ifru_flags[1]	/* flags */
482#endif /* __APPLE__ */
483#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
484#define	ifr_mtu		ifr_ifru.ifru_mtu	/* mtu */
485#define	ifr_phys	ifr_ifru.ifru_phys	/* physical wire */
486#define	ifr_media	ifr_ifru.ifru_media	/* physical media */
487#define	ifr_data	ifr_ifru.ifru_data	/* for use by interface */
488#define	ifr_devmtu	ifr_ifru.ifru_devmtu
489#define	ifr_intval	ifr_ifru.ifru_intval	/* integer value */
490#ifdef KERNEL_PRIVATE
491#define	ifr_data64	ifr_ifru.ifru_data64	/* 64-bit pointer */
492#endif /* KERNEL_PRIVATE */
493#define	ifr_kpi		ifr_ifru.ifru_kpi
494#define	ifr_wake_flags	ifr_ifru.ifru_wake_flags /* wake capabilities */
495#define	ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references count */
496#ifdef PRIVATE
497#define	ifr_link_quality_metric ifr_ifru.ifru_link_quality_metric /* LQM */
498#endif /* PRIVATE */
499#define	ifr_reqcap	ifr_ifru.ifru_cap[0]	/* requested capabilities */
500#define	ifr_curcap	ifr_ifru.ifru_cap[1]	/* current capabilities */
501#ifdef PRIVATE
502#define	ifr_opportunistic	ifr_ifru.ifru_opportunistic
503#define	ifr_eflags	ifr_ifru.ifru_eflags	/* extended flags  */
504#define	ifr_log		ifr_ifru.ifru_log	/* logging level/flags */
505#define	ifr_delegated	ifr_ifru.ifru_delegated /* delegated interface index */
506#define	ifr_expensive	ifr_ifru.ifru_expensive
507#define	ifr_type	ifr_ifru.ifru_type	/* interface type */
508#define	ifr_awdl_restricted ifr_ifru.ifru_awdl_restricted
509#define	ifr_2kcl	ifr_ifru.ifru_2kcl
510#endif /* PRIVATE */
511};
512
513#define	_SIZEOF_ADDR_IFREQ(ifr) \
514	((ifr).ifr_addr.sa_len > sizeof (struct sockaddr) ? \
515	(sizeof (struct ifreq) - sizeof (struct sockaddr) + \
516	(ifr).ifr_addr.sa_len) : sizeof (struct ifreq))
517
518struct ifaliasreq {
519	char	ifra_name[IFNAMSIZ];		/* if name, e.g. "en0" */
520	struct	sockaddr ifra_addr;
521	struct	sockaddr ifra_broadaddr;
522	struct	sockaddr ifra_mask;
523};
524
525struct rslvmulti_req {
526	struct sockaddr *sa;
527	struct sockaddr **llsa;
528};
529
530#if !defined(KERNEL) || defined(KERNEL_PRIVATE)
531#pragma pack(4)
532
533struct ifmediareq {
534	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
535	int	ifm_current;		/* current media options */
536	int	ifm_mask;		/* don't care mask */
537	int	ifm_status;		/* media status */
538	int	ifm_active;		/* active options */
539	int	ifm_count;		/* # entries in ifm_ulist array */
540	int	*ifm_ulist;		/* media words */
541};
542
543#pragma pack()
544#endif /* !KERNEL || KERNEL_PRIVATE */
545
546#ifdef KERNEL_PRIVATE
547#pragma pack(4)
548struct ifmediareq64 {
549	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
550	int	ifm_current;		/* current media options */
551	int	ifm_mask;		/* don't care mask */
552	int	ifm_status;		/* media status */
553	int	ifm_active;		/* active options */
554	int	ifm_count;		/* # entries in ifm_ulist array */
555	user64_addr_t ifmu_ulist __attribute__((aligned(8)));
556};
557
558struct ifmediareq32 {
559	char	ifm_name[IFNAMSIZ];	/* if name, e.g. "en0" */
560	int	ifm_current;		/* current media options */
561	int	ifm_mask;		/* don't care mask */
562	int	ifm_status;		/* media status */
563	int	ifm_active;		/* active options */
564	int	ifm_count;		/* # entries in ifm_ulist array */
565	user32_addr_t ifmu_ulist;	/* 32-bit pointer */
566};
567#pragma pack()
568#endif /* KERNEL_PRIVATE */
569
570
571#pragma pack(4)
572struct  ifdrv {
573	char		ifd_name[IFNAMSIZ];	/* if name, e.g. "en0" */
574	unsigned long	ifd_cmd;
575	size_t		ifd_len;		/* length of ifd_data buffer */
576	void		*ifd_data;
577};
578#pragma pack()
579
580#ifdef KERNEL_PRIVATE
581#pragma pack(4)
582struct ifdrv32 {
583	char		ifd_name[IFNAMSIZ];	/* if name, e.g. "en0" */
584	u_int32_t	ifd_cmd;
585	u_int32_t	ifd_len;
586	user32_addr_t	ifd_data;
587};
588
589struct  ifdrv64 {
590	char		ifd_name[IFNAMSIZ];	/* if name, e.g. "en0" */
591	u_int64_t	ifd_cmd;
592	u_int64_t	ifd_len;
593	user64_addr_t	ifd_data;
594};
595#pragma pack()
596#endif /* KERNEL_PRIVATE */
597
598/*
599 * Structure used to retrieve aux status data from interfaces.
600 * Kernel suppliers to this interface should respect the formatting
601 * needed by ifconfig(8): each line starts with a TAB and ends with
602 * a newline.
603 */
604
605#define	IFSTATMAX	800		/* 10 lines of text */
606struct ifstat {
607	char	ifs_name[IFNAMSIZ];	/* if name, e.g. "en0" */
608	char	ascii[IFSTATMAX + 1];
609};
610
611#if !defined(KERNEL) || defined(KERNEL_PRIVATE)
612/*
613 * Structure used in SIOCGIFCONF request.
614 * Used to retrieve interface configuration
615 * for machine (useful for programs which
616 * must know all networks accessible).
617 */
618#pragma pack(4)
619struct	ifconf {
620	int	ifc_len;		/* size of associated buffer */
621	union {
622		caddr_t	ifcu_buf;
623		struct	ifreq *ifcu_req;
624	} ifc_ifcu;
625};
626#pragma pack()
627#define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
628#define	ifc_req	ifc_ifcu.ifcu_req	/* array of structures returned */
629#endif /* !KERNEL || KERNEL_PRIVATE */
630
631#if defined(KERNEL_PRIVATE)
632#pragma pack(4)
633struct ifconf32 {
634	int	ifc_len;		/* size of associated buffer */
635	struct {
636		user32_addr_t ifcu_req;
637	} ifc_ifcu;
638};
639
640struct ifconf64 {
641	int	ifc_len;		/* size of associated buffer */
642	struct {
643		user64_addr_t ifcu_req	__attribute__((aligned(8)));
644	} ifc_ifcu;
645};
646#pragma pack()
647#endif /* KERNEL_PRIVATE */
648
649/*
650 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure
651 */
652struct kev_dl_proto_data {
653	struct net_event_data   	link_data;
654	u_int32_t			proto_family;
655	u_int32_t			proto_remaining_count;
656};
657
658#ifdef PRIVATE
659/*
660 * Link Quality Metrics
661 *
662 *	IFNET_LQM_THRESH_OFF      Metric is not available; device is off.
663 *	IFNET_LQM_THRESH_UNKNOWN  Metric is not (yet) known.
664 *	IFNET_LQM_THRESH_BAD	  Link quality is considered bad by driver.
665 *	IFNET_LQM_THRESH_POOR     Link quality is considered poor by driver.
666 *	IFNET_LQM_THRESH_GOOD     Link quality is considered good by driver.
667 */
668enum {
669	IFNET_LQM_THRESH_OFF		= (-2),
670	IFNET_LQM_THRESH_UNKNOWN	= (-1),
671	IFNET_LQM_THRESH_BAD		= 10,
672	IFNET_LQM_THRESH_POOR		= 50,
673	IFNET_LQM_THRESH_GOOD		= 100
674};
675#ifdef XNU_KERNEL_PRIVATE
676#define	IFNET_LQM_MIN	IFNET_LQM_THRESH_OFF
677#define	IFNET_LQM_MAX	IFNET_LQM_THRESH_GOOD
678#endif /* XNU_KERNEL_PRIVATE */
679
680/*
681 * DLIL KEV_DL_LINK_QUALITY_METRIC_CHANGED structure
682 */
683struct kev_dl_link_quality_metric_data {
684	struct net_event_data	link_data;
685	int			link_quality_metric;
686};
687
688#define	IF_DESCSIZE	128
689
690/*
691 * Structure for SIOC[SG]IFDESC
692 */
693struct if_descreq {
694	char			ifdr_name[IFNAMSIZ];	/* interface name */
695	u_int32_t		ifdr_len;		/* up to IF_DESCSIZE */
696	u_int8_t		ifdr_desc[IF_DESCSIZE];	/* opaque data */
697};
698
699/*
700 *	Output packet scheduling models
701 *
702 *	IFNET_SCHED_MODEL_NORMAL The default output packet scheduling model
703 *		where the driver or media does not require strict scheduling
704 *		strategy, and that the networking stack is free to choose the
705 *		most appropriate scheduling and queueing algorithm, including
706 *		shaping traffics.
707 *	IFNET_SCHED_MODEL_DRIVER_MANAGED The alternative output packet
708 *		scheduling model where the driver or media requires strict
709 *		scheduling strategy (e.g. 802.11 WMM), and that the networking
710 *		stack is only responsible for creating multiple queues for the
711 *		corresponding service classes.
712 */
713enum {
714	IFNET_SCHED_MODEL_NORMAL		= 0,
715	IFNET_SCHED_MODEL_DRIVER_MANAGED	= 1,
716#ifdef XNU_KERNEL_PRIVATE
717	IFNET_SCHED_MODEL_MAX			= 2,
718#endif /* XNU_KERNEL_PRIVATE */
719};
720
721/*
722 * Values for iflpr_flags
723 */
724#define	IFLPRF_ALTQ		0x1	/* configured via PF/ALTQ */
725#define	IFLPRF_DRVMANAGED	0x2	/* output queue scheduled by drv */
726
727/*
728 * Structure for SIOCGIFLINKPARAMS
729 */
730struct if_linkparamsreq {
731	char		iflpr_name[IFNAMSIZ];	/* interface name */
732	u_int32_t	iflpr_flags;
733	u_int32_t	iflpr_output_sched;
734	u_int64_t	iflpr_output_tbr_rate;
735	u_int32_t	iflpr_output_tbr_percent;
736	struct if_bandwidths iflpr_output_bw;
737	struct if_bandwidths iflpr_input_bw;
738	struct if_latencies iflpr_output_lt;
739	struct if_latencies iflpr_input_lt;
740};
741
742/*
743 * Structure for SIOCGIFQUEUESTATS
744 */
745struct if_qstatsreq {
746	char		ifqr_name[IFNAMSIZ];	/* interface name */
747	u_int32_t	ifqr_slot;
748	void		*ifqr_buf		__attribute__((aligned(8)));
749	int		 ifqr_len		__attribute__((aligned(8)));
750};
751
752/*
753 * Node Proximity Metrics
754 */
755enum {
756	IFNET_NPM_THRESH_UNKNOWN	= (-1),
757	IFNET_NPM_THRESH_NEAR		= 30,
758	IFNET_NPM_THRESH_GENERAL	= 70,
759	IFNET_NPM_THRESH_FAR		= 100,
760};
761
762/*
763 *	Received Signal Strength Indication [special values]
764 *
765 *	IFNET_RSSI_UNKNOWN	Metric is not (yet) known.
766 */
767enum {
768	IFNET_RSSI_UNKNOWN	= ((-2147483647)-1),	/* INT32_MIN */
769};
770
771
772/*
773 * DLIL KEV_DL_NODE_PRESENCE/KEV_DL_NODE_ABSENCE event structures
774 */
775struct kev_dl_node_presence {
776	struct net_event_data   link_data;
777	struct sockaddr_in6	sin6_node_address;
778	struct sockaddr_dl	sdl_node_address;
779	int32_t			rssi;
780	int			link_quality_metric;
781	int			node_proximity_metric;
782	u_int8_t		node_service_info[48];
783};
784
785struct kev_dl_node_absence {
786	struct net_event_data   link_data;
787	struct sockaddr_in6	sin6_node_address;
788	struct sockaddr_dl	sdl_node_address;
789};
790
791/*
792 * Structure for SIOC[SG]IFTHROTTLE
793 */
794struct if_throttlereq {
795	char		ifthr_name[IFNAMSIZ];	/* interface name */
796	u_int32_t	ifthr_level;
797};
798
799/*
800 *	Interface throttling levels
801 *
802 *	IFNET_THROTTLE_OFF The default throttling level (no throttling.)
803 *		All service class queues operate normally according to the
804 *		standard packet scheduler configuration.
805 *	IFNET_THROTTLE_OPPORTUNISTIC One or more service class queues that
806 *		are responsible for managing "opportunistic" traffics are
807 *		suspended.  Packets enqueued on those queues will be dropped
808 *		and a flow advisory error will be generated to the data
809 *		source.  Existing packets in the queues will stay enqueued
810 *		until the interface is no longer throttled, or until they
811 *		are explicitly flushed.
812 */
813enum {
814	IFNET_THROTTLE_OFF			= 0,
815	IFNET_THROTTLE_OPPORTUNISTIC		= 1,
816#ifdef XNU_KERNEL_PRIVATE
817	IFNET_THROTTLE_MAX			= 2,
818#endif /* XNU_KERNEL_PRIVATE */
819};
820
821#define	DLIL_MODIDLEN	20	/* same as IFNET_MODIDLEN */
822#define	DLIL_MODARGLEN	12	/* same as IFNET_MODARGLEN */
823
824/*
825 * DLIL KEV_DL_ISSUES event structure
826 */
827struct kev_dl_issues {
828	struct net_event_data   link_data;
829	u_int8_t		modid[DLIL_MODIDLEN];
830	u_int64_t		timestamp;
831	u_int8_t		info[DLIL_MODARGLEN];
832};
833#endif /* PRIVATE */
834
835#ifdef KERNEL
836#ifdef MALLOC_DECLARE
837MALLOC_DECLARE(M_IFADDR);
838MALLOC_DECLARE(M_IFMADDR);
839#endif
840#endif
841#endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
842
843#ifndef KERNEL
844struct if_nameindex {
845	unsigned int	 if_index;	/* 1, 2, ... */
846	char		*if_name;	/* null terminated name: "le0", ... */
847};
848
849__BEGIN_DECLS
850unsigned int	 if_nametoindex(const char *);
851char		*if_indextoname(unsigned int, char *);
852struct		 if_nameindex *if_nameindex(void);
853void		 if_freenameindex(struct if_nameindex *);
854__END_DECLS
855#endif
856
857#ifdef KERNEL
858#include <net/kpi_interface.h>
859#endif
860
861#endif /* !_NET_IF_H_ */
862