slcompress.h revision 50477
16059Samurai/*
26059Samurai * Definitions for tcp compression routines.
36059Samurai *
46059Samurai * Copyright (c) 1989 Regents of the University of California.
56059Samurai * All rights reserved.
66059Samurai *
76059Samurai * Redistribution and use in source and binary forms are permitted
86059Samurai * provided that the above copyright notice and this paragraph are
96059Samurai * duplicated in all such forms and that any documentation,
106059Samurai * advertising materials, and other materials related to such
116059Samurai * distribution and use acknowledge that the software was developed
126059Samurai * by the University of California, Berkeley.  The name of the
136059Samurai * University may not be used to endorse or promote products derived
146059Samurai * from this software without specific prior written permission.
156059Samurai * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
166059Samurai * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
176059Samurai * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
188857Srgrimes *
1936960Sbrian * $Id: slcompress.h,v 1.11 1998/05/21 21:48:30 brian Exp $
208857Srgrimes *
216059Samurai *	Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
226059Samurai *	- Initial distribution.
236059Samurai */
246059Samurai
2536285Sbrian#define MIN_VJ_STATES 3
2636285Sbrian#define MAX_VJ_STATES 255
2736285Sbrian#define DEF_VJ_STATES 16		/* must be > 2 and < 256 */
2836285Sbrian#define MAX_HDR 128
296059Samurai
306059Samurai/*
316059Samurai * Compressed packet format:
326059Samurai *
336059Samurai * The first octet contains the packet type (top 3 bits), TCP
346059Samurai * 'push' bit, and flags that indicate which of the 4 TCP sequence
356059Samurai * numbers have changed (bottom 5 bits).  The next octet is a
366059Samurai * conversation number that associates a saved IP/TCP header with
376059Samurai * the compressed packet.  The next two octets are the TCP checksum
386059Samurai * from the original datagram.  The next 0 to 15 octets are
396059Samurai * sequence number changes, one change per bit set in the header
406059Samurai * (there may be no changes and there are two special cases where
416059Samurai * the receiver implicitly knows what changed -- see below).
428857Srgrimes *
436059Samurai * There are 5 numbers which can change (they are always inserted
446059Samurai * in the following order): TCP urgent pointer, window,
456059Samurai * acknowlegement, sequence number and IP ID.  (The urgent pointer
466059Samurai * is different from the others in that its value is sent, not the
476059Samurai * change in value.)  Since typical use of SLIP links is biased
486059Samurai * toward small packets (see comments on MTU/MSS below), changes
496059Samurai * use a variable length coding with one octet for numbers in the
506059Samurai * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
516059Samurai * range 256 - 65535 or 0.  (If the change in sequence number or
526059Samurai * ack is more than 65535, an uncompressed packet is sent.)
536059Samurai */
546059Samurai
556059Samurai/*
566059Samurai * Packet types (must not conflict with IP protocol version)
576059Samurai *
586059Samurai * The top nibble of the first octet is the packet type.  There are
596059Samurai * three possible types: IP (not proto TCP or tcp with one of the
606059Samurai * control flags set); uncompressed TCP (a normal IP/TCP packet but
616059Samurai * with the 8-bit protocol field replaced by an 8-bit connection id --
626059Samurai * this type of packet syncs the sender & receiver); and compressed
636059Samurai * TCP (described above).
646059Samurai *
656059Samurai * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
666059Samurai * is logically part of the 4-bit "changes" field that follows.  Top
676059Samurai * three bits are actual packet type.  For backward compatibility
686059Samurai * and in the interest of conserving bits, numbers are chosen so the
696059Samurai * IP protocol version number (4) which normally appears in this nibble
706059Samurai * means "IP packet".
716059Samurai */
726059Samurai
736059Samurai/* packet types */
746059Samurai#define TYPE_IP 0x40
756059Samurai#define TYPE_UNCOMPRESSED_TCP 0x70
766059Samurai#define TYPE_COMPRESSED_TCP 0x80
776059Samurai#define TYPE_ERROR 0x00
786059Samurai
796059Samurai/* Bits in first octet of compressed packet */
8028679Sbrian#define NEW_C	0x40		/* flag bits for what changed in a packet */
816059Samurai#define NEW_I	0x20
826059Samurai#define NEW_S	0x08
836059Samurai#define NEW_A	0x04
846059Samurai#define NEW_W	0x02
856059Samurai#define NEW_U	0x01
866059Samurai
876059Samurai/* reserved, special-case values of above */
8828679Sbrian#define SPECIAL_I (NEW_S|NEW_W|NEW_U)	/* echoed interactive traffic */
896059Samurai#define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U)	/* unidirectional data */
906059Samurai#define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
916059Samurai
926059Samurai#define TCP_PUSH_BIT 0x10
936059Samurai
946059Samurai/*
956059Samurai * "state" data for each active tcp conversation on the wire.  This is
966059Samurai * basically a copy of the entire IP/TCP header from the last packet
976059Samurai * we saw from the conversation together with a small identifier
986059Samurai * the transmit & receive ends of the line use to locate saved header.
996059Samurai */
1006059Samuraistruct cstate {
10128679Sbrian  struct cstate *cs_next;	/* next most recently used cstate (xmit only) */
10228679Sbrian  u_short cs_hlen;		/* size of hdr (receive only) */
10328679Sbrian  u_char cs_id;			/* connection # associated with this state */
10428679Sbrian  u_char cs_filler;
10528679Sbrian  union {
10628679Sbrian    char csu_hdr[MAX_HDR];
10728679Sbrian    struct ip csu_ip;		/* ip/tcp hdr from most recent packet */
10830715Sbrian  } slcs_u;
1096059Samurai};
11028679Sbrian
1116059Samurai#define cs_ip slcs_u.csu_ip
1126059Samurai#define cs_hdr slcs_u.csu_hdr
1136059Samurai
1146059Samurai/*
1156059Samurai * all the state data for one serial line (we need one of these
1166059Samurai * per line).
1176059Samurai */
1186059Samuraistruct slcompress {
11928679Sbrian  struct cstate *last_cs;	/* most recently used tstate */
12028679Sbrian  u_char last_recv;		/* last rcvd conn. id */
12128679Sbrian  u_char last_xmit;		/* last sent conn. id */
12228679Sbrian  u_short flags;
12336285Sbrian  struct cstate tstate[MAX_VJ_STATES];	/* xmit connection states */
12436285Sbrian  struct cstate rstate[MAX_VJ_STATES];	/* receive connection states */
1256059Samurai};
1266059Samurai
12736285Sbrianstruct slstat {
12836285Sbrian  int sls_packets;		/* outbound packets */
12936285Sbrian  int sls_compressed;		/* outbound compressed packets */
13036285Sbrian  int sls_searches;		/* searches for connection state */
13136285Sbrian  int sls_misses;		/* times couldn't find conn. state */
13236285Sbrian  int sls_uncompressedin;	/* inbound uncompressed packets */
13336285Sbrian  int sls_compressedin;		/* inbound compressed packets */
13436285Sbrian  int sls_errorin;		/* inbound unknown type packets */
13536285Sbrian  int sls_tossed;		/* inbound packets tossed because of error */
13636285Sbrian};
13736285Sbrian
1386059Samurai/* flag values */
1396059Samurai#define SLF_TOSS 1		/* tossing rcvd frames because of input err */
1406059Samurai
14136285Sbrianstruct mbuf;
14236285Sbrianstruct cmdargs;
14336285Sbrian
14430715Sbrianextern void sl_compress_init(struct slcompress *, int);
14536285Sbrianextern u_char sl_compress_tcp(struct mbuf *, struct ip *, struct slcompress *,
14636285Sbrian                              struct slstat *, int);
14736285Sbrianextern int sl_uncompress_tcp(u_char **, int, u_int, struct slcompress *,
14836960Sbrian                             struct slstat *, int);
14936285Sbrianextern int sl_Show(struct cmdargs const *);
150