]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - share/man/man9/ifnet.9
MFC r315802:
[FreeBSD/stable/10.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 March 22, 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"
81 .Ft "struct ifaddr *"
82 .Fn ifa_ifwithnet "struct sockaddr *addr" "int ignore_ptp"
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 Vt ifnet Ss 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_SMART
587 .Aq S*
588 The interface manages its own routes, rather than using the generic
589 code in
590 .Fn if_up
591 and
592 .Fn if_down .
593 This is probably useful for serial lines.
594 .It Dv IFF_DRV_RUNNING
595 .Aq D*
596 The interface has been configured and dynamic resources were
597 successfully allocated.
598 Probably only useful internal to the
599 interface.
600 .It Dv IFF_NOARP
601 .Aq D
602 Disable network address resolution on this interface.
603 .It Dv IFF_PROMISC
604 .Aq D*
605 This interface is in promiscuous mode.
606 .It Dv IFF_PPROMISC
607 .Aq D
608 This interface is in the permanently promiscuous mode (implies
609 .Dv IFF_PROMISC ) .
610 .It Dv IFF_ALLMULTI
611 .Aq D*
612 This interface is in all-multicasts mode (used by multicast routers).
613 .It Dv IFF_DRV_OACTIVE
614 .Aq D*
615 The interface's hardware output queue (if any) is full; output packets
616 are to be queued.
617 .It Dv IFF_SIMPLEX
618 .Aq S*
619 The interface cannot hear its own transmissions.
620 .It Dv IFF_LINK0
621 .It Dv IFF_LINK1
622 .It Dv IFF_LINK2
623 .Aq D
624 Control flags for the link layer.
625 (Currently abused to select among
626 multiple physical layers on some devices.)
627 .It Dv IFF_MULTICAST
628 .Aq S*
629 This interface supports multicast.
630 .It Dv IFF_CANTCONFIG
631 .Aq S*
632 The interface is not configurable in a meaningful way.
633 Primarily useful for
634 .Dv IFT_USB
635 interfaces registered at the interface list.
636 .It Dv IFF_MONITOR
637 .Aq D
638 This interface blocks transmission of packets and discards incoming
639 packets after BPF processing.
640 Used to monitor network traffic but not interact
641 with the network in question.
642 .It Dv IFF_STATICARP
643 .Aq D
644 Used to enable/disable ARP requests on this interface.
645 .It Dv IFF_DYING
646 .Aq D*
647 Set when the
648 .Vt ifnet
649 structure of this interface is being released and still has
650 .Va if_refcount
651 references.
652 .It Dv IFF_RENAMING
653 .Aq D*
654 Set when this interface is being renamed.
655 .El
656 .Ss "Interface Capabilities Flags"
657 Interface capabilities are specialized features an interface may
658 or may not support.
659 These capabilities are very hardware-specific
660 and allow, when enabled,
661 to offload specific network processing to the interface
662 or to offer a particular feature for use by other kernel parts.
663 .Pp
664 It should be stressed that a capability can be completely
665 uncontrolled (i.e., stay always enabled with no way to disable it)
666 or allow limited control over itself (e.g., depend on another
667 capability's state.)
668 Such peculiarities are determined solely by the hardware and driver
669 of a particular interface.
670 Only the driver possesses
671 the knowledge on whether and how the interface capabilities
672 can be controlled.
673 Consequently, capabilities flags in
674 .Va if_capenable
675 should never be modified directly by kernel code other than
676 the interface driver.
677 The command
678 .Dv SIOCSIFCAP
679 to
680 .Fn ifioctl
681 is the dedicated means to attempt altering
682 .Va if_capenable
683 on an interface.
684 Userland code shall use
685 .Xr ioctl 2 .
686 .Pp
687 The following capabilities are currently supported by the system:
688 .Bl -tag -width ".Dv IFCAP_POLLING_NOCOUNT" -offset indent
689 .It Dv IFCAP_RXCSUM
690 This interface can do checksum validation on receiving data.
691 Some interfaces do not have sufficient buffer storage to store frames
692 above a certain MTU-size completely.
693 The driver for the interface might disable hardware checksum validation
694 if the MTU is set above the hardcoded limit.
695 .It Dv IFCAP_TXCSUM
696 This interface can do checksum calculation on transmitting data.
697 .It Dv IFCAP_HWCSUM
698 A shorthand for
699 .Pq Dv IFCAP_RXCSUM | IFCAP_TXCSUM .
700 .It Dv IFCAP_NETCONS
701 This interface can be a network console.
702 .It Dv IFCAP_VLAN_MTU
703 The
704 .Xr vlan 4
705 driver can operate over this interface in software tagging mode
706 without having to decrease MTU on
707 .Xr vlan 4
708 interfaces below 1500 bytes.
709 This implies the ability of this interface to cope with frames somewhat
710 longer than permitted by the Ethernet specification.
711 .It Dv IFCAP_VLAN_HWTAGGING
712 This interface can do VLAN tagging on output and
713 demultiplex frames by their VLAN tag on input.
714 .It Dv IFCAP_JUMBO_MTU
715 This Ethernet interface can transmit and receive frames up to
716 9000 bytes long.
717 .It Dv IFCAP_POLLING
718 This interface supports
719 .Xr polling 4 .
720 See below for details.
721 .It Dv IFCAP_VLAN_HWCSUM
722 This interface can do checksum calculation on both transmitting
723 and receiving data on
724 .Xr vlan 4
725 interfaces (implies
726 .Dv IFCAP_HWCSUM ) .
727 .It Dv IFCAP_TSO4
728 This Ethernet interface supports TCP4 Segmentation offloading.
729 .It Dv IFCAP_TSO6
730 This Ethernet interface supports TCP6 Segmentation offloading.
731 .It Dv IFCAP_TSO
732 A shorthand for
733 .Pq Dv IFCAP_TSO4 | IFCAP_TSO6 .
734 .It Dv IFCAP_TOE4
735 This Ethernet interface supports TCP offloading.
736 .It Dv IFCAP_TOE6
737 This Ethernet interface supports TCP6 offloading.
738 .It Dv IFCAP_TOE
739 A shorthand for
740 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
741 .It Dv IFCAP_WOL_UCAST
742 This Ethernet interface supports waking up on any Unicast packet.
743 .It Dv IFCAP_WOL_MCAST
744 This Ethernet interface supports waking up on any Multicast packet.
745 .It Dv IFCAP_WOL_MAGIC
746 This Ethernet interface supports waking up on any Magic packet such
747 as those sent by
748 .Xr wake 8 .
749 .It Dv IFCAP_WOL
750 A shorthand for
751 .Pq Dv IFCAP_WOL_UCAST | IFCAP_WOL_MCAST | IFCAP_WOL_MAGIC .
752 .It Dv IFCAP_TOE4
753 This Ethernet interface supports TCP4 Offload Engine.
754 .It Dv IFCAP_TOE6
755 This Ethernet interface supports TCP6 Offload Engine.
756 .It Dv IFCAP_TOE
757 A shorthand for
758 .Pq Dv IFCAP_TOE4 | IFCAP_TOE6 .
759 .It Dv IFCAP_VLAN_HWFILTER
760 This interface supports frame filtering in hardware on
761 .Xr vlan 4
762 interfaces.
763 .It Dv IFCAP_POLLING_NOCOUNT
764 The return value for the number of processed packets should be
765 skipped for this interface.
766 .It Dv IFCAP_VLAN_HWTSO
767 This interface supports TCP Segmentation offloading on
768 .Xr vlan 4
769 interfaces (implies
770 .Dv IFCAP_TSO ) .
771 .It Dv IFCAP_LINKSTATE
772 This Ethernet interface supports dynamic link state changes.
773 .El
774 .Pp
775 The ability of advanced network interfaces to offload certain
776 computational tasks from the host CPU to the board is limited
777 mostly to TCP/IP.
778 Therefore a separate field associated with an interface
779 (see
780 .Va ifnet.if_data.ifi_hwassist
781 below)
782 keeps a detailed description of its enabled capabilities
783 specific to TCP/IP processing.
784 The TCP/IP module consults the field to see which tasks
785 can be done on an
786 .Em outgoing
787 packet by the interface.
788 The flags defined for that field are a superset of those for
789 .Va mbuf.m_pkthdr.csum_flags ,
790 namely:
791 .Bl -tag -width ".Dv CSUM_FRAGMENT" -offset indent
792 .It Dv CSUM_IP
793 The interface will compute IP checksums.
794 .It Dv CSUM_TCP
795 The interface will compute TCP checksums.
796 .It Dv CSUM_UDP
797 The interface will compute UDP checksums.
798 .El
799 .Pp
800 An interface notifies the TCP/IP module about the tasks
801 the former has performed on an
802 .Em incoming
803 packet by setting the corresponding flags in the field
804 .Va mbuf.m_pkthdr.csum_flags
805 of the
806 .Vt mbuf chain
807 containing the packet.
808 See
809 .Xr mbuf 9
810 for details.
811 .Pp
812 The capability of a network interface to operate in
813 .Xr polling 4
814 mode involves several flags in different
815 global variables and per-interface fields.
816 The capability flag
817 .Dv IFCAP_POLLING
818 set in interface's
819 .Va if_capabilities
820 indicates support for
821 .Xr polling 4
822 on the particular interface.
823 If set in
824 .Va if_capabilities ,
825 the same flag can be marked or cleared in the interface's
826 .Va if_capenable
827 within
828 .Fn ifioctl ,
829 thus initiating switch of the interface to
830 .Xr polling 4
831 mode or interrupt
832 mode, respectively.
833 The actual mode change is managed by the driver-specific
834 .Fn if_ioctl
835 routine.
836 The
837 .Xr polling 4
838 handler returns the number of packets processed.
839 .Ss The Vt if_data Ss Structure
840 The
841 .Vt if_data
842 structure contains statistics and identifying information used
843 by management programs, and which is exported to user programs by way
844 of the
845 .Xr ifmib 4
846 branch of the
847 .Xr sysctl 3
848 MIB.
849 The following elements of the
850 .Vt if_data
851 structure are initialized by the interface and are not expected to change
852 significantly over the course of normal operation:
853 .Bl -tag -width ".Va ifi_lastchange" -offset indent
854 .It Va ifi_type
855 .Pq Vt u_char
856 The type of the interface, as defined in
857 .In net/if_types.h
858 and described below in the
859 .Sx "Interface Types"
860 section.
861 .It Va ifi_physical
862 .Pq Vt u_char
863 Intended to represent a selection of physical layers on devices which
864 support more than one; never implemented.
865 .It Va ifi_addrlen
866 .Pq Vt u_char
867 Length of a link-layer address on this device, or zero if there are
868 none.
869 Used to initialized the address length field in
870 .Vt sockaddr_dl
871 structures referring to this interface.
872 .It Va ifi_hdrlen
873 .Pq Vt u_char
874 Maximum length of any link-layer header which might be prepended by
875 the driver to a packet before transmission.
876 The generic code computes
877 the maximum over all interfaces and uses that value to influence the
878 placement of data in
879 .Vt mbuf Ns s
880 to attempt to ensure that there is always
881 sufficient space to prepend a link-layer header without allocating an
882 additional
883 .Vt mbuf .
884 .It Va ifi_datalen
885 .Pq Vt u_char
886 Length of the
887 .Vt if_data
888 structure.
889 Allows some stabilization of the routing socket ABI in the face of
890 increases in the length of
891 .Vt struct ifdata .
892 .It Va ifi_mtu
893 .Pq Vt u_long
894 The maximum transmission unit of the medium, exclusive of any
895 link-layer overhead.
896 .It Va ifi_metric
897 .Pq Vt u_long
898 A dimensionless metric interpreted by a user-mode routing process.
899 .It Va ifi_baudrate
900 .Pq Vt u_long
901 The line rate of the interface, in bits per second.
902 .It Va ifi_hwassist
903 .Pq Vt u_long
904 A detailed interpretation of the capabilities
905 to offload computational tasks for
906 .Em outgoing
907 packets.
908 The interface driver must keep this field in accord with
909 the current value of
910 .Va if_capenable .
911 .It Va ifi_epoch
912 .Pq Vt time_t
913 The system uptime when interface was attached or the statistics
914 below were reset.
915 This is intended to be used to set the SNMP variable
916 .Va ifCounterDiscontinuityTime .
917 It may also be used to determine if two successive queries for an
918 interface of the same index have returned results for the same
919 interface.
920 .El
921 .Pp
922 The structure additionally contains generic statistics applicable to a
923 variety of different interface types (except as noted, all members are
924 of type
925 .Vt u_long ) :
926 .Bl -tag -width ".Va ifi_lastchange" -offset indent
927 .It Va ifi_link_state
928 .Pq Vt u_char
929 The current link state of Ethernet interfaces.
930 See the
931 .Sx Interface Link States
932 section for possible values.
933 .It Va ifi_ipackets
934 Number of packets received.
935 .It Va ifi_ierrors
936 Number of receive errors detected (e.g., FCS errors, DMA overruns,
937 etc.).
938 More detailed breakdowns can often be had by way of a
939 link-specific MIB.
940 .It Va ifi_opackets
941 Number of packets transmitted.
942 .It Va ifi_oerrors
943 Number of output errors detected (e.g., late collisions, DMA overruns,
944 etc.).
945 More detailed breakdowns can often be had by way of a
946 link-specific MIB.
947 .It Va ifi_collisions
948 Total number of collisions detected on output for CSMA interfaces.
949 (This member is sometimes [ab]used by other types of interfaces for
950 other output error counts.)
951 .It Va ifi_ibytes
952 Total traffic received, in bytes.
953 .It Va ifi_obytes
954 Total traffic transmitted, in bytes.
955 .It Va ifi_imcasts
956 Number of packets received which were sent by link-layer multicast.
957 .It Va ifi_omcasts
958 Number of packets sent by link-layer multicast.
959 .It Va ifi_iqdrops
960 Number of packets dropped on input.
961 Rarely implemented.
962 .It Va ifi_noproto
963 Number of packets received for unknown network-layer protocol.
964 .It Va ifi_lastchange
965 .Pq Vt "struct timeval"
966 The time of the last administrative change to the interface (as required
967 for
968 .Tn SNMP ) .
969 .El
970 .Ss Interface Types
971 The header file
972 .In net/if_types.h
973 defines symbolic constants for a number of different types of
974 interfaces.
975 The most common are:
976 .Pp
977 .Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact
978 .It Dv IFT_OTHER
979 none of the following
980 .It Dv IFT_ETHER
981 Ethernet
982 .It Dv IFT_ISO88023
983 ISO 8802-3 CSMA/CD
984 .It Dv IFT_ISO88024
985 ISO 8802-4 Token Bus
986 .It Dv IFT_ISO88025
987 ISO 8802-5 Token Ring
988 .It Dv IFT_ISO88026
989 ISO 8802-6 DQDB MAN
990 .It Dv IFT_FDDI
991 FDDI
992 .It Dv IFT_PPP
993 Internet Point-to-Point Protocol
994 .Pq Xr ppp 8
995 .It Dv IFT_LOOP
996 The loopback
997 .Pq Xr lo 4
998 interface
999 .It Dv IFT_SLIP
1000 Serial Line IP
1001 .It Dv IFT_PARA
1002 Parallel-port IP
1003 .Pq Dq Tn PLIP
1004 .It Dv IFT_ATM
1005 Asynchronous Transfer Mode
1006 .It Dv IFT_USB
1007 USB Interface
1008 .El
1009 .Ss Interface Link States
1010 The following link states are currently defined:
1011 .Pp
1012 .Bl -tag -offset indent -width ".Dv LINK_STATE_UNKNOWN" -compact
1013 .It Dv LINK_STATE_UNKNOWN
1014 The link is in an invalid or unknown state.
1015 .It Dv LINK_STATE_DOWN
1016 The link is down.
1017 .It Dv LINK_STATE_UP
1018 The link is up.
1019 .El
1020 .Ss The Vt ifaddr Ss Structure
1021 Every interface is associated with a list
1022 (or, rather, a
1023 .Li TAILQ )
1024 of addresses, rooted at the interface structure's
1025 .Va if_addrlist
1026 member.
1027 The first element in this list is always an
1028 .Dv AF_LINK
1029 address representing the interface itself; multi-access network
1030 drivers should complete this structure by filling in their link-layer
1031 addresses after calling
1032 .Fn if_attach .
1033 Other members of the structure represent network-layer addresses which
1034 have been configured by means of the
1035 .Dv SIOCAIFADDR
1036 command to
1037 .Xr ioctl 2 ,
1038 called on a socket of the appropriate protocol family.
1039 The elements of this list consist of
1040 .Vt ifaddr
1041 structures.
1042 Most protocols will declare their own protocol-specific
1043 interface address structures, but all begin with a
1044 .Vt "struct ifaddr"
1045 which provides the most-commonly-needed functionality across all
1046 protocols.
1047 Interface addresses are reference-counted.
1048 .Pp
1049 The members of
1050 .Vt "struct ifaddr"
1051 are as follows:
1052 .Bl -tag -width ".Va ifa_rtrequest" -offset indent
1053 .It Va ifa_addr
1054 .Pq Vt "struct sockaddr *"
1055 The local address of the interface.
1056 .It Va ifa_dstaddr
1057 .Pq Vt "struct sockaddr *"
1058 The remote address of point-to-point interfaces, and the broadcast
1059 address of broadcast interfaces.
1060 .Va ( ifa_broadaddr
1061 is a macro for
1062 .Va ifa_dstaddr . )
1063 .It Va ifa_netmask
1064 .Pq Vt "struct sockaddr *"
1065 The network mask for multi-access interfaces, and the confusion
1066 generator for point-to-point interfaces.
1067 .It Va ifa_ifp
1068 .Pq Vt "struct ifnet *"
1069 A link back to the interface structure.
1070 .It Va ifa_link
1071 .Pq Fn TAILQ_ENTRY ifaddr
1072 .Xr queue 3
1073 glue for list of addresses on each interface.
1074 .It Va ifa_rtrequest
1075 See below.
1076 .It Va ifa_flags
1077 .Pq Vt u_short
1078 Some of the flags which would be used for a route representing this
1079 address in the route table.
1080 .It Va ifa_refcnt
1081 .Pq Vt short
1082 The reference count.
1083 .It Va ifa_metric
1084 .Pq Vt int
1085 A metric associated with this interface address, for the use of some
1086 external routing protocol.
1087 .El
1088 .Pp
1089 References to
1090 .Vt ifaddr
1091 structures are gained by calling the
1092 .Fn ifa_ref
1093 function and released by calling the
1094 .Fn ifa_free
1095 function.
1096 .Pp
1097 .Fn ifa_rtrequest
1098 is a pointer to a function which receives callouts from the routing
1099 code
1100 .Pq Fn rtrequest
1101 to perform link-layer-specific actions upon requests to add,
1102 or delete routes.
1103 The
1104 .Fa cmd
1105 argument indicates the request in question:
1106 .Dv RTM_ADD ,
1107 or
1108 .Dv RTM_DELETE .
1109 The
1110 .Fa rt
1111 argument is the route in question; the
1112 .Fa info
1113 argument contains the specific destination being manipulated.
1114 .Sh FUNCTIONS
1115 The functions provided by the generic interface code can be divided
1116 into two groups: those which manipulate interfaces, and those which
1117 manipulate interface addresses.
1118 In addition to these functions, there
1119 may also be link-layer support routines which are used by a number of
1120 drivers implementing a specific link layer over different hardware;
1121 see the documentation for that link layer for more details.
1122 .Ss The Vt ifmultiaddr Ss Structure
1123 Every multicast-capable interface is associated with a list of
1124 multicast group memberships, which indicate at a low level which
1125 link-layer multicast addresses (if any) should be accepted, and at a
1126 high level, in which network-layer multicast groups a user process has
1127 expressed interest.
1128 .Pp
1129 The elements of the structure are as follows:
1130 .Bl -tag -width ".Va ifma_refcount" -offset indent
1131 .It Va ifma_link
1132 .Pq Fn LIST_ENTRY ifmultiaddr
1133 .Xr queue 3
1134 macro glue.
1135 .It Va ifma_addr
1136 .Pq Vt "struct sockaddr *"
1137 A pointer to the address which this record represents.
1138 The
1139 memberships for various address families are stored in arbitrary
1140 order.
1141 .It Va ifma_lladdr
1142 .Pq Vt "struct sockaddr *"
1143 A pointer to the link-layer multicast address, if any, to which the
1144 network-layer multicast address in
1145 .Va ifma_addr
1146 is mapped, else a null pointer.
1147 If this element is non-nil, this
1148 membership also holds an invisible reference to another membership for
1149 that link-layer address.
1150 .It Va ifma_refcount
1151 .Pq Vt u_int
1152 A reference count of requests for this particular membership.
1153 .El
1154 .Ss Interface Manipulation Functions
1155 .Bl -ohang -offset indent
1156 .It Fn if_alloc
1157 Allocate and initialize
1158 .Vt "struct ifnet" .
1159 Initialization includes the allocation of an interface index and may
1160 include the allocation of a
1161 .Fa type
1162 specific structure in
1163 .Va if_l2com .
1164 .It Fn if_attach
1165 Link the specified interface
1166 .Fa ifp
1167 into the list of network interfaces.
1168 Also initialize the list of
1169 addresses on that interface, and create a link-layer
1170 .Vt ifaddr
1171 structure to be the first element in that list.
1172 (A pointer to
1173 this address structure is saved in the
1174 .Vt ifnet
1175 structure and shall be accessed by the
1176 .Fn ifaddr_byindex
1177 function.)
1178 The
1179 .Fa ifp
1180 must have been allocated by
1181 .Fn if_alloc .
1182 .It Fn if_detach
1183 Shut down and unlink the specified
1184 .Fa ifp
1185 from the interface list.
1186 .It Fn if_free
1187 Free the given
1188 .Fa ifp
1189 back to the system.
1190 The interface must have been previously detached if it was ever attached.
1191 .It Fn if_free_type
1192 Identical to
1193 .Fn if_free
1194 except that the given
1195 .Fa type
1196 is used to free
1197 .Va if_l2com
1198 instead of the type in
1199 .Va if_type .
1200 This is intended for use with drivers that change their interface type.
1201 .It Fn if_down
1202 Mark the interface
1203 .Fa ifp
1204 as down (i.e.,
1205 .Dv IFF_UP
1206 is not set),
1207 flush its output queue, notify protocols of the transition,
1208 and generate a message from the
1209 .Xr route 4
1210 routing socket.
1211 .It Fn if_up
1212 Mark the interface
1213 .Fa ifp
1214 as up, notify protocols of the transition,
1215 and generate a message from the
1216 .Xr route 4
1217 routing socket.
1218 .It Fn ifpromisc
1219 Add or remove a promiscuous reference to
1220 .Fa ifp .
1221 If
1222 .Fa pswitch
1223 is true, add a reference;
1224 if it is false, remove a reference.
1225 On reference count transitions
1226 from zero to one and one to zero, set the
1227 .Dv IFF_PROMISC
1228 flag appropriately and call
1229 .Fn if_ioctl
1230 to set up the interface in the desired mode.
1231 .It Fn if_allmulti
1232 As
1233 .Fn ifpromisc ,
1234 but for the all-multicasts
1235 .Pq Dv IFF_ALLMULTI
1236 flag instead of the promiscuous flag.
1237 .It Fn ifunit
1238 Return an
1239 .Vt ifnet
1240 pointer for the interface named
1241 .Fa name .
1242 .It Fn ifunit_ref
1243 Return a reference-counted (via
1244 .Fn ifa_ref )
1245 .Vt ifnet
1246 pointer for the interface named
1247 .Fa name .
1248 This is the preferred function over
1249 .Fn ifunit .
1250 The caller is responsible for releasing the reference with
1251 .Fn if_rele
1252 when it is finished with the ifnet.
1253 .It Fn ifioctl
1254 Process the ioctl request
1255 .Fa cmd ,
1256 issued on socket
1257 .Fa so
1258 by thread
1259 .Fa td ,
1260 with data parameter
1261 .Fa data .
1262 This is the main routine for handling all interface configuration
1263 requests from user mode.
1264 It is ordinarily only called from the socket-layer
1265 .Xr ioctl 2
1266 handler, and only for commands with class
1267 .Sq Li i .
1268 Any unrecognized commands will be passed down to socket
1269 .Fa so Ns 's
1270 protocol for
1271 further interpretation.
1272 The following commands are handled by
1273 .Fn ifioctl :
1274 .Pp
1275 .Bl -tag -width ".Dv OSIOCGIFNETMASK" -offset indent -compact
1276 .It Dv SIOCGIFCONF
1277 .It Dv OSIOCGIFCONF
1278 Get interface configuration.
1279 (No call-down to driver.)
1280 .Pp
1281 .It Dv SIOCSIFNAME
1282 Set the interface name.
1283 .Dv RTM_IFANNOUNCE
1284 departure and arrival messages are sent so that
1285 routing code that relies on the interface name will update its interface
1286 list.
1287 Caller must have appropriate privilege.
1288 (No call-down to driver.)
1289 .It Dv SIOCGIFCAP
1290 .It Dv SIOCGIFFIB
1291 .It Dv SIOCGIFFLAGS
1292 .It Dv SIOCGIFMETRIC
1293 .It Dv SIOCGIFMTU
1294 .It Dv SIOCGIFPHYS
1295 Get interface capabilities, FIB, flags, metric, MTU, medium selection.
1296 (No call-down to driver.)
1297 .Pp
1298 .It Dv SIOCSIFCAP
1299 Enable or disable interface capabilities.
1300 Caller must have appropriate privilege.
1301 Before a call to the driver-specific
1302 .Fn if_ioctl
1303 routine, the requested mask for enabled capabilities is checked
1304 against the mask of capabilities supported by the interface,
1305 .Va if_capabilities .
1306 Requesting to enable an unsupported capability is invalid.
1307 The rest is supposed to be done by the driver,
1308 which includes updating
1309 .Va if_capenable
1310 and
1311 .Va if_data.ifi_hwassist
1312 appropriately.
1313 .Pp
1314 .It Dv SIOCSIFFIB
1315 Sets interface FIB.
1316 Caller must have appropriate privilege.
1317 FIB values start at 0 and values greater or equals than
1318 .Va net.fibs
1319 are considered invalid.
1320 .It Dv SIOCSIFFLAGS
1321 Change interface flags.
1322 Caller must have appropriate privilege.
1323 If a change to the
1324 .Dv IFF_UP
1325 flag is requested,
1326 .Fn if_up
1327 or
1328 .Fn if_down
1329 is called as appropriate.
1330 Flags listed in
1331 .Dv IFF_CANTCHANGE
1332 are masked off, and the field
1333 .Va if_flags
1334 in the interface structure is updated.
1335 Finally, the driver
1336 .Fn if_ioctl
1337 routine is called to perform any setup
1338 requested.
1339 .Pp
1340 .It Dv SIOCSIFMETRIC
1341 .It Dv SIOCSIFPHYS
1342 Change interface metric or medium.
1343 Caller must have appropriate privilege.
1344 .Pp
1345 .It Dv SIOCSIFMTU
1346 Change interface MTU.
1347 Caller must have appropriate privilege.
1348 MTU
1349 values less than 72 or greater than 65535 are considered invalid.
1350 The driver
1351 .Fn if_ioctl
1352 routine is called to implement the change; it is responsible for any
1353 additional sanity checking and for actually modifying the MTU in the
1354 interface structure.
1355 .Pp
1356 .It Dv SIOCADDMULTI
1357 .It Dv SIOCDELMULTI
1358 Add or delete permanent multicast group memberships on the interface.
1359 Caller must have appropriate privilege.
1360 The
1361 .Fn if_addmulti
1362 or
1363 .Fn if_delmulti
1364 function is called to perform the operation; qq.v.
1365 .Pp
1366 .It Dv SIOCAIFADDR
1367 .It Dv SIOCDIFADDR
1368 The socket's protocol control routine is called to implement the
1369 requested action.
1370 .Pp
1371 .It Dv OSIOCGIFADDR
1372 .It Dv OSIOCGIFDSTADDR
1373 .It Dv OSIOCGIFBRDADDR
1374 .It Dv OSIOCGIFNETMASK
1375 The socket's protocol control routine is called to implement the
1376 requested action.
1377 On return,
1378 .Vt sockaddr
1379 structures are converted into old-style (no
1380 .Va sa_len
1381 member).
1382 .El
1383 .El
1384 .Pp
1385 .Fn if_down ,
1386 .Fn ifioctl ,
1387 .Fn ifpromisc ,
1388 and
1389 .Fn if_up
1390 must be called at
1391 .Fn splnet
1392 or higher.
1393 .Ss "Interface Address Functions"
1394 Several functions exist to look up an interface address structure
1395 given an address.
1396 .Fn ifa_ifwithaddr
1397 returns an interface address with either a local address or a
1398 broadcast address precisely matching the parameter
1399 .Fa addr .
1400 .Fn ifa_ifwithdstaddr
1401 returns an interface address for a point-to-point interface whose
1402 remote
1403 .Pq Dq destination
1404 address is
1405 .Fa addr .
1406 .Pp
1407 .Fn ifa_ifwithnet
1408 returns the most specific interface address which matches the
1409 specified address,
1410 .Fa addr ,
1411 subject to its configured netmask, or a point-to-point interface
1412 address whose remote address is
1413 .Fa addr
1414 if one is found.
1415 If
1416 .Fa ignore_ptp
1417 is true, skip point-to-point interface addresses.
1418 .Pp
1419 .Fn ifaof_ifpforaddr
1420 returns the most specific address configured on interface
1421 .Fa ifp
1422 which matches address
1423 .Fa addr ,
1424 subject to its configured netmask.
1425 If the interface is
1426 point-to-point, only an interface address whose remote address is
1427 precisely
1428 .Fa addr
1429 will be returned.
1430 .Pp
1431 .Fn ifaddr_byindex
1432 returns the link-level address of the interface with the given index
1433 .Fa idx .
1434 .Pp
1435 All of these functions return a null pointer if no such address can be
1436 found.
1437 .Ss "Interface Multicast Address Functions"
1438 The
1439 .Fn if_addmulti ,
1440 .Fn if_delmulti ,
1441 and
1442 .Fn if_findmulti
1443 functions provide support for requesting and relinquishing multicast
1444 group memberships, and for querying an interface's membership list,
1445 respectively.
1446 The
1447 .Fn if_addmulti
1448 function takes a pointer to an interface,
1449 .Fa ifp ,
1450 and a generic address,
1451 .Fa sa .
1452 It also takes a pointer to a
1453 .Vt "struct ifmultiaddr *"
1454 which is filled in on successful return with the address of the
1455 group membership control block.
1456 The
1457 .Fn if_addmulti
1458 function performs the following four-step process:
1459 .Bl -enum -offset indent
1460 .It
1461 Call the interface's
1462 .Fn if_resolvemulti
1463 entry point to determine the link-layer address, if any, corresponding
1464 to this membership request, and also to give the link layer an
1465 opportunity to veto this membership request should it so desire.
1466 .It
1467 Check the interface's group membership list for a pre-existing
1468 membership for this group.
1469 If one is not found, allocate a new one;
1470 if one is, increment its reference count.
1471 .It
1472 If the
1473 .Fn if_resolvemulti
1474 routine returned a link-layer address corresponding to the group,
1475 repeat the previous step for that address as well.
1476 .It
1477 If the interface's multicast address filter needs to be changed
1478 because a new membership was added, call the interface's
1479 .Fn if_ioctl
1480 routine
1481 (with a
1482 .Fa cmd
1483 argument of
1484 .Dv SIOCADDMULTI )
1485 to request that it do so.
1486 .El
1487 .Pp
1488 The
1489 .Fn if_delmulti
1490 function, given an interface
1491 .Fa ifp
1492 and an address,
1493 .Fa sa ,
1494 reverses this process.
1495 Both functions return zero on success, or a
1496 standard error number on failure.
1497 .Pp
1498 The
1499 .Fn if_findmulti
1500 function examines the membership list of interface
1501 .Fa ifp
1502 for an address matching
1503 .Fa sa ,
1504 and returns a pointer to that
1505 .Vt "struct ifmultiaddr"
1506 if one is found, else it returns a null pointer.
1507 .Sh SEE ALSO
1508 .Xr ioctl 2 ,
1509 .Xr link_addr 3 ,
1510 .Xr queue 3 ,
1511 .Xr sysctl 3 ,
1512 .Xr bpf 4 ,
1513 .Xr ifmib 4 ,
1514 .Xr lo 4 ,
1515 .Xr netintro 4 ,
1516 .Xr polling 4 ,
1517 .Xr config 8 ,
1518 .Xr ppp 8 ,
1519 .Xr mbuf 9 ,
1520 .Xr rtentry 9
1521 .Rs
1522 .%A Gary R. Wright
1523 .%A W. Richard Stevens
1524 .%B TCP/IP Illustrated
1525 .%V Vol. 2
1526 .%O Addison-Wesley, ISBN 0-201-63354-X
1527 .Re
1528 .Sh AUTHORS
1529 This manual page was written by
1530 .An Garrett A. Wollman .