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