Annotation of kernel/bsd/net/if.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
                      7:  * Reserved.  This file contains Original Code and/or Modifications of
                      8:  * Original Code as defined in and that are subject to the Apple Public
                      9:  * Source License Version 1.1 (the "License").  You may not use this file
                     10:  * except in compliance with the License.  Please obtain a copy of the
                     11:  * License at http://www.apple.com/publicsource and read it before using
                     12:  * this file.
                     13:  * 
                     14:  * The Original Code and all software distributed under the License are
                     15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     19:  * License for the specific language governing rights and limitations
                     20:  * under the License.
                     21:  * 
                     22:  * @APPLE_LICENSE_HEADER_END@
                     23:  */
                     24: 
                     25: /* Copyright (c) 1997, 1998 Apple Computer, Inc. All Rights Reserved */
                     26: /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
                     27: /*
                     28:  * Copyright (c) 1982, 1986, 1989, 1993
                     29:  *     The Regents of the University of California.  All rights reserved.
                     30:  *
                     31:  * Redistribution and use in source and binary forms, with or without
                     32:  * modification, are permitted provided that the following conditions
                     33:  * are met:
                     34:  * 1. Redistributions of source code must retain the above copyright
                     35:  *    notice, this list of conditions and the following disclaimer.
                     36:  * 2. Redistributions in binary form must reproduce the above copyright
                     37:  *    notice, this list of conditions and the following disclaimer in the
                     38:  *    documentation and/or other materials provided with the distribution.
                     39:  * 3. All advertising materials mentioning features or use of this software
                     40:  *    must display the following acknowledgement:
                     41:  *     This product includes software developed by the University of
                     42:  *     California, Berkeley and its contributors.
                     43:  * 4. Neither the name of the University nor the names of its contributors
                     44:  *    may be used to endorse or promote products derived from this software
                     45:  *    without specific prior written permission.
                     46:  *
                     47:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     48:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     49:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     50:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     51:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     52:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     53:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     54:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     55:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     56:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     57:  * SUCH DAMAGE.
                     58:  *
                     59:  *     @(#)if.h        8.3 (Berkeley) 2/9/95
                     60:  */
                     61: 
                     62: /*
                     63:  * Structures defining a network interface, providing a packet
                     64:  * transport mechanism (ala level 0 of the PUP protocols).
                     65:  *
                     66:  * Each interface accepts output datagrams of a specified maximum
                     67:  * length, and provides higher level routines with input datagrams
                     68:  * received from its medium.
                     69:  *
                     70:  * Output occurs when the routine if_output is called, with four parameters:
                     71:  *     (*ifp->if_output)(ifp, m, dst, rt)
                     72:  * Here m is the mbuf chain to be sent and dst is the destination address.
                     73:  * The output routine encapsulates the supplied datagram if necessary,
                     74:  * and then transmits it on its medium.
                     75:  *
                     76:  * On input, each interface unwraps the data received by it, and either
                     77:  * places it on the input queue of a internetwork datagram routine
                     78:  * and posts the associated software interrupt, or passes the datagram to a raw
                     79:  * packet input routine.
                     80:  *
                     81:  * Routines exist for locating interfaces by their addresses
                     82:  * or for locating a interface on a certain network, as well as more general
                     83:  * routing and gateway routines maintaining information used to locate
                     84:  * interfaces.  These routines live in the files if.c and route.c
                     85:  */
                     86: /*  XXX fast fix for SNMP, going away soon */
                     87: #ifndef _NET_IF_H
                     88: #define _NET_IF_H
                     89: #include <sys/time.h>
                     90: 
                     91: #ifdef __STDC__
                     92: /*
                     93:  * Forward structure declarations for function prototypes [sic].
                     94:  */
                     95: struct mbuf;
                     96: struct proc;
                     97: struct rtentry;        
                     98: struct socket;
                     99: struct ether_header;
                    100: #endif
                    101: 
                    102: /*
                    103:  * Structure defining statistics and other data kept regarding a network
                    104:  * a network interface.
                    105:  */
                    106: 
                    107: struct if_data {
                    108: /* generic interface information */
                    109:                u_char  ifi_type;       /* ethernet, tokenring, etc */
                    110:                u_char  ifi_addrlen;    /* media address length */
                    111:                u_char  ifi_hdrlen;     /* media header length */
                    112:                u_long  ifi_mtu;        /* maximum transmission unit */
                    113:                u_long  ifi_metric;     /* routing metric (external only) */
                    114:                u_long  ifi_baudrate;   /* linespeed */
                    115: /* volatile statistics */
                    116:                u_long  ifi_ipackets;   /* packets received on interface */
                    117:                u_long  ifi_ierrors;    /* input errors on interface */
                    118:                u_long  ifi_opackets;   /* packets sent on interface */
                    119:                u_long  ifi_oerrors;    /* output errors on interface */
                    120:                u_long  ifi_collisions; /* collisions on csma interfaces */
                    121:                u_long  ifi_ibytes;     /* total number of octets received */
                    122:                u_long  ifi_obytes;     /* total number of octets sent */
                    123:                u_long  ifi_imcasts;    /* packets received via multicast */
                    124:                u_long  ifi_omcasts;    /* packets sent via multicast */
                    125:                u_long  ifi_iqdrops;    /* dropped on input, this interface */
                    126:                u_long  ifi_noproto;    /* destined for unsupported protocol */
                    127:                struct  timeval ifi_lastchange;/* last updated */
                    128: };
                    129: 
                    130: /*
                    131:  * Structure describing information about an interface
                    132:  * which may be of interest to management entities.
                    133:  */
                    134: /*
                    135:  * Structure defining a queue for a network interface.
                    136:  *
                    137:  * (Would like to call this struct ``if'', but C isn't PL/1.)
                    138:  */
                    139: 
                    140: struct ifnet {
                    141:        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
                    142:        struct  ifnet *if_next;         /* all struct ifnets are chained */
                    143:        struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
                    144:        int     if_pcount;              /* number of promiscuous listeners */
                    145:        caddr_t if_bpf;                 /* packet filter structure */
                    146:        u_short if_index;               /* numeric abbreviation for this if */
                    147:        short   if_unit;                /* sub-unit for lower level driver */
                    148:        short   if_timer;               /* time 'til if_watchdog called */
                    149:        short   if_flags;               /* up/down, broadcast, etc. */
                    150:        struct if_data  if_data;
                    151: #if defined(ppc)
                    152:        void    *if_Y;                  /* For Y-adapter connection */
                    153: #endif /* ppc */
                    154:        void    *if_private;            /* private to interface */
                    155: /* procedure handles */
                    156:        int     (*if_init)              /* init routine */
                    157:                __P((int));
                    158:        int     (*if_output)            /* output routine (enqueue) */
                    159:                __P((struct ifnet *, struct mbuf *, struct sockaddr *,
                    160:                     struct rtentry *));
                    161:        int     (*if_start)             /* initiate output routine */
                    162:                __P((struct ifnet *));
                    163: #if    __APPLE__
                    164:        long    if_eflags;              /* autoaddr, autoaddr done, etc. */
                    165: #else
                    166:        int     (*if_done)              /* output complete routine */
                    167:                __P((struct ifnet *));  /* (XXX not used; fake prototype) */
                    168: #endif
                    169:        int     (*if_ioctl)             /* ioctl routine */
                    170:                __P((struct ifnet *, u_long, caddr_t));
                    171:        int     (*if_reset)     
                    172:                __P((int));             /* new autoconfig will permit removal */
                    173:        int     (*if_watchdog)          /* timer routine */
                    174:                __P((int));
                    175:        struct  ifqueue {
                    176:                struct  mbuf *ifq_head;
                    177:                struct  mbuf *ifq_tail;
                    178:                int     ifq_len;
                    179:                int     ifq_maxlen;
                    180:                int     ifq_drops;
                    181:        } if_snd;                       /* output queue */
                    182: };
                    183: #define        if_mtu          if_data.ifi_mtu
                    184: #define        if_type         if_data.ifi_type
                    185: #define        if_addrlen      if_data.ifi_addrlen
                    186: #define        if_hdrlen       if_data.ifi_hdrlen
                    187: #define        if_metric       if_data.ifi_metric
                    188: #define        if_baudrate     if_data.ifi_baudrate
                    189: #define        if_ipackets     if_data.ifi_ipackets
                    190: #define        if_ierrors      if_data.ifi_ierrors
                    191: #define        if_opackets     if_data.ifi_opackets
                    192: #define        if_oerrors      if_data.ifi_oerrors
                    193: #define        if_collisions   if_data.ifi_collisions
                    194: #define        if_ibytes       if_data.ifi_ibytes
                    195: #define        if_obytes       if_data.ifi_obytes
                    196: #define        if_imcasts      if_data.ifi_imcasts
                    197: #define        if_omcasts      if_data.ifi_omcasts
                    198: #define        if_iqdrops      if_data.ifi_iqdrops
                    199: #define        if_noproto      if_data.ifi_noproto
                    200: #define        if_lastchange   if_data.ifi_lastchange
                    201: 
                    202: #define        IFF_UP          0x1             /* interface is up */
                    203: #define        IFF_BROADCAST   0x2             /* broadcast address valid */
                    204: #define        IFF_DEBUG       0x4             /* turn on debugging */
                    205: #define        IFF_LOOPBACK    0x8             /* is a loopback net */
                    206: #define        IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
                    207: #define        IFF_NOTRAILERS  0x20            /* avoid use of trailers */
                    208: #define        IFF_RUNNING     0x40            /* resources allocated */
                    209: #define        IFF_NOARP       0x80            /* no address resolution protocol */
                    210: #define        IFF_PROMISC     0x100           /* receive all packets */
                    211: #define        IFF_ALLMULTI    0x200           /* receive all multicast packets */
                    212: #define        IFF_OACTIVE     0x400           /* transmission in progress */
                    213: #define        IFF_SIMPLEX     0x800           /* can't hear own transmissions */
                    214: #define        IFF_LINK0       0x1000          /* per link layer defined bit */
                    215: #define        IFF_LINK1       0x2000          /* per link layer defined bit */
                    216: #define        IFF_LINK2       0x4000          /* per link layer defined bit */
                    217: #if defined(ppc)
                    218: #define IFF_SPLITTER   IFF_LINK2       /* Y splitter in force */
                    219: #endif /* ppc */
                    220: 
                    221: #define        IFF_MULTICAST   0x8000          /* supports multicast */
                    222: 
                    223: 
                    224: #define        IFEF_AUTOCONF           0x1     /* auto-configuring the interface */
                    225: #define        IFEF_AUTOCONF_DONE      0x2     /* interface has been auto-configured */
                    226: #define        IFEF_NETMASK_AUTH       0x4     /* authoritative ICMP netmask server */
                    227: #define IFEF_AWAITING_NETMASK  0x8     /* ready to accept netmask reply */
                    228: #define IFEF_NEEDMASK          0x10    /* Still need a subnet mask - not used yet */
                    229: #define IFEF_DVR_REENTRY_OK    0x20    /* When set, driver may be reentered from its own thread */
                    230: 
                    231: 
                    232: /* flags set internally only: */
                    233: #define        IFF_CANTCHANGE \
                    234:        (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
                    235:            IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
                    236: 
                    237: /*
                    238:  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
                    239:  * input routines have queues of messages stored on ifqueue structures
                    240:  * (defined above).  Entries are added to and deleted from these structures
                    241:  * by these macros, which should be called with ipl raised to splimp().
                    242:  */
                    243: #define        IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
                    244: #define        IF_DROP(ifq)            ((ifq)->ifq_drops++)
                    245: #define        IF_ENQUEUE(ifq, m) { \
                    246:        (m)->m_nextpkt = 0; \
                    247:        if ((ifq)->ifq_tail == 0) \
                    248:                (ifq)->ifq_head = m; \
                    249:        else \
                    250:                (ifq)->ifq_tail->m_nextpkt = m; \
                    251:        (ifq)->ifq_tail = m; \
                    252:        (ifq)->ifq_len++; \
                    253: }
                    254: #define        IF_PREPEND(ifq, m) { \
                    255:        (m)->m_nextpkt = (ifq)->ifq_head; \
                    256:        if ((ifq)->ifq_tail == 0) \
                    257:                (ifq)->ifq_tail = (m); \
                    258:        (ifq)->ifq_head = (m); \
                    259:        (ifq)->ifq_len++; \
                    260: }
                    261: #define        IF_DEQUEUE(ifq, m) { \
                    262:        (m) = (ifq)->ifq_head; \
                    263:        if (m) { \
                    264:                if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
                    265:                        (ifq)->ifq_tail = 0; \
                    266:                (m)->m_nextpkt = 0; \
                    267:                (ifq)->ifq_len--; \
                    268:        } \
                    269: }
                    270: 
                    271: #define        IFQ_MAXLEN      50
                    272: #define        IFNET_SLOWHZ    1               /* granularity is 1 second */
                    273: 
                    274: /*
                    275:  * The ifaddr structure contains information about one address
                    276:  * of an interface.  They are maintained by the different address families,
                    277:  * are allocated and attached when an address is set, and are linked
                    278:  * together so all addresses for an interface can be located.
                    279:  */
                    280: struct ifaddr {
                    281:        struct  sockaddr *ifa_addr;     /* address of interface */
                    282:        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
                    283: #define        ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
                    284:        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
                    285:        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
                    286:        struct  ifaddr *ifa_next;       /* next address for interface */
                    287:        void    (*ifa_rtrequest)();     /* check or clean routes (+ or -)'d */
                    288:        u_short ifa_flags;              /* mostly rt_flags for cloning */
                    289:        short   ifa_refcnt;             /* extra to malloc for link info */
                    290:        int     ifa_metric;             /* cost of going out this interface */
                    291: #ifdef notdef
                    292:        struct  rtentry *ifa_rt;        /* XXXX for ROUTETOIF ????? */
                    293: #endif
                    294: };
                    295: #define        IFA_ROUTE       RTF_UP          /* route installed */
                    296: 
                    297: /*
                    298:  * Message format for use in obtaining information about interfaces
                    299:  * from getkerninfo and the routing socket
                    300:  */
                    301: struct if_msghdr {
                    302:        u_short ifm_msglen;     /* to skip over non-understood messages */
                    303:        u_char  ifm_version;    /* future binary compatability */
                    304:        u_char  ifm_type;       /* message type */
                    305:        int     ifm_addrs;      /* like rtm_addrs */
                    306:        int     ifm_flags;      /* value of if_flags */
                    307:        u_short ifm_index;      /* index for associated ifp */
                    308:        struct  if_data ifm_data;/* statistics and other data about if */
                    309: };
                    310: 
                    311: /*
                    312:  * Message format for use in obtaining information about interface addresses
                    313:  * from getkerninfo and the routing socket
                    314:  */
                    315: struct ifa_msghdr {
                    316:        u_short ifam_msglen;    /* to skip over non-understood messages */
                    317:        u_char  ifam_version;   /* future binary compatability */
                    318:        u_char  ifam_type;      /* message type */
                    319:        int     ifam_addrs;     /* like rtm_addrs */
                    320:        int     ifam_flags;     /* value of ifa_flags */
                    321:        u_short ifam_index;     /* index for associated ifp */
                    322:        int     ifam_metric;    /* value of ifa_metric */
                    323: };
                    324: 
                    325: /*
                    326:  * Interface request structure used for socket
                    327:  * ioctl's.  All interface ioctl's must have parameter
                    328:  * definitions which begin with ifr_name.  The
                    329:  * remainder may be interface specific.
                    330:  */
                    331: struct ifreq {
                    332: #define        IFNAMSIZ        16
                    333:        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
                    334:        union {
                    335:                struct  sockaddr ifru_addr;
                    336:                struct  sockaddr ifru_dstaddr;
                    337:                struct  sockaddr ifru_broadaddr;
                    338:                short   ifru_flags;
                    339:                int     ifru_metric;
                    340:                int     ifru_mtu;
                    341:                int     ifru_phys;
                    342:                int     ifru_media;
                    343:                caddr_t ifru_data;
                    344:        } ifr_ifru;
                    345: #define        ifr_addr        ifr_ifru.ifru_addr      /* address */
                    346: #define        ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
                    347: #define        ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
                    348: #define        ifr_flags       ifr_ifru.ifru_flags     /* flags */
                    349: #define        ifr_metric      ifr_ifru.ifru_metric    /* metric */
                    350: #define        ifr_mtu         ifr_ifru.ifru_mtu       /* mtu */
                    351: #define ifr_phys       ifr_ifru.ifru_phys      /* physical wire */
                    352: #define ifr_media      ifr_ifru.ifru_media     /* physical media */
                    353: #define        ifr_data        ifr_ifru.ifru_data      /* for use by interface */
                    354: };
                    355: 
                    356: struct ifaliasreq {
                    357:        char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
                    358:        struct  sockaddr ifra_addr;
                    359:        struct  sockaddr ifra_broadaddr;
                    360:        struct  sockaddr ifra_mask;
                    361: };
                    362: 
                    363: struct ifmediareq {
                    364:        char    ifm_name[IFNAMSIZ];     /* if name, e.g. "en0" */
                    365:        int     ifm_current;            /* current media options */
                    366:        int     ifm_mask;               /* don't care mask */
                    367:        int     ifm_status;             /* media status */
                    368:        int     ifm_active;             /* active options */
                    369:        int     ifm_count;              /* # entries in ifm_ulist array */
                    370:        int     *ifm_ulist;             /* media words */
                    371: };
                    372: 
                    373: /*
                    374:  * Structure used in SIOCGIFCONF request.
                    375:  * Used to retrieve interface configuration
                    376:  * for machine (useful for programs which
                    377:  * must know all networks accessible).
                    378:  */
                    379: struct ifconf {
                    380:        int     ifc_len;                /* size of associated buffer */
                    381:        union {
                    382:                caddr_t ifcu_buf;
                    383:                struct  ifreq *ifcu_req;
                    384:        } ifc_ifcu;
                    385: #define        ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
                    386: #define        ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
                    387: };
                    388: 
                    389: #include <net/if_arp.h>
                    390: 
                    391: #ifdef _KERNEL
                    392: #define        IFAFREE(ifa) \
                    393:        if ((ifa)->ifa_refcnt <= 0) \
                    394:                ifafree(ifa); \
                    395:        else \
                    396:                (ifa)->ifa_refcnt--;
                    397: 
                    398: extern struct  ifnet   *ifnet;
                    399: 
                    400: void   ether_ifattach __P((struct ifnet *));
                    401: void   ether_input __P((struct ifnet *, struct ether_header *, struct mbuf *));
                    402: int    ether_output __P((struct ifnet *,
                    403:           struct mbuf *, struct sockaddr *, struct rtentry *));
                    404: char   *ether_sprintf __P((u_char *));
                    405: 
                    406: void   if_attach __P((struct ifnet *));
                    407: void   if_down __P((struct ifnet *));
                    408: void   if_qflush __P((struct ifqueue *));
                    409: void   if_slowtimo __P((void *));
                    410: void   if_up __P((struct ifnet *));
                    411: int    ifconf __P((u_long, caddr_t));
                    412: void   ifinit __P((void));
                    413: int    ifioctl __P((struct socket *, u_long, caddr_t, struct proc *));
                    414: int    ifpromisc __P((struct ifnet *, int));
                    415: struct ifnet *ifunit __P((char *));
                    416: 
                    417: struct ifaddr *ifa_ifwithaddr __P((struct sockaddr *));
                    418: struct ifaddr *ifa_ifwithaf __P((int));
                    419: struct ifaddr *ifa_ifwithdstaddr __P((struct sockaddr *));
                    420: struct ifaddr *ifa_ifwithnet __P((struct sockaddr *));
                    421: struct ifaddr *ifa_ifwithroute __P((int, struct sockaddr *,
                    422:                                        struct sockaddr *));
                    423: struct ifaddr *ifaof_ifpforaddr __P((struct sockaddr *, struct ifnet *));
                    424: void   ifafree __P((struct ifaddr *));
                    425: void   link_rtrequest __P((int, struct rtentry *, struct sockaddr *));
                    426: 
                    427: int    loioctl __P((struct ifnet *, u_long, caddr_t));
                    428: void   loopattach __P((int));
                    429: int    looutput __P((struct ifnet *,
                    430:           struct mbuf *, struct sockaddr *, struct rtentry *));
                    431: void   lortrequest __P((int, struct rtentry *, struct sockaddr *));
                    432: #endif /* _KERNEL */
                    433: #endif /* _NET_IF_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.