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