slcompress.h revision 22975
129088Smarkm/* slcompress.h 8.1 93/06/10 */ 229088Smarkm/* 329088Smarkm * Definitions for tcp compression routines. 429088Smarkm * 529088Smarkm * Copyright (c) 1989, 1993 629088Smarkm * The Regents of the University of California. All rights reserved. 729088Smarkm * 829088Smarkm * Redistribution and use in source and binary forms, with or without 929088Smarkm * modification, are permitted provided that the following conditions 1029088Smarkm * are met: 1129088Smarkm * 1. Redistributions of source code must retain the above copyright 1229088Smarkm * notice, this list of conditions and the following disclaimer. 1329088Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1429088Smarkm * notice, this list of conditions and the following disclaimer in the 1529088Smarkm * documentation and/or other materials provided with the distribution. 1629088Smarkm * 3. All advertising materials mentioning features or use of this software 1729088Smarkm * must display the following acknowledgement: 1829088Smarkm * This product includes software developed by the University of 1929088Smarkm * California, Berkeley and its contributors. 2029088Smarkm * 4. Neither the name of the University nor the names of its contributors 2129088Smarkm * may be used to endorse or promote products derived from this software 2229088Smarkm * without specific prior written permission. 2329088Smarkm * 2429088Smarkm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2529088Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2629088Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2729088Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2829088Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2929088Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3029088Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3129088Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3229088Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3329088Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3429088Smarkm * SUCH DAMAGE. 3529181Smarkm * 3629088Smarkm * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 3729088Smarkm * - Initial distribution. 3829088Smarkm * $Id$ 3929088Smarkm */ 4029088Smarkm 4129088Smarkm#ifndef _NET_SLCOMPRESS_H_ 4229088Smarkm#define _NET_SLCOMPRESS_H_ 4329088Smarkm 4429088Smarkm#define MAX_STATES 16 /* must be > 2 and < 256 */ 4529088Smarkm#define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ 4629181Smarkm 4729181Smarkm/* 4829181Smarkm * Compressed packet format: 4929181Smarkm * 5029088Smarkm * The first octet contains the packet type (top 3 bits), TCP 5129088Smarkm * 'push' bit, and flags that indicate which of the 4 TCP sequence 5229088Smarkm * numbers have changed (bottom 5 bits). The next octet is a 5329088Smarkm * conversation number that associates a saved IP/TCP header with 5429088Smarkm * the compressed packet. The next two octets are the TCP checksum 5529088Smarkm * from the original datagram. The next 0 to 15 octets are 5629088Smarkm * sequence number changes, one change per bit set in the header 5729088Smarkm * (there may be no changes and there are two special cases where 5829088Smarkm * the receiver implicitly knows what changed -- see below). 5929088Smarkm * 6029088Smarkm * There are 5 numbers which can change (they are always inserted 6129088Smarkm * in the following order): TCP urgent pointer, window, 6229088Smarkm * acknowledgement, sequence number and IP ID. (The urgent pointer 6329088Smarkm * is different from the others in that its value is sent, not the 6429088Smarkm * change in value.) Since typical use of SLIP links is biased 6529088Smarkm * toward small packets (see comments on MTU/MSS below), changes 6629088Smarkm * use a variable length coding with one octet for numbers in the 6729088Smarkm * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 6829088Smarkm * range 256 - 65535 or 0. (If the change in sequence number or 6929088Smarkm * ack is more than 65535, an uncompressed packet is sent.) 7029088Smarkm */ 7129088Smarkm 7229088Smarkm/* 7329088Smarkm * Packet types (must not conflict with IP protocol version) 7429088Smarkm * 7529088Smarkm * The top nibble of the first octet is the packet type. There are 7629088Smarkm * three possible types: IP (not proto TCP or tcp with one of the 7729088Smarkm * control flags set); uncompressed TCP (a normal IP/TCP packet but 7829088Smarkm * with the 8-bit protocol field replaced by an 8-bit connection id -- 7929088Smarkm * this type of packet syncs the sender & receiver); and compressed 8029088Smarkm * TCP (described above). 8129088Smarkm * 8229088Smarkm * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 8329088Smarkm * is logically part of the 4-bit "changes" field that follows. Top 8429088Smarkm * three bits are actual packet type. For backward compatibility 8529088Smarkm * and in the interest of conserving bits, numbers are chosen so the 8629088Smarkm * IP protocol version number (4) which normally appears in this nibble 8729088Smarkm * means "IP packet". 8829088Smarkm */ 8929088Smarkm 9029088Smarkm/* packet types */ 9129088Smarkm#define TYPE_IP 0x40 9229088Smarkm#define TYPE_UNCOMPRESSED_TCP 0x70 9329088Smarkm#define TYPE_COMPRESSED_TCP 0x80 9429088Smarkm#define TYPE_ERROR 0x00 9529088Smarkm 9629088Smarkm/* Bits in first octet of compressed packet */ 9729088Smarkm#define NEW_C 0x40 /* flag bits for what changed in a packet */ 9829088Smarkm#define NEW_I 0x20 9929088Smarkm#define NEW_S 0x08 10029088Smarkm#define NEW_A 0x04 10129088Smarkm#define NEW_W 0x02 10229088Smarkm#define NEW_U 0x01 10329088Smarkm 10429088Smarkm/* reserved, special-case values of above */ 10529088Smarkm#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 10629088Smarkm#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 10729088Smarkm#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 10829088Smarkm 10929088Smarkm#define TCP_PUSH_BIT 0x10 11029088Smarkm 11129088Smarkm 11229088Smarkm/* 11329088Smarkm * "state" data for each active tcp conversation on the wire. This is 11429088Smarkm * basically a copy of the entire IP/TCP header from the last packet 11529088Smarkm * we saw from the conversation together with a small identifier 11629088Smarkm * the transmit & receive ends of the line use to locate saved header. 11729088Smarkm */ 11829088Smarkmstruct cstate { 11929088Smarkm struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 12029088Smarkm u_short cs_hlen; /* size of hdr (receive only) */ 12129088Smarkm u_char cs_id; /* connection # associated with this state */ 12229088Smarkm u_char cs_filler; 12329088Smarkm union { 12429088Smarkm char csu_hdr[MAX_HDR]; 12529088Smarkm struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 12629088Smarkm } slcs_u; 12729088Smarkm}; 12829088Smarkm#define cs_ip slcs_u.csu_ip 12929088Smarkm#define cs_hdr slcs_u.csu_hdr 13029088Smarkm 13129088Smarkm/* 13229088Smarkm * all the state data for one serial line (we need one of these 13329088Smarkm * per line). 13429088Smarkm */ 13529088Smarkmstruct slcompress { 13629088Smarkm struct cstate *last_cs; /* most recently used tstate */ 13729088Smarkm u_char last_recv; /* last rcvd conn. id */ 13829088Smarkm u_char last_xmit; /* last sent conn. id */ 13929088Smarkm u_short flags; 14029088Smarkm#ifndef SL_NO_STATS 14129088Smarkm int sls_packets; /* outbound packets */ 14229088Smarkm int sls_compressed; /* outbound compressed packets */ 14329088Smarkm int sls_searches; /* searches for connection state */ 14429088Smarkm int sls_misses; /* times couldn't find conn. state */ 14529088Smarkm int sls_uncompressedin; /* inbound uncompressed packets */ 14629088Smarkm int sls_compressedin; /* inbound compressed packets */ 14729088Smarkm int sls_errorin; /* inbound unknown type packets */ 14829088Smarkm int sls_tossed; /* inbound packets tossed because of error */ 14929088Smarkm#endif 15029088Smarkm struct cstate tstate[MAX_STATES]; /* xmit connection states */ 15129088Smarkm struct cstate rstate[MAX_STATES]; /* receive connection states */ 15229088Smarkm}; 15329088Smarkm/* flag values */ 15429088Smarkm#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 15529088Smarkm 15629088Smarkmvoid sl_compress_init __P((struct slcompress *, int)); 15729088Smarkmu_int sl_compress_tcp __P((struct mbuf *, 15829088Smarkm struct ip *, struct slcompress *, int)); 15929088Smarkmint sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *)); 16029088Smarkmint sl_uncompress_tcp_core __P((u_char *, int, int, u_int, 16129088Smarkm struct slcompress *, u_char **, u_int *)); 16229088Smarkm 16329088Smarkm#endif /* !_NET_SLCOMPRESS_H_ */ 16429088Smarkm