1 /* 2 * Copyright (c) 2004-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 * @header kpi_interface.h 30 * This header defines an API to interact with network interfaces in 31 * the kernel. The network interface KPI may be used to implement 32 * network interfaces or to attach protocols to existing interfaces. 33 */ 34 35 #ifndef __KPI_INTERFACE__ 36 #define __KPI_INTERFACE__ 37 38 #ifndef XNU_KERNEL_PRIVATE 39 #include <TargetConditionals.h> 40 #endif 41 42 #include <sys/kernel_types.h> 43 44 #ifdef KERNEL_PRIVATE 45 struct if_interface_state; 46 struct ifnet_interface_advisory; 47 #include <sys/kpi_mbuf.h> 48 #endif /* KERNEL_PRIVATE */ 49 50 #include <sys/_types/_sa_family_t.h> 51 52 #ifndef PRIVATE 53 #include <Availability.h> 54 #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15.4)) 55 #else 56 #define __NKE_API_DEPRECATED 57 #endif /* PRIVATE */ 58 59 #ifdef XNU_KERNEL_PRIVATE 60 #if !XNU_TARGET_OS_OSX 61 #define KPI_INTERFACE_EMBEDDED 1 62 #else /* XNU_TARGET_OS_OSX && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ 63 #define KPI_INTERFACE_EMBEDDED 0 64 #endif /* XNU_TARGET_OS_OSX && !(TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) */ 65 #else 66 #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR) 67 #define KPI_INTERFACE_EMBEDDED 1 68 #else 69 #define KPI_INTERFACE_EMBEDDED 0 70 #endif 71 #endif 72 73 struct timeval; 74 struct sockaddr; 75 struct sockaddr_dl; 76 struct kern_event_msg; 77 struct kev_msg; 78 struct ifnet_demux_desc; 79 80 /*! 81 * @enum Interface Families 82 * @abstract Constants defining interface families. 83 * @constant IFNET_FAMILY_ANY Match interface of any family type. 84 * @constant IFNET_FAMILY_LOOPBACK A software loopback interface. 85 * @constant IFNET_FAMILY_ETHERNET An Ethernet interface. 86 * @constant IFNET_FAMILY_SLIP A SLIP interface. 87 * @constant IFNET_FAMILY_TUN A tunnel interface. 88 * @constant IFNET_FAMILY_VLAN A virtual LAN interface. 89 * @constant IFNET_FAMILY_PPP A PPP interface. 90 * @constant IFNET_FAMILY_PVC A PVC interface. 91 * @constant IFNET_FAMILY_DISC A DISC interface. 92 * @constant IFNET_FAMILY_MDECAP A MDECAP interface. 93 * @constant IFNET_FAMILY_GIF A generic tunnel interface. 94 * @constant IFNET_FAMILY_FAITH A FAITH [IPv4/IPv6 translation] interface. 95 * @constant IFNET_FAMILY_STF A 6to4 interface. 96 * @constant IFNET_FAMILY_FIREWIRE An IEEE 1394 [Firewire] interface. 97 * @constant IFNET_FAMILY_BOND A virtual bonded interface. 98 * @constant IFNET_FAMILY_CELLULAR A cellular interface. 99 * @constant IFNET_FAMILY_6LOWPAN A 6LoWPAN interface. 100 * @constant IFNET_FAMILY_UTUN A utun interface. 101 * @constant IFNET_FAMILY_IPSEC An IPsec interface. 102 */ 103 enum { 104 IFNET_FAMILY_ANY = 0, 105 IFNET_FAMILY_LOOPBACK = 1, 106 IFNET_FAMILY_ETHERNET = 2, 107 IFNET_FAMILY_SLIP = 3, 108 IFNET_FAMILY_TUN = 4, 109 IFNET_FAMILY_VLAN = 5, 110 IFNET_FAMILY_PPP = 6, 111 IFNET_FAMILY_PVC = 7, 112 IFNET_FAMILY_DISC = 8, 113 IFNET_FAMILY_MDECAP = 9, 114 IFNET_FAMILY_GIF = 10, 115 IFNET_FAMILY_FAITH = 11, /* deprecated */ 116 IFNET_FAMILY_STF = 12, 117 IFNET_FAMILY_FIREWIRE = 13, 118 IFNET_FAMILY_BOND = 14, 119 IFNET_FAMILY_CELLULAR = 15, 120 IFNET_FAMILY_6LOWPAN = 16, 121 IFNET_FAMILY_UTUN = 17, 122 IFNET_FAMILY_IPSEC = 18 123 }; 124 125 /*! 126 * @typedef ifnet_family_t 127 * @abstract Storage type for the interface family. 128 */ 129 typedef u_int32_t ifnet_family_t; 130 131 #ifdef KERNEL_PRIVATE 132 /* 133 * @enum Interface Sub-families 134 * @abstract Constants defining interface sub-families (may also 135 * be viewed as the underlying transport). Some families 136 * (e.g. IFNET_FAMILY_ETHERNET) are often too generic. 137 * These sub-families allow us to further refine the 138 * interface family, e.g. Ethernet over Wi-Fi/USB, etc. 139 */ 140 enum { 141 IFNET_SUBFAMILY_ANY = 0, 142 IFNET_SUBFAMILY_USB = 1, 143 IFNET_SUBFAMILY_BLUETOOTH = 2, 144 IFNET_SUBFAMILY_WIFI = 3, 145 IFNET_SUBFAMILY_THUNDERBOLT = 4, 146 IFNET_SUBFAMILY_RESERVED = 5, 147 IFNET_SUBFAMILY_INTCOPROC = 6, 148 IFNET_SUBFAMILY_QUICKRELAY = 7, 149 IFNET_SUBFAMILY_DEFAULT = 8, 150 IFNET_SUBFAMILY_VMNET = 9, 151 }; 152 153 /* 154 * @typedef ifnet_sub_family_t 155 * @abstract Storage type for the interface sub-family. 156 */ 157 typedef u_int32_t ifnet_subfamily_t; 158 #endif /* KERNEL_PRIVATE */ 159 160 #ifndef BPF_TAP_MODE_T 161 #define BPF_TAP_MODE_T 162 /*! 163 * @enum BPF tap mode 164 * @abstract Constants defining interface families. 165 * @constant BPF_MODE_DISABLED Disable bpf. 166 * @constant BPF_MODE_INPUT Enable input only. 167 * @constant BPF_MODE_OUTPUT Enable output only. 168 * @constant BPF_MODE_INPUT_OUTPUT Enable input and output. 169 */ 170 171 enum { 172 BPF_MODE_DISABLED = 0, 173 BPF_MODE_INPUT = 1, 174 BPF_MODE_OUTPUT = 2, 175 BPF_MODE_INPUT_OUTPUT = 3 176 }; 177 /*! 178 * @typedef bpf_tap_mode 179 * @abstract Mode for tapping. BPF_MODE_DISABLED/BPF_MODE_INPUT_OUTPUT etc. 180 */ 181 typedef u_int32_t bpf_tap_mode; 182 #endif /* !BPF_TAP_MODE_T */ 183 184 /*! 185 * @typedef protocol_family_t 186 * @abstract Storage type for the protocol family. 187 */ 188 typedef u_int32_t protocol_family_t; 189 190 /*! 191 * @enum Interface Abilities 192 * @abstract Constants defining interface offload support. 193 * @constant IFNET_CSUM_IP Hardware will calculate IPv4 checksums. 194 * @constant IFNET_CSUM_TCP Hardware will calculate TCP checksums. 195 * @constant IFNET_CSUM_UDP Hardware will calculate UDP checksums. 196 * @constant IFNET_CSUM_FRAGMENT Hardware will checksum IP fragments. 197 * @constant IFNET_IP_FRAGMENT Hardware will fragment IP packets. 198 * @constant IFNET_CSUM_TCPIPV6 Hardware will calculate TCP IPv6 checksums. 199 * @constant IFNET_CSUM_UDPIPV6 Hardware will calculate UDP IPv6 checksums. 200 * @constant IFNET_IPV6_FRAGMENT Hardware will fragment IPv6 packets. 201 * @constant IFNET_VLAN_TAGGING Hardware will generate VLAN headers. 202 * @constant IFNET_VLAN_MTU Hardware supports VLAN MTU. 203 * @constant IFNET_MULTIPAGES Driver is capable of handling packets 204 * coming down from the network stack that reside in virtually, 205 * but not in physically contiguous span of the external mbuf 206 * clusters. In this case, the data area of a packet in the 207 * external mbuf cluster might cross one or more physical 208 * pages that are disjoint, depending on the interface MTU 209 * and the packet size. Such a use of larger than system page 210 * size clusters by the network stack is done for better system 211 * efficiency. Drivers that utilize the IOMbufNaturalMemoryCursor 212 * with the getPhysicalSegmentsWithCoalesce interfaces and 213 * enumerate the list of vectors should set this flag for 214 * possible gain in performance during bulk data transfer. 215 * @constant IFNET_TSO_IPV4 Hardware supports IPv4 TCP Segment Offloading. 216 * If the Interface driver sets this flag, TCP will send larger frames (up to 64KB) as one 217 * frame to the adapter which will perform the final packetization. The maximum TSO segment 218 * supported by the interface can be set with "ifnet_set_tso_mtu". To retrieve the real MTU 219 * for the TCP connection the function "mbuf_get_tso_requested" is used by the driver. Note 220 * that if TSO is active, all the packets will be flagged for TSO, not just large packets. 221 * @constant IFNET_TSO_IPV6 Hardware supports IPv6 TCP Segment Offloading. 222 * If the Interface driver sets this flag, TCP IPv6 will send larger frames (up to 64KB) as one 223 * frame to the adapter which will perform the final packetization. The maximum TSO segment 224 * supported by the interface can be set with "ifnet_set_tso_mtu". To retrieve the real MTU 225 * for the TCP IPv6 connection the function "mbuf_get_tso_requested" is used by the driver. 226 * Note that if TSO is active, all the packets will be flagged for TSO, not just large packets. 227 * @constant IFNET_TX_STATUS Driver supports returning a per packet 228 * transmission status (pass, fail or other errors) of whether 229 * the packet was successfully transmitted on the link, or the 230 * transmission was aborted, or transmission failed. 231 * 232 */ 233 234 enum { 235 IFNET_CSUM_IP = 0x00000001, 236 IFNET_CSUM_TCP = 0x00000002, 237 IFNET_CSUM_UDP = 0x00000004, 238 IFNET_CSUM_FRAGMENT = 0x00000008, 239 IFNET_IP_FRAGMENT = 0x00000010, 240 IFNET_CSUM_TCPIPV6 = 0x00000020, 241 IFNET_CSUM_UDPIPV6 = 0x00000040, 242 IFNET_IPV6_FRAGMENT = 0x00000080, 243 #ifdef KERNEL_PRIVATE 244 IFNET_CSUM_PARTIAL = 0x00001000, 245 IFNET_CSUM_SUM16 = IFNET_CSUM_PARTIAL, 246 IFNET_CSUM_ZERO_INVERT = 0x00002000, 247 #endif /* KERNEL_PRIVATE */ 248 IFNET_VLAN_TAGGING = 0x00010000, 249 IFNET_VLAN_MTU = 0x00020000, 250 IFNET_MULTIPAGES = 0x00100000, 251 IFNET_TSO_IPV4 = 0x00200000, 252 IFNET_TSO_IPV6 = 0x00400000, 253 IFNET_TX_STATUS = 0x00800000, 254 IFNET_HW_TIMESTAMP = 0x01000000, 255 IFNET_SW_TIMESTAMP = 0x02000000 256 }; 257 /*! 258 * @typedef ifnet_offload_t 259 * @abstract Flags indicating the offload support of the interface. 260 */ 261 typedef u_int32_t ifnet_offload_t; 262 263 #ifdef KERNEL_PRIVATE 264 #define IFNET_OFFLOADF_BITS \ 265 "\020\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS\5IP_FRAGMENT" \ 266 "\6CSUM_TCPIPV6\7CSUM_UDPIPV6\10IPV6_FRAGMENT\15CSUM_PARTIAL" \ 267 "\16CSUM_ZERO_INVERT\20VLAN_TAGGING\21VLAN_MTU\25MULTIPAGES" \ 268 "\26TSO_IPV4\27TSO_IPV6\30TXSTATUS\31HW_TIMESTAMP\32SW_TIMESTAMP" 269 270 #define IFNET_CHECKSUMF \ 271 (IFNET_CSUM_IP | IFNET_CSUM_TCP | IFNET_CSUM_UDP | \ 272 IFNET_CSUM_FRAGMENT | IFNET_CSUM_TCPIPV6 | IFNET_CSUM_UDPIPV6 | \ 273 IFNET_CSUM_PARTIAL | IFNET_CSUM_ZERO_INVERT) 274 275 #define IFNET_TSOF \ 276 (IFNET_TSO_IPV4 | IFNET_TSO_IPV6) 277 #endif /* KERNEL_PRIVATE */ 278 279 /* 280 * Callbacks 281 * 282 * These are function pointers you supply to the kernel in the interface. 283 */ 284 /*! 285 * @typedef bpf_packet_func 286 * 287 * @discussion bpf_packet_func The bpf_packet_func is used to intercept 288 * inbound and outbound packets. The tap function will never free 289 * the mbuf. The tap function will only copy the mbuf in to various 290 * bpf file descriptors tapping this interface. 291 * @param interface The interface being sent or received on. 292 * @param data The packet to be transmitted or received. 293 * @result An errno value or zero upon success. 294 */ 295 /* Fast path - do not block or spend excessive amounts of time */ 296 typedef errno_t (*bpf_packet_func)(ifnet_t interface, mbuf_t data); 297 298 /*! 299 * @typedef ifnet_output_func 300 * 301 * @discussion ifnet_output_func is used to transmit packets. The stack 302 * will pass fully formed packets, including frame header, to the 303 * ifnet_output function for an interface. The driver is 304 * responsible for freeing the mbuf. 305 * @param interface The interface being sent on. 306 * @param data The packet to be sent. 307 */ 308 /* Fast path - do not block or spend excessive amounts of time */ 309 typedef errno_t (*ifnet_output_func)(ifnet_t interface, mbuf_t data); 310 311 /*! 312 * @typedef ifnet_ioctl_func 313 * @discussion ifnet_ioctl_func is used to communicate ioctls from the 314 * stack to the driver. 315 * 316 * All undefined ioctls are reserved for future use by Apple. If 317 * you need to communicate with your kext using an ioctl, please 318 * use SIOCSIFKPI and SIOCGIFKPI. 319 * @param interface The interface the ioctl is being sent to. 320 * @param cmd The ioctl command. 321 * @param data A pointer to any data related to the ioctl. 322 */ 323 typedef errno_t (*ifnet_ioctl_func)(ifnet_t interface, unsigned long cmd, 324 void *data); 325 326 /*! 327 * @typedef ifnet_set_bpf_tap 328 * @discussion Deprecated. Specify NULL. Call bpf_tap_in/bpf_tap_out 329 * for all packets. 330 */ 331 typedef errno_t (*ifnet_set_bpf_tap)(ifnet_t interface, bpf_tap_mode mode, 332 bpf_packet_func callback); 333 334 /*! 335 * @typedef ifnet_detached_func 336 * @discussion ifnet_detached_func is called an interface is detached 337 * from the list of interfaces. When ifnet_detach is called, it may 338 * not detach the interface immediately if protocols are attached. 339 * ifnet_detached_func is used to notify the interface that it has 340 * been detached from the networking stack. This is the last 341 * function that will be called on an interface. Until this 342 * function returns, you must not unload a kext supplying function 343 * pointers to this interface, even if ifnet_detacah has been 344 * called. Your detach function may be called during your call to 345 * ifnet_detach. 346 * @param interface The interface that has been detached. 347 * event. 348 */ 349 typedef void (*ifnet_detached_func)(ifnet_t interface); 350 351 /*! 352 * @typedef ifnet_demux_func 353 * @discussion ifnet_demux_func is called for each inbound packet to 354 * determine which protocol family the packet belongs to. This 355 * information is then used by the stack to determine which 356 * protocol to pass the packet to. This function may return 357 * protocol families for protocols that are not attached. If the 358 * protocol family has not been attached to the interface, the 359 * packet will be discarded. 360 * @param interface The interface the packet was received on. 361 * @param packet The mbuf containing the packet. 362 * @param frame_header A pointer to the frame header. 363 * @param protocol_family Upon return, the protocol family matching the 364 * packet should be stored here. 365 * @result 366 * If the result is zero, processing will continue normally. 367 * If the result is EJUSTRETURN, processing will stop but the 368 * packet will not be freed. 369 * If the result is anything else, the processing will stop and 370 * the packet will be freed. 371 */ 372 typedef errno_t (*ifnet_demux_func)(ifnet_t interface, mbuf_t packet, 373 char *frame_header, protocol_family_t *protocol_family); 374 375 /*! 376 * @typedef ifnet_event_func 377 * @discussion ifnet_event_func is called when an event occurs on a 378 * specific interface. 379 * @param interface The interface the event occurred on. 380 */ 381 typedef void (*ifnet_event_func)(ifnet_t interface, const struct kev_msg *msg); 382 383 /*! 384 * @typedef ifnet_framer_func 385 * @discussion ifnet_framer_func is called for each outbound packet to 386 * give the interface an opportunity to prepend interface specific 387 * headers. 388 * @param interface The interface the packet is being sent on. 389 * @param packet Pointer to the mbuf containing the packet, caller may 390 * set this to a different mbuf upon return. This can happen if the 391 * frameout function needs to prepend another mbuf to the chain to 392 * have enough space for the header. 393 * @param dest The higher layer protocol destination (i.e. IP address). 394 * @param dest_linkaddr The link layer address as determined by the 395 * protocol's pre-output function. 396 * @param frame_type The frame type as determined by the protocol's 397 * pre-output function. 398 * @discussion prepend_len The length of prepended bytes to the mbuf. 399 * (ONLY used if KPI_INTERFACE_EMBEDDED is defined to 1) 400 * @discussion postpend_len The length of the postpended bytes to the mbuf. 401 * (ONLY used if KPI_INTERFACE_EMBEDDED is defined to 1) 402 * @result 403 * If the result is zero, processing will continue normally. 404 * If the result is EJUSTRETURN, processing will stop but the 405 * packet will not be freed. 406 * If the result is anything else, the processing will stop and 407 * the packet will be freed. 408 */ 409 typedef errno_t (*ifnet_framer_func)(ifnet_t interface, mbuf_t *packet, 410 const struct sockaddr *dest, const char *dest_linkaddr, 411 const char *frame_type 412 #if KPI_INTERFACE_EMBEDDED 413 , u_int32_t *prepend_len, u_int32_t *postpend_len 414 #endif /* KPI_INTERFACE_EMBEDDED */ 415 ); 416 #ifdef KERNEL_PRIVATE 417 typedef errno_t (*ifnet_framer_extended_func)(ifnet_t interface, mbuf_t *packet, 418 const struct sockaddr *dest, const char *dest_linkaddr, 419 const char *frame_type, u_int32_t *prepend_len, 420 u_int32_t *postpend_len); 421 #endif /* KERNEL_PRIVATE */ 422 423 /*! 424 * @typedef ifnet_add_proto_func 425 * @discussion if_add_proto_func is called by the stack when a protocol 426 * is attached to an interface. This gives the interface an 427 * opportunity to get a list of protocol description structures 428 * for demuxing packets to this protocol (demux descriptors). 429 * @param interface The interface the protocol will be attached to. 430 * @param protocol_family The family of the protocol being attached. 431 * @param demux_array An array of demux descriptors that describe 432 * the interface specific ways of identifying packets belonging 433 * to this protocol family. 434 * @param demux_count The number of demux descriptors in the array. 435 * @result 436 * If the result is zero, processing will continue normally. 437 * If the result is anything else, the add protocol will be 438 * aborted. 439 */ 440 typedef errno_t (*ifnet_add_proto_func)(ifnet_t interface, 441 protocol_family_t protocol_family, 442 const struct ifnet_demux_desc *demux_array, u_int32_t demux_count); 443 444 /*! 445 * @typedef if_del_proto_func 446 * @discussion if_del_proto_func is called by the stack when a protocol 447 * is being detached from an interface. This gives the interface an 448 * opportunity to free any storage related to this specific 449 * protocol being attached to this interface. 450 * @param interface The interface the protocol will be detached from. 451 * @param protocol_family The family of the protocol being detached. 452 * @result 453 * If the result is zero, processing will continue normally. 454 * If the result is anything else, the detach will continue 455 * and the error will be returned to the caller. 456 */ 457 typedef errno_t (*ifnet_del_proto_func)(ifnet_t interface, 458 protocol_family_t protocol_family); 459 460 /*! 461 * @typedef ifnet_check_multi 462 * @discussion ifnet_check_multi is called for each multicast address 463 * added to an interface. This gives the interface an opportunity 464 * to reject invalid multicast addresses before they are attached 465 * to the interface. 466 * 467 * To prevent an address from being added to your multicast list, 468 * return EADDRNOTAVAIL. If you don't know how to parse/translate 469 * the address, return EOPNOTSUPP. 470 * @param interface The interface. 471 * @param mcast The multicast address. 472 * @result 473 * Zero upon success, EADDRNOTAVAIL on invalid multicast, 474 * EOPNOTSUPP for addresses the interface does not understand. 475 */ 476 typedef errno_t (*ifnet_check_multi)(ifnet_t interface, 477 const struct sockaddr *mcast); 478 479 /*! 480 * @typedef proto_media_input 481 * @discussion proto_media_input is called for all inbound packets for 482 * a specific protocol on a specific interface. This function is 483 * registered on an interface using ifnet_attach_protocol. 484 * @param ifp The interface the packet was received on. 485 * @param protocol The protocol of the packet received. 486 * @param packet The packet being input. 487 * @param header The frame header. 488 * @result 489 * If the result is zero, the caller will assume the packet was 490 * passed to the protocol. 491 * If the result is non-zero and not EJUSTRETURN, the caller will 492 * free the packet. 493 */ 494 typedef errno_t (*proto_media_input)(ifnet_t ifp, protocol_family_t protocol, 495 mbuf_t packet, char *header); 496 497 /*! 498 * @typedef proto_media_input_v2 499 * @discussion proto_media_input_v2 is called for all inbound packets for 500 * a specific protocol on a specific interface. This function is 501 * registered on an interface using ifnet_attach_protocolv2. 502 * proto_media_input_v2 differs from proto_media_input in that it 503 * will be called for a list of packets instead of once for each 504 * individual packet. The frame header can be retrieved using 505 * mbuf_pkthdr_header. 506 * @param ifp The interface the packet was received on. 507 * @param protocol The protocol of the packet received. 508 * @param packet The packet being input. 509 * @result 510 * If the result is zero, the caller will assume the packets were 511 * passed to the protocol. 512 * If the result is non-zero and not EJUSTRETURN, the caller will 513 * free the packets. 514 */ 515 typedef errno_t (*proto_media_input_v2)(ifnet_t ifp, protocol_family_t protocol, 516 mbuf_t packet); 517 518 /*! 519 * @typedef proto_media_preout 520 * @discussion proto_media_preout is called just before the packet 521 * is transmitted. This gives the proto_media_preout function an 522 * opportunity to specify the media specific frame type and 523 * destination. 524 * @param ifp The interface the packet will be sent on. 525 * @param protocol The protocol of the packet being sent 526 * (PF_INET/etc...). 527 * @param packet The packet being sent. 528 * @param dest The protocol level destination address. 529 * @param route A pointer to the routing structure for the packet. 530 * @param frame_type The media specific frame type. 531 * @param link_layer_dest The media specific destination. 532 * @result 533 * If the result is zero, processing will continue normally. If the 534 * result is non-zero, processing will stop. If the result is 535 * non-zero and not EJUSTRETURN, the packet will be freed by the 536 * caller. 537 */ 538 typedef errno_t (*proto_media_preout)(ifnet_t ifp, protocol_family_t protocol, 539 mbuf_t *packet, const struct sockaddr *dest, void *route, char *frame_type, 540 char *link_layer_dest); 541 542 /*! 543 * @typedef proto_media_event 544 * @discussion proto_media_event is called to notify this layer of 545 * interface specific events. 546 * @param ifp The interface. 547 * @param protocol The protocol family. 548 * @param event The event. 549 */ 550 typedef void (*proto_media_event)(ifnet_t ifp, protocol_family_t protocol, 551 const struct kev_msg *event); 552 553 /*! 554 * @typedef proto_media_ioctl 555 * @discussion proto_media_event allows this layer to handle ioctls. 556 * When an ioctl is handled, it is passed to the interface filters, 557 * protocol filters, protocol, and interface. If you do not support 558 * this ioctl, return EOPNOTSUPP. If you successfully handle the 559 * ioctl, return zero. If you return any error other than 560 * EOPNOTSUPP, other parts of the stack may not get an opportunity 561 * to process the ioctl. If you return EJUSTRETURN, processing will 562 * stop and a result of zero will be returned to the caller. 563 * 564 * All undefined ioctls are reserved for future use by Apple. If 565 * you need to communicate with your kext using an ioctl, please 566 * use SIOCSIFKPI and SIOCGIFKPI. 567 * @param ifp The interface. 568 * @param protocol The protocol family. 569 * @param command The ioctl command. 570 * @param argument The argument to the ioctl. 571 * @result 572 * See the discussion. 573 */ 574 typedef errno_t (*proto_media_ioctl)(ifnet_t ifp, protocol_family_t protocol, 575 unsigned long command, void *argument); 576 577 /*! 578 * @typedef proto_media_detached 579 * @discussion proto_media_detached notifies you that your protocol 580 * has been detached. 581 * @param ifp The interface. 582 * @param protocol The protocol family. 583 * @result 584 * See the discussion. 585 */ 586 typedef errno_t (*proto_media_detached)(ifnet_t ifp, protocol_family_t protocol); 587 588 /*! 589 * @typedef proto_media_resolve_multi 590 * @discussion proto_media_resolve_multi is called to resolve a 591 * protocol layer mulitcast address to a link layer multicast 592 * address. 593 * @param ifp The interface. 594 * @param proto_addr The protocol address. 595 * @param out_ll A sockaddr_dl to copy the link layer multicast in to. 596 * @param ll_len The length of data allocated for out_ll. 597 * @result Return zero on success or an errno error value on failure. 598 */ 599 typedef errno_t (*proto_media_resolve_multi)(ifnet_t ifp, 600 const struct sockaddr *proto_addr, struct sockaddr_dl *out_ll, 601 size_t ll_len); 602 603 /*! 604 * @typedef proto_media_send_arp 605 * @discussion proto_media_send_arp is called by the stack to generate 606 * an ARP packet. This field is currently only used with IP. This 607 * function should inspect the parameters and transmit an arp 608 * packet using the information passed in. 609 * @param ifp The interface the arp packet should be sent on. 610 * @param arpop The arp operation (usually ARPOP_REQUEST or 611 * ARPOP_REPLY). 612 * @param sender_hw The value to use for the sender hardware 613 * address field. If this is NULL, use the hardware address 614 * of the interface. 615 * @param sender_proto The value to use for the sender protocol 616 * address field. This will not be NULL. 617 * @param target_hw The value to use for the target hardware address. 618 * If this is NULL, the target hardware address in the ARP packet 619 * should be NULL and the link-layer destination for the back 620 * should be a broadcast. If this is not NULL, this value should be 621 * used for both the link-layer destination and the target hardware 622 * address. 623 * @param target_proto The target protocol address. This will not be 624 * NULL. 625 * @result Return zero on success or an errno error value on failure. 626 */ 627 typedef errno_t (*proto_media_send_arp)(ifnet_t ifp, u_short arpop, 628 const struct sockaddr_dl *sender_hw, const struct sockaddr *sender_proto, 629 const struct sockaddr_dl *target_hw, const struct sockaddr *target_proto); 630 631 /*! 632 * @struct ifnet_stat_increment_param 633 * @discussion This structure is used increment the counters on a 634 * network interface. 635 * @field packets_in The number of packets received. 636 * @field bytes_in The number of bytes received. 637 * @field errors_in The number of receive errors. 638 * @field packets_out The number of packets transmitted. 639 * @field bytes_out The number of bytes transmitted. 640 * @field errors_out The number of transmission errors. 641 * @field collisions The number of collisions seen by this interface. 642 * @field dropped The number of packets dropped. 643 */ 644 struct ifnet_stat_increment_param { 645 u_int32_t packets_in; 646 u_int32_t bytes_in; 647 u_int32_t errors_in; 648 649 u_int32_t packets_out; 650 u_int32_t bytes_out; 651 u_int32_t errors_out; 652 653 u_int32_t collisions; 654 u_int32_t dropped; 655 }; 656 657 /*! 658 * @struct ifnet_init_params 659 * @discussion This structure is used to define various properties of 660 * the interface when calling ifnet_allocate. A copy of these 661 * values will be stored in the ifnet and cannot be modified 662 * while the interface is attached. 663 * @field uniqueid An identifier unique to this instance of the 664 * interface. 665 * @field uniqueid_len The length, in bytes, of the uniqueid. 666 * @field name The interface name (i.e. en). 667 * @field unit The interface unit number (en0's unit number is 0). 668 * @field family The interface family. 669 * @field type The interface type (see sys/if_types.h). Must be less 670 * than 256. For new types, use IFT_OTHER. 671 * @field output The output function for the interface. Every packet the 672 * stack attempts to send through this interface will go out 673 * through this function. 674 * @field demux The function used to determine the protocol family of an 675 * incoming packet. 676 * @field add_proto The function used to attach a protocol to this 677 * interface. 678 * @field del_proto The function used to remove a protocol from this 679 * interface. 680 * @field framer The function used to frame outbound packets, may be NULL. 681 * @field softc Driver specific storage. This value can be retrieved from 682 * the ifnet using the ifnet_softc function. 683 * @field ioctl The function used to handle ioctls. 684 * @field set_bpf_tap The function used to set the bpf_tap function. 685 * @field detach The function called to let the driver know the interface 686 * has been detached. 687 * @field event The function to notify the interface of various interface 688 * specific kernel events. 689 * @field broadcast_addr The link-layer broadcast address for this 690 * interface. 691 * @field broadcast_len The length of the link-layer broadcast address. 692 */ 693 struct ifnet_init_params { 694 /* used to match recycled interface */ 695 const void *uniqueid; /* optional */ 696 u_int32_t uniqueid_len; /* optional */ 697 698 /* used to fill out initial values for interface */ 699 const char *name; /* required */ 700 u_int32_t unit; /* required */ 701 ifnet_family_t family; /* required */ 702 u_int32_t type; /* required */ 703 ifnet_output_func output; /* required */ 704 ifnet_demux_func demux; /* required */ 705 ifnet_add_proto_func add_proto; /* required */ 706 ifnet_del_proto_func del_proto; /* required */ 707 ifnet_check_multi check_multi; /* required for non point-to-point interfaces */ 708 ifnet_framer_func framer; /* optional */ 709 void *softc; /* optional */ 710 ifnet_ioctl_func ioctl; /* optional */ 711 ifnet_set_bpf_tap set_bpf_tap; /* deprecated */ 712 ifnet_detached_func detach; /* optional */ 713 ifnet_event_func event; /* optional */ 714 const void *broadcast_addr; /* required for non point-to-point interfaces */ 715 u_int32_t broadcast_len; /* required for non point-to-point interfaces */ 716 }; 717 718 #ifdef KERNEL_PRIVATE 719 /* Valid values for version */ 720 #define IFNET_INIT_VERSION_2 2 721 #define IFNET_INIT_CURRENT_VERSION IFNET_INIT_VERSION_2 722 723 /* Valid values for flags */ 724 #define IFNET_INIT_LEGACY 0x1 /* legacy network interface model */ 725 #define IFNET_INIT_INPUT_POLL 0x2 /* opportunistic input polling model */ 726 #define IFNET_INIT_NX_NOAUTO 0x4 /* do not auto config nexus */ 727 #define IFNET_INIT_ALLOC_KPI 0x8 /* allocated via the ifnet_alloc() KPI */ 728 #define IFNET_INIT_IF_ADV 0x40000000 /* Supports Interface advisory reporting */ 729 #define IFNET_INIT_SKYWALK_NATIVE 0x80000000 /* native Skywalk driver */ 730 731 /* 732 * @typedef ifnet_pre_enqueue_func 733 * @discussion ifnet_pre_enqueue_func is called for each outgoing packet 734 * for the interface. The driver may perform last-minute changes 735 * on the (fully formed) packet, but it is responsible for calling 736 * ifnet_enqueue() to enqueue the packet upon completion. 737 * @param interface The interface being sent on. 738 * @param data The packet to be sent. 739 */ 740 typedef errno_t (*ifnet_pre_enqueue_func)(ifnet_t interface, mbuf_t data); 741 742 /* 743 * @typedef ifnet_start_func 744 * @discussion ifnet_start_func is used to indicate to the driver that 745 * one or more packets may be dequeued by calling ifnet_dequeue() 746 * or ifnet_dequeue_multi() or ifnet_dequeue_multi_bytes(). 747 * This routine gets invoked when ifnet_start() is called; 748 * the ifnet_start_func callback will be executed within the 749 * context of a dedicated kernel thread, hence it is 750 * guaranteed to be single threaded. The driver must employ 751 * additional serializations if this callback routine is 752 * to be called directly from another context, in order to 753 * prevent race condition related issues (e.g. out-of-order 754 * packets.) The dequeued packets will be fully formed 755 * packets (including frame headers). The packets must be 756 * freed by the driver. 757 * @param interface The interface being sent on. 758 */ 759 typedef void (*ifnet_start_func)(ifnet_t interface); 760 761 /* 762 * @typedef ifnet_input_poll_func 763 * @discussion ifnet_input_poll_func is called by the network stack to 764 * retrieve one or more packets from the driver which implements 765 * the new driver input model. 766 * @param interface The interface to retrieve the packets from. 767 * @param flags For future use. 768 * @param max_count The maximum number of packets to be dequeued. 769 * @param first_packet Pointer to the first packet being dequeued. 770 * @param last_packet Pointer to the last packet being dequeued. 771 * @param cnt Pointer to a storage for the number of packets dequeued. 772 * @param len Pointer to a storage for the total length (in bytes) 773 * of the dequeued packets. 774 */ 775 typedef void (*ifnet_input_poll_func)(ifnet_t interface, u_int32_t flags, 776 u_int32_t max_count, mbuf_t *first_packet, mbuf_t *last_packet, 777 u_int32_t *cnt, u_int32_t *len); 778 779 /*! 780 * @typedef ifnet_free_func 781 * @discussion ifnet_free_func is called as an alternative to ifnet_detach_func 782 * on a specific interface. Implementors of this callback are responsible 783 * for fully tearing down the interface. 784 * @param interface The interface that should be freed 785 */ 786 typedef void (*ifnet_free_func)(ifnet_t interface); 787 788 /* 789 * @enum Interface control commands 790 * @abstract Constants defining control commands. 791 * @discussion 792 * @constant IFNET_CTL_SET_INPUT_MODEL Set input model. 793 * @constant IFNET_CTL_GET_INPUT_MODEL Get input model. 794 * @constant IFNET_CTL_SET_LOG Set logging level. 795 * @constant IFNET_CTL_GET_LOG Get logging level. 796 */ 797 enum { 798 IFNET_CTL_SET_INPUT_MODEL = 1, /* input ctl */ 799 IFNET_CTL_GET_INPUT_MODEL = 2, /* input ctl */ 800 IFNET_CTL_SET_LOG = 3, /* output ctl */ 801 IFNET_CTL_GET_LOG = 4, /* output ctl */ 802 IFNET_CTL_NOTIFY_ADDRESS = 5 /* output ctl */ 803 }; 804 805 /* 806 * @typedef ifnet_ctl_cmd_t 807 * @abstract Storage type for the interface control command. 808 */ 809 typedef u_int32_t ifnet_ctl_cmd_t; 810 811 /* 812 * @enum Interface model sub-commands 813 * @abstract Constants defining model sub-commands. 814 * @discussion 815 * @constant IFNET_MODEL_INPUT_POLL_OFF Polling is inactive. When set, 816 * the network stack will no longer invoke the input_poll callback 817 * until the next time polling is turned on; the driver should 818 * proceed to pushing the packets up to the network stack as in 819 * the legacy input model, and if applicable, the driver should 820 * also enable receive interrupt for the hardware. During get, 821 * this indicates that the driver is currently operating in 822 * the legacy/push input model. 823 * @constant IFNET_MODEL_INPUT_POLL_ON Polling is active. When set, the 824 * network stack will begin to invoke the input_poll callback to 825 * retrieve packets from the driver until the next time polling 826 * is turned off; the driver should no longer be pushing packets 827 * up to the network stack, and if applicable, the driver should 828 * also disable receive interrupt for the hardware. During get, 829 * this indicates that the driver is currently operating in 830 * the new/pull input model. 831 */ 832 enum { 833 IFNET_MODEL_INPUT_POLL_OFF = 0, 834 IFNET_MODEL_INPUT_POLL_ON = 1, 835 }; 836 837 /* 838 * @typedef ifnet_model_t 839 * @abstract Storage type for the interface model sub-command. 840 */ 841 typedef u_int32_t ifnet_model_t; 842 843 /* 844 * @struct ifnet_model_params 845 * @discussion This structure is used as parameter to the ifnet model 846 * sub-commands. 847 * @field model The interface model. 848 */ 849 struct ifnet_model_params { 850 ifnet_model_t model; 851 u_int32_t reserved[3]; 852 }; 853 854 /* 855 * @enum Interface logging sub-commands. 856 * @abstract Constants defining logging levels/priorities. A level 857 * includes all other levels below it. It is expected that 858 * verbosity increases along with the level. 859 * @discussion 860 * @constant IFNET_LOG_DEFAULT Revert to default logging level. 861 * @constant IFNET_LOG_ALERT Log actions that must be taken immediately. 862 * @constant IFNET_LOG_CRITICAL Log critical conditions. 863 * @constant IFNET_LOG_ERROR Log error conditions. 864 * @constant IFNET_LOG_WARNING Log warning conditions. 865 * @constant IFNET_LOG_NOTICE Log normal but significant conditions. 866 * @constant IFNET_LOG_INFORMATIONAL Log informational messages. 867 * @constant IFNET_LOG_DEBUG Log debug-level messages. 868 */ 869 enum { 870 IFNET_LOG_DEFAULT = 0, 871 IFNET_LOG_ALERT = 1, 872 IFNET_LOG_CRITICAL = 2, 873 IFNET_LOG_ERROR = 3, 874 IFNET_LOG_WARNING = 4, 875 IFNET_LOG_NOTICE = 5, 876 IFNET_LOG_INFORMATIONAL = 6, 877 IFNET_LOG_DEBUG = 7 878 }; 879 880 #ifdef BSD_KERNEL_PRIVATE 881 #define IFNET_LOG_MIN IFNET_LOG_DEFAULT 882 #define IFNET_LOG_MAX IFNET_LOG_DEBUG 883 #endif /* BSD_KERNEL_PRIVATE */ 884 885 /* 886 * @typedef ifnet_log_level_t 887 * @abstract Storage type for log level/priority. 888 */ 889 typedef int32_t ifnet_log_level_t; 890 891 /* 892 * @enum Interface logging facilities 893 * @abstract Constants defining the logging facilities which 894 * are to be configured with the specified logging level. 895 * @discussion 896 * @constant IFNET_LOGF_DLIL The DLIL layer. 897 * @constant IFNET_LOGF_FAMILY The networking family layer. 898 * @constant IFNET_LOGF_DRIVER The device driver layer. 899 * @constant IFNET_LOGF_FIRMWARE The firmware layer. 900 */ 901 enum { 902 IFNET_LOGF_DLIL = 0x00000001, 903 IFNET_LOGF_FAMILY = 0x00010000, 904 IFNET_LOGF_DRIVER = 0x01000000, 905 IFNET_LOGF_FIRMWARE = 0x10000000 906 }; 907 908 #ifdef BSD_KERNEL_PRIVATE 909 #define IFNET_LOGF_MASK \ 910 (IFNET_LOGF_DLIL | IFNET_LOGF_FAMILY | IFNET_LOGF_DRIVER | \ 911 IFNET_LOGF_FIRMWARE) 912 913 #define IFNET_LOGF_BITS \ 914 "\020\1DLIL\21FAMILY\31DRIVER\35FIRMWARE" 915 916 #endif /* BSD_KERNEL_PRIVATE */ 917 918 /* 919 * @typedef ifnet_log_flags_t 920 * @abstract Storage type for log flags/facilities. 921 */ 922 typedef u_int32_t ifnet_log_flags_t; 923 924 /* 925 * @enum Interface logging category 926 * @abstract Constants defininig categories for issues experienced. 927 * @discussion 928 * @constant IFNET_LOGCAT_CONNECTIVITY Connectivity related issues. 929 * @constant IFNET_LOGCAT_QUALITY Quality/fidelity related issues. 930 * @constant IFNET_LOGCAT_PERFORMANCE Performance related issues. 931 */ 932 enum { 933 IFNET_LOGCAT_CONNECTIVITY = 1, 934 IFNET_LOGCAT_QUALITY = 2, 935 IFNET_LOGCAT_PERFORMANCE = 3 936 }; 937 938 /* 939 * @typedef ifnet_log_category_t 940 * @abstract Storage type for log category. 941 */ 942 typedef int32_t ifnet_log_category_t; 943 944 /* 945 * @typedef ifnet_log_subcategory_t 946 * @abstract Storage type for log subcategory. This is largely opaque 947 * and it can be used for IOReturn values, etc. 948 */ 949 typedef int32_t ifnet_log_subcategory_t; 950 951 /* 952 * @struct ifnet_log_params 953 * @discussion This structure is used as parameter to the ifnet 954 * logging sub-commands. 955 * @field level The logging level/priority. 956 * @field flags The logging flags/facilities. 957 * @field category The category of issue. 958 * @field subcategory The subcategory of issue. 959 */ 960 struct ifnet_log_params { 961 ifnet_log_level_t level; 962 ifnet_log_flags_t flags; 963 ifnet_log_category_t category; 964 ifnet_log_subcategory_t subcategory; 965 }; 966 967 /* 968 * @struct ifnet_notify_address_params 969 * @discussion This structure is used as parameter to the ifnet 970 * address notification sub-command. This is used to indicate 971 * to the family/driver that one or more addresses of the given 972 * address family has been added to, or removed from the list 973 * of addresses on the interface. The driver may query for the 974 * current address list by calling ifnet_get_address_list_family(). 975 * @field address_family The address family of the interface address(es). 976 */ 977 struct ifnet_notify_address_params { 978 sa_family_t address_family; 979 u_int32_t reserved[3]; 980 }; 981 982 /* 983 * @typedef ifnet_ctl_func 984 * @discussion ifnet_ctl_func is called by the network stack to inform 985 * about changes in parameters, or retrieve the parameters 986 * related to the output or input processing or capabilities. 987 * @param interface The interface. 988 * @param cmd The ifnet_ctl_cmd_t interface control command. 989 * @param arglen The length of the command argument. 990 * @param arg The command argument. 991 * @result 0 upon success, otherwise errno error. 992 */ 993 typedef errno_t (*ifnet_ctl_func)(ifnet_t interface, ifnet_ctl_cmd_t cmd, 994 u_int32_t arglen, void *arg); 995 996 /* 997 * @struct ifnet_init_eparams 998 * @discussion This structure is used to define various properties of 999 * the interface when calling ifnet_allocate_extended. A copy of 1000 * these values will be stored in the ifnet and cannot be modified 1001 * while the interface is attached. 1002 * @field ver The current structure version (IFNET_INIT_CURRENT_VERSION) 1003 * @field len The length of this structure. 1004 * @field flags See above values for flags. 1005 * @field uniqueid An identifier unique to this instance of the 1006 * interface. 1007 * @field uniqueid_len The length, in bytes, of the uniqueid. 1008 * @field name The interface name (i.e. en). 1009 * @field unit The interface unit number (en0's unit number is 0). 1010 * @field family The interface family. 1011 * @field type The interface type (see sys/if_types.h). Must be less 1012 * than 256. For new types, use IFT_OTHER. 1013 * @field sndq_maxlen The maximum size of the output queue; valid only 1014 * if IFNET_INIT_LEGACY is not set. 1015 * @field output The output function for the interface. Every packet the 1016 * stack attempts to send through this interface will go out 1017 * through this function. 1018 * @field pre_enqueue The pre_enqueue function for the interface, valid 1019 * only if IFNET_INIT_LEGACY is not set, and optional if it is set. 1020 * @field start The start function for the interface, valid and required 1021 * only if IFNET_INIT_LEGACY is not set. 1022 * @field output_ctl The output control function for the interface, valid 1023 * only if IFNET_INIT_LEGACY is not set. 1024 * @field output_sched_model The IFNET_SCHED_MODEL value for the output 1025 * queue, as defined in net/if.h 1026 * @field output_target_qdelay The target queue delay is used for 1027 * dynamically sizing the output queue, valid only if 1028 * IFNET_INIT_LEGACY is not set. 1029 * @field output_bw The effective output bandwidth (in bits per second.) 1030 * @field output_bw_max The maximum theoretical output bandwidth 1031 * (in bits per second.) 1032 * @field output_lt The effective output latency (in nanosecond.) 1033 * @field output_lt_max The maximum theoretical output latency 1034 * (in nanosecond.) 1035 * @field start_delay_qlen The maximum length of output queue for 1036 * delaying start callback to the driver. This is an 1037 * optimization for coalescing output packets. 1038 * @field start_delay_timeout The timeout in microseconds to delay 1039 * start callback. If start_delay_qlen number of packets are 1040 * not in the output queue when the timer fires, the start 1041 * callback will be invoked. Maximum allowed value is 1042 * 20ms (in microseconds). 1043 * @field input_poll The poll function for the interface, valid only if 1044 * IFNET_INIT_LEGACY is not set and only if IFNET_INIT_INPUT_POLL 1045 * is set. 1046 * @field input_ctl The input control function for the interface, valid 1047 * only if IFNET_INIT_LEGACY is not set and only if opportunistic 1048 * input polling is enabled via IFNET_INIT_INPUT_POLL flag. 1049 * @field rcvq_maxlen The size of the driver's receive ring or the total 1050 * count of descriptors used in the receive path; valid only if 1051 * IFNET_INIT_INPUT_POLL is set. 1052 * @field input_bw The effective input bandwidth (in bits per second.) 1053 * @field input_bw_max The maximum theoretical input bandwidth 1054 * (in bits per second.) 1055 * @field input_lt The effective input latency (in nanosecond.) 1056 * @field input_lt_max The maximum theoretical input latency 1057 * (in nanosecond.) 1058 * @field demux The function used to determine the protocol family of an 1059 * incoming packet. 1060 * @field add_proto The function used to attach a protocol to this 1061 * interface. 1062 * @field del_proto The function used to remove a protocol from this 1063 * interface. 1064 * @field framer The function used to frame outbound packets, may be NULL. 1065 * @field framer_extended The function used to frame outbound packets, 1066 * in the newer form; may be NULL. If specified, it will override 1067 * the value set via framer. 1068 * @field softc Driver specific storage. This value can be retrieved from 1069 * the ifnet using the ifnet_softc function. 1070 * @field ioctl The function used to handle ioctls. 1071 * @field set_bpf_tap The function used to set the bpf_tap function. 1072 * @field detach The function called to let the driver know the interface 1073 * has been detached. 1074 * @field event The function to notify the interface of various interface 1075 * specific kernel events. 1076 * @field broadcast_addr The link-layer broadcast address for this 1077 * interface. 1078 * @field broadcast_len The length of the link-layer broadcast address. 1079 * @field tx_headroom The amount of headroom space to be reserved in the 1080 * packet being transmitted on the interface, specified in bytes. 1081 * Must be a multiple of 8 bytes. 1082 * @field tx_trailer The amount of trailer space to be reserved in the 1083 * packet being transmitted on the interface, specified in bytes. 1084 * @field rx_mit_ival mitigation interval for the rx mitigation logic, 1085 * specified in microseconds. 1086 */ 1087 struct ifnet_init_eparams { 1088 u_int32_t ver; /* required */ 1089 u_int32_t len; /* required */ 1090 u_int32_t flags; /* optional */ 1091 1092 /* used to match recycled interface */ 1093 const void *uniqueid; /* optional */ 1094 u_int32_t uniqueid_len; /* optional */ 1095 1096 /* used to fill out initial values for interface */ 1097 const char *name; /* required */ 1098 u_int32_t unit; /* required */ 1099 ifnet_family_t family; /* required */ 1100 u_int32_t type; /* required */ 1101 u_int32_t sndq_maxlen; /* optional, only for new model */ 1102 ifnet_output_func output; /* required only for legacy model */ 1103 ifnet_pre_enqueue_func pre_enqueue; /* optional, only for new model */ 1104 ifnet_start_func start; /* required only for new model */ 1105 ifnet_ctl_func output_ctl; /* optional, only for new model */ 1106 u_int32_t output_sched_model; /* optional, only for new model */ 1107 u_int32_t output_target_qdelay; /* optional, only for new model, value in ms */ 1108 u_int64_t output_bw; /* optional */ 1109 u_int64_t output_bw_max; /* optional */ 1110 u_int64_t output_lt; /* optional */ 1111 u_int64_t output_lt_max; /* optional */ 1112 u_int16_t start_delay_qlen; /* optional */ 1113 u_int16_t start_delay_timeout; /* optional */ 1114 u_int32_t _reserved[3]; /* for future use */ 1115 ifnet_input_poll_func input_poll; /* optional, ignored for legacy model */ 1116 ifnet_ctl_func input_ctl; /* required for opportunistic polling */ 1117 u_int32_t rcvq_maxlen; /* optional, only for opportunistic polling */ 1118 u_int32_t __reserved; /* for future use */ 1119 u_int64_t input_bw; /* optional */ 1120 u_int64_t input_bw_max; /* optional */ 1121 u_int64_t input_lt; /* optional */ 1122 u_int64_t input_lt_max; /* optional */ 1123 u_int64_t ___reserved[2]; /* for future use */ 1124 ifnet_demux_func demux; /* required */ 1125 ifnet_add_proto_func add_proto; /* required */ 1126 ifnet_del_proto_func del_proto; /* required */ 1127 ifnet_check_multi check_multi; /* required for non point-to-point interfaces */ 1128 ifnet_framer_func framer; /* optional */ 1129 void *softc; /* optional */ 1130 ifnet_ioctl_func ioctl; /* optional */ 1131 ifnet_set_bpf_tap set_bpf_tap; /* deprecated */ 1132 ifnet_detached_func detach; /* optional */ 1133 ifnet_event_func event; /* optional */ 1134 const void *broadcast_addr; /* required for non point-to-point interfaces */ 1135 u_int32_t broadcast_len; /* required for non point-to-point interfaces */ 1136 ifnet_framer_extended_func framer_extended; /* optional */ 1137 ifnet_subfamily_t subfamily; /* optional */ 1138 u_int16_t tx_headroom; /* optional */ 1139 u_int16_t tx_trailer; /* optional */ 1140 u_int32_t rx_mit_ival; /* optional */ 1141 #if !defined(__LP64__) 1142 ifnet_free_func free; /* optional */ 1143 u_int32_t _____reserved; /* for future use */ 1144 u_int64_t ____reserved[1]; /* for future use */ 1145 #else 1146 u_int32_t ____reserved; /* for future use */ 1147 ifnet_free_func free; /* optional */ 1148 #endif /* __LP64__ */ 1149 }; 1150 #endif /* KERNEL_PRIVATE */ 1151 1152 /*! 1153 * @struct ifnet_stats_param 1154 * @discussion This structure is used get and set the interface 1155 * statistics. 1156 * @field packets_in The number of packets received. 1157 * @field bytes_in The number of bytes received. 1158 * @field errors_in The number of receive errors. 1159 * @field packets_out The number of packets transmitted. 1160 * @field bytes_out The number of bytes transmitted. 1161 * @field errors_out The number of transmission errors. 1162 * @field collisions The number of collisions seen by this interface. 1163 * @field dropped The number of packets dropped. 1164 */ 1165 struct ifnet_stats_param { 1166 u_int64_t packets_in; 1167 u_int64_t bytes_in; 1168 u_int64_t multicasts_in; 1169 u_int64_t errors_in; 1170 1171 u_int64_t packets_out; 1172 u_int64_t bytes_out; 1173 u_int64_t multicasts_out; 1174 u_int64_t errors_out; 1175 1176 u_int64_t collisions; 1177 u_int64_t dropped; 1178 u_int64_t no_protocol; 1179 }; 1180 1181 /*! 1182 * @struct ifnet_demux_desc 1183 * @discussion This structure is to identify packets that belong to a 1184 * specific protocol. The types supported are interface specific. 1185 * Ethernet supports ETHER_DESC_ETYPE2, ETHER_DESC_SAP, and 1186 * ETHER_DESC_SNAP. The type defines the offset in the packet where 1187 * the data will be matched as well as context. For example, if 1188 * ETHER_DESC_SNAP is specified, the only valid datalen is 5 and 1189 * only in the 5 bytes will only be matched when the packet header 1190 * indicates that the packet is a SNAP packet. 1191 * @field type The type of identifier data (i.e. ETHER_DESC_ETYPE2) 1192 * @field data A pointer to an entry of type (i.e. pointer to 0x0800). 1193 * @field datalen The number of bytes of data used to describe the 1194 * packet. 1195 */ 1196 struct ifnet_demux_desc { 1197 u_int32_t type; 1198 void *data; 1199 u_int32_t datalen; 1200 }; 1201 1202 /*! 1203 * @struct ifnet_attach_proto_param 1204 * @discussion This structure is used to attach a protocol to an 1205 * interface. This structure provides the various functions for 1206 * handling operations related to the protocol on the interface as 1207 * well as information for how to demux packets for this protocol. 1208 * @field demux_array An array of ifnet_demux_desc structures 1209 * describing the protocol. 1210 * @field demux_count The number of entries in the demux_array array. 1211 * @field input The function to be called for inbound packets. 1212 * @field pre_output The function to be called for outbound packets. 1213 * @field event The function to be called for interface events. 1214 * @field ioctl The function to be called for ioctls. 1215 * @field detached The function to be called for handling the detach. 1216 */ 1217 #ifdef KERNEL_PRIVATE 1218 #define demux_list demux_array 1219 #endif /* KERNEL_PRIVATE */ 1220 1221 struct ifnet_attach_proto_param { 1222 struct ifnet_demux_desc *demux_array; /* interface may/may not require */ 1223 u_int32_t demux_count; /* interface may/may not require */ 1224 1225 proto_media_input input; /* required */ 1226 proto_media_preout pre_output; /* required */ 1227 proto_media_event event; /* optional */ 1228 proto_media_ioctl ioctl; /* optional */ 1229 proto_media_detached detached; /* optional */ 1230 proto_media_resolve_multi resolve; /* optional */ 1231 proto_media_send_arp send_arp; /* optional */ 1232 }; 1233 1234 struct ifnet_attach_proto_param_v2 { 1235 struct ifnet_demux_desc *demux_array; /* interface may/may not require */ 1236 u_int32_t demux_count; /* interface may/may not require */ 1237 1238 proto_media_input_v2 input; /* required */ 1239 proto_media_preout pre_output; /* required */ 1240 proto_media_event event; /* optional */ 1241 proto_media_ioctl ioctl; /* optional */ 1242 proto_media_detached detached; /* optional */ 1243 proto_media_resolve_multi resolve; /* optional */ 1244 proto_media_send_arp send_arp; /* optional */ 1245 }; 1246 1247 __BEGIN_DECLS 1248 1249 /* 1250 * Ifnet creation and reference counting 1251 */ 1252 1253 /*! 1254 * @function ifnet_allocate 1255 * @discussion Allocate an ifnet_t with an initial refcount of 1. Many 1256 * parts of the stack do not properly refcount the ifnet_t. In 1257 * order to avoid freeing the ifnet_t while some parts of the stack 1258 * may contain a reference to it, the ifnet_ts are only recycled, 1259 * never freed. A unique id is used to try and recycle the same 1260 * ifnet_t when allocating an interface. For example, for an 1261 * ethernet interface, the hardware address of the ethernet card is 1262 * usually used for the uniqueid. If a PC Card is removed and 1263 * inserted again, if the ethernet address of the PC card is used, 1264 * the same ifnet_t will be used for the card the second time it is 1265 * inserted. In the future, when the ifnet_t is correctly 1266 * refcounted by all of the stack, the interfaces may be freed and 1267 * the unique ids ignored. 1268 * @param init The initial values for the interface. These values can 1269 * not be changed after the interface has been allocated. 1270 * @param interface The interface allocated upon success. 1271 * @result May return ENOMEM if there is insufficient memory or EEXIST 1272 * if an interface with the same uniqueid and family has already 1273 * been allocated and is in use. 1274 */ 1275 #ifdef KERNEL_PRIVATE 1276 extern errno_t ifnet_allocate_internal(const struct ifnet_init_params *init, 1277 ifnet_t *interface); 1278 1279 #define ifnet_allocate(init, interface) \ 1280 ifnet_allocate_internal((init), (interface)) 1281 #else 1282 extern errno_t ifnet_allocate(const struct ifnet_init_params *init, 1283 ifnet_t *interface) 1284 __NKE_API_DEPRECATED; 1285 #endif /* KERNEL_PRIVATE */ 1286 1287 #ifdef KERNEL_PRIVATE 1288 /* 1289 * @function ifnet_allocate_extended 1290 * @discussion An extended/newer variant of ifnet_allocate, with additional 1291 * support for the new output and input driver models. 1292 * @param init The initial values for the interface. These values can 1293 * not be changed after the interface has been allocated. 1294 * @param interface The interface allocated upon success. 1295 * @result May return ENOMEM if there is insufficient memory or EBUSY 1296 * if an interface with the same uniqueid/(name + unit) and family has already 1297 * been allocated and is in use. 1298 */ 1299 extern errno_t ifnet_allocate_extended(const struct ifnet_init_eparams *init, 1300 ifnet_t *interface); 1301 1302 /* 1303 * @function ifnet_dispose 1304 * @discusion Dispose the interface. This is meant to only be called 1305 * by clients that implement ifnet_free_func 1306 * @param interface The interface to dispose 1307 */ 1308 extern void ifnet_dispose(ifnet_t interface); 1309 1310 /* 1311 * @function ifnet_purge 1312 * @discussion Purge the output queue of an interface which implements 1313 * the new driver output model. 1314 * @param interface The interface to purge. 1315 */ 1316 extern void ifnet_purge(ifnet_t interface); 1317 1318 /* 1319 * @function ifnet_enqueue 1320 * @discussion Enqueue a packet to the output queue of an interface 1321 * which implements the new driver output model. 1322 * @param interface The interface to enqueue the packet to. 1323 * @param packet The packet being enqueued; only one packet is allowed 1324 * to be enqueued at a time. 1325 * @result May return EINVAL if the parameters are invalid; ENXIO if 1326 * the interface doesn't implement the new driver output model; 1327 * EQFULL if the output queue is flow-controlled; or EQSUSPENDED 1328 * if the output queue is suspended. This routine either frees 1329 * or consumes the packet; the caller must not modify or free 1330 * it after calling this routine. Any attempt to enqueue more 1331 * than one packet will cause the entire packet chain to be freed. 1332 */ 1333 extern errno_t ifnet_enqueue(ifnet_t interface, mbuf_t packet); 1334 1335 /* 1336 * @function ifnet_dequeue 1337 * @discussion Dequeue a packet from the output queue of an interface 1338 * which implements the new driver output model, and that the 1339 * output scheduling model is set to IFNET_SCHED_MODEL_NORMAL. 1340 * @param interface The interface to dequeue the packet from. 1341 * @param packet Pointer to the packet being dequeued. 1342 * @result May return EINVAL if the parameters are invalid, ENXIO if 1343 * the interface doesn't implement the new driver output model 1344 * or the output scheduling model isn't IFNET_SCHED_MODEL_NORMAL, 1345 * or EAGAIN if there is currently no packet available to 1346 * be dequeued. 1347 */ 1348 extern errno_t ifnet_dequeue(ifnet_t interface, mbuf_t *packet); 1349 1350 /* 1351 * @function ifnet_dequeue_service_class 1352 * @discussion Dequeue a packet of a particular service class from the 1353 * appropriate output queue of an interface which implements the 1354 * new driver output model, and that the output scheduling model 1355 * is set to IFNET_SCHED_MODEL_DRIVER_MANAGED. 1356 * @param interface The interface to dequeue the packet from. 1357 * @param sc The service class. 1358 * @param packet Pointer to the packet being dequeued. 1359 * @result May return EINVAL if the parameters are invalid, ENXIO if 1360 * the interface doesn't implement the new driver output model 1361 * or if the output scheduling model isn't configured to 1362 * IFNET_SCHED_MODEL_DRIVER_MANAGED, or EAGAIN if there 1363 * is currently no packet available to be dequeued. 1364 */ 1365 extern errno_t ifnet_dequeue_service_class(ifnet_t interface, 1366 mbuf_svc_class_t sc, mbuf_t *packet); 1367 1368 /* 1369 * @function ifnet_dequeue_multi 1370 * @discussion Dequeue one or more packets from the output queue of an 1371 * interface which implements the new driver output model, and that 1372 * the output scheduling model is set to IFNET_SCHED_MODEL_NORMAL. 1373 * The returned packet chain is traversable with mbuf_nextpkt(). 1374 * @param interface The interface to dequeue the packets from. 1375 * @param max The maximum number of packets in the packet chain that 1376 * may be returned to the caller; this needs to be a non-zero 1377 * value for any packet to be returned. 1378 * @param first_packet Pointer to the first packet being dequeued. 1379 * @param last_packet Pointer to the last packet being dequeued. Caller 1380 * may supply NULL if not interested in value. 1381 * @param cnt Pointer to a storage for the number of packets dequeued. 1382 * Caller may supply NULL if not interested in value. 1383 * @param len Pointer to a storage for the total length (in bytes) 1384 * of the dequeued packets. Caller may supply NULL if not 1385 * interested in value. 1386 * @result May return EINVAL if the parameters are invalid, ENXIO if 1387 * the interface doesn't implement the new driver output model 1388 * or the output scheduling model isn't IFNET_SCHED_MODEL_NORMAL, 1389 * or EAGAIN if there is currently no packet available to 1390 * be dequeued. 1391 */ 1392 extern errno_t ifnet_dequeue_multi(ifnet_t interface, u_int32_t max, 1393 mbuf_t *first_packet, mbuf_t *last_packet, u_int32_t *cnt, u_int32_t *len); 1394 1395 /* 1396 * @function ifnet_dequeue_multi_bytes 1397 * @discussion Dequeue one or more packets from the output queue of 1398 * an interface which implements the new driver output model, 1399 * where the scheduling model is set to 1400 * IFNET_SCHED_MODEL_NORMAL. The limit is specified in terms 1401 * of maximum number of bytes to return. The number of bytes 1402 * returned can be slightly higher than the limit so that 1403 * packet boundaries can be preserved. 1404 * @param interface The interface to dequeue the packets from 1405 * @param max_bytes The maximum number of bytes in the packet chain 1406 * that may be returned to the caller; this needs to be a 1407 * non-zero value for any packet to be returned. 1408 * @param first_packet Pointer to the first packet being dequeued 1409 * @param last_packet Pointer to the last packet being dequeued 1410 * @param cnt Pointer to a storage for the number of bytes dequeued. 1411 * Caller may supply NULL if not interested in this value 1412 * @param len Pointer to a storage for the total length (in bytes) 1413 * of the dequeued packets. Caller may supply NULL if not 1414 * interested in this value. 1415 * @result May return EINVAL if the parameters are invalid, ENXIO if 1416 * the interface doesn't implement the new driver output 1417 * model or the output scheduling model isn't 1418 * IFNET_SCHED_MODEL_NORMAL, or EAGAIN if there is currently 1419 * no packet available to be dequeued 1420 */ 1421 extern errno_t ifnet_dequeue_multi_bytes(ifnet_t interface, 1422 u_int32_t max_bytes, mbuf_t *first_packet, mbuf_t *last_packet, 1423 u_int32_t *cnt, u_int32_t *len); 1424 1425 /* 1426 * @function ifnet_dequeue_service_class_multi 1427 * @discussion Dequeue one or more packets of a particular service class 1428 * from the appropriate output queue of an interface which 1429 * implements the new driver output model, and that the output 1430 * scheduling model is set to IFNET_SCHED_MODEL_DRIVER_MANAGED. 1431 * The returned packet chain is traversable with mbuf_nextpkt(). 1432 * @param interface The interface to dequeue the packets from. 1433 * @param sc The service class. 1434 * @param max The maximum number of packets in the packet chain that 1435 * may be returned to the caller; this needs to be a non-zero 1436 * value for any packet to be returned. 1437 * @param first_packet Pointer to the first packet being dequeued. 1438 * @param last_packet Pointer to the last packet being dequeued. Caller 1439 * may supply NULL if not interested in value. 1440 * @param cnt Pointer to a storage for the number of packets dequeued. 1441 * Caller may supply NULL if not interested in value. 1442 * @param len Pointer to a storage for the total length (in bytes) 1443 * of the dequeued packets. Caller may supply NULL if not 1444 * interested in value. 1445 * @result May return EINVAL if the parameters are invalid, ENXIO if 1446 * the interface doesn't implement the new driver output model 1447 * or if the output scheduling model isn't configured to 1448 * IFNET_SCHED_MODEL_DRIVER_MANAGED, or EAGAIN if there 1449 * is currently no packet available to be dequeued. 1450 */ 1451 extern errno_t ifnet_dequeue_service_class_multi(ifnet_t interface, 1452 mbuf_svc_class_t sc, u_int32_t max, mbuf_t *first_packet, 1453 mbuf_t *last_packet, u_int32_t *cnt, u_int32_t *len); 1454 1455 /* 1456 * @function ifnet_set_output_sched_model 1457 * @discussion Set the output scheduling model of an interface which 1458 * implements the new driver output model. 1459 * @param interface The interface to set scheduling model on. 1460 * @param model The IFNET_SCHED_MODEL value as defined in net/if.h 1461 * @result May return EINVAL if the parameters are invalid or ENXIO if 1462 * the interface doesn't implement the new driver output model. 1463 */ 1464 extern errno_t ifnet_set_output_sched_model(ifnet_t interface, 1465 u_int32_t model); 1466 1467 /* 1468 * @function ifnet_set_sndq_maxlen 1469 * @discussion Set the maximum length of the output queue of an 1470 * interface which implements the new driver output model. 1471 * This call may be issued post ifnet_allocate_extended in 1472 * order to modify the maximum output queue length previously 1473 * set at registration time. 1474 * @param interface The interface to set the max queue length on. 1475 * @param maxqlen The maximum number of packets in the output queue. 1476 * @result May return EINVAL if the parameters are invalid or ENXIO if 1477 * the interface doesn't implement the new driver output model. 1478 */ 1479 extern errno_t ifnet_set_sndq_maxlen(ifnet_t interface, u_int32_t maxqlen); 1480 1481 /* 1482 * @function ifnet_get_sndq_maxlen 1483 * @discussion Get the maximum length of the output queue of an 1484 * interface which implements the new driver output model. 1485 * @param interface The interface to get the max queue length on. 1486 * @param maxqlen Pointer to a storage for the maximum number of packets 1487 * in the output queue for all service classes. 1488 * @result May return EINVAL if the parameters are invalid or ENXIO if 1489 * the interface doesn't implement the new driver output model. 1490 */ 1491 extern errno_t ifnet_get_sndq_maxlen(ifnet_t interface, u_int32_t *maxqlen); 1492 1493 /* 1494 * @function ifnet_get_sndq_len 1495 * @discussion Get the current length of the output queue of an 1496 * interface which implements the new driver output model. 1497 * @param interface The interface to get the current queue length on. 1498 * @param packets Pointer to a storage for the current number of packets 1499 * in the aggregate output queue. This number represents all 1500 * enqueued packets regardless of their service classes. 1501 * @result May return EINVAL if the parameters are invalid or ENXIO if 1502 * the interface doesn't implement the new driver output model. 1503 */ 1504 extern errno_t ifnet_get_sndq_len(ifnet_t interface, u_int32_t *packets); 1505 1506 /* 1507 * @function ifnet_get_service_class_sndq_len 1508 * @discussion Get the current length of the output queue for a specific 1509 * service class of an interface which implements the new driver 1510 * output model. 1511 * @param interface The interface to get the current queue length on. 1512 * @param sc The service class. 1513 * @param packets Pointer to a storage for the current number of packets 1514 * of the specific service class in the output queue; may be 1515 * NULL if caller is not interested in getting the value. Note 1516 * that multiple service classes may be mapped to an output queue; 1517 * this routine reports the packet count of that output queue. 1518 * @param bytes Pointer to a storage for the current size (in bytes) of 1519 * the output queue specific to the service class; may be NULL if 1520 * caller is not interested in getting the value. Note that 1521 * multiple service classes may be mapped to an output queue; 1522 * this routine reports the length of that output queue. 1523 * @result May return EINVAL if the parameters are invalid or ENXIO if 1524 * the interface doesn't implement the new driver output model. 1525 */ 1526 extern errno_t ifnet_get_service_class_sndq_len(ifnet_t interface, 1527 mbuf_svc_class_t sc, u_int32_t *packets, u_int32_t *bytes); 1528 1529 /* 1530 * @function ifnet_set_rcvq_maxlen 1531 * @discussion Set the maximum length of the input queue of an 1532 * interface which implements the new driver input model. 1533 * This call may be issued post ifnet_allocate_extended in 1534 * order to modify the maximum input queue length previously 1535 * set at registration time. 1536 * @param interface The interface to set the max queue length on. 1537 * @param maxqlen The maximum number of packets in the input queue. 1538 * Drivers typically set this to the size of the receive ring 1539 * or the total number of descriptors used for the input path. 1540 * @result May return EINVAL if the parameters are invalid or ENXIO if 1541 * the interface doesn't implement the new driver input model. 1542 */ 1543 extern errno_t ifnet_set_rcvq_maxlen(ifnet_t interface, u_int32_t maxqlen); 1544 1545 /* 1546 * @function ifnet_get_rcvq_maxlen 1547 * @discussion Get the maximum length of the input queue of an 1548 * interface which implements the new driver input model. 1549 * @param interface The interface to get the max queue length on. 1550 * @param maxqlen Pointer to a storage for the maximum number of packets 1551 * in the input queue. 1552 * @result May return EINVAL if the parameters are invalid or ENXIO if 1553 * the interface doesn't implement the new driver input model. 1554 */ 1555 extern errno_t ifnet_get_rcvq_maxlen(ifnet_t interface, u_int32_t *maxqlen); 1556 1557 /* 1558 * @struct ifnet_poll_params 1559 * @discussion This structure is used to define various opportunistic 1560 * polling parameters for an interface. 1561 * @field flags Currently unused/ignored; must be set to zero. 1562 * @field packets_limit The maximum number of packets to be dequeued 1563 * each time the driver's input poll callback is invoked while 1564 * in polling mode; this corresponds to the max_count parameter 1565 * of ifnet_input_poll_func. A zero value indicates the use of 1566 * default maximum packets defined by the system. 1567 * @field packets_lowat Low watermark packet threshold. 1568 * @field packets_hiwat High watermark packet threshold. 1569 * @field bytes_lowat Low watermark packet threshold. 1570 * @field bytes_hiwat High watermark packet threshold. 1571 * The low and high watermark inbound packet and bytes thresholds; 1572 * these values may be link rate dependent. Polling is enabled 1573 * when the average inbound packets or bytes goes above the 1574 * corresponding high watermark value; it stays in that mode until 1575 * both of the average inbound packets and bytes go below their 1576 * corresponding low watermark values. Zero watermark values 1577 * indicates the use of default thresholds as defined by the 1578 * system. Both low and high watermark values must either be 1579 * zeroes, or both must be non-zeroes with low watermark value 1580 * being less than the high watermark value. 1581 * @field interval_time The interval time between each invocation of 1582 * the driver's input poll callback, in nanoseconds. A zero 1583 * value indicates the use of default poll interval time as 1584 * defined by the system. If a non-zero value is specified and 1585 * is less than the minimum interval time, the latter will be 1586 * chosen by the system. 1587 */ 1588 struct ifnet_poll_params { 1589 u_int32_t flags; 1590 u_int32_t packets_limit; 1591 u_int32_t packets_lowat; 1592 u_int32_t packets_hiwat; 1593 u_int32_t bytes_lowat; 1594 u_int32_t bytes_hiwat; 1595 u_int64_t interval_time; 1596 u_int64_t reserved[4]; 1597 }; 1598 1599 typedef struct ifnet_poll_params ifnet_poll_params_t; 1600 1601 /* 1602 * @function ifnet_set_poll_params 1603 * @discussion Configures opportunistic input polling parameters on an 1604 * interface. This call may be issued post ifnet_attach in order 1605 * to modify the interface's polling parameters. The driver may 1606 * alter the default values chosen by the system to achieve the 1607 * optimal performance for a given link rate or driver dynamics. 1608 * @param interface The interface to configure opportunistic polling on. 1609 * @param poll_params Pointer to the polling parameters. If NULL, it 1610 * implies that the system should revert the interface's polling 1611 * parameter to their default values. 1612 * @result May return EINVAL if the parameters are invalid or ENXIO if 1613 * the interface doesn't implement the new driver input model. 1614 */ 1615 extern errno_t ifnet_set_poll_params(ifnet_t interface, 1616 ifnet_poll_params_t *poll_params); 1617 1618 /* 1619 * @function ifnet_poll_params 1620 * @discussion Retrieves opportunistic input polling parameters on an 1621 * interface. This call may be issued post ifnet_attach in order 1622 * to retrieve the interface's polling parameters. 1623 * @param interface The interface to configure opportunistic polling on. 1624 * @param poll_params Pointer to the polling parameters. 1625 * @result May return EINVAL if the parameters are invalid or ENXIO if 1626 * the interface doesn't implement the new driver input model. 1627 */ 1628 extern errno_t ifnet_poll_params(ifnet_t interface, 1629 ifnet_poll_params_t *poll_params); 1630 1631 /* 1632 * @function ifnet_start 1633 * @discussion Trigger the transmission at the driver layer on an 1634 * interface which implements the new driver output model. 1635 * @param interface The interface to start the transmission on. 1636 */ 1637 extern void ifnet_start(ifnet_t interface); 1638 1639 /* 1640 * @function ifnet_flowid 1641 * @discussion Returns the interface flow ID value, which can be used 1642 * by a (virtual) network interface for participating in the 1643 * FLOWSRC_IFNET flow advisory mechanism. The flow ID value 1644 * is available after the interface is attached. 1645 * @param interface The interface to retrieve the flow ID from. 1646 * @param flowid Pointer to the flow ID value. 1647 * @result May return EINVAL if the parameters are invalid or ENXIO if 1648 * the interface doesn't implement the new driver input model. 1649 */ 1650 extern errno_t ifnet_flowid(ifnet_t interface, u_int32_t *flowid); 1651 1652 /* 1653 * @function ifnet_enable_output 1654 * @discussion Enables output on a (virtual) interface if it has been 1655 * previously disabled via ifnet_disable_output(). This call 1656 * is used to override the flow advisory mechanism typically 1657 * used between a (virtual) network interface and a real network 1658 * interface beneath it. Under normal circumstances, the flow 1659 * advisory mechanism will automatically re-enable the (virtual) 1660 * interface's output mechanism when the real network interface 1661 * is able to transmit more data. Re-enabling output will cause 1662 * the (virtual) interface's start callback to be called again. 1663 * @param interface The interface to enable the transmission on. 1664 * @result May return EINVAL if the parameters are invalid or ENXIO if 1665 * the interface doesn't implement the new driver input model. 1666 */ 1667 extern errno_t ifnet_enable_output(ifnet_t interface); 1668 1669 /* 1670 * @function ifnet_disable_output 1671 * @discussion Disables output on a (virtual) interface. Disabling 1672 * output will cause the (virtual) interface's start callback 1673 * to go idle. This call is typically used by a (virtual) 1674 * interface upon receiving flow control feedbacks from the 1675 * real network interface beneath it, in order propagate the 1676 * flow control condition to the layers above. Under normal 1677 * circumstances, the flow advisory mechanism will automatically 1678 * re-enable the (virtual) interface's output mechanism when 1679 * the real network interface is able to transmit more data, 1680 * as long as the (virtual) interface participates in the 1681 * FLOWSRC_IFNET flow advisory for the data that it emits. 1682 * @param interface The interface to disable the transmission on. 1683 * @result May return EINVAL if the parameters are invalid or ENXIO if 1684 * the interface doesn't implement the new driver input model. 1685 */ 1686 extern errno_t ifnet_disable_output(ifnet_t interface); 1687 #endif /* KERNEL_PRIVATE */ 1688 1689 /*! 1690 * @function ifnet_reference 1691 * @discussion Increment the reference count of the ifnet to assure 1692 * that it will not go away. The interface must already have at 1693 * least one reference. 1694 * @param interface The interface to increment the reference count of. 1695 * @result May return EINVAL if the interface is not valid. 1696 */ 1697 extern errno_t ifnet_reference(ifnet_t interface) 1698 __NKE_API_DEPRECATED; 1699 1700 /*! 1701 * @function ifnet_release 1702 * @discussion Release a reference of the ifnet, this may trigger a 1703 * free if the reference count reaches 0. 1704 * @param interface The interface to decrement the reference count of 1705 * and possibly free. 1706 * @result May return EINVAL if the interface is not valid. 1707 */ 1708 extern errno_t ifnet_release(ifnet_t interface) 1709 __NKE_API_DEPRECATED; 1710 1711 /*! 1712 * @function ifnet_attach 1713 * @discussion Attaches an interface to the global interface list. The 1714 * interface must be setup properly before calling attach. The 1715 * stack will take a reference on the interface and hold it until 1716 * ifnet_detach is called. 1717 * 1718 * This function is intended to be called by the driver. A kext 1719 * must not call this function on an interface the kext does not 1720 * own. 1721 * @param interface The interface to attach. 1722 * @param ll_addr The link layer address of the interface. This is used 1723 * to fill out the first ifaddr in the list of addresses for the 1724 * interface. This parameter is not required for interfaces such as 1725 * PPP that have no link-layer address. 1726 * @result Will return an error if there is anything wrong with the 1727 * interface. 1728 */ 1729 extern errno_t ifnet_attach(ifnet_t interface, 1730 const struct sockaddr_dl *ll_addr) 1731 __NKE_API_DEPRECATED; 1732 1733 /*! 1734 * @function ifnet_detach 1735 * @discussion Detaches the interface. 1736 * 1737 * Call this to indicate this interface is no longer valid (i.e. PC 1738 * Card was removed). This function will begin the process of 1739 * removing knowledge of this interface from the stack. 1740 * 1741 * The function will return before the interface is detached. The 1742 * functions you supplied in to the interface may continue to be 1743 * called. When the detach has been completed, your detached 1744 * function will be called. Your kext must not unload until the 1745 * detached function has been called. The interface will be 1746 * properly freed when the reference count reaches zero. 1747 * 1748 * An interface may not be attached again. You must call 1749 * ifnet_allocate to create a new interface to attach. 1750 * 1751 * This function is intended to be called by the driver. A kext 1752 * must not call this function on an interface the kext does not 1753 * own. 1754 * @param interface The interface to detach. 1755 * @result 0 on success, otherwise errno error. 1756 */ 1757 extern errno_t ifnet_detach(ifnet_t interface) 1758 __NKE_API_DEPRECATED; 1759 1760 /*! 1761 * @function ifnet_interface_family_find 1762 * @discussion Look up the interface family identifier for a string. 1763 * If there is no interface family identifier assigned for this string 1764 * a new interface family identifier is created and assigned. 1765 * It is recommended to use the bundle id of the KEXT as the string 1766 * to avoid collisions with other KEXTs. 1767 * The lookup operation is not optimized so a module should call this 1768 * function once during startup and cache the interface family identifier. 1769 * The interface family identifier for a string will not be re-assigned until 1770 * the system reboots. 1771 * @param module_string A unique string identifying your interface family 1772 * @param family_id Upon return, a unique interface family identifier for use with 1773 * ifnet_* functions. This identifier is valid until the system 1774 * is rebooted. 1775 * @result 0 on success, otherwise errno error. 1776 */ 1777 extern errno_t ifnet_interface_family_find(const char *module_string, ifnet_family_t *family_id) 1778 __NKE_API_DEPRECATED; 1779 1780 /* 1781 * Interface manipulation. 1782 */ 1783 1784 /*! 1785 * @function ifnet_softc 1786 * @discussion Returns the driver's private storage on the interface. 1787 * @param interface Interface to retrieve the storage from. 1788 * @result Driver's private storage. 1789 */ 1790 extern void *ifnet_softc(ifnet_t interface) 1791 __NKE_API_DEPRECATED; 1792 1793 /*! 1794 * @function ifnet_name 1795 * @discussion Returns a pointer to the name of the interface. 1796 * @param interface Interface to retrieve the name from. 1797 * @result Pointer to the name. 1798 */ 1799 extern const char *ifnet_name(ifnet_t interface) 1800 __NKE_API_DEPRECATED; 1801 1802 /*! 1803 * @function ifnet_family 1804 * @discussion Returns the family of the interface. 1805 * @param interface Interface to retrieve the family from. 1806 * @result Interface family type. 1807 */ 1808 extern ifnet_family_t ifnet_family(ifnet_t interface) 1809 __NKE_API_DEPRECATED; 1810 1811 #ifdef KERNEL_PRIVATE 1812 /* 1813 * @function ifnet_subfamily 1814 * @discussion Returns the sub-family of the interface. 1815 * @param interface Interface to retrieve the sub-family from. 1816 * @result Interface sub-family type. 1817 */ 1818 extern ifnet_subfamily_t ifnet_subfamily(ifnet_t interface); 1819 #endif /* KERNEL_PRIVATE */ 1820 1821 /*! 1822 * @function ifnet_unit 1823 * @discussion Returns the unit number of the interface. 1824 * @param interface Interface to retrieve the unit number from. 1825 * @result Unit number. 1826 */ 1827 extern u_int32_t ifnet_unit(ifnet_t interface) 1828 __NKE_API_DEPRECATED; 1829 1830 1831 /*! 1832 * @function ifnet_index 1833 * @discussion Returns the index of the interface. This index value 1834 * will match the index you would find in a sockaddr_dl or using 1835 * if_nametoindex or if_indextoname in user space. The value of the 1836 * interface index is undefined for an interface that is not 1837 * currently attached. 1838 * @param interface Interface to retrieve the index of. 1839 * @result Index. 1840 */ 1841 extern u_int32_t ifnet_index(ifnet_t interface) 1842 __NKE_API_DEPRECATED; 1843 1844 /*! 1845 * @function ifnet_set_flags 1846 * @discussion Sets the interface flags to match new_flags. 1847 * @discussion Sets the interface flags to new_flags. This function 1848 * lets you specify which flags you want to change using the mask. 1849 * The kernel will effectively take the lock, then set the 1850 * interface's flags to (if_flags & ~mask) | (new_flags & mask). 1851 * @param interface Interface to set the flags on. 1852 * @param new_flags The new set of flags that should be set. These 1853 * flags are defined in net/if.h 1854 * @result 0 on success otherwise the errno error. 1855 */ 1856 extern errno_t ifnet_set_flags(ifnet_t interface, u_int16_t new_flags, 1857 u_int16_t mask) 1858 __NKE_API_DEPRECATED; 1859 1860 /*! 1861 * @function ifnet_flags 1862 * @discussion Returns the interface flags that are set. 1863 * @param interface Interface to retrieve the flags from. 1864 * @result Flags. These flags are defined in net/if.h 1865 */ 1866 extern u_int16_t ifnet_flags(ifnet_t interface) 1867 __NKE_API_DEPRECATED; 1868 1869 #ifdef KERNEL_PRIVATE 1870 /* 1871 * @function ifnet_set_eflags 1872 * @discussion Sets the extended interface flags to new_flags. This 1873 * function lets you specify which flags you want to change using 1874 * the mask. The kernel will effectively take the lock, then set 1875 * the interface's extended flags to (if_eflags & ~mask) | 1876 * (new_flags & mask). 1877 * @param interface The interface. 1878 * @param new_flags The new set of flags that should be set. These 1879 * flags are defined in net/if.h 1880 * @param mask The mask of flags to be modified. 1881 * @result 0 on success otherwise the errno error. 1882 */ 1883 extern errno_t ifnet_set_eflags(ifnet_t interface, u_int32_t new_flags, 1884 u_int32_t mask); 1885 1886 /* 1887 * @function ifnet_eflags 1888 * @discussion Returns the extended interface flags that are set. 1889 * @param interface Interface to retrieve the flags from. 1890 * @result Extended flags. These flags are defined in net/if.h 1891 */ 1892 extern u_int32_t ifnet_eflags(ifnet_t interface); 1893 1894 /* 1895 * @function ifnet_set_idle_flags 1896 * @discussion Sets the if_idle_flags to new_flags. This function 1897 * lets you specify which flags you want to change using the 1898 * mask. The kernel will effectively take the lock, then set 1899 * the interface's idle flags to: 1900 * (if_idle_flags & ~mask) | (new_flags & mask). 1901 * Setting the flags to any non-zero value will cause the 1902 * networking stack to aggressively purge expired objects, 1903 * such as route entries, etc. 1904 * @param interface The interface. 1905 * @param new_flags The new set of flags that should be set. These 1906 * flags are defined in net/if.h 1907 * @param mask The mask of flags to be modified. 1908 * @result 0 on success otherwise the errno error. ENOTSUP is returned 1909 * when this call is made on non-supporting platforms. 1910 */ 1911 extern errno_t ifnet_set_idle_flags(ifnet_t interface, u_int32_t new_flags, 1912 u_int32_t mask); 1913 1914 /* 1915 * @function ifnet_idle_flags 1916 * @discussion Returns the value of if_idle_flags. 1917 * @param interface Interface to retrieve the flags from. 1918 * @result if_idle_flags. These flags are defined in net/if.h 1919 */ 1920 extern u_int32_t ifnet_idle_flags(ifnet_t interface); 1921 1922 /* 1923 * @function ifnet_set_link_quality 1924 * @discussion Sets the Link Quality Metric for the ifnet. 1925 * @param interface Interface for which the Link Quality Metric should 1926 * be associated to. 1927 * @param quality IFNET_LQM value as defined in net/if.h. 1928 * @result 0 on success otherwise the errno error. EINVAL if quality 1929 * is not a valid value. ENXIO if the interface is not attached. 1930 */ 1931 extern errno_t ifnet_set_link_quality(ifnet_t interface, int quality); 1932 1933 /* 1934 * @function ifnet_link_quality 1935 * @discussion Returns the Link Quality Metric for the ifnet. 1936 * @param interface Interface to retrieve the value from. 1937 * @result IFNET_LQM as defined in net/if.h 1938 */ 1939 extern int ifnet_link_quality(ifnet_t interface); 1940 1941 /* 1942 * @function ifnet_set_interface_state 1943 * @discussion Sets the interface state for the ifnet. 1944 * @param interface Interface for which the interface state should 1945 * be set to. 1946 * @param if_interface_state as defined in net/if_var.h. 1947 * @result 0 on success otherwise the errno error. EINVAL if quality 1948 * is not a valid value. ENXIO if the interface is not attached. 1949 */ 1950 extern errno_t ifnet_set_interface_state(ifnet_t interface, 1951 struct if_interface_state *if_interface_state); 1952 1953 /* 1954 * @function ifnet_get_interface_state 1955 * @discussion Returns the interface state for the ifnet. 1956 * @param if_interface_state to ret. 1957 * @result 0 on success, errno otherwise 1958 */ 1959 extern int ifnet_get_interface_state(ifnet_t interface, 1960 struct if_interface_state *if_interface_state); 1961 1962 /* 1963 * @struct ifnet_llreach_info 1964 * @discussion This structure is used to describe the link-layer 1965 * reachability information of an on-link node. 1966 * @field iflri_refcnt The number of network-layer objects referring 1967 * to this link-layer reachability record. 1968 * @field iflri_probes The total number of outstanding probes. 1969 * @field iflri_snd_expire The send expiration time. This is calculated 1970 * based on the last time the system transmitted a packet to the 1971 * node. A zero value indicates that a packet has not been sent 1972 * to the node. A non-zero value indicates the time before the 1973 * record is determined to be invalid. When the record is no 1974 * longer valid, the system will send probe(s) to resolve the 1975 * node again. This value is relative to the current time 1976 * specified in iflri_curtime. 1977 * @field iflri_rcv_expire The receive expiriation time. This is 1978 * calculated based on the last time the system received a packet 1979 * from the node. A zero value indicates that a packet has not 1980 * been received from the node. A non-zero value indicates the 1981 * time before the record is determined to be invalid. When the 1982 * record is no longer valid, the system will send probe(s) to 1983 * resolve the node again. This value is relative to the current 1984 * time specified in iflri_curtime. 1985 * @field iflri_curtime The current time when this record was retrieved. 1986 * @field iflri_netproto The protocol number of the network-layer object. 1987 * @field iflri_addr The link-layer address of the node. 1988 * @field iflri_rssi The received signal strength indication (RSSI) of the 1989 * node in dBm. The special value IFNET_RSSI_UNKNOWN is used when 1990 * the RSSI is either unknown or inapplicable for the interface. 1991 * @field iflri_lqm The link quality metric (LQM) to the node. The 1992 * special value IFNET_LQM_UNKNOWN is used when the LQM is not 1993 * currently known. The special value IFNET_LQM_OFF is used when 1994 * the link quality metric is inapplicable to nodes at this 1995 * attached to the network at this interface. 1996 * @field iflri_npm The node proximity metric (NPM) to the node. The 1997 * special value IFNET_NPM_UNKNOWN is used when the NPM is not 1998 * currently known. 1999 */ 2000 #define IFNET_LLREACHINFO_ADDRLEN 64 /* max ll addr len */ 2001 2002 struct ifnet_llreach_info { 2003 u_int32_t iflri_refcnt; 2004 u_int32_t iflri_probes; 2005 u_int64_t iflri_snd_expire; 2006 u_int64_t iflri_rcv_expire; 2007 u_int64_t iflri_curtime; 2008 u_int32_t iflri_netproto; 2009 u_int8_t iflri_addr[IFNET_LLREACHINFO_ADDRLEN]; 2010 int32_t iflri_rssi; 2011 int32_t iflri_lqm; 2012 int32_t iflri_npm; 2013 }; 2014 2015 /* 2016 * @function ifnet_inet_defrouter_llreachinfo 2017 * @discussion Retrieve link-layer reachability information of the 2018 * default IPv4 router specific to the interface. 2019 * @param interface The interface associated with the default IPv4 router. 2020 * @param pinfo Pointer to the ifnet_llreach_info structure where the 2021 * information will be returned to, upon success. 2022 * @result 0 upon success, otherwise errno error. 2023 */ 2024 extern errno_t ifnet_inet_defrouter_llreachinfo(ifnet_t interface, 2025 struct ifnet_llreach_info *pinfo); 2026 2027 /* 2028 * @function ifnet_inet6_defrouter_llreachinfo 2029 * @discussion Retrieve link-layer reachability information of the 2030 * default IPv6 router specific to the interface. 2031 * @param interface The interface associated with the default IPv6 router. 2032 * @param pinfo Pointer to the ifnet_llreach_info structure where the 2033 * information will be returned to, upon success. 2034 * @result 0 upon success, otherwise errno error. 2035 */ 2036 extern errno_t ifnet_inet6_defrouter_llreachinfo(ifnet_t interface, 2037 struct ifnet_llreach_info *pinfo); 2038 #endif /* KERNEL_PRIVATE */ 2039 2040 /*! 2041 * @function ifnet_set_capabilities_supported 2042 * @discussion Specify the capabilities supported by the interface. 2043 * @discussion This function lets you specify which capabilities are supported 2044 * by the interface. Typically this function is called by the driver when 2045 * the interface gets attached to the system. 2046 * The mask allows to control which capability to set or unset. 2047 * The kernel will effectively take the lock, then set the 2048 * interface's flags to (if_capabilities & ~mask) | (new_caps & mask). 2049 * 2050 * This function is intended to be called by the driver. A kext 2051 * must not call this function on an interface the kext does not 2052 * own. 2053 * @param interface Interface to set the capabilities on. 2054 * @param new_caps The value of the capabilities that should be set or unset. These 2055 * flags are defined in net/if.h 2056 * @param mask Which capabilities that should be affected. These 2057 * flags are defined in net/if.h 2058 * @result 0 on success otherwise the errno error. 2059 */ 2060 extern errno_t ifnet_set_capabilities_supported(ifnet_t interface, u_int32_t new_caps, 2061 u_int32_t mask) 2062 __NKE_API_DEPRECATED; 2063 2064 /*! 2065 * @function ifnet_capabilities_supported 2066 * @discussion Retrieve the interface capabilities supported by the interface. 2067 * @param interface Interface to retrieve the capabilities from. 2068 * @result Flags. Capabilities flags are defined in net/if.h 2069 */ 2070 extern u_int32_t ifnet_capabilities_supported(ifnet_t interface) 2071 __NKE_API_DEPRECATED; 2072 2073 /*! 2074 * @function ifnet_set_capabilities_enabled 2075 * @discussion Enable and/or disable the interface capabilities to match new_caps. 2076 * @discussion Sets the interface capabilities to new_caps. This function 2077 * lets you specify which capabilities you want to change using the mask. 2078 * The kernel will effectively take the lock, then set the 2079 * interface's flags to (if_capenable & ~mask) | (new_caps & mask). 2080 * 2081 * This function is intended to be called by the driver. A kext 2082 * must not call this function on an interface the kext does not 2083 * own. 2084 * 2085 * Typically this function is called by the driver when the interface is 2086 * created to specify which of the supported capabilities are enabled by 2087 * default. This function is also meant to be called when the driver handles 2088 * the interface ioctl SIOCSIFCAP. 2089 * 2090 * The driver should call ifnet_set_offlad() to indicate the corresponding 2091 * hardware offload bits that will be used by the networking stack. 2092 * 2093 * It is an error to enable a capability that is not marked as 2094 * supported by the interface. 2095 * @param interface Interface to set the capabilities on. 2096 * @param new_caps The value of the capabilities that should be set or unset. These 2097 * flags are defined in net/if.h 2098 * @param mask Which capabilities that should be affected. These 2099 * flags are defined in net/if.h 2100 * @result 0 on success otherwise the errno error. 2101 */ 2102 extern errno_t ifnet_set_capabilities_enabled(ifnet_t interface, u_int32_t new_caps, 2103 u_int32_t mask) 2104 __NKE_API_DEPRECATED; 2105 2106 /*! 2107 * @function ifnet_capabilities_enabled 2108 * @discussion Retrieve the interface capabilities enabled on the interface. 2109 * @param interface Interface to retrieve the capabilities from. 2110 * @result Flags. Capabilities flags are defined in net/if.h 2111 */ 2112 extern u_int32_t ifnet_capabilities_enabled(ifnet_t interface) 2113 __NKE_API_DEPRECATED; 2114 2115 /*! 2116 * @function ifnet_set_offload 2117 * @discussion Sets a bitfield to indicate special hardware offload 2118 * support provided by the interface such as hardware checksums and 2119 * VLAN. This replaces the if_hwassist flags field. Any flags 2120 * unrecognized by the stack will not be set. 2121 * 2122 * Note the system will automatically set the interface capabilities 2123 * that correspond to the offload flags modified -- i.e. the driver 2124 * does not have to call ifnet_set_capabilities_enabled() and 2125 * ifnet_set_capabilities_supported(). 2126 * @param interface The interface. 2127 * @param offload The new set of flags indicating which offload options 2128 * the device supports. 2129 * @result 0 on success otherwise the errno error. 2130 */ 2131 extern errno_t ifnet_set_offload(ifnet_t interface, ifnet_offload_t offload) 2132 __NKE_API_DEPRECATED; 2133 2134 /*! 2135 * @function ifnet_offload 2136 * @discussion Returns flags indicating which operations can be 2137 * offloaded to the interface. 2138 * @param interface Interface to retrieve the offload from. 2139 * @result Abilities flags, see ifnet_offload_t. 2140 */ 2141 extern ifnet_offload_t ifnet_offload(ifnet_t interface) 2142 __NKE_API_DEPRECATED; 2143 2144 /*! 2145 * @function ifnet_set_tso_mtu 2146 * @discussion Sets maximum TCP Segmentation Offload segment size for 2147 * the interface 2148 * @param interface The interface. 2149 * @param family The family for which the offload MTU is provided for 2150 * (AF_INET or AF_INET6) 2151 * @param mtuLen Maximum segment size supported by the interface 2152 * @result 0 on success otherwise the errno error. 2153 */ 2154 extern errno_t ifnet_set_tso_mtu(ifnet_t interface, sa_family_t family, 2155 u_int32_t mtuLen) 2156 __NKE_API_DEPRECATED; 2157 2158 /*! 2159 * @function ifnet_get_tso_mtu 2160 * @discussion Returns maximum TCP Segmentation Offload segment size for 2161 * the interface 2162 * @param interface The interface. 2163 * @param family The family for which the offload MTU is provided for 2164 * (AF_INET or AF_INET6) 2165 * @param mtuLen Value of the maximum MTU supported for the interface 2166 * and family provided. 2167 * @result 0 on success otherwise the errno error. 2168 */ 2169 extern errno_t ifnet_get_tso_mtu(ifnet_t interface, sa_family_t family, 2170 u_int32_t *mtuLen) 2171 __NKE_API_DEPRECATED; 2172 2173 /*! 2174 * @enum Interface wake properties 2175 * @abstract Constants defining Interface wake properties. 2176 * @constant IFNET_WAKE_ON_MAGIC_PACKET Wake on Magic Packet. 2177 */ 2178 enum { 2179 IFNET_WAKE_ON_MAGIC_PACKET = 0x01 2180 }; 2181 2182 /*! 2183 * @function ifnet_set_wake_flags 2184 * @discussion Sets the wake properties of the underlying hardware. These are 2185 * typically set by the driver. 2186 * @param interface The interface. 2187 * @param properties Properties to set or unset. 2188 * @param mask Mask of the properties to set of unset. 2189 * @result 0 on success otherwise the errno error. 2190 */ 2191 extern errno_t ifnet_set_wake_flags(ifnet_t interface, u_int32_t properties, u_int32_t mask) 2192 __NKE_API_DEPRECATED; 2193 2194 /*! 2195 * @function ifnet_get_wake_flags 2196 * @discussion Returns the wake properties set on the interface. 2197 * @param interface The interface. 2198 * @result The wake properties 2199 */ 2200 extern u_int32_t ifnet_get_wake_flags(ifnet_t interface) 2201 __NKE_API_DEPRECATED; 2202 2203 /*! 2204 * @function ifnet_set_link_mib_data 2205 * @discussion Sets the mib link data. The ifnet_t will store the 2206 * pointer you supply and copy mibLen bytes from the pointer 2207 * whenever the sysctl for getting interface specific MIB data is 2208 * used. Since the ifnet_t stores a pointer to your data instead of 2209 * a copy, you may update the data at the address at any time. 2210 * 2211 * This function is intended to be called by the driver. A kext 2212 * must not call this function on an interface the kext does not 2213 * own. 2214 * @param interface Interface to set the unit number of. 2215 * @param mibData A pointer to the data. 2216 * @param mibLen Length of data pointed to. 2217 * @result 0 on success otherwise the errno error. 2218 */ 2219 extern errno_t ifnet_set_link_mib_data(ifnet_t interface, void *mibData, 2220 u_int32_t mibLen) 2221 __NKE_API_DEPRECATED; 2222 2223 /*! 2224 * @function ifnet_get_link_mib_data 2225 * @discussion Copies the link MIB data in to mibData, up to mibLen 2226 * bytes. Returns error if the buffer is too small to hold all of 2227 * the MIB data. 2228 * @param interface The interface. 2229 * @param mibData A pointer to space for the mibData to be copied in 2230 * to. 2231 * @param mibLen When calling, this should be the size of the buffer 2232 * passed in mibData. Upon return, this will be the size of data 2233 * copied in to mibData. 2234 * @result Returns an error if the buffer size is too small or there is 2235 * no data. 2236 */ 2237 extern errno_t ifnet_get_link_mib_data(ifnet_t interface, void *mibData, 2238 u_int32_t *mibLen) 2239 __NKE_API_DEPRECATED; 2240 2241 /*! 2242 * @function ifnet_get_link_mib_data_length 2243 * @discussion Retrieve the size of the mib data. 2244 * @param interface The interface. 2245 * @result Returns the number of bytes of mib data associated with the 2246 * interface. 2247 */ 2248 extern u_int32_t ifnet_get_link_mib_data_length(ifnet_t interface) 2249 __NKE_API_DEPRECATED; 2250 2251 /*! 2252 * @function ifnet_attach_protocol 2253 * @discussion Attaches a protocol to an interface. 2254 * @param interface The interface. 2255 * @param protocol_family The protocol family being attached 2256 * (PF_INET/PF_INET6/etc...). 2257 * @param proto_details Details of the protocol being attached. 2258 * @result 0 on success otherwise the errno error. 2259 */ 2260 extern errno_t ifnet_attach_protocol(ifnet_t interface, 2261 protocol_family_t protocol_family, 2262 const struct ifnet_attach_proto_param *proto_details) 2263 __NKE_API_DEPRECATED; 2264 2265 /*! 2266 * @function ifnet_attach_protocol_v2 2267 * @discussion Attaches a protocol to an interface using the newer 2268 * version 2 style interface. So far the only difference is support 2269 * for packet chains which improve performance. 2270 * @param interface The interface. 2271 * @param protocol_family The protocol family being attached 2272 * (PF_INET/PF_INET6/etc...). 2273 * @param proto_details Details of the protocol being attached. 2274 * @result 0 on success otherwise the errno error. 2275 */ 2276 extern errno_t ifnet_attach_protocol_v2(ifnet_t interface, 2277 protocol_family_t protocol_family, 2278 const struct ifnet_attach_proto_param_v2 *proto_details) 2279 __NKE_API_DEPRECATED; 2280 2281 /*! 2282 * @function ifnet_detach_protocol 2283 * @discussion Detaches a protocol from an interface. 2284 * @param interface The interface. 2285 * @param protocol_family The protocol family of the protocol to 2286 * detach. 2287 * @result 0 on success otherwise the errno error. 2288 */ 2289 extern errno_t ifnet_detach_protocol(ifnet_t interface, 2290 protocol_family_t protocol_family) 2291 __NKE_API_DEPRECATED; 2292 2293 /*! 2294 * @function ifnet_output 2295 * @discussion Handles an outbound packet on the interface by calling 2296 * any filters, a protocol preoutput function, the interface framer 2297 * function, and finally the interface's output function. The 2298 * protocol_family will be used to apply protocol filters and 2299 * determine which preoutput function to call. The route and dest 2300 * parameters will be passed to the preoutput function defined for 2301 * the attachment of the specified protocol to the specified 2302 * interface. ifnet_output will always free the mbuf chain. 2303 * @param interface The interface. 2304 * @param protocol_family The family of the protocol generating this 2305 * packet (i.e. AF_INET). 2306 * @param packet The packet to be transmitted. 2307 * @param route A pointer to a routing structure for this packet. The 2308 * preoutput function determines whether this value may be NULL or 2309 * not. 2310 * @param dest The destination address of protocol_family type. This 2311 * will be passed to the preoutput function. If the preoutput 2312 * function does not require this value, you may pass NULL. 2313 * @result 0 on success otherwise the errno error. 2314 */ 2315 extern errno_t ifnet_output(ifnet_t interface, 2316 protocol_family_t protocol_family, mbuf_t packet, void *route, 2317 const struct sockaddr *dest) 2318 __NKE_API_DEPRECATED; 2319 2320 /*! 2321 * @function ifnet_output_raw 2322 * @discussion Handles and outbond raw packet on the interface by 2323 * calling any filters followed by the interface's output function. 2324 * protocol_family may be zero. If the packet is from a specific 2325 * protocol the protocol_family will be used to apply protocol 2326 * filters. All interface filters will be applied to the outgoing 2327 * packet. Processing, such as calling the protocol preoutput and 2328 * interface framer functions will be bypassed. The packet will 2329 * pass through the filters and be sent on the interface as is. 2330 * ifnet_output_raw will always free the packet chain. 2331 * @param interface The interface. 2332 * @param protocol_family The family of the protocol generating this 2333 * packet (i.e. AF_INET). 2334 * @param packet The fully formed packet to be transmitted. 2335 * @result 0 on success otherwise the errno error. 2336 */ 2337 extern errno_t ifnet_output_raw(ifnet_t interface, 2338 protocol_family_t protocol_family, mbuf_t packet) 2339 __NKE_API_DEPRECATED; 2340 2341 /*! 2342 * @function ifnet_input 2343 * @discussion Inputs packets from the interface. The interface's demux 2344 * will be called to determine the protocol. Once the protocol is 2345 * determined, the interface filters and protocol filters will be 2346 * called. From there, the packet will be passed to the registered 2347 * protocol. If there is an error, the mbuf chain will be freed. 2348 * @param interface The interface. 2349 * @param first_packet The first packet in a chain of packets. 2350 * @param stats Counts to be integrated in to the stats. The interface 2351 * statistics will be incremented by the amounts specified in 2352 * stats. This parameter may be NULL. 2353 * @result 0 on success otherwise the errno error. 2354 */ 2355 extern errno_t ifnet_input(ifnet_t interface, mbuf_t first_packet, 2356 const struct ifnet_stat_increment_param *stats) 2357 __NKE_API_DEPRECATED; 2358 2359 #ifdef KERNEL_PRIVATE 2360 /* 2361 * @function ifnet_input_extended 2362 * @discussion Inputs packets from the interface. The interface's demux 2363 * will be called to determine the protocol. Once the protocol is 2364 * determined, the interface filters and protocol filters will be 2365 * called. From there, the packet will be passed to the registered 2366 * protocol. If there is an error, the mbuf chain will be freed. 2367 * @param interface The interface. 2368 * @param first_packet The first packet in a chain of packets. 2369 * @param last_packet The last packet in a chain of packets. This may be 2370 * set to NULL if the driver does not have the information. 2371 * @param stats Counts to be integrated in to the stats. The interface 2372 * statistics will be incremented by the amounts specified in 2373 * stats. Unlike ifnet_input(), this parameter is required by 2374 * this extended variant. 2375 * @result 0 on success otherwise the errno error. 2376 */ 2377 extern errno_t ifnet_input_extended(ifnet_t interface, mbuf_t first_packet, 2378 mbuf_t last_packet, const struct ifnet_stat_increment_param *stats); 2379 #endif /* KERNEL_PRIVATE */ 2380 2381 /*! 2382 * @function ifnet_ioctl 2383 * @discussion Calls the interface's ioctl function with the parameters 2384 * passed. 2385 * 2386 * All undefined ioctls are reserved for future use by Apple. If 2387 * you need to communicate with your kext using an ioctl, please 2388 * use SIOCSIFKPI and SIOCGIFKPI. 2389 * @param interface The interface. 2390 * @param protocol The protocol family of the protocol to send the 2391 * ioctl to (may be zero). Some ioctls apply to a protocol while 2392 * other ioctls apply to just an interface. 2393 * @param ioctl_code The ioctl to perform. 2394 * @param ioctl_arg Any parameters to the ioctl. 2395 * @result 0 on success otherwise the errno error. 2396 */ 2397 extern errno_t ifnet_ioctl(ifnet_t interface, protocol_family_t protocol, 2398 unsigned long ioctl_code, void *ioctl_arg) 2399 __NKE_API_DEPRECATED; 2400 2401 /*! 2402 * @function ifnet_event 2403 * @discussion Calls the interface's event function. 2404 * @param interface The interface. 2405 * @param event_ptr Pointer to an kern_event structure describing the 2406 * event. 2407 * @result 0 on success otherwise the errno error. 2408 */ 2409 extern errno_t ifnet_event(ifnet_t interface, struct kern_event_msg *event_ptr) 2410 __NKE_API_DEPRECATED; 2411 2412 /*! 2413 * @function ifnet_set_mtu 2414 * @discussion Sets the value of the MTU in the interface structure. 2415 * Calling this function will not notify the driver that the MTU 2416 * should be changed. Use the appropriate ioctl. 2417 * 2418 * This function is intended to be called by the driver. A kext 2419 * must not call this function on an interface the kext does not 2420 * own. 2421 * @param interface The interface. 2422 * @param mtu The new MTU. 2423 * @result 0 on success otherwise the errno error. 2424 */ 2425 extern errno_t ifnet_set_mtu(ifnet_t interface, u_int32_t mtu) 2426 __NKE_API_DEPRECATED; 2427 2428 /*! 2429 * @function ifnet_mtu 2430 * @param interface The interface. 2431 * @result The MTU. 2432 */ 2433 extern u_int32_t ifnet_mtu(ifnet_t interface) 2434 __NKE_API_DEPRECATED; 2435 2436 /*! 2437 * @function ifnet_type 2438 * @param interface The interface. 2439 * @result The type. See net/if_types.h. 2440 */ 2441 extern u_int8_t ifnet_type(ifnet_t interface) 2442 __NKE_API_DEPRECATED; 2443 2444 /*! 2445 * @function ifnet_set_addrlen 2446 * @discussion 2447 * This function is intended to be called by the driver. A kext 2448 * must not call this function on an interface the kext does not 2449 * own. 2450 * @param interface The interface. 2451 * @param addrlen The new address length. 2452 * @result 0 on success otherwise the errno error. 2453 */ 2454 extern errno_t ifnet_set_addrlen(ifnet_t interface, u_int8_t addrlen) 2455 __NKE_API_DEPRECATED; 2456 2457 /*! 2458 * @function ifnet_addrlen 2459 * @param interface The interface. 2460 * @result The address length. 2461 */ 2462 extern u_int8_t ifnet_addrlen(ifnet_t interface) 2463 __NKE_API_DEPRECATED; 2464 2465 /*! 2466 * @function ifnet_set_hdrlen 2467 * @discussion 2468 * This function is intended to be called by the driver. A kext 2469 * must not call this function on an interface the kext does not 2470 * own. 2471 * @param interface The interface. 2472 * @param hdrlen The new header length. 2473 * @result 0 on success otherwise the errno error. 2474 */ 2475 extern errno_t ifnet_set_hdrlen(ifnet_t interface, u_int8_t hdrlen) 2476 __NKE_API_DEPRECATED; 2477 2478 /*! 2479 * @function ifnet_hdrlen 2480 * @param interface The interface. 2481 * @result The header length. 2482 */ 2483 extern u_int8_t ifnet_hdrlen(ifnet_t interface) 2484 __NKE_API_DEPRECATED; 2485 2486 /*! 2487 * @function ifnet_set_metric 2488 * @discussion 2489 * This function is intended to be called by the driver. A kext 2490 * must not call this function on an interface the kext does not 2491 * own. 2492 * @param interface The interface. 2493 * @param metric The new metric. 2494 * @result 0 on success otherwise the errno error. 2495 */ 2496 extern errno_t ifnet_set_metric(ifnet_t interface, u_int32_t metric) 2497 __NKE_API_DEPRECATED; 2498 2499 /*! 2500 * @function ifnet_metric 2501 * @param interface The interface. 2502 * @result The metric. 2503 */ 2504 extern u_int32_t ifnet_metric(ifnet_t interface) 2505 __NKE_API_DEPRECATED; 2506 2507 /*! 2508 * @function ifnet_set_baudrate 2509 * @discussion 2510 * This function is intended to be called by the driver. A kext 2511 * must not call this function on an interface the kext does not 2512 * own. 2513 * @param interface The interface. 2514 * @param baudrate The new baudrate. 2515 * @result 0 on success otherwise the errno error. 2516 */ 2517 extern errno_t ifnet_set_baudrate(ifnet_t interface, u_int64_t baudrate) 2518 __NKE_API_DEPRECATED; 2519 2520 /*! 2521 * @function ifnet_baudrate 2522 * @param interface The interface. 2523 * @result The baudrate. 2524 */ 2525 extern u_int64_t ifnet_baudrate(ifnet_t interface) 2526 __NKE_API_DEPRECATED; 2527 2528 #ifdef KERNEL_PRIVATE 2529 typedef struct if_bandwidths if_bandwidths_t; 2530 2531 /* 2532 * @function ifnet_set_bandwidths 2533 * @discussion This function allows a driver to indicate the output 2534 * and/or input bandwidth information to the system. Each set 2535 * is comprised of the effective and maximum theoretical values. 2536 * Each value must be greater than zero. 2537 * @param interface The interface. 2538 * @param output_bw The output bandwidth values (in bits per second). 2539 * May be set to NULL if the caller does not want to alter the 2540 * existing output bandwidth values. 2541 * @param input_bw The input bandwidth values (in bits per second). 2542 * May be set to NULL if the caller does not want to alter the 2543 * existing input bandwidth values. 2544 * @result 0 on success otherwise the errno error. 2545 */ 2546 extern errno_t ifnet_set_bandwidths(ifnet_t interface, 2547 if_bandwidths_t *output_bw, if_bandwidths_t *input_bw); 2548 2549 /* 2550 * @function ifnet_bandwidths 2551 * @param interface The interface. 2552 * @param output_bw The output bandwidth values (in bits per second). 2553 * May be set to NULL if the caller does not want to retrieve the 2554 * output bandwidth value. 2555 * @param input_bw The input bandwidth values (in bits per second). 2556 * May be set to NULL if the caller does not want to retrieve the 2557 * input bandwidth value. 2558 * @result 0 on success otherwise the errno error. 2559 */ 2560 extern errno_t ifnet_bandwidths(ifnet_t interface, if_bandwidths_t *output_bw, 2561 if_bandwidths_t *input_bw); 2562 2563 typedef struct if_latencies if_latencies_t; 2564 2565 /* 2566 * @function ifnet_set_latencies 2567 * @discussion This function allows a driver to indicate the output 2568 * and/or input latency information to the system. Each set 2569 * is comprised of the effective and maximum theoretical values. 2570 * Each value must be greater than zero. 2571 * @param interface The interface. 2572 * @param output_lt The output latency values (in nanosecond). 2573 * May be set to NULL if the caller does not want to alter the 2574 * existing output latency values. 2575 * @param input_lt The input latency values (in nanosecond). 2576 * May be set to NULL if the caller does not want to alter the 2577 * existing input latency values. 2578 * @result 0 on success otherwise the errno error. 2579 */ 2580 extern errno_t ifnet_set_latencies(ifnet_t interface, 2581 if_latencies_t *output_lt, if_latencies_t *input_lt); 2582 2583 /* 2584 * @function ifnet_latencies 2585 * @param interface The interface. 2586 * @param output_lt The output latency values (in nanosecond). 2587 * May be set to NULL if the caller does not want to retrieve the 2588 * output latency value. 2589 * @param input_lt The input latency values (in nanosecond). 2590 * May be set to NULL if the caller does not want to retrieve the 2591 * input latency value. 2592 * @result 0 on success otherwise the errno error. 2593 */ 2594 extern errno_t ifnet_latencies(ifnet_t interface, if_latencies_t *output_lt, 2595 if_latencies_t *input_lt); 2596 #endif /* KERNEL_PRIVATE */ 2597 2598 /*! 2599 * @function ifnet_stat_increment 2600 * @discussion 2601 * This function is intended to be called by the driver. A kext 2602 * must not call this function on an interface the kext does not 2603 * own. 2604 * @param interface The interface. 2605 * @param counts A pointer to a structure containing the amount to 2606 * increment each counter by. Any counts not appearing in the 2607 * ifnet_counter_increment structure are handled in the stack. 2608 * @result 0 on success otherwise the errno error. 2609 */ 2610 extern errno_t ifnet_stat_increment(ifnet_t interface, 2611 const struct ifnet_stat_increment_param *counts) 2612 __NKE_API_DEPRECATED; 2613 2614 /*! 2615 * @function ifnet_stat_increment_in 2616 * @discussion 2617 * This function is intended to be called by the driver. This 2618 * function allows a driver to update the inbound interface counts. 2619 * The most efficient time to update these counts is when calling 2620 * ifnet_input. 2621 * 2622 * A lock protects the counts, this makes the increment functions 2623 * expensive. The increment function will update the lastchanged 2624 * value. 2625 * @param interface The interface. 2626 * @param packets_in The number of additional packets received. 2627 * @param bytes_in The number of additional bytes received. 2628 * @param errors_in The number of additional receive errors. 2629 * @result 0 on success otherwise the errno error. 2630 */ 2631 extern errno_t ifnet_stat_increment_in(ifnet_t interface, 2632 u_int32_t packets_in, u_int32_t bytes_in, u_int32_t errors_in) 2633 __NKE_API_DEPRECATED; 2634 2635 /*! 2636 * @function ifnet_stat_increment_out 2637 * @discussion 2638 * This function is intended to be called by the driver. This 2639 * function allows a driver to update the outbound interface 2640 * counts. 2641 * 2642 * A lock protects the counts, this makes the increment functions 2643 * expensive. The increment function will update the lastchanged 2644 * value. 2645 * @param interface The interface. 2646 * @param packets_out The number of additional packets sent. 2647 * @param bytes_out The number of additional bytes sent. 2648 * @param errors_out The number of additional send errors. 2649 * @result 0 on success otherwise the errno error. 2650 */ 2651 extern errno_t ifnet_stat_increment_out(ifnet_t interface, 2652 u_int32_t packets_out, u_int32_t bytes_out, u_int32_t errors_out) 2653 __NKE_API_DEPRECATED; 2654 2655 /*! 2656 * @function ifnet_set_stat 2657 * @discussion 2658 * This function is intended to be called by the driver. A kext 2659 * must not call this function on an interface the kext does not 2660 * own. 2661 * 2662 * The one exception would be the case where a kext wants to zero 2663 * all of the counters. 2664 * @param interface The interface. 2665 * @param stats The new stats values. 2666 * @result 0 on success otherwise the errno error. 2667 */ 2668 extern errno_t ifnet_set_stat(ifnet_t interface, 2669 const struct ifnet_stats_param *stats) 2670 __NKE_API_DEPRECATED; 2671 2672 /*! 2673 * @function ifnet_stat 2674 * @param interface The interface. 2675 * @param out_stats Storage for the values. 2676 * @result 0 on success otherwise the errno error. 2677 */ 2678 extern errno_t ifnet_stat(ifnet_t interface, 2679 struct ifnet_stats_param *out_stats) 2680 __NKE_API_DEPRECATED; 2681 2682 /*! 2683 * @function ifnet_set_promiscuous 2684 * @discussion Enable or disable promiscuous mode on the interface. The 2685 * interface keeps an internal count of the number of times 2686 * promiscuous mode has been enabled. Promiscuous mode is only 2687 * disabled when this count reaches zero. Be sure to disable 2688 * promiscuous mode only once for every time you enable it. 2689 * @param interface The interface to toggle promiscuous mode on. 2690 * @param on If set, the number of promicuous on requests will be 2691 * incremented. If this is the first request, promiscuous mode 2692 * will be enabled. If this is not set, the number of promiscous 2693 * clients will be decremented. If this causes the number to reach 2694 * zero, promiscuous mode will be disabled. 2695 * @result 0 on success otherwise the errno error. 2696 */ 2697 extern errno_t ifnet_set_promiscuous(ifnet_t interface, int on) 2698 __NKE_API_DEPRECATED; 2699 2700 /*! 2701 * @function ifnet_touch_lastchange 2702 * @discussion Updates the lastchange value to now. 2703 * @param interface The interface. 2704 * @result 0 on success otherwise the errno error. 2705 */ 2706 extern errno_t ifnet_touch_lastchange(ifnet_t interface) 2707 __NKE_API_DEPRECATED; 2708 2709 /*! 2710 * @function ifnet_lastchange 2711 * @param interface The interface. 2712 * @param last_change A timeval struct to copy the last time changed in 2713 * to. 2714 */ 2715 extern errno_t ifnet_lastchange(ifnet_t interface, struct timeval *last_change) 2716 __NKE_API_DEPRECATED; 2717 2718 /*! 2719 * @function ifnet_get_address_list 2720 * @discussion Get a list of addresses on the interface. Passing NULL 2721 * for the interface will return a list of all addresses. The 2722 * addresses will have their reference count bumped so they will 2723 * not go away. Calling ifnet_free_address_list will decrement the 2724 * refcount and free the array. If you wish to hold on to a 2725 * reference to an ifaddr_t, be sure to bump the reference count 2726 * before calling ifnet_free_address_list. 2727 * @param interface The interface. 2728 * @param addresses A pointer to a NULL terminated array of ifaddr_ts. 2729 * @result 0 on success otherwise the errno error. 2730 */ 2731 extern errno_t ifnet_get_address_list(ifnet_t interface, ifaddr_t **addresses) 2732 __NKE_API_DEPRECATED; 2733 2734 /*! 2735 * @function ifnet_get_address_list_family 2736 * @discussion Get a list of addresses on the interface. Passing NULL 2737 * for the interface will return a list of all addresses. The 2738 * addresses will have their reference count bumped so they will 2739 * not go away. Calling ifnet_free_address_list will decrement the 2740 * refcount and free the array. If you wish to hold on to a 2741 * reference to an ifaddr_t, be sure to bump the reference count 2742 * before calling ifnet_free_address_list. Unlike 2743 * ifnet_get_address_list, this function lets the caller specify 2744 * the address family to get a list of only a specific address type. 2745 * @param interface The interface. 2746 * @param addresses A pointer to a NULL terminated array of ifaddr_ts. 2747 * @result 0 on success otherwise the errno error. 2748 */ 2749 extern errno_t ifnet_get_address_list_family(ifnet_t interface, 2750 ifaddr_t **addresses, sa_family_t family) 2751 __NKE_API_DEPRECATED; 2752 2753 #ifdef KERNEL_PRIVATE 2754 /*! 2755 * @function ifnet_get_inuse_address_list 2756 * @discussion Get a list of addresses on the interface that are in 2757 * use by atleast one TCP or UDP socket. The rest of the API is similar 2758 * to ifnet_get_address_list. Calling ifnet_free_address_list will 2759 * free the array of addresses. Note this only gives a point in time 2760 * snapshot of the addresses in use. 2761 * @param interface The interface 2762 * @param addresses A pointer to a NULL terminated array of ifaddr_ts 2763 * @result 0 on success otherwise the errno error. 2764 */ 2765 extern errno_t ifnet_get_inuse_address_list(ifnet_t interface, 2766 ifaddr_t **addresses); 2767 2768 __private_extern__ errno_t ifnet_get_address_list_family_internal(ifnet_t, 2769 ifaddr_t **, sa_family_t, int, int, int); 2770 #endif /* KERNEL_PRIVATE */ 2771 2772 /*! 2773 * @function ifnet_free_address_list 2774 * @discussion Free a list of addresses returned from 2775 * ifnet_get_address_list. Decrements the refcounts and frees the 2776 * memory used for the array of references. 2777 * @param addresses An array of ifaddr_ts. 2778 */ 2779 extern void ifnet_free_address_list(ifaddr_t *addresses) 2780 __NKE_API_DEPRECATED; 2781 2782 /*! 2783 * @function ifnet_set_lladdr 2784 * @discussion Sets the link-layer address for this interface. 2785 * @param interface The interface the link layer address is being 2786 * changed on. 2787 * @param lladdr A pointer to the raw link layer address (pointer to 2788 * the 6 byte ethernet address for ethernet). 2789 * @param lladdr_len The length, in bytes, of the link layer address. 2790 */ 2791 extern errno_t ifnet_set_lladdr(ifnet_t interface, const void *lladdr, 2792 size_t lladdr_len) 2793 __NKE_API_DEPRECATED; 2794 2795 /*! 2796 * @function ifnet_lladdr_copy_bytes 2797 * @discussion Copies the bytes of the link-layer address into the 2798 * specified buffer. 2799 * @param interface The interface to copy the link-layer address from. 2800 * @param lladdr The buffer to copy the link-layer address in to. 2801 * @param length The length of the buffer. This value must match the 2802 * length of the link-layer address. 2803 */ 2804 extern errno_t ifnet_lladdr_copy_bytes(ifnet_t interface, void *lladdr, 2805 size_t length) 2806 __NKE_API_DEPRECATED; 2807 2808 #ifdef KERNEL_PRIVATE 2809 /*! 2810 * @function ifnet_guarded_lladdr_copy_bytes 2811 * @discussion Copies the bytes of the link-layer address into the 2812 * specified buffer unless the current process is a sandboxed 2813 * application without the net.link.addr system info privilege. 2814 * @param interface The interface to copy the link-layer address from. 2815 * @param lladdr The buffer to copy the link-layer address in to. 2816 * @param length The length of the buffer. This value must match the 2817 * length of the link-layer address. 2818 */ 2819 extern errno_t ifnet_guarded_lladdr_copy_bytes(ifnet_t interface, void *lladdr, 2820 size_t length); 2821 2822 /*! 2823 * @function ifnet_lladdr 2824 * @discussion Returns a pointer to the link-layer address. 2825 * @param interface The interface the link-layer address is on. 2826 */ 2827 extern void *ifnet_lladdr(ifnet_t interface); 2828 2829 #endif /* KERNEL_PRIVATE */ 2830 2831 /*! 2832 * @function ifnet_llbroadcast_copy_bytes 2833 * @discussion Retrieves the link-layer broadcast address for this 2834 * interface. 2835 * @param interface The interface. 2836 * @param addr A buffer to copy the broadcast address in to. 2837 * @param bufferlen The length of the buffer at addr. 2838 * @param out_len On return, the length of the broadcast address. 2839 */ 2840 extern errno_t ifnet_llbroadcast_copy_bytes(ifnet_t interface, void *addr, 2841 size_t bufferlen, size_t *out_len) 2842 __NKE_API_DEPRECATED; 2843 2844 #ifdef KERNEL_PRIVATE 2845 /*! 2846 * @function ifnet_set_lladdr_and_type 2847 * @discussion Sets the link-layer address as well as the type field in 2848 * the sockaddr_dl. Support for setting the type was added for vlan 2849 * and bond interfaces. 2850 * @param interface The interface the link layer address is being 2851 * changed on. 2852 * @param lladdr A pointer to the raw link layer address (pointer to 2853 * the 6 byte ethernet address for ethernet). 2854 * @param length The length, in bytes, of the link layer address. 2855 * @param type The link-layer address type. 2856 */ 2857 extern errno_t ifnet_set_lladdr_and_type(ifnet_t interface, const void *lladdr, 2858 size_t length, u_char type) 2859 __NKE_API_DEPRECATED; 2860 #endif /* KERNEL_PRIVATE */ 2861 2862 /*! 2863 * @function ifnet_resolve_multicast 2864 * @discussion Resolves a multicast address for an attached protocol to 2865 * a link-layer address. If a link-layer address is passed in, the 2866 * interface will verify that it is a valid multicast address. 2867 * @param ifp The interface. 2868 * @param proto_addr A protocol address to be converted to a link-layer 2869 * address. 2870 * @param ll_addr Storage for the resulting link-layer address. 2871 * @param ll_len Length of the storage for the link-layer address. 2872 * @result 0 on success. EOPNOTSUPP indicates the multicast address was 2873 * not supported or could not be translated. Other errors may 2874 * indicate other failures. 2875 */ 2876 extern errno_t ifnet_resolve_multicast(ifnet_t ifp, 2877 const struct sockaddr *proto_addr, struct sockaddr *ll_addr, size_t ll_len) 2878 __NKE_API_DEPRECATED; 2879 2880 /*! 2881 * @function ifnet_add_multicast 2882 * @discussion Joins a multicast and returns an ifmultiaddr_t with the 2883 * reference count incremented for you. You are responsible for 2884 * decrementing the reference count after calling 2885 * ifnet_remove_multicast and making sure you no longer have any 2886 * references to the multicast. 2887 * @param interface The interface. 2888 * @param maddr The multicast address (AF_UNSPEC/AF_LINK) to join. Either 2889 * a physical address or logical address to be translated to a 2890 * physical address. 2891 * @param multicast The resulting ifmultiaddr_t multicast address. 2892 * @result 0 on success otherwise the errno error. 2893 */ 2894 extern errno_t ifnet_add_multicast(ifnet_t interface, 2895 const struct sockaddr *maddr, ifmultiaddr_t *multicast) 2896 __NKE_API_DEPRECATED; 2897 2898 /*! 2899 * @function ifnet_remove_multicast 2900 * @discussion Causes the interface to leave the multicast group. The 2901 * stack keeps track of how many times ifnet_add_multicast has been 2902 * called for a given multicast address. The multicast will only be 2903 * removed when the number of times ifnet_remove_multicast has been 2904 * called matches the number of times ifnet_add_multicast has been 2905 * called. 2906 * 2907 * The memory for the multicast address is not actually freed until 2908 * the separate reference count has reached zero. Some parts of the 2909 * stack may keep a pointer to the multicast even after that 2910 * multicast has been removed from the interface. 2911 * 2912 * When an interface is detached, all of the multicasts are 2913 * removed. If the interface of the multicast passed in is no 2914 * longer attached, this function will gracefully return, 2915 * performing no work. 2916 * 2917 * It is the callers responsibility to release the multicast 2918 * address after calling this function. 2919 * @param multicast The multicast to be removed. 2920 * @result 0 on success otherwise the errno error. 2921 */ 2922 extern errno_t ifnet_remove_multicast(ifmultiaddr_t multicast) 2923 __NKE_API_DEPRECATED; 2924 2925 /*! 2926 * @function ifnet_get_multicast_list 2927 * @discussion Retrieves a list of multicast address the interface is 2928 * set to receive. This function allocates and returns an array of 2929 * references to the various multicast addresses. The multicasts 2930 * have their reference counts bumped on your behalf. Calling 2931 * ifnet_free_multicast_list will decrement the reference counts 2932 * and free the array. 2933 * @param interface The interface. 2934 * @param addresses A pointer to a NULL terminated array of references 2935 * to the multicast addresses. 2936 * @result 0 on success otherwise the errno error. 2937 */ 2938 extern errno_t ifnet_get_multicast_list(ifnet_t interface, 2939 ifmultiaddr_t **addresses) 2940 __NKE_API_DEPRECATED; 2941 2942 /*! 2943 * @function ifnet_free_multicast_list 2944 * @discussion Frees a list of multicasts returned by 2945 * ifnet_get_multicast_list. Decrements the refcount on each 2946 * multicast address and frees the array. 2947 * @param multicasts An array of references to the multicast addresses. 2948 */ 2949 extern void ifnet_free_multicast_list(ifmultiaddr_t *multicasts) 2950 __NKE_API_DEPRECATED; 2951 2952 /*! 2953 * @function ifnet_find_by_name 2954 * @discussion Find an interface by the name including the unit number. 2955 * Caller must call ifnet_release on any non-null interface return 2956 * value. 2957 * @param ifname The name of the interface, including any unit number 2958 * (i.e. "en0"). 2959 * @param interface A pointer to an interface reference. This will be 2960 * filled in if a matching interface is found. 2961 * @result 0 on success otherwise the errno error. 2962 */ 2963 extern errno_t ifnet_find_by_name(const char *ifname, ifnet_t *interface) 2964 __NKE_API_DEPRECATED; 2965 2966 /*! 2967 * @function ifnet_list_get 2968 * @discussion Get a list of attached interfaces. List will be set to 2969 * point to an array allocated by ifnet_list_get. The interfaces 2970 * are refcounted and the counts will be incremented before the 2971 * function returns. The list of interfaces must be freed using 2972 * ifnet_list_free. 2973 * @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To 2974 * find interfaces of all families, use IFNET_FAMILY_ANY. 2975 * @param interfaces A pointer to an array of interface references. 2976 * @param count A pointer that will be filled in with the number of 2977 * matching interfaces in the array. 2978 * @result 0 on success otherwise the errno error. 2979 */ 2980 extern errno_t ifnet_list_get(ifnet_family_t family, ifnet_t **interfaces, 2981 u_int32_t *count) 2982 __NKE_API_DEPRECATED; 2983 2984 #ifdef KERNEL_PRIVATE 2985 /*! 2986 * @function ifnet_list_get_all 2987 * @discussion Get a list of attached interfaces. List will be set to 2988 * point to an array allocated by ifnet_list_get. The interfaces 2989 * are refcounted and the counts will be incremented before the 2990 * function returns. The list of interfaces must be freed using 2991 * ifnet_list_free. This is similar to ifnet_list_get, except 2992 * that it includes interfaces that are detaching. 2993 * @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To 2994 * find interfaces of all families, use IFNET_FAMILY_ANY. 2995 * @param interfaces A pointer to an array of interface references. 2996 * @param count A pointer that will be filled in with the number of 2997 * matching interfaces in the array. 2998 * @result 0 on success otherwise the errno error. 2999 */ 3000 extern errno_t ifnet_list_get_all(ifnet_family_t family, ifnet_t **interfaces, 3001 u_int32_t *count); 3002 3003 #endif /* KERNEL_PRIVATE */ 3004 3005 /*! 3006 * @function ifnet_list_free 3007 * @discussion Free a list of interfaces returned by ifnet_list_get. 3008 * Decrements the reference count on each interface and frees the 3009 * array of references. If you keep a reference to an interface, be 3010 * sure to increment the reference count before calling 3011 * ifnet_list_free. 3012 * @param interfaces An array of interface references from ifnet_list_get. 3013 */ 3014 extern void ifnet_list_free(ifnet_t *interfaces) 3015 __NKE_API_DEPRECATED; 3016 3017 /******************************************************************************/ 3018 /* ifaddr_t accessors */ 3019 /******************************************************************************/ 3020 3021 /*! 3022 * @function ifaddr_reference 3023 * @discussion Increment the reference count of an address tied to an 3024 * interface. 3025 * @param ifaddr The interface address. 3026 * @result 0 upon success 3027 */ 3028 extern errno_t ifaddr_reference(ifaddr_t ifaddr) 3029 __NKE_API_DEPRECATED; 3030 3031 /*! 3032 * @function ifaddr_release 3033 * @discussion Decrements the reference count of and possibly frees an 3034 * address tied to an interface. 3035 * @param ifaddr The interface address. 3036 * @result 0 upon success 3037 */ 3038 extern errno_t ifaddr_release(ifaddr_t ifaddr) 3039 __NKE_API_DEPRECATED; 3040 3041 /*! 3042 * @function ifaddr_address 3043 * @discussion Copies the address out of the ifaddr. 3044 * @param ifaddr The interface address. 3045 * @param out_addr The sockaddr storage for the address. 3046 * @param addr_size The size of the storage for the address. 3047 * @result 0 upon success 3048 */ 3049 extern errno_t ifaddr_address(ifaddr_t ifaddr, struct sockaddr *out_addr, 3050 u_int32_t addr_size) 3051 __NKE_API_DEPRECATED; 3052 3053 /*! 3054 * @function ifaddr_address 3055 * @discussion Returns the address family of the address. 3056 * @param ifaddr The interface address. 3057 * @result 0 on failure, address family on success. 3058 */ 3059 extern sa_family_t ifaddr_address_family(ifaddr_t ifaddr) 3060 __NKE_API_DEPRECATED; 3061 3062 /*! 3063 * @function ifaddr_dstaddress 3064 * @discussion Copies the destination address out of the ifaddr. 3065 * @param ifaddr The interface address. 3066 * @param out_dstaddr The sockaddr storage for the destination address. 3067 * @param dstaddr_size The size of the storage for the destination address. 3068 * @result 0 upon success 3069 */ 3070 extern errno_t ifaddr_dstaddress(ifaddr_t ifaddr, struct sockaddr *out_dstaddr, 3071 u_int32_t dstaddr_size) 3072 __NKE_API_DEPRECATED; 3073 3074 /*! 3075 * @function ifaddr_netmask 3076 * @discussion Copies the netmask out of the ifaddr. 3077 * @param ifaddr The interface address. 3078 * @param out_netmask The sockaddr storage for the netmask. 3079 * @param netmask_size The size of the storage for the netmask. 3080 * @result 0 upon success 3081 */ 3082 extern errno_t ifaddr_netmask(ifaddr_t ifaddr, struct sockaddr *out_netmask, 3083 u_int32_t netmask_size) 3084 __NKE_API_DEPRECATED; 3085 3086 /*! 3087 * @function ifaddr_ifnet 3088 * @discussion Returns the interface the address is attached to. The 3089 * reference is only valid until the ifaddr is released. If you 3090 * need to hold a reference to the ifnet for longer than you hold a 3091 * reference to the ifaddr, increment the reference using 3092 * ifnet_reference. 3093 * @param ifaddr The interface address. 3094 * @result A reference to the interface the address is attached to. 3095 */ 3096 extern ifnet_t ifaddr_ifnet(ifaddr_t ifaddr) 3097 __NKE_API_DEPRECATED; 3098 3099 /*! 3100 * @function ifaddr_withaddr 3101 * @discussion Returns an interface address with the address specified. 3102 * Increments the reference count on the ifaddr before returning to 3103 * the caller. Caller is responsible for calling ifaddr_release. 3104 * @param address The address to search for. 3105 * @result A reference to the interface address. 3106 */ 3107 extern ifaddr_t ifaddr_withaddr(const struct sockaddr *address) 3108 __NKE_API_DEPRECATED; 3109 3110 /*! 3111 * @function ifaddr_withdstaddr 3112 * @discussion Returns an interface address for the interface address 3113 * that matches the destination when the netmask is applied. 3114 * Increments the reference count on the ifaddr before returning to 3115 * the caller. Caller is responsible for calling ifaddr_release. 3116 * @param destination The destination to search for. 3117 * @result A reference to the interface address. 3118 */ 3119 extern ifaddr_t ifaddr_withdstaddr(const struct sockaddr *destination) 3120 __NKE_API_DEPRECATED; 3121 /*! 3122 * @function ifaddr_withnet 3123 * @discussion Returns an interface address for the interface with the 3124 * network described by net. Increments the reference count on the 3125 * ifaddr before returning to the caller. Caller is responsible for 3126 * calling ifaddr_release. 3127 * @param net The network to search for. 3128 * @result A reference to the interface address. 3129 */ 3130 extern ifaddr_t ifaddr_withnet(const struct sockaddr *net) 3131 __NKE_API_DEPRECATED; 3132 3133 /*! 3134 * @function ifaddr_withroute 3135 * @discussion Returns an interface address given a destination and 3136 * gateway. Increments the reference count on the ifaddr before 3137 * returning to the caller. Caller is responsible for calling 3138 * ifaddr_release. 3139 * @param flags Routing flags. See net/route.h, RTF_GATEWAY etc. 3140 * @param destination The destination to search for. 3141 * @param gateway A gateway to search for. 3142 * @result A reference to the interface address. 3143 */ 3144 extern ifaddr_t ifaddr_withroute(int flags, const struct sockaddr *destination, 3145 const struct sockaddr *gateway) 3146 __NKE_API_DEPRECATED; 3147 3148 /*! 3149 * @function ifaddr_findbestforaddr 3150 * @discussion Finds the best local address assigned to a specific 3151 * interface to use when communicating with another address. 3152 * Increments the reference count on the ifaddr before returning to 3153 * the caller. Caller is responsible for calling ifaddr_release. 3154 * @param addr The remote address. 3155 * @param interface The local interface. 3156 * @result A reference to the interface address. 3157 */ 3158 extern ifaddr_t ifaddr_findbestforaddr(const struct sockaddr *addr, 3159 ifnet_t interface) 3160 __NKE_API_DEPRECATED; 3161 3162 /******************************************************************************/ 3163 /* ifmultiaddr_t accessors */ 3164 /******************************************************************************/ 3165 3166 /*! 3167 * @function ifmaddr_reference 3168 * @discussion Increment the reference count of an interface multicast 3169 * address. 3170 * @param ifmaddr The interface multicast address. 3171 * @result 0 on success. Only error will be EINVAL if ifmaddr is not valid. 3172 */ 3173 extern errno_t ifmaddr_reference(ifmultiaddr_t ifmaddr) 3174 __NKE_API_DEPRECATED; 3175 3176 /*! 3177 * @function ifmaddr_release 3178 * @discussion Decrement the reference count of an interface multicast 3179 * address. If the reference count reaches zero, the ifmultiaddr 3180 * will be removed from the interface and the ifmultiaddr will be 3181 * freed. 3182 * @param ifmaddr The interface multicast address. 3183 * @result 0 on success. Only error will be EINVAL if ifmaddr is not valid. 3184 */ 3185 extern errno_t ifmaddr_release(ifmultiaddr_t ifmaddr) 3186 __NKE_API_DEPRECATED; 3187 3188 /*! 3189 * @function ifmaddr_address 3190 * @discussion Copies the multicast address to out_multicast. 3191 * @param out_multicast Storage for a sockaddr. 3192 * @param addr_size Size of the storage. 3193 * @result 0 on success. 3194 */ 3195 extern errno_t ifmaddr_address(ifmultiaddr_t ifmaddr, 3196 struct sockaddr *out_multicast, u_int32_t addr_size) 3197 __NKE_API_DEPRECATED; 3198 3199 /*! 3200 * @function ifmaddr_lladdress 3201 * @discussion Copies the link layer multicast address to 3202 * out_link_layer_multicast. 3203 * @param out_link_layer_multicast Storage for a sockaddr. 3204 * @param addr_size Size of the storage. 3205 * @result 0 on success. 3206 */ 3207 extern errno_t ifmaddr_lladdress(ifmultiaddr_t ifmaddr, 3208 struct sockaddr *out_link_layer_multicast, u_int32_t addr_size) 3209 __NKE_API_DEPRECATED; 3210 3211 /*! 3212 * @function ifmaddr_ifnet 3213 * @discussion Returns the interface this multicast address is attached 3214 * to. The interface reference count is not bumped by this 3215 * function. The interface is only valid as long as you don't 3216 * release the refernece to the multiast address. If you need to 3217 * maintain your pointer to the ifnet, call ifnet_reference 3218 * followed by ifnet_release when you're finished. 3219 * @param ifmaddr The interface multicast address. 3220 * @result A reference to the interface. 3221 */ 3222 extern ifnet_t ifmaddr_ifnet(ifmultiaddr_t ifmaddr) 3223 __NKE_API_DEPRECATED; 3224 3225 #ifdef KERNEL_PRIVATE 3226 /******************************************************************************/ 3227 /* interface cloner */ 3228 /******************************************************************************/ 3229 3230 /* 3231 * @typedef ifnet_clone_create_func 3232 * @discussion ifnet_clone_create_func is called to create an interface. 3233 * @param ifcloner The interface cloner. 3234 * @param unit The interface unit number to create. 3235 * @param params Additional information specific to the interface cloner. 3236 * @result Return zero on success or an errno error value on failure. 3237 */ 3238 typedef errno_t (*ifnet_clone_create_func)(if_clone_t ifcloner, u_int32_t unit, void *params); 3239 3240 /* 3241 * @typedef ifnet_clone_destroy_func 3242 * @discussion ifnet_clone_create_func is called to destroy an interface created 3243 * by an interface cloner. 3244 * @param interface The interface to destroy. 3245 * @result Return zero on success or an errno error value on failure. 3246 */ 3247 typedef errno_t (*ifnet_clone_destroy_func)(ifnet_t interface); 3248 3249 /* 3250 * @struct ifnet_clone_params 3251 * @discussion This structure is used to represent an interface cloner. 3252 * @field ifc_name The interface name handled by this interface cloner. 3253 * @field ifc_create The function to create an interface. 3254 * @field ifc_destroy The function to destroy an interface. 3255 */ 3256 struct ifnet_clone_params { 3257 const char *ifc_name; 3258 ifnet_clone_create_func ifc_create; 3259 ifnet_clone_destroy_func ifc_destroy; 3260 }; 3261 3262 /* 3263 * @function ifnet_clone_attach 3264 * @discussion Attaches a new interface cloner. 3265 * @param cloner_params The structure that defines an interface cloner. 3266 * @param interface A pointer to an opaque handle that represent the interface cloner 3267 * that is attached upon success. 3268 * @result Returns 0 on success. 3269 * May return ENOBUFS if there is insufficient memory. 3270 * May return EEXIST if an interface cloner with the same name is already attached. 3271 */ 3272 extern errno_t ifnet_clone_attach(struct ifnet_clone_params *cloner_params, if_clone_t *ifcloner); 3273 3274 /* 3275 * @function ifnet_clone_detach 3276 * @discussion Detaches a previously attached interface cloner. 3277 * @param ifcloner The opaque handle returned when the interface cloner was attached. 3278 * @result Returns 0 on success. 3279 */ 3280 extern errno_t ifnet_clone_detach(if_clone_t ifcloner); 3281 3282 /******************************************************************************/ 3283 /* misc */ 3284 /******************************************************************************/ 3285 3286 /* 3287 * @function ifnet_get_local_ports 3288 * @discussion Returns a bitfield indicating which ports of PF_INET 3289 * and PF_INET6 protocol families have sockets in the usable 3290 * state. An interface that supports waking the host on unicast 3291 * traffic may use this information to discard incoming unicast 3292 * packets that don't have a corresponding bit set instead of 3293 * waking up the host. For port 0x0001, bit 1 of the first byte 3294 * would be set. For port n, bit 1 << (n % 8) of the (n / 8)'th 3295 * byte would be set. 3296 * @param ifp The interface in question. May be NULL, which means 3297 * all interfaces. 3298 * @param bitfield A pointer to 8192 bytes. 3299 * @result Returns 0 on success. 3300 */ 3301 extern errno_t ifnet_get_local_ports(ifnet_t ifp, u_int8_t *bitfield); 3302 3303 #define IFNET_GET_LOCAL_PORTS_WILDCARDOK 0x01 3304 #define IFNET_GET_LOCAL_PORTS_NOWAKEUPOK 0x02 3305 #define IFNET_GET_LOCAL_PORTS_TCPONLY 0x04 3306 #define IFNET_GET_LOCAL_PORTS_UDPONLY 0x08 3307 #define IFNET_GET_LOCAL_PORTS_RECVANYIFONLY 0x10 3308 #define IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY 0x20 3309 #define IFNET_GET_LOCAL_PORTS_ACTIVEONLY 0x40 3310 #define IFNET_GET_LOCAL_PORTS_ANYTCPSTATEOK 0x80 3311 /* 3312 * @function ifnet_get_local_ports_extended 3313 * @discussion Returns a bitfield indicating which local ports of the 3314 * specified protocol have sockets in the usable state. An 3315 * interface that supports waking the host on unicast traffic may 3316 * use this information to discard incoming unicast packets that 3317 * don't have a corresponding bit set instead of waking up the 3318 * host. For port 0x0001, bit 1 of the first byte would be set. 3319 * For port n, bit 1 << (n % 8) of the (n / 8)'th byte would be 3320 * set. 3321 * @param ifp The interface in question. May be NULL, which means 3322 * all interfaces. 3323 * @param protocol The protocol family of the sockets. PF_UNSPEC (0) 3324 * means all protocols, otherwise PF_INET or PF_INET6. 3325 * @param flags A bitwise of the following flags: 3326 * IFNET_GET_LOCAL_PORTS_WILDCARDOK: When bit is set, 3327 * the list of local ports should include those that are 3328 * used by sockets that aren't bound to any local address. 3329 * IFNET_GET_LOCAL_PORTS_NOWAKEUPOK: When bit is 3330 * set, the list of local ports should return all sockets 3331 * including the ones that do not need a wakeup from sleep. 3332 * Sockets that do not want to wake from sleep are marked 3333 * with a socket option. 3334 * IFNET_GET_LOCAL_PORTS_TCPONLY: When bit is set, the list 3335 * of local ports should return the ports used by TCP sockets. 3336 * IFNET_GET_LOCAL_PORTS_UDPONLY: When bit is set, the list 3337 * of local ports should return the ports used by UDP sockets. 3338 * only. 3339 * IFNET_GET_LOCAL_PORTS_RECVANYIFONLY: When bit is set, the 3340 * port is in the list only if the socket has the option 3341 * SO_RECV_ANYIF set 3342 * IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY: When bit is set, the 3343 * port is in the list only if the socket has the option 3344 * SO_EXTENDED_BK_IDLE set 3345 * IFNET_GET_LOCAL_PORTS_ACTIVEONLY: When bit is set, the 3346 * port is in the list only if the socket is not in a final TCP 3347 * state or the connection is not idle in a final TCP state 3348 * IFNET_GET_LOCAL_PORTS_ANYTCPSTATEOK: When bit is set, the 3349 * port is in the list for all the TCP states except CLOSED 3350 * and TIME_WAIT 3351 * @param bitfield A pointer to 8192 bytes. 3352 * @result Returns 0 on success. 3353 */ 3354 extern errno_t ifnet_get_local_ports_extended(ifnet_t ifp, 3355 protocol_family_t protocol, u_int32_t flags, u_int8_t *bitfield); 3356 3357 /******************************************************************************/ 3358 /* for reporting issues */ 3359 /******************************************************************************/ 3360 3361 #define IFNET_MODIDLEN 20 3362 #define IFNET_MODARGLEN 12 3363 3364 /* 3365 * @function ifnet_report_issues 3366 * @discussion Provided for network interface families and drivers to 3367 * notify the system of issues detected at their layers. 3368 * @param ifp The interface experiencing issues. 3369 * @param modid The ID of the module reporting issues. It may contain 3370 * any value that is unique enough to identify the module, such 3371 * as the SHA-1 hash of the bundle ID of the module, e.g. 3372 * "com.apple.iokit.IONetworkingFamily" or 3373 * "com.apple.iokit.IO80211Family". 3374 * @param info An optional, fixed-size array of octets containing opaque 3375 * information data used specific to the module/layer reporting 3376 * the issues. May be NULL. 3377 * @result Returns 0 on success, or EINVAL if arguments are invalid. 3378 */ 3379 extern errno_t ifnet_report_issues(ifnet_t ifp, u_int8_t modid[IFNET_MODIDLEN], 3380 u_int8_t info[IFNET_MODARGLEN]); 3381 3382 /******************************************************************************/ 3383 /* for interfaces that support link level transmit completion status */ 3384 /******************************************************************************/ 3385 /* 3386 * @enum Per packet phy level transmit completion status values 3387 * @abstract Constants defining possible completion status values 3388 * A driver may support all or some of these values 3389 * @discussion 3390 * @constant IFNET_TX_COMPL_SUCCESS link transmission succeeded 3391 * @constant IFNET_TX_COMPL_FAIL link transmission failed 3392 * @constant IFNET_TX_COMPL_ABORTED link transmission aborted, may retry 3393 * @constant IFNET_TX_QUEUE_FULL link level secondary queue full 3394 */ 3395 enum { 3396 IFNET_TX_COMPL_SUCCESS = 0, /* sent on link */ 3397 IFNET_TX_COMPL_FAIL = 1, /* failed to send on link */ 3398 IFNET_TX_COMPL_ABORTED = 2, /* aborted send, peer asleep */ 3399 IFNET_TX_COMPL_QFULL = 3 /* driver level queue full */ 3400 }; 3401 3402 typedef u_int32_t tx_compl_val_t; 3403 3404 /* 3405 * @function ifnet_tx_compl_status 3406 * @discussion Used as an upcall from IONetwork Family to stack that 3407 * indicates the link level completion status of a transmitted 3408 * packet. 3409 * @param ifp The interface to which the mbuf was sent 3410 * @param m The mbuf that was transmitted 3411 * @param val indicates the status of the transmission 3412 */ 3413 extern errno_t ifnet_tx_compl_status(ifnet_t ifp, mbuf_t m, tx_compl_val_t val); 3414 3415 /* 3416 * @function ifnet_tx_compl 3417 * @discussion Used to indicates the packet has been transmitted. 3418 * @param ifp The interface to which the mbuf was sent 3419 * @param m The mbuf that was transmitted 3420 */ 3421 extern errno_t ifnet_tx_compl(ifnet_t ifp, mbuf_t m); 3422 3423 /******************************************************************************/ 3424 /* for interfaces that support dynamic node absence/presence events */ 3425 /******************************************************************************/ 3426 3427 /* 3428 * @function ifnet_notice_node_presence 3429 * @discussion Provided for network interface drivers to notify the 3430 * system of a change detected in the presence of the specified 3431 * node. 3432 * @param ifp The interface attached to the link where the specified node 3433 * is present. 3434 * @param sa The AF_LINK family address of the node whose presence is 3435 * changing. 3436 * @param rssi The received signal strength indication as measured in 3437 * dBm by a radio receiver. 3438 * @param lqm A link quality metric associated with the specified node. 3439 * @param npm A node proximity metric associated with the specified node. 3440 * @param srvinfo A fixed-size array of octets containing opaque service 3441 * information data used by the mDNS responder subsystem. 3442 * @result Returns 0 on success, or EINVAL if arguments are invalid. 3443 */ 3444 extern errno_t 3445 ifnet_notice_node_presence(ifnet_t ifp, struct sockaddr *sa, int32_t rssi, 3446 int lqm, int npm, u_int8_t srvinfo[48]); 3447 3448 /* 3449 * @function ifnet_notice_node_absence 3450 * @discussion Provided for network interface drivers to notify the 3451 * system that the absence of the specified node has been detected. 3452 * @param ifp The interface attached to the link where the absence of the 3453 * specified node has been detected. 3454 * @param sa The AF_INET6 or AF_LINK family address of the node whose absence has been 3455 * detected. If AF_LINK is specified, AF_INET6 address is derived from the 3456 * AF_LINK address. 3457 * @result Returns 0 on success, or EINVAL if arguments are invalid. 3458 */ 3459 extern errno_t ifnet_notice_node_absence(ifnet_t ifp, struct sockaddr *sa); 3460 3461 /* 3462 * @function ifnet_notice_node_presence_v2 3463 * @discussion Provided for network interface drivers to notify the 3464 * system of a change detected in the presence of the specified 3465 * node. 3466 * @param ifp The interface attached to the link where the specified node 3467 * is present. 3468 * @param sa The AF_INET6 family address of the node whose presence is 3469 * changing. 3470 * @param sdl The AF_LINK family address of the node whose presence is 3471 * changing. 3472 * @param rssi The received signal strength indication as measured in 3473 * dBm by a radio receiver. 3474 * @param lqm A link quality metric associated with the specified node. 3475 * @param npm A node proximity metric associated with the specified node. 3476 * @param srvinfo A fixed-size array of octets containing opaque service 3477 * information data used by the mDNS responder subsystem. 3478 * @result Returns 0 on success, or EINVAL if arguments are invalid. 3479 */ 3480 extern errno_t 3481 ifnet_notice_node_presence_v2(ifnet_t ifp, struct sockaddr *sa, struct sockaddr_dl *sdl, int32_t rssi, 3482 int lqm, int npm, u_int8_t srvinfo[48]); 3483 3484 /* 3485 * @function ifnet_notice_primary_elected 3486 * @discussion Provided for network interface drivers to notify the system 3487 * that the nodes with a locally detected presence on the attached 3488 * link have elected a new primary. 3489 * @param ifp The interface attached to the link where the new primary has 3490 * been elected. 3491 * @result Returns 0 on success, or EINVAL if arguments are invalid. 3492 */ 3493 extern errno_t ifnet_notice_primary_elected(ifnet_t ifp); 3494 3495 /* 3496 * @function ifnet_notice_master_elected 3497 * @discussion Obsolete, use ifnet_notice_primary_elected instead 3498 */ 3499 extern errno_t ifnet_notice_master_elected(ifnet_t ifp); 3500 3501 /******************************************************************************/ 3502 /* for interface delegation */ 3503 /******************************************************************************/ 3504 3505 /* 3506 * @function ifnet_set_delegate 3507 * @discussion Indicate that an interface is delegating another interface 3508 * for accounting/restriction purposes. This could be used by a 3509 * virtual interface that is going over another interface, where 3510 * the virtual interface is to be treated as if it's the underlying 3511 * interface for certain operations/checks. 3512 * @param ifp The delegating interface. 3513 * @param delegated_ifp The delegated interface. If NULL or equal to 3514 * the delegating interface itself, any previously-established 3515 * delegation is removed. If non-NULL, a reference to the 3516 * delegated interface is held by the delegating interface; 3517 * this reference is released via a subsequent call to remove 3518 * the established association, or when the delegating interface 3519 * is detached. 3520 * @param Returns 0 on success, EINVAL if arguments are invalid, or 3521 * ENXIO if the delegating interface isn't currently attached. 3522 */ 3523 extern errno_t 3524 ifnet_set_delegate(ifnet_t ifp, ifnet_t delegated_ifp); 3525 3526 /* 3527 * @function ifnet_get_delegate 3528 * @discussion Retrieve delegated interface information on an interface. 3529 * @param ifp The delegating interface. 3530 * @param pdelegated_ifp Pointer to the delegated interface. Upon 3531 * success, this will contain the delegated interface or 3532 * NULL if there is no delegation in place. If non-NULL, 3533 * the delegated interface will be returned with a reference 3534 * held for caller, and the caller is responsible for releasing 3535 * it via ifnet_release(); 3536 * @param Returns 0 on success, EINVAL if arguments are invalid, or 3537 * ENXIO if the delegating interface isn't currently attached. 3538 */ 3539 extern errno_t 3540 ifnet_get_delegate(ifnet_t ifp, ifnet_t *pdelegated_ifp); 3541 3542 /*************************************************************************/ 3543 /* for interface keep alive offload support */ 3544 /*************************************************************************/ 3545 3546 /* 3547 * @struct ifnet_keepalive_offload_frame 3548 * @discussion This structure is used to define various opportunistic 3549 * polling parameters for an interface. 3550 * For IPsec and AirPlay UDP keep alive only a subset of the 3551 * fields are relevant. 3552 * An incoming TCP keep alive probe has the sequence number 3553 * in the TCP header equal to "remote_seq" and the 3554 * acknowledgment number field is equal to "local_seq". 3555 * An incoming TCP keep alive probe has the sequence number 3556 * equlal to "remote_seq" minus 1 and the acknowledgment number 3557 * field is equal to "local_seq". 3558 * Note that remote_seq is in network byte order so the value to 3559 * match may have to be converted to host byte order when 3560 * subtracting 1. 3561 * For TCP, the field "interval" corresponds to the socket option 3562 * TCP_KEEPALIVE, the field "keep_cnt" to TCP_KEEPINTVL and 3563 * the field "keep_cnt" to TCP_KEEPCNT. 3564 * @field data Keep alive probe to be sent. 3565 * @field type The type of keep alive frame 3566 * @field length The length of the frame in the data field 3567 * @field interval Keep alive interval between probes in seconds 3568 * @field ether_type Tell if it's the protocol is IPv4 or IPv6 3569 * @field keep_cnt Maximum number of time to retry probes (TCP only) 3570 * @field keep_retry Interval before retrying if previous probe was not answered (TCP only) 3571 * @field reply_length The length of the frame in the reply_data field (TCP only) 3572 * @field addr_length Length in bytes of local_addr and remote_addr (TCP only) 3573 * @field flags Flags (TCP only) 3574 * @field reply_data Keep alive reply to be sent to incoming probe (TCP only) 3575 * @field local_addr Local address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only) 3576 * @field remote_addr Remote address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only) 3577 * @field local_port Local port (TCP only) 3578 * @field remote_port Remote port (TCP only) 3579 * @field local_seq Local sequence number for matching incoming replies (TCP only) 3580 * @field remote_seq Remote sequence number for matching incoming probes or replies (TCP only) 3581 */ 3582 3583 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE 128 3584 #define IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE 16 3585 3586 struct ifnet_keepalive_offload_frame { 3587 u_int8_t data[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE]; /* data bytes */ 3588 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_IPSEC 0x0 3589 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_AIRPLAY 0x1 3590 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_TCP 0x2 3591 u_int8_t type; /* type of application */ 3592 u_int8_t length; /* Number of valid data bytes including offset */ 3593 u_int16_t interval; /* Keep alive interval in seconds */ 3594 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV4 0x0 3595 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV6 0x1 3596 u_int8_t ether_type; /* Ether type IPv4 or IPv6 */ 3597 u_int8_t keep_cnt; /* max number of time to retry probes */ 3598 u_int16_t keep_retry; /* interval before retrying if previous probe was not answered */ 3599 u_int8_t reply_length; /* Length of valid reply_data bytes including offset */ 3600 u_int8_t addr_length; /* Length of valid bytes in local_addr and remote_addr */ 3601 #define IFNET_KEEPALIVE_OFFLOAD_FLAG_NOWAKEFROMSLEEP 0x01 3602 u_int8_t flags; 3603 u_int8_t reserved[1]; 3604 u_int8_t reply_data[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE]; /* Response packet */ 3605 u_int8_t local_addr[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE]; /* in network byte order */ 3606 u_int8_t remote_addr[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE]; /* in network byte order */ 3607 u_int16_t local_port; /* in host byte order */ 3608 u_int16_t remote_port; /* in host byte order */ 3609 u_int32_t local_seq; /* in host byte order */ 3610 u_int32_t remote_seq; /* in host byte order */ 3611 }; 3612 3613 /* 3614 * @function ifnet_get_keepalive_offload_frames 3615 * @discussion Fills out frames_array with IP packets to send at 3616 * periodic intervals as Keep-alive or heartbeat messages. 3617 * This can be used to offload keep alives for UDP or TCP. 3618 * Note: The frames are returned in this order: first the IPsec 3619 * frames, then the AirPlay frames and finally the TCP frames. 3620 * If a device does not support one kind of keep alive frames_array 3621 * it should provide a frames_array large enough to accomodate 3622 * the other frames 3623 * @param ifp The interface to send frames out on. This is used to 3624 * select which sockets or IPsec SAs should generate the 3625 * packets. 3626 * @param frames_array An array of ifnet_keepalive_offload_frame 3627 * structs. This is allocated by the caller, and has 3628 * frames_array_count frames of valid memory. 3629 * @param frames_array_count The number of valid frames allocated 3630 * by the caller in frames_array 3631 * @param frame_data_offset The offset in bytes into each frame data 3632 * at which the IPv4/IPv6 packet and payload should be written 3633 * @param used_frames_count The returned number of frames that were 3634 * filled out with valid information. 3635 * @result Returns 0 on success, error number otherwise. 3636 */ 3637 extern errno_t ifnet_get_keepalive_offload_frames(ifnet_t ifp, 3638 struct ifnet_keepalive_offload_frame *frames_array, 3639 u_int32_t frames_array_count, size_t frame_data_offset, 3640 u_int32_t *used_frames_count); 3641 3642 3643 /* 3644 * @function ifnet_notify_tcp_keepalive_offload_timeout 3645 * @discussion Used by an interface to notify a TCP connection whose 3646 * keep alive was offloaded did experience a timeout. 3647 * @param ifp The interface for which the TCP keep alive offload timed out 3648 * @param frame The ifnet_keepalive_offload_frame structure that identifies 3649 * the TCP connection that experienced the timeout. 3650 * All the fields must be zeroed by the caller except for: 3651 * - type: must be IFNET_KEEPALIVE_OFFLOAD_FRAME_TCP 3652 * and for the fields identifying the 5-tup;e of the 3653 * TCP connection: 3654 * - ether_type 3655 * - local_addr 3656 * - remote_addr 3657 * - local_port 3658 * - remote_port 3659 * @result Returns 0 on success, error number otherwise. 3660 */ 3661 extern errno_t ifnet_notify_tcp_keepalive_offload_timeout(ifnet_t ifp, 3662 struct ifnet_keepalive_offload_frame *frame); 3663 3664 /*************************************************************************/ 3665 /* Link level notifications */ 3666 /*************************************************************************/ 3667 /* 3668 * @function ifnet_link_status_report 3669 * @discussion A KPI to let the driver provide link specific 3670 * status information to the protocol stack. The KPI will 3671 * copy contents from the buffer based on the version and 3672 * length provided by the driver. The contents of the buffer 3673 * will be read but will not be modified. 3674 * @param ifp The interface that is generating the report 3675 * @param buffer Buffer containing the link specific information 3676 * for this interface. It is the caller's responsibility 3677 * to free this buffer. 3678 * @param buffer_len Valid length of the buffer provided by the caller 3679 * @result Returns 0 on success, error number otherwise. 3680 */ 3681 extern errno_t ifnet_link_status_report(ifnet_t ifp, const void *buffer, 3682 size_t buffer_len); 3683 3684 /*************************************************************************/ 3685 /* QoS Fastlane */ 3686 /*************************************************************************/ 3687 /*! 3688 * @function ifnet_set_fastlane_capable 3689 * @param interface The interface. 3690 * @param capable Set the truth value that the interface is attached to 3691 * a network that is capable of Fastlane QoS marking. 3692 * @result Returns 0 on success, error number otherwise. 3693 */ 3694 extern errno_t ifnet_set_fastlane_capable(ifnet_t interface, boolean_t capable); 3695 3696 /*! 3697 * @function ifnet_get_fastlane_capable 3698 * @param interface The interface. 3699 * @param capable On output contains the truth value that the interface 3700 * is attached ta network that is capable of Fastlane QoS marking. 3701 * @result Returns 0 on success, error number otherwise. 3702 */ 3703 extern errno_t ifnet_get_fastlane_capable(ifnet_t interface, boolean_t *capable); 3704 3705 /*! 3706 * @function ifnet_get_unsent_bytes 3707 * @param interface The interface 3708 * @param unsent_bytes An out parameter that contains unsent bytes for 3709 * an interface 3710 * @result Returns 0 on success, error otherwise. 3711 */ 3712 extern errno_t ifnet_get_unsent_bytes(ifnet_t interface, int64_t *unsent_bytes); 3713 3714 typedef struct { 3715 int32_t buf_interface; /* data to send at interface */ 3716 int32_t buf_sndbuf; /* data to send at socket buffer */ 3717 } ifnet_buffer_status_t; 3718 3719 /*! 3720 * @function ifnet_get_buffer_status 3721 * @param interface The interface 3722 * @param buf_status An out parameter that contains unsent bytes 3723 * for an interface 3724 * @result Returns 0 on success, EINVAL if any of the arguments is 3725 * NULL, ENXIO if the interface pointer is invalid 3726 */ 3727 extern errno_t ifnet_get_buffer_status(const ifnet_t interface, 3728 ifnet_buffer_status_t *buf_status); 3729 3730 /*! 3731 * @function ifnet_normalise_unsent_data 3732 * @discussion 3733 * Gathers the unsent bytes on all the interfaces. 3734 * This data will be reported to NetworkStatistics. 3735 * 3736 */ 3737 extern void ifnet_normalise_unsent_data(void); 3738 3739 /*************************************************************************/ 3740 /* Low Power Mode */ 3741 /*************************************************************************/ 3742 3743 /*! 3744 * @function ifnet_set_low_power_mode 3745 * @param interface The interface. 3746 * @param on Set the truth value that the interface is in low power mode. 3747 * @result Returns 0 on success, error number otherwise. 3748 */ 3749 extern errno_t ifnet_set_low_power_mode(ifnet_t interface, boolean_t on); 3750 3751 /*! 3752 * @function ifnet_get_low_power_mode 3753 * @param interface The interface. 3754 * @param on On output contains the truth value that the interface 3755 * is in low power mode. 3756 * @result Returns 0 on success, error number otherwise. 3757 */ 3758 extern errno_t ifnet_get_low_power_mode(ifnet_t interface, boolean_t *on); 3759 3760 /*! 3761 * @function ifnet_touch_lastupdown 3762 * @discussion Updates the lastupdown value to now. 3763 * @param interface The interface. 3764 * @result 0 on success otherwise the errno error. 3765 */ 3766 extern errno_t ifnet_touch_lastupdown(ifnet_t interface); 3767 3768 /*! 3769 * @function ifnet_updown_delta 3770 * @discussion Retrieves the difference between lastupdown and now. 3771 * @param interface The interface. 3772 * @param updown_delta A timeval struct to copy the delta between lastupdown and now. 3773 * to. 3774 */ 3775 extern errno_t ifnet_updown_delta(ifnet_t interface, struct timeval *updown_delta); 3776 3777 /*************************************************************************/ 3778 /* Interface advisory notifications */ 3779 /*************************************************************************/ 3780 /*! 3781 * @function ifnet_interface_advisory_report 3782 * @discussion KPI to let the driver provide interface advisory 3783 * notifications to the user space. 3784 * @param ifp The interface that is generating the advisory report. 3785 * @param advisory structure containing the advisory notification 3786 * information. 3787 * @result Returns 0 on success, error number otherwise. 3788 */ 3789 extern errno_t ifnet_interface_advisory_report(ifnet_t ifp, 3790 const struct ifnet_interface_advisory *advisory); 3791 3792 #endif /* KERNEL_PRIVATE */ 3793 3794 __END_DECLS 3795 3796 #undef __NKE_API_DEPRECATED 3797 #endif /* __KPI_INTERFACE__ */ 3798