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

Defined variables

ifnet defined in line 209; used 11 times
rawintrq defined in line 208; used 4 times

Defined struct's

ifconf defined in line 196; used 4 times
ifnet defined in line 39; used 370 times
ifreq defined in line 171; used 22 times

Defined macros

IFF_ALLMULTI defined in line 80; never used
IFF_CANTCHANGE defined in line 82; used 2 times
IFF_DEBUG defined in line 72; used 1 times
IFF_NOARP defined in line 77; used 2 times
IFF_PROMISC defined in line 79; never used
IFNAMSIZ defined in line 172; used 3 times
IFNET_SLOWHZ defined in line 145; used 1 times
IF_ADJ defined in line 114; used 3 times
IF_PREPEND defined in line 101; used 1 times
ifa_broadaddr defined in line 159; used 1 times
ifc_buf defined in line 202; never used
ifc_req defined in line 203; used 1 times
ifr_addr defined in line 182; used 11 times
ifr_broadaddr defined in line 184; used 1 times
ifr_data defined in line 187; never used
ifr_flags defined in line 185; used 4 times
ifr_metric defined in line 186; used 2 times

Usage of this include

if.h used 47 times
Last modified: 1986-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1768
Valid CSS Valid XHTML 1.0 Strict