]> git.ozlabs.org Git - ppp.git/blob - linux/ppp_deflate.c
fixes for SVR4
[ppp.git] / linux / ppp_deflate.c
1 /*
2  *  ==FILEVERSION 960302==
3  *
4  * ppp_deflate.c - interface the zlib procedures for Deflate compression
5  * and decompression (as used by gzip) to the PPP code.
6  * This version is for use with Linux kernel 1.3.X.
7  *
8  * Copyright (c) 1994 The Australian National University.
9  * All rights reserved.
10  *
11  * Permission to use, copy, modify, and distribute this software and its
12  * documentation is hereby granted, provided that the above copyright
13  * notice appears in all copies.  This software is provided without any
14  * warranty, express or implied. The Australian National University
15  * makes no representations about the suitability of this software for
16  * any purpose.
17  *
18  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
19  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
20  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
21  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
22  * OF SUCH DAMAGE.
23  *
24  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
25  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
27  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
28  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
29  * OR MODIFICATIONS.
30  *
31  * From: deflate.c,v 1.1 1996/01/18 03:17:48 paulus Exp
32  */
33
34 #include <linux/module.h>
35
36 #include <endian.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/types.h>
40 #include <linux/fcntl.h>
41 #include <linux/interrupt.h>
42 #include <linux/ptrace.h>
43 #include <linux/ioport.h>
44 #include <linux/in.h>
45 #include <linux/malloc.h>
46 #include <linux/tty.h>
47 #include <linux/errno.h>
48 #include <linux/sched.h>        /* to get the struct task_struct */
49 #include <linux/string.h>       /* used in new tty drivers */
50 #include <linux/signal.h>       /* used in new tty drivers */
51
52 #include <asm/system.h>
53 #include <asm/bitops.h>
54 #include <asm/segment.h>
55
56 #include <net/if.h>
57
58 #include <linux/if_ether.h>
59 #include <linux/netdevice.h>
60 #include <linux/skbuff.h>
61 #include <linux/inet.h>
62 #include <linux/ioctl.h>
63
64 #include <linux/ppp_defs.h>
65
66 #ifdef NEW_SKBUFF
67 #include <linux/netprotocol.h>
68 #endif
69
70 #include <netinet/ip.h>
71 #include <netinet/tcp.h>
72 #include <net/if_arp.h>
73
74 #undef   PACKETPTR
75 #define  PACKETPTR 1
76 #include <linux/ppp-comp.h>
77 #undef   PACKETPTR
78
79 #include "zlib.c"
80
81 /*
82  * State for a Deflate (de)compressor.
83  */
84 struct ppp_deflate_state {
85     int         seqno;
86     int         w_size;
87     int         unit;
88     int         mru;
89     int         debug;
90     z_stream    strm;
91     struct compstat stats;
92 };
93
94 #define DEFLATE_OVHD    2               /* Deflate overhead/packet */
95
96 static void     *zalloc __P((void *, unsigned int items, unsigned int size));
97 static void     zfree __P((void *, void *ptr, unsigned int nb));
98 static void     *z_comp_alloc __P((unsigned char *options, int opt_len));
99 static void     *z_decomp_alloc __P((unsigned char *options, int opt_len));
100 static void     z_comp_free __P((void *state));
101 static void     z_decomp_free __P((void *state));
102 static int      z_comp_init __P((void *state, unsigned char *options,
103                                  int opt_len,
104                                  int unit, int hdrlen, int debug));
105 static int      z_decomp_init __P((void *state, unsigned char *options,
106                                    int opt_len,
107                                    int unit, int hdrlen, int mru, int debug));
108 static int      z_compress __P((void *state, unsigned char *rptr,
109                                 unsigned char *obuf,
110                                 int isize, int osize));
111 static void     z_incomp __P((void *state, unsigned char *ibuf, int icnt));
112 static int      z_decompress __P((void *state, unsigned char *ibuf,
113                                 int isize, unsigned char *obuf, int osize));
114 static void     z_comp_reset __P((void *state));
115 static void     z_decomp_reset __P((void *state));
116 static void     z_comp_stats __P((void *state, struct compstat *stats));
117
118 /*
119  * This is a small set of memory allocation routines.  I created them so
120  * that all memory allocation from the kernel takes place at the
121  * z_(de)comp_alloc and z_(de)comp_free routines.  This eliminates worry
122  * about calling valloc() from within an interrupt.
123  *
124  * The free list is a single linked list sorted by memory address.
125  * The zfree() function re-combines any segments it can.
126  */
127 typedef struct memchunk {
128     unsigned int m_size;
129     struct memchunk *m_next;
130 } MemChunk;
131
132 typedef struct {
133     void *memHead;
134     MemChunk *freePool;
135 } MemPool;
136
137 static int     memPoolAlloc __P((void *arg, unsigned int size));
138 static void    memPoolFree __P((void *arg));
139
140 static int
141 memPoolAlloc(arg, size)
142 void *arg;
143 unsigned int size;
144 {
145     MemPool **memPool = arg;
146     MemChunk *freePool;
147
148     if ((*memPool = kmalloc(sizeof(MemPool), GFP_KERNEL)) == NULL) {
149         printk(KERN_DEBUG "Unable to allocate Memory Head\n");
150         return 0;
151     }
152
153     if (((*memPool)->memHead = (void *)vmalloc(size)) == NULL) {
154         printk(KERN_DEBUG "Unable to allocate Memory Pool\n");
155         kfree(*memPool);
156         return 0;
157     }
158     freePool = (*memPool)->freePool = (*memPool)->memHead;
159     freePool->m_size = size;
160     freePool->m_next = 0;
161
162     return 1;
163 }
164
165 static void
166 memPoolFree(arg)
167 void *arg;
168 {
169     MemPool **memPool = arg;
170
171     if (*memPool) {
172         vfree((*memPool)->memHead);
173         kfree(*memPool);
174         *memPool = NULL;
175     }
176 }
177
178 #ifdef POOLDGB
179 static void    showFreeList __P((MemChunk *));
180
181 static void
182 showFreeList(freePool)
183 MemChunk *freePool;
184 {
185     MemChunk *node;
186     
187     for (node = freePool; node; node = node->m_next)
188         printk(KERN_DEBUG "{%x,%d}->", node, node->m_size);
189     printk(KERN_DEBUG "\n");
190 }
191 #endif
192
193 /*
194  * Space allocation and freeing routines for use by zlib routines.
195  */
196 void
197 zfree(arg, ptr, nbytes)
198     void *arg;
199     void *ptr;
200     unsigned int nbytes;
201 {
202     MemPool *memPool = (MemPool *)arg;
203     MemChunk *mprev = 0, *node;
204     MemChunk *new = (void *)(((unsigned char *)ptr) - sizeof(MemChunk));
205
206     if (!memPool->freePool) {
207         new->m_next = 0;
208         memPool->freePool = new;
209     } else {
210         /*
211          * Find where this new chunk fits in the free list.
212          */
213         for (node = memPool->freePool; node && new > node; node = node->m_next)
214             mprev = node;
215         /*
216          * Re-combine with the following free chunk if possible.
217          */
218         if ((((unsigned char *)new) + new->m_size) == (unsigned char *)node) {
219             new->m_size += node->m_size;
220             new->m_next = node->m_next;
221             if (mprev) {
222                 if ((((unsigned char *)mprev) + mprev->m_size) == (unsigned char *)new) {
223                     mprev->m_size += new->m_size;
224                     mprev->m_next = new->m_next;
225                 } else
226                     mprev->m_next = new;
227             } else
228                 memPool->freePool = new;
229         /*
230          * Re-combine with the previous free chunk if possible.
231          */
232         } else if (mprev && (((unsigned char *)mprev) + mprev->m_size) ==
233           (unsigned char *)new) {
234             mprev->m_size += new->m_size;
235             if ((((unsigned char *)mprev) + mprev->m_size) == (unsigned char *)node) {
236                 mprev->m_size += node->m_size;
237                 mprev->m_next = node->m_next;
238             } else
239                 mprev->m_next = node;
240         /*
241          * No luck re-combining, just insert the new chunk into the list.
242          */
243         } else {
244             if (mprev)
245                 mprev->m_next = new;
246             else
247                 memPool->freePool = new;
248             new->m_next = node;
249         }
250     }
251 }
252
253 void *
254 zalloc(arg, items, size)
255     void *arg;
256     unsigned int items, size;
257 {
258     MemPool *memPool = (MemPool *)arg;
259     MemChunk *mprev = 0, *node;
260
261     size *= items;
262     size += sizeof(MemChunk);
263     if (size & 0x3)
264         size = (size + 7) & ~3; 
265     for (node = memPool->freePool; node; node = node->m_next) {
266         if (size == node->m_size) {
267             if (mprev)
268                 mprev->m_next = node->m_next;
269             else
270                 memPool->freePool = node->m_next;
271             return (void *)(((unsigned char *)node)+sizeof(MemChunk));
272         } else if (node->m_size > (size + sizeof(MemChunk) + 7)) {
273             MemChunk *new;
274
275             new = (void *)(((unsigned char *)node) + size);
276             new->m_size = node->m_size - size;
277             new->m_next = node->m_next;
278             if (mprev)
279                 mprev->m_next = new;
280             else
281                 memPool->freePool = new;
282
283             node->m_size = size;
284
285             return (void *)(((unsigned char *)node)+sizeof(MemChunk));
286             break;
287         }
288         mprev = node;
289     }
290     printk(KERN_DEBUG
291            "zalloc(%d)... Out of memory in Pool!\n", size - sizeof(MemChunk)); 
292     return NULL;
293 }
294
295 static void
296 z_comp_free(arg)
297     void *arg;
298 {
299     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
300
301     if (state) {
302             deflateEnd(&state->strm);
303             memPoolFree(&state->strm.opaque);
304             kfree(state);
305             MOD_DEC_USE_COUNT;
306     }
307 }
308
309 /*
310  * Allocate space for a compressor.
311  */
312 static void *
313 z_comp_alloc(options, opt_len)
314     unsigned char *options;
315     int opt_len;
316 {
317     struct ppp_deflate_state *state;
318     int w_size;
319
320     if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
321         || options[1] != CILEN_DEFLATE
322         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
323         || options[3] != DEFLATE_CHK_SEQUENCE)
324         return NULL;
325     w_size = DEFLATE_SIZE(options[2]);
326     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
327         return NULL;
328
329     state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL);
330     if (state == NULL)
331         return NULL;
332
333     MOD_INC_USE_COUNT;
334     memset (state, 0, sizeof (struct ppp_deflate_state));
335     state->strm.next_in = NULL;
336     state->strm.zalloc  = zalloc;
337     state->strm.zfree   = zfree;
338     state->w_size       = w_size;
339
340     if (!memPoolAlloc(&state->strm.opaque, 0x50000)) {
341         z_comp_free(state);
342         return NULL;
343     }
344
345     if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL,
346                      -w_size, 8, Z_DEFAULT_STRATEGY, DEFLATE_OVHD+2) != Z_OK) {
347         z_comp_free(state);
348         return NULL;
349     }
350     return (void *) state;
351 }
352
353 static int
354 z_comp_init(arg, options, opt_len, unit, hdrlen, debug)
355     void *arg;
356     unsigned char *options;
357     int opt_len, unit, hdrlen, debug;
358 {
359     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
360
361     if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
362         || options[1] != CILEN_DEFLATE
363         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
364         || DEFLATE_SIZE(options[2]) != state->w_size
365         || options[3] != DEFLATE_CHK_SEQUENCE)
366         return 0;
367
368     state->seqno = 0;
369     state->unit  = unit;
370     state->debug = debug;
371
372     deflateReset(&state->strm);
373
374     return 1;
375 }
376
377 static void
378 z_comp_reset(arg)
379     void *arg;
380 {
381     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
382     state->seqno = 0;
383     deflateReset(&state->strm);
384 }
385
386 int
387 z_compress(arg, rptr, obuf, isize, osize)
388     void *arg;
389     unsigned char *rptr;        /* uncompressed packet (in) */
390     unsigned char *obuf;        /* compressed packet (out) */
391     int isize, osize;
392 {
393     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
394     int r, proto, off, olen;
395     unsigned char *wptr;
396
397     /*
398      * Check that the protocol is in the range we handle.
399      */
400     proto = PPP_PROTOCOL(rptr);
401     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
402         return isize;
403
404     /* Don't generate compressed packets which are larger than
405        the uncompressed packet. */
406     if (osize > isize)
407         osize = isize;
408
409     wptr = obuf;
410
411     /*
412      * Copy over the PPP header and store the 2-byte sequence number.
413      */
414     wptr[0] = PPP_ADDRESS(rptr);
415     wptr[1] = PPP_CONTROL(rptr);
416     wptr[2] = PPP_COMP >> 8;
417     wptr[3] = PPP_COMP;
418     wptr += PPP_HDRLEN;
419     wptr[0] = state->seqno >> 8;
420     wptr[1] = state->seqno;
421     wptr += 2;
422     state->strm.next_out = wptr;
423     state->strm.avail_out = osize - (PPP_HDRLEN + 2);
424     ++state->seqno;
425
426     off = (proto > 0xff) ? 2 : 3;       /* skip 1st proto byte if 0 */
427     rptr += off;
428     state->strm.next_in = rptr;
429     state->strm.avail_in = (isize - off);
430
431     olen = 0;
432     for (;;) {
433         r = deflate(&state->strm, Z_PACKET_FLUSH);
434         if (r != Z_OK) {
435             printk(KERN_DEBUG "z_compress: deflate returned %d (%s)\n",
436                    r, (state->strm.msg? state->strm.msg: ""));
437             break;
438         }
439         if (state->strm.avail_out == 0) {
440             olen += osize;
441             state->strm.next_out = NULL;
442             state->strm.avail_out = 1000000;
443         } else {
444             break;              /* all done */
445         }
446     }
447     if (olen < osize)
448         olen += osize - state->strm.avail_out;
449
450     /*
451      * See if we managed to reduce the size of the packet.
452      * If the compressor just gave us a single zero byte, it means
453      * the packet was incompressible.
454      */
455     if (olen < isize && !(olen == PPP_HDRLEN + 3 && *wptr == 0)) {
456         state->stats.comp_bytes += olen;
457         state->stats.comp_packets++;
458     } else {
459         state->stats.inc_bytes += isize;
460         state->stats.inc_packets++;
461         olen = 0;
462     }
463     state->stats.unc_bytes += isize;
464     state->stats.unc_packets++;
465
466     return olen;
467 }
468
469 static void
470 z_comp_stats(arg, stats)
471     void *arg;
472     struct compstat *stats;
473 {
474     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
475
476     *stats = state->stats;
477 }
478
479 static void
480 z_decomp_free(arg)
481     void *arg;
482 {
483     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
484
485     if (state) {
486             inflateEnd(&state->strm);
487             memPoolFree(&state->strm.opaque);
488             kfree(state);
489             MOD_DEC_USE_COUNT;
490     }
491 }
492
493 /*
494  * Allocate space for a decompressor.
495  */
496 static void *
497 z_decomp_alloc(options, opt_len)
498     unsigned char *options;
499     int opt_len;
500 {
501     struct ppp_deflate_state *state;
502     int w_size;
503
504     if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
505         || options[1] != CILEN_DEFLATE
506         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
507         || options[3] != DEFLATE_CHK_SEQUENCE)
508         return NULL;
509     w_size = DEFLATE_SIZE(options[2]);
510     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
511         return NULL;
512
513     state = (struct ppp_deflate_state *) kmalloc(sizeof(*state), GFP_KERNEL);
514     if (state == NULL)
515         return NULL;
516
517     MOD_INC_USE_COUNT;
518     memset (state, 0, sizeof (struct ppp_deflate_state));
519     state->w_size        = w_size;
520     state->strm.next_out = NULL;
521     state->strm.zalloc   = zalloc;
522     state->strm.zfree    = zfree;
523
524     if (!memPoolAlloc(&state->strm.opaque, 0x10000)) {
525         z_decomp_free(state);
526         return NULL;
527     }
528
529     if (inflateInit2(&state->strm, -w_size) != Z_OK) {
530         z_decomp_free(state);
531         return NULL;
532     }
533     return (void *) state;
534 }
535
536 static int
537 z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
538     void *arg;
539     unsigned char *options;
540     int opt_len, unit, hdrlen, mru, debug;
541 {
542     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
543
544     if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
545         || options[1] != CILEN_DEFLATE
546         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
547         || DEFLATE_SIZE(options[2]) != state->w_size
548         || options[3] != DEFLATE_CHK_SEQUENCE)
549         return 0;
550
551     state->seqno = 0;
552     state->unit  = unit;
553     state->debug = debug;
554     state->mru   = mru;
555
556     inflateReset(&state->strm);
557
558     return 1;
559 }
560
561 static void
562 z_decomp_reset(arg)
563     void *arg;
564 {
565     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
566
567     state->seqno = 0;
568     inflateReset(&state->strm);
569 }
570
571 /*
572  * Decompress a Deflate-compressed packet.
573  *
574  * Because of patent problems, we return DECOMP_ERROR for errors
575  * found by inspecting the input data and for system problems, but
576  * DECOMP_FATALERROR for any errors which could possibly be said to
577  * be being detected "after" decompression.  For DECOMP_ERROR,
578  * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
579  * infringing a patent of Motorola's if we do, so we take CCP down
580  * instead.
581  *
582  * Given that the frame has the correct sequence number and a good FCS,
583  * errors such as invalid codes in the input most likely indicate a
584  * bug, so we return DECOMP_FATALERROR for them in order to turn off
585  * compression, even though they are detected by inspecting the input.
586  */
587 int
588 z_decompress(arg, ibuf, isize, obuf, osize)
589     void *arg;
590     unsigned char *ibuf;
591     int isize;
592     unsigned char *obuf;
593     int osize;
594 {
595     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
596     int olen, seq, i, r, decode_proto;
597     unsigned char hdr[PPP_HDRLEN + DEFLATE_OVHD];
598     unsigned char *rptr, *wptr;
599
600     rptr = ibuf;
601     wptr = obuf;
602     for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i)
603         hdr[i] = *rptr++;
604
605     /* Check the sequence number. */
606     seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1];
607     if (seq != state->seqno) {
608         if (state->debug)
609             printk(KERN_DEBUG "z_decompress%d: bad seq # %d, expected %d\n",
610                    state->unit, seq, state->seqno);
611         return DECOMP_ERROR;
612     }
613     ++state->seqno;
614
615     /*
616      * Fill in the first part of the PPP header.  The protocol field
617      * comes from the decompressed data.
618      */
619     wptr[0] = PPP_ADDRESS(hdr);
620     wptr[1] = PPP_CONTROL(hdr);
621     wptr[2] = 0;
622
623     /*
624      * Set up to call inflate.  We set avail_out to 1 initially so we can
625      * look at the first byte of the output and decide whether we have
626      * a 1-byte or 2-byte protocol field.
627      */
628     state->strm.next_in = rptr;
629     state->strm.avail_in = isize - (PPP_HDRLEN + DEFLATE_OVHD);
630     state->strm.next_out = wptr + 3;
631     state->strm.avail_out = 1;
632     decode_proto = 1;
633
634     /*
635      * Call inflate, supplying more input or output as needed.
636      */
637     for (;;) {
638         r = inflate(&state->strm, Z_PACKET_FLUSH);
639         if (r != Z_OK) {
640             if (state->debug)
641                 printk(KERN_DEBUG "z_decompress%d: inflate returned %d (%s)\n",
642                        state->unit, r, (state->strm.msg? state->strm.msg: ""));
643             return DECOMP_FATALERROR;
644         }
645         if (state->strm.avail_out != 0)
646             break;              /* all done */
647         if (state->strm.avail_out == 0) {
648             if (decode_proto) {
649                 state->strm.avail_out = osize - PPP_HDRLEN;
650                 if ((wptr[3] & 1) == 0) {
651                     /* 2-byte protocol field */
652                     wptr[2] = wptr[3];
653                     --state->strm.next_out;
654                     ++state->strm.avail_out;
655                 }
656                 decode_proto = 0;
657             } else {
658                 if (state->debug)
659                     printk(KERN_DEBUG "z_decompress%d: ran out of mru\n",
660                        state->unit);
661                 return DECOMP_FATALERROR;
662             }
663         }
664     }
665
666     if (decode_proto)
667         return DECOMP_ERROR;
668
669     olen = (osize - state->strm.avail_out);
670
671     state->stats.unc_bytes += olen;
672     state->stats.unc_packets++;
673     state->stats.comp_bytes += isize;
674     state->stats.comp_packets++;
675
676     return olen;
677 }
678
679 /*
680  * Incompressible data has arrived - add it to the history.
681  */
682 static void
683 z_incomp(arg, ibuf, icnt)
684     void *arg;
685     unsigned char *ibuf;
686     int icnt;
687 {
688     struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
689     unsigned char *rptr = ibuf;
690     int proto, r;
691
692     /*
693      * Check that the protocol is one we handle.
694      */
695     proto = PPP_PROTOCOL(rptr);
696     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
697         return;
698
699     ++state->seqno;
700
701     /*
702      * Iterate through the message blocks, adding the characters in them
703      * to the decompressor's history.  For the first block, we start
704      * at the either the 1st or 2nd byte of the protocol field,
705      * depending on whether the protocol value is compressible.
706      */
707     state->strm.next_in = rptr + 3;
708     state->strm.avail_in = icnt - 3;
709     if (proto > 0xff) {
710         --state->strm.next_in;
711         ++state->strm.avail_in;
712     }
713
714     r = inflateIncomp(&state->strm);
715     if (r != Z_OK) {
716         /* gak! */
717         if (state->debug) {
718             printk(KERN_DEBUG "z_incomp%d: inflateIncomp returned %d (%s)\n",
719                    state->unit, r, (state->strm.msg? state->strm.msg: ""));
720         }
721         return;
722     }
723
724     /*
725      * Update stats.
726      */
727     state->stats.inc_bytes += icnt;
728     state->stats.inc_packets++;
729     state->stats.unc_bytes += icnt;
730     state->stats.unc_packets++;
731 }
732
733 /*************************************************************
734  * Module interface table
735  *************************************************************/
736
737 /* These are in ppp.c */
738 extern int  ppp_register_compressor   (struct compressor *cp);
739 extern void ppp_unregister_compressor (struct compressor *cp);
740
741 /*
742  * Procedures exported to if_ppp.c.
743  */
744 struct compressor ppp_deflate = {
745     CI_DEFLATE,                 /* compress_proto */
746     z_comp_alloc,               /* comp_alloc */
747     z_comp_free,                /* comp_free */
748     z_comp_init,                /* comp_init */
749     z_comp_reset,               /* comp_reset */
750     z_compress,                 /* compress */
751     z_comp_stats,               /* comp_stat */
752     z_decomp_alloc,             /* decomp_alloc */
753     z_decomp_free,              /* decomp_free */
754     z_decomp_init,              /* decomp_init */
755     z_decomp_reset,             /* decomp_reset */
756     z_decompress,               /* decompress */
757     z_incomp,                   /* incomp */
758     z_comp_stats,               /* decomp_stat */
759 };
760
761 /*************************************************************
762  * Module support routines
763  *************************************************************/
764
765 int
766 init_module(void)
767 {  
768         int answer = ppp_register_compressor (&ppp_deflate);
769         if (answer == 0)
770                 printk (KERN_INFO
771                         "PPP Deflate Compression module registered\n");
772         return answer;
773 }
774      
775 void
776 cleanup_module(void)
777 {
778         if (MOD_IN_USE)
779                 printk (KERN_INFO
780                         "Deflate Compression module busy, remove delayed\n");
781         else
782                 ppp_unregister_compressor (&ppp_deflate);
783 }