1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// include/slcompress.h
|
4 |
|
|
//
|
5 |
|
|
//==========================================================================
|
6 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
7 |
|
|
// -------------------------------------------
|
8 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
9 |
|
|
// Copyright (C) 2003 Free Software Foundation, Inc.
|
10 |
|
|
//
|
11 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
12 |
|
|
// the terms of the GNU General Public License as published by the Free
|
13 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
14 |
|
|
// version.
|
15 |
|
|
//
|
16 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
17 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
18 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
19 |
|
|
// for more details.
|
20 |
|
|
//
|
21 |
|
|
// You should have received a copy of the GNU General Public License
|
22 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
23 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
24 |
|
|
//
|
25 |
|
|
// As a special exception, if other files instantiate templates or use
|
26 |
|
|
// macros or inline functions from this file, or you compile this file
|
27 |
|
|
// and link it with other works to produce a work based on this file,
|
28 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
29 |
|
|
// the GNU General Public License. However the source code for this file
|
30 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
31 |
|
|
// General Public License v2.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based
|
34 |
|
|
// on this file might be covered by the GNU General Public License.
|
35 |
|
|
// -------------------------------------------
|
36 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
37 |
|
|
// ####BSDALTCOPYRIGHTBEGIN####
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
// Portions of this software may have been derived from FreeBSD, OpenBSD,
|
40 |
|
|
// or other sources, and if so are covered by the appropriate copyright
|
41 |
|
|
// and license included herein.
|
42 |
|
|
// -------------------------------------------
|
43 |
|
|
// ####BSDALTCOPYRIGHTEND####
|
44 |
|
|
//==========================================================================
|
45 |
|
|
|
46 |
|
|
/*
|
47 |
|
|
* Definitions for tcp compression routines.
|
48 |
|
|
*
|
49 |
|
|
* Copyright (c) 1989, 1993
|
50 |
|
|
* The Regents of the University of California. All rights reserved.
|
51 |
|
|
*
|
52 |
|
|
* Redistribution and use in source and binary forms, with or without
|
53 |
|
|
* modification, are permitted provided that the following conditions
|
54 |
|
|
* are met:
|
55 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
56 |
|
|
* notice, this list of conditions and the following disclaimer.
|
57 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
58 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
59 |
|
|
* documentation and/or other materials provided with the distribution.
|
60 |
|
|
* 3. Neither the name of the University nor the names of its contributors
|
61 |
|
|
* may be used to endorse or promote products derived from this software
|
62 |
|
|
* without specific prior written permission.
|
63 |
|
|
*
|
64 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
65 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
66 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
67 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
68 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
69 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
70 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
71 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
72 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
73 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
74 |
|
|
* SUCH DAMAGE.
|
75 |
|
|
*
|
76 |
|
|
* Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
|
77 |
|
|
* - Initial distribution.
|
78 |
|
|
* $FreeBSD: src/sys/net/slcompress.h,v 1.14.2.1 2000/05/05 13:37:06 jlemon Exp $
|
79 |
|
|
*/
|
80 |
|
|
|
81 |
|
|
#ifndef _NET_SLCOMPRESS_H_
|
82 |
|
|
#define _NET_SLCOMPRESS_H_
|
83 |
|
|
|
84 |
|
|
#include <cyg/ppp/names.h>
|
85 |
|
|
|
86 |
|
|
#define MAX_STATES 16 /* must be > 2 and < 256 */
|
87 |
|
|
#define MAX_HDR 128
|
88 |
|
|
|
89 |
|
|
/*
|
90 |
|
|
* Compressed packet format:
|
91 |
|
|
*
|
92 |
|
|
* The first octet contains the packet type (top 3 bits), TCP
|
93 |
|
|
* 'push' bit, and flags that indicate which of the 4 TCP sequence
|
94 |
|
|
* numbers have changed (bottom 5 bits). The next octet is a
|
95 |
|
|
* conversation number that associates a saved IP/TCP header with
|
96 |
|
|
* the compressed packet. The next two octets are the TCP checksum
|
97 |
|
|
* from the original datagram. The next 0 to 15 octets are
|
98 |
|
|
* sequence number changes, one change per bit set in the header
|
99 |
|
|
* (there may be no changes and there are two special cases where
|
100 |
|
|
* the receiver implicitly knows what changed -- see below).
|
101 |
|
|
*
|
102 |
|
|
* There are 5 numbers which can change (they are always inserted
|
103 |
|
|
* in the following order): TCP urgent pointer, window,
|
104 |
|
|
* acknowledgement, sequence number and IP ID. (The urgent pointer
|
105 |
|
|
* is different from the others in that its value is sent, not the
|
106 |
|
|
* change in value.) Since typical use of SLIP links is biased
|
107 |
|
|
* toward small packets (see comments on MTU/MSS below), changes
|
108 |
|
|
* use a variable length coding with one octet for numbers in the
|
109 |
|
|
* range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
|
110 |
|
|
* range 256 - 65535 or 0. (If the change in sequence number or
|
111 |
|
|
* ack is more than 65535, an uncompressed packet is sent.)
|
112 |
|
|
*/
|
113 |
|
|
|
114 |
|
|
/*
|
115 |
|
|
* Packet types (must not conflict with IP protocol version)
|
116 |
|
|
*
|
117 |
|
|
* The top nibble of the first octet is the packet type. There are
|
118 |
|
|
* three possible types: IP (not proto TCP or tcp with one of the
|
119 |
|
|
* control flags set); uncompressed TCP (a normal IP/TCP packet but
|
120 |
|
|
* with the 8-bit protocol field replaced by an 8-bit connection id --
|
121 |
|
|
* this type of packet syncs the sender & receiver); and compressed
|
122 |
|
|
* TCP (described above).
|
123 |
|
|
*
|
124 |
|
|
* LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
|
125 |
|
|
* is logically part of the 4-bit "changes" field that follows. Top
|
126 |
|
|
* three bits are actual packet type. For backward compatibility
|
127 |
|
|
* and in the interest of conserving bits, numbers are chosen so the
|
128 |
|
|
* IP protocol version number (4) which normally appears in this nibble
|
129 |
|
|
* means "IP packet".
|
130 |
|
|
*/
|
131 |
|
|
|
132 |
|
|
/* packet types */
|
133 |
|
|
#define TYPE_IP 0x40
|
134 |
|
|
#define TYPE_UNCOMPRESSED_TCP 0x70
|
135 |
|
|
#define TYPE_COMPRESSED_TCP 0x80
|
136 |
|
|
#define TYPE_ERROR 0x00
|
137 |
|
|
|
138 |
|
|
/* Bits in first octet of compressed packet */
|
139 |
|
|
#define NEW_C 0x40 /* flag bits for what changed in a packet */
|
140 |
|
|
#define NEW_I 0x20
|
141 |
|
|
#define NEW_S 0x08
|
142 |
|
|
#define NEW_A 0x04
|
143 |
|
|
#define NEW_W 0x02
|
144 |
|
|
#define NEW_U 0x01
|
145 |
|
|
|
146 |
|
|
/* reserved, special-case values of above */
|
147 |
|
|
#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
|
148 |
|
|
#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
|
149 |
|
|
#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
|
150 |
|
|
|
151 |
|
|
#define TCP_PUSH_BIT 0x10
|
152 |
|
|
|
153 |
|
|
|
154 |
|
|
/*
|
155 |
|
|
* "state" data for each active tcp conversation on the wire. This is
|
156 |
|
|
* basically a copy of the entire IP/TCP header from the last packet
|
157 |
|
|
* we saw from the conversation together with a small identifier
|
158 |
|
|
* the transmit & receive ends of the line use to locate saved header.
|
159 |
|
|
*/
|
160 |
|
|
struct cstate {
|
161 |
|
|
struct cstate *cs_next; /* next most recently used cstate (xmit only) */
|
162 |
|
|
u_int16_t cs_hlen; /* size of hdr (receive only) */
|
163 |
|
|
u_char cs_id; /* connection # associated with this state */
|
164 |
|
|
u_char cs_filler;
|
165 |
|
|
union {
|
166 |
|
|
char csu_hdr[MAX_HDR];
|
167 |
|
|
struct ip csu_ip; /* ip/tcp hdr from most recent packet */
|
168 |
|
|
} slcs_u;
|
169 |
|
|
};
|
170 |
|
|
#define cs_ip slcs_u.csu_ip
|
171 |
|
|
#define cs_hdr slcs_u.csu_hdr
|
172 |
|
|
|
173 |
|
|
/*
|
174 |
|
|
* all the state data for one serial line (we need one of these
|
175 |
|
|
* per line).
|
176 |
|
|
*/
|
177 |
|
|
struct slcompress {
|
178 |
|
|
struct cstate *last_cs; /* most recently used tstate */
|
179 |
|
|
u_char last_recv; /* last rcvd conn. id */
|
180 |
|
|
u_char last_xmit; /* last sent conn. id */
|
181 |
|
|
u_int16_t flags;
|
182 |
|
|
#ifndef SL_NO_STATS
|
183 |
|
|
int sls_packets; /* outbound packets */
|
184 |
|
|
int sls_compressed; /* outbound compressed packets */
|
185 |
|
|
int sls_searches; /* searches for connection state */
|
186 |
|
|
int sls_misses; /* times couldn't find conn. state */
|
187 |
|
|
int sls_uncompressedin; /* inbound uncompressed packets */
|
188 |
|
|
int sls_compressedin; /* inbound compressed packets */
|
189 |
|
|
int sls_errorin; /* inbound unknown type packets */
|
190 |
|
|
int sls_tossed; /* inbound packets tossed because of error */
|
191 |
|
|
#endif
|
192 |
|
|
struct cstate tstate[MAX_STATES]; /* xmit connection states */
|
193 |
|
|
struct cstate rstate[MAX_STATES]; /* receive connection states */
|
194 |
|
|
};
|
195 |
|
|
/* flag values */
|
196 |
|
|
#define SLF_TOSS 1 /* tossing rcvd frames because of input err */
|
197 |
|
|
|
198 |
|
|
void sl_compress_init __P((struct slcompress *, int));
|
199 |
|
|
u_int sl_compress_tcp __P((struct mbuf *,
|
200 |
|
|
struct ip *, struct slcompress *, int));
|
201 |
|
|
int sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
|
202 |
|
|
int sl_uncompress_tcp_core __P((u_char *, int, int, u_int,
|
203 |
|
|
struct slcompress *, u_char **, u_int *));
|
204 |
|
|
|
205 |
|
|
#endif /* !_NET_SLCOMPRESS_H_ */
|