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/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> 59 #include <net/slhc_vj.h> 60 61 #ifdef CONFIG_INET 62 /* Entire module is for IP only */ 63 #include <linux/mm.h> 64 #include <linux/socket.h> 65 #include <linux/sockios.h> 66 #include <linux/termios.h> 67 #include <linux/in.h> 68 #include <linux/fcntl.h> 69 #include <linux/inet.h> 70 #include <linux/netdevice.h> 71 #include <net/ip.h> 72 #include <net/protocol.h> 73 #include <net/icmp.h> 74 #include <net/tcp.h> 75 #include <linux/skbuff.h> 76 #include <net/sock.h> 77 #include <linux/timer.h> 78 #include <linux/uaccess.h> 79 #include <net/checksum.h> 80 #include <linux/unaligned.h> 81 82 static unsigned char *encode(unsigned char *cp, unsigned short n); 83 static long decode(unsigned char **cpp, const unsigned char *end); 84 static unsigned char * put16(unsigned char *cp, unsigned short x); 85 static long pull16(unsigned char **cpp, const unsigned char *end); 86 87 /* Allocate compression data structure 88 * slots must be in range 0 to 255 (zero meaning no compression) 89 * Returns pointer to structure or ERR_PTR() on error. 90 */ 91 struct slcompress * 92 slhc_init(int rslots, int tslots) 93 { 94 short i; 95 struct cstate *ts; 96 struct slcompress *comp; 97 98 if (rslots < 0 || rslots > 255 || tslots < 0 || tslots > 255) 99 return ERR_PTR(-EINVAL); 100 101 comp = kzalloc_obj(struct slcompress); 102 if (! comp) 103 goto out_fail; 104 105 if (rslots > 0) { 106 size_t rsize = rslots * sizeof(struct cstate); 107 comp->rstate = kzalloc(rsize, GFP_KERNEL); 108 if (! comp->rstate) 109 goto out_free; 110 comp->rslot_limit = rslots - 1; 111 } 112 113 if (tslots > 0) { 114 size_t tsize = tslots * sizeof(struct cstate); 115 comp->tstate = kzalloc(tsize, GFP_KERNEL); 116 if (! comp->tstate) 117 goto out_free2; 118 comp->tslot_limit = tslots - 1; 119 } 120 121 comp->xmit_oldest = 0; 122 comp->xmit_current = 255; 123 comp->recv_current = 255; 124 /* 125 * don't accept any packets with implicit index until we get 126 * one with an explicit index. Otherwise the uncompress code 127 * will try to use connection 255, which is almost certainly 128 * out of range 129 */ 130 comp->flags |= SLF_TOSS; 131 132 if ( tslots > 0 ) { 133 ts = comp->tstate; 134 for(i = comp->tslot_limit; i > 0; --i){ 135 ts[i].cs_this = i; 136 ts[i].next = &(ts[i - 1]); 137 } 138 ts[0].next = &(ts[comp->tslot_limit]); 139 ts[0].cs_this = 0; 140 } 141 return comp; 142 143 out_free2: 144 kfree(comp->rstate); 145 out_free: 146 kfree(comp); 147 out_fail: 148 return ERR_PTR(-ENOMEM); 149 } 150 151 152 /* Free a compression data structure */ 153 void 154 slhc_free(struct slcompress *comp) 155 { 156 if ( IS_ERR_OR_NULL(comp) ) 157 return; 158 159 if ( comp->tstate != NULLSLSTATE ) 160 kfree( comp->tstate ); 161 162 if ( comp->rstate != NULLSLSTATE ) 163 kfree( comp->rstate ); 164 165 kfree( comp ); 166 } 167 168 169 /* Put a short in host order into a char array in network order */ 170 static inline unsigned char * 171 put16(unsigned char *cp, unsigned short x) 172 { 173 *cp++ = x >> 8; 174 *cp++ = x; 175 176 return cp; 177 } 178 179 180 /* Encode a number */ 181 static unsigned char * 182 encode(unsigned char *cp, unsigned short n) 183 { 184 if(n >= 256 || n == 0){ 185 *cp++ = 0; 186 cp = put16(cp,n); 187 } else { 188 *cp++ = n; 189 } 190 return cp; 191 } 192 193 /* Pull a 16-bit integer in host order from buffer in network byte order. 194 * Returns -1 if the buffer is exhausted, otherwise the 16-bit value. 195 */ 196 static long 197 pull16(unsigned char **cpp, const unsigned char *end) 198 { 199 long rval; 200 201 if (*cpp + 2 > end) 202 return -1; 203 rval = *(*cpp)++; 204 rval <<= 8; 205 rval |= *(*cpp)++; 206 return rval; 207 } 208 209 /* Decode a number. Returns -1 if the buffer is exhausted. */ 210 static long 211 decode(unsigned char **cpp, const unsigned char *end) 212 { 213 int x; 214 215 if (*cpp >= end) 216 return -1; 217 x = *(*cpp)++; 218 if (x == 0) 219 return pull16(cpp, end); 220 return x & 0xff; 221 } 222 223 /* 224 * icp and isize are the original packet. 225 * ocp is a place to put a copy if necessary. 226 * cpp is initially a pointer to icp. If the copy is used, 227 * change it to ocp. 228 */ 229 230 int 231 slhc_compress(struct slcompress *comp, unsigned char *icp, int isize, 232 unsigned char *ocp, unsigned char **cpp, int compress_cid) 233 { 234 struct cstate *ocs = &(comp->tstate[comp->xmit_oldest]); 235 struct cstate *lcs = ocs; 236 struct cstate *cs = lcs->next; 237 unsigned long deltaS, deltaA; 238 short changes = 0; 239 int nlen, hlen; 240 unsigned char new_seq[16]; 241 unsigned char *cp = new_seq; 242 struct iphdr *ip; 243 struct tcphdr *th, *oth; 244 __sum16 csum; 245 246 247 /* 248 * Don't play with runt packets. 249 */ 250 251 if(isize<sizeof(struct iphdr)) 252 return isize; 253 254 ip = (struct iphdr *) icp; 255 if (ip->version != 4 || ip->ihl < 5) 256 return isize; 257 258 /* Bail if this packet isn't TCP, or is an IP fragment */ 259 if (ip->protocol != IPPROTO_TCP || (ntohs(ip->frag_off) & 0x3fff)) { 260 /* Send as regular IP */ 261 if(ip->protocol != IPPROTO_TCP) 262 comp->sls_o_nontcp++; 263 else 264 comp->sls_o_tcp++; 265 return isize; 266 } 267 nlen = ip->ihl * 4; 268 if (isize < nlen + sizeof(*th)) 269 return isize; 270 271 th = (struct tcphdr *)(icp + nlen); 272 if (th->doff < sizeof(struct tcphdr) / 4) 273 return isize; 274 hlen = nlen + th->doff * 4; 275 276 /* Bail if the TCP packet isn't `compressible' (i.e., ACK isn't set or 277 * some other control bit is set). Also uncompressible if 278 * it's a runt. 279 */ 280 if(hlen > isize || 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(ip->version != cs->cs_ip.version || ip->ihl != cs->cs_ip.ihl 358 || ip->tos != cs->cs_ip.tos 359 || (ip->frag_off & htons(0x4000)) != (cs->cs_ip.frag_off & htons(0x4000)) 360 || ip->ttl != cs->cs_ip.ttl 361 || th->doff != cs->cs_tcp.doff 362 || (ip->ihl > 5 && memcmp(ip+1,cs->cs_ipopt,((ip->ihl)-5)*4) != 0) 363 || (th->doff > 5 && memcmp(th+1,cs->cs_tcpopt,((th->doff)-5)*4) != 0)){ 364 goto uncompressed; 365 } 366 367 /* 368 * Figure out which of the changing fields changed. The 369 * receiver expects changes in the order: urgent, window, 370 * ack, seq (the order minimizes the number of temporaries 371 * needed in this section of code). 372 */ 373 if(th->urg){ 374 deltaS = ntohs(th->urg_ptr); 375 cp = encode(cp,deltaS); 376 changes |= NEW_U; 377 } else if(th->urg_ptr != oth->urg_ptr){ 378 /* argh! URG not set but urp changed -- a sensible 379 * implementation should never do this but RFC793 380 * doesn't prohibit the change so we have to deal 381 * with it. */ 382 goto uncompressed; 383 } 384 if((deltaS = ntohs(th->window) - ntohs(oth->window)) != 0){ 385 cp = encode(cp,deltaS); 386 changes |= NEW_W; 387 } 388 if((deltaA = ntohl(th->ack_seq) - ntohl(oth->ack_seq)) != 0L){ 389 if(deltaA > 0x0000ffff) 390 goto uncompressed; 391 cp = encode(cp,deltaA); 392 changes |= NEW_A; 393 } 394 if((deltaS = ntohl(th->seq) - ntohl(oth->seq)) != 0L){ 395 if(deltaS > 0x0000ffff) 396 goto uncompressed; 397 cp = encode(cp,deltaS); 398 changes |= NEW_S; 399 } 400 401 switch(changes){ 402 case 0: /* Nothing changed. If this packet contains data and the 403 * last one didn't, this is probably a data packet following 404 * an ack (normal on an interactive connection) and we send 405 * it compressed. Otherwise it's probably a retransmit, 406 * retransmitted ack or window probe. Send it uncompressed 407 * in case the other side missed the compressed version. 408 */ 409 if(ip->tot_len != cs->cs_ip.tot_len && 410 ntohs(cs->cs_ip.tot_len) == hlen) 411 break; 412 goto uncompressed; 413 case SPECIAL_I: 414 case SPECIAL_D: 415 /* actual changes match one of our special case encodings -- 416 * send packet uncompressed. 417 */ 418 goto uncompressed; 419 case NEW_S|NEW_A: 420 if(deltaS == deltaA && 421 deltaS == ntohs(cs->cs_ip.tot_len) - hlen){ 422 /* special case for echoed terminal traffic */ 423 changes = SPECIAL_I; 424 cp = new_seq; 425 } 426 break; 427 case NEW_S: 428 if(deltaS == ntohs(cs->cs_ip.tot_len) - hlen){ 429 /* special case for data xfer */ 430 changes = SPECIAL_D; 431 cp = new_seq; 432 } 433 break; 434 } 435 deltaS = ntohs(ip->id) - ntohs(cs->cs_ip.id); 436 if(deltaS != 1){ 437 cp = encode(cp,deltaS); 438 changes |= NEW_I; 439 } 440 if(th->psh) 441 changes |= TCP_PUSH_BIT; 442 /* Grab the cksum before we overwrite it below. Then update our 443 * state with this packet's header. 444 */ 445 csum = th->check; 446 memcpy(&cs->cs_ip,ip,20); 447 memcpy(&cs->cs_tcp,th,20); 448 /* We want to use the original packet as our compressed packet. 449 * (cp - new_seq) is the number of bytes we need for compressed 450 * sequence numbers. In addition we need one byte for the change 451 * mask, one for the connection id and two for the tcp checksum. 452 * So, (cp - new_seq) + 4 bytes of header are needed. 453 */ 454 deltaS = cp - new_seq; 455 if(compress_cid == 0 || comp->xmit_current != cs->cs_this){ 456 cp = ocp; 457 *cpp = ocp; 458 *cp++ = changes | NEW_C; 459 *cp++ = cs->cs_this; 460 comp->xmit_current = cs->cs_this; 461 } else { 462 cp = ocp; 463 *cpp = ocp; 464 *cp++ = changes; 465 } 466 *(__sum16 *)cp = csum; 467 cp += 2; 468 /* deltaS is now the size of the change section of the compressed header */ 469 memcpy(cp,new_seq,deltaS); /* Write list of deltas */ 470 memcpy(cp+deltaS,icp+hlen,isize-hlen); 471 comp->sls_o_compressed++; 472 ocp[0] |= SL_TYPE_COMPRESSED_TCP; 473 return isize - hlen + deltaS + (cp - ocp); 474 475 /* Update connection state cs & send uncompressed packet (i.e., 476 * a regular ip/tcp packet but with the 'conversation id' we hope 477 * to use on future compressed packets in the protocol field). 478 */ 479 uncompressed: 480 memcpy(&cs->cs_ip,ip,20); 481 memcpy(&cs->cs_tcp,th,20); 482 if (ip->ihl > 5) 483 memcpy(cs->cs_ipopt, ip+1, ((ip->ihl) - 5) * 4); 484 if (th->doff > 5) 485 memcpy(cs->cs_tcpopt, th+1, ((th->doff) - 5) * 4); 486 comp->xmit_current = cs->cs_this; 487 comp->sls_o_uncompressed++; 488 memcpy(ocp, icp, isize); 489 *cpp = ocp; 490 ocp[9] = cs->cs_this; 491 ocp[0] |= SL_TYPE_UNCOMPRESSED_TCP; 492 return isize; 493 } 494 495 496 int 497 slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize) 498 { 499 int changes; 500 long x; 501 struct tcphdr *thp; 502 struct iphdr *ip; 503 struct cstate *cs; 504 int len, hdrlen; 505 unsigned char *cp = icp; 506 const unsigned char *end = icp + isize; 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 if (!comp->rstate) 515 goto bad; 516 changes = *cp++; 517 if(changes & NEW_C){ 518 /* Make sure the state index is in range, then grab the state. 519 * If we have a good state index, clear the 'discard' flag. 520 */ 521 x = *cp++; /* Read conn index */ 522 if(x < 0 || x > comp->rslot_limit) 523 goto bad; 524 525 /* Check if the cstate is initialized */ 526 if (!comp->rstate[x].initialized) 527 goto bad; 528 529 comp->flags &=~ SLF_TOSS; 530 comp->recv_current = x; 531 } else { 532 /* this packet has an implicit state index. If we've 533 * had a line error since the last time we got an 534 * explicit state index, we have to toss the packet. */ 535 if(comp->flags & SLF_TOSS){ 536 comp->sls_i_tossed++; 537 return 0; 538 } 539 } 540 cs = &comp->rstate[comp->recv_current]; 541 thp = &cs->cs_tcp; 542 ip = &cs->cs_ip; 543 544 if (cp + 2 > end) 545 goto bad; 546 thp->check = *(__sum16 *)cp; 547 cp += 2; 548 549 thp->psh = (changes & TCP_PUSH_BIT) ? 1 : 0; 550 /* 551 * we can use the same number for the length of the saved header and 552 * the current one, because the packet wouldn't have been sent 553 * as compressed unless the options were the same as the previous one 554 */ 555 556 hdrlen = ip->ihl * 4 + thp->doff * 4; 557 558 switch(changes & SPECIALS_MASK){ 559 case SPECIAL_I: /* Echoed terminal traffic */ 560 { 561 short i; 562 i = ntohs(ip->tot_len) - hdrlen; 563 thp->ack_seq = htonl( ntohl(thp->ack_seq) + i); 564 thp->seq = htonl( ntohl(thp->seq) + i); 565 } 566 break; 567 568 case SPECIAL_D: /* Unidirectional data */ 569 thp->seq = htonl( ntohl(thp->seq) + 570 ntohs(ip->tot_len) - hdrlen); 571 break; 572 573 default: 574 if(changes & NEW_U){ 575 thp->urg = 1; 576 if((x = decode(&cp, end)) == -1) { 577 goto bad; 578 } 579 thp->urg_ptr = htons(x); 580 } else 581 thp->urg = 0; 582 if(changes & NEW_W){ 583 if((x = decode(&cp, end)) == -1) { 584 goto bad; 585 } 586 thp->window = htons( ntohs(thp->window) + x); 587 } 588 if(changes & NEW_A){ 589 if((x = decode(&cp, end)) == -1) { 590 goto bad; 591 } 592 thp->ack_seq = htonl( ntohl(thp->ack_seq) + x); 593 } 594 if(changes & NEW_S){ 595 if((x = decode(&cp, end)) == -1) { 596 goto bad; 597 } 598 thp->seq = htonl( ntohl(thp->seq) + x); 599 } 600 break; 601 } 602 if(changes & NEW_I){ 603 if((x = decode(&cp, end)) == -1) { 604 goto bad; 605 } 606 ip->id = htons (ntohs (ip->id) + x); 607 } else 608 ip->id = htons (ntohs (ip->id) + 1); 609 610 /* 611 * At this point, cp points to the first byte of data in the 612 * packet. Put the reconstructed TCP and IP headers back on the 613 * packet. Recalculate IP checksum (but not TCP checksum). 614 */ 615 616 len = isize - (cp - icp); 617 if (len < 0) 618 goto bad; 619 len += hdrlen; 620 ip->tot_len = htons(len); 621 ip->check = 0; 622 623 memmove(icp + hdrlen, cp, len - hdrlen); 624 625 cp = icp; 626 memcpy(cp, ip, 20); 627 cp += 20; 628 629 if (ip->ihl > 5) { 630 memcpy(cp, cs->cs_ipopt, (ip->ihl - 5) * 4); 631 cp += (ip->ihl - 5) * 4; 632 } 633 634 put_unaligned(ip_fast_csum(icp, ip->ihl), 635 &((struct iphdr *)icp)->check); 636 637 memcpy(cp, thp, 20); 638 cp += 20; 639 640 if (thp->doff > 5) { 641 memcpy(cp, cs->cs_tcpopt, ((thp->doff) - 5) * 4); 642 cp += ((thp->doff) - 5) * 4; 643 } 644 645 return len; 646 bad: 647 comp->sls_i_error++; 648 return slhc_toss( comp ); 649 } 650 651 652 int 653 slhc_remember(struct slcompress *comp, unsigned char *icp, int isize) 654 { 655 const struct tcphdr *th; 656 unsigned char index; 657 struct iphdr *iph; 658 struct cstate *cs; 659 unsigned int ihl; 660 661 if (!comp->rstate) { 662 comp->sls_i_error++; 663 return slhc_toss(comp); 664 } 665 /* The packet is shorter than a legal IP header. 666 * Also make sure isize is positive. 667 */ 668 if (isize < (int)sizeof(struct iphdr)) { 669 runt: 670 comp->sls_i_runt++; 671 return slhc_toss(comp); 672 } 673 iph = (struct iphdr *)icp; 674 /* Peek at the IP header's IHL field to find its length */ 675 ihl = iph->ihl; 676 /* The IP header length field is too small, 677 * or packet is shorter than the IP header followed 678 * by minimal tcp header. 679 */ 680 if (ihl < 5 || isize < ihl * 4 + sizeof(struct tcphdr)) 681 goto runt; 682 683 index = iph->protocol; 684 iph->protocol = IPPROTO_TCP; 685 686 if (ip_fast_csum(icp, ihl)) { 687 /* Bad IP header checksum; discard */ 688 comp->sls_i_badcheck++; 689 return slhc_toss(comp); 690 } 691 if (index > comp->rslot_limit) { 692 comp->sls_i_error++; 693 return slhc_toss(comp); 694 } 695 th = (struct tcphdr *)(icp + ihl * 4); 696 if (th->doff < sizeof(struct tcphdr) / 4) 697 goto runt; 698 if (isize < ihl * 4 + th->doff * 4) 699 goto runt; 700 /* Update local state */ 701 cs = &comp->rstate[comp->recv_current = index]; 702 comp->flags &=~ SLF_TOSS; 703 memcpy(&cs->cs_ip, iph, sizeof(*iph)); 704 memcpy(&cs->cs_tcp, th, sizeof(*th)); 705 if (ihl > 5) 706 memcpy(cs->cs_ipopt, &iph[1], (ihl - 5) * 4); 707 if (th->doff > 5) 708 memcpy(cs->cs_tcpopt, &th[1], (th->doff - 5) * 4); 709 cs->cs_hsize = ihl*2 + th->doff*2; 710 cs->initialized = true; 711 /* Put headers back on packet 712 * Neither header checksum is recalculated 713 */ 714 comp->sls_i_uncompressed++; 715 return isize; 716 } 717 718 int 719 slhc_toss(struct slcompress *comp) 720 { 721 if ( comp == NULLSLCOMPR ) 722 return 0; 723 724 comp->flags |= SLF_TOSS; 725 return 0; 726 } 727 728 #else /* CONFIG_INET */ 729 730 int 731 slhc_toss(struct slcompress *comp) 732 { 733 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_toss"); 734 return -EINVAL; 735 } 736 int 737 slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize) 738 { 739 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_uncompress"); 740 return -EINVAL; 741 } 742 int 743 slhc_compress(struct slcompress *comp, unsigned char *icp, int isize, 744 unsigned char *ocp, unsigned char **cpp, int compress_cid) 745 { 746 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_compress"); 747 return -EINVAL; 748 } 749 750 int 751 slhc_remember(struct slcompress *comp, unsigned char *icp, int isize) 752 { 753 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_remember"); 754 return -EINVAL; 755 } 756 757 void 758 slhc_free(struct slcompress *comp) 759 { 760 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_free"); 761 } 762 struct slcompress * 763 slhc_init(int rslots, int tslots) 764 { 765 printk(KERN_DEBUG "Called IP function on non IP-system: slhc_init"); 766 return NULL; 767 } 768 769 #endif /* CONFIG_INET */ 770 771 /* VJ header compression */ 772 EXPORT_SYMBOL(slhc_init); 773 EXPORT_SYMBOL(slhc_free); 774 EXPORT_SYMBOL(slhc_remember); 775 EXPORT_SYMBOL(slhc_compress); 776 EXPORT_SYMBOL(slhc_uncompress); 777 EXPORT_SYMBOL(slhc_toss); 778 779 MODULE_DESCRIPTION("Compression helpers for SLIP (serial line)"); 780 MODULE_LICENSE("Dual BSD/GPL"); 781