Linux Audio

Check our new training course

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