NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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