175115Sfenner/*
275115Sfenner * Definitions for tcp compression routines.
375115Sfenner *
4190207Srpaulo * @(#) $Header: /tcpdump/master/tcpdump/slcompress.h,v 1.2 2000-10-09 02:03:44 guy Exp $ (LBL)
575115Sfenner *
675115Sfenner * Copyright (c) 1989, 1990, 1992, 1993 Regents of the University of
775115Sfenner * California. All rights reserved.
875115Sfenner *
975115Sfenner * Redistribution and use in source and binary forms are permitted
1075115Sfenner * provided that the above copyright notice and this paragraph are
1175115Sfenner * duplicated in all such forms and that any documentation,
1275115Sfenner * advertising materials, and other materials related to such
1375115Sfenner * distribution and use acknowledge that the software was developed
1475115Sfenner * by the University of California, Berkeley.  The name of the
1575115Sfenner * University may not be used to endorse or promote products derived
1675115Sfenner * from this software without specific prior written permission.
1775115Sfenner * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1875115Sfenner * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1975115Sfenner * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2075115Sfenner *
2175115Sfenner *	Van Jacobson (van@ee.lbl.gov), Dec 31, 1989:
2275115Sfenner *	- Initial distribution.
2375115Sfenner */
2475115Sfenner
2575115Sfenner/*
2675115Sfenner * Compressed packet format:
2775115Sfenner *
2875115Sfenner * The first octet contains the packet type (top 3 bits), TCP
2975115Sfenner * 'push' bit, and flags that indicate which of the 4 TCP sequence
3075115Sfenner * numbers have changed (bottom 5 bits).  The next octet is a
3175115Sfenner * conversation number that associates a saved IP/TCP header with
3275115Sfenner * the compressed packet.  The next two octets are the TCP checksum
3375115Sfenner * from the original datagram.  The next 0 to 15 octets are
3475115Sfenner * sequence number changes, one change per bit set in the header
3575115Sfenner * (there may be no changes and there are two special cases where
3675115Sfenner * the receiver implicitly knows what changed -- see below).
3775115Sfenner *
3875115Sfenner * There are 5 numbers which can change (they are always inserted
3975115Sfenner * in the following order): TCP urgent pointer, window,
4075115Sfenner * acknowlegement, sequence number and IP ID.  (The urgent pointer
4175115Sfenner * is different from the others in that its value is sent, not the
4275115Sfenner * change in value.)  Since typical use of SLIP links is biased
4375115Sfenner * toward small packets (see comments on MTU/MSS below), changes
4475115Sfenner * use a variable length coding with one octet for numbers in the
4575115Sfenner * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
4675115Sfenner * range 256 - 65535 or 0.  (If the change in sequence number or
4775115Sfenner * ack is more than 65535, an uncompressed packet is sent.)
4875115Sfenner */
4975115Sfenner
5075115Sfenner/*
5175115Sfenner * Packet types (must not conflict with IP protocol version)
5275115Sfenner *
5375115Sfenner * The top nibble of the first octet is the packet type.  There are
5475115Sfenner * three possible types: IP (not proto TCP or tcp with one of the
5575115Sfenner * control flags set); uncompressed TCP (a normal IP/TCP packet but
5675115Sfenner * with the 8-bit protocol field replaced by an 8-bit connection id --
5775115Sfenner * this type of packet syncs the sender & receiver); and compressed
5875115Sfenner * TCP (described above).
5975115Sfenner *
6075115Sfenner * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
6175115Sfenner * is logically part of the 4-bit "changes" field that follows.  Top
6275115Sfenner * three bits are actual packet type.  For backward compatibility
6375115Sfenner * and in the interest of conserving bits, numbers are chosen so the
6475115Sfenner * IP protocol version number (4) which normally appears in this nibble
6575115Sfenner * means "IP packet".
6675115Sfenner */
6775115Sfenner
6875115Sfenner/* packet types */
6975115Sfenner#define TYPE_IP 0x40
7075115Sfenner#define TYPE_UNCOMPRESSED_TCP 0x70
7175115Sfenner#define TYPE_COMPRESSED_TCP 0x80
7275115Sfenner#define TYPE_ERROR 0x00
7375115Sfenner
7475115Sfenner/* Bits in first octet of compressed packet */
7575115Sfenner#define NEW_C	0x40	/* flag bits for what changed in a packet */
7675115Sfenner#define NEW_I	0x20
7775115Sfenner#define NEW_S	0x08
7875115Sfenner#define NEW_A	0x04
7975115Sfenner#define NEW_W	0x02
8075115Sfenner#define NEW_U	0x01
8175115Sfenner
8275115Sfenner/* reserved, special-case values of above */
8375115Sfenner#define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
8475115Sfenner#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
8575115Sfenner#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
8675115Sfenner
8775115Sfenner#define TCP_PUSH_BIT 0x10
88