home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / net / slcompress.h < prev   
Encoding:
C/C++ Source or Header  |  1992-04-22  |  7.7 KB  |  192 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    slcompress.h,v $
  29.  * Revision 2.1  92/04/21  17:13:42  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*    slcompress.h    7.4    90/06/28    */
  36. /*
  37.  * Definitions for tcp compression routines.
  38.  *
  39.  * $Header: /afs/cs.cmu.edu/project/mach/mach3/rcs/bsdss/server/net/slcompress.h,v 2.1 92/04/21 17:13:42 rwd Exp $
  40.  *
  41.  * Copyright (c) 1989 Regents of the University of California.
  42.  * All rights reserved.
  43.  *
  44.  * Redistribution and use in source and binary forms, with or without
  45.  * modification, are permitted provided that the following conditions
  46.  * are met:
  47.  * 1. Redistributions of source code must retain the above copyright
  48.  *    notice, this list of conditions and the following disclaimer.
  49.  * 2. Redistributions in binary form must reproduce the above copyright
  50.  *    notice, this list of conditions and the following disclaimer in the
  51.  *    documentation and/or other materials provided with the distribution.
  52.  * 3. All advertising materials mentioning features or use of this software
  53.  *    must display the following acknowledgement:
  54.  *    This product includes software developed by the University of
  55.  *    California, Berkeley and its contributors.
  56.  * 4. Neither the name of the University nor the names of its contributors
  57.  *    may be used to endorse or promote products derived from this software
  58.  *    without specific prior written permission.
  59.  *
  60.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  61.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  64.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  65.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  66.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  67.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  68.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  70.  * SUCH DAMAGE.
  71.  *
  72.  *    Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  73.  *    - Initial distribution.
  74.  */
  75.  
  76. #define MAX_STATES 16        /* must be > 2 and < 256 */
  77. #define MAX_HDR MLEN        /* XXX 4bsd-ism: should really be 128 */
  78.  
  79. /*
  80.  * Compressed packet format:
  81.  *
  82.  * The first octet contains the packet type (top 3 bits), TCP
  83.  * 'push' bit, and flags that indicate which of the 4 TCP sequence
  84.  * numbers have changed (bottom 5 bits).  The next octet is a
  85.  * conversation number that associates a saved IP/TCP header with
  86.  * the compressed packet.  The next two octets are the TCP checksum
  87.  * from the original datagram.  The next 0 to 15 octets are
  88.  * sequence number changes, one change per bit set in the header
  89.  * (there may be no changes and there are two special cases where
  90.  * the receiver implicitly knows what changed -- see below).
  91.  * 
  92.  * There are 5 numbers which can change (they are always inserted
  93.  * in the following order): TCP urgent pointer, window,
  94.  * acknowlegement, sequence number and IP ID.  (The urgent pointer
  95.  * is different from the others in that its value is sent, not the
  96.  * change in value.)  Since typical use of SLIP links is biased
  97.  * toward small packets (see comments on MTU/MSS below), changes
  98.  * use a variable length coding with one octet for numbers in the
  99.  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
  100.  * range 256 - 65535 or 0.  (If the change in sequence number or
  101.  * ack is more than 65535, an uncompressed packet is sent.)
  102.  */
  103.  
  104. /*
  105.  * Packet types (must not conflict with IP protocol version)
  106.  *
  107.  * The top nibble of the first octet is the packet type.  There are
  108.  * three possible types: IP (not proto TCP or tcp with one of the
  109.  * control flags set); uncompressed TCP (a normal IP/TCP packet but
  110.  * with the 8-bit protocol field replaced by an 8-bit connection id --
  111.  * this type of packet syncs the sender & receiver); and compressed
  112.  * TCP (described above).
  113.  *
  114.  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
  115.  * is logically part of the 4-bit "changes" field that follows.  Top
  116.  * three bits are actual packet type.  For backward compatibility
  117.  * and in the interest of conserving bits, numbers are chosen so the
  118.  * IP protocol version number (4) which normally appears in this nibble
  119.  * means "IP packet".
  120.  */
  121.  
  122. /* packet types */
  123. #define TYPE_IP 0x40
  124. #define TYPE_UNCOMPRESSED_TCP 0x70
  125. #define TYPE_COMPRESSED_TCP 0x80
  126. #define TYPE_ERROR 0x00
  127.  
  128. /* Bits in first octet of compressed packet */
  129. #define NEW_C    0x40    /* flag bits for what changed in a packet */
  130. #define NEW_I    0x20
  131. #define NEW_S    0x08
  132. #define NEW_A    0x04
  133. #define NEW_W    0x02
  134. #define NEW_U    0x01
  135.  
  136. /* reserved, special-case values of above */
  137. #define SPECIAL_I (NEW_S|NEW_W|NEW_U)        /* echoed interactive traffic */
  138. #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)    /* unidirectional data */
  139. #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
  140.  
  141. #define TCP_PUSH_BIT 0x10
  142.  
  143.  
  144. /*
  145.  * "state" data for each active tcp conversation on the wire.  This is
  146.  * basically a copy of the entire IP/TCP header from the last packet
  147.  * we saw from the conversation together with a small identifier
  148.  * the transmit & receive ends of the line use to locate saved header.
  149.  */
  150. struct cstate {
  151.     struct cstate *cs_next;    /* next most recently used cstate (xmit only) */
  152.     u_short cs_hlen;    /* size of hdr (receive only) */
  153.     u_char cs_id;        /* connection # associated with this state */
  154.     u_char cs_filler;
  155.     union {
  156.         char csu_hdr[MAX_HDR];
  157.         struct ip csu_ip;    /* ip/tcp hdr from most recent packet */
  158.     } slcs_u;
  159. };
  160. #define cs_ip slcs_u.csu_ip
  161. #define cs_hdr slcs_u.csu_hdr
  162.  
  163. /*
  164.  * all the state data for one serial line (we need one of these
  165.  * per line).
  166.  */
  167. struct slcompress {
  168.     struct cstate *last_cs;    /* most recently used tstate */
  169.     u_char last_recv;    /* last rcvd conn. id */
  170.     u_char last_xmit;    /* last sent conn. id */
  171.     u_short flags;
  172. #ifndef SL_NO_STATS
  173.     int sls_packets;    /* outbound packets */
  174.     int sls_compressed;    /* outbound compressed packets */
  175.     int sls_searches;    /* searches for connection state */
  176.     int sls_misses;        /* times couldn't find conn. state */
  177.     int sls_uncompressedin;    /* inbound uncompressed packets */
  178.     int sls_compressedin;    /* inbound compressed packets */
  179.     int sls_errorin;    /* inbound unknown type packets */
  180.     int sls_tossed;        /* inbound packets tossed because of error */
  181. #endif
  182.     struct cstate tstate[MAX_STATES];    /* xmit connection states */
  183.     struct cstate rstate[MAX_STATES];    /* receive connection states */
  184. };
  185. /* flag values */
  186. #define SLF_TOSS 1        /* tossing rcvd frames because of input err */
  187.  
  188. extern void sl_compress_init(/* struct slcompress * */);
  189. extern u_char sl_compress_tcp(/* struct mbuf *, struct ip *,
  190.                 struct slcompress *, int compress_cid_flag */);
  191. extern int sl_uncompress_tcp(/* u_char **, int,  u_char, struct slcompress * */);
  192.