if.h revision 1.107 1 /* $NetBSD: if.h,v 1.107 2005/03/31 15:48:13 christos 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1982, 1986, 1989, 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 *
67 * @(#)if.h 8.3 (Berkeley) 2/9/95
68 */
69
70 #ifndef _NET_IF_H_
71 #define _NET_IF_H_
72
73 #include <sys/featuretest.h>
74
75 /*
76 * Length of interface external name, including terminating '\0'.
77 * Note: this is the same size as a generic device's external name.
78 */
79 #define IF_NAMESIZE 16
80
81 #if defined(_NETBSD_SOURCE)
82
83 #include <sys/socket.h>
84 #include <sys/queue.h>
85 #include <net/dlt.h>
86 #include <net/pfil.h>
87
88 /*
89 * Always include ALTQ glue here -- we use the ALTQ interface queue
90 * structure even when ALTQ is not configured into the kernel so that
91 * the size of struct ifnet does not changed based on the option. The
92 * ALTQ queue structure is API-compatible with the legacy ifqueue.
93 */
94 #include <altq/if_altq.h>
95
96 /*
97 * Structures defining a network interface, providing a packet
98 * transport mechanism (ala level 0 of the PUP protocols).
99 *
100 * Each interface accepts output datagrams of a specified maximum
101 * length, and provides higher level routines with input datagrams
102 * received from its medium.
103 *
104 * Output occurs when the routine if_output is called, with four parameters:
105 * (*ifp->if_output)(ifp, m, dst, rt)
106 * Here m is the mbuf chain to be sent and dst is the destination address.
107 * The output routine encapsulates the supplied datagram if necessary,
108 * and then transmits it on its medium.
109 *
110 * On input, each interface unwraps the data received by it, and either
111 * places it on the input queue of a internetwork datagram routine
112 * and posts the associated software interrupt, or passes the datagram to a raw
113 * packet input routine.
114 *
115 * Routines exist for locating interfaces by their addresses
116 * or for locating a interface on a certain network, as well as more general
117 * routing and gateway routines maintaining information used to locate
118 * interfaces. These routines live in the files if.c and route.c
119 */
120 /* XXX fast fix for SNMP, going away soon */
121 #include <sys/time.h>
122
123 #if defined(_KERNEL_OPT)
124 #include "opt_compat_netbsd.h"
125 #include "agr.h"
126 #endif
127
128 struct mbuf;
129 struct proc;
130 struct rtentry;
131 struct socket;
132 struct ether_header;
133 struct ifnet;
134 struct rt_addrinfo;
135
136 #define IFNAMSIZ IF_NAMESIZE
137
138 /*
139 * Structure describing a `cloning' interface.
140 */
141 struct if_clone {
142 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
143 const char *ifc_name; /* name of device, e.g. `gif' */
144 size_t ifc_namelen; /* length of name */
145
146 int (*ifc_create)(struct if_clone *, int);
147 int (*ifc_destroy)(struct ifnet *);
148 };
149
150 #define IF_CLONE_INITIALIZER(name, create, destroy) \
151 { { 0 }, name, sizeof(name) - 1, create, destroy }
152
153 /*
154 * Structure used to query names of interface cloners.
155 */
156 struct if_clonereq {
157 int ifcr_total; /* total cloners (out) */
158 int ifcr_count; /* room for this many in user buffer */
159 char *ifcr_buffer; /* buffer for cloner names */
160 };
161
162 /*
163 * Structure defining statistics and other data kept regarding a network
164 * interface.
165 */
166 struct if_data {
167 /* generic interface information */
168 u_char ifi_type; /* ethernet, tokenring, etc. */
169 u_char ifi_addrlen; /* media address length */
170 u_char ifi_hdrlen; /* media header length */
171 int ifi_link_state; /* current link state */
172 u_quad_t ifi_mtu; /* maximum transmission unit */
173 u_quad_t ifi_metric; /* routing metric (external only) */
174 u_quad_t ifi_baudrate; /* linespeed */
175 /* volatile statistics */
176 u_quad_t ifi_ipackets; /* packets received on interface */
177 u_quad_t ifi_ierrors; /* input errors on interface */
178 u_quad_t ifi_opackets; /* packets sent on interface */
179 u_quad_t ifi_oerrors; /* output errors on interface */
180 u_quad_t ifi_collisions; /* collisions on csma interfaces */
181 u_quad_t ifi_ibytes; /* total number of octets received */
182 u_quad_t ifi_obytes; /* total number of octets sent */
183 u_quad_t ifi_imcasts; /* packets received via multicast */
184 u_quad_t ifi_omcasts; /* packets sent via multicast */
185 u_quad_t ifi_iqdrops; /* dropped on input, this interface */
186 u_quad_t ifi_noproto; /* destined for unsupported protocol */
187 struct timeval ifi_lastchange; /* last operational state change */
188 };
189
190 /*
191 * Values for if_link_state.
192 */
193 #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
194 #define LINK_STATE_DOWN 1 /* link is down */
195 #define LINK_STATE_UP 2 /* link is up */
196
197 #if defined(_KERNEL) && defined(COMPAT_14)
198 /* Pre-1.5 if_data struct */
199 struct if_data14 {
200 /* generic interface information */
201 u_char ifi_type; /* ethernet, tokenring, etc. */
202 u_char ifi_addrlen; /* media address length */
203 u_char ifi_hdrlen; /* media header length */
204 u_long ifi_mtu; /* maximum transmission unit */
205 u_long ifi_metric; /* routing metric (external only) */
206 u_long ifi_baudrate; /* linespeed */
207 /* volatile statistics */
208 u_long ifi_ipackets; /* packets received on interface */
209 u_long ifi_ierrors; /* input errors on interface */
210 u_long ifi_opackets; /* packets sent on interface */
211 u_long ifi_oerrors; /* output errors on interface */
212 u_long ifi_collisions; /* collisions on csma interfaces */
213 u_long ifi_ibytes; /* total number of octets received */
214 u_long ifi_obytes; /* total number of octets sent */
215 u_long ifi_imcasts; /* packets received via multicast */
216 u_long ifi_omcasts; /* packets sent via multicast */
217 u_long ifi_iqdrops; /* dropped on input, this interface */
218 u_long ifi_noproto; /* destined for unsupported protocol */
219 struct timeval ifi_lastchange; /* last operational state change */
220 };
221 #endif /* _KERNEL && COMPAT_14 */
222
223 /*
224 * Structure defining a queue for a network interface.
225 */
226 struct ifqueue {
227 struct mbuf *ifq_head;
228 struct mbuf *ifq_tail;
229 int ifq_len;
230 int ifq_maxlen;
231 int ifq_drops;
232 };
233
234 /*
235 * Structure defining a queue for a network interface.
236 *
237 * (Would like to call this struct ``if'', but C isn't PL/1.)
238 */
239 TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
240
241 struct ifnet { /* and the entries */
242 void *if_softc; /* lower-level data for this if */
243 TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
244 TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
245 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
246 int if_pcount; /* number of promiscuous listeners */
247 caddr_t if_bpf; /* packet filter structure */
248 u_short if_index; /* numeric abbreviation for this if */
249 short if_timer; /* time 'til if_watchdog called */
250 short if_flags; /* up/down, broadcast, etc. */
251 short if__pad1; /* be nice to m68k ports */
252 struct if_data if_data; /* statistics and other data about if */
253 /*
254 * Procedure handles. If you add more of these, don't forget the
255 * corresponding NULL stub in if.c.
256 */
257 int (*if_output) /* output routine (enqueue) */
258 __P((struct ifnet *, struct mbuf *, struct sockaddr *,
259 struct rtentry *));
260 void (*if_input) /* input routine (from h/w driver) */
261 __P((struct ifnet *, struct mbuf *));
262 void (*if_start) /* initiate output routine */
263 __P((struct ifnet *));
264 int (*if_ioctl) /* ioctl routine */
265 __P((struct ifnet *, u_long, caddr_t));
266 int (*if_init) /* init routine */
267 __P((struct ifnet *));
268 void (*if_stop) /* stop routine */
269 __P((struct ifnet *, int));
270 void (*if_watchdog) /* timer routine */
271 __P((struct ifnet *));
272 void (*if_drain) /* routine to release resources */
273 __P((struct ifnet *));
274 struct ifaltq if_snd; /* output queue (includes altq) */
275 struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */
276 const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */
277 void *if_bridge; /* bridge glue */
278 int if_dlt; /* data link type (<net/dlt.h>) */
279 struct pfil_head if_pfil; /* filtering point */
280 uint64_t if_capabilities; /* interface capabilities */
281 uint64_t if_capenable; /* capabilities enabled */
282
283 /*
284 * These are pre-computed based on an interfaces enabled
285 * capabilities, for speed elsewhere.
286 */
287 int if_csum_flags_tx; /* M_CSUM_* flags for Tx */
288 int if_csum_flags_rx; /* M_CSUM_* flags for Rx */
289
290 void *if_afdata[AF_MAX];
291 struct mowner *if_mowner; /* who owns mbufs for this interface */
292
293 #if NAGR > 0
294 void *if_agrprivate;
295 #endif
296 };
297 #define if_mtu if_data.ifi_mtu
298 #define if_type if_data.ifi_type
299 #define if_addrlen if_data.ifi_addrlen
300 #define if_hdrlen if_data.ifi_hdrlen
301 #define if_metric if_data.ifi_metric
302 #define if_link_state if_data.ifi_link_state
303 #define if_baudrate if_data.ifi_baudrate
304 #define if_ipackets if_data.ifi_ipackets
305 #define if_ierrors if_data.ifi_ierrors
306 #define if_opackets if_data.ifi_opackets
307 #define if_oerrors if_data.ifi_oerrors
308 #define if_collisions if_data.ifi_collisions
309 #define if_ibytes if_data.ifi_ibytes
310 #define if_obytes if_data.ifi_obytes
311 #define if_imcasts if_data.ifi_imcasts
312 #define if_omcasts if_data.ifi_omcasts
313 #define if_iqdrops if_data.ifi_iqdrops
314 #define if_noproto if_data.ifi_noproto
315 #define if_lastchange if_data.ifi_lastchange
316
317 #define IFF_UP 0x0001 /* interface is up */
318 #define IFF_BROADCAST 0x0002 /* broadcast address valid */
319 #define IFF_DEBUG 0x0004 /* turn on debugging */
320 #define IFF_LOOPBACK 0x0008 /* is a loopback net */
321 #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */
322 #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */
323 #define IFF_RUNNING 0x0040 /* resources allocated */
324 #define IFF_NOARP 0x0080 /* no address resolution protocol */
325 #define IFF_PROMISC 0x0100 /* receive all packets */
326 #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
327 #define IFF_OACTIVE 0x0400 /* transmission in progress */
328 #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */
329 #define IFF_LINK0 0x1000 /* per link layer defined bit */
330 #define IFF_LINK1 0x2000 /* per link layer defined bit */
331 #define IFF_LINK2 0x4000 /* per link layer defined bit */
332 #define IFF_MULTICAST 0x8000 /* supports multicast */
333
334 #define IFFBITS \
335 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS" \
336 "\7RUNNING\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX" \
337 "\15LINK0\16LINK1\17LINK2\20MULTICAST"
338
339 /* flags set internally only: */
340 #define IFF_CANTCHANGE \
341 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
342 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC)
343
344 /*
345 * Some convenience macros used for setting ifi_baudrate.
346 * XXX 1000 vs. 1024? --thorpej (at) NetBSD.org
347 */
348 #define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */
349 #define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
350 #define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
351
352 /* Capabilities that interfaces can advertise. */
353 #define IFCAP_CSUM_IPv4 0x0001 /* can do IPv4 header checksums */
354 #define IFCAP_CSUM_TCPv4 0x0002 /* can do IPv4/TCP checksums */
355 #define IFCAP_CSUM_UDPv4 0x0004 /* can do IPv4/UDP checksums */
356 #define IFCAP_CSUM_TCPv6 0x0008 /* can do IPv6/TCP checksums */
357 #define IFCAP_CSUM_UDPv6 0x0010 /* can do IPv6/UDP checksums */
358 #define IFCAP_CSUM_TCPv4_Rx 0x0020 /* can do IPv4/TCP (Rx only) */
359 #define IFCAP_CSUM_UDPv4_Rx 0x0040 /* can do IPv4/UDP (Rx only) */
360 #define IFCAP_TSOv4 0x0080 /* can do TCPv4 segmentation offload */
361
362 #define IFCAPBITS \
363 "\020\1IP4CSUM\2TCP4CSUM\3UDP4CSUM\4TCP6CSUM\5UDP6CSUM\6TCP4CSUM_Rx" \
364 "\7UDP4CSUM_Rx\10TSO4"
365
366 /*
367 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
368 * input routines have queues of messages stored on ifqueue structures
369 * (defined above). Entries are added to and deleted from these structures
370 * by these macros, which should be called with ipl raised to splnet().
371 */
372 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
373 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
374 #define IF_ENQUEUE(ifq, m) { \
375 (m)->m_nextpkt = 0; \
376 if ((ifq)->ifq_tail == 0) \
377 (ifq)->ifq_head = m; \
378 else \
379 (ifq)->ifq_tail->m_nextpkt = m; \
380 (ifq)->ifq_tail = m; \
381 (ifq)->ifq_len++; \
382 }
383 #define IF_PREPEND(ifq, m) { \
384 (m)->m_nextpkt = (ifq)->ifq_head; \
385 if ((ifq)->ifq_tail == 0) \
386 (ifq)->ifq_tail = (m); \
387 (ifq)->ifq_head = (m); \
388 (ifq)->ifq_len++; \
389 }
390 #define IF_DEQUEUE(ifq, m) { \
391 (m) = (ifq)->ifq_head; \
392 if (m) { \
393 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
394 (ifq)->ifq_tail = 0; \
395 (m)->m_nextpkt = 0; \
396 (ifq)->ifq_len--; \
397 } \
398 }
399 #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
400 #define IF_PURGE(ifq) \
401 do { \
402 struct mbuf *__m0; \
403 \
404 for (;;) { \
405 IF_DEQUEUE((ifq), __m0); \
406 if (__m0 == NULL) \
407 break; \
408 else \
409 m_freem(__m0); \
410 } \
411 } while (/*CONSTCOND*/ 0)
412 #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
413
414 #ifndef IFQ_MAXLEN
415 #define IFQ_MAXLEN 256
416 #endif
417 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
418
419 /*
420 * Structure defining statistics and other data kept regarding an address
421 * on a network interface.
422 */
423 struct ifaddr_data {
424 int64_t ifad_inbytes;
425 int64_t ifad_outbytes;
426 };
427
428 /*
429 * The ifaddr structure contains information about one address
430 * of an interface. They are maintained by the different address families,
431 * are allocated and attached when an address is set, and are linked
432 * together so all addresses for an interface can be located.
433 */
434 struct ifaddr {
435 struct sockaddr *ifa_addr; /* address of interface */
436 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
437 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
438 struct sockaddr *ifa_netmask; /* used to determine subnet */
439 struct ifnet *ifa_ifp; /* back-pointer to interface */
440 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
441 struct ifaddr_data ifa_data; /* statistics on the address */
442 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
443 __P((int, struct rtentry *, struct rt_addrinfo *));
444 u_int ifa_flags; /* mostly rt_flags for cloning */
445 int ifa_refcnt; /* count of references */
446 int ifa_metric; /* cost of going out this interface */
447 };
448 #define IFA_ROUTE RTF_UP /* 0x01 *//* route installed */
449
450 /*
451 * Message format for use in obtaining information about interfaces
452 * from sysctl and the routing socket.
453 */
454 struct if_msghdr {
455 u_short ifm_msglen; /* to skip over non-understood messages */
456 u_char ifm_version; /* future binary compatibility */
457 u_char ifm_type; /* message type */
458 int ifm_addrs; /* like rtm_addrs */
459 int ifm_flags; /* value of if_flags */
460 u_short ifm_index; /* index for associated ifp */
461 struct if_data ifm_data;/* statistics and other data about if */
462 };
463
464 #if defined(_KERNEL) && defined(COMPAT_14)
465 /* pre-1.5 if_msghdr (ifm_data changed) */
466 struct if_msghdr14 {
467 u_short ifm_msglen; /* to skip over non-understood messages */
468 u_char ifm_version; /* future binary compatibility */
469 u_char ifm_type; /* message type */
470 int ifm_addrs; /* like rtm_addrs */
471 int ifm_flags; /* value of if_flags */
472 u_short ifm_index; /* index for associated ifp */
473 struct if_data14 ifm_data; /* statistics and other data about if */
474 };
475 #endif /* _KERNEL && COMPAT_14 */
476
477 /*
478 * Message format for use in obtaining information about interface addresses
479 * from sysctl and the routing socket.
480 */
481 struct ifa_msghdr {
482 u_short ifam_msglen; /* to skip over non-understood messages */
483 u_char ifam_version; /* future binary compatibility */
484 u_char ifam_type; /* message type */
485 int ifam_addrs; /* like rtm_addrs */
486 int ifam_flags; /* value of ifa_flags */
487 u_short ifam_index; /* index for associated ifp */
488 int ifam_metric; /* value of ifa_metric */
489 };
490
491 /*
492 * Message format announcing the arrival or departure of a network interface.
493 */
494 struct if_announcemsghdr {
495 u_short ifan_msglen; /* to skip over non-understood messages */
496 u_char ifan_version; /* future binary compatibility */
497 u_char ifan_type; /* message type */
498 u_short ifan_index; /* index for associated ifp */
499 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
500 u_short ifan_what; /* what type of announcement */
501 };
502
503 #define IFAN_ARRIVAL 0 /* interface arrival */
504 #define IFAN_DEPARTURE 1 /* interface departure */
505
506 /*
507 * Interface request structure used for socket
508 * ioctl's. All interface ioctl's must have parameter
509 * definitions which begin with ifr_name. The
510 * remainder may be interface specific.
511 */
512 struct ifreq {
513 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
514 union {
515 struct sockaddr ifru_addr;
516 struct sockaddr ifru_dstaddr;
517 struct sockaddr ifru_broadaddr;
518 short ifru_flags;
519 int ifru_metric;
520 int ifru_mtu;
521 int ifru_dlt;
522 u_int ifru_value;
523 caddr_t ifru_data;
524 } ifr_ifru;
525 #define ifr_addr ifr_ifru.ifru_addr /* address */
526 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
527 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
528 #define ifr_flags ifr_ifru.ifru_flags /* flags */
529 #define ifr_metric ifr_ifru.ifru_metric /* metric */
530 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
531 #define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */
532 #define ifr_value ifr_ifru.ifru_value /* generic value */
533 #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
534 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
535 };
536
537 struct ifcapreq {
538 char ifcr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
539 uint64_t ifcr_capabilities; /* supported capabiliites */
540 uint64_t ifcr_capenable; /* capabilities enabled */
541 };
542
543 struct ifaliasreq {
544 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
545 struct sockaddr ifra_addr;
546 struct sockaddr ifra_dstaddr;
547 #define ifra_broadaddr ifra_dstaddr
548 struct sockaddr ifra_mask;
549 };
550
551 struct ifdatareq {
552 char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
553 struct if_data ifdr_data;
554 };
555
556 struct ifmediareq {
557 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
558 int ifm_current; /* current media options */
559 int ifm_mask; /* don't care mask */
560 int ifm_status; /* media status */
561 int ifm_active; /* active options */
562 int ifm_count; /* # entries in ifm_ulist
563 array */
564 int *ifm_ulist; /* media words */
565 };
566
567
568 struct ifdrv {
569 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
570 unsigned long ifd_cmd;
571 size_t ifd_len;
572 void *ifd_data;
573 };
574
575 /*
576 * Structure used in SIOCGIFCONF request.
577 * Used to retrieve interface configuration
578 * for machine (useful for programs which
579 * must know all networks accessible).
580 */
581 struct ifconf {
582 int ifc_len; /* size of associated buffer */
583 union {
584 caddr_t ifcu_buf;
585 struct ifreq *ifcu_req;
586 } ifc_ifcu;
587 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
588 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
589 };
590
591 /*
592 * Structure for SIOC[AGD]LIFADDR
593 */
594 struct if_laddrreq {
595 char iflr_name[IFNAMSIZ];
596 unsigned int flags;
597 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
598 unsigned int prefixlen; /* in/out */
599 struct sockaddr_storage addr; /* in/out */
600 struct sockaddr_storage dstaddr; /* out */
601 };
602
603 #include <net/if_arp.h>
604
605 #endif /* _NETBSD_SOURCE */
606
607 #ifdef _KERNEL
608 #ifdef IFAREF_DEBUG
609 #define IFAREF(ifa) \
610 do { \
611 printf("IFAREF: %s:%d %p -> %d\n", __FILE__, __LINE__, \
612 (ifa), ++(ifa)->ifa_refcnt); \
613 } while (/*CONSTCOND*/ 0)
614
615 #define IFAFREE(ifa) \
616 do { \
617 if ((ifa)->ifa_refcnt <= 0) \
618 panic("%s:%d: %p ifa_refcnt <= 0", __FILE__, \
619 __LINE__, (ifa)); \
620 printf("IFAFREE: %s:%d %p -> %d\n", __FILE__, __LINE__, \
621 (ifa), --(ifa)->ifa_refcnt); \
622 if ((ifa)->ifa_refcnt == 0) \
623 ifafree(ifa); \
624 } while (/*CONSTCOND*/ 0)
625 #else
626 #define IFAREF(ifa) (ifa)->ifa_refcnt++
627
628 #ifdef DIAGNOSTIC
629 #define IFAFREE(ifa) \
630 do { \
631 if ((ifa)->ifa_refcnt <= 0) \
632 panic("%s:%d: %p ifa_refcnt <= 0", __FILE__, \
633 __LINE__, (ifa)); \
634 if (--(ifa)->ifa_refcnt == 0) \
635 ifafree(ifa); \
636 } while (/*CONSTCOND*/ 0)
637 #else
638 #define IFAFREE(ifa) \
639 do { \
640 if (--(ifa)->ifa_refcnt == 0) \
641 ifafree(ifa); \
642 } while (/*CONSTCOND*/ 0)
643 #endif /* DIAGNOSTIC */
644 #endif /* IFAREF_DEBUG */
645
646 #ifdef ALTQ
647 #define ALTQ_DECL(x) x
648 #define ALTQ_COMMA ,
649
650 #define IFQ_ENQUEUE(ifq, m, pattr, err) \
651 do { \
652 if (ALTQ_IS_ENABLED((ifq))) \
653 ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \
654 else { \
655 if (IF_QFULL((ifq))) { \
656 m_freem((m)); \
657 (err) = ENOBUFS; \
658 } else { \
659 IF_ENQUEUE((ifq), (m)); \
660 (err) = 0; \
661 } \
662 } \
663 if ((err)) \
664 (ifq)->ifq_drops++; \
665 } while (/*CONSTCOND*/ 0)
666
667 #define IFQ_DEQUEUE(ifq, m) \
668 do { \
669 if (TBR_IS_ENABLED((ifq))) \
670 (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \
671 else if (ALTQ_IS_ENABLED((ifq))) \
672 ALTQ_DEQUEUE((ifq), (m)); \
673 else \
674 IF_DEQUEUE((ifq), (m)); \
675 } while (/*CONSTCOND*/ 0)
676
677 #define IFQ_POLL(ifq, m) \
678 do { \
679 if (TBR_IS_ENABLED((ifq))) \
680 (m) = tbr_dequeue((ifq), ALTDQ_POLL); \
681 else if (ALTQ_IS_ENABLED((ifq))) \
682 ALTQ_POLL((ifq), (m)); \
683 else \
684 IF_POLL((ifq), (m)); \
685 } while (/*CONSTCOND*/ 0)
686
687 #define IFQ_PURGE(ifq) \
688 do { \
689 if (ALTQ_IS_ENABLED((ifq))) \
690 ALTQ_PURGE((ifq)); \
691 else \
692 IF_PURGE((ifq)); \
693 } while (/*CONSTCOND*/ 0)
694
695 #define IFQ_SET_READY(ifq) \
696 do { \
697 (ifq)->altq_flags |= ALTQF_READY; \
698 } while (/*CONSTCOND*/ 0)
699
700 #define IFQ_CLASSIFY(ifq, m, af, pa) \
701 do { \
702 if (ALTQ_IS_ENABLED((ifq))) { \
703 if (ALTQ_NEEDS_CLASSIFY((ifq))) \
704 (pa)->pattr_class = (*(ifq)->altq_classify) \
705 ((ifq)->altq_clfier, (m), (af)); \
706 (pa)->pattr_af = (af); \
707 (pa)->pattr_hdr = mtod((m), caddr_t); \
708 } \
709 } while (/*CONSTCOND*/ 0)
710 #else /* ! ALTQ */
711 #define ALTQ_DECL(x) /* nothing */
712 #define ALTQ_COMMA
713
714 #define IFQ_ENQUEUE(ifq, m, pattr, err) \
715 do { \
716 if (IF_QFULL((ifq))) { \
717 m_freem((m)); \
718 (err) = ENOBUFS; \
719 } else { \
720 IF_ENQUEUE((ifq), (m)); \
721 (err) = 0; \
722 } \
723 if ((err)) \
724 (ifq)->ifq_drops++; \
725 } while (/*CONSTCOND*/ 0)
726
727 #define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m))
728
729 #define IFQ_POLL(ifq, m) IF_POLL((ifq), (m))
730
731 #define IFQ_PURGE(ifq) IF_PURGE((ifq))
732
733 #define IFQ_SET_READY(ifq) /* nothing */
734
735 #define IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */
736
737 #endif /* ALTQ */
738
739 #define IFQ_IS_EMPTY(ifq) IF_IS_EMPTY((ifq))
740 #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
741 #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
742 #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
743 #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
744
745 #include <sys/mallocvar.h>
746 MALLOC_DECLARE(M_IFADDR);
747 MALLOC_DECLARE(M_IFMADDR);
748
749 #define IFNET_FOREACH(ifp) TAILQ_FOREACH(ifp, &ifnet, if_list)
750 #define IFADDR_FOREACH(ifa, ifp) TAILQ_FOREACH(ifa, \
751 &(ifp)->if_addrlist, ifa_list)
752
753 extern struct ifnet_head ifnet;
754 extern struct ifnet **ifindex2ifnet;
755 extern struct ifnet *lo0ifp;
756 extern size_t if_indexlim;
757
758 char *ether_sprintf __P((const u_char *));
759
760 void if_alloc_sadl __P((struct ifnet *));
761 void if_free_sadl __P((struct ifnet *));
762 void if_attach __P((struct ifnet *));
763 void if_attachdomain __P((void));
764 void if_attachdomain1 __P((struct ifnet *));
765 void if_deactivate __P((struct ifnet *));
766 void if_detach __P((struct ifnet *));
767 void if_down __P((struct ifnet *));
768 void if_slowtimo __P((void *));
769 void if_up __P((struct ifnet *));
770 int ifconf __P((u_long, caddr_t));
771 void ifinit __P((void));
772 int ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
773 int ifpromisc __P((struct ifnet *, int));
774 struct ifnet *ifunit __P((const char *));
775
776 struct ifaddr *ifa_ifwithaddr __P((const struct sockaddr *));
777 struct ifaddr *ifa_ifwithaf __P((int));
778 struct ifaddr *ifa_ifwithdstaddr __P((const struct sockaddr *));
779 struct ifaddr *ifa_ifwithnet __P((const struct sockaddr *));
780 struct ifaddr *ifa_ifwithladdr __P((const struct sockaddr *));
781 struct ifaddr *ifa_ifwithroute __P((int, const struct sockaddr *,
782 const struct sockaddr *));
783 struct ifaddr *ifaof_ifpforaddr __P((const struct sockaddr *, struct ifnet *));
784 void ifafree __P((struct ifaddr *));
785 void link_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
786
787 void if_clone_attach __P((struct if_clone *));
788 void if_clone_detach __P((struct if_clone *));
789
790 int if_clone_create __P((const char *));
791 int if_clone_destroy __P((const char *));
792
793 int ifq_enqueue(struct ifnet *, struct mbuf * ALTQ_COMMA
794 ALTQ_DECL(struct altq_pktattr *));
795 int ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf * ALTQ_COMMA
796 ALTQ_DECL(struct altq_pktattr *));
797
798 int loioctl __P((struct ifnet *, u_long, caddr_t));
799 void loopattach __P((int));
800 int looutput __P((struct ifnet *,
801 struct mbuf *, struct sockaddr *, struct rtentry *));
802 void lortrequest __P((int, struct rtentry *, struct rt_addrinfo *));
803
804 /*
805 * These are exported because they're an easy way to tell if
806 * an interface is going away without having to burn a flag.
807 */
808 int if_nulloutput __P((struct ifnet *, struct mbuf *,
809 struct sockaddr *, struct rtentry *));
810 void if_nullinput __P((struct ifnet *, struct mbuf *));
811 void if_nullstart __P((struct ifnet *));
812 int if_nullioctl __P((struct ifnet *, u_long, caddr_t));
813 int if_nullinit __P((struct ifnet *));
814 void if_nullstop __P((struct ifnet *, int));
815 void if_nullwatchdog __P((struct ifnet *));
816 void if_nulldrain __P((struct ifnet *));
817 #else
818 struct if_nameindex {
819 unsigned int if_index; /* 1, 2, ... */
820 char *if_name; /* null terminated name: "le0", ... */
821 };
822
823 #include <sys/cdefs.h>
824 __BEGIN_DECLS
825 unsigned int if_nametoindex __P((const char *));
826 char * if_indextoname __P((unsigned int, char *));
827 struct if_nameindex * if_nameindex __P((void));
828 void if_freenameindex __P((struct if_nameindex *));
829 __END_DECLS
830 #endif /* _KERNEL */ /* XXX really ALTQ? */
831
832 #ifdef _KERNEL
833 /*
834 * ifq sysctl support
835 */
836 int sysctl_ifq __P((int *name, u_int namelen, void *oldp,
837 size_t *oldlenp, void *newp, size_t newlen,
838 struct ifqueue *ifq));
839 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
840 #define IFQCTL_LEN 1
841 #define IFQCTL_MAXLEN 2
842 #define IFQCTL_PEAK 3
843 #define IFQCTL_DROPS 4
844 #define IFQCTL_MAXID 5
845
846 #endif /* _KERNEL */
847
848 #ifdef _NETBSD_SOURCE
849 /*
850 * sysctl for ifq (per-protocol packet input queue variant of ifqueue)
851 */
852 #define CTL_IFQ_NAMES { \
853 { 0, 0 }, \
854 { "len", CTLTYPE_INT }, \
855 { "maxlen", CTLTYPE_INT }, \
856 { "peak", CTLTYPE_INT }, \
857 { "drops", CTLTYPE_INT }, \
858 }
859 #endif /* _NETBSD_SOURCE */
860 #endif /* !_NET_IF_H_ */
861