if.h revision 1.204 1 /* $NetBSD: if.h,v 1.204 2016/05/12 02:24:16 ozaki-r Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by William Studenmund and Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright (c) 1982, 1986, 1989, 1993
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)if.h 8.3 (Berkeley) 2/9/95
61 */
62
63 #ifndef _NET_IF_H_
64 #define _NET_IF_H_
65
66 #if !defined(_KERNEL) && !defined(_STANDALONE)
67 #include <stdbool.h>
68 #endif
69
70 #include <sys/featuretest.h>
71
72 /*
73 * Length of interface external name, including terminating '\0'.
74 * Note: this is the same size as a generic device's external name.
75 */
76 #define IF_NAMESIZE 16
77
78 #if defined(_NETBSD_SOURCE)
79
80 #include <sys/socket.h>
81 #include <sys/queue.h>
82 #include <sys/mutex.h>
83
84 #include <net/dlt.h>
85 #include <net/pfil.h>
86 #ifdef _KERNEL
87 #include <net/pktqueue.h>
88 #include <sys/pslist.h>
89 #include <sys/pserialize.h>
90 #include <sys/psref.h>
91 #endif
92
93 /*
94 * Always include ALTQ glue here -- we use the ALTQ interface queue
95 * structure even when ALTQ is not configured into the kernel so that
96 * the size of struct ifnet does not changed based on the option. The
97 * ALTQ queue structure is API-compatible with the legacy ifqueue.
98 */
99 #include <altq/if_altq.h>
100
101 /*
102 * Structures defining a network interface, providing a packet
103 * transport mechanism (ala level 0 of the PUP protocols).
104 *
105 * Each interface accepts output datagrams of a specified maximum
106 * length, and provides higher level routines with input datagrams
107 * received from its medium.
108 *
109 * Output occurs when the routine if_output is called, with four parameters:
110 * (*ifp->if_output)(ifp, m, dst, rt)
111 * Here m is the mbuf chain to be sent and dst is the destination address.
112 * The output routine encapsulates the supplied datagram if necessary,
113 * and then transmits it on its medium.
114 *
115 * On input, each interface unwraps the data received by it, and either
116 * places it on the input queue of a internetwork datagram routine
117 * and posts the associated software interrupt, or passes the datagram to a raw
118 * packet input routine.
119 *
120 * Routines exist for locating interfaces by their addresses
121 * or for locating a interface on a certain network, as well as more general
122 * routing and gateway routines maintaining information used to locate
123 * interfaces. These routines live in the files if.c and route.c
124 */
125 #include <sys/time.h>
126
127 #if defined(_KERNEL_OPT)
128 #include "opt_compat_netbsd.h"
129 #include "opt_gateway.h"
130 #endif
131
132 struct mbuf;
133 struct proc;
134 struct rtentry;
135 struct socket;
136 struct ether_header;
137 struct ifaddr;
138 struct ifnet;
139 struct rt_addrinfo;
140
141 #define IFNAMSIZ IF_NAMESIZE
142
143 /*
144 * Structure describing a `cloning' interface.
145 */
146 struct if_clone {
147 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
148 const char *ifc_name; /* name of device, e.g. `gif' */
149 size_t ifc_namelen; /* length of name */
150
151 int (*ifc_create)(struct if_clone *, int);
152 int (*ifc_destroy)(struct ifnet *);
153 };
154
155 #define IF_CLONE_INITIALIZER(name, create, destroy) \
156 { { NULL, NULL }, name, sizeof(name) - 1, create, destroy }
157
158 /*
159 * Structure used to query names of interface cloners.
160 */
161 struct if_clonereq {
162 int ifcr_total; /* total cloners (out) */
163 int ifcr_count; /* room for this many in user buffer */
164 char *ifcr_buffer; /* buffer for cloner names */
165 };
166
167 /*
168 * Structure defining statistics and other data kept regarding a network
169 * interface.
170 */
171 struct if_data {
172 /* generic interface information */
173 u_char ifi_type; /* ethernet, tokenring, etc. */
174 u_char ifi_addrlen; /* media address length */
175 u_char ifi_hdrlen; /* media header length */
176 int ifi_link_state; /* current link state */
177 uint64_t ifi_mtu; /* maximum transmission unit */
178 uint64_t ifi_metric; /* routing metric (external only) */
179 uint64_t ifi_baudrate; /* linespeed */
180 /* volatile statistics */
181 uint64_t ifi_ipackets; /* packets received on interface */
182 uint64_t ifi_ierrors; /* input errors on interface */
183 uint64_t ifi_opackets; /* packets sent on interface */
184 uint64_t ifi_oerrors; /* output errors on interface */
185 uint64_t ifi_collisions; /* collisions on csma interfaces */
186 uint64_t ifi_ibytes; /* total number of octets received */
187 uint64_t ifi_obytes; /* total number of octets sent */
188 uint64_t ifi_imcasts; /* packets received via multicast */
189 uint64_t ifi_omcasts; /* packets sent via multicast */
190 uint64_t ifi_iqdrops; /* dropped on input, this interface */
191 uint64_t ifi_noproto; /* destined for unsupported protocol */
192 struct timespec ifi_lastchange;/* last operational state change */
193 };
194
195 /*
196 * Values for if_link_state.
197 */
198 #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
199 #define LINK_STATE_DOWN 1 /* link is down */
200 #define LINK_STATE_UP 2 /* link is up */
201
202 /*
203 * Structure defining a queue for a network interface.
204 */
205 struct ifqueue {
206 struct mbuf *ifq_head;
207 struct mbuf *ifq_tail;
208 int ifq_len;
209 int ifq_maxlen;
210 int ifq_drops;
211 kmutex_t *ifq_lock;
212 };
213
214 struct ifnet_lock;
215
216 #ifdef _KERNEL
217 #include <sys/condvar.h>
218 #include <sys/percpu.h>
219 #include <sys/callout.h>
220 #include <sys/rwlock.h>
221
222 struct ifnet_lock {
223 kmutex_t il_lock; /* Protects the critical section. */
224 uint64_t il_nexit; /* Counts threads across all CPUs who
225 * have exited the critical section.
226 * Access to il_nexit is synchronized
227 * by il_lock.
228 */
229 percpu_t *il_nenter; /* Counts threads on each CPU who have
230 * entered or who wait to enter the
231 * critical section protected by il_lock.
232 * Synchronization is not required.
233 */
234 kcondvar_t il_emptied; /* The ifnet_lock user must arrange for
235 * the last threads in the critical
236 * section to signal this condition variable
237 * before they leave.
238 */
239 };
240 #endif /* _KERNEL */
241
242 /*
243 * Structure defining a queue for a network interface.
244 *
245 * (Would like to call this struct ``if'', but C isn't PL/1.)
246 */
247 TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
248
249 struct bridge_softc;
250 struct bridge_iflist;
251 struct callout;
252 struct krwlock;
253 struct if_percpuq;
254
255 typedef struct ifnet {
256 void *if_softc; /* lower-level data for this if */
257 /* DEPRECATED. Keep it to avoid breaking kvm(3) users */
258 TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
259 TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
260 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
261 int if_pcount; /* number of promiscuous listeners */
262 struct bpf_if *if_bpf; /* packet filter structure */
263 u_short if_index; /* numeric abbreviation for this if */
264 short if_timer; /* time 'til if_slowtimo called */
265 short if_flags; /* up/down, broadcast, etc. */
266 short if__pad1; /* be nice to m68k ports */
267 struct if_data if_data; /* statistics and other data about if */
268 /*
269 * Procedure handles. If you add more of these, don't forget the
270 * corresponding NULL stub in if.c.
271 */
272 int (*if_output) /* output routine (enqueue) */
273 (struct ifnet *, struct mbuf *, const struct sockaddr *,
274 const struct rtentry *);
275 void (*_if_input) /* input routine (from h/w driver) */
276 (struct ifnet *, struct mbuf *);
277 void (*if_start) /* initiate output routine */
278 (struct ifnet *);
279 int (*if_transmit) /* output routine (direct) */
280 (struct ifnet *, struct mbuf *);
281 int (*if_ioctl) /* ioctl routine */
282 (struct ifnet *, u_long, void *);
283 int (*if_init) /* init routine */
284 (struct ifnet *);
285 void (*if_stop) /* stop routine */
286 (struct ifnet *, int);
287 void (*if_slowtimo) /* timer routine */
288 (struct ifnet *);
289 #define if_watchdog if_slowtimo
290 void (*if_drain) /* routine to release resources */
291 (struct ifnet *);
292 struct ifaltq if_snd; /* output queue (includes altq) */
293 struct ifaddr *if_dl; /* identity of this interface. */
294 const struct sockaddr_dl *if_sadl; /* pointer to sockaddr_dl
295 * of if_dl
296 */
297 /* if_hwdl: h/w identity
298 *
299 * May be NULL. If not NULL, it is the address assigned
300 * to the interface by the manufacturer, so it very likely
301 * to be unique. It MUST NOT be deleted. It is highly
302 * suitable for deriving the EUI64 for the interface.
303 */
304 struct ifaddr *if_hwdl;
305 const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */
306 struct bridge_softc *if_bridge; /* bridge glue */
307 struct bridge_iflist *if_bridgeif; /* shortcut to interface list entry */
308 int if_dlt; /* data link type (<net/dlt.h>) */
309 pfil_head_t * if_pfil; /* filtering point */
310 uint64_t if_capabilities; /* interface capabilities */
311 uint64_t if_capenable; /* capabilities enabled */
312 union {
313 void * carp_s; /* carp structure (used by !carp ifs) */
314 struct ifnet *carp_d;/* ptr to carpdev (used by carp ifs) */
315 } if_carp_ptr;
316 #define if_carp if_carp_ptr.carp_s
317 #define if_carpdev if_carp_ptr.carp_d
318 /*
319 * These are pre-computed based on an interfaces enabled
320 * capabilities, for speed elsewhere.
321 */
322 int if_csum_flags_tx; /* M_CSUM_* flags for Tx */
323 int if_csum_flags_rx; /* M_CSUM_* flags for Rx */
324
325 void *if_afdata[AF_MAX];
326 struct mowner *if_mowner; /* who owns mbufs for this interface */
327
328 void *if_agrprivate; /* used only when #if NAGR > 0 */
329
330 /*
331 * pf specific data, used only when #if NPF > 0.
332 */
333 void *if_pf_kif; /* pf interface abstraction */
334 void *if_pf_groups; /* pf interface groups */
335 /*
336 * During an ifnet's lifetime, it has only one if_index, but
337 * and if_index is not sufficient to identify an ifnet
338 * because during the lifetime of the system, many ifnets may occupy a
339 * given if_index. Let us tell different ifnets at the same
340 * if_index apart by their if_index_gen, a unique number that each ifnet
341 * is assigned when it if_attach()s. Now, the kernel can use the
342 * pair (if_index, if_index_gen) as a weak reference to an ifnet.
343 */
344 uint64_t if_index_gen; /* generation number for the ifnet
345 * at if_index: if two ifnets' index
346 * and generation number are both the
347 * same, they are the same ifnet.
348 */
349 struct sysctllog *if_sysctl_log;
350 int (*if_initaddr)(struct ifnet *, struct ifaddr *, bool);
351 int (*if_mcastop)(struct ifnet *, const unsigned long,
352 const struct sockaddr *);
353 int (*if_setflags)(struct ifnet *, const short);
354 struct ifnet_lock *if_ioctl_lock;
355 #ifdef _KERNEL /* XXX kvm(3) */
356 struct callout *if_slowtimo_ch;
357 struct krwlock *if_afdata_lock;
358 struct if_percpuq *if_percpuq; /* We should remove it in the future */
359 void *if_link_si; /* softint to handle link state changes */
360 uint16_t if_link_queue; /* masked link state change queue */
361 struct pslist_entry if_pslist_entry;
362 struct psref_target if_psref;
363 #endif
364 } ifnet_t;
365
366 #define if_mtu if_data.ifi_mtu
367 #define if_type if_data.ifi_type
368 #define if_addrlen if_data.ifi_addrlen
369 #define if_hdrlen if_data.ifi_hdrlen
370 #define if_metric if_data.ifi_metric
371 #define if_link_state if_data.ifi_link_state
372 #define if_baudrate if_data.ifi_baudrate
373 #define if_ipackets if_data.ifi_ipackets
374 #define if_ierrors if_data.ifi_ierrors
375 #define if_opackets if_data.ifi_opackets
376 #define if_oerrors if_data.ifi_oerrors
377 #define if_collisions if_data.ifi_collisions
378 #define if_ibytes if_data.ifi_ibytes
379 #define if_obytes if_data.ifi_obytes
380 #define if_imcasts if_data.ifi_imcasts
381 #define if_omcasts if_data.ifi_omcasts
382 #define if_iqdrops if_data.ifi_iqdrops
383 #define if_noproto if_data.ifi_noproto
384 #define if_lastchange if_data.ifi_lastchange
385
386 #define IFF_UP 0x0001 /* interface is up */
387 #define IFF_BROADCAST 0x0002 /* broadcast address valid */
388 #define IFF_DEBUG 0x0004 /* turn on debugging */
389 #define IFF_LOOPBACK 0x0008 /* is a loopback net */
390 #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */
391 #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */
392 #define IFF_RUNNING 0x0040 /* resources allocated */
393 #define IFF_NOARP 0x0080 /* no address resolution protocol */
394 #define IFF_PROMISC 0x0100 /* receive all packets */
395 #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
396 #define IFF_OACTIVE 0x0400 /* transmission in progress */
397 #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */
398 #define IFF_LINK0 0x1000 /* per link layer defined bit */
399 #define IFF_LINK1 0x2000 /* per link layer defined bit */
400 #define IFF_LINK2 0x4000 /* per link layer defined bit */
401 #define IFF_MULTICAST 0x8000 /* supports multicast */
402
403 #define IFFBITS \
404 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \
405 "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \
406 "\15LINK0\16LINK1\17LINK2\20MULTICAST"
407
408 /* flags set internally only: */
409 #define IFF_CANTCHANGE \
410 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
411 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC)
412
413 /*
414 * Some convenience macros used for setting ifi_baudrate.
415 */
416 #define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */
417 #define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */
418 #define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */
419
420 /* Capabilities that interfaces can advertise. */
421 /* 0x01 .. 0x40 were previously used */
422 #define IFCAP_TSOv4 0x00080 /* can do TCPv4 segmentation offload */
423 #define IFCAP_CSUM_IPv4_Rx 0x00100 /* can do IPv4 header checksums (Rx) */
424 #define IFCAP_CSUM_IPv4_Tx 0x00200 /* can do IPv4 header checksums (Tx) */
425 #define IFCAP_CSUM_TCPv4_Rx 0x00400 /* can do IPv4/TCP checksums (Rx) */
426 #define IFCAP_CSUM_TCPv4_Tx 0x00800 /* can do IPv4/TCP checksums (Tx) */
427 #define IFCAP_CSUM_UDPv4_Rx 0x01000 /* can do IPv4/UDP checksums (Rx) */
428 #define IFCAP_CSUM_UDPv4_Tx 0x02000 /* can do IPv4/UDP checksums (Tx) */
429 #define IFCAP_CSUM_TCPv6_Rx 0x04000 /* can do IPv6/TCP checksums (Rx) */
430 #define IFCAP_CSUM_TCPv6_Tx 0x08000 /* can do IPv6/TCP checksums (Tx) */
431 #define IFCAP_CSUM_UDPv6_Rx 0x10000 /* can do IPv6/UDP checksums (Rx) */
432 #define IFCAP_CSUM_UDPv6_Tx 0x20000 /* can do IPv6/UDP checksums (Tx) */
433 #define IFCAP_TSOv6 0x40000 /* can do TCPv6 segmentation offload */
434 #define IFCAP_LRO 0x80000 /* can do Large Receive Offload */
435 #define IFCAP_MASK 0xfff80 /* currently valid capabilities */
436
437 #define IFCAPBITS \
438 "\020" \
439 "\10TSO4" \
440 "\11IP4CSUM_Rx" \
441 "\12IP4CSUM_Tx" \
442 "\13TCP4CSUM_Rx" \
443 "\14TCP4CSUM_Tx" \
444 "\15UDP4CSUM_Rx" \
445 "\16UDP4CSUM_Tx" \
446 "\17TCP6CSUM_Rx" \
447 "\20TCP6CSUM_Tx" \
448 "\21UDP6CSUM_Rx" \
449 "\22UDP6CSUM_Tx" \
450 "\23TSO6" \
451 "\24LRO" \
452
453 #define IF_AFDATA_LOCK_INIT(ifp) \
454 do {(ifp)->if_afdata_lock = rw_obj_alloc();} while (0)
455
456 #define IF_AFDATA_LOCK_DESTROY(ifp) rw_obj_free((ifp)->if_afdata_lock)
457
458 #define IF_AFDATA_WLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_WRITER)
459 #define IF_AFDATA_RLOCK(ifp) rw_enter((ifp)->if_afdata_lock, RW_READER)
460 #define IF_AFDATA_WUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
461 #define IF_AFDATA_RUNLOCK(ifp) rw_exit((ifp)->if_afdata_lock)
462 #define IF_AFDATA_LOCK(ifp) IF_AFDATA_WLOCK(ifp)
463 #define IF_AFDATA_UNLOCK(ifp) IF_AFDATA_WUNLOCK(ifp)
464 #define IF_AFDATA_TRYLOCK(ifp) rw_tryenter((ifp)->if_afdata_lock, RW_WRITER)
465
466 #define IF_AFDATA_LOCK_ASSERT(ifp) \
467 KASSERT(rw_lock_held((ifp)->if_afdata_lock))
468 #define IF_AFDATA_RLOCK_ASSERT(ifp) \
469 KASSERT(rw_read_held((ifp)->if_afdata_lock))
470 #define IF_AFDATA_WLOCK_ASSERT(ifp) \
471 KASSERT(rw_write_held((ifp)->if_afdata_lock))
472 #define IF_AFDATA_UNLOCK_ASSERT(ifp) \
473 KASSERT(!rw_lock_held((ifp)->if_afdata_lock))
474
475 #define IFQ_LOCK(_ifq) if ((_ifq)->ifq_lock) mutex_enter((_ifq)->ifq_lock)
476 #define IFQ_UNLOCK(_ifq) if ((_ifq)->ifq_lock) mutex_exit((_ifq)->ifq_lock)
477
478 /*
479 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
480 * input routines have queues of messages stored on ifqueue structures
481 * (defined above). Entries are added to and deleted from these structures
482 * by these macros, which should be called with ipl raised to splnet().
483 */
484 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
485 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
486 #define IF_ENQUEUE(ifq, m) do { \
487 (m)->m_nextpkt = 0; \
488 if ((ifq)->ifq_tail == 0) \
489 (ifq)->ifq_head = m; \
490 else \
491 (ifq)->ifq_tail->m_nextpkt = m; \
492 (ifq)->ifq_tail = m; \
493 (ifq)->ifq_len++; \
494 } while (/*CONSTCOND*/0)
495 #define IF_PREPEND(ifq, m) do { \
496 (m)->m_nextpkt = (ifq)->ifq_head; \
497 if ((ifq)->ifq_tail == 0) \
498 (ifq)->ifq_tail = (m); \
499 (ifq)->ifq_head = (m); \
500 (ifq)->ifq_len++; \
501 } while (/*CONSTCOND*/0)
502 #define IF_DEQUEUE(ifq, m) do { \
503 (m) = (ifq)->ifq_head; \
504 if (m) { \
505 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
506 (ifq)->ifq_tail = 0; \
507 (m)->m_nextpkt = 0; \
508 (ifq)->ifq_len--; \
509 } \
510 } while (/*CONSTCOND*/0)
511 #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
512 #define IF_PURGE(ifq) \
513 do { \
514 struct mbuf *__m0; \
515 \
516 for (;;) { \
517 IF_DEQUEUE((ifq), __m0); \
518 if (__m0 == NULL) \
519 break; \
520 else \
521 m_freem(__m0); \
522 } \
523 } while (/*CONSTCOND*/ 0)
524 #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
525
526 #ifndef IFQ_MAXLEN
527 #define IFQ_MAXLEN 256
528 #endif
529 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
530
531 /*
532 * Structure defining statistics and other data kept regarding an address
533 * on a network interface.
534 */
535 struct ifaddr_data {
536 int64_t ifad_inbytes;
537 int64_t ifad_outbytes;
538 };
539
540 /*
541 * The ifaddr structure contains information about one address
542 * of an interface. They are maintained by the different address families,
543 * are allocated and attached when an address is set, and are linked
544 * together so all addresses for an interface can be located.
545 */
546 struct ifaddr {
547 struct sockaddr *ifa_addr; /* address of interface */
548 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
549 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
550 struct sockaddr *ifa_netmask; /* used to determine subnet */
551 struct ifnet *ifa_ifp; /* back-pointer to interface */
552 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
553 struct ifaddr_data ifa_data; /* statistics on the address */
554 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
555 (int, struct rtentry *, const struct rt_addrinfo *);
556 u_int ifa_flags; /* mostly rt_flags for cloning */
557 int ifa_refcnt; /* count of references */
558 int ifa_metric; /* cost of going out this interface */
559 struct ifaddr *(*ifa_getifa)(struct ifaddr *,
560 const struct sockaddr *);
561 uint32_t *ifa_seqno;
562 int16_t ifa_preference; /* preference level for this address */
563 };
564 #define IFA_ROUTE RTF_UP /* (0x01) route installed */
565
566 /*
567 * Message format for use in obtaining information about interfaces from
568 * sysctl and the routing socket. We need to force 64-bit alignment if we
569 * aren't using compatiblity definitons.
570 */
571 #if !defined(_KERNEL) || !defined(COMPAT_RTSOCK)
572 #define __align64 __aligned(sizeof(uint64_t))
573 #else
574 #define __align64
575 #endif
576 struct if_msghdr {
577 u_short ifm_msglen __align64;
578 /* to skip over non-understood messages */
579 u_char ifm_version; /* future binary compatibility */
580 u_char ifm_type; /* message type */
581 int ifm_addrs; /* like rtm_addrs */
582 int ifm_flags; /* value of if_flags */
583 u_short ifm_index; /* index for associated ifp */
584 struct if_data ifm_data __align64;
585 /* statistics and other data about if */
586 };
587
588 /*
589 * Message format for use in obtaining information about interface addresses
590 * from sysctl and the routing socket.
591 */
592 struct ifa_msghdr {
593 u_short ifam_msglen __align64;
594 /* to skip over non-understood messages */
595 u_char ifam_version; /* future binary compatibility */
596 u_char ifam_type; /* message type */
597 int ifam_addrs; /* like rtm_addrs */
598 int ifam_flags; /* value of ifa_flags */
599 int ifam_metric; /* value of ifa_metric */
600 u_short ifam_index; /* index for associated ifp */
601 };
602
603 /*
604 * Message format announcing the arrival or departure of a network interface.
605 */
606 struct if_announcemsghdr {
607 u_short ifan_msglen __align64;
608 /* to skip over non-understood messages */
609 u_char ifan_version; /* future binary compatibility */
610 u_char ifan_type; /* message type */
611 u_short ifan_index; /* index for associated ifp */
612 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
613 u_short ifan_what; /* what type of announcement */
614 };
615
616 #define IFAN_ARRIVAL 0 /* interface arrival */
617 #define IFAN_DEPARTURE 1 /* interface departure */
618
619 #undef __align64
620
621 /*
622 * Interface request structure used for socket
623 * ioctl's. All interface ioctl's must have parameter
624 * definitions which begin with ifr_name. The
625 * remainder may be interface specific.
626 */
627 struct ifreq {
628 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
629 union {
630 struct sockaddr ifru_addr;
631 struct sockaddr ifru_dstaddr;
632 struct sockaddr ifru_broadaddr;
633 struct sockaddr_storage ifru_space;
634 short ifru_flags;
635 int ifru_addrflags;
636 int ifru_metric;
637 int ifru_mtu;
638 int ifru_dlt;
639 u_int ifru_value;
640 void * ifru_data;
641 struct {
642 uint32_t b_buflen;
643 void *b_buf;
644 } ifru_b;
645 } ifr_ifru;
646 #define ifr_addr ifr_ifru.ifru_addr /* address */
647 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
648 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
649 #define ifr_space ifr_ifru.ifru_space /* sockaddr_storage */
650 #define ifr_flags ifr_ifru.ifru_flags /* flags */
651 #define ifr_addrflags ifr_ifru.ifru_addrflags /* addr flags */
652 #define ifr_metric ifr_ifru.ifru_metric /* metric */
653 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
654 #define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */
655 #define ifr_value ifr_ifru.ifru_value /* generic value */
656 #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
657 #define ifr_data ifr_ifru.ifru_data /* for use by interface
658 * XXX deprecated
659 */
660 #define ifr_buf ifr_ifru.ifru_b.b_buf /* new interface ioctls */
661 #define ifr_buflen ifr_ifru.ifru_b.b_buflen
662 #define ifr_index ifr_ifru.ifru_value /* interface index, BSD */
663 #define ifr_ifindex ifr_index /* interface index, linux */
664 };
665
666 #ifdef _KERNEL
667 #define ifreq_setdstaddr ifreq_setaddr
668 #define ifreq_setbroadaddr ifreq_setaddr
669 #define ifreq_getdstaddr ifreq_getaddr
670 #define ifreq_getbroadaddr ifreq_getaddr
671
672 static inline const struct sockaddr *
673 /*ARGSUSED*/
674 ifreq_getaddr(u_long cmd, const struct ifreq *ifr)
675 {
676 return &ifr->ifr_addr;
677 }
678 #endif /* _KERNEL */
679
680 struct ifcapreq {
681 char ifcr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
682 uint64_t ifcr_capabilities; /* supported capabiliites */
683 uint64_t ifcr_capenable; /* capabilities enabled */
684 };
685
686 struct ifaliasreq {
687 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
688 struct sockaddr ifra_addr;
689 struct sockaddr ifra_dstaddr;
690 #define ifra_broadaddr ifra_dstaddr
691 struct sockaddr ifra_mask;
692 };
693
694 struct ifdatareq {
695 char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
696 struct if_data ifdr_data;
697 };
698
699 struct ifmediareq {
700 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
701 int ifm_current; /* current media options */
702 int ifm_mask; /* don't care mask */
703 int ifm_status; /* media status */
704 int ifm_active; /* active options */
705 int ifm_count; /* # entries in ifm_ulist
706 array */
707 int *ifm_ulist; /* media words */
708 };
709
710
711 struct ifdrv {
712 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
713 unsigned long ifd_cmd;
714 size_t ifd_len;
715 void *ifd_data;
716 };
717 #define IFLINKSTR_QUERYLEN 0x01
718 #define IFLINKSTR_UNSET 0x02
719
720 /*
721 * Structure used in SIOCGIFCONF request.
722 * Used to retrieve interface configuration
723 * for machine (useful for programs which
724 * must know all networks accessible).
725 */
726 struct ifconf {
727 int ifc_len; /* size of associated buffer */
728 union {
729 void * ifcu_buf;
730 struct ifreq *ifcu_req;
731 } ifc_ifcu;
732 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
733 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
734 };
735
736 /*
737 * Structure for SIOC[AGD]LIFADDR
738 */
739 struct if_laddrreq {
740 char iflr_name[IFNAMSIZ];
741 unsigned int flags;
742 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
743 #define IFLR_ACTIVE 0x4000 /* in/out: link-layer address activation */
744 #define IFLR_FACTORY 0x2000 /* in/out: factory link-layer address */
745 unsigned int prefixlen; /* in/out */
746 struct sockaddr_storage addr; /* in/out */
747 struct sockaddr_storage dstaddr; /* out */
748 };
749
750 /*
751 * Structure for SIOC[SG]IFADDRPREF
752 */
753 struct if_addrprefreq {
754 char ifap_name[IFNAMSIZ];
755 int16_t ifap_preference; /* in/out */
756 struct sockaddr_storage ifap_addr; /* in/out */
757 };
758
759 #include <net/if_arp.h>
760
761 #endif /* _NETBSD_SOURCE */
762
763 #ifdef _KERNEL
764 #ifdef ALTQ
765 #define IFQ_ENQUEUE(ifq, m, err) \
766 do { \
767 IFQ_LOCK((ifq)); \
768 if (ALTQ_IS_ENABLED((ifq))) \
769 ALTQ_ENQUEUE((ifq), (m), (err)); \
770 else { \
771 if (IF_QFULL((ifq))) { \
772 m_freem((m)); \
773 (err) = ENOBUFS; \
774 } else { \
775 IF_ENQUEUE((ifq), (m)); \
776 (err) = 0; \
777 } \
778 } \
779 if ((err)) \
780 (ifq)->ifq_drops++; \
781 IFQ_UNLOCK((ifq)); \
782 } while (/*CONSTCOND*/ 0)
783
784 #define IFQ_DEQUEUE(ifq, m) \
785 do { \
786 IFQ_LOCK((ifq)); \
787 if (TBR_IS_ENABLED((ifq))) \
788 (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \
789 else if (ALTQ_IS_ENABLED((ifq))) \
790 ALTQ_DEQUEUE((ifq), (m)); \
791 else \
792 IF_DEQUEUE((ifq), (m)); \
793 IFQ_UNLOCK((ifq)); \
794 } while (/*CONSTCOND*/ 0)
795
796 #define IFQ_POLL(ifq, m) \
797 do { \
798 IFQ_LOCK((ifq)); \
799 if (TBR_IS_ENABLED((ifq))) \
800 (m) = tbr_dequeue((ifq), ALTDQ_POLL); \
801 else if (ALTQ_IS_ENABLED((ifq))) \
802 ALTQ_POLL((ifq), (m)); \
803 else \
804 IF_POLL((ifq), (m)); \
805 IFQ_UNLOCK((ifq)); \
806 } while (/*CONSTCOND*/ 0)
807
808 #define IFQ_PURGE(ifq) \
809 do { \
810 IFQ_LOCK((ifq)); \
811 if (ALTQ_IS_ENABLED((ifq))) \
812 ALTQ_PURGE((ifq)); \
813 else \
814 IF_PURGE((ifq)); \
815 IFQ_UNLOCK((ifq)); \
816 } while (/*CONSTCOND*/ 0)
817
818 #define IFQ_SET_READY(ifq) \
819 do { \
820 (ifq)->altq_flags |= ALTQF_READY; \
821 } while (/*CONSTCOND*/ 0)
822
823 #define IFQ_CLASSIFY(ifq, m, af) \
824 do { \
825 IFQ_LOCK((ifq)); \
826 if (ALTQ_IS_ENABLED((ifq))) { \
827 if (ALTQ_NEEDS_CLASSIFY((ifq))) \
828 m->m_pkthdr.pattr_class = (*(ifq)->altq_classify) \
829 ((ifq)->altq_clfier, (m), (af)); \
830 m->m_pkthdr.pattr_af = (af); \
831 m->m_pkthdr.pattr_hdr = mtod((m), void *); \
832 } \
833 IFQ_UNLOCK((ifq)); \
834 } while (/*CONSTCOND*/ 0)
835 #else /* ! ALTQ */
836 #define IFQ_ENQUEUE(ifq, m, err) \
837 do { \
838 IFQ_LOCK((ifq)); \
839 if (IF_QFULL((ifq))) { \
840 m_freem((m)); \
841 (err) = ENOBUFS; \
842 } else { \
843 IF_ENQUEUE((ifq), (m)); \
844 (err) = 0; \
845 } \
846 if ((err)) \
847 (ifq)->ifq_drops++; \
848 IFQ_UNLOCK((ifq)); \
849 } while (/*CONSTCOND*/ 0)
850
851 #define IFQ_DEQUEUE(ifq, m) \
852 do { \
853 IFQ_LOCK((ifq)); \
854 IF_DEQUEUE((ifq), (m)); \
855 IFQ_UNLOCK((ifq)); \
856 } while (/*CONSTCOND*/ 0)
857
858 #define IFQ_POLL(ifq, m) \
859 do { \
860 IFQ_LOCK((ifq)); \
861 IF_POLL((ifq), (m)); \
862 IFQ_UNLOCK((ifq)); \
863 } while (/*CONSTCOND*/ 0)
864
865 #define IFQ_PURGE(ifq) \
866 do { \
867 IFQ_LOCK((ifq)); \
868 IF_PURGE((ifq)); \
869 IFQ_UNLOCK((ifq)); \
870 } while (/*CONSTCOND*/ 0)
871
872 #define IFQ_SET_READY(ifq) /* nothing */
873
874 #define IFQ_CLASSIFY(ifq, m, af) /* nothing */
875
876 #endif /* ALTQ */
877
878 #define IFQ_IS_EMPTY(ifq) IF_IS_EMPTY((ifq))
879 #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
880 #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
881 #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
882 #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
883
884 #include <sys/mallocvar.h>
885 MALLOC_DECLARE(M_IFADDR);
886 MALLOC_DECLARE(M_IFMADDR);
887
888 int ifreq_setaddr(u_long, struct ifreq *, const struct sockaddr *);
889
890 struct ifnet *if_alloc(u_char);
891 void if_free(struct ifnet *);
892 void if_initname(struct ifnet *, const char *, int);
893 struct ifaddr *if_dl_create(const struct ifnet *, const struct sockaddr_dl **);
894 void if_activate_sadl(struct ifnet *, struct ifaddr *,
895 const struct sockaddr_dl *);
896 void if_set_sadl(struct ifnet *, const void *, u_char, bool);
897 void if_alloc_sadl(struct ifnet *);
898 void if_initialize(struct ifnet *);
899 void if_register(struct ifnet *);
900 void if_attach(struct ifnet *); /* Deprecated. Use if_initialize and if_register */
901 void if_attachdomain(void);
902 void if_deactivate(struct ifnet *);
903 void if_purgeaddrs(struct ifnet *, int, void (*)(struct ifaddr *));
904 void if_detach(struct ifnet *);
905 void if_down(struct ifnet *);
906 void if_link_state_change(struct ifnet *, int);
907 void if_up(struct ifnet *);
908 void ifinit(void);
909 void ifinit1(void);
910 int ifaddrpref_ioctl(struct socket *, u_long, void *, struct ifnet *);
911 extern int (*ifioctl)(struct socket *, u_long, void *, struct lwp *);
912 int ifioctl_common(struct ifnet *, u_long, void *);
913 int ifpromisc(struct ifnet *, int);
914 struct ifnet *ifunit(const char *);
915 int if_addr_init(ifnet_t *, struct ifaddr *, bool);
916 int if_do_dad(struct ifnet *);
917 int if_mcast_op(ifnet_t *, const unsigned long, const struct sockaddr *);
918 int if_flags_set(struct ifnet *, const short);
919 int if_clone_list(int, char *, int *);
920
921 void if_input(struct ifnet *, struct mbuf *);
922
923 struct if_percpuq *
924 if_percpuq_create(struct ifnet *);
925 void if_percpuq_destroy(struct if_percpuq *);
926 void
927 if_percpuq_enqueue(struct if_percpuq *, struct mbuf *);
928
929 void ifa_insert(struct ifnet *, struct ifaddr *);
930 void ifa_remove(struct ifnet *, struct ifaddr *);
931
932 void ifaref(struct ifaddr *);
933 void ifafree(struct ifaddr *);
934
935 struct ifaddr *ifa_ifwithaddr(const struct sockaddr *);
936 struct ifaddr *ifa_ifwithaf(int);
937 struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *);
938 struct ifaddr *ifa_ifwithnet(const struct sockaddr *);
939 struct ifaddr *ifa_ifwithladdr(const struct sockaddr *);
940 struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *,
941 const struct sockaddr *);
942 struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *);
943 void ifafree(struct ifaddr *);
944 void link_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
945 void p2p_rtrequest(int, struct rtentry *, const struct rt_addrinfo *);
946
947 void if_clone_attach(struct if_clone *);
948 void if_clone_detach(struct if_clone *);
949
950 int if_transmit(struct ifnet *, struct mbuf *);
951
952 int ifq_enqueue(struct ifnet *, struct mbuf *);
953 int ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf *);
954
955 int loioctl(struct ifnet *, u_long, void *);
956 void loopattach(int);
957 int looutput(struct ifnet *,
958 struct mbuf *, const struct sockaddr *, const struct rtentry *);
959 void lortrequest(int, struct rtentry *, const struct rt_addrinfo *);
960
961 /*
962 * These are exported because they're an easy way to tell if
963 * an interface is going away without having to burn a flag.
964 */
965 int if_nulloutput(struct ifnet *, struct mbuf *,
966 const struct sockaddr *, const struct rtentry *);
967 void if_nullinput(struct ifnet *, struct mbuf *);
968 void if_nullstart(struct ifnet *);
969 int if_nulltransmit(struct ifnet *, struct mbuf *);
970 int if_nullioctl(struct ifnet *, u_long, void *);
971 int if_nullinit(struct ifnet *);
972 void if_nullstop(struct ifnet *, int);
973 void if_nullslowtimo(struct ifnet *);
974 #define if_nullwatchdog if_nullslowtimo
975 void if_nulldrain(struct ifnet *);
976 #else
977 struct if_nameindex {
978 unsigned int if_index; /* 1, 2, ... */
979 char *if_name; /* null terminated name: "le0", ... */
980 };
981
982 #include <sys/cdefs.h>
983 __BEGIN_DECLS
984 unsigned int if_nametoindex(const char *);
985 char * if_indextoname(unsigned int, char *);
986 struct if_nameindex * if_nameindex(void);
987 void if_freenameindex(struct if_nameindex *);
988 __END_DECLS
989 #endif /* _KERNEL */ /* XXX really ALTQ? */
990
991 #ifdef _KERNEL
992
993 #define IFADDR_FIRST(__ifp) TAILQ_FIRST(&(__ifp)->if_addrlist)
994 #define IFADDR_NEXT(__ifa) TAILQ_NEXT((__ifa), ifa_list)
995 #define IFADDR_FOREACH(__ifa, __ifp) TAILQ_FOREACH(__ifa, \
996 &(__ifp)->if_addrlist, ifa_list)
997 #define IFADDR_FOREACH_SAFE(__ifa, __ifp, __nifa) \
998 TAILQ_FOREACH_SAFE(__ifa, \
999 &(__ifp)->if_addrlist, ifa_list, __nifa)
1000 #define IFADDR_EMPTY(__ifp) TAILQ_EMPTY(&(__ifp)->if_addrlist)
1001
1002 #define IFNET_LOCK() mutex_enter(&ifnet_mtx)
1003 #define IFNET_UNLOCK() mutex_exit(&ifnet_mtx)
1004 #define IFNET_LOCKED() mutex_owned(&ifnet_mtx)
1005
1006 #define IFNET_READER_EMPTY() \
1007 (PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) == NULL)
1008 #define IFNET_READER_FIRST() \
1009 PSLIST_READER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry)
1010 #define IFNET_READER_NEXT(__ifp) \
1011 PSLIST_READER_NEXT((__ifp), struct ifnet, if_pslist_entry)
1012 #define IFNET_READER_FOREACH(__ifp) \
1013 PSLIST_READER_FOREACH((__ifp), &ifnet_pslist, struct ifnet, \
1014 if_pslist_entry)
1015 #define IFNET_WRITER_INSERT_HEAD(__ifp) \
1016 PSLIST_WRITER_INSERT_HEAD(&ifnet_pslist, (__ifp), if_pslist_entry)
1017 #define IFNET_WRITER_REMOVE(__ifp) \
1018 PSLIST_WRITER_REMOVE((__ifp), if_pslist_entry)
1019 #define IFNET_WRITER_FOREACH(__ifp) \
1020 PSLIST_WRITER_FOREACH((__ifp), &ifnet_pslist, struct ifnet, \
1021 if_pslist_entry)
1022 #define IFNET_WRITER_NEXT(__ifp) \
1023 PSLIST_WRITER_NEXT((__ifp), struct ifnet, if_pslist_entry)
1024 #define IFNET_WRITER_INSERT_AFTER(__ifp, __new) \
1025 PSLIST_WRITER_INSERT_AFTER((__ifp), (__new), if_pslist_entry)
1026 #define IFNET_WRITER_EMPTY() \
1027 (PSLIST_WRITER_FIRST(&ifnet_pslist, struct ifnet, if_pslist_entry) == NULL)
1028 #define IFNET_WRITER_INSERT_TAIL(__new) \
1029 do { \
1030 if (IFNET_WRITER_EMPTY()) { \
1031 IFNET_WRITER_INSERT_HEAD((__new)); \
1032 } else { \
1033 struct ifnet *__ifp; \
1034 IFNET_WRITER_FOREACH(__ifp) { \
1035 if (IFNET_WRITER_NEXT(__ifp) == NULL) { \
1036 IFNET_WRITER_INSERT_AFTER(__ifp,\
1037 (__new)); \
1038 break; \
1039 } \
1040 } \
1041 } \
1042 } while (0)
1043
1044 extern struct pslist_head ifnet_pslist;
1045 extern struct psref_class *ifnet_psref_class;
1046 extern kmutex_t ifnet_mtx;
1047
1048 extern struct ifnet *lo0ifp;
1049
1050 ifnet_t * if_byindex(u_int);
1051
1052 /*
1053 * ifq sysctl support
1054 */
1055 int sysctl_ifq(int *name, u_int namelen, void *oldp,
1056 size_t *oldlenp, void *newp, size_t newlen,
1057 struct ifqueue *ifq);
1058 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
1059 #define IFQCTL_LEN 1
1060 #define IFQCTL_MAXLEN 2
1061 #define IFQCTL_PEAK 3
1062 #define IFQCTL_DROPS 4
1063 #define IFQCTL_MAXID 5
1064
1065 #endif /* _KERNEL */
1066
1067 #ifdef _NETBSD_SOURCE
1068 /*
1069 * sysctl for ifq (per-protocol packet input queue variant of ifqueue)
1070 */
1071 #define CTL_IFQ_NAMES { \
1072 { 0, 0 }, \
1073 { "len", CTLTYPE_INT }, \
1074 { "maxlen", CTLTYPE_INT }, \
1075 { "peak", CTLTYPE_INT }, \
1076 { "drops", CTLTYPE_INT }, \
1077 }
1078 #endif /* _NETBSD_SOURCE */
1079 #endif /* !_NET_IF_H_ */
1080