1 /*
2 * Copyright (c) 2000-2023 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_PRIVATE_H_
64 #define _NET_IF_PRIVATE_H_
65
66 #include <mach/vm_types.h>
67 #include <net/if.h>
68 #include <net/if_dl.h>
69 #include <net/if_var.h>
70 #include <net/if_var_private.h>
71 #include <netinet/in.h>
72 #include <sys/types.h>
73 #include <uuid/uuid.h>
74
75 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
76 #ifndef DRIVERKIT
77 #ifdef KERNEL_PRIVATE
78 #define IF_MAXUNIT 0x7fff /* historical value */
79
80 struct if_clonereq64 {
81 int ifcr_total; /* total cloners (out) */
82 int ifcr_count; /* room for this many in user buffer */
83 user64_addr_t ifcru_buffer __attribute__((aligned(8)));
84 };
85
86 struct if_clonereq32 {
87 int ifcr_total; /* total cloners (out) */
88 int ifcr_count; /* room for this many in user buffer */
89 user32_addr_t ifcru_buffer;
90 };
91 #endif /* KERNEL_PRIVATE */
92
93 /* extended flags definitions: (all bits reserved for internal/future use) */
94 #define IFEF_AUTOCONFIGURING 0x00000001 /* allow BOOTP/DHCP replies to enter */
95 #define IFEF_ENQUEUE_MULTI 0x00000002 /* enqueue multiple packets at once */
96 #define IFEF_DELAY_START 0x00000004 /* delay start callback */
97 #define IFEF_PROBE_CONNECTIVITY 0x00000008 /* Probe connections going over this interface */
98 #define IFEF_ADV_REPORT 0x00000010 /* Supports interface advisory report */
99 #define IFEF_IPV6_DISABLED 0x00000020 /* coupled to ND6_IFF_IFDISABLED */
100 #define IFEF_ACCEPT_RTADV 0x00000040 /* accepts IPv6 RA on the interface */
101 #define IFEF_TXSTART 0x00000080 /* has start callback */
102 #define IFEF_RXPOLL 0x00000100 /* supports opportunistic input poll */
103 #define IFEF_VLAN 0x00000200 /* interface has one or more vlans */
104 #define IFEF_BOND 0x00000400 /* interface is part of bond */
105 #define IFEF_ARPLL 0x00000800 /* ARP for IPv4LL addresses */
106 #define IFEF_CLAT46 0x00001000 /* CLAT46 RFC 6877 */
107
108 #define IS_INTF_CLAT46(ifp) ((ifp) != NULL && ((ifp)->if_eflags & IFEF_CLAT46))
109 #define INTF_ADJUST_MTU_FOR_CLAT46(intf) \
110 (IS_INTF_CLAT46((intf)) || \
111 IS_INTF_CLAT46((intf)->if_delegated.ifp)) \
112
113 /*
114 * XXX IFEF_NOAUTOIPV6LL is deprecated and should be done away with.
115 * Configd pretty much manages the interface configuration.
116 * Rather than looking at the flag we check if a specific LLA
117 * has to be configured or the IID has to be generated by kernel.
118 */
119 #define IFEF_NOAUTOIPV6LL 0x00002000 /* Need explicit IPv6 LL address */
120 #define IFEF_EXPENSIVE 0x00004000 /* Data access has a cost */
121 #define IFEF_IPV4_ROUTER 0x00008000 /* interior when in IPv4 router mode */
122 #define IFEF_CLONE 0x00010000 /* created using if_clone */
123 #define IFEF_LOCALNET_PRIVATE 0x00020000 /* local private network */
124 #define IFEF_SERVICE_TRIGGERED IFEF_LOCALNET_PRIVATE
125 #define IFEF_IPV6_ND6ALT 0x00040000 /* alternative. KPI for ND6 */
126 #define IFEF_RESTRICTED_RECV 0x00080000 /* interface restricts inbound pkts */
127 #define IFEF_AWDL 0x00100000 /* Apple Wireless Direct Link */
128 #define IFEF_NOACKPRI 0x00200000 /* No TCP ACK prioritization */
129 #define IFEF_AWDL_RESTRICTED 0x00400000 /* Restricted AWDL mode */
130 #define IFEF_2KCL 0x00800000 /* prefers 2K cluster (socket based tunnel) */
131 #define IFEF_UNUSED1 0x01000000
132 #define IFEF_UNUSED2 0x02000000
133 #define IFEF_SKYWALK_NATIVE 0x04000000 /* Native Skywalk support */
134 #define IFEF_3CA 0x08000000 /* Capable of 3CA */
135 #define IFEF_SENDLIST 0x10000000 /* Supports tx packet lists */
136 #define IFEF_DIRECTLINK 0x20000000 /* point-to-point topology */
137 #define IFEF_QOSMARKING_ENABLED 0x40000000 /* QoS marking is enabled */
138 #define IFEF_UPDOWNCHANGE 0x80000000 /* up/down state is changing */
139
140 #ifdef XNU_KERNEL_PRIVATE
141 /*
142 * Extra flags
143 */
144 #define IFXF_WAKE_ON_MAGIC_PACKET 0x00000001 /* wake on magic packet */
145 #define IFXF_TIMESTAMP_ENABLED 0x00000002 /* time stamping enabled */
146 #define IFXF_NX_NOAUTO 0x00000004 /* no auto config nexus */
147 #define IFXF_LEGACY 0x00000008 /* legacy (non-netif) mode */
148 #define IFXF_LOW_INTERNET_UL 0x00000010 /* Uplink Low Internet is confirmed */
149 #define IFXF_LOW_INTERNET_DL 0x00000020 /* Downlink Low Internet is confirmed */
150 #define IFXF_ALLOC_KPI 0x00000040 /* Allocated via the ifnet_alloc KPI */
151 #define IFXF_LOW_POWER 0x00000080 /* Low Power Mode */
152 #define IFXF_MPK_LOG 0x00000100 /* Multi-layer Packet Logging */
153 #define IFXF_CONSTRAINED 0x00000200 /* Constrained - Save Data Mode */
154 #define IFXF_LOW_LATENCY 0x00000400 /* Low latency interface */
155 #define IFXF_MARK_WAKE_PKT 0x00000800 /* Mark next input packet as wake packet */
156 #define IFXF_FAST_PKT_DELIVERY 0x00001000 /* Fast Packet Delivery */
157 #define IFXF_NO_TRAFFIC_SHAPING 0x00002000 /* Skip dummynet and netem traffic shaping */
158 #define IFXF_MANAGEMENT 0x00004000 /* Management interface */
159 #define IFXF_ULTRA_CONSTRAINED 0x00008000 /* Ultra constrained mode */
160 #define IFXF_IS_VPN 0x00010000 /* Is VPN */
161 #define IFXF_DELAYWAKEPKTEVENT 0x00020000 /* Delay notification of wake packet events */
162 #define IFXF_DISABLE_INPUT 0x00040000 /* Drop receive traffic */
163 #define IFXF_CONGESTED_LINK 0x00080000 /* Link is congested */
164 #define IFXF_IS_COMPANIONLINK 0x00100000 /* Is companion link */
165 #define IFXF_RX_FLOW_STEERING 0x00200000 /* Rx flow steering */
166 #define IFXF_LINK_HEURISTICS 0x00800000 /* Link heuristics enabled */
167 #define IFXF_LINK_HEUR_OFF_PENDING 0x01000000 /* Link heurisitics delay disable */
168 #define IFXF_POINTOPOINT_MDNS 0x02000000 /* Point-to-point interface supports mDNS */
169 #define IFXF_INBAND_WAKE_PKT_TAGGING 0x04000000 /* Inband tagging of packet wake flag */
170 #define IFXF_LOW_POWER_WAKE 0x08000000 /* Low Power Wake */
171 #define IFXF_REQUIRE_CELL_THREAD_GROUP 0x10000000 /* Require cellular thread group */
172
173 /*
174 * Current requirements for an AWDL interface. Setting/clearing IFEF_AWDL
175 * will also trigger the setting/clearing of the rest of the flags. Once
176 * IFEF_AWDL is set, the rest of flags cannot be cleared, by definition.
177 */
178 #define IFEF_AWDL_MASK \
179 (IFEF_LOCALNET_PRIVATE | IFEF_IPV6_ND6ALT | IFEF_RESTRICTED_RECV | \
180 IFEF_AWDL)
181 #endif /* XNU_KERNEL_PRIVATE */
182
183 #ifdef KERNEL_PRIVATE
184 /*
185 * !!! NOTE !!!
186 *
187 * if_idle_flags definitions: (all bits are reserved for internal/future
188 * use). Setting these flags MUST be done via the ifnet_set_idle_flags()
189 * KPI due to the associated reference counting. Clearing them may be done by
190 * calling the KPI, otherwise implicitly at interface detach time. Setting
191 * the if_idle_flags field to a non-zero value will cause the networking
192 * stack to aggressively purge expired objects (routes, etc.)
193 */
194 #define IFRF_IDLE_NOTIFY 0x1 /* Generate notifications on idle */
195
196 /* flags set internally only: */
197 #define IFF_CANTCHANGE \
198 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
199 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
200
201 #define IF_WAKE_VALID_FLAGS IF_WAKE_ON_MAGIC_PACKET
202 #endif /* KERNEL_PRIVATE */
203
204 #ifdef IFREQ_OPAQUE
205 /*
206 * This is the private version of the ifreq structure, the
207 * public version lives in if.h. If you make any changes
208 * here, you probably also need to make them in if.h!
209 */
210 struct ifreq {
211 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
212 union {
213 struct sockaddr ifru_addr;
214 struct sockaddr ifru_dstaddr;
215 struct sockaddr ifru_broadaddr;
216 short ifru_flags;
217 int ifru_metric;
218 int ifru_mtu;
219 int ifru_phys;
220 int ifru_media;
221 int ifru_intval;
222 caddr_t ifru_data;
223 #ifdef KERNEL_PRIVATE
224 u_int64_t ifru_data64; /* 64-bit ifru_data */
225 #endif /* KERNEL_PRIVATE */
226 struct ifdevmtu ifru_devmtu;
227 struct ifkpi ifru_kpi;
228 u_int32_t ifru_wake_flags;
229 u_int32_t ifru_route_refcnt;
230 int ifru_link_quality_metric;
231 int ifru_cap[2];
232 struct {
233 uint32_t ifo_flags;
234 #define IFRIFOF_BLOCK_OPPORTUNISTIC 0x00000001
235 uint32_t ifo_inuse;
236 } ifru_opportunistic;
237 u_int64_t ifru_eflags;
238 u_int64_t ifru_xflags;
239 struct {
240 int32_t ifl_level;
241 uint32_t ifl_flags;
242 #define IFRLOGF_DLIL 0x00000001
243 #define IFRLOGF_FAMILY 0x00010000
244 #define IFRLOGF_DRIVER 0x01000000
245 #define IFRLOGF_FIRMWARE 0x10000000
246 int32_t ifl_category;
247 #define IFRLOGCAT_CONNECTIVITY 1
248 #define IFRLOGCAT_QUALITY 2
249 #define IFRLOGCAT_PERFORMANCE 3
250 int32_t ifl_subcategory;
251 } ifru_log;
252 u_int32_t ifru_delegated;
253 struct {
254 uint32_t ift_type;
255 uint32_t ift_family;
256 #define IFRTYPE_FAMILY_ANY 0
257 #define IFRTYPE_FAMILY_LOOPBACK 1
258 #define IFRTYPE_FAMILY_ETHERNET 2
259 #define IFRTYPE_FAMILY_SLIP 3
260 #define IFRTYPE_FAMILY_TUN 4
261 #define IFRTYPE_FAMILY_VLAN 5
262 #define IFRTYPE_FAMILY_PPP 6
263 #define IFRTYPE_FAMILY_PVC 7
264 #define IFRTYPE_FAMILY_DISC 8
265 #define IFRTYPE_FAMILY_MDECAP 9
266 #define IFRTYPE_FAMILY_GIF 10
267 #define IFRTYPE_FAMILY_FAITH 11
268 #define IFRTYPE_FAMILY_STF 12
269 #define IFRTYPE_FAMILY_FIREWIRE 13
270 #define IFRTYPE_FAMILY_BOND 14
271 #define IFRTYPE_FAMILY_CELLULAR 15
272 #define IFRTYPE_FAMILY_UNUSED_16 16 /* Un-used */
273 #define IFRTYPE_FAMILY_UTUN 17
274 #define IFRTYPE_FAMILY_IPSEC 18
275 uint32_t ift_subfamily;
276 #define IFRTYPE_SUBFAMILY_ANY 0
277 #define IFRTYPE_SUBFAMILY_USB 1
278 #define IFRTYPE_SUBFAMILY_BLUETOOTH 2
279 #define IFRTYPE_SUBFAMILY_WIFI 3
280 #define IFRTYPE_SUBFAMILY_THUNDERBOLT 4
281 #define IFRTYPE_SUBFAMILY_RESERVED 5
282 #define IFRTYPE_SUBFAMILY_INTCOPROC 6
283 #define IFRTYPE_SUBFAMILY_QUICKRELAY 7
284 #define IFRTYPE_SUBFAMILY_DEFAULT 8
285 #define IFRTYPE_SUBFAMILY_VMNET 9
286 #define IFRTYPE_SUBFAMILY_SIMCELL 10
287 #define IFRTYPE_SUBFAMILY_REDIRECT 11
288 #define IFRTYPE_SUBFAMILY_MANAGEMENT 12
289 } ifru_type;
290 u_int32_t ifru_functional_type;
291 u_int32_t ifru_peer_egress_functional_type;
292 #define IFRTYPE_FUNCTIONAL_UNKNOWN 0
293 #define IFRTYPE_FUNCTIONAL_LOOPBACK 1
294 #define IFRTYPE_FUNCTIONAL_WIRED 2
295 #define IFRTYPE_FUNCTIONAL_WIFI_INFRA 3
296 #define IFRTYPE_FUNCTIONAL_WIFI_AWDL 4
297 #define IFRTYPE_FUNCTIONAL_CELLULAR 5
298 #define IFRTYPE_FUNCTIONAL_INTCOPROC 6
299 #define IFRTYPE_FUNCTIONAL_COMPANIONLINK 7
300 #define IFRTYPE_FUNCTIONAL_MANAGEMENT 8
301 #define IFRTYPE_FUNCTIONAL_LAST 8
302 u_int32_t ifru_expensive;
303 u_int32_t ifru_constrained;
304 u_int32_t ifru_2kcl;
305 struct {
306 u_int32_t qlen;
307 u_int32_t timeout;
308 } ifru_start_delay;
309 struct if_interface_state ifru_interface_state;
310 u_int32_t ifru_probe_connectivity;
311 u_int32_t ifru_ecn_mode;
312 #define IFRTYPE_ECN_DEFAULT 0
313 #define IFRTYPE_ECN_ENABLE 1
314 #define IFRTYPE_ECN_DISABLE 2
315 uint32_t ifru_l4s_mode;
316 #define IFRTYPE_L4S_DEFAULT 0
317 #define IFRTYPE_L4S_ENABLE 1
318 #define IFRTYPE_L4S_DISABLE 2
319 u_int32_t ifru_qosmarking_mode;
320 #define IFRTYPE_QOSMARKING_MODE_NONE 0
321 #define IFRTYPE_QOSMARKING_FASTLANE 1 /* supported: socket/channel */
322 #define IFRTYPE_QOSMARKING_RFC4594 2 /* supported: channel only */
323 #define IFRTYPE_QOSMARKING_CUSTOM 3 /* supported: socket/channel */
324 u_int32_t ifru_qosmarking_enabled;
325 u_int32_t ifru_disable_output;
326 int32_t ifru_point_to_point_mdns;
327 u_int32_t ifru_low_internet;
328 #define IFRTYPE_LOW_INTERNET_DISABLE_UL_DL 0x0000
329 #define IFRTYPE_LOW_INTERNET_ENABLE_UL 0x0001
330 #define IFRTYPE_LOW_INTERNET_ENABLE_DL 0x0002
331 int ifru_low_power_mode;
332 u_int32_t ifru_tcp_kao_max;
333 int ifru_mpk_log; /* Multi Layer Packet Log */
334 u_int32_t ifru_noack_prio;
335 struct {
336 u_int8_t up_bucket;
337 u_int8_t down_bucket;
338 } ifru_estimated_throughput;
339 struct {
340 u_int8_t technology;
341 u_int8_t channel;
342 } ifru_radio_details;
343 uint64_t ifru_creation_generation_id;
344 u_int8_t ifru_is_directlink;
345 u_int8_t ifru_is_vpn;
346 uint32_t ifru_delay_wake_pkt_event;
347 u_int8_t ifru_is_companionlink;
348 } ifr_ifru;
349 #define ifr_addr ifr_ifru.ifru_addr /* address */
350 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
351 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
352 #ifdef __APPLE__
353 #define ifr_flags ifr_ifru.ifru_flags /* flags */
354 #else
355 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */
356 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */
357 #endif /* __APPLE__ */
358 #define ifr_metric ifr_ifru.ifru_metric /* metric */
359 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
360 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */
361 #define ifr_media ifr_ifru.ifru_media /* physical media */
362 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
363 #define ifr_devmtu ifr_ifru.ifru_devmtu
364 #define ifr_intval ifr_ifru.ifru_intval /* integer value */
365 #ifdef KERNEL_PRIVATE
366 #define ifr_data64 ifr_ifru.ifru_data64 /* 64-bit pointer */
367 #endif /* KERNEL_PRIVATE */
368 #define ifr_kpi ifr_ifru.ifru_kpi
369 #define ifr_wake_flags ifr_ifru.ifru_wake_flags /* wake capabilities */
370 #define ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references count */
371 #define ifr_link_quality_metric ifr_ifru.ifru_link_quality_metric /* LQM */
372 #define ifr_reqcap ifr_ifru.ifru_cap[0] /* requested capabilities */
373 #define ifr_curcap ifr_ifru.ifru_cap[1] /* current capabilities */
374 #define ifr_opportunistic ifr_ifru.ifru_opportunistic
375 #define ifr_eflags ifr_ifru.ifru_eflags /* extended flags */
376 #define ifr_xflags ifr_ifru.ifru_xflags /* extra flags */
377 #define ifr_log ifr_ifru.ifru_log /* logging level/flags */
378 #define ifr_delegated ifr_ifru.ifru_delegated /* delegated interface index */
379 #define ifr_expensive ifr_ifru.ifru_expensive
380 #define ifr_constrained ifr_ifru.ifru_constrained
381 #define ifr_type ifr_ifru.ifru_type /* interface type */
382 #define ifr_functional_type ifr_ifru.ifru_functional_type
383 #define ifr_peer_egress_functional_type ifr_ifru.ifru_peer_egress_functional_type
384 #define ifr_2kcl ifr_ifru.ifru_2kcl
385 #define ifr_start_delay_qlen ifr_ifru.ifru_start_delay.qlen
386 #define ifr_start_delay_timeout ifr_ifru.ifru_start_delay.timeout
387 #define ifr_interface_state ifr_ifru.ifru_interface_state
388 #define ifr_probe_connectivity ifr_ifru.ifru_probe_connectivity
389 #define ifr_ecn_mode ifr_ifru.ifru_ecn_mode
390 #define ifr_l4s_mode ifr_ifru.ifru_l4s_mode
391 #define ifr_qosmarking_mode ifr_ifru.ifru_qosmarking_mode
392 #define ifr_fastlane_capable ifr_qosmarking_mode
393 #define ifr_qosmarking_enabled ifr_ifru.ifru_qosmarking_enabled
394 #define ifr_fastlane_enabled ifr_qosmarking_enabled
395 #define ifr_disable_output ifr_ifru.ifru_disable_output
396 #define ifr_point_to_point_mdns ifr_ifru.ifru_point_to_point_mdns
397 #define ifr_low_internet ifr_ifru.ifru_low_internet
398 #define ifr_low_power_mode ifr_ifru.ifru_low_power_mode
399 #define ifr_tcp_kao_max ifr_ifru.ifru_tcp_kao_max
400 #define ifr_mpk_log ifr_ifru.ifru_mpk_log
401 #define ifr_noack_prio ifr_ifru.ifru_noack_prio
402 #define ifr_estimated_throughput ifr_ifru.ifru_estimated_throughput
403 #define ifr_radio_details ifr_ifru.ifru_radio_details
404 #define ifr_creation_generation_id ifr_ifru.ifru_creation_generation_id
405 #define ifr_is_directlink ifr_ifru.ifru_is_directlink
406 #define ifr_is_vpn ifr_ifru.ifru_is_vpn
407 #define ifr_delay_wake_pkt_event ifr_ifru.ifru_delay_wake_pkt_event
408 #define ifr_is_companionlink ifr_ifru.ifru_is_companionlink
409 };
410
411 #define _SIZEOF_ADDR_IFREQ(ifr) \
412 ((ifr).ifr_addr.sa_len > sizeof (struct sockaddr) ? \
413 (sizeof (struct ifreq) - sizeof (struct sockaddr) + \
414 (ifr).ifr_addr.sa_len) : sizeof (struct ifreq))
415 #endif /* IFREQ_OPAQUE */
416
417 #ifdef KERNEL_PRIVATE
418 #pragma pack(4)
419 struct ifmediareq64 {
420 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
421 int ifm_current; /* current media options */
422 int ifm_mask; /* don't care mask */
423 int ifm_status; /* media status */
424 int ifm_active; /* active options */
425 int ifm_count; /* # entries in ifm_ulist array */
426 user64_addr_t ifmu_ulist __attribute__((aligned(8)));
427 };
428
429 struct ifmediareq32 {
430 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
431 int ifm_current; /* current media options */
432 int ifm_mask; /* don't care mask */
433 int ifm_status; /* media status */
434 int ifm_active; /* active options */
435 int ifm_count; /* # entries in ifm_ulist array */
436 user32_addr_t ifmu_ulist; /* 32-bit pointer */
437 };
438
439 struct ifdrv32 {
440 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
441 u_int32_t ifd_cmd;
442 u_int32_t ifd_len;
443 user32_addr_t ifd_data;
444 };
445
446 struct ifdrv64 {
447 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
448 u_int64_t ifd_cmd;
449 u_int64_t ifd_len;
450 user64_addr_t ifd_data;
451 };
452
453 struct ifconf32 {
454 int ifc_len; /* size of associated buffer */
455 struct {
456 user32_addr_t ifcu_req;
457 } ifc_ifcu;
458 };
459
460 struct ifconf64 {
461 int ifc_len; /* size of associated buffer */
462 struct {
463 user64_addr_t ifcu_req __attribute__((aligned(8)));
464 } ifc_ifcu;
465 };
466 #pragma pack()
467 #endif /* KERNEL_PRIVATE */
468
469 /*
470 * Link Quality Metrics
471 *
472 * IFNET_LQM_THRESH_OFF Metric is not available; device is off.
473 * IFNET_LQM_THRESH_UNKNOWN Metric is not (yet) known.
474 * IFNET_LQM_THRESH_BAD Link quality is considered bad by driver.
475 * IFNET_LQM_THRESH_POOR Link quality is considered poor by driver.
476 * IFNET_LQM_THRESH_GOOD Link quality is considered good by driver.
477 */
478 enum {
479 IFNET_LQM_THRESH_OFF = (-2),
480 IFNET_LQM_THRESH_UNKNOWN = (-1),
481 IFNET_LQM_THRESH_ABORT = 10,
482 IFNET_LQM_THRESH_MINIMALLY_VIABLE = 20,
483 IFNET_LQM_THRESH_POOR = 50,
484 IFNET_LQM_THRESH_GOOD = 100
485 };
486 #define IFNET_LQM_THRESH_BAD IFNET_LQM_THRESH_ABORT
487
488 #ifdef XNU_KERNEL_PRIVATE
489 /*
490 * Determine the LQM threshold corresponding to the input.
491 */
492 static inline int8_t
ifnet_lqm_normalize(int32_t raw_lqm)493 ifnet_lqm_normalize(int32_t raw_lqm)
494 {
495 if (raw_lqm == IFNET_LQM_THRESH_OFF) {
496 return IFNET_LQM_THRESH_OFF;
497 }
498 if (raw_lqm <= 0) {
499 return IFNET_LQM_THRESH_UNKNOWN;
500 }
501 if (raw_lqm <= IFNET_LQM_THRESH_ABORT) {
502 return IFNET_LQM_THRESH_ABORT;
503 }
504 if (raw_lqm <= IFNET_LQM_THRESH_MINIMALLY_VIABLE) {
505 return IFNET_LQM_THRESH_MINIMALLY_VIABLE;
506 }
507 if (raw_lqm <= IFNET_LQM_THRESH_POOR) {
508 return IFNET_LQM_THRESH_POOR;
509 }
510 if (raw_lqm <= IFNET_LQM_THRESH_GOOD) {
511 return IFNET_LQM_THRESH_GOOD;
512 }
513 return IFNET_LQM_THRESH_UNKNOWN;
514 }
515 #endif /* XNU_KERNEL_PRIVATE */
516
517 #ifdef XNU_KERNEL_PRIVATE
518 #define IFNET_LQM_MIN IFNET_LQM_THRESH_OFF
519 #define IFNET_LQM_MAX IFNET_LQM_THRESH_GOOD
520 #endif /* XNU_KERNEL_PRIVATE */
521
522 /*
523 * DLIL KEV_DL_LINK_QUALITY_METRIC_CHANGED structure
524 */
525 struct kev_dl_link_quality_metric_data {
526 struct net_event_data link_data;
527 int link_quality_metric;
528 };
529
530 #define IF_DESCSIZE 128
531
532 /*
533 * Structure for SIOC[SG]IFDESC
534 */
535 struct if_descreq {
536 char ifdr_name[IFNAMSIZ]; /* interface name */
537 u_int32_t ifdr_len; /* up to IF_DESCSIZE */
538 u_int8_t ifdr_desc[IF_DESCSIZE]; /* opaque data */
539 };
540
541 /*
542 * Output packet scheduling models
543 *
544 * IFNET_SCHED_MODEL_NORMAL The default output packet scheduling model
545 * where the driver or media does not require strict scheduling
546 * strategy, and that the networking stack is free to choose the
547 * most appropriate scheduling and queueing algorithm, including
548 * shaping traffics.
549 * IFNET_SCHED_MODEL_DRIVER_MANAGED The alternative output packet
550 * scheduling model where the driver or media requires strict
551 * scheduling strategy (e.g. 802.11 WMM), and that the networking
552 * stack is only responsible for creating multiple queues for the
553 * corresponding service classes.
554 * IFNET_SCHED_MODEL_FQ_CODEL Use legacy FQ_CoDel as the output packet
555 * scheduling model. This also schedules traffic classes.
556 * This legacy FQ-CoDel implementation employs flow control
557 * when queuing dealy is above the configured threshold.
558 * IFNET_SCHED_MODEL_FQ_CODEL_DM Legacy FQ_CoDel but for driver/media that
559 * requires strict scheduling strategy. The driver is responisble
560 * for selecting the appropriate SVC at dequeue time.
561 * IFNET_SCHED_MODEL_FQ_CODEL_NEW RFC compliant FQ_CoDel implementation.
562 * This impplementation does not rely on flow control but rather packet
563 * drops and ECN markings to bring down queuing delay.
564 * IFNET_SCHED_MODEL_FQ_CODEL_NEW_DM Same as IFNET_SCHED_MODEL_FQ_CODEL_NEW
565 * but for driver/media that requires strict scheduling strategy.
566 */
567
568 #define IFNET_SCHED_MODEL_LIST \
569 X(IFNET_SCHED_MODEL_NORMAL, 0x00000000, normal) \
570 X(IFNET_SCHED_MODEL_DRIVER_MANAGED, 0x00000001, driver managed) \
571 X(IFNET_SCHED_MODEL_FQ_CODEL, 0x00000002, fq_codel) \
572 X(IFNET_SCHED_MODEL_FQ_CODEL_DM, 0x00000004, fq_codel DM) \
573 X(IFNET_SCHED_MODEL_FQ_CODEL_NEW, 0x00000008, fq_codel_new) \
574 X(IFNET_SCHED_MODEL_FQ_CODEL_NEW_DM, 0x00000010, fq_codel_new DM)
575 enum {
576 #define X(name, value, ...) name = value,
577 IFNET_SCHED_MODEL_LIST
578 #undef X
579 };
580
581 #define IFNET_SCHED_DRIVER_MANGED_MODELS \
582 (IFNET_SCHED_MODEL_DRIVER_MANAGED | IFNET_SCHED_MODEL_FQ_CODEL_DM | IFNET_SCHED_MODEL_FQ_CODEL_NEW_DM)
583
584 #define IFNET_SCHED_VALID_MODELS \
585 (IFNET_SCHED_MODEL_NORMAL | IFNET_SCHED_MODEL_DRIVER_MANAGED | \
586 IFNET_SCHED_MODEL_FQ_CODEL | IFNET_SCHED_MODEL_FQ_CODEL_DM | \
587 IFNET_SCHED_MODEL_FQ_CODEL_NEW | IFNET_SCHED_MODEL_FQ_CODEL_NEW_DM)
588
589 #define IFNET_MODEL_IS_VALID(_model) \
590 (((_model == IFNET_SCHED_MODEL_NORMAL) || ((_model) & IFNET_SCHED_VALID_MODELS)) && ((_model) & (_model - 1)) == 0)
591
592 /*
593 * Values for iflpr_flags
594 */
595 #define IFLPRF_ALTQ 0x1 /* configured via PF/ALTQ */
596 #define IFLPRF_DRVMANAGED 0x2 /* output queue scheduled by drv */
597
598 /*
599 * Structure for SIOCGIFLINKPARAMS
600 */
601 struct if_linkparamsreq {
602 char iflpr_name[IFNAMSIZ]; /* interface name */
603 u_int32_t iflpr_flags;
604 u_int32_t iflpr_output_sched;
605 u_int64_t iflpr_output_tbr_rate;
606 u_int32_t iflpr_output_tbr_percent;
607 u_int64_t iflpr_input_tbr_rate;
608 struct if_bandwidths iflpr_output_bw;
609 struct if_bandwidths iflpr_input_bw;
610 struct if_latencies iflpr_output_lt;
611 struct if_latencies iflpr_input_lt;
612 struct if_netem_params iflpr_input_netem;
613 struct if_netem_params iflpr_output_netem;
614 };
615
616 /*
617 * Structure for SIOCGIFQUEUESTATS
618 */
619 struct if_qstatsreq {
620 char ifqr_name[IFNAMSIZ]; /* interface name */
621 u_int32_t ifqr_grp_idx;
622 u_int32_t ifqr_slot;
623 void *ifqr_buf __attribute__((aligned(8)));
624 int ifqr_len __attribute__((aligned(8)));
625 };
626
627 /*
628 * Node Proximity Metrics
629 */
630 enum {
631 IFNET_NPM_THRESH_UNKNOWN = (-1),
632 IFNET_NPM_THRESH_NEAR = 30,
633 IFNET_NPM_THRESH_GENERAL = 70,
634 IFNET_NPM_THRESH_FAR = 100,
635 };
636
637 /*
638 * Received Signal Strength Indication [special values]
639 *
640 * IFNET_RSSI_UNKNOWN Metric is not (yet) known.
641 */
642 enum {
643 IFNET_RSSI_UNKNOWN = ((-2147483647) - 1), /* INT32_MIN */
644 };
645
646 /*
647 * DLIL KEV_DL_NODE_PRESENCE/KEV_DL_NODE_ABSENCE event structures
648 */
649 struct kev_dl_node_presence {
650 struct net_event_data link_data;
651 struct sockaddr_in6 sin6_node_address;
652 struct sockaddr_dl sdl_node_address;
653 int32_t rssi;
654 int link_quality_metric;
655 int node_proximity_metric;
656 u_int8_t node_service_info[48];
657 };
658
659 struct kev_dl_node_absence {
660 struct net_event_data link_data;
661 struct sockaddr_in6 sin6_node_address;
662 struct sockaddr_dl sdl_node_address;
663 };
664
665 /*
666 * Structure for SIOC[SG]IFTHROTTLE
667 */
668 struct if_throttlereq {
669 char ifthr_name[IFNAMSIZ]; /* interface name */
670 u_int32_t ifthr_level;
671 };
672
673 /*
674 * Interface throttling levels
675 *
676 * IFNET_THROTTLE_OFF The default throttling level (no throttling.)
677 * All service class queues operate normally according to the
678 * standard packet scheduler configuration.
679 * IFNET_THROTTLE_OPPORTUNISTIC One or more service class queues that
680 * are responsible for managing "opportunistic" traffics are
681 * suspended. Packets enqueued on those queues will be dropped
682 * and a flow advisory error will be generated to the data
683 * source. Existing packets in the queues will stay enqueued
684 * until the interface is no longer throttled, or until they
685 * are explicitly flushed.
686 */
687 enum {
688 IFNET_THROTTLE_OFF = 0,
689 IFNET_THROTTLE_OPPORTUNISTIC = 1,
690 #ifdef XNU_KERNEL_PRIVATE
691 IFNET_THROTTLE_MAX = 2,
692 #endif /* XNU_KERNEL_PRIVATE */
693 };
694
695 /*
696 * Structure for SIOC[A/D]IFAGENTID
697 */
698 struct if_agentidreq {
699 char ifar_name[IFNAMSIZ]; /* interface name */
700 uuid_t ifar_uuid; /* agent UUID to add or delete */
701 };
702
703 /*
704 * Structure for SIOCGIFAGENTIDS
705 */
706 struct if_agentidsreq {
707 char ifar_name[IFNAMSIZ]; /* interface name */
708 u_int32_t ifar_count; /* number of agent UUIDs */
709 uuid_t *ifar_uuids; /* array of agent UUIDs */
710 };
711
712 #ifdef BSD_KERNEL_PRIVATE
713 struct if_agentidsreq32 {
714 char ifar_name[IFNAMSIZ];
715 u_int32_t ifar_count;
716 user32_addr_t ifar_uuids;
717 };
718 struct if_agentidsreq64 {
719 char ifar_name[IFNAMSIZ];
720 u_int32_t ifar_count;
721 user64_addr_t ifar_uuids __attribute__((aligned(8)));
722 };
723 #endif /* BSD_KERNEL_PRIVATE */
724
725 /*
726 * Structure for SIOCGIFNEXUS
727 */
728 struct if_nexusreq {
729 char ifnr_name[IFNAMSIZ]; /* interface name */
730 uint64_t ifnr_flags; /* unused, must be zero */
731 uuid_t ifnr_netif; /* netif nexus instance UUID */
732 uuid_t ifnr_flowswitch; /* flowswitch nexus UUID */
733 uint64_t ifnr_reserved[5];
734 };
735
736 #define DLIL_MODIDLEN 20 /* same as IFNET_MODIDLEN */
737 #define DLIL_MODARGLEN 12 /* same as IFNET_MODARGLEN */
738
739 /*
740 * DLIL KEV_DL_ISSUES event structure
741 */
742 struct kev_dl_issues {
743 struct net_event_data link_data;
744 u_int8_t modid[DLIL_MODIDLEN];
745 u_int64_t timestamp;
746 u_int8_t info[DLIL_MODARGLEN];
747 };
748
749 /*
750 * DLIL KEV_DL_RRC_STATE_CHANGED structure
751 */
752 struct kev_dl_rrc_state {
753 struct net_event_data link_data;
754 u_int32_t rrc_state;
755 };
756
757 /*
758 * KEV_DL_LOW_POWER_MODE_CHANGED
759 */
760 struct kev_dl_low_power_mode {
761 struct net_event_data link_data;
762 int low_power_event;
763 };
764
765 /*
766 * Length of network signature/fingerprint blob.
767 */
768 #define IFNET_SIGNATURELEN 20
769
770 /*
771 * Structure for SIOC[S/G]IFNETSIGNATURE
772 */
773 struct if_nsreq {
774 char ifnsr_name[IFNAMSIZ];
775 u_int8_t ifnsr_family; /* address family */
776 u_int8_t ifnsr_len; /* data length */
777 u_int16_t ifnsr_flags; /* for future */
778 u_int8_t ifnsr_data[IFNET_SIGNATURELEN];
779 };
780
781 /* Structure for SIOCSIFNETWORKID */
782 struct if_netidreq {
783 char ifnetid_name[IFNAMSIZ];
784 u_int8_t ifnetid_len;
785 u_int8_t ifnetid[IFNET_NETWORK_ID_LEN];
786 };
787
788 #define NAT64_PREFIX_LEN_32 4
789 #define NAT64_PREFIX_LEN_40 5
790 #define NAT64_PREFIX_LEN_48 6
791 #define NAT64_PREFIX_LEN_56 7
792 #define NAT64_PREFIX_LEN_64 8
793 #define NAT64_PREFIX_LEN_96 12
794 #define NAT64_PREFIX_LEN_MAX NAT64_PREFIX_LEN_96
795
796 #define NAT64_MAX_NUM_PREFIXES 4
797
798 struct ipv6_prefix {
799 struct in6_addr ipv6_prefix;
800 uint32_t prefix_len;
801 };
802
803 struct if_ipv6_address {
804 struct in6_addr v6_address;
805 uint32_t v6_prefixlen;
806 };
807
808 /* Structure for SIOC[S/G]IFNAT64PREFIX */
809 struct if_nat64req {
810 char ifnat64_name[IFNAMSIZ];
811 struct ipv6_prefix ifnat64_prefixes[NAT64_MAX_NUM_PREFIXES];
812 };
813
814 /* Structure for SIOCGIFCLAT46ADDR */
815 struct if_clat46req {
816 char ifclat46_name[IFNAMSIZ];
817 struct if_ipv6_address ifclat46_addr;
818 };
819
820 /*
821 * Structure for SIOC[S/G]IFORDER
822 *
823 * When setting, ifo_count is the number of u_int32_t interface indices
824 * in the ifo_ordered_indices array.
825 *
826 * When getting, if ifo_count is 0, the length of the ordered list will
827 * be returned. If the ifo_count is non-0, it is the number of u_int32_t
828 * interface indices allocated. Upon return, ifo_count will contain the number
829 * of indices copied into the array.
830 */
831 struct if_order {
832 u_int32_t ifo_count;
833 u_int32_t ifo_reserved;
834 mach_vm_address_t ifo_ordered_indices; /* array of u_int32_t */
835 };
836
837 /*
838 * Struct for traffic class to DSCP mapping
839 */
840 struct if_tdmreq {
841 char iftdm_name[IFNAMSIZ];
842 u_int32_t iftdm_len; /* byte length of the table */
843 struct netsvctype_dscp_map *iftdm_table;
844 };
845
846 #ifdef BSD_KERNEL_PRIVATE
847 struct if_tdmreq32 {
848 char iftdm_name[IFNAMSIZ];
849 u_int32_t iftdm_len; /* byte length of the table */
850 user32_addr_t iftdm_table;
851 };
852
853 struct if_tdmreq64 {
854 char iftdm_name[IFNAMSIZ];
855 u_int32_t iftdm_len; /* byte length of the table */
856 user64_addr_t iftdm_table __attribute__((aligned(8)));
857 };
858 #endif
859
860 /*
861 * Structure for SIOCGIFPROTOLIST.
862 */
863 struct if_protolistreq {
864 char ifpl_name[IFNAMSIZ];
865 u_int32_t ifpl_count;
866 u_int32_t ifpl_reserved; /* must be zero */
867 u_int32_t *ifpl_list;
868 };
869
870 #ifdef BSD_KERNEL_PRIVATE
871 struct if_protolistreq32 {
872 char ifpl_name[IFNAMSIZ];
873 u_int32_t ifpl_count;
874 u_int32_t ifpl_reserved; /* must be zero */
875 user32_addr_t ifpl_list;
876 };
877
878 struct if_protolistreq64 {
879 char ifpl_name[IFNAMSIZ];
880 u_int32_t ifpl_count;
881 u_int32_t ifpl_reserved; /* must be zero */
882 user64_addr_t ifpl_list;
883 };
884 #endif /* BSD_KERNEL_PRIVATE */
885
886 /*
887 * Entitlement to send/receive data on an INTCOPROC interface
888 */
889 #define INTCOPROC_RESTRICTED_ENTITLEMENT "com.apple.private.network.intcoproc.restricted"
890 #define INTCOPROC_RESTRICTED_ENTITLEMENT_DEVELOPMENT "com.apple.private.network.intcoproc.restricted.development"
891
892 /*
893 * Entitlement to send/receive data on a management interface
894 */
895 #define MANAGEMENT_DATA_ENTITLEMENT "com.apple.private.network.management.data"
896 #define MANAGEMENT_DATA_ENTITLEMENT_DEVELOPMENT "com.apple.private.network.management.data.development"
897
898 /*
899 * Entitlement to make change to a management interface
900 */
901 #define MANAGEMENT_CONTROL_ENTITLEMENT "com.apple.private.network.management.control"
902
903 /*
904 * Entitlement to allow socket access on ultra-constrained interfaces
905 */
906 #define ULTRA_CONSTRAINED_ENTITLEMENT "com.apple.private.network.ultraconstrained"
907
908 #ifdef BSD_KERNEL_PRIVATE
909 #include <sys/protosw.h>
910
911 /*
912 * Link heuristics feature flags for variable if_link_heuristics_flags
913 */
914 #define IF_LINK_HEURISTICS_CELLULAR 0x0001 /* for cellular only by default */
915 #define IF_LINK_HEURISTICS_ANY 0x0002 /* for testing on any type of interface */
916 #define IF_LINK_HEURISTICS_LQM 0x0004 /* take in account LQM threshold */
917 #define IF_LINK_HEURISTICS_LINK_CONGESTED 0x0008 /* take in account link congestion indication */
918
919 /*
920 * Time to wait before disabling the LQM heuristics after a
921 * change to IFNET_LQM_THRESH_GOOD to avoid to flip back and
922 * forth when the conditions are variable
923 */
924 #define IF_LINK_HEURISTICS_DELAY_MSECS 30000
925
926 extern uint32_t if_link_heuristics_flags;
927 extern int if_link_heuristics_lqm_max;
928 extern uint32_t if_link_heuristics_delay;
929
930 /*
931 * Interface link heuristics are enabled when any of the following is true:
932 * - The interface link quality metric is below the threshold
933 * - The interface link is congested
934 */
935 static inline bool
if_link_heuristics_enabled(struct ifnet * ifp)936 if_link_heuristics_enabled(struct ifnet *ifp)
937 {
938 if (ifp != NULL &&
939 ((ifp->if_xflags & IFXF_LINK_HEURISTICS) != 0) &&
940 ((if_link_heuristics_flags & IF_LINK_HEURISTICS_ANY) != 0 ||
941 ((if_link_heuristics_flags & IF_LINK_HEURISTICS_CELLULAR) != 0 && IFNET_IS_CELLULAR(ifp)))) {
942 return true;
943 }
944 return false;
945 }
946
947 #endif /* BSD_KERNEL_PRIVATE */
948
949 #endif /* DRIVERKIT */
950 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
951
952 #endif /* !_NET_IF_PRIVATE_H_ */
953