xref: /titanic_50/usr/src/uts/common/net/vjcompress.h (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define	MAX_STATES 16		/* must be > 2 and < 256 */
38 #define	MAX_HDR	   128
39 
40 /*
41  * Compressed packet format:
42  *
43  * The first octet contains the packet type (top 3 bits), TCP
44  * 'push' bit, and flags that indicate which of the 4 TCP sequence
45  * numbers have changed (bottom 5 bits).  The next octet is a
46  * conversation number that associates a saved IP/TCP header with
47  * the compressed packet.  The next two octets are the TCP checksum
48  * from the original datagram.  The next 0 to 15 octets are
49  * sequence number changes, one change per bit set in the header
50  * (there may be no changes and there are two special cases where
51  * the receiver implicitly knows what changed -- see below).
52  *
53  * There are 5 numbers which can change (they are always inserted
54  * in the following order): TCP urgent pointer, window,
55  * acknowlegement, sequence number and IP ID.  (The urgent pointer
56  * is different from the others in that its value is sent, not the
57  * change in value.)  Since typical use of SLIP links is biased
58  * toward small packets (see comments on MTU/MSS below), changes
59  * use a variable length coding with one octet for numbers in the
60  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
61  * range 256 - 65535 or 0.  (If the change in sequence number or
62  * ack is more than 65535, an uncompressed packet is sent.)
63  */
64 
65 /*
66  * Packet types (must not conflict with IP protocol version)
67  *
68  * The top nibble of the first octet is the packet type.  There are
69  * three possible types: IP (not proto TCP or tcp with one of the
70  * control flags set); uncompressed TCP (a normal IP/TCP packet but
71  * with the 8-bit protocol field replaced by an 8-bit connection id --
72  * this type of packet syncs the sender & receiver); and compressed
73  * TCP (described above).
74  *
75  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
76  * is logically part of the 4-bit "changes" field that follows.  Top
77  * three bits are actual packet type.  For backward compatibility
78  * and in the interest of conserving bits, numbers are chosen so the
79  * IP protocol version number (4) which normally appears in this nibble
80  * means "IP packet".
81  */
82 
83 /* packet types */
84 #define	TYPE_IP 0x40
85 #define	TYPE_UNCOMPRESSED_TCP 0x70
86 #define	TYPE_COMPRESSED_TCP 0x80
87 #define	TYPE_ERROR 0x00
88 
89 /* Bits in first octet of compressed packet */
90 #define	NEW_C	0x40	/* flag bits for what changed in a packet */
91 #define	NEW_I	0x20
92 #define	NEW_S	0x08
93 #define	NEW_A	0x04
94 #define	NEW_W	0x02
95 #define	NEW_U	0x01
96 
97 /* reserved, special-case values of above */
98 #define	SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
99 #define	SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
100 #define	SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
101 
102 #define	TCP_PUSH_BIT 0x10
103 
104 
105 /*
106  * "state" data for each active tcp conversation on the wire.  This is
107  * basically a copy of the entire IP/TCP header from the last packet
108  * we saw from the conversation together with a small identifier
109  * the transmit & receive ends of the line use to locate saved header.
110  */
111 struct cstate {
112 	struct cstate *cs_next;	/* next most recently used state (xmit only) */
113 	ushort_t cs_hlen;	/* size of hdr (receive only) */
114 	uchar_t cs_id;		/* connection # associated with this state */
115 	uchar_t cs_filler;
116 	union {
117 		char csu_hdr[MAX_HDR];
118 		struct ip csu_ip; /* ip/tcp hdr from most recent packet */
119 	} vjcs_u;
120 };
121 #define	cs_ip vjcs_u.csu_ip
122 #define	cs_hdr vjcs_u.csu_hdr
123 
124 /*
125  * all the state data for one serial line (we need one of these per line).
126  */
127 struct vjcompress {
128 	struct cstate *last_cs;	/* most recently used tstate */
129 	uchar_t last_recv;		/* last rcvd conn. id */
130 	uchar_t last_xmit;		/* last sent conn. id */
131 	ushort_t flags;
132 #ifndef VJ_NO_STATS
133 	struct vjstat stats;
134 #endif
135 	struct cstate tstate[MAX_STATES];	/* xmit connection states */
136 	struct cstate rstate[MAX_STATES];	/* receive connection states */
137 };
138 
139 /* flag values */
140 #define	VJF_TOSS 1		/* tossing rcvd frames because of input err */
141 
142 extern void  vj_compress_init __P((struct vjcompress *comp, int max_state));
143 extern uint_t vj_compress_tcp __P((struct ip *ip, uint_t mlen,
144 				struct vjcompress *comp, int compress_cid_flag,
145 				uchar_t **vjhdrp));
146 extern void  vj_uncompress_err __P((struct vjcompress *comp));
147 extern int   vj_uncompress_uncomp __P((uchar_t *buf, int buflen,
148 				struct vjcompress *comp));
149 extern int   vj_uncompress_tcp __P((uchar_t *buf, int buflen, int total_len,
150 				struct vjcompress *comp, uchar_t **hdrp,
151 				uint_t *hlenp));
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif /* _VJCOMPRESS_H_ */
158