]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/kpi_interface.h
xnu-1504.3.12.tar.gz
[apple/xnu.git] / bsd / net / kpi_interface.h
CommitLineData
91447636 1/*
b0d623f7 2 * Copyright (c) 2008 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
91447636 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.
8f6c56a5 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.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
91447636
A
27 */
28/*!
29 @header kpi_interface.h
30 This header defines an API to interact with network interfaces in
31 the kernel. The network interface KPI may be used to implement
32 network interfaces or to attach protocols to existing interfaces.
33 */
34
35#ifndef __KPI_INTERFACE__
36#define __KPI_INTERFACE__
37#include <sys/kernel_types.h>
38
39#ifndef _SA_FAMILY_T
40#define _SA_FAMILY_T
41typedef __uint8_t sa_family_t;
42#endif
43
44struct timeval;
45struct sockaddr;
46struct sockaddr_dl;
47struct kern_event_msg;
48struct kev_msg;
49struct ifnet_demux_desc;
50
51/*!
52 @enum Interface Families
53 @abstract Constants defining interface families.
54 @constant IFNET_FAMILY_ANY Match interface of any family type.
55 @constant IFNET_FAMILY_LOOPBACK A software loopback interface.
56 @constant IFNET_FAMILY_ETHERNET An Ethernet interface.
57 @constant IFNET_FAMILY_SLIP A SLIP interface.
58 @constant IFNET_FAMILY_TUN A tunnel interface.
59 @constant IFNET_FAMILY_VLAN A virtual LAN interface.
60 @constant IFNET_FAMILY_PPP A PPP interface.
61 @constant IFNET_FAMILY_PVC A PVC interface.
62 @constant IFNET_FAMILY_DISC A DISC interface.
63 @constant IFNET_FAMILY_MDECAP A MDECAP interface.
64 @constant IFNET_FAMILY_GIF A generic tunnel interface.
65 @constant IFNET_FAMILY_FAITH A FAITH (IPv4/IPv6 translation) interface.
66 @constant IFNET_FAMILY_STF A 6to4 interface.
67 @constant IFNET_FAMILY_FIREWIRE An IEEE 1394 (firewire) interface.
68 @constant IFNET_FAMILY_BOND A virtual bonded interface.
69*/
70
71enum {
b0d623f7
A
72 IFNET_FAMILY_ANY = 0,
73 IFNET_FAMILY_LOOPBACK = 1,
74 IFNET_FAMILY_ETHERNET = 2,
75 IFNET_FAMILY_SLIP = 3,
76 IFNET_FAMILY_TUN = 4,
77 IFNET_FAMILY_VLAN = 5,
78 IFNET_FAMILY_PPP = 6,
79 IFNET_FAMILY_PVC = 7,
80 IFNET_FAMILY_DISC = 8,
81 IFNET_FAMILY_MDECAP = 9,
82 IFNET_FAMILY_GIF = 10,
83 IFNET_FAMILY_FAITH = 11,
84 IFNET_FAMILY_STF = 12,
85 IFNET_FAMILY_FIREWIRE = 13,
86 IFNET_FAMILY_BOND = 14
91447636
A
87};
88/*!
89 @typedef ifnet_family_t
90 @abstract Storage type for the interface family.
91*/
92typedef u_int32_t ifnet_family_t;
93
2d21ac55
A
94#ifndef BPF_TAP_MODE_T
95#define BPF_TAP_MODE_T
91447636
A
96/*!
97 @enum BPF tap mode
98 @abstract Constants defining interface families.
99 @constant BPF_MODE_DISABLED Disable bpf.
100 @constant BPF_MODE_INPUT Enable input only.
101 @constant BPF_MODE_OUTPUT Enable output only.
102 @constant BPF_MODE_INPUT_OUTPUT Enable input and output.
103*/
104
105enum {
b0d623f7
A
106 BPF_MODE_DISABLED = 0,
107 BPF_MODE_INPUT = 1,
108 BPF_MODE_OUTPUT = 2,
109 BPF_MODE_INPUT_OUTPUT = 3
91447636
A
110};
111/*!
112 @typedef bpf_tap_mode
113 @abstract Mode for tapping. BPF_MODE_DISABLED/BPF_MODE_INPUT_OUTPUT etc.
114*/
115typedef u_int32_t bpf_tap_mode;
2d21ac55 116#endif /* !BPF_TAP_MODE_T */
91447636
A
117
118/*!
119 @typedef protocol_family_t
120 @abstract Storage type for the protocol family.
121*/
122typedef u_int32_t protocol_family_t;
123
124/*!
125 @enum Interface Abilities
126 @abstract Constants defining interface offload support.
127 @constant IFNET_CSUM_IP Hardware will calculate IPv4 checksums.
128 @constant IFNET_CSUM_TCP Hardware will calculate TCP checksums.
129 @constant IFNET_CSUM_UDP Hardware will calculate UDP checksums.
130 @constant IFNET_CSUM_FRAGMENT Hardware will checksum IP fragments.
131 @constant IFNET_IP_FRAGMENT Hardware will fragment IP packets.
132 @constant IFNET_VLAN_TAGGING Hardware will generate VLAN headers.
133 @constant IFNET_VLAN_MTU Hardware supports VLAN MTU.
2d21ac55
A
134 @constant IFNET_MULTIPAGES Driver is capable of handling packets
135 coming down from the network stack that reside in virtually,
136 but not in physically contiguous span of the external mbuf
137 clusters. In this case, the data area of a packet in the
138 external mbuf cluster might cross one or more physical
139 pages that are disjoint, depending on the interface MTU
140 and the packet size. Such a use of larger than system page
141 size clusters by the network stack is done for better system
142 efficiency. Drivers that utilize the IOMbufNaturalMemoryCursor
143 with the getPhysicalSegmentsWithCoalesce interfaces and
144 enumerate the list of vectors should set this flag for
145 possible gain in performance during bulk data transfer.
b0d623f7
A
146 @constant IFNET_TSO_IPV4 Hardware supports IPv4 TCP Segment Offloading.
147 If the Interface driver sets this flag, TCP will send larger frames (up to 64KB) as one
148 frame to the adapter which will perform the final packetization. The maximum TSO segment
149 supported by the interface can be set with "ifnet_set_tso_mtu". To retreive the real MTU
150 for the TCP connection the function "mbuf_get_tso_requested" is used by the driver.
151 @constant IFNET_TSO_IPV6 Hardware supports IPv6 TCP Segment Offloading.
91447636
A
152*/
153
154enum {
b0d623f7
A
155 IFNET_CSUM_IP = 0x00000001,
156 IFNET_CSUM_TCP = 0x00000002,
157 IFNET_CSUM_UDP = 0x00000004,
158 IFNET_CSUM_FRAGMENT = 0x00000008,
159 IFNET_IP_FRAGMENT = 0x00000010,
91447636 160#ifdef KERNEL_PRIVATE
b0d623f7
A
161 IFNET_CSUM_SUM16 = 0x00001000,
162#endif /* KERNEL_PRIVATE */
163 IFNET_VLAN_TAGGING = 0x00010000,
164 IFNET_VLAN_MTU = 0x00020000,
165 IFNET_MULTIPAGES = 0x00100000,
166 IFNET_TSO_IPV4 = 0x00200000,
167 IFNET_TSO_IPV6 = 0x00400000,
91447636
A
168};
169/*!
170 @typedef ifnet_offload_t
171 @abstract Flags indicating the offload support of the interface.
172*/
173typedef u_int32_t ifnet_offload_t;
174
175/*
176 * Callbacks
177 *
178 * These are function pointers you supply to the kernel in the interface.
179 */
180/*!
181 @typedef bpf_packet_func
b0d623f7 182
91447636
A
183 @discussion bpf_packet_func The bpf_packet_func is used to intercept
184 inbound and outbound packets. The tap function will never free
185 the mbuf. The tap function will only copy the mbuf in to various
186 bpf file descriptors tapping this interface.
187 @param interface The interface being sent or received on.
188 @param data The packet to be transmitted or received.
189 @result An errno value or zero upon success.
190 */
191/* Fast path - do not block or spend excessive amounts of time */
192typedef errno_t (*bpf_packet_func)(ifnet_t interface, mbuf_t data);
193
194/*!
195 @typedef ifnet_output_func
b0d623f7 196
91447636
A
197 @discussion ifnet_output_func is used to transmit packets. The stack
198 will pass fully formed packets, including frame header, to the
199 ifnet_output function for an interface. The driver is
200 responsible for freeing the mbuf.
201 @param interface The interface being sent on.
202 @param data The packet to be sent.
203 */
204/* Fast path - do not block or spend excessive amounts of time */
205typedef errno_t (*ifnet_output_func)(ifnet_t interface, mbuf_t data);
206
207/*!
208 @typedef ifnet_ioctl_func
209 @discussion ifnet_ioctl_func is used to communicate ioctls from the
210 stack to the driver.
b0d623f7 211
2d21ac55
A
212 All undefined ioctls are reserved for future use by Apple. If
213 you need to communicate with your kext using an ioctl, please
214 use SIOCSIFKPI and SIOCGIFKPI.
91447636
A
215 @param interface The interface the ioctl is being sent to.
216 @param proto_family The protocol family to handle the ioctl, may be
217 zero for no protocol_family.
218 @param cmd The ioctl command.
219 @param data A pointer to any data related to the ioctl.
220 */
b0d623f7
A
221typedef errno_t (*ifnet_ioctl_func)(ifnet_t interface, unsigned long cmd,
222 void *data);
91447636
A
223
224/*!
225 @typedef ifnet_set_bpf_tap
2d21ac55
A
226 @discussion Deprecated. Specify NULL. Call bpf_tap_in/bpf_tap_out
227 for all packets.
91447636
A
228 */
229typedef errno_t (*ifnet_set_bpf_tap)(ifnet_t interface, bpf_tap_mode mode,
b0d623f7 230 bpf_packet_func callback);
91447636
A
231
232/*!
233 @typedef ifnet_detached_func
234 @discussion ifnet_detached_func is called an interface is detached
235 from the list of interfaces. When ifnet_detach is called, it may
236 not detach the interface immediately if protocols are attached.
237 ifnet_detached_func is used to notify the interface that it has
238 been detached from the networking stack. This is the last
239 function that will be called on an interface. Until this
240 function returns, you must not unload a kext supplying function
241 pointers to this interface, even if ifnet_detacah has been
242 called. Your detach function may be called during your call to
243 ifnet_detach.
244 @param interface The interface that has been detached.
245 event.
246 */
247typedef void (*ifnet_detached_func)(ifnet_t interface);
248
249/*!
250 @typedef ifnet_demux_func
b0d623f7
A
251 @discussion ifnet_demux_func is called for each inbound packet to
252 determine which protocol family the packet belongs to. This
253 information is then used by the stack to determine which
254 protocol to pass the packet to. This function may return
255 protocol families for protocols that are not attached. If the
256 protocol family has not been attached to the interface, the
257 packet will be discarded.
91447636
A
258 @param interface The interface the packet was received on.
259 @param packet The mbuf containing the packet.
260 @param frame_header A pointer to the frame header.
261 @param protocol_family Upon return, the protocol family matching the
262 packet should be stored here.
263 @result
264 If the result is zero, processing will continue normally.
b0d623f7
A
265 If the result is EJUSTRETURN, processing will stop but the
266 packet will not be freed.
267 If the result is anything else, the processing will stop and
268 the packet will be freed.
91447636
A
269 */
270typedef errno_t (*ifnet_demux_func)(ifnet_t interface, mbuf_t packet,
b0d623f7 271 char *frame_header, protocol_family_t *protocol_family);
91447636
A
272
273/*!
274 @typedef ifnet_event_func
275 @discussion ifnet_event_func is called when an event occurs on a
276 specific interface.
277 @param interface The interface the event occurred on.
278 @param event_ptr Pointer to a kern_event structure describing the
279 event.
280 */
281typedef void (*ifnet_event_func)(ifnet_t interface, const struct kev_msg *msg);
282
283/*!
284 @typedef ifnet_framer_func
285 @discussion ifnet_framer_func is called for each outbound packet to
286 give the interface an opportunity to prepend interface specific
287 headers.
288 @param interface The interface the packet is being sent on.
289 @param packet Pointer to the mbuf containing the packet, caller may
290 set this to a different mbuf upon return. This can happen if the
291 frameout function needs to prepend another mbuf to the chain to
292 have enough space for the header.
293 @param dest The higher layer protocol destination (i.e. IP address).
294 @param dest_linkaddr The link layer address as determined by the
295 protocol's pre-output function.
296 @param frame_type The frame type as determined by the protocol's
297 pre-output function.
298 @result
299 If the result is zero, processing will continue normally.
b0d623f7
A
300 If the result is EJUSTRETURN, processing will stop but the
301 packet will not be freed.
302 If the result is anything else, the processing will stop and
303 the packet will be freed.
91447636
A
304 */
305typedef errno_t (*ifnet_framer_func)(ifnet_t interface, mbuf_t *packet,
b0d623f7
A
306 const struct sockaddr *dest, const char *desk_linkaddr,
307 const char *frame_type);
91447636
A
308
309/*!
310 @typedef ifnet_add_proto_func
311 @discussion if_add_proto_func is called by the stack when a protocol
312 is attached to an interface. This gives the interface an
313 opportunity to get a list of protocol description structures
314 for demuxing packets to this protocol (demux descriptors).
315 @param interface The interface the protocol will be attached to.
316 @param protocol_family The family of the protocol being attached.
317 @param demux_array An array of demux descriptors that describe
318 the interface specific ways of identifying packets belonging
319 to this protocol family.
320 @param demux_count The number of demux descriptors in the array.
321 @result
322 If the result is zero, processing will continue normally.
b0d623f7
A
323 If the result is anything else, the add protocol will be
324 aborted.
91447636
A
325 */
326typedef errno_t (*ifnet_add_proto_func)(ifnet_t interface,
b0d623f7
A
327 protocol_family_t protocol_family,
328 const struct ifnet_demux_desc *demux_array, u_int32_t demux_count);
91447636
A
329
330/*!
331 @typedef if_del_proto_func
332 @discussion if_del_proto_func is called by the stack when a protocol
333 is being detached from an interface. This gives the interface an
334 opportunity to free any storage related to this specific
335 protocol being attached to this interface.
336 @param interface The interface the protocol will be detached from.
337 @param protocol_family The family of the protocol being detached.
338 @result
339 If the result is zero, processing will continue normally.
340 If the result is anything else, the detach will continue
341 and the error will be returned to the caller.
342 */
343typedef errno_t (*ifnet_del_proto_func)(ifnet_t interface,
b0d623f7 344 protocol_family_t protocol_family);
91447636
A
345
346/*!
347 @typedef ifnet_check_multi
348 @discussion ifnet_check_multi is called for each multicast address
349 added to an interface. This gives the interface an opportunity
350 to reject invalid multicast addresses before they are attached
351 to the interface.
b0d623f7 352
91447636
A
353 To prevent an address from being added to your multicast list,
354 return EADDRNOTAVAIL. If you don't know how to parse/translate
355 the address, return EOPNOTSUPP.
356 @param The interface.
357 @param mcast The multicast address.
358 @result
359 Zero upon success, EADDRNOTAVAIL on invalid multicast,
360 EOPNOTSUPP for addresses the interface does not understand.
361 */
362typedef errno_t (*ifnet_check_multi)(ifnet_t interface,
b0d623f7 363 const struct sockaddr *mcast);
91447636
A
364
365/*!
366 @typedef proto_media_input
367 @discussion proto_media_input is called for all inbound packets for
368 a specific protocol on a specific interface. This function is
369 registered on an interface using ifnet_attach_protocol.
370 @param ifp The interface the packet was received on.
371 @param protocol_family The protocol of the packet received.
372 @param packet The packet being input.
373 @param header The frame header.
374 @result
b0d623f7
A
375 If the result is zero, the caller will assume the packet was
376 passed to the protocol.
377 If the result is non-zero and not EJUSTRETURN, the caller will
378 free the packet.
91447636
A
379 */
380typedef errno_t (*proto_media_input)(ifnet_t ifp, protocol_family_t protocol,
b0d623f7 381 mbuf_t packet, char *header);
91447636 382
2d21ac55
A
383/*!
384 @typedef proto_media_input_v2
385 @discussion proto_media_input_v2 is called for all inbound packets for
386 a specific protocol on a specific interface. This function is
387 registered on an interface using ifnet_attach_protocolv2.
b0d623f7
A
388 proto_media_input_v2 differs from proto_media_input in that it
389 will be called for a list of packets instead of once for each
390 individual packet. The frame header can be retrieved using
391 mbuf_pkthdr_header.
2d21ac55
A
392 @param ifp The interface the packet was received on.
393 @param protocol_family The protocol of the packet received.
394 @param packet The packet being input.
395 @result
b0d623f7
A
396 If the result is zero, the caller will assume the packets were
397 passed to the protocol.
398 If the result is non-zero and not EJUSTRETURN, the caller will
399 free the packets.
2d21ac55
A
400 */
401typedef errno_t (*proto_media_input_v2)(ifnet_t ifp, protocol_family_t protocol,
b0d623f7 402 mbuf_t packet);
2d21ac55 403
91447636
A
404/*!
405 @typedef proto_media_preout
406 @discussion proto_media_preout is called just before the packet
407 is transmitted. This gives the proto_media_preout function an
408 opportunity to specify the media specific frame type and
409 destination.
410 @param ifp The interface the packet will be sent on.
411 @param protocol_family The protocol of the packet being sent
412 (PF_INET/etc...).
413 @param packet The packet being sent.
414 @param dest The protocol level destination address.
415 @param route A pointer to the routing structure for the packet.
416 @param frame_type The media specific frame type.
417 @param link_layer_dest The media specific destination.
418 @result
419 If the result is zero, processing will continue normally. If the
420 result is non-zero, processing will stop. If the result is
421 non-zero and not EJUSTRETURN, the packet will be freed by the
422 caller.
423 */
424typedef errno_t (*proto_media_preout)(ifnet_t ifp, protocol_family_t protocol,
b0d623f7
A
425 mbuf_t *packet, const struct sockaddr *dest, void *route, char *frame_type,
426 char *link_layer_dest);
91447636
A
427
428/*!
429 @typedef proto_media_event
430 @discussion proto_media_event is called to notify this layer of
431 interface specific events.
432 @param ifp The interface.
433 @param protocol_family The protocol family.
434 @param kev_msg The event.
435 */
436typedef void (*proto_media_event)(ifnet_t ifp, protocol_family_t protocol,
b0d623f7 437 const struct kev_msg *event);
91447636
A
438
439/*!
440 @typedef proto_media_ioctl
441 @discussion proto_media_event allows this layer to handle ioctls.
442 When an ioctl is handled, it is passed to the interface filters,
443 protocol filters, protocol, and interface. If you do not support
444 this ioctl, return EOPNOTSUPP. If you successfully handle the
445 ioctl, return zero. If you return any error other than
446 EOPNOTSUPP, other parts of the stack may not get an opportunity
447 to process the ioctl. If you return EJUSTRETURN, processing will
448 stop and a result of zero will be returned to the caller.
b0d623f7 449
2d21ac55
A
450 All undefined ioctls are reserved for future use by Apple. If
451 you need to communicate with your kext using an ioctl, please
452 use SIOCSIFKPI and SIOCGIFKPI.
91447636
A
453 @param ifp The interface.
454 @param protocol_family The protocol family.
455 @param command The ioctl command.
456 @param argument The argument to the ioctl.
457 @result
458 See the discussion.
459 */
460typedef errno_t (*proto_media_ioctl)(ifnet_t ifp, protocol_family_t protocol,
b0d623f7 461 unsigned long command, void *argument);
91447636
A
462
463/*!
464 @typedef proto_media_detached
465 @discussion proto_media_detached notifies you that your protocol
466 has been detached.
467 @param ifp The interface.
468 @param protocol_family The protocol family.
469 @result
470 See the discussion.
471 */
472typedef errno_t (*proto_media_detached)(ifnet_t ifp, protocol_family_t protocol);
473
91447636
A
474/*!
475 @typedef proto_media_resolve_multi
476 @discussion proto_media_resolve_multi is called to resolve a
477 protocol layer mulitcast address to a link layer multicast
478 address.
479 @param ifp The interface.
480 @param proto_addr The protocol address.
481 @param out_ll A sockaddr_dl to copy the link layer multicast in to.
482 @param ll_len The length of data allocated for out_ll.
483 @result Return zero on success or an errno error value on failure.
484 */
485typedef errno_t (*proto_media_resolve_multi)(ifnet_t ifp,
b0d623f7
A
486 const struct sockaddr *proto_addr, struct sockaddr_dl *out_ll,
487 size_t ll_len);
91447636
A
488
489/*!
490 @typedef proto_media_send_arp
491 @discussion proto_media_send_arp is called by the stack to generate
492 an ARP packet. This field is currently only used with IP. This
493 function should inspect the parameters and transmit an arp
494 packet using the information passed in.
495 @param ifp The interface the arp packet should be sent on.
496 @param protocol_family The protocol family of the addresses
497 (PF_INET).
498 @param arpop The arp operation (usually ARPOP_REQUEST or
499 ARPOP_REPLY).
500 @param sender_hw The value to use for the sender hardware
501 address field. If this is NULL, use the hardware address
502 of the interface.
503 @param sender_proto The value to use for the sender protocol
504 address field. This will not be NULL.
505 @param target_hw The value to use for the target hardware address.
506 If this is NULL, the target hardware address in the ARP packet
507 should be NULL and the link-layer destination for the back
508 should be a broadcast. If this is not NULL, this value should be
509 used for both the link-layer destination and the target hardware
510 address.
511 @param target_proto The target protocol address. This will not be
512 NULL.
513 @result Return zero on success or an errno error value on failure.
514 */
b0d623f7
A
515typedef errno_t (*proto_media_send_arp)(ifnet_t ifp, u_short arpop,
516 const struct sockaddr_dl *sender_hw, const struct sockaddr *sender_proto,
517 const struct sockaddr_dl *target_hw, const struct sockaddr *target_proto);
91447636
A
518
519/*!
520 @struct ifnet_stat_increment_param
521 @discussion This structure is used increment the counters on a
522 network interface.
523 @field packets_in The number of packets received.
524 @field bytes_in The number of bytes received.
525 @field errors_in The number of receive errors.
526 @field packets_out The number of packets transmitted.
527 @field bytes_out The number of bytes transmitted.
528 @field errors_out The number of transmission errors.
529 @field collisions The number of collisions seen by this interface.
530 @field dropped The number of packets dropped.
531*/
91447636
A
532struct ifnet_stat_increment_param {
533 u_int32_t packets_in;
534 u_int32_t bytes_in;
535 u_int32_t errors_in;
b0d623f7 536
91447636
A
537 u_int32_t packets_out;
538 u_int32_t bytes_out;
539 u_int32_t errors_out;
b0d623f7 540
91447636
A
541 u_int32_t collisions;
542 u_int32_t dropped;
543};
544
545/*!
546 @struct ifnet_init_params
547 @discussion This structure is used to define various properties of
548 the interface when calling ifnet_init. A copy of these values
549 will be stored in the ifnet and can not be modified while the
550 interface is attached.
551 @field uniqueid An identifier unique to this instance of the
552 interface.
553 @field uniqueid_len The length, in bytes, of the uniqueid.
554 @field name The interface name (i.e. en).
555 @field unit The interface unit number (en0's unit number is 0).
556 @field family The interface family.
557 @field type The interface type (see sys/if_types.h). Must be less
558 than 256. For new types, use IFT_OTHER.
559 @field output The output function for the interface. Every packet the
b0d623f7
A
560 stack attempts to send through this interface will go out
561 through this function.
91447636
A
562 @field demux The function used to determine the protocol family of an
563 incoming packet.
b0d623f7
A
564 @field add_proto The function used to attach a protocol to this
565 interface.
566 @field del_proto The function used to remove a protocol from this
567 interface.
91447636 568 @field framer The function used to frame outbound packets, may be NULL.
b0d623f7
A
569 @field softc Driver specific storage. This value can be retrieved from
570 the ifnet using the ifnet_softc function.
91447636
A
571 @field ioctl The function used to handle ioctls.
572 @field set_bpf_tap The function used to set the bpf_tap function.
b0d623f7
A
573 @field detach The function called to let the driver know the interface
574 has been detached.
575 @field event The function to notify the interface of various interface
576 specific kernel events.
577 @field broadcast_addr The link-layer broadcast address for this
578 interface.
91447636
A
579 @field broadcast_len The length of the link-layer broadcast address.
580*/
91447636
A
581struct ifnet_init_params {
582 /* used to match recycled interface */
b0d623f7
A
583 const void *uniqueid; /* optional */
584 u_int32_t uniqueid_len; /* optional */
585
91447636 586 /* used to fill out initial values for interface */
b0d623f7
A
587 const char *name; /* required */
588 u_int32_t unit; /* required */
589 ifnet_family_t family; /* required */
590 u_int32_t type; /* required */
591 ifnet_output_func output; /* required */
592 ifnet_demux_func demux; /* required */
91447636
A
593 ifnet_add_proto_func add_proto; /* required */
594 ifnet_del_proto_func del_proto; /* required */
b0d623f7
A
595 ifnet_check_multi check_multi; /* required for non point-to-point interfaces */
596 ifnet_framer_func framer; /* optional */
597 void *softc; /* optional */
598 ifnet_ioctl_func ioctl; /* optional */
599 ifnet_set_bpf_tap set_bpf_tap; /* deprecated */
600 ifnet_detached_func detach; /* optional */
601 ifnet_event_func event; /* optional */
602 const void *broadcast_addr; /* required for non point-to-point interfaces */
603 u_int32_t broadcast_len; /* required for non point-to-point interfaces */
91447636
A
604};
605
606/*!
607 @struct ifnet_stats_param
608 @discussion This structure is used get and set the interface
609 statistics.
610 @field packets_in The number of packets received.
611 @field bytes_in The number of bytes received.
612 @field errors_in The number of receive errors.
613 @field packets_out The number of packets transmitted.
614 @field bytes_out The number of bytes transmitted.
615 @field errors_out The number of transmission errors.
616 @field collisions The number of collisions seen by this interface.
617 @field dropped The number of packets dropped.
618*/
91447636
A
619struct ifnet_stats_param {
620 u_int64_t packets_in;
621 u_int64_t bytes_in;
622 u_int64_t multicasts_in;
623 u_int64_t errors_in;
b0d623f7 624
91447636
A
625 u_int64_t packets_out;
626 u_int64_t bytes_out;
627 u_int64_t multicasts_out;
628 u_int64_t errors_out;
b0d623f7 629
91447636
A
630 u_int64_t collisions;
631 u_int64_t dropped;
632 u_int64_t no_protocol;
633};
634
635/*!
636 @struct ifnet_demux_desc
637 @discussion This structure is to identify packets that belong to a
638 specific protocol. The types supported are interface specific.
639 Ethernet supports ETHER_DESC_ETYPE2, ETHER_DESC_SAP, and
640 ETHER_DESC_SNAP. The type defines the offset in the packet where
641 the data will be matched as well as context. For example, if
642 ETHER_DESC_SNAP is specified, the only valid datalen is 5 and
643 only in the 5 bytes will only be matched when the packet header
644 indicates that the packet is a SNAP packet.
645 @field type The type of identifier data (i.e. ETHER_DESC_ETYPE2)
646 @field data A pointer to an entry of type (i.e. pointer to 0x0800).
647 @field datalen The number of bytes of data used to describe the
648 packet.
649*/
91447636
A
650struct ifnet_demux_desc {
651 u_int32_t type;
b0d623f7 652 void *data;
91447636
A
653 u_int32_t datalen;
654};
655
656/*!
657 @struct ifnet_attach_proto_param
658 @discussion This structure is used to attach a protocol to an
659 interface. This structure provides the various functions for
660 handling operations related to the protocol on the interface as
661 well as information for how to demux packets for this protocol.
662 @field demux_array An array of ifnet_demux_desc structures
663 describing the protocol.
664 @field demux_count The number of entries in the demux_array array.
665 @field input The function to be called for inbound packets.
666 @field pre_output The function to be called for outbound packets.
667 @field event The function to be called for interface events.
668 @field ioctl The function to be called for ioctls.
669 @field detached The function to be called for handling the detach.
670*/
671#ifdef KERNEL_PRIVATE
672#define demux_list demux_array
673#endif /* KERNEL_PRIVATE */
674
675struct ifnet_attach_proto_param {
b0d623f7
A
676 struct ifnet_demux_desc *demux_array; /* interface may/may not require */
677 u_int32_t demux_count; /* interface may/may not require */
678
679 proto_media_input input; /* required */
680 proto_media_preout pre_output; /* required */
681 proto_media_event event; /* optional */
682 proto_media_ioctl ioctl; /* optional */
91447636
A
683 proto_media_detached detached; /* optional */
684 proto_media_resolve_multi resolve; /* optional */
685 proto_media_send_arp send_arp; /* optional */
686};
687
2d21ac55 688struct ifnet_attach_proto_param_v2 {
b0d623f7
A
689 struct ifnet_demux_desc *demux_array; /* interface may/may not require */
690 u_int32_t demux_count; /* interface may/may not require */
691
2d21ac55 692 proto_media_input_v2 input; /* required */
b0d623f7
A
693 proto_media_preout pre_output; /* required */
694 proto_media_event event; /* optional */
695 proto_media_ioctl ioctl; /* optional */
2d21ac55
A
696 proto_media_detached detached; /* optional */
697 proto_media_resolve_multi resolve; /* optional */
698 proto_media_send_arp send_arp; /* optional */
699};
700
91447636
A
701__BEGIN_DECLS
702
703/*
704 * Ifnet creation and reference counting
705 */
706
707/*!
708 @function ifnet_allocate
709 @discussion Allocate an ifnet_t with an initial refcount of 1. Many
710 parts of the stack do not properly refcount the ifnet_t. In
711 order to avoid freeing the ifnet_t while some parts of the stack
712 may contain a reference to it, the ifnet_ts are only recycled,
713 never freed. A unique id is used to try and recycle the same
714 ifnet_t when allocating an interface. For example, for an
715 ethernet interface, the hardware address of the ethernet card is
716 usually used for the uniqueid. If a PC Card is removed and
717 inserted again, if the ethernet address of the PC card is used,
718 the same ifnet_t will be used for the card the second time it is
719 inserted. In the future, when the ifnet_t is correctly
720 refcounted by all of the stack, the interfaces may be freed and
721 the unique ids ignored.
722 @param init The initial values for the interface. These values can
723 not be changed after the interface has been allocated.
724 @param interface The interface allocated upon success.
725 @result May return ENOMEM if there is insufficient memory or EEXIST
726 if an interface with the same uniqueid and family has already
727 been allocated and is in use.
728 */
b0d623f7
A
729extern errno_t ifnet_allocate(const struct ifnet_init_params *init,
730 ifnet_t *interface);
91447636
A
731
732/*!
733 @function ifnet_reference
734 @discussion Increment the reference count of the ifnet to assure
735 that it will not go away. The interface must already have at
736 least one reference.
737 @param interface The interface to increment the reference count of.
738 @result May return EINVAL if the interface is not valid.
739 */
b0d623f7 740extern errno_t ifnet_reference(ifnet_t interface);
91447636
A
741
742/*!
743 @function ifnet_release
744 @discussion Release a reference of the ifnet, this may trigger a
745 free if the reference count reaches 0.
746 @param interface The interface to decrement the reference count of
747 and possibly free.
748 @result May return EINVAL if the interface is not valid.
749 */
b0d623f7 750extern errno_t ifnet_release(ifnet_t interface);
91447636
A
751
752/*!
753 @function ifnet_attach
754 @discussion Attaches an interface to the global interface list. The
755 interface must be setup properly before calling attach. The
756 stack will take a reference on the interface and hold it until
757 ifnet_detach is called.
b0d623f7 758
91447636
A
759 This function is intended to be called by the driver. A kext
760 must not call this function on an interface the kext does not
761 own.
762 @param interface The interface to attach.
763 @param ll_addr The link layer address of the interface. This is used
764 to fill out the first ifaddr in the list of addresses for the
765 interface. This parameter is not required for interfaces such as
766 PPP that have no link-layer address.
767 @result Will return an error if there is anything wrong with the
768 interface.
769 */
b0d623f7
A
770extern errno_t ifnet_attach(ifnet_t interface,
771 const struct sockaddr_dl *ll_addr);
91447636
A
772
773/*!
774 @function ifnet_detach
775 @discussion Detaches the interface.
b0d623f7 776
91447636
A
777 Call this to indicate this interface is no longer valid (i.e. PC
778 Card was removed). This function will begin the process of
779 removing knowledge of this interface from the stack.
b0d623f7 780
91447636
A
781 The function will return before the interface is detached. The
782 functions you supplied in to the interface may continue to be
783 called. When the detach has been completed, your detached
784 function will be called. Your kext must not unload until the
785 detached function has been called. The interface will be
786 properly freed when the reference count reaches zero.
b0d623f7 787
91447636
A
788 An interface may not be attached again. You must call
789 ifnet_allocate to create a new interface to attach.
b0d623f7 790
91447636
A
791 This function is intended to be called by the driver. A kext
792 must not call this function on an interface the kext does not
793 own.
794 @param interface The interface to detach.
795 @result 0 on success, otherwise errno error.
796 */
b0d623f7
A
797extern errno_t ifnet_detach(ifnet_t interface);
798
799/*!
800 @function ifnet_interface_family_find
801 @discussion Look up the interface family identifier for a string.
802 If there is no interface family identifier assigned for this string
803 a new interface family identifier is created and assigned.
804 It is recommended to use the bundle id of the KEXT as the string
805 to avoid collisions with other KEXTs.
806 The lookup operation is not optimized so a module should call this
807 function once during startup and cache the interface family identifier.
808 The interface family identifier for a string will not be re-assigned until
809 the system reboots.
810 @param module_string A unique string identifying your interface family
811 @param family_id Upon return, a unique interface family identifier for use with
812 ifnet_* functions. This identifier is valid until the system
813 is rebooted.
814 @result 0 on success, otherwise errno error.
815*/
816extern errno_t ifnet_interface_family_find(const char *module_string, ifnet_family_t *family_id);
817
91447636
A
818/*
819 * Interface manipulation.
820 */
821
822/*!
823 @function ifnet_softc
824 @discussion Returns the driver's private storage on the interface.
825 @param interface Interface to retrieve the storage from.
826 @result Driver's private storage.
827 */
b0d623f7 828extern void *ifnet_softc(ifnet_t interface);
91447636
A
829
830/*!
831 @function ifnet_name
832 @discussion Returns a pointer to the name of the interface.
833 @param interface Interface to retrieve the name from.
834 @result Pointer to the name.
835 */
b0d623f7 836extern const char *ifnet_name(ifnet_t interface);
91447636
A
837
838/*!
839 @function ifnet_family
840 @discussion Returns the family of the interface.
841 @param interface Interface to retrieve the unit number from.
842 @result Unit number.
843 */
b0d623f7 844extern ifnet_family_t ifnet_family(ifnet_t interface);
91447636
A
845
846/*!
847 @function ifnet_unit
848 @discussion Returns the unit number of the interface.
849 @param interface Interface to retrieve the unit number from.
850 @result Unit number.
851 */
b0d623f7 852extern u_int32_t ifnet_unit(ifnet_t interface);
91447636
A
853
854/*!
855 @function ifnet_index
856 @discussion Returns the index of the interface. This index value
857 will match the index you would find in a sockaddr_dl or using
858 if_nametoindex or if_indextoname in user space. The value of the
859 interface index is undefined for an interface that is not
860 currently attached.
861 @param interface Interface to retrieve the index of.
862 @result Index.
863 */
b0d623f7 864extern u_int32_t ifnet_index(ifnet_t interface);
91447636
A
865
866/*!
867 @function ifnet_set_flags
868 @discussion Sets the interface flags to match new_flags.
869 @discussion Sets the interface flags to new_flags. This function
870 lets you specify which flags you want to change using the mask.
871 The kernel will effectively take the lock, then set the
872 interface's flags to (if_flags & ~mask) | (new_flags & mask).
873 @param interface Interface to set the flags on.
874 @param new_flags The new set of flags that should be set. These
875 flags are defined in net/if.h
876 @result 0 on success otherwise the errno error.
877 */
b0d623f7
A
878extern errno_t ifnet_set_flags(ifnet_t interface, u_int16_t new_flags,
879 u_int16_t mask);
91447636
A
880
881/*!
882 @function ifnet_flags
883 @discussion Returns the interface flags that are set.
884 @param interface Interface to retrieve the flags from.
885 @result Flags. These flags are defined in net/if.h
886 */
b0d623f7 887extern u_int16_t ifnet_flags(ifnet_t interface);
91447636
A
888
889
890#ifdef KERNEL_PRIVATE
891/*!
892 @function ifnet_set_eflags
893 @discussion Sets the extended interface flags to new_flags. This
894 function lets you specify which flags you want to change using
895 the mask. The kernel will effectively take the lock, then set
896 the interface's extended flags to (if_eflags & ~mask) |
897 (new_flags & mask).
898 @param interface The interface.
899 @param new_flags The new set of flags that should be set. These
900 flags are defined in net/if.h
901 @param mask The mask of flags to be modified.
902 @result 0 on success otherwise the errno error.
903 */
b0d623f7
A
904extern errno_t ifnet_set_eflags(ifnet_t interface, u_int32_t new_flags,
905 u_int32_t mask);
91447636
A
906
907/*!
908 @function ifnet_eflags
909 @discussion Returns the extended interface flags that are set.
910 @param interface Interface to retrieve the flags from.
911 @result Extended flags. These flags are defined in net/if.h
912 */
b0d623f7
A
913extern u_int32_t ifnet_eflags(ifnet_t interface);
914#endif /* KERNEL_PRIVATE */
91447636
A
915
916/*!
917 @function ifnet_set_offload
918 @discussion Sets a bitfield to indicate special hardware offload
919 support provided by the interface such as hardware checksums and
920 VLAN. This replaces the if_hwassist flags field. Any flags
921 unrecognized by the stack will not be set.
922 @param interface The interface.
923 @param offload The new set of flags indicating which offload options
924 the device supports.
925 @param mask The mask of flags to be modified.
926 @result 0 on success otherwise the errno error.
927 */
b0d623f7 928extern errno_t ifnet_set_offload(ifnet_t interface, ifnet_offload_t offload);
91447636
A
929
930/*!
931 @function ifnet_offload
932 @discussion Returns flags indicating which operations can be
933 offloaded to the interface.
934 @param interface Interface to retrieve the offload from.
935 @result Abilities flags, see ifnet_offload_t.
936 */
b0d623f7
A
937extern ifnet_offload_t ifnet_offload(ifnet_t interface);
938
939/*!
940 @function ifnet_set_tso_mtu
941 @discussion Sets maximum TCP Segmentation Offload segment size for
942 the interface
943 @param interface The interface.
944 @param family The family for which the offload MTU is provided for
945 (AF_INET or AF_INET6)
946 @param mtuLen Maximum segment size supported by the interface
947 @result 0 on success otherwise the errno error.
948*/
949extern errno_t ifnet_set_tso_mtu(ifnet_t interface, sa_family_t family,
950 u_int32_t mtuLen);
951
952/*!
953 @function ifnet_get_tso_mtu
954 @discussion Returns maximum TCP Segmentation Offload segment size for
955 the interface
956 @param interface The interface.
957 @param family The family for which the offload MTU is provided for
958 (AF_INET or AF_INET6)
959 @param mtuLen Value of the maximum MTU supported for the interface
960 and family provided.
961 @result 0 on success otherwise the errno error.
962 */
963extern errno_t ifnet_get_tso_mtu(ifnet_t interface, sa_family_t family,
964 u_int32_t *mtuLen);
965
966/*!
967 @enum Interface wake properties
968 @abstract Constants defining Interface wake properties.
969 @constant IFNET_WAKE_ON_MAGIC_PACKET Wake on Magic Packet.
970*/
971enum {
972 IFNET_WAKE_ON_MAGIC_PACKET = 0x01
973};
974
975/*!
976 @function ifnet_set_wake_flags
977 @discussion Sets the wake properties of the underlying hardware. These are
978 typically set by the driver.
979 @param interface The interface.
980 @param properties Properties to set or unset.
981 @param mask Mask of the properties to set of unset.
982 @result 0 on success otherwise the errno error.
983*/
984extern errno_t ifnet_set_wake_flags(ifnet_t interface, u_int32_t properties, u_int32_t mask);
985
986/*!
987 @function ifnet_get_wake_flags
988 @discussion Returns the wake properties set on the interface.
989 @param interface The interface.
990 @result The wake properties
991*/
992extern u_int32_t ifnet_get_wake_flags(ifnet_t interface);
91447636
A
993
994/*!
995 @function ifnet_set_link_mib_data
996 @discussion Sets the mib link data. The ifnet_t will store the
997 pointer you supply and copy mibLen bytes from the pointer
998 whenever the sysctl for getting interface specific MIB data is
999 used. Since the ifnet_t stores a pointer to your data instead of
1000 a copy, you may update the data at the address at any time.
b0d623f7 1001
91447636
A
1002 This function is intended to be called by the driver. A kext
1003 must not call this function on an interface the kext does not
1004 own.
1005 @param interface Interface to set the unit number of.
1006 @param mibData A pointer to the data.
1007 @param mibLen Length of data pointed to.
1008 @result 0 on success otherwise the errno error.
b0d623f7
A
1009*/
1010extern errno_t ifnet_set_link_mib_data(ifnet_t interface, void *mibData,
1011 u_int32_t mibLen);
91447636
A
1012
1013/*!
1014 @function ifnet_get_link_mib_data
1015 @discussion Copies the link MIB data in to mibData, up to mibLen
1016 bytes. Returns error if the buffer is too small to hold all of
1017 the MIB data.
1018 @param interface The interface.
1019 @param mibData A pointer to space for the mibData to be copied in
1020 to.
1021 @param mibLen When calling, this should be the size of the buffer
1022 passed in mibData. Upon return, this will be the size of data
1023 copied in to mibData.
1024 @result Returns an error if the buffer size is too small or there is
1025 no data.
1026 */
b0d623f7
A
1027extern errno_t ifnet_get_link_mib_data(ifnet_t interface, void *mibData,
1028 u_int32_t *mibLen);
91447636
A
1029
1030/*!
1031 @function ifnet_get_link_mib_data_length
1032 @discussion Retrieve the size of the mib data.
1033 @param interface The interface.
1034 @result Returns the number of bytes of mib data associated with the
1035 interface.
1036 */
b0d623f7 1037extern u_int32_t ifnet_get_link_mib_data_length(ifnet_t interface);
91447636
A
1038
1039/*!
1040 @function ifnet_attach_protocol
1041 @discussion Attaches a protocol to an interface.
1042 @param interface The interface.
1043 @param protocol_family The protocol family being attached
1044 (PF_INET/PF_APPLETALK/etc...).
1045 @param proto_details Details of the protocol being attached.
1046 @result 0 on success otherwise the errno error.
1047 */
b0d623f7
A
1048extern errno_t ifnet_attach_protocol(ifnet_t interface,
1049 protocol_family_t protocol_family,
1050 const struct ifnet_attach_proto_param *proto_details);
91447636 1051
2d21ac55
A
1052/*!
1053 @function ifnet_attach_protocol_v2
b0d623f7
A
1054 @discussion Attaches a protocol to an interface using the newer
1055 version 2 style interface. So far the only difference is support
1056 for packet chains which improve performance.
2d21ac55
A
1057 @param interface The interface.
1058 @param protocol_family The protocol family being attached
1059 (PF_INET/PF_APPLETALK/etc...).
1060 @param proto_details Details of the protocol being attached.
1061 @result 0 on success otherwise the errno error.
1062 */
b0d623f7
A
1063extern errno_t ifnet_attach_protocol_v2(ifnet_t interface,
1064 protocol_family_t protocol_family,
1065 const struct ifnet_attach_proto_param_v2 *proto_details);
2d21ac55 1066
91447636
A
1067/*!
1068 @function ifnet_detach_protocol
1069 @discussion Detaches a protocol from an interface.
1070 @param interface The interface.
1071 @param protocol_family The protocol family of the protocol to
1072 detach.
1073 @result 0 on success otherwise the errno error.
1074 */
b0d623f7
A
1075extern errno_t ifnet_detach_protocol(ifnet_t interface,
1076 protocol_family_t protocol_family);
91447636
A
1077
1078/*!
1079 @function ifnet_output
1080 @discussion Handles an outbound packet on the interface by calling
1081 any filters, a protocol preoutput function, the interface framer
1082 function, and finally the interface's output function. The
1083 protocol_family will be used to apply protocol filters and
1084 determine which preoutput function to call. The route and dest
1085 parameters will be passed to the preoutput function defined for
1086 the attachment of the specified protocol to the specified
2d21ac55 1087 interface. ifnet_output will always free the mbuf chain.
91447636
A
1088 @param interface The interface.
1089 @param protocol_family The family of the protocol generating this
1090 packet (i.e. AF_INET).
1091 @param packet The packet to be transmitted.
1092 @param route A pointer to a routing structure for this packet. The
1093 preoutput function determines whether this value may be NULL or
1094 not.
1095 @param dest The destination address of protocol_family type. This
1096 will be passed to the preoutput function. If the preoutput
1097 function does not require this value, you may pass NULL.
1098 @result 0 on success otherwise the errno error.
1099 */
b0d623f7
A
1100extern errno_t ifnet_output(ifnet_t interface,
1101 protocol_family_t protocol_family, mbuf_t packet, void *route,
1102 const struct sockaddr *dest);
91447636
A
1103
1104/*!
1105 @function ifnet_output_raw
1106 @discussion Handles and outbond raw packet on the interface by
1107 calling any filters followed by the interface's output function.
1108 protocol_family may be zero. If the packet is from a specific
1109 protocol the protocol_family will be used to apply protocol
1110 filters. All interface filters will be applied to the outgoing
1111 packet. Processing, such as calling the protocol preoutput and
1112 interface framer functions will be bypassed. The packet will
1113 pass through the filters and be sent on the interface as is.
2d21ac55 1114 ifnet_output_raw will always free the packet chain.
91447636
A
1115 @param interface The interface.
1116 @param protocol_family The family of the protocol generating this
1117 packet (i.e. AF_INET).
1118 @param packet The fully formed packet to be transmitted.
1119 @result 0 on success otherwise the errno error.
1120 */
b0d623f7
A
1121extern errno_t ifnet_output_raw(ifnet_t interface,
1122 protocol_family_t protocol_family, mbuf_t packet);
91447636
A
1123
1124/*!
1125 @function ifnet_input
1126 @discussion Inputs packets from the interface. The interface's demux
1127 will be called to determine the protocol. Once the protocol is
1128 determined, the interface filters and protocol filters will be
1129 called. From there, the packet will be passed to the registered
1130 protocol. If there is an error, the mbuf chain will be freed.
1131 @param interface The interface.
1132 @param first_packet The first packet in a chain of packets.
1133 @param stats Counts to be integrated in to the stats. The interface
1134 statistics will be incremented by the amounts specified in
1135 stats. This parameter may be NULL.
1136 @result 0 on success otherwise the errno error.
1137 */
b0d623f7
A
1138extern errno_t ifnet_input(ifnet_t interface, mbuf_t first_packet,
1139 const struct ifnet_stat_increment_param *stats);
91447636
A
1140
1141/*!
1142 @function ifnet_ioctl
1143 @discussion Calls the interface's ioctl function with the parameters
1144 passed.
b0d623f7 1145
2d21ac55
A
1146 All undefined ioctls are reserved for future use by Apple. If
1147 you need to communicate with your kext using an ioctl, please
1148 use SIOCSIFKPI and SIOCGIFKPI.
91447636
A
1149 @param interface The interface.
1150 @param protocol The protocol family of the protocol to send the
1151 ioctl to (may be zero). Some ioctls apply to a protocol while
1152 other ioctls apply to just an interface.
1153 @param ioctl_code The ioctl to perform.
1154 @param ioctl_arg Any parameters to the ioctl.
1155 @result 0 on success otherwise the errno error.
1156 */
b0d623f7
A
1157extern errno_t ifnet_ioctl(ifnet_t interface, protocol_family_t protocol,
1158 unsigned long ioctl_code, void *ioctl_arg);
91447636
A
1159
1160/*!
1161 @function ifnet_event
1162 @discussion Calls the interface's event function.
1163 @param interface The interface.
1164 @param event_ptr Pointer to an kern_event structure describing the
1165 event.
1166 @result 0 on success otherwise the errno error.
1167 */
b0d623f7 1168extern errno_t ifnet_event(ifnet_t interface, struct kern_event_msg *event_ptr);
91447636
A
1169
1170/*!
1171 @function ifnet_set_mtu
1172 @discussion Sets the value of the MTU in the interface structure.
1173 Calling this function will not notify the driver that the MTU
1174 should be changed. Use the appropriate ioctl.
b0d623f7 1175
91447636
A
1176 This function is intended to be called by the driver. A kext
1177 must not call this function on an interface the kext does not
1178 own.
1179 @param interface The interface.
1180 @param mtu The new MTU.
1181 @result 0 on success otherwise the errno error.
1182 */
b0d623f7 1183extern errno_t ifnet_set_mtu(ifnet_t interface, u_int32_t mtu);
91447636
A
1184
1185/*!
1186 @function ifnet_mtu
1187 @param interface The interface.
1188 @result The MTU.
1189 */
b0d623f7 1190extern u_int32_t ifnet_mtu(ifnet_t interface);
91447636
A
1191
1192/*!
1193 @function ifnet_type
1194 @param interface The interface.
1195 @result The type. See net/if_types.h.
1196 */
b0d623f7 1197extern u_int8_t ifnet_type(ifnet_t interface);
91447636
A
1198
1199/*!
1200 @function ifnet_set_addrlen
1201 @discussion
1202 This function is intended to be called by the driver. A kext
1203 must not call this function on an interface the kext does not
1204 own.
1205 @param interface The interface.
1206 @param addrlen The new address length.
1207 @result 0 on success otherwise the errno error.
1208 */
b0d623f7 1209extern errno_t ifnet_set_addrlen(ifnet_t interface, u_int8_t addrlen);
91447636
A
1210
1211/*!
1212 @function ifnet_addrlen
1213 @param interface The interface.
1214 @result The address length.
1215 */
b0d623f7 1216extern u_int8_t ifnet_addrlen(ifnet_t interface);
91447636
A
1217
1218/*!
1219 @function ifnet_set_hdrlen
1220 @discussion
1221 This function is intended to be called by the driver. A kext
1222 must not call this function on an interface the kext does not
1223 own.
1224 @param interface The interface.
1225 @param hdrlen The new header length.
1226 @result 0 on success otherwise the errno error.
1227 */
b0d623f7 1228extern errno_t ifnet_set_hdrlen(ifnet_t interface, u_int8_t hdrlen);
91447636
A
1229
1230/*!
1231 @function ifnet_hdrlen
1232 @param interface The interface.
1233 @result The header length.
1234 */
b0d623f7 1235extern u_int8_t ifnet_hdrlen(ifnet_t interface);
91447636
A
1236
1237/*!
1238 @function ifnet_set_metric
1239 @discussion
1240 This function is intended to be called by the driver. A kext
1241 must not call this function on an interface the kext does not
1242 own.
1243 @param interface The interface.
1244 @param metric The new metric.
1245 @result 0 on success otherwise the errno error.
1246 */
b0d623f7 1247extern errno_t ifnet_set_metric(ifnet_t interface, u_int32_t metric);
91447636
A
1248
1249/*!
1250 @function ifnet_metric
1251 @param interface The interface.
1252 @result The metric.
1253 */
b0d623f7 1254extern u_int32_t ifnet_metric(ifnet_t interface);
91447636
A
1255
1256/*!
1257 @function ifnet_set_baudrate
1258 @discussion
1259 This function is intended to be called by the driver. A kext
1260 must not call this function on an interface the kext does not
1261 own.
1262 @param interface The interface.
1263 @param baudrate The new baudrate.
1264 @result 0 on success otherwise the errno error.
1265 */
b0d623f7 1266extern errno_t ifnet_set_baudrate(ifnet_t interface, u_int64_t baudrate);
91447636
A
1267
1268/*!
1269 @function ifnet_baudrate
1270 @param interface The interface.
1271 @result The baudrate.
1272 */
b0d623f7 1273extern u_int64_t ifnet_baudrate(ifnet_t interface);
91447636
A
1274
1275/*!
1276 @function ifnet_stat_increment
1277 @discussion
1278 This function is intended to be called by the driver. A kext
1279 must not call this function on an interface the kext does not
1280 own.
1281 @param interface The interface.
1282 @param counts A pointer to a structure containing the amount to
1283 increment each counter by. Any counts not appearing in the
1284 ifnet_counter_increment structure are handled in the stack.
1285 @result 0 on success otherwise the errno error.
1286 */
b0d623f7
A
1287extern errno_t ifnet_stat_increment(ifnet_t interface,
1288 const struct ifnet_stat_increment_param *counts);
91447636
A
1289
1290/*!
1291 @function ifnet_stat_increment_in
1292 @discussion
1293 This function is intended to be called by the driver. This
1294 function allows a driver to update the inbound interface counts.
1295 The most efficient time to update these counts is when calling
1296 ifnet_input.
b0d623f7 1297
91447636
A
1298 A lock protects the counts, this makes the increment functions
1299 expensive. The increment function will update the lastchanged
1300 value.
1301 @param interface The interface.
1302 @param packets_in The number of additional packets received.
1303 @param bytes_in The number of additional bytes received.
1304 @param errors_in The number of additional receive errors.
1305 @result 0 on success otherwise the errno error.
1306 */
b0d623f7
A
1307extern errno_t ifnet_stat_increment_in(ifnet_t interface,
1308 u_int32_t packets_in, u_int32_t bytes_in, u_int32_t errors_in);
91447636
A
1309
1310/*!
1311 @function ifnet_stat_increment_out
1312 @discussion
1313 This function is intended to be called by the driver. This
b0d623f7
A
1314 function allows a driver to update the outbound interface
1315 counts.
1316
91447636
A
1317 A lock protects the counts, this makes the increment functions
1318 expensive. The increment function will update the lastchanged
1319 value.
1320 @param interface The interface.
1321 @param packets_out The number of additional packets sent.
1322 @param bytes_out The number of additional bytes sent.
1323 @param errors_out The number of additional send errors.
1324 @result 0 on success otherwise the errno error.
1325 */
b0d623f7
A
1326extern errno_t ifnet_stat_increment_out(ifnet_t interface,
1327u_int32_t packets_out, u_int32_t bytes_out, u_int32_t errors_out);
91447636
A
1328
1329/*!
1330 @function ifnet_set_stat
1331 @discussion
1332 This function is intended to be called by the driver. A kext
1333 must not call this function on an interface the kext does not
1334 own.
b0d623f7 1335
91447636
A
1336 The one exception would be the case where a kext wants to zero
1337 all of the counters.
1338 @param interface The interface.
1339 @param counts The new stats values.
1340 @result 0 on success otherwise the errno error.
1341 */
b0d623f7
A
1342extern errno_t ifnet_set_stat(ifnet_t interface,
1343 const struct ifnet_stats_param *stats);
91447636
A
1344
1345/*!
1346 @function ifnet_stat
1347 @param interface The interface.
1348 @param out_stats Storage for the values.
1349 @result 0 on success otherwise the errno error.
1350 */
b0d623f7
A
1351extern errno_t ifnet_stat(ifnet_t interface,
1352 struct ifnet_stats_param *out_stats);
91447636
A
1353
1354/*!
1355 @function ifnet_set_promiscuous
1356 @discussion Enable or disable promiscuous mode on the interface. The
1357 interface keeps an internal count of the number of times
1358 promiscuous mode has been enabled. Promiscuous mode is only
1359 disabled when this count reaches zero. Be sure to disable
1360 promiscuous mode only once for every time you enable it.
1361 @param interface The interface to toggle promiscuous mode on.
1362 @param on If set, the number of promicuous on requests will be
1363 incremented. If this is the first requrest, promiscuous mode
1364 will be enabled. If this is not set, the number of promiscous
1365 clients will be decremented. If this causes the number to reach
1366 zero, promiscuous mode will be disabled.
1367 @result 0 on success otherwise the errno error.
1368 */
b0d623f7 1369extern errno_t ifnet_set_promiscuous(ifnet_t interface, int on);
91447636
A
1370
1371/*!
1372 @function ifnet_touch_lastchange
1373 @discussion Updates the lastchange value to now.
1374 @param interface The interface.
1375 @result 0 on success otherwise the errno error.
1376 */
b0d623f7 1377extern errno_t ifnet_touch_lastchange(ifnet_t interface);
91447636
A
1378
1379/*!
1380 @function ifnet_lastchange
1381 @param interface The interface.
1382 @param last_change A timeval struct to copy the last time changed in
1383 to.
1384 */
b0d623f7 1385extern errno_t ifnet_lastchange(ifnet_t interface, struct timeval *last_change);
91447636
A
1386
1387/*!
1388 @function ifnet_get_address_list
1389 @discussion Get a list of addresses on the interface. Passing NULL
1390 for the interface will return a list of all addresses. The
1391 addresses will have their reference count bumped so they will
1392 not go away. Calling ifnet_free_address_list will decrement the
1393 refcount and free the array. If you wish to hold on to a
1394 reference to an ifaddr_t, be sure to bump the reference count
1395 before calling ifnet_free_address_list.
1396 @param interface The interface.
1397 @param addresses A pointer to a NULL terminated array of ifaddr_ts.
1398 @result 0 on success otherwise the errno error.
1399 */
b0d623f7 1400extern errno_t ifnet_get_address_list(ifnet_t interface, ifaddr_t **addresses);
91447636
A
1401
1402/*!
1403 @function ifnet_get_address_list_family
1404 @discussion Get a list of addresses on the interface. Passing NULL
1405 for the interface will return a list of all addresses. The
1406 addresses will have their reference count bumped so they will
1407 not go away. Calling ifnet_free_address_list will decrement the
1408 refcount and free the array. If you wish to hold on to a
1409 reference to an ifaddr_t, be sure to bump the reference count
1410 before calling ifnet_free_address_list. Unlike
1411 ifnet_get_address_list, this function lets the caller specify
1412 the address family to get a list of only a specific address type.
1413 @param interface The interface.
1414 @param addresses A pointer to a NULL terminated array of ifaddr_ts.
1415 @result 0 on success otherwise the errno error.
1416 */
b0d623f7
A
1417extern errno_t ifnet_get_address_list_family(ifnet_t interface,
1418 ifaddr_t **addresses, sa_family_t family);
91447636
A
1419
1420/*!
1421 @function ifnet_free_address_list
1422 @discussion Free a list of addresses returned from
1423 ifnet_get_address_list. Decrements the refcounts and frees the
1424 memory used for the array of references.
1425 @param addresses An array of ifaddr_ts.
1426 */
b0d623f7 1427extern void ifnet_free_address_list(ifaddr_t *addresses);
91447636
A
1428
1429/*!
1430 @function ifnet_set_lladdr
1431 @discussion Sets the link-layer address for this interface.
1432 @param interface The interface the link layer address is being
1433 changed on.
1434 @param lladdr A pointer to the raw link layer address (pointer to
1435 the 6 byte ethernet address for ethernet).
1436 @param lladdr_len The length, in bytes, of the link layer address.
1437 */
b0d623f7
A
1438extern errno_t ifnet_set_lladdr(ifnet_t interface, const void *lladdr,
1439 size_t lladdr_len);
91447636
A
1440
1441/*!
1442 @function ifnet_lladdr_copy_bytes
1443 @discussion Copies the bytes of the link-layer address in to the
1444 specified buffer.
1445 @param interface The interface to copy the link-layer address from.
1446 @param lladdr The buffer to copy the link-layer address in to.
1447 @param length The length of the buffer. This value must match the
1448 length of the link-layer address.
1449 */
b0d623f7
A
1450extern errno_t ifnet_lladdr_copy_bytes(ifnet_t interface, void *lladdr,
1451 size_t length);
91447636
A
1452
1453#ifdef KERNEL_PRIVATE
1454/*!
1455 @function ifnet_lladdr
1456 @discussion Returns a pointer to the link-layer address.
1457 @param interface The interface the link-layer address is on.
1458 */
b0d623f7
A
1459extern void *ifnet_lladdr(ifnet_t interface);
1460#endif /* KERNEL_PRIVATE */
91447636
A
1461
1462/*!
1463 @function ifnet_llbroadcast_copy_bytes
1464 @discussion Retrieves the link-layer broadcast address for this
1465 interface.
1466 @param interface The interface.
1467 @param addr A buffer to copy the broadcast address in to.
1468 @param bufferlen The length of the buffer at addr.
1469 @param addr_len On return, the length of the broadcast address.
1470 @param lladdr_len The length, in bytes, of the link layer address.
1471 */
b0d623f7
A
1472extern errno_t ifnet_llbroadcast_copy_bytes(ifnet_t interface, void *addr,
1473 size_t bufferlen, size_t *addr_len);
91447636
A
1474
1475#ifdef KERNEL_PRIVATE
1476/*!
1477 @function ifnet_set_lladdr_and_type
1478 @discussion Sets the link-layer address as well as the type field in
1479 the sockaddr_dl. Support for setting the type was added for vlan
1480 and bond interfaces.
1481 @param interface The interface the link layer address is being
1482 changed on.
1483 @param lladdr A pointer to the raw link layer address (pointer to
1484 the 6 byte ethernet address for ethernet).
1485 @param lladdr_len The length, in bytes, of the link layer address.
1486 @param type The link-layer address type.
1487 */
b0d623f7
A
1488extern errno_t ifnet_set_lladdr_and_type(ifnet_t interface, const void *lladdr,
1489 size_t length, u_char type);
1490#endif /* KERNEL_PRIVATE */
91447636 1491
2d21ac55
A
1492/*!
1493 @function ifnet_resolve_multicast
1494 @discussion Resolves a multicast address for an attached protocol to
1495 a link-layer address. If a link-layer address is passed in, the
1496 interface will verify that it is a valid multicast address.
1497 @param interface The interface.
1498 @param proto_addr A protocol address to be converted to a link-layer
1499 address.
1500 @param ll_addr Storage for the resulting link-layer address.
1501 @param ll_len Length of the storage for the link-layer address.
1502 @result 0 on success. EOPNOTSUPP indicates the multicast address was
1503 not supported or could not be translated. Other errors may
1504 indicate other failures.
1505 */
b0d623f7
A
1506extern errno_t ifnet_resolve_multicast(ifnet_t ifp,
1507 const struct sockaddr *proto_addr, struct sockaddr *ll_addr, size_t ll_len);
2d21ac55 1508
91447636
A
1509/*!
1510 @function ifnet_add_multicast
1511 @discussion Joins a multicast and returns an ifmultiaddr_t with the
1512 reference count incremented for you. You are responsible for
1513 decrementing the reference count after calling
1514 ifnet_remove_multicast and making sure you no longer have any
1515 references to the multicast.
1516 @param interface The interface.
1517 @param maddr The multicast address to join. Either a physical
1518 address or logical address to be translated to a physical
1519 address.
1520 @param multicast The resulting ifmultiaddr_t multicast address.
1521 @result 0 on success otherwise the errno error.
1522 */
b0d623f7
A
1523extern errno_t ifnet_add_multicast(ifnet_t interface,
1524 const struct sockaddr *maddr, ifmultiaddr_t *multicast);
91447636
A
1525
1526/*!
1527 @function ifnet_remove_multicast
1528 @discussion Causes the interface to leave the multicast group. The
1529 stack keeps track of how many times ifnet_add_multicast has been
1530 called for a given multicast address. The multicast will only be
1531 removed when the number of times ifnet_remove_multicast has been
1532 called matches the number of times ifnet_add_multicast has been
1533 called.
b0d623f7 1534
91447636
A
1535 The memory for the multicast address is not actually freed until
1536 the separate reference count has reached zero. Some parts of the
1537 stack may keep a pointer to the multicast even after that
1538 multicast has been removed from the interface.
b0d623f7 1539
91447636
A
1540 When an interface is detached, all of the multicasts are
1541 removed. If the interface of the multicast passed in is no
1542 longer attached, this function will gracefully return,
1543 performing no work.
b0d623f7 1544
91447636
A
1545 It is the callers responsibility to release the multicast
1546 address after calling this function.
1547 @param multicast The multicast to be removed.
1548 @result 0 on success otherwise the errno error.
1549 */
b0d623f7 1550extern errno_t ifnet_remove_multicast(ifmultiaddr_t multicast);
91447636
A
1551
1552/*!
1553 @function ifnet_get_multicast_list
1554 @discussion Retrieves a list of multicast address the interface is
1555 set to receive. This function allocates and returns an array of
1556 references to the various multicast addresses. The multicasts
1557 have their reference counts bumped on your behalf. Calling
1558 ifnet_free_multicast_list will decrement the reference counts
1559 and free the array.
1560 @param interface The interface.
1561 @param multicasts A pointer to a NULL terminated array of references
1562 to the multicast addresses.
1563 @result 0 on success otherwise the errno error.
1564 */
b0d623f7
A
1565extern errno_t ifnet_get_multicast_list(ifnet_t interface,
1566 ifmultiaddr_t **addresses);
91447636
A
1567
1568/*!
1569 @function ifnet_free_multicast_list
1570 @discussion Frees a list of multicasts returned by
1571 ifnet_get_multicast_list. Decrements the refcount on each
1572 multicast address and frees the array.
1573 @param multicasts An array of references to the multicast addresses.
1574 @result 0 on success otherwise the errno error.
1575 */
b0d623f7 1576extern void ifnet_free_multicast_list(ifmultiaddr_t *multicasts);
91447636
A
1577
1578/*!
1579 @function ifnet_find_by_name
1580 @discussion Find an interface by the name including the unit number.
1581 Caller must call ifnet_release on any non-null interface return
1582 value.
1583 @param name The name of the interface, including any unit number
1584 (i.e. "en0").
1585 @param interface A pointer to an interface reference. This will be
1586 filled in if a matching interface is found.
1587 @result 0 on success otherwise the errno error.
1588 */
b0d623f7 1589extern errno_t ifnet_find_by_name(const char *ifname, ifnet_t *interface);
91447636
A
1590
1591/*!
1592 @function ifnet_list_get
1593 @discussion Get a list of attached interfaces. List will be set to
1594 point to an array allocated by ifnet_list_get. The interfaces
1595 are refcounted and the counts will be incremented before the
1596 function returns. The list of interfaces must be freed using
1597 ifnet_list_free.
1598 @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To
1599 find interfaces of all families, use IFNET_FAMILY_ANY.
1600 @param interfaces A pointer to an array of interface references.
1601 @param count A pointer that will be filled in with the number of
1602 matching interfaces in the array.
1603 @result 0 on success otherwise the errno error.
1604 */
b0d623f7
A
1605extern errno_t ifnet_list_get(ifnet_family_t family, ifnet_t **interfaces,
1606 u_int32_t *count);
91447636 1607
4a3eedf9
A
1608#ifdef KERNEL_PRIVATE
1609/*!
1610 @function ifnet_list_get_all
1611 @discussion Get a list of attached interfaces. List will be set to
1612 point to an array allocated by ifnet_list_get. The interfaces
1613 are refcounted and the counts will be incremented before the
1614 function returns. The list of interfaces must be freed using
1615 ifnet_list_free. This is similar to ifnet_list_get, except
1616 that it includes interfaces that are detaching.
1617 @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To
1618 find interfaces of all families, use IFNET_FAMILY_ANY.
1619 @param interfaces A pointer to an array of interface references.
1620 @param count A pointer that will be filled in with the number of
1621 matching interfaces in the array.
1622 @result 0 on success otherwise the errno error.
1623 */
b0d623f7
A
1624extern errno_t ifnet_list_get_all(ifnet_family_t family, ifnet_t **interfaces,
1625 u_int32_t *count);
4a3eedf9
A
1626#endif /* KERNEL_PRIVATE */
1627
91447636
A
1628/*!
1629 @function ifnet_list_free
1630 @discussion Free a list of interfaces returned by ifnet_list_get.
1631 Decrements the reference count on each interface and frees the
1632 array of references. If you keep a reference to an interface, be
1633 sure to increment the reference count before calling
1634 ifnet_list_free.
1635 @param interfaces An array of interface references from ifnet_list_get.
1636 */
b0d623f7 1637extern void ifnet_list_free(ifnet_t *interfaces);
91447636 1638
b0d623f7
A
1639/******************************************************************************/
1640/* ifaddr_t accessors */
1641/******************************************************************************/
91447636
A
1642
1643/*!
1644 @function ifaddr_reference
1645 @discussion Increment the reference count of an address tied to an
1646 interface.
1647 @param ifaddr The interface address.
1648 @result 0 upon success
1649 */
b0d623f7 1650extern errno_t ifaddr_reference(ifaddr_t ifaddr);
91447636
A
1651
1652/*!
1653 @function ifaddr_release
1654 @discussion Decrements the reference count of and possibly frees an
1655 address tied to an interface.
1656 @param ifaddr The interface address.
1657 @result 0 upon success
1658 */
b0d623f7 1659extern errno_t ifaddr_release(ifaddr_t ifaddr);
91447636
A
1660
1661/*!
1662 @function ifaddr_address
1663 @discussion Copies the address out of the ifaddr.
1664 @param ifaddr The interface address.
1665 @param out_addr The sockaddr storage for the address.
1666 @param addr_size The size of the storage for the address.
1667 @result 0 upon success
1668 */
b0d623f7
A
1669extern errno_t ifaddr_address(ifaddr_t ifaddr, struct sockaddr *out_addr,
1670 u_int32_t addr_size);
91447636
A
1671
1672/*!
1673 @function ifaddr_address
1674 @discussion Returns the address family of the address.
1675 @param ifaddr The interface address.
1676 @result 0 on failure, address family on success.
1677 */
b0d623f7 1678extern sa_family_t ifaddr_address_family(ifaddr_t ifaddr);
91447636
A
1679
1680/*!
1681 @function ifaddr_dstaddress
1682 @discussion Copies the destination address out of the ifaddr.
1683 @param ifaddr The interface address.
1684 @param out_dstaddr The sockaddr storage for the destination address.
1685 @param dstaddr_size The size of the storage for the destination address.
1686 @result 0 upon success
1687 */
b0d623f7
A
1688extern errno_t ifaddr_dstaddress(ifaddr_t ifaddr, struct sockaddr *out_dstaddr,
1689 u_int32_t dstaddr_size);
91447636
A
1690
1691/*!
1692 @function ifaddr_netmask
1693 @discussion Copies the netmask out of the ifaddr.
1694 @param ifaddr The interface address.
1695 @param out_netmask The sockaddr storage for the netmask.
1696 @param netmask_size The size of the storage for the netmask.
1697 @result 0 upon success
1698 */
b0d623f7
A
1699extern errno_t ifaddr_netmask(ifaddr_t ifaddr, struct sockaddr *out_netmask,
1700 u_int32_t netmask_size);
91447636
A
1701
1702/*!
1703 @function ifaddr_ifnet
1704 @discussion Returns the interface the address is attached to. The
1705 reference is only valid until the ifaddr is released. If you
1706 need to hold a reference to the ifnet for longer than you hold a
1707 reference to the ifaddr, increment the reference using
1708 ifnet_reference.
1709 @param ifaddr The interface address.
1710 @result A reference to the interface the address is attached to.
1711 */
b0d623f7 1712extern ifnet_t ifaddr_ifnet(ifaddr_t ifaddr);
91447636
A
1713
1714/*!
1715 @function ifaddr_withaddr
1716 @discussion Returns an interface address with the address specified.
1717 Increments the reference count on the ifaddr before returning to
1718 the caller. Caller is responsible for calling ifaddr_release.
1719 @param address The address to search for.
1720 @result A reference to the interface address.
1721 */
b0d623f7 1722extern ifaddr_t ifaddr_withaddr(const struct sockaddr *address);
91447636
A
1723
1724/*!
1725 @function ifaddr_withdstaddr
1726 @discussion Returns an interface address for the interface address
1727 that matches the destination when the netmask is applied.
1728 Increments the reference count on the ifaddr before returning to
1729 the caller. Caller is responsible for calling ifaddr_release.
1730 @param destination The destination to search for.
1731 @result A reference to the interface address.
1732 */
b0d623f7 1733extern ifaddr_t ifaddr_withdstaddr(const struct sockaddr *destination);
91447636
A
1734
1735/*!
1736 @function ifaddr_withnet
1737 @discussion Returns an interface address for the interface with the
1738 network described by net. Increments the reference count on the
1739 ifaddr before returning to the caller. Caller is responsible for
1740 calling ifaddr_release.
1741 @param net The network to search for.
1742 @result A reference to the interface address.
1743 */
b0d623f7 1744extern ifaddr_t ifaddr_withnet(const struct sockaddr *net);
91447636
A
1745
1746/*!
1747 @function ifaddr_withroute
1748 @discussion Returns an interface address given a destination and
1749 gateway. Increments the reference count on the ifaddr before
1750 returning to the caller. Caller is responsible for calling
1751 ifaddr_release.
1752 @param flags Routing flags. See net/route.h, RTF_GATEWAY etc.
1753 @param destination The destination to search for.
1754 @param gateway A gateway to search for.
1755 @result A reference to the interface address.
1756 */
b0d623f7
A
1757extern ifaddr_t ifaddr_withroute(int flags, const struct sockaddr *destination,
1758 const struct sockaddr *gateway);
91447636
A
1759
1760/*!
1761 @function ifaddr_findbestforaddr
1762 @discussion Finds the best local address assigned to a specific
1763 interface to use when communicating with another address.
1764 Increments the reference count on the ifaddr before returning to
1765 the caller. Caller is responsible for calling ifaddr_release.
1766 @param addr The remote address.
1767 @param interface The local interface.
1768 @result A reference to the interface address.
1769 */
b0d623f7
A
1770extern ifaddr_t ifaddr_findbestforaddr(const struct sockaddr *addr,
1771 ifnet_t interface);
91447636 1772
b0d623f7
A
1773/******************************************************************************/
1774/* ifmultiaddr_t accessors */
1775/******************************************************************************/
91447636
A
1776
1777/*!
1778 @function ifmaddr_reference
1779 @discussion Increment the reference count of an interface multicast
1780 address.
1781 @param ifmaddr The interface multicast address.
1782 @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
1783 */
b0d623f7 1784extern errno_t ifmaddr_reference(ifmultiaddr_t ifmaddr);
91447636
A
1785
1786/*!
1787 @function ifmaddr_release
1788 @discussion Decrement the reference count of an interface multicast
1789 address. If the reference count reaches zero, the ifmultiaddr
1790 will be removed from the interface and the ifmultiaddr will be
1791 freed.
1792 @param ifmaddr The interface multicast address.
1793 @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
1794 */
b0d623f7 1795extern errno_t ifmaddr_release(ifmultiaddr_t ifmaddr);
91447636
A
1796
1797/*!
1798 @function ifmaddr_address
1799 @discussion Copies the multicast address to out_multicast.
1800 @param out_multicast Storage for a sockaddr.
1801 @param addr_size Size of the storage.
1802 @result 0 on success.
1803 */
b0d623f7
A
1804extern errno_t ifmaddr_address(ifmultiaddr_t ifmaddr,
1805 struct sockaddr *out_multicast, u_int32_t addr_size);
91447636
A
1806
1807/*!
1808 @function ifmaddr_lladdress
1809 @discussion Copies the link layer multicast address to
1810 out_link_layer_multicast.
1811 @param out_link_layer_multicast Storage for a sockaddr.
1812 @param addr_size Size of the storage.
1813 @result 0 on success.
1814 */
b0d623f7
A
1815extern errno_t ifmaddr_lladdress(ifmultiaddr_t ifmaddr,
1816 struct sockaddr *out_link_layer_multicast, u_int32_t addr_size);
91447636
A
1817
1818/*!
1819 @function ifmaddr_ifnet
1820 @discussion Returns the interface this multicast address is attached
1821 to. The interface reference count is not bumped by this
1822 function. The interface is only valid as long as you don't
1823 release the refernece to the multiast address. If you need to
1824 maintain your pointer to the ifnet, call ifnet_reference
1825 followed by ifnet_release when you're finished.
1826 @param ifmaddr The interface multicast address.
1827 @result A reference to the interface.
1828 */
b0d623f7 1829extern ifnet_t ifmaddr_ifnet(ifmultiaddr_t ifmaddr);
91447636
A
1830
1831__END_DECLS
1832
b0d623f7 1833#endif /* __KPI_INTERFACE__ */