xref: /freebsd/sys/net/slcompress.h (revision 881048943390d6e5a88cc0c5fb88da73dfb688cc)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Definitions for tcp compression routines.
3df8bae1dSRodney W. Grimes  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 1989, 1993
5df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
6df8bae1dSRodney W. Grimes  *
7df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
8df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
9df8bae1dSRodney W. Grimes  * are met:
10df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
12df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
13df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
14df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
15df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
16df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
17df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
18df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
19df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
20df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
21df8bae1dSRodney W. Grimes  *    without specific prior written permission.
22df8bae1dSRodney W. Grimes  *
23df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
34df8bae1dSRodney W. Grimes  *
35df8bae1dSRodney W. Grimes  *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
36df8bae1dSRodney W. Grimes  *	- Initial distribution.
37c3aac50fSPeter Wemm  * $FreeBSD$
38df8bae1dSRodney W. Grimes  */
39df8bae1dSRodney W. Grimes 
409d0de5ebSPaul Richards #ifndef _NET_SLCOMPRESS_H_
41cea1da3bSPaul Richards #define _NET_SLCOMPRESS_H_
42cea1da3bSPaul Richards 
43df8bae1dSRodney W. Grimes #define MAX_STATES 16		/* must be > 2 and < 256 */
4488104894SGary Jennejohn #define MAX_HDR 128
45df8bae1dSRodney W. Grimes 
46df8bae1dSRodney W. Grimes /*
47df8bae1dSRodney W. Grimes  * Compressed packet format:
48df8bae1dSRodney W. Grimes  *
49df8bae1dSRodney W. Grimes  * The first octet contains the packet type (top 3 bits), TCP
50df8bae1dSRodney W. Grimes  * 'push' bit, and flags that indicate which of the 4 TCP sequence
51df8bae1dSRodney W. Grimes  * numbers have changed (bottom 5 bits).  The next octet is a
52df8bae1dSRodney W. Grimes  * conversation number that associates a saved IP/TCP header with
53df8bae1dSRodney W. Grimes  * the compressed packet.  The next two octets are the TCP checksum
54df8bae1dSRodney W. Grimes  * from the original datagram.  The next 0 to 15 octets are
55df8bae1dSRodney W. Grimes  * sequence number changes, one change per bit set in the header
56df8bae1dSRodney W. Grimes  * (there may be no changes and there are two special cases where
57df8bae1dSRodney W. Grimes  * the receiver implicitly knows what changed -- see below).
58df8bae1dSRodney W. Grimes  *
59df8bae1dSRodney W. Grimes  * There are 5 numbers which can change (they are always inserted
60df8bae1dSRodney W. Grimes  * in the following order): TCP urgent pointer, window,
616c5e9bbdSMike Pritchard  * acknowledgement, sequence number and IP ID.  (The urgent pointer
62df8bae1dSRodney W. Grimes  * is different from the others in that its value is sent, not the
63df8bae1dSRodney W. Grimes  * change in value.)  Since typical use of SLIP links is biased
64df8bae1dSRodney W. Grimes  * toward small packets (see comments on MTU/MSS below), changes
65df8bae1dSRodney W. Grimes  * use a variable length coding with one octet for numbers in the
66df8bae1dSRodney W. Grimes  * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
67df8bae1dSRodney W. Grimes  * range 256 - 65535 or 0.  (If the change in sequence number or
68df8bae1dSRodney W. Grimes  * ack is more than 65535, an uncompressed packet is sent.)
69df8bae1dSRodney W. Grimes  */
70df8bae1dSRodney W. Grimes 
71df8bae1dSRodney W. Grimes /*
72df8bae1dSRodney W. Grimes  * Packet types (must not conflict with IP protocol version)
73df8bae1dSRodney W. Grimes  *
74df8bae1dSRodney W. Grimes  * The top nibble of the first octet is the packet type.  There are
75df8bae1dSRodney W. Grimes  * three possible types: IP (not proto TCP or tcp with one of the
76df8bae1dSRodney W. Grimes  * control flags set); uncompressed TCP (a normal IP/TCP packet but
77df8bae1dSRodney W. Grimes  * with the 8-bit protocol field replaced by an 8-bit connection id --
78df8bae1dSRodney W. Grimes  * this type of packet syncs the sender & receiver); and compressed
79df8bae1dSRodney W. Grimes  * TCP (described above).
80df8bae1dSRodney W. Grimes  *
81df8bae1dSRodney W. Grimes  * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
82df8bae1dSRodney W. Grimes  * is logically part of the 4-bit "changes" field that follows.  Top
83df8bae1dSRodney W. Grimes  * three bits are actual packet type.  For backward compatibility
84df8bae1dSRodney W. Grimes  * and in the interest of conserving bits, numbers are chosen so the
85df8bae1dSRodney W. Grimes  * IP protocol version number (4) which normally appears in this nibble
86df8bae1dSRodney W. Grimes  * means "IP packet".
87df8bae1dSRodney W. Grimes  */
88df8bae1dSRodney W. Grimes 
89df8bae1dSRodney W. Grimes /* packet types */
90df8bae1dSRodney W. Grimes #define TYPE_IP 0x40
91df8bae1dSRodney W. Grimes #define TYPE_UNCOMPRESSED_TCP 0x70
92df8bae1dSRodney W. Grimes #define TYPE_COMPRESSED_TCP 0x80
93df8bae1dSRodney W. Grimes #define TYPE_ERROR 0x00
94df8bae1dSRodney W. Grimes 
95df8bae1dSRodney W. Grimes /* Bits in first octet of compressed packet */
96df8bae1dSRodney W. Grimes #define NEW_C	0x40	/* flag bits for what changed in a packet */
97df8bae1dSRodney W. Grimes #define NEW_I	0x20
98df8bae1dSRodney W. Grimes #define NEW_S	0x08
99df8bae1dSRodney W. Grimes #define NEW_A	0x04
100df8bae1dSRodney W. Grimes #define NEW_W	0x02
101df8bae1dSRodney W. Grimes #define NEW_U	0x01
102df8bae1dSRodney W. Grimes 
103df8bae1dSRodney W. Grimes /* reserved, special-case values of above */
104df8bae1dSRodney W. Grimes #define SPECIAL_I (NEW_S|NEW_W|NEW_U)		/* echoed interactive traffic */
105df8bae1dSRodney W. Grimes #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
106df8bae1dSRodney W. Grimes #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
107df8bae1dSRodney W. Grimes 
108df8bae1dSRodney W. Grimes #define TCP_PUSH_BIT 0x10
109df8bae1dSRodney W. Grimes 
110df8bae1dSRodney W. Grimes 
111df8bae1dSRodney W. Grimes /*
112df8bae1dSRodney W. Grimes  * "state" data for each active tcp conversation on the wire.  This is
113df8bae1dSRodney W. Grimes  * basically a copy of the entire IP/TCP header from the last packet
114df8bae1dSRodney W. Grimes  * we saw from the conversation together with a small identifier
115df8bae1dSRodney W. Grimes  * the transmit & receive ends of the line use to locate saved header.
116df8bae1dSRodney W. Grimes  */
117df8bae1dSRodney W. Grimes struct cstate {
118df8bae1dSRodney W. Grimes 	struct cstate *cs_next;	/* next most recently used cstate (xmit only) */
1192d4b190bSPeter Wemm 	u_int16_t cs_hlen;	/* size of hdr (receive only) */
120df8bae1dSRodney W. Grimes 	u_char cs_id;		/* connection # associated with this state */
121df8bae1dSRodney W. Grimes 	u_char cs_filler;
12288104894SGary Jennejohn 	struct ip cs_ip;	/* ip/tcp hdr from most recent packet */
123df8bae1dSRodney W. Grimes };
124df8bae1dSRodney W. Grimes 
125df8bae1dSRodney W. Grimes /*
126df8bae1dSRodney W. Grimes  * all the state data for one serial line (we need one of these
127df8bae1dSRodney W. Grimes  * per line).
128df8bae1dSRodney W. Grimes  */
129df8bae1dSRodney W. Grimes struct slcompress {
130df8bae1dSRodney W. Grimes 	struct cstate *last_cs;	/* most recently used tstate */
131df8bae1dSRodney W. Grimes 	u_char last_recv;	/* last rcvd conn. id */
132df8bae1dSRodney W. Grimes 	u_char last_xmit;	/* last sent conn. id */
1332d4b190bSPeter Wemm 	u_int16_t flags;
134df8bae1dSRodney W. Grimes #ifndef SL_NO_STATS
135df8bae1dSRodney W. Grimes 	int sls_packets;	/* outbound packets */
136df8bae1dSRodney W. Grimes 	int sls_compressed;	/* outbound compressed packets */
137df8bae1dSRodney W. Grimes 	int sls_searches;	/* searches for connection state */
138df8bae1dSRodney W. Grimes 	int sls_misses;		/* times couldn't find conn. state */
139df8bae1dSRodney W. Grimes 	int sls_uncompressedin;	/* inbound uncompressed packets */
140df8bae1dSRodney W. Grimes 	int sls_compressedin;	/* inbound compressed packets */
141df8bae1dSRodney W. Grimes 	int sls_errorin;	/* inbound unknown type packets */
142df8bae1dSRodney W. Grimes 	int sls_tossed;		/* inbound packets tossed because of error */
143df8bae1dSRodney W. Grimes #endif
144df8bae1dSRodney W. Grimes 	struct cstate tstate[MAX_STATES];	/* xmit connection states */
145df8bae1dSRodney W. Grimes 	struct cstate rstate[MAX_STATES];	/* receive connection states */
146df8bae1dSRodney W. Grimes };
147df8bae1dSRodney W. Grimes /* flag values */
148df8bae1dSRodney W. Grimes #define SLF_TOSS 1		/* tossing rcvd frames because of input err */
149df8bae1dSRodney W. Grimes 
15071b9cf73SPeter Wemm void	 sl_compress_init __P((struct slcompress *, int));
151df8bae1dSRodney W. Grimes u_int	 sl_compress_tcp __P((struct mbuf *,
152df8bae1dSRodney W. Grimes 	    struct ip *, struct slcompress *, int));
153df8bae1dSRodney W. Grimes int	 sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
15471b9cf73SPeter Wemm int	 sl_uncompress_tcp_core __P((u_char *, int, int, u_int,
15571b9cf73SPeter Wemm 	    struct slcompress *, u_char **, u_int *));
156c80c3fd1SBruce Evans 
15768e2ef24SBruce Evans #endif /* !_NET_SLCOMPRESS_H_ */
158