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