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