if.h revision 1.130
1/* $OpenBSD: if.h,v 1.130 2011/11/02 02:03:47 haesbaert 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#include <sys/tree.h> 40 41/* 42 * Always include ALTQ glue here -- we use the ALTQ interface queue 43 * structure even when ALTQ is not configured into the kernel so that 44 * the size of struct ifnet does not changed based on the option. The 45 * ALTQ queue structure is API-compatible with the legacy ifqueue. 46 */ 47#include <altq/if_altq.h> 48 49/* 50 * Structures defining a network interface, providing a packet 51 * transport mechanism (ala level 0 of the PUP protocols). 52 * 53 * Each interface accepts output datagrams of a specified maximum 54 * length, and provides higher level routines with input datagrams 55 * received from its medium. 56 * 57 * Output occurs when the routine if_output is called, with four parameters: 58 * (*ifp->if_output)(ifp, m, dst, rt) 59 * Here m is the mbuf chain to be sent and dst is the destination address. 60 * The output routine encapsulates the supplied datagram if necessary, 61 * and then transmits it on its medium. 62 * 63 * On input, each interface unwraps the data received by it, and either 64 * places it on the input queue of an internetwork datagram routine 65 * and posts the associated software interrupt, or passes the datagram to a raw 66 * packet input routine. 67 * 68 * Routines exist for locating interfaces by their addresses 69 * or for locating an interface on a certain network, as well as more general 70 * routing and gateway routines maintaining information used to locate 71 * interfaces. These routines live in the files if.c and route.c 72 */ 73/* XXX fast fix for SNMP, going away soon */ 74#include <sys/time.h> 75 76struct mbuf; 77struct proc; 78struct rtentry; 79struct socket; 80struct ether_header; 81struct arpcom; 82struct rt_addrinfo; 83struct ifnet; 84 85/* 86 * Structure describing a `cloning' interface. 87 */ 88struct if_clone { 89 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ 90 const char *ifc_name; /* name of device, e.g. `gif' */ 91 size_t ifc_namelen; /* length of name */ 92 93 int (*ifc_create)(struct if_clone *, int); 94 int (*ifc_destroy)(struct ifnet *); 95}; 96 97#define IF_CLONE_INITIALIZER(name, create, destroy) \ 98 { { 0 }, name, sizeof(name) - 1, create, destroy } 99 100/* 101 * Structure used to query names of interface cloners. 102 */ 103struct if_clonereq { 104 int ifcr_total; /* total cloners (out) */ 105 int ifcr_count; /* room for this many in user buffer */ 106 char *ifcr_buffer; /* buffer for cloner names */ 107}; 108 109#define MCLPOOLS 7 /* number of cluster pools */ 110 111struct mclpool { 112 u_int mcl_grown; 113 u_short mcl_alive; 114 u_short mcl_hwm; 115 u_short mcl_cwm; 116 u_short mcl_lwm; 117}; 118 119/* 120 * Structure defining statistics and other data kept regarding a network 121 * interface. 122 */ 123struct if_data { 124 /* generic interface information */ 125 u_char ifi_type; /* ethernet, tokenring, etc. */ 126 u_char ifi_addrlen; /* media address length */ 127 u_char ifi_hdrlen; /* media header length */ 128 u_char ifi_link_state; /* current link state */ 129 u_int32_t ifi_mtu; /* maximum transmission unit */ 130 u_int32_t ifi_metric; /* routing metric (external only) */ 131 u_int32_t ifi_pad; 132 u_int64_t ifi_baudrate; /* linespeed */ 133 /* volatile statistics */ 134 u_int64_t ifi_ipackets; /* packets received on interface */ 135 u_int64_t ifi_ierrors; /* input errors on interface */ 136 u_int64_t ifi_opackets; /* packets sent on interface */ 137 u_int64_t ifi_oerrors; /* output errors on interface */ 138 u_int64_t ifi_collisions; /* collisions on csma interfaces */ 139 u_int64_t ifi_ibytes; /* total number of octets received */ 140 u_int64_t ifi_obytes; /* total number of octets sent */ 141 u_int64_t ifi_imcasts; /* packets received via multicast */ 142 u_int64_t ifi_omcasts; /* packets sent via multicast */ 143 u_int64_t ifi_iqdrops; /* dropped on input, this interface */ 144 u_int64_t ifi_noproto; /* destined for unsupported protocol */ 145 u_int32_t ifi_capabilities; /* interface capabilities */ 146 struct timeval ifi_lastchange; /* last operational state change */ 147 148 struct mclpool ifi_mclpool[MCLPOOLS]; 149}; 150 151#define IFQ_NQUEUES ALTQ_IFQ_NQUEUES 152#define IFQ_MAXPRIO IFQ_NQUEUES - 1 153#define IFQ_DEFPRIO 3 154 155/* 156 * Structure defining a queue for a network interface. 157 * XXX keep in sync with struct ifaltq. 158 */ 159struct ifqueue { 160 struct { 161 struct mbuf *head; 162 struct mbuf *tail; 163 } ifq_q[IFQ_NQUEUES]; 164 int ifq_len; 165 int ifq_maxlen; 166 int ifq_drops; 167 struct timeout *ifq_congestion; 168}; 169 170/* 171 * Values for if_link_state. 172 */ 173#define LINK_STATE_UNKNOWN 0 /* link unknown */ 174#define LINK_STATE_INVALID 1 /* link invalid */ 175#define LINK_STATE_DOWN 2 /* link is down */ 176#define LINK_STATE_KALIVE_DOWN 3 /* keepalive reports down */ 177#define LINK_STATE_UP 4 /* link is up */ 178#define LINK_STATE_HALF_DUPLEX 5 /* link is up and half duplex */ 179#define LINK_STATE_FULL_DUPLEX 6 /* link is up and full duplex */ 180 181#define LINK_STATE_IS_UP(_s) \ 182 ((_s) >= LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN) 183 184/* 185 * Status bit descriptions for the various interface types. 186 */ 187struct if_status_description { 188 u_char ifs_type; 189 u_char ifs_state; 190 const char *ifs_string; 191}; 192 193#define LINK_STATE_DESC_MATCH(_ifs, _t, _s) \ 194 (((_ifs)->ifs_type == (_t) || (_ifs)->ifs_type == 0) && \ 195 (_ifs)->ifs_state == (_s)) 196 197 198 199#define LINK_STATE_DESCRIPTIONS { \ 200 { IFT_ETHER, LINK_STATE_DOWN, "no carrier" }, \ 201 \ 202 { IFT_IEEE80211, LINK_STATE_DOWN, "no network" }, \ 203 \ 204 { IFT_PPP, LINK_STATE_DOWN, "no carrier" }, \ 205 \ 206 { IFT_CARP, LINK_STATE_DOWN, "backup" }, \ 207 { IFT_CARP, LINK_STATE_UP, "master" }, \ 208 { IFT_CARP, LINK_STATE_HALF_DUPLEX, "master" }, \ 209 { IFT_CARP, LINK_STATE_FULL_DUPLEX, "master" }, \ 210 \ 211 { 0, LINK_STATE_UP, "active" }, \ 212 { 0, LINK_STATE_HALF_DUPLEX, "active" }, \ 213 { 0, LINK_STATE_FULL_DUPLEX, "active" }, \ 214 \ 215 { 0, LINK_STATE_UNKNOWN, "unknown" }, \ 216 { 0, LINK_STATE_INVALID, "invalid" }, \ 217 { 0, LINK_STATE_DOWN, "down" }, \ 218 { 0, LINK_STATE_KALIVE_DOWN, "keepalive down" }, \ 219 { 0, 0, NULL } \ 220} 221 222/* 223 * Structure defining a queue for a network interface. 224 * 225 * (Would like to call this struct ``if'', but C isn't PL/1.) 226 */ 227TAILQ_HEAD(ifnet_head, ifnet); /* the actual queue head */ 228 229/* 230 * Length of interface external name, including terminating '\0'. 231 * Note: this is the same size as a generic device's external name. 232 */ 233#define IFNAMSIZ 16 234#define IF_NAMESIZE IFNAMSIZ 235 236/* 237 * Length of interface description, including terminating '\0'. 238 */ 239#define IFDESCRSIZE 64 240 241struct ifnet { /* and the entries */ 242 void *if_softc; /* lower-level data for this if */ 243 TAILQ_ENTRY(ifnet) if_list; /* all struct ifnets are chained */ 244 TAILQ_ENTRY(ifnet) if_txlist; /* list of ifnets ready to tx */ 245 TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */ 246 TAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if */ 247 struct hook_desc_head *if_addrhooks; /* address change callbacks */ 248 struct hook_desc_head *if_linkstatehooks; /* link change callbacks */ 249 struct hook_desc_head *if_detachhooks; /* detach callbacks */ 250 char if_xname[IFNAMSIZ]; /* external name (name + unit) */ 251 int if_pcount; /* number of promiscuous listeners */ 252 caddr_t if_bpf; /* packet filter structure */ 253 caddr_t if_bridge; /* bridge structure */ 254 caddr_t if_tp; /* used by trunk ports */ 255 caddr_t if_pf_kif; /* pf interface abstraction */ 256 union { 257 caddr_t carp_s; /* carp structure (used by !carp ifs) */ 258 struct ifnet *carp_d; /* ptr to carpdev (used by carp ifs) */ 259 } if_carp_ptr; 260#define if_carp if_carp_ptr.carp_s 261#define if_carpdev if_carp_ptr.carp_d 262 u_short if_index; /* numeric abbreviation for this if */ 263 short if_timer; /* time 'til if_watchdog called */ 264 short if_flags; /* up/down, broadcast, etc. */ 265 int if_xflags; /* extra softnet flags */ 266 struct if_data if_data; /* stats and other data about if */ 267 u_int32_t if_hardmtu; /* maximum MTU device supports */ 268 u_int if_rdomain; /* routing instance */ 269 char if_description[IFDESCRSIZE]; /* interface description */ 270 u_short if_rtlabelid; /* next route label */ 271 u_int8_t if_priority; 272 273 /* procedure handles */ 274 /* output routine (enqueue) */ 275 int (*if_output)(struct ifnet *, struct mbuf *, struct sockaddr *, 276 struct rtentry *); 277 278 /* link level output function */ 279 int (*if_ll_output)(struct ifnet *, struct mbuf *, 280 struct sockaddr *, struct rtentry *); 281 /* initiate output routine */ 282 void (*if_start)(struct ifnet *); 283 /* ioctl routine */ 284 int (*if_ioctl)(struct ifnet *, u_long, caddr_t); 285 /* stop routine */ 286 int (*if_stop)(struct ifnet *, int); 287 /* timer routine */ 288 void (*if_watchdog)(struct ifnet *); 289 int (*if_wol)(struct ifnet *, int); 290 struct ifaltq if_snd; /* output queue (includes altq) */ 291 struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */ 292 293 void *if_afdata[AF_MAX]; 294}; 295#define if_mtu if_data.ifi_mtu 296#define if_type if_data.ifi_type 297#define if_addrlen if_data.ifi_addrlen 298#define if_hdrlen if_data.ifi_hdrlen 299#define if_metric if_data.ifi_metric 300#define if_link_state if_data.ifi_link_state 301#define if_baudrate if_data.ifi_baudrate 302#define if_ipackets if_data.ifi_ipackets 303#define if_ierrors if_data.ifi_ierrors 304#define if_opackets if_data.ifi_opackets 305#define if_oerrors if_data.ifi_oerrors 306#define if_collisions if_data.ifi_collisions 307#define if_ibytes if_data.ifi_ibytes 308#define if_obytes if_data.ifi_obytes 309#define if_imcasts if_data.ifi_imcasts 310#define if_omcasts if_data.ifi_omcasts 311#define if_iqdrops if_data.ifi_iqdrops 312#define if_noproto if_data.ifi_noproto 313#define if_lastchange if_data.ifi_lastchange 314#define if_capabilities if_data.ifi_capabilities 315 316#define IFF_UP 0x1 /* interface is up */ 317#define IFF_BROADCAST 0x2 /* broadcast address valid */ 318#define IFF_DEBUG 0x4 /* turn on debugging */ 319#define IFF_LOOPBACK 0x8 /* is a loopback net */ 320#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ 321#define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ 322#define IFF_RUNNING 0x40 /* resources allocated */ 323#define IFF_NOARP 0x80 /* no address resolution protocol */ 324#define IFF_PROMISC 0x100 /* receive all packets */ 325#define IFF_ALLMULTI 0x200 /* receive all multicast packets */ 326#define IFF_OACTIVE 0x400 /* transmission in progress */ 327#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */ 328#define IFF_LINK0 0x1000 /* per link layer defined bit */ 329#define IFF_LINK1 0x2000 /* per link layer defined bit */ 330#define IFF_LINK2 0x4000 /* per link layer defined bit */ 331#define IFF_MULTICAST 0x8000 /* supports multicast */ 332 333/* flags set internally only: */ 334#define IFF_CANTCHANGE \ 335 (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\ 336 IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI) 337 338#define IFXF_TXREADY 0x1 /* interface is ready to tx */ 339#define IFXF_NOINET6 0x2 /* don't do inet6 */ 340#define IFXF_INET6_PRIVACY 0x4 /* autoconf privacy extension */ 341#define IFXF_MPLS 0x8 /* supports MPLS */ 342#define IFXF_WOL 0x10 /* wake on lan enabled */ 343 344#define IFXF_CANTCHANGE \ 345 (IFXF_TXREADY) 346 347/* 348 * Some convenience macros used for setting ifi_baudrate. 349 */ 350#define IF_Kbps(x) ((x) * 1000ULL) /* kilobits/sec. */ 351#define IF_Mbps(x) (IF_Kbps((x) * 1000ULL)) /* megabits/sec. */ 352#define IF_Gbps(x) (IF_Mbps((x) * 1000ULL)) /* gigabits/sec. */ 353 354/* Capabilities that interfaces can advertise. */ 355#define IFCAP_CSUM_IPv4 0x00000001 /* can do IPv4 header csum */ 356#define IFCAP_CSUM_TCPv4 0x00000002 /* can do IPv4/TCP csum */ 357#define IFCAP_CSUM_UDPv4 0x00000004 /* can do IPv4/UDP csum */ 358#define IFCAP_IPSEC 0x00000008 /* can do IPsec */ 359#define IFCAP_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */ 360#define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */ 361#define IFCAP_IPCOMP 0x00000040 /* can do IPcomp */ 362#define IFCAP_CSUM_TCPv6 0x00000080 /* can do IPv6/TCP checksums */ 363#define IFCAP_CSUM_UDPv6 0x00000100 /* can do IPv6/UDP checksums */ 364#define IFCAP_WOL 0x00008000 /* can do wake on lan */ 365 366/* 367 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 368 * input routines have queues of messages stored on ifqueue structures 369 * (defined above). Entries are added to and deleted from these structures 370 * by these macros, which should be called with ipl raised to splnet(). 371 */ 372#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 373#define IF_DROP(ifq) ((ifq)->ifq_drops++) 374#define IF_ENQUEUE(ifq, m) \ 375do { \ 376 (m)->m_nextpkt = NULL; \ 377 if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL) \ 378 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = m; \ 379 else \ 380 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail->m_nextpkt = m; \ 381 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = m; \ 382 (ifq)->ifq_len++; \ 383} while (/* CONSTCOND */0) 384#define IF_PREPEND(ifq, m) \ 385do { \ 386 (m)->m_nextpkt = (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head; \ 387 if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL) \ 388 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = (m); \ 389 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = (m); \ 390 (ifq)->ifq_len++; \ 391} while (/* CONSTCOND */0) 392 393#define IF_POLL(ifq, m) \ 394do { \ 395 int if_dequeue_prio = IFQ_MAXPRIO; \ 396 do { \ 397 (m) = (ifq)->ifq_q[if_dequeue_prio].head; \ 398 } while (!(m) && --if_dequeue_prio >= 0); \ 399} while (/* CONSTCOND */0) 400 401#define IF_DEQUEUE(ifq, m) \ 402do { \ 403 int if_dequeue_prio = IFQ_MAXPRIO; \ 404 do { \ 405 (m) = (ifq)->ifq_q[if_dequeue_prio].head; \ 406 if (m) { \ 407 if (((ifq)->ifq_q[if_dequeue_prio].head = \ 408 (m)->m_nextpkt) == NULL) \ 409 (ifq)->ifq_q[if_dequeue_prio].tail = NULL; \ 410 (m)->m_nextpkt = NULL; \ 411 (ifq)->ifq_len--; \ 412 } \ 413 } while (!(m) && --if_dequeue_prio >= 0); \ 414} while (/* CONSTCOND */0) 415 416#define IF_INPUT_ENQUEUE(ifq, m) \ 417do { \ 418 if (IF_QFULL(ifq)) { \ 419 IF_DROP(ifq); \ 420 m_freem(m); \ 421 if (!(ifq)->ifq_congestion) \ 422 if_congestion(ifq); \ 423 } else \ 424 IF_ENQUEUE(ifq, m); \ 425} while (/* CONSTCOND */0) 426 427#define IF_PURGE(ifq) \ 428do { \ 429 struct mbuf *__m0; \ 430 \ 431 for (;;) { \ 432 IF_DEQUEUE((ifq), __m0); \ 433 if (__m0 == NULL) \ 434 break; \ 435 else \ 436 m_freem(__m0); \ 437 } \ 438} while (/* CONSTCOND */0) 439#define IF_LEN(ifq) ((ifq)->ifq_len) 440#define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 441 442#define IFQ_MAXLEN 256 443#define IFNET_SLOWHZ 1 /* granularity is 1 second */ 444 445/* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ 446#define IFQCTL_LEN 1 447#define IFQCTL_MAXLEN 2 448#define IFQCTL_DROPS 3 449#define IFQCTL_CONGESTION 4 450#define IFQCTL_MAXID 5 451 452/* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */ 453#define CTL_IFQ_NAMES { \ 454 { 0, 0 }, \ 455 { "len", CTLTYPE_INT }, \ 456 { "maxlen", CTLTYPE_INT }, \ 457 { "drops", CTLTYPE_INT }, \ 458 { "congestion", CTLTYPE_INT }, \ 459} 460 461/* 462 * The ifaddr structure contains information about one address 463 * of an interface. They are maintained by the different address families, 464 * are allocated and attached when an address is set, and are linked 465 * together so all addresses for an interface can be located. 466 */ 467struct ifaddr { 468 struct sockaddr *ifa_addr; /* address of interface */ 469 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 470#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 471 struct sockaddr *ifa_netmask; /* used to determine subnet */ 472 struct ifnet *ifa_ifp; /* back-pointer to interface */ 473 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */ 474 /* check or clean routes (+ or -)'d */ 475 void (*ifa_rtrequest)(int, struct rtentry *, struct rt_addrinfo *); 476 u_int ifa_flags; /* mostly rt_flags for cloning */ 477 u_int ifa_refcnt; /* count of references */ 478 int ifa_metric; /* cost of going out this interface */ 479}; 480#define IFA_ROUTE RTF_UP /* route installed */ 481 482struct ifaddr_item { 483 RB_ENTRY(ifaddr_item) ifai_entry; 484 struct sockaddr *ifai_addr; 485 struct ifaddr *ifai_ifa; 486 struct ifaddr_item *ifai_next; 487 u_int ifai_rdomain; 488}; 489 490/* 491 * Message format for use in obtaining information about interfaces 492 * from sysctl and the routing socket. 493 */ 494struct if_msghdr { 495 u_short ifm_msglen; /* to skip over non-understood messages */ 496 u_char ifm_version; /* future binary compatibility */ 497 u_char ifm_type; /* message type */ 498 u_short ifm_hdrlen; /* sizeof(if_msghdr) to skip over the header */ 499 u_short ifm_index; /* index for associated ifp */ 500 u_short ifm_tableid; /* routing table id */ 501 u_char ifm_pad1; 502 u_char ifm_pad2; 503 int ifm_addrs; /* like rtm_addrs */ 504 int ifm_flags; /* value of if_flags */ 505 int ifm_xflags; 506 struct if_data ifm_data;/* statistics and other data about if */ 507}; 508 509/* 510 * Message format for use in obtaining information about interface addresses 511 * from sysctl and the routing socket. 512 */ 513struct ifa_msghdr { 514 u_short ifam_msglen; /* to skip over non-understood messages */ 515 u_char ifam_version; /* future binary compatibility */ 516 u_char ifam_type; /* message type */ 517 u_short ifam_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */ 518 u_short ifam_index; /* index for associated ifp */ 519 u_short ifam_tableid; /* routing table id */ 520 u_char ifam_pad1; 521 u_char ifam_pad2; 522 int ifam_addrs; /* like rtm_addrs */ 523 int ifam_flags; /* value of ifa_flags */ 524 int ifam_metric; /* value of ifa_metric */ 525}; 526 527 528/* 529 * Message format announcing the arrival or departure of a network interface. 530 */ 531struct if_announcemsghdr { 532 u_short ifan_msglen; /* to skip over non-understood messages */ 533 u_char ifan_version; /* future binary compatibility */ 534 u_char ifan_type; /* message type */ 535 u_short ifan_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */ 536 u_short ifan_index; /* index for associated ifp */ 537 u_short ifan_what; /* what type of announcement */ 538 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 539}; 540 541#define IFAN_ARRIVAL 0 /* interface arrival */ 542#define IFAN_DEPARTURE 1 /* interface departure */ 543 544/* 545 * interface groups 546 */ 547 548#define IFG_ALL "all" /* group contains all interfaces */ 549#define IFG_EGRESS "egress" /* if(s) default route(s) point to */ 550 551struct ifg_group { 552 char ifg_group[IFNAMSIZ]; 553 u_int ifg_refcnt; 554 caddr_t ifg_pf_kif; 555 int ifg_carp_demoted; 556 TAILQ_HEAD(, ifg_member) ifg_members; 557 TAILQ_ENTRY(ifg_group) ifg_next; 558}; 559 560struct ifg_member { 561 TAILQ_ENTRY(ifg_member) ifgm_next; 562 struct ifnet *ifgm_ifp; 563}; 564 565struct ifg_list { 566 struct ifg_group *ifgl_group; 567 TAILQ_ENTRY(ifg_list) ifgl_next; 568}; 569 570struct ifg_req { 571 union { 572 char ifgrqu_group[IFNAMSIZ]; 573 char ifgrqu_member[IFNAMSIZ]; 574 } ifgrq_ifgrqu; 575#define ifgrq_group ifgrq_ifgrqu.ifgrqu_group 576#define ifgrq_member ifgrq_ifgrqu.ifgrqu_member 577}; 578 579struct ifg_attrib { 580 int ifg_carp_demoted; 581}; 582 583/* 584 * Used to lookup groups for an interface 585 */ 586struct ifgroupreq { 587 char ifgr_name[IFNAMSIZ]; 588 u_int ifgr_len; 589 union { 590 char ifgru_group[IFNAMSIZ]; 591 struct ifg_req *ifgru_groups; 592 struct ifg_attrib ifgru_attrib; 593 } ifgr_ifgru; 594#define ifgr_group ifgr_ifgru.ifgru_group 595#define ifgr_groups ifgr_ifgru.ifgru_groups 596#define ifgr_attrib ifgr_ifgru.ifgru_attrib 597}; 598 599/* 600 * Interface request structure used for socket 601 * ioctl's. All interface ioctl's must have parameter 602 * definitions which begin with ifr_name. The 603 * remainder may be interface specific. 604 */ 605struct ifreq { 606 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 607 union { 608 struct sockaddr ifru_addr; 609 struct sockaddr ifru_dstaddr; 610 struct sockaddr ifru_broadaddr; 611 short ifru_flags; 612 int ifru_metric; 613 caddr_t ifru_data; 614 } ifr_ifru; 615#define ifr_addr ifr_ifru.ifru_addr /* address */ 616#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 617#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 618#define ifr_flags ifr_ifru.ifru_flags /* flags */ 619#define ifr_metric ifr_ifru.ifru_metric /* metric */ 620#define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */ 621#define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ 622#define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */ 623#define ifr_data ifr_ifru.ifru_data /* for use by interface */ 624}; 625 626struct ifaliasreq { 627 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 628 struct sockaddr ifra_addr; 629 struct sockaddr ifra_dstaddr; 630#define ifra_broadaddr ifra_dstaddr 631 struct sockaddr ifra_mask; 632}; 633 634struct ifmediareq { 635 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 636 int ifm_current; /* current media options */ 637 int ifm_mask; /* don't care mask */ 638 int ifm_status; /* media status */ 639 int ifm_active; /* active options */ 640 int ifm_count; /* # entries in ifm_ulist 641 array */ 642 int *ifm_ulist; /* media words */ 643}; 644 645struct ifkalivereq { 646 char ikar_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 647 int ikar_timeo; 648 int ikar_cnt; 649}; 650 651/* 652 * Structure used in SIOCGIFCONF request. 653 * Used to retrieve interface configuration 654 * for machine (useful for programs which 655 * must know all networks accessible). 656 */ 657struct ifconf { 658 int ifc_len; /* size of associated buffer */ 659 union { 660 caddr_t ifcu_buf; 661 struct ifreq *ifcu_req; 662 } ifc_ifcu; 663#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 664#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 665}; 666 667/* 668 * Structure for SIOC[AGD]LIFADDR 669 */ 670struct if_laddrreq { 671 char iflr_name[IFNAMSIZ]; 672 unsigned int flags; 673#define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ 674 unsigned int prefixlen; /* in/out */ 675 struct sockaddr_storage addr; /* in/out */ 676 struct sockaddr_storage dstaddr; /* out */ 677}; 678 679struct if_nameindex { 680 unsigned int if_index; 681 char *if_name; 682}; 683 684#ifndef _KERNEL 685__BEGIN_DECLS 686unsigned int if_nametoindex(const char *); 687char *if_indextoname(unsigned int, char *); 688struct if_nameindex *if_nameindex(void); 689void if_freenameindex(struct if_nameindex *); 690__END_DECLS 691#endif 692 693#include <net/if_arp.h> 694 695#ifdef _KERNEL 696#define IFAFREE(ifa) \ 697do { \ 698 if ((ifa)->ifa_refcnt <= 0) \ 699 ifafree(ifa); \ 700 else \ 701 (ifa)->ifa_refcnt--; \ 702} while (/* CONSTCOND */0) 703 704#ifdef ALTQ 705 706#define IFQ_ENQUEUE(ifq, m, pattr, err) \ 707do { \ 708 if (ALTQ_IS_ENABLED((ifq))) { \ 709 m->m_pkthdr.pf.prio = IFQ_MAXPRIO; \ 710 ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \ 711 } else { \ 712 if (IF_QFULL((ifq))) { \ 713 m_freem((m)); \ 714 (err) = ENOBUFS; \ 715 } else { \ 716 IF_ENQUEUE((ifq), (m)); \ 717 (err) = 0; \ 718 } \ 719 } \ 720 if ((err)) \ 721 (ifq)->ifq_drops++; \ 722} while (/* CONSTCOND */0) 723 724#define IFQ_DEQUEUE(ifq, m) \ 725do { \ 726 if (OLDTBR_IS_ENABLED((ifq))) \ 727 (m) = oldtbr_dequeue((ifq), ALTDQ_REMOVE); \ 728 else if (ALTQ_IS_ENABLED((ifq))) \ 729 ALTQ_DEQUEUE((ifq), (m)); \ 730 else \ 731 IF_DEQUEUE((ifq), (m)); \ 732} while (/* CONSTCOND */0) 733 734#define IFQ_POLL(ifq, m) \ 735do { \ 736 if (TBR_IS_ENABLED((ifq))) \ 737 (m) = oldtbr_dequeue((ifq), ALTDQ_POLL); \ 738 else if (ALTQ_IS_ENABLED((ifq))) \ 739 ALTQ_POLL((ifq), (m)); \ 740 else \ 741 IF_POLL((ifq), (m)); \ 742} while (/* CONSTCOND */0) 743 744#define IFQ_PURGE(ifq) \ 745do { \ 746 if (ALTQ_IS_ENABLED((ifq))) \ 747 ALTQ_PURGE((ifq)); \ 748 else \ 749 IF_PURGE((ifq)); \ 750} while (/* CONSTCOND */0) 751 752#define IFQ_SET_READY(ifq) \ 753do { \ 754 ((ifq)->altq_flags |= ALTQF_READY); \ 755} while (/* CONSTCOND */0) 756 757#else /* !ALTQ */ 758 759#define IFQ_ENQUEUE(ifq, m, pattr, err) \ 760do { \ 761 if (IF_QFULL((ifq))) { \ 762 m_freem((m)); \ 763 (err) = ENOBUFS; \ 764 } else { \ 765 IF_ENQUEUE((ifq), (m)); \ 766 (err) = 0; \ 767 } \ 768 if ((err)) \ 769 (ifq)->ifq_drops++; \ 770} while (/* CONSTCOND */0) 771 772#define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m)) 773 774#define IFQ_POLL(ifq, m) IF_POLL((ifq), (m)) 775 776#define IFQ_PURGE(ifq) IF_PURGE((ifq)) 777 778#define IFQ_SET_READY(ifq) /* nothing */ 779 780#endif /* ALTQ */ 781 782#define IFQ_LEN(ifq) IF_LEN(ifq) 783#define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 784#define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++) 785#define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len) 786#define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++) 787#define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len)) 788 789/* default interface priorities */ 790#define IF_WIRED_DEFAULT_PRIORITY 0 791#define IF_WIRELESS_DEFAULT_PRIORITY 4 792 793extern int ifqmaxlen; 794extern struct ifnet_head ifnet; 795extern struct ifnet **ifindex2ifnet; 796extern struct ifnet *lo0ifp; 797extern int if_indexlim; 798 799#define ether_input_mbuf(ifp, m) ether_input((ifp), NULL, (m)) 800 801void ether_ifattach(struct ifnet *); 802void ether_ifdetach(struct ifnet *); 803int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t); 804void ether_input(struct ifnet *, struct ether_header *, struct mbuf *); 805int ether_output(struct ifnet *, 806 struct mbuf *, struct sockaddr *, struct rtentry *); 807char *ether_sprintf(u_char *); 808 809void if_alloc_sadl(struct ifnet *); 810void if_free_sadl(struct ifnet *); 811void if_attach(struct ifnet *); 812void if_attachdomain(void); 813void if_attachtail(struct ifnet *); 814void if_attachhead(struct ifnet *); 815void if_detach(struct ifnet *); 816void if_down(struct ifnet *); 817void if_downall(void); 818void if_link_state_change(struct ifnet *); 819void if_slowtimo(void *); 820void if_up(struct ifnet *); 821int ifconf(u_long, caddr_t); 822void ifinit(void); 823int ifioctl(struct socket *, u_long, caddr_t, struct proc *); 824int ifpromisc(struct ifnet *, int); 825struct ifg_group *if_creategroup(const char *); 826int if_addgroup(struct ifnet *, const char *); 827int if_delgroup(struct ifnet *, const char *); 828void if_group_routechange(struct sockaddr *, struct sockaddr *); 829struct ifnet *ifunit(const char *); 830void if_start(struct ifnet *); 831void ifnewlladdr(struct ifnet *); 832 833struct ifaddr *ifa_ifwithaddr(struct sockaddr *, u_int); 834struct ifaddr *ifa_ifwithaf(int, u_int); 835struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *, u_int); 836struct ifaddr *ifa_ifwithnet(struct sockaddr *, u_int); 837struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, 838 struct sockaddr *, u_int); 839struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 840void ifafree(struct ifaddr *); 841void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 842 843void if_clone_attach(struct if_clone *); 844void if_clone_detach(struct if_clone *); 845 846int if_clone_create(const char *); 847int if_clone_destroy(const char *); 848 849void if_congestion(struct ifqueue *); 850int sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t, 851 struct ifqueue *); 852 853int loioctl(struct ifnet *, u_long, caddr_t); 854void loopattach(int); 855int looutput(struct ifnet *, 856 struct mbuf *, struct sockaddr *, struct rtentry *); 857void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 858void ifa_add(struct ifnet *, struct ifaddr *); 859void ifa_del(struct ifnet *, struct ifaddr *); 860void ifa_update_broadaddr(struct ifnet *, struct ifaddr *, 861 struct sockaddr *); 862#endif /* _KERNEL */ 863#endif /* _NET_IF_H_ */ 864