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