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