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_alloc_dev "u_char type" "device_t dev"
54 .Fn if_alloc_domain "u_char type" "int numa_domain"
56 .Fn if_attach "struct ifnet *ifp"
58 .Fn if_detach "struct ifnet *ifp"
60 .Fn if_free "struct ifnet *ifp"
62 .Fn if_free_type "struct ifnet *ifp" "u_char type"
64 .Fn if_down "struct ifnet *ifp"
66 .Fn ifioctl "struct socket *so" "u_long cmd" "caddr_t data" "struct thread *td"
68 .Fn ifpromisc "struct ifnet *ifp" "int pswitch"
70 .Fn if_allmulti "struct ifnet *ifp" "int amswitch"
72 .Fn ifunit "const char *name"
74 .Fn ifunit_ref "const char *name"
76 .Fn if_up "struct ifnet *ifp"
78 .Ss "Interface Address Functions"
80 .Fn ifaddr_byindex "u_short idx"
82 .Fn ifa_ifwithaddr "struct sockaddr *addr"
84 .Fn ifa_ifwithdstaddr "struct sockaddr *addr" "int fib"
86 .Fn ifa_ifwithnet "struct sockaddr *addr" "int ignore_ptp" "int fib"
88 .Fn ifaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp"
90 .Fn ifa_ref "struct ifaddr *ifa"
92 .Fn ifa_free "struct ifaddr *ifa"
94 .Ss "Interface Multicast Address Functions"
96 .Fn if_addmulti "struct ifnet *ifp" "struct sockaddr *sa" "struct ifmultiaddr **ifmap"
98 .Fn if_delmulti "struct ifnet *ifp" "struct sockaddr *sa"
99 .Ft "struct ifmultiaddr *"
100 .Fn if_findmulti "struct ifnet *ifp" "struct sockaddr *sa"
101 .Ss "Output queue macros"
102 .Fn IF_DEQUEUE "struct ifqueue *ifq" "struct mbuf *m"
104 .Ss "struct ifnet Member Functions"
106 .Fn \*(lp*if_input\*(rp "struct ifnet *ifp" "struct mbuf *m"
108 .Fo \*(lp*if_output\*(rp
109 .Fa "struct ifnet *ifp" "struct mbuf *m"
110 .Fa "const struct sockaddr *dst" "struct route *ro"
113 .Fn \*(lp*if_start\*(rp "struct ifnet *ifp"
115 .Fn \*(lp*if_transmit\*(rp "struct ifnet *ifp" "struct mbuf *m"
117 .Fn \*(lp*if_qflush\*(rp "struct ifnet *ifp"
119 .Fn \*(lp*if_ioctl\*(rp "struct ifnet *ifp" "u_long cmd" "caddr_t data"
121 .Fn \*(lp*if_init\*(rp "void *if_softc"
123 .Fo \*(lp*if_resolvemulti\*(rp
124 .Fa "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr"
126 .Ss "struct ifaddr member function"
128 .Fo \*(lp*ifa_rtrequest\*(rp
129 .Fa "int cmd" "struct rtentry *rt" "struct rt_addrinfo *info"
132 .Ss "Global Variables"
133 .Vt extern struct ifnethead ifnet ;
134 .\" extern struct ifindex_entry *ifindex_table ;
135 .Vt extern int if_index ;
136 .Vt extern int ifqmaxlen ;
138 The kernel mechanisms for handling network interfaces reside primarily
140 .Vt ifnet , if_data , ifaddr ,
147 and the functions named above and defined in
149 Those interfaces which are intended to be used by user programs
152 these include the interface flags, the
154 structure, and the structures defining the appearance of
155 interface-related messages on the
157 routing socket and in
161 defines the kernel-internal interfaces, including the
165 structures and the functions which manipulate them.
166 (A few user programs will need
168 because it is the prerequisite of some other header file like
169 .In netinet/if_ether.h .
170 Most references to those two files in particular can be replaced by
171 .In net/ethernet.h . )
173 The system keeps a linked list of interfaces using the
177 this list is headed by a
178 .Vt "struct ifnethead"
181 The elements of this list are of type
183 and most kernel routines which manipulate interface as such accept or
184 return pointers to these structures.
185 Each interface structure
188 structure used for statistics and information.
189 Each interface also has a
191 of interface addresses, described by
199 describing the link layer implemented by the interface (if any)
205 (Some trivial interfaces do not provide any link layer addresses;
206 this structure, while still present, serves only to identify the
207 interface name and index.)
209 Finally, those interfaces supporting reception of multicast datagrams
212 of multicast group memberships, described by
215 These memberships are reference-counted.
217 Interfaces are also associated with an output queue, defined as a
218 .Vt "struct ifqueue" ;
219 this structure is used to hold packets while the interface is in the
220 process of sending another.
222 .Ss The ifnet Structure
226 .Bl -tag -width ".Va if_capabilities" -offset indent
229 A pointer to the driver's private state block.
230 (Initialized by driver.)
233 A pointer to the common data for the interface's layer 2 protocol.
237 .Pq Vt "struct vnet *"
238 A pointer to the virtual network stack instance.
242 .Pq Vt "struct vnet *"
243 A pointer to the parent virtual network stack, where this
249 .Pq Fn TAILQ_ENTRY ifnet
254 The name of the interface,
259 (Initialized by driver
261 .Fn if_initname ) . )
263 .Pq Vt "const char *"
264 The name of the driver.
265 (Initialized by driver
267 .Fn if_initname ) . )
270 A unique number assigned to each interface managed by a particular
272 Drivers may choose to set this to
274 if a unit number is not associated with the device.
275 (Initialized by driver
277 .Fn if_initname ) . )
284 .Pq Vt "struct ifaddrhead"
288 containing the list of addresses assigned to this interface.
291 A count of promiscuous listeners on this interface, used to
296 .Pq Vt "struct carp_if *"
297 A pointer to the CARP interface structure,
299 (Initialized by the driver-specific
303 .Pq Vt "struct bpf_if *"
304 Opaque per-interface data for the packet filter,
310 A unique number assigned to each interface in sequence as it is
312 This number can be used in a
313 .Vt "struct sockaddr_dl"
314 to refer to a particular interface by index
320 .Pq Vt struct ifvlantrunk *
321 A pointer to 802.1Q trunk structure,
323 (Initialized by the driver-specific
328 Flags describing operational parameters of this interface (see below).
329 (Manipulated by generic code.)
332 Flags describing operational status of this interface (see below).
333 (Manipulated by driver.)
334 .It Va if_capabilities
336 Flags describing the capabilities the interface supports (see below).
339 Flags describing the enabled capabilities of the interface (see below).
342 A pointer to an interface-specific MIB structure exported by
344 (Initialized by driver.)
347 The size of said structure.
348 (Initialized by driver.)
350 .Pq Vt "struct if_data"
351 More statistics and information; see
352 .Sx "The if_data structure" ,
354 (Initialized by driver, manipulated by both driver and generic
357 .Pq Vt struct ifmultihead
361 containing the list of multicast addresses assigned to this interface.
364 A number of multicast requests on this interface, used to
369 .Pq Vt "struct ifaddr *"
370 A pointer to the link-level interface address.
373 .\" .It Va if_llsoftc
375 .\" The purpose of the field is unclear.
377 .Pq Vt "struct ifaltq"
379 (Manipulated by driver.)
380 .It Va if_broadcastaddr
381 .Pq Vt "const u_int8_t *"
382 A link-level broadcast bytestring for protocols with variable address
386 A pointer to the bridge interface structure,
388 (Initialized by the driver-specific
392 .Pq Vt "struct label *"
393 A pointer to the MAC Framework label structure,
399 An address family dependent data region.
400 .It Va if_afdata_initialized
402 Used to track the current state of address family initialization.
403 .It Va if_afdata_lock
404 .Pq Vt "struct rwlock"
414 task scheduled for link state change events of the interface.
416 .Pq Vt "struct rwlock"
419 lock used to protect interface-related address lists.
421 .Pq Fn LIST_ENTRY ifnet
423 macro glue for the list of clonable network interfaces.
425 .Pq Fn TAILQ_HEAD "" "ifg_list"
429 containing the list of groups per interface.
432 A pointer to the structure used for interface abstraction by
441 The type of the interface as it was at the time of its allocation.
442 It is used to cache the type passed to
446 it would not be changed by drivers.
447 .It Va if_numa_domain
449 The NUMA domain of the hardware device associated with the interface.
450 This is filled in with a wildcard value unless the kernel is NUMA
451 aware, the system is a NUMA system, and the ifnet is allocated
455 .Fn if_alloc_domain .
460 structures are gained by calling the
462 function and released by calling the
465 They are used to allow kernel code walking global interface lists
472 There are in addition a number of function pointers which the driver
473 must initialize to complete its interface with the generic interface
475 .Bl -ohang -offset indent
477 Pass a packet to an appropriate upper layer as determined
478 from the link-layer header of the packet.
479 This routine is to be called from an interrupt handler or
480 used to emulate reception of a packet on this interface.
481 A single function implementing
483 can be shared among multiple drivers utilizing the same link-layer
484 framing, e.g., Ethernet.
486 Output a packet on interface
488 or queue it on the output queue if the interface is already active.
490 Transmit a packet on an interface or queue it if the interface is
492 This function will return
494 if the devices software and hardware queues are both full.
495 This function must be installed after
497 to override the default implementation.
498 This function is exposed in order to allow drivers to manage their own queues
499 and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
501 The suggested internal software queuing mechanism is buf_ring.
503 Free mbufs in internally managed queues when the interface is marked down.
504 This function must be installed after
506 to override the default implementation.
507 This function is exposed in order to allow drivers to manage their own queues
508 and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
510 The suggested internal software queuing mechanism is buf_ring.
512 Start queued output on an interface.
513 This function is exposed in
514 order to provide for some interface classes to share a
518 may only be called when the
523 does not literally mean that output is active, but rather that the
524 device's internal output queue is full.) Please note that this function
525 will soon be deprecated.
527 Process interface-related
532 Preliminary processing is done by the generic routine
534 to check for appropriate privileges, locate the interface being
535 manipulated, and perform certain generic operations like twiddling
536 flags and flushing queues.
537 See the description of
539 below for more information.
541 Initialize and bring up the hardware,
542 e.g., reset the chip and enable the receiver unit.
543 Should mark the interface running,
545 .Dv ( IFF_DRV_RUNNING , ~IIF_DRV_OACTIVE ) .
546 .It Fn if_resolvemulti
547 Check the requested multicast group membership,
549 for validity, and if necessary compute a link-layer group which
550 corresponds to that address which is returned in
552 Returns zero on success, or an error code on failure.
554 .Ss "Interface Flags"
555 Interface flags are used for a number of different purposes.
557 flags simply indicate information about the type of interface and its
558 capabilities; others are dynamically manipulated to reflect the
559 current state of the interface.
560 Flags of the former kind are marked
562 in this table; the latter are marked
564 Flags which begin with
568 all other flags are stored in
573 defines the bits which cannot be set by a user program using the
577 these are indicated by an asterisk
579 in the following listing.
581 .Bl -tag -width ".Dv IFF_POINTOPOINT" -offset indent -compact
584 The interface has been configured up by the user-level code.
587 The interface supports broadcast.
590 Used to enable/disable driver debugging code.
593 The interface is a loopback device.
594 .It Dv IFF_POINTOPOINT
596 The interface is point-to-point;
598 address is actually the address of the other end.
599 .It Dv IFF_DRV_RUNNING
601 The interface has been configured and dynamic resources were
602 successfully allocated.
603 Probably only useful internal to the
607 Disable network address resolution on this interface.
610 This interface is in promiscuous mode.
613 This interface is in the permanently promiscuous mode (implies
617 This interface is in all-multicasts mode (used by multicast routers).
618 .It Dv IFF_DRV_OACTIVE
620 The interface's hardware output queue (if any) is full; output packets
624 The interface cannot hear its own transmissions.
629 Control flags for the link layer.
630 (Currently abused to select among
631 multiple physical layers on some devices.)
634 This interface supports multicast.
635 .It Dv IFF_CANTCONFIG
637 The interface is not configurable in a meaningful way.
640 interfaces registered at the interface list.
643 This interface blocks transmission of packets and discards incoming
644 packets after BPF processing.
645 Used to monitor network traffic but not interact
646 with the network in question.
649 Used to enable/disable ARP requests on this interface.
654 structure of this interface is being released and still has
659 Set when this interface is being renamed.
661 .Ss "Interface Capabilities Flags"
662 Interface capabilities are specialized features an interface may
664 These capabilities are very hardware-specific
665 and allow, when enabled,
666 to offload specific network processing to the interface
667 or to offer a particular feature for use by other kernel parts.
669 It should be stressed that a capability can be completely
670 uncontrolled (i.e., stay always enabled with no way to disable it)
671 or allow limited control over itself (e.g., depend on another
673 Such peculiarities are determined solely by the hardware and driver
674 of a particular interface.
675 Only the driver possesses
676 the knowledge on whether and how the interface capabilities
678 Consequently, capabilities flags in
680 should never be modified directly by kernel code other than
681 the interface driver.
686 is the dedicated means to attempt altering
689 Userland code shall use
692 The following capabilities are currently supported by the system:
693 .Bl -tag -width ".Dv IFCAP_VLAN_HWTAGGING" -offset indent
695 This interface can do checksum validation on receiving data.
696 Some interfaces do not have sufficient buffer storage to store frames
697 above a certain MTU-size completely.
698 The driver for the interface might disable hardware checksum validation
699 if the MTU is set above the hardcoded limit.
701 This interface can do checksum calculation on transmitting data.
704 .Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM .
706 This interface can be a network console.
707 .It Dv IFCAP_VLAN_MTU
710 driver can operate over this interface in software tagging mode
711 without having to decrease MTU on
713 interfaces below 1500 bytes.
714 This implies the ability of this interface to cope with frames somewhat
715 longer than permitted by the Ethernet specification.
716 .It Dv IFCAP_VLAN_HWTAGGING
717 This interface can do VLAN tagging on output and
718 demultiplex frames by their VLAN tag on input.
719 .It Dv IFCAP_JUMBO_MTU
720 This Ethernet interface can transmit and receive frames up to
723 This interface supports
725 See below for details.
726 .It Dv IFCAP_VLAN_HWCSUM
727 This interface can do checksum calculation on both transmitting
728 and receiving data on
733 This Ethernet interface supports TCP4 Segmentation offloading.
735 This Ethernet interface supports TCP6 Segmentation offloading.
738 .Pq Dv IFCAP_TSO4 | IFCAP_TSO6 .
740 This Ethernet interface supports TCP offloading.
742 This Ethernet interface supports TCP6 offloading.
745 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
746 .It Dv IFCAP_WOL_UCAST
747 This Ethernet interface supports waking up on any Unicast packet.
748 .It Dv IFCAP_WOL_MCAST
749 This Ethernet interface supports waking up on any Multicast packet.
750 .It Dv IFCAP_WOL_MAGIC
751 This Ethernet interface supports waking up on any Magic packet such
756 .Pq Dv IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC .
758 This Ethernet interface supports TCP4 Offload Engine.
760 This Ethernet interface supports TCP6 Offload Engine.
763 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
764 .It Dv IFCAP_VLAN_HWFILTER
765 This interface supports frame filtering in hardware on
768 .It Dv IFCAP_VLAN_HWTSO
769 This interface supports TCP Segmentation offloading on
773 .It Dv IFCAP_LINKSTATE
774 This Ethernet interface supports dynamic link state changes.
776 This Ethernet interface supports
780 The ability of advanced network interfaces to offload certain
781 computational tasks from the host CPU to the board is limited
783 Therefore a separate field associated with an interface
785 .Va ifnet.if_data.ifi_hwassist
787 keeps a detailed description of its enabled capabilities
788 specific to TCP/IP processing.
789 The TCP/IP module consults the field to see which tasks
792 packet by the interface.
793 The flags defined for that field are a superset of those for
794 .Va mbuf.m_pkthdr.csum_flags ,
796 .Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent
798 The interface will compute IP checksums.
800 The interface will compute TCP checksums.
802 The interface will compute UDP checksums.
805 An interface notifies the TCP/IP module about the tasks
806 the former has performed on an
808 packet by setting the corresponding flags in the field
809 .Va mbuf.m_pkthdr.csum_flags
812 containing the packet.
817 The capability of a network interface to operate in
819 mode involves several flags in different
820 global variables and per-interface fields.
825 indicates support for
827 on the particular interface.
829 .Va if_capabilities ,
830 the same flag can be marked or cleared in the interface's
834 thus initiating switch of the interface to
838 The actual mode change is managed by the driver-specific
843 handler returns the number of packets processed.
844 .Ss The if_data Structure
847 structure contains statistics and identifying information used
848 by management programs, and which is exported to user programs by way
854 The following elements of the
856 structure are initialized by the interface and are not expected to change
857 significantly over the course of normal operation:
858 .Bl -tag -width ".Va ifi_lastchange" -offset indent
861 The type of the interface, as defined in
863 and described below in the
864 .Sx "Interface Types"
868 Intended to represent a selection of physical layers on devices which
869 support more than one; never implemented.
872 Length of a link-layer address on this device, or zero if there are
874 Used to initialized the address length field in
876 structures referring to this interface.
879 Maximum length of any link-layer header which might be prepended by
880 the driver to a packet before transmission.
881 The generic code computes
882 the maximum over all interfaces and uses that value to influence the
885 to attempt to ensure that there is always
886 sufficient space to prepend a link-layer header without allocating an
894 Allows some stabilization of the routing socket ABI in the face of
895 increases in the length of
899 The maximum transmission unit of the medium, exclusive of any
903 A dimensionless metric interpreted by a user-mode routing process.
906 The line rate of the interface, in bits per second.
909 A detailed interpretation of the capabilities
910 to offload computational tasks for
913 The interface driver must keep this field in accord with
918 The system uptime when interface was attached or the statistics
920 This is intended to be used to set the SNMP variable
921 .Va ifCounterDiscontinuityTime .
922 It may also be used to determine if two successive queries for an
923 interface of the same index have returned results for the same
927 The structure additionally contains generic statistics applicable to a
928 variety of different interface types (except as noted, all members are
931 .Bl -tag -width ".Va ifi_lastchange" -offset indent
932 .It Va ifi_link_state
934 The current link state of Ethernet interfaces.
936 .Sx Interface Link States
937 section for possible values.
939 Number of packets received.
941 Number of receive errors detected (e.g., FCS errors, DMA overruns,
943 More detailed breakdowns can often be had by way of a
946 Number of packets transmitted.
948 Number of output errors detected (e.g., late collisions, DMA overruns,
950 More detailed breakdowns can often be had by way of a
952 .It Va ifi_collisions
953 Total number of collisions detected on output for CSMA interfaces.
954 (This member is sometimes [ab]used by other types of interfaces for
955 other output error counts.)
957 Total traffic received, in bytes.
959 Total traffic transmitted, in bytes.
961 Number of packets received which were sent by link-layer multicast.
963 Number of packets sent by link-layer multicast.
965 Number of packets dropped on input.
968 Number of packets dropped on output.
970 Number of packets received for unknown network-layer protocol.
971 .It Va ifi_lastchange
972 .Pq Vt "struct timeval"
973 The time of the last administrative change to the interface (as required
980 defines symbolic constants for a number of different types of
984 .Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact
986 none of the following
994 ISO 8802-5 Token Ring
1000 Internet Point-to-Point Protocol
1012 Asynchronous Transfer Mode
1016 .Ss Interface Link States
1017 The following link states are currently defined:
1019 .Bl -tag -offset indent -width ".Dv LINK_STATE_UNKNOWN" -compact
1020 .It Dv LINK_STATE_UNKNOWN
1021 The link is in an invalid or unknown state.
1022 .It Dv LINK_STATE_DOWN
1024 .It Dv LINK_STATE_UP
1027 .Ss The ifaddr Structure
1028 Every interface is associated with a list
1031 of addresses, rooted at the interface structure's
1034 The first element in this list is always an
1036 address representing the interface itself; multi-access network
1037 drivers should complete this structure by filling in their link-layer
1038 addresses after calling
1040 Other members of the structure represent network-layer addresses which
1041 have been configured by means of the
1045 called on a socket of the appropriate protocol family.
1046 The elements of this list consist of
1049 Most protocols will declare their own protocol-specific
1050 interface address structures, but all begin with a
1052 which provides the most-commonly-needed functionality across all
1054 Interface addresses are reference-counted.
1059 .Bl -tag -width ".Va ifa_rtrequest" -offset indent
1061 .Pq Vt "struct sockaddr *"
1062 The local address of the interface.
1064 .Pq Vt "struct sockaddr *"
1065 The remote address of point-to-point interfaces, and the broadcast
1066 address of broadcast interfaces.
1071 .Pq Vt "struct sockaddr *"
1072 The network mask for multi-access interfaces, and the confusion
1073 generator for point-to-point interfaces.
1075 .Pq Vt "struct ifnet *"
1076 A link back to the interface structure.
1078 .Pq Fn TAILQ_ENTRY ifaddr
1080 glue for list of addresses on each interface.
1081 .It Va ifa_rtrequest
1085 Some of the flags which would be used for a route representing this
1086 address in the route table.
1089 The reference count.
1094 structures are gained by calling the
1096 function and released by calling the
1101 is a pointer to a function which receives callouts from the routing
1104 to perform link-layer-specific actions upon requests to add,
1108 argument indicates the request in question:
1114 argument is the route in question; the
1116 argument contains the specific destination being manipulated.
1118 The functions provided by the generic interface code can be divided
1119 into two groups: those which manipulate interfaces, and those which
1120 manipulate interface addresses.
1121 In addition to these functions, there
1122 may also be link-layer support routines which are used by a number of
1123 drivers implementing a specific link layer over different hardware;
1124 see the documentation for that link layer for more details.
1125 .Ss The ifmultiaddr Structure
1126 Every multicast-capable interface is associated with a list of
1127 multicast group memberships, which indicate at a low level which
1128 link-layer multicast addresses (if any) should be accepted, and at a
1129 high level, in which network-layer multicast groups a user process has
1132 The elements of the structure are as follows:
1133 .Bl -tag -width ".Va ifma_refcount" -offset indent
1135 .Pq Fn LIST_ENTRY ifmultiaddr
1139 .Pq Vt "struct sockaddr *"
1140 A pointer to the address which this record represents.
1142 memberships for various address families are stored in arbitrary
1145 .Pq Vt "struct sockaddr *"
1146 A pointer to the link-layer multicast address, if any, to which the
1147 network-layer multicast address in
1149 is mapped, else a null pointer.
1150 If this element is non-nil, this
1151 membership also holds an invisible reference to another membership for
1152 that link-layer address.
1153 .It Va ifma_refcount
1155 A reference count of requests for this particular membership.
1157 .Ss Interface Manipulation Functions
1158 .Bl -ohang -offset indent
1160 Allocate and initialize
1161 .Vt "struct ifnet" .
1162 Initialization includes the allocation of an interface index and may
1163 include the allocation of a
1165 specific structure in
1168 Allocate and initialize
1172 does, with the addition that the ifnet can be tagged with the
1173 appropriate NUMA domain derived from the
1175 argument passed by the caller.
1176 .It Fn if_alloc_domain
1177 Allocate and initialize
1181 does, with the addition that the ifnet will be tagged with the NUMA
1184 argument passed by the caller.
1186 Link the specified interface
1188 into the list of network interfaces.
1189 Also initialize the list of
1190 addresses on that interface, and create a link-layer
1192 structure to be the first element in that list.
1194 this address structure is saved in the
1196 structure and is accessed by the
1201 must have been allocated by
1205 .Fn if_alloc_domain .
1207 Shut down and unlink the specified
1209 from the interface list.
1214 The interface must have been previously detached if it was ever attached.
1218 except that the given
1222 instead of the type in
1224 This is intended for use with drivers that change their interface type.
1231 flush its output queue, notify protocols of the transition,
1232 and generate a message from the
1238 as up, notify protocols of the transition,
1239 and generate a message from the
1243 Add or remove a promiscuous reference to
1247 is true, add a reference;
1248 if it is false, remove a reference.
1249 On reference count transitions
1250 from zero to one and one to zero, set the
1252 flag appropriately and call
1254 to set up the interface in the desired mode.
1258 but for the all-multicasts
1260 flag instead of the promiscuous flag.
1264 pointer for the interface named
1267 Return a reference-counted (via
1270 pointer for the interface named
1272 This is the preferred function over
1274 The caller is responsible for releasing the reference with
1276 when it is finished with the ifnet.
1278 Process the ioctl request
1286 This is the main routine for handling all interface configuration
1287 requests from user mode.
1288 It is ordinarily only called from the socket-layer
1290 handler, and only for commands with class
1292 Any unrecognized commands will be passed down to socket
1295 further interpretation.
1296 The following commands are handled by
1299 .Bl -tag -width ".Dv SIOCGIFNETMASK" -offset indent -compact
1301 Get interface configuration.
1302 (No call-down to driver.)
1305 Set the interface name.
1307 departure and arrival messages are sent so that
1308 routing code that relies on the interface name will update its interface
1310 Caller must have appropriate privilege.
1311 (No call-down to driver.)
1315 .It Dv SIOCGIFMETRIC
1318 Get interface capabilities, FIB, flags, metric, MTU, medium selection.
1319 (No call-down to driver.)
1322 Enable or disable interface capabilities.
1323 Caller must have appropriate privilege.
1324 Before a call to the driver-specific
1326 routine, the requested mask for enabled capabilities is checked
1327 against the mask of capabilities supported by the interface,
1328 .Va if_capabilities .
1329 Requesting to enable an unsupported capability is invalid.
1330 The rest is supposed to be done by the driver,
1331 which includes updating
1334 .Va if_data.ifi_hwassist
1339 Caller must have appropriate privilege.
1340 FIB values start at 0 and values greater or equals than
1342 are considered invalid.
1344 Change interface flags.
1345 Caller must have appropriate privilege.
1352 is called as appropriate.
1355 are masked off, and the field
1357 in the interface structure is updated.
1360 routine is called to perform any setup
1363 .It Dv SIOCSIFMETRIC
1365 Change interface metric or medium.
1366 Caller must have appropriate privilege.
1369 Change interface MTU.
1370 Caller must have appropriate privilege.
1372 values less than 72 or greater than 65535 are considered invalid.
1375 routine is called to implement the change; it is responsible for any
1376 additional sanity checking and for actually modifying the MTU in the
1377 interface structure.
1381 Add or delete permanent multicast group memberships on the interface.
1382 Caller must have appropriate privilege.
1387 function is called to perform the operation; qq.v.
1391 The socket's protocol control routine is called to implement the
1404 .Ss "Interface Address Functions"
1405 Several functions exist to look up an interface address structure
1408 returns an interface address with either a local address or a
1409 broadcast address precisely matching the parameter
1411 .Fn ifa_ifwithdstaddr
1412 returns an interface address for a point-to-point interface whose
1423 then the first interface address matching
1428 returns the most specific interface address which matches the
1431 subject to its configured netmask, or a point-to-point interface
1432 address whose remote address is
1437 is true, skip point-to-point interface addresses.
1440 parameter is handled the same way as by
1441 .Fn ifa_ifwithdstaddr .
1443 .Fn ifaof_ifpforaddr
1444 returns the most specific address configured on interface
1446 which matches address
1448 subject to its configured netmask.
1450 point-to-point, only an interface address whose remote address is
1456 returns the link-level address of the interface with the given index
1459 All of these functions return a null pointer if no such address can be
1461 .Ss "Interface Multicast Address Functions"
1467 functions provide support for requesting and relinquishing multicast
1468 group memberships, and for querying an interface's membership list,
1472 function takes a pointer to an interface,
1474 and a generic address,
1476 It also takes a pointer to a
1477 .Vt "struct ifmultiaddr *"
1478 which is filled in on successful return with the address of the
1479 group membership control block.
1482 function performs the following four-step process:
1483 .Bl -enum -offset indent
1485 Call the interface's
1487 entry point to determine the link-layer address, if any, corresponding
1488 to this membership request, and also to give the link layer an
1489 opportunity to veto this membership request should it so desire.
1491 Check the interface's group membership list for a pre-existing
1492 membership for this group.
1493 If one is not found, allocate a new one;
1494 if one is, increment its reference count.
1498 routine returned a link-layer address corresponding to the group,
1499 repeat the previous step for that address as well.
1501 If the interface's multicast address filter needs to be changed
1502 because a new membership was added, call the interface's
1509 to request that it do so.
1514 function, given an interface
1518 reverses this process.
1519 Both functions return zero on success, or a
1520 standard error number on failure.
1524 function examines the membership list of interface
1526 for an address matching
1528 and returns a pointer to that
1529 .Vt "struct ifmultiaddr"
1530 if one is found, else it returns a null pointer.
1547 .%A W. Richard Stevens
1548 .%B TCP/IP Illustrated
1550 .%O Addison-Wesley, ISBN 0-201-63354-X
1553 This manual page was written by
1554 .An Garrett A. Wollman .