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