acpi: Narrow workaround for broken interrupt settings
[dragonfly.git] / share / man / man9 / ifnet.9
blobc067ab2a66f9e7c9abff1ed7c7f2c583d141404a
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: src/share/man/man9/ifnet.9,v 1.9.2.10 2003/06/15 02:22:30 hmp Exp $
30 .\"
31 .Dd June 20, 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/types.h
42 .In sys/time.h
43 .In sys/socket.h
44 .In net/if.h
45 .In net/if_var.h
46 .In net/if_types.h
47 .\"
48 .Ss "Interface Manipulation Functions"
49 .Ft void
50 .Fn if_attach "struct ifnet *ifp"
51 .Ft void
52 .Fn if_down "struct ifnet *ifp"
53 .Ft int
54 .Fn ifioctl "struct socket *so" "u_long cmd" "caddr_t data" "struct proc *p"
55 .Ft int
56 .Fn ifpromisc "struct ifnet *ifp" "int pswitch"
57 .Ft int
58 .Fn if_allmulti "struct ifnet *ifp" "int amswitch"
59 .Ft "struct ifnet *"
60 .Fn ifunit "const char *name"
61 .Ft void
62 .Fn if_up "struct ifnet *ifp"
63 .\"
64 .Ss "Interface Address Functions"
65 .Ft "struct ifaddr *"
66 .Fn ifa_ifwithaddr "struct sockaddr *addr"
67 .Ft "struct ifaddr *"
68 .Fn ifa_ifwithdstaddr "struct sockaddr *addr"
69 .Ft "struct ifaddr *"
70 .Fn ifa_ifwithnet "struct sockaddr *addr"
71 .Ft "struct ifaddr *"
72 .Fn ifaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp"
73 .Fn IFAFREE "struct ifaddr *ifa"
74 .\"
75 .Ss "Interface Multicast Address Functions"
76 .Ft int
77 .Fn if_addmulti "struct ifnet *ifp" "struct sockaddr *sa" "struct ifmultiaddr **ifmap"
78 .Ft int
79 .Fn if_delmulti "struct ifnet *ifp" "struct sockaddr *sa"
80 .Ft "struct ifmultiaddr *"
81 .Fn ifmaof_ifpforaddr "struct sockaddr *addr" "struct ifnet *ifp"
82 .Ss "Output queue macros"
83 .Fn IF_DEQUEUE "struct ifqueue *ifq" "struct mbuf *m"
84 .\"
85 .Ss "struct ifnet Member Functions"
86 .Ft int
87 .Fo (*if_output)
88 .Fa "struct ifnet *ifp" "struct mbuf *m"
89 .Fa "struct sockaddr *dst" "struct rtentry *rt"
90 .Fc
91 .Ft void
92 .Fo (*if_input)
93 .Fa "struct ifnet *ifp" "struct mbuf *m"
94 .Fa "const struct pktinfo *pi" "int cpuid"
95 .Fc
96 .Ft void
97 .Fn (*if_start) "struct ifnet *ifp" "struct ifaltq_subque *ifsq"
98 .Ft int
99 .Fo (*if_ioctl)
100 .Fa "struct ifnet *ifp" "u_long command" "caddr_t data" "struct ucred *cr"
102 .Ft void
103 .Fn (*if_watchdog) "struct ifnet *ifp"
104 .Ft void
105 .Fn (*if_init) "void *if_softc"
106 .Ft int
107 .Fo (*if_resolvemulti)
108 .Fa "struct ifnet *ifp" "struct sockaddr **retsa" "struct sockaddr *addr"
110 .Ft void
111 .Fn (*if_poll) "struct ifnet *ifp" "enum poll_cmd cmd" "int count"
112 .Ss "struct ifaddr member function"
113 .Ft void
114 .Fo (*ifa_rtrequest)
115 .Fa "int cmd" "struct rtentry *rt" "struct sockaddr *dst"
118 .Ss "Global Variables"
119 .Vt extern struct ifnethead ifnet ;
120 .Vt extern int if_index ;
121 .Vt extern int ifqmaxlen ;
122 .Sh DATA STRUCTURES
123 The kernel mechanisms for handling network interfaces reside primarily
124 in the
125 .Vt ifnet , if_data , ifaddr ,
127 .Vt ifmultiaddr
128 structures in
129 .In net/if.h
131 .In net/if_var.h
132 and the functions named above and defined in
133 .Pa sys/net/if.c .
134 Those interfaces which are intended to be used by user programs
135 are defined in
136 .In net/if.h ;
137 these include the interface flags, the
138 .Vt if_data
139 structure, and the structures defining the appearance of
140 interface-related messages on the
141 .Xr route 4
142 routing socket and in
143 .Xr sysctl 3 .
144 The header file
145 .In net/if_var.h
146 defines the kernel-internal interfaces, including the
147 .Vt ifnet , ifaddr ,
149 .Vt ifmultiaddr
150 structures and the functions which manipulate them.
151 (A few user programs will need
152 .In net/if_var.h
153 because it is the prerequisite of some other header file like
154 .In netinet/if_ether.h .
155 Most references to those two files in particular can be replaced by
156 .In net/ethernet.h . )
158 The system keeps a linked list of interfaces using the
159 .Li TAILQ
160 macros defined in
161 .Xr queue 3 ;
162 this list is headed by a
163 .Vt "struct ifnethead"
164 called
165 .Va ifnet .
166 The elements of this list are of type
167 .Vt "struct ifnet" ,
168 and most kernel routines which manipulate interface as such accept or
169 return pointers to these structures.
170 Each interface structure
171 contains an
172 .Vt if_data
173 structure, which contains statistics and identifying information used
174 by management programs, and which is exported to user programs by way
175 of the
176 .Xr ifmib 4
177 branch of the
178 .Xr sysctl 3
179 MIB.
180 Each interface also has a
181 .Li TAILQ
182 of interface addresses, described by
183 .Vt ifaddr
184 structures; the head of the queue is always an
185 .Dv AF_LINK
186 address
187 (see
188 .Xr link_addr 3 )
189 describing the link layer implemented by the interface (if any).
190 (Some trivial interfaces do not provide any link layer addresses;
191 this structure, while still present, serves only to identify the
192 interface name and index.)
194 Finally, those interfaces supporting reception of multicast datagrams
195 have a
196 .Li LIST
197 of multicast group memberships, described by
198 .Vt ifmultiaddr
199 structures.
200 These memberships are reference-counted.
202 Interfaces are also associated with an output queue, defined as a
203 .Vt "struct ifqueue" ;
204 this structure is used to hold packets while the interface is in the
205 process of sending another.
206 .Ss Eo
208 .Vt ifnet
209 structure
211 The fields of
212 .Vt "struct ifnet"
213 are as follows:
214 .Bl -tag -width ".Va if_poll_slowq" -offset indent
215 .It Va if_softc
216 .Pq Vt "void *"
217 A pointer to the driver's private state block.
218 (Initialized by driver.)
219 .It Va if_link
220 .Pq Fn TAILQ_ENTRY ifnet
221 .Xr queue 3
222 macro glue.
223 .It Va if_xname
224 .Pq Vt "char *"
225 The name of the interface,
226 (e.g.,
227 .Dq Li fxp0
229 .Dq Li lo0 ) .
230 (Initialized by driver.)
231 .It Va if_dname
232 .Pq Vt "const char *"
233 The name of the driver.
234 (Initialized by driver.)
235 .It Va if_dunit
236 .Pq Vt int
237 A unique number assigned to each interface managed by a particular
238 driver.
239 Drivers may choose to set this to
240 .Dv IF_DUNIT_NONE
241 if a unit number is not associated with the device.
242 (Initialized by driver.)
243 .\" .It Va if_vlantrunks
244 .\" .Pq Vt "void *"
245 .\" ...
246 .It Va if_addrhead
247 .Pq Vt "struct ifaddrhead"
248 The head of the
249 .Xr queue 3
250 .Li TAILQ
251 containing the list of addresses assigned to this interface.
252 .It Va if_pcount
253 .Pq Vt int
254 A count of promiscuous listeners on this interface, used to
255 reference-count the
256 .Dv IFF_PROMISC
257 flag.
258 .It Va if_carp
259 .Pq Vt "struct carp_if *"
260 Per-interface data for
261 .Xr carp 4 .
262 .It Va if_bpf
263 .Pq Vt "struct bpf_if *"
264 Opaque per-interface data for the packet filter,
265 .Xr bpf 4 .
266 (Initialized by
267 .Fn bpfattach . )
268 .It Va if_index
269 .Pq Vt u_short
270 A unique number assigned to each interface in sequence as it is
271 attached.
272 This number can be used in a
273 .Vt "struct sockaddr_dl"
274 to refer to a particular interface by index
275 (see
276 .Xr link_addr 3 ) .
277 .It Va if_timer
278 .Pq Vt short
279 Number of seconds until the watchdog timer
280 .Fn if_watchdog
281 is called, or zero if the timer is disabled.
282 (Set by driver,
283 decremented by generic watchdog code.)
284 .It Va if_flags
285 .Pq Vt int
286 Flags describing operational parameters of this interface (see below).
287 (Manipulated by both driver and generic code.)
288 .It Va if_linkmib
289 .Pq Vt "void *"
290 A pointer to an interface-specific MIB structure exported by
291 .Xr ifmib 4 .
292 (Initialized by driver.)
293 .It Va if_linkmiblen
294 .Pq Vt size_t
295 The size of said structure.
296 (Initialized by driver.)
297 .It Va if_data
298 .Pq Vt "struct if_data"
299 More statistics and information; see
300 .Sx "The if_data structure" ,
301 below.
302 (Initialized by driver, manipulated by both driver and generic
303 code.)
304 .\" .It Va if_poll_cpuid
305 .\" .Pq Vt int
306 .\" ...
307 .It Va if_snd
308 .Pq Vt "struct ifaltq"
309 The output queue including
310 .Xr altq 4 .
311 (Manipulated by driver.)
312 .\" .It Va if_broadcastaddr
313 .\" .Pq Vt "const uint8_t"
314 .\" ...
315 .\" .It Va if_bridge
316 .\" .Pq Vt "void *"
317 .\" ...
318 .\" .It Va if_afdata
319 .\" .Pq Vt "void *"
320 .\" ...
321 .\" .It Va if_lladdr
322 .\" .Pq Vt "struct ifaddr"
323 .\" ...
324 .\" .It Va if_serializer
325 .\" .Pq Vt "struct lwkt_serialize"
326 .\" ...
327 .\" .It Va if_default_serializer
328 .\" .Pq Vt "struct lwkt_serialize"
329 .\" ...
332 There are in addition a number of function pointers which the driver
333 must initialize to complete its interface with the generic interface
334 layer:
335 .Bl -ohang -offset indent
336 .It Fn if_output
337 Output a packet on interface
338 .Fa ifp ,
339 or queue it on the output queue if the interface is already active.
340 .It Fn if_start
341 Start queued output on an interface.
342 This function is exposed in
343 order to provide for some interface classes to share a
344 .Fn if_output
345 among all drivers.
346 .Fn if_start
347 may only be called when the
348 .Dv IFF_OACTIVE
349 flag is not set.
350 (Thus,
351 .Dv IFF_OACTIVE
352 does not literally mean that output is active, but rather that the
353 device's internal output queue is full.)
354 .It Fn if_ioctl
355 Process interface-related
356 .Xr ioctl 2
357 requests
358 (defined in
359 .In sys/sockio.h ) .
360 Preliminary processing is done by the generic routine
361 .Fn ifioctl
362 to check for appropriate privileges, locate the interface being
363 manipulated, and perform certain generic operations like twiddling
364 flags and flushing queues.
365 See the description of
366 .Fn ifioctl
367 below for more information.
368 .It Fn if_watchdog
369 Routine called by the generic code when the watchdog timer,
370 .Va if_timer ,
371 expires.
372 Usually this will reset the interface.
373 .\".It Fn if_poll
374 .\" See the
375 .\" .Sx POLLING
376 .\" section, below.
377 .It Fn if_init
378 Initialize and bring up the hardware,
379 e.g., reset the chip and the watchdog timer and enable the receiver unit.
380 Should mark the interface running,
381 but not active
382 .Dv ( IFF_RUNNING , ~IFF_OACTIVE ) .
383 .It Fn if_resolvemulti
384 Check the requested multicast group membership,
385 .Fa addr ,
386 for validity, and if necessary compute a link-layer group which
387 corresponds to that address which is returned in
388 .Fa *retsa .
389 Returns zero on success, or an error code on failure.
391 .Ss "Interface Flags"
392 Interface flags are used for a number of different purposes.
393 Some
394 flags simply indicate information about the type of interface and its
395 capabilities; others are dynamically manipulated to reflect the
396 current state of the interface.
397 Flags of the former kind are marked
398 .Aq S
399 in this table; the latter are marked
400 .Aq D .
402 .Bl -tag -width ".Dv IFF_POINTOPOINT" -offset indent -compact
403 .It Dv IFF_UP
404 .Aq D
405 The interface has been configured up by the user-level code.
406 .It Dv IFF_BROADCAST
407 .Aq S*
408 The interface supports broadcast.
409 .It Dv IFF_DEBUG
410 .Aq D
411 Used to enable/disable driver debugging code.
412 .It Dv IFF_LOOPBACK
413 .Aq S
414 The interface is a loopback device.
415 .It Dv IFF_POINTOPOINT
416 .Aq S*
417 The interface is point-to-point;
418 .Dq broadcast
419 address is actually the address of the other end.
420 .It Dv IFF_RUNNING
421 .Aq D*
422 The interface has been configured and dynamic resources were
423 successfully allocated.
424 Probably only useful internal to the
425 interface.
426 .It Dv IFF_NOARP
427 .Aq D
428 Disable network address resolution on this interface.
429 .It Dv IFF_PROMISC
430 .Aq D*
431 This interface is in promiscuous mode.
432 .It Dv IFF_PPROMISC
433 .Aq D
434 This interface is in the permanently promiscuous mode (implies
435 .Dv IFF_PROMISC ) .
436 .It Dv IFF_ALLMULTI
437 .Aq D*
438 This interface is in all-multicasts mode (used by multicast routers).
439 .It Dv IFF_OACTIVE
440 .Aq D*
441 The interface's hardware output queue (if any) is full; output packets
442 are to be queued.
443 .It Dv IFF_SIMPLEX
444 .Aq S*
445 The interface cannot hear its own transmissions.
446 .It Dv IFF_LINK0
447 .It Dv IFF_LINK1
448 .It Dv IFF_LINK2
449 .Aq D
450 Control flags for the link layer.
451 (Currently abused to select among
452 multiple physical layers on some devices.)
453 .It Dv IFF_MULTICAST
454 .Aq S*
455 This interface supports multicast.
456 .It Dv IFF_POLLING
457 The interface is in polling mode.
458 .\" .It Dv IFF_MONITOR
459 .\" ...
462 The macro
463 .Dv IFF_CANTCHANGE
464 defines the bits which cannot be set by a user program using the
465 .Dv SIOCSIFFLAGS
466 command to
467 .Xr ioctl 2 ;
468 these are indicated by an asterisk in the listing above.
469 .Ss Eo
471 .Vt if_data
472 Structure
475 .Bx 4.4 ,
476 a subset of the interface information believed to be of interest to
477 management stations was segregated from the
478 .Vt ifnet
479 structure and moved into its own
480 .Vt if_data
481 structure to facilitate its use by user programs.
482 The following elements of the
483 .Vt if_data
484 structure are initialized by the interface and are not expected to change
485 significantly over the course of normal operation:
486 .Bl -tag -width ".Va ifi_lastchange" -offset indent
487 .It Va ifi_type
488 .Pq Vt u_char
489 The type of the interface, as defined in
490 .In net/if_types.h
491 and described below in the
492 .Sx "Interface Types"
493 section.
494 .It Va ifi_physical
495 .Pq Vt u_char
496 Intended to represent a selection of physical layers on devices which
497 support more than one; never implemented.
498 .It Va ifi_addrlen
499 .Pq Vt u_char
500 Length of a link-layer address on this device, or zero if there are
501 none.
502 Used to initialize the address length field in
503 .Vt sockaddr_dl
504 structures referring to this interface.
505 .It Va ifi_hdrlen
506 .Pq Vt u_char
507 Maximum length of any link-layer header which might be prepended by
508 the driver to a packet before transmission.
509 The generic code computes
510 the maximum over all interfaces and uses that value to influence the
511 placement of data in
512 .Vt mbuf Ns s
513 to attempt to ensure that there is always
514 sufficient space to prepend a link-layer header without allocating an
515 additional
516 .Vt mbuf .
517 .\" (See
518 .\" .Xr mbuf 9 . )
519 .\" .It Va ifi_recvquota
520 .\" .Pq Vt u_char
521 .\" Number of packets the interface is permitted to receive at one time
522 .\" when in polled mode.
523 .\" .It Va ifi_xmitquota
524 .\" .Pq Vt u_char
525 .\" Number of packets the interface is permitted to queue for transmission
526 .\" at one time when in polled mode.
527 .\" There is some controversy over
528 .\" whether such a restriction makes any sense at all.
529 .It Va ifi_mtu
530 .Pq Vt u_long
531 The maximum transmission unit of the medium, exclusive of any
532 link-layer overhead.
533 .It Va ifi_metric
534 .Pq Vt u_long
535 A dimensionless metric interpreted by a user-mode routing process.
536 .It Va ifi_link_state
537 .Pq Vt u_long
538 The link state of the interface, either
539 .Dv LINK_STATE_UNKNOWN ,
540 .Dv LINK_STATE_DOWN ,
542 .Dv LINK_STATE_UP .
543 .It Va ifi_baudrate
544 .Pq Vt uint64_t
545 The line rate of the interface, in bits per second.
548 The structure additionally contains generic statistics applicable to a
549 variety of different interface types (except as noted, all members are
550 of type
551 .Vt u_long ) :
552 .Bl -tag -width ".Va ifi_lastchange" -offset indent
553 .It Va ifi_ipackets
554 Number of packets received.
555 .It Va ifi_ierrors
556 Number of receive errors detected (e.g., FCS errors, DMA overruns,
557 etc.).
558 More detailed breakdowns can often be had by way of a
559 link-specific MIB.
560 .It Va ifi_opackets
561 Number of packets transmitted.
562 .It Va ifi_oerrors
563 Number of output errors detected (e.g., late collisions, DMA overruns,
564 etc.).
565 More detailed breakdowns can often be had by way of a
566 link-specific MIB.
567 .It Va ifi_collisions
568 Total number of collisions detected on output for CSMA interfaces.
569 (This member is sometimes [ab]used by other types of interfaces for
570 other output error counts.)
571 .It Va ifi_ibytes
572 Total traffic received, in bytes.
573 .It Va ifi_obytes
574 Total traffic transmitted, in bytes.
575 .It Va ifi_imcasts
576 Number of packets received which were sent by link-layer multicast.
577 .It Va ifi_omcasts
578 Number of packets sent by link-layer multicast.
579 .It Va ifi_iqdrops
580 Number of packets dropped on input.
581 Rarely implemented.
582 .It Va ifi_noproto
583 Number of packets received for unknown network-layer protocol.
584 .It Va ifi_lastchange
585 .Pq Vt "struct timeval"
586 The time of the last administrative change to the interface (as required
588 .Tn SNMP ) .
590 .Ss Interface Types
591 The header file
592 .In net/if_types.h
593 defines symbolic constants for a number of different types of
594 interfaces.
595 The most common are:
597 .Bl -tag -offset indent -width ".Dv IFT_PROPVIRTUAL" -compact
598 .It Dv IFT_OTHER
599 none of the following
600 .It Dv IFT_ETHER
601 Ethernet
602 .It Dv IFT_ISO88023
603 ISO 8802-3 CSMA/CD
604 .It Dv IFT_ISO88024
605 ISO 8802-4 Token Bus
606 .It Dv IFT_ISO88025
607 ISO 8802-5 Token Ring
608 .It Dv IFT_ISO88026
609 ISO 8802-6 DQDB MAN
610 .It Dv IFT_FDDI
611 FDDI
612 .It Dv IFT_PPP
613 Internet Point-to-Point Protocol
614 .Pq Xr ppp 8
615 .It Dv IFT_LOOP
616 The loopback
617 .Pq Xr lo 4
618 interface
619 .It Dv IFT_SLIP
620 Serial Line IP
621 .It Dv IFT_PARA
622 Parallel-port IP
623 .Pq Dq Tn PLIP
624 .It Dv IFT_ATM
625 Asynchronous Transfer Mode
627 .Ss Eo
629 .Vt ifaddr
630 Structure
632 Every interface is associated with a list
633 (or, rather, a
634 .Li TAILQ )
635 of addresses, rooted at the interface structure's
636 .Va if_addrlist
637 member.
638 The first element in this list is always an
639 .Dv AF_LINK
640 address representing the interface itself; multi-access network
641 drivers should complete this structure by filling in their link-layer
642 addresses after calling
643 .Fn if_attach .
644 Other members of the structure represent network-layer addresses which
645 have been configured by means of the
646 .Dv SIOCAIFADDR
647 command to
648 .Xr ioctl 2 ,
649 called on a socket of the appropriate protocol family.
650 The elements of this list consist of
651 .Vt ifaddr
652 structures.
653 Most protocols will declare their own protocol-specific
654 interface address structures, but all begin with a
655 .Vt "struct ifaddr"
656 which provides the most-commonly-needed functionality across all
657 protocols.
658 Interface addresses are reference-counted.
660 The members of
661 .Vt "struct ifaddr"
662 are as follows:
663 .Bl -tag -width ".Va ifa_rtrequest" -offset indent
664 .It Va ifa_addr
665 .Pq Vt "struct sockaddr *"
666 The local address of the interface.
667 .It Va ifa_dstaddr
668 .Pq Vt "struct sockaddr *"
669 The remote address of point-to-point interfaces, and the broadcast
670 address of broadcast interfaces.
671 .Va ( ifa_broadaddr
672 is a macro for
673 .Va ifa_dstaddr . )
674 .It Va ifa_netmask
675 .Pq Vt "struct sockaddr *"
676 The network mask for multi-access interfaces, and the confusion
677 generator for point-to-point interfaces.
678 .\" .It Va if_data
679 .\" .Pq Vt "struct if_data"
680 .\" ...
681 .It Va ifa_ifp
682 .Pq Vt "struct ifnet *"
683 A link back to the interface structure.
684 .It Va ifa_containers
685 .Pq Vt "struct ifaddr_container *"
686 A pointer to an array of
687 .Vt ifaddr_container
688 structures which hold per-CPU data.
689 .It Va ifa_rtrequest
690 See below.
691 .It Va ifa_flags
692 .Pq Vt u_short
693 Some of the flags which would be used for a route representing this
694 address in the route table.
695 .\" .It Va ifa_cpumask
696 .\" .Pq Vt cpumask_t
697 .\" ...
698 .It Va ifa_metric
699 .Pq Vt int
700 A metric associated with this interface address, for the use of some
701 external routing protocol.
704 References to
705 .Vt ifaddr
706 structures are gained manually, by incrementing the
707 .Va ifa_refcnt
708 member of the according
709 .Va ifa_containers
710 structure (such as by calling the
711 .Fn IFAREF
712 macro).
713 References are released by calling the
714 .Fn IFAFREE
715 macro.
717 .Fn ifa_rtrequest
718 is a pointer to a function which receives callouts from the routing
719 code
720 .Pq Fn rtrequest
721 to perform link-layer-specific actions upon requests to add, resolve,
722 or delete routes.
724 .Fa cmd
725 argument indicates the request in question:
726 .Dv RTM_ADD , RTM_RESOLVE ,
728 .Dv RTM_DELETE .
730 .Fa rt
731 argument is the route in question; the
732 .Fa dst
733 argument is the specific destination being manipulated
735 .Dv RTM_RESOLVE ,
736 or a null pointer otherwise.
737 .Sh FUNCTIONS
738 The functions provided by the generic interface code can be divided
739 into two groups: those which manipulate interfaces, and those which
740 manipulate interface addresses.
741 In addition to these functions, there
742 may also be link-layer support routines which are used by a number of
743 drivers implementing a specific link layer over different hardware;
744 see the documentation for that link layer for more details.
745 .Ss Eo
747 .Vt ifmultiaddr
748 Structure
750 Every multicast-capable interface is associated with a list of
751 multicast group memberships, which indicate at a low level which
752 link-layer multicast addresses (if any) should be accepted, and at a
753 high level, in which network-layer multicast groups a user process has
754 expressed interest.
756 The elements of the structure are as follows:
757 .Bl -tag -width ".Va ifma_refcount" -offset indent
758 .It Va ifma_link
759 .Pq Fn LIST_ENTRY ifmultiaddr
760 .Xr queue 3
761 macro glue.
762 .It Va ifma_addr
763 .Pq Vt "struct sockaddr *"
764 A pointer to the address which this record represents.
766 memberships for various address families are stored in arbitrary
767 order.
768 .It Va ifma_lladdr
769 .Pq Vt "struct sockaddr *"
770 A pointer to the link-layer multicast address, if any, to which the
771 network-layer multicast address in
772 .Va ifma_addr
773 is mapped, else a null pointer.
774 If this element is non-NULL, this
775 membership also holds an invisible reference to another membership for
776 that link-layer address.
777 .It Va ifma_refcount
778 .Pq Vt u_int
779 A reference count of requests for this particular membership.
781 .Ss Interface Manipulation Functions
782 .Bl -ohang -offset indent
783 .It Fn if_attach
784 Link the specified interface
785 .Fa ifp
786 into the list of network interfaces.
787 Also initialize the list of
788 addresses on that interface, and create a link-layer
789 .Vt ifaddr
790 structure to be the first element in that list.
791 (A pointer to
792 this address structure is saved in the global array
793 .Va ifnet_addrs . )
794 .It Fn if_down
795 Mark the interface
796 .Fa ifp
797 as down (i.e.,
798 .Dv IFF_UP
799 is not set),
800 flush its output queue, notify protocols of the transition,
801 and generate a message from the
802 .Xr route 4
803 routing socket.
804 .It Fn if_up
805 Mark the interface
806 .Fa ifp
807 as up, notify protocols of the transition,
808 and generate a message from the
809 .Xr route 4
810 routing socket.
811 .It Fn ifpromisc
812 Add or remove a promiscuous reference to
813 .Fa ifp .
815 .Fa pswitch
816 is true, add a reference;
817 if it is false, remove a reference.
818 On reference count transitions
819 from zero to one and one to zero, set the
820 .Dv IFF_PROMISC
821 flag appropriately and call
822 .Fn if_ioctl
823 to set up the interface in the desired mode.
824 .It Fn if_allmulti
826 .Fn ifpromisc ,
827 but for the all-multicasts
828 .Pq Dv IFF_ALLMULTI
829 flag instead of the promiscuous flag.
830 .It Fn ifunit
831 Return an
832 .Vt ifnet
833 pointer for the interface named
834 .Fa name .
835 .It Fn ifioctl
836 Process the ioctl request
837 .Fa cmd ,
838 issued on socket
839 .Fa so
840 by process
841 .Fa p ,
842 with data parameter
843 .Fa data .
844 This is the main routine for handling all interface configuration
845 requests from user mode.
846 It is ordinarily only called from the socket-layer
847 .Xr ioctl 2
848 handler, and only for commands with class
849 .Sq Li i .
850 Any unrecognized commands will be passed down to socket
851 .Fa so Ns 's
852 protocol for
853 further interpretation.
854 The following commands are handled by
855 .Fn ifioctl :
857 .Bl -tag -width ".Dv SIOCSIFDSTADDR" -offset indent -compact
858 .It Dv SIOCGIFCONF
859 Get interface configuration.
860 (No call-down to driver.)
862 .It Dv SIOCGIFFLAGS
863 .It Dv SIOCGIFMETRIC
864 .It Dv SIOCGIFMTU
865 .It Dv SIOCGIFPHYS
866 Get interface flags, metric, MTU, medium selection.
867 (No call-down to driver.)
869 .It Dv SIOCSIFFLAGS
870 Change interface flags.
871 Caller must have appropriate privilege.
872 If a change to the
873 .Dv IFF_UP
874 flag is requested,
875 .Fn if_up
877 .Fn if_down
878 is called as appropriate.
879 Flags listed in
880 .Dv IFF_CANTCHANGE
881 are masked off, and the driver
882 .Fn if_ioctl
883 routine is called to perform any setup
884 requested.
886 .It Dv SIOCSIFMETRIC
887 .It Dv SIOCSIFPHYS
888 Change interface metric or medium.
889 Caller must have appropriate privilege.
891 .It Dv SIOCSIFMTU
892 Change interface MTU.
893 Caller must have appropriate privilege.
895 values less than 72 or greater than 65535 are considered invalid.
896 The driver
897 .Fn if_ioctl
898 routine is called to implement the change; it is responsible for any
899 additional sanity checking and for actually modifying the MTU in the
900 interface structure.
902 .It Dv SIOCADDMULTI
903 .It Dv SIOCDELMULTI
904 Add or delete permanent multicast group memberships on the interface.
905 Caller must have appropriate privilege.
907 .Fn if_addmulti
909 .Fn if_delmulti
910 function is called to perform the operation; qq.v.
912 .It Dv SIOCSIFDSTADDR
913 .It Dv SIOCSIFADDR
914 .It Dv SIOCSIFBRDADDR
915 .It Dv SIOCSIFNETMASK
916 The socket's protocol control routine is called to implement the
917 requested action.
921 .Fn if_down ,
922 .Fn ifioctl ,
923 .Fn ifpromisc ,
925 .Fn if_up
926 must be called inside a critical section.
927 .Ss "Interface Address Functions"
928 Several functions exist to look up an interface address structure
929 given an address.
930 .Fn ifa_ifwithaddr
931 returns an interface address with either a local address or a
932 broadcast address precisely matching the parameter
933 .Fa addr .
934 .Fn ifa_ifwithdstaddr
935 returns an interface address for a point-to-point interface whose
936 remote
937 .Pq Dq destination
938 address is
939 .Fa addr .
941 .Fn ifa_ifwithnet
942 returns the most specific interface address which matches the
943 specified address,
944 .Fa addr ,
945 subject to its configured netmask, or a point-to-point interface
946 address whose remote address is
947 .Fa addr
948 if one is found.
950 .Fn ifaof_ifpforaddr
951 returns the most specific address configured on interface
952 .Fa ifp
953 which matches address
954 .Fa addr ,
955 subject to its configured netmask.
956 If the interface is
957 point-to-point, only an interface address whose remote address is
958 precisely
959 .Fa addr
960 will be returned.
962 All of these functions return a null pointer if no such address can be
963 found.
964 .Ss "Interface Multicast Address Functions"
966 .Fn if_addmulti ,
967 .Fn if_delmulti ,
969 .Fn ifmaof_ifpforaddr
970 functions provide support for requesting and relinquishing multicast
971 group memberships, and for querying an interface's membership list,
972 respectively.
974 .Fn if_addmulti
975 function takes a pointer to an interface,
976 .Fa ifp ,
977 and a generic address,
978 .Fa sa .
979 It also takes a pointer to a
980 .Vt "struct ifmultiaddr *"
981 which is filled in on successful return with the address of the
982 group membership control block.
984 .Fn if_addmulti
985 function performs the following four-step process:
986 .Bl -enum -offset indent
988 Call the interface's
989 .Fn if_resolvemulti
990 entry point to determine the link-layer address, if any, corresponding
991 to this membership request, and also to give the link layer an
992 opportunity to veto this membership request should it so desire.
994 Check the interface's group membership list for a pre-existing
995 membership for this group.
996 If one is not found, allocate a new one;
997 if one is, increment its reference count.
999 If the
1000 .Fn if_resolvemulti
1001 routine returned a link-layer address corresponding to the group,
1002 repeat the previous step for that address as well.
1004 If the interface's multicast address filter needs to be changed
1005 because a new membership was added, call the interface's
1006 .Fn if_ioctl
1007 routine
1008 (with a
1009 .Fa cmd
1010 argument of
1011 .Dv SIOCADDMULTI )
1012 to request that it do so.
1016 .Fn if_delmulti
1017 function, given an interface
1018 .Fa ifp
1019 and an address,
1020 .Fa sa ,
1021 reverses this process.
1022 Both functions return zero on success, or a
1023 standard error number on failure.
1026 .Fn ifmaof_ifpforaddr
1027 function examines the membership list of interface
1028 .Fa ifp
1029 for an address matching
1030 .Fa addr ,
1031 and returns a pointer to that
1032 .Vt "struct ifmultiaddr"
1033 if one is found, else it returns a null pointer.
1034 .\" .Sh POLLING
1035 .\" XXX write me!
1036 .Sh SEE ALSO
1037 .Xr ioctl 2 ,
1038 .Xr link_addr 3 ,
1039 .Xr queue 3 ,
1040 .Xr sysctl 3 ,
1041 .Xr bpf 4 ,
1042 .Xr ifmib 4 ,
1043 .Xr lo 4 ,
1044 .Xr netintro 4 ,
1045 .Xr ppp 8 ,
1046 .\" .Xr mbuf 9 ,
1047 .Xr rtentry 9
1049 .%A Gary R. Wright
1050 .%A W. Richard Stevens
1051 .%B TCP/IP Illustrated
1052 .%V Vol. 2
1053 .%O Addison-Wesley, ISBN 0-201-63354-X
1055 .Sh AUTHORS
1056 This manual page was written by
1057 .An Garrett A. Wollman .