X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=modules%2Fvjcompress.c;h=73a59d4986a61c816560d66de3a372116142f40d;hp=80246ddc443301b2cb16af74e14bf4d313ef9554;hb=1bd5f1186d0bc87dc8383ac3395ef8935e5ba453;hpb=a9de09991f0cc67879a9bb33f6d553d8c291aaf8 diff --git a/modules/vjcompress.c b/modules/vjcompress.c index 80246dd..73a59d4 100644 --- a/modules/vjcompress.c +++ b/modules/vjcompress.c @@ -23,27 +23,47 @@ * Modified June 1993 by Paul Mackerras, paulus@cs.anu.edu.au, * so that the entire packet being decompressed doesn't have * to be in contiguous memory (just the compressed header). + */ + +/* + * This version is used under SunOS 4.x, DEC Alpha OSF/1, AIX 4.x, + * and SVR4 systems including Solaris 2. * - * $Id: vjcompress.c,v 1.1 1994/09/16 06:58:24 paulus Exp $ + * $Id: vjcompress.c,v 1.6 1995/05/29 06:33:55 paulus Exp $ */ #include #include + +#ifdef __svr4__ +#ifndef __GNUC__ +#include /* for ntohl, etc. */ +#else +/* make sure we don't get the gnu "fixed" one! */ +#include "/usr/include/sys/byteorder.h" +#endif +#endif + +#ifdef __osf__ +#include +#endif #include -#include -#include -#include -#ifdef __STDC__ -#define __P(x) x +#ifdef __aix4__ +#define _NETINET_IN_SYSTM_H_ +typedef u_long n_long; #else -#define __P() () +#include #endif +#include +#include + +#include #include #ifndef VJ_NO_STATS -#define INCR(counter) ++comp->counter +#define INCR(counter) ++comp->stats.counter #else #define INCR(counter) #endif @@ -55,6 +75,15 @@ #define ovbcopy bcopy #endif +#ifdef __osf__ +#define getip_hl(base) (((base).ip_vhl)&0xf) +#define getth_off(base) ((((base).th_xoff)&0xf0)>>4) + +#else +#define getip_hl(base) ((base).ip_hl) +#define getth_off(base) ((base).th_off) +#endif + void vj_compress_init(comp, max_state) struct vjcompress *comp; @@ -106,19 +135,23 @@ vj_compress_init(comp, max_state) #define DECODEL(f) { \ if (*cp == 0) {\ - (f) = htonl(ntohl(f) + ((cp[1] << 8) | cp[2])); \ + u_int32_t tmp = ntohl(f) + ((cp[1] << 8) | cp[2]); \ + (f) = htonl(tmp); \ cp += 3; \ } else { \ - (f) = htonl(ntohl(f) + (u_long)*cp++); \ + u_int32_t tmp = ntohl(f) + (u_int32_t)*cp++; \ + (f) = htonl(tmp); \ } \ } #define DECODES(f) { \ if (*cp == 0) {\ - (f) = htons(ntohs(f) + ((cp[1] << 8) | cp[2])); \ + u_short tmp = ntohs(f) + ((cp[1] << 8) | cp[2]); \ + (f) = htons(tmp); \ cp += 3; \ } else { \ - (f) = htons(ntohs(f) + (u_long)*cp++); \ + u_short tmp = ntohs(f) + (u_int32_t)*cp++; \ + (f) = htons(tmp); \ } \ } @@ -127,7 +160,7 @@ vj_compress_init(comp, max_state) (f) = htons((cp[1] << 8) | cp[2]); \ cp += 3; \ } else { \ - (f) = htons((u_long)*cp++); \ + (f) = htons((u_int32_t)*cp++); \ } \ } @@ -140,7 +173,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) u_char **vjhdrp; { register struct cstate *cs = comp->last_cs->cs_next; - register u_int hlen = ip->ip_hl; + register u_int hlen = getip_hl(*ip); register struct tcphdr *oth; register struct tcphdr *th; register u_int deltaS, deltaA; @@ -170,7 +203,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) INCR(vjs_packets); if (ip->ip_src.s_addr != cs->cs_ip.ip_src.s_addr || ip->ip_dst.s_addr != cs->cs_ip.ip_dst.s_addr || - *(int *)th != ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl]) { + *(int *)th != ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) { /* * Wasn't the first -- search for it. * @@ -191,7 +224,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) INCR(vjs_searches); if (ip->ip_src.s_addr == cs->cs_ip.ip_src.s_addr && ip->ip_dst.s_addr == cs->cs_ip.ip_dst.s_addr - && *(int *)th == ((int *)&cs->cs_ip)[cs->cs_ip.ip_hl]) + && *(int *)th == ((int *)&cs->cs_ip)[getip_hl(cs->cs_ip)]) goto found; } while (cs != lastcs); @@ -205,7 +238,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) */ INCR(vjs_misses); comp->last_cs = lcs; - hlen += th->th_off; + hlen += getth_off(*th); hlen <<= 2; if (hlen > mlen) return (TYPE_IP); @@ -237,7 +270,7 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) */ oth = (struct tcphdr *)&((int *)&cs->cs_ip)[hlen]; deltaS = hlen; - hlen += th->th_off; + hlen += getth_off(*th); hlen <<= 2; if (hlen > mlen) return (TYPE_IP); @@ -245,9 +278,9 @@ vj_compress_tcp(ip, mlen, comp, compress_cid, vjhdrp) if (((u_short *)ip)[0] != ((u_short *)&cs->cs_ip)[0] || ((u_short *)ip)[3] != ((u_short *)&cs->cs_ip)[3] || ((u_short *)ip)[4] != ((u_short *)&cs->cs_ip)[4] || - th->th_off != oth->th_off || + getth_off(*th) != getth_off(*oth) || (deltaS > 5 && BCMP(ip + 1, &cs->cs_ip + 1, (deltaS - 5) << 2)) || - (th->th_off > 5 && BCMP(th + 1, oth + 1, (th->th_off - 5) << 2))) + (getth_off(*th) > 5 && BCMP(th + 1, oth + 1, (getth_off(*th) - 5) << 2))) goto uncompressed; /* @@ -414,8 +447,8 @@ vj_uncompress_uncomp(buf, comp) cs = &comp->rstate[comp->last_recv = ip->ip_p]; comp->flags &=~ VJF_TOSS; ip->ip_p = IPPROTO_TCP; - hlen = ip->ip_hl; - hlen += ((struct tcphdr *)&((int *)ip)[hlen])->th_off; + hlen = getip_hl(*ip); + hlen += getth_off(*((struct tcphdr *)&((int *)ip)[hlen])); hlen <<= 2; BCOPY(ip, &cs->cs_ip, hlen); cs->cs_hlen = hlen; @@ -443,9 +476,9 @@ vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp) register u_int hlen, changes; register struct tcphdr *th; register struct cstate *cs; - register struct ip *ip; register u_short *bp; register u_int vjlen; + register u_int32_t tmp; INCR(vjs_compressedin); cp = buf; @@ -468,7 +501,7 @@ vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp) } } cs = &comp->rstate[comp->last_recv]; - hlen = cs->cs_ip.ip_hl << 2; + hlen = getip_hl(cs->cs_ip) << 2; th = (struct tcphdr *)&((u_char *)&cs->cs_ip)[hlen]; th->th_sum = htons((*cp << 8) | cp[1]); cp += 2; @@ -480,15 +513,19 @@ vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp) switch (changes & SPECIALS_MASK) { case SPECIAL_I: { - register u_int i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen; - th->th_ack = htonl(ntohl(th->th_ack) + i); - th->th_seq = htonl(ntohl(th->th_seq) + i); + register u_int32_t i = ntohs(cs->cs_ip.ip_len) - cs->cs_hlen; + /* some compilers can't nest inline assembler.. */ + tmp = ntohl(th->th_ack) + i; + th->th_ack = htonl(tmp); + tmp = ntohl(th->th_seq) + i; + th->th_seq = htonl(tmp); } break; case SPECIAL_D: - th->th_seq = htonl(ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len) - - cs->cs_hlen); + /* some compilers can't nest inline assembler.. */ + tmp = ntohl(th->th_seq) + ntohs(cs->cs_ip.ip_len) - cs->cs_hlen; + th->th_seq = htonl(tmp); break; default: @@ -507,8 +544,10 @@ vj_uncompress_tcp(buf, buflen, total_len, comp, hdrp, hlenp) } if (changes & NEW_I) { DECODES(cs->cs_ip.ip_id); - } else - cs->cs_ip.ip_id = htons(ntohs(cs->cs_ip.ip_id) + 1); + } else { + cs->cs_ip.ip_id = ntohs(cs->cs_ip.ip_id) + 1; + cs->cs_ip.ip_id = htons(cs->cs_ip.ip_id); + } /* * At this point, cp points to the first byte of data in the