]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/slcompress.h
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / net / slcompress.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * Definitions for tcp compression routines.
27 *
28 * Copyright (c) 1989, 1993
29 * The Regents of the University of California. All rights reserved.
30 *
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
33 * are met:
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
60 * - Initial distribution.
9bccf70c 61 * $FreeBSD: src/sys/net/slcompress.h,v 1.14.2.1 2000/05/05 13:37:06 jlemon Exp $
1c79356b
A
62 */
63
64#ifndef _NET_SLCOMPRESS_H_
65#define _NET_SLCOMPRESS_H_
9bccf70c 66#include <sys/appleapiopts.h>
1c79356b
A
67
68#include <netinet/ip.h>
69
70#define MAX_STATES 16 /* must be > 2 and < 256 */
9bccf70c 71#define MAX_HDR 128
1c79356b
A
72
73/*
74 * Compressed packet format:
75 *
76 * The first octet contains the packet type (top 3 bits), TCP
77 * 'push' bit, and flags that indicate which of the 4 TCP sequence
78 * numbers have changed (bottom 5 bits). The next octet is a
79 * conversation number that associates a saved IP/TCP header with
80 * the compressed packet. The next two octets are the TCP checksum
81 * from the original datagram. The next 0 to 15 octets are
82 * sequence number changes, one change per bit set in the header
83 * (there may be no changes and there are two special cases where
84 * the receiver implicitly knows what changed -- see below).
85 *
86 * There are 5 numbers which can change (they are always inserted
87 * in the following order): TCP urgent pointer, window,
88 * acknowledgement, sequence number and IP ID. (The urgent pointer
89 * is different from the others in that its value is sent, not the
90 * change in value.) Since typical use of SLIP links is biased
91 * toward small packets (see comments on MTU/MSS below), changes
92 * use a variable length coding with one octet for numbers in the
93 * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
94 * range 256 - 65535 or 0. (If the change in sequence number or
95 * ack is more than 65535, an uncompressed packet is sent.)
96 */
97
98/*
99 * Packet types (must not conflict with IP protocol version)
100 *
101 * The top nibble of the first octet is the packet type. There are
102 * three possible types: IP (not proto TCP or tcp with one of the
103 * control flags set); uncompressed TCP (a normal IP/TCP packet but
104 * with the 8-bit protocol field replaced by an 8-bit connection id --
105 * this type of packet syncs the sender & receiver); and compressed
106 * TCP (described above).
107 *
108 * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
109 * is logically part of the 4-bit "changes" field that follows. Top
110 * three bits are actual packet type. For backward compatibility
111 * and in the interest of conserving bits, numbers are chosen so the
112 * IP protocol version number (4) which normally appears in this nibble
113 * means "IP packet".
114 */
115
116/* packet types */
117#define TYPE_IP 0x40
118#define TYPE_UNCOMPRESSED_TCP 0x70
119#define TYPE_COMPRESSED_TCP 0x80
120#define TYPE_ERROR 0x00
121
122/* Bits in first octet of compressed packet */
123#define NEW_C 0x40 /* flag bits for what changed in a packet */
124#define NEW_I 0x20
125#define NEW_S 0x08
126#define NEW_A 0x04
127#define NEW_W 0x02
128#define NEW_U 0x01
129
130/* reserved, special-case values of above */
131#define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
132#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
133#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
134
135#define TCP_PUSH_BIT 0x10
136
137
138/*
139 * "state" data for each active tcp conversation on the wire. This is
140 * basically a copy of the entire IP/TCP header from the last packet
141 * we saw from the conversation together with a small identifier
142 * the transmit & receive ends of the line use to locate saved header.
143 */
144struct cstate {
145 struct cstate *cs_next; /* next most recently used cstate (xmit only) */
146 u_int16_t cs_hlen; /* size of hdr (receive only) */
147 u_char cs_id; /* connection # associated with this state */
148 u_char cs_filler;
149 union {
150 char csu_hdr[MAX_HDR];
151 struct ip csu_ip; /* ip/tcp hdr from most recent packet */
152 } slcs_u;
153};
154#define cs_ip slcs_u.csu_ip
155#define cs_hdr slcs_u.csu_hdr
156
157/*
158 * all the state data for one serial line (we need one of these
159 * per line).
160 */
161struct slcompress {
162 struct cstate *last_cs; /* most recently used tstate */
163 u_char last_recv; /* last rcvd conn. id */
164 u_char last_xmit; /* last sent conn. id */
165 u_int16_t flags;
166#ifndef SL_NO_STATS
167 int sls_packets; /* outbound packets */
168 int sls_compressed; /* outbound compressed packets */
169 int sls_searches; /* searches for connection state */
170 int sls_misses; /* times couldn't find conn. state */
171 int sls_uncompressedin; /* inbound uncompressed packets */
172 int sls_compressedin; /* inbound compressed packets */
173 int sls_errorin; /* inbound unknown type packets */
174 int sls_tossed; /* inbound packets tossed because of error */
175#endif
176 struct cstate tstate[MAX_STATES]; /* xmit connection states */
177 struct cstate rstate[MAX_STATES]; /* receive connection states */
178};
179/* flag values */
180#define SLF_TOSS 1 /* tossing rcvd frames because of input err */
181
9bccf70c 182#if !defined(KERNEL) || defined(__APPLE_API_PRIVATE)
1c79356b
A
183void sl_compress_init __P((struct slcompress *, int));
184u_int sl_compress_tcp __P((struct mbuf *,
185 struct ip *, struct slcompress *, int));
186int sl_uncompress_tcp __P((u_char **, int, u_int, struct slcompress *));
187int sl_uncompress_tcp_core __P((u_char *, int, int, u_int,
188 struct slcompress *, u_char **, u_int *));
189
9bccf70c 190#endif /* !KERNEL || __APPLE_API_PRIVATE */
1c79356b 191#endif /* !_NET_SLCOMPRESS_H_ */