|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* ! 23: * Copyright (c) 1982, 1986, 1989, 1993 ! 24: * The Regents of the University of California. All rights reserved. ! 25: * ! 26: * Redistribution and use in source and binary forms, with or without ! 27: * modification, are permitted provided that the following conditions ! 28: * are met: ! 29: * 1. Redistributions of source code must retain the above copyright ! 30: * notice, this list of conditions and the following disclaimer. ! 31: * 2. Redistributions in binary form must reproduce the above copyright ! 32: * notice, this list of conditions and the following disclaimer in the ! 33: * documentation and/or other materials provided with the distribution. ! 34: * 3. All advertising materials mentioning features or use of this software ! 35: * must display the following acknowledgement: ! 36: * This product includes software developed by the University of ! 37: * California, Berkeley and its contributors. ! 38: * 4. Neither the name of the University nor the names of its contributors ! 39: * may be used to endorse or promote products derived from this software ! 40: * without specific prior written permission. ! 41: * ! 42: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 43: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 44: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 45: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 46: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 47: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 48: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 49: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 50: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 51: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 52: * SUCH DAMAGE. ! 53: * ! 54: * From: @(#)if.h 8.1 (Berkeley) 6/10/93 ! 55: */ ! 56: ! 57: #ifndef _NET_IF_VAR_H_ ! 58: #define _NET_IF_VAR_H_ ! 59: ! 60: ! 61: ! 62: #define APPLE_IF_FAM_LOOPBACK 1 ! 63: #define APPLE_IF_FAM_ETHERNET 2 ! 64: #define APPLE_IF_FAM_SLIP 3 ! 65: #define APPLE_IF_FAM_TUN 4 ! 66: #define APPLE_IF_FAM_VLAN 5 ! 67: #define APPLE_IF_FAM_PPP 6 ! 68: #define APPLE_IF_FAM_PVC 7 ! 69: #define APPLE_IF_FAM_DISC 8 ! 70: #define APPLE_IF_FAM_MDECAP 9 ! 71: ! 72: ! 73: /* ! 74: * Structures defining a network interface, providing a packet ! 75: * transport mechanism (ala level 0 of the PUP protocols). ! 76: * ! 77: * Each interface accepts output datagrams of a specified maximum ! 78: * length, and provides higher level routines with input datagrams ! 79: * received from its medium. ! 80: * ! 81: * Output occurs when the routine if_output is called, with three parameters: ! 82: * (*ifp->if_output)(ifp, m, dst, rt) ! 83: * Here m is the mbuf chain to be sent and dst is the destination address. ! 84: * The output routine encapsulates the supplied datagram if necessary, ! 85: * and then transmits it on its medium. ! 86: * ! 87: * On input, each interface unwraps the data received by it, and either ! 88: * places it on the input queue of a internetwork datagram routine ! 89: * and posts the associated software interrupt, or passes the datagram to a raw ! 90: * packet input routine. ! 91: * ! 92: * Routines exist for locating interfaces by their addresses ! 93: * or for locating a interface on a certain network, as well as more general ! 94: * routing and gateway routines maintaining information used to locate ! 95: * interfaces. These routines live in the files if.c and route.c ! 96: */ ! 97: ! 98: #ifdef __STDC__ ! 99: /* ! 100: * Forward structure declarations for function prototypes [sic]. ! 101: */ ! 102: struct mbuf; ! 103: struct proc; ! 104: struct rtentry; ! 105: struct socket; ! 106: struct sockaddr_dl; ! 107: #endif ! 108: ! 109: #define IFNAMSIZ 16 ! 110: ! 111: #include <sys/queue.h> /* get TAILQ macros */ ! 112: ! 113: struct tqdummy { ! 114: }; ! 115: ! 116: TAILQ_HEAD(tailq_head, tqdummy); ! 117: ! 118: ! 119: /* This belongs up in socket.h or socketvar.h, depending on how far the ! 120: * event bubbles up. ! 121: */ ! 122: ! 123: struct event_msg { ! 124: int msg_len; ! 125: int event_code; ! 126: char msg[1]; /* actually, variable length */ ! 127: }; ! 128: ! 129: ! 130: ! 131: TAILQ_HEAD(ifnethead, ifnet); /* we use TAILQs so that the order of */ ! 132: TAILQ_HEAD(ifaddrhead, ifaddr); /* instantiation is preserved in the list */ ! 133: LIST_HEAD(ifmultihead, ifmultiaddr); ! 134: ! 135: ! 136: /* ! 137: * Structure describing information about an interface ! 138: * which may be of interest to management entities. ! 139: */ ! 140: struct if_data { ! 141: /* generic interface information */ ! 142: u_char ifi_type; /* ethernet, tokenring, etc */ ! 143: u_char ifi_typelen; /* Length of frame type id */ ! 144: u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */ ! 145: u_char ifi_addrlen; /* media address length */ ! 146: u_char ifi_hdrlen; /* media header length */ ! 147: u_char ifi_recvquota; /* polling quota for receive intrs */ ! 148: u_char ifi_xmitquota; /* polling quota for xmit intrs */ ! 149: u_long ifi_mtu; /* maximum transmission unit */ ! 150: u_long ifi_metric; /* routing metric (external only) */ ! 151: u_long ifi_baudrate; /* linespeed */ ! 152: /* volatile statistics */ ! 153: u_long ifi_ipackets; /* packets received on interface */ ! 154: u_long ifi_ierrors; /* input errors on interface */ ! 155: u_long ifi_opackets; /* packets sent on interface */ ! 156: u_long ifi_oerrors; /* output errors on interface */ ! 157: u_long ifi_collisions; /* collisions on csma interfaces */ ! 158: u_long ifi_ibytes; /* total number of octets received */ ! 159: u_long ifi_obytes; /* total number of octets sent */ ! 160: u_long ifi_imcasts; /* packets received via multicast */ ! 161: u_long ifi_omcasts; /* packets sent via multicast */ ! 162: u_long ifi_iqdrops; /* dropped on input, this interface */ ! 163: u_long ifi_noproto; /* destined for unsupported protocol */ ! 164: u_long ifi_recvtiming; /* usec spent receiving when timing */ ! 165: u_long ifi_xmittiming; /* usec spent xmitting when timing */ ! 166: struct timeval ifi_lastchange; /* time of last administrative change */ ! 167: u_long default_proto; /* Default dl_tag when none is specified ! 168: * on dlil_output ! 169: */ ! 170: }; ! 171: ! 172: ! 173: /* ! 174: * Structure defining a queue for a network interface. ! 175: */ ! 176: struct ifqueue { ! 177: struct mbuf *ifq_head; ! 178: struct mbuf *ifq_tail; ! 179: int ifq_len; ! 180: int ifq_maxlen; ! 181: int ifq_drops; ! 182: }; ! 183: ! 184: /* ! 185: * Structure defining a network interface. ! 186: * ! 187: * (Would like to call this struct ``if'', but C isn't PL/1.) ! 188: */ ! 189: struct ifnet { ! 190: void *if_softc; /* pointer to driver state */ ! 191: char *if_name; /* name, e.g. ``en'' or ``lo'' */ ! 192: TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ ! 193: struct ifaddrhead if_addrhead; /* linked list of addresses per if */ ! 194: struct tailq_head proto_head; /* Head for if_proto structures */ ! 195: int if_pcount; /* number of promiscuous listeners */ ! 196: struct bpf_if *if_bpf; /* packet filter structure */ ! 197: u_short if_index; /* numeric abbreviation for this if */ ! 198: short if_unit; /* sub-unit for lower level driver */ ! 199: short if_timer; /* time 'til if_watchdog called */ ! 200: short if_flags; /* up/down, broadcast, etc. */ ! 201: int if_ipending; /* interrupts pending */ ! 202: void *if_linkmib; /* link-type-specific MIB data */ ! 203: size_t if_linkmiblen; /* length of above data */ ! 204: struct if_data if_data; ! 205: ! 206: /* New with DLIL */ ! 207: int refcnt; ! 208: int offercnt; ! 209: int (*if_output)(struct ifnet *ifnet_ptr, struct mbuf *m); ! 210: int (*if_ioctl)(struct ifnet *ifnet_ptr, u_long ioctl_code, void *ioctl_arg); ! 211: int (*if_set_bpf_tap)(struct ifnet *ifp, int mode, ! 212: int (*bpf_callback)(struct ifnet *, struct mbuf *)); ! 213: int (*if_free)(struct ifnet *ifnet_ptr); ! 214: int (*if_demux)(struct ifnet *ifnet_ptr, struct mbuf *mbuf_ptr, ! 215: char *frame_ptr, void *if_proto_ptr); ! 216: ! 217: int (*if_event)(struct ifnet *ifnet_ptr, struct event_msg *event_msg_str); ! 218: ! 219: int (*if_framer)(struct ifnet *ifp, ! 220: struct mbuf **m, ! 221: struct sockaddr *dest, ! 222: char *dest_linkaddr, ! 223: char *frame_type); ! 224: ! 225: u_long if_family; /* ulong assigned by Apple */ ! 226: struct tailq_head if_flt_head; ! 227: ! 228: /* End DLIL specific */ ! 229: ! 230: /* #if defined(ppc) */ ! 231: void *if_Y; /* For Y-adapter connection */ ! 232: /* #endif */ ! 233: void *if_private; /* private to interface */ ! 234: /* procedure handles */ ! 235: #if __APPLE__ ! 236: long if_eflags; /* autoaddr, autoaddr done, etc. */ ! 237: #else ! 238: int (*if_done) /* output complete routine */ ! 239: __P((struct ifnet *)); /* (XXX not used; fake prototype) */ ! 240: #endif ! 241: ! 242: ! 243: struct ifmultihead if_multiaddrs; /* multicast addresses configured */ ! 244: int if_amcount; /* number of all-multicast requests */ ! 245: /* procedure handles */ ! 246: int (*if_poll_recv) /* polled receive routine */ ! 247: __P((struct ifnet *, int *)); ! 248: int (*if_poll_xmit) /* polled transmit routine */ ! 249: __P((struct ifnet *, int *)); ! 250: void (*if_poll_intren) /* polled interrupt reenable routine */ ! 251: __P((struct ifnet *)); ! 252: void (*if_poll_slowinput) /* input routine for slow devices */ ! 253: __P((struct ifnet *, struct mbuf *)); ! 254: void (*if_init) /* Init routine */ ! 255: __P((void *)); ! 256: int (*if_resolvemulti) /* validate/resolve multicast */ ! 257: __P((struct ifnet *, struct sockaddr **, struct sockaddr *)); ! 258: struct ifqueue if_snd; /* output queue */ ! 259: struct ifqueue *if_poll_slowq; /* input queue for slow devices */ ! 260: u_long family_cookie; ! 261: }; ! 262: typedef void if_init_f_t __P((void *)); ! 263: ! 264: #define if_mtu if_data.ifi_mtu ! 265: #define if_type if_data.ifi_type ! 266: #define if_typelen if_data.ifi_typelen ! 267: #define if_physical if_data.ifi_physical ! 268: #define if_addrlen if_data.ifi_addrlen ! 269: #define if_hdrlen if_data.ifi_hdrlen ! 270: #define if_metric if_data.ifi_metric ! 271: #define if_baudrate if_data.ifi_baudrate ! 272: #define if_ipackets if_data.ifi_ipackets ! 273: #define if_ierrors if_data.ifi_ierrors ! 274: #define if_opackets if_data.ifi_opackets ! 275: #define if_oerrors if_data.ifi_oerrors ! 276: #define if_collisions if_data.ifi_collisions ! 277: #define if_ibytes if_data.ifi_ibytes ! 278: #define if_obytes if_data.ifi_obytes ! 279: #define if_imcasts if_data.ifi_imcasts ! 280: #define if_omcasts if_data.ifi_omcasts ! 281: #define if_iqdrops if_data.ifi_iqdrops ! 282: #define if_noproto if_data.ifi_noproto ! 283: #define if_lastchange if_data.ifi_lastchange ! 284: #define if_recvquota if_data.ifi_recvquota ! 285: #define if_xmitquota if_data.ifi_xmitquota ! 286: #define if_rawoutput(if, m, sa) if_output(if, m, sa, (struct rtentry *)0) ! 287: ! 288: /* ! 289: * Bit values in if_ipending ! 290: */ ! 291: #define IFI_RECV 1 /* I want to receive */ ! 292: #define IFI_XMIT 2 /* I want to transmit */ ! 293: ! 294: /* ! 295: * Output queues (ifp->if_snd) and slow device input queues (*ifp->if_slowq) ! 296: * are queues of messages stored on ifqueue structures ! 297: * (defined above). Entries are added to and deleted from these structures ! 298: * by these macros, which should be called with ipl raised to splimp(). ! 299: */ ! 300: #define IF_QFULL(ifq) ((ifq)->ifq_len >= (ifq)->ifq_maxlen) ! 301: #define IF_DROP(ifq) ((ifq)->ifq_drops++) ! 302: #define IF_ENQUEUE(ifq, m) { \ ! 303: (m)->m_nextpkt = 0; \ ! 304: if ((ifq)->ifq_tail == 0) \ ! 305: (ifq)->ifq_head = m; \ ! 306: else \ ! 307: (ifq)->ifq_tail->m_nextpkt = m; \ ! 308: (ifq)->ifq_tail = m; \ ! 309: (ifq)->ifq_len++; \ ! 310: } ! 311: #define IF_PREPEND(ifq, m) { \ ! 312: (m)->m_nextpkt = (ifq)->ifq_head; \ ! 313: if ((ifq)->ifq_tail == 0) \ ! 314: (ifq)->ifq_tail = (m); \ ! 315: (ifq)->ifq_head = (m); \ ! 316: (ifq)->ifq_len++; \ ! 317: } ! 318: #define IF_DEQUEUE(ifq, m) { \ ! 319: (m) = (ifq)->ifq_head; \ ! 320: if (m) { \ ! 321: if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \ ! 322: (ifq)->ifq_tail = 0; \ ! 323: (m)->m_nextpkt = 0; \ ! 324: (ifq)->ifq_len--; \ ! 325: } \ ! 326: } ! 327: ! 328: #ifdef KERNEL ! 329: #define IF_ENQ_DROP(ifq, m) if_enq_drop(ifq, m) ! 330: ! 331: #if defined(__GNUC__) && defined(MT_HEADER) ! 332: static __inline int ! 333: if_queue_drop(struct ifqueue *ifq, struct mbuf *m) ! 334: { ! 335: IF_DROP(ifq); ! 336: return 0; ! 337: } ! 338: ! 339: static __inline int ! 340: if_enq_drop(struct ifqueue *ifq, struct mbuf *m) ! 341: { ! 342: if (IF_QFULL(ifq) && ! 343: !if_queue_drop(ifq, m)) ! 344: return 0; ! 345: IF_ENQUEUE(ifq, m); ! 346: return 1; ! 347: } ! 348: #else ! 349: ! 350: #ifdef MT_HEADER ! 351: int if_enq_drop __P((struct ifqueue *, struct mbuf *)); ! 352: #endif ! 353: ! 354: #endif ! 355: #endif /* KERNEL */ ! 356: ! 357: /* ! 358: * The ifaddr structure contains information about one address ! 359: * of an interface. They are maintained by the different address families, ! 360: * are allocated and attached when an address is set, and are linked ! 361: * together so all addresses for an interface can be located. ! 362: */ ! 363: struct ifaddr { ! 364: struct sockaddr *ifa_addr; /* address of interface */ ! 365: struct sockaddr *ifa_dstaddr; /* other end of p-to-p link */ ! 366: #define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ ! 367: struct sockaddr *ifa_netmask; /* used to determine subnet */ ! 368: struct ifnet *ifa_ifp; /* back-pointer to interface */ ! 369: TAILQ_ENTRY(ifaddr) ifa_link; /* queue macro glue */ ! 370: void (*ifa_rtrequest) /* check or clean routes (+ or -)'d */ ! 371: __P((int, struct rtentry *, struct sockaddr *)); ! 372: u_short ifa_flags; /* mostly rt_flags for cloning */ ! 373: short ifa_refcnt; /* references to this structure */ ! 374: int ifa_metric; /* cost of going out this interface */ ! 375: #ifdef notdef ! 376: struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */ ! 377: #endif ! 378: u_long ifa_dlt; ! 379: int (*ifa_claim_addr) /* check if an addr goes to this if */ ! 380: __P((struct ifaddr *, struct sockaddr *)); ! 381: ! 382: }; ! 383: #define IFA_ROUTE RTF_UP /* route installed */ ! 384: ! 385: /* ! 386: * Multicast address structure. This is analogous to the ifaddr ! 387: * structure except that it keeps track of multicast addresses. ! 388: * Also, the reference count here is a count of requests for this ! 389: * address, not a count of pointers to this structure. ! 390: */ ! 391: struct ifmultiaddr { ! 392: LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ ! 393: struct sockaddr *ifma_addr; /* address this membership is for */ ! 394: struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ ! 395: struct ifnet *ifma_ifp; /* back-pointer to interface */ ! 396: u_int ifma_refcount; /* reference count */ ! 397: void *ifma_protospec; /* protocol-specific state, if any */ ! 398: }; ! 399: ! 400: #if KERNEL ! 401: #define IFAFREE(ifa) \ ! 402: if ((ifa)->ifa_refcnt <= 0) \ ! 403: ifafree(ifa); \ ! 404: else \ ! 405: (ifa)->ifa_refcnt--; ! 406: ! 407: extern struct ifnethead ifnet; ! 408: extern int ifqmaxlen; ! 409: extern struct ifnet loif[]; ! 410: extern int if_index; ! 411: extern struct ifaddr **ifnet_addrs; ! 412: ! 413: int if_addmulti __P((struct ifnet *, struct sockaddr *, ! 414: struct ifmultiaddr **)); ! 415: int if_allmulti __P((struct ifnet *, int)); ! 416: void if_attach __P((struct ifnet *)); ! 417: int if_delmulti __P((struct ifnet *, struct sockaddr *)); ! 418: void if_down __P((struct ifnet *)); ! 419: void if_route __P((struct ifnet *, int flag, int fam)); ! 420: void if_unroute __P((struct ifnet *, int flag, int fam)); ! 421: void if_up __P((struct ifnet *)); ! 422: /*void ifinit __P((void));*/ /* declared in systm.h for main() */ ! 423: int ifioctl __P((struct socket *, u_long, caddr_t, struct proc *)); ! 424: int ifpromisc __P((struct ifnet *, int)); ! 425: struct ifnet *ifunit __P((char *)); ! 426: ! 427: int if_poll_recv_slow __P((struct ifnet *ifp, int *quotap)); ! 428: void if_poll_xmit_slow __P((struct ifnet *ifp, int *quotap)); ! 429: void if_poll_throttle __P((void)); ! 430: void if_poll_unthrottle __P((void *)); ! 431: void if_poll_init __P((void)); ! 432: void if_poll __P((void)); ! 433: ! 434: struct ifaddr *ifa_ifwithaddr __P((struct sockaddr *)); ! 435: struct ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *)); ! 436: struct ifaddr *ifa_ifwithnet __P((struct sockaddr *)); ! 437: struct ifaddr *ifa_ifwithroute __P((int, struct sockaddr *, ! 438: struct sockaddr *)); ! 439: struct ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *)); ! 440: void ifafree __P((struct ifaddr *)); ! 441: ! 442: struct ifmultiaddr *ifmaof_ifpforaddr __P((struct sockaddr *, ! 443: struct ifnet *)); ! 444: int if_simloop __P((struct ifnet *ifp, struct mbuf *m, ! 445: struct sockaddr *dst, int hlen)); ! 446: ! 447: #endif /* KERNEL */ ! 448: ! 449: ! 450: #endif /* !_NET_IF_VAR_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.