2 .\" Copyright 1996, 1997 Massachusetts Institute of Technology
4 .\" Permission to use, copy, modify, and distribute this software and
5 .\" its documentation for any purpose and without fee is hereby
6 .\" granted, provided that both the above copyright notice and this
7 .\" permission notice appear in all copies, that both the above
8 .\" copyright notice and this permission notice appear in all
9 .\" supporting documentation, and that the name of M.I.T. not be used
10 .\" in advertising or publicity pertaining to distribution of the
11 .\" software without specific, written prior permission. M.I.T. makes
12 .\" no representations about the suitability of this software for any
13 .\" purpose. It is provided "as is" without express or implied
16 .\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
17 .\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
20 .\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 .\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 .\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 .Nd kernel interfaces for manipulating network interfaces
48 .Ss "Interface Manipulation Functions"
50 .Fn if_alloc "u_char type"
52 .Fn if_attach "struct ifnet *ifp"
54 .Fn if_detach "struct ifnet *ifp"
56 .Fn if_free "struct ifnet *ifp"
58 .Fn if_free_type "struct ifnet *ifp" "u_char type"
60 .Fn if_down "struct ifnet *ifp"
62 .Fn ifioctl "struct socket *so" "u_long cmd" "caddr_t data" "struct thread *td"
64 .Fn ifpromisc "struct ifnet *ifp" "int pswitch"
66 .Fn if_allmulti "struct ifnet *ifp" "int amswitch"
68 .Fn ifunit "const char *name"
70 .Fn ifunit_ref "const char *name"
72 .Fn if_up "struct ifnet *ifp"
74 .Ss "Interface Address Functions"
76 .Fn ifaddr_byindex "u_short idx"
78 .Fn ifa_ifwithaddr "struct sockaddr *addr"
80 .Fn ifa_ifwithdstaddr "struct sockaddr *addr" "int fib"
82 .Fn ifa_ifwithnet "struct sockaddr *addr" "int ignore_ptp" "int fib"
84 .Fn ifaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp"
86 .Fn ifa_ref "struct ifaddr *ifa"
88 .Fn ifa_free "struct ifaddr *ifa"
90 .Ss "Interface Multicast Address Functions"
92 .Fn if_addmulti "struct ifnet *ifp" "struct sockaddr *sa" "struct ifmultiaddr **ifmap"
94 .Fn if_delmulti "struct ifnet *ifp" "struct sockaddr *sa"
95 .Ft "struct ifmultiaddr *"
96 .Fn if_findmulti "struct ifnet *ifp" "struct sockaddr *sa"
97 .Ss "Output queue macros"
98 .Fn IF_DEQUEUE "struct ifqueue *ifq" "struct mbuf *m"
100 .Ss "struct ifnet Member Functions"
102 .Fn \*(lp*if_input\*(rp "struct ifnet *ifp" "struct mbuf *m"
104 .Fo \*(lp*if_output\*(rp
105 .Fa "struct ifnet *ifp" "struct mbuf *m"
106 .Fa "const struct sockaddr *dst" "struct route *ro"
109 .Fn \*(lp*if_start\*(rp "struct ifnet *ifp"
111 .Fn \*(lp*if_transmit\*(rp "struct ifnet *ifp" "struct mbuf *m"
113 .Fn \*(lp*if_qflush\*(rp "struct ifnet *ifp"
115 .Fn \*(lp*if_ioctl\*(rp "struct ifnet *ifp" "u_long cmd" "caddr_t data"
117 .Fn \*(lp*if_init\*(rp "void *if_softc"
119 .Fo \*(lp*if_resolvemulti\*(rp
120 .Fa "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr"
122 .Ss "struct ifaddr member function"
124 .Fo \*(lp*ifa_rtrequest\*(rp
125 .Fa "int cmd" "struct rtentry *rt" "struct rt_addrinfo *info"
128 .Ss "Global Variables"
129 .Vt extern struct ifnethead ifnet ;
130 .\" extern struct ifindex_entry *ifindex_table ;
131 .Vt extern int if_index ;
132 .Vt extern int ifqmaxlen ;
134 The kernel mechanisms for handling network interfaces reside primarily
136 .Vt ifnet , if_data , ifaddr ,
143 and the functions named above and defined in
145 Those interfaces which are intended to be used by user programs
148 these include the interface flags, the
150 structure, and the structures defining the appearance of
151 interface-related messages on the
153 routing socket and in
157 defines the kernel-internal interfaces, including the
161 structures and the functions which manipulate them.
162 (A few user programs will need
164 because it is the prerequisite of some other header file like
165 .In netinet/if_ether.h .
166 Most references to those two files in particular can be replaced by
167 .In net/ethernet.h . )
169 The system keeps a linked list of interfaces using the
173 this list is headed by a
174 .Vt "struct ifnethead"
177 The elements of this list are of type
179 and most kernel routines which manipulate interface as such accept or
180 return pointers to these structures.
181 Each interface structure
184 structure used for statistics and information.
185 Each interface also has a
187 of interface addresses, described by
195 describing the link layer implemented by the interface (if any)
201 (Some trivial interfaces do not provide any link layer addresses;
202 this structure, while still present, serves only to identify the
203 interface name and index.)
205 Finally, those interfaces supporting reception of multicast datagrams
208 of multicast group memberships, described by
211 These memberships are reference-counted.
213 Interfaces are also associated with an output queue, defined as a
214 .Vt "struct ifqueue" ;
215 this structure is used to hold packets while the interface is in the
216 process of sending another.
218 .Ss The ifnet Structure
222 .Bl -tag -width ".Va if_capabilities" -offset indent
225 A pointer to the driver's private state block.
226 (Initialized by driver.)
229 A pointer to the common data for the interface's layer 2 protocol.
233 .Pq Vt "struct vnet *"
234 A pointer to the virtual network stack instance.
238 .Pq Vt "struct vnet *"
239 A pointer to the parent virtual network stack, where this
245 .Pq Fn TAILQ_ENTRY ifnet
250 The name of the interface,
255 (Initialized by driver
257 .Fn if_initname ) . )
259 .Pq Vt "const char *"
260 The name of the driver.
261 (Initialized by driver
263 .Fn if_initname ) . )
266 A unique number assigned to each interface managed by a particular
268 Drivers may choose to set this to
270 if a unit number is not associated with the device.
271 (Initialized by driver
273 .Fn if_initname ) . )
280 .Pq Vt "struct ifaddrhead"
284 containing the list of addresses assigned to this interface.
287 A count of promiscuous listeners on this interface, used to
292 .Pq Vt "struct carp_if *"
293 A pointer to the CARP interface structure,
295 (Initialized by the driver-specific
299 .Pq Vt "struct bpf_if *"
300 Opaque per-interface data for the packet filter,
306 A unique number assigned to each interface in sequence as it is
308 This number can be used in a
309 .Vt "struct sockaddr_dl"
310 to refer to a particular interface by index
316 .Pq Vt struct ifvlantrunk *
317 A pointer to 802.1Q trunk structure,
319 (Initialized by the driver-specific
324 Flags describing operational parameters of this interface (see below).
325 (Manipulated by generic code.)
328 Flags describing operational status of this interface (see below).
329 (Manipulated by driver.)
330 .It Va if_capabilities
332 Flags describing the capabilities the interface supports (see below).
335 Flags describing the enabled capabilities of the interface (see below).
338 A pointer to an interface-specific MIB structure exported by
340 (Initialized by driver.)
343 The size of said structure.
344 (Initialized by driver.)
346 .Pq Vt "struct if_data"
347 More statistics and information; see
348 .Sx "The if_data structure" ,
350 (Initialized by driver, manipulated by both driver and generic
353 .Pq Vt struct ifmultihead
357 containing the list of multicast addresses assigned to this interface.
360 A number of multicast requests on this interface, used to
365 .Pq Vt "struct ifaddr *"
366 A pointer to the link-level interface address.
369 .\" .It Va if_llsoftc
371 .\" The purpose of the field is unclear.
373 .Pq Vt "struct ifaltq"
375 (Manipulated by driver.)
376 .It Va if_broadcastaddr
377 .Pq Vt "const u_int8_t *"
378 A link-level broadcast bytestring for protocols with variable address
382 A pointer to the bridge interface structure,
384 (Initialized by the driver-specific
388 .Pq Vt "struct label *"
389 A pointer to the MAC Framework label structure,
395 An address family dependent data region.
396 .It Va if_afdata_initialized
398 Used to track the current state of address family initialization.
399 .It Va if_afdata_lock
400 .Pq Vt "struct rwlock"
410 task scheduled for link state change events of the interface.
412 .Pq Vt "struct rwlock"
415 lock used to protect interface-related address lists.
417 .Pq Fn LIST_ENTRY ifnet
419 macro glue for the list of clonable network interfaces.
421 .Pq Fn TAILQ_HEAD "" "ifg_list"
425 containing the list of groups per interface.
428 A pointer to the structure used for interface abstraction by
437 The type of the interface as it was at the time of its allocation.
438 It is used to cache the type passed to
442 it would not be changed by drivers.
447 structures are gained by calling the
449 function and released by calling the
452 They are used to allow kernel code walking global interface lists
459 There are in addition a number of function pointers which the driver
460 must initialize to complete its interface with the generic interface
462 .Bl -ohang -offset indent
464 Pass a packet to an appropriate upper layer as determined
465 from the link-layer header of the packet.
466 This routine is to be called from an interrupt handler or
467 used to emulate reception of a packet on this interface.
468 A single function implementing
470 can be shared among multiple drivers utilizing the same link-layer
471 framing, e.g., Ethernet.
473 Output a packet on interface
475 or queue it on the output queue if the interface is already active.
477 Transmit a packet on an interface or queue it if the interface is
479 This function will return
481 if the devices software and hardware queues are both full.
482 This function must be installed after
484 to override the default implementation.
485 This function is exposed in order to allow drivers to manage their own queues
486 and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
488 The suggested internal software queueing mechanism is buf_ring.
490 Free mbufs in internally managed queues when the interface is marked down.
491 This function must be installed after
493 to override the default implementation.
494 This function is exposed in order to allow drivers to manage their own queues
495 and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
497 The suggested internal software queueing mechanism is buf_ring.
499 Start queued output on an interface.
500 This function is exposed in
501 order to provide for some interface classes to share a
505 may only be called when the
510 does not literally mean that output is active, but rather that the
511 device's internal output queue is full.) Please note that this function
512 will soon be deprecated.
514 Process interface-related
519 Preliminary processing is done by the generic routine
521 to check for appropriate privileges, locate the interface being
522 manipulated, and perform certain generic operations like twiddling
523 flags and flushing queues.
524 See the description of
526 below for more information.
528 Initialize and bring up the hardware,
529 e.g., reset the chip and enable the receiver unit.
530 Should mark the interface running,
532 .Dv ( IFF_DRV_RUNNING , ~IIF_DRV_OACTIVE ) .
533 .It Fn if_resolvemulti
534 Check the requested multicast group membership,
536 for validity, and if necessary compute a link-layer group which
537 corresponds to that address which is returned in
539 Returns zero on success, or an error code on failure.
541 .Ss "Interface Flags"
542 Interface flags are used for a number of different purposes.
544 flags simply indicate information about the type of interface and its
545 capabilities; others are dynamically manipulated to reflect the
546 current state of the interface.
547 Flags of the former kind are marked
549 in this table; the latter are marked
551 Flags which begin with
555 all other flags are stored in
560 defines the bits which cannot be set by a user program using the
564 these are indicated by an asterisk
566 in the following listing.
568 .Bl -tag -width ".Dv IFF_POINTOPOINT" -offset indent -compact
571 The interface has been configured up by the user-level code.
574 The interface supports broadcast.
577 Used to enable/disable driver debugging code.
580 The interface is a loopback device.
581 .It Dv IFF_POINTOPOINT
583 The interface is point-to-point;
585 address is actually the address of the other end.
586 .It Dv IFF_DRV_RUNNING
588 The interface has been configured and dynamic resources were
589 successfully allocated.
590 Probably only useful internal to the
594 Disable network address resolution on this interface.
597 This interface is in promiscuous mode.
600 This interface is in the permanently promiscuous mode (implies
604 This interface is in all-multicasts mode (used by multicast routers).
605 .It Dv IFF_DRV_OACTIVE
607 The interface's hardware output queue (if any) is full; output packets
611 The interface cannot hear its own transmissions.
616 Control flags for the link layer.
617 (Currently abused to select among
618 multiple physical layers on some devices.)
621 This interface supports multicast.
622 .It Dv IFF_CANTCONFIG
624 The interface is not configurable in a meaningful way.
627 interfaces registered at the interface list.
630 This interface blocks transmission of packets and discards incoming
631 packets after BPF processing.
632 Used to monitor network traffic but not interact
633 with the network in question.
636 Used to enable/disable ARP requests on this interface.
641 structure of this interface is being released and still has
646 Set when this interface is being renamed.
648 .Ss "Interface Capabilities Flags"
649 Interface capabilities are specialized features an interface may
651 These capabilities are very hardware-specific
652 and allow, when enabled,
653 to offload specific network processing to the interface
654 or to offer a particular feature for use by other kernel parts.
656 It should be stressed that a capability can be completely
657 uncontrolled (i.e., stay always enabled with no way to disable it)
658 or allow limited control over itself (e.g., depend on another
660 Such peculiarities are determined solely by the hardware and driver
661 of a particular interface.
662 Only the driver possesses
663 the knowledge on whether and how the interface capabilities
665 Consequently, capabilities flags in
667 should never be modified directly by kernel code other than
668 the interface driver.
673 is the dedicated means to attempt altering
676 Userland code shall use
679 The following capabilities are currently supported by the system:
680 .Bl -tag -width ".Dv IFCAP_POLLING_NOCOUNT" -offset indent
682 This interface can do checksum validation on receiving data.
683 Some interfaces do not have sufficient buffer storage to store frames
684 above a certain MTU-size completely.
685 The driver for the interface might disable hardware checksum validation
686 if the MTU is set above the hardcoded limit.
688 This interface can do checksum calculation on transmitting data.
691 .Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM .
693 This interface can be a network console.
694 .It Dv IFCAP_VLAN_MTU
697 driver can operate over this interface in software tagging mode
698 without having to decrease MTU on
700 interfaces below 1500 bytes.
701 This implies the ability of this interface to cope with frames somewhat
702 longer than permitted by the Ethernet specification.
703 .It Dv IFCAP_VLAN_HWTAGGING
704 This interface can do VLAN tagging on output and
705 demultiplex frames by their VLAN tag on input.
706 .It Dv IFCAP_JUMBO_MTU
707 This Ethernet interface can transmit and receive frames up to
710 This interface supports
712 See below for details.
713 .It Dv IFCAP_VLAN_HWCSUM
714 This interface can do checksum calculation on both transmitting
715 and receiving data on
720 This Ethernet interface supports TCP4 Segmentation offloading.
722 This Ethernet interface supports TCP6 Segmentation offloading.
725 .Pq Dv IFCAP_TSO4 | IFCAP_TSO6 .
727 This Ethernet interface supports TCP offloading.
729 This Ethernet interface supports TCP6 offloading.
732 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
733 .It Dv IFCAP_WOL_UCAST
734 This Ethernet interface supports waking up on any Unicast packet.
735 .It Dv IFCAP_WOL_MCAST
736 This Ethernet interface supports waking up on any Multicast packet.
737 .It Dv IFCAP_WOL_MAGIC
738 This Ethernet interface supports waking up on any Magic packet such
743 .Pq Dv IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC .
745 This Ethernet interface supports TCP4 Offload Engine.
747 This Ethernet interface supports TCP6 Offload Engine.
750 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
751 .It Dv IFCAP_VLAN_HWFILTER
752 This interface supports frame filtering in hardware on
755 .It Dv IFCAP_POLLING_NOCOUNT
756 The return value for the number of processed packets should be
757 skipped for this interface.
758 .It Dv IFCAP_VLAN_HWTSO
759 This interface supports TCP Segmentation offloading on
763 .It Dv IFCAP_LINKSTATE
764 This Ethernet interface supports dynamic link state changes.
767 The ability of advanced network interfaces to offload certain
768 computational tasks from the host CPU to the board is limited
770 Therefore a separate field associated with an interface
772 .Va ifnet.if_data.ifi_hwassist
774 keeps a detailed description of its enabled capabilities
775 specific to TCP/IP processing.
776 The TCP/IP module consults the field to see which tasks
779 packet by the interface.
780 The flags defined for that field are a superset of those for
781 .Va mbuf.m_pkthdr.csum_flags ,
783 .Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent
785 The interface will compute IP checksums.
787 The interface will compute TCP checksums.
789 The interface will compute UDP checksums.
791 The interface can compute a TCP or UDP checksum for a packet
792 fragmented by the host CPU.
793 Makes sense only along with
798 The interface will do the fragmentation of IP packets if necessary.
799 The host CPU does not need to care about MTU on this interface
800 as long as a packet to transmit through it is an IP one and it
801 does not exceed the size of the hardware buffer.
804 An interface notifies the TCP/IP module about the tasks
805 the former has performed on an
807 packet by setting the corresponding flags in the field
808 .Va mbuf.m_pkthdr.csum_flags
811 containing the packet.
816 The capability of a network interface to operate in
818 mode involves several flags in different
819 global variables and per-interface fields.
824 indicates support for
826 on the particular interface.
828 .Va if_capabilities ,
829 the same flag can be marked or cleared in the interface's
833 thus initiating switch of the interface to
837 The actual mode change is managed by the driver-specific
842 handler returns the number of packets processed.
843 .Ss The if_data Structure
846 structure contains statistics and identifying information used
847 by management programs, and which is exported to user programs by way
853 The following elements of the
855 structure are initialized by the interface and are not expected to change
856 significantly over the course of normal operation:
857 .Bl -tag -width ".Va ifi_lastchange" -offset indent
860 The type of the interface, as defined in
862 and described below in the
863 .Sx "Interface Types"
867 Intended to represent a selection of physical layers on devices which
868 support more than one; never implemented.
871 Length of a link-layer address on this device, or zero if there are
873 Used to initialized the address length field in
875 structures referring to this interface.
878 Maximum length of any link-layer header which might be prepended by
879 the driver to a packet before transmission.
880 The generic code computes
881 the maximum over all interfaces and uses that value to influence the
884 to attempt to ensure that there is always
885 sufficient space to prepend a link-layer header without allocating an
893 Allows some stabilization of the routing socket ABI in the face of
894 increases in the length of
898 The maximum transmission unit of the medium, exclusive of any
902 A dimensionless metric interpreted by a user-mode routing process.
905 The line rate of the interface, in bits per second.
908 A detailed interpretation of the capabilities
909 to offload computational tasks for
912 The interface driver must keep this field in accord with
917 The system uptime when interface was attached or the statistics
919 This is intended to be used to set the SNMP variable
920 .Va ifCounterDiscontinuityTime .
921 It may also be used to determine if two successive queries for an
922 interface of the same index have returned results for the same
926 The structure additionally contains generic statistics applicable to a
927 variety of different interface types (except as noted, all members are
930 .Bl -tag -width ".Va ifi_lastchange" -offset indent
931 .It Va ifi_link_state
933 The current link state of Ethernet interfaces.
935 .Sx Interface Link States
936 section for possible values.
938 Number of packets received.
940 Number of receive errors detected (e.g., FCS errors, DMA overruns,
942 More detailed breakdowns can often be had by way of a
945 Number of packets transmitted.
947 Number of output errors detected (e.g., late collisions, DMA overruns,
949 More detailed breakdowns can often be had by way of a
951 .It Va ifi_collisions
952 Total number of collisions detected on output for CSMA interfaces.
953 (This member is sometimes [ab]used by other types of interfaces for
954 other output error counts.)
956 Total traffic received, in bytes.
958 Total traffic transmitted, in bytes.
960 Number of packets received which were sent by link-layer multicast.
962 Number of packets sent by link-layer multicast.
964 Number of packets dropped on input.
967 Number of packets received for unknown network-layer protocol.
968 .It Va ifi_lastchange
969 .Pq Vt "struct timeval"
970 The time of the last administrative change to the interface (as required
977 defines symbolic constants for a number of different types of
981 .Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact
983 none of the following
991 ISO 8802-5 Token Ring
997 Internet Point-to-Point Protocol
1009 Asynchronous Transfer Mode
1013 .Ss Interface Link States
1014 The following link states are currently defined:
1016 .Bl -tag -offset indent -width ".Dv LINK_STATE_UNKNOWN" -compact
1017 .It Dv LINK_STATE_UNKNOWN
1018 The link is in an invalid or unknown state.
1019 .It Dv LINK_STATE_DOWN
1021 .It Dv LINK_STATE_UP
1024 .Ss The ifaddr Structure
1025 Every interface is associated with a list
1028 of addresses, rooted at the interface structure's
1031 The first element in this list is always an
1033 address representing the interface itself; multi-access network
1034 drivers should complete this structure by filling in their link-layer
1035 addresses after calling
1037 Other members of the structure represent network-layer addresses which
1038 have been configured by means of the
1042 called on a socket of the appropriate protocol family.
1043 The elements of this list consist of
1046 Most protocols will declare their own protocol-specific
1047 interface address structures, but all begin with a
1049 which provides the most-commonly-needed functionality across all
1051 Interface addresses are reference-counted.
1056 .Bl -tag -width ".Va ifa_rtrequest" -offset indent
1058 .Pq Vt "struct sockaddr *"
1059 The local address of the interface.
1061 .Pq Vt "struct sockaddr *"
1062 The remote address of point-to-point interfaces, and the broadcast
1063 address of broadcast interfaces.
1068 .Pq Vt "struct sockaddr *"
1069 The network mask for multi-access interfaces, and the confusion
1070 generator for point-to-point interfaces.
1072 .Pq Vt "struct ifnet *"
1073 A link back to the interface structure.
1075 .Pq Fn TAILQ_ENTRY ifaddr
1077 glue for list of addresses on each interface.
1078 .It Va ifa_rtrequest
1082 Some of the flags which would be used for a route representing this
1083 address in the route table.
1086 The reference count.
1091 structures are gained by calling the
1093 function and released by calling the
1098 is a pointer to a function which receives callouts from the routing
1101 to perform link-layer-specific actions upon requests to add,
1105 argument indicates the request in question:
1111 argument is the route in question; the
1113 argument contains the specific destination being manipulated.
1115 The functions provided by the generic interface code can be divided
1116 into two groups: those which manipulate interfaces, and those which
1117 manipulate interface addresses.
1118 In addition to these functions, there
1119 may also be link-layer support routines which are used by a number of
1120 drivers implementing a specific link layer over different hardware;
1121 see the documentation for that link layer for more details.
1122 .Ss The ifmultiaddr Structure
1123 Every multicast-capable interface is associated with a list of
1124 multicast group memberships, which indicate at a low level which
1125 link-layer multicast addresses (if any) should be accepted, and at a
1126 high level, in which network-layer multicast groups a user process has
1129 The elements of the structure are as follows:
1130 .Bl -tag -width ".Va ifma_refcount" -offset indent
1132 .Pq Fn LIST_ENTRY ifmultiaddr
1136 .Pq Vt "struct sockaddr *"
1137 A pointer to the address which this record represents.
1139 memberships for various address families are stored in arbitrary
1142 .Pq Vt "struct sockaddr *"
1143 A pointer to the link-layer multicast address, if any, to which the
1144 network-layer multicast address in
1146 is mapped, else a null pointer.
1147 If this element is non-nil, this
1148 membership also holds an invisible reference to another membership for
1149 that link-layer address.
1150 .It Va ifma_refcount
1152 A reference count of requests for this particular membership.
1154 .Ss Interface Manipulation Functions
1155 .Bl -ohang -offset indent
1157 Allocate and initialize
1158 .Vt "struct ifnet" .
1159 Initialization includes the allocation of an interface index and may
1160 include the allocation of a
1162 specific structure in
1165 Link the specified interface
1167 into the list of network interfaces.
1168 Also initialize the list of
1169 addresses on that interface, and create a link-layer
1171 structure to be the first element in that list.
1173 this address structure is saved in the
1175 structure and is accessed by the
1180 must have been allocated by
1183 Shut down and unlink the specified
1185 from the interface list.
1190 The interface must have been previously detached if it was ever attached.
1194 except that the given
1198 instead of the type in
1200 This is intended for use with drivers that change their interface type.
1207 flush its output queue, notify protocols of the transition,
1208 and generate a message from the
1214 as up, notify protocols of the transition,
1215 and generate a message from the
1219 Add or remove a promiscuous reference to
1223 is true, add a reference;
1224 if it is false, remove a reference.
1225 On reference count transitions
1226 from zero to one and one to zero, set the
1228 flag appropriately and call
1230 to set up the interface in the desired mode.
1234 but for the all-multicasts
1236 flag instead of the promiscuous flag.
1240 pointer for the interface named
1243 Return a reference-counted (via
1246 pointer for the interface named
1248 This is the preferred function over
1250 The caller is responsible for releasing the reference with
1252 when it is finished with the ifnet.
1254 Process the ioctl request
1262 This is the main routine for handling all interface configuration
1263 requests from user mode.
1264 It is ordinarily only called from the socket-layer
1266 handler, and only for commands with class
1268 Any unrecognized commands will be passed down to socket
1271 further interpretation.
1272 The following commands are handled by
1275 .Bl -tag -width ".Dv SIOCGIFNETMASK" -offset indent -compact
1277 Get interface configuration.
1278 (No call-down to driver.)
1281 Set the interface name.
1283 departure and arrival messages are sent so that
1284 routing code that relies on the interface name will update its interface
1286 Caller must have appropriate privilege.
1287 (No call-down to driver.)
1291 .It Dv SIOCGIFMETRIC
1294 Get interface capabilities, FIB, flags, metric, MTU, medium selection.
1295 (No call-down to driver.)
1298 Enable or disable interface capabilities.
1299 Caller must have appropriate privilege.
1300 Before a call to the driver-specific
1302 routine, the requested mask for enabled capabilities is checked
1303 against the mask of capabilities supported by the interface,
1304 .Va if_capabilities .
1305 Requesting to enable an unsupported capability is invalid.
1306 The rest is supposed to be done by the driver,
1307 which includes updating
1310 .Va if_data.ifi_hwassist
1315 Caller must have appropriate privilege.
1316 FIB values start at 0 and values greater or equals than
1318 are considered invalid.
1320 Change interface flags.
1321 Caller must have appropriate privilege.
1328 is called as appropriate.
1331 are masked off, and the field
1333 in the interface structure is updated.
1336 routine is called to perform any setup
1339 .It Dv SIOCSIFMETRIC
1341 Change interface metric or medium.
1342 Caller must have appropriate privilege.
1345 Change interface MTU.
1346 Caller must have appropriate privilege.
1348 values less than 72 or greater than 65535 are considered invalid.
1351 routine is called to implement the change; it is responsible for any
1352 additional sanity checking and for actually modifying the MTU in the
1353 interface structure.
1357 Add or delete permanent multicast group memberships on the interface.
1358 Caller must have appropriate privilege.
1363 function is called to perform the operation; qq.v.
1367 The socket's protocol control routine is called to implement the
1380 .Ss "Interface Address Functions"
1381 Several functions exist to look up an interface address structure
1384 returns an interface address with either a local address or a
1385 broadcast address precisely matching the parameter
1387 .Fn ifa_ifwithdstaddr
1388 returns an interface address for a point-to-point interface whose
1399 then the first interface address matching
1404 returns the most specific interface address which matches the
1407 subject to its configured netmask, or a point-to-point interface
1408 address whose remote address is
1413 is true, skip point-to-point interface addresses.
1416 parameter is handled the same way as by
1417 .Fn ifa_ifwithdstaddr .
1419 .Fn ifaof_ifpforaddr
1420 returns the most specific address configured on interface
1422 which matches address
1424 subject to its configured netmask.
1426 point-to-point, only an interface address whose remote address is
1432 returns the link-level address of the interface with the given index
1435 All of these functions return a null pointer if no such address can be
1437 .Ss "Interface Multicast Address Functions"
1443 functions provide support for requesting and relinquishing multicast
1444 group memberships, and for querying an interface's membership list,
1448 function takes a pointer to an interface,
1450 and a generic address,
1452 It also takes a pointer to a
1453 .Vt "struct ifmultiaddr *"
1454 which is filled in on successful return with the address of the
1455 group membership control block.
1458 function performs the following four-step process:
1459 .Bl -enum -offset indent
1461 Call the interface's
1463 entry point to determine the link-layer address, if any, corresponding
1464 to this membership request, and also to give the link layer an
1465 opportunity to veto this membership request should it so desire.
1467 Check the interface's group membership list for a pre-existing
1468 membership for this group.
1469 If one is not found, allocate a new one;
1470 if one is, increment its reference count.
1474 routine returned a link-layer address corresponding to the group,
1475 repeat the previous step for that address as well.
1477 If the interface's multicast address filter needs to be changed
1478 because a new membership was added, call the interface's
1485 to request that it do so.
1490 function, given an interface
1494 reverses this process.
1495 Both functions return zero on success, or a
1496 standard error number on failure.
1500 function examines the membership list of interface
1502 for an address matching
1504 and returns a pointer to that
1505 .Vt "struct ifmultiaddr"
1506 if one is found, else it returns a null pointer.
1523 .%A W. Richard Stevens
1524 .%B TCP/IP Illustrated
1526 .%O Addison-Wesley, ISBN 0-201-63354-X
1529 This manual page was written by
1530 .An Garrett A. Wollman .