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