Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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