home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / SLHC.H < prev    next >
C/C++ Source or Header  |  1991-08-06  |  7KB  |  192 lines

  1. #ifndef _SLHC_H
  2. #define _SLHC_H
  3. /*
  4.  * Definitions for tcp compression routines.
  5.  *
  6.  * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
  7.  *
  8.  * Copyright (c) 1989 Regents of the University of California.
  9.  * All rights reserved.
  10.  *
  11.  * Redistribution and use in source and binary forms are permitted
  12.  * provided that the above copyright notice and this paragraph are
  13.  * duplicated in all such forms and that any documentation,
  14.  * advertising materials, and other materials related to such
  15.  * distribution and use acknowledge that the software was developed
  16.  * by the University of California, Berkeley.  The name of the
  17.  * University may not be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  *
  23.  *    Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  24.  *    - Initial distribution.
  25.  *
  26.  *
  27.  * modified for KA9Q Internet Software Package by
  28.  * Katie Stevens (dkstevens@ucdavis.edu)
  29.  * University of California, Davis
  30.  * Computing Services
  31.  *    - 01-31-90    initial adaptation
  32.  *
  33.  *    - Feb 1991    Bill_Simpson@um.cc.umich.edu
  34.  *            variable number of conversation slots
  35.  *            allow zero or one slots
  36.  *            separate routines
  37.  *            status display
  38.  */
  39. #ifndef    _GLOBAL_H
  40. #include "global.h"
  41. #endif
  42.  
  43. #ifndef    _MBUF_H
  44. #include "mbuf.h"
  45. #endif
  46.  
  47. #ifndef    _IP_H
  48. #include "ip.h"
  49. #endif
  50.  
  51. #ifndef    _TCP_H
  52. #include "tcp.h"
  53. #endif
  54.  
  55. /*
  56.  * Compressed packet format:
  57.  *
  58.  * The first octet contains the packet type (top 3 bits), TCP
  59.  * 'push' bit, and flags that indicate which of the 4 TCP sequence
  60.  * numbers have changed (bottom 5 bits).  The next octet is a
  61.  * conversation number that associates a saved IP/TCP header with
  62.  * the compressed packet.  The next two octets are the TCP checksum
  63.  * from the original datagram.  The next 0 to 15 octets are
  64.  * sequence number changes, one change per bit set in the header
  65.  * (there may be no changes and there are two special cases where
  66.  * the receiver implicitly knows what changed -- see below).
  67.  *
  68.  * There are 5 numbers which can change (they are always inserted
  69.  * in the following order): TCP urgent pointer, window,
  70.  * acknowlegement, sequence number and IP ID.  (The urgent pointer
  71.  * is different from the others in that its value is sent, not the
  72.  * change in value.)  Since typical use of SLIP links is biased
  73.  * toward small packets (see comments on MTU/MSS below), changes
  74.  * use a variable length coding with one octet for numbers in the
  75.  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  76.  * range 256 - 65535 or 0.  (If the change in sequence number or
  77.  * ack is more than 65535, an uncompressed packet is sent.)
  78.  */
  79.  
  80. /*
  81.  * Packet types (must not conflict with IP protocol version)
  82.  *
  83.  * The top nibble of the first octet is the packet type.  There are
  84.  * three possible types: IP (not proto TCP or tcp with one of the
  85.  * control flags set); uncompressed TCP (a normal IP/TCP packet but
  86.  * with the 8-bit protocol field replaced by an 8-bit connection id --
  87.  * this type of packet syncs the sender & receiver); and compressed
  88.  * TCP (described above).
  89.  *
  90.  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  91.  * is logically part of the 4-bit "changes" field that follows.  Top
  92.  * three bits are actual packet type.  For backward compatibility
  93.  * and in the interest of conserving bits, numbers are chosen so the
  94.  * IP protocol version number (4) which normally appears in this nibble
  95.  * means "IP packet".
  96.  */
  97.  
  98. /* SLIP compression masks for len/vers byte */
  99. #define SL_TYPE_IP 0x40
  100. #define SL_TYPE_UNCOMPRESSED_TCP 0x70
  101. #define SL_TYPE_COMPRESSED_TCP 0x80
  102. #define SL_TYPE_ERROR 0x00
  103.  
  104. /* Bits in first octet of compressed packet */
  105. #define NEW_C    0x40    /* flag bits for what changed in a packet */
  106. #define NEW_I    0x20
  107. #define NEW_S    0x08
  108. #define NEW_A    0x04
  109. #define NEW_W    0x02
  110. #define NEW_U    0x01
  111.  
  112. /* reserved, special-case values of above */
  113. #define SPECIAL_I (NEW_S|NEW_W|NEW_U)        /* echoed interactive traffic */
  114. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
  115. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  116.  
  117. #define TCP_PUSH_BIT 0x10
  118.  
  119. /*
  120.  * data type and sizes conversion assumptions:
  121.  *
  122.  *    VJ code        KA9Q style    generic
  123.  *    u_char        byte_t        unsigned char     8 bits
  124.  *    u_short        int16        unsigned short    16 bits
  125.  *    u_int        int16        unsigned short    16 bits
  126.  *    u_long        unsigned long    unsigned long    32 bits
  127.  *    int        int32        long        32 bits
  128.  */
  129.  
  130. /*
  131.  * "state" data for each active tcp conversation on the wire.  This is
  132.  * basically a copy of the entire IP/TCP header from the last packet
  133.  * we saw from the conversation together with a small identifier
  134.  * the transmit & receive ends of the line use to locate saved header.
  135.  */
  136. struct cstate {
  137.     byte_t    this;        /* connection id number (xmit) */
  138.     struct cstate *next;    /* next in ring (xmit) */
  139.     struct ip cs_ip;    /* ip/tcp hdr from most recent packet */
  140.     struct tcp cs_tcp;
  141. };
  142. #define NULLSLSTATE    (struct cstate *)0
  143.  
  144. /*
  145.  * all the state data for one serial line (we need one of these per line).
  146.  */
  147. struct slcompress {
  148.     struct cstate *tstate;    /* transmit connection states (array)*/
  149.     struct cstate *rstate;    /* receive connection states (array)*/
  150.  
  151.     byte_t tslot_limit;    /* highest transmit slot id (0-l)*/
  152.     byte_t rslot_limit;    /* highest receive slot id (0-l)*/
  153.  
  154.     byte_t xmit_oldest;    /* oldest xmit in ring */
  155.     byte_t xmit_current;    /* most recent xmit id */
  156.     byte_t recv_current;    /* most recent rcvd id */
  157.  
  158.     byte_t flags;
  159. #define SLF_TOSS    0x01    /* tossing rcvd frames until id received */
  160.  
  161.     int32 sls_o_nontcp;    /* outbound non-TCP packets */
  162.     int32 sls_o_tcp;    /* outbound TCP packets */
  163.     int32 sls_o_uncompressed;    /* outbound uncompressed packets */
  164.     int32 sls_o_compressed;    /* outbound compressed packets */
  165.     int32 sls_o_searches;    /* searches for connection state */
  166.     int32 sls_o_misses;    /* times couldn't find conn. state */
  167.  
  168.     int32 sls_i_uncompressed;    /* inbound uncompressed packets */
  169.     int32 sls_i_compressed;    /* inbound compressed packets */
  170.     int32 sls_i_error;    /* inbound error packets */
  171.     int32 sls_i_tossed;    /* inbound packets tossed because of error */
  172. };
  173. #define NULLSLCOMPR    (struct slcompress *)0
  174.  
  175.  
  176. /* In slhc.c: */
  177. struct slcompress *slhc_init __ARGS((int rslots, int tslots));
  178. void slhc_free __ARGS((struct slcompress *comp));
  179.  
  180. int slhc_compress __ARGS((struct slcompress *comp,
  181.     struct mbuf **bpp, int compress_cid));
  182. int slhc_uncompress __ARGS((struct slcompress *comp,
  183.     struct mbuf **bpp));
  184. int slhc_remember __ARGS((struct slcompress *comp,
  185.     struct mbuf **bpp));
  186. int slhc_toss __ARGS((struct slcompress *comp));
  187.  
  188. void slhc_i_status __ARGS((struct slcompress *comp));
  189. void slhc_o_status __ARGS((struct slcompress *comp));
  190.  
  191. #endif    /* _SLHC_H */
  192.