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

Defined variables

rawintrq defined in line 218; used 4 times

Defined struct's

ifnet defined in line 45; used 332 times

Defined macros

IFF_ALLMULTI defined in line 86; never used
IFF_CANTCHANGE defined in line 88; used 2 times
IFF_NOARP defined in line 83; used 4 times
IFF_PROMISC defined in line 85; never used
IFNAMSIZ defined in line 182; used 3 times
IFNET_SLOWHZ defined in line 155; used 1 times
IF_ADJ defined in line 120; used 3 times
IF_PREPEND defined in line 107; used 1 times
ifa_broadaddr defined in line 169; used 1 times
ifa_dstaddr defined in line 170; used 2 times
ifr_data defined in line 197; never used

Usage of this include

if.h used 65 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1000
Valid CSS Valid XHTML 1.0 Strict