slcompress.h revision 59005
11541Srgrimes/* 21541Srgrimes * Definitions for tcp compression routines. 31541Srgrimes * 41541Srgrimes * Copyright (c) 1989, 1993 51541Srgrimes * The Regents of the University of California. All rights reserved. 61541Srgrimes * 71541Srgrimes * Redistribution and use in source and binary forms, with or without 81541Srgrimes * modification, are permitted provided that the following conditions 91541Srgrimes * are met: 101541Srgrimes * 1. Redistributions of source code must retain the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer. 121541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 131541Srgrimes * notice, this list of conditions and the following disclaimer in the 141541Srgrimes * documentation and/or other materials provided with the distribution. 151541Srgrimes * 3. All advertising materials mentioning features or use of this software 161541Srgrimes * must display the following acknowledgement: 171541Srgrimes * This product includes software developed by the University of 181541Srgrimes * California, Berkeley and its contributors. 191541Srgrimes * 4. Neither the name of the University nor the names of its contributors 201541Srgrimes * may be used to endorse or promote products derived from this software 211541Srgrimes * without specific prior written permission. 221541Srgrimes * 231541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331541Srgrimes * SUCH DAMAGE. 341541Srgrimes * 351541Srgrimes * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 361541Srgrimes * - Initial distribution. 3750477Speter * $FreeBSD: head/sys/net/slcompress.h 59005 2000-04-04 09:20:53Z gj $ 381541Srgrimes */ 391541Srgrimes 402192Spaul#ifndef _NET_SLCOMPRESS_H_ 412168Spaul#define _NET_SLCOMPRESS_H_ 422168Spaul 431541Srgrimes#define MAX_STATES 16 /* must be > 2 and < 256 */ 4458982Sgj#define MAX_HDR 128 451541Srgrimes 461541Srgrimes/* 471541Srgrimes * Compressed packet format: 481541Srgrimes * 491541Srgrimes * The first octet contains the packet type (top 3 bits), TCP 501541Srgrimes * 'push' bit, and flags that indicate which of the 4 TCP sequence 511541Srgrimes * numbers have changed (bottom 5 bits). The next octet is a 521541Srgrimes * conversation number that associates a saved IP/TCP header with 531541Srgrimes * the compressed packet. The next two octets are the TCP checksum 541541Srgrimes * from the original datagram. The next 0 to 15 octets are 551541Srgrimes * sequence number changes, one change per bit set in the header 561541Srgrimes * (there may be no changes and there are two special cases where 571541Srgrimes * the receiver implicitly knows what changed -- see below). 588876Srgrimes * 591541Srgrimes * There are 5 numbers which can change (they are always inserted 601541Srgrimes * in the following order): TCP urgent pointer, window, 6113765Smpp * acknowledgement, sequence number and IP ID. (The urgent pointer 621541Srgrimes * is different from the others in that its value is sent, not the 631541Srgrimes * change in value.) Since typical use of SLIP links is biased 641541Srgrimes * toward small packets (see comments on MTU/MSS below), changes 651541Srgrimes * use a variable length coding with one octet for numbers in the 661541Srgrimes * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 671541Srgrimes * range 256 - 65535 or 0. (If the change in sequence number or 681541Srgrimes * ack is more than 65535, an uncompressed packet is sent.) 691541Srgrimes */ 701541Srgrimes 711541Srgrimes/* 721541Srgrimes * Packet types (must not conflict with IP protocol version) 731541Srgrimes * 741541Srgrimes * The top nibble of the first octet is the packet type. There are 751541Srgrimes * three possible types: IP (not proto TCP or tcp with one of the 761541Srgrimes * control flags set); uncompressed TCP (a normal IP/TCP packet but 771541Srgrimes * with the 8-bit protocol field replaced by an 8-bit connection id -- 781541Srgrimes * this type of packet syncs the sender & receiver); and compressed 791541Srgrimes * TCP (described above). 801541Srgrimes * 811541Srgrimes * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 821541Srgrimes * is logically part of the 4-bit "changes" field that follows. Top 831541Srgrimes * three bits are actual packet type. For backward compatibility 841541Srgrimes * and in the interest of conserving bits, numbers are chosen so the 851541Srgrimes * IP protocol version number (4) which normally appears in this nibble 861541Srgrimes * means "IP packet". 871541Srgrimes */ 881541Srgrimes 891541Srgrimes/* packet types */ 901541Srgrimes#define TYPE_IP 0x40 911541Srgrimes#define TYPE_UNCOMPRESSED_TCP 0x70 921541Srgrimes#define TYPE_COMPRESSED_TCP 0x80 931541Srgrimes#define TYPE_ERROR 0x00 941541Srgrimes 951541Srgrimes/* Bits in first octet of compressed packet */ 961541Srgrimes#define NEW_C 0x40 /* flag bits for what changed in a packet */ 971541Srgrimes#define NEW_I 0x20 981541Srgrimes#define NEW_S 0x08 991541Srgrimes#define NEW_A 0x04 1001541Srgrimes#define NEW_W 0x02 1011541Srgrimes#define NEW_U 0x01 1021541Srgrimes 1031541Srgrimes/* reserved, special-case values of above */ 1041541Srgrimes#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 1051541Srgrimes#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 1061541Srgrimes#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 1071541Srgrimes 1081541Srgrimes#define TCP_PUSH_BIT 0x10 1091541Srgrimes 1101541Srgrimes 1111541Srgrimes/* 1121541Srgrimes * "state" data for each active tcp conversation on the wire. This is 1131541Srgrimes * basically a copy of the entire IP/TCP header from the last packet 1141541Srgrimes * we saw from the conversation together with a small identifier 1151541Srgrimes * the transmit & receive ends of the line use to locate saved header. 1161541Srgrimes */ 1171541Srgrimesstruct cstate { 1181541Srgrimes struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 11928415Speter u_int16_t cs_hlen; /* size of hdr (receive only) */ 1201541Srgrimes u_char cs_id; /* connection # associated with this state */ 1211541Srgrimes u_char cs_filler; 12259005Sgj union { 12359005Sgj char csu_hdr[MAX_HDR]; 12459005Sgj struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 12559005Sgj } slcs_u; 1261541Srgrimes}; 12759005Sgj#define cs_ip slcs_u.csu_ip 12859005Sgj#define cs_hdr slcs_u.csu_hdr 1291541Srgrimes 1301541Srgrimes/* 1311541Srgrimes * all the state data for one serial line (we need one of these 1321541Srgrimes * per line). 1331541Srgrimes */ 1341541Srgrimesstruct slcompress { 1351541Srgrimes struct cstate *last_cs; /* most recently used tstate */ 1361541Srgrimes u_char last_recv; /* last rcvd conn. id */ 1371541Srgrimes u_char last_xmit; /* last sent conn. id */ 13828415Speter u_int16_t flags; 1391541Srgrimes#ifndef SL_NO_STATS 1401541Srgrimes int sls_packets; /* outbound packets */ 1411541Srgrimes int sls_compressed; /* outbound compressed packets */ 1421541Srgrimes int sls_searches; /* searches for connection state */ 1431541Srgrimes int sls_misses; /* times couldn't find conn. state */ 1441541Srgrimes int sls_uncompressedin; /* inbound uncompressed packets */ 1451541Srgrimes int sls_compressedin; /* inbound compressed packets */ 1461541Srgrimes int sls_errorin; /* inbound unknown type packets */ 1471541Srgrimes int sls_tossed; /* inbound packets tossed because of error */ 1481541Srgrimes#endif 1491541Srgrimes struct cstate tstate[MAX_STATES]; /* xmit connection states */ 1501541Srgrimes struct cstate rstate[MAX_STATES]; /* receive connection states */ 1511541Srgrimes}; 1521541Srgrimes/* flag values */ 1531541Srgrimes#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 1541541Srgrimes 15511964Spetervoid sl_compress_init __P((struct slcompress *, int)); 1561541Srgrimesu_int sl_compress_tcp __P((struct mbuf *, 1571541Srgrimes struct ip *, struct slcompress *, int)); 1582214Sbdeint sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *)); 15911964Speterint sl_uncompress_tcp_core __P((u_char *, int, int, u_int, 16011964Speter struct slcompress *, u_char **, u_int *)); 1612168Spaul 16212375Sbde#endif /* !_NET_SLCOMPRESS_H_ */ 163