root/drivers/net/slhc.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. slhc_init
  2. slhc_free
  3. put16
  4. encode
  5. pull16
  6. decode
  7. slhc_compress
  8. slhc_uncompress
  9. slhc_remember
  10. slhc_toss
  11. slhc_i_status
  12. slhc_o_status

   1 /*
   2  * Routines to compress and uncompress tcp packets (for transmission
   3  * over low speed serial lines).
   4  *
   5  * Copyright (c) 1989 Regents of the University of California.
   6  * All rights reserved.
   7  *
   8  * Redistribution and use in source and binary forms are permitted
   9  * provided that the above copyright notice and this paragraph are
  10  * duplicated in all such forms and that any documentation,
  11  * advertising materials, and other materials related to such
  12  * distribution and use acknowledge that the software was developed
  13  * by the University of California, Berkeley.  The name of the
  14  * University may not be used to endorse or promote products derived
  15  * from this software without specific prior written permission.
  16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  18  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19  *
  20  *      Van Jacobson (van@helios.ee.lbl.gov), Dec 31, 1989:
  21  *      - Initial distribution.
  22  *
  23  *
  24  * modified for KA9Q Internet Software Package by
  25  * Katie Stevens (dkstevens@ucdavis.edu)
  26  * University of California, Davis
  27  * Computing Services
  28  *      - 01-31-90      initial adaptation (from 1.19)
  29  *      PPP.05  02-15-90 [ks]
  30  *      PPP.08  05-02-90 [ks]   use PPP protocol field to signal compression
  31  *      PPP.15  09-90    [ks]   improve mbuf handling
  32  *      PPP.16  11-02    [karn] substantially rewritten to use NOS facilities
  33  *
  34  *      - Feb 1991      Bill_Simpson@um.cc.umich.edu
  35  *                      variable number of conversation slots
  36  *                      allow zero or one slots
  37  *                      separate routines
  38  *                      status display
  39  *
  40  *
  41  *      This module is a difficult issue. Its clearly inet code but its also clearly
  42  *      driver code belonging close to PPP and SLIP
  43  */
  44 
  45 #include <linux/config.h>
  46 #ifdef CONFIG_INET
  47 /* Entire module is for IP only */
  48 #include <linux/types.h>
  49 #include <linux/sched.h>
  50 #include <linux/mm.h>
  51 #include <linux/string.h>
  52 #include <linux/socket.h>
  53 #include <linux/sockios.h>
  54 #include <linux/termios.h>
  55 #include <linux/in.h>
  56 #include <linux/fcntl.h>
  57 #include <linux/inet.h>
  58 #include <linux/netdevice.h>
  59 #include "ip.h"
  60 #include "protocol.h"
  61 #include "icmp.h"
  62 #include "tcp.h"
  63 #include <linux/skbuff.h>
  64 #include "sock.h"
  65 #include <linux/errno.h>
  66 #include <linux/timer.h>
  67 #include <asm/system.h>
  68 #include <asm/segment.h>
  69 #include <linux/mm.h>
  70 #include "slhc.h"
  71 
  72 int last_retran;
  73 
  74 static unsigned char *encode(unsigned char *cp, unsigned short n);
  75 static long decode(unsigned char **cpp);
  76 static unsigned char * put16(unsigned char *cp, unsigned short x);
  77 static unsigned short pull16(unsigned char **cpp);
  78 
  79 extern int ip_csum(struct iphdr *iph);
  80 
  81 
  82 /* Initialize compression data structure
  83  *      slots must be in range 0 to 255 (zero meaning no compression)
  84  */
  85 struct slcompress *
  86 slhc_init(int rslots, int tslots)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         register short i;
  89         register struct cstate *ts;
  90         struct slcompress *comp;
  91 
  92         comp = (struct slcompress *)kmalloc(sizeof(struct slcompress), 
  93                                             GFP_KERNEL);
  94         if (! comp)
  95                 return NULL;
  96 
  97         memset(comp, 0, sizeof(struct slcompress));
  98 
  99         if ( rslots > 0  &&  rslots < 256 ) {
 100                 comp->rstate =
 101                   (struct cstate *)kmalloc(rslots * sizeof(struct cstate),
 102                                            GFP_KERNEL);
 103                 if (! comp->rstate)
 104                         return NULL;
 105                 memset(comp->rstate, 0, rslots * sizeof(struct cstate));
 106                 comp->rslot_limit = rslots - 1;
 107         }
 108 
 109         if ( tslots > 0  &&  tslots < 256 ) {
 110                 comp->tstate = 
 111                   (struct cstate *)kmalloc(tslots * sizeof(struct cstate),
 112                                            GFP_KERNEL);
 113                 if (! comp->tstate)
 114                         return NULL;
 115                 memset(comp->tstate, 0, rslots * sizeof(struct cstate));
 116                 comp->tslot_limit = tslots - 1;
 117         }
 118 
 119         comp->xmit_oldest = 0;
 120         comp->xmit_current = 255;
 121         comp->recv_current = 255;
 122         /*
 123          * don't accept any packets with implicit index until we get
 124          * one with an explicit index.  Otherwise the uncompress code
 125          * will try to use connection 255, which is almost certainly
 126          * out of range
 127          */
 128         comp->flags |= SLF_TOSS;
 129 
 130         if ( tslots > 0 ) {
 131                 ts = comp->tstate;
 132                 for(i = comp->tslot_limit; i > 0; --i){
 133                         ts[i].cs_this = i;
 134                         ts[i].next = &(ts[i - 1]);
 135                 }
 136                 ts[0].next = &(ts[comp->tslot_limit]);
 137                 ts[0].cs_this = 0;
 138         }
 139         return comp;
 140 }
 141 
 142 
 143 /* Free a compression data structure */
 144 void
 145 slhc_free(struct slcompress *comp)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147         if ( comp == NULLSLCOMPR )
 148                 return;
 149 
 150         if ( comp->rstate != NULLSLSTATE )
 151                 kfree( comp->rstate );
 152 
 153         if ( comp->tstate != NULLSLSTATE )
 154                 kfree( comp->tstate );
 155 
 156         kfree( comp );
 157 }
 158 
 159 
 160 /* Put a short in host order into a char array in network order */
 161 static inline unsigned char *
 162 put16(unsigned char *cp, unsigned short x)
     /* [previous][next][first][last][top][bottom][index][help] */
 163 {
 164         *cp++ = x >> 8;
 165         *cp++ = x;
 166 
 167         return cp;
 168 }
 169 
 170 
 171 /* Encode a number */
 172 unsigned char *
 173 encode(unsigned char *cp, unsigned short n)
     /* [previous][next][first][last][top][bottom][index][help] */
 174 {
 175         if(n >= 256 || n == 0){
 176                 *cp++ = 0;
 177                 cp = put16(cp,n);
 178         } else {
 179                 *cp++ = n;
 180         }
 181         return cp;
 182 }
 183 
 184 /* Pull a 16-bit integer in host order from buffer in network byte order */
 185 static unsigned short
 186 pull16(unsigned char **cpp)
     /* [previous][next][first][last][top][bottom][index][help] */
 187 {
 188         short rval;
 189 
 190         rval = *(*cpp)++;
 191         rval <<= 8;
 192         rval |= *(*cpp)++;
 193         return rval;
 194 }
 195 
 196 /* Decode a number */
 197 long
 198 decode(unsigned char **cpp)
     /* [previous][next][first][last][top][bottom][index][help] */
 199 {
 200         register int x;
 201 
 202         x = *(*cpp)++;
 203         if(x == 0){
 204                 return pull16(cpp) & 0xffff;    /* pull16 returns -1 on error */
 205         } else {
 206                 return x & 0xff;                /* -1 if PULLCHAR returned error */
 207         }
 208 }
 209 
 210 /* 
 211  * icp and isize are the original packet.
 212  * ocp is a place to put a copy if necessary.
 213  * cpp is initially a pointer to icp.  If the copy is used,
 214  *    change it to ocp.
 215  */
 216 
 217 int
 218 slhc_compress(struct slcompress *comp, unsigned char *icp, int isize,
     /* [previous][next][first][last][top][bottom][index][help] */
 219         unsigned char *ocp, unsigned char **cpp, int compress_cid)
 220 {
 221         register struct cstate *ocs = &(comp->tstate[comp->xmit_oldest]);
 222         register struct cstate *lcs = ocs;
 223         register struct cstate *cs = lcs->next;
 224         register unsigned long deltaS, deltaA;
 225         register short changes = 0;
 226         int hlen;
 227         unsigned char new_seq[16];
 228         register unsigned char *cp = new_seq;
 229         struct iphdr *ip;
 230         struct tcphdr *th, *oth;
 231 
 232         ip = (struct iphdr *) icp;
 233 
 234         /* Bail if this packet isn't TCP, or is an IP fragment */
 235         if(ip->protocol != IPPROTO_TCP || (ntohs(ip->frag_off) & 0x1fff) || 
 236                                        (ip->frag_off & 32)){
 237                 /* Send as regular IP */
 238                 if(ip->protocol != IPPROTO_TCP)
 239                         comp->sls_o_nontcp++;
 240                 else
 241                         comp->sls_o_tcp++;
 242                 return isize;
 243         }
 244         /* Extract TCP header */
 245 
 246         th = (struct tcphdr *)(((unsigned char *)ip) + ip->ihl*4);
 247         hlen = ip->ihl*4 + th->doff*4;
 248 
 249         /*  Bail if the TCP packet isn't `compressible' (i.e., ACK isn't set or
 250          *  some other control bit is set).
 251          */
 252         if(th->syn || th->fin || th->rst ||
 253             ! (th->ack)){
 254                 /* TCP connection stuff; send as regular IP */
 255                 comp->sls_o_tcp++;
 256                 return isize;
 257         }
 258         /*
 259          * Packet is compressible -- we're going to send either a
 260          * COMPRESSED_TCP or UNCOMPRESSED_TCP packet.  Either way,
 261          * we need to locate (or create) the connection state.
 262          *
 263          * States are kept in a circularly linked list with
 264          * xmit_oldest pointing to the end of the list.  The
 265          * list is kept in lru order by moving a state to the
 266          * head of the list whenever it is referenced.  Since
 267          * the list is short and, empirically, the connection
 268          * we want is almost always near the front, we locate
 269          * states via linear search.  If we don't find a state
 270          * for the datagram, the oldest state is (re-)used.
 271          */
 272         for ( ; ; ) {
 273                 if( ip->saddr == cs->cs_ip.saddr
 274                  && ip->daddr == cs->cs_ip.daddr
 275                  && th->source == cs->cs_tcp.source
 276                  && th->dest == cs->cs_tcp.dest)
 277                         goto found;
 278 
 279                 /* if current equal oldest, at end of list */
 280                 if ( cs == ocs )
 281                         break;
 282                 lcs = cs;
 283                 cs = cs->next;
 284                 comp->sls_o_searches++;
 285         };
 286         /*
 287          * Didn't find it -- re-use oldest cstate.  Send an
 288          * uncompressed packet that tells the other side what
 289          * connection number we're using for this conversation.
 290          *
 291          * Note that since the state list is circular, the oldest
 292          * state points to the newest and we only need to set
 293          * xmit_oldest to update the lru linkage.
 294          */
 295         comp->sls_o_misses++;
 296         comp->xmit_oldest = lcs->cs_this;
 297         goto uncompressed;
 298 
 299 found:
 300         /*
 301          * Found it -- move to the front on the connection list.
 302          */
 303         if(lcs == ocs) {
 304                 /* found at most recently used */
 305         } else if (cs == ocs) {
 306                 /* found at least recently used */
 307                 comp->xmit_oldest = lcs->cs_this;
 308         } else {
 309                 /* more than 2 elements */
 310                 lcs->next = cs->next;
 311                 cs->next = ocs->next;
 312                 ocs->next = cs;
 313         }
 314 
 315         /*
 316          * Make sure that only what we expect to change changed.
 317          * Check the following:
 318          * IP protocol version, header length & type of service.
 319          * The "Don't fragment" bit.
 320          * The time-to-live field.
 321          * The TCP header length.
 322          * IP options, if any.
 323          * TCP options, if any.
 324          * If any of these things are different between the previous &
 325          * current datagram, we send the current datagram `uncompressed'.
 326          */
 327         oth = &cs->cs_tcp;
 328 
 329         if(last_retran
 330          || ip->version != cs->cs_ip.version || ip->ihl != cs->cs_ip.ihl
 331          || ip->tos != cs->cs_ip.tos
 332          || (ip->frag_off & 64) != (cs->cs_ip.frag_off & 64)
 333          || ip->ttl != cs->cs_ip.ttl
 334          || th->doff != cs->cs_tcp.doff
 335          || (ip->ihl > 5 && memcmp(ip+1,cs->cs_ipopt,((ip->ihl)-5)*4) != 0)
 336          || (th->doff > 5 && memcmp(th+1,cs->cs_tcpopt,((th->doff)-5)*4 != 0))){
 337                 goto uncompressed;
 338         }
 339         
 340         /*
 341          * Figure out which of the changing fields changed.  The
 342          * receiver expects changes in the order: urgent, window,
 343          * ack, seq (the order minimizes the number of temporaries
 344          * needed in this section of code).
 345          */
 346         if(th->urg){
 347                 deltaS = ntohs(th->urg_ptr);
 348                 cp = encode(cp,deltaS);
 349                 changes |= NEW_U;
 350         } else if(th->urg_ptr != oth->urg_ptr){
 351                 /* argh! URG not set but urp changed -- a sensible
 352                  * implementation should never do this but RFC793
 353                  * doesn't prohibit the change so we have to deal
 354                  * with it. */
 355                 goto uncompressed;
 356         }
 357         if((deltaS = ntohs(th->window) - ntohs(oth->window)) != 0){
 358                 cp = encode(cp,deltaS);
 359                 changes |= NEW_W;
 360         }
 361         if((deltaA = ntohl(th->ack_seq) - ntohl(oth->ack_seq)) != 0L){
 362                 if(deltaA > 0x0000ffff)
 363                         goto uncompressed;
 364                 cp = encode(cp,deltaA);
 365                 changes |= NEW_A;
 366         }
 367         if((deltaS = ntohl(th->seq) - ntohl(oth->seq)) != 0L){
 368                 if(deltaS > 0x0000ffff)
 369                         goto uncompressed;
 370                 cp = encode(cp,deltaS);
 371                 changes |= NEW_S;
 372         }
 373         
 374         switch(changes){
 375         case 0: /* Nothing changed. If this packet contains data and the
 376                  * last one didn't, this is probably a data packet following
 377                  * an ack (normal on an interactive connection) and we send
 378                  * it compressed.  Otherwise it's probably a retransmit,
 379                  * retransmitted ack or window probe.  Send it uncompressed
 380                  * in case the other side missed the compressed version.
 381                  */
 382                 if(ip->tot_len != cs->cs_ip.tot_len && 
 383                    ntohs(cs->cs_ip.tot_len) == hlen)
 384                         break;
 385                 goto uncompressed;
 386                 break;
 387         case SPECIAL_I:
 388         case SPECIAL_D:
 389                 /* actual changes match one of our special case encodings --
 390                  * send packet uncompressed.
 391                  */
 392                 goto uncompressed;
 393         case NEW_S|NEW_A:
 394                 if(deltaS == deltaA &&
 395                     deltaS == ntohs(cs->cs_ip.tot_len) - hlen){
 396                         /* special case for echoed terminal traffic */
 397                         changes = SPECIAL_I;
 398                         cp = new_seq;
 399                 }
 400                 break;
 401         case NEW_S:
 402                 if(deltaS == ntohs(cs->cs_ip.tot_len) - hlen){
 403                         /* special case for data xfer */
 404                         changes = SPECIAL_D;
 405                         cp = new_seq;
 406                 }
 407                 break;
 408         }
 409         deltaS = ntohs(ip->id) - ntohs(cs->cs_ip.id);
 410         if(deltaS != 1){
 411                 cp = encode(cp,deltaS);
 412                 changes |= NEW_I;
 413         }
 414         if(th->psh)
 415                 changes |= TCP_PUSH_BIT;
 416         /* Grab the cksum before we overwrite it below.  Then update our
 417          * state with this packet's header.
 418          */
 419         deltaA = ntohs(th->check);
 420         memcpy(&cs->cs_ip,ip,20);
 421         memcpy(&cs->cs_tcp,th,20);
 422         /* We want to use the original packet as our compressed packet.
 423          * (cp - new_seq) is the number of bytes we need for compressed
 424          * sequence numbers.  In addition we need one byte for the change
 425          * mask, one for the connection id and two for the tcp checksum.
 426          * So, (cp - new_seq) + 4 bytes of header are needed.
 427          */
 428         deltaS = cp - new_seq;
 429         if(compress_cid == 0 || comp->xmit_current != cs->cs_this){
 430                 cp = ocp;
 431                 *cpp = ocp;
 432                 *cp++ = changes | NEW_C;
 433                 *cp++ = cs->cs_this;
 434                 comp->xmit_current = cs->cs_this;
 435         } else {
 436                 cp = ocp;
 437                 *cpp = ocp;
 438                 *cp++ = changes;
 439         }
 440         cp = put16(cp,(short)deltaA);   /* Write TCP checksum */
 441 /* deltaS is now the size of the change section of the compressed header */
 442         memcpy(cp,new_seq,deltaS);      /* Write list of deltas */
 443         memcpy(cp+deltaS,icp+hlen,isize-hlen);
 444         comp->sls_o_compressed++;
 445         ocp[0] |= SL_TYPE_COMPRESSED_TCP;
 446         return isize - hlen + deltaS + (cp - ocp);
 447 
 448         /* Update connection state cs & send uncompressed packet (i.e.,
 449          * a regular ip/tcp packet but with the 'conversation id' we hope
 450          * to use on future compressed packets in the protocol field).
 451          */
 452 uncompressed:
 453         memcpy(&cs->cs_ip,ip,20);
 454         memcpy(&cs->cs_tcp,th,20);
 455         if (ip->ihl > 5)
 456           memcpy(cs->cs_ipopt, ip+1, ((ip->ihl) - 5) * 4);
 457         if (th->doff > 5)
 458           memcpy(cs->cs_tcpopt, th+1, ((th->doff) - 5) * 4);
 459         comp->xmit_current = cs->cs_this;
 460         comp->sls_o_uncompressed++;
 461         memcpy(ocp, icp, isize);
 462         *cpp = ocp;
 463         ocp[9] = cs->cs_this;
 464         ocp[0] |= SL_TYPE_UNCOMPRESSED_TCP;
 465         return isize;
 466 }
 467 
 468 
 469 int
 470 slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
     /* [previous][next][first][last][top][bottom][index][help] */
 471 {
 472         register int changes;
 473         long x;
 474         register struct tcphdr *thp;
 475         register struct iphdr *ip;
 476         register struct cstate *cs;
 477         int len, hdrlen;
 478         unsigned char *cp = icp;
 479 
 480         /* We've got a compressed packet; read the change byte */
 481         comp->sls_i_compressed++;
 482         if(isize < 3){
 483                 comp->sls_i_error++;
 484                 return 0;
 485         }
 486         changes = *cp++;
 487         if(changes & NEW_C){
 488                 /* Make sure the state index is in range, then grab the state.
 489                  * If we have a good state index, clear the 'discard' flag.
 490                  */
 491                 x = *cp++;      /* Read conn index */
 492                 if(x < 0 || x > comp->rslot_limit)
 493                         goto bad;
 494 
 495                 comp->flags &=~ SLF_TOSS;
 496                 comp->recv_current = x;
 497         } else {
 498                 /* this packet has an implicit state index.  If we've
 499                  * had a line error since the last time we got an
 500                  * explicit state index, we have to toss the packet. */
 501                 if(comp->flags & SLF_TOSS){
 502                         comp->sls_i_tossed++;
 503                         return 0;
 504                 }
 505         }
 506         cs = &comp->rstate[comp->recv_current];
 507         thp = &cs->cs_tcp;
 508         ip = &cs->cs_ip;
 509 
 510         if((x = pull16(&cp)) == -1) {   /* Read the TCP checksum */
 511                 goto bad;
 512         }
 513         thp->check = htons(x);
 514 
 515         thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0;
 516 /* 
 517  * we can use the same number for the length of the saved header and
 518  * the current one, because the packet wouldn't have been sent
 519  * as compressed unless the options were the same as the previous one
 520  */
 521 
 522         hdrlen = ip->ihl * 4 + thp->doff * 4;
 523 
 524         switch(changes & SPECIALS_MASK){
 525         case SPECIAL_I:         /* Echoed terminal traffic */
 526                 {
 527                 register short i;
 528                 i = ntohs(ip->tot_len) - hdrlen;
 529                 thp->ack_seq = htonl( ntohl(thp->ack_seq) + i);
 530                 thp->seq = htonl( ntohl(thp->seq) + i);
 531                 }
 532                 break;
 533 
 534         case SPECIAL_D:                 /* Unidirectional data */
 535                 thp->seq = htonl( ntohl(thp->seq) +
 536                                   ntohs(ip->tot_len) - hdrlen);
 537                 break;
 538 
 539         default:
 540                 if(changes & NEW_U){
 541                         thp->urg = 1;
 542                         if((x = decode(&cp)) == -1) {
 543                                 goto bad;
 544                         }
 545                         thp->urg_ptr = htons(x);
 546                 } else
 547                         thp->urg = 0;
 548                 if(changes & NEW_W){
 549                         if((x = decode(&cp)) == -1) {
 550                                 goto bad;
 551                         }       
 552                         thp->window = htons( ntohs(thp->window) + x);
 553                 }
 554                 if(changes & NEW_A){
 555                         if((x = decode(&cp)) == -1) {
 556                                 goto bad;
 557                         }
 558                         thp->ack_seq = htonl( ntohl(thp->ack_seq) + x);
 559                 }
 560                 if(changes & NEW_S){
 561                         if((x = decode(&cp)) == -1) {
 562                                 goto bad;
 563                         }
 564                         thp->seq = htonl( ntohl(thp->seq) + x);
 565                 }
 566                 break;
 567         }
 568         if(changes & NEW_I){
 569                 if((x = decode(&cp)) == -1) {
 570                         goto bad;
 571                 }
 572                 ip->id = htons (ntohs (ip->id) + x);
 573         } else
 574                 ip->id = htons (ntohs (ip->id) + 1);
 575 
 576         /*
 577          * At this point, cp points to the first byte of data in the
 578          * packet.  Put the reconstructed TCP and IP headers back on the
 579          * packet.  Recalculate IP checksum (but not TCP checksum).
 580          */
 581 
 582         len = isize - (cp - icp);
 583         if (len < 0)
 584                 goto bad;
 585         len += hdrlen;
 586         ip->tot_len = htons(len);
 587         ip->check = 0;
 588 
 589         memmove(icp + hdrlen, cp, len - hdrlen);
 590 
 591         cp = icp;
 592         memcpy(cp, ip, 20);
 593         cp += 20;
 594 
 595         if (ip->ihl > 5) {
 596           memcpy(cp, cs->cs_ipopt, ((ip->ihl) - 5) * 4);
 597           cp += ((ip->ihl) - 5) * 4;
 598         }
 599 
 600         ((struct iphdr *)icp)->check = ip_csum((struct iphdr*)icp);
 601 
 602         memcpy(cp, thp, 20);
 603         cp += 20;
 604 
 605         if (thp->doff > 5) {
 606           memcpy(cp, cs->cs_tcpopt, ((thp->doff) - 5) * 4);
 607           cp += ((thp->doff) - 5) * 4;
 608         }
 609 
 610         return len;
 611 bad:
 612         comp->sls_i_error++;
 613         return slhc_toss( comp );
 614 }
 615 
 616 
 617 int
 618 slhc_remember(struct slcompress *comp, unsigned char *icp, int isize)
     /* [previous][next][first][last][top][bottom][index][help] */
 619 {
 620         register struct cstate *cs;
 621         short ip_len;
 622         struct iphdr *ip;
 623         struct tcphdr *thp;
 624 
 625         unsigned char index;
 626 
 627         if(isize < 20) {
 628                 /* The packet is shorter than a legal IP header */
 629                 comp->sls_i_runt++;
 630                 return slhc_toss( comp );
 631         }
 632         /* Sneak a peek at the IP header's IHL field to find its length */
 633         ip_len = (icp[0] & 0xf) << 2;
 634         if(ip_len < 20){
 635                 /* The IP header length field is too small */
 636                 comp->sls_i_runt++;
 637                 return slhc_toss( comp );
 638         }
 639         index = icp[9];
 640         icp[9] = IPPROTO_TCP;
 641         ip = (struct iphdr *) icp;
 642 
 643         if (ip_csum(ip)) {
 644                 /* Bad IP header checksum; discard */
 645                 comp->sls_i_badcheck++;
 646                 return slhc_toss( comp );
 647         }
 648         thp = (struct tcphdr *)(((unsigned char *)ip) + ip->ihl*4);
 649         if(index > comp->rslot_limit) {
 650                 comp->sls_i_error++;
 651                 return slhc_toss(comp);
 652         }
 653 
 654         /* Update local state */
 655         cs = &comp->rstate[comp->recv_current = index];
 656         comp->flags &=~ SLF_TOSS;
 657         memcpy(&cs->cs_ip,ip,20);
 658         memcpy(&cs->cs_tcp,thp,20);
 659         if (ip->ihl > 5)
 660           memcpy(cs->cs_ipopt, ip+1, ((ip->ihl) - 5) * 4);
 661         if (thp->doff > 5)
 662           memcpy(cs->cs_tcpopt, thp+1, ((thp->doff) - 5) * 4);
 663         cs->cs_hsize = ip->ihl*2 + thp->doff*2;
 664         /* Put headers back on packet
 665          * Neither header checksum is recalculated
 666          */
 667         comp->sls_i_uncompressed++;
 668         return isize;
 669 }
 670 
 671 
 672 int
 673 slhc_toss(struct slcompress *comp)
     /* [previous][next][first][last][top][bottom][index][help] */
 674 {
 675         if ( comp == NULLSLCOMPR )
 676                 return 0;
 677 
 678         comp->flags |= SLF_TOSS;
 679         return 0;
 680 }
 681 
 682 
 683 void slhc_i_status(struct slcompress *comp)
     /* [previous][next][first][last][top][bottom][index][help] */
 684 {
 685         if (comp != NULLSLCOMPR) {
 686                 printk("\t%ld Cmp, %ld Uncmp, %ld Bad, %ld Tossed\n",
 687                         comp->sls_i_compressed,
 688                         comp->sls_i_uncompressed,
 689                         comp->sls_i_error,
 690                         comp->sls_i_tossed);
 691         }
 692 }
 693 
 694 
 695 void slhc_o_status(struct slcompress *comp)
     /* [previous][next][first][last][top][bottom][index][help] */
 696 {
 697         if (comp != NULLSLCOMPR) {
 698                 printk("\t%ld Cmp, %ld Uncmp, %ld AsIs, %ld NotTCP\n",
 699                         comp->sls_o_compressed,
 700                         comp->sls_o_uncompressed,
 701                         comp->sls_o_tcp,
 702                         comp->sls_o_nontcp);
 703                 printk("\t%10ld Searches, %10ld Misses\n",
 704                         comp->sls_o_searches,
 705                         comp->sls_o_misses);
 706         }
 707 }
 708 
 709 #endif /* CONFIG_INET */

/* [previous][next][first][last][top][bottom][index][help] */