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