Annotation of 43BSD/sys/net/if.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986 Regents of the University of California.
                      3:  * All rights reserved.  The Berkeley software License Agreement
                      4:  * specifies the terms and conditions for redistribution.
                      5:  *
                      6:  *     @(#)if.h        7.1 (Berkeley) 6/4/86
                      7:  */
                      8: 
                      9: /*
                     10:  * Structures defining a network interface, providing a packet
                     11:  * transport mechanism (ala level 0 of the PUP protocols).
                     12:  *
                     13:  * Each interface accepts output datagrams of a specified maximum
                     14:  * length, and provides higher level routines with input datagrams
                     15:  * received from its medium.
                     16:  *
                     17:  * Output occurs when the routine if_output is called, with three parameters:
                     18:  *     (*ifp->if_output)(ifp, m, dst)
                     19:  * Here m is the mbuf chain to be sent and dst is the destination address.
                     20:  * The output routine encapsulates the supplied datagram if necessary,
                     21:  * and then transmits it on its medium.
                     22:  *
                     23:  * On input, each interface unwraps the data received by it, and either
                     24:  * places it on the input queue of a internetwork datagram routine
                     25:  * and posts the associated software interrupt, or passes the datagram to a raw
                     26:  * packet input routine.
                     27:  *
                     28:  * Routines exist for locating interfaces by their addresses
                     29:  * or for locating a interface on a certain network, as well as more general
                     30:  * routing and gateway routines maintaining information used to locate
                     31:  * interfaces.  These routines live in the files if.c and route.c
                     32:  */
                     33: 
                     34: /*
                     35:  * Structure defining a queue for a network interface.
                     36:  *
                     37:  * (Would like to call this struct ``if'', but C isn't PL/1.)
                     38:  */
                     39: struct ifnet {
                     40:        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
                     41:        short   if_unit;                /* sub-unit for lower level driver */
                     42:        short   if_mtu;                 /* maximum transmission unit */
                     43:        short   if_flags;               /* up/down, broadcast, etc. */
                     44:        short   if_timer;               /* time 'til if_watchdog called */
                     45:        int     if_metric;              /* routing metric (external only) */
                     46:        struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
                     47:        struct  ifqueue {
                     48:                struct  mbuf *ifq_head;
                     49:                struct  mbuf *ifq_tail;
                     50:                int     ifq_len;
                     51:                int     ifq_maxlen;
                     52:                int     ifq_drops;
                     53:        } if_snd;                       /* output queue */
                     54: /* procedure handles */
                     55:        int     (*if_init)();           /* init routine */
                     56:        int     (*if_output)();         /* output routine */
                     57:        int     (*if_ioctl)();          /* ioctl routine */
                     58:        int     (*if_reset)();          /* bus reset routine */
                     59:        int     (*if_watchdog)();       /* timer routine */
                     60: /* generic interface statistics */
                     61:        int     if_ipackets;            /* packets received on interface */
                     62:        int     if_ierrors;             /* input errors on interface */
                     63:        int     if_opackets;            /* packets sent on interface */
                     64:        int     if_oerrors;             /* output errors on interface */
                     65:        int     if_collisions;          /* collisions on csma interfaces */
                     66: /* end statistics */
                     67:        struct  ifnet *if_next;
                     68: };
                     69: 
                     70: #define        IFF_UP          0x1             /* interface is up */
                     71: #define        IFF_BROADCAST   0x2             /* broadcast address valid */
                     72: #define        IFF_DEBUG       0x4             /* turn on debugging */
                     73: #define        IFF_LOOPBACK    0x8             /* is a loopback net */
                     74: #define        IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
                     75: #define        IFF_NOTRAILERS  0x20            /* avoid use of trailers */
                     76: #define        IFF_RUNNING     0x40            /* resources allocated */
                     77: #define        IFF_NOARP       0x80            /* no address resolution protocol */
                     78: /* next two not supported now, but reserved: */
                     79: #define        IFF_PROMISC     0x100           /* receive all packets */
                     80: #define        IFF_ALLMULTI    0x200           /* receive all multicast packets */
                     81: /* flags set internally only: */
                     82: #define        IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
                     83: 
                     84: /*
                     85:  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
                     86:  * input routines have queues of messages stored on ifqueue structures
                     87:  * (defined above).  Entries are added to and deleted from these structures
                     88:  * by these macros, which should be called with ipl raised to splimp().
                     89:  */
                     90: #define        IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
                     91: #define        IF_DROP(ifq)            ((ifq)->ifq_drops++)
                     92: #define        IF_ENQUEUE(ifq, m) { \
                     93:        (m)->m_act = 0; \
                     94:        if ((ifq)->ifq_tail == 0) \
                     95:                (ifq)->ifq_head = m; \
                     96:        else \
                     97:                (ifq)->ifq_tail->m_act = m; \
                     98:        (ifq)->ifq_tail = m; \
                     99:        (ifq)->ifq_len++; \
                    100: }
                    101: #define        IF_PREPEND(ifq, m) { \
                    102:        (m)->m_act = (ifq)->ifq_head; \
                    103:        if ((ifq)->ifq_tail == 0) \
                    104:                (ifq)->ifq_tail = (m); \
                    105:        (ifq)->ifq_head = (m); \
                    106:        (ifq)->ifq_len++; \
                    107: }
                    108: /*
                    109:  * Packets destined for level-1 protocol input routines
                    110:  * have a pointer to the receiving interface prepended to the data.
                    111:  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
                    112:  * IF_ADJ should be used otherwise to adjust for its presence.
                    113:  */
                    114: #define        IF_ADJ(m) { \
                    115:        (m)->m_off += sizeof(struct ifnet *); \
                    116:        (m)->m_len -= sizeof(struct ifnet *); \
                    117:        if ((m)->m_len == 0) { \
                    118:                struct mbuf *n; \
                    119:                MFREE((m), n); \
                    120:                (m) = n; \
                    121:        } \
                    122: }
                    123: #define        IF_DEQUEUEIF(ifq, m, ifp) { \
                    124:        (m) = (ifq)->ifq_head; \
                    125:        if (m) { \
                    126:                if (((ifq)->ifq_head = (m)->m_act) == 0) \
                    127:                        (ifq)->ifq_tail = 0; \
                    128:                (m)->m_act = 0; \
                    129:                (ifq)->ifq_len--; \
                    130:                (ifp) = *(mtod((m), struct ifnet **)); \
                    131:                IF_ADJ(m); \
                    132:        } \
                    133: }
                    134: #define        IF_DEQUEUE(ifq, m) { \
                    135:        (m) = (ifq)->ifq_head; \
                    136:        if (m) { \
                    137:                if (((ifq)->ifq_head = (m)->m_act) == 0) \
                    138:                        (ifq)->ifq_tail = 0; \
                    139:                (m)->m_act = 0; \
                    140:                (ifq)->ifq_len--; \
                    141:        } \
                    142: }
                    143: 
                    144: #define        IFQ_MAXLEN      50
                    145: #define        IFNET_SLOWHZ    1               /* granularity is 1 second */
                    146: 
                    147: /*
                    148:  * The ifaddr structure contains information about one address
                    149:  * of an interface.  They are maintained by the different address families,
                    150:  * are allocated and attached when an address is set, and are linked
                    151:  * together so all addresses for an interface can be located.
                    152:  */
                    153: struct ifaddr {
                    154:        struct  sockaddr ifa_addr;      /* address of interface */
                    155:        union {
                    156:                struct  sockaddr ifu_broadaddr;
                    157:                struct  sockaddr ifu_dstaddr;
                    158:        } ifa_ifu;
                    159: #define        ifa_broadaddr   ifa_ifu.ifu_broadaddr   /* broadcast address */
                    160: #define        ifa_dstaddr     ifa_ifu.ifu_dstaddr     /* other end of p-to-p link */
                    161:        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
                    162:        struct  ifaddr *ifa_next;       /* next address for interface */
                    163: };
                    164: 
                    165: /*
                    166:  * Interface request structure used for socket
                    167:  * ioctl's.  All interface ioctl's must have parameter
                    168:  * definitions which begin with ifr_name.  The
                    169:  * remainder may be interface specific.
                    170:  */
                    171: struct ifreq {
                    172: #define        IFNAMSIZ        16
                    173:        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
                    174:        union {
                    175:                struct  sockaddr ifru_addr;
                    176:                struct  sockaddr ifru_dstaddr;
                    177:                struct  sockaddr ifru_broadaddr;
                    178:                short   ifru_flags;
                    179:                int     ifru_metric;
                    180:                caddr_t ifru_data;
                    181:        } ifr_ifru;
                    182: #define        ifr_addr        ifr_ifru.ifru_addr      /* address */
                    183: #define        ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
                    184: #define        ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
                    185: #define        ifr_flags       ifr_ifru.ifru_flags     /* flags */
                    186: #define        ifr_metric      ifr_ifru.ifru_metric    /* metric */
                    187: #define        ifr_data        ifr_ifru.ifru_data      /* for use by interface */
                    188: };
                    189: 
                    190: /*
                    191:  * Structure used in SIOCGIFCONF request.
                    192:  * Used to retrieve interface configuration
                    193:  * for machine (useful for programs which
                    194:  * must know all networks accessible).
                    195:  */
                    196: struct ifconf {
                    197:        int     ifc_len;                /* size of associated buffer */
                    198:        union {
                    199:                caddr_t ifcu_buf;
                    200:                struct  ifreq *ifcu_req;
                    201:        } ifc_ifcu;
                    202: #define        ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
                    203: #define        ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
                    204: };
                    205: 
                    206: #ifdef KERNEL
                    207: #include "../net/if_arp.h"
                    208: struct ifqueue rawintrq;               /* raw packet input queue */
                    209: struct ifnet *ifnet;
                    210: struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
                    211: struct ifaddr *ifa_ifwithdstaddr();
                    212: #else KERNEL
                    213: #include <net/if_arp.h>
                    214: #endif KERNEL

unix.superglobalmegacorp.com

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