Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:41:36 2011 +0000
Revision:
0:8f5825f330b0
setDataLen hacked to 180bytes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RodColeman 0:8f5825f330b0 1 /*
RodColeman 0:8f5825f330b0 2 * Routines to compress and uncompess tcp packets (for transmission
RodColeman 0:8f5825f330b0 3 * over low speed serial lines.
RodColeman 0:8f5825f330b0 4 *
RodColeman 0:8f5825f330b0 5 * Copyright (c) 1989 Regents of the University of California.
RodColeman 0:8f5825f330b0 6 * All rights reserved.
RodColeman 0:8f5825f330b0 7 *
RodColeman 0:8f5825f330b0 8 * Redistribution and use in source and binary forms are permitted
RodColeman 0:8f5825f330b0 9 * provided that the above copyright notice and this paragraph are
RodColeman 0:8f5825f330b0 10 * duplicated in all such forms and that any documentation,
RodColeman 0:8f5825f330b0 11 * advertising materials, and other materials related to such
RodColeman 0:8f5825f330b0 12 * distribution and use acknowledge that the software was developed
RodColeman 0:8f5825f330b0 13 * by the University of California, Berkeley. The name of the
RodColeman 0:8f5825f330b0 14 * University may not be used to endorse or promote products derived
RodColeman 0:8f5825f330b0 15 * from this software without specific prior written permission.
RodColeman 0:8f5825f330b0 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
RodColeman 0:8f5825f330b0 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
RodColeman 0:8f5825f330b0 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
RodColeman 0:8f5825f330b0 19 *
RodColeman 0:8f5825f330b0 20 * Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
RodColeman 0:8f5825f330b0 21 * Initial distribution.
RodColeman 0:8f5825f330b0 22 *
RodColeman 0:8f5825f330b0 23 * Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au,
RodColeman 0:8f5825f330b0 24 * so that the entire packet being decompressed doesn't have
RodColeman 0:8f5825f330b0 25 * to be in contiguous memory (just the compressed header).
RodColeman 0:8f5825f330b0 26 *
RodColeman 0:8f5825f330b0 27 * Modified March 1998 by Guy Lancaster, glanca@gesn.com,
RodColeman 0:8f5825f330b0 28 * for a 16 bit processor.
RodColeman 0:8f5825f330b0 29 */
RodColeman 0:8f5825f330b0 30
RodColeman 0:8f5825f330b0 31 #include "lwip/opt.h"
RodColeman 0:8f5825f330b0 32
RodColeman 0:8f5825f330b0 33 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
RodColeman 0:8f5825f330b0 34
RodColeman 0:8f5825f330b0 35 #include "ppp.h"
RodColeman 0:8f5825f330b0 36 #include "pppdebug.h"
RodColeman 0:8f5825f330b0 37
RodColeman 0:8f5825f330b0 38 #include "vj.h"
RodColeman 0:8f5825f330b0 39
RodColeman 0:8f5825f330b0 40 #include <string.h>
RodColeman 0:8f5825f330b0 41
RodColeman 0:8f5825f330b0 42 #if VJ_SUPPORT
RodColeman 0:8f5825f330b0 43
RodColeman 0:8f5825f330b0 44 #if LINK_STATS
RodColeman 0:8f5825f330b0 45 #define INCR(counter) ++comp->stats.counter
RodColeman 0:8f5825f330b0 46 #else
RodColeman 0:8f5825f330b0 47 #define INCR(counter)
RodColeman 0:8f5825f330b0 48 #endif
RodColeman 0:8f5825f330b0 49
RodColeman 0:8f5825f330b0 50 void
RodColeman 0:8f5825f330b0 51 vj_compress_init(struct vjcompress *comp)
RodColeman 0:8f5825f330b0 52 {
RodColeman 0:8f5825f330b0 53 register u_char i;
RodColeman 0:8f5825f330b0 54 register struct cstate *tstate = comp->tstate;
RodColeman 0:8f5825f330b0 55
RodColeman 0:8f5825f330b0 56 #if MAX_SLOTS == 0
RodColeman 0:8f5825f330b0 57 memset((char *)comp, 0, sizeof(*comp));
RodColeman 0:8f5825f330b0 58 #endif
RodColeman 0:8f5825f330b0 59 comp->maxSlotIndex = MAX_SLOTS - 1;
RodColeman 0:8f5825f330b0 60 comp->compressSlot = 0; /* Disable slot ID compression by default. */
RodColeman 0:8f5825f330b0 61 for (i = MAX_SLOTS - 1; i > 0; --i) {
RodColeman 0:8f5825f330b0 62 tstate[i].cs_id = i;
RodColeman 0:8f5825f330b0 63 tstate[i].cs_next = &tstate[i - 1];
RodColeman 0:8f5825f330b0 64 }
RodColeman 0:8f5825f330b0 65 tstate[0].cs_next = &tstate[MAX_SLOTS - 1];
RodColeman 0:8f5825f330b0 66 tstate[0].cs_id = 0;
RodColeman 0:8f5825f330b0 67 comp->last_cs = &tstate[0];
RodColeman 0:8f5825f330b0 68 comp->last_recv = 255;
RodColeman 0:8f5825f330b0 69 comp->last_xmit = 255;
RodColeman 0:8f5825f330b0 70 comp->flags = VJF_TOSS;
RodColeman 0:8f5825f330b0 71 }
RodColeman 0:8f5825f330b0 72
RodColeman 0:8f5825f330b0 73
RodColeman 0:8f5825f330b0 74 /* ENCODE encodes a number that is known to be non-zero. ENCODEZ
RodColeman 0:8f5825f330b0 75 * checks for zero (since zero has to be encoded in the long, 3 byte
RodColeman 0:8f5825f330b0 76 * form).
RodColeman 0:8f5825f330b0 77 */
RodColeman 0:8f5825f330b0 78 #define ENCODE(n) { \
RodColeman 0:8f5825f330b0 79 if ((u_short)(n) >= 256) { \
RodColeman 0:8f5825f330b0 80 *cp++ = 0; \
RodColeman 0:8f5825f330b0 81 cp[1] = (u_char)(n); \
RodColeman 0:8f5825f330b0 82 cp[0] = (u_char)((n) >> 8); \
RodColeman 0:8f5825f330b0 83 cp += 2; \
RodColeman 0:8f5825f330b0 84 } else { \
RodColeman 0:8f5825f330b0 85 *cp++ = (u_char)(n); \
RodColeman 0:8f5825f330b0 86 } \
RodColeman 0:8f5825f330b0 87 }
RodColeman 0:8f5825f330b0 88 #define ENCODEZ(n) { \
RodColeman 0:8f5825f330b0 89 if ((u_short)(n) >= 256 || (u_short)(n) == 0) { \
RodColeman 0:8f5825f330b0 90 *cp++ = 0; \
RodColeman 0:8f5825f330b0 91 cp[1] = (u_char)(n); \
RodColeman 0:8f5825f330b0 92 cp[0] = (u_char)((n) >> 8); \
RodColeman 0:8f5825f330b0 93 cp += 2; \
RodColeman 0:8f5825f330b0 94 } else { \
RodColeman 0:8f5825f330b0 95 *cp++ = (u_char)(n); \
RodColeman 0:8f5825f330b0 96 } \
RodColeman 0:8f5825f330b0 97 }
RodColeman 0:8f5825f330b0 98
RodColeman 0:8f5825f330b0 99 #define DECODEL(f) { \
RodColeman 0:8f5825f330b0 100 if (*cp == 0) {\
RodColeman 0:8f5825f330b0 101 u32_t tmp = ntohl(f) + ((cp[1] << 8) | cp[2]); \
RodColeman 0:8f5825f330b0 102 (f) = htonl(tmp); \
RodColeman 0:8f5825f330b0 103 cp += 3; \
RodColeman 0:8f5825f330b0 104 } else { \
RodColeman 0:8f5825f330b0 105 u32_t tmp = ntohl(f) + (u32_t)*cp++; \
RodColeman 0:8f5825f330b0 106 (f) = htonl(tmp); \
RodColeman 0:8f5825f330b0 107 } \
RodColeman 0:8f5825f330b0 108 }
RodColeman 0:8f5825f330b0 109
RodColeman 0:8f5825f330b0 110 #define DECODES(f) { \
RodColeman 0:8f5825f330b0 111 if (*cp == 0) {\
RodColeman 0:8f5825f330b0 112 u_short tmp = ntohs(f) + (((u_short)cp[1] << 8) | cp[2]); \
RodColeman 0:8f5825f330b0 113 (f) = htons(tmp); \
RodColeman 0:8f5825f330b0 114 cp += 3; \
RodColeman 0:8f5825f330b0 115 } else { \
RodColeman 0:8f5825f330b0 116 u_short tmp = ntohs(f) + (u_short)*cp++; \
RodColeman 0:8f5825f330b0 117 (f) = htons(tmp); \
RodColeman 0:8f5825f330b0 118 } \
RodColeman 0:8f5825f330b0 119 }
RodColeman 0:8f5825f330b0 120
RodColeman 0:8f5825f330b0 121 #define DECODEU(f) { \
RodColeman 0:8f5825f330b0 122 if (*cp == 0) {\
RodColeman 0:8f5825f330b0 123 (f) = htons(((u_short)cp[1] << 8) | cp[2]); \
RodColeman 0:8f5825f330b0 124 cp += 3; \
RodColeman 0:8f5825f330b0 125 } else { \
RodColeman 0:8f5825f330b0 126 (f) = htons((u_short)*cp++); \
RodColeman 0:8f5825f330b0 127 } \
RodColeman 0:8f5825f330b0 128 }
RodColeman 0:8f5825f330b0 129
RodColeman 0:8f5825f330b0 130 /*
RodColeman 0:8f5825f330b0 131 * vj_compress_tcp - Attempt to do Van Jacobson header compression on a
RodColeman 0:8f5825f330b0 132 * packet. This assumes that nb and comp are not null and that the first
RodColeman 0:8f5825f330b0 133 * buffer of the chain contains a valid IP header.
RodColeman 0:8f5825f330b0 134 * Return the VJ type code indicating whether or not the packet was
RodColeman 0:8f5825f330b0 135 * compressed.
RodColeman 0:8f5825f330b0 136 */
RodColeman 0:8f5825f330b0 137 u_int
RodColeman 0:8f5825f330b0 138 vj_compress_tcp(struct vjcompress *comp, struct pbuf *pb)
RodColeman 0:8f5825f330b0 139 {
RodColeman 0:8f5825f330b0 140 register struct ip_hdr *ip = (struct ip_hdr *)pb->payload;
RodColeman 0:8f5825f330b0 141 register struct cstate *cs = comp->last_cs->cs_next;
RodColeman 0:8f5825f330b0 142 register u_short hlen = IPH_HL(ip);
RodColeman 0:8f5825f330b0 143 register struct tcp_hdr *oth;
RodColeman 0:8f5825f330b0 144 register struct tcp_hdr *th;
RodColeman 0:8f5825f330b0 145 register u_short deltaS, deltaA;
RodColeman 0:8f5825f330b0 146 register u_long deltaL;
RodColeman 0:8f5825f330b0 147 register u_int changes = 0;
RodColeman 0:8f5825f330b0 148 u_char new_seq[16];
RodColeman 0:8f5825f330b0 149 register u_char *cp = new_seq;
RodColeman 0:8f5825f330b0 150
RodColeman 0:8f5825f330b0 151 /*
RodColeman 0:8f5825f330b0 152 * Check that the packet is IP proto TCP.
RodColeman 0:8f5825f330b0 153 */
RodColeman 0:8f5825f330b0 154 if (IPH_PROTO(ip) != IP_PROTO_TCP) {
RodColeman 0:8f5825f330b0 155 return (TYPE_IP);
RodColeman 0:8f5825f330b0 156 }
RodColeman 0:8f5825f330b0 157
RodColeman 0:8f5825f330b0 158 /*
RodColeman 0:8f5825f330b0 159 * Bail if this is an IP fragment or if the TCP packet isn't
RodColeman 0:8f5825f330b0 160 * `compressible' (i.e., ACK isn't set or some other control bit is
RodColeman 0:8f5825f330b0 161 * set).
RodColeman 0:8f5825f330b0 162 */
RodColeman 0:8f5825f330b0 163 if ((IPH_OFFSET(ip) & PP_HTONS(0x3fff)) || pb->tot_len < 40) {
RodColeman 0:8f5825f330b0 164 return (TYPE_IP);
RodColeman 0:8f5825f330b0 165 }
RodColeman 0:8f5825f330b0 166 th = (struct tcp_hdr *)&((long *)ip)[hlen];
RodColeman 0:8f5825f330b0 167 if ((TCPH_FLAGS(th) & (TCP_SYN|TCP_FIN|TCP_RST|TCP_ACK)) != TCP_ACK) {
RodColeman 0:8f5825f330b0 168 return (TYPE_IP);
RodColeman 0:8f5825f330b0 169 }
RodColeman 0:8f5825f330b0 170 /*
RodColeman 0:8f5825f330b0 171 * Packet is compressible -- we're going to send either a
RodColeman 0:8f5825f330b0 172 * COMPRESSED_TCP or UNCOMPRESSED_TCP packet. Either way we need
RodColeman 0:8f5825f330b0 173 * to locate (or create) the connection state. Special case the
RodColeman 0:8f5825f330b0 174 * most recently used connection since it's most likely to be used
RodColeman 0:8f5825f330b0 175 * again & we don't have to do any reordering if it's used.
RodColeman 0:8f5825f330b0 176 */
RodColeman 0:8f5825f330b0 177 INCR(vjs_packets);
RodColeman 0:8f5825f330b0 178 if (!ip_addr_cmp(&ip->src, &cs->cs_ip.src)
RodColeman 0:8f5825f330b0 179 || !ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
RodColeman 0:8f5825f330b0 180 || *(long *)th != ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
RodColeman 0:8f5825f330b0 181 /*
RodColeman 0:8f5825f330b0 182 * Wasn't the first -- search for it.
RodColeman 0:8f5825f330b0 183 *
RodColeman 0:8f5825f330b0 184 * States are kept in a circularly linked list with
RodColeman 0:8f5825f330b0 185 * last_cs pointing to the end of the list. The
RodColeman 0:8f5825f330b0 186 * list is kept in lru order by moving a state to the
RodColeman 0:8f5825f330b0 187 * head of the list whenever it is referenced. Since
RodColeman 0:8f5825f330b0 188 * the list is short and, empirically, the connection
RodColeman 0:8f5825f330b0 189 * we want is almost always near the front, we locate
RodColeman 0:8f5825f330b0 190 * states via linear search. If we don't find a state
RodColeman 0:8f5825f330b0 191 * for the datagram, the oldest state is (re-)used.
RodColeman 0:8f5825f330b0 192 */
RodColeman 0:8f5825f330b0 193 register struct cstate *lcs;
RodColeman 0:8f5825f330b0 194 register struct cstate *lastcs = comp->last_cs;
RodColeman 0:8f5825f330b0 195
RodColeman 0:8f5825f330b0 196 do {
RodColeman 0:8f5825f330b0 197 lcs = cs; cs = cs->cs_next;
RodColeman 0:8f5825f330b0 198 INCR(vjs_searches);
RodColeman 0:8f5825f330b0 199 if (ip_addr_cmp(&ip->src, &cs->cs_ip.src)
RodColeman 0:8f5825f330b0 200 && ip_addr_cmp(&ip->dest, &cs->cs_ip.dest)
RodColeman 0:8f5825f330b0 201 && *(long *)th == ((long *)&cs->cs_ip)[IPH_HL(&cs->cs_ip)]) {
RodColeman 0:8f5825f330b0 202 goto found;
RodColeman 0:8f5825f330b0 203 }
RodColeman 0:8f5825f330b0 204 } while (cs != lastcs);
RodColeman 0:8f5825f330b0 205
RodColeman 0:8f5825f330b0 206 /*
RodColeman 0:8f5825f330b0 207 * Didn't find it -- re-use oldest cstate. Send an
RodColeman 0:8f5825f330b0 208 * uncompressed packet that tells the other side what
RodColeman 0:8f5825f330b0 209 * connection number we're using for this conversation.
RodColeman 0:8f5825f330b0 210 * Note that since the state list is circular, the oldest
RodColeman 0:8f5825f330b0 211 * state points to the newest and we only need to set
RodColeman 0:8f5825f330b0 212 * last_cs to update the lru linkage.
RodColeman 0:8f5825f330b0 213 */
RodColeman 0:8f5825f330b0 214 INCR(vjs_misses);
RodColeman 0:8f5825f330b0 215 comp->last_cs = lcs;
RodColeman 0:8f5825f330b0 216 hlen += TCPH_OFFSET(th);
RodColeman 0:8f5825f330b0 217 hlen <<= 2;
RodColeman 0:8f5825f330b0 218 /* Check that the IP/TCP headers are contained in the first buffer. */
RodColeman 0:8f5825f330b0 219 if (hlen > pb->len) {
RodColeman 0:8f5825f330b0 220 return (TYPE_IP);
RodColeman 0:8f5825f330b0 221 }
RodColeman 0:8f5825f330b0 222 goto uncompressed;
RodColeman 0:8f5825f330b0 223
RodColeman 0:8f5825f330b0 224 found:
RodColeman 0:8f5825f330b0 225 /*
RodColeman 0:8f5825f330b0 226 * Found it -- move to the front on the connection list.
RodColeman 0:8f5825f330b0 227 */
RodColeman 0:8f5825f330b0 228 if (cs == lastcs) {
RodColeman 0:8f5825f330b0 229 comp->last_cs = lcs;
RodColeman 0:8f5825f330b0 230 } else {
RodColeman 0:8f5825f330b0 231 lcs->cs_next = cs->cs_next;
RodColeman 0:8f5825f330b0 232 cs->cs_next = lastcs->cs_next;
RodColeman 0:8f5825f330b0 233 lastcs->cs_next = cs;
RodColeman 0:8f5825f330b0 234 }
RodColeman 0:8f5825f330b0 235 }
RodColeman 0:8f5825f330b0 236
RodColeman 0:8f5825f330b0 237 oth = (struct tcp_hdr *)&((long *)&cs->cs_ip)[hlen];
RodColeman 0:8f5825f330b0 238 deltaS = hlen;
RodColeman 0:8f5825f330b0 239 hlen += TCPH_OFFSET(th);
RodColeman 0:8f5825f330b0 240 hlen <<= 2;
RodColeman 0:8f5825f330b0 241 /* Check that the IP/TCP headers are contained in the first buffer. */
RodColeman 0:8f5825f330b0 242 if (hlen > pb->len) {
RodColeman 0:8f5825f330b0 243 PPPDEBUG(LOG_INFO, ("vj_compress_tcp: header len %d spans buffers\n", hlen));
RodColeman 0:8f5825f330b0 244 return (TYPE_IP);
RodColeman 0:8f5825f330b0 245 }
RodColeman 0:8f5825f330b0 246
RodColeman 0:8f5825f330b0 247 /*
RodColeman 0:8f5825f330b0 248 * Make sure that only what we expect to change changed. The first
RodColeman 0:8f5825f330b0 249 * line of the `if' checks the IP protocol version, header length &
RodColeman 0:8f5825f330b0 250 * type of service. The 2nd line checks the "Don't fragment" bit.
RodColeman 0:8f5825f330b0 251 * The 3rd line checks the time-to-live and protocol (the protocol
RodColeman 0:8f5825f330b0 252 * check is unnecessary but costless). The 4th line checks the TCP
RodColeman 0:8f5825f330b0 253 * header length. The 5th line checks IP options, if any. The 6th
RodColeman 0:8f5825f330b0 254 * line checks TCP options, if any. If any of these things are
RodColeman 0:8f5825f330b0 255 * different between the previous & current datagram, we send the
RodColeman 0:8f5825f330b0 256 * current datagram `uncompressed'.
RodColeman 0:8f5825f330b0 257 */
RodColeman 0:8f5825f330b0 258 if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0]
RodColeman 0:8f5825f330b0 259 || ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3]
RodColeman 0:8f5825f330b0 260 || ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4]
RodColeman 0:8f5825f330b0 261 || TCPH_OFFSET(th) != TCPH_OFFSET(oth)
RodColeman 0:8f5825f330b0 262 || (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2))
RodColeman 0:8f5825f330b0 263 || (TCPH_OFFSET(th) > 5 && BCMP(th + 1, oth + 1, (TCPH_OFFSET(th) - 5) << 2))) {
RodColeman 0:8f5825f330b0 264 goto uncompressed;
RodColeman 0:8f5825f330b0 265 }
RodColeman 0:8f5825f330b0 266
RodColeman 0:8f5825f330b0 267 /*
RodColeman 0:8f5825f330b0 268 * Figure out which of the changing fields changed. The
RodColeman 0:8f5825f330b0 269 * receiver expects changes in the order: urgent, window,
RodColeman 0:8f5825f330b0 270 * ack, seq (the order minimizes the number of temporaries
RodColeman 0:8f5825f330b0 271 * needed in this section of code).
RodColeman 0:8f5825f330b0 272 */
RodColeman 0:8f5825f330b0 273 if (TCPH_FLAGS(th) & TCP_URG) {
RodColeman 0:8f5825f330b0 274 deltaS = ntohs(th->urgp);
RodColeman 0:8f5825f330b0 275 ENCODEZ(deltaS);
RodColeman 0:8f5825f330b0 276 changes |= NEW_U;
RodColeman 0:8f5825f330b0 277 } else if (th->urgp != oth->urgp) {
RodColeman 0:8f5825f330b0 278 /* argh! URG not set but urp changed -- a sensible
RodColeman 0:8f5825f330b0 279 * implementation should never do this but RFC793
RodColeman 0:8f5825f330b0 280 * doesn't prohibit the change so we have to deal
RodColeman 0:8f5825f330b0 281 * with it. */
RodColeman 0:8f5825f330b0 282 goto uncompressed;
RodColeman 0:8f5825f330b0 283 }
RodColeman 0:8f5825f330b0 284
RodColeman 0:8f5825f330b0 285 if ((deltaS = (u_short)(ntohs(th->wnd) - ntohs(oth->wnd))) != 0) {
RodColeman 0:8f5825f330b0 286 ENCODE(deltaS);
RodColeman 0:8f5825f330b0 287 changes |= NEW_W;
RodColeman 0:8f5825f330b0 288 }
RodColeman 0:8f5825f330b0 289
RodColeman 0:8f5825f330b0 290 if ((deltaL = ntohl(th->ackno) - ntohl(oth->ackno)) != 0) {
RodColeman 0:8f5825f330b0 291 if (deltaL > 0xffff) {
RodColeman 0:8f5825f330b0 292 goto uncompressed;
RodColeman 0:8f5825f330b0 293 }
RodColeman 0:8f5825f330b0 294 deltaA = (u_short)deltaL;
RodColeman 0:8f5825f330b0 295 ENCODE(deltaA);
RodColeman 0:8f5825f330b0 296 changes |= NEW_A;
RodColeman 0:8f5825f330b0 297 }
RodColeman 0:8f5825f330b0 298
RodColeman 0:8f5825f330b0 299 if ((deltaL = ntohl(th->seqno) - ntohl(oth->seqno)) != 0) {
RodColeman 0:8f5825f330b0 300 if (deltaL > 0xffff) {
RodColeman 0:8f5825f330b0 301 goto uncompressed;
RodColeman 0:8f5825f330b0 302 }
RodColeman 0:8f5825f330b0 303 deltaS = (u_short)deltaL;
RodColeman 0:8f5825f330b0 304 ENCODE(deltaS);
RodColeman 0:8f5825f330b0 305 changes |= NEW_S;
RodColeman 0:8f5825f330b0 306 }
RodColeman 0:8f5825f330b0 307
RodColeman 0:8f5825f330b0 308 switch(changes) {
RodColeman 0:8f5825f330b0 309 case 0:
RodColeman 0:8f5825f330b0 310 /*
RodColeman 0:8f5825f330b0 311 * Nothing changed. If this packet contains data and the
RodColeman 0:8f5825f330b0 312 * last one didn't, this is probably a data packet following
RodColeman 0:8f5825f330b0 313 * an ack (normal on an interactive connection) and we send
RodColeman 0:8f5825f330b0 314 * it compressed. Otherwise it's probably a retransmit,
RodColeman 0:8f5825f330b0 315 * retransmitted ack or window probe. Send it uncompressed
RodColeman 0:8f5825f330b0 316 * in case the other side missed the compressed version.
RodColeman 0:8f5825f330b0 317 */
RodColeman 0:8f5825f330b0 318 if (IPH_LEN(ip) != IPH_LEN(&cs->cs_ip) &&
RodColeman 0:8f5825f330b0 319 ntohs(IPH_LEN(&cs->cs_ip)) == hlen) {
RodColeman 0:8f5825f330b0 320 break;
RodColeman 0:8f5825f330b0 321 }
RodColeman 0:8f5825f330b0 322
RodColeman 0:8f5825f330b0 323 /* (fall through) */
RodColeman 0:8f5825f330b0 324
RodColeman 0:8f5825f330b0 325 case SPECIAL_I:
RodColeman 0:8f5825f330b0 326 case SPECIAL_D:
RodColeman 0:8f5825f330b0 327 /*
RodColeman 0:8f5825f330b0 328 * actual changes match one of our special case encodings --
RodColeman 0:8f5825f330b0 329 * send packet uncompressed.
RodColeman 0:8f5825f330b0 330 */
RodColeman 0:8f5825f330b0 331 goto uncompressed;
RodColeman 0:8f5825f330b0 332
RodColeman 0:8f5825f330b0 333 case NEW_S|NEW_A:
RodColeman 0:8f5825f330b0 334 if (deltaS == deltaA && deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
RodColeman 0:8f5825f330b0 335 /* special case for echoed terminal traffic */
RodColeman 0:8f5825f330b0 336 changes = SPECIAL_I;
RodColeman 0:8f5825f330b0 337 cp = new_seq;
RodColeman 0:8f5825f330b0 338 }
RodColeman 0:8f5825f330b0 339 break;
RodColeman 0:8f5825f330b0 340
RodColeman 0:8f5825f330b0 341 case NEW_S:
RodColeman 0:8f5825f330b0 342 if (deltaS == ntohs(IPH_LEN(&cs->cs_ip)) - hlen) {
RodColeman 0:8f5825f330b0 343 /* special case for data xfer */
RodColeman 0:8f5825f330b0 344 changes = SPECIAL_D;
RodColeman 0:8f5825f330b0 345 cp = new_seq;
RodColeman 0:8f5825f330b0 346 }
RodColeman 0:8f5825f330b0 347 break;
RodColeman 0:8f5825f330b0 348 }
RodColeman 0:8f5825f330b0 349
RodColeman 0:8f5825f330b0 350 deltaS = (u_short)(ntohs(IPH_ID(ip)) - ntohs(IPH_ID(&cs->cs_ip)));
RodColeman 0:8f5825f330b0 351 if (deltaS != 1) {
RodColeman 0:8f5825f330b0 352 ENCODEZ(deltaS);
RodColeman 0:8f5825f330b0 353 changes |= NEW_I;
RodColeman 0:8f5825f330b0 354 }
RodColeman 0:8f5825f330b0 355 if (TCPH_FLAGS(th) & TCP_PSH) {
RodColeman 0:8f5825f330b0 356 changes |= TCP_PUSH_BIT;
RodColeman 0:8f5825f330b0 357 }
RodColeman 0:8f5825f330b0 358 /*
RodColeman 0:8f5825f330b0 359 * Grab the cksum before we overwrite it below. Then update our
RodColeman 0:8f5825f330b0 360 * state with this packet's header.
RodColeman 0:8f5825f330b0 361 */
RodColeman 0:8f5825f330b0 362 deltaA = ntohs(th->chksum);
RodColeman 0:8f5825f330b0 363 BCOPY(ip, &cs->cs_ip, hlen);
RodColeman 0:8f5825f330b0 364
RodColeman 0:8f5825f330b0 365 /*
RodColeman 0:8f5825f330b0 366 * We want to use the original packet as our compressed packet.
RodColeman 0:8f5825f330b0 367 * (cp - new_seq) is the number of bytes we need for compressed
RodColeman 0:8f5825f330b0 368 * sequence numbers. In addition we need one byte for the change
RodColeman 0:8f5825f330b0 369 * mask, one for the connection id and two for the tcp checksum.
RodColeman 0:8f5825f330b0 370 * So, (cp - new_seq) + 4 bytes of header are needed. hlen is how
RodColeman 0:8f5825f330b0 371 * many bytes of the original packet to toss so subtract the two to
RodColeman 0:8f5825f330b0 372 * get the new packet size.
RodColeman 0:8f5825f330b0 373 */
RodColeman 0:8f5825f330b0 374 deltaS = (u_short)(cp - new_seq);
RodColeman 0:8f5825f330b0 375 if (!comp->compressSlot || comp->last_xmit != cs->cs_id) {
RodColeman 0:8f5825f330b0 376 comp->last_xmit = cs->cs_id;
RodColeman 0:8f5825f330b0 377 hlen -= deltaS + 4;
RodColeman 0:8f5825f330b0 378 if(pbuf_header(pb, -hlen)){
RodColeman 0:8f5825f330b0 379 /* Can we cope with this failing? Just assert for now */
RodColeman 0:8f5825f330b0 380 LWIP_ASSERT("pbuf_header failed\n", 0);
RodColeman 0:8f5825f330b0 381 }
RodColeman 0:8f5825f330b0 382 cp = (u_char *)pb->payload;
RodColeman 0:8f5825f330b0 383 *cp++ = (u_char)(changes | NEW_C);
RodColeman 0:8f5825f330b0 384 *cp++ = cs->cs_id;
RodColeman 0:8f5825f330b0 385 } else {
RodColeman 0:8f5825f330b0 386 hlen -= deltaS + 3;
RodColeman 0:8f5825f330b0 387 if(pbuf_header(pb, -hlen)) {
RodColeman 0:8f5825f330b0 388 /* Can we cope with this failing? Just assert for now */
RodColeman 0:8f5825f330b0 389 LWIP_ASSERT("pbuf_header failed\n", 0);
RodColeman 0:8f5825f330b0 390 }
RodColeman 0:8f5825f330b0 391 cp = (u_char *)pb->payload;
RodColeman 0:8f5825f330b0 392 *cp++ = (u_char)changes;
RodColeman 0:8f5825f330b0 393 }
RodColeman 0:8f5825f330b0 394 *cp++ = (u_char)(deltaA >> 8);
RodColeman 0:8f5825f330b0 395 *cp++ = (u_char)deltaA;
RodColeman 0:8f5825f330b0 396 BCOPY(new_seq, cp, deltaS);
RodColeman 0:8f5825f330b0 397 INCR(vjs_compressed);
RodColeman 0:8f5825f330b0 398 return (TYPE_COMPRESSED_TCP);
RodColeman 0:8f5825f330b0 399
RodColeman 0:8f5825f330b0 400 /*
RodColeman 0:8f5825f330b0 401 * Update connection state cs & send uncompressed packet (that is,
RodColeman 0:8f5825f330b0 402 * a regular ip/tcp packet but with the 'conversation id' we hope
RodColeman 0:8f5825f330b0 403 * to use on future compressed packets in the protocol field).
RodColeman 0:8f5825f330b0 404 */
RodColeman 0:8f5825f330b0 405 uncompressed:
RodColeman 0:8f5825f330b0 406 BCOPY(ip, &cs->cs_ip, hlen);
RodColeman 0:8f5825f330b0 407 IPH_PROTO_SET(ip, cs->cs_id);
RodColeman 0:8f5825f330b0 408 comp->last_xmit = cs->cs_id;
RodColeman 0:8f5825f330b0 409 return (TYPE_UNCOMPRESSED_TCP);
RodColeman 0:8f5825f330b0 410 }
RodColeman 0:8f5825f330b0 411
RodColeman 0:8f5825f330b0 412 /*
RodColeman 0:8f5825f330b0 413 * Called when we may have missed a packet.
RodColeman 0:8f5825f330b0 414 */
RodColeman 0:8f5825f330b0 415 void
RodColeman 0:8f5825f330b0 416 vj_uncompress_err(struct vjcompress *comp)
RodColeman 0:8f5825f330b0 417 {
RodColeman 0:8f5825f330b0 418 comp->flags |= VJF_TOSS;
RodColeman 0:8f5825f330b0 419 INCR(vjs_errorin);
RodColeman 0:8f5825f330b0 420 }
RodColeman 0:8f5825f330b0 421
RodColeman 0:8f5825f330b0 422 /*
RodColeman 0:8f5825f330b0 423 * "Uncompress" a packet of type TYPE_UNCOMPRESSED_TCP.
RodColeman 0:8f5825f330b0 424 * Return 0 on success, -1 on failure.
RodColeman 0:8f5825f330b0 425 */
RodColeman 0:8f5825f330b0 426 int
RodColeman 0:8f5825f330b0 427 vj_uncompress_uncomp(struct pbuf *nb, struct vjcompress *comp)
RodColeman 0:8f5825f330b0 428 {
RodColeman 0:8f5825f330b0 429 register u_int hlen;
RodColeman 0:8f5825f330b0 430 register struct cstate *cs;
RodColeman 0:8f5825f330b0 431 register struct ip_hdr *ip;
RodColeman 0:8f5825f330b0 432
RodColeman 0:8f5825f330b0 433 ip = (struct ip_hdr *)nb->payload;
RodColeman 0:8f5825f330b0 434 hlen = IPH_HL(ip) << 2;
RodColeman 0:8f5825f330b0 435 if (IPH_PROTO(ip) >= MAX_SLOTS
RodColeman 0:8f5825f330b0 436 || hlen + sizeof(struct tcp_hdr) > nb->len
RodColeman 0:8f5825f330b0 437 || (hlen += TCPH_OFFSET(((struct tcp_hdr *)&((char *)ip)[hlen])) << 2)
RodColeman 0:8f5825f330b0 438 > nb->len
RodColeman 0:8f5825f330b0 439 || hlen > MAX_HDR) {
RodColeman 0:8f5825f330b0 440 PPPDEBUG(LOG_INFO, ("vj_uncompress_uncomp: bad cid=%d, hlen=%d buflen=%d\n",
RodColeman 0:8f5825f330b0 441 IPH_PROTO(ip), hlen, nb->len));
RodColeman 0:8f5825f330b0 442 comp->flags |= VJF_TOSS;
RodColeman 0:8f5825f330b0 443 INCR(vjs_errorin);
RodColeman 0:8f5825f330b0 444 return -1;
RodColeman 0:8f5825f330b0 445 }
RodColeman 0:8f5825f330b0 446 cs = &comp->rstate[comp->last_recv = IPH_PROTO(ip)];
RodColeman 0:8f5825f330b0 447 comp->flags &=~ VJF_TOSS;
RodColeman 0:8f5825f330b0 448 IPH_PROTO_SET(ip, IP_PROTO_TCP);
RodColeman 0:8f5825f330b0 449 BCOPY(ip, &cs->cs_ip, hlen);
RodColeman 0:8f5825f330b0 450 cs->cs_hlen = (u_short)hlen;
RodColeman 0:8f5825f330b0 451 INCR(vjs_uncompressedin);
RodColeman 0:8f5825f330b0 452 return 0;
RodColeman 0:8f5825f330b0 453 }
RodColeman 0:8f5825f330b0 454
RodColeman 0:8f5825f330b0 455 /*
RodColeman 0:8f5825f330b0 456 * Uncompress a packet of type TYPE_COMPRESSED_TCP.
RodColeman 0:8f5825f330b0 457 * The packet is composed of a buffer chain and the first buffer
RodColeman 0:8f5825f330b0 458 * must contain an accurate chain length.
RodColeman 0:8f5825f330b0 459 * The first buffer must include the entire compressed TCP/IP header.
RodColeman 0:8f5825f330b0 460 * This procedure replaces the compressed header with the uncompressed
RodColeman 0:8f5825f330b0 461 * header and returns the length of the VJ header.
RodColeman 0:8f5825f330b0 462 */
RodColeman 0:8f5825f330b0 463 int
RodColeman 0:8f5825f330b0 464 vj_uncompress_tcp(struct pbuf **nb, struct vjcompress *comp)
RodColeman 0:8f5825f330b0 465 {
RodColeman 0:8f5825f330b0 466 u_char *cp;
RodColeman 0:8f5825f330b0 467 struct tcp_hdr *th;
RodColeman 0:8f5825f330b0 468 struct cstate *cs;
RodColeman 0:8f5825f330b0 469 u_short *bp;
RodColeman 0:8f5825f330b0 470 struct pbuf *n0 = *nb;
RodColeman 0:8f5825f330b0 471 u32_t tmp;
RodColeman 0:8f5825f330b0 472 u_int vjlen, hlen, changes;
RodColeman 0:8f5825f330b0 473
RodColeman 0:8f5825f330b0 474 INCR(vjs_compressedin);
RodColeman 0:8f5825f330b0 475 cp = (u_char *)n0->payload;
RodColeman 0:8f5825f330b0 476 changes = *cp++;
RodColeman 0:8f5825f330b0 477 if (changes & NEW_C) {
RodColeman 0:8f5825f330b0 478 /*
RodColeman 0:8f5825f330b0 479 * Make sure the state index is in range, then grab the state.
RodColeman 0:8f5825f330b0 480 * If we have a good state index, clear the 'discard' flag.
RodColeman 0:8f5825f330b0 481 */
RodColeman 0:8f5825f330b0 482 if (*cp >= MAX_SLOTS) {
RodColeman 0:8f5825f330b0 483 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: bad cid=%d\n", *cp));
RodColeman 0:8f5825f330b0 484 goto bad;
RodColeman 0:8f5825f330b0 485 }
RodColeman 0:8f5825f330b0 486
RodColeman 0:8f5825f330b0 487 comp->flags &=~ VJF_TOSS;
RodColeman 0:8f5825f330b0 488 comp->last_recv = *cp++;
RodColeman 0:8f5825f330b0 489 } else {
RodColeman 0:8f5825f330b0 490 /*
RodColeman 0:8f5825f330b0 491 * this packet has an implicit state index. If we've
RodColeman 0:8f5825f330b0 492 * had a line error since the last time we got an
RodColeman 0:8f5825f330b0 493 * explicit state index, we have to toss the packet.
RodColeman 0:8f5825f330b0 494 */
RodColeman 0:8f5825f330b0 495 if (comp->flags & VJF_TOSS) {
RodColeman 0:8f5825f330b0 496 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: tossing\n"));
RodColeman 0:8f5825f330b0 497 INCR(vjs_tossed);
RodColeman 0:8f5825f330b0 498 return (-1);
RodColeman 0:8f5825f330b0 499 }
RodColeman 0:8f5825f330b0 500 }
RodColeman 0:8f5825f330b0 501 cs = &comp->rstate[comp->last_recv];
RodColeman 0:8f5825f330b0 502 hlen = IPH_HL(&cs->cs_ip) << 2;
RodColeman 0:8f5825f330b0 503 th = (struct tcp_hdr *)&((u_char *)&cs->cs_ip)[hlen];
RodColeman 0:8f5825f330b0 504 th->chksum = htons((*cp << 8) | cp[1]);
RodColeman 0:8f5825f330b0 505 cp += 2;
RodColeman 0:8f5825f330b0 506 if (changes & TCP_PUSH_BIT) {
RodColeman 0:8f5825f330b0 507 TCPH_SET_FLAG(th, TCP_PSH);
RodColeman 0:8f5825f330b0 508 } else {
RodColeman 0:8f5825f330b0 509 TCPH_UNSET_FLAG(th, TCP_PSH);
RodColeman 0:8f5825f330b0 510 }
RodColeman 0:8f5825f330b0 511
RodColeman 0:8f5825f330b0 512 switch (changes & SPECIALS_MASK) {
RodColeman 0:8f5825f330b0 513 case SPECIAL_I:
RodColeman 0:8f5825f330b0 514 {
RodColeman 0:8f5825f330b0 515 register u32_t i = ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
RodColeman 0:8f5825f330b0 516 /* some compilers can't nest inline assembler.. */
RodColeman 0:8f5825f330b0 517 tmp = ntohl(th->ackno) + i;
RodColeman 0:8f5825f330b0 518 th->ackno = htonl(tmp);
RodColeman 0:8f5825f330b0 519 tmp = ntohl(th->seqno) + i;
RodColeman 0:8f5825f330b0 520 th->seqno = htonl(tmp);
RodColeman 0:8f5825f330b0 521 }
RodColeman 0:8f5825f330b0 522 break;
RodColeman 0:8f5825f330b0 523
RodColeman 0:8f5825f330b0 524 case SPECIAL_D:
RodColeman 0:8f5825f330b0 525 /* some compilers can't nest inline assembler.. */
RodColeman 0:8f5825f330b0 526 tmp = ntohl(th->seqno) + ntohs(IPH_LEN(&cs->cs_ip)) - cs->cs_hlen;
RodColeman 0:8f5825f330b0 527 th->seqno = htonl(tmp);
RodColeman 0:8f5825f330b0 528 break;
RodColeman 0:8f5825f330b0 529
RodColeman 0:8f5825f330b0 530 default:
RodColeman 0:8f5825f330b0 531 if (changes & NEW_U) {
RodColeman 0:8f5825f330b0 532 TCPH_SET_FLAG(th, TCP_URG);
RodColeman 0:8f5825f330b0 533 DECODEU(th->urgp);
RodColeman 0:8f5825f330b0 534 } else {
RodColeman 0:8f5825f330b0 535 TCPH_UNSET_FLAG(th, TCP_URG);
RodColeman 0:8f5825f330b0 536 }
RodColeman 0:8f5825f330b0 537 if (changes & NEW_W) {
RodColeman 0:8f5825f330b0 538 DECODES(th->wnd);
RodColeman 0:8f5825f330b0 539 }
RodColeman 0:8f5825f330b0 540 if (changes & NEW_A) {
RodColeman 0:8f5825f330b0 541 DECODEL(th->ackno);
RodColeman 0:8f5825f330b0 542 }
RodColeman 0:8f5825f330b0 543 if (changes & NEW_S) {
RodColeman 0:8f5825f330b0 544 DECODEL(th->seqno);
RodColeman 0:8f5825f330b0 545 }
RodColeman 0:8f5825f330b0 546 break;
RodColeman 0:8f5825f330b0 547 }
RodColeman 0:8f5825f330b0 548 if (changes & NEW_I) {
RodColeman 0:8f5825f330b0 549 DECODES(cs->cs_ip._id);
RodColeman 0:8f5825f330b0 550 } else {
RodColeman 0:8f5825f330b0 551 IPH_ID_SET(&cs->cs_ip, ntohs(IPH_ID(&cs->cs_ip)) + 1);
RodColeman 0:8f5825f330b0 552 IPH_ID_SET(&cs->cs_ip, htons(IPH_ID(&cs->cs_ip)));
RodColeman 0:8f5825f330b0 553 }
RodColeman 0:8f5825f330b0 554
RodColeman 0:8f5825f330b0 555 /*
RodColeman 0:8f5825f330b0 556 * At this point, cp points to the first byte of data in the
RodColeman 0:8f5825f330b0 557 * packet. Fill in the IP total length and update the IP
RodColeman 0:8f5825f330b0 558 * header checksum.
RodColeman 0:8f5825f330b0 559 */
RodColeman 0:8f5825f330b0 560 vjlen = (u_short)(cp - (u_char*)n0->payload);
RodColeman 0:8f5825f330b0 561 if (n0->len < vjlen) {
RodColeman 0:8f5825f330b0 562 /*
RodColeman 0:8f5825f330b0 563 * We must have dropped some characters (crc should detect
RodColeman 0:8f5825f330b0 564 * this but the old slip framing won't)
RodColeman 0:8f5825f330b0 565 */
RodColeman 0:8f5825f330b0 566 PPPDEBUG(LOG_INFO, ("vj_uncompress_tcp: head buffer %d too short %d\n",
RodColeman 0:8f5825f330b0 567 n0->len, vjlen));
RodColeman 0:8f5825f330b0 568 goto bad;
RodColeman 0:8f5825f330b0 569 }
RodColeman 0:8f5825f330b0 570
RodColeman 0:8f5825f330b0 571 #if BYTE_ORDER == LITTLE_ENDIAN
RodColeman 0:8f5825f330b0 572 tmp = n0->tot_len - vjlen + cs->cs_hlen;
RodColeman 0:8f5825f330b0 573 IPH_LEN_SET(&cs->cs_ip, htons((u_short)tmp));
RodColeman 0:8f5825f330b0 574 #else
RodColeman 0:8f5825f330b0 575 IPH_LEN_SET(&cs->cs_ip, htons(n0->tot_len - vjlen + cs->cs_hlen));
RodColeman 0:8f5825f330b0 576 #endif
RodColeman 0:8f5825f330b0 577
RodColeman 0:8f5825f330b0 578 /* recompute the ip header checksum */
RodColeman 0:8f5825f330b0 579 bp = (u_short *) &cs->cs_ip;
RodColeman 0:8f5825f330b0 580 IPH_CHKSUM_SET(&cs->cs_ip, 0);
RodColeman 0:8f5825f330b0 581 for (tmp = 0; hlen > 0; hlen -= 2) {
RodColeman 0:8f5825f330b0 582 tmp += *bp++;
RodColeman 0:8f5825f330b0 583 }
RodColeman 0:8f5825f330b0 584 tmp = (tmp & 0xffff) + (tmp >> 16);
RodColeman 0:8f5825f330b0 585 tmp = (tmp & 0xffff) + (tmp >> 16);
RodColeman 0:8f5825f330b0 586 IPH_CHKSUM_SET(&cs->cs_ip, (u_short)(~tmp));
RodColeman 0:8f5825f330b0 587
RodColeman 0:8f5825f330b0 588 /* Remove the compressed header and prepend the uncompressed header. */
RodColeman 0:8f5825f330b0 589 if(pbuf_header(n0, -((s16_t)(vjlen)))) {
RodColeman 0:8f5825f330b0 590 /* Can we cope with this failing? Just assert for now */
RodColeman 0:8f5825f330b0 591 LWIP_ASSERT("pbuf_header failed\n", 0);
RodColeman 0:8f5825f330b0 592 goto bad;
RodColeman 0:8f5825f330b0 593 }
RodColeman 0:8f5825f330b0 594
RodColeman 0:8f5825f330b0 595 if(LWIP_MEM_ALIGN(n0->payload) != n0->payload) {
RodColeman 0:8f5825f330b0 596 struct pbuf *np, *q;
RodColeman 0:8f5825f330b0 597 u8_t *bufptr;
RodColeman 0:8f5825f330b0 598
RodColeman 0:8f5825f330b0 599 np = pbuf_alloc(PBUF_RAW, n0->len + cs->cs_hlen, PBUF_POOL);
RodColeman 0:8f5825f330b0 600 if(!np) {
RodColeman 0:8f5825f330b0 601 PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: realign failed\n"));
RodColeman 0:8f5825f330b0 602 goto bad;
RodColeman 0:8f5825f330b0 603 }
RodColeman 0:8f5825f330b0 604
RodColeman 0:8f5825f330b0 605 if(pbuf_header(np, -cs->cs_hlen)) {
RodColeman 0:8f5825f330b0 606 /* Can we cope with this failing? Just assert for now */
RodColeman 0:8f5825f330b0 607 LWIP_ASSERT("pbuf_header failed\n", 0);
RodColeman 0:8f5825f330b0 608 goto bad;
RodColeman 0:8f5825f330b0 609 }
RodColeman 0:8f5825f330b0 610
RodColeman 0:8f5825f330b0 611 bufptr = (u8_t *)n0->payload;
RodColeman 0:8f5825f330b0 612 for(q = np; q != NULL; q = q->next) {
RodColeman 0:8f5825f330b0 613 MEMCPY(q->payload, bufptr, q->len);
RodColeman 0:8f5825f330b0 614 bufptr += q->len;
RodColeman 0:8f5825f330b0 615 }
RodColeman 0:8f5825f330b0 616
RodColeman 0:8f5825f330b0 617 if(n0->next) {
RodColeman 0:8f5825f330b0 618 pbuf_chain(np, n0->next);
RodColeman 0:8f5825f330b0 619 pbuf_dechain(n0);
RodColeman 0:8f5825f330b0 620 }
RodColeman 0:8f5825f330b0 621 pbuf_free(n0);
RodColeman 0:8f5825f330b0 622 n0 = np;
RodColeman 0:8f5825f330b0 623 }
RodColeman 0:8f5825f330b0 624
RodColeman 0:8f5825f330b0 625 if(pbuf_header(n0, cs->cs_hlen)) {
RodColeman 0:8f5825f330b0 626 struct pbuf *np;
RodColeman 0:8f5825f330b0 627
RodColeman 0:8f5825f330b0 628 LWIP_ASSERT("vj_uncompress_tcp: cs->cs_hlen <= PBUF_POOL_BUFSIZE", cs->cs_hlen <= PBUF_POOL_BUFSIZE);
RodColeman 0:8f5825f330b0 629 np = pbuf_alloc(PBUF_RAW, cs->cs_hlen, PBUF_POOL);
RodColeman 0:8f5825f330b0 630 if(!np) {
RodColeman 0:8f5825f330b0 631 PPPDEBUG(LOG_WARNING, ("vj_uncompress_tcp: prepend failed\n"));
RodColeman 0:8f5825f330b0 632 goto bad;
RodColeman 0:8f5825f330b0 633 }
RodColeman 0:8f5825f330b0 634 pbuf_cat(np, n0);
RodColeman 0:8f5825f330b0 635 n0 = np;
RodColeman 0:8f5825f330b0 636 }
RodColeman 0:8f5825f330b0 637 LWIP_ASSERT("n0->len >= cs->cs_hlen", n0->len >= cs->cs_hlen);
RodColeman 0:8f5825f330b0 638 MEMCPY(n0->payload, &cs->cs_ip, cs->cs_hlen);
RodColeman 0:8f5825f330b0 639
RodColeman 0:8f5825f330b0 640 *nb = n0;
RodColeman 0:8f5825f330b0 641
RodColeman 0:8f5825f330b0 642 return vjlen;
RodColeman 0:8f5825f330b0 643
RodColeman 0:8f5825f330b0 644 bad:
RodColeman 0:8f5825f330b0 645 comp->flags |= VJF_TOSS;
RodColeman 0:8f5825f330b0 646 INCR(vjs_errorin);
RodColeman 0:8f5825f330b0 647 return (-1);
RodColeman 0:8f5825f330b0 648 }
RodColeman 0:8f5825f330b0 649
RodColeman 0:8f5825f330b0 650 #endif /* VJ_SUPPORT */
RodColeman 0:8f5825f330b0 651
RodColeman 0:8f5825f330b0 652 #endif /* PPP_SUPPORT */