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

1.1       root        1: /*
                      2:  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution is only permitted until one year after the first shipment
                      6:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
                      7:  * binary forms are permitted provided that: (1) source distributions retain
                      8:  * this entire copyright notice and comment, and (2) distributions including
                      9:  * binaries display the following acknowledgement:  This product includes
                     10:  * software developed by the University of California, Berkeley and its
                     11:  * contributors'' in the documentation or other materials provided with the
                     12:  * distribution and in all advertising materials mentioning features or use
                     13:  * of this software.  Neither the name of the University nor the names of
                     14:  * its contributors may be used to endorse or promote products derived from
                     15:  * this software without specific prior written permission.
                     16:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     17:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     18:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     19:  *
                     20:  *     @(#)if.h        7.9 (Berkeley) 6/28/90
                     21:  */
                     22: 
                     23: /*
                     24:  * Structures defining a network interface, providing a packet
                     25:  * transport mechanism (ala level 0 of the PUP protocols).
                     26:  *
                     27:  * Each interface accepts output datagrams of a specified maximum
                     28:  * length, and provides higher level routines with input datagrams
                     29:  * received from its medium.
                     30:  *
                     31:  * Output occurs when the routine if_output is called, with three parameters:
                     32:  *     (*ifp->if_output)(ifp, m, dst)
                     33:  * Here m is the mbuf chain to be sent and dst is the destination address.
                     34:  * The output routine encapsulates the supplied datagram if necessary,
                     35:  * and then transmits it on its medium.
                     36:  *
                     37:  * On input, each interface unwraps the data received by it, and either
                     38:  * places it on the input queue of a internetwork datagram routine
                     39:  * and posts the associated software interrupt, or passes the datagram to a raw
                     40:  * packet input routine.
                     41:  *
                     42:  * Routines exist for locating interfaces by their addresses
                     43:  * or for locating a interface on a certain network, as well as more general
                     44:  * routing and gateway routines maintaining information used to locate
                     45:  * interfaces.  These routines live in the files if.c and route.c
                     46:  */
                     47: #ifndef _TIME_ /*  XXX fast fix for SNMP, going away soon */
                     48: #ifdef KERNEL
                     49: #include "../sys/time.h"
                     50: #else
                     51: #include <sys/time.h>
                     52: #endif
                     53: #endif
                     54: 
                     55: /*
                     56:  * Structure defining a queue for a network interface.
                     57:  *
                     58:  * (Would like to call this struct ``if'', but C isn't PL/1.)
                     59:  */
                     60: 
                     61: struct ifnet {
                     62:        char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
                     63:        short   if_unit;                /* sub-unit for lower level driver */
                     64:        short   if_mtu;                 /* maximum transmission unit */
                     65:        short   if_flags;               /* up/down, broadcast, etc. */
                     66:        short   if_timer;               /* time 'til if_watchdog called */
                     67:        int     if_metric;              /* routing metric (external only) */
                     68:        struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
                     69:        struct  ifqueue {
                     70:                struct  mbuf *ifq_head;
                     71:                struct  mbuf *ifq_tail;
                     72:                int     ifq_len;
                     73:                int     ifq_maxlen;
                     74:                int     ifq_drops;
                     75:        } if_snd;                       /* output queue */
                     76: /* procedure handles */
                     77:        int     (*if_init)();           /* init routine */
                     78:        int     (*if_output)();         /* output routine (enqueue) */
                     79:        int     (*if_start)();          /* initiate output routine */
                     80:        int     (*if_done)();           /* output complete routine */
                     81:        int     (*if_ioctl)();          /* ioctl routine */
                     82:        int     (*if_reset)();          /* bus reset routine */
                     83:        int     (*if_watchdog)();       /* timer routine */
                     84: /* generic interface statistics */
                     85:        int     if_ipackets;            /* packets received on interface */
                     86:        int     if_ierrors;             /* input errors on interface */
                     87:        int     if_opackets;            /* packets sent on interface */
                     88:        int     if_oerrors;             /* output errors on interface */
                     89:        int     if_collisions;          /* collisions on csma interfaces */
                     90: /* end statistics */
                     91:        struct  ifnet *if_next;
                     92:        u_char  if_type;                /* ethernet, tokenring, etc */
                     93:        u_char  if_addrlen;             /* media address length */
                     94:        u_char  if_hdrlen;              /* media header length */
                     95:        u_char  if_index;               /* numeric abbreviation for this if  */
                     96: /* more statistics here to avoid recompiling netstat */
                     97:        struct  timeval if_lastchange;  /* last updated */
                     98:        int     if_ibytes;              /* total number of octets received */
                     99:        int     if_obytes;              /* total number of octets sent */
                    100:        int     if_imcasts;             /* packets received via multicast */
                    101:        int     if_omcasts;             /* packets sent via multicast */
                    102:        int     if_iqdrops;             /* dropped on input, this interface */
                    103:        int     if_noproto;             /* destined for unsupported protocol */
                    104:        int     if_baudrate;            /* linespeed */
                    105: };
                    106: 
                    107: #define        IFF_UP          0x1             /* interface is up */
                    108: #define        IFF_BROADCAST   0x2             /* broadcast address valid */
                    109: #define        IFF_DEBUG       0x4             /* turn on debugging */
                    110: #define        IFF_LOOPBACK    0x8             /* is a loopback net */
                    111: #define        IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
                    112: #define        IFF_NOTRAILERS  0x20            /* avoid use of trailers */
                    113: #define        IFF_RUNNING     0x40            /* resources allocated */
                    114: #define        IFF_NOARP       0x80            /* no address resolution protocol */
                    115: /* next two not supported now, but reserved: */
                    116: #define        IFF_PROMISC     0x100           /* receive all packets */
                    117: #define        IFF_ALLMULTI    0x200           /* receive all multicast packets */
                    118: #define        IFF_OACTIVE     0x400           /* transmission in progress */
                    119: #define        IFF_SIMPLEX     0x800           /* can't hear own transmissions */
                    120: 
                    121: /* flags set internally only: */
                    122: #define        IFF_CANTCHANGE  (IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE)
                    123: 
                    124: /*
                    125:  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
                    126:  * input routines have queues of messages stored on ifqueue structures
                    127:  * (defined above).  Entries are added to and deleted from these structures
                    128:  * by these macros, which should be called with ipl raised to splimp().
                    129:  */
                    130: #define        IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
                    131: #define        IF_DROP(ifq)            ((ifq)->ifq_drops++)
                    132: #define        IF_ENQUEUE(ifq, m) { \
                    133:        (m)->m_nextpkt = 0; \
                    134:        if ((ifq)->ifq_tail == 0) \
                    135:                (ifq)->ifq_head = m; \
                    136:        else \
                    137:                (ifq)->ifq_tail->m_nextpkt = m; \
                    138:        (ifq)->ifq_tail = m; \
                    139:        (ifq)->ifq_len++; \
                    140: }
                    141: #define        IF_PREPEND(ifq, m) { \
                    142:        (m)->m_nextpkt = (ifq)->ifq_head; \
                    143:        if ((ifq)->ifq_tail == 0) \
                    144:                (ifq)->ifq_tail = (m); \
                    145:        (ifq)->ifq_head = (m); \
                    146:        (ifq)->ifq_len++; \
                    147: }
                    148: #define        IF_DEQUEUE(ifq, m) { \
                    149:        (m) = (ifq)->ifq_head; \
                    150:        if (m) { \
                    151:                if (((ifq)->ifq_head = (m)->m_nextpkt) == 0) \
                    152:                        (ifq)->ifq_tail = 0; \
                    153:                (m)->m_nextpkt = 0; \
                    154:                (ifq)->ifq_len--; \
                    155:        } \
                    156: }
                    157: 
                    158: #define        IFQ_MAXLEN      50
                    159: #define        IFNET_SLOWHZ    1               /* granularity is 1 second */
                    160: 
                    161: /*
                    162:  * The ifaddr structure contains information about one address
                    163:  * of an interface.  They are maintained by the different address families,
                    164:  * are allocated and attached when an address is set, and are linked
                    165:  * together so all addresses for an interface can be located.
                    166:  */
                    167: struct ifaddr {
                    168:        struct  sockaddr *ifa_addr;     /* address of interface */
                    169:        struct  sockaddr *ifa_dstaddr;  /* other end of p-to-p link */
                    170: #define        ifa_broadaddr   ifa_dstaddr     /* broadcast address interface */
                    171:        struct  sockaddr *ifa_netmask;  /* used to determine subnet */
                    172:        struct  ifnet *ifa_ifp;         /* back-pointer to interface */
                    173:        struct  ifaddr *ifa_next;       /* next address for interface */
                    174:        int     (*ifa_rtrequest)();     /* check or clean routes (+ or -)'d */
                    175:        struct  rtentry *ifa_rt;        /* ??? for ROUTETOIF */
                    176:        u_short ifa_flags;              /* mostly rt_flags for cloning */
                    177:        u_short ifa_llinfolen;          /* extra to malloc for link info */
                    178: };
                    179: #define IFA_ROUTE      RTF_UP          /* route installed */
                    180: /*
                    181:  * Interface request structure used for socket
                    182:  * ioctl's.  All interface ioctl's must have parameter
                    183:  * definitions which begin with ifr_name.  The
                    184:  * remainder may be interface specific.
                    185:  */
                    186: struct ifreq {
                    187: #define        IFNAMSIZ        16
                    188:        char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
                    189:        union {
                    190:                struct  sockaddr ifru_addr;
                    191:                struct  sockaddr ifru_dstaddr;
                    192:                struct  sockaddr ifru_broadaddr;
                    193:                short   ifru_flags;
                    194:                int     ifru_metric;
                    195:                caddr_t ifru_data;
                    196:        } ifr_ifru;
                    197: #define        ifr_addr        ifr_ifru.ifru_addr      /* address */
                    198: #define        ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
                    199: #define        ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
                    200: #define        ifr_flags       ifr_ifru.ifru_flags     /* flags */
                    201: #define        ifr_metric      ifr_ifru.ifru_metric    /* metric */
                    202: #define        ifr_data        ifr_ifru.ifru_data      /* for use by interface */
                    203: };
                    204: 
                    205: struct ifaliasreq {
                    206:        char    ifra_name[IFNAMSIZ];            /* if name, e.g. "en0" */
                    207:        struct  sockaddr ifra_addr;
                    208:        struct  sockaddr ifra_broadaddr;
                    209:        struct  sockaddr ifra_mask;
                    210: };
                    211: 
                    212: /*
                    213:  * Structure used in SIOCGIFCONF request.
                    214:  * Used to retrieve interface configuration
                    215:  * for machine (useful for programs which
                    216:  * must know all networks accessible).
                    217:  */
                    218: struct ifconf {
                    219:        int     ifc_len;                /* size of associated buffer */
                    220:        union {
                    221:                caddr_t ifcu_buf;
                    222:                struct  ifreq *ifcu_req;
                    223:        } ifc_ifcu;
                    224: #define        ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
                    225: #define        ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
                    226: };
                    227: 
                    228: #ifdef KERNEL
                    229: #include "../net/if_arp.h"
                    230: struct ifqueue rawintrq;               /* raw packet input queue */
                    231: struct ifnet *ifnet;
                    232: struct ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
                    233: struct ifaddr *ifa_ifwithdstaddr();
                    234: #else KERNEL
                    235: #include <net/if_arp.h>
                    236: #endif KERNEL

unix.superglobalmegacorp.com

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