xref: /freebsd/share/man/man9/ifnet.9 (revision 6990ffd8a95caaba6858ad44ff1b3157d1efba8f)
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.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" "u_long 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 \*(lp*if_output\*(rp "struct ifnet *ifp" "struct mbuf *m" "struct sockaddr *dst" "struct rtentry *rt"
93.Ft void
94.Fn \*(lp*if_start\*(rp "struct ifnet *ifp"
95.Ft int
96.Fn \*(lp*if_dont\*(rp "struct ifnet *ifp"
97.Ft int
98.Fn \*(lp*if_ioctl\*(rp "struct ifnet *ifp" "int cmd" "caddr_t data"
99.Ft void
100.Fn \*(lp*if_watchdog\*(rp "struct ifnet *ifp"
101.Ft int
102.Fn \*(lp*if_poll_recv\*(rp "struct ifnet *ifp" "int *quotap"
103.Ft int
104.Fn \*(lp*if_poll_xmit\*(rp "struct ifnet *ifp" "int *quotap"
105.Ft void
106.Fn \*(lp*if_poll_inttrn\*(rp "struct ifnet *ifp"
107.Ft void
108.Fn \*(lp*if_poll_slowinput\*(rp "struct ifnet *ifp" "struct mbuf *m"
109.Ft void
110.Fn \*(lp*if_init\*(rp "void *if_softc"
111.Ft int
112.Fn \*(lp*if_resolvemulti\*(rp "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr"
113.Ss "struct ifaddr member function"
114.Ft void
115.Fn \*(lp*ifa_rtrequest\*(rp "int cmd" "struct rtentry *rt" "struct sockaddr *dst"
116.Ss "Global variables"
117.Vt extern struct ifnethead ifnet ;
118.Vt extern struct ifaddr \&**ifnet_addrs ;
119.Vt extern int if_index ;
120.Vt 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.
339The prototype is faked.
340.It Fn if_ioctl
341Process interface-related
342.Xr ioctl 2
343requests
344(defined in
345.Aq Pa sys/sockio.h ) .
346Preliminary processing is done by the generic routine
347.Fn ifioctl
348to check for appropriate privileges, locate the interface being
349manipulated, and perform certain generic operations like twiddling
350flags and flushing queues.  See the description of
351.Fn ifioctl
352below for more information.
353.It Fn if_watchdog
354Routine called by the generic code when the watchdog timer,
355.Li if_timer ,
356expires.  Usually this will reset the interface.
357.\" .It Fn if_poll_recv
358.\" .It Fn if_poll_xmit
359.\" .It Fn if_poll_slowinput
360.\" .It Fn if_poll_intren
361.\" See the
362.\" .Sx Polling
363.\" section, below.
364.It Fn if_init
365Initialize and bring up the hardware,
366e.g. reset the chip and the watchdog timer and enable the receiver unit.
367Should mark the interface running,
368but not active
369.Dv ( IFF_RUNNING , ~IIF_OACTIVE ) .
370.It Fn if_resolvemulti
371Check the requested multicast group membership,
372.Ar addr ,
373for validity, and if necessary compute a link-layer group which
374corresponds to that address which is returned in
375.Ar \&*retsa .
376Returns zero on success, or an error code on failure.
377.El
378.Ss "Interface flags"
379Interface flags are used for a number of different purposes.  Some
380flags simply indicate information about the type of interface and its
381capabilities; others are dynamically manipulated to reflect the
382current state of the interface.  Flags of the former kind are marked
383.Aq S
384in this table; the latter are marked
385.Aq D .
386.Pp
387.Bl -tag -width "IFF_POINTOPOINT" -compact -offset indent
388.It Dv IFF_UP
389.Aq D
390The interface has been configured up by the user-level code.
391.It Dv IFF_BROADCAST
392.Aq S*
393The interface supports broadcast.
394.It Dv IFF_DEBUG
395.Aq D
396Used to enable/disable driver debugging code.
397.It Dv IFF_LOOPBACK
398.Aq S
399The interface is a loopback device.
400.It Dv IFF_POINTOPOINT
401.Aq S*
402The interface is point-to-point;
403.Dq broadcast
404addresses are actually the address of the other end.
405.It Dv IFF_RUNNING
406.Aq D*
407The interface has been configured and dynamic resources were
408successfully allocated.  Probably only useful internal to the
409interface.
410.It Dv IFF_NOARP
411.Aq D
412Disable network address resolution on this interface.
413.It Dv IFF_PROMISC
414.Aq D
415This interface is in promiscuous mode.
416.It Dv IFF_ALLMULTI
417.Aq D*
418This interface is in all-multicasts mode (used by multicast routers).
419.It Dv IFF_OACTIVE
420.Aq D*
421The interface's hardware output queue (if any) is full; output packets
422are to be queued.
423.It Dv IFF_SIMPLEX
424.Aq S*
425The interface cannot hear its own transmissions.
426.It Dv IFF_LINK0
427.It Dv IFF_LINK1
428.It Dv IFF_LINK2
429.Aq D
430Control flags for the link layer.  (Currently abused to select among
431multiple physical layers on some devices.)
432.It Dv IFF_MULTICAST
433.Aq S*
434This interface supports multicast.
435.El
436.Pp
437The macro
438.Dv IFF_CANTCHANGE
439defines the bits which cannot be set by a user program using the
440.Dv SIOCSIFFLAGS
441command to
442.Xr ioctl 2 ;
443these are indicated by an asterisk in the listing above.
444.Ss The if_data structure
445In
446.Bx 4.4 ,
447a subset of the interface information believed to be of interest to
448management stations was segregated from the
449.Li ifnet
450structure and moved into its own
451.Li if_data
452structure to facilitate its use by user programs.  The following
453elements of the
454.Li if_data
455structure are initialized by the interface and are not expected to change
456significantly over the course of normal operation:
457.Bl -tag -width "ifi_lastchange" -offset indent
458.It Li ifi_type
459.Pq Li u_char
460The type of the interface, as defined in
461.Aq Pa net/if_types.h
462and described below in the
463.Dq Sx "Interface types"
464section.
465.It Li ifi_physical
466.Pq Li u_char
467Intended to represent a selection of physical layers on devices which
468support more than one; never implemented.
469.It Li ifi_addrlen
470.Pq Li u_char
471Length of a link-layer address on this device, or zero if there are
472none.  Used to initialized the address length field in
473.Li "sockaddr_dl"
474structures referring to this interface.
475.It Li ifi_hdrlen
476.Pq Li u_char
477Maximum length of any link-layer header which might be prepended by
478the driver to a packet before transmission.  The generic code computes
479the maximum over all interfaces and uses that value to influence the
480placement of data in
481.Li mbuf Ns s
482to attempt to ensure that there is always
483sufficient space to prepend a link-layer header without allocating an
484additional
485.Li mbuf .
486.\" (See
487.\" .Xr mbuf 9 . )
488.\" .It Li ifi_recvquota
489.\" .Pq Li u_char
490.\" Number of packets the interface is permitted to receive at one time
491.\" when in polled mode.
492.\" .It Li ifi_xmitquota
493.\" .Pq Li u_char
494.\" Number of packets the interface is permitted to queue for transmission
495.\" at one time when in polled mode.  There is some controversy over
496.\" whether such a restriction makes any sense at all.
497.It Li ifi_mtu
498.Pq Li u_long
499The maximum transmission unit of the medium, exclusive of any
500link-layer overhead.
501.It Li ifi_metric
502.Pq Li u_long
503A dimensionless metric interpreted by a user-mode routing process.
504.It Li ifi_baudrate
505.Pq Li u_long
506The line rate of the interface, in bits per second.
507.El
508.Pp
509The structure additionally contains generic statistics applicable to a
510variety of different interface types (except as noted, all members are
511of type
512.Li u_long ) :
513.Bl -tag -width "ifi_lastchange" -offset indent
514.It Li ifi_ipackets
515Number of packets received.
516.It Li ifi_ierrors
517Number of receive errors detected (e.g., FCS errors, DMA overruns,
518etc.).  More detailed breakdowns can often be had by way of a
519link-specific MIB.
520.It Li ifi_opackets
521Number of packets transmitted.
522.It Li ifi_oerrors
523Number of output errors detected (e.g., late collisions, DMA overruns,
524etc.).  More detailed breakdowns can often be had by way of a
525link-specific MIB.
526.It Li ifi_collisions
527Total number of collisions detected on output for CSMA interfaces.
528(This member is sometimes [ab]used by other types of interfaces for
529other output error counts.)
530.It Li ifi_ibytes
531Total traffic received, in bytes.
532.It Li ifi_obytes
533Total traffic transmitted, in bytes.
534.It Li ifi_imcasts
535Number of packets received which were sent by link-layer multicast.
536.It Li ifi_omcasts
537Number of packets sent by link-layer multicast.
538.It Li ifi_iqdrops
539Number of packets dropped on input.  Rarely implemented.
540.It Li ifi_noproto
541Number of packets received for unknown network-layer protocol.
542.\" .It Li ifi_recvtiming
543.\" Amount of time, in microseconds, spent to receive an average packet on
544.\" this interface.  See the
545.\" .Sx Polling
546.\" section, below.
547.\" .It Li ifi_xmittiming
548.\" Amount of time, in microseconds, spent to service a transmit-complete
549.\" interrupt on this interface.  See the
550.\" .Sx Polling
551.\" section, below.
552.It Li ifi_lastchange
553.Pq Li "struct timeval"
554The time of the last administrative change to the interface (as required
555for
556.Tn SNMP ) .
557.El
558.Ss Interface types
559The header file
560.Aq Pa net/if_types.h
561defines symbolic constants for a number of different types of
562interfaces.  The most common are:
563.Pp
564.Bl -tag -compact -offset indent -width IFT_PROPVIRTUAL
565.It Dv IFT_OTHER
566none of the following
567.It Dv IFT_ETHER
568Ethernet
569.It Dv IFT_ISO88023
570ISO 8802-3 CSMA/CD
571.It Dv IFT_ISO88024
572ISO 8802-4 Token Bus
573.It Dv IFT_ISO88025
574ISO 8802-5 Token Ring
575.It Dv IFT_ISO88026
576ISO 8802-6 DQDB MAN
577.It Dv IFT_FDDI
578FDDI
579.It Dv IFT_PPP
580Internet Point-to-Point Protocol
581.Pq Xr ppp 8
582.It Dv IFT_LOOP
583The loopback
584.Pq Xr lo 4
585interface.
586.It Dv IFT_SLIP
587Serial Line IP
588.It Dv IFT_PARA
589Parallel-port IP
590.Pq Dq Tn PLIP
591.It Dv IFT_ATM
592Asynchronous Transfer Mode
593.El
594.Ss The ifaddr structure
595Every interface is associated with a list
596(or, rather, a
597.Dv TAILQ )
598of addresses, rooted at the interface structure's
599.Li if_addrlist
600member.  The first element in this list is always an
601.Dv AF_LINK
602address representing the interface itself; multi-access network
603drivers should complete this structure by filling in their link-layer
604addresses after calling
605.Fn if_attach .
606Other members of the structure represent network-layer addresses which
607have been configured by means of the
608.Dv SIOCAIFADDR
609command to
610.Xr ioctl 2 ,
611called on a socket of the appropriate protocol family.
612The elements of this list consist of
613.Li ifaddr
614structures.  Most protocols will declare their own protocol-specific
615interface address structures, but all begin with a
616.Li "struct ifaddr"
617which provides the most-commonly-needed functionality across all
618protocols.  Interface addresses are reference-counted.
619.Pp
620The members of
621.Li "struct ifaddr"
622are as follows:
623.Bl -tag -width ifa_rtrequest -offset indent
624.It Li ifa_addr
625.Pq Li "struct sockaddr *"
626The local address of the interface.
627.It Li ifa_dstaddr
628.Pq Li "struct sockaddr *"
629The remote address of point-to-point interfaces, and the broadcast
630address of broadcast interfaces.
631.Li ( ifa_broadaddr
632is a macro for
633.Li ifa_dstaddr . )
634.It Li ifa_netmask
635.Pq Li "struct sockaddr *"
636The network mask for multi-access interfaces, and the confusion
637generator for point-to-point interfaces.
638.It Li ifa_ifp
639.Pq Li "struct ifnet *"
640A link back to the interface structure.
641.It Li ifa_link
642.Pq Li TAILQ_ENTRY(ifaddr)
643.Xr queue 3
644glue for list of addresses on each interface.
645.It Li ifa_rtrequest
646See below.
647.It Li ifa_flags
648.Pq Li u_short
649Some of the flags which would be used for a route representing this
650address in the route table.
651.It Li ifa_refcnt
652.Pq Li short
653The reference count.
654.It Li ifa_metric
655.Pq Li int
656A metric associated with this interface address, for the use of some
657external routing protocol.
658.El
659.Pp
660References to
661.Li ifaddr
662structures are gained manually, by incrementing the
663.Li ifa_refcnt
664member.  References are released by calling either the
665.Fn ifafree
666function or the
667.Fn IFAFREE
668macro.
669.Pp
670.Fn ifa_rtrequest
671is a pointer to a function which receives callouts from the routing
672code
673.Pq Fn rtrequest
674to perform link-layer-specific actions upon requests to add, resolve,
675or delete routes.  The
676.Ar cmd
677argument indicates the request in question:
678.Dv RTM_ADD ,
679.Dv RTM_RESOLVE ,
680or
681.Dv RTM_DELETE .
682The
683.Ar rt
684argument is the route in question; the
685.Ar sa
686argument is the specific destination being manipulated
687for
688.Dv RTM_RESOLVE ,
689or a null pointer otherwise.
690.Sh FUNCTIONS
691The functions provided by the generic interface code can be divided
692into two groups: those which manipulate interfaces, and those which
693manipulate interface addresses.  In addition to these functions, there
694may also be link-layer support routines which are used by a number of
695drivers implementing a specific link layer over different hardware;
696see the documentation for that link layer for more details.
697.Ss The ifmultiaddr structure
698Every multicast-capable interface is associated with a list of
699multicast group memberships, which indicate at a low level which
700link-layer multicast addresses (if any) should be accepted, and at a
701high level, in which network-layer multicast groups a user process has
702expressed interest.
703.Pp
704The elements of the structure are as follows:
705.Bl -tag -width ifma_refcount -offset indent
706.It Li ifma_link
707.Pq Li LIST_ENTRY(ifmultiaddr)
708.Xr queue 3
709macro glue.
710.It Li ifma_addr
711.Pq Li "struct sockaddr *"
712A pointer to the address which this record represents.  The
713memberships for various address families are stored in arbitrary
714order.
715.It Li ifma_lladdr
716.Pq Li "struct sockaddr *"
717A pointer to the link-layer multicast address, if any, to which the
718network-layer multicast address in
719.Li ifma_addr
720is mapped, else a null pointer.  If this element is non-nil, this
721membership also holds an invisible reference to another membership for
722that link-layer address.
723.It Li ifma_refcount
724.Pq Li u_int
725A reference count of requests for this particular membership.
726.El
727.Ss Interface manipulation functions
728.Bl -ohang -offset indent
729.It Fn if_attach
730Link the specified interface
731.Ar ifp
732into the list of network interfaces.  Also initialize the list of
733addresses on that interface, and create a link-layer
734.Li ifaddr
735structure to be the first element in that list.  (A pointer to
736this address structure is saved in the global array
737.Li ifnet_addrs . )
738.It Fn if_down
739Mark the interface
740.Ar ifp
741as down (i.e.,
742.Dv IFF_UP
743is not set),
744flush its output queue, notify protocols of the transition,
745and generate a message from the
746.Xr route 4
747routing socket.
748.It Fn if_up
749Mark the interface
750.Ar ifp
751as up, notify protocols of the transition,
752and generate a message from the
753.Xr route 4
754routing socket.
755.It Fn ifpromisc
756Add or remove a promiscuous reference to
757.Ar ifp .
758If
759.Ar pswitch
760is true, add a reference;
761if it is false, remove a reference.  On reference count transitions
762from zero to one and one to zero, set the
763.Dv IFF_PROMISC
764flag appropriately and call
765.Fn if_ioctl
766to set up the interface in the desired mode.
767.It Fn if_allmulti
768As
769.Fn ifpromisc ,
770but for the all-multicasts
771.Pq Dv IFF_ALLMULTI
772flag instead of the promiscuous flag.
773.It Fn ifunit
774Return an
775.Li ifnet
776pointer for the interface named
777.Ar name .
778.It Fn ifioctl
779Process the ioctl request
780.Ar cmd ,
781issued on socket
782.Ar so
783by process
784.Ar p ,
785with data parameter
786.Ar data .
787This is the main routine for handling all interface configuration
788requests from user mode.
789It is ordinarily only called from the socket-layer
790.Xr ioctl 2
791handler, and only for commands with class
792.Sq Li i .
793Any unrecognized commands will be passed down to socket
794.Ar so Ns 's
795protocol for
796further interpretation.  The following commands are handled by
797.Fn ifioctl :
798.Pp
799.Bl -tag -width OSIOCGIFNETMASK -compact -offset indent
800.It Dv SIOCGIFCONF
801.It Dv OSIOCGIFCONF
802Get interface configuration.  (No call-down to driver.)
803.It Dv SIOCGIFFLAGS
804.It Dv SIOCGIFMETRIC
805.It Dv SIOCGIFMTU
806.It Dv SIOCGIFPHYS
807Get interface flags, metric, MTU, medium selection.  (No call-down to
808driver.)
809.Pp
810.It Dv SIOCSIFFLAGS
811Change interface flags.  Caller must have appropriate privilege.  If
812requested a change to the IFF_UP flag is requested,
813.Fn if_up
814or
815.Fn if_down
816is called as appropriate.  Flags listed in
817.Dv IFF_CANTCHANGE
818are masked off, and the driver
819.Fn if_ioctl
820routine is called to perform any setup
821requested.
822.It Dv SIOCSIFMETRIC
823.It Dv SIOCSIFPHYS
824Change interface metric or medium.  Caller must have appropriate privilege.
825.Pp
826.It Dv SIOCSIFMTU
827Change interface MTU.  Caller must have appropriate privilege.  MTU
828values less than 72 or greater than 65535 are considered invalid.  The
829driver
830.Fn if_ioctl
831routine is called to implement the change; it is responsible for any
832additional sanity checking and for actually modifying the MTU in the
833interface structure.
834.It Dv SIOCADDMULTI
835.It Dv SIOCDELMULTI
836Add or delete permanent multicast group memberships on the interface.
837Caller must have appropriate privilege.  The
838.Fn if_addmulti
839or
840.Fn if_delmulti
841function is called to perform the operation; qq.v.
842.It Dv SIOCSIFDSTADDR
843.It Dv SIOCSIFADDR
844.It Dv SIOCSIFBRDADDR
845.It Dv SIOCSIFNETMASK
846The socket's protocol control routine is called to implement the
847requested action.
848.It Dv OSIOGIFADDR
849.It Dv OSIOCGIFDSTADDR
850.It Dv OSIOCGIFBRDADDR
851.It Dv OSIOCGIFNETMASK
852The socket's protocol control routine is called to implement the
853requested action.  On return,
854.Li sockaddr
855structures are converted into old-style (no
856.Li sa_len
857member).
858.El
859.El
860.Pp
861.Fn if_down ,
862.Fn ifioctl ,
863.Fn ifpromisc ,
864and
865.Fn if_up
866must be called at
867.Fn splnet
868or higher.
869.Ss "Interface address functions"
870Several functions exist to look up an interface address structure
871given an address.
872.Fn ifa_ifwithaddr
873returns an interface address with either a local address or a
874broadcast address precisely matching the parameter
875.Ar addr .
876.Fn ifa_ifwithdstaddr
877returns an interface address for a point-to-point interface whose
878remote (``destination'') address is
879.Ar addr .
880.Pp
881.Fn ifa_ifwithnet
882returns the most specific interface address which matches the
883specified address,
884.Ar addr ,
885subject to its configured netmask, or a point-to-point interface
886address whose remote address is
887.Ar addr
888if one is found.
889.Pp
890.Fn ifaof_ifpforaddr
891returns the most specific address configured on interface
892.Ar ifp
893which matches address
894.Ar addr ,
895subject to its configured netmask.  If the interface is
896point-to-point, only an interface address whose remote address is
897precisely
898.Ar addr
899will be returned.
900.Pp
901All of these functions return a null pointer if no such address can be
902found.
903.Ss "Interface multicast address functions"
904The
905.Fn if_addmulti ,
906.Fn if_delmulti ,
907and
908.Fn ifmaof_ifpforaddr
909functions provide support for requesting and relinquishing multicast
910group memberships, and for querying an interface's membership list,
911respectively.  The
912.Fn if_addmulti
913function takes a pointer to an interface,
914.Ar ifp ,
915and a generic address,
916.Ar sa .
917It also takes a pointer to a
918.Sq Li "struct ifmultiaddr *"
919which is filled in on successful return with the address of the
920group membership control block.  The
921.Fn if_addmulti
922function performs the following four-step process:
923.Bl -enum -offset indent
924.It
925Call the interface's
926.Fn if_resolvemulti
927entry point to determine the link-layer address, if any, corresponding
928to this membership request, and also to give the link layer an
929opportunity to veto this membership request should it so desire.
930.It
931Check the interface's group membership list for a pre-existing
932membership for this group.  If one is not found, allocate a new one;
933if one is, increment its reference count.
934.It
935If the
936.Fn if_resolvemulti
937routine returned a link-layer address corresponding to the group,
938repeat the previous step for that address as well.
939.It
940If the interface's multicast address filter needs to be changed
941because a new membership was added, call the interface's
942.Fn if_ioctl
943routine
944(with a
945.Ar cmd
946argument of
947.Dv SIOCADDMULTI )
948to request that it do so.
949.El
950.Pp
951The
952.Fn if_delmulti
953function, given an interface
954.Ar ifp
955and an address,
956.Ar sa ,
957reverses this process.  Both functions return zero on success, or a
958standard error number on failure.
959.Pp
960The
961.Fn ifmaof_ifpforaddr
962function examines the membership list of interface
963.Ar ifp
964for an address matching
965.Ar addr ,
966and returns a pointer to that
967.Li "struct ifmultiaddr"
968if one is found, else it returns a null pointer.
969.\" .Sh POLLING
970.\" XXX write me!
971.Sh SEE ALSO
972.Xr ioctl 2 ,
973.Xr link_addr 3 ,
974.Xr queue 3 ,
975.Xr sysctl 3 ,
976.Xr bpf 4 ,
977.Xr ifmib 4 ,
978.Xr lo 4 ,
979.Xr netintro 4 ,
980.Xr config 8 ,
981.Xr ppp 8 ,
982.Xr rtentry 9
983.\" .Xr mbuf 9 ,
984.Rs
985.%A Gary R. Wright
986.%A W. Richard Stevens
987.%B TCP/IP Illustrated
988.%V vol. 2
989.%O Addison-Wesley, ISBN 0-201-63354-X
990.Re
991.Sh AUTHORS
992This manual page was written by
993.An Garrett A. Wollman .
994