-*- Nroff -*- Copyright 1996, 1997 Massachusetts Institute of Technology Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that both the above copyright notice and this permission notice appear in all copies, that both the above copyright notice and this permission notice appear in all supporting documentation, and that the name of M.I.T. not be used in advertising or publicity pertaining to distrib...
NAMEifnet ifaddr ifqueue if_data - kernel interfaces for manipulating network interfaces
SYNOPSISIn sys/param.h In sys/time.h In sys/socket.h In net/if.h In net/if_var.h In net/if_types.h
Interface Manipulation FunctionsFt struct ifnet * Fn if_alloc u_char type Ft void Fn if_attach struct ifnet *ifp Ft void Fn if_detach struct ifnet *ifp Ft void Fn if_free struct ifnet *ifp Ft void Fn if_free_type struct ifnet *ifp u_char type Ft void Fn if_down struct ifnet *ifp Ft int Fn ifioctl struct socket *so u_long cmd caddr_t data struct thread *td Ft int Fn ifpromisc struct ifnet *ifp int pswitch Ft int Fn if_allmulti struct ifnet *ifp int amswitch Ft struct ifnet * Fn ifunit const char *name Ft struct ifnet * Fn ifunit_ref const char *name Ft void Fn if_up struct ifnet *ifp
Interface Address FunctionsFt struct ifaddr * Fn ifaddr_byindex u_short idx Ft struct ifaddr * Fn ifa_ifwithaddr struct sockaddr *addr Ft struct ifaddr * Fn ifa_ifwithdstaddr struct sockaddr *addr Ft struct ifaddr * Fn ifa_ifwithnet struct sockaddr *addr int ignore_ptp Ft struct ifaddr * Fn ifaof_ifpforaddr struct sockaddr *addr struct ifnet *ifp Ft void Fn ifa_ref struct ifaddr *ifa Ft void Fn ifa_free struct ifaddr *ifa
Interface Multicast Address FunctionsFt int Fn if_addmulti struct ifnet *ifp struct sockaddr *sa struct ifmultiaddr **ifmap Ft int Fn if_delmulti struct ifnet *ifp struct sockaddr *sa Ft struct ifmultiaddr * Fn if_findmulti struct ifnet *ifp struct sockaddr *sa
Output queue macrosFn IF_DEQUEUE struct ifqueue *ifq struct mbuf *m
struct ifnet Member FunctionsFt void Fn *if_input struct ifnet *ifp struct mbuf *m Ft int Fo *if_output Fa struct ifnet *ifp struct mbuf *m Fa const struct sockaddr *dst struct route *ro Fc Ft void Fn *if_start struct ifnet *ifp Ft int Fn *if_transmit struct ifnet *ifp struct mbuf *m Ft void Fn *if_qflush struct ifnet *ifp Ft int Fn *if_ioctl struct ifnet *ifp u_long cmd caddr_t data Ft void Fn *if_init void *if_softc Ft int Fo *if_resolvemulti Fa struct ifnet *ifp struct sockaddr **retsa struct sockaddr *addr Fc
struct ifaddr member functionFt void Fo *ifa_rtrequest Fa int cmd struct rtentry *rt struct rt_addrinfo *info Fc
Global VariablesVt extern struct ifnethead ifnet ; Vt extern int if_index ; Vt extern int ifqmaxlen ;
DATA STRUCTURESThe kernel mechanisms for handling network interfaces reside primarily in the Vt ifnet , if_data , ifaddr , and Vt ifmultiaddr structures in In net/if.h and In net/if_var.h and the functions named above and defined in /sys/net/if.c Those interfaces which are intended to be used by user programs are defined in In net/if.h ; these include the interface flags, the Vt if_data structure, and the structures defining the appearance of interface-related messages on the route(4) routing socket and in sysctl(3). The header file In net/if_var.h defines the kernel-internal interfaces, including the Vt ifnet , ifaddr , and Vt ifmultiaddr structures and the functions which manipulate them. (A few user programs will need In net/if_var.h because it is the prerequisite of some other header file like In netinet/if_ether.h . Most references to those two files in particular can be replaced by In net/ethernet.h . )
The system keeps a linked list of interfaces using the TAILQ macros defined in queue(3); this list is headed by a Vt struct ifnethead called ifnet The elements of this list are of type Vt struct ifnet , and most kernel routines which manipulate interface as such accept or return pointers to these structures. Each interface structure contains an Vt if_data structure used for statistics and information. Each interface also has a TAILQ of interface addresses, described by Vt ifaddr structures. An AF_LINK address (see link_addr3) describing the link layer implemented by the interface (if any) is accessed by the Fn ifaddr_byindex function or if_addr structure. (Some trivial interfaces do not provide any link layer addresses; this structure, while still present, serves only to identify the interface name and index.)
Finally, those interfaces supporting reception of multicast datagrams have a TAILQ of multicast group memberships, described by Vt ifmultiaddr structures. These memberships are reference-counted.
Interfaces are also associated with an output queue, defined as a Vt struct ifqueue ; this structure is used to hold packets while the interface is in the process of sending another.
The Vt ifnet
The fields of
Vt struct ifnet
are as follows:
- (Vt void * ) A pointer to the driver's private state block. (Initialized by driver.)
- (Vt void * ) A pointer to the common data for the interface's layer 2 protocol. (Initialized by Fn if_alloc . )
- (Vt struct vnet * ) A pointer to the virtual network stack instance. (Initialized by Fn if_attach . )
- (Vt struct vnet * ) A pointer to the parent virtual network stack, where this Vt struct ifnet originates from. (Initialized by Fn if_attach . )
- (Fn TAILQ_ENTRY ifnet ) queue(3) macro glue.
- (Vt char * ) The name of the interface, (e.g., ``fxp0 '' or ``lo0 '' (Initialized by driver (usually via Fn if_initname ) . )
- (Vt const char * ) The name of the driver. (Initialized by driver (usually via Fn if_initname ) . )
- (Vt int ) A unique number assigned to each interface managed by a particular driver. Drivers may choose to set this to IF_DUNIT_NONE if a unit number is not associated with the device. (Initialized by driver (usually via Fn if_initname ) . )
- (Vt u_int ) The reference count. (Initialized by Fn if_alloc . )
- (Vt struct ifaddrhead ) The head of the queue(3) TAILQ containing the list of addresses assigned to this interface.
- (Vt int ) A count of promiscuous listeners on this interface, used to reference-count the IFF_PROMISC flag.
- (Vt struct carp_if * ) A pointer to the CARP interface structure, carp(4). (Initialized by the driver-specific Fn if_ioctl routine.)
- (Vt struct bpf_if * ) Opaque per-interface data for the packet filter, bpf(4). (Initialized by Fn bpf_attach . )
- (Vt u_short ) A unique number assigned to each interface in sequence as it is attached. This number can be used in a Vt struct sockaddr_dl to refer to a particular interface by index (see link_addr3). (Initialized by Fn if_alloc . )
- (Vt struct ifvlantrunk ) A pointer to 802.1Q trunk structure, vlan(4). (Initialized by the driver-specific Fn if_ioctl routine.)
- (Vt int ) Flags describing operational parameters of this interface (see below). (Manipulated by generic code.)
- (Vt int ) Flags describing operational status of this interface (see below). (Manipulated by driver.)
- (Vt int ) Flags describing the capabilities the interface supports (see below).
- (Vt int ) Flags describing the enabled capabilities of the interface (see below).
- (Vt void * ) A pointer to an interface-specific MIB structure exported by ifmib(4). (Initialized by driver.)
- (Vt size_t ) The size of said structure. (Initialized by driver.)
- (Vt struct if_data ) More statistics and information; see Sx The if_data structure , below. (Initialized by driver, manipulated by both driver and generic code.)
- (Vt struct ifmultihead ) The head of the queue(3) TAILQ containing the list of multicast addresses assigned to this interface.
- (Vt int ) A number of multicast requests on this interface, used to reference-count the IFF_ALLMULTI flag.
- (Vt struct ifaddr * ) A pointer to the link-level interface address. (Initialized by Fn if_alloc . )
- (Vt struct ifaltq ) The output queue. (Manipulated by driver.)
- (Vt const u_int8_t * ) A link-level broadcast bytestring for protocols with variable address length.
- (Vt void * ) A pointer to the bridge interface structure, if_bridge4. (Initialized by the driver-specific Fn if_ioctl routine.)
- (Vt struct label * ) A pointer to the MAC Framework label structure, mac(4). (Initialized by Fn if_alloc . )
- (Vt void * ) An address family dependent data region.
- (Vt int ) Used to track the current state of address family initialization.
- (Vt struct rwlock ) An rwlock(9) lock used to protect if_afdata internals.
- (Vt struct task ) A taskqueue(9) task scheduled for link state change events of the interface.
- (Vt struct rwlock ) An rwlock(9) lock used to protect interface-related address lists.
- (Fn LIST_ENTRY ifnet ) queue(3) macro glue for the list of clonable network interfaces.
- (Fn TAILQ_HEAD , ifg_list ) The head of the queue(3) TAILQ containing the list of groups per interface.
- (Vt void * ) A pointer to the structure used for interface abstraction by pf(4).
- (Vt void * ) A pointer to the lagg(4) interface structure.
- (Vt u_char ) The type of the interface as it was at the time of its allocation. It is used to cache the type passed to Fn if_alloc , but unlike if_type it would not be changed by drivers.
References to Vt ifnet structures are gained by calling the Fn if_ref function and released by calling the Fn if_rele function. They are used to allow kernel code walking global interface lists to release the Vt ifnet lock yet keep the Vt ifnet structure stable.
There are in addition a number of function pointers which the driver must initialize to complete its interface with the generic interface layer:
- Fn if_input
- Pass a packet to an appropriate upper layer as determined from the link-layer header of the packet. This routine is to be called from an interrupt handler or used to emulate reception of a packet on this interface. A single function implementing Fn if_input can be shared among multiple drivers utilizing the same link-layer framing, e.g., Ethernet.
- Fn if_output
- Output a packet on interface Fa ifp , or queue it on the output queue if the interface is already active.
- Fn if_transmit
- Transmit a packet on an interface or queue it if the interface is in use. This function will return ENOBUFS if the devices software and hardware queues are both full. This function must be installed after Fn if_attach to override the default implementation. This function is exposed in order to allow drivers to manage their own queues and to reduce the latency caused by a frequently gratuitous enqueue / dequeue pair to ifq. The suggested internal software queueing mechanism is buf_ring.
- Fn if_qflush
- Free mbufs in internally managed queues when the interface is marked down. This function must be installed after Fn if_attach to override the default implementation. This function is exposed in order to allow drivers to manage their own queues and to reduce the latency caused by a frequently gratuitous enqueue / dequeue pair to ifq. The suggested internal software queueing mechanism is buf_ring.
- Fn if_start
- Start queued output on an interface. This function is exposed in order to provide for some interface classes to share a Fn if_output among all drivers. Fn if_start may only be called when the IFF_DRV_OACTIVE flag is not set. (Thus, IFF_DRV_OACTIVE does not literally mean that output is active, but rather that the device's internal output queue is full.) Please note that this function will soon be deprecated.
- Fn if_ioctl
- Process interface-related ioctl(2) requests (defined in In sys/sockio.h ) . Preliminary processing is done by the generic routine Fn ifioctl to check for appropriate privileges, locate the interface being manipulated, and perform certain generic operations like twiddling flags and flushing queues. See the description of Fn ifioctl below for more information.
- Fn if_init
- Initialize and bring up the hardware, e.g., reset the chip and enable the receiver unit. Should mark the interface running, but not active ( IFF_DRV_RUNNING , ~IIF_DRV_OACTIVE )
- Fn if_resolvemulti
- Check the requested multicast group membership, Fa addr , for validity, and if necessary compute a link-layer group which corresponds to that address which is returned in Fa *retsa . Returns zero on success, or an error code on failure.
Interface FlagsInterface flags are used for a number of different purposes. Some flags simply indicate information about the type of interface and its capabilities; others are dynamically manipulated to reflect the current state of the interface. Flags of the former kind are marked Aq S in this table; the latter are marked Aq D . Flags which begin with ``IFF_DRV_'' are stored in if_drv_flags all other flags are stored in if_flags
The macro IFF_CANTCHANGE defines the bits which cannot be set by a user program using the SIOCSIFFLAGS command to ioctl(2); these are indicated by an asterisk (`*' ) in the following listing.
- Aq D The interface has been configured up by the user-level code.
- Aq S* The interface supports broadcast.
- Aq D Used to enable/disable driver debugging code.
- Aq S The interface is a loopback device.
- Aq S* The interface is point-to-point; ``broadcast'' address is actually the address of the other end.
- Aq S* The interface manages its own routes, rather than using the generic code in Fn if_up and Fn if_down . This is probably useful for serial lines.
- Aq D* The interface has been configured and dynamic resources were successfully allocated. Probably only useful internal to the interface.
- Aq D Disable network address resolution on this interface.
- Aq D* This interface is in promiscuous mode.
- Aq D This interface is in the permanently promiscuous mode (implies IFF_PROMISC )
- Aq D* This interface is in all-multicasts mode (used by multicast routers).
- Aq D* The interface's hardware output queue (if any) is full; output packets are to be queued.
- Aq S* The interface cannot hear its own transmissions.
- Aq D Control flags for the link layer. (Currently abused to select among multiple physical layers on some devices.)
- Aq S* This interface supports multicast.
- Aq S* The interface is not configurable in a meaningful way. Primarily useful for IFT_USB interfaces registered at the interface list.
- Aq D This interface blocks transmission of packets and discards incoming packets after BPF processing. Used to monitor network traffic but not interact with the network in question.
- Aq D Used to enable/disable ARP requests on this interface.
- Aq D* Set when the Vt ifnet structure of this interface is being released and still has if_refcount references.
- Aq D* Set when this interface is being renamed.
Interface Capabilities FlagsInterface capabilities are specialized features an interface may or may not support. These capabilities are very hardware-specific and allow, when enabled, to offload specific network processing to the interface or to offer a particular feature for use by other kernel parts.
It should be stressed that a capability can be completely uncontrolled (i.e., stay always enabled with no way to disable it) or allow limited control over itself (e.g., depend on another capability's state.) Such peculiarities are determined solely by the hardware and driver of a particular interface. Only the driver possesses the knowledge on whether and how the interface capabilities can be controlled. Consequently, capabilities flags in if_capenable should never be modified directly by kernel code other than the interface driver. The command SIOCSIFCAP to Fn ifioctl is the dedicated means to attempt altering if_capenable on an interface. Userland code shall use ioctl(2).
The following capabilities are currently supported by the system:
- This interface can do checksum validation on receiving data. Some interfaces do not have sufficient buffer storage to store frames above a certain MTU-size completely. The driver for the interface might disable hardware checksum validation if the MTU is set above the hardcoded limit.
- This interface can do checksum calculation on transmitting data.
- A shorthand for (IFCAP_RXCSUM | IFCAP_TXCSUM )
- This interface can be a network console.
- The vlan(4) driver can operate over this interface in software tagging mode without having to decrease MTU on vlan(4) interfaces below 1500 bytes. This implies the ability of this interface to cope with frames somewhat longer than permitted by the Ethernet specification.
- This interface can do VLAN tagging on output and demultiplex frames by their VLAN tag on input.
- This Ethernet interface can transmit and receive frames up to 9000 bytes long.
- This interface supports polling(4). See below for details.
- This interface can do checksum calculation on both transmitting and receiving data on vlan(4) interfaces (implies IFCAP_HWCSUM )
- This Ethernet interface supports TCP4 Segmentation offloading.
- This Ethernet interface supports TCP6 Segmentation offloading.
- A shorthand for (IFCAP_TSO4 | IFCAP_TSO6 )
- This Ethernet interface supports TCP offloading.
- This Ethernet interface supports TCP6 offloading.
- A shorthand for (IFCAP_TOE4 | IFCAP_TOE6 )
- This Ethernet interface supports waking up on any Unicast packet.
- This Ethernet interface supports waking up on any Multicast packet.
- This Ethernet interface supports waking up on any Magic packet such as those sent by wake(8).
- A shorthand for (IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC )
- This Ethernet interface supports TCP4 Offload Engine.
- This Ethernet interface supports TCP6 Offload Engine.
- A shorthand for (IFCAP_TOE4 | IFCAP_TOE6 )
- This interface supports frame filtering in hardware on vlan(4) interfaces.
- The return value for the number of processed packets should be skipped for this interface.
- This interface supports TCP Segmentation offloading on vlan(4) interfaces (implies IFCAP_TSO )
- This Ethernet interface supports dynamic link state changes.
The ability of advanced network interfaces to offload certain computational tasks from the host CPU to the board is limited mostly to TCP/IP. Therefore a separate field associated with an interface (see ifnet.if_data.ifi_hwassist below) keeps a detailed description of its enabled capabilities specific to TCP/IP processing. The TCP/IP module consults the field to see which tasks can be done on an outgoing packet by the interface. The flags defined for that field are a superset of those for mbuf.m_pkthdr.csum_flags namely:
- The interface will compute IP checksums.
- The interface will compute TCP checksums.
- The interface will compute UDP checksums.
- The interface can compute a TCP or UDP checksum for a packet fragmented by the host CPU. Makes sense only along with CSUM_TCP or CSUM_UDP
- The interface will do the fragmentation of IP packets if necessary. The host CPU does not need to care about MTU on this interface as long as a packet to transmit through it is an IP one and it does not exceed the size of the hardware buffer.
An interface notifies the TCP/IP module about the tasks the former has performed on an incoming packet by setting the corresponding flags in the field mbuf.m_pkthdr.csum_flags of the Vt mbuf chain containing the packet. See mbuf(9) for details.
The capability of a network interface to operate in polling(4) mode involves several flags in different global variables and per-interface fields. The capability flag IFCAP_POLLING set in interface's if_capabilities indicates support for polling(4) on the particular interface. If set in if_capabilities the same flag can be marked or cleared in the interface's if_capenable within Fn ifioctl , thus initiating switch of the interface to polling(4) mode or interrupt mode, respectively. The actual mode change is managed by the driver-specific Fn if_ioctl routine. The polling handler returns the number of packets processed.
The Vt if_data
structure contains statistics and identifying information used
by management programs, and which is exported to user programs by way
branch of the
The following elements of the
structure are initialized by the interface and are not expected to change
significantly over the course of normal operation:
- (Vt u_char ) The type of the interface, as defined in In net/if_types.h and described below in the Sx Interface Types section.
- (Vt u_char ) Intended to represent a selection of physical layers on devices which support more than one; never implemented.
- (Vt u_char ) Length of a link-layer address on this device, or zero if there are none. Used to initialized the address length field in Vt sockaddr_dl structures referring to this interface.
- (Vt u_char ) Maximum length of any link-layer header which might be prepended by the driver to a packet before transmission. The generic code computes the maximum over all interfaces and uses that value to influence the placement of data in Vt mbuf Ns s to attempt to ensure that there is always sufficient space to prepend a link-layer header without allocating an additional Vt mbuf .
- (Vt u_char ) Length of the Vt if_data structure. Allows some stabilization of the routing socket ABI in the face of increases in the length of Vt struct ifdata .
- (Vt u_long ) The maximum transmission unit of the medium, exclusive of any link-layer overhead.
- (Vt u_long ) A dimensionless metric interpreted by a user-mode routing process.
- (Vt u_long ) The line rate of the interface, in bits per second.
- (Vt u_long ) A detailed interpretation of the capabilities to offload computational tasks for outgoing packets. The interface driver must keep this field in accord with the current value of if_capenable
- (Vt time_t ) The system uptime when interface was attached or the statistics below were reset. This is intended to be used to set the SNMP variable ifCounterDiscontinuityTime It may also be used to determine if two successive queries for an interface of the same index have returned results for the same interface.
The structure additionally contains generic statistics applicable to a variety of different interface types (except as noted, all members are of type Vt u_long ) :
- (Vt u_char ) The current link state of Ethernet interfaces. See the Sx Interface Link States section for possible values.
- Number of packets received.
- Number of receive errors detected (e.g., FCS errors, DMA overruns, etc.). More detailed breakdowns can often be had by way of a link-specific MIB.
- Number of packets transmitted.
- Number of output errors detected (e.g., late collisions, DMA overruns, etc.). More detailed breakdowns can often be had by way of a link-specific MIB.
- Total number of collisions detected on output for CSMA interfaces. (This member is sometimes [ab]used by other types of interfaces for other output error counts.)
- Total traffic received, in bytes.
- Total traffic transmitted, in bytes.
- Number of packets received which were sent by link-layer multicast.
- Number of packets sent by link-layer multicast.
- Number of packets dropped on input. Rarely implemented.
- Number of packets received for unknown network-layer protocol.
- (Vt struct timeval ) The time of the last administrative change to the interface (as required for SNMP )
Interface TypesThe header file In net/if_types.h defines symbolic constants for a number of different types of interfaces. The most common are:
- none of the following
- ISO 8802-3 CSMA/CD
- ISO 8802-4 Token Bus
- ISO 8802-5 Token Ring
- ISO 8802-6 DQDB MAN
- Internet Point-to-Point Protocol (ppp(8) )
- The loopback (lo(4) ) interface
- Serial Line IP
- Parallel-port IP (``PLIP '' )
- Asynchronous Transfer Mode
- USB Interface
Interface Link StatesThe following link states are currently defined:
- The link is in an invalid or unknown state.
- The link is down.
- The link is up.
The Vt ifaddr
Every interface is associated with a list
(or, rather, a
of addresses, rooted at the interface structure's
The first element in this list is always an
address representing the interface itself; multi-access network
drivers should complete this structure by filling in their link-layer
addresses after calling
Fn if_attach .
Other members of the structure represent network-layer addresses which
have been configured by means of the
called on a socket of the appropriate protocol family.
The elements of this list consist of
Most protocols will declare their own protocol-specific
interface address structures, but all begin with a
Vt struct ifaddr
which provides the most-commonly-needed functionality across all
Interface addresses are reference-counted.
The members of Vt struct ifaddr are as follows:
- (Vt struct sockaddr * ) The local address of the interface.
- (Vt struct sockaddr * ) The remote address of point-to-point interfaces, and the broadcast address of broadcast interfaces. ( ifa_broadaddr is a macro for ifa_dstaddr .
- (Vt struct sockaddr * ) The network mask for multi-access interfaces, and the confusion generator for point-to-point interfaces.
- (Vt struct ifnet * ) A link back to the interface structure.
- (Fn TAILQ_ENTRY ifaddr ) queue(3) glue for list of addresses on each interface.
- See below.
- (Vt u_short ) Some of the flags which would be used for a route representing this address in the route table.
- (Vt short ) The reference count.
- (Vt int ) A metric associated with this interface address, for the use of some external routing protocol.
References to Vt ifaddr structures are gained by calling the Fn ifa_ref function and released by calling the Fn ifa_free function.
Fn ifa_rtrequest is a pointer to a function which receives callouts from the routing code (Fn rtrequest ) to perform link-layer-specific actions upon requests to add, or delete routes. The Fa cmd argument indicates the request in question: RTM_ADD or RTM_DELETE The Fa rt argument is the route in question; the Fa info argument contains the specific destination being manipulated.
FUNCTIONSThe functions provided by the generic interface code can be divided into two groups: those which manipulate interfaces, and those which manipulate interface addresses. In addition to these functions, there may also be link-layer support routines which are used by a number of drivers implementing a specific link layer over different hardware; see the documentation for that link layer for more details.
The Vt ifmultiaddr
Every multicast-capable interface is associated with a list of
multicast group memberships, which indicate at a low level which
link-layer multicast addresses (if any) should be accepted, and at a
high level, in which network-layer multicast groups a user process has
The elements of the structure are as follows:
- (Fn LIST_ENTRY ifmultiaddr ) queue(3) macro glue.
- (Vt struct sockaddr * ) A pointer to the address which this record represents. The memberships for various address families are stored in arbitrary order.
- (Vt struct sockaddr * ) A pointer to the link-layer multicast address, if any, to which the network-layer multicast address in ifma_addr is mapped, else a null pointer. If this element is non-nil, this membership also holds an invisible reference to another membership for that link-layer address.
- (Vt u_int ) A reference count of requests for this particular membership.
Interface Manipulation Functions
- Fn if_alloc
- Allocate and initialize Vt struct ifnet . Initialization includes the allocation of an interface index and may include the allocation of a Fa type specific structure in if_l2com
- Fn if_attach
- Link the specified interface Fa ifp into the list of network interfaces. Also initialize the list of addresses on that interface, and create a link-layer Vt ifaddr structure to be the first element in that list. (A pointer to this address structure is saved in the Vt ifnet structure and shall be accessed by the Fn ifaddr_byindex function.) The Fa ifp must have been allocated by Fn if_alloc .
- Fn if_detach
- Shut down and unlink the specified Fa ifp from the interface list.
- Fn if_free
- Free the given Fa ifp back to the system. The interface must have been previously detached if it was ever attached.
- Fn if_free_type
- Identical to Fn if_free except that the given Fa type is used to free if_l2com instead of the type in if_type This is intended for use with drivers that change their interface type.
- Fn if_down
- Mark the interface Fa ifp as down (i.e., IFF_UP is not set), flush its output queue, notify protocols of the transition, and generate a message from the route(4) routing socket.
- Fn if_up
- Mark the interface Fa ifp as up, notify protocols of the transition, and generate a message from the route(4) routing socket.
- Fn ifpromisc
- Add or remove a promiscuous reference to Fa ifp . If Fa pswitch is true, add a reference; if it is false, remove a reference. On reference count transitions from zero to one and one to zero, set the IFF_PROMISC flag appropriately and call Fn if_ioctl to set up the interface in the desired mode.
- Fn if_allmulti
- As Fn ifpromisc , but for the all-multicasts (IFF_ALLMULTI ) flag instead of the promiscuous flag.
- Fn ifunit
- Return an Vt ifnet pointer for the interface named Fa name .
- Fn ifunit_ref
- Return a reference-counted (via Fn ifa_ref ) Vt ifnet pointer for the interface named Fa name . This is the preferred function over Fn ifunit . The caller is responsible for releasing the reference with Fn if_rele when it is finished with the ifnet.
- Fn ifioctl
Process the ioctl request
Fa cmd ,
issued on socket
Fa td ,
with data parameter
Fa data .
This is the main routine for handling all interface configuration
requests from user mode.
It is ordinarily only called from the socket-layer
handler, and only for commands with class
Any unrecognized commands will be passed down to socket
Fa so Ns 's
The following commands are handled by
Fn ifioctl :
Get interface configuration.
(No call-down to driver.)
- Set the interface name. RTM_IFANNOUNCE departure and arrival messages are sent so that routing code that relies on the interface name will update its interface list. Caller must have appropriate privilege. (No call-down to driver.)
Get interface capabilities, FIB, flags, metric, MTU, medium selection.
(No call-down to driver.)
Enable or disable interface capabilities.
Caller must have appropriate privilege.
Before a call to the driver-specific
routine, the requested mask for enabled capabilities is checked
against the mask of capabilities supported by the interface,
Requesting to enable an unsupported capability is invalid.
The rest is supposed to be done by the driver,
which includes updating
- Sets interface FIB. Caller must have appropriate privilege. FIB values start at 0 and values greater or equals than net.fibs are considered invalid.
Change interface flags.
Caller must have appropriate privilege.
If a change to the
flag is requested,
is called as appropriate.
Flags listed in
are masked off, and the field
in the interface structure is updated.
Finally, the driver
routine is called to perform any setup
Change interface metric or medium.
Caller must have appropriate privilege.
Change interface MTU.
Caller must have appropriate privilege.
values less than 72 or greater than 65535 are considered invalid.
routine is called to implement the change; it is responsible for any
additional sanity checking and for actually modifying the MTU in the
Add or delete permanent multicast group memberships on the interface.
Caller must have appropriate privilege.
function is called to perform the operation; qq.v.
The socket's protocol control routine is called to implement the
- The socket's protocol control routine is called to implement the requested action. On return, Vt sockaddr structures are converted into old-style (no sa_len member).
Fn if_down , Fn ifioctl , Fn ifpromisc , and Fn if_up must be called at Fn splnet or higher.
Interface Address FunctionsSeveral functions exist to look up an interface address structure given an address. Fn ifa_ifwithaddr returns an interface address with either a local address or a broadcast address precisely matching the parameter Fa addr . Fn ifa_ifwithdstaddr returns an interface address for a point-to-point interface whose remote (``destination'' ) address is Fa addr .
Fn ifa_ifwithnet returns the most specific interface address which matches the specified address, Fa addr , subject to its configured netmask, or a point-to-point interface address whose remote address is Fa addr if one is found. If Fa ignore_ptp is true, skip point-to-point interface addresses.
Fn ifaof_ifpforaddr returns the most specific address configured on interface Fa ifp which matches address Fa addr , subject to its configured netmask. If the interface is point-to-point, only an interface address whose remote address is precisely Fa addr will be returned.
Fn ifaddr_byindex returns the link-level address of the interface with the given index Fa idx .
All of these functions return a null pointer if no such address can be found.
Interface Multicast Address FunctionsThe Fn if_addmulti , Fn if_delmulti , and Fn if_findmulti functions provide support for requesting and relinquishing multicast group memberships, and for querying an interface's membership list, respectively. The Fn if_addmulti function takes a pointer to an interface, Fa ifp , and a generic address, Fa sa . It also takes a pointer to a Vt struct ifmultiaddr * which is filled in on successful return with the address of the group membership control block. The Fn if_addmulti function performs the following four-step process:
- Call the interface's Fn if_resolvemulti entry point to determine the link-layer address, if any, corresponding to this membership request, and also to give the link layer an opportunity to veto this membership request should it so desire.
- Check the interface's group membership list for a pre-existing membership for this group. If one is not found, allocate a new one; if one is, increment its reference count.
- If the Fn if_resolvemulti routine returned a link-layer address corresponding to the group, repeat the previous step for that address as well.
- If the interface's multicast address filter needs to be changed because a new membership was added, call the interface's Fn if_ioctl routine (with a Fa cmd argument of SIOCADDMULTI to request that it do so.
The Fn if_delmulti function, given an interface Fa ifp and an address, Fa sa , reverses this process. Both functions return zero on success, or a standard error number on failure.
The Fn if_findmulti function examines the membership list of interface Fa ifp for an address matching Fa sa , and returns a pointer to that Vt struct ifmultiaddr if one is found, else it returns a null pointer.
SEE ALSOioctl(2), link_addr3, queue(3), sysctl(3), bpf(4), ifmib(4), lo(4), netintro(4), polling(4), config(8), ppp(8), mbuf(9), rtentry(9)
- Gary R. Wright W. Richard Stevens TCP/IP Illustrated Vol. 2 Addison-Wesley, ISBN 0-201-63354-X