2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 @header kpi_interface.h
32 This header defines an API to interact with network interfaces in
33 the kernel. The network interface KPI may be used to implement
34 network interfaces or to attach protocols to existing interfaces.
37 #ifndef __KPI_INTERFACE__
38 #define __KPI_INTERFACE__
39 #include <sys/kernel_types.h>
43 typedef __uint8_t sa_family_t
;
49 struct kern_event_msg
;
51 struct ifnet_demux_desc
;
54 @enum Interface Families
55 @abstract Constants defining interface families.
56 @constant IFNET_FAMILY_ANY Match interface of any family type.
57 @constant IFNET_FAMILY_LOOPBACK A software loopback interface.
58 @constant IFNET_FAMILY_ETHERNET An Ethernet interface.
59 @constant IFNET_FAMILY_SLIP A SLIP interface.
60 @constant IFNET_FAMILY_TUN A tunnel interface.
61 @constant IFNET_FAMILY_VLAN A virtual LAN interface.
62 @constant IFNET_FAMILY_PPP A PPP interface.
63 @constant IFNET_FAMILY_PVC A PVC interface.
64 @constant IFNET_FAMILY_DISC A DISC interface.
65 @constant IFNET_FAMILY_MDECAP A MDECAP interface.
66 @constant IFNET_FAMILY_GIF A generic tunnel interface.
67 @constant IFNET_FAMILY_FAITH A FAITH (IPv4/IPv6 translation) interface.
68 @constant IFNET_FAMILY_STF A 6to4 interface.
69 @constant IFNET_FAMILY_FIREWIRE An IEEE 1394 (firewire) interface.
70 @constant IFNET_FAMILY_BOND A virtual bonded interface.
75 IFNET_FAMILY_LOOPBACK
= 1,
76 IFNET_FAMILY_ETHERNET
= 2,
77 IFNET_FAMILY_SLIP
= 3,
79 IFNET_FAMILY_VLAN
= 5,
82 IFNET_FAMILY_DISC
= 8,
83 IFNET_FAMILY_MDECAP
= 9,
84 IFNET_FAMILY_GIF
= 10,
85 IFNET_FAMILY_FAITH
= 11,
86 IFNET_FAMILY_STF
= 12,
87 IFNET_FAMILY_FIREWIRE
= 13,
88 IFNET_FAMILY_BOND
= 14
91 @typedef ifnet_family_t
92 @abstract Storage type for the interface family.
94 typedef u_int32_t ifnet_family_t
;
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.
106 BPF_MODE_DISABLED
= 0,
109 BPF_MODE_INPUT_OUTPUT
= 3
112 @typedef bpf_tap_mode
113 @abstract Mode for tapping. BPF_MODE_DISABLED/BPF_MODE_INPUT_OUTPUT etc.
115 typedef u_int32_t bpf_tap_mode
;
118 @typedef protocol_family_t
119 @abstract Storage type for the protocol family.
121 typedef u_int32_t protocol_family_t
;
124 @enum Interface Abilities
125 @abstract Constants defining interface offload support.
126 @constant IFNET_CSUM_IP Hardware will calculate IPv4 checksums.
127 @constant IFNET_CSUM_TCP Hardware will calculate TCP checksums.
128 @constant IFNET_CSUM_UDP Hardware will calculate UDP checksums.
129 @constant IFNET_CSUM_FRAGMENT Hardware will checksum IP fragments.
130 @constant IFNET_IP_FRAGMENT Hardware will fragment IP packets.
131 @constant IFNET_VLAN_TAGGING Hardware will generate VLAN headers.
132 @constant IFNET_VLAN_MTU Hardware supports VLAN MTU.
136 IFNET_CSUM_IP
= 0x00000001,
137 IFNET_CSUM_TCP
= 0x00000002,
138 IFNET_CSUM_UDP
= 0x00000004,
139 IFNET_CSUM_FRAGMENT
= 0x00000008,
140 IFNET_IP_FRAGMENT
= 0x00000010,
141 #ifdef KERNEL_PRIVATE
142 IFNET_CSUM_SUM16
= 0x00001000,
144 IFNET_VLAN_TAGGING
= 0x00010000,
145 IFNET_VLAN_MTU
= 0x00020000,
148 @typedef ifnet_offload_t
149 @abstract Flags indicating the offload support of the interface.
151 typedef u_int32_t ifnet_offload_t
;
156 * These are function pointers you supply to the kernel in the interface.
159 @typedef bpf_packet_func
161 @discussion bpf_packet_func The bpf_packet_func is used to intercept
162 inbound and outbound packets. The tap function will never free
163 the mbuf. The tap function will only copy the mbuf in to various
164 bpf file descriptors tapping this interface.
165 @param interface The interface being sent or received on.
166 @param data The packet to be transmitted or received.
167 @result An errno value or zero upon success.
169 /* Fast path - do not block or spend excessive amounts of time */
170 typedef errno_t (*bpf_packet_func
)(ifnet_t interface
, mbuf_t data
);
173 @typedef ifnet_output_func
175 @discussion ifnet_output_func is used to transmit packets. The stack
176 will pass fully formed packets, including frame header, to the
177 ifnet_output function for an interface. The driver is
178 responsible for freeing the mbuf.
179 @param interface The interface being sent on.
180 @param data The packet to be sent.
182 /* Fast path - do not block or spend excessive amounts of time */
183 typedef errno_t (*ifnet_output_func
)(ifnet_t interface
, mbuf_t data
);
186 @typedef ifnet_ioctl_func
187 @discussion ifnet_ioctl_func is used to communicate ioctls from the
189 @param interface The interface the ioctl is being sent to.
190 @param proto_family The protocol family to handle the ioctl, may be
191 zero for no protocol_family.
192 @param cmd The ioctl command.
193 @param data A pointer to any data related to the ioctl.
195 typedef errno_t (*ifnet_ioctl_func
)(ifnet_t interface
, u_int32_t cmd
, void *data
);
198 @typedef ifnet_set_bpf_tap
199 @discussion ifnet_set_bpf_tap is used to set the bpf tap function to
200 be called when packets are sent and/or received.
201 @param interface The interface the bpf tap function is being set on.
202 @param mode Sets the mode of the tap to either disabled, input,
203 output, or input/output.
204 @param callback A function pointer to be called when a packet is
207 typedef errno_t (*ifnet_set_bpf_tap
)(ifnet_t interface
, bpf_tap_mode mode
,
208 bpf_packet_func callback
);
211 @typedef ifnet_detached_func
212 @discussion ifnet_detached_func is called an interface is detached
213 from the list of interfaces. When ifnet_detach is called, it may
214 not detach the interface immediately if protocols are attached.
215 ifnet_detached_func is used to notify the interface that it has
216 been detached from the networking stack. This is the last
217 function that will be called on an interface. Until this
218 function returns, you must not unload a kext supplying function
219 pointers to this interface, even if ifnet_detacah has been
220 called. Your detach function may be called during your call to
222 @param interface The interface that has been detached.
225 typedef void (*ifnet_detached_func
)(ifnet_t interface
);
228 @typedef ifnet_demux_func
229 @discussion ifnet_demux_func is called for each inbound packet to determine
230 which protocol family the packet belongs to. This information is then
231 used by the stack to determine which protocol to pass the packet to.
232 This function may return protocol families for protocols that are
233 not attached. If the protocol family has not been attached to the
234 interface, the packet will be discarded.
235 @param interface The interface the packet was received on.
236 @param packet The mbuf containing the packet.
237 @param frame_header A pointer to the frame header.
238 @param protocol_family Upon return, the protocol family matching the
239 packet should be stored here.
241 If the result is zero, processing will continue normally.
242 If the result is EJUSTRETURN, processing will stop but the packet will not be freed.
243 If the result is anything else, the processing will stop and the packet will be freed.
245 typedef errno_t (*ifnet_demux_func
)(ifnet_t interface
, mbuf_t packet
,
247 protocol_family_t
*protocol_family
);
250 @typedef ifnet_event_func
251 @discussion ifnet_event_func is called when an event occurs on a
253 @param interface The interface the event occurred on.
254 @param event_ptr Pointer to a kern_event structure describing the
257 typedef void (*ifnet_event_func
)(ifnet_t interface
, const struct kev_msg
*msg
);
260 @typedef ifnet_framer_func
261 @discussion ifnet_framer_func is called for each outbound packet to
262 give the interface an opportunity to prepend interface specific
264 @param interface The interface the packet is being sent on.
265 @param packet Pointer to the mbuf containing the packet, caller may
266 set this to a different mbuf upon return. This can happen if the
267 frameout function needs to prepend another mbuf to the chain to
268 have enough space for the header.
269 @param dest The higher layer protocol destination (i.e. IP address).
270 @param dest_linkaddr The link layer address as determined by the
271 protocol's pre-output function.
272 @param frame_type The frame type as determined by the protocol's
275 If the result is zero, processing will continue normally.
276 If the result is EJUSTRETURN, processing will stop but the packet will not be freed.
277 If the result is anything else, the processing will stop and the packet will be freed.
279 typedef errno_t (*ifnet_framer_func
)(ifnet_t interface
, mbuf_t
*packet
,
280 const struct sockaddr
*dest
,
281 const char *desk_linkaddr
,
282 const char *frame_type
);
285 @typedef ifnet_add_proto_func
286 @discussion if_add_proto_func is called by the stack when a protocol
287 is attached to an interface. This gives the interface an
288 opportunity to get a list of protocol description structures
289 for demuxing packets to this protocol (demux descriptors).
290 @param interface The interface the protocol will be attached to.
291 @param protocol_family The family of the protocol being attached.
292 @param demux_array An array of demux descriptors that describe
293 the interface specific ways of identifying packets belonging
294 to this protocol family.
295 @param demux_count The number of demux descriptors in the array.
297 If the result is zero, processing will continue normally.
298 If the result is anything else, the add protocol will be aborted.
300 typedef errno_t (*ifnet_add_proto_func
)(ifnet_t interface
,
301 protocol_family_t protocol_family
,
302 const struct ifnet_demux_desc
*demux_array
,
303 u_int32_t demux_count
);
306 @typedef if_del_proto_func
307 @discussion if_del_proto_func is called by the stack when a protocol
308 is being detached from an interface. This gives the interface an
309 opportunity to free any storage related to this specific
310 protocol being attached to this interface.
311 @param interface The interface the protocol will be detached from.
312 @param protocol_family The family of the protocol being detached.
314 If the result is zero, processing will continue normally.
315 If the result is anything else, the detach will continue
316 and the error will be returned to the caller.
318 typedef errno_t (*ifnet_del_proto_func
)(ifnet_t interface
,
319 protocol_family_t protocol_family
);
322 @typedef ifnet_check_multi
323 @discussion ifnet_check_multi is called for each multicast address
324 added to an interface. This gives the interface an opportunity
325 to reject invalid multicast addresses before they are attached
328 To prevent an address from being added to your multicast list,
329 return EADDRNOTAVAIL. If you don't know how to parse/translate
330 the address, return EOPNOTSUPP.
331 @param The interface.
332 @param mcast The multicast address.
334 Zero upon success, EADDRNOTAVAIL on invalid multicast,
335 EOPNOTSUPP for addresses the interface does not understand.
337 typedef errno_t (*ifnet_check_multi
)(ifnet_t interface
,
338 const struct sockaddr
* mcast
);
341 @typedef proto_media_input
342 @discussion proto_media_input is called for all inbound packets for
343 a specific protocol on a specific interface. This function is
344 registered on an interface using ifnet_attach_protocol.
345 @param ifp The interface the packet was received on.
346 @param protocol_family The protocol of the packet received.
347 @param packet The packet being input.
348 @param header The frame header.
350 If the result is zero, the caller will assume the packet was passed
352 If the result is non-zero and not EJUSTRETURN, the caller will free
355 typedef errno_t (*proto_media_input
)(ifnet_t ifp
, protocol_family_t protocol
,
356 mbuf_t packet
, char* header
);
359 @typedef proto_media_preout
360 @discussion proto_media_preout is called just before the packet
361 is transmitted. This gives the proto_media_preout function an
362 opportunity to specify the media specific frame type and
364 @param ifp The interface the packet will be sent on.
365 @param protocol_family The protocol of the packet being sent
367 @param packet The packet being sent.
368 @param dest The protocol level destination address.
369 @param route A pointer to the routing structure for the packet.
370 @param frame_type The media specific frame type.
371 @param link_layer_dest The media specific destination.
373 If the result is zero, processing will continue normally. If the
374 result is non-zero, processing will stop. If the result is
375 non-zero and not EJUSTRETURN, the packet will be freed by the
378 typedef errno_t (*proto_media_preout
)(ifnet_t ifp
, protocol_family_t protocol
,
379 mbuf_t
*packet
, const struct sockaddr
*dest
,
380 void *route
, char *frame_type
, char *link_layer_dest
);
383 @typedef proto_media_event
384 @discussion proto_media_event is called to notify this layer of
385 interface specific events.
386 @param ifp The interface.
387 @param protocol_family The protocol family.
388 @param kev_msg The event.
390 typedef void (*proto_media_event
)(ifnet_t ifp
, protocol_family_t protocol
,
391 const struct kev_msg
*event
);
394 @typedef proto_media_ioctl
395 @discussion proto_media_event allows this layer to handle ioctls.
396 When an ioctl is handled, it is passed to the interface filters,
397 protocol filters, protocol, and interface. If you do not support
398 this ioctl, return EOPNOTSUPP. If you successfully handle the
399 ioctl, return zero. If you return any error other than
400 EOPNOTSUPP, other parts of the stack may not get an opportunity
401 to process the ioctl. If you return EJUSTRETURN, processing will
402 stop and a result of zero will be returned to the caller.
403 @param ifp The interface.
404 @param protocol_family The protocol family.
405 @param command The ioctl command.
406 @param argument The argument to the ioctl.
410 typedef errno_t (*proto_media_ioctl
)(ifnet_t ifp
, protocol_family_t protocol
,
411 u_int32_t command
, void* argument
);
414 @typedef proto_media_detached
415 @discussion proto_media_detached notifies you that your protocol
417 @param ifp The interface.
418 @param protocol_family The protocol family.
422 typedef errno_t (*proto_media_detached
)(ifnet_t ifp
, protocol_family_t protocol
);
426 @typedef proto_media_resolve_multi
427 @discussion proto_media_resolve_multi is called to resolve a
428 protocol layer mulitcast address to a link layer multicast
430 @param ifp The interface.
431 @param proto_addr The protocol address.
432 @param out_ll A sockaddr_dl to copy the link layer multicast in to.
433 @param ll_len The length of data allocated for out_ll.
434 @result Return zero on success or an errno error value on failure.
436 typedef errno_t (*proto_media_resolve_multi
)(ifnet_t ifp
,
437 const struct sockaddr
*proto_addr
,
438 struct sockaddr_dl
*out_ll
, size_t ll_len
);
441 @typedef proto_media_send_arp
442 @discussion proto_media_send_arp is called by the stack to generate
443 an ARP packet. This field is currently only used with IP. This
444 function should inspect the parameters and transmit an arp
445 packet using the information passed in.
446 @param ifp The interface the arp packet should be sent on.
447 @param protocol_family The protocol family of the addresses
449 @param arpop The arp operation (usually ARPOP_REQUEST or
451 @param sender_hw The value to use for the sender hardware
452 address field. If this is NULL, use the hardware address
454 @param sender_proto The value to use for the sender protocol
455 address field. This will not be NULL.
456 @param target_hw The value to use for the target hardware address.
457 If this is NULL, the target hardware address in the ARP packet
458 should be NULL and the link-layer destination for the back
459 should be a broadcast. If this is not NULL, this value should be
460 used for both the link-layer destination and the target hardware
462 @param target_proto The target protocol address. This will not be
464 @result Return zero on success or an errno error value on failure.
466 typedef errno_t (*proto_media_send_arp
)(ifnet_t ifp
,
468 const struct sockaddr_dl
* sender_hw
,
469 const struct sockaddr
* sender_proto
,
470 const struct sockaddr_dl
* target_hw
,
471 const struct sockaddr
* target_proto
);
474 @struct ifnet_stat_increment_param
475 @discussion This structure is used increment the counters on a
477 @field packets_in The number of packets received.
478 @field bytes_in The number of bytes received.
479 @field errors_in The number of receive errors.
480 @field packets_out The number of packets transmitted.
481 @field bytes_out The number of bytes transmitted.
482 @field errors_out The number of transmission errors.
483 @field collisions The number of collisions seen by this interface.
484 @field dropped The number of packets dropped.
487 struct ifnet_stat_increment_param
{
488 u_int32_t packets_in
;
492 u_int32_t packets_out
;
494 u_int32_t errors_out
;
496 u_int32_t collisions
;
501 @struct ifnet_init_params
502 @discussion This structure is used to define various properties of
503 the interface when calling ifnet_init. A copy of these values
504 will be stored in the ifnet and can not be modified while the
505 interface is attached.
506 @field uniqueid An identifier unique to this instance of the
508 @field uniqueid_len The length, in bytes, of the uniqueid.
509 @field name The interface name (i.e. en).
510 @field unit The interface unit number (en0's unit number is 0).
511 @field family The interface family.
512 @field type The interface type (see sys/if_types.h). Must be less
513 than 256. For new types, use IFT_OTHER.
514 @field output The output function for the interface. Every packet the
515 stack attempts to send through this interface will go out through
517 @field demux The function used to determine the protocol family of an
519 @field add_proto The function used to attach a protocol to this interface.
520 @field del_proto The function used to remove a protocol from this interface.
521 @field framer The function used to frame outbound packets, may be NULL.
522 @field softc Driver specific storage. This value can be retrieved from the
523 ifnet using the ifnet_softc function.
524 @field ioctl The function used to handle ioctls.
525 @field set_bpf_tap The function used to set the bpf_tap function.
526 @field detach The function called to let the driver know the interface has been detached.
527 @field event The function to notify the interface of various interface specific kernel events.
528 @field broadcast_addr The link-layer broadcast address for this interface.
529 @field broadcast_len The length of the link-layer broadcast address.
532 struct ifnet_init_params
{
533 /* used to match recycled interface */
534 const void* uniqueid
; /* optional */
535 u_int32_t uniqueid_len
; /* optional */
537 /* used to fill out initial values for interface */
538 const char* name
; /* required */
539 u_int32_t unit
; /* required */
540 ifnet_family_t family
; /* required */
541 u_int32_t type
; /* required */
542 ifnet_output_func output
; /* required */
543 ifnet_demux_func demux
; /* required */
544 ifnet_add_proto_func add_proto
; /* required */
545 ifnet_del_proto_func del_proto
; /* required */
546 ifnet_check_multi check_multi
; /* required for non point-to-point interfaces */
547 ifnet_framer_func framer
; /* optional */
548 void* softc
; /* optional */
549 ifnet_ioctl_func ioctl
; /* optional */
550 ifnet_set_bpf_tap set_bpf_tap
; /* optional */
551 ifnet_detached_func detach
; /* optional */
552 ifnet_event_func event
; /* optional */
553 const void *broadcast_addr
;/* required for non point-to-point interfaces */
554 u_int32_t broadcast_len
; /* required for non point-to-point interfaces */
558 @struct ifnet_stats_param
559 @discussion This structure is used get and set the interface
561 @field packets_in The number of packets received.
562 @field bytes_in The number of bytes received.
563 @field errors_in The number of receive errors.
564 @field packets_out The number of packets transmitted.
565 @field bytes_out The number of bytes transmitted.
566 @field errors_out The number of transmission errors.
567 @field collisions The number of collisions seen by this interface.
568 @field dropped The number of packets dropped.
571 struct ifnet_stats_param
{
572 u_int64_t packets_in
;
574 u_int64_t multicasts_in
;
577 u_int64_t packets_out
;
579 u_int64_t multicasts_out
;
580 u_int64_t errors_out
;
582 u_int64_t collisions
;
584 u_int64_t no_protocol
;
588 @struct ifnet_demux_desc
589 @discussion This structure is to identify packets that belong to a
590 specific protocol. The types supported are interface specific.
591 Ethernet supports ETHER_DESC_ETYPE2, ETHER_DESC_SAP, and
592 ETHER_DESC_SNAP. The type defines the offset in the packet where
593 the data will be matched as well as context. For example, if
594 ETHER_DESC_SNAP is specified, the only valid datalen is 5 and
595 only in the 5 bytes will only be matched when the packet header
596 indicates that the packet is a SNAP packet.
597 @field type The type of identifier data (i.e. ETHER_DESC_ETYPE2)
598 @field data A pointer to an entry of type (i.e. pointer to 0x0800).
599 @field datalen The number of bytes of data used to describe the
603 struct ifnet_demux_desc
{
610 @struct ifnet_attach_proto_param
611 @discussion This structure is used to attach a protocol to an
612 interface. This structure provides the various functions for
613 handling operations related to the protocol on the interface as
614 well as information for how to demux packets for this protocol.
615 @field demux_array An array of ifnet_demux_desc structures
616 describing the protocol.
617 @field demux_count The number of entries in the demux_array array.
618 @field input The function to be called for inbound packets.
619 @field pre_output The function to be called for outbound packets.
620 @field event The function to be called for interface events.
621 @field ioctl The function to be called for ioctls.
622 @field detached The function to be called for handling the detach.
624 #ifdef KERNEL_PRIVATE
625 #define demux_list demux_array
626 #endif /* KERNEL_PRIVATE */
628 struct ifnet_attach_proto_param
{
629 struct ifnet_demux_desc
*demux_array
; /* interface may/may not require */
630 u_int32_t demux_count
; /* interface may/may not require */
632 proto_media_input input
; /* required */
633 proto_media_preout pre_output
; /* required */
634 proto_media_event event
; /* optional */
635 proto_media_ioctl ioctl
; /* optional */
636 proto_media_detached detached
; /* optional */
637 proto_media_resolve_multi resolve
; /* optional */
638 proto_media_send_arp send_arp
; /* optional */
644 * Ifnet creation and reference counting
648 @function ifnet_allocate
649 @discussion Allocate an ifnet_t with an initial refcount of 1. Many
650 parts of the stack do not properly refcount the ifnet_t. In
651 order to avoid freeing the ifnet_t while some parts of the stack
652 may contain a reference to it, the ifnet_ts are only recycled,
653 never freed. A unique id is used to try and recycle the same
654 ifnet_t when allocating an interface. For example, for an
655 ethernet interface, the hardware address of the ethernet card is
656 usually used for the uniqueid. If a PC Card is removed and
657 inserted again, if the ethernet address of the PC card is used,
658 the same ifnet_t will be used for the card the second time it is
659 inserted. In the future, when the ifnet_t is correctly
660 refcounted by all of the stack, the interfaces may be freed and
661 the unique ids ignored.
662 @param init The initial values for the interface. These values can
663 not be changed after the interface has been allocated.
664 @param interface The interface allocated upon success.
665 @result May return ENOMEM if there is insufficient memory or EEXIST
666 if an interface with the same uniqueid and family has already
667 been allocated and is in use.
669 errno_t
ifnet_allocate(const struct ifnet_init_params
*init
, ifnet_t
*interface
);
672 @function ifnet_reference
673 @discussion Increment the reference count of the ifnet to assure
674 that it will not go away. The interface must already have at
676 @param interface The interface to increment the reference count of.
677 @result May return EINVAL if the interface is not valid.
679 errno_t
ifnet_reference(ifnet_t interface
);
682 @function ifnet_release
683 @discussion Release a reference of the ifnet, this may trigger a
684 free if the reference count reaches 0.
685 @param interface The interface to decrement the reference count of
687 @result May return EINVAL if the interface is not valid.
689 errno_t
ifnet_release(ifnet_t interface
);
692 @function ifnet_attach
693 @discussion Attaches an interface to the global interface list. The
694 interface must be setup properly before calling attach. The
695 stack will take a reference on the interface and hold it until
696 ifnet_detach is called.
698 This function is intended to be called by the driver. A kext
699 must not call this function on an interface the kext does not
701 @param interface The interface to attach.
702 @param ll_addr The link layer address of the interface. This is used
703 to fill out the first ifaddr in the list of addresses for the
704 interface. This parameter is not required for interfaces such as
705 PPP that have no link-layer address.
706 @result Will return an error if there is anything wrong with the
709 errno_t
ifnet_attach(ifnet_t interface
, const struct sockaddr_dl
*ll_addr
);
712 @function ifnet_detach
713 @discussion Detaches the interface.
715 Call this to indicate this interface is no longer valid (i.e. PC
716 Card was removed). This function will begin the process of
717 removing knowledge of this interface from the stack.
719 The function will return before the interface is detached. The
720 functions you supplied in to the interface may continue to be
721 called. When the detach has been completed, your detached
722 function will be called. Your kext must not unload until the
723 detached function has been called. The interface will be
724 properly freed when the reference count reaches zero.
726 An interface may not be attached again. You must call
727 ifnet_allocate to create a new interface to attach.
729 This function is intended to be called by the driver. A kext
730 must not call this function on an interface the kext does not
732 @param interface The interface to detach.
733 @result 0 on success, otherwise errno error.
735 errno_t
ifnet_detach(ifnet_t interface
);
738 * Interface manipulation.
742 @function ifnet_softc
743 @discussion Returns the driver's private storage on the interface.
744 @param interface Interface to retrieve the storage from.
745 @result Driver's private storage.
747 void* ifnet_softc(ifnet_t interface
);
751 @discussion Returns a pointer to the name of the interface.
752 @param interface Interface to retrieve the name from.
753 @result Pointer to the name.
755 const char* ifnet_name(ifnet_t interface
);
758 @function ifnet_family
759 @discussion Returns the family of the interface.
760 @param interface Interface to retrieve the unit number from.
763 ifnet_family_t
ifnet_family(ifnet_t interface
);
767 @discussion Returns the unit number of the interface.
768 @param interface Interface to retrieve the unit number from.
771 u_int32_t
ifnet_unit(ifnet_t interface
);
774 @function ifnet_index
775 @discussion Returns the index of the interface. This index value
776 will match the index you would find in a sockaddr_dl or using
777 if_nametoindex or if_indextoname in user space. The value of the
778 interface index is undefined for an interface that is not
780 @param interface Interface to retrieve the index of.
783 u_int32_t
ifnet_index(ifnet_t interface
);
786 @function ifnet_set_flags
787 @discussion Sets the interface flags to match new_flags.
788 @discussion Sets the interface flags to new_flags. This function
789 lets you specify which flags you want to change using the mask.
790 The kernel will effectively take the lock, then set the
791 interface's flags to (if_flags & ~mask) | (new_flags & mask).
792 @param interface Interface to set the flags on.
793 @param new_flags The new set of flags that should be set. These
794 flags are defined in net/if.h
795 @result 0 on success otherwise the errno error.
797 errno_t
ifnet_set_flags(ifnet_t interface
, u_int16_t new_flags
, u_int16_t mask
);
800 @function ifnet_flags
801 @discussion Returns the interface flags that are set.
802 @param interface Interface to retrieve the flags from.
803 @result Flags. These flags are defined in net/if.h
805 u_int16_t
ifnet_flags(ifnet_t interface
);
808 #ifdef KERNEL_PRIVATE
810 @function ifnet_set_eflags
811 @discussion Sets the extended interface flags to new_flags. This
812 function lets you specify which flags you want to change using
813 the mask. The kernel will effectively take the lock, then set
814 the interface's extended flags to (if_eflags & ~mask) |
816 @param interface The interface.
817 @param new_flags The new set of flags that should be set. These
818 flags are defined in net/if.h
819 @param mask The mask of flags to be modified.
820 @result 0 on success otherwise the errno error.
822 errno_t
ifnet_set_eflags(ifnet_t interface
, u_int32_t new_flags
, u_int32_t mask
);
825 @function ifnet_eflags
826 @discussion Returns the extended interface flags that are set.
827 @param interface Interface to retrieve the flags from.
828 @result Extended flags. These flags are defined in net/if.h
830 u_int32_t
ifnet_eflags(ifnet_t interface
);
834 @function ifnet_set_offload
835 @discussion Sets a bitfield to indicate special hardware offload
836 support provided by the interface such as hardware checksums and
837 VLAN. This replaces the if_hwassist flags field. Any flags
838 unrecognized by the stack will not be set.
839 @param interface The interface.
840 @param offload The new set of flags indicating which offload options
842 @param mask The mask of flags to be modified.
843 @result 0 on success otherwise the errno error.
845 errno_t
ifnet_set_offload(ifnet_t interface
, ifnet_offload_t offload
);
848 @function ifnet_offload
849 @discussion Returns flags indicating which operations can be
850 offloaded to the interface.
851 @param interface Interface to retrieve the offload from.
852 @result Abilities flags, see ifnet_offload_t.
854 ifnet_offload_t
ifnet_offload(ifnet_t interface
);
857 @function ifnet_set_link_mib_data
858 @discussion Sets the mib link data. The ifnet_t will store the
859 pointer you supply and copy mibLen bytes from the pointer
860 whenever the sysctl for getting interface specific MIB data is
861 used. Since the ifnet_t stores a pointer to your data instead of
862 a copy, you may update the data at the address at any time.
864 This function is intended to be called by the driver. A kext
865 must not call this function on an interface the kext does not
867 @param interface Interface to set the unit number of.
868 @param mibData A pointer to the data.
869 @param mibLen Length of data pointed to.
870 @result 0 on success otherwise the errno error.
872 errno_t
ifnet_set_link_mib_data(ifnet_t interface
, void *mibData
, u_int32_t mibLen
);
875 @function ifnet_get_link_mib_data
876 @discussion Copies the link MIB data in to mibData, up to mibLen
877 bytes. Returns error if the buffer is too small to hold all of
879 @param interface The interface.
880 @param mibData A pointer to space for the mibData to be copied in
882 @param mibLen When calling, this should be the size of the buffer
883 passed in mibData. Upon return, this will be the size of data
884 copied in to mibData.
885 @result Returns an error if the buffer size is too small or there is
888 errno_t
ifnet_get_link_mib_data(ifnet_t interface
, void *mibData
, u_int32_t
*mibLen
);
891 @function ifnet_get_link_mib_data_length
892 @discussion Retrieve the size of the mib data.
893 @param interface The interface.
894 @result Returns the number of bytes of mib data associated with the
897 u_int32_t
ifnet_get_link_mib_data_length(ifnet_t interface
);
900 @function ifnet_attach_protocol
901 @discussion Attaches a protocol to an interface.
902 @param interface The interface.
903 @param protocol_family The protocol family being attached
904 (PF_INET/PF_APPLETALK/etc...).
905 @param proto_details Details of the protocol being attached.
906 @result 0 on success otherwise the errno error.
908 errno_t
ifnet_attach_protocol(ifnet_t interface
, protocol_family_t protocol_family
,
909 const struct ifnet_attach_proto_param
*proto_details
);
912 @function ifnet_detach_protocol
913 @discussion Detaches a protocol from an interface.
914 @param interface The interface.
915 @param protocol_family The protocol family of the protocol to
917 @result 0 on success otherwise the errno error.
919 errno_t
ifnet_detach_protocol(ifnet_t interface
, protocol_family_t protocol_family
);
922 @function ifnet_output
923 @discussion Handles an outbound packet on the interface by calling
924 any filters, a protocol preoutput function, the interface framer
925 function, and finally the interface's output function. The
926 protocol_family will be used to apply protocol filters and
927 determine which preoutput function to call. The route and dest
928 parameters will be passed to the preoutput function defined for
929 the attachment of the specified protocol to the specified
930 interface. ifnet_output will free the mbuf chain in the event of
932 @param interface The interface.
933 @param protocol_family The family of the protocol generating this
934 packet (i.e. AF_INET).
935 @param packet The packet to be transmitted.
936 @param route A pointer to a routing structure for this packet. The
937 preoutput function determines whether this value may be NULL or
939 @param dest The destination address of protocol_family type. This
940 will be passed to the preoutput function. If the preoutput
941 function does not require this value, you may pass NULL.
942 @result 0 on success otherwise the errno error.
944 errno_t
ifnet_output(ifnet_t interface
, protocol_family_t protocol_family
, mbuf_t packet
,
945 void* route
, const struct sockaddr
*dest
);
948 @function ifnet_output_raw
949 @discussion Handles and outbond raw packet on the interface by
950 calling any filters followed by the interface's output function.
951 protocol_family may be zero. If the packet is from a specific
952 protocol the protocol_family will be used to apply protocol
953 filters. All interface filters will be applied to the outgoing
954 packet. Processing, such as calling the protocol preoutput and
955 interface framer functions will be bypassed. The packet will
956 pass through the filters and be sent on the interface as is.
957 ifnet_output_raw will free the packet chain in the event of an
959 @param interface The interface.
960 @param protocol_family The family of the protocol generating this
961 packet (i.e. AF_INET).
962 @param packet The fully formed packet to be transmitted.
963 @result 0 on success otherwise the errno error.
965 errno_t
ifnet_output_raw(ifnet_t interface
, protocol_family_t protocol_family
, mbuf_t packet
);
968 @function ifnet_input
969 @discussion Inputs packets from the interface. The interface's demux
970 will be called to determine the protocol. Once the protocol is
971 determined, the interface filters and protocol filters will be
972 called. From there, the packet will be passed to the registered
973 protocol. If there is an error, the mbuf chain will be freed.
974 @param interface The interface.
975 @param first_packet The first packet in a chain of packets.
976 @param stats Counts to be integrated in to the stats. The interface
977 statistics will be incremented by the amounts specified in
978 stats. This parameter may be NULL.
979 @result 0 on success otherwise the errno error.
981 errno_t
ifnet_input(ifnet_t interface
, mbuf_t first_packet
,
982 const struct ifnet_stat_increment_param
*stats
);
985 @function ifnet_ioctl
986 @discussion Calls the interface's ioctl function with the parameters
988 @param interface The interface.
989 @param protocol The protocol family of the protocol to send the
990 ioctl to (may be zero). Some ioctls apply to a protocol while
991 other ioctls apply to just an interface.
992 @param ioctl_code The ioctl to perform.
993 @param ioctl_arg Any parameters to the ioctl.
994 @result 0 on success otherwise the errno error.
996 errno_t
ifnet_ioctl(ifnet_t interface
, protocol_family_t protocol
,
997 u_int32_t ioctl_code
, void *ioctl_arg
);
1000 @function ifnet_event
1001 @discussion Calls the interface's event function.
1002 @param interface The interface.
1003 @param event_ptr Pointer to an kern_event structure describing the
1005 @result 0 on success otherwise the errno error.
1007 errno_t
ifnet_event(ifnet_t interface
, struct kern_event_msg
* event_ptr
);
1010 @function ifnet_set_mtu
1011 @discussion Sets the value of the MTU in the interface structure.
1012 Calling this function will not notify the driver that the MTU
1013 should be changed. Use the appropriate ioctl.
1015 This function is intended to be called by the driver. A kext
1016 must not call this function on an interface the kext does not
1018 @param interface The interface.
1019 @param mtu The new MTU.
1020 @result 0 on success otherwise the errno error.
1022 errno_t
ifnet_set_mtu(ifnet_t interface
, u_int32_t mtu
);
1026 @param interface The interface.
1029 u_int32_t
ifnet_mtu(ifnet_t interface
);
1032 @function ifnet_type
1033 @param interface The interface.
1034 @result The type. See net/if_types.h.
1036 u_int8_t
ifnet_type(ifnet_t interface
);
1039 @function ifnet_set_addrlen
1041 This function is intended to be called by the driver. A kext
1042 must not call this function on an interface the kext does not
1044 @param interface The interface.
1045 @param addrlen The new address length.
1046 @result 0 on success otherwise the errno error.
1048 errno_t
ifnet_set_addrlen(ifnet_t interface
, u_int8_t addrlen
);
1051 @function ifnet_addrlen
1052 @param interface The interface.
1053 @result The address length.
1055 u_int8_t
ifnet_addrlen(ifnet_t interface
);
1058 @function ifnet_set_hdrlen
1060 This function is intended to be called by the driver. A kext
1061 must not call this function on an interface the kext does not
1063 @param interface The interface.
1064 @param hdrlen The new header length.
1065 @result 0 on success otherwise the errno error.
1067 errno_t
ifnet_set_hdrlen(ifnet_t interface
, u_int8_t hdrlen
);
1070 @function ifnet_hdrlen
1071 @param interface The interface.
1072 @result The header length.
1074 u_int8_t
ifnet_hdrlen(ifnet_t interface
);
1077 @function ifnet_set_metric
1079 This function is intended to be called by the driver. A kext
1080 must not call this function on an interface the kext does not
1082 @param interface The interface.
1083 @param metric The new metric.
1084 @result 0 on success otherwise the errno error.
1086 errno_t
ifnet_set_metric(ifnet_t interface
, u_int32_t metric
);
1089 @function ifnet_metric
1090 @param interface The interface.
1093 u_int32_t
ifnet_metric(ifnet_t interface
);
1096 @function ifnet_set_baudrate
1098 This function is intended to be called by the driver. A kext
1099 must not call this function on an interface the kext does not
1101 @param interface The interface.
1102 @param baudrate The new baudrate.
1103 @result 0 on success otherwise the errno error.
1105 errno_t
ifnet_set_baudrate(ifnet_t interface
, u_int64_t baudrate
);
1108 @function ifnet_baudrate
1109 @param interface The interface.
1110 @result The baudrate.
1112 u_int64_t
ifnet_baudrate(ifnet_t interface
);
1115 @function ifnet_stat_increment
1117 This function is intended to be called by the driver. A kext
1118 must not call this function on an interface the kext does not
1120 @param interface The interface.
1121 @param counts A pointer to a structure containing the amount to
1122 increment each counter by. Any counts not appearing in the
1123 ifnet_counter_increment structure are handled in the stack.
1124 @result 0 on success otherwise the errno error.
1126 errno_t
ifnet_stat_increment(ifnet_t interface
,
1127 const struct ifnet_stat_increment_param
*counts
);
1130 @function ifnet_stat_increment_in
1132 This function is intended to be called by the driver. This
1133 function allows a driver to update the inbound interface counts.
1134 The most efficient time to update these counts is when calling
1137 A lock protects the counts, this makes the increment functions
1138 expensive. The increment function will update the lastchanged
1140 @param interface The interface.
1141 @param packets_in The number of additional packets received.
1142 @param bytes_in The number of additional bytes received.
1143 @param errors_in The number of additional receive errors.
1144 @result 0 on success otherwise the errno error.
1146 errno_t
ifnet_stat_increment_in(ifnet_t interface
,
1147 u_int32_t packets_in
, u_int32_t bytes_in
,
1148 u_int32_t errors_in
);
1151 @function ifnet_stat_increment_out
1153 This function is intended to be called by the driver. This
1154 function allows a driver to update the outbound interface counts.
1156 A lock protects the counts, this makes the increment functions
1157 expensive. The increment function will update the lastchanged
1159 @param interface The interface.
1160 @param packets_out The number of additional packets sent.
1161 @param bytes_out The number of additional bytes sent.
1162 @param errors_out The number of additional send errors.
1163 @result 0 on success otherwise the errno error.
1165 errno_t
ifnet_stat_increment_out(ifnet_t interface
,
1166 u_int32_t packets_out
, u_int32_t bytes_out
,
1167 u_int32_t errors_out
);
1170 @function ifnet_set_stat
1172 This function is intended to be called by the driver. A kext
1173 must not call this function on an interface the kext does not
1176 The one exception would be the case where a kext wants to zero
1177 all of the counters.
1178 @param interface The interface.
1179 @param counts The new stats values.
1180 @result 0 on success otherwise the errno error.
1182 errno_t
ifnet_set_stat(ifnet_t interface
,
1183 const struct ifnet_stats_param
*stats
);
1186 @function ifnet_stat
1187 @param interface The interface.
1188 @param out_stats Storage for the values.
1189 @result 0 on success otherwise the errno error.
1191 errno_t
ifnet_stat(ifnet_t interface
,
1192 struct ifnet_stats_param
*out_stats
);
1195 @function ifnet_set_promiscuous
1196 @discussion Enable or disable promiscuous mode on the interface. The
1197 interface keeps an internal count of the number of times
1198 promiscuous mode has been enabled. Promiscuous mode is only
1199 disabled when this count reaches zero. Be sure to disable
1200 promiscuous mode only once for every time you enable it.
1201 @param interface The interface to toggle promiscuous mode on.
1202 @param on If set, the number of promicuous on requests will be
1203 incremented. If this is the first requrest, promiscuous mode
1204 will be enabled. If this is not set, the number of promiscous
1205 clients will be decremented. If this causes the number to reach
1206 zero, promiscuous mode will be disabled.
1207 @result 0 on success otherwise the errno error.
1209 errno_t
ifnet_set_promiscuous(ifnet_t interface
, int on
);
1212 @function ifnet_touch_lastchange
1213 @discussion Updates the lastchange value to now.
1214 @param interface The interface.
1215 @result 0 on success otherwise the errno error.
1217 errno_t
ifnet_touch_lastchange(ifnet_t interface
);
1220 @function ifnet_lastchange
1221 @param interface The interface.
1222 @param last_change A timeval struct to copy the last time changed in
1225 errno_t
ifnet_lastchange(ifnet_t interface
, struct timeval
*last_change
);
1228 @function ifnet_get_address_list
1229 @discussion Get a list of addresses on the interface. Passing NULL
1230 for the interface will return a list of all addresses. The
1231 addresses will have their reference count bumped so they will
1232 not go away. Calling ifnet_free_address_list will decrement the
1233 refcount and free the array. If you wish to hold on to a
1234 reference to an ifaddr_t, be sure to bump the reference count
1235 before calling ifnet_free_address_list.
1236 @param interface The interface.
1237 @param addresses A pointer to a NULL terminated array of ifaddr_ts.
1238 @result 0 on success otherwise the errno error.
1240 errno_t
ifnet_get_address_list(ifnet_t interface
, ifaddr_t
**addresses
);
1243 @function ifnet_get_address_list_family
1244 @discussion Get a list of addresses on the interface. Passing NULL
1245 for the interface will return a list of all addresses. The
1246 addresses will have their reference count bumped so they will
1247 not go away. Calling ifnet_free_address_list will decrement the
1248 refcount and free the array. If you wish to hold on to a
1249 reference to an ifaddr_t, be sure to bump the reference count
1250 before calling ifnet_free_address_list. Unlike
1251 ifnet_get_address_list, this function lets the caller specify
1252 the address family to get a list of only a specific address type.
1253 @param interface The interface.
1254 @param addresses A pointer to a NULL terminated array of ifaddr_ts.
1255 @result 0 on success otherwise the errno error.
1257 errno_t
ifnet_get_address_list_family(ifnet_t interface
, ifaddr_t
**addresses
, sa_family_t family
);
1260 @function ifnet_free_address_list
1261 @discussion Free a list of addresses returned from
1262 ifnet_get_address_list. Decrements the refcounts and frees the
1263 memory used for the array of references.
1264 @param addresses An array of ifaddr_ts.
1266 void ifnet_free_address_list(ifaddr_t
*addresses
);
1269 @function ifnet_set_lladdr
1270 @discussion Sets the link-layer address for this interface.
1271 @param interface The interface the link layer address is being
1273 @param lladdr A pointer to the raw link layer address (pointer to
1274 the 6 byte ethernet address for ethernet).
1275 @param lladdr_len The length, in bytes, of the link layer address.
1277 errno_t
ifnet_set_lladdr(ifnet_t interface
, const void* lladdr
, size_t lladdr_len
);
1280 @function ifnet_lladdr_copy_bytes
1281 @discussion Copies the bytes of the link-layer address in to the
1283 @param interface The interface to copy the link-layer address from.
1284 @param lladdr The buffer to copy the link-layer address in to.
1285 @param length The length of the buffer. This value must match the
1286 length of the link-layer address.
1288 errno_t
ifnet_lladdr_copy_bytes(ifnet_t interface
, void* lladdr
, size_t length
);
1290 #ifdef KERNEL_PRIVATE
1292 @function ifnet_lladdr
1293 @discussion Returns a pointer to the link-layer address.
1294 @param interface The interface the link-layer address is on.
1296 void* ifnet_lladdr(ifnet_t interface
);
1297 #endif KERNEL_PRIVATE
1300 @function ifnet_llbroadcast_copy_bytes
1301 @discussion Retrieves the link-layer broadcast address for this
1303 @param interface The interface.
1304 @param addr A buffer to copy the broadcast address in to.
1305 @param bufferlen The length of the buffer at addr.
1306 @param addr_len On return, the length of the broadcast address.
1307 @param lladdr_len The length, in bytes, of the link layer address.
1309 errno_t
ifnet_llbroadcast_copy_bytes(ifnet_t interface
, void* addr
,
1310 size_t bufferlen
, size_t* addr_len
);
1312 #ifdef KERNEL_PRIVATE
1314 @function ifnet_set_lladdr_and_type
1315 @discussion Sets the link-layer address as well as the type field in
1316 the sockaddr_dl. Support for setting the type was added for vlan
1317 and bond interfaces.
1318 @param interface The interface the link layer address is being
1320 @param lladdr A pointer to the raw link layer address (pointer to
1321 the 6 byte ethernet address for ethernet).
1322 @param lladdr_len The length, in bytes, of the link layer address.
1323 @param type The link-layer address type.
1325 errno_t
ifnet_set_lladdr_and_type(ifnet_t interface
, const void* lladdr
, size_t length
, u_char type
);
1326 #endif KERNEL_PRIVATE
1329 @function ifnet_add_multicast
1330 @discussion Joins a multicast and returns an ifmultiaddr_t with the
1331 reference count incremented for you. You are responsible for
1332 decrementing the reference count after calling
1333 ifnet_remove_multicast and making sure you no longer have any
1334 references to the multicast.
1335 @param interface The interface.
1336 @param maddr The multicast address to join. Either a physical
1337 address or logical address to be translated to a physical
1339 @param multicast The resulting ifmultiaddr_t multicast address.
1340 @result 0 on success otherwise the errno error.
1342 errno_t
ifnet_add_multicast(ifnet_t interface
, const struct sockaddr
*maddr
,
1343 ifmultiaddr_t
*multicast
);
1346 @function ifnet_remove_multicast
1347 @discussion Causes the interface to leave the multicast group. The
1348 stack keeps track of how many times ifnet_add_multicast has been
1349 called for a given multicast address. The multicast will only be
1350 removed when the number of times ifnet_remove_multicast has been
1351 called matches the number of times ifnet_add_multicast has been
1354 The memory for the multicast address is not actually freed until
1355 the separate reference count has reached zero. Some parts of the
1356 stack may keep a pointer to the multicast even after that
1357 multicast has been removed from the interface.
1359 When an interface is detached, all of the multicasts are
1360 removed. If the interface of the multicast passed in is no
1361 longer attached, this function will gracefully return,
1364 It is the callers responsibility to release the multicast
1365 address after calling this function.
1366 @param multicast The multicast to be removed.
1367 @result 0 on success otherwise the errno error.
1369 errno_t
ifnet_remove_multicast(ifmultiaddr_t multicast
);
1372 @function ifnet_get_multicast_list
1373 @discussion Retrieves a list of multicast address the interface is
1374 set to receive. This function allocates and returns an array of
1375 references to the various multicast addresses. The multicasts
1376 have their reference counts bumped on your behalf. Calling
1377 ifnet_free_multicast_list will decrement the reference counts
1379 @param interface The interface.
1380 @param multicasts A pointer to a NULL terminated array of references
1381 to the multicast addresses.
1382 @result 0 on success otherwise the errno error.
1384 errno_t
ifnet_get_multicast_list(ifnet_t interface
, ifmultiaddr_t
**addresses
);
1387 @function ifnet_free_multicast_list
1388 @discussion Frees a list of multicasts returned by
1389 ifnet_get_multicast_list. Decrements the refcount on each
1390 multicast address and frees the array.
1391 @param multicasts An array of references to the multicast addresses.
1392 @result 0 on success otherwise the errno error.
1394 void ifnet_free_multicast_list(ifmultiaddr_t
*multicasts
);
1397 @function ifnet_find_by_name
1398 @discussion Find an interface by the name including the unit number.
1399 Caller must call ifnet_release on any non-null interface return
1401 @param name The name of the interface, including any unit number
1403 @param interface A pointer to an interface reference. This will be
1404 filled in if a matching interface is found.
1405 @result 0 on success otherwise the errno error.
1407 errno_t
ifnet_find_by_name(const char *ifname
, ifnet_t
*interface
);
1410 @function ifnet_list_get
1411 @discussion Get a list of attached interfaces. List will be set to
1412 point to an array allocated by ifnet_list_get. The interfaces
1413 are refcounted and the counts will be incremented before the
1414 function returns. The list of interfaces must be freed using
1416 @param family The interface family (i.e. IFNET_FAMILY_ETHERNET). To
1417 find interfaces of all families, use IFNET_FAMILY_ANY.
1418 @param interfaces A pointer to an array of interface references.
1419 @param count A pointer that will be filled in with the number of
1420 matching interfaces in the array.
1421 @result 0 on success otherwise the errno error.
1423 errno_t
ifnet_list_get(ifnet_family_t family
, ifnet_t
**interfaces
, u_int32_t
*count
);
1426 @function ifnet_list_free
1427 @discussion Free a list of interfaces returned by ifnet_list_get.
1428 Decrements the reference count on each interface and frees the
1429 array of references. If you keep a reference to an interface, be
1430 sure to increment the reference count before calling
1432 @param interfaces An array of interface references from ifnet_list_get.
1434 void ifnet_list_free(ifnet_t
*interfaces
);
1436 /********************************************************************************************/
1437 /* ifaddr_t accessors */
1438 /********************************************************************************************/
1441 @function ifaddr_reference
1442 @discussion Increment the reference count of an address tied to an
1444 @param ifaddr The interface address.
1445 @result 0 upon success
1447 errno_t
ifaddr_reference(ifaddr_t ifaddr
);
1450 @function ifaddr_release
1451 @discussion Decrements the reference count of and possibly frees an
1452 address tied to an interface.
1453 @param ifaddr The interface address.
1454 @result 0 upon success
1456 errno_t
ifaddr_release(ifaddr_t ifaddr
);
1459 @function ifaddr_address
1460 @discussion Copies the address out of the ifaddr.
1461 @param ifaddr The interface address.
1462 @param out_addr The sockaddr storage for the address.
1463 @param addr_size The size of the storage for the address.
1464 @result 0 upon success
1466 errno_t
ifaddr_address(ifaddr_t ifaddr
, struct sockaddr
*out_addr
, u_int32_t addr_size
);
1469 @function ifaddr_address
1470 @discussion Returns the address family of the address.
1471 @param ifaddr The interface address.
1472 @result 0 on failure, address family on success.
1474 sa_family_t
ifaddr_address_family(ifaddr_t ifaddr
);
1477 @function ifaddr_dstaddress
1478 @discussion Copies the destination address out of the ifaddr.
1479 @param ifaddr The interface address.
1480 @param out_dstaddr The sockaddr storage for the destination address.
1481 @param dstaddr_size The size of the storage for the destination address.
1482 @result 0 upon success
1484 errno_t
ifaddr_dstaddress(ifaddr_t ifaddr
, struct sockaddr
*out_dstaddr
, u_int32_t dstaddr_size
);
1487 @function ifaddr_netmask
1488 @discussion Copies the netmask out of the ifaddr.
1489 @param ifaddr The interface address.
1490 @param out_netmask The sockaddr storage for the netmask.
1491 @param netmask_size The size of the storage for the netmask.
1492 @result 0 upon success
1494 errno_t
ifaddr_netmask(ifaddr_t ifaddr
, struct sockaddr
*out_netmask
, u_int32_t netmask_size
);
1497 @function ifaddr_ifnet
1498 @discussion Returns the interface the address is attached to. The
1499 reference is only valid until the ifaddr is released. If you
1500 need to hold a reference to the ifnet for longer than you hold a
1501 reference to the ifaddr, increment the reference using
1503 @param ifaddr The interface address.
1504 @result A reference to the interface the address is attached to.
1506 ifnet_t
ifaddr_ifnet(ifaddr_t ifaddr
);
1509 @function ifaddr_withaddr
1510 @discussion Returns an interface address with the address specified.
1511 Increments the reference count on the ifaddr before returning to
1512 the caller. Caller is responsible for calling ifaddr_release.
1513 @param address The address to search for.
1514 @result A reference to the interface address.
1516 ifaddr_t
ifaddr_withaddr(const struct sockaddr
* address
);
1519 @function ifaddr_withdstaddr
1520 @discussion Returns an interface address for the interface address
1521 that matches the destination when the netmask is applied.
1522 Increments the reference count on the ifaddr before returning to
1523 the caller. Caller is responsible for calling ifaddr_release.
1524 @param destination The destination to search for.
1525 @result A reference to the interface address.
1527 ifaddr_t
ifaddr_withdstaddr(const struct sockaddr
* destination
);
1530 @function ifaddr_withnet
1531 @discussion Returns an interface address for the interface with the
1532 network described by net. Increments the reference count on the
1533 ifaddr before returning to the caller. Caller is responsible for
1534 calling ifaddr_release.
1535 @param net The network to search for.
1536 @result A reference to the interface address.
1538 ifaddr_t
ifaddr_withnet(const struct sockaddr
* net
);
1541 @function ifaddr_withroute
1542 @discussion Returns an interface address given a destination and
1543 gateway. Increments the reference count on the ifaddr before
1544 returning to the caller. Caller is responsible for calling
1546 @param flags Routing flags. See net/route.h, RTF_GATEWAY etc.
1547 @param destination The destination to search for.
1548 @param gateway A gateway to search for.
1549 @result A reference to the interface address.
1551 ifaddr_t
ifaddr_withroute(int flags
, const struct sockaddr
* destination
,
1552 const struct sockaddr
* gateway
);
1555 @function ifaddr_findbestforaddr
1556 @discussion Finds the best local address assigned to a specific
1557 interface to use when communicating with another address.
1558 Increments the reference count on the ifaddr before returning to
1559 the caller. Caller is responsible for calling ifaddr_release.
1560 @param addr The remote address.
1561 @param interface The local interface.
1562 @result A reference to the interface address.
1564 ifaddr_t
ifaddr_findbestforaddr(const struct sockaddr
*addr
, ifnet_t interface
);
1566 /********************************************************************************************/
1567 /* ifmultiaddr_t accessors */
1568 /********************************************************************************************/
1571 @function ifmaddr_reference
1572 @discussion Increment the reference count of an interface multicast
1574 @param ifmaddr The interface multicast address.
1575 @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
1577 errno_t
ifmaddr_reference(ifmultiaddr_t ifmaddr
);
1580 @function ifmaddr_release
1581 @discussion Decrement the reference count of an interface multicast
1582 address. If the reference count reaches zero, the ifmultiaddr
1583 will be removed from the interface and the ifmultiaddr will be
1585 @param ifmaddr The interface multicast address.
1586 @result 0 on success. Only error will be EINVAL if ifmaddr is not valid.
1588 errno_t
ifmaddr_release(ifmultiaddr_t ifmaddr
);
1591 @function ifmaddr_address
1592 @discussion Copies the multicast address to out_multicast.
1593 @param out_multicast Storage for a sockaddr.
1594 @param addr_size Size of the storage.
1595 @result 0 on success.
1597 errno_t
ifmaddr_address(ifmultiaddr_t ifmaddr
, struct sockaddr
*out_multicast
, u_int32_t addr_size
);
1600 @function ifmaddr_lladdress
1601 @discussion Copies the link layer multicast address to
1602 out_link_layer_multicast.
1603 @param out_link_layer_multicast Storage for a sockaddr.
1604 @param addr_size Size of the storage.
1605 @result 0 on success.
1607 errno_t
ifmaddr_lladdress(ifmultiaddr_t ifmaddr
, struct sockaddr
*out_link_layer_multicast
,
1608 u_int32_t addr_size
);
1611 @function ifmaddr_ifnet
1612 @discussion Returns the interface this multicast address is attached
1613 to. The interface reference count is not bumped by this
1614 function. The interface is only valid as long as you don't
1615 release the refernece to the multiast address. If you need to
1616 maintain your pointer to the ifnet, call ifnet_reference
1617 followed by ifnet_release when you're finished.
1618 @param ifmaddr The interface multicast address.
1619 @result A reference to the interface.
1621 ifnet_t
ifmaddr_ifnet(ifmultiaddr_t ifmaddr
);