Committer:
donatien
Date:
Fri Aug 06 10:42:05 2010 +0000
Revision:
3:e02ec42cf9c8
Parent:
0:0f5a52711275

        

Who changed what in which revision?

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