|
|
Log In | Not a Member? |
Contact ADC |
|
ADC Home > Reference Library > Reference > Darwin > KPI Reference
|
kpi_interface.h |
| Includes: | <sys/kernel_types.h> |
This header defines an API to interact with network interfaces in the kernel. The network interface KPI may be used to implement network interfaces or to attach protocols to existing interfaces.
ifaddr_address(ifaddr_t) |
sa_family_t ifaddr_address_family( ifaddr_t ifaddr);
ifaddr0 on failure, address family on success.
Returns the address family of the address.
ifaddr_address(ifaddr_t, struct sockaddr *, u_int32_t) |
errno_t ifaddr_address( ifaddr_t ifaddr, struct sockaddr *out_addr, u_int32_t addr_size);
ifaddrout_addraddr_size0 upon success
Copies the address out of the ifaddr.
ifaddr_address_family |
sa_family_t ifaddr_address_family( ifaddr_t ifaddr);
ifaddr0 on failure, address family on success.
Returns the address family of the address.
ifaddr_dstaddress |
errno_t ifaddr_dstaddress( ifaddr_t ifaddr, struct sockaddr *out_dstaddr, u_int32_t dstaddr_size);
ifaddrout_dstaddrdstaddr_size0 upon success
Copies the destination address out of the ifaddr.
ifaddr_findbestforaddr |
ifaddr_t ifaddr_findbestforaddr( const struct sockaddr *addr, ifnet_t interface);
addrinterfaceA reference to the interface address.
Finds the best local address assigned to a specific interface to use when communicating with another address. Increments the reference count on the ifaddr before returning to the caller. Caller is responsible for calling ifaddr_release.
ifaddr_ifnet |
ifnet_t ifaddr_ifnet( ifaddr_t ifaddr);
ifaddrA reference to the interface the address is attached to.
Returns the interface the address is attached to. The reference is only valid until the ifaddr is released. If you need to hold a reference to the ifnet for longer than you hold a reference to the ifaddr, increment the reference using ifnet_reference.
ifaddr_netmask |
errno_t ifaddr_netmask( ifaddr_t ifaddr, struct sockaddr *out_netmask, u_int32_t netmask_size);
ifaddrout_netmasknetmask_size0 upon success
Copies the netmask out of the ifaddr.
ifaddr_reference |
errno_t ifaddr_reference( ifaddr_t ifaddr);
ifaddr0 upon success
Increment the reference count of an address tied to an interface.
ifaddr_release |
errno_t ifaddr_release( ifaddr_t ifaddr);
ifaddr0 upon success
Decrements the reference count of and possibly frees an address tied to an interface.
ifaddr_withaddr |
ifaddr_t ifaddr_withaddr( const struct sockaddr*address);
addressA reference to the interface address.
Returns an interface address with the address specified. Increments the reference count on the ifaddr before returning to the caller. Caller is responsible for calling ifaddr_release.
ifaddr_withdstaddr |
ifaddr_t ifaddr_withdstaddr( const struct sockaddr*destination);
destinationA reference to the interface address.
Returns an interface address for the interface address that matches the destination when the netmask is applied. Increments the reference count on the ifaddr before returning to the caller. Caller is responsible for calling ifaddr_release.
ifaddr_withnet |
ifaddr_t ifaddr_withnet( const struct sockaddr*net);
netA reference to the interface address.
Returns an interface address for the interface with the network described by net. Increments the reference count on the ifaddr before returning to the caller. Caller is responsible for calling ifaddr_release.
ifaddr_withroute |
ifaddr_t ifaddr_withroute( int flags, const struct sockaddr*destination, const struct sockaddr*gateway);
flagsdestinationgatewayA reference to the interface address.
Returns an interface address given a destination and gateway. Increments the reference count on the ifaddr before returning to the caller. Caller is responsible for calling ifaddr_release.
ifmaddr_address |
errno_t ifmaddr_address( ifmultiaddr_t ifmaddr, struct sockaddr *out_multicast, u_int32_t addr_size);
out_multicastaddr_size0 on success.
Copies the multicast address to out_multicast.
ifmaddr_ifnet |
ifnet_t ifmaddr_ifnet( ifmultiaddr_t ifmaddr);
ifmaddrA reference to the interface.
Returns the interface this multicast address is attached to. The interface reference count is not bumped by this function. The interface is only valid as long as you don't release the refernece to the multiast address. If you need to maintain your pointer to the ifnet, call ifnet_reference followed by ifnet_release when you're finished.
ifmaddr_lladdress |
errno_t ifmaddr_lladdress( ifmultiaddr_t ifmaddr, struct sockaddr *out_link_layer_multicast, u_int32_t addr_size);
out_link_layer_multicastaddr_size0 on success.
Copies the link layer multicast address to out_link_layer_multicast.
ifmaddr_reference |
errno_t ifmaddr_reference( ifmultiaddr_t ifmaddr);
ifmaddr0 on success. Only error will be EINVAL if ifmaddr is not valid.
Increment the reference count of an interface multicast address.
ifmaddr_release |
errno_t ifmaddr_release( ifmultiaddr_t ifmaddr);
ifmaddr0 on success. Only error will be EINVAL if ifmaddr is not valid.
Decrement the reference count of an interface multicast address. If the reference count reaches zero, the ifmultiaddr will be removed from the interface and the ifmultiaddr will be freed.
ifnet_add_multicast |
errno_t ifnet_add_multicast( ifnet_t interface, const struct sockaddr *maddr, ifmultiaddr_t *multicast);
interfacemaddrmulticast0 on success otherwise the errno error.
Joins a multicast and returns an ifmultiaddr_t with the reference count incremented for you. You are responsible for decrementing the reference count after calling ifnet_remove_multicast and making sure you no longer have any references to the multicast.
ifnet_addrlen |
u_int8_t ifnet_addrlen( ifnet_t interface);
interfaceThe address length.
ifnet_allocate |
errno_t ifnet_allocate( const struct ifnet_init_params *init, ifnet_t *interface);
initinterfaceMay return ENOMEM if there is insufficient memory or EEXIST if an interface with the same uniqueid and family has already been allocated and is in use.
Allocate an ifnet_t with an initial refcount of 1. Many parts of the stack do not properly refcount the ifnet_t. In order to avoid freeing the ifnet_t while some parts of the stack may contain a reference to it, the ifnet_ts are only recycled, never freed. A unique id is used to try and recycle the same ifnet_t when allocating an interface. For example, for an ethernet interface, the hardware address of the ethernet card is usually used for the uniqueid. If a PC Card is removed and inserted again, if the ethernet address of the PC card is used, the same ifnet_t will be used for the card the second time it is inserted. In the future, when the ifnet_t is correctly refcounted by all of the stack, the interfaces may be freed and the unique ids ignored.
ifnet_attach |
errno_t ifnet_attach( ifnet_t interface, const struct sockaddr_dl *ll_addr);
interfacell_addrWill return an error if there is anything wrong with the interface.
Attaches an interface to the global interface list. The
interface must be setup properly before calling attach. The
stack will take a reference on the interface and hold it until
ifnet_detach is called.
This function is intended to be called by the driver. A kext
must not call this function on an interface the kext does not
own.
ifnet_attach_protocol |
errno_t ifnet_attach_protocol( ifnet_t interface, protocol_family_t protocol_family, const struct ifnet_attach_proto_param *proto_details);
interfaceprotocol_familyproto_details0 on success otherwise the errno error.
Attaches a protocol to an interface.
ifnet_baudrate |
u_int64_t ifnet_baudrate( ifnet_t interface);
interfaceThe baudrate.
ifnet_detach |
errno_t ifnet_detach( ifnet_t interface);
interface0 on success, otherwise errno error.
Detaches the interface.
Call this to indicate this interface is no longer valid (i.e. PC
Card was removed). This function will begin the process of
removing knowledge of this interface from the stack.
The function will return before the interface is detached. The
functions you supplied in to the interface may continue to be
called. When the detach has been completed, your detached
function will be called. Your kext must not unload until the
detached function has been called. The interface will be
properly freed when the reference count reaches zero.
An interface may not be attached again. You must call
ifnet_allocate to create a new interface to attach.
This function is intended to be called by the driver. A kext
must not call this function on an interface the kext does not
own.
ifnet_detach_protocol |
errno_t ifnet_detach_protocol( ifnet_t interface, protocol_family_t protocol_family);
interfaceprotocol_family0 on success otherwise the errno error.
Detaches a protocol from an interface.
ifnet_event |
errno_t ifnet_event( ifnet_t interface, struct kern_event_msg*event_ptr);
interfaceevent_ptr0 on success otherwise the errno error.
Calls the interface's event function.
ifnet_family |
ifnet_family_t ifnet_family( ifnet_t interface);
interfaceUnit number.
Returns the family of the interface.
ifnet_find_by_name |
errno_t ifnet_find_by_name( const char *ifname, ifnet_t *interface);
nameinterface0 on success otherwise the errno error.
Find an interface by the name including the unit number. Caller must call ifnet_release on any non-null interface return value.
ifnet_flags |
u_int16_t ifnet_flags( ifnet_t interface);
interfaceFlags. These flags are defined in net/if.h
Returns the interface flags that are set.
ifnet_free_address_list |
void ifnet_free_address_list( ifaddr_t *addresses);
addressesFree a list of addresses returned from ifnet_get_address_list. Decrements the refcounts and frees the memory used for the array of references.
ifnet_free_multicast_list |
void ifnet_free_multicast_list( ifmultiaddr_t *multicasts);
multicasts0 on success otherwise the errno error.
Frees a list of multicasts returned by ifnet_get_multicast_list. Decrements the refcount on each multicast address and frees the array.
ifnet_get_address_list |
errno_t ifnet_get_address_list( ifnet_t interface, ifaddr_t **addresses);
interfaceaddresses0 on success otherwise the errno error.
Get a list of addresses on the interface. Passing NULL
for the interface will return a list of all addresses. The
addresses will have their reference count bumped so they will
not go away. Calling ifnet_free_address_list will decrement the
refcount and free the array. If you wish to hold on to a
reference to an ifaddr_t, be sure to bump the reference count
before calling ifnet_free_address_list.
Old versions of this function erroneously returned EINVAL when
passed NULL for the interface. Passing NULL will not work on
some versions of MacOS X 10.4.
ifnet_get_address_list_family |
errno_t ifnet_get_address_list_family( ifnet_t interface, ifaddr_t **addresses, sa_family_t family);
interfaceaddresses0 on success otherwise the errno error.
Get a list of addresses on the interface. Passing NULL for the interface will return a list of all addresses. The addresses will have their reference count bumped so they will not go away. Calling ifnet_free_address_list will decrement the refcount and free the array. If you wish to hold on to a reference to an ifaddr_t, be sure to bump the reference count before calling ifnet_free_address_list. Unlike ifnet_get_address_list, this function lets the caller specify the address family to get a list of only a specific address type. Old versions of this function erroneously returned EINVAL when passed NULL for the interface. Passing NULL will not work on some versions of MacOS X 10.4.
ifnet_get_link_mib_data |
errno_t ifnet_get_link_mib_data( ifnet_t interface, void *mibData, u_int32_t *mibLen);
interfacemibDatamibLenReturns an error if the buffer size is too small or there is no data.
Copies the link MIB data in to mibData, up to mibLen bytes. Returns error if the buffer is too small to hold all of the MIB data.
ifnet_get_link_mib_data_length |
u_int32_t ifnet_get_link_mib_data_length( ifnet_t interface);
interfaceReturns the number of bytes of mib data associated with the interface.
Retrieve the size of the mib data.
ifnet_get_multicast_list |
errno_t ifnet_get_multicast_list( ifnet_t interface, ifmultiaddr_t **addresses);
interfacemulticasts0 on success otherwise the errno error.
Retrieves a list of multicast address the interface is set to receive. This function allocates and returns an array of references to the various multicast addresses. The multicasts have their reference counts bumped on your behalf. Calling ifnet_free_multicast_list will decrement the reference counts and free the array.
ifnet_hdrlen |
u_int8_t ifnet_hdrlen( ifnet_t interface);
interfaceThe header length.
ifnet_index |
u_int32_t ifnet_index( ifnet_t interface);
interfaceIndex.
Returns the index of the interface. This index value will match the index you would find in a sockaddr_dl or using if_nametoindex or if_indextoname in user space. The value of the interface index is undefined for an interface that is not currently attached.
ifnet_input |
errno_t ifnet_input( ifnet_t interface, mbuf_t first_packet, const struct ifnet_stat_increment_param *stats);
interfacefirst_packetstats0 on success otherwise the errno error.
Inputs packets from the interface. The interface's demux will be called to determine the protocol. Once the protocol is determined, the interface filters and protocol filters will be called. From there, the packet will be passed to the registered protocol. If there is an error, the mbuf chain will be freed.
ifnet_ioctl |
errno_t ifnet_ioctl( ifnet_t interface, protocol_family_t protocol, u_int32_t ioctl_code, void *ioctl_arg);
interfaceprotocolioctl_codeioctl_arg0 on success otherwise the errno error.
Calls the interface's ioctl function with the parameters
passed.
All undefined ioctls are reserved for future use by Apple. If
you need to communicate with your kext using an ioctl, please
use SIOCSIFKPI and SIOCGIFKPI.
ifnet_lastchange |
errno_t ifnet_lastchange( ifnet_t interface, struct timeval *last_change);
interfacelast_changeifnet_list_free |
void ifnet_list_free( ifnet_t *interfaces);
interfacesFree a list of interfaces returned by ifnet_list_get. Decrements the reference count on each interface and frees the array of references. If you keep a reference to an interface, be sure to increment the reference count before calling ifnet_list_free.
ifnet_list_get |
errno_t ifnet_list_get( ifnet_family_t family, ifnet_t **interfaces, u_int32_t *count);
familyinterfacescount0 on success otherwise the errno error.
Get a list of attached interfaces. List will be set to point to an array allocated by ifnet_list_get. The interfaces are refcounted and the counts will be incremented before the function returns. The list of interfaces must be freed using ifnet_list_free.
ifnet_lladdr_copy_bytes |
errno_t ifnet_lladdr_copy_bytes( ifnet_t interface, void*lladdr, size_t length);
interfacelladdrlengthCopies the bytes of the link-layer address in to the specified buffer.
ifnet_llbroadcast_copy_bytes |
errno_t ifnet_llbroadcast_copy_bytes( ifnet_t interface, void*addr, size_t bufferlen, size_t*addr_len);
interfaceaddrbufferlenaddr_lenlladdr_lenRetrieves the link-layer broadcast address for this interface.
ifnet_metric |
u_int32_t ifnet_metric( ifnet_t interface);
interfaceThe metric.
ifnet_mtu |
u_int32_t ifnet_mtu( ifnet_t interface);
interfaceThe MTU.
ifnet_name |
const char* ifnet_name( ifnet_t interface);
interfacePointer to the name.
Returns a pointer to the name of the interface.
ifnet_offload |
ifnet_offload_t ifnet_offload( ifnet_t interface);
interfaceAbilities flags, see ifnet_offload_t.
Returns flags indicating which operations can be offloaded to the interface.
ifnet_output |
errno_t ifnet_output( ifnet_t interface, protocol_family_t protocol_family, mbuf_t packet, void*route, const struct sockaddr *dest);
interfaceprotocol_familypacketroutedest0 on success otherwise the errno error.
Handles an outbound packet on the interface by calling any filters, a protocol preoutput function, the interface framer function, and finally the interface's output function. The protocol_family will be used to apply protocol filters and determine which preoutput function to call. The route and dest parameters will be passed to the preoutput function defined for the attachment of the specified protocol to the specified interface. ifnet_output will always free the mbuf chain.
ifnet_output_raw |
errno_t ifnet_output_raw( ifnet_t interface, protocol_family_t protocol_family, mbuf_t packet);
interfaceprotocol_familypacket0 on success otherwise the errno error.
Handles and outbond raw packet on the interface by calling any filters followed by the interface's output function. protocol_family may be zero. If the packet is from a specific protocol the protocol_family will be used to apply protocol filters. All interface filters will be applied to the outgoing packet. Processing, such as calling the protocol preoutput and interface framer functions will be bypassed. The packet will pass through the filters and be sent on the interface as is. ifnet_output_raw will always free the packet chain.
ifnet_reference |
errno_t ifnet_reference( ifnet_t interface);
interfaceMay return EINVAL if the interface is not valid.
Increment the reference count of the ifnet to assure that it will not go away. The interface must already have at least one reference.
ifnet_release |
errno_t ifnet_release( ifnet_t interface);
interfaceMay return EINVAL if the interface is not valid.
Release a reference of the ifnet, this may trigger a free if the reference count reaches 0.
ifnet_remove_multicast |
errno_t ifnet_remove_multicast( ifmultiaddr_t multicast);
multicast0 on success otherwise the errno error.
Causes the interface to leave the multicast group. The
stack keeps track of how many times ifnet_add_multicast has been
called for a given multicast address. The multicast will only be
removed when the number of times ifnet_remove_multicast has been
called matches the number of times ifnet_add_multicast has been
called.
The memory for the multicast address is not actually freed until
the separate reference count has reached zero. Some parts of the
stack may keep a pointer to the multicast even after that
multicast has been removed from the interface.
When an interface is detached, all of the multicasts are
removed. If the interface of the multicast passed in is no
longer attached, this function will gracefully return,
performing no work.
It is the callers responsibility to release the multicast
address after calling this function.
ifnet_resolve_multicast |
errno_t ifnet_resolve_multicast( ifnet_t ifp, const struct sockaddr *proto_addr, struct sockaddr *ll_addr, size_t ll_len);
interfaceproto_addrll_addrll_len0 on success. EOPNOTSUPP indicates the multicast address was not supported or could not be translated. Other errors may indicate other failures.
Resolves a multicast address for an attached protocol to a link-layer address. If a link-layer address is passed in, the interface will verify that it is a valid multicast address.
ifnet_set_addrlen |
errno_t ifnet_set_addrlen( ifnet_t interface, u_int8_t addrlen);
interfaceaddrlen0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext must not call this function on an interface the kext does not own.
ifnet_set_baudrate |
errno_t ifnet_set_baudrate( ifnet_t interface, u_int64_t baudrate);
interfacebaudrate0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext must not call this function on an interface the kext does not own.
ifnet_set_flags |
errno_t ifnet_set_flags( ifnet_t interface, u_int16_t new_flags, u_int16_t mask);
interfacenew_flags0 on success otherwise the errno error.
Sets the interface flags to new_flags. This function lets you specify which flags you want to change using the mask. The kernel will effectively take the lock, then set the interface's flags to (if_flags & ~mask) | (new_flags & mask).
ifnet_set_flags Sets the interface flags to match new_flags. |
errno_t ifnet_set_flags( ifnet_t interface, u_int16_t new_flags, u_int16_t mask);
interfacenew_flags0 on success otherwise the errno error.
Sets the interface flags to new_flags. This function lets you specify which flags you want to change using the mask. The kernel will effectively take the lock, then set the interface's flags to (if_flags & ~mask) | (new_flags & mask).
ifnet_set_hdrlen |
errno_t ifnet_set_hdrlen( ifnet_t interface, u_int8_t hdrlen);
interfacehdrlen0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext must not call this function on an interface the kext does not own.
ifnet_set_link_mib_data |
errno_t ifnet_set_link_mib_data( ifnet_t interface, void *mibData, u_int32_t mibLen);
interfacemibDatamibLen0 on success otherwise the errno error.
Sets the mib link data. The ifnet_t will store the
pointer you supply and copy mibLen bytes from the pointer
whenever the sysctl for getting interface specific MIB data is
used. Since the ifnet_t stores a pointer to your data instead of
a copy, you may update the data at the address at any time.
This function is intended to be called by the driver. A kext
must not call this function on an interface the kext does not
own.
ifnet_set_lladdr |
errno_t ifnet_set_lladdr( ifnet_t interface, const void*lladdr, size_t lladdr_len);
interfacelladdrlladdr_lenSets the link-layer address for this interface.
ifnet_set_metric |
errno_t ifnet_set_metric( ifnet_t interface, u_int32_t metric);
interfacemetric0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext must not call this function on an interface the kext does not own.
ifnet_set_mtu |
errno_t ifnet_set_mtu( ifnet_t interface, u_int32_t mtu);
interfacemtu0 on success otherwise the errno error.
Sets the value of the MTU in the interface structure.
Calling this function will not notify the driver that the MTU
should be changed. Use the appropriate ioctl.
This function is intended to be called by the driver. A kext
must not call this function on an interface the kext does not
own.
ifnet_set_offload |
errno_t ifnet_set_offload( ifnet_t interface, ifnet_offload_t offload);
interfaceoffloadmask0 on success otherwise the errno error.
Sets a bitfield to indicate special hardware offload support provided by the interface such as hardware checksums and VLAN. This replaces the if_hwassist flags field. Any flags unrecognized by the stack will not be set.
ifnet_set_promiscuous |
errno_t ifnet_set_promiscuous( ifnet_t interface, int on);
interfaceon0 on success otherwise the errno error.
Enable or disable promiscuous mode on the interface. The interface keeps an internal count of the number of times promiscuous mode has been enabled. Promiscuous mode is only disabled when this count reaches zero. Be sure to disable promiscuous mode only once for every time you enable it.
ifnet_set_stat |
errno_t ifnet_set_stat( ifnet_t interface, const struct ifnet_stats_param *stats);
interfacecounts0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext
must not call this function on an interface the kext does not
own.
The one exception would be the case where a kext wants to zero
all of the counters.
ifnet_softc |
void* ifnet_softc( ifnet_t interface);
interfaceDriver's private storage.
Returns the driver's private storage on the interface.
ifnet_stat |
errno_t ifnet_stat( ifnet_t interface, struct ifnet_stats_param *out_stats);
interfaceout_stats0 on success otherwise the errno error.
ifnet_stat_increment |
errno_t ifnet_stat_increment( ifnet_t interface, const struct ifnet_stat_increment_param *counts);
interfacecounts0 on success otherwise the errno error.
This function is intended to be called by the driver. A kext must not call this function on an interface the kext does not own.
ifnet_stat_increment_in |
errno_t ifnet_stat_increment_in( ifnet_t interface, u_int32_t packets_in, u_int32_t bytes_in, u_int32_t errors_in);
interfacepackets_inbytes_inerrors_in0 on success otherwise the errno error.
This function is intended to be called by the driver. This
function allows a driver to update the inbound interface counts.
The most efficient time to update these counts is when calling
ifnet_input.
A lock protects the counts, this makes the increment functions
expensive. The increment function will update the lastchanged
value.
ifnet_stat_increment_out |
errno_t ifnet_stat_increment_out( ifnet_t interface, u_int32_t packets_out, u_int32_t bytes_out, u_int32_t errors_out);
interfacepackets_outbytes_outerrors_out0 on success otherwise the errno error.
This function is intended to be called by the driver. This
function allows a driver to update the outbound interface counts.
A lock protects the counts, this makes the increment functions
expensive. The increment function will update the lastchanged
value.
ifnet_touch_lastchange |
errno_t ifnet_touch_lastchange( ifnet_t interface);
interface0 on success otherwise the errno error.
Updates the lastchange value to now.
ifnet_type |
u_int8_t