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