xref: /csrg-svn/sys/net/slcompress.h (revision 63211)
1*63211Sbostic /*	slcompress.h	8.1	93/06/10	*/
238369Skarels /*
338369Skarels  * Definitions for tcp compression routines.
438369Skarels  *
539948Ssam  * $Header: slcompress.h,v 1.10 89/12/31 08:53:02 van Exp $
639948Ssam  *
7*63211Sbostic  * Copyright (c) 1989, 1993
8*63211Sbostic  *	The Regents of the University of California.  All rights reserved.
938369Skarels  *
1044466Sbostic  * %sccs.include.redist.c%
1139948Ssam  *
1239948Ssam  *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
1339948Ssam  *	- Initial distribution.
1438369Skarels  */
1538369Skarels 
1638369Skarels #define MAX_STATES 16		/* must be > 2 and < 256 */
1738369Skarels #define MAX_HDR MLEN		/* XXX 4bsd-ism: should really be 128 */
1838369Skarels 
1938369Skarels /*
2038369Skarels  * Compressed packet format:
2138369Skarels  *
2238369Skarels  * The first octet contains the packet type (top 3 bits), TCP
2338369Skarels  * 'push' bit, and flags that indicate which of the 4 TCP sequence
2438369Skarels  * numbers have changed (bottom 5 bits).  The next octet is a
2538369Skarels  * conversation number that associates a saved IP/TCP header with
2638369Skarels  * the compressed packet.  The next two octets are the TCP checksum
2738369Skarels  * from the original datagram.  The next 0 to 15 octets are
2838369Skarels  * sequence number changes, one change per bit set in the header
2938369Skarels  * (there may be no changes and there are two special cases where
3038369Skarels  * the receiver implicitly knows what changed -- see below).
3138369Skarels  *
3238369Skarels  * There are 5 numbers which can change (they are always inserted
3338369Skarels  * in the following order): TCP urgent pointer, window,
3438369Skarels  * acknowlegement, sequence number and IP ID.  (The urgent pointer
3538369Skarels  * is different from the others in that its value is sent, not the
3638369Skarels  * change in value.)  Since typical use of SLIP links is biased
3738369Skarels  * toward small packets (see comments on MTU/MSS below), changes
3838369Skarels  * use a variable length coding with one octet for numbers in the
3938369Skarels  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
4038369Skarels  * range 256 - 65535 or 0.  (If the change in sequence number or
4138369Skarels  * ack is more than 65535, an uncompressed packet is sent.)
4238369Skarels  */
4338369Skarels 
4438369Skarels /*
4538369Skarels  * Packet types (must not conflict with IP protocol version)
4638369Skarels  *
4738369Skarels  * The top nibble of the first octet is the packet type.  There are
4838369Skarels  * three possible types: IP (not proto TCP or tcp with one of the
4938369Skarels  * control flags set); uncompressed TCP (a normal IP/TCP packet but
5038369Skarels  * with the 8-bit protocol field replaced by an 8-bit connection id --
5138369Skarels  * this type of packet syncs the sender & receiver); and compressed
5238369Skarels  * TCP (described above).
5338369Skarels  *
5438369Skarels  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
5538369Skarels  * is logically part of the 4-bit "changes" field that follows.  Top
5638369Skarels  * three bits are actual packet type.  For backward compatibility
5738369Skarels  * and in the interest of conserving bits, numbers are chosen so the
5838369Skarels  * IP protocol version number (4) which normally appears in this nibble
5938369Skarels  * means "IP packet".
6038369Skarels  */
6138369Skarels 
6238369Skarels /* packet types */
6338369Skarels #define TYPE_IP 0x40
6438378Skarels #define TYPE_UNCOMPRESSED_TCP 0x70
6538369Skarels #define TYPE_COMPRESSED_TCP 0x80
6638369Skarels #define TYPE_ERROR 0x00
6738369Skarels 
6838369Skarels /* Bits in first octet of compressed packet */
6938369Skarels #define NEW_C	0x40	/* flag bits for what changed in a packet */
7038369Skarels #define NEW_I	0x20
7138369Skarels #define NEW_S	0x08
7238369Skarels #define NEW_A	0x04
7338369Skarels #define NEW_W	0x02
7438369Skarels #define NEW_U	0x01
7538369Skarels 
7638369Skarels /* reserved, special-case values of above */
7738369Skarels #define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
7838369Skarels #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
7938369Skarels #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
8038369Skarels 
8138369Skarels #define TCP_PUSH_BIT 0x10
8238369Skarels 
8338369Skarels 
8438369Skarels /*
8538369Skarels  * "state" data for each active tcp conversation on the wire.  This is
8638369Skarels  * basically a copy of the entire IP/TCP header from the last packet
8738369Skarels  * we saw from the conversation together with a small identifier
8838369Skarels  * the transmit & receive ends of the line use to locate saved header.
8938369Skarels  */
9038369Skarels struct cstate {
9138369Skarels 	struct cstate *cs_next;	/* next most recently used cstate (xmit only) */
9238369Skarels 	u_short cs_hlen;	/* size of hdr (receive only) */
9338369Skarels 	u_char cs_id;		/* connection # associated with this state */
9438369Skarels 	u_char cs_filler;
9538369Skarels 	union {
9639948Ssam 		char csu_hdr[MAX_HDR];
9738369Skarels 		struct ip csu_ip;	/* ip/tcp hdr from most recent packet */
9839948Ssam 	} slcs_u;
9938369Skarels };
10039948Ssam #define cs_ip slcs_u.csu_ip
10139948Ssam #define cs_hdr slcs_u.csu_hdr
10238369Skarels 
10338369Skarels /*
10438369Skarels  * all the state data for one serial line (we need one of these
10538369Skarels  * per line).
10638369Skarels  */
10738369Skarels struct slcompress {
10838378Skarels 	struct cstate *last_cs;	/* most recently used tstate */
10938378Skarels 	u_char last_recv;	/* last rcvd conn. id */
11038378Skarels 	u_char last_xmit;	/* last sent conn. id */
11138369Skarels 	u_short flags;
11239948Ssam #ifndef SL_NO_STATS
11338378Skarels 	int sls_packets;	/* outbound packets */
11438378Skarels 	int sls_compressed;	/* outbound compressed packets */
11538378Skarels 	int sls_searches;	/* searches for connection state */
11638378Skarels 	int sls_misses;		/* times couldn't find conn. state */
11738378Skarels 	int sls_uncompressedin;	/* inbound uncompressed packets */
11838378Skarels 	int sls_compressedin;	/* inbound compressed packets */
11938378Skarels 	int sls_errorin;	/* inbound unknown type packets */
12038378Skarels 	int sls_tossed;		/* inbound packets tossed because of error */
12138378Skarels #endif
12238369Skarels 	struct cstate tstate[MAX_STATES];	/* xmit connection states */
12338369Skarels 	struct cstate rstate[MAX_STATES];	/* receive connection states */
12438369Skarels };
12538369Skarels /* flag values */
12638369Skarels #define SLF_TOSS 1		/* tossing rcvd frames because of input err */
12738369Skarels 
12861349Sbostic void	 sl_compress_init __P((struct slcompress *));
12961349Sbostic u_int	 sl_compress_tcp __P((struct mbuf *,
13061349Sbostic 	    struct ip *, struct slcompress *, int));
13161349Sbostic int	 sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
132