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