156893Sfenner/*
256893Sfenner * Definitions for tcp compression routines.
356893Sfenner *
456893Sfenner * Copyright (c) 1989, 1990, 1992, 1993 Regents of the University of
5127668Sbms * California. All rights reserved.
656893Sfenner *
756893Sfenner * Redistribution and use in source and binary forms are permitted
856893Sfenner * provided that the above copyright notice and this paragraph are
9127668Sbms * duplicated in all such forms and that any documentation,
1056893Sfenner * advertising materials, and other materials related to such
1156893Sfenner * distribution and use acknowledge that the software was developed
12127668Sbms * by the University of California, Berkeley.  The name of the
1356893Sfenner * University may not be used to endorse or promote products derived
1456893Sfenner * from this software without specific prior written permission.
1556893Sfenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16127668Sbms * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1756893Sfenner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1856893Sfenner *
1956893Sfenner *	Van Jacobson (van@ee.lbl.gov), Dec 31, 1989:
2056893Sfenner *	- Initial distribution.
21127668Sbms */
2256893Sfenner
2356893Sfenner/*
2456893Sfenner * Compressed packet format:
25127668Sbms *
2656893Sfenner * The first octet contains the packet type (top 3 bits), TCP
2756893Sfenner * 'push' bit, and flags that indicate which of the 4 TCP sequence
2856893Sfenner * numbers have changed (bottom 5 bits).  The next octet is a
2956893Sfenner * conversation number that associates a saved IP/TCP header with
3056893Sfenner * the compressed packet.  The next two octets are the TCP checksum
3156893Sfenner * from the original datagram.  The next 0 to 15 octets are
3256893Sfenner * sequence number changes, one change per bit set in the header
3356893Sfenner * (there may be no changes and there are two special cases where
3456893Sfenner * the receiver implicitly knows what changed -- see below).
3556893Sfenner *
3656893Sfenner * There are 5 numbers which can change (they are always inserted
3756893Sfenner * in the following order): TCP urgent pointer, window,
3856893Sfenner * acknowledgement, sequence number and IP ID.  (The urgent pointer
39127668Sbms * is different from the others in that its value is sent, not the
4056893Sfenner * change in value.)  Since typical use of SLIP links is biased
4156893Sfenner * toward small packets (see comments on MTU/MSS below), changes
42127668Sbms * use a variable length coding with one octet for numbers in the
43127668Sbms * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
4456893Sfenner * range 256 - 65535 or 0.  (If the change in sequence number or
4556893Sfenner * ack is more than 65535, an uncompressed packet is sent.)
46127668Sbms */
4756893Sfenner
4856893Sfenner/*
4956893Sfenner * Packet types (must not conflict with IP protocol version)
5056893Sfenner *
5156893Sfenner * The top nibble of the first octet is the packet type.  There are
5256893Sfenner * three possible types: IP (not proto TCP or tcp with one of the
5356893Sfenner * control flags set); uncompressed TCP (a normal IP/TCP packet but
5456893Sfenner * with the 8-bit protocol field replaced by an 8-bit connection id --
5556893Sfenner * this type of packet syncs the sender & receiver); and compressed
5656893Sfenner * TCP (described above).
5756893Sfenner *
5856893Sfenner * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
5956893Sfenner * is logically part of the 4-bit "changes" field that follows.  Top
6056893Sfenner * three bits are actual packet type.  For backward compatibility
61 * and in the interest of conserving bits, numbers are chosen so the
62 * IP protocol version number (4) which normally appears in this nibble
63 * means "IP packet".
64 */
65
66/* packet types */
67#define TYPE_IP 0x40
68#define TYPE_UNCOMPRESSED_TCP 0x70
69#define TYPE_COMPRESSED_TCP 0x80
70#define TYPE_ERROR 0x00
71
72/* Bits in first octet of compressed packet */
73#define NEW_C	0x40	/* flag bits for what changed in a packet */
74#define NEW_I	0x20
75#define NEW_S	0x08
76#define NEW_A	0x04
77#define NEW_W	0x02
78#define NEW_U	0x01
79
80/* reserved, special-case values of above */
81#define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
82#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
83#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
84
85#define TCP_PUSH_BIT 0x10
86