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