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