1/* 2 * Copyright (c) 2000-2008 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28/* 29 * Copyright (c) 1982, 1986, 1989, 1993 30 * The Regents of the University of California. All rights reserved. 31 * 32 * Redistribution and use in source and binary forms, with or without 33 * modification, are permitted provided that the following conditions 34 * are met: 35 * 1. Redistributions of source code must retain the above copyright 36 * notice, this list of conditions and the following disclaimer. 37 * 2. Redistributions in binary form must reproduce the above copyright 38 * notice, this list of conditions and the following disclaimer in the 39 * documentation and/or other materials provided with the distribution. 40 * 3. All advertising materials mentioning features or use of this software 41 * must display the following acknowledgement: 42 * This product includes software developed by the University of 43 * California, Berkeley and its contributors. 44 * 4. Neither the name of the University nor the names of its contributors 45 * may be used to endorse or promote products derived from this software 46 * without specific prior written permission. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * SUCH DAMAGE. 59 * 60 * From: @(#)if.h 8.1 (Berkeley) 6/10/93 61 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.7 2001/07/24 19:10:18 brooks Exp $ 62 */ 63 64#ifndef _NET_IF_VAR_H_ 65#define _NET_IF_VAR_H_ 66 67#include <sys/appleapiopts.h> 68#include <sys/types.h> 69#include <sys/time.h> 70#include <sys/queue.h> /* get TAILQ macros */ 71#ifdef KERNEL_PRIVATE 72#include <kern/locks.h> 73#endif /* KERNEL_PRIVATE */ 74 75#ifdef KERNEL 76#include <net/kpi_interface.h> 77#endif KERNEL 78 79#ifdef __APPLE__ 80#define APPLE_IF_FAM_LOOPBACK 1 81#define APPLE_IF_FAM_ETHERNET 2 82#define APPLE_IF_FAM_SLIP 3 83#define APPLE_IF_FAM_TUN 4 84#define APPLE_IF_FAM_VLAN 5 85#define APPLE_IF_FAM_PPP 6 86#define APPLE_IF_FAM_PVC 7 87#define APPLE_IF_FAM_DISC 8 88#define APPLE_IF_FAM_MDECAP 9 89#define APPLE_IF_FAM_GIF 10 90#define APPLE_IF_FAM_FAITH 11 91#define APPLE_IF_FAM_STF 12 92#define APPLE_IF_FAM_FIREWIRE 13 93#define APPLE_IF_FAM_BOND 14 94#endif /* __APPLE__ */ 95 96/* 97 * 72 was chosen below because it is the size of a TCP/IP 98 * header (40) + the minimum mss (32). 99 */ 100#define IF_MINMTU 72 101#define IF_MAXMTU 65535 102 103/* 104 * Structures defining a network interface, providing a packet 105 * transport mechanism (ala level 0 of the PUP protocols). 106 * 107 * Each interface accepts output datagrams of a specified maximum 108 * length, and provides higher level routines with input datagrams 109 * received from its medium. 110 * 111 * Output occurs when the routine if_output is called, with three parameters: 112 * (*ifp->if_output)(ifp, m, dst, rt) 113 * Here m is the mbuf chain to be sent and dst is the destination address. 114 * The output routine encapsulates the supplied datagram if necessary, 115 * and then transmits it on its medium. 116 * 117 * On input, each interface unwraps the data received by it, and either 118 * places it on the input queue of a internetwork datagram routine 119 * and posts the associated software interrupt, or passes the datagram to a raw 120 * packet input routine. 121 * 122 * Routines exist for locating interfaces by their addresses 123 * or for locating a interface on a certain network, as well as more general 124 * routing and gateway routines maintaining information used to locate 125 * interfaces. These routines live in the files if.c and route.c 126 */ 127 128#define IFNAMSIZ 16 129 130/* This belongs up in socket.h or socketvar.h, depending on how far the 131 * event bubbles up. 132 */ 133 134struct net_event_data { 135 u_int32_t if_family; 136 u_int32_t if_unit; 137 char if_name[IFNAMSIZ]; 138}; 139 140#if defined(__LP64__) 141#define __need_struct_timeval32 142#include <sys/_structs.h> 143#define IF_DATA_TIMEVAL timeval32 144#else 145#define IF_DATA_TIMEVAL timeval 146#endif 147 148#pragma pack(4) 149 150/* 151 * Structure describing information about an interface 152 * which may be of interest to management entities. 153 */ 154struct if_data { 155 /* generic interface information */ 156 u_char ifi_type; /* ethernet, tokenring, etc */ 157 u_char ifi_typelen; /* Length of frame type id */ 158 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 159 u_char ifi_addrlen; /* media address length */ 160 u_char ifi_hdrlen; /* media header length */ 161 u_char ifi_recvquota; /* polling quota for receive intrs */ 162 u_char ifi_xmitquota; /* polling quota for xmit intrs */ 163 u_char ifi_unused1; /* for future use */ 164 u_int32_t ifi_mtu; /* maximum transmission unit */ 165 u_int32_t ifi_metric; /* routing metric (external only) */ 166 u_int32_t ifi_baudrate; /* linespeed */ 167 /* volatile statistics */ 168 u_int32_t ifi_ipackets; /* packets received on interface */ 169 u_int32_t ifi_ierrors; /* input errors on interface */ 170 u_int32_t ifi_opackets; /* packets sent on interface */ 171 u_int32_t ifi_oerrors; /* output errors on interface */ 172 u_int32_t ifi_collisions; /* collisions on csma interfaces */ 173 u_int32_t ifi_ibytes; /* total number of octets received */ 174 u_int32_t ifi_obytes; /* total number of octets sent */ 175 u_int32_t ifi_imcasts; /* packets received via multicast */ 176 u_int32_t ifi_omcasts; /* packets sent via multicast */ 177 u_int32_t ifi_iqdrops; /* dropped on input, this interface */ 178 u_int32_t ifi_noproto; /* destined for unsupported protocol */ 179 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ 180 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ 181 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ 182 u_int32_t ifi_unused2; /* used to be the default_proto */ 183 u_int32_t ifi_hwassist; /* HW offload capabilities */ 184 u_int32_t ifi_reserved1; /* for future use */ 185 u_int32_t ifi_reserved2; /* for future use */ 186}; 187 188/* 189 * Structure describing information about an interface 190 * which may be of interest to management entities. 191 */ 192struct if_data64 { 193 /* generic interface information */ 194 u_char ifi_type; /* ethernet, tokenring, etc */ 195 u_char ifi_typelen; /* Length of frame type id */ 196 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 197 u_char ifi_addrlen; /* media address length */ 198 u_char ifi_hdrlen; /* media header length */ 199 u_char ifi_recvquota; /* polling quota for receive intrs */ 200 u_char ifi_xmitquota; /* polling quota for xmit intrs */ 201 u_char ifi_unused1; /* for future use */ 202 u_int32_t ifi_mtu; /* maximum transmission unit */ 203 u_int32_t ifi_metric; /* routing metric (external only) */ 204 u_int64_t ifi_baudrate; /* linespeed */ 205 /* volatile statistics */ 206 u_int64_t ifi_ipackets; /* packets received on interface */ 207 u_int64_t ifi_ierrors; /* input errors on interface */ 208 u_int64_t ifi_opackets; /* packets sent on interface */ 209 u_int64_t ifi_oerrors; /* output errors on interface */ 210 u_int64_t ifi_collisions; /* collisions on csma interfaces */ 211 u_int64_t ifi_ibytes; /* total number of octets received */ 212 u_int64_t ifi_obytes; /* total number of octets sent */ 213 u_int64_t ifi_imcasts; /* packets received via multicast */ 214 u_int64_t ifi_omcasts; /* packets sent via multicast */ 215 u_int64_t ifi_iqdrops; /* dropped on input, this interface */ 216 u_int64_t ifi_noproto; /* destined for unsupported protocol */ 217 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ 218 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ 219 struct IF_DATA_TIMEVAL ifi_lastchange; /* time of last administrative change */ 220}; 221 222#pragma pack() 223 224#ifdef PRIVATE 225/* 226 * Internal storage of if_data. This is bound to change. Various places in the 227 * stack will translate this data structure in to the externally visible 228 * if_data structure above. 229 */ 230struct if_data_internal { 231 /* generic interface information */ 232 u_char ifi_type; /* ethernet, tokenring, etc */ 233 u_char ifi_typelen; /* Length of frame type id */ 234 u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ 235 u_char ifi_addrlen; /* media address length */ 236 u_char ifi_hdrlen; /* media header length */ 237 u_char ifi_recvquota; /* polling quota for receive intrs */ 238 u_char ifi_xmitquota; /* polling quota for xmit intrs */ 239 u_char ifi_unused1; /* for future use */ 240 u_int32_t ifi_mtu; /* maximum transmission unit */ 241 u_int32_t ifi_metric; /* routing metric (external only) */ 242 u_int32_t ifi_baudrate; /* linespeed */ 243 /* volatile statistics */ 244 u_int64_t ifi_ipackets; /* packets received on interface */ 245 u_int64_t ifi_ierrors; /* input errors on interface */ 246 u_int64_t ifi_opackets; /* packets sent on interface */ 247 u_int64_t ifi_oerrors; /* output errors on interface */ 248 u_int64_t ifi_collisions; /* collisions on csma interfaces */ 249 u_int64_t ifi_ibytes; /* total number of octets received */ 250 u_int64_t ifi_obytes; /* total number of octets sent */ 251 u_int64_t ifi_imcasts; /* packets received via multicast */ 252 u_int64_t ifi_omcasts; /* packets sent via multicast */ 253 u_int64_t ifi_iqdrops; /* dropped on input, this interface */ 254 u_int64_t ifi_noproto; /* destined for unsupported protocol */ 255 u_int32_t ifi_recvtiming; /* usec spent receiving when timing */ 256 u_int32_t ifi_xmittiming; /* usec spent xmitting when timing */ 257#define IF_LASTCHANGEUPTIME 1 /* lastchange: 1-uptime 0-calendar time */ 258 struct timeval ifi_lastchange; /* time of last administrative change */ 259 u_int32_t ifi_hwassist; /* HW offload capabilities */ 260}; 261 262#define if_mtu if_data.ifi_mtu 263#define if_type if_data.ifi_type 264#define if_typelen if_data.ifi_typelen 265#define if_physical if_data.ifi_physical 266#define if_addrlen if_data.ifi_addrlen 267#define if_hdrlen if_data.ifi_hdrlen 268#define if_metric if_data.ifi_metric 269#define if_baudrate if_data.ifi_baudrate 270#define if_hwassist if_data.ifi_hwassist 271#define if_ipackets if_data.ifi_ipackets 272#define if_ierrors if_data.ifi_ierrors 273#define if_opackets if_data.ifi_opackets 274#define if_oerrors if_data.ifi_oerrors 275#define if_collisions if_data.ifi_collisions 276#define if_ibytes if_data.ifi_ibytes 277#define if_obytes if_data.ifi_obytes 278#define if_imcasts if_data.ifi_imcasts 279#define if_omcasts if_data.ifi_omcasts 280#define if_iqdrops if_data.ifi_iqdrops 281#define if_noproto if_data.ifi_noproto 282#define if_lastchange if_data.ifi_lastchange 283#define if_recvquota if_data.ifi_recvquota 284#define if_xmitquota if_data.ifi_xmitquota 285#define if_iflags if_data.ifi_iflags 286 287struct mbuf; 288struct ifaddr; 289TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ 290TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ 291TAILQ_HEAD(ifprefixhead, ifprefix); 292LIST_HEAD(ifmultihead, ifmultiaddr); 293struct tqdummy; 294TAILQ_HEAD(tailq_head, tqdummy); 295 296/* 297 * Forward structure declarations for function prototypes [sic]. 298 */ 299struct proc; 300struct rtentry; 301struct socket; 302struct ether_header; 303struct sockaddr_dl; 304struct ifnet_filter; 305 306TAILQ_HEAD(ifnet_filter_head, ifnet_filter); 307TAILQ_HEAD(ddesc_head_name, dlil_demux_desc); 308 309/* bottom 16 bits reserved for hardware checksum */ 310#define IF_HWASSIST_CSUM_IP 0x0001 /* will csum IP */ 311#define IF_HWASSIST_CSUM_TCP 0x0002 /* will csum TCP */ 312#define IF_HWASSIST_CSUM_UDP 0x0004 /* will csum UDP */ 313#define IF_HWASSIST_CSUM_IP_FRAGS 0x0008 /* will csum IP fragments */ 314#define IF_HWASSIST_CSUM_FRAGMENT 0x0010 /* will do IP fragmentation */ 315#define IF_HWASSIST_CSUM_TCP_SUM16 0x1000 /* simple TCP Sum16 computation */ 316#define IF_HWASSIST_CSUM_MASK 0xffff 317#define IF_HWASSIST_CSUM_FLAGS(hwassist) ((hwassist) & IF_HWASSIST_CSUM_MASK) 318 319/* VLAN support */ 320#define IF_HWASSIST_VLAN_TAGGING 0x10000 /* supports VLAN tagging */ 321#define IF_HWASSIST_VLAN_MTU 0x20000 /* supports VLAN MTU-sized packet (for software VLAN) */ 322 323#define IFNET_RW_LOCK 1 324 325#endif /* PRIVATE */ 326/* 327 * Structure defining a queue for a network interface. 328 */ 329struct ifqueue { 330 void *ifq_head; 331 void *ifq_tail; 332 int ifq_len; 333 int ifq_maxlen; 334 int ifq_drops; 335}; 336 337#ifdef PRIVATE 338 339struct ddesc_head_str; 340struct proto_hash_entry; 341struct kev_msg; 342struct dlil_threading_info; 343 344/* 345 * Structure defining a network interface. 346 * 347 * (Would like to call this struct ``if'', but C isn't PL/1.) 348 */ 349struct ifnet { 350 void *if_softc; /* pointer to driver state */ 351 const char *if_name; /* name, e.g. ``en'' or ``lo'' */ 352 TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ 353 struct ifaddrhead if_addrhead; /* linked list of addresses per if */ 354 u_long if_refcnt; 355#ifdef __KPI_INTERFACE__ 356 ifnet_check_multi if_check_multi; 357#else 358 void* if_check_multi; 359#endif __KPI_INTERFACE__ 360 int if_pcount; /* number of promiscuous listeners */ 361 struct bpf_if *if_bpf; /* packet filter structure */ 362 u_short if_index; /* numeric abbreviation for this if */ 363 short if_unit; /* sub-unit for lower level driver */ 364 short if_timer; /* time 'til if_watchdog called */ 365 short if_flags; /* up/down, broadcast, etc. */ 366 int if_ipending; /* interrupts pending */ 367 void *if_linkmib; /* link-type-specific MIB data */ 368 size_t if_linkmiblen; /* length of above data */ 369 struct if_data_internal if_data; 370 371/* New with DLIL */ 372#ifdef BSD_KERNEL_PRIVATE 373 int if_usecnt; 374#else 375 int refcnt; 376#endif 377#ifdef __KPI_INTERFACE__ 378 ifnet_output_func if_output; 379 ifnet_ioctl_func if_ioctl; 380 ifnet_set_bpf_tap if_set_bpf_tap; 381 ifnet_detached_func if_free; 382 ifnet_demux_func if_demux; 383 ifnet_event_func if_event; 384 ifnet_framer_func if_framer; 385 ifnet_family_t if_family; /* ulong assigned by Apple */ 386#else 387 void* if_output; 388 void* if_ioctl; 389 void* if_set_bpf_tap; 390 void* if_free; 391 void* if_demux; 392 void* if_event; 393 void* if_framer; 394 u_long if_family; /* ulong assigned by Apple */ 395#endif 396 397 struct ifnet_filter_head if_flt_head; 398 399/* End DLIL specific */ 400 401 u_long if_delayed_detach; /* need to perform delayed detach */ 402 void *if_private; /* private to interface */ 403 long if_eflags; /* autoaddr, autoaddr done, etc. */ 404 405 struct ifmultihead if_multiaddrs; /* multicast addresses configured */ 406 int if_amcount; /* number of all-multicast requests */ 407/* procedure handles */ 408#ifdef __KPI_INTERFACE__ 409 ifnet_add_proto_func if_add_proto; 410 ifnet_del_proto_func if_del_proto; 411#else __KPI_INTERFACE__ 412 void* if_add_proto; 413 void* if_del_proto; 414#endif __KPI_INTERFACE__ 415 struct proto_hash_entry *if_proto_hash; 416 void *if_kpi_storage; 417#if 0 418 void *unused_was_init; 419#else 420 struct dlil_threading_info *if_input_thread; 421#endif 422 void *unused_was_resolvemulti; 423 424 struct ifqueue if_snd; 425 u_long unused_2[1]; 426#ifdef __APPLE__ 427 u_long family_cookie; 428 struct ifprefixhead if_prefixhead; /* list of prefixes per if */ 429 430#ifdef _KERN_LOCKS_H_ 431#if IFNET_RW_LOCK 432 lck_rw_t *if_lock; /* Lock to protect this interface */ 433#else 434 lck_mtx_t *if_lock; /* Lock to protect this interface */ 435#endif 436#else 437 void *if_lock; 438#endif 439 440#else 441 struct ifprefixhead if_prefixhead; /* list of prefixes per if */ 442#endif /* __APPLE__ */ 443 struct { 444 u_long length; 445 union { 446 u_char buffer[8]; 447 u_char *ptr; 448 } u; 449 } if_broadcast; 450#if CONFIG_MACF_NET 451 struct label *if_label; /* interface MAC label */ 452#endif 453}; 454 455#ifndef __APPLE__ 456/* for compatibility with other BSDs */ 457#define if_addrlist if_addrhead 458#define if_list if_link 459#endif !__APPLE__ 460 461 462#endif /* PRIVATE */ 463 464#ifdef KERNEL_PRIVATE 465/* 466 * Structure describing a `cloning' interface. 467 */ 468struct if_clone { 469 LIST_ENTRY(if_clone) ifc_list; /* on list of cloners */ 470 const char *ifc_name; /* name of device, e.g. `vlan' */ 471 size_t ifc_namelen; /* length of name */ 472 int ifc_minifs; /* minimum number of interfaces */ 473 int ifc_maxunit; /* maximum unit number */ 474 unsigned char *ifc_units; /* bitmap to handle units */ 475 int ifc_bmlen; /* bitmap length */ 476 477 int (*ifc_create)(struct if_clone *, int); 478 void (*ifc_destroy)(struct ifnet *); 479}; 480 481#define IF_CLONE_INITIALIZER(name, create, destroy, minifs, maxunit) \ 482 { { NULL, NULL }, name, sizeof(name) - 1, minifs, maxunit, NULL, 0, create, destroy } 483 484/* 485 * Bit values in if_ipending 486 */ 487#define IFI_RECV 1 /* I want to receive */ 488#define IFI_XMIT 2 /* I want to transmit */ 489 490/* 491 * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) 492 * are queues of messages stored on ifqueue structures 493 * (defined above). Entries are added to and deleted from these structures 494 * by these macros, which should be called with ipl raised to splimp(). 495 */ 496#define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) 497#define IF_DROP(ifq) ((ifq)->ifq_drops++) 498#define IF_ENQUEUE(ifq, m) { \ 499 (m)->m_nextpkt = 0; \ 500 if ((ifq)->ifq_tail == 0) \ 501 (ifq)->ifq_head = m; \ 502 else \ 503 ((struct mbuf*)(ifq)->ifq_tail)->m_nextpkt = m; \ 504 (ifq)->ifq_tail = m; \ 505 (ifq)->ifq_len++; \ 506} 507#define IF_PREPEND(ifq, m) { \ 508 (m)->m_nextpkt = (ifq)->ifq_head; \ 509 if ((ifq)->ifq_tail == 0) \ 510 (ifq)->ifq_tail = (m); \ 511 (ifq)->ifq_head = (m); \ 512 (ifq)->ifq_len++; \ 513} 514#define IF_DEQUEUE(ifq, m) { \ 515 (m) = (ifq)->ifq_head; \ 516 if (m) { \ 517 if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ 518 (ifq)->ifq_tail = 0; \ 519 (m)->m_nextpkt = 0; \ 520 (ifq)->ifq_len--; \ 521 } \ 522} 523 524#define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) 525 526#if defined(__GNUC__) && defined(MT_HEADER) 527static __inline int 528if_queue_drop(struct ifqueue *ifq, __unused struct mbuf *m) 529{ 530 IF_DROP(ifq); 531 return 0; 532} 533 534static __inline int 535if_enq_drop(struct ifqueue *ifq, struct mbuf *m) 536{ 537 if (IF_QFULL(ifq) && 538 !if_queue_drop(ifq, m)) 539 return 0; 540 IF_ENQUEUE(ifq, m); 541 return 1; 542} 543#else 544 545#ifdef MT_HEADER 546int if_enq_drop(struct ifqueue *, struct mbuf *); 547#endif MT_HEADER 548 549#endif defined(__GNUC__) && defined(MT_HEADER) 550 551#endif /* KERNEL_PRIVATE */ 552 553 554#ifdef PRIVATE 555/* 556 * The ifaddr structure contains information about one address 557 * of an interface. They are maintained by the different address families, 558 * are allocated and attached when an address is set, and are linked 559 * together so all addresses for an interface can be located. 560 */ 561struct ifaddr { 562 struct sockaddr *ifa_addr; /* address of interface */ 563 struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ 564#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ 565 struct sockaddr *ifa_netmask; /* used to determine subnet */ 566 struct ifnet *ifa_ifp; /* back-pointer to interface */ 567 TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ 568 void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ 569 (int, struct rtentry *, struct sockaddr *); 570 u_short ifa_flags; /* mostly rt_flags for cloning */ 571 int ifa_refcnt;/* 32bit ref count, use ifaref, ifafree */ 572 int ifa_metric; /* cost of going out this interface */ 573#ifdef notdef 574 struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */ 575#endif 576 int (*ifa_claim_addr) /* check if an addr goes to this if */ 577 (struct ifaddr *, const struct sockaddr *); 578 u_long ifa_debug; /* debug flags */ 579}; 580#define IFA_ROUTE RTF_UP /* route installed (0x1) */ 581#define IFA_CLONING RTF_CLONING /* (0x100) */ 582#define IFA_ATTACHED 0x1 /* ifa_debug: IFA is attached to an interface */ 583 584#endif /* PRIVATE */ 585 586#ifdef KERNEL_PRIVATE 587/* 588 * The prefix structure contains information about one prefix 589 * of an interface. They are maintained by the different address families, 590 * are allocated and attached when an prefix or an address is set, 591 * and are linked together so all prefixes for an interface can be located. 592 */ 593struct ifprefix { 594 struct sockaddr *ifpr_prefix; /* prefix of interface */ 595 struct ifnet *ifpr_ifp; /* back-pointer to interface */ 596 TAILQ_ENTRY(ifprefix) ifpr_list; /* queue macro glue */ 597 u_char ifpr_plen; /* prefix length in bits */ 598 u_char ifpr_type; /* protocol dependent prefix type */ 599}; 600#endif /* KERNEL_PRIVATE */ 601 602#ifdef PRIVATE 603typedef void (*ifma_protospec_free_func)(void* ifma_protospec); 604 605/* 606 * Multicast address structure. This is analogous to the ifaddr 607 * structure except that it keeps track of multicast addresses. 608 * Also, the reference count here is a count of requests for this 609 * address, not a count of pointers to this structure. 610 */ 611struct ifmultiaddr { 612 LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ 613 struct sockaddr *ifma_addr; /* address this membership is for */ 614 struct ifmultiaddr *ifma_ll; /* link-layer translation, if any */ 615 struct ifnet *ifma_ifp; /* back-pointer to interface */ 616 u_int ifma_usecount; /* use count, protected by ifp's lock */ 617 void *ifma_protospec; /* protocol-specific state, if any */ 618 int32_t ifma_refcount; /* reference count, atomically protected */ 619 ifma_protospec_free_func ifma_free; /* function called to free ifma_protospec */ 620}; 621#endif /* PRIVATE */ 622 623#ifdef KERNEL_PRIVATE 624#define IFAREF(ifa) ifaref(ifa) 625#define IFAFREE(ifa) ifafree(ifa) 626 627/* 628 * To preserve kmem compatibility, we define 629 * ifnet_head to ifnet. This should be temp. 630 */ 631#define ifnet_head ifnet 632extern struct ifnethead ifnet_head; 633extern struct ifnet **ifindex2ifnet; 634extern int ifqmaxlen; 635extern ifnet_t lo_ifp; 636extern int if_index; 637extern struct ifaddr **ifnet_addrs; 638 639int if_addmulti(struct ifnet *, const struct sockaddr *, struct ifmultiaddr **); 640int if_allmulti(struct ifnet *, int); 641void if_attach(struct ifnet *); 642int if_delmultiaddr(struct ifmultiaddr *ifma, int locked); 643int if_delmulti(struct ifnet *, const struct sockaddr *); 644void if_down(struct ifnet *); 645int if_down_all(void); 646void if_route(struct ifnet *, int flag, int fam); 647void if_unroute(struct ifnet *, int flag, int fam); 648void if_up(struct ifnet *); 649void if_updown(struct ifnet *ifp, int up); 650/*void ifinit(void));*/ /* declared in systm.h for main( */ 651int ifioctl(struct socket *, u_long, caddr_t, struct proc *); 652int ifioctllocked(struct socket *, u_long, caddr_t, struct proc *); 653struct ifnet *ifunit(const char *); 654struct ifnet *if_withname(struct sockaddr *); 655 656void if_clone_attach(struct if_clone *); 657void if_clone_detach(struct if_clone *); 658 659void ifnet_lock_assert(struct ifnet *ifp, int what); 660void ifnet_lock_shared(struct ifnet *ifp); 661void ifnet_lock_exclusive(struct ifnet *ifp); 662void ifnet_lock_done(struct ifnet *ifp); 663 664void ifnet_head_lock_shared(void); 665void ifnet_head_lock_exclusive(void); 666void ifnet_head_done(void); 667 668void if_attach_ifa(struct ifnet * ifp, struct ifaddr *ifa); 669void if_detach_ifa(struct ifnet * ifp, struct ifaddr *ifa); 670 671void ifma_reference(struct ifmultiaddr *ifma); 672void ifma_release(struct ifmultiaddr *ifma); 673 674struct ifaddr *ifa_ifwithaddr(const struct sockaddr *); 675struct ifaddr *ifa_ifwithaddr_scoped(const struct sockaddr *, unsigned int); 676struct ifaddr *ifa_ifwithdstaddr(const struct sockaddr *); 677struct ifaddr *ifa_ifwithnet(const struct sockaddr *); 678struct ifaddr *ifa_ifwithnet_scoped(const struct sockaddr *, unsigned int); 679struct ifaddr *ifa_ifwithroute(int, const struct sockaddr *, const struct sockaddr *); 680struct ifaddr *ifa_ifwithroute_locked(int, const struct sockaddr *, const struct sockaddr *); 681struct ifaddr *ifa_ifwithroute_scoped_locked(int, const struct sockaddr *, 682 const struct sockaddr *, unsigned int); 683struct ifaddr *ifaof_ifpforaddr(const struct sockaddr *, struct ifnet *); 684struct ifaddr *ifa_ifpgetprimary(struct ifnet *, int); 685void ifafree(struct ifaddr *); 686void ifaref(struct ifaddr *); 687 688struct ifmultiaddr *ifmaof_ifpforaddr(const struct sockaddr *, struct ifnet *); 689 690int ifa_foraddr(unsigned int addr); 691 692#ifdef BSD_KERNEL_PRIVATE 693enum { 694 kIfNetUseCount_MayBeZero = 0, 695 kIfNetUseCount_MustNotBeZero = 1 696}; 697 698int ifp_use(struct ifnet *ifp, int handle_zero); 699int ifp_unuse(struct ifnet *ifp); 700void ifp_use_reached_zero(struct ifnet *ifp); 701 702void if_data_internal_to_if_data(struct ifnet *ifp, const struct if_data_internal *if_data_int, 703 struct if_data *if_data); 704void if_data_internal_to_if_data64(struct ifnet *ifp, const struct if_data_internal *if_data_int, 705 struct if_data64 *if_data64); 706#endif /* BSD_KERNEL_PRIVATE */ 707#endif /* KERNEL_PRIVATE */ 708#endif /* !_NET_IF_VAR_H_ */ 709