home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tcp30tkt.zip / PGMG1.ZIP / INCLUDE / NET / IF.H < prev    next >
Text File  |  1995-12-04  |  12KB  |  283 lines

  1. #ifndef __IF_32H
  2. #define __IF_32H
  3.  
  4. /*
  5.  * Copyright (c) 1982, 1986 Regents of the University of California.
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms are permitted
  9.  * provided that this notice is preserved and that due credit is given
  10.  * to the University of California at Berkeley. The name of the University
  11.  * may not be used to endorse or promote products derived from this
  12.  * software without specific prior written permission. This software
  13.  * is provided ``as is'' without express or implied warranty.
  14.  *
  15.  *      @(#)if.h        7.2 (Berkeley) 12/30/87
  16.  */
  17.  
  18. /*
  19.  * Structures defining a network interface, providing a packet
  20.  * transport mechanism (ala level 0 of the PUP protocols).
  21.  *
  22.  * Each interface accepts output datagrams of a specified maximum
  23.  * length, and provides higher level routines with input datagrams
  24.  * received from its medium.
  25.  *
  26.  * Output occurs when the routine if_output is called, with three parameters:
  27.  *      (*ifp->if_output)(ifp, m, dst)
  28.  * Here m is the mbuf chain to be sent and dst is the destination address.
  29.  * The output routine encapsulates the supplied datagram if necessary,
  30.  * and then transmits it on its medium.
  31.  *
  32.  * On input, each interface unwraps the data received by it, and either
  33.  * places it on the input queue of a internetwork datagram routine
  34.  * and posts the associated software interrupt, or passes the datagram to a raw
  35.  * packet input routine.
  36.  *
  37.  * Routines exist for locating interfaces by their addresses
  38.  * or for locating a interface on a certain network, as well as more general
  39.  * routing and gateway routines maintaining information used to locate
  40.  * interfaces.  These routines live in the files if.c and route.c
  41.  */
  42.  
  43.  
  44. #ifndef IFMIB_ENTRIES
  45. #define IFMIB_ENTRIES 20
  46. #endif
  47.  
  48. /*
  49.  * Structure defining a queue for a network interface.
  50.  *
  51.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  52.  */
  53. #pragma pack(4) /* force on doubleword boundary */
  54. struct mbuf;   /* Pre declaration */
  55. struct ifaddr; /* Pre declaration */
  56. struct ifnet {
  57.         char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
  58.         short   if_unit;                /* sub-unit for lower level driver */
  59.         short   if_mtu;                 /* maximum transmission unit */
  60.         short   if_flags;               /* up/down, broadcast, etc. */
  61.         short   if_timer;               /* time 'til if_watchdog called */
  62.         int     if_metric;              /* routing metric (external only) */
  63.         struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
  64.         struct  ifqueue {
  65.                 struct  mbuf *ifq_head;
  66.                 struct  mbuf *ifq_tail;
  67.                 int     ifq_len;
  68.                 int     ifq_maxlen;
  69.                 int     ifq_drops;
  70.         } if_snd;                       /* output queue */
  71. /* procedure handles */
  72.         int     (*if_init)();           /* init routine */
  73.         int     (*if_output)();         /* output routine */
  74.         int     (*if_ioctl)();          /* ioctl routine */
  75.         int     (*if_reset)();          /* bus reset routine */
  76.         int     (*if_watchdog)();       /* timer routine */
  77. /* generic interface statistics */
  78.         int     if_ipackets;            /* do not take icmp redirect flag */
  79.         int     if_ierrors;             /* input errors on interface */
  80.         int     if_opackets;            /* packets sent on interface */
  81.         int     if_oerrors;             /* output errors on interface */
  82.         int     if_collisions;          /* 802.3 flag */
  83. /* end statistics */
  84.         struct  ifnet *if_next;
  85. #ifdef OS2
  86.         u_char  if_adapternum;          /* adapter number */
  87.         u_int if_adaptype;
  88.         u_int if_broadcast;
  89.         u_long if_speed;
  90.  
  91.         /* [db3l] Interface TCP estimates/controls.  Serves the same */
  92.         /* purpose as the per-route values in BSD-Reno, but I didn't */
  93.         /* have to touch any of the route manipulation code.         */
  94.         u_short if_rtt;                 /* Est interface rtt in ms */
  95.         u_short if_rttvar;              /* Est interface rttvar in ms */
  96.         u_short if_rttmin;              /* Fixed interface rttmin in ms */
  97.         u_short if_sendpipe;            /* Send socket buffer/window size */
  98.         u_short if_recvpipe;            /* Recv socket buffer/window size */
  99.         u_short if_ssthresh;            /* Gateway buffer limit (slow strt) */
  100. #endif
  101. };
  102. #pragma pack()   /* reset to default packing */
  103.  
  104. /* [db3l] Definition for scale to use for RTT values above.  Set to ms */
  105. #define IF_RTTSCALE 1000
  106.  
  107. #pragma pack(1) /* force on doubleword boundary */
  108. struct ifmib {
  109.   short ifNumber;  /* number of network interfaces */
  110.   struct iftable {
  111.     short  ifIndex;        /* index of this interface */
  112.     char   ifDescr[45];    /* description             */
  113.     short  ifType;         /* type of the interface   */
  114.     short  ifMtu;          /* MTU of the interface   */
  115.     char   ifPhysAddr[6];  /* MTU of the interface   */
  116.     short  ifOperStatus;
  117.     u_long ifSpeed;
  118.     u_long ifLastChange;
  119.     u_long ifInOctets;
  120.     u_long ifOutOctets;
  121.     u_long ifOutDiscards;
  122.     u_long ifInDiscards;
  123.     u_long ifInErrors;
  124.     u_long ifOutErrors;
  125.     u_long ifInUnknownProtos;
  126.     u_long ifInUcastPkts;
  127.     u_long ifOutUcastPkts;
  128.     u_long ifInNUcastPkts;
  129.     u_long ifOutNUcastPkts;
  130.   } iftable[IFMIB_ENTRIES];
  131. };
  132. #pragma pack()   /* reset to default packing */
  133.  
  134. #define IFF_UP          0x1             /* interface is up */
  135. #define IFF_BROADCAST   0x2             /* broadcast address valid */
  136. #define IFF_DEBUG       0x4             /* turn on debugging */
  137. #define IFF_LOOPBACK    0x8             /* is a loopback net */
  138. #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
  139. #define IFF_NOTRAILERS  0x20            /* avoid use of trailers */
  140. #define IFF_RUNNING     0x40            /* resources allocated */
  141. #define IFF_NOARP       0x80            /* no address resolution protocol */
  142. /* next two not supported now, but reserved: */
  143. #define IFF_PROMISC     0x100           /* receive all packets */
  144. #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
  145. #define IFF_BRIDGE     0x1000           /* support token ring routine field */
  146. #define IFF_SNAP       0x2000           /* support extended SAP header */
  147. #define IFF_ETHER      0x4000           /* Ethernet interface */
  148. #define IFF_LOOPBRD    0x8000           /* Ethernet interface */
  149. /* flags set internally only: */
  150. #define IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  151.  
  152. /*
  153.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  154.  * input routines have queues of messages stored on ifqueue structures
  155.  * (defined above).  Entries are added to and deleted from these structures
  156.  * by these macros, which should be called with ipl raised to splimp().
  157.  */
  158. #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  159. #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
  160. #define IF_ENQUEUE(ifq, m) { \
  161.         (m)->m_act = 0; \
  162.         if ((ifq)->ifq_tail == 0) \
  163.                 (ifq)->ifq_head = m; \
  164.         else \
  165.                 (ifq)->ifq_tail->m_act = m; \
  166.         (ifq)->ifq_tail = m; \
  167.         (ifq)->ifq_len++; \
  168. }
  169. #define IF_PREPEND(ifq, m) { \
  170.         (m)->m_act = (ifq)->ifq_head; \
  171.         if ((ifq)->ifq_tail == 0) \
  172.                 (ifq)->ifq_tail = (m); \
  173.         (ifq)->ifq_head = (m); \
  174.         (ifq)->ifq_len++; \
  175. }
  176. /*
  177.  * Packets destined for level-1 protocol input routines
  178.  * have a pointer to the receiving interface prepended to the data.
  179.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  180.  * IF_ADJ should be used otherwise to adjust for its presence.
  181.  */
  182. #define IF_ADJ(m) { \
  183.         (m)->m_off += sizeof(struct ifnet  *); \
  184.         (m)->m_len -= sizeof(struct ifnet  *); \
  185.         if ((m)->m_len == 0) { \
  186.                 struct mbuf  *n; \
  187.                 MFREE((m), n); \
  188.                 (m) = n; \
  189.         } \
  190. }
  191. #define IF_DEQUEUEIF(ifq, m, ifp) { \
  192.         (m) = (ifq)->ifq_head; \
  193.         if (m) { \
  194.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  195.                         (ifq)->ifq_tail = 0; \
  196.                 (m)->m_act = 0; \
  197.                 (ifq)->ifq_len--; \
  198.                 (ifp) = *(mtod((m), struct ifnet * *)); \
  199.                 IF_ADJ(m); \
  200.         } \
  201. }
  202. #define IF_DEQUEUE(ifq, m) { \
  203.         (m) = (ifq)->ifq_head; \
  204.         if (m) { \
  205.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  206.                         (ifq)->ifq_tail = 0; \
  207.                 (m)->m_act = 0; \
  208.                 (ifq)->ifq_len--; \
  209.         } \
  210. }
  211.  
  212. #define IFQ_MAXLEN      50
  213. #define IFNET_SLOWHZ    1               /* granularity is 1 second */
  214.  
  215. /*
  216.  * The ifaddr structure contains information about one address
  217.  * of an interface.  They are maintained by the different address families,
  218.  * are allocated and attached when an address is set, and are linked
  219.  * together so all addresses for an interface can be located.
  220.  */
  221. struct ifaddr {
  222.         struct  sockaddr ifa_addr;      /* address of interface */
  223.         union {
  224.                 struct  sockaddr ifu_broadaddr;
  225.                 struct  sockaddr ifu_dstaddr;
  226.         } ifa_ifu;
  227. #define ifa_broadaddr   ifa_ifu.ifu_broadaddr   /* broadcast address */
  228. #define ifa_dstaddr     ifa_ifu.ifu_dstaddr     /* other end of p-to-p link */
  229.         struct  ifnet  *ifa_ifp;         /* back-pointer to interface */
  230.         struct  ifaddr  *ifa_next;       /* next address for interface */
  231. };
  232.  
  233. /*
  234.  * Interface request structure used for socket
  235.  * ioctl's.  All interface ioctl's must have parameter
  236.  * definitions which begin with ifr_name.  The
  237.  * remainder may be interface specific.
  238.  */
  239. struct  ifreq {
  240. #define IFNAMSIZ        16
  241.         char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
  242.         union {
  243.                 struct  sockaddr ifru_addr;
  244.                 struct  sockaddr ifru_dstaddr;
  245.                 struct  sockaddr ifru_broadaddr;
  246.                 short   ifru_flags;
  247.                 int     ifru_metric;
  248.                 caddr_t ifru_data;
  249.         } ifr_ifru;
  250. #define ifr_addr        ifr_ifru.ifru_addr      /* address */
  251. #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
  252. #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
  253. #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
  254. #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
  255. #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
  256. };
  257.  
  258. /*
  259.  * Structure used in SIOCGIFCONF request.
  260.  * Used to retrieve interface configuration
  261.  * for machine (useful for programs which
  262.  * must know all networks accessible).
  263.  */
  264. struct  ifconf {
  265.         int     ifc_len;                /* size of associated buffer */
  266.         union {
  267.                 caddr_t ifcu_buf;
  268.                 struct  ifreq  *ifcu_req;
  269.         } ifc_ifcu;
  270. #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
  271. #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
  272. };
  273.  
  274. #include <net/if_arp.h>
  275. #ifdef KERNEL
  276. struct  ifqueue near rawintrq;               /* raw packet input queue */
  277. struct  ifnet  * near ifnet;
  278. struct  ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  279. struct  ifaddr *ifa_ifwithdstaddr();
  280. #endif
  281.  
  282. #endif /* __IF_32H */
  283.