xref: /aosp_15_r20/external/tcpdump/slcompress.h (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*
2*05b00f60SXin Li  * Definitions for tcp compression routines.
3*05b00f60SXin Li  *
4*05b00f60SXin Li  * Copyright (c) 1989, 1990, 1992, 1993 Regents of the University of
5*05b00f60SXin Li  * California. All rights reserved.
6*05b00f60SXin Li  *
7*05b00f60SXin Li  * Redistribution and use in source and binary forms are permitted
8*05b00f60SXin Li  * provided that the above copyright notice and this paragraph are
9*05b00f60SXin Li  * duplicated in all such forms and that any documentation,
10*05b00f60SXin Li  * advertising materials, and other materials related to such
11*05b00f60SXin Li  * distribution and use acknowledge that the software was developed
12*05b00f60SXin Li  * by the University of California, Berkeley.  The name of the
13*05b00f60SXin Li  * University may not be used to endorse or promote products derived
14*05b00f60SXin Li  * from this software without specific prior written permission.
15*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16*05b00f60SXin Li  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17*05b00f60SXin Li  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18*05b00f60SXin Li  *
19*05b00f60SXin Li  *	Van Jacobson ([email protected]), Dec 31, 1989:
20*05b00f60SXin Li  *	- Initial distribution.
21*05b00f60SXin Li  */
22*05b00f60SXin Li 
23*05b00f60SXin Li /*
24*05b00f60SXin Li  * Compressed packet format:
25*05b00f60SXin Li  *
26*05b00f60SXin Li  * The first octet contains the packet type (top 3 bits), TCP
27*05b00f60SXin Li  * 'push' bit, and flags that indicate which of the 4 TCP sequence
28*05b00f60SXin Li  * numbers have changed (bottom 5 bits).  The next octet is a
29*05b00f60SXin Li  * conversation number that associates a saved IP/TCP header with
30*05b00f60SXin Li  * the compressed packet.  The next two octets are the TCP checksum
31*05b00f60SXin Li  * from the original datagram.  The next 0 to 15 octets are
32*05b00f60SXin Li  * sequence number changes, one change per bit set in the header
33*05b00f60SXin Li  * (there may be no changes and there are two special cases where
34*05b00f60SXin Li  * the receiver implicitly knows what changed -- see below).
35*05b00f60SXin Li  *
36*05b00f60SXin Li  * There are 5 numbers which can change (they are always inserted
37*05b00f60SXin Li  * in the following order): TCP urgent pointer, window,
38*05b00f60SXin Li  * acknowledgement, sequence number and IP ID.  (The urgent pointer
39*05b00f60SXin Li  * is different from the others in that its value is sent, not the
40*05b00f60SXin Li  * change in value.)  Since typical use of SLIP links is biased
41*05b00f60SXin Li  * toward small packets (see comments on MTU/MSS below), changes
42*05b00f60SXin Li  * use a variable length coding with one octet for numbers in the
43*05b00f60SXin Li  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
44*05b00f60SXin Li  * range 256 - 65535 or 0.  (If the change in sequence number or
45*05b00f60SXin Li  * ack is more than 65535, an uncompressed packet is sent.)
46*05b00f60SXin Li  */
47*05b00f60SXin Li 
48*05b00f60SXin Li /*
49*05b00f60SXin Li  * Packet types (must not conflict with IP protocol version)
50*05b00f60SXin Li  *
51*05b00f60SXin Li  * The top nibble of the first octet is the packet type.  There are
52*05b00f60SXin Li  * three possible types: IP (not proto TCP or tcp with one of the
53*05b00f60SXin Li  * control flags set); uncompressed TCP (a normal IP/TCP packet but
54*05b00f60SXin Li  * with the 8-bit protocol field replaced by an 8-bit connection id --
55*05b00f60SXin Li  * this type of packet syncs the sender & receiver); and compressed
56*05b00f60SXin Li  * TCP (described above).
57*05b00f60SXin Li  *
58*05b00f60SXin Li  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
59*05b00f60SXin Li  * is logically part of the 4-bit "changes" field that follows.  Top
60*05b00f60SXin Li  * three bits are actual packet type.  For backward compatibility
61*05b00f60SXin Li  * and in the interest of conserving bits, numbers are chosen so the
62*05b00f60SXin Li  * IP protocol version number (4) which normally appears in this nibble
63*05b00f60SXin Li  * means "IP packet".
64*05b00f60SXin Li  */
65*05b00f60SXin Li 
66*05b00f60SXin Li /* packet types */
67*05b00f60SXin Li #define TYPE_IP 0x40
68*05b00f60SXin Li #define TYPE_UNCOMPRESSED_TCP 0x70
69*05b00f60SXin Li #define TYPE_COMPRESSED_TCP 0x80
70*05b00f60SXin Li #define TYPE_ERROR 0x00
71*05b00f60SXin Li 
72*05b00f60SXin Li /* Bits in first octet of compressed packet */
73*05b00f60SXin Li #define NEW_C	0x40	/* flag bits for what changed in a packet */
74*05b00f60SXin Li #define NEW_I	0x20
75*05b00f60SXin Li #define NEW_S	0x08
76*05b00f60SXin Li #define NEW_A	0x04
77*05b00f60SXin Li #define NEW_W	0x02
78*05b00f60SXin Li #define NEW_U	0x01
79*05b00f60SXin Li 
80*05b00f60SXin Li /* reserved, special-case values of above */
81*05b00f60SXin Li #define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
82*05b00f60SXin Li #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
83*05b00f60SXin Li #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
84*05b00f60SXin Li 
85*05b00f60SXin Li #define TCP_PUSH_BIT 0x10
86