home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilss / sockets / include / net / h / if < prev    next >
Encoding:
Text File  |  1995-01-11  |  8.4 KB  |  262 lines

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