138369Skarels /* 238369Skarels * Definitions for tcp compression routines. 338369Skarels * 438369Skarels * Copyright (c) 1988, 1989 by Van Jacobson, Lawrence Berkeley Laboratory 538369Skarels * All rights reserved. 638369Skarels * 7*38378Skarels * $Header: slcompress.h,v 1.6 89/06/05 08:29:13 van Exp $ 838369Skarels */ 938369Skarels 1038369Skarels #define MAX_STATES 16 /* must be > 2 and < 256 */ 1138369Skarels #define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ 1238369Skarels 1338369Skarels /* 1438369Skarels * Compressed packet format: 1538369Skarels * 1638369Skarels * The first octet contains the packet type (top 3 bits), TCP 1738369Skarels * 'push' bit, and flags that indicate which of the 4 TCP sequence 1838369Skarels * numbers have changed (bottom 5 bits). The next octet is a 1938369Skarels * conversation number that associates a saved IP/TCP header with 2038369Skarels * the compressed packet. The next two octets are the TCP checksum 2138369Skarels * from the original datagram. The next 0 to 15 octets are 2238369Skarels * sequence number changes, one change per bit set in the header 2338369Skarels * (there may be no changes and there are two special cases where 2438369Skarels * the receiver implicitly knows what changed -- see below). 2538369Skarels * 2638369Skarels * There are 5 numbers which can change (they are always inserted 2738369Skarels * in the following order): TCP urgent pointer, window, 2838369Skarels * acknowlegement, sequence number and IP ID. (The urgent pointer 2938369Skarels * is different from the others in that its value is sent, not the 3038369Skarels * change in value.) Since typical use of SLIP links is biased 3138369Skarels * toward small packets (see comments on MTU/MSS below), changes 3238369Skarels * use a variable length coding with one octet for numbers in the 3338369Skarels * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the 3438369Skarels * range 256 - 65535 or 0. (If the change in sequence number or 3538369Skarels * ack is more than 65535, an uncompressed packet is sent.) 3638369Skarels */ 3738369Skarels 3838369Skarels /* 3938369Skarels * Packet types (must not conflict with IP protocol version) 4038369Skarels * 4138369Skarels * The top nibble of the first octet is the packet type. There are 4238369Skarels * three possible types: IP (not proto TCP or tcp with one of the 4338369Skarels * control flags set); uncompressed TCP (a normal IP/TCP packet but 4438369Skarels * with the 8-bit protocol field replaced by an 8-bit connection id -- 4538369Skarels * this type of packet syncs the sender & receiver); and compressed 4638369Skarels * TCP (described above). 4738369Skarels * 4838369Skarels * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and 4938369Skarels * is logically part of the 4-bit "changes" field that follows. Top 5038369Skarels * three bits are actual packet type. For backward compatibility 5138369Skarels * and in the interest of conserving bits, numbers are chosen so the 5238369Skarels * IP protocol version number (4) which normally appears in this nibble 5338369Skarels * means "IP packet". 5438369Skarels */ 5538369Skarels 5638369Skarels /* packet types */ 5738369Skarels #define TYPE_IP 0x40 58*38378Skarels #define TYPE_UNCOMPRESSED_TCP 0x70 5938369Skarels #define TYPE_COMPRESSED_TCP 0x80 6038369Skarels #define TYPE_ERROR 0x00 6138369Skarels 6238369Skarels /* Bits in first octet of compressed packet */ 6338369Skarels #define NEW_C 0x40 /* flag bits for what changed in a packet */ 6438369Skarels #define NEW_I 0x20 6538369Skarels #define NEW_S 0x08 6638369Skarels #define NEW_A 0x04 6738369Skarels #define NEW_W 0x02 6838369Skarels #define NEW_U 0x01 6938369Skarels 7038369Skarels /* reserved, special-case values of above */ 7138369Skarels #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ 7238369Skarels #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ 7338369Skarels #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) 7438369Skarels 7538369Skarels #define TCP_PUSH_BIT 0x10 7638369Skarels 7738369Skarels 7838369Skarels /* 7938369Skarels * "state" data for each active tcp conversation on the wire. This is 8038369Skarels * basically a copy of the entire IP/TCP header from the last packet 8138369Skarels * we saw from the conversation together with a small identifier 8238369Skarels * the transmit & receive ends of the line use to locate saved header. 8338369Skarels */ 8438369Skarels struct cstate { 8538369Skarels struct cstate *cs_next; /* next most recently used cstate (xmit only) */ 8638369Skarels u_short cs_hlen; /* size of hdr (receive only) */ 8738369Skarels u_char cs_id; /* connection # associated with this state */ 8838369Skarels u_char cs_filler; 8938369Skarels union { 9038369Skarels char hdr[MAX_HDR]; 9138369Skarels struct ip csu_ip; /* ip/tcp hdr from most recent packet */ 9238369Skarels } u; 9338369Skarels }; 9438369Skarels #define cs_ip u.csu_ip 9538369Skarels 9638369Skarels /* 9738369Skarels * all the state data for one serial line (we need one of these 9838369Skarels * per line). 9938369Skarels */ 10038369Skarels struct slcompress { 101*38378Skarels struct cstate *last_cs; /* most recently used tstate */ 102*38378Skarels u_char last_recv; /* last rcvd conn. id */ 103*38378Skarels u_char last_xmit; /* last sent conn. id */ 10438369Skarels u_short flags; 105*38378Skarels #ifndef NO_SL_STATS 106*38378Skarels int sls_packets; /* outbound packets */ 107*38378Skarels int sls_compressed; /* outbound compressed packets */ 108*38378Skarels int sls_searches; /* searches for connection state */ 109*38378Skarels int sls_misses; /* times couldn't find conn. state */ 110*38378Skarels int sls_uncompressedin; /* inbound uncompressed packets */ 111*38378Skarels int sls_compressedin; /* inbound compressed packets */ 112*38378Skarels int sls_errorin; /* inbound unknown type packets */ 113*38378Skarels int sls_tossed; /* inbound packets tossed because of error */ 114*38378Skarels #endif 11538369Skarels struct cstate tstate[MAX_STATES]; /* xmit connection states */ 11638369Skarels struct cstate rstate[MAX_STATES]; /* receive connection states */ 11738369Skarels }; 11838369Skarels /* flag values */ 11938369Skarels #define SLF_TOSS 1 /* tossing rcvd frames because of input err */ 12038369Skarels 12138369Skarels extern void sl_compress_init(/* struct slcompress * */); 12238369Skarels extern u_char sl_compress_tcp(/* struct mbuf *, struct ip *, struct slcompress * */); 123*38378Skarels extern int sl_uncompress_tcp(/* u_char **, int, u_char, struct slcompress * */); 124