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