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