45 #define INCR(counter) ++comp->stats.counter
57 memset((
char *)comp, 0,
sizeof(*comp));
63 tstate[i].
cs_next = &tstate[i - 1];
79 if ((u_short)(n) >= 256) { \
81 cp[1] = (u_char)(n); \
82 cp[0] = (u_char)((n) >> 8); \
85 *cp++ = (u_char)(n); \
88 #define ENCODEZ(n) { \
89 if ((u_short)(n) >= 256 || (u_short)(n) == 0) { \
91 cp[1] = (u_char)(n); \
92 cp[0] = (u_char)((n) >> 8); \
95 *cp++ = (u_char)(n); \
99 #define DECODEL(f) { \
101 u32_t tmp = ntohl(f) + ((cp[1] << 8) | cp[2]); \
105 u32_t tmp = ntohl(f) + (u32_t)*cp++; \
110 #define DECODES(f) { \
112 u_short tmp = ntohs(f) + (((u_short)cp[1] << 8) | cp[2]); \
116 u_short tmp = ntohs(f) + (u_short)*cp++; \
121 #define DECODEU(f) { \
123 (f) = htons(((u_short)cp[1] << 8) | cp[2]); \
126 (f) = htons((u_short)*cp++); \
142 register u_short hlen =
IPH_HL(ip);
143 register struct tcp_hdr *oth;
144 register struct tcp_hdr *th;
145 register u_short deltaS, deltaA;
146 register u_long deltaL;
147 register u_int changes = 0;
149 register u_char *cp = new_seq;
166 th = (
struct tcp_hdr *)&((
long *)ip)[hlen];
167 if ((TCPH_FLAGS(th) & (TCP_SYN|TCP_FIN|TCP_RST|TCP_ACK)) != TCP_ACK) {
180 || *(
long *)th != ((
long *)&cs->cs_ip)[
IPH_HL(&cs->cs_ip)]) {
193 register struct cstate *lcs;
201 && *(
long *)th == ((
long *)&cs->cs_ip)[
IPH_HL(&cs->cs_ip)]) {
204 }
while (cs != lastcs);
216 hlen += TCPH_OFFSET(th);
219 if (hlen > pb->
len) {
237 oth = (
struct tcp_hdr *)&((
long *)&cs->cs_ip)[hlen];
239 hlen += TCPH_OFFSET(th);
242 if (hlen > pb->
len) {
243 PPPDEBUG(
LOG_INFO, (
"vj_compress_tcp: header len %d spans buffers\n", hlen));
258 if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0]
259 || ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3]
260 || ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4]
261 || TCPH_OFFSET(th) != TCPH_OFFSET(oth)
262 || (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2))
263 || (TCPH_OFFSET(th) > 5 && BCMP(th + 1, oth + 1, (TCPH_OFFSET(th) - 5) << 2))) {
273 if (TCPH_FLAGS(th) & TCP_URG) {
274 deltaS =
ntohs(th->urgp);
277 }
else if (th->urgp != oth->urgp) {
285 if ((deltaS = (u_short)(
ntohs(th->wnd) -
ntohs(oth->wnd))) != 0) {
290 if ((deltaL =
ntohl(th->ackno) -
ntohl(oth->ackno)) != 0) {
291 if (deltaL > 0xffff) {
294 deltaA = (u_short)deltaL;
299 if ((deltaL =
ntohl(th->seqno) -
ntohl(oth->seqno)) != 0) {
300 if (deltaL > 0xffff) {
303 deltaS = (u_short)deltaL;
334 if (deltaS == deltaA && deltaS ==
ntohs(
IPH_LEN(&cs->cs_ip)) - hlen) {
355 if (TCPH_FLAGS(th) & TCP_PSH) {
362 deltaA =
ntohs(th->chksum);
363 BCOPY(ip, &cs->cs_ip, hlen);
374 deltaS = (u_short)(cp - new_seq);
383 *cp++ = (u_char)(changes |
NEW_C);
392 *cp++ = (u_char)changes;
394 *cp++ = (u_char)(deltaA >> 8);
395 *cp++ = (u_char)deltaA;
396 BCOPY(new_seq, cp, deltaS);
397 INCR(vjs_compressed);
406 BCOPY(ip, &cs->cs_ip, hlen);
430 register struct cstate *cs;
431 register struct ip_hdr *ip;
436 || hlen +
sizeof(
struct tcp_hdr) > nb->len
437 || (hlen += TCPH_OFFSET(((
struct tcp_hdr *)&((
char *)ip)[hlen])) << 2)
440 PPPDEBUG(
LOG_INFO, (
"vj_uncompress_uncomp: bad cid=%d, hlen=%d buflen=%d\n",
449 BCOPY(ip, &cs->cs_ip, hlen);
451 INCR(vjs_uncompressedin);
470 struct pbuf *n0 = *nb;
472 u_int vjlen, hlen, changes;
474 INCR(vjs_compressedin);
477 if (changes &
NEW_C) {
502 hlen =
IPH_HL(&cs->cs_ip) << 2;
503 th = (
struct tcp_hdr *)&((u_char *)&cs->cs_ip)[hlen];
504 th->chksum =
htons((*cp << 8) | cp[1]);
507 TCPH_SET_FLAG(th, TCP_PSH);
509 TCPH_UNSET_FLAG(th, TCP_PSH);
517 tmp =
ntohl(th->ackno) + i;
518 th->ackno =
htonl(tmp);
519 tmp =
ntohl(th->seqno) + i;
520 th->seqno =
htonl(tmp);
527 th->seqno =
htonl(tmp);
531 if (changes &
NEW_U) {
532 TCPH_SET_FLAG(th, TCP_URG);
535 TCPH_UNSET_FLAG(th, TCP_URG);
537 if (changes &
NEW_W) {
540 if (changes &
NEW_A) {
543 if (changes &
NEW_S) {
548 if (changes &
NEW_I) {
549 DECODES(cs->cs_ip._id);
560 vjlen = (u_short)(cp - (u_char*)n0->
payload);
561 if (n0->
len < vjlen) {
571 #if BYTE_ORDER == LITTLE_ENDIAN
579 bp = (u_short *) &cs->cs_ip;
581 for (tmp = 0; hlen > 0; hlen -= 2) {
584 tmp = (tmp & 0xffff) + (tmp >> 16);
585 tmp = (tmp & 0xffff) + (tmp >> 16);
612 for(q = np; q !=
NULL; q = q->
next) {