slcompress.h revision 11964
1139825Simp/* slcompress.h 8.1 93/06/10 */ 21541Srgrimes/* 31549Srgrimes * Definitions for tcp compression routines. 41549Srgrimes * 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 * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341549Srgrimes * SUCH DAMAGE. 3550477Speter * 361541Srgrimes * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989: 371541Srgrimes * - Initial distribution. 38108599Sphk * $Id: slcompress.h,v 1.6 1995/05/30 08:08:34 rgrimes Exp $ 39108599Sphk */ 401541Srgrimes 41166550Sjhb#ifndef _NET_SLCOMPRESS_H_ 42166550Sjhb#define _NET_SLCOMPRESS_H_ 43166550Sjhb 44166550Sjhb#define MAX_STATES 16 /* must be > 2 and < 256 */ 45166550Sjhb#define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ 46166550Sjhb 47166550Sjhb/* 48166550Sjhb * Compressed packet format: 49166550Sjhb * 50166550Sjhb * The first octet contains the packet type (top 3 bits), TCP 51166550Sjhb * 'push' bit, and flags that indicate which of the 4 TCP sequence 52166550Sjhb * numbers have changed (bottom 5 bits). The next octet is a 53166550Sjhb * conversation number that associates a saved IP/TCP header with 54166550Sjhb * the compressed packet. The next two octets are the TCP checksum 55166550Sjhb * from the original datagram. The next 0 to 15 octets are 56166550Sjhb * sequence number changes, one change per bit set in the header 57166550Sjhb * (there may be no changes and there are two special cases where 58166550Sjhb * the receiver implicitly knows what changed -- see below). 59166550Sjhb * 60166550Sjhb * There are 5 numbers which can change (they are always inserted 61166550Sjhb * in the following order): TCP urgent pointer, window, 62166550Sjhb * acknowlegement, sequence number and IP ID. (The urgent pointer 63166550Sjhb * is different from the others in that its value is sent, not the 64166550Sjhb * change in value.) Since typical use of SLIP links is biased 65166550Sjhb * toward small packets (see comments on MTU/MSS below), changes 66166550Sjhb * use a variable length coding with one octet for numbers in the 67166550Sjhb * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 68166550Sjhb * range 256 - 65535 or 0. (If the change in sequence number or 69166550Sjhb * ack is more than 65535, an uncompressed packet is sent.) 70166550Sjhb */ 71248514Skib 72166550Sjhb/* 73166550Sjhb * Packet types (must not conflict with IP protocol version) 74108602Sphk * 75108602Sphk * The top nibble of the first octet is the packet type. There are 7611317Sdg * three possible types: IP (not proto TCP or tcp with one of the 77118390Sphk * control flags set); uncompressed TCP (a normal IP/TCP packet but 7810080Sbde * with the 8-bit protocol field replaced by an 8-bit connection id -- 79224582Skib * this type of packet syncs the sender & receiver); and compressed 80224582Skib * TCP (described above). 8192727Salfred * 8292727Salfred * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 8392727Salfred * is logically part of the 4-bit "changes" field that follows. Top 84118390Sphk * three bits are actual packet type. For backward compatibility 8592727Salfred * and in the interest of conserving bits, numbers are chosen so the 86117723Sphk * IP protocol version number (4) which normally appears in this nibble 87157628Spjd * means "IP packet". 8842957Sdillon */ 8992029Seivind 90108599Sphk/* packet types */ 91#define TYPE_IP 0x40 92#define TYPE_UNCOMPRESSED_TCP 0x70 93#define TYPE_COMPRESSED_TCP 0x80 94#define TYPE_ERROR 0x00 95 96/* Bits in first octet of compressed packet */ 97#define NEW_C 0x40 /* flag bits for what changed in a packet */ 98#define NEW_I 0x20 99#define NEW_S 0x08 100#define NEW_A 0x04 101#define NEW_W 0x02 102#define NEW_U 0x01 103 104/* reserved, special-case values of above */ 105#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 106#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 107#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 108 109#define TCP_PUSH_BIT 0x10 110 111 112/* 113 * "state" data for each active tcp conversation on the wire. This is 114 * basically a copy of the entire IP/TCP header from the last packet 115 * we saw from the conversation together with a small identifier 116 * the transmit & receive ends of the line use to locate saved header. 117 */ 118struct cstate { 119 struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 120 u_short cs_hlen; /* size of hdr (receive only) */ 121 u_char cs_id; /* connection # associated with this state */ 122 u_char cs_filler; 123 union { 124 char csu_hdr[MAX_HDR]; 125 struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 126 } slcs_u; 127}; 128#define cs_ip slcs_u.csu_ip 129#define cs_hdr slcs_u.csu_hdr 130 131/* 132 * all the state data for one serial line (we need one of these 133 * per line). 134 */ 135struct slcompress { 136 struct cstate *last_cs; /* most recently used tstate */ 137 u_char last_recv; /* last rcvd conn. id */ 138 u_char last_xmit; /* last sent conn. id */ 139 u_short flags; 140#ifndef SL_NO_STATS 141 int sls_packets; /* outbound packets */ 142 int sls_compressed; /* outbound compressed packets */ 143 int sls_searches; /* searches for connection state */ 144 int sls_misses; /* times couldn't find conn. state */ 145 int sls_uncompressedin; /* inbound uncompressed packets */ 146 int sls_compressedin; /* inbound compressed packets */ 147 int sls_errorin; /* inbound unknown type packets */ 148 int sls_tossed; /* inbound packets tossed because of error */ 149#endif 150 struct cstate tstate[MAX_STATES]; /* xmit connection states */ 151 struct cstate rstate[MAX_STATES]; /* receive connection states */ 152}; 153/* flag values */ 154#define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 155 156void sl_compress_init __P((struct slcompress *, int)); 157u_int sl_compress_tcp __P((struct mbuf *, 158 struct ip *, struct slcompress *, int)); 159int sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *)); 160int sl_uncompress_tcp_core __P((u_char *, int, int, u_int, 161 struct slcompress *, u_char **, u_int *)); 162 163#endif /* _NET_SLCOMPRESS_H_ */ 164