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