home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / network / src_1218.zip / SLCOMPRE.H < prev    next >
Text File  |  1990-11-10  |  7KB  |  183 lines

  1. #ifndef _SLCOMPRESS_H
  2. #define _SLCOMPRESS_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. #ifndef _GLOBAL_H
  34. #include "global.h"
  35. #endif
  36.  
  37. #ifndef    _MBUF_H
  38. #include "mbuf.h"
  39. #endif
  40.  
  41. #ifndef    _IP_H
  42. #include "ip.h"
  43. #endif
  44.  
  45. #ifndef    _TCP_H
  46. #include "tcp.h"
  47. #endif
  48.  
  49. #define MLEN 128
  50. #define MAX_STATES 16        /* must be > 2 and < 256 */
  51. #define MAX_HDR MLEN        /* XXX 4bsd-ism: should really be 128 */
  52.  
  53. /*
  54.  * Compressed packet format:
  55.  *
  56.  * The first octet contains the packet type (top 3 bits), TCP
  57.  * 'push' bit, and flags that indicate which of the 4 TCP sequence
  58.  * numbers have changed (bottom 5 bits).  The next octet is a
  59.  * conversation number that associates a saved IP/TCP header with
  60.  * the compressed packet.  The next two octets are the TCP checksum
  61.  * from the original datagram.  The next 0 to 15 octets are
  62.  * sequence number changes, one change per bit set in the header
  63.  * (there may be no changes and there are two special cases where
  64.  * the receiver implicitly knows what changed -- see below).
  65.  * 
  66.  * There are 5 numbers which can change (they are always inserted
  67.  * in the following order): TCP urgent pointer, window,
  68.  * acknowlegement, sequence number and IP ID.  (The urgent pointer
  69.  * is different from the others in that its value is sent, not the
  70.  * change in value.)  Since typical use of SLIP links is biased
  71.  * toward small packets (see comments on MTU/MSS below), changes
  72.  * use a variable length coding with one octet for numbers in the
  73.  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  74.  * range 256 - 65535 or 0.  (If the change in sequence number or
  75.  * ack is more than 65535, an uncompressed packet is sent.)
  76.  */
  77.  
  78. /*
  79.  * Packet types (must not conflict with IP protocol version)
  80.  *
  81.  * The top nibble of the first octet is the packet type.  There are
  82.  * three possible types: IP (not proto TCP or tcp with one of the
  83.  * control flags set); uncompressed TCP (a normal IP/TCP packet but
  84.  * with the 8-bit protocol field replaced by an 8-bit connection id --
  85.  * this type of packet syncs the sender & receiver); and compressed
  86.  * TCP (described above).
  87.  *
  88.  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  89.  * is logically part of the 4-bit "changes" field that follows.  Top
  90.  * three bits are actual packet type.  For backward compatibility
  91.  * and in the interest of conserving bits, numbers are chosen so the
  92.  * IP protocol version number (4) which normally appears in this nibble
  93.  * means "IP packet".
  94.  */
  95.  
  96. /* SLIP compression masks for len/vers byte */
  97. #define SL_TYPE_IP 0x40
  98. #define SL_TYPE_UNCOMPRESSED_TCP 0x70
  99. #define SL_TYPE_COMPRESSED_TCP 0x80
  100. #define SL_TYPE_ERROR 0x00
  101.  
  102. /* Bits in first octet of compressed packet */
  103. #define NEW_C    0x40    /* flag bits for what changed in a packet */
  104. #define NEW_I    0x20
  105. #define NEW_S    0x08
  106. #define NEW_A    0x04
  107. #define NEW_W    0x02
  108. #define NEW_U    0x01
  109.  
  110. /* reserved, special-case values of above */
  111. #define SPECIAL_I (NEW_S|NEW_W|NEW_U)        /* echoed interactive traffic */
  112. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
  113. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  114.  
  115. #define TCP_PUSH_BIT 0x10
  116.  
  117. /*
  118.  * data type and sizes conversion assumptions:
  119.  *
  120.  *    VJ code        KA9Q style    generic    
  121.  *    u_char        unsigned char    unsigned char     8 bits
  122.  *    u_short        int16        unsigned short    16 bits
  123.  *    u_int        int16        unsigned short    16 bits
  124.  *    u_long        unsigned long    unsigned long    32 bits
  125.  *    int        int32        long        32 bits
  126.  */
  127.  
  128. /*
  129.  * "state" data for each active tcp conversation on the wire.  This is
  130.  * basically a copy of the entire IP/TCP header from the last packet
  131.  * we saw from the conversation together with a small identifier
  132.  * the transmit & receive ends of the line use to locate saved header.
  133.  */
  134. struct cstate {
  135.     struct cstate *cs_next;    /* next most recently used cstate (xmit only) */
  136.     int cs_id;    /* connection # associated with this state */
  137.     struct ip cs_ip;    /* ip/tcp hdr from most recent packet */
  138.     struct tcp cs_tcp;
  139. };
  140.  
  141. /*
  142.  * all the state data for one serial line (we need one of these
  143.  * per line).
  144.  */
  145. struct slcompress {
  146.     struct cstate *last_cs;    /* most recently used tstate */
  147.     unsigned char last_recv;    /* last rcvd conn. id */
  148.     unsigned char last_xmit;    /* last sent conn. id */
  149.     int16 flags;
  150. #ifndef SL_NO_STATS
  151.     int32 sls_nontcp;    /* outbound non-TCP packets */
  152.     int32 sls_asistcp;    /* outbound TCP packets */
  153.     int32 sls_compressed;    /* outbound compressed packets */
  154.     int32 sls_uncompressed;    /* outbound uncompressed packets */
  155.     int32 sls_searches;    /* searches for connection state */
  156.     int32 sls_misses;    /* times couldn't find conn. state */
  157.     int32 sls_nontcpin;    /* inbound non-TCP packets */
  158.     int32 sls_tcpin;    /* inbound TCP packets */
  159.     int32 sls_uncompressedin;    /* inbound uncompressed packets */
  160.     int32 sls_compressedin;    /* inbound compressed packets */
  161.     int32 sls_errorin;    /* inbound unknown type packets */
  162.     int32 sls_tossed;    /* inbound packets tossed because of error */
  163. #endif
  164.     struct cstate tstate[MAX_STATES];    /* xmit connection states */
  165.     struct cstate rstate[MAX_STATES];    /* receive connection states */
  166. };
  167. /* flag values */
  168. #define SLF_TOSS 1        /* tossing rcvd frames because of input err */
  169. /* Null pointer */
  170. #define NULLSLCOMPR    (struct slcompress *)0
  171.  
  172. extern struct slcompress *Slcomp;
  173.  
  174. /* In slcompress.c: */
  175. void sl_compress_init __ARGS((struct slcompress *comp));
  176. int sl_compress_tcp __ARGS((struct mbuf **bpp,
  177.     struct slcompress *comp,
  178.     int compress_cid));
  179. int sl_uncompress_tcp __ARGS((struct mbuf **bufp, int len,
  180.     int16 type, struct slcompress *comp));
  181.  
  182. #endif    /* _SLCOMPRESS_H */
  183.