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