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