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