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