home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / net / if.h < prev    next >
Text File  |  1993-10-19  |  8KB  |  254 lines

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