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