2 * Copyright (c) 2004-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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.
35 #ifndef __KPI_INTERFACE__
36 #define __KPI_INTERFACE__
38 #ifndef XNU_KERNEL_PRIVATE
39 #include <TargetConditionals.h>
42 #include <sys/kernel_types.h>
45 struct if_interface_state
;
46 struct ifnet_interface_advisory
;
47 #include <sys/kpi_mbuf.h>
48 #endif /* KERNEL_PRIVATE */
50 #include <sys/_types/_sa_family_t.h>
52 #ifdef XNU_KERNEL_PRIVATE
54 #define KPI_INTERFACE_EMBEDDED 1
56 #define KPI_INTERFACE_EMBEDDED 0
59 #if (TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR)
60 #define KPI_INTERFACE_EMBEDDED 1
62 #define KPI_INTERFACE_EMBEDDED 0
69 struct kern_event_msg
;
71 struct ifnet_demux_desc
;
74 * @enum Interface Families
75 * @abstract Constants defining interface families.
76 * @constant IFNET_FAMILY_ANY Match interface of any family type.
77 * @constant IFNET_FAMILY_LOOPBACK A software loopback interface.
78 * @constant IFNET_FAMILY_ETHERNET An Ethernet interface.
79 * @constant IFNET_FAMILY_SLIP A SLIP interface.
80 * @constant IFNET_FAMILY_TUN A tunnel interface.
81 * @constant IFNET_FAMILY_VLAN A virtual LAN interface.
82 * @constant IFNET_FAMILY_PPP A PPP interface.
83 * @constant IFNET_FAMILY_PVC A PVC interface.
84 * @constant IFNET_FAMILY_DISC A DISC interface.
85 * @constant IFNET_FAMILY_MDECAP A MDECAP interface.
86 * @constant IFNET_FAMILY_GIF A generic tunnel interface.
87 * @constant IFNET_FAMILY_FAITH A FAITH [IPv4/IPv6 translation] interface.
88 * @constant IFNET_FAMILY_STF A 6to4 interface.
89 * @constant IFNET_FAMILY_FIREWIRE An IEEE 1394 [Firewire] interface.
90 * @constant IFNET_FAMILY_BOND A virtual bonded interface.
91 * @constant IFNET_FAMILY_CELLULAR A cellular interface.
92 * @constant IFNET_FAMILY_6LOWPAN A 6LoWPAN interface.
93 * @constant IFNET_FAMILY_UTUN A utun interface.
94 * @constant IFNET_FAMILY_IPSEC An IPsec interface.
98 IFNET_FAMILY_LOOPBACK
= 1,
99 IFNET_FAMILY_ETHERNET
= 2,
100 IFNET_FAMILY_SLIP
= 3,
101 IFNET_FAMILY_TUN
= 4,
102 IFNET_FAMILY_VLAN
= 5,
103 IFNET_FAMILY_PPP
= 6,
104 IFNET_FAMILY_PVC
= 7,
105 IFNET_FAMILY_DISC
= 8,
106 IFNET_FAMILY_MDECAP
= 9,
107 IFNET_FAMILY_GIF
= 10,
108 IFNET_FAMILY_FAITH
= 11, /* deprecated */
109 IFNET_FAMILY_STF
= 12,
110 IFNET_FAMILY_FIREWIRE
= 13,
111 IFNET_FAMILY_BOND
= 14,
112 IFNET_FAMILY_CELLULAR
= 15,
113 IFNET_FAMILY_6LOWPAN
= 16,
114 IFNET_FAMILY_UTUN
= 17,
115 IFNET_FAMILY_IPSEC
= 18
119 * @typedef ifnet_family_t
120 * @abstract Storage type for the interface family.
122 typedef u_int32_t ifnet_family_t
;
124 #ifdef KERNEL_PRIVATE
126 * @enum Interface Sub-families
127 * @abstract Constants defining interface sub-families (may also
128 * be viewed as the underlying transport). Some families
129 * (e.g. IFNET_FAMILY_ETHERNET) are often too generic.
130 * These sub-families allow us to further refine the
131 * interface family, e.g. Ethernet over Wi-Fi/USB, etc.
134 IFNET_SUBFAMILY_ANY
= 0,
135 IFNET_SUBFAMILY_USB
= 1,
136 IFNET_SUBFAMILY_BLUETOOTH
= 2,
137 IFNET_SUBFAMILY_WIFI
= 3,
138 IFNET_SUBFAMILY_THUNDERBOLT
= 4,
139 IFNET_SUBFAMILY_RESERVED
= 5,
140 IFNET_SUBFAMILY_INTCOPROC
= 6,
141 IFNET_SUBFAMILY_QUICKRELAY
= 7,
142 IFNET_SUBFAMILY_DEFAULT
= 8,
146 * @typedef ifnet_sub_family_t
147 * @abstract Storage type for the interface sub-family.
149 typedef u_int32_t ifnet_subfamily_t
;
150 #endif /* KERNEL_PRIVATE */
152 #ifndef BPF_TAP_MODE_T
153 #define BPF_TAP_MODE_T
156 * @abstract Constants defining interface families.
157 * @constant BPF_MODE_DISABLED Disable bpf.
158 * @constant BPF_MODE_INPUT Enable input only.
159 * @constant BPF_MODE_OUTPUT Enable output only.
160 * @constant BPF_MODE_INPUT_OUTPUT Enable input and output.
164 BPF_MODE_DISABLED
= 0,
167 BPF_MODE_INPUT_OUTPUT
= 3
170 * @typedef bpf_tap_mode
171 * @abstract Mode for tapping. BPF_MODE_DISABLED/BPF_MODE_INPUT_OUTPUT etc.
173 typedef u_int32_t bpf_tap_mode
;
174 #endif /* !BPF_TAP_MODE_T */
177 * @typedef protocol_family_t
178 * @abstract Storage type for the protocol family.
180 typedef u_int32_t protocol_family_t
;
183 * @enum Interface Abilities
184 * @abstract Constants defining interface offload support.
185 * @constant IFNET_CSUM_IP Hardware will calculate IPv4 checksums.
186 * @constant IFNET_CSUM_TCP Hardware will calculate TCP checksums.
187 * @constant IFNET_CSUM_UDP Hardware will calculate UDP checksums.
188 * @constant IFNET_CSUM_FRAGMENT Hardware will checksum IP fragments.
189 * @constant IFNET_IP_FRAGMENT Hardware will fragment IP packets.
190 * @constant IFNET_CSUM_TCPIPV6 Hardware will calculate TCP IPv6 checksums.
191 * @constant IFNET_CSUM_UDPIPV6 Hardware will calculate UDP IPv6 checksums.
192 * @constant IFNET_IPV6_FRAGMENT Hardware will fragment IPv6 packets.
193 * @constant IFNET_VLAN_TAGGING Hardware will generate VLAN headers.
194 * @constant IFNET_VLAN_MTU Hardware supports VLAN MTU.
195 * @constant IFNET_MULTIPAGES Driver is capable of handling packets
196 * coming down from the network stack that reside in virtually,
197 * but not in physically contiguous span of the external mbuf
198 * clusters. In this case, the data area of a packet in the
199 * external mbuf cluster might cross one or more physical
200 * pages that are disjoint, depending on the interface MTU
201 * and the packet size. Such a use of larger than system page
202 * size clusters by the network stack is done for better system
203 * efficiency. Drivers that utilize the IOMbufNaturalMemoryCursor
204 * with the getPhysicalSegmentsWithCoalesce interfaces and
205 * enumerate the list of vectors should set this flag for
206 * possible gain in performance during bulk data transfer.
207 * @constant IFNET_TSO_IPV4 Hardware supports IPv4 TCP Segment Offloading.
208 * If the Interface driver sets this flag, TCP will send larger frames (up to 64KB) as one
209 * frame to the adapter which will perform the final packetization. The maximum TSO segment
210 * supported by the interface can be set with "ifnet_set_tso_mtu". To retreive the real MTU
211 * for the TCP connection the function "mbuf_get_tso_requested" is used by the driver. Note
212 * that if TSO is active, all the packets will be flagged for TSO, not just large packets.
213 * @constant IFNET_TSO_IPV6 Hardware supports IPv6 TCP Segment Offloading.
214 * If the Interface driver sets this flag, TCP IPv6 will send larger frames (up to 64KB) as one
215 * frame to the adapter which will perform the final packetization. The maximum TSO segment
216 * supported by the interface can be set with "ifnet_set_tso_mtu". To retreive the real MTU
217 * for the TCP IPv6 connection the function "mbuf_get_tso_requested" is used by the driver.
218 * Note that if TSO is active, all the packets will be flagged for TSO, not just large packets.
219 * @constant IFNET_TX_STATUS Driver supports returning a per packet
220 * transmission status (pass, fail or other errors) of whether
221 * the packet was successfully transmitted on the link, or the
222 * transmission was aborted, or transmission failed.
227 IFNET_CSUM_IP
= 0x00000001,
228 IFNET_CSUM_TCP
= 0x00000002,
229 IFNET_CSUM_UDP
= 0x00000004,
230 IFNET_CSUM_FRAGMENT
= 0x00000008,
231 IFNET_IP_FRAGMENT
= 0x00000010,
232 IFNET_CSUM_TCPIPV6
= 0x00000020,
233 IFNET_CSUM_UDPIPV6
= 0x00000040,
234 IFNET_IPV6_FRAGMENT
= 0x00000080,
235 #ifdef KERNEL_PRIVATE
236 IFNET_CSUM_PARTIAL
= 0x00001000,
237 IFNET_CSUM_SUM16
= IFNET_CSUM_PARTIAL
,
238 IFNET_CSUM_ZERO_INVERT
= 0x00002000,
239 #endif /* KERNEL_PRIVATE */
240 IFNET_VLAN_TAGGING
= 0x00010000,
241 IFNET_VLAN_MTU
= 0x00020000,
242 IFNET_MULTIPAGES
= 0x00100000,
243 IFNET_TSO_IPV4
= 0x00200000,
244 IFNET_TSO_IPV6
= 0x00400000,
245 IFNET_TX_STATUS
= 0x00800000,
246 IFNET_HW_TIMESTAMP
= 0x01000000,
247 IFNET_SW_TIMESTAMP
= 0x02000000
250 * @typedef ifnet_offload_t
251 * @abstract Flags indicating the offload support of the interface.
253 typedef u_int32_t ifnet_offload_t
;
255 #ifdef KERNEL_PRIVATE
256 #define IFNET_OFFLOADF_BITS \
257 "\020\1CSUM_IP\2CSUM_TCP\3CSUM_UDP\4CSUM_IP_FRAGS\5IP_FRAGMENT" \
258 "\6CSUM_TCPIPV6\7CSUM_UDPIPV6\10IPV6_FRAGMENT\15CSUM_PARTIAL" \
259 "\16CSUM_ZERO_INVERT\20VLAN_TAGGING\21VLAN_MTU\25MULTIPAGES" \
260 "\26TSO_IPV4\27TSO_IPV6\30TXSTATUS\31HW_TIMESTAMP\32SW_TIMESTAMP"
262 #define IFNET_CHECKSUMF \
263 (IFNET_CSUM_IP | IFNET_CSUM_TCP | IFNET_CSUM_UDP | \
264 IFNET_CSUM_FRAGMENT | IFNET_CSUM_TCPIPV6 | IFNET_CSUM_UDPIPV6 | \
265 IFNET_CSUM_PARTIAL | IFNET_CSUM_ZERO_INVERT)
268 (IFNET_TSO_IPV4 | IFNET_TSO_IPV6)
269 #endif /* KERNEL_PRIVATE */
274 * These are function pointers you supply to the kernel in the interface.
277 * @typedef bpf_packet_func
279 * @discussion bpf_packet_func The bpf_packet_func is used to intercept
280 * inbound and outbound packets. The tap function will never free
281 * the mbuf. The tap function will only copy the mbuf in to various
282 * bpf file descriptors tapping this interface.
283 * @param interface The interface being sent or received on.
284 * @param data The packet to be transmitted or received.
285 * @result An errno value or zero upon success.
287 /* Fast path - do not block or spend excessive amounts of time */
288 typedef errno_t (*bpf_packet_func
)(ifnet_t interface
, mbuf_t data
);
291 * @typedef ifnet_output_func
293 * @discussion ifnet_output_func is used to transmit packets. The stack
294 * will pass fully formed packets, including frame header, to the
295 * ifnet_output function for an interface. The driver is
296 * responsible for freeing the mbuf.
297 * @param interface The interface being sent on.
298 * @param data The packet to be sent.
300 /* Fast path - do not block or spend excessive amounts of time */
301 typedef errno_t (*ifnet_output_func
)(ifnet_t interface
, mbuf_t data
);
304 * @typedef ifnet_ioctl_func
305 * @discussion ifnet_ioctl_func is used to communicate ioctls from the
306 * stack to the driver.
308 * All undefined ioctls are reserved for future use by Apple. If
309 * you need to communicate with your kext using an ioctl, please
310 * use SIOCSIFKPI and SIOCGIFKPI.
311 * @param interface The interface the ioctl is being sent to.
312 * @param cmd The ioctl command.
313 * @param data A pointer to any data related to the ioctl.
315 typedef errno_t (*ifnet_ioctl_func
)(ifnet_t interface
, unsigned long cmd
,
319 * @typedef ifnet_set_bpf_tap
320 * @discussion Deprecated. Specify NULL. Call bpf_tap_in/bpf_tap_out
323 typedef errno_t (*ifnet_set_bpf_tap
)(ifnet_t interface
, bpf_tap_mode mode
,
324 bpf_packet_func callback
);
327 * @typedef ifnet_detached_func
328 * @discussion ifnet_detached_func is called an interface is detached
329 * from the list of interfaces. When ifnet_detach is called, it may
330 * not detach the interface immediately if protocols are attached.
331 * ifnet_detached_func is used to notify the interface that it has
332 * been detached from the networking stack. This is the last
333 * function that will be called on an interface. Until this
334 * function returns, you must not unload a kext supplying function
335 * pointers to this interface, even if ifnet_detacah has been
336 * called. Your detach function may be called during your call to
338 * @param interface The interface that has been detached.
341 typedef void (*ifnet_detached_func
)(ifnet_t interface
);
344 * @typedef ifnet_demux_func
345 * @discussion ifnet_demux_func is called for each inbound packet to
346 * determine which protocol family the packet belongs to. This
347 * information is then used by the stack to determine which
348 * protocol to pass the packet to. This function may return
349 * protocol families for protocols that are not attached. If the
350 * protocol family has not been attached to the interface, the
351 * packet will be discarded.
352 * @param interface The interface the packet was received on.
353 * @param packet The mbuf containing the packet.
354 * @param frame_header A pointer to the frame header.
355 * @param protocol_family Upon return, the protocol family matching the
356 * packet should be stored here.
358 * If the result is zero, processing will continue normally.
359 * If the result is EJUSTRETURN, processing will stop but the
360 * packet will not be freed.
361 * If the result is anything else, the processing will stop and
362 * the packet will be freed.
364 typedef errno_t (*ifnet_demux_func
)(ifnet_t interface
, mbuf_t packet
,
365 char *frame_header
, protocol_family_t
*protocol_family
);
368 * @typedef ifnet_event_func
369 * @discussion ifnet_event_func is called when an event occurs on a
370 * specific interface.
371 * @param interface The interface the event occurred on.
373 typedef void (*ifnet_event_func
)(ifnet_t interface
, const struct kev_msg
*msg
);
376 * @typedef ifnet_framer_func
377 * @discussion ifnet_framer_func is called for each outbound packet to
378 * give the interface an opportunity to prepend interface specific
380 * @param interface The interface the packet is being sent on.
381 * @param packet Pointer to the mbuf containing the packet, caller may
382 * set this to a different mbuf upon return. This can happen if the
383 * frameout function needs to prepend another mbuf to the chain to
384 * have enough space for the header.
385 * @param dest The higher layer protocol destination (i.e. IP address).
386 * @param dest_linkaddr The link layer address as determined by the
387 * protocol's pre-output function.
388 * @param frame_type The frame type as determined by the protocol's
389 * pre-output function.
390 * @discussion prepend_len The length of prepended bytes to the mbuf.
391 * (ONLY used if KPI_INTERFACE_EMBEDDED is defined to 1)
392 * @discussion postpend_len The length of the postpended bytes to the mbuf.
393 * (ONLY used if KPI_INTERFACE_EMBEDDED is defined to 1)
395 * If the result is zero, processing will continue normally.
396 * If the result is EJUSTRETURN, processing will stop but the
397 * packet will not be freed.
398 * If the result is anything else, the processing will stop and
399 * the packet will be freed.
401 typedef errno_t (*ifnet_framer_func
)(ifnet_t interface
, mbuf_t
*packet
,
402 const struct sockaddr
*dest
, const char *dest_linkaddr
,
403 const char *frame_type
404 #if KPI_INTERFACE_EMBEDDED
405 , u_int32_t
*prepend_len
, u_int32_t
*postpend_len
406 #endif /* KPI_INTERFACE_EMBEDDED */
408 #ifdef KERNEL_PRIVATE
409 typedef errno_t (*ifnet_framer_extended_func
)(ifnet_t interface
, mbuf_t
*packet
,
410 const struct sockaddr
*dest
, const char *dest_linkaddr
,
411 const char *frame_type
, u_int32_t
*prepend_len
,
412 u_int32_t
*postpend_len
);
413 #endif /* KERNEL_PRIVATE */
416 * @typedef ifnet_add_proto_func
417 * @discussion if_add_proto_func is called by the stack when a protocol
418 * is attached to an interface. This gives the interface an
419 * opportunity to get a list of protocol description structures
420 * for demuxing packets to this protocol (demux descriptors).
421 * @param interface The interface the protocol will be attached to.
422 * @param protocol_family The family of the protocol being attached.
423 * @param demux_array An array of demux descriptors that describe
424 * the interface specific ways of identifying packets belonging
425 * to this protocol family.
426 * @param demux_count The number of demux descriptors in the array.
428 * If the result is zero, processing will continue normally.
429 * If the result is anything else, the add protocol will be
432 typedef errno_t (*ifnet_add_proto_func
)(ifnet_t interface
,
433 protocol_family_t protocol_family
,
434 const struct ifnet_demux_desc
*demux_array
, u_int32_t demux_count
);
437 * @typedef if_del_proto_func
438 * @discussion if_del_proto_func is called by the stack when a protocol
439 * is being detached from an interface. This gives the interface an
440 * opportunity to free any storage related to this specific
441 * protocol being attached to this interface.
442 * @param interface The interface the protocol will be detached from.
443 * @param protocol_family The family of the protocol being detached.
445 * If the result is zero, processing will continue normally.
446 * If the result is anything else, the detach will continue
447 * and the error will be returned to the caller.
449 typedef errno_t (*ifnet_del_proto_func
)(ifnet_t interface
,
450 protocol_family_t protocol_family
);
453 * @typedef ifnet_check_multi
454 * @discussion ifnet_check_multi is called for each multicast address
455 * added to an interface. This gives the interface an opportunity
456 * to reject invalid multicast addresses before they are attached
459 * To prevent an address from being added to your multicast list,
460 * return EADDRNOTAVAIL. If you don't know how to parse/translate
461 * the address, return EOPNOTSUPP.
462 * @param interface The interface.
463 * @param mcast The multicast address.
465 * Zero upon success, EADDRNOTAVAIL on invalid multicast,
466 * EOPNOTSUPP for addresses the interface does not understand.
468 typedef errno_t (*ifnet_check_multi
)(ifnet_t interface
,
469 const struct sockaddr
*mcast
);
472 * @typedef proto_media_input
473 * @discussion proto_media_input is called for all inbound packets for
474 * a specific protocol on a specific interface. This function is
475 * registered on an interface using ifnet_attach_protocol.
476 * @param ifp The interface the packet was received on.
477 * @param protocol The protocol of the packet received.
478 * @param packet The packet being input.
479 * @param header The frame header.
481 * If the result is zero, the caller will assume the packet was
482 * passed to the protocol.
483 * If the result is non-zero and not EJUSTRETURN, the caller will
486 typedef errno_t (*proto_media_input
)(ifnet_t ifp
, protocol_family_t protocol
,
487 mbuf_t packet
, char *header
);
490 * @typedef proto_media_input_v2
491 * @discussion proto_media_input_v2 is called for all inbound packets for
492 * a specific protocol on a specific interface. This function is
493 * registered on an interface using ifnet_attach_protocolv2.
494 * proto_media_input_v2 differs from proto_media_input in that it
495 * will be called for a list of packets instead of once for each
496 * individual packet. The frame header can be retrieved using
497 * mbuf_pkthdr_header.
498 * @param ifp The interface the packet was received on.
499 * @param protocol The protocol of the packet received.
500 * @param packet The packet being input.
502 * If the result is zero, the caller will assume the packets were
503 * passed to the protocol.
504 * If the result is non-zero and not EJUSTRETURN, the caller will
507 typedef errno_t (*proto_media_input_v2
)(ifnet_t ifp
, protocol_family_t protocol
,
511 * @typedef proto_media_preout
512 * @discussion proto_media_preout is called just before the packet
513 * is transmitted. This gives the proto_media_preout function an
514 * opportunity to specify the media specific frame type and
516 * @param ifp The interface the packet will be sent on.
517 * @param protocol The protocol of the packet being sent
519 * @param packet The packet being sent.
520 * @param dest The protocol level destination address.
521 * @param route A pointer to the routing structure for the packet.
522 * @param frame_type The media specific frame type.
523 * @param link_layer_dest The media specific destination.
525 * If the result is zero, processing will continue normally. If the
526 * result is non-zero, processing will stop. If the result is
527 * non-zero and not EJUSTRETURN, the packet will be freed by the
530 typedef errno_t (*proto_media_preout
)(ifnet_t ifp
, protocol_family_t protocol
,
531 mbuf_t
*packet
, const struct sockaddr
*dest
, void *route
, char *frame_type
,
532 char *link_layer_dest
);
535 * @typedef proto_media_event
536 * @discussion proto_media_event is called to notify this layer of
537 * interface specific events.
538 * @param ifp The interface.
539 * @param protocol The protocol family.
540 * @param event The event.
542 typedef void (*proto_media_event
)(ifnet_t ifp
, protocol_family_t protocol
,
543 const struct kev_msg
*event
);
546 * @typedef proto_media_ioctl
547 * @discussion proto_media_event allows this layer to handle ioctls.
548 * When an ioctl is handled, it is passed to the interface filters,
549 * protocol filters, protocol, and interface. If you do not support
550 * this ioctl, return EOPNOTSUPP. If you successfully handle the
551 * ioctl, return zero. If you return any error other than
552 * EOPNOTSUPP, other parts of the stack may not get an opportunity
553 * to process the ioctl. If you return EJUSTRETURN, processing will
554 * stop and a result of zero will be returned to the caller.
556 * All undefined ioctls are reserved for future use by Apple. If
557 * you need to communicate with your kext using an ioctl, please
558 * use SIOCSIFKPI and SIOCGIFKPI.
559 * @param ifp The interface.
560 * @param protocol The protocol family.
561 * @param command The ioctl command.
562 * @param argument The argument to the ioctl.
564 * See the discussion.
566 typedef errno_t (*proto_media_ioctl
)(ifnet_t ifp
, protocol_family_t protocol
,
567 unsigned long command
, void *argument
);
570 * @typedef proto_media_detached
571 * @discussion proto_media_detached notifies you that your protocol
573 * @param ifp The interface.
574 * @param protocol The protocol family.
576 * See the discussion.
578 typedef errno_t (*proto_media_detached
)(ifnet_t ifp
, protocol_family_t protocol
);
581 * @typedef proto_media_resolve_multi
582 * @discussion proto_media_resolve_multi is called to resolve a
583 * protocol layer mulitcast address to a link layer multicast
585 * @param ifp The interface.
586 * @param proto_addr The protocol address.
587 * @param out_ll A sockaddr_dl to copy the link layer multicast in to.
588 * @param ll_len The length of data allocated for out_ll.
589 * @result Return zero on success or an errno error value on failure.
591 typedef errno_t (*proto_media_resolve_multi
)(ifnet_t ifp
,
592 const struct sockaddr
*proto_addr
, struct sockaddr_dl
*out_ll
,
596 * @typedef proto_media_send_arp
597 * @discussion proto_media_send_arp is called by the stack to generate
598 * an ARP packet. This field is currently only used with IP. This
599 * function should inspect the parameters and transmit an arp
600 * packet using the information passed in.
601 * @param ifp The interface the arp packet should be sent on.
602 * @param arpop The arp operation (usually ARPOP_REQUEST or
604 * @param sender_hw The value to use for the sender hardware
605 * address field. If this is NULL, use the hardware address
607 * @param sender_proto The value to use for the sender protocol
608 * address field. This will not be NULL.
609 * @param target_hw The value to use for the target hardware address.
610 * If this is NULL, the target hardware address in the ARP packet
611 * should be NULL and the link-layer destination for the back
612 * should be a broadcast. If this is not NULL, this value should be
613 * used for both the link-layer destination and the target hardware
615 * @param target_proto The target protocol address. This will not be
617 * @result Return zero on success or an errno error value on failure.
619 typedef errno_t (*proto_media_send_arp
)(ifnet_t ifp
, u_short arpop
,
620 const struct sockaddr_dl
*sender_hw
, const struct sockaddr
*sender_proto
,
621 const struct sockaddr_dl
*target_hw
, const struct sockaddr
*target_proto
);
624 * @struct ifnet_stat_increment_param
625 * @discussion This structure is used increment the counters on a
627 * @field packets_in The number of packets received.
628 * @field bytes_in The number of bytes received.
629 * @field errors_in The number of receive errors.
630 * @field packets_out The number of packets transmitted.
631 * @field bytes_out The number of bytes transmitted.
632 * @field errors_out The number of transmission errors.
633 * @field collisions The number of collisions seen by this interface.
634 * @field dropped The number of packets dropped.
636 struct ifnet_stat_increment_param
{
637 u_int32_t packets_in
;
641 u_int32_t packets_out
;
643 u_int32_t errors_out
;
645 u_int32_t collisions
;
650 * @struct ifnet_init_params
651 * @discussion This structure is used to define various properties of
652 * the interface when calling ifnet_allocate. A copy of these
653 * values will be stored in the ifnet and cannot be modified
654 * while the interface is attached.
655 * @field uniqueid An identifier unique to this instance of the
657 * @field uniqueid_len The length, in bytes, of the uniqueid.
658 * @field name The interface name (i.e. en).
659 * @field unit The interface unit number (en0's unit number is 0).
660 * @field family The interface family.
661 * @field type The interface type (see sys/if_types.h). Must be less
662 * than 256. For new types, use IFT_OTHER.
663 * @field output The output function for the interface. Every packet the
664 * stack attempts to send through this interface will go out
665 * through this function.
666 * @field demux The function used to determine the protocol family of an
668 * @field add_proto The function used to attach a protocol to this
670 * @field del_proto The function used to remove a protocol from this
672 * @field framer The function used to frame outbound packets, may be NULL.
673 * @field softc Driver specific storage. This value can be retrieved from
674 * the ifnet using the ifnet_softc function.
675 * @field ioctl The function used to handle ioctls.
676 * @field set_bpf_tap The function used to set the bpf_tap function.
677 * @field detach The function called to let the driver know the interface
679 * @field event The function to notify the interface of various interface
680 * specific kernel events.
681 * @field broadcast_addr The link-layer broadcast address for this
683 * @field broadcast_len The length of the link-layer broadcast address.
685 struct ifnet_init_params
{
686 /* used to match recycled interface */
687 const void *uniqueid
; /* optional */
688 u_int32_t uniqueid_len
; /* optional */
690 /* used to fill out initial values for interface */
691 const char *name
; /* required */
692 u_int32_t unit
; /* required */
693 ifnet_family_t family
; /* required */
694 u_int32_t type
; /* required */
695 ifnet_output_func output
; /* required */
696 ifnet_demux_func demux
; /* required */
697 ifnet_add_proto_func add_proto
; /* required */
698 ifnet_del_proto_func del_proto
; /* required */
699 ifnet_check_multi check_multi
; /* required for non point-to-point interfaces */
700 ifnet_framer_func framer
; /* optional */
701 void *softc
; /* optional */
702 ifnet_ioctl_func ioctl
; /* optional */
703 ifnet_set_bpf_tap set_bpf_tap
; /* deprecated */
704 ifnet_detached_func detach
; /* optional */
705 ifnet_event_func event
; /* optional */
706 const void *broadcast_addr
; /* required for non point-to-point interfaces */
707 u_int32_t broadcast_len
; /* required for non point-to-point interfaces */
710 #ifdef KERNEL_PRIVATE
711 /* Valid values for version */
712 #define IFNET_INIT_VERSION_2 2
713 #define IFNET_INIT_CURRENT_VERSION IFNET_INIT_VERSION_2
715 /* Valid values for flags */
716 #define IFNET_INIT_LEGACY 0x1 /* legacy network interface model */
717 #define IFNET_INIT_INPUT_POLL 0x2 /* opportunistic input polling model */
718 #define IFNET_INIT_NX_NOAUTO 0x4 /* do not auto config nexus */
719 #define IFNET_INIT_ALLOC_KPI 0x8 /* allocated via the ifnet_alloc() KPI */
722 * @typedef ifnet_pre_enqueue_func
723 * @discussion ifnet_pre_enqueue_func is called for each outgoing packet
724 * for the interface. The driver may perform last-minute changes
725 * on the (fully formed) packet, but it is responsible for calling
726 * ifnet_enqueue() to enqueue the packet upon completion.
727 * @param interface The interface being sent on.
728 * @param data The packet to be sent.
730 typedef errno_t (*ifnet_pre_enqueue_func
)(ifnet_t interface
, mbuf_t data
);
733 * @typedef ifnet_start_func
734 * @discussion ifnet_start_func is used to indicate to the driver that
735 * one or more packets may be dequeued by calling ifnet_dequeue()
736 * or ifnet_dequeue_multi() or ifnet_dequeue_multi_bytes().
737 * This routine gets invoked when ifnet_start() is called;
738 * the ifnet_start_func callback will be executed within the
739 * context of a dedicated kernel thread, hence it is
740 * guaranteed to be single threaded. The driver must employ
741 * additional serializations if this callback routine is
742 * to be called directly from another context, in order to
743 * prevent race condition related issues (e.g. out-of-order
744 * packets.) The dequeued packets will be fully formed
745 * packets (including frame headers). The packets must be
746 * freed by the driver.
747 * @param interface The interface being sent on.
749 typedef void (*ifnet_start_func
)(ifnet_t interface
);
752 * @typedef ifnet_input_poll_func
753 * @discussion ifnet_input_poll_func is called by the network stack to
754 * retrieve one or more packets from the driver which implements
755 * the new driver input model.
756 * @param interface The interface to retrieve the packets from.
757 * @param flags For future use.
758 * @param max_count The maximum number of packets to be dequeued.
759 * @param first_packet Pointer to the first packet being dequeued.
760 * @param last_packet Pointer to the last packet being dequeued.
761 * @param cnt Pointer to a storage for the number of packets dequeued.
762 * @param len Pointer to a storage for the total length (in bytes)
763 * of the dequeued packets.
765 typedef void (*ifnet_input_poll_func
)(ifnet_t interface
, u_int32_t flags
,
766 u_int32_t max_count
, mbuf_t
*first_packet
, mbuf_t
*last_packet
,
767 u_int32_t
*cnt
, u_int32_t
*len
);
770 * @enum Interface control commands
771 * @abstract Constants defining control commands.
773 * @constant IFNET_CTL_SET_INPUT_MODEL Set input model.
774 * @constant IFNET_CTL_GET_INPUT_MODEL Get input model.
775 * @constant IFNET_CTL_SET_LOG Set logging level.
776 * @constant IFNET_CTL_GET_LOG Get logging level.
779 IFNET_CTL_SET_INPUT_MODEL
= 1, /* input ctl */
780 IFNET_CTL_GET_INPUT_MODEL
= 2, /* input ctl */
781 IFNET_CTL_SET_LOG
= 3, /* output ctl */
782 IFNET_CTL_GET_LOG
= 4, /* output ctl */
783 IFNET_CTL_NOTIFY_ADDRESS
= 5 /* output ctl */
787 * @typedef ifnet_ctl_cmd_t
788 * @abstract Storage type for the interface control command.
790 typedef u_int32_t ifnet_ctl_cmd_t
;
793 * @enum Interface model sub-commands
794 * @abstract Constants defining model sub-commands.
796 * @constant IFNET_MODEL_INPUT_POLL_OFF Polling is inactive. When set,
797 * the network stack will no longer invoke the input_poll callback
798 * until the next time polling is turned on; the driver should
799 * proceed to pushing the packets up to the network stack as in
800 * the legacy input model, and if applicable, the driver should
801 * also enable receive interrupt for the hardware. During get,
802 * this indicates that the driver is currently operating in
803 * the legacy/push input model.
804 * @constant IFNET_MODEL_INPUT_POLL_ON Polling is active. When set, the
805 * network stack will begin to invoke the input_poll callback to
806 * retrieve packets from the driver until the next time polling
807 * is turned off; the driver should no longer be pushing packets
808 * up to the network stack, and if applicable, the driver should
809 * also disable receive interrupt for the hardware. During get,
810 * this indicates that the driver is currently operating in
811 * the new/pull input model.
814 IFNET_MODEL_INPUT_POLL_OFF
= 0,
815 IFNET_MODEL_INPUT_POLL_ON
= 1,
819 * @typedef ifnet_model_t
820 * @abstract Storage type for the interface model sub-command.
822 typedef u_int32_t ifnet_model_t
;
825 * @struct ifnet_model_params
826 * @discussion This structure is used as parameter to the ifnet model
828 * @field model The interface model.
830 struct ifnet_model_params
{
832 u_int32_t reserved
[3];
836 * @enum Interface logging sub-commands.
837 * @abstract Constants defining logging levels/priorities. A level
838 * includes all other levels below it. It is expected that
839 * verbosity increases along with the level.
841 * @constant IFNET_LOG_DEFAULT Revert to default logging level.
842 * @constant IFNET_LOG_ALERT Log actions that must be taken immediately.
843 * @constant IFNET_LOG_CRITICAL Log critical conditions.
844 * @constant IFNET_LOG_ERROR Log error conditions.
845 * @constant IFNET_LOG_WARNING Log warning conditions.
846 * @constant IFNET_LOG_NOTICE Log normal but significant conditions.
847 * @constant IFNET_LOG_INFORMATIONAL Log informational messages.
848 * @constant IFNET_LOG_DEBUG Log debug-level messages.
851 IFNET_LOG_DEFAULT
= 0,
853 IFNET_LOG_CRITICAL
= 2,
855 IFNET_LOG_WARNING
= 4,
856 IFNET_LOG_NOTICE
= 5,
857 IFNET_LOG_INFORMATIONAL
= 6,
861 #ifdef BSD_KERNEL_PRIVATE
862 #define IFNET_LOG_MIN IFNET_LOG_DEFAULT
863 #define IFNET_LOG_MAX IFNET_LOG_DEBUG
864 #endif /* BSD_KERNEL_PRIVATE */
867 * @typedef ifnet_log_level_t
868 * @abstract Storage type for log level/priority.
870 typedef int32_t ifnet_log_level_t
;
873 * @enum Interface logging facilities
874 * @abstract Constants defining the logging facilities which
875 * are to be configured with the specified logging level.
877 * @constant IFNET_LOGF_DLIL The DLIL layer.
878 * @constant IFNET_LOGF_FAMILY The networking family layer.
879 * @constant IFNET_LOGF_DRIVER The device driver layer.
880 * @constant IFNET_LOGF_FIRMWARE The firmware layer.
883 IFNET_LOGF_DLIL
= 0x00000001,
884 IFNET_LOGF_FAMILY
= 0x00010000,
885 IFNET_LOGF_DRIVER
= 0x01000000,
886 IFNET_LOGF_FIRMWARE
= 0x10000000
889 #ifdef BSD_KERNEL_PRIVATE
890 #define IFNET_LOGF_MASK \
891 (IFNET_LOGF_DLIL | IFNET_LOGF_FAMILY | IFNET_LOGF_DRIVER | \
894 #define IFNET_LOGF_BITS \
895 "\020\1DLIL\21FAMILY\31DRIVER\35FIRMWARE"
897 #endif /* BSD_KERNEL_PRIVATE */
900 * @typedef ifnet_log_flags_t
901 * @abstract Storage type for log flags/facilities.
903 typedef u_int32_t ifnet_log_flags_t
;
906 * @enum Interface logging category
907 * @abstract Constants defininig categories for issues experienced.
909 * @constant IFNET_LOGCAT_CONNECTIVITY Connectivity related issues.
910 * @constant IFNET_LOGCAT_QUALITY Quality/fidelity related issues.
911 * @constant IFNET_LOGCAT_PERFORMANCE Performance related issues.
914 IFNET_LOGCAT_CONNECTIVITY
= 1,
915 IFNET_LOGCAT_QUALITY
= 2,
916 IFNET_LOGCAT_PERFORMANCE
= 3
920 * @typedef ifnet_log_category_t
921 * @abstract Storage type for log category.
923 typedef int32_t ifnet_log_category_t
;
926 * @typedef ifnet_log_subcategory_t
927 * @abstract Storage type for log subcategory. This is largely opaque
928 * and it can be used for IOReturn values, etc.
930 typedef int32_t ifnet_log_subcategory_t
;
933 * @struct ifnet_log_params
934 * @discussion This structure is used as parameter to the ifnet
935 * logging sub-commands.
936 * @field level The logging level/priority.
937 * @field flags The logging flags/facilities.
938 * @field category The category of issue.
939 * @field subcategory The subcategory of issue.
941 struct ifnet_log_params
{
942 ifnet_log_level_t level
;
943 ifnet_log_flags_t flags
;
944 ifnet_log_category_t category
;
945 ifnet_log_subcategory_t subcategory
;
949 * @struct ifnet_notify_address_params
950 * @discussion This structure is used as parameter to the ifnet
951 * address notification sub-command. This is used to indicate
952 * to the family/driver that one or more addresses of the given
953 * address family has been added to, or removed from the list
954 * of addresses on the interface. The driver may query for the
955 * current address list by calling ifnet_get_address_list_family().
956 * @field address_family The address family of the interface address(es).
958 struct ifnet_notify_address_params
{
959 sa_family_t address_family
;
960 u_int32_t reserved
[3];
964 * @typedef ifnet_ctl_func
965 * @discussion ifnet_ctl_func is called by the network stack to inform
966 * about changes in parameters, or retrieve the parameters
967 * related to the output or input processing or capabilities.
968 * @param interface The interface.
969 * @param cmd The ifnet_ctl_cmd_t interface control command.
970 * @param arglen The length of the command argument.
971 * @param arg The command argument.
972 * @result 0 upon success, otherwise errno error.
974 typedef errno_t (*ifnet_ctl_func
)(ifnet_t interface
, ifnet_ctl_cmd_t cmd
,
975 u_int32_t arglen
, void *arg
);
978 * @struct ifnet_init_eparams
979 * @discussion This structure is used to define various properties of
980 * the interface when calling ifnet_allocate_extended. A copy of
981 * these values will be stored in the ifnet and cannot be modified
982 * while the interface is attached.
983 * @field ver The current structure version (IFNET_INIT_CURRENT_VERSION)
984 * @field len The length of this structure.
985 * @field flags See above values for flags.
986 * @field uniqueid An identifier unique to this instance of the
988 * @field uniqueid_len The length, in bytes, of the uniqueid.
989 * @field name The interface name (i.e. en).
990 * @field unit The interface unit number (en0's unit number is 0).
991 * @field family The interface family.
992 * @field type The interface type (see sys/if_types.h). Must be less
993 * than 256. For new types, use IFT_OTHER.
994 * @field sndq_maxlen The maximum size of the output queue; valid only
995 * if IFNET_INIT_LEGACY is not set.
996 * @field output The output function for the interface. Every packet the
997 * stack attempts to send through this interface will go out
998 * through this function.
999 * @field pre_enqueue The pre_enqueue function for the interface, valid
1000 * only if IFNET_INIT_LEGACY is not set, and optional if it is set.
1001 * @field start The start function for the interface, valid and required
1002 * only if IFNET_INIT_LEGACY is not set.
1003 * @field output_ctl The output control function for the interface, valid
1004 * only if IFNET_INIT_LEGACY is not set.
1005 * @field output_sched_model The IFNET_SCHED_MODEL value for the output
1006 * queue, as defined in net/if.h
1007 * @field output_target_qdelay The target queue delay is used for
1008 * dynamically sizing the output queue, valid only if
1009 * IFNET_INIT_LEGACY is not set.
1010 * @field output_bw The effective output bandwidth (in bits per second.)
1011 * @field output_bw_max The maximum theoretical output bandwidth
1012 * (in bits per second.)
1013 * @field output_lt The effective output latency (in nanosecond.)
1014 * @field output_lt_max The maximum theoretical output latency
1016 * @field start_delay_qlen The maximum length of output queue for
1017 * delaying start callback to the driver. This is an
1018 * optimization for coalescing output packets.
1019 * @field start_delay_timeout The timeout in microseconds to delay
1020 * start callback. If start_delay_qlen number of packets are
1021 * not in the output queue when the timer fires, the start
1022 * callback will be invoked. Maximum allowed value is
1023 * 20ms (in microseconds).
1024 * @field input_poll The poll function for the interface, valid only if
1025 * IFNET_INIT_LEGACY is not set and only if IFNET_INIT_INPUT_POLL
1027 * @field input_ctl The input control function for the interface, valid
1028 * only if IFNET_INIT_LEGACY is not set and only if opportunistic
1029 * input polling is enabled via IFNET_INIT_INPUT_POLL flag.
1030 * @field rcvq_maxlen The size of the driver's receive ring or the total
1031 * count of descriptors used in the receive path; valid only if
1032 * IFNET_INIT_INPUT_POLL is set.
1033 * @field input_bw The effective input bandwidth (in bits per second.)
1034 * @field input_bw_max The maximum theoretical input bandwidth
1035 * (in bits per second.)
1036 * @field input_lt The effective input latency (in nanosecond.)
1037 * @field input_lt_max The maximum theoretical input latency
1039 * @field demux The function used to determine the protocol family of an
1041 * @field add_proto The function used to attach a protocol to this
1043 * @field del_proto The function used to remove a protocol from this
1045 * @field framer The function used to frame outbound packets, may be NULL.
1046 * @field framer_extended The function used to frame outbound packets,
1047 * in the newer form; may be NULL. If specified, it will override
1048 * the value set via framer.
1049 * @field softc Driver specific storage. This value can be retrieved from
1050 * the ifnet using the ifnet_softc function.
1051 * @field ioctl The function used to handle ioctls.
1052 * @field set_bpf_tap The function used to set the bpf_tap function.
1053 * @field detach The function called to let the driver know the interface
1054 * has been detached.
1055 * @field event The function to notify the interface of various interface
1056 * specific kernel events.
1057 * @field broadcast_addr The link-layer broadcast address for this
1059 * @field broadcast_len The length of the link-layer broadcast address.
1060 * @field tx_headroom The amount of headroom space to be reserved in the
1061 * packet being transmitted on the interface, specified in bytes.
1062 * Must be a multiple of 8 bytes.
1063 * @field tx_trailer The amount of trailer space to be reserved in the
1064 * packet being transmitted on the interface, specified in bytes.
1065 * @field rx_mit_ival mitigation interval for the rx mitigation logic,
1066 * specified in microseconds.
1068 struct ifnet_init_eparams
{
1069 u_int32_t ver
; /* required */
1070 u_int32_t len
; /* required */
1071 u_int32_t flags
; /* optional */
1073 /* used to match recycled interface */
1074 const void *uniqueid
; /* optional */
1075 u_int32_t uniqueid_len
; /* optional */
1077 /* used to fill out initial values for interface */
1078 const char *name
; /* required */
1079 u_int32_t unit
; /* required */
1080 ifnet_family_t family
; /* required */
1081 u_int32_t type
; /* required */
1082 u_int32_t sndq_maxlen
; /* optional, only for new model */
1083 ifnet_output_func output
; /* required only for legacy model */
1084 ifnet_pre_enqueue_func pre_enqueue
; /* optional, only for new model */
1085 ifnet_start_func start
; /* required only for new model */
1086 ifnet_ctl_func output_ctl
; /* optional, only for new model */
1087 u_int32_t output_sched_model
; /* optional, only for new model */
1088 u_int32_t output_target_qdelay
; /* optional, only for new model, value in ms */
1089 u_int64_t output_bw
; /* optional */
1090 u_int64_t output_bw_max
; /* optional */
1091 u_int64_t output_lt
; /* optional */
1092 u_int64_t output_lt_max
; /* optional */
1093 u_int16_t start_delay_qlen
; /* optional */
1094 u_int16_t start_delay_timeout
; /* optional */
1095 u_int32_t _reserved
[3]; /* for future use */
1096 ifnet_input_poll_func input_poll
; /* optional, ignored for legacy model */
1097 ifnet_ctl_func input_ctl
; /* required for opportunistic polling */
1098 u_int32_t rcvq_maxlen
; /* optional, only for opportunistic polling */
1099 u_int32_t __reserved
; /* for future use */
1100 u_int64_t input_bw
; /* optional */
1101 u_int64_t input_bw_max
; /* optional */
1102 u_int64_t input_lt
; /* optional */
1103 u_int64_t input_lt_max
; /* optional */
1104 u_int64_t ___reserved
[2]; /* for future use */
1105 ifnet_demux_func demux
; /* required */
1106 ifnet_add_proto_func add_proto
; /* required */
1107 ifnet_del_proto_func del_proto
; /* required */
1108 ifnet_check_multi check_multi
; /* required for non point-to-point interfaces */
1109 ifnet_framer_func framer
; /* optional */
1110 void *softc
; /* optional */
1111 ifnet_ioctl_func ioctl
; /* optional */
1112 ifnet_set_bpf_tap set_bpf_tap
; /* deprecated */
1113 ifnet_detached_func detach
; /* optional */
1114 ifnet_event_func event
; /* optional */
1115 const void *broadcast_addr
; /* required for non point-to-point interfaces */
1116 u_int32_t broadcast_len
; /* required for non point-to-point interfaces */
1117 ifnet_framer_extended_func framer_extended
; /* optional */
1118 ifnet_subfamily_t subfamily
; /* optional */
1119 u_int16_t tx_headroom
; /* optional */
1120 u_int16_t tx_trailer
; /* optional */
1121 u_int32_t rx_mit_ival
; /* optional */
1122 #if !defined(__LP64__)
1123 u_int64_t ____reserved
[2]; /* for future use */
1125 u_int32_t ____reserved
; /* for future use */
1126 u_int64_t _____reserved
[1]; /* for future use */
1127 #endif /* __LP64__ */
1129 #endif /* KERNEL_PRIVATE */
1132 * @struct ifnet_stats_param
1133 * @discussion This structure is used get and set the interface
1135 * @field packets_in The number of packets received.
1136 * @field bytes_in The number of bytes received.
1137 * @field errors_in The number of receive errors.
1138 * @field packets_out The number of packets transmitted.
1139 * @field bytes_out The number of bytes transmitted.
1140 * @field errors_out The number of transmission errors.
1141 * @field collisions The number of collisions seen by this interface.
1142 * @field dropped The number of packets dropped.
1144 struct ifnet_stats_param
{
1145 u_int64_t packets_in
;
1147 u_int64_t multicasts_in
;
1148 u_int64_t errors_in
;
1150 u_int64_t packets_out
;
1151 u_int64_t bytes_out
;
1152 u_int64_t multicasts_out
;
1153 u_int64_t errors_out
;
1155 u_int64_t collisions
;
1157 u_int64_t no_protocol
;
1161 * @struct ifnet_demux_desc
1162 * @discussion This structure is to identify packets that belong to a
1163 * specific protocol. The types supported are interface specific.
1164 * Ethernet supports ETHER_DESC_ETYPE2, ETHER_DESC_SAP, and
1165 * ETHER_DESC_SNAP. The type defines the offset in the packet where
1166 * the data will be matched as well as context. For example, if
1167 * ETHER_DESC_SNAP is specified, the only valid datalen is 5 and
1168 * only in the 5 bytes will only be matched when the packet header
1169 * indicates that the packet is a SNAP packet.
1170 * @field type The type of identifier data (i.e. ETHER_DESC_ETYPE2)
1171 * @field data A pointer to an entry of type (i.e. pointer to 0x0800).
1172 * @field datalen The number of bytes of data used to describe the
1175 struct ifnet_demux_desc
{
1182 * @struct ifnet_attach_proto_param
1183 * @discussion This structure is used to attach a protocol to an
1184 * interface. This structure provides the various functions for
1185 * handling operations related to the protocol on the interface as
1186 * well as information for how to demux packets for this protocol.
1187 * @field demux_array An array of ifnet_demux_desc structures
1188 * describing the protocol.
1189 * @field demux_count The number of entries in the demux_array array.
1190 * @field input The function to be called for inbound packets.
1191 * @field pre_output The function to be called for outbound packets.
1192 * @field event The function to be called for interface events.
1193 * @field ioctl The function to be called for ioctls.
1194 * @field detached The function to be called for handling the detach.
1196 #ifdef KERNEL_PRIVATE
1197 #define demux_list demux_array
1198 #endif /* KERNEL_PRIVATE */
1200 struct ifnet_attach_proto_param
{
1201 struct ifnet_demux_desc
*demux_array
; /* interface may/may not require */
1202 u_int32_t demux_count
; /* interface may/may not require */
1204 proto_media_input input
; /* required */
1205 proto_media_preout pre_output
; /* required */
1206 proto_media_event event
; /* optional */
1207 proto_media_ioctl ioctl
; /* optional */
1208 proto_media_detached detached
; /* optional */
1209 proto_media_resolve_multi resolve
; /* optional */
1210 proto_media_send_arp send_arp
; /* optional */
1213 struct ifnet_attach_proto_param_v2
{
1214 struct ifnet_demux_desc
*demux_array
; /* interface may/may not require */
1215 u_int32_t demux_count
; /* interface may/may not require */
1217 proto_media_input_v2 input
; /* required */
1218 proto_media_preout pre_output
; /* required */
1219 proto_media_event event
; /* optional */
1220 proto_media_ioctl ioctl
; /* optional */
1221 proto_media_detached detached
; /* optional */
1222 proto_media_resolve_multi resolve
; /* optional */
1223 proto_media_send_arp send_arp
; /* optional */
1229 * Ifnet creation and reference counting
1233 * @function ifnet_allocate
1234 * @discussion Allocate an ifnet_t with an initial refcount of 1. Many
1235 * parts of the stack do not properly refcount the ifnet_t. In
1236 * order to avoid freeing the ifnet_t while some parts of the stack
1237 * may contain a reference to it, the ifnet_ts are only recycled,
1238 * never freed. A unique id is used to try and recycle the same
1239 * ifnet_t when allocating an interface. For example, for an
1240 * ethernet interface, the hardware address of the ethernet card is
1241 * usually used for the uniqueid. If a PC Card is removed and
1242 * inserted again, if the ethernet address of the PC card is used,
1243 * the same ifnet_t will be used for the card the second time it is
1244 * inserted. In the future, when the ifnet_t is correctly
1245 * refcounted by all of the stack, the interfaces may be freed and
1246 * the unique ids ignored.
1247 * @param init The initial values for the interface. These values can
1248 * not be changed after the interface has been allocated.
1249 * @param interface The interface allocated upon success.
1250 * @result May return ENOMEM if there is insufficient memory or EEXIST
1251 * if an interface with the same uniqueid and family has already
1252 * been allocated and is in use.
1254 #ifdef KERNEL_PRIVATE
1255 extern errno_t
ifnet_allocate_internal(const struct ifnet_init_params
*init
,
1256 ifnet_t
*interface
);
1258 #define ifnet_allocate(init, interface) \
1259 ifnet_allocate_internal((init), (interface))
1261 extern errno_t
ifnet_allocate(const struct ifnet_init_params
*init
,
1262 ifnet_t
*interface
);
1263 #endif /* KERNEL_PRIVATE */
1265 #ifdef KERNEL_PRIVATE
1267 * @function ifnet_allocate_extended
1268 * @discussion An extended/newer variant of ifnet_allocate, with additional
1269 * support for the new output and input driver models.
1270 * @param init The initial values for the interface. These values can
1271 * not be changed after the interface has been allocated.
1272 * @param interface The interface allocated upon success.
1273 * @result May return ENOMEM if there is insufficient memory or EBUSY
1274 * if an interface with the same uniqueid/(name + unit) and family has already
1275 * been allocated and is in use.
1277 extern errno_t
ifnet_allocate_extended(const struct ifnet_init_eparams
*init
,
1278 ifnet_t
*interface
);
1281 * @function ifnet_purge
1282 * @discussion Purge the output queue of an interface which implements
1283 * the new driver output model.
1284 * @param interface The interface to purge.
1286 extern void ifnet_purge(ifnet_t interface
);
1289 * @function ifnet_enqueue
1290 * @discussion Enqueue a packet to the output queue of an interface
1291 * which implements the new driver output model.
1292 * @param interface The interface to enqueue the packet to.
1293 * @param packet The packet being enqueued; only one packet is allowed
1294 * to be enqueued at a time.
1295 * @result May return EINVAL if the parameters are invalid; ENXIO if
1296 * the interface doesn't implement the new driver output model;
1297 * EQFULL if the output queue is flow-controlled; or EQSUSPENDED
1298 * if the output queue is suspended. This routine either frees
1299 * or consumes the packet; the caller must not modify or free
1300 * it after calling this routine. Any attempt to enqueue more
1301 * than one packet will cause the entire packet chain to be freed.
1303 extern errno_t
ifnet_enqueue(ifnet_t interface
, mbuf_t packet
);
1306 * @function ifnet_dequeue
1307 * @discussion Dequeue a packet from the output queue of an interface
1308 * which implements the new driver output model, and that the
1309 * output scheduling model is set to IFNET_SCHED_MODEL_NORMAL.
1310 * @param interface The interface to dequeue the packet from.
1311 * @param packet Pointer to the packet being dequeued.
1312 * @result May return EINVAL if the parameters are invalid, ENXIO if
1313 * the interface doesn't implement the new driver output model
1314 * or the output scheduling model isn't IFNET_SCHED_MODEL_NORMAL,
1315 * or EAGAIN if there is currently no packet available to
1318 extern errno_t
ifnet_dequeue(ifnet_t interface
, mbuf_t
*packet
);
1321 * @function ifnet_dequeue_service_class
1322 * @discussion Dequeue a packet of a particular service class from the
1323 * appropriate output queue of an interface which implements the
1324 * new driver output model, and that the output scheduling model
1325 * is set to IFNET_SCHED_MODEL_DRIVER_MANAGED.
1326 * @param interface The interface to dequeue the packet from.
1327 * @param sc The service class.
1328 * @param packet Pointer to the packet being dequeued.
1329 * @result May return EINVAL if the parameters are invalid, ENXIO if
1330 * the interface doesn't implement the new driver output model
1331 * or if the output scheduling model isn't configured to
1332 * IFNET_SCHED_MODEL_DRIVER_MANAGED, or EAGAIN if there
1333 * is currently no packet available to be dequeued.
1335 extern errno_t
ifnet_dequeue_service_class(ifnet_t interface
,
1336 mbuf_svc_class_t sc
, mbuf_t
*packet
);
1339 * @function ifnet_dequeue_multi
1340 * @discussion Dequeue one or more packets from the output queue of an
1341 * interface which implements the new driver output model, and that
1342 * the output scheduling model is set to IFNET_SCHED_MODEL_NORMAL.
1343 * The returned packet chain is traversable with mbuf_nextpkt().
1344 * @param interface The interface to dequeue the packets from.
1345 * @param max The maximum number of packets in the packet chain that
1346 * may be returned to the caller; this needs to be a non-zero
1347 * value for any packet to be returned.
1348 * @param first_packet Pointer to the first packet being dequeued.
1349 * @param last_packet Pointer to the last packet being dequeued. Caller
1350 * may supply NULL if not interested in value.
1351 * @param cnt Pointer to a storage for the number of packets dequeued.
1352 * Caller may supply NULL if not interested in value.
1353 * @param len Pointer to a storage for the total length (in bytes)
1354 * of the dequeued packets. Caller may supply NULL if not
1355 * interested in value.
1356 * @result May return EINVAL if the parameters are invalid, ENXIO if
1357 * the interface doesn't implement the new driver output model
1358 * or the output scheduling model isn't IFNET_SCHED_MODEL_NORMAL,
1359 * or EAGAIN if there is currently no packet available to
1362 extern errno_t
ifnet_dequeue_multi(ifnet_t interface
, u_int32_t max
,
1363 mbuf_t
*first_packet
, mbuf_t
*last_packet
, u_int32_t
*cnt
, u_int32_t
*len
);
1366 * @function ifnet_dequeue_multi_bytes
1367 * @discussion Dequeue one or more packets from the output queue of
1368 * an interface which implements the new driver output model,
1369 * where the scheduling model is set to
1370 * IFNET_SCHED_MODEL_NORMAL. The limit is specified in terms
1371 * of maximum number of bytes to return. The number of bytes
1372 * returned can be slightly higher than the limit so that
1373 * packet boundaries can be preserved.
1374 * @param interface The interface to dequeue the packets from
1375 * @param max_bytes The maximum number of bytes in the packet chain
1376 * that may be returned to the caller; this needs to be a
1377 * non-zero value for any packet to be returned.
1378 * @param first_packet Pointer to the first packet being dequeued
1379 * @param last_packet Pointer to the last packet being dequeued
1380 * @param cnt Pointer to a storage for the number of bytes dequeued.
1381 * Caller may supply NULL if not interested in this value
1382 * @param len Pointer to a storage for the total length (in bytes)
1383 * of the dequeued packets. Caller may supply NULL if not
1384 * interested in this value.
1385 * @result May return EINVAL if the parameters are invalid, ENXIO if
1386 * the interface doesn't implement the new driver output
1387 * model or the output scheduling model isn't
1388 * IFNET_SCHED_MODEL_NORMAL, or EAGAIN if there is currently
1389 * no packet available to be dequeued
1391 extern errno_t
ifnet_dequeue_multi_bytes(ifnet_t interface
,
1392 u_int32_t max_bytes
, mbuf_t
*first_packet
, mbuf_t
*last_packet
,
1393 u_int32_t
*cnt
, u_int32_t
*len
);
1396 * @function ifnet_dequeue_service_class_multi
1397 * @discussion Dequeue one or more packets of a particular service class
1398 * from the appropriate output queue of an interface which
1399 * implements the new driver output model, and that the output
1400 * scheduling model is set to IFNET_SCHED_MODEL_DRIVER_MANAGED.
1401 * The returned packet chain is traversable with mbuf_nextpkt().
1402 * @param interface The interface to dequeue the packets from.
1403 * @param sc The service class.
1404 * @param max The maximum number of packets in the packet chain that
1405 * may be returned to the caller; this needs to be a non-zero
1406 * value for any packet to be returned.
1407 * @param first_packet Pointer to the first packet being dequeued.
1408 * @param last_packet Pointer to the last packet being dequeued. Caller
1409 * may supply NULL if not interested in value.
1410 * @param cnt Pointer to a storage for the number of packets dequeued.
1411 * Caller may supply NULL if not interested in value.
1412 * @param len Pointer to a storage for the total length (in bytes)
1413 * of the dequeued packets. Caller may supply NULL if not
1414 * interested in value.
1415 * @result May return EINVAL if the parameters are invalid, ENXIO if
1416 * the interface doesn't implement the new driver output model
1417 * or if the output scheduling model isn't configured to
1418 * IFNET_SCHED_MODEL_DRIVER_MANAGED, or EAGAIN if there
1419 * is currently no packet available to be dequeued.
1421 extern errno_t
ifnet_dequeue_service_class_multi(ifnet_t interface
,
1422 mbuf_svc_class_t sc
, u_int32_t max
, mbuf_t
*first_packet
,
1423 mbuf_t
*last_packet
, u_int32_t
*cnt
, u_int32_t
*len
);
1426 * @function ifnet_set_output_sched_model
1427 * @discussion Set the output scheduling model of an interface which
1428 * implements the new driver output model.
1429 * @param interface The interface to set scheduling model on.
1430 * @param model The IFNET_SCHED_MODEL value as defined in net/if.h
1431 * @result May return EINVAL if the parameters are invalid or ENXIO if
1432 * the interface doesn't implement the new driver output model.
1434 extern errno_t
ifnet_set_output_sched_model(ifnet_t interface
,
1438 * @function ifnet_set_sndq_maxlen
1439 * @discussion Set the maximum length of the output queue of an
1440 * interface which implements the new driver output model.
1441 * This call may be issued post ifnet_allocate_extended in
1442 * order to modify the maximum output queue length previously
1443 * set at registration time.
1444 * @param interface The interface to set the max queue length on.
1445 * @param maxqlen The maximum number of packets in the output queue.
1446 * @result May return EINVAL if the parameters are invalid or ENXIO if
1447 * the interface doesn't implement the new driver output model.
1449 extern errno_t
ifnet_set_sndq_maxlen(ifnet_t interface
, u_int32_t maxqlen
);
1452 * @function ifnet_get_sndq_maxlen
1453 * @discussion Get the maximum length of the output queue of an
1454 * interface which implements the new driver output model.
1455 * @param interface The interface to get the max queue length on.
1456 * @param maxqlen Pointer to a storage for the maximum number of packets
1457 * in the output queue for all service classes.
1458 * @result May return EINVAL if the parameters are invalid or ENXIO if
1459 * the interface doesn't implement the new driver output model.
1461 extern errno_t
ifnet_get_sndq_maxlen(ifnet_t interface
, u_int32_t
*maxqlen
);
1464 * @function ifnet_get_sndq_len
1465 * @discussion Get the current length of the output queue of an
1466 * interface which implements the new driver output model.
1467 * @param interface The interface to get the current queue length on.
1468 * @param packets Pointer to a storage for the current number of packets
1469 * in the aggregate output queue. This number represents all
1470 * enqueued packets regardless of their service classes.
1471 * @result May return EINVAL if the parameters are invalid or ENXIO if
1472 * the interface doesn't implement the new driver output model.
1474 extern errno_t
ifnet_get_sndq_len(ifnet_t interface
, u_int32_t
*packets
);
1477 * @function ifnet_get_service_class_sndq_len
1478 * @discussion Get the current length of the output queue for a specific
1479 * service class of an interface which implements the new driver
1481 * @param interface The interface to get the current queue length on.
1482 * @param sc The service class.
1483 * @param packets Pointer to a storage for the current number of packets
1484 * of the specific service class in the output queue; may be
1485 * NULL if caller is not interested in getting the value. Note
1486 * that multiple service classes may be mapped to an output queue;
1487 * this routine reports the packet count of that output queue.
1488 * @param bytes Pointer to a storage for the current size (in bytes) of
1489 * the output queue specific to the service class; may be NULL if
1490 * caller is not interested in getting the value. Note that
1491 * multiple service classes may be mapped to an output queue;
1492 * this routine reports the length of that output queue.
1493 * @result May return EINVAL if the parameters are invalid or ENXIO if
1494 * the interface doesn't implement the new driver output model.
1496 extern errno_t
ifnet_get_service_class_sndq_len(ifnet_t interface
,
1497 mbuf_svc_class_t sc
, u_int32_t
*packets
, u_int32_t
*bytes
);
1500 * @function ifnet_set_rcvq_maxlen
1501 * @discussion Set the maximum length of the input queue of an
1502 * interface which implements the new driver input model.
1503 * This call may be issued post ifnet_allocate_extended in
1504 * order to modify the maximum input queue length previously
1505 * set at registration time.
1506 * @param interface The interface to set the max queue length on.
1507 * @param maxqlen The maximum number of packets in the input queue.
1508 * Drivers typically set this to the size of the receive ring
1509 * or the total number of descriptors used for the input path.
1510 * @result May return EINVAL if the parameters are invalid or ENXIO if
1511 * the interface doesn't implement the new driver input model.
1513 extern errno_t
ifnet_set_rcvq_maxlen(ifnet_t interface
, u_int32_t maxqlen
);
1516 * @function ifnet_get_rcvq_maxlen
1517 * @discussion Get the maximum length of the input queue of an
1518 * interface which implements the new driver input model.
1519 * @param interface The interface to get the max queue length on.
1520 * @param maxqlen Pointer to a storage for the maximum number of packets
1521 * in the input queue.
1522 * @result May return EINVAL if the parameters are invalid or ENXIO if
1523 * the interface doesn't implement the new driver input model.
1525 extern errno_t
ifnet_get_rcvq_maxlen(ifnet_t interface
, u_int32_t
*maxqlen
);
1528 * @struct ifnet_poll_params
1529 * @discussion This structure is used to define various opportunistic
1530 * polling parameters for an interface.
1531 * @field flags Currently unused/ignored; must be set to zero.
1532 * @field packets_limit The maximum number of packets to be dequeued
1533 * each time the driver's input poll callback is invoked while
1534 * in polling mode; this corresponds to the max_count parameter
1535 * of ifnet_input_poll_func. A zero value indicates the use of
1536 * default maximum packets defined by the system.
1537 * @field packets_lowat Low watermark packet threshold.
1538 * @field packets_hiwat High watermark packet threshold.
1539 * @field bytes_lowat Low watermark packet threshold.
1540 * @field bytes_hiwat High watermark packet threshold.
1541 * The low and high watermark inbound packet and bytes thresholds;
1542 * these values may be link rate dependent. Polling is enabled
1543 * when the average inbound packets or bytes goes above the
1544 * corresponding high watermark value; it stays in that mode until
1545 * both of the average inbound packets and bytes go below their
1546 * corresponding low watermark values. Zero watermark values
1547 * indicates the use of default thresholds as defined by the
1548 * system. Both low and high watermark values must either be
1549 * zeroes, or both must be non-zeroes with low watermark value
1550 * being less than the high watermark value.
1551 * @field interval_time The interval time between each invocation of
1552 * the driver's input poll callback, in nanoseconds. A zero
1553 * value indicates the use of default poll interval time as
1554 * defined by the system. If a non-zero value is specified and
1555 * is less than the minimum interval time, the latter will be
1556 * chosen by the system.
1558 struct ifnet_poll_params
{
1560 u_int32_t packets_limit
;
1561 u_int32_t packets_lowat
;
1562 u_int32_t packets_hiwat
;
1563 u_int32_t bytes_lowat
;
1564 u_int32_t bytes_hiwat
;
1565 u_int64_t interval_time
;
1566 u_int64_t reserved
[4];
1569 typedef struct ifnet_poll_params ifnet_poll_params_t
;
1572 * @function ifnet_set_poll_params
1573 * @discussion Configures opportunistic input polling parameters on an
1574 * interface. This call may be issued post ifnet_attach in order
1575 * to modify the interface's polling parameters. The driver may
1576 * alter the default values chosen by the system to achieve the
1577 * optimal performance for a given link rate or driver dynamics.
1578 * @param interface The interface to configure opportunistic polling on.
1579 * @param poll_params Pointer to the polling parameters. If NULL, it
1580 * implies that the system should revert the interface's polling
1581 * parameter to their default values.
1582 * @result May return EINVAL if the parameters are invalid or ENXIO if
1583 * the interface doesn't implement the new driver input model.
1585 extern errno_t
ifnet_set_poll_params(ifnet_t interface
,
1586 ifnet_poll_params_t
*poll_params
);
1589 * @function ifnet_poll_params
1590 * @discussion Retrieves opportunistic input polling parameters on an
1591 * interface. This call may be issued post ifnet_attach in order
1592 * to retrieve the interface's polling parameters.
1593 * @param interface The interface to configure opportunistic polling on.
1594 * @param poll_params Pointer to the polling parameters.
1595 * @result May return EINVAL if the parameters are invalid or ENXIO if
1596 * the interface doesn't implement the new driver input model.
1598 extern errno_t
ifnet_poll_params(ifnet_t interface
,
1599 ifnet_poll_params_t
*poll_params
);
1602 * @function ifnet_start
1603 * @discussion Trigger the transmission at the driver layer on an
1604 * interface which implements the new driver output model.
1605 * @param interface The interface to start the transmission on.
1607 extern void ifnet_start(ifnet_t interface
);
1610 * @function ifnet_flowid
1611 * @discussion Returns the interface flow ID value, which can be used
1612 * by a (virtual) network interface for participating in the
1613 * FLOWSRC_IFNET flow advisory mechanism. The flow ID value
1614 * is available after the interface is attached.
1615 * @param interface The interface to retrieve the flow ID from.
1616 * @param flowid Pointer to the flow ID value.
1617 * @result May return EINVAL if the parameters are invalid or ENXIO if
1618 * the interface doesn't implement the new driver input model.
1620 extern errno_t
ifnet_flowid(ifnet_t interface
, u_int32_t
*flowid
);
1623 * @function ifnet_enable_output
1624 * @discussion Enables output on a (virtual) interface if it has been
1625 * previously disabled via ifnet_disable_output(). This call
1626 * is used to override the flow advisory mechanism typically
1627 * used between a (virtual) network interface and a real network
1628 * interface beneath it. Under normal circumstances, the flow
1629 * advisory mechanism will automatically re-enable the (virtual)
1630 * interface's output mechanism when the real network interface
1631 * is able to transmit more data. Re-enabling output will cause
1632 * the (virtual) interface's start callback to be called again.
1633 * @param interface The interface to enable the transmission on.
1634 * @result May return EINVAL if the parameters are invalid or ENXIO if
1635 * the interface doesn't implement the new driver input model.
1637 extern errno_t
ifnet_enable_output(ifnet_t interface
);
1640 * @function ifnet_disable_output
1641 * @discussion Disables output on a (virtual) interface. Disabling
1642 * output will cause the (virtual) interface's start callback
1643 * to go idle. This call is typically used by a (virtual)
1644 * interface upon receiving flow control feedbacks from the
1645 * real network interface beneath it, in order propagate the
1646 * flow control condition to the layers above. Under normal
1647 * circumstances, the flow advisory mechanism will automatically
1648 * re-enable the (virtual) interface's output mechanism when
1649 * the real network interface is able to transmit more data,
1650 * as long as the (virtual) interface participates in the
1651 * FLOWSRC_IFNET flow advisory for the data that it emits.
1652 * @param interface The interface to disable the transmission on.
1653 * @result May return EINVAL if the parameters are invalid or ENXIO if
1654 * the interface doesn't implement the new driver input model.
1656 extern errno_t
ifnet_disable_output(ifnet_t interface
);
1657 #endif /* KERNEL_PRIVATE */
1660 * @function ifnet_reference
1661 * @discussion Increment the reference count of the ifnet to assure
1662 * that it will not go away. The interface must already have at
1663 * least one reference.
1664 * @param interface The interface to increment the reference count of.
1665 * @result May return EINVAL if the interface is not valid.
1667 extern errno_t
ifnet_reference(ifnet_t interface
);
1670 * @function ifnet_release
1671 * @discussion Release a reference of the ifnet, this may trigger a
1672 * free if the reference count reaches 0.
1673 * @param interface The interface to decrement the reference count of
1674 * and possibly free.
1675 * @result May return EINVAL if the interface is not valid.
1677 extern errno_t
ifnet_release(ifnet_t interface
);
1680 * @function ifnet_attach
1681 * @discussion Attaches an interface to the global interface list. The
1682 * interface must be setup properly before calling attach. The
1683 * stack will take a reference on the interface and hold it until
1684 * ifnet_detach is called.
1686 * This function is intended to be called by the driver. A kext
1687 * must not call this function on an interface the kext does not
1689 * @param interface The interface to attach.
1690 * @param ll_addr The link layer address of the interface. This is used
1691 * to fill out the first ifaddr in the list of addresses for the
1692 * interface. This parameter is not required for interfaces such as
1693 * PPP that have no link-layer address.
1694 * @result Will return an error if there is anything wrong with the
1697 extern errno_t
ifnet_attach(ifnet_t interface
,
1698 const struct sockaddr_dl
*ll_addr
);
1701 * @function ifnet_detach
1702 * @discussion Detaches the interface.
1704 * Call this to indicate this interface is no longer valid (i.e. PC
1705 * Card was removed). This function will begin the process of
1706 * removing knowledge of this interface from the stack.
1708 * The function will return before the interface is detached. The
1709 * functions you supplied in to the interface may continue to be
1710 * called. When the detach has been completed, your detached
1711 * function will be called. Your kext must not unload until the
1712 * detached function has been called. The interface will be
1713 * properly freed when the reference count reaches zero.
1715 * An interface may not be attached again. You must call
1716 * ifnet_allocate to create a new interface to attach.
1718 * This function is intended to be called by the driver. A kext
1719 * must not call this function on an interface the kext does not
1721 * @param interface The interface to detach.
1722 * @result 0 on success, otherwise errno error.
1724 extern errno_t
ifnet_detach(ifnet_t interface
);
1727 * @function ifnet_interface_family_find
1728 * @discussion Look up the interface family identifier for a string.
1729 * If there is no interface family identifier assigned for this string
1730 * a new interface family identifier is created and assigned.
1731 * It is recommended to use the bundle id of the KEXT as the string
1732 * to avoid collisions with other KEXTs.
1733 * The lookup operation is not optimized so a module should call this
1734 * function once during startup and cache the interface family identifier.
1735 * The interface family identifier for a string will not be re-assigned until
1736 * the system reboots.
1737 * @param module_string A unique string identifying your interface family
1738 * @param family_id Upon return, a unique interface family identifier for use with
1739 * ifnet_* functions. This identifier is valid until the system
1741 * @result 0 on success, otherwise errno error.
1743 extern errno_t
ifnet_interface_family_find(const char *module_string
, ifnet_family_t
*family_id
);
1746 * Interface manipulation.
1750 * @function ifnet_softc
1751 * @discussion Returns the driver's private storage on the interface.
1752 * @param interface Interface to retrieve the storage from.
1753 * @result Driver's private storage.
1755 extern void *ifnet_softc(ifnet_t interface
);
1758 * @function ifnet_name
1759 * @discussion Returns a pointer to the name of the interface.
1760 * @param interface Interface to retrieve the name from.
1761 * @result Pointer to the name.
1763 extern const char *ifnet_name(ifnet_t interface
);
1766 * @function ifnet_family
1767 * @discussion Returns the family of the interface.
1768 * @param interface Interface to retrieve the family from.
1769 * @result Interface family type.
1771 extern ifnet_family_t
ifnet_family(ifnet_t interface
);
1773 #ifdef KERNEL_PRIVATE
1775 * @function ifnet_subfamily
1776 * @discussion Returns the sub-family of the interface.
1777 * @param interface Interface to retrieve the sub-family from.
1778 * @result Interface sub-family type.
1780 extern ifnet_subfamily_t
ifnet_subfamily(ifnet_t interface
);
1781 #endif /* KERNEL_PRIVATE */
1784 * @function ifnet_unit
1785 * @discussion Returns the unit number of the interface.
1786 * @param interface Interface to retrieve the unit number from.
1787 * @result Unit number.
1789 extern u_int32_t
ifnet_unit(ifnet_t interface
);
1792 * @function ifnet_index
1793 * @discussion Returns the index of the interface. This index value
1794 * will match the index you would find in a sockaddr_dl or using
1795 * if_nametoindex or if_indextoname in user space. The value of the
1796 * interface index is undefined for an interface that is not
1797 * currently attached.
1798 * @param interface Interface to retrieve the index of.
1801 extern u_int32_t
ifnet_index(ifnet_t interface
);
1804 * @function ifnet_set_flags
1805 * @discussion Sets the interface flags to match new_flags.
1806 * @discussion Sets the interface flags to new_flags. This function
1807 * lets you specify which flags you want to change using the mask.
1808 * The kernel will effectively take the lock, then set the
1809 * interface's flags to (if_flags & ~mask) | (new_flags & mask).
1810 * @param interface Interface to set the flags on.
1811 * @param new_flags The new set of flags that should be set. These
1812 * flags are defined in net/if.h
1813 * @result 0 on success otherwise the errno error.
1815 extern errno_t
ifnet_set_flags(ifnet_t interface
, u_int16_t new_flags
,
1819 * @function ifnet_flags
1820 * @discussion Returns the interface flags that are set.
1821 * @param interface Interface to retrieve the flags from.
1822 * @result Flags. These flags are defined in net/if.h
1824 extern u_int16_t
ifnet_flags(ifnet_t interface
);
1827 #ifdef KERNEL_PRIVATE
1829 * @function ifnet_set_eflags
1830 * @discussion Sets the extended interface flags to new_flags. This
1831 * function lets you specify which flags you want to change using
1832 * the mask. The kernel will effectively take the lock, then set
1833 * the interface's extended flags to (if_eflags & ~mask) |
1834 * (new_flags & mask).
1835 * @param interface The interface.
1836 * @param new_flags The new set of flags that should be set. These
1837 * flags are defined in net/if.h
1838 * @param mask The mask of flags to be modified.
1839 * @result 0 on success otherwise the errno error.
1841 extern errno_t
ifnet_set_eflags(ifnet_t interface
, u_int32_t new_flags
,
1845 * @function ifnet_eflags
1846 * @discussion Returns the extended interface flags that are set.
1847 * @param interface Interface to retrieve the flags from.
1848 * @result Extended flags. These flags are defined in net/if.h
1850 extern u_int32_t
ifnet_eflags(ifnet_t interface
);
1853 * @function ifnet_set_idle_flags
1854 * @discussion Sets the if_idle_flags to new_flags. This function
1855 * lets you specify which flags you want to change using the
1856 * mask. The kernel will effectively take the lock, then set
1857 * the interface's idle flags to:
1858 * (if_idle_flags & ~mask) | (new_flags & mask).
1859 * Setting the flags to any non-zero value will cause the
1860 * networking stack to aggressively purge expired objects,
1861 * such as route entries, etc.
1862 * @param interface The interface.
1863 * @param new_flags The new set of flags that should be set. These
1864 * flags are defined in net/if.h
1865 * @param mask The mask of flags to be modified.
1866 * @result 0 on success otherwise the errno error. ENOTSUP is returned
1867 * when this call is made on non-supporting platforms.
1869 extern errno_t
ifnet_set_idle_flags(ifnet_t interface
, u_int32_t new_flags
,
1873 * @function ifnet_idle_flags
1874 * @discussion Returns the value of if_idle_flags.
1875 * @param interface Interface to retrieve the flags from.
1876 * @result if_idle_flags. These flags are defined in net/if.h
1878 extern u_int32_t
ifnet_idle_flags(ifnet_t interface
);
1881 * @function ifnet_set_link_quality
1882 * @discussion Sets the Link Quality Metric for the ifnet.
1883 * @param interface Interface for which the Link Quality Metric should
1885 * @param quality IFNET_LQM value as defined in net/if.h.
1886 * @result 0 on success otherwise the errno error. EINVAL if quality
1887 * is not a valid value. ENXIO if the interface is not attached.
1889 extern errno_t
ifnet_set_link_quality(ifnet_t interface
, int quality
);
1892 * @function ifnet_link_quality
1893 * @discussion Returns the Link Quality Metric for the ifnet.
1894 * @param interface Interface to retrieve the value from.
1895 * @result IFNET_LQM as defined in net/if.h
1897 extern int ifnet_link_quality(ifnet_t interface
);
1900 * @function ifnet_set_interface_state
1901 * @discussion Sets the interface state for the ifnet.
1902 * @param interface Interface for which the interface state should
1904 * @param if_interface_state as defined in net/if_var.h.
1905 * @result 0 on success otherwise the errno error. EINVAL if quality
1906 * is not a valid value. ENXIO if the interface is not attached.
1908 extern errno_t
ifnet_set_interface_state(ifnet_t interface
,
1909 struct if_interface_state
*if_interface_state
);
1912 * @function ifnet_get_interface_state
1913 * @discussion Returns the interface state for the ifnet.
1914 * @param if_interface_state to ret.
1915 * @result 0 on success, errno otherwise
1917 extern int ifnet_get_interface_state(ifnet_t interface
,
1918 struct if_interface_state
*if_interface_state
);
1921 * @struct ifnet_llreach_info
1922 * @discussion This structure is used to describe the link-layer
1923 * reachability information of an on-link node.
1924 * @field iflri_refcnt The number of network-layer objects referring
1925 * to this link-layer reachability record.
1926 * @field iflri_probes The total number of outstanding probes.
1927 * @field iflri_snd_expire The send expiration time. This is calculated
1928 * based on the last time the system transmitted a packet to the
1929 * node. A zero value indicates that a packet has not been sent
1930 * to the node. A non-zero value indicates the time before the
1931 * record is determined to be invalid. When the record is no
1932 * longer valid, the system will send probe(s) to resolve the
1933 * node again. This value is relative to the current time
1934 * specified in iflri_curtime.
1935 * @field iflri_rcv_expire The receive expiriation time. This is
1936 * calculated based on the last time the system received a packet
1937 * from the node. A zero value indicates that a packet has not
1938 * been received from the node. A non-zero value indicates the
1939 * time before the record is determined to be invalid. When the
1940 * record is no longer valid, the system will send probe(s) to
1941 * resolve the node again. This value is relative to the current
1942 * time specified in iflri_curtime.
1943 * @field iflri_curtime The current time when this record was retrieved.
1944 * @field iflri_netproto The protocol number of the network-layer object.
1945 * @field iflri_addr The link-layer address of the node.
1946 * @field iflri_rssi The received signal strength indication (RSSI) of the
1947 * node in dBm. The special value IFNET_RSSI_UNKNOWN is used when
1948 * the RSSI is either unknown or inapplicable for the interface.
1949 * @field iflri_lqm The link quality metric (LQM) to the node. The
1950 * special value IFNET_LQM_UNKNOWN is used when the LQM is not
1951 * currently known. The special value IFNET_LQM_OFF is used when
1952 * the link quality metric is inapplicable to nodes at this
1953 * attached to the network at this interface.
1954 * @field iflri_npm The node proximity metric (NPM) to the node. The
1955 * special value IFNET_NPM_UNKNOWN is used when the NPM is not
1958 #define IFNET_LLREACHINFO_ADDRLEN 64 /* max ll addr len */
1960 struct ifnet_llreach_info
{
1961 u_int32_t iflri_refcnt
;
1962 u_int32_t iflri_probes
;
1963 u_int64_t iflri_snd_expire
;
1964 u_int64_t iflri_rcv_expire
;
1965 u_int64_t iflri_curtime
;
1966 u_int32_t iflri_netproto
;
1967 u_int8_t iflri_addr
[IFNET_LLREACHINFO_ADDRLEN
];
1974 * @function ifnet_inet_defrouter_llreachinfo
1975 * @discussion Retrieve link-layer reachability information of the
1976 * default IPv4 router specific to the interface.
1977 * @param interface The interface associated with the default IPv4 router.
1978 * @param pinfo Pointer to the ifnet_llreach_info structure where the
1979 * information will be returned to, upon success.
1980 * @result 0 upon success, otherwise errno error.
1982 extern errno_t
ifnet_inet_defrouter_llreachinfo(ifnet_t interface
,
1983 struct ifnet_llreach_info
*pinfo
);
1986 * @function ifnet_inet6_defrouter_llreachinfo
1987 * @discussion Retrieve link-layer reachability information of the
1988 * default IPv6 router specific to the interface.
1989 * @param interface The interface associated with the default IPv6 router.
1990 * @param pinfo Pointer to the ifnet_llreach_info structure where the
1991 * information will be returned to, upon success.
1992 * @result 0 upon success, otherwise errno error.
1994 extern errno_t
ifnet_inet6_defrouter_llreachinfo(ifnet_t interface
,
1995 struct ifnet_llreach_info
*pinfo
);
1996 #endif /* KERNEL_PRIVATE */
1999 * @function ifnet_set_capabilities_supported
2000 * @discussion Specify the capabilities supported by the interface.
2001 * @discussion This function lets you specify which capabilities are supported
2002 * by the interface. Typically this function is called by the driver when
2003 * the interface gets attached to the system.
2004 * The mask allows to control which capability to set or unset.
2005 * The kernel will effectively take the lock, then set the
2006 * interface's flags to (if_capabilities & ~mask) | (new_caps & mask).
2008 * This function is intended to be called by the driver. A kext
2009 * must not call this function on an interface the kext does not
2011 * @param interface Interface to set the capabilities on.
2012 * @param new_caps The value of the capabilities that should be set or unset. These
2013 * flags are defined in net/if.h
2014 * @param mask Which capabilities that should be affected. These
2015 * flags are defined in net/if.h
2016 * @result 0 on success otherwise the errno error.
2018 extern errno_t
ifnet_set_capabilities_supported(ifnet_t interface
, u_int32_t new_caps
,
2022 * @function ifnet_capabilities_supported
2023 * @discussion Retrieve the interface capabilities supported by the interface.
2024 * @param interface Interface to retrieve the capabilities from.
2025 * @result Flags. Capabilities flags are defined in net/if.h
2027 extern u_int32_t
ifnet_capabilities_supported(ifnet_t interface
);
2030 * @function ifnet_set_capabilities_enabled
2031 * @discussion Enable and/or disable the interface capabilities to match new_caps.
2032 * @discussion Sets the interface capabilities to new_caps. This function
2033 * lets you specify which capabilities you want to change using the mask.
2034 * The kernel will effectively take the lock, then set the
2035 * interface's flags to (if_capenable & ~mask) | (new_caps & mask).
2037 * This function is intended to be called by the driver. A kext
2038 * must not call this function on an interface the kext does not
2041 * Typically this function is called by the driver when the interface is
2042 * created to specify which of the supported capabilities are enabled by
2043 * default. This function is also meant to be called when the driver handles
2044 * the interface ioctl SIOCSIFCAP.
2046 * The driver should call ifnet_set_offlad() to indicate the corresponding
2047 * hardware offload bits that will be used by the networking stack.
2049 * It is an error to enable a capability that is not marked as
2050 * supported by the interface.
2051 * @param interface Interface to set the capabilities on.
2052 * @param new_caps The value of the capabilities that should be set or unset. These
2053 * flags are defined in net/if.h
2054 * @param mask Which capabilities that should be affected. These
2055 * flags are defined in net/if.h
2056 * @result 0 on success otherwise the errno error.
2058 extern errno_t
ifnet_set_capabilities_enabled(ifnet_t interface
, u_int32_t new_caps
,
2062 * @function ifnet_capabilities_enabled
2063 * @discussion Retrieve the interface capabilities enabled on the interface.
2064 * @param interface Interface to retrieve the capabilities from.
2065 * @result Flags. Capabilities flags are defined in net/if.h
2067 extern u_int32_t
ifnet_capabilities_enabled(ifnet_t interface
);
2071 * @function ifnet_set_offload
2072 * @discussion Sets a bitfield to indicate special hardware offload
2073 * support provided by the interface such as hardware checksums and
2074 * VLAN. This replaces the if_hwassist flags field. Any flags
2075 * unrecognized by the stack will not be set.
2077 * Note the system will automatically set the interface capabilities
2078 * that correspond to the offload flags modified -- i.e. the driver
2079 * does not have to call ifnet_set_capabilities_enabled() and
2080 * ifnet_set_capabilities_supported().
2081 * @param interface The interface.
2082 * @param offload The new set of flags indicating which offload options
2083 * the device supports.
2084 * @result 0 on success otherwise the errno error.
2086 extern errno_t
ifnet_set_offload(ifnet_t interface
, ifnet_offload_t offload
);
2089 * @function ifnet_offload
2090 * @discussion Returns flags indicating which operations can be
2091 * offloaded to the interface.
2092 * @param interface Interface to retrieve the offload from.
2093 * @result Abilities flags, see ifnet_offload_t.
2095 extern ifnet_offload_t
ifnet_offload(ifnet_t interface
);
2098 * @function ifnet_set_tso_mtu
2099 * @discussion Sets maximum TCP Segmentation Offload segment size for
2101 * @param interface The interface.
2102 * @param family The family for which the offload MTU is provided for
2103 * (AF_INET or AF_INET6)
2104 * @param mtuLen Maximum segment size supported by the interface
2105 * @result 0 on success otherwise the errno error.
2107 extern errno_t
ifnet_set_tso_mtu(ifnet_t interface
, sa_family_t family
,
2111 * @function ifnet_get_tso_mtu
2112 * @discussion Returns maximum TCP Segmentation Offload segment size for
2114 * @param interface The interface.
2115 * @param family The family for which the offload MTU is provided for
2116 * (AF_INET or AF_INET6)
2117 * @param mtuLen Value of the maximum MTU supported for the interface
2118 * and family provided.
2119 * @result 0 on success otherwise the errno error.
2121 extern errno_t
ifnet_get_tso_mtu(ifnet_t interface
, sa_family_t family
,
2125 * @enum Interface wake properties
2126 * @abstract Constants defining Interface wake properties.
2127 * @constant IFNET_WAKE_ON_MAGIC_PACKET Wake on Magic Packet.
2130 IFNET_WAKE_ON_MAGIC_PACKET
= 0x01
2134 * @function ifnet_set_wake_flags
2135 * @discussion Sets the wake properties of the underlying hardware. These are
2136 * typically set by the driver.
2137 * @param interface The interface.
2138 * @param properties Properties to set or unset.
2139 * @param mask Mask of the properties to set of unset.
2140 * @result 0 on success otherwise the errno error.
2142 extern errno_t
ifnet_set_wake_flags(ifnet_t interface
, u_int32_t properties
, u_int32_t mask
);
2145 * @function ifnet_get_wake_flags
2146 * @discussion Returns the wake properties set on the interface.
2147 * @param interface The interface.
2148 * @result The wake properties
2150 extern u_int32_t
ifnet_get_wake_flags(ifnet_t interface
);
2153 * @function ifnet_set_link_mib_data
2154 * @discussion Sets the mib link data. The ifnet_t will store the
2155 * pointer you supply and copy mibLen bytes from the pointer
2156 * whenever the sysctl for getting interface specific MIB data is
2157 * used. Since the ifnet_t stores a pointer to your data instead of
2158 * a copy, you may update the data at the address at any time.
2160 * This function is intended to be called by the driver. A kext
2161 * must not call this function on an interface the kext does not
2163 * @param interface Interface to set the unit number of.
2164 * @param mibData A pointer to the data.
2165 * @param mibLen Length of data pointed to.
2166 * @result 0 on success otherwise the errno error.
2168 extern errno_t
ifnet_set_link_mib_data(ifnet_t interface
, void *mibData
,
2172 * @function ifnet_get_link_mib_data
2173 * @discussion Copies the link MIB data in to mibData, up to mibLen
2174 * bytes. Returns error if the buffer is too small to hold all of
2176 * @param interface The interface.
2177 * @param mibData A pointer to space for the mibData to be copied in
2179 * @param mibLen When calling, this should be the size of the buffer
2180 * passed in mibData. Upon return, this will be the size of data
2181 * copied in to mibData.
2182 * @result Returns an error if the buffer size is too small or there is
2185 extern errno_t
ifnet_get_link_mib_data(ifnet_t interface
, void *mibData
,
2189 * @function ifnet_get_link_mib_data_length
2190 * @discussion Retrieve the size of the mib data.
2191 * @param interface The interface.
2192 * @result Returns the number of bytes of mib data associated with the
2195 extern u_int32_t
ifnet_get_link_mib_data_length(ifnet_t interface
);
2198 * @function ifnet_attach_protocol
2199 * @discussion Attaches a protocol to an interface.
2200 * @param interface The interface.
2201 * @param protocol_family The protocol family being attached
2202 * (PF_INET/PF_INET6/etc...).
2203 * @param proto_details Details of the protocol being attached.
2204 * @result 0 on success otherwise the errno error.
2206 extern errno_t
ifnet_attach_protocol(ifnet_t interface
,
2207 protocol_family_t protocol_family
,
2208 const struct ifnet_attach_proto_param
*proto_details
);
2211 * @function ifnet_attach_protocol_v2
2212 * @discussion Attaches a protocol to an interface using the newer
2213 * version 2 style interface. So far the only difference is support
2214 * for packet chains which improve performance.
2215 * @param interface The interface.
2216 * @param protocol_family The protocol family being attached
2217 * (PF_INET/PF_INET6/etc...).
2218 * @param proto_details Details of the protocol being attached.
2219 * @result 0 on success otherwise the errno error.
2221 extern errno_t
ifnet_attach_protocol_v2(ifnet_t interface
,
2222 protocol_family_t protocol_family
,
2223 const struct ifnet_attach_proto_param_v2
*proto_details
);
2226 * @function ifnet_detach_protocol
2227 * @discussion Detaches a protocol from an interface.
2228 * @param interface The interface.
2229 * @param protocol_family The protocol family of the protocol to
2231 * @result 0 on success otherwise the errno error.
2233 extern errno_t
ifnet_detach_protocol(ifnet_t interface
,
2234 protocol_family_t protocol_family
);
2237 * @function ifnet_output
2238 * @discussion Handles an outbound packet on the interface by calling
2239 * any filters, a protocol preoutput function, the interface framer
2240 * function, and finally the interface's output function. The
2241 * protocol_family will be used to apply protocol filters and
2242 * determine which preoutput function to call. The route and dest
2243 * parameters will be passed to the preoutput function defined for
2244 * the attachment of the specified protocol to the specified
2245 * interface. ifnet_output will always free the mbuf chain.
2246 * @param interface The interface.
2247 * @param protocol_family The family of the protocol generating this
2248 * packet (i.e. AF_INET).
2249 * @param packet The packet to be transmitted.
2250 * @param route A pointer to a routing structure for this packet. The
2251 * preoutput function determines whether this value may be NULL or
2253 * @param dest The destination address of protocol_family type. This
2254 * will be passed to the preoutput function. If the preoutput
2255 * function does not require this value, you may pass NULL.
2256 * @result 0 on success otherwise the errno error.
2258 extern errno_t
ifnet_output(ifnet_t interface
,
2259 protocol_family_t protocol_family
, mbuf_t packet
, void *route
,
2260 const struct sockaddr
*dest
);
2263 * @function ifnet_output_raw
2264 * @discussion Handles and outbond raw packet on the interface by
2265 * calling any filters followed by the interface's output function.
2266 * protocol_family may be zero. If the packet is from a specific
2267 * protocol the protocol_family will be used to apply protocol
2268 * filters. All interface filters will be applied to the outgoing
2269 * packet. Processing, such as calling the protocol preoutput and
2270 * interface framer functions will be bypassed. The packet will
2271 * pass through the filters and be sent on the interface as is.
2272 * ifnet_output_raw will always free the packet chain.
2273 * @param interface The interface.
2274 * @param protocol_family The family of the protocol generating this
2275 * packet (i.e. AF_INET).
2276 * @param packet The fully formed packet to be transmitted.
2277 * @result 0 on success otherwise the errno error.
2279 extern errno_t
ifnet_output_raw(ifnet_t interface
,
2280 protocol_family_t protocol_family
, mbuf_t packet
);
2283 * @function ifnet_input
2284 * @discussion Inputs packets from the interface. The interface's demux
2285 * will be called to determine the protocol. Once the protocol is
2286 * determined, the interface filters and protocol filters will be
2287 * called. From there, the packet will be passed to the registered
2288 * protocol. If there is an error, the mbuf chain will be freed.
2289 * @param interface The interface.
2290 * @param first_packet The first packet in a chain of packets.
2291 * @param stats Counts to be integrated in to the stats. The interface
2292 * statistics will be incremented by the amounts specified in
2293 * stats. This parameter may be NULL.
2294 * @result 0 on success otherwise the errno error.
2296 extern errno_t
ifnet_input(ifnet_t interface
, mbuf_t first_packet
,
2297 const struct ifnet_stat_increment_param
*stats
);
2299 #ifdef KERNEL_PRIVATE
2301 * @function ifnet_input_extended
2302 * @discussion Inputs packets from the interface. The interface's demux
2303 * will be called to determine the protocol. Once the protocol is
2304 * determined, the interface filters and protocol filters will be
2305 * called. From there, the packet will be passed to the registered
2306 * protocol. If there is an error, the mbuf chain will be freed.
2307 * @param interface The interface.
2308 * @param first_packet The first packet in a chain of packets.
2309 * @param last_packet The last packet in a chain of packets. This may be
2310 * set to NULL if the driver does not have the information.
2311 * @param stats Counts to be integrated in to the stats. The interface
2312 * statistics will be incremented by the amounts specified in
2313 * stats. Unlike ifnet_input(), this parameter is required by
2314 * this extended variant.
2315 * @result 0 on success otherwise the errno error.
2317 extern errno_t
ifnet_input_extended(ifnet_t interface
, mbuf_t first_packet
,
2318 mbuf_t last_packet
, const struct ifnet_stat_increment_param
*stats
);
2319 #endif /* KERNEL_PRIVATE */
2322 * @function ifnet_ioctl
2323 * @discussion Calls the interface's ioctl function with the parameters
2326 * All undefined ioctls are reserved for future use by Apple. If
2327 * you need to communicate with your kext using an ioctl, please
2328 * use SIOCSIFKPI and SIOCGIFKPI.
2329 * @param interface The interface.
2330 * @param protocol The protocol family of the protocol to send the
2331 * ioctl to (may be zero). Some ioctls apply to a protocol while
2332 * other ioctls apply to just an interface.
2333 * @param ioctl_code The ioctl to perform.
2334 * @param ioctl_arg Any parameters to the ioctl.
2335 * @result 0 on success otherwise the errno error.
2337 extern errno_t
ifnet_ioctl(ifnet_t interface
, protocol_family_t protocol
,
2338 unsigned long ioctl_code
, void *ioctl_arg
);
2341 * @function ifnet_event
2342 * @discussion Calls the interface's event function.
2343 * @param interface The interface.
2344 * @param event_ptr Pointer to an kern_event structure describing the
2346 * @result 0 on success otherwise the errno error.
2348 extern errno_t
ifnet_event(ifnet_t interface
, struct kern_event_msg
*event_ptr
);
2351 * @function ifnet_set_mtu
2352 * @discussion Sets the value of the MTU in the interface structure.
2353 * Calling this function will not notify the driver that the MTU
2354 * should be changed. Use the appropriate ioctl.
2356 * This function is intended to be called by the driver. A kext
2357 * must not call this function on an interface the kext does not
2359 * @param interface The interface.
2360 * @param mtu The new MTU.
2361 * @result 0 on success otherwise the errno error.
2363 extern errno_t
ifnet_set_mtu(ifnet_t interface
, u_int32_t mtu
);
2366 * @function ifnet_mtu
2367 * @param interface The interface.
2370 extern u_int32_t
ifnet_mtu(ifnet_t interface
);
2373 * @function ifnet_type
2374 * @param interface The interface.
2375 * @result The type. See net/if_types.h.
2377 extern u_int8_t
ifnet_type(ifnet_t interface
);
2380 * @function ifnet_set_addrlen
2382 * This function is intended to be called by the driver. A kext
2383 * must not call this function on an interface the kext does not
2385 * @param interface The interface.
2386 * @param addrlen The new address length.
2387 * @result 0 on success otherwise the errno error.
2389 extern errno_t
ifnet_set_addrlen(ifnet_t interface
, u_int8_t addrlen
);
2392 * @function ifnet_addrlen
2393 * @param interface The interface.
2394 * @result The address length.
2396 extern u_int8_t
ifnet_addrlen(ifnet_t interface
);
2399 * @function ifnet_set_hdrlen
2401 * This function is intended to be called by the driver. A kext
2402 * must not call this function on an interface the kext does not
2404 * @param interface The interface.
2405 * @param hdrlen The new header length.
2406 * @result 0 on success otherwise the errno error.
2408 extern errno_t
ifnet_set_hdrlen(ifnet_t interface
, u_int8_t hdrlen
);
2411 * @function ifnet_hdrlen
2412 * @param interface The interface.
2413 * @result The header length.
2415 extern u_int8_t
ifnet_hdrlen(ifnet_t interface
);
2418 * @function ifnet_set_metric
2420 * This function is intended to be called by the driver. A kext
2421 * must not call this function on an interface the kext does not
2423 * @param interface The interface.
2424 * @param metric The new metric.
2425 * @result 0 on success otherwise the errno error.
2427 extern errno_t
ifnet_set_metric(ifnet_t interface
, u_int32_t metric
);
2430 * @function ifnet_metric
2431 * @param interface The interface.
2432 * @result The metric.
2434 extern u_int32_t
ifnet_metric(ifnet_t interface
);
2437 * @function ifnet_set_baudrate
2439 * This function is intended to be called by the driver. A kext
2440 * must not call this function on an interface the kext does not
2442 * @param interface The interface.
2443 * @param baudrate The new baudrate.
2444 * @result 0 on success otherwise the errno error.
2446 extern errno_t
ifnet_set_baudrate(ifnet_t interface
, u_int64_t baudrate
);
2449 * @function ifnet_baudrate
2450 * @param interface The interface.
2451 * @result The baudrate.
2453 extern u_int64_t
ifnet_baudrate(ifnet_t interface
);
2455 #ifdef KERNEL_PRIVATE
2456 typedef struct if_bandwidths if_bandwidths_t
;
2459 * @function ifnet_set_bandwidths
2460 * @discussion This function allows a driver to indicate the output
2461 * and/or input bandwidth information to the system. Each set
2462 * is comprised of the effective and maximum theoretical values.
2463 * Each value must be greater than zero.
2464 * @param interface The interface.
2465 * @param output_bw The output bandwidth values (in bits per second).
2466 * May be set to NULL if the caller does not want to alter the
2467 * existing output bandwidth values.
2468 * @param input_bw The input bandwidth values (in bits per second).
2469 * May be set to NULL if the caller does not want to alter the
2470 * existing input bandwidth values.
2471 * @result 0 on success otherwise the errno error.
2473 extern errno_t
ifnet_set_bandwidths(ifnet_t interface
,
2474 if_bandwidths_t
*output_bw
, if_bandwidths_t
*input_bw
);
2477 * @function ifnet_bandwidths
2478 * @param interface The interface.
2479 * @param output_bw The output bandwidth values (in bits per second).
2480 * May be set to NULL if the caller does not want to retrieve the
2481 * output bandwidth value.
2482 * @param input_bw The input bandwidth values (in bits per second).
2483 * May be set to NULL if the caller does not want to retrieve the
2484 * input bandwidth value.
2485 * @result 0 on success otherwise the errno error.
2487 extern errno_t
ifnet_bandwidths(ifnet_t interface
, if_bandwidths_t
*output_bw
,
2488 if_bandwidths_t
*input_bw
);
2490 typedef struct if_latencies if_latencies_t
;
2493 * @function ifnet_set_latencies
2494 * @discussion This function allows a driver to indicate the output
2495 * and/or input latency information to the system. Each set
2496 * is comprised of the effective and maximum theoretical values.
2497 * Each value must be greater than zero.
2498 * @param interface The interface.
2499 * @param output_lt The output latency values (in nanosecond).
2500 * May be set to NULL if the caller does not want to alter the
2501 * existing output latency values.
2502 * @param input_lt The input latency values (in nanosecond).
2503 * May be set to NULL if the caller does not want to alter the
2504 * existing input latency values.
2505 * @result 0 on success otherwise the errno error.
2507 extern errno_t
ifnet_set_latencies(ifnet_t interface
,
2508 if_latencies_t
*output_lt
, if_latencies_t
*input_lt
);
2511 * @function ifnet_latencies
2512 * @param interface The interface.
2513 * @param output_lt The output latency values (in nanosecond).
2514 * May be set to NULL if the caller does not want to retrieve the
2515 * output latency value.
2516 * @param input_lt The input latency values (in nanosecond).
2517 * May be set to NULL if the caller does not want to retrieve the
2518 * input latency value.
2519 * @result 0 on success otherwise the errno error.
2521 extern errno_t
ifnet_latencies(ifnet_t interface
, if_latencies_t
*output_lt
,
2522 if_latencies_t
*input_lt
);
2523 #endif /* KERNEL_PRIVATE */
2526 * @function ifnet_stat_increment
2528 * This function is intended to be called by the driver. A kext
2529 * must not call this function on an interface the kext does not
2531 * @param interface The interface.
2532 * @param counts A pointer to a structure containing the amount to
2533 * increment each counter by. Any counts not appearing in the
2534 * ifnet_counter_increment structure are handled in the stack.
2535 * @result 0 on success otherwise the errno error.
2537 extern errno_t
ifnet_stat_increment(ifnet_t interface
,
2538 const struct ifnet_stat_increment_param
*counts
);
2541 * @function ifnet_stat_increment_in
2543 * This function is intended to be called by the driver. This
2544 * function allows a driver to update the inbound interface counts.
2545 * The most efficient time to update these counts is when calling
2548 * A lock protects the counts, this makes the increment functions
2549 * expensive. The increment function will update the lastchanged
2551 * @param interface The interface.
2552 * @param packets_in The number of additional packets received.
2553 * @param bytes_in The number of additional bytes received.
2554 * @param errors_in The number of additional receive errors.
2555 * @result 0 on success otherwise the errno error.
2557 extern errno_t
ifnet_stat_increment_in(ifnet_t interface
,
2558 u_int32_t packets_in
, u_int32_t bytes_in
, u_int32_t errors_in
);
2561 * @function ifnet_stat_increment_out
2563 * This function is intended to be called by the driver. This
2564 * function allows a driver to update the outbound interface
2567 * A lock protects the counts, this makes the increment functions
2568 * expensive. The increment function will update the lastchanged
2570 * @param interface The interface.
2571 * @param packets_out The number of additional packets sent.
2572 * @param bytes_out The number of additional bytes sent.
2573 * @param errors_out The number of additional send errors.
2574 * @result 0 on success otherwise the errno error.
2576 extern errno_t
ifnet_stat_increment_out(ifnet_t interface
,
2577 u_int32_t packets_out
, u_int32_t bytes_out
, u_int32_t errors_out
);
2580 * @function ifnet_set_stat
2582 * This function is intended to be called by the driver. A kext
2583 * must not call this function on an interface the kext does not
2586 * The one exception would be the case where a kext wants to zero
2587 * all of the counters.
2588 * @param interface The interface.
2589 * @param stats The new stats values.
2590 * @result 0 on success otherwise the errno error.
2592 extern errno_t
ifnet_set_stat(ifnet_t interface
,
2593 const struct ifnet_stats_param
*stats
);
2596 * @function ifnet_stat
2597 * @param interface The interface.
2598 * @param out_stats Storage for the values.
2599 * @result 0 on success otherwise the errno error.
2601 extern errno_t
ifnet_stat(ifnet_t interface
,
2602 struct ifnet_stats_param
*out_stats
);
2605 * @function ifnet_set_promiscuous
2606 * @discussion Enable or disable promiscuous mode on the interface. The
2607 * interface keeps an internal count of the number of times
2608 * promiscuous mode has been enabled. Promiscuous mode is only
2609 * disabled when this count reaches zero. Be sure to disable
2610 * promiscuous mode only once for every time you enable it.
2611 * @param interface The interface to toggle promiscuous mode on.
2612 * @param on If set, the number of promicuous on requests will be
2613 * incremented. If this is the first requrest, promiscuous mode
2614 * will be enabled. If this is not set, the number of promiscous
2615 * clients will be decremented. If this causes the number to reach
2616 * zero, promiscuous mode will be disabled.
2617 * @result 0 on success otherwise the errno error.
2619 extern errno_t
ifnet_set_promiscuous(ifnet_t interface
, int on
);
2622 * @function ifnet_touch_lastchange
2623 * @discussion Updates the lastchange value to now.
2624 * @param interface The interface.
2625 * @result 0 on success otherwise the errno error.
2627 extern errno_t
ifnet_touch_lastchange(ifnet_t interface
);
2630 * @function ifnet_lastchange
2631 * @param interface The interface.
2632 * @param last_change A timeval struct to copy the last time changed in
2635 extern errno_t
ifnet_lastchange(ifnet_t interface
, struct timeval
*last_change
);
2638 * @function ifnet_get_address_list
2639 * @discussion Get a list of addresses on the interface. Passing NULL
2640 * for the interface will return a list of all addresses. The
2641 * addresses will have their reference count bumped so they will
2642 * not go away. Calling ifnet_free_address_list will decrement the
2643 * refcount and free the array. If you wish to hold on to a
2644 * reference to an ifaddr_t, be sure to bump the reference count
2645 * before calling ifnet_free_address_list.
2646 * @param interface The interface.
2647 * @param addresses A pointer to a NULL terminated array of ifaddr_ts.
2648 * @result 0 on success otherwise the errno error.
2650 extern errno_t
ifnet_get_address_list(ifnet_t interface
, ifaddr_t
**addresses
);
2653 * @function ifnet_get_address_list_family
2654 * @discussion Get a list of addresses on the interface. Passing NULL
2655 * for the interface will return a list of all addresses. The
2656 * addresses will have their reference count bumped so they will
2657 * not go away. Calling ifnet_free_address_list will decrement the
2658 * refcount and free the array. If you wish to hold on to a
2659 * reference to an ifaddr_t, be sure to bump the reference count
2660 * before calling ifnet_free_address_list. Unlike
2661 * ifnet_get_address_list, this function lets the caller specify
2662 * the address family to get a list of only a specific address type.
2663 * @param interface The interface.
2664 * @param addresses A pointer to a NULL terminated array of ifaddr_ts.
2665 * @result 0 on success otherwise the errno error.
2667 extern errno_t
ifnet_get_address_list_family(ifnet_t interface
,
2668 ifaddr_t
**addresses
, sa_family_t family
);
2670 #ifdef KERNEL_PRIVATE
2672 * @function ifnet_get_inuse_address_list
2673 * @discussion Get a list of addresses on the interface that are in
2674 * use by atleast one TCP or UDP socket. The rest of the API is similar
2675 * to ifnet_get_address_list. Calling ifnet_free_address_list will
2676 * free the array of addresses. Note this only gives a point in time
2677 * snapshot of the addresses in use.
2678 * @param interface The interface
2679 * @param addresses A pointer to a NULL terminated array of ifaddr_ts
2680 * @result 0 on success otherwise the errno error.
2682 extern errno_t
ifnet_get_inuse_address_list(ifnet_t interface
,
2683 ifaddr_t
**addresses
);
2685 __private_extern__ errno_t
ifnet_get_address_list_family_internal(ifnet_t
,
2686 ifaddr_t
**, sa_family_t
, int, int, int);
2687 #endif /* KERNEL_PRIVATE */
2690 * @function ifnet_free_address_list
2691 * @discussion Free a list of addresses returned from
2692 * ifnet_get_address_list. Decrements the refcounts and frees the
2693 * memory used for the array of references.
2694 * @param addresses An array of ifaddr_ts.
2696 extern void ifnet_free_address_list(ifaddr_t
*addresses
);
2699 * @function ifnet_set_lladdr
2700 * @discussion Sets the link-layer address for this interface.
2701 * @param interface The interface the link layer address is being
2703 * @param lladdr A pointer to the raw link layer address (pointer to
2704 * the 6 byte ethernet address for ethernet).
2705 * @param lladdr_len The length, in bytes, of the link layer address.
2707 extern errno_t
ifnet_set_lladdr(ifnet_t interface
, const void *lladdr
,
2711 * @function ifnet_lladdr_copy_bytes
2712 * @discussion Copies the bytes of the link-layer address into the
2714 * @param interface The interface to copy the link-layer address from.
2715 * @param lladdr The buffer to copy the link-layer address in to.
2716 * @param length The length of the buffer. This value must match the
2717 * length of the link-layer address.
2719 extern errno_t
ifnet_lladdr_copy_bytes(ifnet_t interface
, void *lladdr
,
2722 #ifdef KERNEL_PRIVATE
2724 * @function ifnet_guarded_lladdr_copy_bytes
2725 * @discussion Copies the bytes of the link-layer address into the
2726 * specified buffer unless the current process is a sandboxed
2727 * application without the net.link.addr system info privilege.
2728 * @param interface The interface to copy the link-layer address from.
2729 * @param lladdr The buffer to copy the link-layer address in to.
2730 * @param length The length of the buffer. This value must match the
2731 * length of the link-layer address.
2733 extern errno_t
ifnet_guarded_lladdr_copy_bytes(ifnet_t interface
, void *lladdr
,
2737 * @function ifnet_lladdr
2738 * @discussion Returns a pointer to the link-layer address.
2739 * @param interface The interface the link-layer address is on.
2741 extern void *ifnet_lladdr(ifnet_t interface
);
2742 #endif /* KERNEL_PRIVATE */
2745 * @function ifnet_llbroadcast_copy_bytes
2746 * @discussion Retrieves the link-layer broadcast address for this
2748 * @param interface The interface.
2749 * @param addr A buffer to copy the broadcast address in to.
2750 * @param bufferlen The length of the buffer at addr.
2751 * @param out_len On return, the length of the broadcast address.
2753 extern errno_t
ifnet_llbroadcast_copy_bytes(ifnet_t interface
, void *addr
,
2754 size_t bufferlen
, size_t *out_len
);
2756 #ifdef KERNEL_PRIVATE
2758 * @function ifnet_set_lladdr_and_type
2759 * @discussion Sets the link-layer address as well as the type field in
2760 * the sockaddr_dl. Support for setting the type was added for vlan
2761 * and bond interfaces.
2762 * @param interface The interface the link layer address is being
2764 * @param lladdr A pointer to the raw link layer address (pointer to
2765 * the 6 byte ethernet address for ethernet).
2766 * @param length The length, in bytes, of the link layer address.
2767 * @param type The link-layer address type.
2769 extern errno_t
ifnet_set_lladdr_and_type(ifnet_t interface
, const void *lladdr
,
2770 size_t length
, u_char type
);
2771 #endif /* KERNEL_PRIVATE */
2774 * @function ifnet_resolve_multicast
2775 * @discussion Resolves a multicast address for an attached protocol to
2776 * a link-layer address. If a link-layer address is passed in, the
2777 * interface will verify that it is a valid multicast address.
2778 * @param ifp The interface.
2779 * @param proto_addr A protocol address to be converted to a link-layer
2781 * @param ll_addr Storage for the resulting link-layer address.
2782 * @param ll_len Length of the storage for the link-layer address.
2783 * @result 0 on success. EOPNOTSUPP indicates the multicast address was
2784 * not supported or could not be translated. Other errors may
2785 * indicate other failures.
2787 extern errno_t
ifnet_resolve_multicast(ifnet_t ifp
,
2788 const struct sockaddr
*proto_addr
, struct sockaddr
*ll_addr
, size_t ll_len
);
2791 * @function ifnet_add_multicast
2792 * @discussion Joins a multicast and returns an ifmultiaddr_t with the
2793 * reference count incremented for you. You are responsible for
2794 * decrementing the reference count after calling
2795 * ifnet_remove_multicast and making sure you no longer have any
2796 * references to the multicast.
2797 * @param interface The interface.
2798 * @param maddr The multicast address (AF_UNSPEC/AF_LINK) to join. Either
2799 * a physical address or logical address to be translated to a
2801 * @param multicast The resulting ifmultiaddr_t multicast address.
2802 * @result 0 on success otherwise the errno error.
2804 extern errno_t
ifnet_add_multicast(ifnet_t interface
,
2805 const struct sockaddr
*maddr
, ifmultiaddr_t
*multicast
);
2808 * @function ifnet_remove_multicast
2809 * @discussion Causes the interface to leave the multicast group. The
2810 * stack keeps track of how many times ifnet_add_multicast has been
2811 * called for a given multicast address. The multicast will only be
2812 * removed when the number of times ifnet_remove_multicast has been
2813 * called matches the number of times ifnet_add_multicast has been
2816 * The memory for the multicast address is not actually freed until
2817 * the separate reference count has reached zero. Some parts of the
2818 * stack may keep a pointer to the multicast even after that
2819 * multicast has been removed from the interface.
2821 * When an interface is detached, all of the multicasts are
2822 * removed. If the interface of the multicast passed in is no
2823 * longer attached, this function will gracefully return,
2824 * performing no work.
2826 * It is the callers responsibility to release the multicast
2827 * address after calling this function.
2828 * @param multicast The multicast to be removed.
2829 * @result 0 on success otherwise the errno error.
2831 extern errno_t
ifnet_remove_multicast(ifmultiaddr_t multicast
);
2834 * @function ifnet_get_multicast_list
2835 * @discussion Retrieves a list of multicast address the interface is
2836 * set to receive. This function allocates and returns an array of
2837 * references to the various multicast addresses. The multicasts
2838 * have their reference counts bumped on your behalf. Calling
2839 * ifnet_free_multicast_list will decrement the reference counts
2840 * and free the array.
2841 * @param interface The interface.
2842 * @param addresses A pointer to a NULL terminated array of references
2843 * to the multicast addresses.
2844 * @result 0 on success otherwise the errno error.
2846 extern errno_t
ifnet_get_multicast_list(ifnet_t interface
,
2847 ifmultiaddr_t
**addresses
);
2850 * @function ifnet_free_multicast_list
2851 * @discussion Frees a list of multicasts returned by
2852 * ifnet_get_multicast_list. Decrements the refcount on each
2853 * multicast address and frees the array.
2854 * @param multicasts An array of references to the multicast addresses.
2856 extern void ifnet_free_multicast_list(ifmultiaddr_t
*multicasts
);
2859 * @function ifnet_find_by_name
2860 * @discussion Find an interface by the name including the unit number.
2861 * Caller must call ifnet_release on any non-null interface return
2863 * @param ifname The name of the interface, including any unit number
2865 * @param interface A pointer to an interface reference. This will be
2866 * filled in if a matching interface is found.
2867 * @result 0 on success otherwise the errno error.
2869 extern errno_t
ifnet_find_by_name(const char *ifname
, ifnet_t
*interface
);
2872 * @function ifnet_list_get
2873 * @discussion Get a list of attached interfaces. List will be set to
2874 * point to an array allocated by ifnet_list_get. The interfaces
2875 * are refcounted and the counts will be incremented before the
2876 * function returns. The list of interfaces must be freed using
2878 * @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To
2879 * find interfaces of all families, use IFNET_FAMILY_ANY.
2880 * @param interfaces A pointer to an array of interface references.
2881 * @param count A pointer that will be filled in with the number of
2882 * matching interfaces in the array.
2883 * @result 0 on success otherwise the errno error.
2885 extern errno_t
ifnet_list_get(ifnet_family_t family
, ifnet_t
**interfaces
,
2888 #ifdef KERNEL_PRIVATE
2890 * @function ifnet_list_get_all
2891 * @discussion Get a list of attached interfaces. List will be set to
2892 * point to an array allocated by ifnet_list_get. The interfaces
2893 * are refcounted and the counts will be incremented before the
2894 * function returns. The list of interfaces must be freed using
2895 * ifnet_list_free. This is similar to ifnet_list_get, except
2896 * that it includes interfaces that are detaching.
2897 * @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To
2898 * find interfaces of all families, use IFNET_FAMILY_ANY.
2899 * @param interfaces A pointer to an array of interface references.
2900 * @param count A pointer that will be filled in with the number of
2901 * matching interfaces in the array.
2902 * @result 0 on success otherwise the errno error.
2904 extern errno_t
ifnet_list_get_all(ifnet_family_t family
, ifnet_t
**interfaces
,
2906 #endif /* KERNEL_PRIVATE */
2909 * @function ifnet_list_free
2910 * @discussion Free a list of interfaces returned by ifnet_list_get.
2911 * Decrements the reference count on each interface and frees the
2912 * array of references. If you keep a reference to an interface, be
2913 * sure to increment the reference count before calling
2915 * @param interfaces An array of interface references from ifnet_list_get.
2917 extern void ifnet_list_free(ifnet_t
*interfaces
);
2919 /******************************************************************************/
2920 /* ifaddr_t accessors */
2921 /******************************************************************************/
2924 * @function ifaddr_reference
2925 * @discussion Increment the reference count of an address tied to an
2927 * @param ifaddr The interface address.
2928 * @result 0 upon success
2930 extern errno_t
ifaddr_reference(ifaddr_t ifaddr
);
2933 * @function ifaddr_release
2934 * @discussion Decrements the reference count of and possibly frees an
2935 * address tied to an interface.
2936 * @param ifaddr The interface address.
2937 * @result 0 upon success
2939 extern errno_t
ifaddr_release(ifaddr_t ifaddr
);
2942 * @function ifaddr_address
2943 * @discussion Copies the address out of the ifaddr.
2944 * @param ifaddr The interface address.
2945 * @param out_addr The sockaddr storage for the address.
2946 * @param addr_size The size of the storage for the address.
2947 * @result 0 upon success
2949 extern errno_t
ifaddr_address(ifaddr_t ifaddr
, struct sockaddr
*out_addr
,
2950 u_int32_t addr_size
);
2953 * @function ifaddr_address
2954 * @discussion Returns the address family of the address.
2955 * @param ifaddr The interface address.
2956 * @result 0 on failure, address family on success.
2958 extern sa_family_t
ifaddr_address_family(ifaddr_t ifaddr
);
2961 * @function ifaddr_dstaddress
2962 * @discussion Copies the destination address out of the ifaddr.
2963 * @param ifaddr The interface address.
2964 * @param out_dstaddr The sockaddr storage for the destination address.
2965 * @param dstaddr_size The size of the storage for the destination address.
2966 * @result 0 upon success
2968 extern errno_t
ifaddr_dstaddress(ifaddr_t ifaddr
, struct sockaddr
*out_dstaddr
,
2969 u_int32_t dstaddr_size
);
2972 * @function ifaddr_netmask
2973 * @discussion Copies the netmask out of the ifaddr.
2974 * @param ifaddr The interface address.
2975 * @param out_netmask The sockaddr storage for the netmask.
2976 * @param netmask_size The size of the storage for the netmask.
2977 * @result 0 upon success
2979 extern errno_t
ifaddr_netmask(ifaddr_t ifaddr
, struct sockaddr
*out_netmask
,
2980 u_int32_t netmask_size
);
2983 * @function ifaddr_ifnet
2984 * @discussion Returns the interface the address is attached to. The
2985 * reference is only valid until the ifaddr is released. If you
2986 * need to hold a reference to the ifnet for longer than you hold a
2987 * reference to the ifaddr, increment the reference using
2989 * @param ifaddr The interface address.
2990 * @result A reference to the interface the address is attached to.
2992 extern ifnet_t
ifaddr_ifnet(ifaddr_t ifaddr
);
2995 * @function ifaddr_withaddr
2996 * @discussion Returns an interface address with the address specified.
2997 * Increments the reference count on the ifaddr before returning to
2998 * the caller. Caller is responsible for calling ifaddr_release.
2999 * @param address The address to search for.
3000 * @result A reference to the interface address.
3002 extern ifaddr_t
ifaddr_withaddr(const struct sockaddr
*address
);
3005 * @function ifaddr_withdstaddr
3006 * @discussion Returns an interface address for the interface address
3007 * that matches the destination when the netmask is applied.
3008 * Increments the reference count on the ifaddr before returning to
3009 * the caller. Caller is responsible for calling ifaddr_release.
3010 * @param destination The destination to search for.
3011 * @result A reference to the interface address.
3013 extern ifaddr_t
ifaddr_withdstaddr(const struct sockaddr
*destination
);
3016 * @function ifaddr_withnet
3017 * @discussion Returns an interface address for the interface with the
3018 * network described by net. Increments the reference count on the
3019 * ifaddr before returning to the caller. Caller is responsible for
3020 * calling ifaddr_release.
3021 * @param net The network to search for.
3022 * @result A reference to the interface address.
3024 extern ifaddr_t
ifaddr_withnet(const struct sockaddr
*net
);
3027 * @function ifaddr_withroute
3028 * @discussion Returns an interface address given a destination and
3029 * gateway. Increments the reference count on the ifaddr before
3030 * returning to the caller. Caller is responsible for calling
3032 * @param flags Routing flags. See net/route.h, RTF_GATEWAY etc.
3033 * @param destination The destination to search for.
3034 * @param gateway A gateway to search for.
3035 * @result A reference to the interface address.
3037 extern ifaddr_t
ifaddr_withroute(int flags
, const struct sockaddr
*destination
,
3038 const struct sockaddr
*gateway
);
3041 * @function ifaddr_findbestforaddr
3042 * @discussion Finds the best local address assigned to a specific
3043 * interface to use when communicating with another address.
3044 * Increments the reference count on the ifaddr before returning to
3045 * the caller. Caller is responsible for calling ifaddr_release.
3046 * @param addr The remote address.
3047 * @param interface The local interface.
3048 * @result A reference to the interface address.
3050 extern ifaddr_t
ifaddr_findbestforaddr(const struct sockaddr
*addr
,
3053 /******************************************************************************/
3054 /* ifmultiaddr_t accessors */
3055 /******************************************************************************/
3058 * @function ifmaddr_reference
3059 * @discussion Increment the reference count of an interface multicast
3061 * @param ifmaddr The interface multicast address.
3062 * @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
3064 extern errno_t
ifmaddr_reference(ifmultiaddr_t ifmaddr
);
3067 * @function ifmaddr_release
3068 * @discussion Decrement the reference count of an interface multicast
3069 * address. If the reference count reaches zero, the ifmultiaddr
3070 * will be removed from the interface and the ifmultiaddr will be
3072 * @param ifmaddr The interface multicast address.
3073 * @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
3075 extern errno_t
ifmaddr_release(ifmultiaddr_t ifmaddr
);
3078 * @function ifmaddr_address
3079 * @discussion Copies the multicast address to out_multicast.
3080 * @param out_multicast Storage for a sockaddr.
3081 * @param addr_size Size of the storage.
3082 * @result 0 on success.
3084 extern errno_t
ifmaddr_address(ifmultiaddr_t ifmaddr
,
3085 struct sockaddr
*out_multicast
, u_int32_t addr_size
);
3088 * @function ifmaddr_lladdress
3089 * @discussion Copies the link layer multicast address to
3090 * out_link_layer_multicast.
3091 * @param out_link_layer_multicast Storage for a sockaddr.
3092 * @param addr_size Size of the storage.
3093 * @result 0 on success.
3095 extern errno_t
ifmaddr_lladdress(ifmultiaddr_t ifmaddr
,
3096 struct sockaddr
*out_link_layer_multicast
, u_int32_t addr_size
);
3099 * @function ifmaddr_ifnet
3100 * @discussion Returns the interface this multicast address is attached
3101 * to. The interface reference count is not bumped by this
3102 * function. The interface is only valid as long as you don't
3103 * release the refernece to the multiast address. If you need to
3104 * maintain your pointer to the ifnet, call ifnet_reference
3105 * followed by ifnet_release when you're finished.
3106 * @param ifmaddr The interface multicast address.
3107 * @result A reference to the interface.
3109 extern ifnet_t
ifmaddr_ifnet(ifmultiaddr_t ifmaddr
);
3111 #ifdef KERNEL_PRIVATE
3112 /******************************************************************************/
3113 /* interface cloner */
3114 /******************************************************************************/
3117 * @typedef ifnet_clone_create_func
3118 * @discussion ifnet_clone_create_func is called to create an interface.
3119 * @param ifcloner The interface cloner.
3120 * @param unit The interface unit number to create.
3121 * @param params Additional information specific to the interface cloner.
3122 * @result Return zero on success or an errno error value on failure.
3124 typedef errno_t (*ifnet_clone_create_func
)(if_clone_t ifcloner
, u_int32_t unit
, void *params
);
3127 * @typedef ifnet_clone_destroy_func
3128 * @discussion ifnet_clone_create_func is called to destroy an interface created
3129 * by an interface cloner.
3130 * @param interface The interface to destroy.
3131 * @result Return zero on success or an errno error value on failure.
3133 typedef errno_t (*ifnet_clone_destroy_func
)(ifnet_t interface
);
3136 * @struct ifnet_clone_params
3137 * @discussion This structure is used to represent an interface cloner.
3138 * @field ifc_name The interface name handled by this interface cloner.
3139 * @field ifc_create The function to create an interface.
3140 * @field ifc_destroy The function to destroy an interface.
3142 struct ifnet_clone_params
{
3143 const char *ifc_name
;
3144 ifnet_clone_create_func ifc_create
;
3145 ifnet_clone_destroy_func ifc_destroy
;
3149 * @function ifnet_clone_attach
3150 * @discussion Attaches a new interface cloner.
3151 * @param cloner_params The structure that defines an interface cloner.
3152 * @param interface A pointer to an opaque handle that represent the interface cloner
3153 * that is attached upon success.
3154 * @result Returns 0 on success.
3155 * May return ENOBUFS if there is insufficient memory.
3156 * May return EEXIST if an interface cloner with the same name is already attached.
3158 extern errno_t
ifnet_clone_attach(struct ifnet_clone_params
*cloner_params
, if_clone_t
*ifcloner
);
3161 * @function ifnet_clone_detach
3162 * @discussion Detaches a previously attached interface cloner.
3163 * @param ifcloner The opaque handle returned when the interface cloner was attached.
3164 * @result Returns 0 on success.
3166 extern errno_t
ifnet_clone_detach(if_clone_t ifcloner
);
3168 /******************************************************************************/
3170 /******************************************************************************/
3173 * @function ifnet_get_local_ports
3174 * @discussion Returns a bitfield indicating which ports of PF_INET
3175 * and PF_INET6 protocol families have sockets in the usable
3176 * state. An interface that supports waking the host on unicast
3177 * traffic may use this information to discard incoming unicast
3178 * packets that don't have a corresponding bit set instead of
3179 * waking up the host. For port 0x0001, bit 1 of the first byte
3180 * would be set. For port n, bit 1 << (n % 8) of the (n / 8)'th
3181 * byte would be set.
3182 * @param ifp The interface in question. May be NULL, which means
3184 * @param bitfield A pointer to 8192 bytes.
3185 * @result Returns 0 on success.
3187 extern errno_t
ifnet_get_local_ports(ifnet_t ifp
, u_int8_t
*bitfield
);
3189 #define IFNET_GET_LOCAL_PORTS_WILDCARDOK 0x01
3190 #define IFNET_GET_LOCAL_PORTS_NOWAKEUPOK 0x02
3191 #define IFNET_GET_LOCAL_PORTS_TCPONLY 0x04
3192 #define IFNET_GET_LOCAL_PORTS_UDPONLY 0x08
3193 #define IFNET_GET_LOCAL_PORTS_RECVANYIFONLY 0x10
3194 #define IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY 0x20
3195 #define IFNET_GET_LOCAL_PORTS_ACTIVEONLY 0x40
3197 * @function ifnet_get_local_ports_extended
3198 * @discussion Returns a bitfield indicating which local ports of the
3199 * specified protocol have sockets in the usable state. An
3200 * interface that supports waking the host on unicast traffic may
3201 * use this information to discard incoming unicast packets that
3202 * don't have a corresponding bit set instead of waking up the
3203 * host. For port 0x0001, bit 1 of the first byte would be set.
3204 * For port n, bit 1 << (n % 8) of the (n / 8)'th byte would be
3206 * @param ifp The interface in question. May be NULL, which means
3208 * @param protocol The protocol family of the sockets. PF_UNSPEC (0)
3209 * means all protocols, otherwise PF_INET or PF_INET6.
3210 * @param flags A bitwise of the following flags:
3211 * IFNET_GET_LOCAL_PORTS_WILDCARDOK: When bit is set,
3212 * the list of local ports should include those that are
3213 * used by sockets that aren't bound to any local address.
3214 * IFNET_GET_LOCAL_PORTS_NOWAKEUPOK: When bit is
3215 * set, the list of local ports should return all sockets
3216 * including the ones that do not need a wakeup from sleep.
3217 * Sockets that do not want to wake from sleep are marked
3218 * with a socket option.
3219 * IFNET_GET_LOCAL_PORTS_TCPONLY: When bit is set, the list
3220 * of local ports should return the ports used by TCP sockets.
3221 * IFNET_GET_LOCAL_PORTS_UDPONLY: When bit is set, the list
3222 * of local ports should return the ports used by UDP sockets.
3224 * IFNET_GET_LOCAL_PORTS_RECVANYIFONLY: When bit is set, the
3225 * port is in the list only if the socket has the option
3227 * IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY: When bit is set, the
3228 * port is in the list only if the socket has the option
3229 * SO_EXTENDED_BK_IDLE set
3230 * IFNET_GET_LOCAL_PORTS_ACTIVEONLY: When bit is set, the
3231 * port is in the list only if the socket is not in a final TCP
3232 * state or the connection is not idle in a final TCP state
3233 * @param bitfield A pointer to 8192 bytes.
3234 * @result Returns 0 on success.
3236 extern errno_t
ifnet_get_local_ports_extended(ifnet_t ifp
,
3237 protocol_family_t protocol
, u_int32_t flags
, u_int8_t
*bitfield
);
3239 /******************************************************************************/
3240 /* for reporting issues */
3241 /******************************************************************************/
3243 #define IFNET_MODIDLEN 20
3244 #define IFNET_MODARGLEN 12
3247 * @function ifnet_report_issues
3248 * @discussion Provided for network interface families and drivers to
3249 * notify the system of issues detected at their layers.
3250 * @param ifp The interface experiencing issues.
3251 * @param modid The ID of the module reporting issues. It may contain
3252 * any value that is unique enough to identify the module, such
3253 * as the SHA-1 hash of the bundle ID of the module, e.g.
3254 * "com.apple.iokit.IONetworkingFamily" or
3255 * "com.apple.iokit.IO80211Family".
3256 * @param info An optional, fixed-size array of octets containing opaque
3257 * information data used specific to the module/layer reporting
3258 * the issues. May be NULL.
3259 * @result Returns 0 on success, or EINVAL if arguments are invalid.
3261 extern errno_t
ifnet_report_issues(ifnet_t ifp
, u_int8_t modid
[IFNET_MODIDLEN
],
3262 u_int8_t info
[IFNET_MODARGLEN
]);
3264 /******************************************************************************/
3265 /* for interfaces that support link level transmit completion status */
3266 /******************************************************************************/
3268 * @enum Per packet phy level transmit completion status values
3269 * @abstract Constants defining possible completion status values
3270 * A driver may support all or some of these values
3272 * @constant IFNET_TX_COMPL_SUCCESS link transmission succeeded
3273 * @constant IFNET_TX_COMPL_FAIL link transmission failed
3274 * @constant IFNET_TX_COMPL_ABORTED link transmission aborted, may retry
3275 * @constant IFNET_TX_QUEUE_FULL link level secondary queue full
3278 IFNET_TX_COMPL_SUCCESS
= 0, /* sent on link */
3279 IFNET_TX_COMPL_FAIL
= 1, /* failed to send on link */
3280 IFNET_TX_COMPL_ABORTED
= 2, /* aborted send, peer asleep */
3281 IFNET_TX_COMPL_QFULL
= 3 /* driver level queue full */
3284 typedef u_int32_t tx_compl_val_t
;
3287 * @function ifnet_tx_compl_status
3288 * @discussion Used as an upcall from IONetwork Family to stack that
3289 * indicates the link level completion status of a transmitted
3291 * @param ifp The interface to which the mbuf was sent
3292 * @param m The mbuf that was transmitted
3293 * @param val indicates the status of the transmission
3295 extern errno_t
ifnet_tx_compl_status(ifnet_t ifp
, mbuf_t m
, tx_compl_val_t val
);
3298 * @function ifnet_tx_compl
3299 * @discussion Used to indicates the packet has been transmitted.
3300 * @param ifp The interface to which the mbuf was sent
3301 * @param m The mbuf that was transmitted
3303 extern errno_t
ifnet_tx_compl(ifnet_t ifp
, mbuf_t m
);
3305 /******************************************************************************/
3306 /* for interfaces that support dynamic node absence/presence events */
3307 /******************************************************************************/
3310 * @function ifnet_notice_node_presence
3311 * @discussion Provided for network interface drivers to notify the
3312 * system of a change detected in the presence of the specified
3314 * @param ifp The interface attached to the link where the specified node
3316 * @param sa The AF_LINK family address of the node whose presence is
3318 * @param rssi The received signal strength indication as measured in
3319 * dBm by a radio receiver.
3320 * @param lqm A link quality metric associated with the specified node.
3321 * @param npm A node proximity metric associated with the specified node.
3322 * @param srvinfo A fixed-size array of octets containing opaque service
3323 * information data used by the mDNS responder subsystem.
3324 * @result Returns 0 on success, or EINVAL if arguments are invalid.
3327 ifnet_notice_node_presence(ifnet_t ifp
, struct sockaddr
*sa
, int32_t rssi
,
3328 int lqm
, int npm
, u_int8_t srvinfo
[48]);
3331 * @function ifnet_notice_node_absence
3332 * @discussion Provided for network interface drivers to notify the
3333 * system that the absence of the specified node has been detected.
3334 * @param ifp The interface attached to the link where the absence of the
3335 * specified node has been detected.
3336 * @param sa The AF_INET6 or AF_LINK family address of the node whose absence has been
3337 * detected. If AF_LINK is specified, AF_INET6 address is derived from the
3339 * @result Returns 0 on success, or EINVAL if arguments are invalid.
3341 extern errno_t
ifnet_notice_node_absence(ifnet_t ifp
, struct sockaddr
*sa
);
3344 * @function ifnet_notice_node_presence_v2
3345 * @discussion Provided for network interface drivers to notify the
3346 * system of a change detected in the presence of the specified
3348 * @param ifp The interface attached to the link where the specified node
3350 * @param sa The AF_INET6 family address of the node whose presence is
3352 * @param sdl The AF_LINK family address of the node whose presence is
3354 * @param rssi The received signal strength indication as measured in
3355 * dBm by a radio receiver.
3356 * @param lqm A link quality metric associated with the specified node.
3357 * @param npm A node proximity metric associated with the specified node.
3358 * @param srvinfo A fixed-size array of octets containing opaque service
3359 * information data used by the mDNS responder subsystem.
3360 * @result Returns 0 on success, or EINVAL if arguments are invalid.
3363 ifnet_notice_node_presence_v2(ifnet_t ifp
, struct sockaddr
*sa
, struct sockaddr_dl
*sdl
, int32_t rssi
,
3364 int lqm
, int npm
, u_int8_t srvinfo
[48]);
3367 * @function ifnet_notice_master_elected
3368 * @discussion Provided for network interface drivers to notify the system
3369 * that the nodes with a locally detected presence on the attached
3370 * link have elected a new master.
3371 * @param ifp The interface attached to the link where the new master has
3373 * @result Returns 0 on success, or EINVAL if arguments are invalid.
3375 extern errno_t
ifnet_notice_master_elected(ifnet_t ifp
);
3377 /******************************************************************************/
3378 /* for interface delegation */
3379 /******************************************************************************/
3382 * @function ifnet_set_delegate
3383 * @discussion Indicate that an interface is delegating another interface
3384 * for accounting/restriction purposes. This could be used by a
3385 * virtual interface that is going over another interface, where
3386 * the virtual interface is to be treated as if it's the underlying
3387 * interface for certain operations/checks.
3388 * @param ifp The delegating interface.
3389 * @param delegated_ifp The delegated interface. If NULL or equal to
3390 * the delegating interface itself, any previously-established
3391 * delegation is removed. If non-NULL, a reference to the
3392 * delegated interface is held by the delegating interface;
3393 * this reference is released via a subsequent call to remove
3394 * the established association, or when the delegating interface
3396 * @param Returns 0 on success, EINVAL if arguments are invalid, or
3397 * ENXIO if the delegating interface isn't currently attached.
3400 ifnet_set_delegate(ifnet_t ifp
, ifnet_t delegated_ifp
);
3403 * @function ifnet_get_delegate
3404 * @discussion Retrieve delegated interface information on an interface.
3405 * @param ifp The delegating interface.
3406 * @param pdelegated_ifp Pointer to the delegated interface. Upon
3407 * success, this will contain the delegated interface or
3408 * NULL if there is no delegation in place. If non-NULL,
3409 * the delegated interface will be returned with a reference
3410 * held for caller, and the caller is responsible for releasing
3411 * it via ifnet_release();
3412 * @param Returns 0 on success, EINVAL if arguments are invalid, or
3413 * ENXIO if the delegating interface isn't currently attached.
3416 ifnet_get_delegate(ifnet_t ifp
, ifnet_t
*pdelegated_ifp
);
3418 /*************************************************************************/
3419 /* for interface keep alive offload support */
3420 /*************************************************************************/
3423 * @struct ifnet_keepalive_offload_frame
3424 * @discussion This structure is used to define various opportunistic
3425 * polling parameters for an interface.
3426 * For IPsec and AirPlay UDP keep alive only a subset of the
3427 * fields are relevant.
3428 * An incoming TCP keep alive probe has the sequence number
3429 * in the TCP header equal to "remote_seq" and the
3430 * acknowledgment number field is equal to "local_seq".
3431 * An incoming TCP keep alive probe has the sequence number
3432 * equlal to "remote_seq" minus 1 and the acknowledgment number
3433 * field is equal to "local_seq".
3434 * Note that remote_seq is in network byte order so the value to
3435 * match may have to be converted to host byte order when
3437 * For TCP, the field "interval" corresponds to the socket option
3438 * TCP_KEEPALIVE, the field "keep_cnt" to TCP_KEEPINTVL and
3439 * the field "keep_cnt" to TCP_KEEPCNT.
3440 * @field data Keep alive probe to be sent.
3441 * @field type The type of keep alive frame
3442 * @field length The length of the frame in the data field
3443 * @field interval Keep alive interval between probes in seconds
3444 * @field ether_type Tell if it's the protocol is IPv4 or IPv6
3445 * @field keep_cnt Maximum number of time to retry probes (TCP only)
3446 * @field keep_retry Interval before retrying if previous probe was not answered (TCP only)
3447 * @field reply_length The length of the frame in the reply_data field (TCP only)
3448 * @field addr_length Length in bytes of local_addr and remote_addr (TCP only)
3449 * @field flags Flags (TCP only)
3450 * @field reply_data Keep alive reply to be sent to incoming probe (TCP only)
3451 * @field local_addr Local address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only)
3452 * @field remote_addr Remote address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only)
3453 * @field local_port Local port (TCP only)
3454 * @field remote_port Remote port (TCP only)
3455 * @field local_seq Local sequence number for matching incoming replies (TCP only)
3456 * @field remote_seq Remote sequence number for matching incoming probes or replies (TCP only)
3459 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE 128
3460 #define IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE 16
3462 struct ifnet_keepalive_offload_frame
{
3463 u_int8_t data
[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE
]; /* data bytes */
3464 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_IPSEC 0x0
3465 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_AIRPLAY 0x1
3466 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_TCP 0x2
3467 u_int8_t type
; /* type of application */
3468 u_int8_t length
; /* Number of valid data bytes including offset */
3469 u_int16_t interval
; /* Keep alive interval in seconds */
3470 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV4 0x0
3471 #define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV6 0x1
3472 u_int8_t ether_type
; /* Ether type IPv4 or IPv6 */
3473 u_int8_t keep_cnt
; /* max number of time to retry probes */
3474 u_int16_t keep_retry
; /* interval before retrying if previous probe was not answered */
3475 u_int8_t reply_length
; /* Length of valid reply_data bytes including offset */
3476 u_int8_t addr_length
; /* Length of valid bytes in local_addr and remote_addr */
3477 #define IFNET_KEEPALIVE_OFFLOAD_FLAG_NOWAKEFROMSLEEP 0x01
3479 u_int8_t reserved
[1];
3480 u_int8_t reply_data
[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE
]; /* Response packet */
3481 u_int8_t local_addr
[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE
]; /* in network byte order */
3482 u_int8_t remote_addr
[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE
]; /* in network byte order */
3483 u_int16_t local_port
; /* in host byte order */
3484 u_int16_t remote_port
; /* in host byte order */
3485 u_int32_t local_seq
; /* in host byte order */
3486 u_int32_t remote_seq
; /* in host byte order */
3490 * @function ifnet_get_keepalive_offload_frames
3491 * @discussion Fills out frames_array with IP packets to send at
3492 * periodic intervals as Keep-alive or heartbeat messages.
3493 * This can be used to offload keep alives for UDP or TCP.
3494 * Note: The frames are returned in this order: first the IPsec
3495 * frames, then the AirPlay frames and finally the TCP frames.
3496 * If a device does not support one kind of keep alive frames_array
3497 * it should provide a frames_array large enough to accomodate
3499 * @param ifp The interface to send frames out on. This is used to
3500 * select which sockets or IPsec SAs should generate the
3502 * @param frames_array An array of ifnet_keepalive_offload_frame
3503 * structs. This is allocated by the caller, and has
3504 * frames_array_count frames of valid memory.
3505 * @param frames_array_count The number of valid frames allocated
3506 * by the caller in frames_array
3507 * @param frame_data_offset The offset in bytes into each frame data
3508 * at which the IPv4/IPv6 packet and payload should be written
3509 * @param used_frames_count The returned number of frames that were
3510 * filled out with valid information.
3511 * @result Returns 0 on success, error number otherwise.
3513 extern errno_t
ifnet_get_keepalive_offload_frames(ifnet_t ifp
,
3514 struct ifnet_keepalive_offload_frame
*frames_array
,
3515 u_int32_t frames_array_count
, size_t frame_data_offset
,
3516 u_int32_t
*used_frames_count
);
3520 * @function ifnet_notify_tcp_keepalive_offload_timeout
3521 * @discussion Used by an interface to notify a TCP connection whose
3522 * keep alive was offloaded did experience a timeout.
3523 * @param ifp The interface for which the TCP keep alive offload timed out
3524 * @param frame The ifnet_keepalive_offload_frame structure that identifies
3525 * the TCP connection that experienced the timeout.
3526 * All the fields must be zeroed by the caller except for:
3527 * - type: must be IFNET_KEEPALIVE_OFFLOAD_FRAME_TCP
3528 * and for the fields identifying the 5-tup;e of the
3535 * @result Returns 0 on success, error number otherwise.
3537 extern errno_t
ifnet_notify_tcp_keepalive_offload_timeout(ifnet_t ifp
,
3538 struct ifnet_keepalive_offload_frame
*frame
);
3540 /*************************************************************************/
3541 /* Link level notifications */
3542 /*************************************************************************/
3544 * @function ifnet_link_status_report
3545 * @discussion A KPI to let the driver provide link specific
3546 * status information to the protocol stack. The KPI will
3547 * copy contents from the buffer based on the version and
3548 * length provided by the driver. The contents of the buffer
3549 * will be read but will not be modified.
3550 * @param ifp The interface that is generating the report
3551 * @param buffer Buffer containing the link specific information
3552 * for this interface. It is the caller's responsibility
3553 * to free this buffer.
3554 * @param buffer_len Valid length of the buffer provided by the caller
3555 * @result Returns 0 on success, error number otherwise.
3557 extern errno_t
ifnet_link_status_report(ifnet_t ifp
, const void *buffer
,
3560 /*************************************************************************/
3562 /*************************************************************************/
3564 * @function ifnet_set_fastlane_capable
3565 * @param interface The interface.
3566 * @param capable Set the truth value that the interface is attached to
3567 * a network that is capable of Fastlane QoS marking.
3568 * @result Returns 0 on success, error number otherwise.
3570 extern errno_t
ifnet_set_fastlane_capable(ifnet_t interface
, boolean_t capable
);
3573 * @function ifnet_get_fastlane_capable
3574 * @param interface The interface.
3575 * @param capable On output contains the truth value that the interface
3576 * is attached ta network that is capable of Fastlane QoS marking.
3577 * @result Returns 0 on success, error number otherwise.
3579 extern errno_t
ifnet_get_fastlane_capable(ifnet_t interface
, boolean_t
*capable
);
3582 * @function ifnet_get_unsent_bytes
3583 * @param interface The interface
3584 * @param unsent_bytes An out parameter that contains unsent bytes for
3586 * @result Returns 0 on success, error otherwise.
3588 extern errno_t
ifnet_get_unsent_bytes(ifnet_t interface
, int64_t *unsent_bytes
);
3591 int32_t buf_interface
; /* data to send at interface */
3592 int32_t buf_sndbuf
; /* data to send at socket buffer */
3593 } ifnet_buffer_status_t
;
3596 * @function ifnet_get_buffer_status
3597 * @param interface The interface
3598 * @param buf_status An out parameter that contains unsent bytes
3600 * @result Returns 0 on success, EINVAL if any of the arguments is
3601 * NULL, ENXIO if the interface pointer is invalid
3603 extern errno_t
ifnet_get_buffer_status(const ifnet_t interface
,
3604 ifnet_buffer_status_t
*buf_status
);
3607 * @function ifnet_normalise_unsent_data
3609 * Gathers the unsent bytes on all the interfaces.
3610 * This data will be reported to NetworkStatistics.
3613 extern void ifnet_normalise_unsent_data(void);
3615 /*************************************************************************/
3616 /* Low Power Mode */
3617 /*************************************************************************/
3620 * @function ifnet_set_low_power_mode
3621 * @param interface The interface.
3622 * @param on Set the truth value that the interface is in low power mode.
3623 * @result Returns 0 on success, error number otherwise.
3625 extern errno_t
ifnet_set_low_power_mode(ifnet_t interface
, boolean_t on
);
3628 * @function ifnet_get_low_power_mode
3629 * @param interface The interface.
3630 * @param on On output contains the truth value that the interface
3631 * is in low power mode.
3632 * @result Returns 0 on success, error number otherwise.
3634 extern errno_t
ifnet_get_low_power_mode(ifnet_t interface
, boolean_t
*on
);
3637 * @function ifnet_touch_lastupdown
3638 * @discussion Updates the lastupdown value to now.
3639 * @param interface The interface.
3640 * @result 0 on success otherwise the errno error.
3642 extern errno_t
ifnet_touch_lastupdown(ifnet_t interface
);
3645 * @function ifnet_updown_delta
3646 * @discussion Retrieves the difference between lastupdown and now.
3647 * @param interface The interface.
3648 * @param updown_delta A timeval struct to copy the delta between lastupdown and now.
3651 extern errno_t
ifnet_updown_delta(ifnet_t interface
, struct timeval
*updown_delta
);
3653 /*************************************************************************/
3654 /* Interface advisory notifications */
3655 /*************************************************************************/
3657 * @function ifnet_interface_advisory_report
3658 * @discussion KPI to let the driver provide interface advisory
3659 * notifications to the user space.
3660 * @param ifp The interface that is generating the advisory report.
3661 * @param advisory structure containing the advisory notification
3663 * @result Returns 0 on success, error number otherwise.
3665 extern errno_t
ifnet_interface_advisory_report(ifnet_t ifp
,
3666 const struct ifnet_interface_advisory
*advisory
);
3668 #endif /* KERNEL_PRIVATE */
3672 #endif /* __KPI_INTERFACE__ */