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