| 1 | /* |
| 2 | * Definitions for tcp compression routines. |
| 3 | * |
| 4 | * Copyright (c) 1988, 1989 by Van Jacobson, Lawrence Berkeley Laboratory |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * $Header: slcompress.h,v 1.6 89/06/05 08:29:13 van Exp $ |
| 8 | */ |
| 9 | |
| 10 | #define MAX_STATES 16 /* must be > 2 and < 256 */ |
| 11 | #define MAX_HDR MLEN /* XXX 4bsd-ism: should really be 128 */ |
| 12 | |
| 13 | /* |
| 14 | * Compressed packet format: |
| 15 | * |
| 16 | * The first octet contains the packet type (top 3 bits), TCP |
| 17 | * 'push' bit, and flags that indicate which of the 4 TCP sequence |
| 18 | * numbers have changed (bottom 5 bits). The next octet is a |
| 19 | * conversation number that associates a saved IP/TCP header with |
| 20 | * the compressed packet. The next two octets are the TCP checksum |
| 21 | * from the original datagram. The next 0 to 15 octets are |
| 22 | * sequence number changes, one change per bit set in the header |
| 23 | * (there may be no changes and there are two special cases where |
| 24 | * the receiver implicitly knows what changed -- see below). |
| 25 | * |
| 26 | * There are 5 numbers which can change (they are always inserted |
| 27 | * in the following order): TCP urgent pointer, window, |
| 28 | * acknowlegement, sequence number and IP ID. (The urgent pointer |
| 29 | * is different from the others in that its value is sent, not the |
| 30 | * change in value.) Since typical use of SLIP links is biased |
| 31 | * toward small packets (see comments on MTU/MSS below), changes |
| 32 | * use a variable length coding with one octet for numbers in the |
| 33 | * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the |
| 34 | * range 256 - 65535 or 0. (If the change in sequence number or |
| 35 | * ack is more than 65535, an uncompressed packet is sent.) |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * Packet types (must not conflict with IP protocol version) |
| 40 | * |
| 41 | * The top nibble of the first octet is the packet type. There are |
| 42 | * three possible types: IP (not proto TCP or tcp with one of the |
| 43 | * control flags set); uncompressed TCP (a normal IP/TCP packet but |
| 44 | * with the 8-bit protocol field replaced by an 8-bit connection id -- |
| 45 | * this type of packet syncs the sender & receiver); and compressed |
| 46 | * TCP (described above). |
| 47 | * |
| 48 | * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and |
| 49 | * is logically part of the 4-bit "changes" field that follows. Top |
| 50 | * three bits are actual packet type. For backward compatibility |
| 51 | * and in the interest of conserving bits, numbers are chosen so the |
| 52 | * IP protocol version number (4) which normally appears in this nibble |
| 53 | * means "IP packet". |
| 54 | */ |
| 55 | |
| 56 | /* packet types */ |
| 57 | #define TYPE_IP 0x40 |
| 58 | #define TYPE_UNCOMPRESSED_TCP 0x70 |
| 59 | #define TYPE_COMPRESSED_TCP 0x80 |
| 60 | #define TYPE_ERROR 0x00 |
| 61 | |
| 62 | /* Bits in first octet of compressed packet */ |
| 63 | #define NEW_C 0x40 /* flag bits for what changed in a packet */ |
| 64 | #define NEW_I 0x20 |
| 65 | #define NEW_S 0x08 |
| 66 | #define NEW_A 0x04 |
| 67 | #define NEW_W 0x02 |
| 68 | #define NEW_U 0x01 |
| 69 | |
| 70 | /* reserved, special-case values of above */ |
| 71 | #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */ |
| 72 | #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */ |
| 73 | #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U) |
| 74 | |
| 75 | #define TCP_PUSH_BIT 0x10 |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * "state" data for each active tcp conversation on the wire. This is |
| 80 | * basically a copy of the entire IP/TCP header from the last packet |
| 81 | * we saw from the conversation together with a small identifier |
| 82 | * the transmit & receive ends of the line use to locate saved header. |
| 83 | */ |
| 84 | struct cstate { |
| 85 | struct cstate *cs_next; /* next most recently used cstate (xmit only) */ |
| 86 | u_short cs_hlen; /* size of hdr (receive only) */ |
| 87 | u_char cs_id; /* connection # associated with this state */ |
| 88 | u_char cs_filler; |
| 89 | union { |
| 90 | char hdr[MAX_HDR]; |
| 91 | struct ip csu_ip; /* ip/tcp hdr from most recent packet */ |
| 92 | } u; |
| 93 | }; |
| 94 | #define cs_ip u.csu_ip |
| 95 | |
| 96 | /* |
| 97 | * all the state data for one serial line (we need one of these |
| 98 | * per line). |
| 99 | */ |
| 100 | struct slcompress { |
| 101 | struct cstate *last_cs; /* most recently used tstate */ |
| 102 | u_char last_recv; /* last rcvd conn. id */ |
| 103 | u_char last_xmit; /* last sent conn. id */ |
| 104 | u_short flags; |
| 105 | #ifndef NO_SL_STATS |
| 106 | int sls_packets; /* outbound packets */ |
| 107 | int sls_compressed; /* outbound compressed packets */ |
| 108 | int sls_searches; /* searches for connection state */ |
| 109 | int sls_misses; /* times couldn't find conn. state */ |
| 110 | int sls_uncompressedin; /* inbound uncompressed packets */ |
| 111 | int sls_compressedin; /* inbound compressed packets */ |
| 112 | int sls_errorin; /* inbound unknown type packets */ |
| 113 | int sls_tossed; /* inbound packets tossed because of error */ |
| 114 | #endif |
| 115 | struct cstate tstate[MAX_STATES]; /* xmit connection states */ |
| 116 | struct cstate rstate[MAX_STATES]; /* receive connection states */ |
| 117 | }; |
| 118 | /* flag values */ |
| 119 | #define SLF_TOSS 1 /* tossing rcvd frames because of input err */ |
| 120 | |
| 121 | extern void sl_compress_init(/* struct slcompress * */); |
| 122 | extern u_char sl_compress_tcp(/* struct mbuf *, struct ip *, struct slcompress * */); |
| 123 | extern int sl_uncompress_tcp(/* u_char **, int, u_char, struct slcompress * */); |