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 May 24, 2022 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_DRV_OACTIVE 612.Aq D* 613The interface's hardware output queue (if any) is full; output packets 614are to be queued. 615.It Dv IFF_SIMPLEX 616.Aq S* 617The interface cannot hear its own transmissions. 618.It Dv IFF_LINK0 619.It Dv IFF_LINK1 620.It Dv IFF_LINK2 621.Aq D 622Control flags for the link layer. 623(Currently abused to select among 624multiple physical layers on some devices.) 625.It Dv IFF_MULTICAST 626.Aq S* 627This interface supports multicast. 628.It Dv IFF_CANTCONFIG 629.Aq S* 630The interface is not configurable in a meaningful way. 631Primarily useful for 632.Dv IFT_USB 633interfaces registered at the interface list. 634.It Dv IFF_MONITOR 635.Aq D 636This interface blocks transmission of packets and discards incoming 637packets after BPF processing. 638Used to monitor network traffic but not interact 639with the network in question. 640.It Dv IFF_STATICARP 641.Aq D 642Used to enable/disable ARP requests on this interface. 643.It Dv IFF_DYING 644.Aq D* 645Set when the 646.Vt ifnet 647structure of this interface is being released and still has 648.Va if_refcount 649references. 650.It Dv IFF_RENAMING 651.Aq D 652Set when this interface is being renamed. 653.El 654.Ss "Interface Capabilities Flags" 655Interface capabilities are specialized features an interface may 656or may not support. 657These capabilities are very hardware-specific 658and allow, when enabled, 659to offload specific network processing to the interface 660or to offer a particular feature for use by other kernel parts. 661.Pp 662It should be stressed that a capability can be completely 663uncontrolled (i.e., stay always enabled with no way to disable it) 664or allow limited control over itself (e.g., depend on another 665capability's state.) 666Such peculiarities are determined solely by the hardware and driver 667of a particular interface. 668Only the driver possesses 669the knowledge on whether and how the interface capabilities 670can be controlled. 671Consequently, capabilities flags in 672.Va if_capenable 673should never be modified directly by kernel code other than 674the interface driver. 675The command 676.Dv SIOCSIFCAP 677to 678.Fn ifioctl 679is the dedicated means to attempt altering 680.Va if_capenable 681on an interface. 682Userland code shall use 683.Xr ioctl 2 . 684.Pp 685The following capabilities are currently supported by the system: 686.Bl -tag -width ".Dv IFCAP_VLAN_HWTAGGING" -offset indent 687.It Dv IFCAP_RXCSUM 688This interface can do checksum validation on receiving data. 689Some interfaces do not have sufficient buffer storage to store frames 690above a certain MTU-size completely. 691The driver for the interface might disable hardware checksum validation 692if the MTU is set above the hardcoded limit. 693.It Dv IFCAP_TXCSUM 694This interface can do checksum calculation on transmitting data. 695.It Dv IFCAP_HWCSUM 696A shorthand for 697.Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM . 698.It Dv IFCAP_NETCONS 699This interface can be a network console. 700.It Dv IFCAP_VLAN_MTU 701The 702.Xr vlan 4 703driver can operate over this interface in software tagging mode 704without having to decrease MTU on 705.Xr vlan 4 706interfaces below 1500 bytes. 707This implies the ability of this interface to cope with frames somewhat 708longer than permitted by the Ethernet specification. 709.It Dv IFCAP_VLAN_HWTAGGING 710This interface can do VLAN tagging on output and 711demultiplex frames by their VLAN tag on input. 712.It Dv IFCAP_JUMBO_MTU 713This Ethernet interface can transmit and receive frames up to 7149000 bytes long. 715.It Dv IFCAP_POLLING 716This interface supports 717.Xr polling 4 . 718See below for details. 719.It Dv IFCAP_VLAN_HWCSUM 720This interface can do checksum calculation on both transmitting 721and receiving data on 722.Xr vlan 4 723interfaces (implies 724.Dv IFCAP_HWCSUM ) . 725.It Dv IFCAP_TSO4 726This Ethernet interface supports TCP4 Segmentation offloading. 727.It Dv IFCAP_TSO6 728This Ethernet interface supports TCP6 Segmentation offloading. 729.It Dv IFCAP_TSO 730A shorthand for 731.Pq Dv IFCAP_TSO4 | IFCAP_TSO6 . 732.It Dv IFCAP_TOE4 733This Ethernet interface supports TCP4 Offload Engine. 734.It Dv IFCAP_TOE6 735This Ethernet interface supports TCP6 Offload Engine. 736.It Dv IFCAP_TOE 737A shorthand for 738.Pq Dv IFCAP_TOE4 | IFCAP_TOE6 . 739.It Dv IFCAP_WOL_UCAST 740This Ethernet interface supports waking up on any Unicast packet. 741.It Dv IFCAP_WOL_MCAST 742This Ethernet interface supports waking up on any Multicast packet. 743.It Dv IFCAP_WOL_MAGIC 744This Ethernet interface supports waking up on any Magic packet such 745as those sent by 746.Xr wake 8 . 747.It Dv IFCAP_WOL 748A shorthand for 749.Pq Dv IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC . 750.It Dv IFCAP_VLAN_HWFILTER 751This interface supports frame filtering in hardware on 752.Xr vlan 4 753interfaces. 754.It Dv IFCAP_VLAN_HWTSO 755This interface supports TCP Segmentation offloading on 756.Xr vlan 4 757interfaces (implies 758.Dv IFCAP_TSO ) . 759.It Dv IFCAP_LINKSTATE 760This Ethernet interface supports dynamic link state changes. 761.It Dv IFCAP_NETMAP 762This Ethernet interface supports 763.Xr netmap 4 . 764.El 765.Pp 766The ability of advanced network interfaces to offload certain 767computational tasks from the host CPU to the board is limited 768mostly to TCP/IP. 769Therefore a separate field associated with an interface 770(see 771.Va ifnet.if_data.ifi_hwassist 772below) 773keeps a detailed description of its enabled capabilities 774specific to TCP/IP processing. 775The TCP/IP module consults the field to see which tasks 776can be done on an 777.Em outgoing 778packet by the interface. 779The flags defined for that field are a superset of those for 780.Va mbuf.m_pkthdr.csum_flags , 781namely: 782.Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent 783.It Dv CSUM_IP 784The interface will compute IP checksums. 785.It Dv CSUM_TCP 786The interface will compute TCP checksums. 787.It Dv CSUM_UDP 788The interface will compute UDP checksums. 789.El 790.Pp 791An interface notifies the TCP/IP module about the tasks 792the former has performed on an 793.Em incoming 794packet by setting the corresponding flags in the field 795.Va mbuf.m_pkthdr.csum_flags 796of the 797.Vt mbuf chain 798containing the packet. 799See 800.Xr mbuf 9 801for details. 802.Pp 803The capability of a network interface to operate in 804.Xr polling 4 805mode involves several flags in different 806global variables and per-interface fields. 807The capability flag 808.Dv IFCAP_POLLING 809set in interface's 810.Va if_capabilities 811indicates support for 812.Xr polling 4 813on the particular interface. 814If set in 815.Va if_capabilities , 816the same flag can be marked or cleared in the interface's 817.Va if_capenable 818within 819.Fn ifioctl , 820thus initiating switch of the interface to 821.Xr polling 4 822mode or interrupt 823mode, respectively. 824The actual mode change is managed by the driver-specific 825.Fn if_ioctl 826routine. 827The 828.Xr polling 4 829handler returns the number of packets processed. 830.Ss The if_data Structure 831The 832.Vt if_data 833structure contains statistics and identifying information used 834by management programs, and which is exported to user programs by way 835of the 836.Xr ifmib 4 837branch of the 838.Xr sysctl 3 839MIB. 840The following elements of the 841.Vt if_data 842structure are initialized by the interface and are not expected to change 843significantly over the course of normal operation: 844.Bl -tag -width ".Va ifi_lastchange" -offset indent 845.It Va ifi_type 846.Pq Vt u_char 847The type of the interface, as defined in 848.In net/if_types.h 849and described below in the 850.Sx "Interface Types" 851section. 852.It Va ifi_physical 853.Pq Vt u_char 854Intended to represent a selection of physical layers on devices which 855support more than one; never implemented. 856.It Va ifi_addrlen 857.Pq Vt u_char 858Length of a link-layer address on this device, or zero if there are 859none. 860Used to initialized the address length field in 861.Vt sockaddr_dl 862structures referring to this interface. 863.It Va ifi_hdrlen 864.Pq Vt u_char 865Maximum length of any link-layer header which might be prepended by 866the driver to a packet before transmission. 867The generic code computes 868the maximum over all interfaces and uses that value to influence the 869placement of data in 870.Vt mbuf Ns s 871to attempt to ensure that there is always 872sufficient space to prepend a link-layer header without allocating an 873additional 874.Vt mbuf . 875.It Va ifi_datalen 876.Pq Vt u_char 877Length of the 878.Vt if_data 879structure. 880Allows some stabilization of the routing socket ABI in the face of 881increases in the length of 882.Vt struct ifdata . 883.It Va ifi_mtu 884.Pq Vt u_long 885The maximum transmission unit of the medium, exclusive of any 886link-layer overhead. 887.It Va ifi_metric 888.Pq Vt u_long 889A dimensionless metric interpreted by a user-mode routing process. 890.It Va ifi_baudrate 891.Pq Vt u_long 892The line rate of the interface, in bits per second. 893.It Va ifi_hwassist 894.Pq Vt u_long 895A detailed interpretation of the capabilities 896to offload computational tasks for 897.Em outgoing 898packets. 899The interface driver must keep this field in accord with 900the current value of 901.Va if_capenable . 902.It Va ifi_epoch 903.Pq Vt time_t 904The system uptime when interface was attached or the statistics 905below were reset. 906This is intended to be used to set the SNMP variable 907.Va ifCounterDiscontinuityTime . 908It may also be used to determine if two successive queries for an 909interface of the same index have returned results for the same 910interface. 911.El 912.Pp 913The structure additionally contains generic statistics applicable to a 914variety of different interface types (except as noted, all members are 915of type 916.Vt u_long ) : 917.Bl -tag -width ".Va ifi_lastchange" -offset indent 918.It Va ifi_link_state 919.Pq Vt u_char 920The current link state of Ethernet interfaces. 921See the 922.Sx Interface Link States 923section for possible values. 924.It Va ifi_ipackets 925Number of packets received. 926.It Va ifi_ierrors 927Number of receive errors detected (e.g., FCS errors, DMA overruns, 928etc.). 929More detailed breakdowns can often be had by way of a 930link-specific MIB. 931.It Va ifi_opackets 932Number of packets transmitted. 933.It Va ifi_oerrors 934Number of output errors detected (e.g., late collisions, DMA overruns, 935etc.). 936More detailed breakdowns can often be had by way of a 937link-specific MIB. 938.It Va ifi_collisions 939Total number of collisions detected on output for CSMA interfaces. 940(This member is sometimes [ab]used by other types of interfaces for 941other output error counts.) 942.It Va ifi_ibytes 943Total traffic received, in bytes. 944.It Va ifi_obytes 945Total traffic transmitted, in bytes. 946.It Va ifi_imcasts 947Number of packets received which were sent by link-layer multicast. 948.It Va ifi_omcasts 949Number of packets sent by link-layer multicast. 950.It Va ifi_iqdrops 951Number of packets dropped on input. 952Rarely implemented. 953.It Va ifi_oqdrops 954Number of packets dropped on output. 955.It Va ifi_noproto 956Number of packets received for unknown network-layer protocol. 957.It Va ifi_lastchange 958.Pq Vt "struct timeval" 959The time of the last administrative change to the interface (as required 960for 961.Tn SNMP ) . 962.El 963.Ss Interface Types 964The header file 965.In net/if_types.h 966defines symbolic constants for a number of different types of 967interfaces. 968The most common are: 969.Pp 970.Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact 971.It Dv IFT_OTHER 972none of the following 973.It Dv IFT_ETHER 974Ethernet 975.It Dv IFT_ISO88023 976ISO 8802-3 CSMA/CD 977.It Dv IFT_ISO88024 978ISO 8802-4 Token Bus 979.It Dv IFT_ISO88025 980ISO 8802-5 Token Ring 981.It Dv IFT_ISO88026 982ISO 8802-6 DQDB MAN 983.It Dv IFT_FDDI 984FDDI 985.It Dv IFT_PPP 986Internet Point-to-Point Protocol 987.Pq Xr ppp 8 988.It Dv IFT_LOOP 989The loopback 990.Pq Xr lo 4 991interface 992.It Dv IFT_SLIP 993Serial Line IP 994.It Dv IFT_PARA 995Parallel-port IP 996.Pq Dq Tn PLIP 997.It Dv IFT_ATM 998Asynchronous Transfer Mode 999.It Dv IFT_USB 1000USB Interface 1001.El 1002.Ss Interface Link States 1003The following link states are currently defined: 1004.Pp 1005.Bl -tag -offset indent -width ".Dv LINK_STATE_UNKNOWN" -compact 1006.It Dv LINK_STATE_UNKNOWN 1007The link is in an invalid or unknown state. 1008.It Dv LINK_STATE_DOWN 1009The link is down. 1010.It Dv LINK_STATE_UP 1011The link is up. 1012.El 1013.Ss The ifaddr Structure 1014Every interface is associated with a list 1015(or, rather, a 1016.Li TAILQ ) 1017of addresses, rooted at the interface structure's 1018.Va if_addrhead 1019member. 1020The first element in this list is always an 1021.Dv AF_LINK 1022address representing the interface itself; multi-access network 1023drivers should complete this structure by filling in their link-layer 1024addresses after calling 1025.Fn if_attach . 1026Other members of the structure represent network-layer addresses which 1027have been configured by means of the 1028.Dv SIOCAIFADDR 1029command to 1030.Xr ioctl 2 , 1031called on a socket of the appropriate protocol family. 1032The elements of this list consist of 1033.Vt ifaddr 1034structures. 1035Most protocols will declare their own protocol-specific 1036interface address structures, but all begin with a 1037.Vt "struct ifaddr" 1038which provides the most-commonly-needed functionality across all 1039protocols. 1040Interface addresses are reference-counted. 1041.Pp 1042The members of 1043.Vt "struct ifaddr" 1044are as follows: 1045.Bl -tag -width ".Va ifa_rtrequest" -offset indent 1046.It Va ifa_addr 1047.Pq Vt "struct sockaddr *" 1048The local address of the interface. 1049.It Va ifa_dstaddr 1050.Pq Vt "struct sockaddr *" 1051The remote address of point-to-point interfaces, and the broadcast 1052address of broadcast interfaces. 1053.Va ( ifa_broadaddr 1054is a macro for 1055.Va ifa_dstaddr . ) 1056.It Va ifa_netmask 1057.Pq Vt "struct sockaddr *" 1058The network mask for multi-access interfaces, and the confusion 1059generator for point-to-point interfaces. 1060.It Va ifa_ifp 1061.Pq Vt "struct ifnet *" 1062A link back to the interface structure. 1063.It Va ifa_link 1064.Pq Fn TAILQ_ENTRY ifaddr 1065.Xr queue 3 1066glue for list of addresses on each interface. 1067.It Va ifa_rtrequest 1068See below. 1069.It Va ifa_flags 1070.Pq Vt u_short 1071Some of the flags which would be used for a route representing this 1072address in the route table. 1073.It Va ifa_refcnt 1074.Pq Vt short 1075The reference count. 1076.El 1077.Pp 1078References to 1079.Vt ifaddr 1080structures are gained by calling the 1081.Fn ifa_ref 1082function and released by calling the 1083.Fn ifa_free 1084function. 1085.Pp 1086.Fn ifa_rtrequest 1087is a pointer to a function which receives callouts from the routing 1088code 1089.Pq Fn rtrequest 1090to perform link-layer-specific actions upon requests to add, 1091or delete routes. 1092The 1093.Fa cmd 1094argument indicates the request in question: 1095.Dv RTM_ADD , 1096or 1097.Dv RTM_DELETE . 1098The 1099.Fa rt 1100argument is the route in question; the 1101.Fa info 1102argument contains the specific destination being manipulated. 1103.Sh FUNCTIONS 1104The functions provided by the generic interface code can be divided 1105into two groups: those which manipulate interfaces, and those which 1106manipulate interface addresses. 1107In addition to these functions, there 1108may also be link-layer support routines which are used by a number of 1109drivers implementing a specific link layer over different hardware; 1110see the documentation for that link layer for more details. 1111.Ss The ifmultiaddr Structure 1112Every multicast-capable interface is associated with a list of 1113multicast group memberships, which indicate at a low level which 1114link-layer multicast addresses (if any) should be accepted, and at a 1115high level, in which network-layer multicast groups a user process has 1116expressed interest. 1117.Pp 1118The elements of the structure are as follows: 1119.Bl -tag -width ".Va ifma_refcount" -offset indent 1120.It Va ifma_link 1121.Pq Fn LIST_ENTRY ifmultiaddr 1122.Xr queue 3 1123macro glue. 1124.It Va ifma_addr 1125.Pq Vt "struct sockaddr *" 1126A pointer to the address which this record represents. 1127The 1128memberships for various address families are stored in arbitrary 1129order. 1130.It Va ifma_lladdr 1131.Pq Vt "struct sockaddr *" 1132A pointer to the link-layer multicast address, if any, to which the 1133network-layer multicast address in 1134.Va ifma_addr 1135is mapped, else a null pointer. 1136If this element is non-nil, this 1137membership also holds an invisible reference to another membership for 1138that link-layer address. 1139.It Va ifma_refcount 1140.Pq Vt u_int 1141A reference count of requests for this particular membership. 1142.El 1143.Ss Interface Manipulation Functions 1144.Bl -ohang -offset indent 1145.It Fn if_alloc 1146Allocate and initialize 1147.Vt "struct ifnet" . 1148Initialization includes the allocation of an interface index and may 1149include the allocation of a 1150.Fa type 1151specific structure in 1152.Va if_l2com . 1153.It Fn if_alloc_dev 1154Allocate and initialize 1155.Vt "struct ifnet" 1156as 1157.Fn if_alloc 1158does, with the addition that the ifnet can be tagged with the 1159appropriate NUMA domain derived from the 1160.Fa dev 1161argument passed by the caller. 1162.It Fn if_alloc_domain 1163Allocate and initialize 1164.Vt "struct ifnet" 1165as 1166.Fn if_alloc 1167does, with the addition that the ifnet will be tagged with the NUMA 1168domain via the 1169.Fa numa_domain 1170argument passed by the caller. 1171.It Fn if_attach 1172Link the specified interface 1173.Fa ifp 1174into the list of network interfaces. 1175Also initialize the list of 1176addresses on that interface, and create a link-layer 1177.Vt ifaddr 1178structure to be the first element in that list. 1179(A pointer to 1180this address structure is saved in the 1181.Vt ifnet 1182structure.) 1183The 1184.Fa ifp 1185must have been allocated by 1186.Fn if_alloc , 1187.Fn if_alloc_dev 1188or 1189.Fn if_alloc_domain . 1190.It Fn if_detach 1191Shut down and unlink the specified 1192.Fa ifp 1193from the interface list. 1194.It Fn if_free 1195Free the given 1196.Fa ifp 1197back to the system. 1198The interface must have been previously detached if it was ever attached. 1199.It Fn if_free_type 1200Identical to 1201.Fn if_free 1202except that the given 1203.Fa type 1204is used to free 1205.Va if_l2com 1206instead of the type in 1207.Va if_type . 1208This is intended for use with drivers that change their interface type. 1209.It Fn if_down 1210Mark the interface 1211.Fa ifp 1212as down (i.e., 1213.Dv IFF_UP 1214is not set), 1215flush its output queue, notify protocols of the transition, 1216and generate a message from the 1217.Xr route 4 1218routing socket. 1219.It Fn if_up 1220Mark the interface 1221.Fa ifp 1222as up, notify protocols of the transition, 1223and generate a message from the 1224.Xr route 4 1225routing socket. 1226.It Fn ifpromisc 1227Add or remove a promiscuous reference to 1228.Fa ifp . 1229If 1230.Fa pswitch 1231is true, add a reference; 1232if it is false, remove a reference. 1233On reference count transitions 1234from zero to one and one to zero, set the 1235.Dv IFF_PROMISC 1236flag appropriately and call 1237.Fn if_ioctl 1238to set up the interface in the desired mode. 1239.It Fn if_allmulti 1240As 1241.Fn ifpromisc , 1242but for the all-multicasts 1243.Pq Dv IFF_ALLMULTI 1244flag instead of the promiscuous flag. 1245.It Fn ifunit 1246Return an 1247.Vt ifnet 1248pointer for the interface named 1249.Fa name . 1250.It Fn ifunit_ref 1251Return a reference-counted (via 1252.Fn ifa_ref ) 1253.Vt ifnet 1254pointer for the interface named 1255.Fa name . 1256This is the preferred function over 1257.Fn ifunit . 1258The caller is responsible for releasing the reference with 1259.Fn if_rele 1260when it is finished with the ifnet. 1261.It Fn ifioctl 1262Process the ioctl request 1263.Fa cmd , 1264issued on socket 1265.Fa so 1266by thread 1267.Fa td , 1268with data parameter 1269.Fa data . 1270This is the main routine for handling all interface configuration 1271requests from user mode. 1272It is ordinarily only called from the socket-layer 1273.Xr ioctl 2 1274handler, and only for commands with class 1275.Sq Li i . 1276Any unrecognized commands will be passed down to socket 1277.Fa so Ns 's 1278protocol for 1279further interpretation. 1280The following commands are handled by 1281.Fn ifioctl : 1282.Pp 1283.Bl -tag -width ".Dv SIOCGIFNETMASK" -offset indent -compact 1284.It Dv SIOCGIFCONF 1285Get interface configuration. 1286(No call-down to driver.) 1287.Pp 1288.It Dv SIOCSIFNAME 1289Set the interface name. 1290.Dv RTM_IFANNOUNCE 1291departure and arrival messages are sent so that 1292routing code that relies on the interface name will update its interface 1293list. 1294Caller must have appropriate privilege. 1295(No call-down to driver.) 1296.It Dv SIOCGIFCAP 1297.It Dv SIOCGIFDATA 1298.It Dv SIOCGIFFIB 1299.It Dv SIOCGIFFLAGS 1300.It Dv SIOCGIFMETRIC 1301.It Dv SIOCGIFMTU 1302.It Dv SIOCGIFPHYS 1303Get interface capabilities, data, FIB, flags, metric, MTU, medium selection. 1304(No call-down to driver.) 1305.Pp 1306.It Dv SIOCSIFCAP 1307Enable or disable interface capabilities. 1308Caller must have appropriate privilege. 1309Before a call to the driver-specific 1310.Fn if_ioctl 1311routine, the requested mask for enabled capabilities is checked 1312against the mask of capabilities supported by the interface, 1313.Va if_capabilities . 1314Requesting to enable an unsupported capability is invalid. 1315The rest is supposed to be done by the driver, 1316which includes updating 1317.Va if_capenable 1318and 1319.Va if_data.ifi_hwassist 1320appropriately. 1321.Pp 1322.It Dv SIOCGIFCAPNV 1323.Xr NV 9 1324version of the 1325.Dv SIOCGIFCAP 1326ioctl. 1327Caller must provide a pointer to 1328.Vt struct ifreq_cap_nv 1329as 1330.Fa data , 1331where the member 1332.Dv buffer 1333points to some buffer containing 1334.Dv buf_length 1335bytes. 1336The serialized nvlist with description of the device capabilities 1337is written to the buffer. 1338If buffer is too short, the structure is updated with 1339.Dv buffer 1340member set to 1341.Dv NULL , 1342.Dv length 1343set to the minimal required length, and error 1344.Er EFBIG 1345is returned. 1346.Pp 1347Elements of the returned nvlist for simple capabilities are boolean, 1348identified by names. 1349Presence of the boolean element means that corresponding capability is 1350supported by the interface. 1351Element's value describes the current configured state: 1352.Dv true 1353means that the capability is enabled, and 1354.Dv false 1355that it is disabled. 1356.Pp 1357Driver indicates support for both 1358.Dv SIOCGIFCAPNV 1359and 1360.Dv SIOCSIFCAPNV 1361requests by setting 1362.Dv IFCAP_NV 1363non-modifiable capability bit in 1364.Dv if_capabilities . 1365.Pp 1366.It Dv SIOCSIFCAPNV 1367.Xr NV 9 1368version of the 1369.Dv SIOCSIFCAP 1370ioctl. 1371Caller must provide the pointer to 1372.Vt struct ifreq_cap_nv 1373as 1374.Fa data , 1375where the member 1376.Dv buffer 1377points to serialized nvlist of 1378.Dv length 1379bytes. 1380Each element of nvlist describes a requested update of one capability, 1381identified by the element name. 1382For simple capabilities, the element must be boolean. 1383Its 1384.Dv true 1385value means that the caller asks to enable the capability, and 1386.Dv false 1387value to disable. 1388Only capabilities listed in the nvlist are affected by the call. 1389.Pp 1390.It Dv SIOCSIFFIB 1391Sets interface FIB. 1392Caller must have appropriate privilege. 1393FIB values start at 0 and values greater or equals than 1394.Va net.fibs 1395are considered invalid. 1396.It Dv SIOCSIFFLAGS 1397Change interface flags. 1398Caller must have appropriate privilege. 1399If a change to the 1400.Dv IFF_UP 1401flag is requested, 1402.Fn if_up 1403or 1404.Fn if_down 1405is called as appropriate. 1406Flags listed in 1407.Dv IFF_CANTCHANGE 1408are masked off, and the field 1409.Va if_flags 1410in the interface structure is updated. 1411Finally, the driver 1412.Fn if_ioctl 1413routine is called to perform any setup 1414requested. 1415.Pp 1416.It Dv SIOCSIFMETRIC 1417.It Dv SIOCSIFPHYS 1418Change interface metric or medium. 1419Caller must have appropriate privilege. 1420.Pp 1421.It Dv SIOCSIFMTU 1422Change interface MTU. 1423Caller must have appropriate privilege. 1424MTU 1425values less than 72 or greater than 65535 are considered invalid. 1426The driver 1427.Fn if_ioctl 1428routine is called to implement the change; it is responsible for any 1429additional sanity checking and for actually modifying the MTU in the 1430interface structure. 1431.Pp 1432.It Dv SIOCADDMULTI 1433.It Dv SIOCDELMULTI 1434Add or delete permanent multicast group memberships on the interface. 1435Caller must have appropriate privilege. 1436The 1437.Fn if_addmulti 1438or 1439.Fn if_delmulti 1440function is called to perform the operation; qq.v. 1441.Pp 1442.It Dv SIOCAIFADDR 1443.It Dv SIOCDIFADDR 1444The socket's protocol control routine is called to implement the 1445requested action. 1446.El 1447.El 1448.Ss "Interface Address Functions" 1449Several functions exist to look up an interface address structure 1450given an address. 1451.Fn ifa_ifwithaddr 1452returns an interface address with either a local address or a 1453broadcast address precisely matching the parameter 1454.Fa addr . 1455.Fn ifa_ifwithdstaddr 1456returns an interface address for a point-to-point interface whose 1457remote 1458.Pq Dq destination 1459address is 1460.Fa addr 1461and a fib is 1462.Fa fib . 1463If 1464.Fa fib 1465is 1466.Dv RT_ALL_FIBS , 1467then the first interface address matching 1468.Fa addr 1469will be returned. 1470.Pp 1471.Fn ifa_ifwithnet 1472returns the most specific interface address which matches the 1473specified address, 1474.Fa addr , 1475subject to its configured netmask, or a point-to-point interface 1476address whose remote address is 1477.Fa addr 1478if one is found. 1479If 1480.Fa ignore_ptp 1481is true, skip point-to-point interface addresses. 1482The 1483.Fa fib 1484parameter is handled the same way as by 1485.Fn ifa_ifwithdstaddr . 1486.Pp 1487.Fn ifaof_ifpforaddr 1488returns the most specific address configured on interface 1489.Fa ifp 1490which matches address 1491.Fa addr , 1492subject to its configured netmask. 1493If the interface is 1494point-to-point, only an interface address whose remote address is 1495precisely 1496.Fa addr 1497will be returned. 1498.Pp 1499All of these functions return a null pointer if no such address can be 1500found. 1501.Ss "Interface Multicast Address Functions" 1502The 1503.Fn if_addmulti , 1504.Fn if_delmulti , 1505and 1506.Fn if_findmulti 1507functions provide support for requesting and relinquishing multicast 1508group memberships, and for querying an interface's membership list, 1509respectively. 1510The 1511.Fn if_addmulti 1512function takes a pointer to an interface, 1513.Fa ifp , 1514and a generic address, 1515.Fa sa . 1516It also takes a pointer to a 1517.Vt "struct ifmultiaddr *" 1518which is filled in on successful return with the address of the 1519group membership control block. 1520The 1521.Fn if_addmulti 1522function performs the following four-step process: 1523.Bl -enum -offset indent 1524.It 1525Call the interface's 1526.Fn if_resolvemulti 1527entry point to determine the link-layer address, if any, corresponding 1528to this membership request, and also to give the link layer an 1529opportunity to veto this membership request should it so desire. 1530.It 1531Check the interface's group membership list for a pre-existing 1532membership for this group. 1533If one is not found, allocate a new one; 1534if one is, increment its reference count. 1535.It 1536If the 1537.Fn if_resolvemulti 1538routine returned a link-layer address corresponding to the group, 1539repeat the previous step for that address as well. 1540.It 1541If the interface's multicast address filter needs to be changed 1542because a new membership was added, call the interface's 1543.Fn if_ioctl 1544routine 1545(with a 1546.Fa cmd 1547argument of 1548.Dv SIOCADDMULTI ) 1549to request that it do so. 1550.El 1551.Pp 1552The 1553.Fn if_delmulti 1554function, given an interface 1555.Fa ifp 1556and an address, 1557.Fa sa , 1558reverses this process. 1559Both functions return zero on success, or a 1560standard error number on failure. 1561.Pp 1562The 1563.Fn if_findmulti 1564function examines the membership list of interface 1565.Fa ifp 1566for an address matching 1567.Fa sa , 1568and returns a pointer to that 1569.Vt "struct ifmultiaddr" 1570if one is found, else it returns a null pointer. 1571.Sh SEE ALSO 1572.Xr ioctl 2 , 1573.Xr link_addr 3 , 1574.Xr queue 3 , 1575.Xr sysctl 3 , 1576.Xr bpf 4 , 1577.Xr ifmib 4 , 1578.Xr lo 4 , 1579.Xr netintro 4 , 1580.Xr polling 4 , 1581.Xr config 8 , 1582.Xr ppp 8 , 1583.Xr mbuf 9 , 1584.Xr rtentry 9 1585.Rs 1586.%A Gary R. Wright 1587.%A W. Richard Stevens 1588.%B TCP/IP Illustrated 1589.%V Vol. 2 1590.%O Addison-Wesley, ISBN 0-201-63354-X 1591.Re 1592.Sh AUTHORS 1593This manual page was written by 1594.An Garrett A. Wollman . 1595