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