53 #include <linux/module.h>
54 #include <linux/slab.h>
55 #include <linux/types.h>
56 #include <linux/string.h>
57 #include <linux/errno.h>
58 #include <linux/kernel.h>
64 #include <linux/socket.h>
68 #include <linux/fcntl.h>
70 #include <linux/netdevice.h>
78 #include <asm/uaccess.h>
80 #include <asm/unaligned.h>
82 static unsigned char *encode(
unsigned char *
cp,
unsigned short n);
83 static long decode(
unsigned char **
cpp);
84 static unsigned char * put16(
unsigned char *
cp,
unsigned short x);
85 static unsigned short pull16(
unsigned char **
cpp);
101 if ( rslots > 0 && rslots < 256 ) {
102 size_t rsize = rslots *
sizeof(
struct cstate);
109 if ( tslots > 0 && tslots < 256 ) {
110 size_t tsize = tslots *
sizeof(
struct cstate);
132 ts[
i].
next = &(ts[i - 1]);
166 static inline unsigned char *
167 put16(
unsigned char *
cp,
unsigned short x)
177 static unsigned char *
178 encode(
unsigned char *
cp,
unsigned short n)
180 if(n >= 256 || n == 0){
190 static unsigned short
191 pull16(
unsigned char **
cpp)
203 decode(
unsigned char **
cpp)
209 return pull16(cpp) & 0xffff;
224 unsigned char *ocp,
unsigned char **cpp,
int compress_cid)
227 register struct cstate *lcs = ocs;
229 register unsigned long deltaS, deltaA;
230 register short changes = 0;
232 unsigned char new_seq[16];
233 register unsigned char *cp = new_seq;
243 if(isize<
sizeof(
struct iphdr))
246 ip = (
struct iphdr *) icp;
259 th = (
struct tcphdr *)(((
unsigned char *)
ip) + ip->ihl*4);
260 hlen = ip->ihl*4 + th->doff*4;
266 if(hlen > isize || th->syn || th->fin || th->rst ||
319 }
else if (cs == ocs) {
343 if(ip->version != cs->
cs_ip.version || ip->ihl != cs->
cs_ip.ihl
347 || th->doff != cs->
cs_tcp.doff
348 || (ip->ihl > 5 &&
memcmp(ip+1,cs->
cs_ipopt,((ip->ihl)-5)*4) != 0)
349 || (th->doff > 5 &&
memcmp(th+1,cs->
cs_tcpopt,((th->doff)-5)*4) != 0)){
361 cp = encode(cp,deltaS);
371 cp = encode(cp,deltaS);
375 if(deltaA > 0x0000ffff)
377 cp = encode(cp,deltaA);
381 if(deltaS > 0x0000ffff)
383 cp = encode(cp,deltaS);
407 if(deltaS == deltaA &&
415 if(deltaS ==
ntohs(cs->
cs_ip.tot_len) - hlen){
424 cp = encode(cp,deltaS);
441 deltaS = cp - new_seq;
445 *cp++ = changes |
NEW_C;
456 memcpy(cp,new_seq,deltaS);
457 memcpy(cp+deltaS,icp+hlen,isize-hlen);
460 return isize - hlen + deltaS + (cp - ocp);
486 register int changes;
488 register struct tcphdr *thp;
492 unsigned char *cp = icp;
534 hdrlen = ip->ihl * 4 + thp->doff * 4;
554 if((x = decode(&cp)) == -1) {
561 if((x = decode(&cp)) == -1) {
567 if((x = decode(&cp)) == -1) {
573 if((x = decode(&cp)) == -1) {
581 if((x = decode(&cp)) == -1) {
594 len = isize - (cp - icp);
601 memmove(icp + hdrlen, cp, len - hdrlen);
609 cp += (ip->ihl - 5) * 4;
613 &((
struct iphdr *)icp)->check);
620 cp += ((thp->doff) - 5) * 4;
706 unsigned char *ocp,
unsigned char **cpp,
int compress_cid)