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