xref: /illumos-gate/usr/src/uts/common/net/vjcompress.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * Definitions for tcp compression routines.
3  *
4  * $Id: vjcompress.h,v 1.3 1996/05/28 00:55:33 paulus Exp $
5  *
6  * Copyright (c) 2000 by Sun Microsystems, Inc.
7  * All rights reserved.
8  *
9  * Copyright (c) 1989 Regents of the University of California.
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms are permitted
13  * provided that the above copyright notice and this paragraph are
14  * duplicated in all such forms and that any documentation,
15  * advertising materials, and other materials related to such
16  * distribution and use acknowledge that the software was developed
17  * by the University of California, Berkeley.  The name of the
18  * University may not be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
25  *	- Initial distribution.
26  */
27 
28 #ifndef _VJCOMPRESS_H_
29 #define	_VJCOMPRESS_H_
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #define	MAX_STATES 16		/* must be > 2 and < 256 */
36 #define	MAX_HDR	   128
37 
38 /*
39  * Compressed packet format:
40  *
41  * The first octet contains the packet type (top 3 bits), TCP
42  * 'push' bit, and flags that indicate which of the 4 TCP sequence
43  * numbers have changed (bottom 5 bits).  The next octet is a
44  * conversation number that associates a saved IP/TCP header with
45  * the compressed packet.  The next two octets are the TCP checksum
46  * from the original datagram.  The next 0 to 15 octets are
47  * sequence number changes, one change per bit set in the header
48  * (there may be no changes and there are two special cases where
49  * the receiver implicitly knows what changed -- see below).
50  *
51  * There are 5 numbers which can change (they are always inserted
52  * in the following order): TCP urgent pointer, window,
53  * acknowlegement, sequence number and IP ID.  (The urgent pointer
54  * is different from the others in that its value is sent, not the
55  * change in value.)  Since typical use of SLIP links is biased
56  * toward small packets (see comments on MTU/MSS below), changes
57  * use a variable length coding with one octet for numbers in the
58  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
59  * range 256 - 65535 or 0.  (If the change in sequence number or
60  * ack is more than 65535, an uncompressed packet is sent.)
61  */
62 
63 /*
64  * Packet types (must not conflict with IP protocol version)
65  *
66  * The top nibble of the first octet is the packet type.  There are
67  * three possible types: IP (not proto TCP or tcp with one of the
68  * control flags set); uncompressed TCP (a normal IP/TCP packet but
69  * with the 8-bit protocol field replaced by an 8-bit connection id --
70  * this type of packet syncs the sender & receiver); and compressed
71  * TCP (described above).
72  *
73  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
74  * is logically part of the 4-bit "changes" field that follows.  Top
75  * three bits are actual packet type.  For backward compatibility
76  * and in the interest of conserving bits, numbers are chosen so the
77  * IP protocol version number (4) which normally appears in this nibble
78  * means "IP packet".
79  */
80 
81 /* packet types */
82 #define	TYPE_IP 0x40
83 #define	TYPE_UNCOMPRESSED_TCP 0x70
84 #define	TYPE_COMPRESSED_TCP 0x80
85 #define	TYPE_ERROR 0x00
86 
87 /* Bits in first octet of compressed packet */
88 #define	NEW_C	0x40	/* flag bits for what changed in a packet */
89 #define	NEW_I	0x20
90 #define	NEW_S	0x08
91 #define	NEW_A	0x04
92 #define	NEW_W	0x02
93 #define	NEW_U	0x01
94 
95 /* reserved, special-case values of above */
96 #define	SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
97 #define	SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
98 #define	SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
99 
100 #define	TCP_PUSH_BIT 0x10
101 
102 
103 /*
104  * "state" data for each active tcp conversation on the wire.  This is
105  * basically a copy of the entire IP/TCP header from the last packet
106  * we saw from the conversation together with a small identifier
107  * the transmit & receive ends of the line use to locate saved header.
108  */
109 struct cstate {
110 	struct cstate *cs_next;	/* next most recently used state (xmit only) */
111 	ushort_t cs_hlen;	/* size of hdr (receive only) */
112 	uchar_t cs_id;		/* connection # associated with this state */
113 	uchar_t cs_filler;
114 	union {
115 		char csu_hdr[MAX_HDR];
116 		struct ip csu_ip; /* ip/tcp hdr from most recent packet */
117 	} vjcs_u;
118 };
119 #define	cs_ip vjcs_u.csu_ip
120 #define	cs_hdr vjcs_u.csu_hdr
121 
122 /*
123  * all the state data for one serial line (we need one of these per line).
124  */
125 struct vjcompress {
126 	struct cstate *last_cs;	/* most recently used tstate */
127 	uchar_t last_recv;		/* last rcvd conn. id */
128 	uchar_t last_xmit;		/* last sent conn. id */
129 	ushort_t flags;
130 #ifndef VJ_NO_STATS
131 	struct vjstat stats;
132 #endif
133 	struct cstate tstate[MAX_STATES];	/* xmit connection states */
134 	struct cstate rstate[MAX_STATES];	/* receive connection states */
135 };
136 
137 /* flag values */
138 #define	VJF_TOSS 1		/* tossing rcvd frames because of input err */
139 
140 extern void  vj_compress_init __P((struct vjcompress *comp, int max_state));
141 extern uint_t vj_compress_tcp __P((struct ip *ip, uint_t mlen,
142 				struct vjcompress *comp, int compress_cid_flag,
143 				uchar_t **vjhdrp));
144 extern void  vj_uncompress_err __P((struct vjcompress *comp));
145 extern int   vj_uncompress_uncomp __P((uchar_t *buf, int buflen,
146 				struct vjcompress *comp));
147 extern int   vj_uncompress_tcp __P((uchar_t *buf, int buflen, int total_len,
148 				struct vjcompress *comp, uchar_t **hdrp,
149 				uint_t *hlenp));
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif /* _VJCOMPRESS_H_ */
156