home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / detk45he.zip / stack16 / net / if.h < prev    next >
Text File  |  1999-05-11  |  13KB  |  319 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 42
  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(1) /* 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.                 short   ifq_len;
  68.                 short   ifq_maxlen;
  69.                 u_short ifq_drops;
  70.         } if_snd;                       /* output queue */
  71. /* procedure handles */
  72.         int     (*if_init)(void);           /* init routine */
  73.         int     (*if_output)(void);         /* output routine */
  74.         int     (*if_ioctl)(void);          /* ioctl routine */
  75.         int     (*if_reset)(void);          /* bus reset routine */
  76.         int     (*if_watchdog)(void);       /* timer routine */
  77. /* generic interface statistics */
  78.         u_short if_ipackets;            /* do not take icmp redirect flag */
  79.         u_short if_ierrors;             /* input errors on interface */
  80.         u_short if_opackets;            /* packets sent on interface */
  81.         u_short if_oerrors;             /* output errors on interface */
  82.         u_short 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.         /* 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.         u_long  if_eflags;              /* Extended Flags */
  101.         struct ifqueue if_traceq;       /* packet trace queue */
  102.         u_short if_segsize;             /* segment size for interface*/
  103.         u_short if_use576;              /* use 576 or 1460 as def. mss if going thru a router */
  104.         /* Token Ring IP multicast flag */
  105.         u_short if_rfc1469;             /* using broadcast or functional address */
  106.                                         /* for IP Mulitcast */
  107. #endif
  108. };
  109. #pragma pack()   /* reset to default packing */
  110.  
  111. #define IF_RTTSCALE 1000
  112.  
  113. #ifdef OS2
  114. #define IFF_RFC1469_BC 1  /* using broadcast */
  115. #define IFF_RFC1469_FA 2  /* using functional address */
  116. #define IFF_RFC1469_MA 3  /* using mulitcast address */
  117. #endif
  118.  
  119. #pragma pack(1) /* force on doubleword boundary */
  120. struct ifmib {
  121.   short ifNumber;  /* number of network interfaces */
  122.   struct iftable {
  123.     short  ifIndex;        /* index of this interface */
  124.     char   ifDescr[45];    /* description             */
  125.     short  ifType;         /* type of the interface   */
  126.     short  ifMtu;          /* MTU of the interface   */
  127.     char   ifPhysAddr[6];  /* MTU of the interface   */
  128.     short  ifOperStatus;
  129.     u_long ifSpeed;
  130.     u_long ifLastChange;
  131.     u_long ifInOctets;
  132.     u_long ifOutOctets;
  133.     u_long ifOutDiscards;
  134.     u_long ifInDiscards;
  135.     u_long ifInErrors;
  136.     u_long ifOutErrors;
  137.     u_long ifInUnknownProtos;
  138.     u_long ifInUcastPkts;
  139.     u_long ifOutUcastPkts;
  140.     u_long ifInNUcastPkts;
  141.     u_long ifOutNUcastPkts;
  142.   } iftable[IFMIB_ENTRIES];
  143. };
  144. #pragma pack()   /* reset to default packing */
  145.  
  146. #define IFF_UP          0x1             /* interface is up */
  147. #define IFF_BROADCAST   0x2             /* broadcast address valid */
  148. #define IFF_DEBUG       0x4             /* turn on debugging */
  149. #define IFF_LOOPBACK    0x8             /* is a loopback net */
  150. #define IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
  151. #define IFF_NOTRAILERS  0x20            /* avoid use of trailers */
  152. #define IFF_RUNNING     0x40            /* resources allocated */
  153. #define IFF_NOARP       0x80            /* no address resolution protocol */
  154. /* next two not supported now, but reserved: */
  155. #define IFF_PROMISC     0x100           /* receive all packets */
  156. #define IFF_ALLMULTI    0x200           /* receive all multicast packets */
  157. #define IFF_DEFMTU      0x400           /* default mtu of 1500 */
  158. #define IFF_MULTICAST   0x800           /* supports multicast */
  159. /*
  160.  * The IFF_MULTICAST flag indicates that the network can support the
  161.  * transmission and reception of higher-level (e.g., IP) multicast packets.
  162.  * It is independent of hardware support for multicasting; for example,
  163.  * point-to-point links or pure broadcast networks may well support
  164.  * higher-level multicasts.
  165.  */
  166. #define IFF_BRIDGE     0x1000           /* support token ring routine field */
  167. #define IFF_SNAP       0x2000           /* support extended SAP header */
  168. #define IFF_ETHER      0x4000           /* Ethernet interface */
  169. #define IFF_LOOPBRD    0x8000           /* Ethernet interface */
  170. /* flags set internally only: */
  171. #define IFF_CANTCHANGE  (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  172.  
  173. #ifdef OS2
  174. #define IFFE_PKTTRACE   0x00000001      /* trace datalink where possible */
  175. #define IFFE_IPTRACE    0x00000002      /* trace ONLY IP packets */
  176.  
  177. #ifdef __32BIT__
  178. struct pkt_trace_hdr {
  179.    u_short  pt_htype;  /* header type */
  180.    u_short  pt_len;    /* in: pt_buf len, out: packet len */
  181.    caddr_t  _Seg16 pt_data;   /* packet */
  182.    u_long   pt_tstamp; /* time stamp in milliseconds */
  183.    };
  184. #endif
  185.  
  186. #define HT_IP           0x01  /* IP */
  187. #define HT_ETHER        0x06  /* Ethernet */
  188. #define HT_ISO88023     0x07  /* CSMA CD */
  189. #define HT_ISO88025     0x09  /* Token Ring */
  190. #define HT_SLIP         0x1c  /* Serial Line IP */
  191. #define HT_PPP          0x18  /* PPP IP */
  192. #endif
  193.  
  194. /*
  195.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  196.  * input routines have queues of messages stored on ifqueue structures
  197.  * (defined above).  Entries are added to and deleted from these structures
  198.  * by these macros, which should be called with ipl raised to splimp().
  199.  */
  200. #define IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  201. #define IF_DROP(ifq)            ((ifq)->ifq_drops++)
  202. #define IF_ENQUEUE(ifq, m) { \
  203.         (m)->m_act = 0; \
  204.         if ((ifq)->ifq_tail == 0) \
  205.                 (ifq)->ifq_head = m; \
  206.         else \
  207.                 (ifq)->ifq_tail->m_act = m; \
  208.         (ifq)->ifq_tail = m; \
  209.         (ifq)->ifq_len++; \
  210. }
  211. #define IF_PREPEND(ifq, m) { \
  212.         (m)->m_act = (ifq)->ifq_head; \
  213.         if ((ifq)->ifq_tail == 0) \
  214.                 (ifq)->ifq_tail = (m); \
  215.         (ifq)->ifq_head = (m); \
  216.         (ifq)->ifq_len++; \
  217. }
  218. /*
  219.  * Packets destined for level-1 protocol input routines
  220.  * have a pointer to the receiving interface prepended to the data.
  221.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  222.  * IF_ADJ should be used otherwise to adjust for its presence.
  223.  */
  224. #define IF_ADJ(m) { \
  225.         (m)->m_off += sizeof(struct ifnet  *); \
  226.         (m)->m_len -= sizeof(struct ifnet  *); \
  227.         if ((m)->m_len == 0) { \
  228.                 struct mbuf  *n; \
  229.                 MFREE((m), n); \
  230.                 (m) = n; \
  231.         } \
  232. }
  233. #define IF_DEQUEUEIF(ifq, m, ifp) { \
  234.         (m) = (ifq)->ifq_head; \
  235.         if (m) { \
  236.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  237.                         (ifq)->ifq_tail = 0; \
  238.                 (m)->m_act = 0; \
  239.                 (ifq)->ifq_len--; \
  240.                 (ifp) = *(mtod((m), struct ifnet * *)); \
  241.                 IF_ADJ(m); \
  242.         } \
  243. }
  244. #define IF_DEQUEUE(ifq, m) { \
  245.         (m) = (ifq)->ifq_head; \
  246.         if (m) { \
  247.                 if (((ifq)->ifq_head = (m)->m_act) == 0) \
  248.                         (ifq)->ifq_tail = 0; \
  249.                 (m)->m_act = 0; \
  250.                 (ifq)->ifq_len--; \
  251.         } \
  252. }
  253.  
  254. #define IFQ_MAXLEN      50
  255. #define IFNET_SLOWHZ    1               /* granularity is 1 second */
  256.  
  257. /*
  258.  * The ifaddr structure contains information about one address
  259.  * of an interface.  They are maintained by the different address families,
  260.  * are allocated and attached when an address is set, and are linked
  261.  * together so all addresses for an interface can be located.
  262.  */
  263. struct ifaddr {
  264.         struct  sockaddr ifa_addr;      /* address of interface */
  265.         union {
  266.                 struct  sockaddr ifu_broadaddr;
  267.                 struct  sockaddr ifu_dstaddr;
  268.         } ifa_ifu;
  269. #define ifa_broadaddr   ifa_ifu.ifu_broadaddr   /* broadcast address */
  270. #define ifa_dstaddr     ifa_ifu.ifu_dstaddr     /* other end of p-to-p link */
  271.         struct  ifnet  *ifa_ifp;         /* back-pointer to interface */
  272.         struct  ifaddr  *ifa_next;       /* next address for interface */
  273. };
  274.  
  275. /*
  276.  * Interface request structure used for socket
  277.  * ioctl's.  All interface ioctl's must have parameter
  278.  * definitions which begin with ifr_name.  The
  279.  * remainder may be interface specific.
  280.  */
  281. struct  ifreq {
  282. #define IFNAMSIZ        16
  283.         char    ifr_name[IFNAMSIZ];             /* if name, e.g. "en0" */
  284.         union {
  285.                 struct  sockaddr ifru_addr;
  286.                 struct  sockaddr ifru_dstaddr;
  287.                 struct  sockaddr ifru_broadaddr;
  288.                 short   ifru_flags;
  289.                 int     ifru_metric;
  290.                 caddr_t ifru_data;
  291.         } ifr_ifru;
  292. #define ifr_addr        ifr_ifru.ifru_addr      /* address */
  293. #define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-to-p link */
  294. #define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address */
  295. #define ifr_flags       ifr_ifru.ifru_flags     /* flags */
  296. #define ifr_metric      ifr_ifru.ifru_metric    /* metric */
  297. #define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
  298. };
  299.  
  300. /*
  301.  * Structure used in SIOCGIFCONF request.
  302.  * Used to retrieve interface configuration
  303.  * for machine (useful for programs which
  304.  * must know all networks accessible).
  305.  */
  306. struct  ifconf {
  307.         int     ifc_len;                /* size of associated buffer */
  308.         union {
  309.                 caddr_t ifcu_buf;
  310.                 struct  ifreq  *ifcu_req;
  311.         } ifc_ifcu;
  312. #define ifc_buf ifc_ifcu.ifcu_buf       /* buffer address */
  313. #define ifc_req ifc_ifcu.ifcu_req       /* array of structures returned */
  314. };
  315.  
  316. #include <net/if_arp.h>
  317.  
  318. #endif /* __IF_32H */
  319.