11739Ssundar/* 21739Ssundar * Definitions for tcp compression routines. 31739Ssundar * 41739Ssundar * Copyright (c) 1989, 1993 51739Ssundar * The Regents of the University of California. All rights reserved. 61739Ssundar * 71739Ssundar * Redistribution and use in source and binary forms, with or without 81739Ssundar * modification, are permitted provided that the following conditions 91739Ssundar * are met: 101739Ssundar * 1. Redistributions of source code must retain the above copyright 111739Ssundar * notice, this list of conditions and the following disclaimer. 121739Ssundar * 2. Redistributions in binary form must reproduce the above copyright 131739Ssundar * notice, this list of conditions and the following disclaimer in the 141739Ssundar * documentation and/or other materials provided with the distribution. 151739Ssundar * 3. Neither the name of the University nor the names of its contributors 161739Ssundar * may be used to endorse or promote products derived from this software 171739Ssundar * without specific prior written permission. 181739Ssundar * 191739Ssundar * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201739Ssundar * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211739Ssundar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221739Ssundar * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231739Ssundar * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241739Ssundar * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251739Ssundar * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261739Ssundar * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271739Ssundar * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281739Ssundar * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291739Ssundar * SUCH DAMAGE. 301739Ssundar * 311739Ssundar * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 321739Ssundar * - Initial distribution. 331739Ssundar * 341739Ssundar * $FreeBSD$ 351739Ssundar */ 361739Ssundar 371739Ssundar#define MIN_VJ_STATES 3 381739Ssundar#define MAX_VJ_STATES 255 391739Ssundar#define DEF_VJ_STATES 16 /* must be > 2 and < 256 */ 401739Ssundar#define MAX_HDR 128 411739Ssundar 421739Ssundar/* 431739Ssundar * Compressed packet format: 441739Ssundar * 451739Ssundar * The first octet contains the packet type (top 3 bits), TCP 461739Ssundar * 'push' bit, and flags that indicate which of the 4 TCP sequence 471739Ssundar * numbers have changed (bottom 5 bits). The next octet is a 481739Ssundar * conversation number that associates a saved IP/TCP header with 491739Ssundar * the compressed packet. The next two octets are the TCP checksum 501739Ssundar * from the original datagram. The next 0 to 15 octets are 511739Ssundar * sequence number changes, one change per bit set in the header 521739Ssundar * (there may be no changes and there are two special cases where 531739Ssundar * the receiver implicitly knows what changed -- see below). 541739Ssundar * 551739Ssundar * There are 5 numbers which can change (they are always inserted 561739Ssundar * in the following order): TCP urgent pointer, window, 571739Ssundar * acknowlegement, sequence number and IP ID. (The urgent pointer 581739Ssundar * is different from the others in that its value is sent, not the 591739Ssundar * change in value.) Since typical use of SLIP links is biased 601739Ssundar * toward small packets (see comments on MTU/MSS below), changes 611739Ssundar * use a variable length coding with one octet for numbers in the 621739Ssundar * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 631739Ssundar * range 256 - 65535 or 0. (If the change in sequence number or 641739Ssundar * ack is more than 65535, an uncompressed packet is sent.) 651739Ssundar */ 661739Ssundar 671739Ssundar/* 681739Ssundar * Packet types (must not conflict with IP protocol version) 691739Ssundar * 701739Ssundar * The top nibble of the first octet is the packet type. There are 711739Ssundar * three possible types: IP (not proto TCP or tcp with one of the 721739Ssundar * control flags set); uncompressed TCP (a normal IP/TCP packet but 731739Ssundar * with the 8-bit protocol field replaced by an 8-bit connection id -- 741739Ssundar * this type of packet syncs the sender & receiver); and compressed 751739Ssundar * TCP (described above). 761739Ssundar * 771739Ssundar * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 781739Ssundar * is logically part of the 4-bit "changes" field that follows. Top 791739Ssundar * three bits are actual packet type. For backward compatibility 801739Ssundar * and in the interest of conserving bits, numbers are chosen so the 811739Ssundar * IP protocol version number (4) which normally appears in this nibble 821739Ssundar * means "IP packet". 831739Ssundar */ 841739Ssundar 851739Ssundar/* packet types */ 861739Ssundar#define TYPE_IP 0x40 871739Ssundar#define TYPE_UNCOMPRESSED_TCP 0x70 881739Ssundar#define TYPE_COMPRESSED_TCP 0x80 891739Ssundar#define TYPE_ERROR 0x00 901739Ssundar 911739Ssundar/* Bits in first octet of compressed packet */ 921739Ssundar#define NEW_C 0x40 /* flag bits for what changed in a packet */ 931739Ssundar#define NEW_I 0x20 941739Ssundar#define NEW_S 0x08 951739Ssundar#define NEW_A 0x04 961739Ssundar#define NEW_W 0x02 971739Ssundar#define NEW_U 0x01 981739Ssundar 991739Ssundar/* reserved, special-case values of above */ 1001739Ssundar#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 1011739Ssundar#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 1021739Ssundar#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 1031739Ssundar 1041739Ssundar#define TCP_PUSH_BIT 0x10 1051739Ssundar 1061739Ssundar/* 1071739Ssundar * "state" data for each active tcp conversation on the wire. This is 1081739Ssundar * basically a copy of the entire IP/TCP header from the last packet 1091739Ssundar * we saw from the conversation together with a small identifier 1101739Ssundar * the transmit & receive ends of the line use to locate saved header. 1111739Ssundar */ 1121739Ssundarstruct cstate { 1131739Ssundar struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 1141739Ssundar u_short cs_hlen; /* size of hdr (receive only) */ 1151739Ssundar u_char cs_id; /* connection # associated with this state */ 1161739Ssundar u_char cs_filler; 1171739Ssundar union { 1181739Ssundar char csu_hdr[MAX_HDR]; 1191739Ssundar struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 1201739Ssundar } slcs_u; 1211739Ssundar}; 1221739Ssundar 1231739Ssundar#define cs_ip slcs_u.csu_ip 1241739Ssundar#define cs_hdr slcs_u.csu_hdr 1251739Ssundar 1261739Ssundar/* 1271739Ssundar * all the state data for one serial line (we need one of these 1281739Ssundar * per line). 1291739Ssundar */ 1301739Ssundarstruct slcompress { 1311739Ssundar struct cstate *last_cs; /* most recently used tstate */ 1321739Ssundar u_char last_recv; /* last rcvd conn. id */ 1331739Ssundar u_char last_xmit; /* last sent conn. id */ 1341739Ssundar u_short flags; 1351739Ssundar struct cstate tstate[MAX_VJ_STATES]; /* xmit connection states */ 1361739Ssundar struct cstate rstate[MAX_VJ_STATES]; /* receive connection states */ 1371739Ssundar}; 1381739Ssundar 1391739Ssundarstruct slstat { 1401739Ssundar int sls_packets; /* outbound packets */ 1411739Ssundar int sls_compressed; /* outbound compressed packets */ 1421739Ssundar int sls_searches; /* searches for connection state */ 1431739Ssundar int sls_misses; /* times couldn't find conn. state */ 1441739Ssundar int sls_uncompressedin; /* inbound uncompressed packets */ 1451739Ssundar int sls_compressedin; /* inbound compressed packets */ 1461739Ssundar int sls_errorin; /* inbound unknown type packets */ 1471739Ssundar int sls_tossed; /* inbound packets tossed because of error */ 1481739Ssundar}; 1491739Ssundar 1501739Ssundar/* flag values */ 1511739Ssundar#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 1521739Ssundar 1531739Ssundarstruct mbuf; 1541739Ssundarstruct cmdargs; 1551739Ssundar 1561739Ssundarextern void sl_compress_init(struct slcompress *, int); 1571739Ssundarextern u_char sl_compress_tcp(struct mbuf *, struct ip *, struct slcompress *, 1581739Ssundar struct slstat *, int); 1591739Ssundarextern int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *, 1601739Ssundar struct slstat *, int); 1611739Ssundarextern int sl_Show(struct cmdargs const *); 1621739Ssundar