slcompress.h revision 8876
1139790Simp/* slcompress.h 8.1 93/06/10 */ 225164Speter/* 325164Speter * Definitions for tcp compression routines. 425164Speter * 525164Speter * Copyright (c) 1989, 1993 625164Speter * The Regents of the University of California. All rights reserved. 725164Speter * 825164Speter * Redistribution and use in source and binary forms, with or without 925164Speter * modification, are permitted provided that the following conditions 1025164Speter * are met: 1125164Speter * 1. Redistributions of source code must retain the above copyright 1225164Speter * notice, this list of conditions and the following disclaimer. 1325164Speter * 2. Redistributions in binary form must reproduce the above copyright 1425164Speter * notice, this list of conditions and the following disclaimer in the 1525164Speter * documentation and/or other materials provided with the distribution. 1625164Speter * 3. All advertising materials mentioning features or use of this software 1725164Speter * must display the following acknowledgement: 1825164Speter * This product includes software developed by the University of 1925164Speter * California, Berkeley and its contributors. 2025164Speter * 4. Neither the name of the University nor the names of its contributors 2125164Speter * may be used to endorse or promote products derived from this software 2225164Speter * without specific prior written permission. 2325164Speter * 2425164Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2550477Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2625164Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2725164Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28214631Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29214631Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3025164Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3125164Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3225164Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3325164Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3425164Speter * SUCH DAMAGE. 3525164Speter * 36118953Sjhb * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 3725164Speter * - Initial distribution. 3825164Speter * $Id: slcompress.h,v 1.5 1994/08/22 14:16:36 bde Exp $ 39118953Sjhb */ 4025164Speter 4125164Speter#ifndef _NET_SLCOMPRESS_H_ 42119938Sjhb#define _NET_SLCOMPRESS_H_ 4325164Speter 4425164Speter#define MAX_STATES 16 /* must be > 2 and < 256 */ 4525164Speter#define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ 4625164Speter 4725164Speter/* 4825164Speter * Compressed packet format: 4925164Speter * 5025164Speter * The first octet contains the packet type (top 3 bits), TCP 5125164Speter * 'push' bit, and flags that indicate which of the 4 TCP sequence 5225164Speter * numbers have changed (bottom 5 bits). The next octet is a 5325164Speter * conversation number that associates a saved IP/TCP header with 5425164Speter * the compressed packet. The next two octets are the TCP checksum 5525164Speter * from the original datagram. The next 0 to 15 octets are 5625164Speter * sequence number changes, one change per bit set in the header 5725164Speter * (there may be no changes and there are two special cases where 5825164Speter * the receiver implicitly knows what changed -- see below). 5925164Speter * 6025164Speter * There are 5 numbers which can change (they are always inserted 6125164Speter * in the following order): TCP urgent pointer, window, 6225164Speter * acknowlegement, sequence number and IP ID. (The urgent pointer 6325164Speter * is different from the others in that its value is sent, not the 6425164Speter * change in value.) Since typical use of SLIP links is biased 6525164Speter * toward small packets (see comments on MTU/MSS below), changes 6625164Speter * use a variable length coding with one octet for numbers in the 6725164Speter * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 6825164Speter * range 256 - 65535 or 0. (If the change in sequence number or 6925164Speter * ack is more than 65535, an uncompressed packet is sent.) 7025164Speter */ 7125164Speter 7225164Speter/* 7325164Speter * Packet types (must not conflict with IP protocol version) 7425164Speter * 7525164Speter * The top nibble of the first octet is the packet type. There are 7625164Speter * three possible types: IP (not proto TCP or tcp with one of the 7725164Speter * control flags set); uncompressed TCP (a normal IP/TCP packet but 7825164Speter * with the 8-bit protocol field replaced by an 8-bit connection id -- 7925164Speter * this type of packet syncs the sender & receiver); and compressed 8025164Speter * TCP (described above). 8125164Speter * 8225164Speter * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 8325164Speter * is logically part of the 4-bit "changes" field that follows. Top 8425164Speter * three bits are actual packet type. For backward compatibility 8525164Speter * and in the interest of conserving bits, numbers are chosen so the 8625164Speter * IP protocol version number (4) which normally appears in this nibble 8725164Speter * means "IP packet". 8825164Speter */ 8925164Speter 9025164Speter/* packet types */ 9125164Speter#define TYPE_IP 0x40 92208507Sjhb#define TYPE_UNCOMPRESSED_TCP 0x70 9325164Speter#define TYPE_COMPRESSED_TCP 0x80 9425164Speter#define TYPE_ERROR 0x00 9525164Speter 96115905Sjhb/* Bits in first octet of compressed packet */ 97115905Sjhb#define NEW_C 0x40 /* flag bits for what changed in a packet */ 9825164Speter#define NEW_I 0x20 9925164Speter#define NEW_S 0x08 10025164Speter#define NEW_A 0x04 10125164Speter#define NEW_W 0x02 10225164Speter#define NEW_U 0x01 10325164Speter 10425164Speter/* reserved, special-case values of above */ 10525164Speter#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 10625164Speter#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 10725164Speter#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 10825164Speter 10925164Speter#define TCP_PUSH_BIT 0x10 11025164Speter 11125164Speter 11225164Speter/* 11325164Speter * "state" data for each active tcp conversation on the wire. This is 11425164Speter * basically a copy of the entire IP/TCP header from the last packet 11525164Speter * we saw from the conversation together with a small identifier 11625164Speter * the transmit & receive ends of the line use to locate saved header. 11725164Speter */ 11826269Sfsmpstruct cstate { 11926269Sfsmp struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 12026269Sfsmp u_short cs_hlen; /* size of hdr (receive only) */ 12126269Sfsmp u_char cs_id; /* connection # associated with this state */ 12226269Sfsmp u_char cs_filler; 12326269Sfsmp union { 12426269Sfsmp char csu_hdr[MAX_HDR]; 12526269Sfsmp struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 12626269Sfsmp } slcs_u; 12726269Sfsmp}; 12826269Sfsmp#define cs_ip slcs_u.csu_ip 12926269Sfsmp#define cs_hdr slcs_u.csu_hdr 13026269Sfsmp 13126269Sfsmp/* 13226269Sfsmp * all the state data for one serial line (we need one of these 13326269Sfsmp * per line). 13426269Sfsmp */ 13526269Sfsmpstruct slcompress { 13626269Sfsmp struct cstate *last_cs; /* most recently used tstate */ 13726269Sfsmp u_char last_recv; /* last rcvd conn. id */ 13826269Sfsmp u_char last_xmit; /* last sent conn. id */ 13926269Sfsmp u_short flags; 14026269Sfsmp#ifndef SL_NO_STATS 14126269Sfsmp int sls_packets; /* outbound packets */ 14226269Sfsmp int sls_compressed; /* outbound compressed packets */ 14326269Sfsmp int sls_searches; /* searches for connection state */ 14426269Sfsmp int sls_misses; /* times couldn't find conn. state */ 14526269Sfsmp int sls_uncompressedin; /* inbound uncompressed packets */ 14626269Sfsmp int sls_compressedin; /* inbound compressed packets */ 14726269Sfsmp int sls_errorin; /* inbound unknown type packets */ 14826269Sfsmp int sls_tossed; /* inbound packets tossed because of error */ 14926269Sfsmp#endif 15026269Sfsmp struct cstate tstate[MAX_STATES]; /* xmit connection states */ 15126269Sfsmp struct cstate rstate[MAX_STATES]; /* receive connection states */ 15226269Sfsmp}; 15326269Sfsmp/* flag values */ 15426269Sfsmp#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 15526269Sfsmp 15626269Sfsmpvoid sl_compress_init __P((struct slcompress *)); 15726269Sfsmpu_int sl_compress_tcp __P((struct mbuf *, 15826269Sfsmp struct ip *, struct slcompress *, int)); 15926269Sfsmpint sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *)); 16026269Sfsmp 16126269Sfsmp#endif /* !_NET_SLCOMPRESS_H_ */ 16226269Sfsmp