if.h revision 1.53
1/* $OpenBSD: if.h,v 1.53 2004/05/29 17:54:45 jcs 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 a 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 a 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 75struct mbuf; 76struct proc; 77struct rtentry; 78struct socket; 79struct ether_header; 80struct arpcom; 81struct rt_addrinfo; 82 83/* 84 * Structure describing a `cloning' interface. 85 */ 86struct 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 */ 101struct 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 */ 111struct 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 */ 138struct ifqueue { 139 struct mbuf *ifq_head; 140 struct mbuf *ifq_tail; 141 int ifq_len; 142 int ifq_maxlen; 143 int ifq_drops; 144 int 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 154/* 155 * Structure defining a queue for a network interface. 156 * 157 * (Would like to call this struct ``if'', but C isn't PL/1.) 158 */ 159TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ 160 161/* 162 * Length of interface external name, including terminating '\0'. 163 * Note: this is the same size as a generic device's external name. 164 */ 165#define IFNAMSIZ 16 166#define IF_NAMESIZE IFNAMSIZ 167 168/* 169 * Length of interface description, including terminating '\0'. 170 */ 171#define IFDESCRSIZE 64 172 173struct ifnet { /* and the entries */ 174 void *if_softc; /* lower-level data for this if */ 175 TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */ 176 TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */ 177 struct hook_desc_head *if_addrhooks; /* address change callbacks */ 178 char if_xname[IFNAMSIZ]; /* external name (name + unit) */ 179 int if_pcount; /* number of promiscuous listeners */ 180 caddr_t if_bpf; /* packet filter structure */ 181 caddr_t if_bridge; /* bridge structure */ 182 caddr_t if_carp; /* carp structure */ 183 u_short if_index; /* numeric abbreviation for this if */ 184 short if_timer; /* time 'til if_watchdog called */ 185 short if_flags; /* up/down, broadcast, etc. */ 186 struct if_data if_data; /* stats and other data about if */ 187 int if_capabilities; /* interface capabilities */ 188 char if_description[IFDESCRSIZE]; /* interface description */ 189 190 /* procedure handles */ 191 /* output routine (enqueue) */ 192 int (*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 193 struct rtentry *); 194 /* initiate output routine */ 195 void (*if_start)(struct ifnet *); 196 /* ioctl routine */ 197 int (*if_ioctl)(struct ifnet *, u_long, caddr_t); 198 /* init routine */ 199 int (*if_init)(struct ifnet *); 200 /* XXX bus reset routine */ 201 int (*if_reset)(struct ifnet *); 202 /* timer routine */ 203 void (*if_watchdog)(struct ifnet *); 204 struct ifaltq if_snd; /* output queue (includes altq) */ 205 struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */ 206 207 void *if_afdata[AF_MAX]; 208}; 209#define if_mtu if_data.ifi_mtu 210#define if_type if_data.ifi_type 211#define if_addrlen if_data.ifi_addrlen 212#define if_hdrlen if_data.ifi_hdrlen 213#define if_metric if_data.ifi_metric 214#define if_link_state if_data.ifi_link_state 215#define if_baudrate if_data.ifi_baudrate 216#define if_ipackets if_data.ifi_ipackets 217#define if_ierrors if_data.ifi_ierrors 218#define if_opackets if_data.ifi_opackets 219#define if_oerrors if_data.ifi_oerrors 220#define if_collisions if_data.ifi_collisions 221#define if_ibytes if_data.ifi_ibytes 222#define if_obytes if_data.ifi_obytes 223#define if_imcasts if_data.ifi_imcasts 224#define if_omcasts if_data.ifi_omcasts 225#define if_iqdrops if_data.ifi_iqdrops 226#define if_noproto if_data.ifi_noproto 227#define if_lastchange if_data.ifi_lastchange 228 229#define IFF_UP 0x1 /* interface is up */ 230#define IFF_BROADCAST 0x2 /* broadcast address valid */ 231#define IFF_DEBUG 0x4 /* turn on debugging */ 232#define IFF_LOOPBACK 0x8 /* is a loopback net */ 233#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 234#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 235#define IFF_RUNNING 0x40 /* resources allocated */ 236#define IFF_NOARP 0x80 /* no address resolution protocol */ 237#define IFF_PROMISC 0x100 /* receive all packets */ 238#define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 239#define IFF_OACTIVE 0x400 /* transmission in progress */ 240#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 241#define IFF_LINK0 0x1000 /* per link layer defined bit */ 242#define IFF_LINK1 0x2000 /* per link layer defined bit */ 243#define IFF_LINK2 0x4000 /* per link layer defined bit */ 244#define IFF_MULTICAST 0x8000 /* supports multicast */ 245 246/* flags set internally only: */ 247#define IFF_CANTCHANGE \ 248 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ 249 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI) 250 251/* 252 * Some convenience macros used for setting ifi_baudrate. 253 */ 254#define IF_Kbps(x) ((x) * 1000) /* kilobits/sec. */ 255#define IF_Mbps(x) (IF_Kbps((x) * 1000)) /* megabits/sec. */ 256#define IF_Gbps(x) (IF_Mbps((x) * 1000)) /* gigabits/sec. */ 257 258/* Capabilities that interfaces can advertise. */ 259#define IFCAP_CSUM_IPv4 0x00000001 /* can do IPv4 header csum */ 260#define IFCAP_CSUM_TCPv4 0x00000002 /* can do IPv4/TCP csum */ 261#define IFCAP_CSUM_UDPv4 0x00000004 /* can do IPv4/UDP csum */ 262#define IFCAP_IPSEC 0x00000008 /* can do IPsec */ 263#define IFCAP_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */ 264#define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */ 265#define IFCAP_IPCOMP 0x00000040 /* can do IPcomp */ 266#define IFCAP_JUMBO_MTU 0x00000080 /* 9000 byte MTU supported */ 267#define IFCAP_CSUM_TCPv6 0x00000100 /* can do IPv6/TCP checksums */ 268#define IFCAP_CSUM_UDPv6 0x00000200 /* can do IPv6/UDP checksums */ 269#define IFCAP_CSUM_TCPv4_Rx 0x00000400 /* can do IPv4/TCP (Rx only) */ 270#define IFCAP_CSUM_UDPv4_Rx 0x00000800 /* can do IPv4/UDP (Rx only) */ 271 272/* 273 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 274 * input routines have queues of messages stored on ifqueue structures 275 * (defined above). Entries are added to and deleted from these structures 276 * by these macros, which should be called with ipl raised to splimp(). 277 */ 278#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 279#define IF_DROP(ifq) ((ifq)->ifq_drops++) 280#define IF_ENQUEUE(ifq, m) { \ 281 (m)->m_nextpkt = 0; \ 282 if ((ifq)->ifq_tail == 0) \ 283 (ifq)->ifq_head = m; \ 284 else \ 285 (ifq)->ifq_tail->m_nextpkt = m; \ 286 (ifq)->ifq_tail = m; \ 287 (ifq)->ifq_len++; \ 288} 289#define IF_PREPEND(ifq, m) { \ 290 (m)->m_nextpkt = (ifq)->ifq_head; \ 291 if ((ifq)->ifq_tail == 0) \ 292 (ifq)->ifq_tail = (m); \ 293 (ifq)->ifq_head = (m); \ 294 (ifq)->ifq_len++; \ 295} 296#define IF_DEQUEUE(ifq, m) { \ 297 (m) = (ifq)->ifq_head; \ 298 if (m) { \ 299 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 300 (ifq)->ifq_tail = 0; \ 301 (m)->m_nextpkt = 0; \ 302 (ifq)->ifq_len--; \ 303 } \ 304} 305 306#define IF_INPUT_ENQUEUE(ifq, m) { \ 307 if (IF_QFULL(ifq)) { \ 308 IF_DROP(ifq); \ 309 m_freem(m); \ 310 if (!ifq->ifq_congestion) \ 311 if_congestion(ifq); \ 312 } else { \ 313 if (m->m_next == NULL && (m->m_flags & M_PKTHDR)) { \ 314 if ((m->m_flags & M_CLUSTER) && \ 315 m->m_len <= (MHLEN &~ (sizeof(long) - 1))) {\ 316 caddr_t data = m->m_data; \ 317 caddr_t ext_buf = m->m_ext.ext_buf; \ 318 m->m_data = m->m_pktdat; \ 319 MH_ALIGN(m, m->m_len); \ 320 bcopy(data, m->m_data, m->m_len); \ 321 pool_put(&mclpool, ext_buf); \ 322 m->m_flags &= ~(M_EXT|M_CLUSTER); \ 323 } \ 324 } \ 325 IF_ENQUEUE(ifq, m); \ 326 } \ 327} 328 329#define IF_POLL(ifq, m) ((m) = (ifq)->ifq_head) 330#define IF_PURGE(ifq) \ 331do { \ 332 struct mbuf *__m0; \ 333 \ 334 for (;;) { \ 335 IF_DEQUEUE((ifq), __m0); \ 336 if (__m0 == NULL) \ 337 break; \ 338 else \ 339 m_freem(__m0); \ 340 } \ 341} while (0) 342#define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 343 344#define IFQ_MAXLEN 50 345#define IFNET_SLOWHZ 1 /* granularity is 1 second */ 346 347/* 348 * The ifaddr structure contains information about one address 349 * of an interface. They are maintained by the different address families, 350 * are allocated and attached when an address is set, and are linked 351 * together so all addresses for an interface can be located. 352 */ 353struct ifaddr { 354 struct sockaddr *ifa_addr; /* address of interface */ 355 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 356#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 357 struct sockaddr *ifa_netmask; /* used to determine subnet */ 358 struct ifnet *ifa_ifp; /* back-pointer to interface */ 359 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */ 360 /* check or clean routes (+ or -)'d */ 361 void (*ifa_rtrequest)(int, struct rtentry *, struct rt_addrinfo *); 362 u_int ifa_flags; /* mostly rt_flags for cloning */ 363 u_int ifa_refcnt; /* count of references */ 364 int ifa_metric; /* cost of going out this interface */ 365}; 366#define IFA_ROUTE RTF_UP /* route installed */ 367 368/* 369 * Message format for use in obtaining information about interfaces 370 * from sysctl and the routing socket. 371 */ 372struct if_msghdr { 373 u_short ifm_msglen; /* to skip over non-understood messages */ 374 u_char ifm_version; /* future binary compatibility */ 375 u_char ifm_type; /* message type */ 376 int ifm_addrs; /* like rtm_addrs */ 377 int ifm_flags; /* value of if_flags */ 378 u_short ifm_index; /* index for associated ifp */ 379 struct if_data ifm_data;/* statistics and other data about if */ 380}; 381 382/* 383 * Message format for use in obtaining information about interface addresses 384 * from sysctl and the routing socket. 385 */ 386struct ifa_msghdr { 387 u_short ifam_msglen; /* to skip over non-understood messages */ 388 u_char ifam_version; /* future binary compatibility */ 389 u_char ifam_type; /* message type */ 390 int ifam_addrs; /* like rtm_addrs */ 391 int ifam_flags; /* value of ifa_flags */ 392 u_short ifam_index; /* index for associated ifp */ 393 int ifam_metric; /* value of ifa_metric */ 394}; 395 396 397/* 398 * Message format announcing the arrival or departure of a network interface. 399 */ 400struct if_announcemsghdr { 401 u_short ifan_msglen; /* to skip over non-understood messages */ 402 u_char ifan_version; /* future binary compatibility */ 403 u_char ifan_type; /* message type */ 404 u_short ifan_index; /* index for associated ifp */ 405 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 406 u_short ifan_what; /* what type of announcement */ 407}; 408 409#define IFAN_ARRIVAL 0 /* interface arrival */ 410#define IFAN_DEPARTURE 1 /* interface departure */ 411 412/* 413 * Interface request structure used for socket 414 * ioctl's. All interface ioctl's must have parameter 415 * definitions which begin with ifr_name. The 416 * remainder may be interface specific. 417 */ 418struct ifreq { 419 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 420 union { 421 struct sockaddr ifru_addr; 422 struct sockaddr ifru_dstaddr; 423 struct sockaddr ifru_broadaddr; 424 short ifru_flags; 425 int ifru_metric; 426 caddr_t ifru_data; 427 } ifr_ifru; 428#define ifr_addr ifr_ifru.ifru_addr /* address */ 429#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 430#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 431#define ifr_flags ifr_ifru.ifru_flags /* flags */ 432#define ifr_metric ifr_ifru.ifru_metric /* metric */ 433#define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */ 434#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ 435#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 436}; 437 438struct ifaliasreq { 439 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 440 struct sockaddr ifra_addr; 441 struct sockaddr ifra_dstaddr; 442#define ifra_broadaddr ifra_dstaddr 443 struct sockaddr ifra_mask; 444}; 445 446struct ifmediareq { 447 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 448 int ifm_current; /* current media options */ 449 int ifm_mask; /* don't care mask */ 450 int ifm_status; /* media status */ 451 int ifm_active; /* active options */ 452 int ifm_count; /* # entries in ifm_ulist 453 array */ 454 int *ifm_ulist; /* media words */ 455}; 456 457/* 458 * Structure used in SIOCGIFCONF request. 459 * Used to retrieve interface configuration 460 * for machine (useful for programs which 461 * must know all networks accessible). 462 */ 463struct ifconf { 464 int ifc_len; /* size of associated buffer */ 465 union { 466 caddr_t ifcu_buf; 467 struct ifreq *ifcu_req; 468 } ifc_ifcu; 469#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 470#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 471}; 472 473/* 474 * Structure for SIOC[AGD]LIFADDR 475 */ 476struct if_laddrreq { 477 char iflr_name[IFNAMSIZ]; 478 unsigned int flags; 479#define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ 480 unsigned int prefixlen; /* in/out */ 481 struct sockaddr_storage addr; /* in/out */ 482 struct sockaddr_storage dstaddr; /* out */ 483}; 484 485struct if_nameindex { 486 unsigned int if_index; 487 char *if_name; 488}; 489 490#ifndef _KERNEL 491__BEGIN_DECLS 492unsigned int if_nametoindex(const char *); 493char *if_indextoname(unsigned int, char *); 494struct if_nameindex *if_nameindex(void); 495__END_DECLS 496#define if_freenameindex(x) free(x) 497#endif 498 499#include <net/if_arp.h> 500 501#ifdef _KERNEL 502#define IFAFREE(ifa) \ 503do { \ 504 if ((ifa)->ifa_refcnt <= 0) \ 505 ifafree(ifa); \ 506 else \ 507 (ifa)->ifa_refcnt--; \ 508} while (0) 509 510#ifdef ALTQ 511#define ALTQ_DECL(x) x 512 513#define IFQ_ENQUEUE(ifq, m, pattr, err) \ 514do { \ 515 if (ALTQ_IS_ENABLED((ifq))) \ 516 ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \ 517 else { \ 518 if (IF_QFULL((ifq))) { \ 519 m_freem((m)); \ 520 (err) = ENOBUFS; \ 521 } else { \ 522 IF_ENQUEUE((ifq), (m)); \ 523 (err) = 0; \ 524 } \ 525 } \ 526 if ((err)) \ 527 (ifq)->ifq_drops++; \ 528} while (0) 529 530#define IFQ_DEQUEUE(ifq, m) \ 531do { \ 532 if (TBR_IS_ENABLED((ifq))) \ 533 (m) = tbr_dequeue((ifq), ALTDQ_REMOVE); \ 534 else if (ALTQ_IS_ENABLED((ifq))) \ 535 ALTQ_DEQUEUE((ifq), (m)); \ 536 else \ 537 IF_DEQUEUE((ifq), (m)); \ 538} while (0) 539 540#define IFQ_POLL(ifq, m) \ 541do { \ 542 if (TBR_IS_ENABLED((ifq))) \ 543 (m) = tbr_dequeue((ifq), ALTDQ_POLL); \ 544 else if (ALTQ_IS_ENABLED((ifq))) \ 545 ALTQ_POLL((ifq), (m)); \ 546 else \ 547 IF_POLL((ifq), (m)); \ 548} while (0) 549 550#define IFQ_PURGE(ifq) \ 551do { \ 552 if (ALTQ_IS_ENABLED((ifq))) \ 553 ALTQ_PURGE((ifq)); \ 554 else \ 555 IF_PURGE((ifq)); \ 556} while (0) 557 558#define IFQ_SET_READY(ifq) \ 559 do { ((ifq)->altq_flags |= ALTQF_READY); } while (0) 560 561#define IFQ_CLASSIFY(ifq, m, af, pa) \ 562do { \ 563 if (ALTQ_IS_ENABLED((ifq))) { \ 564 if (ALTQ_NEEDS_CLASSIFY((ifq))) \ 565 (pa)->pattr_class = (*(ifq)->altq_classify) \ 566 ((ifq)->altq_clfier, (m), (af)); \ 567 (pa)->pattr_af = (af); \ 568 (pa)->pattr_hdr = mtod((m), caddr_t); \ 569 } \ 570} while (0) 571 572#else /* !ALTQ */ 573#define ALTQ_DECL(x) /* nothing */ 574 575#define IFQ_ENQUEUE(ifq, m, pattr, err) \ 576do { \ 577 if (IF_QFULL((ifq))) { \ 578 m_freem((m)); \ 579 (err) = ENOBUFS; \ 580 } else { \ 581 IF_ENQUEUE((ifq), (m)); \ 582 (err) = 0; \ 583 } \ 584 if ((err)) \ 585 (ifq)->ifq_drops++; \ 586} while (0) 587 588#define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m)) 589 590#define IFQ_POLL(ifq, m) IF_POLL((ifq), (m)) 591 592#define IFQ_PURGE(ifq) IF_PURGE((ifq)) 593 594#define IFQ_SET_READY(ifq) /* nothing */ 595 596#define IFQ_CLASSIFY(ifq, m, af, pa) /* nothing */ 597 598#endif /* ALTQ */ 599 600#define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 601#define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++) 602#define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len) 603#define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++) 604#define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len)) 605 606extern struct ifnet_head ifnet; 607extern struct ifnet **ifindex2ifnet; 608extern struct ifnet *lo0ifp; 609extern int if_indexlim; 610 611void ether_ifattach(struct ifnet *); 612void ether_ifdetach(struct ifnet *); 613int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t); 614void ether_input_mbuf(struct ifnet *, struct mbuf *); 615void ether_input(struct ifnet *, struct ether_header *, struct mbuf *); 616int ether_output(struct ifnet *, 617 struct mbuf *, struct sockaddr *, struct rtentry *); 618char *ether_sprintf(u_char *); 619 620void if_alloc_sadl(struct ifnet *); 621void if_free_sadl(struct ifnet *); 622void if_attach(struct ifnet *); 623void if_attachdomain(void); 624void if_attachtail(struct ifnet *); 625void if_attachhead(struct ifnet *); 626void if_detach(struct ifnet *); 627void if_down(struct ifnet *); 628void if_qflush(struct ifqueue *); 629void if_slowtimo(void *); 630void if_up(struct ifnet *); 631int ifconf(u_long, caddr_t); 632void ifinit(void); 633int ifioctl(struct socket *, u_long, caddr_t, struct proc *); 634int ifpromisc(struct ifnet *, int); 635struct ifnet *ifunit(const char *); 636 637struct ifaddr *ifa_ifwithaddr(struct sockaddr *); 638struct ifaddr *ifa_ifwithaf(int); 639struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *); 640struct ifaddr *ifa_ifwithnet(struct sockaddr *); 641struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, 642 struct sockaddr *); 643struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 644void ifafree(struct ifaddr *); 645void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 646 647void if_clone_attach(struct if_clone *); 648void if_clone_detach(struct if_clone *); 649 650int if_clone_create(const char *); 651int if_clone_destroy(const char *); 652 653void if_congestion(struct ifqueue *); 654 655int loioctl(struct ifnet *, u_long, caddr_t); 656void loopattach(int); 657int looutput(struct ifnet *, 658 struct mbuf *, struct sockaddr *, struct rtentry *); 659void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 660#endif /* _KERNEL */ 661#endif /* _NET_IF_H_ */ 662