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
  13. init_module
  14. cleanup_module

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

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