Annotation of sys/net/if.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: if.h,v 1.91 2007/06/25 16:37:58 henning Exp $ */
2: /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
3:
4: /*
5: * Copyright (c) 1982, 1986, 1989, 1993
6: * The Regents of the University of California. All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. Neither the name of the University nor the names of its contributors
17: * may be used to endorse or promote products derived from this software
18: * without specific prior written permission.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
32: * @(#)if.h 8.1 (Berkeley) 6/10/93
33: */
34:
35: #ifndef _NET_IF_H_
36: #define _NET_IF_H_
37:
38: #include <sys/queue.h>
39:
40: /*
41: * Always include ALTQ glue here -- we use the ALTQ interface queue
42: * structure even when ALTQ is not configured into the kernel so that
43: * the size of struct ifnet does not changed based on the option. The
44: * ALTQ queue structure is API-compatible with the legacy ifqueue.
45: */
46: #include <altq/if_altq.h>
47:
48: /*
49: * Structures defining a network interface, providing a packet
50: * transport mechanism (ala level 0 of the PUP protocols).
51: *
52: * Each interface accepts output datagrams of a specified maximum
53: * length, and provides higher level routines with input datagrams
54: * received from its medium.
55: *
56: * Output occurs when the routine if_output is called, with four parameters:
57: * (*ifp->if_output)(ifp, m, dst, rt)
58: * Here m is the mbuf chain to be sent and dst is the destination address.
59: * The output routine encapsulates the supplied datagram if necessary,
60: * and then transmits it on its medium.
61: *
62: * On input, each interface unwraps the data received by it, and either
63: * places it on the input queue of an internetwork datagram routine
64: * and posts the associated software interrupt, or passes the datagram to a raw
65: * packet input routine.
66: *
67: * Routines exist for locating interfaces by their addresses
68: * or for locating an interface on a certain network, as well as more general
69: * routing and gateway routines maintaining information used to locate
70: * interfaces. These routines live in the files if.c and route.c
71: */
72: /* XXX fast fix for SNMP, going away soon */
73: #include <sys/time.h>
74:
75: struct mbuf;
76: struct proc;
77: struct rtentry;
78: struct socket;
79: struct ether_header;
80: struct arpcom;
81: struct rt_addrinfo;
82:
83: /*
84: * Structure describing a `cloning' interface.
85: */
86: struct if_clone {
87: LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */
88: const char *ifc_name; /* name of device, e.g. `gif' */
89: size_t ifc_namelen; /* length of name */
90:
91: int (*ifc_create)(struct if_clone *, int);
92: int (*ifc_destroy)(struct ifnet *);
93: };
94:
95: #define IF_CLONE_INITIALIZER(name, create, destroy) \
96: { { 0 }, name, sizeof(name) - 1, create, destroy }
97:
98: /*
99: * Structure used to query names of interface cloners.
100: */
101: struct if_clonereq {
102: int ifcr_total; /* total cloners (out) */
103: int ifcr_count; /* room for this many in user buffer */
104: char *ifcr_buffer; /* buffer for cloner names */
105: };
106:
107: /*
108: * Structure defining statistics and other data kept regarding a network
109: * interface.
110: */
111: struct if_data {
112: /* generic interface information */
113: u_char ifi_type; /* ethernet, tokenring, etc. */
114: u_char ifi_addrlen; /* media address length */
115: u_char ifi_hdrlen; /* media header length */
116: u_char ifi_link_state; /* current link state */
117: u_long ifi_mtu; /* maximum transmission unit */
118: u_long ifi_metric; /* routing metric (external only) */
119: u_long ifi_baudrate; /* linespeed */
120: /* volatile statistics */
121: u_long ifi_ipackets; /* packets received on interface */
122: u_long ifi_ierrors; /* input errors on interface */
123: u_long ifi_opackets; /* packets sent on interface */
124: u_long ifi_oerrors; /* output errors on interface */
125: u_long ifi_collisions; /* collisions on csma interfaces */
126: u_long ifi_ibytes; /* total number of octets received */
127: u_long ifi_obytes; /* total number of octets sent */
128: u_long ifi_imcasts; /* packets received via multicast */
129: u_long ifi_omcasts; /* packets sent via multicast */
130: u_long ifi_iqdrops; /* dropped on input, this interface */
131: u_long ifi_noproto; /* destined for unsupported protocol */
132: struct timeval ifi_lastchange; /* last operational state change */
133: };
134:
135: /*
136: * Structure defining a queue for a network interface.
137: */
138: struct ifqueue {
139: struct mbuf *ifq_head;
140: struct mbuf *ifq_tail;
141: int ifq_len;
142: int ifq_maxlen;
143: int ifq_drops;
144: struct timeout *ifq_congestion;
145: };
146:
147: /*
148: * Values for if_link_state.
149: */
150: #define LINK_STATE_UNKNOWN 0 /* link invalid/unknown */
151: #define LINK_STATE_DOWN 1 /* link is down */
152: #define LINK_STATE_UP 2 /* link is up */
153: #define LINK_STATE_HALF_DUPLEX 3 /* link is up and half duplex */
154: #define LINK_STATE_FULL_DUPLEX 4 /* link is up and full duplex */
155: #define LINK_STATE_IS_UP(_s) ((_s) >= LINK_STATE_UP)
156:
157: /*
158: * Structure defining a queue for a network interface.
159: *
160: * (Would like to call this struct ``if'', but C isn't PL/1.)
161: */
162: TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */
163:
164: /*
165: * Length of interface external name, including terminating '\0'.
166: * Note: this is the same size as a generic device's external name.
167: */
168: #define IFNAMSIZ 16
169: #define IF_NAMESIZE IFNAMSIZ
170:
171: /*
172: * Length of interface description, including terminating '\0'.
173: */
174: #define IFDESCRSIZE 64
175:
176: struct ifnet { /* and the entries */
177: void *if_softc; /* lower-level data for this if */
178: TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */
179: TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
180: TAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if */
181: struct hook_desc_head *if_addrhooks; /* address change callbacks */
182: struct hook_desc_head *if_linkstatehooks; /* link change callbacks */
183: struct hook_desc_head *if_detachhooks; /* detach callbacks */
184: char if_xname[IFNAMSIZ]; /* external name (name + unit) */
185: int if_pcount; /* number of promiscuous listeners */
186: caddr_t if_bpf; /* packet filter structure */
187: caddr_t if_bridge; /* bridge structure */
188: caddr_t if_tp; /* used by trunk ports */
189: caddr_t if_pf_kif; /* pf interface abstraction */
190: union {
191: caddr_t carp_s; /* carp structure (used by !carp ifs) */
192: struct ifnet *carp_d; /* ptr to carpdev (used by carp ifs) */
193: } if_carp_ptr;
194: #define if_carp if_carp_ptr.carp_s
195: #define if_carpdev if_carp_ptr.carp_d
196: u_short if_index; /* numeric abbreviation for this if */
197: short if_timer; /* time 'til if_watchdog called */
198: short if_flags; /* up/down, broadcast, etc. */
199: struct if_data if_data; /* stats and other data about if */
200: u_int32_t if_hardmtu; /* maximum MTU device supports */
201: int if_capabilities; /* interface capabilities */
202: char if_description[IFDESCRSIZE]; /* interface description */
203: u_short if_rtlabelid; /* next route label */
204:
205: /* procedure handles */
206: /* output routine (enqueue) */
207: int (*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *,
208: struct rtentry *);
209: /* initiate output routine */
210: void (*if_start)(struct ifnet *);
211: /* ioctl routine */
212: int (*if_ioctl)(struct ifnet *, u_long, caddr_t);
213: /* init routine */
214: int (*if_init)(struct ifnet *);
215: /* XXX bus reset routine */
216: int (*if_reset)(struct ifnet *);
217: /* timer routine */
218: void (*if_watchdog)(struct ifnet *);
219: struct ifaltq if_snd; /* output queue (includes altq) */
220: struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */
221:
222: void *if_afdata[AF_MAX];
223: };
224: #define if_mtu if_data.ifi_mtu
225: #define if_type if_data.ifi_type
226: #define if_addrlen if_data.ifi_addrlen
227: #define if_hdrlen if_data.ifi_hdrlen
228: #define if_metric if_data.ifi_metric
229: #define if_link_state if_data.ifi_link_state
230: #define if_baudrate if_data.ifi_baudrate
231: #define if_ipackets if_data.ifi_ipackets
232: #define if_ierrors if_data.ifi_ierrors
233: #define if_opackets if_data.ifi_opackets
234: #define if_oerrors if_data.ifi_oerrors
235: #define if_collisions if_data.ifi_collisions
236: #define if_ibytes if_data.ifi_ibytes
237: #define if_obytes if_data.ifi_obytes
238: #define if_imcasts if_data.ifi_imcasts
239: #define if_omcasts if_data.ifi_omcasts
240: #define if_iqdrops if_data.ifi_iqdrops
241: #define if_noproto if_data.ifi_noproto
242: #define if_lastchange if_data.ifi_lastchange
243:
244: #define IFF_UP 0x1 /* interface is up */
245: #define IFF_BROADCAST 0x2 /* broadcast address valid */
246: #define IFF_DEBUG 0x4 /* turn on debugging */
247: #define IFF_LOOPBACK 0x8 /* is a loopback net */
248: #define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
249: #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */
250: #define IFF_RUNNING 0x40 /* resources allocated */
251: #define IFF_NOARP 0x80 /* no address resolution protocol */
252: #define IFF_PROMISC 0x100 /* receive all packets */
253: #define IFF_ALLMULTI 0x200 /* receive all multicast packets */
254: #define IFF_OACTIVE 0x400 /* transmission in progress */
255: #define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
256: #define IFF_LINK0 0x1000 /* per link layer defined bit */
257: #define IFF_LINK1 0x2000 /* per link layer defined bit */
258: #define IFF_LINK2 0x4000 /* per link layer defined bit */
259: #define IFF_MULTICAST 0x8000 /* supports multicast */
260:
261: /* flags set internally only: */
262: #define IFF_CANTCHANGE \
263: (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
264: IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
265:
266: /*
267: * Some convenience macros used for setting ifi_baudrate.
268: */
269: #define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */
270: #define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */
271: #define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */
272:
273: /* Capabilities that interfaces can advertise. */
274: #define IFCAP_CSUM_IPv4 0x00000001 /* can do IPv4 header csum */
275: #define IFCAP_CSUM_TCPv4 0x00000002 /* can do IPv4/TCP csum */
276: #define IFCAP_CSUM_UDPv4 0x00000004 /* can do IPv4/UDP csum */
277: #define IFCAP_IPSEC 0x00000008 /* can do IPsec */
278: #define IFCAP_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */
279: #define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */
280: #define IFCAP_IPCOMP 0x00000040 /* can do IPcomp */
281: #define IFCAP_CSUM_TCPv6 0x00000080 /* can do IPv6/TCP checksums */
282: #define IFCAP_CSUM_UDPv6 0x00000100 /* can do IPv6/UDP checksums */
283: #define IFCAP_CSUM_TCPv4_Rx 0x00000200 /* can do IPv4/TCP (Rx only) */
284: #define IFCAP_CSUM_UDPv4_Rx 0x00000400 /* can do IPv4/UDP (Rx only) */
285:
286: /*
287: * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
288: * input routines have queues of messages stored on ifqueue structures
289: * (defined above). Entries are added to and deleted from these structures
290: * by these macros, which should be called with ipl raised to splnet().
291: */
292: #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
293: #define IF_DROP(ifq) ((ifq)->ifq_drops++)
294: #define IF_ENQUEUE(ifq, m) \
295: do { \
296: (m)->m_nextpkt = 0; \
297: if ((ifq)->ifq_tail == 0) \
298: (ifq)->ifq_head = m; \
299: else \
300: (ifq)->ifq_tail->m_nextpkt = m; \
301: (ifq)->ifq_tail = m; \
302: (ifq)->ifq_len++; \
303: } while (0)
304: #define IF_PREPEND(ifq, m) \
305: do { \
306: (m)->m_nextpkt = (ifq)->ifq_head; \
307: if ((ifq)->ifq_tail == 0) \
308: (ifq)->ifq_tail = (m); \
309: (ifq)->ifq_head = (m); \
310: (ifq)->ifq_len++; \
311: } while (0)
312: #define IF_DEQUEUE(ifq, m) \
313: do { \
314: (m) = (ifq)->ifq_head; \
315: if (m) { \
316: if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
317: (ifq)->ifq_tail = 0; \
318: (m)->m_nextpkt = 0; \
319: (ifq)->ifq_len--; \
320: } \
321: } while (0)
322:
323: #define IF_INPUT_ENQUEUE(ifq, m) \
324: do { \
325: if (IF_QFULL(ifq)) { \
326: IF_DROP(ifq); \
327: m_freem(m); \
328: if (!(ifq)->ifq_congestion) \
329: if_congestion(ifq); \
330: } else \
331: IF_ENQUEUE(ifq, m); \
332: } while (0)
333:
334: #define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head)
335: #define IF_PURGE(ifq) \
336: do { \
337: struct mbuf *__m0; \
338: \
339: for (;;) { \
340: IF_DEQUEUE((ifq), __m0); \
341: if (__m0 == NULL) \
342: break; \
343: else \
344: m_freem(__m0); \
345: } \
346: } while (0)
347: #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
348:
349: #define IFQ_MAXLEN 256
350: #define IFNET_SLOWHZ 1 /* granularity is 1 second */
351:
352: /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */
353: #define IFQCTL_LEN 1
354: #define IFQCTL_MAXLEN 2
355: #define IFQCTL_DROPS 3
356: #define IFQCTL_CONGESTION 4
357: #define IFQCTL_MAXID 5
358:
359: /* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */
360: #define CTL_IFQ_NAMES { \
361: { 0, 0 }, \
362: { "len", CTLTYPE_INT }, \
363: { "maxlen", CTLTYPE_INT }, \
364: { "drops", CTLTYPE_INT }, \
365: { "congestion", CTLTYPE_INT }, \
366: }
367:
368: /*
369: * The ifaddr structure contains information about one address
370: * of an interface. They are maintained by the different address families,
371: * are allocated and attached when an address is set, and are linked
372: * together so all addresses for an interface can be located.
373: */
374: struct ifaddr {
375: struct sockaddr *ifa_addr; /* address of interface */
376: struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */
377: #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
378: struct sockaddr *ifa_netmask; /* used to determine subnet */
379: struct ifnet *ifa_ifp; /* back-pointer to interface */
380: TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */
381: /* check or clean routes (+ or -)'d */
382: void (*ifa_rtrequest)(int, struct rtentry *, struct rt_addrinfo *);
383: u_int ifa_flags; /* mostly rt_flags for cloning */
384: u_int ifa_refcnt; /* count of references */
385: int ifa_metric; /* cost of going out this interface */
386: };
387: #define IFA_ROUTE RTF_UP /* route installed */
388:
389: /*
390: * Message format for use in obtaining information about interfaces
391: * from sysctl and the routing socket.
392: */
393: struct if_msghdr {
394: u_short ifm_msglen; /* to skip over non-understood messages */
395: u_char ifm_version; /* future binary compatibility */
396: u_char ifm_type; /* message type */
397: int ifm_addrs; /* like rtm_addrs */
398: int ifm_flags; /* value of if_flags */
399: u_short ifm_index; /* index for associated ifp */
400: struct if_data ifm_data;/* statistics and other data about if */
401: };
402:
403: /*
404: * Message format for use in obtaining information about interface addresses
405: * from sysctl and the routing socket.
406: */
407: struct ifa_msghdr {
408: u_short ifam_msglen; /* to skip over non-understood messages */
409: u_char ifam_version; /* future binary compatibility */
410: u_char ifam_type; /* message type */
411: int ifam_addrs; /* like rtm_addrs */
412: int ifam_flags; /* value of ifa_flags */
413: u_short ifam_index; /* index for associated ifp */
414: int ifam_metric; /* value of ifa_metric */
415: };
416:
417:
418: /*
419: * Message format announcing the arrival or departure of a network interface.
420: */
421: struct if_announcemsghdr {
422: u_short ifan_msglen; /* to skip over non-understood messages */
423: u_char ifan_version; /* future binary compatibility */
424: u_char ifan_type; /* message type */
425: u_short ifan_index; /* index for associated ifp */
426: char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */
427: u_short ifan_what; /* what type of announcement */
428: };
429:
430: #define IFAN_ARRIVAL 0 /* interface arrival */
431: #define IFAN_DEPARTURE 1 /* interface departure */
432:
433: /*
434: * interface groups
435: */
436:
437: #define IFG_ALL "all" /* group contains all interfaces */
438: #define IFG_EGRESS "egress" /* if(s) default route(s) point to */
439:
440: struct ifg_group {
441: char ifg_group[IFNAMSIZ];
442: u_int ifg_refcnt;
443: caddr_t ifg_pf_kif;
444: int ifg_carp_demoted;
445: TAILQ_HEAD(, ifg_member) ifg_members;
446: TAILQ_ENTRY(ifg_group) ifg_next;
447: };
448:
449: struct ifg_member {
450: TAILQ_ENTRY(ifg_member) ifgm_next;
451: struct ifnet *ifgm_ifp;
452: };
453:
454: struct ifg_list {
455: struct ifg_group *ifgl_group;
456: TAILQ_ENTRY(ifg_list) ifgl_next;
457: };
458:
459: struct ifg_req {
460: union {
461: char ifgrqu_group[IFNAMSIZ];
462: char ifgrqu_member[IFNAMSIZ];
463: } ifgrq_ifgrqu;
464: #define ifgrq_group ifgrq_ifgrqu.ifgrqu_group
465: #define ifgrq_member ifgrq_ifgrqu.ifgrqu_member
466: };
467:
468: struct ifg_attrib {
469: int ifg_carp_demoted;
470: };
471:
472: /*
473: * Used to lookup groups for an interface
474: */
475: struct ifgroupreq {
476: char ifgr_name[IFNAMSIZ];
477: u_int ifgr_len;
478: union {
479: char ifgru_group[IFNAMSIZ];
480: struct ifg_req *ifgru_groups;
481: struct ifg_attrib ifgru_attrib;
482: } ifgr_ifgru;
483: #define ifgr_group ifgr_ifgru.ifgru_group
484: #define ifgr_groups ifgr_ifgru.ifgru_groups
485: #define ifgr_attrib ifgr_ifgru.ifgru_attrib
486: };
487:
488: /*
489: * Interface request structure used for socket
490: * ioctl's. All interface ioctl's must have parameter
491: * definitions which begin with ifr_name. The
492: * remainder may be interface specific.
493: */
494: struct ifreq {
495: char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
496: union {
497: struct sockaddr ifru_addr;
498: struct sockaddr ifru_dstaddr;
499: struct sockaddr ifru_broadaddr;
500: short ifru_flags;
501: int ifru_metric;
502: caddr_t ifru_data;
503: } ifr_ifru;
504: #define ifr_addr ifr_ifru.ifru_addr /* address */
505: #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
506: #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
507: #define ifr_flags ifr_ifru.ifru_flags /* flags */
508: #define ifr_metric ifr_ifru.ifru_metric /* metric */
509: #define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */
510: #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */
511: #define ifr_data ifr_ifru.ifru_data /* for use by interface */
512: };
513:
514: struct ifaliasreq {
515: char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
516: struct sockaddr ifra_addr;
517: struct sockaddr ifra_dstaddr;
518: #define ifra_broadaddr ifra_dstaddr
519: struct sockaddr ifra_mask;
520: };
521:
522: struct ifmediareq {
523: char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
524: int ifm_current; /* current media options */
525: int ifm_mask; /* don't care mask */
526: int ifm_status; /* media status */
527: int ifm_active; /* active options */
528: int ifm_count; /* # entries in ifm_ulist
529: array */
530: int *ifm_ulist; /* media words */
531: };
532:
533: /*
534: * Structure used in SIOCGIFCONF request.
535: * Used to retrieve interface configuration
536: * for machine (useful for programs which
537: * must know all networks accessible).
538: */
539: struct ifconf {
540: int ifc_len; /* size of associated buffer */
541: union {
542: caddr_t ifcu_buf;
543: struct ifreq *ifcu_req;
544: } ifc_ifcu;
545: #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
546: #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
547: };
548:
549: /*
550: * Structure for SIOC[AGD]LIFADDR
551: */
552: struct if_laddrreq {
553: char iflr_name[IFNAMSIZ];
554: unsigned int flags;
555: #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */
556: unsigned int prefixlen; /* in/out */
557: struct sockaddr_storage addr; /* in/out */
558: struct sockaddr_storage dstaddr; /* out */
559: };
560:
561: struct if_nameindex {
562: unsigned int if_index;
563: char *if_name;
564: };
565:
566: #ifndef _KERNEL
567: __BEGIN_DECLS
568: unsigned int if_nametoindex(const char *);
569: char *if_indextoname(unsigned int, char *);
570: struct if_nameindex *if_nameindex(void);
571: __END_DECLS
572: #define if_freenameindex(x) free(x)
573: #endif
574:
575: #include <net/if_arp.h>
576:
577: #ifdef _KERNEL
578: #define IFAFREE(ifa) \
579: do { \
580: if ((ifa)->ifa_refcnt <= 0) \
581: ifafree(ifa); \
582: else \
583: (ifa)->ifa_refcnt--; \
584: } while (0)
585:
586: #ifdef ALTQ
587: #define ALTQ_DECL(x) x
588:
589: #define IFQ_ENQUEUE(ifq, m, pattr, err) \
590: do { \
591: if (ALTQ_IS_ENABLED((ifq))) \
592: ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \
593: else { \
594: if (IF_QFULL((ifq))) { \
595: m_freem((m)); \
596: (err) = ENOBUFS; \
597: } else { \
598: IF_ENQUEUE((ifq), (m)); \
599: (err) = 0; \
600: } \
601: } \
602: if ((err)) \
603: (ifq)->ifq_drops++; \
604: } while (0)
605:
606: #define IFQ_DEQUEUE(ifq, m) \
607: do { \
608: if (TBR_IS_ENABLED((ifq))) \
609: (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \
610: else if (ALTQ_IS_ENABLED((ifq))) \
611: ALTQ_DEQUEUE((ifq), (m)); \
612: else \
613: IF_DEQUEUE((ifq), (m)); \
614: } while (0)
615:
616: #define IFQ_POLL(ifq, m) \
617: do { \
618: if (TBR_IS_ENABLED((ifq))) \
619: (m) = tbr_dequeue((ifq), ALTDQ_POLL); \
620: else if (ALTQ_IS_ENABLED((ifq))) \
621: ALTQ_POLL((ifq), (m)); \
622: else \
623: IF_POLL((ifq), (m)); \
624: } while (0)
625:
626: #define IFQ_PURGE(ifq) \
627: do { \
628: if (ALTQ_IS_ENABLED((ifq))) \
629: ALTQ_PURGE((ifq)); \
630: else \
631: IF_PURGE((ifq)); \
632: } while (0)
633:
634: #define IFQ_SET_READY(ifq) \
635: do { ((ifq)->altq_flags |= ALTQF_READY); } while (0)
636:
637: #define IFQ_CLASSIFY(ifq, m, af, pa) \
638: do { \
639: if (ALTQ_IS_ENABLED((ifq))) { \
640: if (ALTQ_NEEDS_CLASSIFY((ifq))) \
641: (pa)->pattr_class = (*(ifq)->altq_classify) \
642: ((ifq)->altq_clfier, (m), (af)); \
643: (pa)->pattr_af = (af); \
644: (pa)->pattr_hdr = mtod((m), caddr_t); \
645: } \
646: } while (0)
647:
648: #else /* !ALTQ */
649: #define ALTQ_DECL(x) /* nothing */
650:
651: #define IFQ_ENQUEUE(ifq, m, pattr, err) \
652: do { \
653: if (IF_QFULL((ifq))) { \
654: m_freem((m)); \
655: (err) = ENOBUFS; \
656: } else { \
657: IF_ENQUEUE((ifq), (m)); \
658: (err) = 0; \
659: } \
660: if ((err)) \
661: (ifq)->ifq_drops++; \
662: } while (0)
663:
664: #define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m))
665:
666: #define IFQ_POLL(ifq, m) IF_POLL((ifq), (m))
667:
668: #define IFQ_PURGE(ifq) IF_PURGE((ifq))
669:
670: #define IFQ_SET_READY(ifq) /* nothing */
671:
672: #define IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */
673:
674: #endif /* ALTQ */
675:
676: #define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0)
677: #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++)
678: #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len)
679: #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++)
680: #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len))
681:
682: extern int ifqmaxlen;
683: extern struct ifnet_head ifnet;
684: extern struct ifnet **ifindex2ifnet;
685: extern struct ifnet *lo0ifp;
686: extern int if_indexlim;
687:
688: #define ether_input_mbuf(ifp, m) ether_input((ifp), NULL, (m))
689:
690: void ether_ifattach(struct ifnet *);
691: void ether_ifdetach(struct ifnet *);
692: int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t);
693: void ether_input(struct ifnet *, struct ether_header *, struct mbuf *);
694: int ether_output(struct ifnet *,
695: struct mbuf *, struct sockaddr *, struct rtentry *);
696: char *ether_sprintf(u_char *);
697:
698: void if_alloc_sadl(struct ifnet *);
699: void if_free_sadl(struct ifnet *);
700: void if_attach(struct ifnet *);
701: void if_attachdomain(void);
702: void if_attachtail(struct ifnet *);
703: void if_attachhead(struct ifnet *);
704: void if_detach(struct ifnet *);
705: void if_down(struct ifnet *);
706: void if_link_state_change(struct ifnet *);
707: void if_qflush(struct ifqueue *);
708: void if_slowtimo(void *);
709: void if_up(struct ifnet *);
710: int ifconf(u_long, caddr_t);
711: void ifinit(void);
712: int ifioctl(struct socket *, u_long, caddr_t, struct proc *);
713: int ifpromisc(struct ifnet *, int);
714: struct ifg_group *if_creategroup(const char *);
715: int if_addgroup(struct ifnet *, const char *);
716: int if_delgroup(struct ifnet *, const char *);
717: void if_group_routechange(struct sockaddr *, struct sockaddr *);
718: struct ifnet *ifunit(const char *);
719:
720: struct ifaddr *ifa_ifwithaddr(struct sockaddr *);
721: struct ifaddr *ifa_ifwithaf(int);
722: struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *);
723: struct ifaddr *ifa_ifwithnet(struct sockaddr *);
724: struct ifaddr *ifa_ifwithroute(int, struct sockaddr *,
725: struct sockaddr *);
726: struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *);
727: void ifafree(struct ifaddr *);
728: void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
729:
730: void if_clone_attach(struct if_clone *);
731: void if_clone_detach(struct if_clone *);
732:
733: int if_clone_create(const char *);
734: int if_clone_destroy(const char *);
735:
736: void if_congestion(struct ifqueue *);
737: int sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t,
738: struct ifqueue *);
739:
740: int loioctl(struct ifnet *, u_long, caddr_t);
741: void loopattach(int);
742: int looutput(struct ifnet *,
743: struct mbuf *, struct sockaddr *, struct rtentry *);
744: void lortrequest(int, struct rtentry *, struct rt_addrinfo *);
745: #endif /* _KERNEL */
746: #endif /* _NET_IF_H_ */
CVSweb