1 /* $OpenBSD: if.h,v 1.131 2011/12/02 03:15:31 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 76 struct mbuf; 77 struct proc; 78 struct rtentry; 79 struct socket; 80 struct ether_header; 81 struct arpcom; 82 struct rt_addrinfo; 83 struct ifnet; 84 85 /* 86 * Structure describing a `cloning' interface. 87 */ 88 struct 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 */ 103 struct 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 111 struct 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 */ 123 struct 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 */ 159 struct 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 */ 187 struct 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 */ 227 TAILQ_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 241 struct 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_VLAN_MTU 0x00000010 /* VLAN-compatible MTU */ 359 #define IFCAP_VLAN_HWTAGGING 0x00000020 /* hardware VLAN tag support */ 360 #define IFCAP_CSUM_TCPv6 0x00000080 /* can do IPv6/TCP checksums */ 361 #define IFCAP_CSUM_UDPv6 0x00000100 /* can do IPv6/UDP checksums */ 362 #define IFCAP_WOL 0x00008000 /* can do wake on lan */ 363 364 /* 365 * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1) 366 * input routines have queues of messages stored on ifqueue structures 367 * (defined above). Entries are added to and deleted from these structures 368 * by these macros, which should be called with ipl raised to splnet(). 369 */ 370 #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 371 #define IF_DROP(ifq) ((ifq)->ifq_drops++) 372 #define IF_ENQUEUE(ifq, m) \ 373 do { \ 374 (m)->m_nextpkt = NULL; \ 375 if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL) \ 376 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = m; \ 377 else \ 378 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail->m_nextpkt = m; \ 379 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = m; \ 380 (ifq)->ifq_len++; \ 381 } while (/* CONSTCOND */0) 382 #define IF_PREPEND(ifq, m) \ 383 do { \ 384 (m)->m_nextpkt = (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head; \ 385 if ((ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail == NULL) \ 386 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].tail = (m); \ 387 (ifq)->ifq_q[(m)->m_pkthdr.pf.prio].head = (m); \ 388 (ifq)->ifq_len++; \ 389 } while (/* CONSTCOND */0) 390 391 #define IF_POLL(ifq, m) \ 392 do { \ 393 int if_dequeue_prio = IFQ_MAXPRIO; \ 394 do { \ 395 (m) = (ifq)->ifq_q[if_dequeue_prio].head; \ 396 } while (!(m) && --if_dequeue_prio >= 0); \ 397 } while (/* CONSTCOND */0) 398 399 #define IF_DEQUEUE(ifq, m) \ 400 do { \ 401 int if_dequeue_prio = IFQ_MAXPRIO; \ 402 do { \ 403 (m) = (ifq)->ifq_q[if_dequeue_prio].head; \ 404 if (m) { \ 405 if (((ifq)->ifq_q[if_dequeue_prio].head = \ 406 (m)->m_nextpkt) == NULL) \ 407 (ifq)->ifq_q[if_dequeue_prio].tail = NULL; \ 408 (m)->m_nextpkt = NULL; \ 409 (ifq)->ifq_len--; \ 410 } \ 411 } while (!(m) && --if_dequeue_prio >= 0); \ 412 } while (/* CONSTCOND */0) 413 414 #define IF_INPUT_ENQUEUE(ifq, m) \ 415 do { \ 416 if (IF_QFULL(ifq)) { \ 417 IF_DROP(ifq); \ 418 m_freem(m); \ 419 if (!(ifq)->ifq_congestion) \ 420 if_congestion(ifq); \ 421 } else \ 422 IF_ENQUEUE(ifq, m); \ 423 } while (/* CONSTCOND */0) 424 425 #define IF_PURGE(ifq) \ 426 do { \ 427 struct mbuf *__m0; \ 428 \ 429 for (;;) { \ 430 IF_DEQUEUE((ifq), __m0); \ 431 if (__m0 == NULL) \ 432 break; \ 433 else \ 434 m_freem(__m0); \ 435 } \ 436 } while (/* CONSTCOND */0) 437 #define IF_LEN(ifq) ((ifq)->ifq_len) 438 #define IF_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 439 440 #define IFQ_MAXLEN 256 441 #define IFNET_SLOWHZ 1 /* granularity is 1 second */ 442 443 /* symbolic names for terminal (per-protocol) CTL_IFQ_ nodes */ 444 #define IFQCTL_LEN 1 445 #define IFQCTL_MAXLEN 2 446 #define IFQCTL_DROPS 3 447 #define IFQCTL_CONGESTION 4 448 #define IFQCTL_MAXID 5 449 450 /* sysctl for ifq (per-protocol packet input queue variant of ifqueue) */ 451 #define CTL_IFQ_NAMES { \ 452 { 0, 0 }, \ 453 { "len", CTLTYPE_INT }, \ 454 { "maxlen", CTLTYPE_INT }, \ 455 { "drops", CTLTYPE_INT }, \ 456 { "congestion", CTLTYPE_INT }, \ 457 } 458 459 /* 460 * The ifaddr structure contains information about one address 461 * of an interface. They are maintained by the different address families, 462 * are allocated and attached when an address is set, and are linked 463 * together so all addresses for an interface can be located. 464 */ 465 struct ifaddr { 466 struct sockaddr *ifa_addr; /* address of interface */ 467 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 468 #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 469 struct sockaddr *ifa_netmask; /* used to determine subnet */ 470 struct ifnet *ifa_ifp; /* back-pointer to interface */ 471 TAILQ_ENTRY(ifaddr) ifa_list; /* list of addresses for interface */ 472 /* check or clean routes (+ or -)'d */ 473 void (*ifa_rtrequest)(int, struct rtentry *, struct rt_addrinfo *); 474 u_int ifa_flags; /* mostly rt_flags for cloning */ 475 u_int ifa_refcnt; /* count of references */ 476 int ifa_metric; /* cost of going out this interface */ 477 }; 478 #define IFA_ROUTE RTF_UP /* route installed */ 479 480 struct ifaddr_item { 481 RB_ENTRY(ifaddr_item) ifai_entry; 482 struct sockaddr *ifai_addr; 483 struct ifaddr *ifai_ifa; 484 struct ifaddr_item *ifai_next; 485 u_int ifai_rdomain; 486 }; 487 488 /* 489 * Message format for use in obtaining information about interfaces 490 * from sysctl and the routing socket. 491 */ 492 struct if_msghdr { 493 u_short ifm_msglen; /* to skip over non-understood messages */ 494 u_char ifm_version; /* future binary compatibility */ 495 u_char ifm_type; /* message type */ 496 u_short ifm_hdrlen; /* sizeof(if_msghdr) to skip over the header */ 497 u_short ifm_index; /* index for associated ifp */ 498 u_short ifm_tableid; /* routing table id */ 499 u_char ifm_pad1; 500 u_char ifm_pad2; 501 int ifm_addrs; /* like rtm_addrs */ 502 int ifm_flags; /* value of if_flags */ 503 int ifm_xflags; 504 struct if_data ifm_data;/* statistics and other data about if */ 505 }; 506 507 /* 508 * Message format for use in obtaining information about interface addresses 509 * from sysctl and the routing socket. 510 */ 511 struct ifa_msghdr { 512 u_short ifam_msglen; /* to skip over non-understood messages */ 513 u_char ifam_version; /* future binary compatibility */ 514 u_char ifam_type; /* message type */ 515 u_short ifam_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */ 516 u_short ifam_index; /* index for associated ifp */ 517 u_short ifam_tableid; /* routing table id */ 518 u_char ifam_pad1; 519 u_char ifam_pad2; 520 int ifam_addrs; /* like rtm_addrs */ 521 int ifam_flags; /* value of ifa_flags */ 522 int ifam_metric; /* value of ifa_metric */ 523 }; 524 525 526 /* 527 * Message format announcing the arrival or departure of a network interface. 528 */ 529 struct if_announcemsghdr { 530 u_short ifan_msglen; /* to skip over non-understood messages */ 531 u_char ifan_version; /* future binary compatibility */ 532 u_char ifan_type; /* message type */ 533 u_short ifan_hdrlen; /* sizeof(ifa_msghdr) to skip over the header */ 534 u_short ifan_index; /* index for associated ifp */ 535 u_short ifan_what; /* what type of announcement */ 536 char ifan_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 537 }; 538 539 #define IFAN_ARRIVAL 0 /* interface arrival */ 540 #define IFAN_DEPARTURE 1 /* interface departure */ 541 542 /* 543 * interface groups 544 */ 545 546 #define IFG_ALL "all" /* group contains all interfaces */ 547 #define IFG_EGRESS "egress" /* if(s) default route(s) point to */ 548 549 struct ifg_group { 550 char ifg_group[IFNAMSIZ]; 551 u_int ifg_refcnt; 552 caddr_t ifg_pf_kif; 553 int ifg_carp_demoted; 554 TAILQ_HEAD(, ifg_member) ifg_members; 555 TAILQ_ENTRY(ifg_group) ifg_next; 556 }; 557 558 struct ifg_member { 559 TAILQ_ENTRY(ifg_member) ifgm_next; 560 struct ifnet *ifgm_ifp; 561 }; 562 563 struct ifg_list { 564 struct ifg_group *ifgl_group; 565 TAILQ_ENTRY(ifg_list) ifgl_next; 566 }; 567 568 struct ifg_req { 569 union { 570 char ifgrqu_group[IFNAMSIZ]; 571 char ifgrqu_member[IFNAMSIZ]; 572 } ifgrq_ifgrqu; 573 #define ifgrq_group ifgrq_ifgrqu.ifgrqu_group 574 #define ifgrq_member ifgrq_ifgrqu.ifgrqu_member 575 }; 576 577 struct ifg_attrib { 578 int ifg_carp_demoted; 579 }; 580 581 /* 582 * Used to lookup groups for an interface 583 */ 584 struct ifgroupreq { 585 char ifgr_name[IFNAMSIZ]; 586 u_int ifgr_len; 587 union { 588 char ifgru_group[IFNAMSIZ]; 589 struct ifg_req *ifgru_groups; 590 struct ifg_attrib ifgru_attrib; 591 } ifgr_ifgru; 592 #define ifgr_group ifgr_ifgru.ifgru_group 593 #define ifgr_groups ifgr_ifgru.ifgru_groups 594 #define ifgr_attrib ifgr_ifgru.ifgru_attrib 595 }; 596 597 /* 598 * Interface request structure used for socket 599 * ioctl's. All interface ioctl's must have parameter 600 * definitions which begin with ifr_name. The 601 * remainder may be interface specific. 602 */ 603 struct ifreq { 604 char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 605 union { 606 struct sockaddr ifru_addr; 607 struct sockaddr ifru_dstaddr; 608 struct sockaddr ifru_broadaddr; 609 short ifru_flags; 610 int ifru_metric; 611 caddr_t ifru_data; 612 } ifr_ifru; 613 #define ifr_addr ifr_ifru.ifru_addr /* address */ 614 #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */ 615 #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 616 #define ifr_flags ifr_ifru.ifru_flags /* flags */ 617 #define ifr_metric ifr_ifru.ifru_metric /* metric */ 618 #define ifr_mtu ifr_ifru.ifru_metric /* mtu (overload) */ 619 #define ifr_media ifr_ifru.ifru_metric /* media options (overload) */ 620 #define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */ 621 #define ifr_data ifr_ifru.ifru_data /* for use by interface */ 622 }; 623 624 struct ifaliasreq { 625 char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 626 struct sockaddr ifra_addr; 627 struct sockaddr ifra_dstaddr; 628 #define ifra_broadaddr ifra_dstaddr 629 struct sockaddr ifra_mask; 630 }; 631 632 struct ifmediareq { 633 char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 634 int ifm_current; /* current media options */ 635 int ifm_mask; /* don't care mask */ 636 int ifm_status; /* media status */ 637 int ifm_active; /* active options */ 638 int ifm_count; /* # entries in ifm_ulist 639 array */ 640 int *ifm_ulist; /* media words */ 641 }; 642 643 struct ifkalivereq { 644 char ikar_name[IFNAMSIZ]; /* if name, e.g. "en0" */ 645 int ikar_timeo; 646 int ikar_cnt; 647 }; 648 649 /* 650 * Structure used in SIOCGIFCONF request. 651 * Used to retrieve interface configuration 652 * for machine (useful for programs which 653 * must know all networks accessible). 654 */ 655 struct ifconf { 656 int ifc_len; /* size of associated buffer */ 657 union { 658 caddr_t ifcu_buf; 659 struct ifreq *ifcu_req; 660 } ifc_ifcu; 661 #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ 662 #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */ 663 }; 664 665 /* 666 * Structure for SIOC[AGD]LIFADDR 667 */ 668 struct if_laddrreq { 669 char iflr_name[IFNAMSIZ]; 670 unsigned int flags; 671 #define IFLR_PREFIX 0x8000 /* in: prefix given out: kernel fills id */ 672 unsigned int prefixlen; /* in/out */ 673 struct sockaddr_storage addr; /* in/out */ 674 struct sockaddr_storage dstaddr; /* out */ 675 }; 676 677 struct if_nameindex { 678 unsigned int if_index; 679 char *if_name; 680 }; 681 682 #ifndef _KERNEL 683 __BEGIN_DECLS 684 unsigned int if_nametoindex(const char *); 685 char *if_indextoname(unsigned int, char *); 686 struct if_nameindex *if_nameindex(void); 687 void if_freenameindex(struct if_nameindex *); 688 __END_DECLS 689 #endif 690 691 #include <net/if_arp.h> 692 693 #ifdef _KERNEL 694 #define IFAFREE(ifa) \ 695 do { \ 696 if ((ifa)->ifa_refcnt <= 0) \ 697 ifafree(ifa); \ 698 else \ 699 (ifa)->ifa_refcnt--; \ 700 } while (/* CONSTCOND */0) 701 702 #ifdef ALTQ 703 704 #define IFQ_ENQUEUE(ifq, m, pattr, err) \ 705 do { \ 706 if (ALTQ_IS_ENABLED((ifq))) { \ 707 m->m_pkthdr.pf.prio = IFQ_MAXPRIO; \ 708 ALTQ_ENQUEUE((ifq), (m), (pattr), (err)); \ 709 } else { \ 710 if (IF_QFULL((ifq))) { \ 711 m_freem((m)); \ 712 (err) = ENOBUFS; \ 713 } else { \ 714 IF_ENQUEUE((ifq), (m)); \ 715 (err) = 0; \ 716 } \ 717 } \ 718 if ((err)) \ 719 (ifq)->ifq_drops++; \ 720 } while (/* CONSTCOND */0) 721 722 #define IFQ_DEQUEUE(ifq, m) \ 723 do { \ 724 if (OLDTBR_IS_ENABLED((ifq))) \ 725 (m) = oldtbr_dequeue((ifq), ALTDQ_REMOVE); \ 726 else if (ALTQ_IS_ENABLED((ifq))) \ 727 ALTQ_DEQUEUE((ifq), (m)); \ 728 else \ 729 IF_DEQUEUE((ifq), (m)); \ 730 } while (/* CONSTCOND */0) 731 732 #define IFQ_POLL(ifq, m) \ 733 do { \ 734 if (TBR_IS_ENABLED((ifq))) \ 735 (m) = oldtbr_dequeue((ifq), ALTDQ_POLL); \ 736 else if (ALTQ_IS_ENABLED((ifq))) \ 737 ALTQ_POLL((ifq), (m)); \ 738 else \ 739 IF_POLL((ifq), (m)); \ 740 } while (/* CONSTCOND */0) 741 742 #define IFQ_PURGE(ifq) \ 743 do { \ 744 if (ALTQ_IS_ENABLED((ifq))) \ 745 ALTQ_PURGE((ifq)); \ 746 else \ 747 IF_PURGE((ifq)); \ 748 } while (/* CONSTCOND */0) 749 750 #define IFQ_SET_READY(ifq) \ 751 do { \ 752 ((ifq)->altq_flags |= ALTQF_READY); \ 753 } while (/* CONSTCOND */0) 754 755 #else /* !ALTQ */ 756 757 #define IFQ_ENQUEUE(ifq, m, pattr, err) \ 758 do { \ 759 if (IF_QFULL((ifq))) { \ 760 m_freem((m)); \ 761 (err) = ENOBUFS; \ 762 } else { \ 763 IF_ENQUEUE((ifq), (m)); \ 764 (err) = 0; \ 765 } \ 766 if ((err)) \ 767 (ifq)->ifq_drops++; \ 768 } while (/* CONSTCOND */0) 769 770 #define IFQ_DEQUEUE(ifq, m) IF_DEQUEUE((ifq), (m)) 771 772 #define IFQ_POLL(ifq, m) IF_POLL((ifq), (m)) 773 774 #define IFQ_PURGE(ifq) IF_PURGE((ifq)) 775 776 #define IFQ_SET_READY(ifq) /* nothing */ 777 778 #endif /* ALTQ */ 779 780 #define IFQ_LEN(ifq) IF_LEN(ifq) 781 #define IFQ_IS_EMPTY(ifq) ((ifq)->ifq_len == 0) 782 #define IFQ_INC_LEN(ifq) ((ifq)->ifq_len++) 783 #define IFQ_DEC_LEN(ifq) (--(ifq)->ifq_len) 784 #define IFQ_INC_DROPS(ifq) ((ifq)->ifq_drops++) 785 #define IFQ_SET_MAXLEN(ifq, len) ((ifq)->ifq_maxlen = (len)) 786 787 /* default interface priorities */ 788 #define IF_WIRED_DEFAULT_PRIORITY 0 789 #define IF_WIRELESS_DEFAULT_PRIORITY 4 790 791 extern int ifqmaxlen; 792 extern struct ifnet_head ifnet; 793 extern struct ifnet **ifindex2ifnet; 794 extern struct ifnet *lo0ifp; 795 extern int if_indexlim; 796 797 #define ether_input_mbuf(ifp, m) ether_input((ifp), NULL, (m)) 798 799 void ether_ifattach(struct ifnet *); 800 void ether_ifdetach(struct ifnet *); 801 int ether_ioctl(struct ifnet *, struct arpcom *, u_long, caddr_t); 802 void ether_input(struct ifnet *, struct ether_header *, struct mbuf *); 803 int ether_output(struct ifnet *, 804 struct mbuf *, struct sockaddr *, struct rtentry *); 805 char *ether_sprintf(u_char *); 806 807 void if_alloc_sadl(struct ifnet *); 808 void if_free_sadl(struct ifnet *); 809 void if_attach(struct ifnet *); 810 void if_attachdomain(void); 811 void if_attachtail(struct ifnet *); 812 void if_attachhead(struct ifnet *); 813 void if_detach(struct ifnet *); 814 void if_down(struct ifnet *); 815 void if_downall(void); 816 void if_link_state_change(struct ifnet *); 817 void if_slowtimo(void *); 818 void if_up(struct ifnet *); 819 int ifconf(u_long, caddr_t); 820 void ifinit(void); 821 int ifioctl(struct socket *, u_long, caddr_t, struct proc *); 822 int ifpromisc(struct ifnet *, int); 823 struct ifg_group *if_creategroup(const char *); 824 int if_addgroup(struct ifnet *, const char *); 825 int if_delgroup(struct ifnet *, const char *); 826 void if_group_routechange(struct sockaddr *, struct sockaddr *); 827 struct ifnet *ifunit(const char *); 828 void if_start(struct ifnet *); 829 void ifnewlladdr(struct ifnet *); 830 831 struct ifaddr *ifa_ifwithaddr(struct sockaddr *, u_int); 832 struct ifaddr *ifa_ifwithaf(int, u_int); 833 struct ifaddr *ifa_ifwithdstaddr(struct sockaddr *, u_int); 834 struct ifaddr *ifa_ifwithnet(struct sockaddr *, u_int); 835 struct ifaddr *ifa_ifwithroute(int, struct sockaddr *, 836 struct sockaddr *, u_int); 837 struct ifaddr *ifaof_ifpforaddr(struct sockaddr *, struct ifnet *); 838 void ifafree(struct ifaddr *); 839 void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 840 841 void if_clone_attach(struct if_clone *); 842 void if_clone_detach(struct if_clone *); 843 844 int if_clone_create(const char *); 845 int if_clone_destroy(const char *); 846 847 void if_congestion(struct ifqueue *); 848 int sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t, 849 struct ifqueue *); 850 851 int loioctl(struct ifnet *, u_long, caddr_t); 852 void loopattach(int); 853 int looutput(struct ifnet *, 854 struct mbuf *, struct sockaddr *, struct rtentry *); 855 void lortrequest(int, struct rtentry *, struct rt_addrinfo *); 856 void ifa_add(struct ifnet *, struct ifaddr *); 857 void ifa_del(struct ifnet *, struct ifaddr *); 858 void ifa_update_broadaddr(struct ifnet *, struct ifaddr *, 859 struct sockaddr *); 860 #endif /* _KERNEL */ 861 #endif /* _NET_IF_H_ */ 862