1.\" -*- Nroff -*- 2.\" Copyright 1996, 1997 Massachusetts Institute of Technology 3.\" 4.\" Permission to use, copy, modify, and distribute this software and 5.\" its documentation for any purpose and without fee is hereby 6.\" granted, provided that both the above copyright notice and this 7.\" permission notice appear in all copies, that both the above 8.\" copyright notice and this permission notice appear in all 9.\" supporting documentation, and that the name of M.I.T. not be used 10.\" in advertising or publicity pertaining to distribution of the 11.\" software without specific, written prior permission. M.I.T. makes 12.\" no representations about the suitability of this software for any 13.\" purpose. It is provided "as is" without express or implied 14.\" warranty. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17.\" ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20.\" SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24.\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27.\" SUCH DAMAGE. 28.\" 29.\" $FreeBSD$ 30.\" 31.Dd June 8, 2004 32.Os 33.Dt IFNET 9 34.Sh NAME 35.Nm ifnet , 36.Nm ifaddr , 37.Nm ifqueue , 38.Nm if_data 39.Nd kernel interfaces for manipulating network interfaces 40.Sh SYNOPSIS 41.In sys/param.h 42.In sys/time.h 43.In sys/socket.h 44.In net/if.h 45.In net/if_var.h 46.In net/if_types.h 47.\" 48.Ss "Interface Manipulation Functions" 49.Ft void 50.Fn if_attach "struct ifnet *ifp" 51.Ft void 52.Fn if_down "struct ifnet *ifp" 53.Ft int 54.Fn ifioctl "struct socket *so" "u_long cmd" "caddr_t data" "struct thread *td" 55.Ft int 56.Fn ifpromisc "struct ifnet *ifp" "int pswitch" 57.Ft int 58.Fn if_allmulti "struct ifnet *ifp" "int amswitch" 59.Ft "struct ifnet *" 60.Fn ifunit "const char *name" 61.Ft void 62.Fn if_up "struct ifnet *ifp" 63.\" 64.Ss "Interface Address Functions" 65.Ft "struct ifaddr *" 66.Fn ifa_ifwithaddr "struct sockaddr *addr" 67.Ft "struct ifaddr *" 68.Fn ifa_ifwithdstaddr "struct sockaddr *addr" 69.Ft "struct ifaddr *" 70.Fn ifa_ifwithnet "struct sockaddr *addr" 71.Ft "struct ifaddr *" 72.Fn ifaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp" 73.Ft void 74.Fn ifafree "struct ifaddr *ifa" 75.Fn IFAFREE "struct ifaddr *ifa" 76.\" 77.Ss "Interface Multicast Address Functions" 78.Ft int 79.Fn if_addmulti "struct ifnet *ifp" "struct sockaddr *sa" "struct ifmultiaddr **ifmap" 80.Ft int 81.Fn if_delmulti "struct ifnet *ifp" "struct sockaddr *sa" 82.Ft "struct ifmultiaddr *" 83.Fn ifmaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp" 84.Ss "Output queue macros" 85.Fn IF_DEQUEUE "struct ifqueue *ifq" "struct mbuf *m" 86.\" 87.Ss "struct ifnet Member Functions" 88.Ft void 89.Fn \*(lp*if_input\*(rp "struct ifnet *ifp" "struct mbuf *m" 90.Ft int 91.Fo \*(lp*if_output\*(rp 92.Fa "struct ifnet *ifp" "struct mbuf *m" 93.Fa "struct sockaddr *dst" "struct rtentry *rt" 94.Fc 95.Ft void 96.Fn \*(lp*if_start\*(rp "struct ifnet *ifp" 97.Ft int 98.Fn \*(lp*if_done\*(rp "struct ifnet *ifp" 99.Ft int 100.Fn \*(lp*if_ioctl\*(rp "struct ifnet *ifp" "int cmd" "caddr_t data" 101.Ft void 102.Fn \*(lp*if_watchdog\*(rp "struct ifnet *ifp" 103.Ft int 104.Fn \*(lp*if_poll_recv\*(rp "struct ifnet *ifp" "int *quotap" 105.Ft int 106.Fn \*(lp*if_poll_xmit\*(rp "struct ifnet *ifp" "int *quotap" 107.Ft void 108.Fn \*(lp*if_poll_inttrn\*(rp "struct ifnet *ifp" 109.Ft void 110.Fn \*(lp*if_poll_slowinput\*(rp "struct ifnet *ifp" "struct mbuf *m" 111.Ft void 112.Fn \*(lp*if_init\*(rp "void *if_softc" 113.Ft int 114.Fo \*(lp*if_resolvemulti\*(rp 115.Fa "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr" 116.Fc 117.Ss "struct ifaddr member function" 118.Ft void 119.Fo \*(lp*ifa_rtrequest\*(rp 120.Fa "int cmd" "struct rtentry *rt" "struct sockaddr *dst" 121.Fc 122.\" 123.Ss "Global Variables" 124.Vt extern struct ifnethead ifnet ; 125.Vt extern struct ifaddr **ifnet_addrs ; 126.Vt extern int if_index ; 127.Vt extern int ifqmaxlen ; 128.Sh DATA STRUCTURES 129The kernel mechanisms for handling network interfaces reside primarily 130in the 131.Vt ifnet , if_data , ifaddr , 132and 133.Vt ifmultiaddr 134structures in 135.In net/if.h 136and 137.In net/if_var.h 138and the functions named above and defined in 139.Pa /sys/net/if.c . 140Those interfaces which are intended to be used by user programs 141are defined in 142.In net/if.h ; 143these include the interface flags, the 144.Vt if_data 145structure, and the structures defining the appearance of 146interface-related messages on the 147.Xr route 4 148routing socket and in 149.Xr sysctl 3 . 150The header file 151.In net/if_var.h 152defines the kernel-internal interfaces, including the 153.Vt ifnet , ifaddr , 154and 155.Vt ifmultiaddr 156structures and the functions which manipulate them. 157(A few user programs will need 158.In net/if_var.h 159because it is the prerequisite of some other header file like 160.In netinet/if_ether.h . 161Most references to those two files in particular can be replaced by 162.In net/ethernet.h . ) 163.Pp 164The system keeps a linked list of interfaces using the 165.Li TAILQ 166macros defined in 167.Xr queue 3 ; 168this list is headed by a 169.Vt "struct ifnethead" 170called 171.Va ifnet . 172The elements of this list are of type 173.Vt "struct ifnet" , 174and most kernel routines which manipulate interface as such accept or 175return pointers to these structures. 176Each interface structure 177contains an 178.Vt if_data 179structure, which contains statistics and identifying information used 180by management programs, and which is exported to user programs by way 181of the 182.Xr ifmib 4 183branch of the 184.Xr sysctl 3 185MIB. 186Each interface also has a 187.Li TAILQ 188of interface addresses, described by 189.Vt ifaddr 190structures; the head of the queue is always an 191.Dv AF_LINK 192address 193(see 194.Xr link_addr 3 ) 195describing the link layer implemented by the interface (if any). 196(Some trivial interfaces do not provide any link layer addresses; 197this structure, while still present, serves only to identify the 198interface name and index.) 199.Pp 200Finally, those interfaces supporting reception of multicast datagrams 201have a 202.Li TAILQ 203of multicast group memberships, described by 204.Vt ifmultiaddr 205structures. 206These memberships are reference-counted. 207.Pp 208Interfaces are also associated with an output queue, defined as a 209.Vt "struct ifqueue" ; 210this structure is used to hold packets while the interface is in the 211process of sending another. 212.Pp 213.Ss The Vt ifnet Ss structure 214The fields of 215.Vt "struct ifnet" 216are as follows: 217.Bl -tag -width ".Va if_capabilities" -offset indent 218.It Va if_softc 219.Pq Vt "void *" 220A pointer to the driver's private state block. 221(Initialized by driver.) 222.It Va if_link 223.Pq Fn TAILQ_ENTRY ifnet 224.Xr queue 3 225macro glue. 226.It Va if_xname 227.Pq Vt "char *" 228The name of the interface, 229(e.g., 230.Dq Li fxp0 231or 232.Dq Li lo0 ) . 233(Initialized by driver.) 234.It Va if_dname 235.Pq Vt "const char *" 236The name of the driver. 237(Initialized by driver.) 238.It Va if_dunit 239.Pq Vt int 240A unique number assigned to each interface managed by a particular 241driver. 242Drivers may choose to set this to 243.Dv IF_DUNIT_NONE 244if a unit number is not associated with the device. 245(Initialized by driver.) 246.It Va if_addrhead 247.Pq Vt "struct ifaddrhead" 248The head of the 249.Xr queue 3 250.Li TAILQ 251containing the list of addresses assigned to this interface. 252.It Va if_pcount 253.Pq Vt int 254A count of promiscuous listeners on this interface, used to 255reference-count the 256.Dv IFF_PROMISC 257flag. 258.It Va if_bpf 259.Pq Vt "struct bpf_if *" 260Opaque per-interface data for the packet filter, 261.Xr bpf 4 . 262(Initialized by 263.Fn bpf_attach . ) 264.It Va if_index 265.Pq Vt u_short 266A unique number assigned to each interface in sequence as it is 267attached. 268This number can be used in a 269.Vt "struct sockaddr_dl" 270to refer to a particular interface by index 271(see 272.Xr link_addr 3 ) . 273.It Va if_timer 274.Pq Vt short 275Number of seconds until the watchdog timer 276.Fn if_watchdog 277is called, or zero if the timer is disabled. 278(Set by driver, 279decremented by generic watchdog code.) 280.It Va if_flags 281.Pq Vt int 282Flags describing operational parameters of this interface (see below). 283(Manipulated by both driver and generic code.) 284.It Va if_capabilities 285.Pq Vt int 286Flags describing the capabilities the interface supports (see below). 287.It Va if_capenable 288.Pq Vt int 289Flags describing the enabled capabilities of the interface (see below). 290.\" .It Va if_ipending 291.\" Interrupt-pending bits for polled operation: 292.\" .Dv IFI_XMIT 293.\" (transmit complete interrupt) 294.\" and 295.\" .Dv IFI_RECV 296.\" (received packet ready interrupt). 297.\" See the 298.\" .Sx Polling 299.\" section, below. 300.\" (Manipulated by driver.) 301.It Va if_linkmib 302.Pq Vt "void *" 303A pointer to an interface-specific MIB structure exported by 304.Xr ifmib 4 . 305(Initialized by driver.) 306.It Va if_linkmiblen 307.Pq Vt size_t 308The size of said structure. 309(Initialized by driver.) 310.It Va if_data 311.Pq Vt "struct if_data" 312More statistics and information; see 313.Sx "The if_data structure" , 314below. 315(Initialized by driver, manipulated by both driver and generic 316code.) 317.It Va if_snd 318.Pq Vt "struct ifqueue" 319The output queue. 320(Manipulated by driver.) 321.\".It Va if_poll_slowq 322.\".Pq Vt "struct ifqueue *" 323.\"A pointer to the input queue for devices which do not support polling 324.\"well. 325.\"See the 326.\".Sx Polling 327.\"section, below. 328.\"(Initialized by driver.) 329.El 330.Pp 331There are in addition a number of function pointers which the driver 332must initialize to complete its interface with the generic interface 333layer: 334.Bl -ohang -offset indent 335.It Fn if_input 336Pass a packet to an appropriate upper layer as determined 337from the link-layer header of the packet. 338This routine is to be called from an interrupt handler or 339used to emulate reception of a packet on this interface. 340A single function implementing 341.Fn if_input 342can be shared among multiple drivers utilizing the same link-layer 343framing, e.g., Ethernet. 344.It Fn if_output 345Output a packet on interface 346.Fa ifp , 347or queue it on the output queue if the interface is already active. 348.It Fn if_start 349Start queued output on an interface. 350This function is exposed in 351order to provide for some interface classes to share a 352.Fn if_output 353among all drivers. 354.Fn if_start 355may only be called when the 356.Dv IFF_OACTIVE 357flag is not set. 358(Thus, 359.Dv IFF_OACTIVE 360does not literally mean that output is active, but rather that the 361device's internal output queue is full.) 362.It Fn if_done 363Not used. 364We are not even sure what it was ever for. 365The prototype is faked. 366.It Fn if_ioctl 367Process interface-related 368.Xr ioctl 2 369requests 370(defined in 371.In sys/sockio.h ) . 372Preliminary processing is done by the generic routine 373.Fn ifioctl 374to check for appropriate privileges, locate the interface being 375manipulated, and perform certain generic operations like twiddling 376flags and flushing queues. 377See the description of 378.Fn ifioctl 379below for more information. 380.It Fn if_watchdog 381Routine called by the generic code when the watchdog timer, 382.Va if_timer , 383expires. 384Usually this will reset the interface. 385.\" .It Fn if_poll_recv 386.\" .It Fn if_poll_xmit 387.\" .It Fn if_poll_slowinput 388.\" .It Fn if_poll_intren 389.\" See the 390.\" .Sx Polling 391.\" section, below. 392.It Fn if_init 393Initialize and bring up the hardware, 394e.g., reset the chip and the watchdog timer and enable the receiver unit. 395Should mark the interface running, 396but not active 397.Dv ( IFF_RUNNING , ~IIF_OACTIVE ) . 398.It Fn if_resolvemulti 399Check the requested multicast group membership, 400.Fa addr , 401for validity, and if necessary compute a link-layer group which 402corresponds to that address which is returned in 403.Fa *retsa . 404Returns zero on success, or an error code on failure. 405.El 406.Ss "Interface Flags" 407Interface flags are used for a number of different purposes. 408Some 409flags simply indicate information about the type of interface and its 410capabilities; others are dynamically manipulated to reflect the 411current state of the interface. 412Flags of the former kind are marked 413.Aq S 414in this table; the latter are marked 415.Aq D . 416.Pp 417The macro 418.Dv IFF_CANTCHANGE 419defines the bits which cannot be set by a user program using the 420.Dv SIOCSIFFLAGS 421command to 422.Xr ioctl 2 ; 423these are indicated by an asterisk 424.Pq Ql * 425in the following listing. 426.Pp 427.Bl -tag -width ".Dv IFF_POINTOPOINT" -offset indent -compact 428.It Dv IFF_UP 429.Aq D 430The interface has been configured up by the user-level code. 431.It Dv IFF_BROADCAST 432.Aq S* 433The interface supports broadcast. 434.It Dv IFF_DEBUG 435.Aq D 436Used to enable/disable driver debugging code. 437.It Dv IFF_LOOPBACK 438.Aq S 439The interface is a loopback device. 440.It Dv IFF_POINTOPOINT 441.Aq S* 442The interface is point-to-point; 443.Dq broadcast 444address is actually the address of the other end. 445.It Dv IFF_RUNNING 446.Aq D* 447The interface has been configured and dynamic resources were 448successfully allocated. 449Probably only useful internal to the 450interface. 451.It Dv IFF_NOARP 452.Aq D 453Disable network address resolution on this interface. 454.It Dv IFF_PROMISC 455.Aq D* 456This interface is in promiscuous mode. 457.It Dv IFF_PPROMISC 458.Aq D 459This interface is in the permanently promiscuous mode (implies 460.Dv IFF_PROMISC ) . 461.It Dv IFF_ALLMULTI 462.Aq D* 463This interface is in all-multicasts mode (used by multicast routers). 464.It Dv IFF_OACTIVE 465.Aq D* 466The interface's hardware output queue (if any) is full; output packets 467are to be queued. 468.It Dv IFF_SIMPLEX 469.Aq S* 470The interface cannot hear its own transmissions. 471.It Dv IFF_LINK0 472.It Dv IFF_LINK1 473.It Dv IFF_LINK2 474.Aq D 475Control flags for the link layer. 476(Currently abused to select among 477multiple physical layers on some devices.) 478.It Dv IFF_MULTICAST 479.Aq S* 480This interface supports multicast. 481.It Dv IFF_POLLING 482.Aq D* 483The interface is in 484.Xr polling 4 485mode. 486See 487.Sx Interface Capabilities Flags 488for details. 489.El 490.Ss "Interface Capabilities Flags" 491Interface capabilities are specialized features an interface may 492or may not support. 493These capabilities are very hardware-specific 494and allow, when enabled, 495to offload specific network processing to the interface 496or to offer a particular feature for use by other kernel parts. 497.Pp 498It should be stressed that a capability can be completely 499uncontrolled (i.e., stay always enabled with no way to disable it) 500or allow limited control over itself (e.g., depend on another 501capability's state.) 502Such peculiarities are determined solely by the hardware and driver 503of a particular interface. 504Only the driver possesses 505the knowledge on whether and how the interface capabilities 506can be controlled. 507Consequently, capabilities flags in 508.Va if_capenable 509should never be modified directly by kernel code other than 510the interface driver. 511The command 512.Dv SIOCSIFCAP 513to 514.Fn ifioctl 515is the dedicated means to attempt altering 516.Va if_capenable 517on an interface. 518Userland code shall use 519.Xr ioctl 2 . 520.Pp 521The following capabilities are currently supported by the system: 522.Bl -tag -width ".Dv IFCAP_VLAN_HWTAGGING" -offset indent 523.It Dv IFCAP_NETCONS 524This interface can be a network console. 525.It Dv IFCAP_POLLING 526This interface supports 527.Xr polling 4 . 528See below for details. 529.It Dv IFCAP_RXCSUM 530This interface can do checksum validation on receiving data. 531Some interfaces do not have sufficient buffer storage to store frames 532above a certain MTU-size completely. 533The driver for the interface might disable hardware checksum validation 534if the MTU is set above the hardcoded limit. 535.It Dv IFCAP_TXCSUM 536This interface can do checksum calculation on transmitting data. 537.It Dv IFCAP_HWCSUM 538A shorthand for 539.Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM . 540.It Dv IFCAP_VLAN_HWTAGGING 541This interface can do VLAN tagging on output and 542demultiplex frames by their VLAN tag on input. 543.It Dv IFCAP_VLAN_MTU 544The 545.Xr vlan 4 546driver can operate over this interface in software tagging mode 547without having to decrease MTU on 548.Xr vlan 4 549interfaces below 1500 bytes. 550This implies the ability of this interface to cope with frames somewhat 551longer than permitted by the Ethernet specification. 552.It Dv IFCAP_JUMBO_MTU 553This Ethernet interface can transmit and receive frames up to 5549000 bytes long. 555.El 556.Pp 557The ability of advanced network interfaces to offload certain 558computational tasks from the host CPU to the board is limited 559mostly to TCP/IP. 560Therefore a separate field associated with an interface 561(see 562.Va ifnet.if_data.ifi_hwassist 563below) 564keeps a detailed description of its enabled capabilities 565specific to TCP/IP processing. 566The TCP/IP module consults the field to see which tasks 567can be done on an 568.Em outgoing 569packet by the interface. 570The flags defined for that field are a superset of those for 571.Va mbuf.m_pkthdr.csum_flags , 572namely: 573.Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent 574.It Dv CSUM_IP 575The interface will compute IP checksums. 576.It Dv CSUM_TCP 577The interface will compute TCP checksums. 578.It Dv CSUM_UDP 579The interface will compute UDP checksums. 580.It Dv CSUM_IP_FRAGS 581The interface can compute a TCP or UDP checksum for a packet 582fragmented by the host CPU. 583Makes sense only along with 584.Dv CSUM_TCP 585or 586.Dv CSUM_UDP . 587.It Dv CSUM_FRAGMENT 588The interface will do the fragmentation of IP packets if necessary. 589The host CPU does not need to care about MTU on this interface 590as long as a packet to transmit through it is an IP one and it 591does not exceed the size of the hardware buffer. 592.El 593.Pp 594An interface notifies the TCP/IP module about the tasks 595the former has performed on an 596.Em incoming 597packet by setting the corresponding flags in the field 598.Va mbuf.m_pkthdr.csum_flags 599of the 600.Vt mbuf chain 601containing the packet. 602See 603.Xr mbuf 9 604for details. 605.Pp 606The capability of a network interface to operate in 607.Xr polling 4 608mode involves several flags in different 609global variables and per-interface fields. 610First, there is a system-wide 611.Xr sysctl 8 612master switch named 613.Va kern.polling.enable , 614which can toggle 615.Xr polling 4 616globally. 617If that variable is set to non-zero, 618.Xr polling 4 619will be used on those devices where it is enabled individually. 620Otherwise, 621.Xr polling 4 622will not be used in the system. 623Second, the capability flag 624.Dv IFCAP_POLLING 625set in interface's 626.Va if_capabilities 627indicates support for 628.Xr polling 4 629on the particular interface. 630If set in 631.Va if_capabilities , 632the same flag can be marked or cleared in the interface's 633.Va if_capenable , 634thus initiating switch of the interface to 635.Xr polling 4 636mode or interrupt 637mode, respectively. 638The actual mode change will occur at an implementation-specific moment 639in the future, e.g., during the next interrupt or 640.Xr polling 4 641cycle. 642And finally, if the mode transition has been successful, the flag 643.Dv IFF_POLLING 644is marked or cleared in the interface's 645.Va if_flags 646to indicate the current mode of the interface. 647.Ss The Vt if_data Ss Structure 648In 649.Bx 4.4 , 650a subset of the interface information believed to be of interest to 651management stations was segregated from the 652.Vt ifnet 653structure and moved into its own 654.Vt if_data 655structure to facilitate its use by user programs. 656The following elements of the 657.Vt if_data 658structure are initialized by the interface and are not expected to change 659significantly over the course of normal operation: 660.Bl -tag -width ".Va ifi_lastchange" -offset indent 661.It Va ifi_type 662.Pq Vt u_char 663The type of the interface, as defined in 664.In net/if_types.h 665and described below in the 666.Sx "Interface Types" 667section. 668.It Va ifi_physical 669.Pq Vt u_char 670Intended to represent a selection of physical layers on devices which 671support more than one; never implemented. 672.It Va ifi_addrlen 673.Pq Vt u_char 674Length of a link-layer address on this device, or zero if there are 675none. 676Used to initialized the address length field in 677.Vt sockaddr_dl 678structures referring to this interface. 679.It Va ifi_hdrlen 680.Pq Vt u_char 681Maximum length of any link-layer header which might be prepended by 682the driver to a packet before transmission. 683The generic code computes 684the maximum over all interfaces and uses that value to influence the 685placement of data in 686.Vt mbuf Ns s 687to attempt to ensure that there is always 688sufficient space to prepend a link-layer header without allocating an 689additional 690.Vt mbuf . 691.\" (See 692.\" .Xr mbuf 9 . ) 693.\" .It Va ifi_recvquota 694.\" .Pq Vt u_char 695.\" Number of packets the interface is permitted to receive at one time 696.\" when in polled mode. 697.\" .It Va ifi_xmitquota 698.\" .Pq Vt u_char 699.\" Number of packets the interface is permitted to queue for transmission 700.\" at one time when in polled mode. 701.\" There is some controversy over 702.\" whether such a restriction makes any sense at all. 703.It Va ifi_mtu 704.Pq Vt u_long 705The maximum transmission unit of the medium, exclusive of any 706link-layer overhead. 707.It Va ifi_metric 708.Pq Vt u_long 709A dimensionless metric interpreted by a user-mode routing process. 710.It Va ifi_baudrate 711.Pq Vt u_long 712The line rate of the interface, in bits per second. 713.It Va ifi_hwassist 714.Pq Vt u_long 715A detailed interpretation of the capabilities 716to offload computational tasks for 717.Em outgoing 718packets. 719The interface driver must keep this field in accord with 720the current value of 721.Va if_capenable . 722.El 723.Pp 724The structure additionally contains generic statistics applicable to a 725variety of different interface types (except as noted, all members are 726of type 727.Vt u_long ) : 728.Bl -tag -width ".Va ifi_lastchange" -offset indent 729.It Va ifi_ipackets 730Number of packets received. 731.It Va ifi_ierrors 732Number of receive errors detected (e.g., FCS errors, DMA overruns, 733etc.). 734More detailed breakdowns can often be had by way of a 735link-specific MIB. 736.It Va ifi_opackets 737Number of packets transmitted. 738.It Va ifi_oerrors 739Number of output errors detected (e.g., late collisions, DMA overruns, 740etc.). 741More detailed breakdowns can often be had by way of a 742link-specific MIB. 743.It Va ifi_collisions 744Total number of collisions detected on output for CSMA interfaces. 745(This member is sometimes [ab]used by other types of interfaces for 746other output error counts.) 747.It Va ifi_ibytes 748Total traffic received, in bytes. 749.It Va ifi_obytes 750Total traffic transmitted, in bytes. 751.It Va ifi_imcasts 752Number of packets received which were sent by link-layer multicast. 753.It Va ifi_omcasts 754Number of packets sent by link-layer multicast. 755.It Va ifi_iqdrops 756Number of packets dropped on input. 757Rarely implemented. 758.It Va ifi_noproto 759Number of packets received for unknown network-layer protocol. 760.\" .It Va ifi_recvtiming 761.\" Amount of time, in microseconds, spent to receive an average packet on 762.\" this interface. 763.\" See the 764.\" .Sx Polling 765.\" section, below. 766.\" .It Va ifi_xmittiming 767.\" Amount of time, in microseconds, spent to service a transmit-complete 768.\" interrupt on this interface. 769.\" See the 770.\" .Sx Polling 771.\" section, below. 772.It Va ifi_lastchange 773.Pq Vt "struct timeval" 774The time of the last administrative change to the interface (as required 775for 776.Tn SNMP ) . 777.El 778.Ss Interface Types 779The header file 780.In net/if_types.h 781defines symbolic constants for a number of different types of 782interfaces. 783The most common are: 784.Pp 785.Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact 786.It Dv IFT_OTHER 787none of the following 788.It Dv IFT_ETHER 789Ethernet 790.It Dv IFT_ISO88023 791ISO 8802-3 CSMA/CD 792.It Dv IFT_ISO88024 793ISO 8802-4 Token Bus 794.It Dv IFT_ISO88025 795ISO 8802-5 Token Ring 796.It Dv IFT_ISO88026 797ISO 8802-6 DQDB MAN 798.It Dv IFT_FDDI 799FDDI 800.It Dv IFT_PPP 801Internet Point-to-Point Protocol 802.Pq Xr ppp 8 803.It Dv IFT_LOOP 804The loopback 805.Pq Xr lo 4 806interface 807.It Dv IFT_SLIP 808Serial Line IP 809.It Dv IFT_PARA 810Parallel-port IP 811.Pq Dq Tn PLIP 812.It Dv IFT_ATM 813Asynchronous Transfer Mode 814.El 815.Ss The Vt ifaddr Ss Structure 816Every interface is associated with a list 817(or, rather, a 818.Li TAILQ ) 819of addresses, rooted at the interface structure's 820.Va if_addrlist 821member. 822The first element in this list is always an 823.Dv AF_LINK 824address representing the interface itself; multi-access network 825drivers should complete this structure by filling in their link-layer 826addresses after calling 827.Fn if_attach . 828Other members of the structure represent network-layer addresses which 829have been configured by means of the 830.Dv SIOCAIFADDR 831command to 832.Xr ioctl 2 , 833called on a socket of the appropriate protocol family. 834The elements of this list consist of 835.Vt ifaddr 836structures. 837Most protocols will declare their own protocol-specific 838interface address structures, but all begin with a 839.Vt "struct ifaddr" 840which provides the most-commonly-needed functionality across all 841protocols. 842Interface addresses are reference-counted. 843.Pp 844The members of 845.Vt "struct ifaddr" 846are as follows: 847.Bl -tag -width ".Va ifa_rtrequest" -offset indent 848.It Va ifa_addr 849.Pq Vt "struct sockaddr *" 850The local address of the interface. 851.It Va ifa_dstaddr 852.Pq Vt "struct sockaddr *" 853The remote address of point-to-point interfaces, and the broadcast 854address of broadcast interfaces. 855.Va ( ifa_broadaddr 856is a macro for 857.Va ifa_dstaddr . ) 858.It Va ifa_netmask 859.Pq Vt "struct sockaddr *" 860The network mask for multi-access interfaces, and the confusion 861generator for point-to-point interfaces. 862.It Va ifa_ifp 863.Pq Vt "struct ifnet *" 864A link back to the interface structure. 865.It Va ifa_link 866.Pq Fn TAILQ_ENTRY ifaddr 867.Xr queue 3 868glue for list of addresses on each interface. 869.It Va ifa_rtrequest 870See below. 871.It Va ifa_flags 872.Pq Vt u_short 873Some of the flags which would be used for a route representing this 874address in the route table. 875.It Va ifa_refcnt 876.Pq Vt short 877The reference count. 878.It Va ifa_metric 879.Pq Vt int 880A metric associated with this interface address, for the use of some 881external routing protocol. 882.El 883.Pp 884References to 885.Vt ifaddr 886structures are gained manually, by incrementing the 887.Va ifa_refcnt 888member. 889References are released by calling either the 890.Fn ifafree 891function or the 892.Fn IFAFREE 893macro. 894.Pp 895.Fn ifa_rtrequest 896is a pointer to a function which receives callouts from the routing 897code 898.Pq Fn rtrequest 899to perform link-layer-specific actions upon requests to add, resolve, 900or delete routes. 901The 902.Fa cmd 903argument indicates the request in question: 904.Dv RTM_ADD , RTM_RESOLVE , 905or 906.Dv RTM_DELETE . 907The 908.Fa rt 909argument is the route in question; the 910.Fa dst 911argument is the specific destination being manipulated 912for 913.Dv RTM_RESOLVE , 914or a null pointer otherwise. 915.Sh FUNCTIONS 916The functions provided by the generic interface code can be divided 917into two groups: those which manipulate interfaces, and those which 918manipulate interface addresses. 919In addition to these functions, there 920may also be link-layer support routines which are used by a number of 921drivers implementing a specific link layer over different hardware; 922see the documentation for that link layer for more details. 923.Ss The Vt ifmultiaddr Ss Structure 924Every multicast-capable interface is associated with a list of 925multicast group memberships, which indicate at a low level which 926link-layer multicast addresses (if any) should be accepted, and at a 927high level, in which network-layer multicast groups a user process has 928expressed interest. 929.Pp 930The elements of the structure are as follows: 931.Bl -tag -width ".Va ifma_refcount" -offset indent 932.It Va ifma_link 933.Pq Fn LIST_ENTRY ifmultiaddr 934.Xr queue 3 935macro glue. 936.It Va ifma_addr 937.Pq Vt "struct sockaddr *" 938A pointer to the address which this record represents. 939The 940memberships for various address families are stored in arbitrary 941order. 942.It Va ifma_lladdr 943.Pq Vt "struct sockaddr *" 944A pointer to the link-layer multicast address, if any, to which the 945network-layer multicast address in 946.Va ifma_addr 947is mapped, else a null pointer. 948If this element is non-nil, this 949membership also holds an invisible reference to another membership for 950that link-layer address. 951.It Va ifma_refcount 952.Pq Vt u_int 953A reference count of requests for this particular membership. 954.El 955.Ss Interface Manipulation Functions 956.Bl -ohang -offset indent 957.It Fn if_attach 958Link the specified interface 959.Fa ifp 960into the list of network interfaces. 961Also initialize the list of 962addresses on that interface, and create a link-layer 963.Vt ifaddr 964structure to be the first element in that list. 965(A pointer to 966this address structure is saved in the global array 967.Va ifnet_addrs . ) 968.It Fn if_down 969Mark the interface 970.Fa ifp 971as down (i.e., 972.Dv IFF_UP 973is not set), 974flush its output queue, notify protocols of the transition, 975and generate a message from the 976.Xr route 4 977routing socket. 978.It Fn if_up 979Mark the interface 980.Fa ifp 981as up, notify protocols of the transition, 982and generate a message from the 983.Xr route 4 984routing socket. 985.It Fn ifpromisc 986Add or remove a promiscuous reference to 987.Fa ifp . 988If 989.Fa pswitch 990is true, add a reference; 991if it is false, remove a reference. 992On reference count transitions 993from zero to one and one to zero, set the 994.Dv IFF_PROMISC 995flag appropriately and call 996.Fn if_ioctl 997to set up the interface in the desired mode. 998.It Fn if_allmulti 999As 1000.Fn ifpromisc , 1001but for the all-multicasts 1002.Pq Dv IFF_ALLMULTI 1003flag instead of the promiscuous flag. 1004.It Fn ifunit 1005Return an 1006.Vt ifnet 1007pointer for the interface named 1008.Fa name . 1009.It Fn ifioctl 1010Process the ioctl request 1011.Fa cmd , 1012issued on socket 1013.Fa so 1014by thread 1015.Fa td , 1016with data parameter 1017.Fa data . 1018This is the main routine for handling all interface configuration 1019requests from user mode. 1020It is ordinarily only called from the socket-layer 1021.Xr ioctl 2 1022handler, and only for commands with class 1023.Sq Li i . 1024Any unrecognized commands will be passed down to socket 1025.Fa so Ns 's 1026protocol for 1027further interpretation. 1028The following commands are handled by 1029.Fn ifioctl : 1030.Pp 1031.Bl -tag -width ".Dv OSIOCGIFNETMASK" -offset indent -compact 1032.It Dv SIOCGIFCONF 1033.It Dv OSIOCGIFCONF 1034Get interface configuration. 1035(No call-down to driver.) 1036.Pp 1037.It Dv SIOCSIFNAME 1038Set the interface name. 1039.Dv RTM_IFANNOUNCE 1040departure and arrival messages are sent so that 1041routing code that relies on the interface name will update its interface 1042list. 1043Caller must have appropriate privilege. 1044(No call-down to driver.) 1045.It Dv SIOCGIFCAP 1046.It Dv SIOCGIFFLAGS 1047.It Dv SIOCGIFMETRIC 1048.It Dv SIOCGIFMTU 1049.It Dv SIOCGIFPHYS 1050Get interface capabilities, flags, metric, MTU, medium selection. 1051(No call-down to driver.) 1052.Pp 1053.It Dv SIOCSIFCAP 1054Enable or disable interface capabilities. 1055Caller must have appropriate privilege. 1056Before a call to the driver-specific 1057.Fn if_ioctl 1058routine, the requested mask for enabled capabilities is checked 1059against the mask of capabilities supported by the interface, 1060.Va if_capabilities . 1061Requesting to enable an unsupported capability is invalid. 1062The rest is supposed to be done by the driver, 1063which includes updating 1064.Va if_capenable 1065and 1066.Va if_data.ifi_hwassist 1067appropriately. 1068.Pp 1069.It Dv SIOCSIFFLAGS 1070Change interface flags. 1071Caller must have appropriate privilege. 1072If a change to the 1073.Dv IFF_UP 1074flag is requested, 1075.Fn if_up 1076or 1077.Fn if_down 1078is called as appropriate. 1079Flags listed in 1080.Dv IFF_CANTCHANGE 1081are masked off, and the field 1082.Va if_flags 1083in the interface structure is updated. 1084Finally, the driver 1085.Fn if_ioctl 1086routine is called to perform any setup 1087requested. 1088.Pp 1089.It Dv SIOCSIFMETRIC 1090.It Dv SIOCSIFPHYS 1091Change interface metric or medium. 1092Caller must have appropriate privilege. 1093.Pp 1094.It Dv SIOCSIFMTU 1095Change interface MTU. 1096Caller must have appropriate privilege. 1097MTU 1098values less than 72 or greater than 65535 are considered invalid. 1099The driver 1100.Fn if_ioctl 1101routine is called to implement the change; it is responsible for any 1102additional sanity checking and for actually modifying the MTU in the 1103interface structure. 1104.Pp 1105.It Dv SIOCADDMULTI 1106.It Dv SIOCDELMULTI 1107Add or delete permanent multicast group memberships on the interface. 1108Caller must have appropriate privilege. 1109The 1110.Fn if_addmulti 1111or 1112.Fn if_delmulti 1113function is called to perform the operation; qq.v. 1114.Pp 1115.It Dv SIOCSIFDSTADDR 1116.It Dv SIOCSIFADDR 1117.It Dv SIOCSIFBRDADDR 1118.It Dv SIOCSIFNETMASK 1119The socket's protocol control routine is called to implement the 1120requested action. 1121.Pp 1122.It Dv OSIOGIFADDR 1123.It Dv OSIOCGIFDSTADDR 1124.It Dv OSIOCGIFBRDADDR 1125.It Dv OSIOCGIFNETMASK 1126The socket's protocol control routine is called to implement the 1127requested action. 1128On return, 1129.Vt sockaddr 1130structures are converted into old-style (no 1131.Va sa_len 1132member). 1133.El 1134.El 1135.Pp 1136.Fn if_down , 1137.Fn ifioctl , 1138.Fn ifpromisc , 1139and 1140.Fn if_up 1141must be called at 1142.Fn splnet 1143or higher. 1144.Ss "Interface Address Functions" 1145Several functions exist to look up an interface address structure 1146given an address. 1147.Fn ifa_ifwithaddr 1148returns an interface address with either a local address or a 1149broadcast address precisely matching the parameter 1150.Fa addr . 1151.Fn ifa_ifwithdstaddr 1152returns an interface address for a point-to-point interface whose 1153remote 1154.Pq Dq destination 1155address is 1156.Fa addr . 1157.Pp 1158.Fn ifa_ifwithnet 1159returns the most specific interface address which matches the 1160specified address, 1161.Fa addr , 1162subject to its configured netmask, or a point-to-point interface 1163address whose remote address is 1164.Fa addr 1165if one is found. 1166.Pp 1167.Fn ifaof_ifpforaddr 1168returns the most specific address configured on interface 1169.Fa ifp 1170which matches address 1171.Fa addr , 1172subject to its configured netmask. 1173If the interface is 1174point-to-point, only an interface address whose remote address is 1175precisely 1176.Fa addr 1177will be returned. 1178.Pp 1179All of these functions return a null pointer if no such address can be 1180found. 1181.Ss "Interface Multicast Address Functions" 1182The 1183.Fn if_addmulti , 1184.Fn if_delmulti , 1185and 1186.Fn ifmaof_ifpforaddr 1187functions provide support for requesting and relinquishing multicast 1188group memberships, and for querying an interface's membership list, 1189respectively. 1190The 1191.Fn if_addmulti 1192function takes a pointer to an interface, 1193.Fa ifp , 1194and a generic address, 1195.Fa sa . 1196It also takes a pointer to a 1197.Vt "struct ifmultiaddr *" 1198which is filled in on successful return with the address of the 1199group membership control block. 1200The 1201.Fn if_addmulti 1202function performs the following four-step process: 1203.Bl -enum -offset indent 1204.It 1205Call the interface's 1206.Fn if_resolvemulti 1207entry point to determine the link-layer address, if any, corresponding 1208to this membership request, and also to give the link layer an 1209opportunity to veto this membership request should it so desire. 1210.It 1211Check the interface's group membership list for a pre-existing 1212membership for this group. 1213If one is not found, allocate a new one; 1214if one is, increment its reference count. 1215.It 1216If the 1217.Fn if_resolvemulti 1218routine returned a link-layer address corresponding to the group, 1219repeat the previous step for that address as well. 1220.It 1221If the interface's multicast address filter needs to be changed 1222because a new membership was added, call the interface's 1223.Fn if_ioctl 1224routine 1225(with a 1226.Fa cmd 1227argument of 1228.Dv SIOCADDMULTI ) 1229to request that it do so. 1230.El 1231.Pp 1232The 1233.Fn if_delmulti 1234function, given an interface 1235.Fa ifp 1236and an address, 1237.Fa sa , 1238reverses this process. 1239Both functions return zero on success, or a 1240standard error number on failure. 1241.Pp 1242The 1243.Fn ifmaof_ifpforaddr 1244function examines the membership list of interface 1245.Fa ifp 1246for an address matching 1247.Fa addr , 1248and returns a pointer to that 1249.Vt "struct ifmultiaddr" 1250if one is found, else it returns a null pointer. 1251.Sh SEE ALSO 1252.Xr ioctl 2 , 1253.Xr link_addr 3 , 1254.Xr queue 3 , 1255.Xr sysctl 3 , 1256.Xr bpf 4 , 1257.Xr ifmib 4 , 1258.Xr lo 4 , 1259.Xr netintro 4 , 1260.Xr polling 4 , 1261.Xr config 8 , 1262.Xr ppp 8 , 1263.Xr mbuf 9 , 1264.Xr rtentry 9 1265.Rs 1266.%A Gary R. Wright 1267.%A W. Richard Stevens 1268.%B TCP/IP Illustrated 1269.%V Vol. 2 1270.%O Addison-Wesley, ISBN 0-201-63354-X 1271.Re 1272.Sh AUTHORS 1273This manual page was written by 1274.An Garrett A. Wollman . 1275