Dependencies:   mbed

Committer:
gbeardall
Date:
Mon Oct 17 10:39:17 2011 +0000
Revision:
0:715023d993d6

        

Who changed what in which revision?

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