slcompress.h revision 2214
1114402Sru/*	slcompress.h	8.1	93/06/10	*/
2114402Sru/*
3114402Sru * Definitions for tcp compression routines.
4114402Sru *
5114402Sru * Copyright (c) 1989, 1993
6114402Sru *	The Regents of the University of California.  All rights reserved.
7114402Sru *
8114402Sru * Redistribution and use in source and binary forms, with or without
9114402Sru * modification, are permitted provided that the following conditions
10114402Sru * are met:
11114402Sru * 1. Redistributions of source code must retain the above copyright
12114402Sru *    notice, this list of conditions and the following disclaimer.
13114402Sru * 2. Redistributions in binary form must reproduce the above copyright
14114402Sru *    notice, this list of conditions and the following disclaimer in the
15114402Sru *    documentation and/or other materials provided with the distribution.
16114402Sru * 3. All advertising materials mentioning features or use of this software
17114402Sru *    must display the following acknowledgement:
18114402Sru *	This product includes software developed by the University of
19151497Sru *	California, Berkeley and its contributors.
20114402Sru * 4. Neither the name of the University nor the names of its contributors
21114402Sru *    may be used to endorse or promote products derived from this software
22114402Sru *    without specific prior written permission.
23114402Sru *
24114402Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25114402Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26114402Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27114402Sru * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28114402Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29114402Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30114402Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31114402Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32114402Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33114402Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34114402Sru * SUCH DAMAGE.
35114402Sru *
36114402Sru *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
37114402Sru *	- Initial distribution.
38114402Sru * $Id: slcompress.h,v 1.4 1994/08/21 19:06:48 paul Exp $
39114402Sru */
40114402Sru
41114402Sru#ifndef _NET_SLCOMPRESS_H_
42114402Sru#define _NET_SLCOMPRESS_H_
43114402Sru
44114402Sru#define MAX_STATES 16		/* must be > 2 and < 256 */
45114402Sru#define MAX_HDR MLEN		/* XXX 4bsd-ism: should really be 128 */
46114402Sru
47114402Sru/*
48114402Sru * Compressed packet format:
49114402Sru *
50114402Sru * The first octet contains the packet type (top 3 bits), TCP
51114402Sru * 'push' bit, and flags that indicate which of the 4 TCP sequence
52114402Sru * numbers have changed (bottom 5 bits).  The next octet is a
53114402Sru * conversation number that associates a saved IP/TCP header with
54114402Sru * the compressed packet.  The next two octets are the TCP checksum
55114402Sru * from the original datagram.  The next 0 to 15 octets are
56114402Sru * sequence number changes, one change per bit set in the header
57114402Sru * (there may be no changes and there are two special cases where
58114402Sru * the receiver implicitly knows what changed -- see below).
59114402Sru *
60114402Sru * There are 5 numbers which can change (they are always inserted
61114402Sru * in the following order): TCP urgent pointer, window,
62114402Sru * acknowlegement, sequence number and IP ID.  (The urgent pointer
63114402Sru * is different from the others in that its value is sent, not the
64114402Sru * change in value.)  Since typical use of SLIP links is biased
65114402Sru * toward small packets (see comments on MTU/MSS below), changes
66114402Sru * use a variable length coding with one octet for numbers in the
67114402Sru * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
68114402Sru * range 256 - 65535 or 0.  (If the change in sequence number or
69114402Sru * ack is more than 65535, an uncompressed packet is sent.)
70114402Sru */
71114402Sru
72114402Sru/*
73114402Sru * Packet types (must not conflict with IP protocol version)
74114402Sru *
75114402Sru * The top nibble of the first octet is the packet type.  There are
76114402Sru * three possible types: IP (not proto TCP or tcp with one of the
77114402Sru * control flags set); uncompressed TCP (a normal IP/TCP packet but
78114402Sru * with the 8-bit protocol field replaced by an 8-bit connection id --
79114402Sru * this type of packet syncs the sender & receiver); and compressed
80114402Sru * TCP (described above).
81114402Sru *
82114402Sru * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
83114402Sru * is logically part of the 4-bit "changes" field that follows.  Top
84114402Sru * three bits are actual packet type.  For backward compatibility
85114402Sru * and in the interest of conserving bits, numbers are chosen so the
86114402Sru * IP protocol version number (4) which normally appears in this nibble
87114402Sru * means "IP packet".
88114402Sru */
89114402Sru
90114402Sru/* packet types */
91114402Sru#define TYPE_IP 0x40
92114402Sru#define TYPE_UNCOMPRESSED_TCP 0x70
93114402Sru#define TYPE_COMPRESSED_TCP 0x80
94114402Sru#define TYPE_ERROR 0x00
95114402Sru
96114402Sru/* Bits in first octet of compressed packet */
97114402Sru#define NEW_C	0x40	/* flag bits for what changed in a packet */
98114402Sru#define NEW_I	0x20
99114402Sru#define NEW_S	0x08
100114402Sru#define NEW_A	0x04
101114402Sru#define NEW_W	0x02
102114402Sru#define NEW_U	0x01
103114402Sru
104114402Sru/* reserved, special-case values of above */
105114402Sru#define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
106114402Sru#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
107114402Sru#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
108114402Sru
109114402Sru#define TCP_PUSH_BIT 0x10
110114402Sru
111114402Sru
112114402Sru/*
113114402Sru * "state" data for each active tcp conversation on the wire.  This is
114114402Sru * basically a copy of the entire IP/TCP header from the last packet
115114402Sru * we saw from the conversation together with a small identifier
116114402Sru * the transmit & receive ends of the line use to locate saved header.
117114402Sru */
118114402Srustruct cstate {
119114402Sru	struct cstate *cs_next;	/* next most recently used cstate (xmit only) */
120114402Sru	u_short cs_hlen;	/* size of hdr (receive only) */
121114402Sru	u_char cs_id;		/* connection # associated with this state */
122114402Sru	u_char cs_filler;
123114402Sru	union {
124114402Sru		char csu_hdr[MAX_HDR];
125114402Sru		struct ip csu_ip;	/* ip/tcp hdr from most recent packet */
126114402Sru	} slcs_u;
127114402Sru};
128114402Sru#define cs_ip slcs_u.csu_ip
129114402Sru#define cs_hdr slcs_u.csu_hdr
130114402Sru
131114402Sru/*
132114402Sru * all the state data for one serial line (we need one of these
133114402Sru * per line).
134114402Sru */
135114402Srustruct slcompress {
136114402Sru	struct cstate *last_cs;	/* most recently used tstate */
137114402Sru	u_char last_recv;	/* last rcvd conn. id */
138114402Sru	u_char last_xmit;	/* last sent conn. id */
139114402Sru	u_short flags;
140114402Sru#ifndef SL_NO_STATS
141114402Sru	int sls_packets;	/* outbound packets */
142114402Sru	int sls_compressed;	/* outbound compressed packets */
143114402Sru	int sls_searches;	/* searches for connection state */
144114402Sru	int sls_misses;		/* times couldn't find conn. state */
145114402Sru	int sls_uncompressedin;	/* inbound uncompressed packets */
146114402Sru	int sls_compressedin;	/* inbound compressed packets */
147114402Sru	int sls_errorin;	/* inbound unknown type packets */
148114402Sru	int sls_tossed;		/* inbound packets tossed because of error */
149114402Sru#endif
150114402Sru	struct cstate tstate[MAX_STATES];	/* xmit connection states */
151114402Sru	struct cstate rstate[MAX_STATES];	/* receive connection states */
152114402Sru};
153114402Sru/* flag values */
154114402Sru#define SLF_TOSS 1		/* tossing rcvd frames because of input err */
155114402Sru
156114402Sruvoid	 sl_compress_init __P((struct slcompress *));
157114402Sruu_int	 sl_compress_tcp __P((struct mbuf *,
158114402Sru	    struct ip *, struct slcompress *, int));
159114402Sruint	 sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
160114402Sru
161114402Sru#endif /* !_NET_SLCOMPRESS_H_ */
162114402Sru