xref: /freebsd/share/man/man9/ifnet.9 (revision 9768746b)
1.\" -*- Nroff -*-
2.\" Copyright 1996, 1997 Massachusetts Institute of Technology
3.\"
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
14.\" warranty.
15.\"
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
27.\" SUCH DAMAGE.
28.\"
29.\" $FreeBSD$
30.\"
31.Dd May 24, 2022
32.Dt IFNET 9
33.Os
34.Sh NAME
35.Nm ifnet ,
36.Nm ifaddr ,
37.Nm ifqueue ,
38.Nm if_data
39.Nd kernel interfaces for manipulating network interfaces
40.Sh SYNOPSIS
41.In sys/param.h
42.In sys/time.h
43.In sys/socket.h
44.In net/if.h
45.In net/if_var.h
46.In net/if_types.h
47.\"
48.Ss "Interface Manipulation Functions"
49.Ft "struct ifnet *"
50.Fn if_alloc "u_char type"
51.Ft "struct ifnet *"
52.Fn if_alloc_dev "u_char type" "device_t dev"
53.Ft "struct ifnet *"
54.Fn if_alloc_domain "u_char type" "int numa_domain"
55.Ft void
56.Fn if_attach "struct ifnet *ifp"
57.Ft void
58.Fn if_detach "struct ifnet *ifp"
59.Ft void
60.Fn if_free "struct ifnet *ifp"
61.Ft void
62.Fn if_free_type "struct ifnet *ifp" "u_char type"
63.Ft void
64.Fn if_down "struct ifnet *ifp"
65.Ft int
66.Fn ifioctl "struct socket *so" "u_long cmd" "caddr_t data" "struct thread *td"
67.Ft int
68.Fn ifpromisc "struct ifnet *ifp" "int pswitch"
69.Ft int
70.Fn if_allmulti "struct ifnet *ifp" "int amswitch"
71.Ft "struct ifnet *"
72.Fn ifunit "const char *name"
73.Ft "struct ifnet *"
74.Fn ifunit_ref "const char *name"
75.Ft void
76.Fn if_up "struct ifnet *ifp"
77.\"
78.Ss "Interface Address Functions"
79.Ft "struct ifaddr *"
80.Fn ifaddr_byindex "u_short idx"
81.Ft "struct ifaddr *"
82.Fn ifa_ifwithaddr "struct sockaddr *addr"
83.Ft "struct ifaddr *"
84.Fn ifa_ifwithdstaddr "struct sockaddr *addr" "int fib"
85.Ft "struct ifaddr *"
86.Fn ifa_ifwithnet "struct sockaddr *addr" "int ignore_ptp" "int fib"
87.Ft "struct ifaddr *"
88.Fn ifaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp"
89.Ft void
90.Fn ifa_ref "struct ifaddr *ifa"
91.Ft void
92.Fn ifa_free "struct ifaddr *ifa"
93.\"
94.Ss "Interface Multicast Address Functions"
95.Ft int
96.Fn if_addmulti "struct ifnet *ifp" "struct sockaddr *sa" "struct ifmultiaddr **ifmap"
97.Ft int
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"
103.\"
104.Ss "struct ifnet Member Functions"
105.Ft void
106.Fn \*(lp*if_input\*(rp "struct ifnet *ifp" "struct mbuf *m"
107.Ft int
108.Fo \*(lp*if_output\*(rp
109.Fa "struct ifnet *ifp" "struct mbuf *m"
110.Fa "const struct sockaddr *dst" "struct route *ro"
111.Fc
112.Ft void
113.Fn \*(lp*if_start\*(rp "struct ifnet *ifp"
114.Ft int
115.Fn \*(lp*if_transmit\*(rp "struct ifnet *ifp" "struct mbuf *m"
116.Ft void
117.Fn \*(lp*if_qflush\*(rp "struct ifnet *ifp"
118.Ft int
119.Fn \*(lp*if_ioctl\*(rp "struct ifnet *ifp" "u_long cmd" "caddr_t data"
120.Ft void
121.Fn \*(lp*if_init\*(rp "void *if_softc"
122.Ft int
123.Fo \*(lp*if_resolvemulti\*(rp
124.Fa "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr"
125.Fc
126.Ss "struct ifaddr member function"
127.Ft void
128.Fo \*(lp*ifa_rtrequest\*(rp
129.Fa "int cmd" "struct rtentry *rt" "struct rt_addrinfo *info"
130.Fc
131.\"
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 ;
137.Sh DATA STRUCTURES
138The kernel mechanisms for handling network interfaces reside primarily
139in the
140.Vt ifnet , if_data , ifaddr ,
141and
142.Vt ifmultiaddr
143structures in
144.In net/if.h
145and
146.In net/if_var.h
147and the functions named above and defined in
148.Pa /sys/net/if.c .
149Those interfaces which are intended to be used by user programs
150are defined in
151.In net/if.h ;
152these include the interface flags, the
153.Vt if_data
154structure, and the structures defining the appearance of
155interface-related messages on the
156.Xr route 4
157routing socket and in
158.Xr sysctl 3 .
159The header file
160.In net/if_var.h
161defines the kernel-internal interfaces, including the
162.Vt ifnet , ifaddr ,
163and
164.Vt ifmultiaddr
165structures and the functions which manipulate them.
166(A few user programs will need
167.In net/if_var.h
168because it is the prerequisite of some other header file like
169.In netinet/if_ether.h .
170Most references to those two files in particular can be replaced by
171.In net/ethernet.h . )
172.Pp
173The system keeps a linked list of interfaces using the
174.Li TAILQ
175macros defined in
176.Xr queue 3 ;
177this list is headed by a
178.Vt "struct ifnethead"
179called
180.Va ifnet .
181The elements of this list are of type
182.Vt "struct ifnet" ,
183and most kernel routines which manipulate interface as such accept or
184return pointers to these structures.
185Each interface structure
186contains an
187.Vt if_data
188structure used for statistics and information.
189Each interface also has a
190.Li TAILQ
191of interface addresses, described by
192.Vt ifaddr
193structures.
194An
195.Dv AF_LINK
196address
197(see
198.Xr link_addr 3 )
199describing the link layer implemented by the interface (if any)
200is accessed by the
201.Fn ifaddr_byindex
202function or
203.Va if_addr
204structure.
205(Some trivial interfaces do not provide any link layer addresses;
206this structure, while still present, serves only to identify the
207interface name and index.)
208.Pp
209Finally, those interfaces supporting reception of multicast datagrams
210have a
211.Li TAILQ
212of multicast group memberships, described by
213.Vt ifmultiaddr
214structures.
215These memberships are reference-counted.
216.Pp
217Interfaces are also associated with an output queue, defined as a
218.Vt "struct ifqueue" ;
219this structure is used to hold packets while the interface is in the
220process of sending another.
221.Ss The ifnet Structure
222The fields of
223.Vt "struct ifnet"
224are as follows:
225.Bl -tag -width ".Va if_capabilities" -offset indent
226.It Va if_softc
227.Pq Vt "void *"
228A pointer to the driver's private state block.
229(Initialized by driver.)
230.It Va if_l2com
231.Pq Vt "void *"
232A pointer to the common data for the interface's layer 2 protocol.
233(Initialized by
234.Fn if_alloc . )
235.It Va if_vnet
236.Pq Vt "struct vnet *"
237A pointer to the virtual network stack instance.
238(Initialized by
239.Fn if_attach . )
240.It Va if_home_vnet
241.Pq Vt "struct vnet *"
242A pointer to the parent virtual network stack, where this
243.Vt "struct ifnet"
244originates from.
245(Initialized by
246.Fn if_attach . )
247.It Va if_link
248.Pq Fn TAILQ_ENTRY ifnet
249.Xr queue 3
250macro glue.
251.It Va if_xname
252.Pq Vt "char *"
253The name of the interface,
254(e.g.,
255.Dq Li fxp0
256or
257.Dq Li lo0 ) .
258(Initialized by driver
259(usually via
260.Fn if_initname ) . )
261.It Va if_dname
262.Pq Vt "const char *"
263The name of the driver.
264(Initialized by driver
265(usually via
266.Fn if_initname ) . )
267.It Va if_dunit
268.Pq Vt int
269A unique number assigned to each interface managed by a particular
270driver.
271Drivers may choose to set this to
272.Dv IF_DUNIT_NONE
273if a unit number is not associated with the device.
274(Initialized by driver
275(usually via
276.Fn if_initname ) . )
277.It Va if_refcount
278.Pq Vt u_int
279The reference count.
280(Initialized by
281.Fn if_alloc . )
282.It Va if_addrhead
283.Pq Vt "struct ifaddrhead"
284The head of the
285.Xr queue 3
286.Li TAILQ
287containing the list of addresses assigned to this interface.
288.It Va if_pcount
289.Pq Vt int
290A count of promiscuous listeners on this interface, used to
291reference-count the
292.Dv IFF_PROMISC
293flag.
294.It Va if_carp
295.Pq Vt "struct carp_if *"
296A pointer to the CARP interface structure,
297.Xr carp 4 .
298(Initialized by the driver-specific
299.Fn if_ioctl
300routine.)
301.It Va if_bpf
302.Pq Vt "struct bpf_if *"
303Opaque per-interface data for the packet filter,
304.Xr bpf 4 .
305(Initialized by
306.Fn bpf_attach . )
307.It Va if_index
308.Pq Vt u_short
309A unique number assigned to each interface in sequence as it is
310attached.
311This number can be used in a
312.Vt "struct sockaddr_dl"
313to refer to a particular interface by index
314(see
315.Xr link_addr 3 ) .
316(Initialized by
317.Fn if_alloc . )
318.It Va if_vlantrunk
319.Pq Vt struct ifvlantrunk *
320A pointer to 802.1Q trunk structure,
321.Xr vlan 4 .
322(Initialized by the driver-specific
323.Fn if_ioctl
324routine.)
325.It Va if_flags
326.Pq Vt int
327Flags describing operational parameters of this interface (see below).
328(Manipulated by generic code.)
329.It Va if_drv_flags
330.Pq Vt int
331Flags describing operational status of this interface (see below).
332(Manipulated by driver.)
333.It Va if_capabilities
334.Pq Vt int
335Flags describing the capabilities the interface supports (see below).
336.It Va if_capenable
337.Pq Vt int
338Flags describing the enabled capabilities of the interface (see below).
339.It Va if_linkmib
340.Pq Vt "void *"
341A pointer to an interface-specific MIB structure exported by
342.Xr ifmib 4 .
343(Initialized by driver.)
344.It Va if_linkmiblen
345.Pq Vt size_t
346The size of said structure.
347(Initialized by driver.)
348.It Va if_data
349.Pq Vt "struct if_data"
350More statistics and information; see
351.Sx "The if_data structure" ,
352below.
353(Initialized by driver, manipulated by both driver and generic
354code.)
355.It Va if_multiaddrs
356.Pq Vt struct ifmultihead
357The head of the
358.Xr queue 3
359.Li TAILQ
360containing the list of multicast addresses assigned to this interface.
361.It Va if_amcount
362.Pq Vt int
363A number of multicast requests on this interface, used to
364reference-count the
365.Dv IFF_ALLMULTI
366flag.
367.It Va if_addr
368.Pq Vt "struct ifaddr *"
369A pointer to the link-level interface address.
370(Initialized by
371.Fn if_alloc . )
372.\" .It Va if_llsoftc
373.\" .Pq Vt "void *"
374.\" The purpose of the field is unclear.
375.It Va if_snd
376.Pq Vt "struct ifaltq"
377The output queue.
378(Manipulated by driver.)
379.It Va if_broadcastaddr
380.Pq Vt "const u_int8_t *"
381A link-level broadcast bytestring for protocols with variable address
382length.
383.It Va if_bridge
384.Pq Vt "void *"
385A pointer to the bridge interface structure,
386.Xr if_bridge 4 .
387(Initialized by the driver-specific
388.Fn if_ioctl
389routine.)
390.It Va if_label
391.Pq Vt "struct label *"
392A pointer to the MAC Framework label structure,
393.Xr mac 4 .
394(Initialized by
395.Fn if_alloc . )
396.It Va if_afdata
397.Pq Vt "void *"
398An address family dependent data region.
399.It Va if_afdata_initialized
400.Pq Vt int
401Used to track the current state of address family initialization.
402.It Va if_afdata_lock
403.Pq Vt "struct rwlock"
404An
405.Xr rwlock 9
406lock used to protect
407.Va if_afdata
408internals.
409.It Va if_linktask
410.Pq Vt "struct task"
411A
412.Xr taskqueue 9
413task scheduled for link state change events of the interface.
414.It Va if_addr_lock
415.Pq Vt "struct rwlock"
416An
417.Xr rwlock 9
418lock used to protect interface-related address lists.
419.It Va if_clones
420.Pq Fn LIST_ENTRY ifnet
421.Xr queue 3
422macro glue for the list of clonable network interfaces.
423.It Va if_groups
424.Pq Fn TAILQ_HEAD "" "ifg_list"
425The head of the
426.Xr queue 3
427.Li TAILQ
428containing the list of groups per interface.
429.It Va if_pf_kif
430.Pq Vt "void *"
431A pointer to the structure used for interface abstraction by
432.Xr pf 4 .
433.It Va if_lagg
434.Pq Vt "void *"
435A pointer to the
436.Xr lagg 4
437interface structure.
438.It Va if_alloctype
439.Pq Vt u_char
440The type of the interface as it was at the time of its allocation.
441It is used to cache the type passed to
442.Fn if_alloc ,
443but unlike
444.Va if_type ,
445it would not be changed by drivers.
446.It Va if_numa_domain
447.Pq Vt uint8_t
448The NUMA domain of the hardware device associated with the interface.
449This is filled in with a wildcard value unless the kernel is NUMA
450aware, the system is a NUMA system, and the ifnet is allocated
451using
452.Fn if_alloc_dev
453or
454.Fn if_alloc_domain .
455.El
456.Pp
457References to
458.Vt ifnet
459structures are gained by calling the
460.Fn if_ref
461function and released by calling the
462.Fn if_rele
463function.
464They are used to allow kernel code walking global interface lists
465to release the
466.Vt ifnet
467lock yet keep the
468.Vt ifnet
469structure stable.
470.Pp
471There are in addition a number of function pointers which the driver
472must initialize to complete its interface with the generic interface
473layer:
474.Bl -ohang -offset indent
475.It Fn if_input
476Pass a packet to an appropriate upper layer as determined
477from the link-layer header of the packet.
478This routine is to be called from an interrupt handler or
479used to emulate reception of a packet on this interface.
480A single function implementing
481.Fn if_input
482can be shared among multiple drivers utilizing the same link-layer
483framing, e.g., Ethernet.
484.It Fn if_output
485Output a packet on interface
486.Fa ifp ,
487or queue it on the output queue if the interface is already active.
488.It Fn if_transmit
489Transmit a packet on an interface or queue it if the interface is
490in use.
491This function will return
492.Dv ENOBUFS
493if the devices software and hardware queues are both full.
494This function must be installed after
495.Fn if_attach
496to override the default implementation.
497This function is exposed in order to allow drivers to manage their own queues
498and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
499pair to ifq.
500The suggested internal software queuing mechanism is buf_ring.
501.It Fn if_qflush
502Free mbufs in internally managed queues when the interface is marked down.
503This function must be installed after
504.Fn if_attach
505to override the default implementation.
506This function is exposed in order to allow drivers to manage their own queues
507and to reduce the latency caused by a frequently gratuitous enqueue / dequeue
508pair to ifq.
509The suggested internal software queuing mechanism is buf_ring.
510.It Fn if_start
511Start queued output on an interface.
512This function is exposed in
513order to provide for some interface classes to share a
514.Fn if_output
515among all drivers.
516.Fn if_start
517may only be called when the
518.Dv IFF_DRV_OACTIVE
519flag is not set.
520(Thus,
521.Dv IFF_DRV_OACTIVE
522does not literally mean that output is active, but rather that the
523device's internal output queue is full.) Please note that this function
524will soon be deprecated.
525.It Fn if_ioctl
526Process interface-related
527.Xr ioctl 2
528requests
529(defined in
530.In sys/sockio.h ) .
531Preliminary processing is done by the generic routine
532.Fn ifioctl
533to check for appropriate privileges, locate the interface being
534manipulated, and perform certain generic operations like twiddling
535flags and flushing queues.
536See the description of
537.Fn ifioctl
538below for more information.
539.It Fn if_init
540Initialize and bring up the hardware,
541e.g., reset the chip and enable the receiver unit.
542Should mark the interface running,
543but not active
544.Dv ( IFF_DRV_RUNNING , ~IIF_DRV_OACTIVE ) .
545.It Fn if_resolvemulti
546Check the requested multicast group membership,
547.Fa addr ,
548for validity, and if necessary compute a link-layer group which
549corresponds to that address which is returned in
550.Fa *retsa .
551Returns zero on success, or an error code on failure.
552.El
553.Ss "Interface Flags"
554Interface flags are used for a number of different purposes.
555Some
556flags simply indicate information about the type of interface and its
557capabilities; others are dynamically manipulated to reflect the
558current state of the interface.
559Flags of the former kind are marked
560.Aq S
561in this table; the latter are marked
562.Aq D .
563Flags which begin with
564.Dq IFF_DRV_
565are stored in
566.Va if_drv_flags ;
567all other flags are stored in
568.Va if_flags .
569.Pp
570The macro
571.Dv IFF_CANTCHANGE
572defines the bits which cannot be set by a user program using the
573.Dv SIOCSIFFLAGS
574command to
575.Xr ioctl 2 ;
576these are indicated by an asterisk
577.Pq Ql *
578in the following listing.
579.Pp
580.Bl -tag -width ".Dv IFF_POINTOPOINT" -offset indent -compact
581.It Dv IFF_UP
582.Aq D
583The interface has been configured up by the user-level code.
584.It Dv IFF_BROADCAST
585.Aq S*
586The interface supports broadcast.
587.It Dv IFF_DEBUG
588.Aq D
589Used to enable/disable driver debugging code.
590.It Dv IFF_LOOPBACK
591.Aq S
592The interface is a loopback device.
593.It Dv IFF_POINTOPOINT
594.Aq S*
595The interface is point-to-point;
596.Dq broadcast
597address is actually the address of the other end.
598.It Dv IFF_DRV_RUNNING
599.Aq D*
600The interface has been configured and dynamic resources were
601successfully allocated.
602Probably only useful internal to the
603interface.
604.It Dv IFF_NOARP
605.Aq D
606Disable network address resolution on this interface.
607.It Dv IFF_PROMISC
608.Aq D*
609This interface is in promiscuous mode.
610.It Dv IFF_PPROMISC
611.Aq D
612This interface is in the permanently promiscuous mode (implies
613.Dv IFF_PROMISC ) .
614.It Dv IFF_ALLMULTI
615.Aq D*
616This interface is in all-multicasts mode (used by multicast routers).
617.It Dv IFF_DRV_OACTIVE
618.Aq D*
619The interface's hardware output queue (if any) is full; output packets
620are to be queued.
621.It Dv IFF_SIMPLEX
622.Aq S*
623The interface cannot hear its own transmissions.
624.It Dv IFF_LINK0
625.It Dv IFF_LINK1
626.It Dv IFF_LINK2
627.Aq D
628Control flags for the link layer.
629(Currently abused to select among
630multiple physical layers on some devices.)
631.It Dv IFF_MULTICAST
632.Aq S*
633This interface supports multicast.
634.It Dv IFF_CANTCONFIG
635.Aq S*
636The interface is not configurable in a meaningful way.
637Primarily useful for
638.Dv IFT_USB
639interfaces registered at the interface list.
640.It Dv IFF_MONITOR
641.Aq D
642This interface blocks transmission of packets and discards incoming
643packets after BPF processing.
644Used to monitor network traffic but not interact
645with the network in question.
646.It Dv IFF_STATICARP
647.Aq D
648Used to enable/disable ARP requests on this interface.
649.It Dv IFF_DYING
650.Aq D*
651Set when the
652.Vt ifnet
653structure of this interface is being released and still has
654.Va if_refcount
655references.
656.It Dv IFF_RENAMING
657.Aq D
658Set when this interface is being renamed.
659.El
660.Ss "Interface Capabilities Flags"
661Interface capabilities are specialized features an interface may
662or may not support.
663These capabilities are very hardware-specific
664and allow, when enabled,
665to offload specific network processing to the interface
666or to offer a particular feature for use by other kernel parts.
667.Pp
668It should be stressed that a capability can be completely
669uncontrolled (i.e., stay always enabled with no way to disable it)
670or allow limited control over itself (e.g., depend on another
671capability's state.)
672Such peculiarities are determined solely by the hardware and driver
673of a particular interface.
674Only the driver possesses
675the knowledge on whether and how the interface capabilities
676can be controlled.
677Consequently, capabilities flags in
678.Va if_capenable
679should never be modified directly by kernel code other than
680the interface driver.
681The command
682.Dv SIOCSIFCAP
683to
684.Fn ifioctl
685is the dedicated means to attempt altering
686.Va if_capenable
687on an interface.
688Userland code shall use
689.Xr ioctl 2 .
690.Pp
691The following capabilities are currently supported by the system:
692.Bl -tag -width ".Dv IFCAP_VLAN_HWTAGGING" -offset indent
693.It Dv IFCAP_RXCSUM
694This interface can do checksum validation on receiving data.
695Some interfaces do not have sufficient buffer storage to store frames
696above a certain MTU-size completely.
697The driver for the interface might disable hardware checksum validation
698if the MTU is set above the hardcoded limit.
699.It Dv IFCAP_TXCSUM
700This interface can do checksum calculation on transmitting data.
701.It Dv IFCAP_HWCSUM
702A shorthand for
703.Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM .
704.It Dv IFCAP_NETCONS
705This interface can be a network console.
706.It Dv IFCAP_VLAN_MTU
707The
708.Xr vlan 4
709driver can operate over this interface in software tagging mode
710without having to decrease MTU on
711.Xr vlan 4
712interfaces below 1500 bytes.
713This implies the ability of this interface to cope with frames somewhat
714longer than permitted by the Ethernet specification.
715.It Dv IFCAP_VLAN_HWTAGGING
716This interface can do VLAN tagging on output and
717demultiplex frames by their VLAN tag on input.
718.It Dv IFCAP_JUMBO_MTU
719This Ethernet interface can transmit and receive frames up to
7209000 bytes long.
721.It Dv IFCAP_POLLING
722This interface supports
723.Xr polling 4 .
724See below for details.
725.It Dv IFCAP_VLAN_HWCSUM
726This interface can do checksum calculation on both transmitting
727and receiving data on
728.Xr vlan 4
729interfaces (implies
730.Dv IFCAP_HWCSUM ) .
731.It Dv IFCAP_TSO4
732This Ethernet interface supports TCP4 Segmentation offloading.
733.It Dv IFCAP_TSO6
734This Ethernet interface supports TCP6 Segmentation offloading.
735.It Dv IFCAP_TSO
736A shorthand for
737.Pq Dv IFCAP_TSO4 | IFCAP_TSO6 .
738.It Dv IFCAP_TOE4
739This Ethernet interface supports TCP4 Offload Engine.
740.It Dv IFCAP_TOE6
741This Ethernet interface supports TCP6 Offload Engine.
742.It Dv IFCAP_TOE
743A shorthand for
744.Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
745.It Dv IFCAP_WOL_UCAST
746This Ethernet interface supports waking up on any Unicast packet.
747.It Dv IFCAP_WOL_MCAST
748This Ethernet interface supports waking up on any Multicast packet.
749.It Dv IFCAP_WOL_MAGIC
750This Ethernet interface supports waking up on any Magic packet such
751as those sent by
752.Xr wake 8 .
753.It Dv IFCAP_WOL
754A shorthand for
755.Pq Dv IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC .
756.It Dv IFCAP_VLAN_HWFILTER
757This interface supports frame filtering in hardware on
758.Xr vlan 4
759interfaces.
760.It Dv IFCAP_VLAN_HWTSO
761This interface supports TCP Segmentation offloading on
762.Xr vlan 4
763interfaces (implies
764.Dv IFCAP_TSO ) .
765.It Dv IFCAP_LINKSTATE
766This Ethernet interface supports dynamic link state changes.
767.It Dv IFCAP_NETMAP
768This Ethernet interface supports
769.Xr netmap  4 .
770.El
771.Pp
772The ability of advanced network interfaces to offload certain
773computational tasks from the host CPU to the board is limited
774mostly to TCP/IP.
775Therefore a separate field associated with an interface
776(see
777.Va ifnet.if_data.ifi_hwassist
778below)
779keeps a detailed description of its enabled capabilities
780specific to TCP/IP processing.
781The TCP/IP module consults the field to see which tasks
782can be done on an
783.Em outgoing
784packet by the interface.
785The flags defined for that field are a superset of those for
786.Va mbuf.m_pkthdr.csum_flags ,
787namely:
788.Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent
789.It Dv CSUM_IP
790The interface will compute IP checksums.
791.It Dv CSUM_TCP
792The interface will compute TCP checksums.
793.It Dv CSUM_UDP
794The interface will compute UDP checksums.
795.El
796.Pp
797An interface notifies the TCP/IP module about the tasks
798the former has performed on an
799.Em incoming
800packet by setting the corresponding flags in the field
801.Va mbuf.m_pkthdr.csum_flags
802of the
803.Vt mbuf chain
804containing the packet.
805See
806.Xr mbuf 9
807for details.
808.Pp
809The capability of a network interface to operate in
810.Xr polling 4
811mode involves several flags in different
812global variables and per-interface fields.
813The capability flag
814.Dv IFCAP_POLLING
815set in interface's
816.Va if_capabilities
817indicates support for
818.Xr polling 4
819on the particular interface.
820If set in
821.Va if_capabilities ,
822the same flag can be marked or cleared in the interface's
823.Va if_capenable
824within
825.Fn ifioctl ,
826thus initiating switch of the interface to
827.Xr polling 4
828mode or interrupt
829mode, respectively.
830The actual mode change is managed by the driver-specific
831.Fn if_ioctl
832routine.
833The
834.Xr polling 4
835handler returns the number of packets processed.
836.Ss The if_data Structure
837The
838.Vt if_data
839structure contains statistics and identifying information used
840by management programs, and which is exported to user programs by way
841of the
842.Xr ifmib 4
843branch of the
844.Xr sysctl 3
845MIB.
846The following elements of the
847.Vt if_data
848structure are initialized by the interface and are not expected to change
849significantly over the course of normal operation:
850.Bl -tag -width ".Va ifi_lastchange" -offset indent
851.It Va ifi_type
852.Pq Vt u_char
853The type of the interface, as defined in
854.In net/if_types.h
855and described below in the
856.Sx "Interface Types"
857section.
858.It Va ifi_physical
859.Pq Vt u_char
860Intended to represent a selection of physical layers on devices which
861support more than one; never implemented.
862.It Va ifi_addrlen
863.Pq Vt u_char
864Length of a link-layer address on this device, or zero if there are
865none.
866Used to initialized the address length field in
867.Vt sockaddr_dl
868structures referring to this interface.
869.It Va ifi_hdrlen
870.Pq Vt u_char
871Maximum length of any link-layer header which might be prepended by
872the driver to a packet before transmission.
873The generic code computes
874the maximum over all interfaces and uses that value to influence the
875placement of data in
876.Vt mbuf Ns s
877to attempt to ensure that there is always
878sufficient space to prepend a link-layer header without allocating an
879additional
880.Vt mbuf .
881.It Va ifi_datalen
882.Pq Vt u_char
883Length of the
884.Vt if_data
885structure.
886Allows some stabilization of the routing socket ABI in the face of
887increases in the length of
888.Vt struct ifdata .
889.It Va ifi_mtu
890.Pq Vt u_long
891The maximum transmission unit of the medium, exclusive of any
892link-layer overhead.
893.It Va ifi_metric
894.Pq Vt u_long
895A dimensionless metric interpreted by a user-mode routing process.
896.It Va ifi_baudrate
897.Pq Vt u_long
898The line rate of the interface, in bits per second.
899.It Va ifi_hwassist
900.Pq Vt u_long
901A detailed interpretation of the capabilities
902to offload computational tasks for
903.Em outgoing
904packets.
905The interface driver must keep this field in accord with
906the current value of
907.Va if_capenable .
908.It Va ifi_epoch
909.Pq Vt time_t
910The system uptime when interface was attached or the statistics
911below were reset.
912This is intended to be used to set the SNMP variable
913.Va ifCounterDiscontinuityTime .
914It may also be used to determine if two successive queries for an
915interface of the same index have returned results for the same
916interface.
917.El
918.Pp
919The structure additionally contains generic statistics applicable to a
920variety of different interface types (except as noted, all members are
921of type
922.Vt u_long ) :
923.Bl -tag -width ".Va ifi_lastchange" -offset indent
924.It Va ifi_link_state
925.Pq Vt u_char
926The current link state of Ethernet interfaces.
927See the
928.Sx Interface Link States
929section for possible values.
930.It Va ifi_ipackets
931Number of packets received.
932.It Va ifi_ierrors
933Number of receive errors detected (e.g., FCS errors, DMA overruns,
934etc.).
935More detailed breakdowns can often be had by way of a
936link-specific MIB.
937.It Va ifi_opackets
938Number of packets transmitted.
939.It Va ifi_oerrors
940Number of output errors detected (e.g., late collisions, DMA overruns,
941etc.).
942More detailed breakdowns can often be had by way of a
943link-specific MIB.
944.It Va ifi_collisions
945Total number of collisions detected on output for CSMA interfaces.
946(This member is sometimes [ab]used by other types of interfaces for
947other output error counts.)
948.It Va ifi_ibytes
949Total traffic received, in bytes.
950.It Va ifi_obytes
951Total traffic transmitted, in bytes.
952.It Va ifi_imcasts
953Number of packets received which were sent by link-layer multicast.
954.It Va ifi_omcasts
955Number of packets sent by link-layer multicast.
956.It Va ifi_iqdrops
957Number of packets dropped on input.
958Rarely implemented.
959.It Va ifi_oqdrops
960Number of packets dropped on output.
961.It Va ifi_noproto
962Number of packets received for unknown network-layer protocol.
963.It Va ifi_lastchange
964.Pq Vt "struct timeval"
965The time of the last administrative change to the interface (as required
966for
967.Tn SNMP ) .
968.El
969.Ss Interface Types
970The header file
971.In net/if_types.h
972defines symbolic constants for a number of different types of
973interfaces.
974The most common are:
975.Pp
976.Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact
977.It Dv IFT_OTHER
978none of the following
979.It Dv IFT_ETHER
980Ethernet
981.It Dv IFT_ISO88023
982ISO 8802-3 CSMA/CD
983.It Dv IFT_ISO88024
984ISO 8802-4 Token Bus
985.It Dv IFT_ISO88025
986ISO 8802-5 Token Ring
987.It Dv IFT_ISO88026
988ISO 8802-6 DQDB MAN
989.It Dv IFT_FDDI
990FDDI
991.It Dv IFT_PPP
992Internet Point-to-Point Protocol
993.Pq Xr ppp 8
994.It Dv IFT_LOOP
995The loopback
996.Pq Xr lo 4
997interface
998.It Dv IFT_SLIP
999Serial Line IP
1000.It Dv IFT_PARA
1001Parallel-port IP
1002.Pq Dq Tn PLIP
1003.It Dv IFT_ATM
1004Asynchronous Transfer Mode
1005.It Dv IFT_USB
1006USB Interface
1007.El
1008.Ss Interface Link States
1009The following link states are currently defined:
1010.Pp
1011.Bl -tag -offset indent -width ".Dv LINK_STATE_UNKNOWN" -compact
1012.It Dv LINK_STATE_UNKNOWN
1013The link is in an invalid or unknown state.
1014.It Dv LINK_STATE_DOWN
1015The link is down.
1016.It Dv LINK_STATE_UP
1017The link is up.
1018.El
1019.Ss The ifaddr Structure
1020Every interface is associated with a list
1021(or, rather, a
1022.Li TAILQ )
1023of addresses, rooted at the interface structure's
1024.Va if_addrhead
1025member.
1026The first element in this list is always an
1027.Dv AF_LINK
1028address representing the interface itself; multi-access network
1029drivers should complete this structure by filling in their link-layer
1030addresses after calling
1031.Fn if_attach .
1032Other members of the structure represent network-layer addresses which
1033have been configured by means of the
1034.Dv SIOCAIFADDR
1035command to
1036.Xr ioctl 2 ,
1037called on a socket of the appropriate protocol family.
1038The elements of this list consist of
1039.Vt ifaddr
1040structures.
1041Most protocols will declare their own protocol-specific
1042interface address structures, but all begin with a
1043.Vt "struct ifaddr"
1044which provides the most-commonly-needed functionality across all
1045protocols.
1046Interface addresses are reference-counted.
1047.Pp
1048The members of
1049.Vt "struct ifaddr"
1050are as follows:
1051.Bl -tag -width ".Va ifa_rtrequest" -offset indent
1052.It Va ifa_addr
1053.Pq Vt "struct sockaddr *"
1054The local address of the interface.
1055.It Va ifa_dstaddr
1056.Pq Vt "struct sockaddr *"
1057The remote address of point-to-point interfaces, and the broadcast
1058address of broadcast interfaces.
1059.Va ( ifa_broadaddr
1060is a macro for
1061.Va ifa_dstaddr . )
1062.It Va ifa_netmask
1063.Pq Vt "struct sockaddr *"
1064The network mask for multi-access interfaces, and the confusion
1065generator for point-to-point interfaces.
1066.It Va ifa_ifp
1067.Pq Vt "struct ifnet *"
1068A link back to the interface structure.
1069.It Va ifa_link
1070.Pq Fn TAILQ_ENTRY ifaddr
1071.Xr queue 3
1072glue for list of addresses on each interface.
1073.It Va ifa_rtrequest
1074See below.
1075.It Va ifa_flags
1076.Pq Vt u_short
1077Some of the flags which would be used for a route representing this
1078address in the route table.
1079.It Va ifa_refcnt
1080.Pq Vt short
1081The reference count.
1082.El
1083.Pp
1084References to
1085.Vt ifaddr
1086structures are gained by calling the
1087.Fn ifa_ref
1088function and released by calling the
1089.Fn ifa_free
1090function.
1091.Pp
1092.Fn ifa_rtrequest
1093is a pointer to a function which receives callouts from the routing
1094code
1095.Pq Fn rtrequest
1096to perform link-layer-specific actions upon requests to add,
1097or delete routes.
1098The
1099.Fa cmd
1100argument indicates the request in question:
1101.Dv RTM_ADD ,
1102or
1103.Dv RTM_DELETE .
1104The
1105.Fa rt
1106argument is the route in question; the
1107.Fa info
1108argument contains the specific destination being manipulated.
1109.Sh FUNCTIONS
1110The functions provided by the generic interface code can be divided
1111into two groups: those which manipulate interfaces, and those which
1112manipulate interface addresses.
1113In addition to these functions, there
1114may also be link-layer support routines which are used by a number of
1115drivers implementing a specific link layer over different hardware;
1116see the documentation for that link layer for more details.
1117.Ss The ifmultiaddr Structure
1118Every multicast-capable interface is associated with a list of
1119multicast group memberships, which indicate at a low level which
1120link-layer multicast addresses (if any) should be accepted, and at a
1121high level, in which network-layer multicast groups a user process has
1122expressed interest.
1123.Pp
1124The elements of the structure are as follows:
1125.Bl -tag -width ".Va ifma_refcount" -offset indent
1126.It Va ifma_link
1127.Pq Fn LIST_ENTRY ifmultiaddr
1128.Xr queue 3
1129macro glue.
1130.It Va ifma_addr
1131.Pq Vt "struct sockaddr *"
1132A pointer to the address which this record represents.
1133The
1134memberships for various address families are stored in arbitrary
1135order.
1136.It Va ifma_lladdr
1137.Pq Vt "struct sockaddr *"
1138A pointer to the link-layer multicast address, if any, to which the
1139network-layer multicast address in
1140.Va ifma_addr
1141is mapped, else a null pointer.
1142If this element is non-nil, this
1143membership also holds an invisible reference to another membership for
1144that link-layer address.
1145.It Va ifma_refcount
1146.Pq Vt u_int
1147A reference count of requests for this particular membership.
1148.El
1149.Ss Interface Manipulation Functions
1150.Bl -ohang -offset indent
1151.It Fn if_alloc
1152Allocate and initialize
1153.Vt "struct ifnet" .
1154Initialization includes the allocation of an interface index and may
1155include the allocation of a
1156.Fa type
1157specific structure in
1158.Va if_l2com .
1159.It Fn if_alloc_dev
1160Allocate and initialize
1161.Vt "struct ifnet"
1162as
1163.Fn if_alloc
1164does, with the addition that the ifnet can be tagged with the
1165appropriate NUMA domain derived from the
1166.Fa dev
1167argument passed by the caller.
1168.It Fn if_alloc_domain
1169Allocate and initialize
1170.Vt "struct ifnet"
1171as
1172.Fn if_alloc
1173does, with the addition that the ifnet will be tagged with the NUMA
1174domain via the
1175.Fa numa_domain
1176argument passed by the caller.
1177.It Fn if_attach
1178Link the specified interface
1179.Fa ifp
1180into the list of network interfaces.
1181Also initialize the list of
1182addresses on that interface, and create a link-layer
1183.Vt ifaddr
1184structure to be the first element in that list.
1185(A pointer to
1186this address structure is saved in the
1187.Vt ifnet
1188structure and is accessed by the
1189.Fn ifaddr_byindex
1190function.)
1191The
1192.Fa ifp
1193must have been allocated by
1194.Fn if_alloc ,
1195.Fn if_alloc_dev
1196or
1197.Fn if_alloc_domain .
1198.It Fn if_detach
1199Shut down and unlink the specified
1200.Fa ifp
1201from the interface list.
1202.It Fn if_free
1203Free the given
1204.Fa ifp
1205back to the system.
1206The interface must have been previously detached if it was ever attached.
1207.It Fn if_free_type
1208Identical to
1209.Fn if_free
1210except that the given
1211.Fa type
1212is used to free
1213.Va if_l2com
1214instead of the type in
1215.Va if_type .
1216This is intended for use with drivers that change their interface type.
1217.It Fn if_down
1218Mark the interface
1219.Fa ifp
1220as down (i.e.,
1221.Dv IFF_UP
1222is not set),
1223flush its output queue, notify protocols of the transition,
1224and generate a message from the
1225.Xr route 4
1226routing socket.
1227.It Fn if_up
1228Mark the interface
1229.Fa ifp
1230as up, notify protocols of the transition,
1231and generate a message from the
1232.Xr route 4
1233routing socket.
1234.It Fn ifpromisc
1235Add or remove a promiscuous reference to
1236.Fa ifp .
1237If
1238.Fa pswitch
1239is true, add a reference;
1240if it is false, remove a reference.
1241On reference count transitions
1242from zero to one and one to zero, set the
1243.Dv IFF_PROMISC
1244flag appropriately and call
1245.Fn if_ioctl
1246to set up the interface in the desired mode.
1247.It Fn if_allmulti
1248As
1249.Fn ifpromisc ,
1250but for the all-multicasts
1251.Pq Dv IFF_ALLMULTI
1252flag instead of the promiscuous flag.
1253.It Fn ifunit
1254Return an
1255.Vt ifnet
1256pointer for the interface named
1257.Fa name .
1258.It Fn ifunit_ref
1259Return a reference-counted (via
1260.Fn ifa_ref )
1261.Vt ifnet
1262pointer for the interface named
1263.Fa name .
1264This is the preferred function over
1265.Fn ifunit .
1266The caller is responsible for releasing the reference with
1267.Fn if_rele
1268when it is finished with the ifnet.
1269.It Fn ifioctl
1270Process the ioctl request
1271.Fa cmd ,
1272issued on socket
1273.Fa so
1274by thread
1275.Fa td ,
1276with data parameter
1277.Fa data .
1278This is the main routine for handling all interface configuration
1279requests from user mode.
1280It is ordinarily only called from the socket-layer
1281.Xr ioctl 2
1282handler, and only for commands with class
1283.Sq Li i .
1284Any unrecognized commands will be passed down to socket
1285.Fa so Ns 's
1286protocol for
1287further interpretation.
1288The following commands are handled by
1289.Fn ifioctl :
1290.Pp
1291.Bl -tag -width ".Dv SIOCGIFNETMASK" -offset indent -compact
1292.It Dv SIOCGIFCONF
1293Get interface configuration.
1294(No call-down to driver.)
1295.Pp
1296.It Dv SIOCSIFNAME
1297Set the interface name.
1298.Dv RTM_IFANNOUNCE
1299departure and arrival messages are sent so that
1300routing code that relies on the interface name will update its interface
1301list.
1302Caller must have appropriate privilege.
1303(No call-down to driver.)
1304.It Dv SIOCGIFCAP
1305.It Dv SIOCGIFDATA
1306.It Dv SIOCGIFFIB
1307.It Dv SIOCGIFFLAGS
1308.It Dv SIOCGIFMETRIC
1309.It Dv SIOCGIFMTU
1310.It Dv SIOCGIFPHYS
1311Get interface capabilities, data, FIB, flags, metric, MTU, medium selection.
1312(No call-down to driver.)
1313.Pp
1314.It Dv SIOCSIFCAP
1315Enable or disable interface capabilities.
1316Caller must have appropriate privilege.
1317Before a call to the driver-specific
1318.Fn if_ioctl
1319routine, the requested mask for enabled capabilities is checked
1320against the mask of capabilities supported by the interface,
1321.Va if_capabilities .
1322Requesting to enable an unsupported capability is invalid.
1323The rest is supposed to be done by the driver,
1324which includes updating
1325.Va if_capenable
1326and
1327.Va if_data.ifi_hwassist
1328appropriately.
1329.Pp
1330.It Dv SIOCGIFCAPNV
1331.Xr NV 9
1332version of the
1333.Dv SIOCGIFCAP
1334ioctl.
1335Caller must provide a pointer to
1336.Vt struct ifreq_cap_nv
1337as
1338.Fa data ,
1339where the member
1340.Dv buffer
1341points to some buffer containing
1342.Dv buf_length
1343bytes.
1344The serialized nvlist with description of the device capabilities
1345is written to the buffer.
1346If buffer is too short, the structure is updated with
1347.Dv buffer
1348member set to
1349.Dv NULL ,
1350.Dv length
1351set to the minimal required length, and error
1352.Er EFBIG
1353is returned.
1354.Pp
1355Elements of the returned nvlist for simple capabilities are boolean,
1356identified by names.
1357Presence of the boolean element means that corresponding capability is
1358supported by the interface.
1359Element's value describes the current configured state:
1360.Dv true
1361means that the capability is enabled, and
1362.Dv false
1363that it is disabled.
1364.Pp
1365Driver indicates support for both
1366.Dv SIOCGIFCAPNV
1367and
1368.Dv SIOCSIFCAPNV
1369requests by setting
1370.Dv IFCAP_NV
1371non-modifiable capability bit in
1372.Dv if_capabilities .
1373.Pp
1374.It Dv SIOCSIFCAPNV
1375.Xr NV 9
1376version of the
1377.Dv SIOCSIFCAP
1378ioctl.
1379Caller must provide the pointer to
1380.Vt struct ifreq_cap_nv
1381as
1382.Fa data ,
1383where the member
1384.Dv buffer
1385points to serialized nvlist of
1386.Dv length
1387bytes.
1388Each element of nvlist describes a requested update of one capability,
1389identified by the element name.
1390For simple capabilities, the element must be boolean.
1391Its
1392.Dv true
1393value means that the caller asks to enable the capability, and
1394.Dv false
1395value to disable.
1396Only capabilities listed in the nvlist are affected by the call.
1397.Pp
1398.It Dv SIOCSIFFIB
1399Sets interface FIB.
1400Caller must have appropriate privilege.
1401FIB values start at 0 and values greater or equals than
1402.Va net.fibs
1403are considered invalid.
1404.It Dv SIOCSIFFLAGS
1405Change interface flags.
1406Caller must have appropriate privilege.
1407If a change to the
1408.Dv IFF_UP
1409flag is requested,
1410.Fn if_up
1411or
1412.Fn if_down
1413is called as appropriate.
1414Flags listed in
1415.Dv IFF_CANTCHANGE
1416are masked off, and the field
1417.Va if_flags
1418in the interface structure is updated.
1419Finally, the driver
1420.Fn if_ioctl
1421routine is called to perform any setup
1422requested.
1423.Pp
1424.It Dv SIOCSIFMETRIC
1425.It Dv SIOCSIFPHYS
1426Change interface metric or medium.
1427Caller must have appropriate privilege.
1428.Pp
1429.It Dv SIOCSIFMTU
1430Change interface MTU.
1431Caller must have appropriate privilege.
1432MTU
1433values less than 72 or greater than 65535 are considered invalid.
1434The driver
1435.Fn if_ioctl
1436routine is called to implement the change; it is responsible for any
1437additional sanity checking and for actually modifying the MTU in the
1438interface structure.
1439.Pp
1440.It Dv SIOCADDMULTI
1441.It Dv SIOCDELMULTI
1442Add or delete permanent multicast group memberships on the interface.
1443Caller must have appropriate privilege.
1444The
1445.Fn if_addmulti
1446or
1447.Fn if_delmulti
1448function is called to perform the operation; qq.v.
1449.Pp
1450.It Dv SIOCAIFADDR
1451.It Dv SIOCDIFADDR
1452The socket's protocol control routine is called to implement the
1453requested action.
1454.El
1455.El
1456.Ss "Interface Address Functions"
1457Several functions exist to look up an interface address structure
1458given an address.
1459.Fn ifa_ifwithaddr
1460returns an interface address with either a local address or a
1461broadcast address precisely matching the parameter
1462.Fa addr .
1463.Fn ifa_ifwithdstaddr
1464returns an interface address for a point-to-point interface whose
1465remote
1466.Pq Dq destination
1467address is
1468.Fa addr
1469and a fib is
1470.Fa fib .
1471If
1472.Fa fib
1473is
1474.Dv RT_ALL_FIBS ,
1475then the first interface address matching
1476.Fa addr
1477will be returned.
1478.Pp
1479.Fn ifa_ifwithnet
1480returns the most specific interface address which matches the
1481specified address,
1482.Fa addr ,
1483subject to its configured netmask, or a point-to-point interface
1484address whose remote address is
1485.Fa addr
1486if one is found.
1487If
1488.Fa ignore_ptp
1489is true, skip point-to-point interface addresses.
1490The
1491.Fa fib
1492parameter is handled the same way as by
1493.Fn ifa_ifwithdstaddr .
1494.Pp
1495.Fn ifaof_ifpforaddr
1496returns the most specific address configured on interface
1497.Fa ifp
1498which matches address
1499.Fa addr ,
1500subject to its configured netmask.
1501If the interface is
1502point-to-point, only an interface address whose remote address is
1503precisely
1504.Fa addr
1505will be returned.
1506.Pp
1507.Fn ifaddr_byindex
1508returns the link-level address of the interface with the given index
1509.Fa idx .
1510.Pp
1511All of these functions return a null pointer if no such address can be
1512found.
1513.Ss "Interface Multicast Address Functions"
1514The
1515.Fn if_addmulti ,
1516.Fn if_delmulti ,
1517and
1518.Fn if_findmulti
1519functions provide support for requesting and relinquishing multicast
1520group memberships, and for querying an interface's membership list,
1521respectively.
1522The
1523.Fn if_addmulti
1524function takes a pointer to an interface,
1525.Fa ifp ,
1526and a generic address,
1527.Fa sa .
1528It also takes a pointer to a
1529.Vt "struct ifmultiaddr *"
1530which is filled in on successful return with the address of the
1531group membership control block.
1532The
1533.Fn if_addmulti
1534function performs the following four-step process:
1535.Bl -enum -offset indent
1536.It
1537Call the interface's
1538.Fn if_resolvemulti
1539entry point to determine the link-layer address, if any, corresponding
1540to this membership request, and also to give the link layer an
1541opportunity to veto this membership request should it so desire.
1542.It
1543Check the interface's group membership list for a pre-existing
1544membership for this group.
1545If one is not found, allocate a new one;
1546if one is, increment its reference count.
1547.It
1548If the
1549.Fn if_resolvemulti
1550routine returned a link-layer address corresponding to the group,
1551repeat the previous step for that address as well.
1552.It
1553If the interface's multicast address filter needs to be changed
1554because a new membership was added, call the interface's
1555.Fn if_ioctl
1556routine
1557(with a
1558.Fa cmd
1559argument of
1560.Dv SIOCADDMULTI )
1561to request that it do so.
1562.El
1563.Pp
1564The
1565.Fn if_delmulti
1566function, given an interface
1567.Fa ifp
1568and an address,
1569.Fa sa ,
1570reverses this process.
1571Both functions return zero on success, or a
1572standard error number on failure.
1573.Pp
1574The
1575.Fn if_findmulti
1576function examines the membership list of interface
1577.Fa ifp
1578for an address matching
1579.Fa sa ,
1580and returns a pointer to that
1581.Vt "struct ifmultiaddr"
1582if one is found, else it returns a null pointer.
1583.Sh SEE ALSO
1584.Xr ioctl 2 ,
1585.Xr link_addr 3 ,
1586.Xr queue 3 ,
1587.Xr sysctl 3 ,
1588.Xr bpf 4 ,
1589.Xr ifmib 4 ,
1590.Xr lo 4 ,
1591.Xr netintro 4 ,
1592.Xr polling 4 ,
1593.Xr config 8 ,
1594.Xr ppp 8 ,
1595.Xr mbuf 9 ,
1596.Xr rtentry 9
1597.Rs
1598.%A Gary R. Wright
1599.%A W. Richard Stevens
1600.%B TCP/IP Illustrated
1601.%V Vol. 2
1602.%O Addison-Wesley, ISBN 0-201-63354-X
1603.Re
1604.Sh AUTHORS
1605This manual page was written by
1606.An Garrett A. Wollman .
1607