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