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