Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed714 0:d616ece2d859 1 /*
mbed714 0:d616ece2d859 2 * Definitions for tcp compression routines.
mbed714 0:d616ece2d859 3 *
mbed714 0:d616ece2d859 4 * $Id: vj.h,v 1.7 2010/02/22 17:52:09 goldsimon Exp $
mbed714 0:d616ece2d859 5 *
mbed714 0:d616ece2d859 6 * Copyright (c) 1989 Regents of the University of California.
mbed714 0:d616ece2d859 7 * All rights reserved.
mbed714 0:d616ece2d859 8 *
mbed714 0:d616ece2d859 9 * Redistribution and use in source and binary forms are permitted
mbed714 0:d616ece2d859 10 * provided that the above copyright notice and this paragraph are
mbed714 0:d616ece2d859 11 * duplicated in all such forms and that any documentation,
mbed714 0:d616ece2d859 12 * advertising materials, and other materials related to such
mbed714 0:d616ece2d859 13 * distribution and use acknowledge that the software was developed
mbed714 0:d616ece2d859 14 * by the University of California, Berkeley. The name of the
mbed714 0:d616ece2d859 15 * University may not be used to endorse or promote products derived
mbed714 0:d616ece2d859 16 * from this software without specific prior written permission.
mbed714 0:d616ece2d859 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
mbed714 0:d616ece2d859 18 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
mbed714 0:d616ece2d859 19 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
mbed714 0:d616ece2d859 20 *
mbed714 0:d616ece2d859 21 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
mbed714 0:d616ece2d859 22 * - Initial distribution.
mbed714 0:d616ece2d859 23 */
mbed714 0:d616ece2d859 24
mbed714 0:d616ece2d859 25 #ifndef VJ_H
mbed714 0:d616ece2d859 26 #define VJ_H
mbed714 0:d616ece2d859 27
mbed714 0:d616ece2d859 28 #include "lwip/ip.h"
mbed714 0:d616ece2d859 29 #include "lwip/tcp_impl.h"
mbed714 0:d616ece2d859 30
mbed714 0:d616ece2d859 31 #define MAX_SLOTS 16 /* must be > 2 and < 256 */
mbed714 0:d616ece2d859 32 #define MAX_HDR 128
mbed714 0:d616ece2d859 33
mbed714 0:d616ece2d859 34 /*
mbed714 0:d616ece2d859 35 * Compressed packet format:
mbed714 0:d616ece2d859 36 *
mbed714 0:d616ece2d859 37 * The first octet contains the packet type (top 3 bits), TCP
mbed714 0:d616ece2d859 38 * 'push' bit, and flags that indicate which of the 4 TCP sequence
mbed714 0:d616ece2d859 39 * numbers have changed (bottom 5 bits). The next octet is a
mbed714 0:d616ece2d859 40 * conversation number that associates a saved IP/TCP header with
mbed714 0:d616ece2d859 41 * the compressed packet. The next two octets are the TCP checksum
mbed714 0:d616ece2d859 42 * from the original datagram. The next 0 to 15 octets are
mbed714 0:d616ece2d859 43 * sequence number changes, one change per bit set in the header
mbed714 0:d616ece2d859 44 * (there may be no changes and there are two special cases where
mbed714 0:d616ece2d859 45 * the receiver implicitly knows what changed -- see below).
mbed714 0:d616ece2d859 46 *
mbed714 0:d616ece2d859 47 * There are 5 numbers which can change (they are always inserted
mbed714 0:d616ece2d859 48 * in the following order): TCP urgent pointer, window,
mbed714 0:d616ece2d859 49 * acknowlegement, sequence number and IP ID. (The urgent pointer
mbed714 0:d616ece2d859 50 * is different from the others in that its value is sent, not the
mbed714 0:d616ece2d859 51 * change in value.) Since typical use of SLIP links is biased
mbed714 0:d616ece2d859 52 * toward small packets (see comments on MTU/MSS below), changes
mbed714 0:d616ece2d859 53 * use a variable length coding with one octet for numbers in the
mbed714 0:d616ece2d859 54 * range 1 - 255 and 3 octets (0, MSB, LSB) for numbers in the
mbed714 0:d616ece2d859 55 * range 256 - 65535 or 0. (If the change in sequence number or
mbed714 0:d616ece2d859 56 * ack is more than 65535, an uncompressed packet is sent.)
mbed714 0:d616ece2d859 57 */
mbed714 0:d616ece2d859 58
mbed714 0:d616ece2d859 59 /*
mbed714 0:d616ece2d859 60 * Packet types (must not conflict with IP protocol version)
mbed714 0:d616ece2d859 61 *
mbed714 0:d616ece2d859 62 * The top nibble of the first octet is the packet type. There are
mbed714 0:d616ece2d859 63 * three possible types: IP (not proto TCP or tcp with one of the
mbed714 0:d616ece2d859 64 * control flags set); uncompressed TCP (a normal IP/TCP packet but
mbed714 0:d616ece2d859 65 * with the 8-bit protocol field replaced by an 8-bit connection id --
mbed714 0:d616ece2d859 66 * this type of packet syncs the sender & receiver); and compressed
mbed714 0:d616ece2d859 67 * TCP (described above).
mbed714 0:d616ece2d859 68 *
mbed714 0:d616ece2d859 69 * LSB of 4-bit field is TCP "PUSH" bit (a worthless anachronism) and
mbed714 0:d616ece2d859 70 * is logically part of the 4-bit "changes" field that follows. Top
mbed714 0:d616ece2d859 71 * three bits are actual packet type. For backward compatibility
mbed714 0:d616ece2d859 72 * and in the interest of conserving bits, numbers are chosen so the
mbed714 0:d616ece2d859 73 * IP protocol version number (4) which normally appears in this nibble
mbed714 0:d616ece2d859 74 * means "IP packet".
mbed714 0:d616ece2d859 75 */
mbed714 0:d616ece2d859 76
mbed714 0:d616ece2d859 77 /* packet types */
mbed714 0:d616ece2d859 78 #define TYPE_IP 0x40
mbed714 0:d616ece2d859 79 #define TYPE_UNCOMPRESSED_TCP 0x70
mbed714 0:d616ece2d859 80 #define TYPE_COMPRESSED_TCP 0x80
mbed714 0:d616ece2d859 81 #define TYPE_ERROR 0x00
mbed714 0:d616ece2d859 82
mbed714 0:d616ece2d859 83 /* Bits in first octet of compressed packet */
mbed714 0:d616ece2d859 84 #define NEW_C 0x40 /* flag bits for what changed in a packet */
mbed714 0:d616ece2d859 85 #define NEW_I 0x20
mbed714 0:d616ece2d859 86 #define NEW_S 0x08
mbed714 0:d616ece2d859 87 #define NEW_A 0x04
mbed714 0:d616ece2d859 88 #define NEW_W 0x02
mbed714 0:d616ece2d859 89 #define NEW_U 0x01
mbed714 0:d616ece2d859 90
mbed714 0:d616ece2d859 91 /* reserved, special-case values of above */
mbed714 0:d616ece2d859 92 #define SPECIAL_I (NEW_S|NEW_W|NEW_U) /* echoed interactive traffic */
mbed714 0:d616ece2d859 93 #define SPECIAL_D (NEW_S|NEW_A|NEW_W|NEW_U) /* unidirectional data */
mbed714 0:d616ece2d859 94 #define SPECIALS_MASK (NEW_S|NEW_A|NEW_W|NEW_U)
mbed714 0:d616ece2d859 95
mbed714 0:d616ece2d859 96 #define TCP_PUSH_BIT 0x10
mbed714 0:d616ece2d859 97
mbed714 0:d616ece2d859 98
mbed714 0:d616ece2d859 99 /*
mbed714 0:d616ece2d859 100 * "state" data for each active tcp conversation on the wire. This is
mbed714 0:d616ece2d859 101 * basically a copy of the entire IP/TCP header from the last packet
mbed714 0:d616ece2d859 102 * we saw from the conversation together with a small identifier
mbed714 0:d616ece2d859 103 * the transmit & receive ends of the line use to locate saved header.
mbed714 0:d616ece2d859 104 */
mbed714 0:d616ece2d859 105 struct cstate {
mbed714 0:d616ece2d859 106 struct cstate *cs_next; /* next most recently used state (xmit only) */
mbed714 0:d616ece2d859 107 u_short cs_hlen; /* size of hdr (receive only) */
mbed714 0:d616ece2d859 108 u_char cs_id; /* connection # associated with this state */
mbed714 0:d616ece2d859 109 u_char cs_filler;
mbed714 0:d616ece2d859 110 union {
mbed714 0:d616ece2d859 111 char csu_hdr[MAX_HDR];
mbed714 0:d616ece2d859 112 struct ip_hdr csu_ip; /* ip/tcp hdr from most recent packet */
mbed714 0:d616ece2d859 113 } vjcs_u;
mbed714 0:d616ece2d859 114 };
mbed714 0:d616ece2d859 115 #define cs_ip vjcs_u.csu_ip
mbed714 0:d616ece2d859 116 #define cs_hdr vjcs_u.csu_hdr
mbed714 0:d616ece2d859 117
mbed714 0:d616ece2d859 118
mbed714 0:d616ece2d859 119 struct vjstat {
mbed714 0:d616ece2d859 120 unsigned long vjs_packets; /* outbound packets */
mbed714 0:d616ece2d859 121 unsigned long vjs_compressed; /* outbound compressed packets */
mbed714 0:d616ece2d859 122 unsigned long vjs_searches; /* searches for connection state */
mbed714 0:d616ece2d859 123 unsigned long vjs_misses; /* times couldn't find conn. state */
mbed714 0:d616ece2d859 124 unsigned long vjs_uncompressedin; /* inbound uncompressed packets */
mbed714 0:d616ece2d859 125 unsigned long vjs_compressedin; /* inbound compressed packets */
mbed714 0:d616ece2d859 126 unsigned long vjs_errorin; /* inbound unknown type packets */
mbed714 0:d616ece2d859 127 unsigned long vjs_tossed; /* inbound packets tossed because of error */
mbed714 0:d616ece2d859 128 };
mbed714 0:d616ece2d859 129
mbed714 0:d616ece2d859 130 /*
mbed714 0:d616ece2d859 131 * all the state data for one serial line (we need one of these per line).
mbed714 0:d616ece2d859 132 */
mbed714 0:d616ece2d859 133 struct vjcompress {
mbed714 0:d616ece2d859 134 struct cstate *last_cs; /* most recently used tstate */
mbed714 0:d616ece2d859 135 u_char last_recv; /* last rcvd conn. id */
mbed714 0:d616ece2d859 136 u_char last_xmit; /* last sent conn. id */
mbed714 0:d616ece2d859 137 u_short flags;
mbed714 0:d616ece2d859 138 u_char maxSlotIndex;
mbed714 0:d616ece2d859 139 u_char compressSlot; /* Flag indicating OK to compress slot ID. */
mbed714 0:d616ece2d859 140 #if LINK_STATS
mbed714 0:d616ece2d859 141 struct vjstat stats;
mbed714 0:d616ece2d859 142 #endif
mbed714 0:d616ece2d859 143 struct cstate tstate[MAX_SLOTS]; /* xmit connection states */
mbed714 0:d616ece2d859 144 struct cstate rstate[MAX_SLOTS]; /* receive connection states */
mbed714 0:d616ece2d859 145 };
mbed714 0:d616ece2d859 146
mbed714 0:d616ece2d859 147 /* flag values */
mbed714 0:d616ece2d859 148 #define VJF_TOSS 1U /* tossing rcvd frames because of input err */
mbed714 0:d616ece2d859 149
mbed714 0:d616ece2d859 150 extern void vj_compress_init (struct vjcompress *comp);
mbed714 0:d616ece2d859 151 extern u_int vj_compress_tcp (struct vjcompress *comp, struct pbuf *pb);
mbed714 0:d616ece2d859 152 extern void vj_uncompress_err (struct vjcompress *comp);
mbed714 0:d616ece2d859 153 extern int vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp);
mbed714 0:d616ece2d859 154 extern int vj_uncompress_tcp (struct pbuf **nb, struct vjcompress *comp);
mbed714 0:d616ece2d859 155
mbed714 0:d616ece2d859 156 #endif /* VJ_H */