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