xref: /original-bsd/sys/net/slcompress.h (revision f46d860e)
1 /*	slcompress.h	8.1	93/06/10	*/
2 /*
3  * Definitions for tcp compression routines.
4  *
5  * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
6  *
7  * Copyright (c) 1989, 1993
8  *	The Regents of the University of California.  All rights reserved.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
13  *	- Initial distribution.
14  */
15 
16 #define MAX_STATES 16		/* must be > 2 and < 256 */
17 #define MAX_HDR MLEN		/* XXX 4bsd-ism: should really be 128 */
18 
19 /*
20  * Compressed packet format:
21  *
22  * The first octet contains the packet type (top 3 bits), TCP
23  * 'push' bit, and flags that indicate which of the 4 TCP sequence
24  * numbers have changed (bottom 5 bits).  The next octet is a
25  * conversation number that associates a saved IP/TCP header with
26  * the compressed packet.  The next two octets are the TCP checksum
27  * from the original datagram.  The next 0 to 15 octets are
28  * sequence number changes, one change per bit set in the header
29  * (there may be no changes and there are two special cases where
30  * the receiver implicitly knows what changed -- see below).
31  *
32  * There are 5 numbers which can change (they are always inserted
33  * in the following order): TCP urgent pointer, window,
34  * acknowlegement, sequence number and IP ID.  (The urgent pointer
35  * is different from the others in that its value is sent, not the
36  * change in value.)  Since typical use of SLIP links is biased
37  * toward small packets (see comments on MTU/MSS below), changes
38  * use a variable length coding with one octet for numbers in the
39  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
40  * range 256 - 65535 or 0.  (If the change in sequence number or
41  * ack is more than 65535, an uncompressed packet is sent.)
42  */
43 
44 /*
45  * Packet types (must not conflict with IP protocol version)
46  *
47  * The top nibble of the first octet is the packet type.  There are
48  * three possible types: IP (not proto TCP or tcp with one of the
49  * control flags set); uncompressed TCP (a normal IP/TCP packet but
50  * with the 8-bit protocol field replaced by an 8-bit connection id --
51  * this type of packet syncs the sender & receiver); and compressed
52  * TCP (described above).
53  *
54  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
55  * is logically part of the 4-bit "changes" field that follows.  Top
56  * three bits are actual packet type.  For backward compatibility
57  * and in the interest of conserving bits, numbers are chosen so the
58  * IP protocol version number (4) which normally appears in this nibble
59  * means "IP packet".
60  */
61 
62 /* packet types */
63 #define TYPE_IP 0x40
64 #define TYPE_UNCOMPRESSED_TCP 0x70
65 #define TYPE_COMPRESSED_TCP 0x80
66 #define TYPE_ERROR 0x00
67 
68 /* Bits in first octet of compressed packet */
69 #define NEW_C	0x40	/* flag bits for what changed in a packet */
70 #define NEW_I	0x20
71 #define NEW_S	0x08
72 #define NEW_A	0x04
73 #define NEW_W	0x02
74 #define NEW_U	0x01
75 
76 /* reserved, special-case values of above */
77 #define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
78 #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
79 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
80 
81 #define TCP_PUSH_BIT 0x10
82 
83 
84 /*
85  * "state" data for each active tcp conversation on the wire.  This is
86  * basically a copy of the entire IP/TCP header from the last packet
87  * we saw from the conversation together with a small identifier
88  * the transmit & receive ends of the line use to locate saved header.
89  */
90 struct cstate {
91 	struct cstate *cs_next;	/* next most recently used cstate (xmit only) */
92 	u_short cs_hlen;	/* size of hdr (receive only) */
93 	u_char cs_id;		/* connection # associated with this state */
94 	u_char cs_filler;
95 	union {
96 		char csu_hdr[MAX_HDR];
97 		struct ip csu_ip;	/* ip/tcp hdr from most recent packet */
98 	} slcs_u;
99 };
100 #define cs_ip slcs_u.csu_ip
101 #define cs_hdr slcs_u.csu_hdr
102 
103 /*
104  * all the state data for one serial line (we need one of these
105  * per line).
106  */
107 struct slcompress {
108 	struct cstate *last_cs;	/* most recently used tstate */
109 	u_char last_recv;	/* last rcvd conn. id */
110 	u_char last_xmit;	/* last sent conn. id */
111 	u_short flags;
112 #ifndef SL_NO_STATS
113 	int sls_packets;	/* outbound packets */
114 	int sls_compressed;	/* outbound compressed packets */
115 	int sls_searches;	/* searches for connection state */
116 	int sls_misses;		/* times couldn't find conn. state */
117 	int sls_uncompressedin;	/* inbound uncompressed packets */
118 	int sls_compressedin;	/* inbound compressed packets */
119 	int sls_errorin;	/* inbound unknown type packets */
120 	int sls_tossed;		/* inbound packets tossed because of error */
121 #endif
122 	struct cstate tstate[MAX_STATES];	/* xmit connection states */
123 	struct cstate rstate[MAX_STATES];	/* receive connection states */
124 };
125 /* flag values */
126 #define SLF_TOSS 1		/* tossing rcvd frames because of input err */
127 
128 void	 sl_compress_init __P((struct slcompress *));
129 u_int	 sl_compress_tcp __P((struct mbuf *,
130 	    struct ip *, struct slcompress *, int));
131 int	 sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
132