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