1 /* 2 * Copyright (c) 2000-2021 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 #define IF_NAMESIZE 16 67 68 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) 69 #ifdef DRIVERKIT 70 #include <stddef.h> 71 #else 72 #include <sys/cdefs.h> 73 #include <sys/appleapiopts.h> 74 #ifdef __APPLE__ 75 76 #include <net/if_var.h> 77 #include <net/net_kev.h> 78 #if __has_ptrcheck 79 #include <netinet/in.h> 80 #endif 81 #include <sys/types.h> 82 #include <sys/socket.h> 83 84 #endif 85 #endif /* DRIVERKIT */ 86 87 #ifndef IFNAMSIZ 88 #define IFNAMSIZ IF_NAMESIZE 89 #endif 90 91 #ifndef DRIVERKIT 92 struct if_clonereq { 93 int ifcr_total; /* total cloners (out) */ 94 int ifcr_count; /* room for this many in user buffer */ 95 char *ifcr_buffer; /* buffer for cloner names */ 96 }; 97 98 #define IFF_UP 0x1 /* interface is up */ 99 #define IFF_BROADCAST 0x2 /* broadcast address valid */ 100 #define IFF_DEBUG 0x4 /* turn on debugging */ 101 #define IFF_LOOPBACK 0x8 /* is a loopback net */ 102 #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 103 #define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */ 104 #define IFF_RUNNING 0x40 /* resources allocated */ 105 #define IFF_NOARP 0x80 /* no address resolution protocol */ 106 #define IFF_PROMISC 0x100 /* receive all packets */ 107 #define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 108 #define IFF_OACTIVE 0x400 /* transmission in progress */ 109 #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 110 #define IFF_LINK0 0x1000 /* per link layer defined bit */ 111 #define IFF_LINK1 0x2000 /* per link layer defined bit */ 112 #define IFF_LINK2 0x4000 /* per link layer defined bit */ 113 #define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */ 114 #define IFF_MULTICAST 0x8000 /* supports multicast */ 115 116 #ifdef PRIVATE 117 /* See if_private.h for extended flags */ 118 #endif /* PRIVATE */ 119 120 /* 121 * Capabilities that interfaces can advertise. 122 * 123 * struct ifnet.if_capabilities 124 * contains the optional features & capabilities a particular interface 125 * supports (not only the driver but also the detected hw revision). 126 * Capabilities are defined by IFCAP_* below. 127 * struct ifnet.if_capenable 128 * contains the enabled (either by default or through ifconfig) optional 129 * features & capabilities on this interface. 130 * Capabilities are defined by IFCAP_* below. 131 * struct if_data.ifi_hwassist in IFNET_* form, defined in net/kpi_interface.h, 132 * contains the enabled optional features & capabilites that can be used 133 * individually per packet and are specified in the mbuf pkthdr.csum_flags 134 * field. IFCAP_* and IFNET_* do not match one to one and IFNET_* may be 135 * more detailed or differentiated than IFCAP_*. 136 * IFNET_* hwassist flags have corresponding CSUM_* in sys/mbuf.h 137 */ 138 #define IFCAP_RXCSUM 0x00001 /* can offload checksum on RX */ 139 #define IFCAP_TXCSUM 0x00002 /* can offload checksum on TX */ 140 #define IFCAP_VLAN_MTU 0x00004 /* VLAN-compatible MTU */ 141 #define IFCAP_VLAN_HWTAGGING 0x00008 /* hardware VLAN tag support */ 142 #define IFCAP_JUMBO_MTU 0x00010 /* 9000 byte MTU supported */ 143 #define IFCAP_TSO4 0x00020 /* can do TCP Segmentation Offload */ 144 #define IFCAP_TSO6 0x00040 /* can do TCP6 Segmentation Offload */ 145 #define IFCAP_LRO 0x00080 /* can do Large Receive Offload */ 146 #define IFCAP_AV 0x00100 /* can do 802.1 AV Bridging */ 147 #define IFCAP_TXSTATUS 0x00200 /* can return linklevel xmit status */ 148 #define IFCAP_SKYWALK 0x00400 /* Skywalk mode supported/enabled */ 149 #define IFCAP_HW_TIMESTAMP 0x00800 /* Time stamping in hardware */ 150 #define IFCAP_SW_TIMESTAMP 0x01000 /* Time stamping in software */ 151 #define IFCAP_CSUM_PARTIAL 0x02000 /* can offload partial checksum */ 152 #define IFCAP_CSUM_ZERO_INVERT 0x04000 /* can invert 0 to -0 (0xffff) */ 153 #define IFCAP_LRO_NUM_SEG 0x08000 /* NIC & driver can set the num of segments a LRO-packet is built of */ 154 155 #define IFCAP_HWCSUM (IFCAP_RXCSUM | IFCAP_TXCSUM) 156 #define IFCAP_TSO (IFCAP_TSO4 | IFCAP_TSO6) 157 158 #define IFCAP_VALID (IFCAP_HWCSUM | IFCAP_TSO | IFCAP_LRO | IFCAP_VLAN_MTU | \ 159 IFCAP_VLAN_HWTAGGING | IFCAP_JUMBO_MTU | IFCAP_AV | IFCAP_TXSTATUS | \ 160 IFCAP_SKYWALK | IFCAP_SW_TIMESTAMP | IFCAP_HW_TIMESTAMP | \ 161 IFCAP_CSUM_PARTIAL | IFCAP_CSUM_ZERO_INVERT) 162 163 #define IFQ_MAXLEN 128 164 #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 165 #define IFQ_DEF_C_TARGET_DELAY (10ULL * 1000 * 1000) /* 10 ms */ 166 #define IFQ_DEF_C_UPDATE_INTERVAL (100ULL * 1000 * 1000) /* 100 ms */ 167 #define IFQ_DEF_L4S_TARGET_DELAY (2ULL * 1000 * 1000) /* 2 ms */ 168 #define IFQ_DEF_L4S_WIRELESS_TARGET_DELAY (15ULL * 1000 * 1000) /* 15 ms */ 169 #define IFQ_DEF_L4S_UPDATE_INTERVAL (100ULL * 1000 * 1000) /* 100 ms */ 170 #define IFQ_LL_C_TARGET_DELAY (10ULL * 1000 * 1000) /* 10 ms */ 171 #define IFQ_LL_C_UPDATE_INTERVAL (100ULL * 1000 * 1000) /* 100 ms */ 172 #define IFQ_LL_L4S_TARGET_DELAY (2ULL * 1000 * 1000) /* 2 ms */ 173 #define IFQ_LL_L4S_WIRELESS_TARGET_DELAY (15ULL * 1000 * 1000) /* 15 ms */ 174 #define IFQ_LL_L4S_UPDATE_INTERVAL (100ULL * 1000 * 1000) /* 100 ms */ 175 /* 176 * Message format for use in obtaining information about interfaces 177 * from sysctl and the routing socket 178 */ 179 struct if_msghdr { 180 unsigned short ifm_msglen; /* to skip non-understood messages */ 181 unsigned char ifm_version; /* future binary compatability */ 182 unsigned char ifm_type; /* message type */ 183 int ifm_addrs; /* like rtm_addrs */ 184 int ifm_flags; /* value of if_flags */ 185 unsigned short ifm_index; /* index for associated ifp */ 186 struct if_data ifm_data; /* statistics and other data about if */ 187 }; 188 189 /* 190 * Message format for use in obtaining information about interface addresses 191 * from sysctl and the routing socket 192 */ 193 struct ifa_msghdr { 194 unsigned short ifam_msglen; /* to skip non-understood messages */ 195 unsigned char ifam_version; /* future binary compatability */ 196 unsigned char ifam_type; /* message type */ 197 int ifam_addrs; /* like rtm_addrs */ 198 int ifam_flags; /* value of ifa_flags */ 199 unsigned short ifam_index; /* index for associated ifp */ 200 int ifam_metric; /* value of ifa_metric */ 201 }; 202 203 /* 204 * Message format for use in obtaining information about multicast addresses 205 * from the routing socket 206 */ 207 struct ifma_msghdr { 208 unsigned short ifmam_msglen; /* to skip non-understood messages */ 209 unsigned char ifmam_version; /* future binary compatability */ 210 unsigned char ifmam_type; /* message type */ 211 int ifmam_addrs; /* like rtm_addrs */ 212 int ifmam_flags; /* value of ifa_flags */ 213 unsigned short ifmam_index; /* index for associated ifp */ 214 }; 215 216 /* 217 * Message format for use in obtaining information about interfaces 218 * from sysctl 219 */ 220 struct if_msghdr2 { 221 u_short ifm_msglen; /* to skip over non-understood messages */ 222 u_char ifm_version; /* future binary compatability */ 223 u_char ifm_type; /* message type */ 224 int ifm_addrs; /* like rtm_addrs */ 225 int ifm_flags; /* value of if_flags */ 226 u_short ifm_index; /* index for associated ifp */ 227 int ifm_snd_len; /* instantaneous length of send queue */ 228 int ifm_snd_maxlen; /* maximum length of send queue */ 229 int ifm_snd_drops; /* number of drops in send queue */ 230 int ifm_timer; /* time until if_watchdog called */ 231 struct if_data64 ifm_data; /* statistics and other data */ 232 }; 233 234 /* 235 * Message format for use in obtaining information about multicast addresses 236 * from sysctl 237 */ 238 struct ifma_msghdr2 { 239 u_short ifmam_msglen; /* to skip over non-understood messages */ 240 u_char ifmam_version; /* future binary compatability */ 241 u_char ifmam_type; /* message type */ 242 int ifmam_addrs; /* like rtm_addrs */ 243 int ifmam_flags; /* value of ifa_flags */ 244 u_short ifmam_index; /* index for associated ifp */ 245 int32_t ifmam_refcount; 246 }; 247 248 /* 249 * ifdevmtu: interface device mtu 250 * Used with SIOCGIFDEVMTU to get the current mtu in use by the device, 251 * as well as the minimum and maximum mtu allowed by the device. 252 */ 253 struct ifdevmtu { 254 int ifdm_current; 255 int ifdm_min; 256 int ifdm_max; 257 }; 258 259 #pragma pack(4) 260 261 /* 262 * ifkpi: interface kpi ioctl 263 * Used with SIOCSIFKPI and SIOCGIFKPI. 264 * 265 * ifk_module_id - From in the kernel, a value from kev_vendor_code_find. From 266 * user space, a value from SIOCGKEVVENDOR ioctl on a kernel event socket. 267 * ifk_type - The type. Types are specific to each module id. 268 * ifk_data - The data. ifk_ptr may be a 64bit pointer for 64 bit processes. 269 * 270 * Copying data between user space and kernel space is done using copyin 271 * and copyout. A process may be running in 64bit mode. In such a case, 272 * the pointer will be a 64bit pointer, not a 32bit pointer. The following 273 * sample is a safe way to copy the data in to the kernel from either a 274 * 32bit or 64bit process: 275 * 276 * user_addr_t tmp_ptr; 277 * if (IS_64BIT_PROCESS(current_proc())) { 278 * tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr64); 279 * } 280 * else { 281 * tmp_ptr = CAST_USER_ADDR_T(ifkpi.ifk_data.ifk_ptr); 282 * } 283 * error = copyin(tmp_ptr, allocated_dst_buffer, size of allocated_dst_buffer); 284 */ 285 286 struct ifkpi { 287 unsigned int ifk_module_id; 288 unsigned int ifk_type; 289 union { 290 void *ifk_ptr; 291 int ifk_value; 292 #ifdef KERNEL 293 u_int64_t ifk_ptr64; 294 #endif /* KERNEL */ 295 } ifk_data; 296 }; 297 298 /* Wake capabilities of a interface */ 299 #define IF_WAKE_ON_MAGIC_PACKET 0x01 300 301 302 #pragma pack() 303 304 #ifdef PRIVATE 305 /* 306 * IFREQ_OPAQUE means that ifreq is an opaque structure 307 * in the public header, and redeclared in if_private.h. 308 */ 309 #define IFREQ_OPAQUE 310 #endif /* PRIVATE */ 311 312 /* 313 * Interface request structure used for socket 314 * ioctl's. All interface ioctl's must have parameter 315 * definitions which begin with ifr_name. The 316 * remainder may be interface specific. 317 */ 318 #ifdef IFREQ_OPAQUE 319 struct ifreq; 320 #else 321 #ifdef PRIVATE 322 /* 323 * This is the public version of the ifreq structure, the 324 * private version lives in if_private.h. If you make any 325 * changes here, you must also make them in if_private.h! 326 */ 327 #endif 328 struct ifreq { 329 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 330 union { 331 struct sockaddr ifru_addr; 332 struct sockaddr ifru_dstaddr; 333 struct sockaddr ifru_broadaddr; 334 short ifru_flags; 335 int ifru_metric; 336 int ifru_mtu; 337 int ifru_phys; 338 int ifru_media; 339 int ifru_intval; 340 caddr_t ifru_data; 341 struct ifdevmtu ifru_devmtu; 342 struct ifkpi ifru_kpi; 343 u_int32_t ifru_wake_flags; 344 u_int32_t ifru_route_refcnt; 345 int ifru_cap[2]; 346 u_int32_t ifru_functional_type; 347 u_int32_t ifru_peer_egress_functional_type; 348 #define IFRTYPE_FUNCTIONAL_UNKNOWN 0 349 #define IFRTYPE_FUNCTIONAL_LOOPBACK 1 350 #define IFRTYPE_FUNCTIONAL_WIRED 2 351 #define IFRTYPE_FUNCTIONAL_WIFI_INFRA 3 352 #define IFRTYPE_FUNCTIONAL_WIFI_AWDL 4 353 #define IFRTYPE_FUNCTIONAL_CELLULAR 5 354 #define IFRTYPE_FUNCTIONAL_INTCOPROC 6 355 #define IFRTYPE_FUNCTIONAL_COMPANIONLINK 7 356 #define IFRTYPE_FUNCTIONAL_MANAGEMENT 8 357 #define IFRTYPE_FUNCTIONAL_LAST 8 358 u_int8_t ifru_is_directlink; 359 u_int8_t ifru_is_vpn; 360 } ifr_ifru; 361 #define ifr_addr ifr_ifru.ifru_addr /* address */ 362 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 363 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 364 #ifdef __APPLE__ 365 #define ifr_flags ifr_ifru.ifru_flags /* flags */ 366 #else 367 #define ifr_flags ifr_ifru.ifru_flags[0] /* flags */ 368 #define ifr_prevflags ifr_ifru.ifru_flags[1] /* flags */ 369 #endif /* __APPLE__ */ 370 #define ifr_metric ifr_ifru.ifru_metric /* metric */ 371 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 372 #define ifr_phys ifr_ifru.ifru_phys /* physical wire */ 373 #define ifr_media ifr_ifru.ifru_media /* physical media */ 374 #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 375 #define ifr_devmtu ifr_ifru.ifru_devmtu 376 #define ifr_intval ifr_ifru.ifru_intval /* integer value */ 377 #define ifr_kpi ifr_ifru.ifru_kpi 378 #define ifr_wake_flags ifr_ifru.ifru_wake_flags /* wake capabilities */ 379 #define ifr_route_refcnt ifr_ifru.ifru_route_refcnt /* route references count */ 380 #define ifr_reqcap ifr_ifru.ifru_cap[0] /* requested capabilities */ 381 #define ifr_curcap ifr_ifru.ifru_cap[1] /* current capabilities */ 382 }; 383 384 #define _SIZEOF_ADDR_IFREQ(ifr) \ 385 ((ifr).ifr_addr.sa_len > sizeof (struct sockaddr) ? \ 386 (sizeof (struct ifreq) - sizeof (struct sockaddr) + \ 387 (ifr).ifr_addr.sa_len) : sizeof (struct ifreq)) 388 #endif /* IFREQ_OPAQUE */ 389 390 struct ifaliasreq { 391 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 392 #if __has_ptrcheck 393 struct sockaddr_in ifra_addr; 394 struct sockaddr_in ifra_broadaddr; 395 struct sockaddr_in ifra_mask; 396 #else 397 struct sockaddr ifra_addr; 398 struct sockaddr ifra_broadaddr; 399 struct sockaddr ifra_mask; 400 #endif /* __has_ptrcheck */ 401 }; 402 403 struct rslvmulti_req { 404 struct sockaddr *sa; 405 struct sockaddr **llsa; 406 }; 407 408 #if !defined(KERNEL) || defined(KERNEL_PRIVATE) 409 #pragma pack(4) 410 411 struct ifmediareq { 412 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 413 int ifm_current; /* current media options */ 414 int ifm_mask; /* don't care mask */ 415 int ifm_status; /* media status */ 416 int ifm_active; /* active options */ 417 int ifm_count; /* # entries in ifm_ulist array */ 418 int *ifm_ulist; /* media words */ 419 }; 420 421 #pragma pack() 422 #endif /* !KERNEL || KERNEL_PRIVATE */ 423 424 #endif /* DRIVERKIT */ 425 426 #pragma pack(4) 427 struct ifdrv { 428 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 429 unsigned long ifd_cmd; 430 size_t ifd_len; /* length of ifd_data buffer */ 431 void *ifd_data; 432 }; 433 #pragma pack() 434 435 #ifndef DRIVERKIT 436 437 /* 438 * Structure used to retrieve aux status data from interfaces. 439 * Kernel suppliers to this interface should respect the formatting 440 * needed by ifconfig(8): each line starts with a TAB and ends with 441 * a newline. 442 */ 443 444 #define IFSTATMAX 800 /* 10 lines of text */ 445 struct ifstat { 446 char ifs_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 447 char ascii[IFSTATMAX + 1]; 448 }; 449 450 #if !defined(KERNEL) || defined(KERNEL_PRIVATE) 451 /* 452 * Structure used in SIOCGIFCONF request. 453 * Used to retrieve interface configuration 454 * for machine (useful for programs which 455 * must know all networks accessible). 456 */ 457 #pragma pack(4) 458 struct ifconf { 459 int ifc_len; /* size of associated buffer */ 460 union { 461 caddr_t ifcu_buf; 462 struct ifreq *ifcu_req; 463 } ifc_ifcu; 464 }; 465 #pragma pack() 466 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 467 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 468 #endif /* !KERNEL || KERNEL_PRIVATE */ 469 470 /* 471 * DLIL KEV_DL_PROTO_ATTACHED/DETACHED structure 472 */ 473 struct kev_dl_proto_data { 474 struct net_event_data link_data; 475 u_int32_t proto_family; 476 u_int32_t proto_remaining_count; 477 }; 478 479 #ifdef KERNEL 480 #ifdef MALLOC_DECLARE 481 MALLOC_DECLARE(M_IFADDR); 482 #endif 483 #endif 484 #endif /* DRIVERKIT */ 485 #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */ 486 487 #ifndef DRIVERKIT 488 #ifndef KERNEL 489 struct if_nameindex { 490 unsigned int if_index; /* 1, 2, ... */ 491 char *if_name; /* null terminated name: "le0", ... */ 492 }; 493 494 __BEGIN_DECLS 495 unsigned int if_nametoindex(const char *); 496 char *if_indextoname(unsigned int, char *); 497 struct if_nameindex *if_nameindex(void); 498 void if_freenameindex(struct if_nameindex *); 499 __END_DECLS 500 #endif /* KERNEL */ 501 #endif /* DRIVERKIT */ 502 503 #ifdef KERNEL 504 #include <net/kpi_interface.h> 505 #endif 506 507 #ifdef PRIVATE 508 #include <net/if_private.h> 509 #endif /* PRIVATE */ 510 511 #endif /* !_NET_IF_H_ */ 512