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