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