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