FreeBSD/Linux Kernel Cross Reference
sys/net/if.h
1 /* $NetBSD: if.h,v 1.103 2005/03/06 00:08:30 matt 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 Studnemund 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 #endif
126
127 struct mbuf;
128 struct proc;
129 struct rtentry;
130 struct socket;
131 struct ether_header;
132 struct ifnet;
133 struct rt_addrinfo;
134
135 #define IFNAMSIZ IF_NAMESIZE
136
137 /*
138 * Structure describing a `cloning' interface.
139 */
140 struct if_clone {
141 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
142 const char *ifc_name; /* name of device, e.g. `gif' */
143 size_t ifc_namelen; /* length of name */
144
145 int (*ifc_create)(struct if_clone *, int);
146 int (*ifc_destroy)(struct ifnet *);
147 };
148
149 #define IF_CLONE_INITIALIZER(name, create, destroy) \
150 { { 0 }, name, sizeof(name) - 1, create, destroy }
151
152 /*
153 * Structure used to query names of interface cloners.
154 */
155 struct if_clonereq {
156 int ifcr_total; /* total cloners (out) */
157 int ifcr_count; /* room for this many in user buffer */
158 char *ifcr_buffer; /* buffer for cloner names */
159 };
160
161 /*
162 * Structure defining statistics and other data kept regarding a network
163 * interface.
164 */
165 struct if_data {
166 /* generic interface information */
167 u_char ifi_type; /* ethernet, tokenring, etc. */
168 u_char ifi_addrlen; /* media address length */
169 u_char ifi_hdrlen; /* media header length */
170 int ifi_link_state; /* current link state */
171 u_quad_t ifi_mtu; /* maximum transmission unit */
172 u_quad_t ifi_metric; /* routing metric (external only) */
173 u_quad_t ifi_baudrate; /* linespeed */
174 /* volatile statistics */
175 u_quad_t ifi_ipackets; /* packets received on interface */
176 u_quad_t ifi_ierrors; /* input errors on interface */
177 u_quad_t ifi_opackets; /* packets sent on interface */
178 u_quad_t ifi_oerrors; /* output errors on interface */
179 u_quad_t ifi_collisions; /* collisions on csma interfaces */
180 u_quad_t ifi_ibytes; /* total number of octets received */
181 u_quad_t ifi_obytes; /* total number of octets sent */
182 u_quad_t ifi_imcasts; /* packets received via multicast */
183 u_quad_t ifi_omcasts; /* packets sent via multicast */
184 u_quad_t ifi_iqdrops; /* dropped on input, this interface */
185 u_quad_t ifi_noproto; /* destined for unsupported protocol */
186 struct timeval ifi_lastchange; /* last operational state change */
187 };
188
189 /*
190 * Values for if_link_state.
191 */
192 #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
193 #define LINK_STATE_DOWN 1 /* link is down */
194 #define LINK_STATE_UP 2 /* link is up */
195
196 #if defined(_KERNEL) && defined(COMPAT_14)
197 /* Pre-1.5 if_data struct */
198 struct if_data14 {
199 /* generic interface information */
200 u_char ifi_type; /* ethernet, tokenring, etc. */
201 u_char ifi_addrlen; /* media address length */
202 u_char ifi_hdrlen; /* media header length */
203 u_long ifi_mtu; /* maximum transmission unit */
204 u_long ifi_metric; /* routing metric (external only) */
205 u_long ifi_baudrate; /* linespeed */
206 /* volatile statistics */
207 u_long ifi_ipackets; /* packets received on interface */
208 u_long ifi_ierrors; /* input errors on interface */
209 u_long ifi_opackets; /* packets sent on interface */
210 u_long ifi_oerrors; /* output errors on interface */
211 u_long ifi_collisions; /* collisions on csma interfaces */
212 u_long ifi_ibytes; /* total number of octets received */
213 u_long ifi_obytes; /* total number of octets sent */
214 u_long ifi_imcasts; /* packets received via multicast */
215 u_long ifi_omcasts; /* packets sent via multicast */
216 u_long ifi_iqdrops; /* dropped on input, this interface */
217 u_long ifi_noproto; /* destined for unsupported protocol */
218 struct timeval ifi_lastchange; /* last operational state change */
219 };
220 #endif /* _KERNEL && COMPAT_14 */
221
222 /*
223 * Structure defining a queue for a network interface.
224 */
225 struct ifqueue {
226 struct mbuf *ifq_head;
227 struct mbuf *ifq_tail;
228 int ifq_len;
229 int ifq_maxlen;
230 int ifq_drops;
231 };
232
233 /*
234 * Structure defining a queue for a network interface.
235 *
236 * (Would like to call this struct ``if'', but C isn't PL/1.)
237 */
238 TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
239
240 struct ifnet { /* and the entries */
241 void *if_softc; /* lower-level data for this if */
242 TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
243 TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
244 char if_xname[IFNAMSIZ]; /* external name (name + unit) */
245 int if_pcount; /* number of promiscuous listeners */
246 caddr_t if_bpf; /* packet filter structure */
247 u_short if_index; /* numeric abbreviation for this if */
248 short if_timer; /* time 'til if_watchdog called */
249 short if_flags; /* up/down, broadcast, etc. */
250 short if__pad1; /* be nice to m68k ports */
251 struct if_data if_data; /* statistics and other data about if */
252 /*
253 * Procedure handles. If you add more of these, don't forget the
254 * corresponding NULL stub in if.c.
255 */
256 int (*if_output) /* output routine (enqueue) */
257 __P((struct ifnet *, struct mbuf *, struct sockaddr *,
258 struct rtentry *));
259 void (*if_input) /* input routine (from h/w driver) */
260 __P((struct ifnet *, struct mbuf *));
261 void (*if_start) /* initiate output routine */
262 __P((struct ifnet *));
263 int (*if_ioctl) /* ioctl routine */
264 __P((struct ifnet *, u_long, caddr_t));
265 int (*if_init) /* init routine */
266 __P((struct ifnet *));
267 void (*if_stop) /* stop routine */
268 __P((struct ifnet *, int));
269 void (*if_watchdog) /* timer routine */
270 __P((struct ifnet *));
271 void (*if_drain) /* routine to release resources */
272 __P((struct ifnet *));
273 struct ifaltq if_snd; /* output queue (includes altq) */
274 struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */
275 const uint8_t *if_broadcastaddr;/* linklevel broadcast bytestring */
276 void *if_bridge; /* bridge glue */
277 int if_dlt; /* data link type (<net/dlt.h>) */
278 struct pfil_head if_pfil; /* filtering point */
279 uint64_t if_capabilities; /* interface capabilities */
280 uint64_t if_capenable; /* capabilities enabled */
281
282 /*
283 * These are pre-computed based on an interfaces enabled
284 * capabilities, for speed elsewhere.
285 */
286 int if_csum_flags_tx; /* M_CSUM_* flags for Tx */
287 int if_csum_flags_rx; /* M_CSUM_* flags for Rx */
288
289 void *if_afdata[AF_MAX];
290 struct mowner *if_mowner; /* who owns mbufs for this interface */
291 };
292 #define if_mtu if_data.ifi_mtu
293 #define if_type if_data.ifi_type
294 #define if_addrlen if_data.ifi_addrlen
295 #define if_hdrlen if_data.ifi_hdrlen
296 #define if_metric if_data.ifi_metric
297 #define if_link_state if_data.ifi_link_state
298 #define if_baudrate if_data.ifi_baudrate
299 #define if_ipackets if_data.ifi_ipackets
300 #define if_ierrors if_data.ifi_ierrors
301 #define if_opackets if_data.ifi_opackets
302 #define if_oerrors if_data.ifi_oerrors
303 #define if_collisions if_data.ifi_collisions
304 #define if_ibytes if_data.ifi_ibytes
305 #define if_obytes if_data.ifi_obytes
306 #define if_imcasts if_data.ifi_imcasts
307 #define if_omcasts if_data.ifi_omcasts
308 #define if_iqdrops if_data.ifi_iqdrops
309 #define if_noproto if_data.ifi_noproto
310 #define if_lastchange if_data.ifi_lastchange
311
312 #define IFF_UP 0x0001 /* interface is up */
313 #define IFF_BROADCAST 0x0002 /* broadcast address valid */
314 #define IFF_DEBUG 0x0004 /* turn on debugging */
315 #define IFF_LOOPBACK 0x0008 /* is a loopback net */
316 #define IFF_POINTOPOINT 0x0010 /* interface is point-to-point link */
317 #define IFF_NOTRAILERS 0x0020 /* avoid use of trailers */
318 #define IFF_RUNNING 0x0040 /* resources allocated */
319 #define IFF_NOARP 0x0080 /* no address resolution protocol */
320 #define IFF_PROMISC 0x0100 /* receive all packets */
321 #define IFF_ALLMULTI 0x0200 /* receive all multicast packets */
322 #define IFF_OACTIVE 0x0400 /* transmission in progress */
323 #define IFF_SIMPLEX 0x0800 /* can't hear own transmissions */
324 #define IFF_LINK0 0x1000 /* per link layer defined bit */
325 #define IFF_LINK1 0x2000 /* per link layer defined bit */
326 #define IFF_LINK2 0x4000 /* per link layer defined bit */
327 #define IFF_MULTICAST 0x8000 /* supports multicast */
328
329 /* flags set internally only: */
330 #define IFF_CANTCHANGE \
331 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
332 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI|IFF_PROMISC)
333
334 /*
335 * Some convenience macros used for setting ifi_baudrate.
336 * XXX 1000 vs. 1024? --thorpej@NetBSD.org
337 */
338 #define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */
339 #define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
340 #define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
341
342 /* Capabilities that interfaces can advertise. */
343 #define IFCAP_CSUM_IPv4 0x0001 /* can do IPv4 header checksums */
344 #define IFCAP_CSUM_TCPv4 0x0002 /* can do IPv4/TCP checksums */
345 #define IFCAP_CSUM_UDPv4 0x0004 /* can do IPv4/UDP checksums */
346 #define IFCAP_CSUM_TCPv6 0x0008 /* can do IPv6/TCP checksums */
347 #define IFCAP_CSUM_UDPv6 0x0010 /* can do IPv6/UDP checksums */
348 #define IFCAP_CSUM_TCPv4_Rx 0x0020 /* can do IPv4/TCP (Rx only) */
349 #define IFCAP_CSUM_UDPv4_Rx 0x0040 /* can do IPv4/UDP (Rx only) */
350 #define IFCAP_TSOv4 0x0080 /* can do TCPv4 segmentation offload */
351
352 /*
353 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
354 * input routines have queues of messages stored on ifqueue structures
355 * (defined above). Entries are added to and deleted from these structures
356 * by these macros, which should be called with ipl raised to splnet().
357 */
358 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
359 #define IF_DROP(ifq) ((ifq)->ifq_drops++)
360 #define IF_ENQUEUE(ifq, m) { \
361 (m)->m_nextpkt = 0; \
362 if ((ifq)->ifq_tail == 0) \
363 (ifq)->ifq_head = m; \
364 else \
365 (ifq)->ifq_tail->m_nextpkt = m; \
366 (ifq)->ifq_tail = m; \
367 (ifq)->ifq_len++; \
368 }
369 #define IF_PREPEND(ifq, m) { \
370 (m)->m_nextpkt = (ifq)->ifq_head; \
371 if ((ifq)->ifq_tail == 0) \
372 (ifq)->ifq_tail = (m); \
373 (ifq)->ifq_head = (m); \
374 (ifq)->ifq_len++; \
375 }
376 #define IF_DEQUEUE(ifq, m) { \
377 (m) = (ifq)->ifq_head; \
378 if (m) { \
379 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
380 (ifq)->ifq_tail = 0; \
381 (m)->m_nextpkt = 0; \
382 (ifq)->ifq_len--; \
383 } \
384 }
385 #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
386 #define IF_PURGE(ifq) \
387 do { \
388 struct mbuf *__m0; \
389 \
390 for (;;) { \
391 IF_DEQUEUE((ifq), __m0); \
392 if (__m0 == NULL) \
393 break; \
394 else \
395 m_freem(__m0); \
396 } \
397 } while (/*CONSTCOND*/ 0)
398 #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
399
400 #ifndef IFQ_MAXLEN
401 #define IFQ_MAXLEN 256
402 #endif
403 #define IFNET_SLOWHZ 1 /* granularity is 1 second */
404
405 /*
406 * Structure defining statistics and other data kept regarding an address
407 * on a network interface.
408 */
409 struct ifaddr_data {
410 int64_t ifad_inbytes;
411 int64_t ifad_outbytes;
412 };
413
414 /*
415 * The ifaddr structure contains information about one address
416 * of an interface. They are maintained by the different address families,
417 * are allocated and attached when an address is set, and are linked
418 * together so all addresses for an interface can be located.
419 */
420 struct ifaddr {
421 struct sockaddr *ifa_addr; /* address of interface */
422 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
423 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
424 struct sockaddr *ifa_netmask; /* used to determine subnet */
425 struct ifnet *ifa_ifp; /* back-pointer to interface */
426 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
427 struct ifaddr_data ifa_data; /* statistics on the address */
428 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */
429 __P((int, struct rtentry *, struct rt_addrinfo *));
430 u_int ifa_flags; /* mostly rt_flags for cloning */
431 int ifa_refcnt; /* count of references */
432 int ifa_metric; /* cost of going out this interface */
433 };
434 #define IFA_ROUTE RTF_UP /* 0x01 *//* route installed */
435
436 /*
437 * Message format for use in obtaining information about interfaces
438 * from sysctl and the routing socket.
439 */
440 struct if_msghdr {
441 u_short ifm_msglen; /* to skip over non-understood messages */
442 u_char ifm_version; /* future binary compatibility */
443 u_char ifm_type; /* message type */
444 int ifm_addrs; /* like rtm_addrs */
445 int ifm_flags; /* value of if_flags */
446 u_short ifm_index; /* index for associated ifp */
447 struct if_data ifm_data;/* statistics and other data about if */
448 };
449
450 #if defined(_KERNEL) && defined(COMPAT_14)
451 /* pre-1.5 if_msghdr (ifm_data changed) */
452 struct if_msghdr14 {
453 u_short ifm_msglen; /* to skip over non-understood messages */
454 u_char ifm_version; /* future binary compatibility */
455 u_char ifm_type; /* message type */
456 int ifm_addrs; /* like rtm_addrs */
457 int ifm_flags; /* value of if_flags */
458 u_short ifm_index; /* index for associated ifp */
459 struct if_data14 ifm_data; /* statistics and other data about if */
460 };
461 #endif /* _KERNEL && COMPAT_14 */
462
463 /*
464 * Message format for use in obtaining information about interface addresses
465 * from sysctl and the routing socket.
466 */
467 struct ifa_msghdr {
468 u_short ifam_msglen; /* to skip over non-understood messages */
469 u_char ifam_version; /* future binary compatibility */
470 u_char ifam_type; /* message type */
471 int ifam_addrs; /* like rtm_addrs */
472 int ifam_flags; /* value of ifa_flags */
473 u_short ifam_index; /* index for associated ifp */
474 int ifam_metric; /* value of ifa_metric */
475 };
476
477 /*
478 * Message format announcing the arrival or departure of a network interface.
479 */
480 struct if_announcemsghdr {
481 u_short ifan_msglen; /* to skip over non-understood messages */
482 u_char ifan_version; /* future binary compatibility */
483 u_char ifan_type; /* message type */
484 u_short ifan_index; /* index for associated ifp */
485 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
486 u_short ifan_what; /* what type of announcement */
487 };
488
489 #define IFAN_ARRIVAL 0 /* interface arrival */
490 #define IFAN_DEPARTURE 1 /* interface departure */
491
492 /*
493 * Interface request structure used for socket
494 * ioctl's. All interface ioctl's must have parameter
495 * definitions which begin with ifr_name. The
496 * remainder may be interface specific.
497 */
498 struct ifreq {
499 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
500 union {
501 struct sockaddr ifru_addr;
502 struct sockaddr ifru_dstaddr;
503 struct sockaddr ifru_broadaddr;
504 short ifru_flags;
505 int ifru_metric;
506 int ifru_mtu;
507 int ifru_dlt;
508 u_int ifru_value;
509 caddr_t ifru_data;
510 } ifr_ifru;
511 #define ifr_addr ifr_ifru.ifru_addr /* address */
512 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
513 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
514 #define ifr_flags ifr_ifru.ifru_flags /* flags */
515 #define ifr_metric ifr_ifru.ifru_metric /* metric */
516 #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
517 #define ifr_dlt ifr_ifru.ifru_dlt /* data link type (DLT_*) */
518 #define ifr_value ifr_ifru.ifru_value /* generic value */
519 #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
520 #define ifr_data ifr_ifru.ifru_data /* for use by interface */
521 };
522
523 struct ifcapreq {
524 char ifcr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
525 uint64_t ifcr_capabilities; /* supported capabiliites */
526 uint64_t ifcr_capenable; /* capabilities enabled */
527 };
528
529 struct ifaliasreq {
530 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
531 struct sockaddr ifra_addr;
532 struct sockaddr ifra_dstaddr;
533 #define ifra_broadaddr ifra_dstaddr
534 struct sockaddr ifra_mask;
535 };
536
537 struct ifdatareq {
538 char ifdr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
539 struct if_data ifdr_data;
540 };
541
542 struct ifmediareq {
543 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
544 int ifm_current; /* current media options */
545 int ifm_mask; /* don't care mask */
546 int ifm_status; /* media status */
547 int ifm_active; /* active options */
548 int ifm_count; /* # entries in ifm_ulist
549 array */
550 int *ifm_ulist; /* media words */
551 };
552
553
554 struct ifdrv {
555 char ifd_name[IFNAMSIZ]; /* if name, e.g. "en0" */
556 unsigned long ifd_cmd;
557 size_t ifd_len;
558 void *ifd_data;
559 };
560
561 /*
562 * Structure used in SIOCGIFCONF request.
563 * Used to retrieve interface configuration
564 * for machine (useful for programs which
565 * must know all networks accessible).
566 */
567 struct ifconf {
568 int ifc_len; /* size of associated buffer */
569 union {
570 caddr_t ifcu_buf;
571 struct ifreq *ifcu_req;
572 } ifc_ifcu;
573 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
574 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
575 };
576
577 /*
578 * Structure for SIOC[AGD]LIFADDR
579 */
580 struct if_laddrreq {
581 char iflr_name[IFNAMSIZ];
582 unsigned int flags;
583 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
584 unsigned int prefixlen; /* in/out */
585 struct sockaddr_storage addr; /* in/out */
586 struct sockaddr_storage dstaddr; /* out */
587 };
588
589 #include <net/if_arp.h>
590
591 #endif /* _NETBSD_SOURCE */
592
593 #ifdef _KERNEL
594 #ifdef IFAREF_DEBUG
595 #define IFAREF(ifa) \
596 do { \
597 printf("IFAREF: %s:%d %p -> %d\n", __FILE__, __LINE__, \
598 (ifa), ++(ifa)->ifa_refcnt); \
599 } while (/*CONSTCOND*/ 0)
600
601 #define IFAFREE(ifa) \
602 do { \
603 if ((ifa)->ifa_refcnt <= 0) \
604 panic("%s:%d: %p ifa_refcnt <= 0", __FILE__, \
605 __LINE__, (ifa)); \
606 printf("IFAFREE: %s:%d %p -> %d\n", __FILE__, __LINE__, \
607 (ifa), --(ifa)->ifa_refcnt); \
608 if ((ifa)->ifa_refcnt == 0) \
609 ifafree(ifa); \
610 } while (/*CONSTCOND*/ 0)
611 #else
612 #define IFAREF(ifa) (ifa)->ifa_refcnt++
613
614 #ifdef DIAGNOSTIC
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 if (--(ifa)->ifa_refcnt == 0) \
621 ifafree(ifa); \
622 } while (/*CONSTCOND*/ 0)
623 #else
624 #define IFAFREE(ifa) \
625 do { \
626 if (--(ifa)->ifa_refcnt == 0) \
627 ifafree(ifa); \
628 } while (/*CONSTCOND*/ 0)
629 #endif /* DIAGNOSTIC */
630 #endif /* IFAREF_DEBUG */
631
632 #ifdef ALTQ
633 #define ALTQ_DECL(x) x
634
635 #define IFQ_ENQUEUE(ifq, m, pattr, err) \
636 do { \
637 if (ALTQ_IS_ENABLED((ifq))) \
638 ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \
639 else { \
640 if (IF_QFULL((ifq))) { \
641 m_freem((m)); \
642 (err) = ENOBUFS; \
643 } else { \
644 IF_ENQUEUE((ifq), (m)); \
645 (err) = 0; \
646 } \
647 } \
648 if ((err)) \
649 (ifq)->ifq_drops++; \
650 } while (/*CONSTCOND*/ 0)
651
652 #define IFQ_DEQUEUE(ifq, m) \
653 do { \
654 if (TBR_IS_ENABLED((ifq))) \
655 (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \
656 else if (ALTQ_IS_ENABLED((ifq))) \
657 ALTQ_DEQUEUE((ifq), (m)); \
658 else \
659 IF_DEQUEUE((ifq), (m)); \
660 } while (/*CONSTCOND*/ 0)
661
662 #define IFQ_POLL(ifq, m) \
663 do { \
664 if (TBR_IS_ENABLED((ifq))) \
665 (m) = tbr_dequeue((ifq), ALTDQ_POLL); \
666 else if (ALTQ_IS_ENABLED((ifq))) \
667 ALTQ_POLL((ifq), (m)); \
668 else \
669 IF_POLL((ifq), (m)); \
670 } while (/*CONSTCOND*/ 0)
671
672 #define IFQ_PURGE(ifq) \
673 do { \
674 if (ALTQ_IS_ENABLED((ifq))) \
675 ALTQ_PURGE((ifq)); \
676 else \
677 IF_PURGE((ifq)); \
678 } while (/*CONSTCOND*/ 0)
679
680 #define IFQ_SET_READY(ifq) \
681 do { \
682 (ifq)->altq_flags |= ALTQF_READY; \
683 } while (/*CONSTCOND*/ 0)
684
685 #define IFQ_CLASSIFY(ifq, m, af, pa) \
686 do { \
687 if (ALTQ_IS_ENABLED((ifq))) { \
688 if (ALTQ_NEEDS_CLASSIFY((ifq))) \
689 (pa)->pattr_class = (*(ifq)->altq_classify) \
690 ((ifq)->altq_clfier, (m), (af)); \
691 (pa)->pattr_af = (af); \
692 (pa)->pattr_hdr = mtod((m), caddr_t); \
693 } \
694 } while (/*CONSTCOND*/ 0)
695 #else /* ! ALTQ */
696 #define ALTQ_DECL(x) /* nothing */
697
698 #define IFQ_ENQUEUE(ifq, m, pattr, err) \
699 do { \
700 if (IF_QFULL((ifq))) { \
701 m_freem((m)); \
702 (err) = ENOBUFS; \
703 } else { \
704 IF_ENQUEUE((ifq), (m)); \
705 (err) = 0; \
706 } \
707 if ((err)) \
708 (ifq)->ifq_drops++; \
709 } while (/*CONSTCOND*/ 0)
710
711 #define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m))
712
713 #define IFQ_POLL(ifq, m) IF_POLL((ifq), (m))
714
715 #define IFQ_PURGE(ifq) IF_PURGE((ifq))
716
717 #define IFQ_SET_READY(ifq) /* nothing */
718
719 #define IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */
720
721 #endif /* ALTQ */
722
723 #define IFQ_IS_EMPTY(ifq) IF_IS_EMPTY((ifq))
724 #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
725 #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
726 #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
727 #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
728
729 #include <sys/mallocvar.h>
730 MALLOC_DECLARE(M_IFADDR);
731 MALLOC_DECLARE(M_IFMADDR);
732
733 #define IFNET_FOREACH(ifp) TAILQ_FOREACH(ifp, &ifnet, if_list)
734 #define IFADDR_FOREACH(ifa, ifp) TAILQ_FOREACH(ifa, \
735 &(ifp)->if_addrlist, ifa_list)
736
737 extern struct ifnet_head ifnet;
738 extern struct ifnet **ifindex2ifnet;
739 extern struct ifnet *lo0ifp;
740 extern size_t if_indexlim;
741
742 char *ether_sprintf __P((const u_char *));
743
744 void if_alloc_sadl __P((struct ifnet *));
745 void if_free_sadl __P((struct ifnet *));
746 void if_attach __P((struct ifnet *));
747 void if_attachdomain __P((void));
748 void if_attachdomain1 __P((struct ifnet *));
749 void if_deactivate __P((struct ifnet *));
750 void if_detach __P((struct ifnet *));
751 void if_down __P((struct ifnet *));
752 void if_slowtimo __P((void *));
753 void if_up __P((struct ifnet *));
754 int ifconf __P((u_long, caddr_t));
755 void ifinit __P((void));
756 int ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
757 int ifpromisc __P((struct ifnet *, int));
758 struct ifnet *ifunit __P((const char *));
759
760 struct ifaddr *ifa_ifwithaddr __P((const struct sockaddr *));
761 struct ifaddr *ifa_ifwithaf __P((int));
762 struct ifaddr *ifa_ifwithdstaddr __P((const struct sockaddr *));
763 struct ifaddr *ifa_ifwithnet __P((const struct sockaddr *));
764 struct ifaddr *ifa_ifwithladdr __P((const struct sockaddr *));
765 struct ifaddr *ifa_ifwithroute __P((int, const struct sockaddr *,
766 const struct sockaddr *));
767 struct ifaddr *ifaof_ifpforaddr __P((const struct sockaddr *, struct ifnet *));
768 void ifafree __P((struct ifaddr *));
769 void link_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
770
771 void if_clone_attach __P((struct if_clone *));
772 void if_clone_detach __P((struct if_clone *));
773
774 int if_clone_create __P((const char *));
775 int if_clone_destroy __P((const char *));
776
777 int loioctl __P((struct ifnet *, u_long, caddr_t));
778 void loopattach __P((int));
779 int looutput __P((struct ifnet *,
780 struct mbuf *, struct sockaddr *, struct rtentry *));
781 void lortrequest __P((int, struct rtentry *, struct rt_addrinfo *));
782
783 /*
784 * These are exported because they're an easy way to tell if
785 * an interface is going away without having to burn a flag.
786 */
787 int if_nulloutput __P((struct ifnet *, struct mbuf *,
788 struct sockaddr *, struct rtentry *));
789 void if_nullinput __P((struct ifnet *, struct mbuf *));
790 void if_nullstart __P((struct ifnet *));
791 int if_nullioctl __P((struct ifnet *, u_long, caddr_t));
792 int if_nullinit __P((struct ifnet *));
793 void if_nullstop __P((struct ifnet *, int));
794 void if_nullwatchdog __P((struct ifnet *));
795 void if_nulldrain __P((struct ifnet *));
796 #else
797 struct if_nameindex {
798 unsigned int if_index; /* 1, 2, ... */
799 char *if_name; /* null terminated name: "le0", ... */
800 };
801
802 #include <sys/cdefs.h>
803 __BEGIN_DECLS
804 unsigned int if_nametoindex __P((const char *));
805 char * if_indextoname __P((unsigned int, char *));
806 struct if_nameindex * if_nameindex __P((void));
807 void if_freenameindex __P((struct if_nameindex *));
808 __END_DECLS
809 #endif /* _KERNEL */ /* XXX really ALTQ? */
810
811 #ifdef _KERNEL
812 /*
813 * ifq sysctl support
814 */
815 int sysctl_ifq __P((int *name, u_int namelen, void *oldp,
816 size_t *oldlenp, void *newp, size_t newlen,
817 struct ifqueue *ifq));
818 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
819 #define IFQCTL_LEN 1
820 #define IFQCTL_MAXLEN 2
821 #define IFQCTL_PEAK 3
822 #define IFQCTL_DROPS 4
823 #define IFQCTL_MAXID 5
824
825 #endif /* _KERNEL */
826
827 #ifdef _NETBSD_SOURCE
828 /*
829 * sysctl for ifq (per-protocol packet input queue variant of ifqueue)
830 */
831 #define CTL_IFQ_NAMES { \
832 { 0, 0 }, \
833 { "len", CTLTYPE_INT }, \
834 { "maxlen", CTLTYPE_INT }, \
835 { "peak", CTLTYPE_INT }, \
836 { "drops", CTLTYPE_INT }, \
837 }
838 #endif /* _NETBSD_SOURCE */
839 #endif /* !_NET_IF_H_ */
Cache object: 72bdeea342612fc2d6a0c8fad36e9a1d
|