1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64#include <linux/module.h>
65#include <linux/init.h>
66#include <linux/slab.h>
67#include <linux/vmalloc.h>
68#include <linux/string.h>
69
70#include <linux/ppp_defs.h>
71
72#undef PACKETPTR
73#define PACKETPTR 1
74#include <linux/ppp-comp.h>
75#undef PACKETPTR
76
77#include <asm/byteorder.h>
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106#define BSD_VERSION(x) ((x) >> 5)
107#define BSD_NBITS(x) ((x) & 0x1F)
108
109#define BSD_CURRENT_VERSION 1
110
111
112
113
114
115struct bsd_dict {
116 union {
117 unsigned long fcode;
118 struct {
119#if defined(__LITTLE_ENDIAN)
120 unsigned short prefix;
121 unsigned char suffix;
122 unsigned char pad;
123#elif defined(__BIG_ENDIAN)
124 unsigned char pad;
125 unsigned char suffix;
126 unsigned short prefix;
127#else
128#error Endianness not defined...
129#endif
130 } hs;
131 } f;
132 unsigned short codem1;
133 unsigned short cptr;
134};
135
136struct bsd_db {
137 int totlen;
138 unsigned int hsize;
139 unsigned char hshift;
140 unsigned char n_bits;
141 unsigned char maxbits;
142 unsigned char debug;
143 unsigned char unit;
144 unsigned short seqno;
145 unsigned int mru;
146 unsigned int maxmaxcode;
147 unsigned int max_ent;
148 unsigned int in_count;
149 unsigned int bytes_out;
150 unsigned int ratio;
151 unsigned int checkpoint;
152 unsigned int clear_count;
153 unsigned int incomp_count;
154 unsigned int incomp_bytes;
155 unsigned int uncomp_count;
156 unsigned int uncomp_bytes;
157 unsigned int comp_count;
158 unsigned int comp_bytes;
159 unsigned short *lens;
160 struct bsd_dict *dict;
161};
162
163#define BSD_OVHD 2
164#define MIN_BSD_BITS 9
165#define BSD_INIT_BITS MIN_BSD_BITS
166#define MAX_BSD_BITS 15
167
168static void bsd_free (void *state);
169static void *bsd_alloc(unsigned char *options, int opt_len, int decomp);
170static void *bsd_comp_alloc (unsigned char *options, int opt_len);
171static void *bsd_decomp_alloc (unsigned char *options, int opt_len);
172
173static int bsd_init (void *db, unsigned char *options,
174 int opt_len, int unit, int debug, int decomp);
175static int bsd_comp_init (void *state, unsigned char *options,
176 int opt_len, int unit, int opthdr, int debug);
177static int bsd_decomp_init (void *state, unsigned char *options,
178 int opt_len, int unit, int opthdr, int mru,
179 int debug);
180
181static void bsd_reset (void *state);
182static void bsd_comp_stats (void *state, struct compstat *stats);
183
184static int bsd_compress (void *state, unsigned char *rptr,
185 unsigned char *obuf, int isize, int osize);
186static void bsd_incomp (void *state, unsigned char *ibuf, int icnt);
187
188static int bsd_decompress (void *state, unsigned char *ibuf, int isize,
189 unsigned char *obuf, int osize);
190
191
192extern int ppp_register_compressor (struct compressor *cp);
193extern void ppp_unregister_compressor (struct compressor *cp);
194
195
196
197
198
199#define CLEAR 256
200#define FIRST 257
201#define LAST 255
202
203#define MAXCODE(b) ((1 << (b)) - 1)
204#define BADCODEM1 MAXCODE(MAX_BSD_BITS)
205
206#define BSD_HASH(prefix,suffix,hshift) ((((unsigned long)(suffix))<<(hshift)) \
207 ^ (unsigned long)(prefix))
208#define BSD_KEY(prefix,suffix) ((((unsigned long)(suffix)) << 16) \
209 + (unsigned long)(prefix))
210
211#define CHECK_GAP 10000
212
213#define RATIO_SCALE_LOG 8
214#define RATIO_SCALE (1<<RATIO_SCALE_LOG)
215#define RATIO_MAX (0x7fffffff>>RATIO_SCALE_LOG)
216
217
218
219
220
221static void
222bsd_clear(struct bsd_db *db)
223{
224 db->clear_count++;
225 db->max_ent = FIRST-1;
226 db->n_bits = BSD_INIT_BITS;
227 db->bytes_out = 0;
228 db->in_count = 0;
229 db->ratio = 0;
230 db->checkpoint = CHECK_GAP;
231}
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247static int bsd_check (struct bsd_db *db)
248 {
249 unsigned int new_ratio;
250
251 if (db->in_count >= db->checkpoint)
252 {
253
254 if (db->in_count >= RATIO_MAX || db->bytes_out >= RATIO_MAX)
255 {
256 db->in_count -= (db->in_count >> 2);
257 db->bytes_out -= (db->bytes_out >> 2);
258 }
259
260 db->checkpoint = db->in_count + CHECK_GAP;
261
262 if (db->max_ent >= db->maxmaxcode)
263 {
264
265
266
267
268
269
270
271
272 new_ratio = db->in_count << RATIO_SCALE_LOG;
273 if (db->bytes_out != 0)
274 {
275 new_ratio /= db->bytes_out;
276 }
277
278 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE)
279 {
280 bsd_clear (db);
281 return 1;
282 }
283 db->ratio = new_ratio;
284 }
285 }
286 return 0;
287 }
288
289
290
291
292
293static void bsd_comp_stats (void *state, struct compstat *stats)
294 {
295 struct bsd_db *db = (struct bsd_db *) state;
296
297 stats->unc_bytes = db->uncomp_bytes;
298 stats->unc_packets = db->uncomp_count;
299 stats->comp_bytes = db->comp_bytes;
300 stats->comp_packets = db->comp_count;
301 stats->inc_bytes = db->incomp_bytes;
302 stats->inc_packets = db->incomp_count;
303 stats->in_count = db->in_count;
304 stats->bytes_out = db->bytes_out;
305 }
306
307
308
309
310
311static void bsd_reset (void *state)
312 {
313 struct bsd_db *db = (struct bsd_db *) state;
314
315 bsd_clear(db);
316
317 db->seqno = 0;
318 db->clear_count = 0;
319 }
320
321
322
323
324
325static void bsd_free (void *state)
326{
327 struct bsd_db *db = state;
328
329 if (!db)
330 return;
331
332
333
334
335 vfree(db->dict);
336 db->dict = NULL;
337
338
339
340 vfree(db->lens);
341 db->lens = NULL;
342
343
344
345 kfree(db);
346}
347
348
349
350
351
352static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
353 {
354 int bits;
355 unsigned int hsize, hshift, maxmaxcode;
356 struct bsd_db *db;
357
358 if (opt_len != 3 || options[0] != CI_BSD_COMPRESS || options[1] != 3
359 || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
360 {
361 return NULL;
362 }
363
364 bits = BSD_NBITS(options[2]);
365
366 switch (bits)
367 {
368 case 9:
369 case 10:
370 case 11:
371 case 12:
372 hsize = 5003;
373 hshift = 4;
374 break;
375 case 13:
376 hsize = 9001;
377 hshift = 5;
378 break;
379 case 14:
380 hsize = 18013;
381 hshift = 6;
382 break;
383 case 15:
384 hsize = 35023;
385 hshift = 7;
386 break;
387 case 16:
388
389
390
391 default:
392 return NULL;
393 }
394
395
396
397 maxmaxcode = MAXCODE(bits);
398 db = kzalloc(sizeof (struct bsd_db),
399 GFP_KERNEL);
400 if (!db)
401 {
402 return NULL;
403 }
404
405
406
407
408
409 db->dict = vmalloc(hsize * sizeof(struct bsd_dict));
410 if (!db->dict)
411 {
412 bsd_free (db);
413 return NULL;
414 }
415
416
417
418
419 if (!decomp)
420 {
421 db->lens = NULL;
422 }
423
424
425
426 else
427 {
428 db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0]));
429 if (!db->lens)
430 {
431 bsd_free (db);
432 return NULL;
433 }
434 }
435
436
437
438 db->totlen = sizeof (struct bsd_db) +
439 (sizeof (struct bsd_dict) * hsize);
440
441 db->hsize = hsize;
442 db->hshift = hshift;
443 db->maxmaxcode = maxmaxcode;
444 db->maxbits = bits;
445
446 return (void *) db;
447 }
448
449static void *bsd_comp_alloc (unsigned char *options, int opt_len)
450 {
451 return bsd_alloc (options, opt_len, 0);
452 }
453
454static void *bsd_decomp_alloc (unsigned char *options, int opt_len)
455 {
456 return bsd_alloc (options, opt_len, 1);
457 }
458
459
460
461
462
463static int bsd_init (void *state, unsigned char *options,
464 int opt_len, int unit, int debug, int decomp)
465 {
466 struct bsd_db *db = state;
467 int indx;
468
469 if ((opt_len != 3) || (options[0] != CI_BSD_COMPRESS) || (options[1] != 3)
470 || (BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
471 || (BSD_NBITS(options[2]) != db->maxbits)
472 || (decomp && db->lens == NULL))
473 {
474 return 0;
475 }
476
477 if (decomp)
478 {
479 indx = LAST;
480 do
481 {
482 db->lens[indx] = 1;
483 }
484 while (indx-- > 0);
485 }
486
487 indx = db->hsize;
488 while (indx-- != 0)
489 {
490 db->dict[indx].codem1 = BADCODEM1;
491 db->dict[indx].cptr = 0;
492 }
493
494 db->unit = unit;
495 db->mru = 0;
496#ifndef DEBUG
497 if (debug)
498#endif
499 db->debug = 1;
500
501 bsd_reset(db);
502
503 return 1;
504 }
505
506static int bsd_comp_init (void *state, unsigned char *options,
507 int opt_len, int unit, int opthdr, int debug)
508 {
509 return bsd_init (state, options, opt_len, unit, debug, 0);
510 }
511
512static int bsd_decomp_init (void *state, unsigned char *options,
513 int opt_len, int unit, int opthdr, int mru,
514 int debug)
515 {
516 return bsd_init (state, options, opt_len, unit, debug, 1);
517 }
518
519
520
521
522
523#define dict_ptrx(p,idx) &(p->dict[idx])
524#define lens_ptrx(p,idx) &(p->lens[idx])
525
526#ifdef DEBUG
527static unsigned short *lens_ptr(struct bsd_db *db, int idx)
528 {
529 if ((unsigned int) idx > (unsigned int) db->maxmaxcode)
530 {
531 printk ("<9>ppp: lens_ptr(%d) > max\n", idx);
532 idx = 0;
533 }
534 return lens_ptrx (db, idx);
535 }
536
537static struct bsd_dict *dict_ptr(struct bsd_db *db, int idx)
538 {
539 if ((unsigned int) idx >= (unsigned int) db->hsize)
540 {
541 printk ("<9>ppp: dict_ptr(%d) > max\n", idx);
542 idx = 0;
543 }
544 return dict_ptrx (db, idx);
545 }
546
547#else
548#define lens_ptr(db,idx) lens_ptrx(db,idx)
549#define dict_ptr(db,idx) dict_ptrx(db,idx)
550#endif
551
552
553
554
555
556
557
558
559
560
561
562
563static int bsd_compress (void *state, unsigned char *rptr, unsigned char *obuf,
564 int isize, int osize)
565 {
566 struct bsd_db *db;
567 int hshift;
568 unsigned int max_ent;
569 unsigned int n_bits;
570 unsigned int bitno;
571 unsigned long accm;
572 int ent;
573 unsigned long fcode;
574 struct bsd_dict *dictp;
575 unsigned char c;
576 int hval;
577 int disp;
578 int ilen;
579 int mxcode;
580 unsigned char *wptr;
581 int olen;
582
583#define PUTBYTE(v) \
584 { \
585 ++olen; \
586 if (wptr) \
587 { \
588 *wptr++ = (unsigned char) (v); \
589 if (olen >= osize) \
590 { \
591 wptr = NULL; \
592 } \
593 } \
594 }
595
596#define OUTPUT(ent) \
597 { \
598 bitno -= n_bits; \
599 accm |= ((ent) << bitno); \
600 do \
601 { \
602 PUTBYTE(accm >> 24); \
603 accm <<= 8; \
604 bitno += 8; \
605 } \
606 while (bitno <= 24); \
607 }
608
609
610
611
612
613
614
615 ent = PPP_PROTOCOL(rptr);
616 if (ent < 0x21 || ent > 0xf9)
617 {
618 return 0;
619 }
620
621 db = (struct bsd_db *) state;
622 hshift = db->hshift;
623 max_ent = db->max_ent;
624 n_bits = db->n_bits;
625 bitno = 32;
626 accm = 0;
627 mxcode = MAXCODE (n_bits);
628
629
630 wptr = obuf;
631 olen = PPP_HDRLEN + BSD_OVHD;
632
633 if (osize > isize)
634 {
635 osize = isize;
636 }
637
638
639 if (wptr)
640 {
641 *wptr++ = PPP_ADDRESS(rptr);
642 *wptr++ = PPP_CONTROL(rptr);
643 *wptr++ = 0;
644 *wptr++ = PPP_COMP;
645 *wptr++ = db->seqno >> 8;
646 *wptr++ = db->seqno;
647 }
648
649
650 rptr += PPP_HDRLEN;
651 isize -= PPP_HDRLEN;
652 ilen = ++isize;
653
654 while (--ilen > 0)
655 {
656 c = *rptr++;
657 fcode = BSD_KEY (ent, c);
658 hval = BSD_HASH (ent, c, hshift);
659 dictp = dict_ptr (db, hval);
660
661
662 if (dictp->codem1 >= max_ent)
663 {
664 goto nomatch;
665 }
666
667 if (dictp->f.fcode == fcode)
668 {
669 ent = dictp->codem1 + 1;
670 continue;
671 }
672
673
674 disp = (hval == 0) ? 1 : hval;
675
676 do
677 {
678 hval += disp;
679 if (hval >= db->hsize)
680 {
681 hval -= db->hsize;
682 }
683 dictp = dict_ptr (db, hval);
684 if (dictp->codem1 >= max_ent)
685 {
686 goto nomatch;
687 }
688 }
689 while (dictp->f.fcode != fcode);
690
691 ent = dictp->codem1 + 1;
692 continue;
693
694nomatch:
695 OUTPUT(ent);
696
697
698 if (max_ent < db->maxmaxcode)
699 {
700 struct bsd_dict *dictp2;
701 struct bsd_dict *dictp3;
702 int indx;
703
704
705 if (max_ent >= mxcode)
706 {
707 db->n_bits = ++n_bits;
708 mxcode = MAXCODE (n_bits);
709 }
710
711
712
713
714
715 dictp2 = dict_ptr (db, max_ent + 1);
716 indx = dictp2->cptr;
717 dictp3 = dict_ptr (db, indx);
718
719 if (dictp3->codem1 == max_ent)
720 {
721 dictp3->codem1 = BADCODEM1;
722 }
723
724 dictp2->cptr = hval;
725 dictp->codem1 = max_ent;
726 dictp->f.fcode = fcode;
727 db->max_ent = ++max_ent;
728
729 if (db->lens)
730 {
731 unsigned short *len1 = lens_ptr (db, max_ent);
732 unsigned short *len2 = lens_ptr (db, ent);
733 *len1 = *len2 + 1;
734 }
735 }
736 ent = c;
737 }
738
739 OUTPUT(ent);
740
741 db->bytes_out += olen - PPP_HDRLEN - BSD_OVHD;
742 db->uncomp_bytes += isize;
743 db->in_count += isize;
744 ++db->uncomp_count;
745 ++db->seqno;
746
747 if (bitno < 32)
748 {
749 ++db->bytes_out;
750 }
751
752
753
754
755
756 if (bsd_check(db))
757 {
758 OUTPUT (CLEAR);
759 }
760
761
762
763
764
765
766 if (bitno != 32)
767 {
768 PUTBYTE((accm | (0xff << (bitno-8))) >> 24);
769 }
770
771
772
773
774
775
776 if (max_ent >= mxcode && max_ent < db->maxmaxcode)
777 {
778 db->n_bits++;
779 }
780
781
782 if (wptr == NULL)
783 {
784 ++db->incomp_count;
785 db->incomp_bytes += isize;
786 olen = 0;
787 }
788 else
789 {
790 ++db->comp_count;
791 db->comp_bytes += olen;
792 }
793
794
795 return olen;
796#undef OUTPUT
797#undef PUTBYTE
798 }
799
800
801
802
803
804
805static void bsd_incomp (void *state, unsigned char *ibuf, int icnt)
806 {
807 (void) bsd_compress (state, ibuf, (char *) 0, icnt, 0);
808 }
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827static int bsd_decompress (void *state, unsigned char *ibuf, int isize,
828 unsigned char *obuf, int osize)
829 {
830 struct bsd_db *db;
831 unsigned int max_ent;
832 unsigned long accm;
833 unsigned int bitno;
834 unsigned int n_bits;
835 unsigned int tgtbitno;
836 struct bsd_dict *dictp;
837 int explen;
838 int seq;
839 unsigned int incode;
840 unsigned int oldcode;
841 unsigned int finchar;
842 unsigned char *p;
843 unsigned char *wptr;
844 int adrs;
845 int ctrl;
846 int ilen;
847 int codelen;
848 int extra;
849
850 db = (struct bsd_db *) state;
851 max_ent = db->max_ent;
852 accm = 0;
853 bitno = 32;
854 n_bits = db->n_bits;
855 tgtbitno = 32 - n_bits;
856
857
858
859
860
861
862 adrs = PPP_ADDRESS (ibuf);
863 ctrl = PPP_CONTROL (ibuf);
864
865 seq = (ibuf[4] << 8) + ibuf[5];
866
867 ibuf += (PPP_HDRLEN + 2);
868 ilen = isize - (PPP_HDRLEN + 2);
869
870
871
872
873
874
875 if (seq != db->seqno)
876 {
877 if (db->debug)
878 {
879 printk("bsd_decomp%d: bad sequence # %d, expected %d\n",
880 db->unit, seq, db->seqno - 1);
881 }
882 return DECOMP_ERROR;
883 }
884
885 ++db->seqno;
886 db->bytes_out += ilen;
887
888
889
890
891
892
893 wptr = obuf;
894 *wptr++ = adrs;
895 *wptr++ = ctrl;
896 *wptr++ = 0;
897
898 oldcode = CLEAR;
899 explen = 3;
900
901
902
903
904
905
906 for (;;)
907 {
908 if (ilen-- <= 0)
909 {
910 db->in_count += (explen - 3);
911 break;
912 }
913
914
915
916
917
918
919
920 bitno -= 8;
921 accm |= *ibuf++ << bitno;
922 if (tgtbitno < bitno)
923 {
924 continue;
925 }
926
927 incode = accm >> tgtbitno;
928 accm <<= n_bits;
929 bitno += n_bits;
930
931
932
933
934
935 if (incode == CLEAR)
936 {
937 if (ilen > 0)
938 {
939 if (db->debug)
940 {
941 printk("bsd_decomp%d: bad CLEAR\n", db->unit);
942 }
943 return DECOMP_FATALERROR;
944 }
945
946 bsd_clear(db);
947 break;
948 }
949
950 if ((incode > max_ent + 2) || (incode > db->maxmaxcode)
951 || (incode > max_ent && oldcode == CLEAR))
952 {
953 if (db->debug)
954 {
955 printk("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
956 db->unit, incode, oldcode);
957 printk("max_ent=0x%x explen=%d seqno=%d\n",
958 max_ent, explen, db->seqno);
959 }
960 return DECOMP_FATALERROR;
961 }
962
963
964 if (incode > max_ent)
965 {
966 finchar = oldcode;
967 extra = 1;
968 }
969 else
970 {
971 finchar = incode;
972 extra = 0;
973 }
974
975 codelen = *(lens_ptr (db, finchar));
976 explen += codelen + extra;
977 if (explen > osize)
978 {
979 if (db->debug)
980 {
981 printk("bsd_decomp%d: ran out of mru\n", db->unit);
982#ifdef DEBUG
983 printk(" len=%d, finchar=0x%x, codelen=%d, explen=%d\n",
984 ilen, finchar, codelen, explen);
985#endif
986 }
987 return DECOMP_FATALERROR;
988 }
989
990
991
992
993
994 wptr += codelen;
995 p = wptr;
996 while (finchar > LAST)
997 {
998 struct bsd_dict *dictp2 = dict_ptr (db, finchar);
999
1000 dictp = dict_ptr (db, dictp2->cptr);
1001#ifdef DEBUG
1002 if (--codelen <= 0 || dictp->codem1 != finchar-1)
1003 {
1004 if (codelen <= 0)
1005 {
1006 printk("bsd_decomp%d: fell off end of chain ", db->unit);
1007 printk("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
1008 incode, finchar, dictp2->cptr, max_ent);
1009 }
1010 else
1011 {
1012 if (dictp->codem1 != finchar-1)
1013 {
1014 printk("bsd_decomp%d: bad code chain 0x%x "
1015 "finchar=0x%x ",
1016 db->unit, incode, finchar);
1017
1018 printk("oldcode=0x%x cptr=0x%x codem1=0x%x\n",
1019 oldcode, dictp2->cptr, dictp->codem1);
1020 }
1021 }
1022 return DECOMP_FATALERROR;
1023 }
1024#endif
1025 *--p = dictp->f.hs.suffix;
1026 finchar = dictp->f.hs.prefix;
1027 }
1028 *--p = finchar;
1029
1030#ifdef DEBUG
1031 if (--codelen != 0)
1032 {
1033 printk("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n",
1034 db->unit, codelen, incode, max_ent);
1035 }
1036#endif
1037
1038 if (extra)
1039 {
1040 *wptr++ = finchar;
1041 }
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051 if (oldcode != CLEAR && max_ent < db->maxmaxcode)
1052 {
1053 struct bsd_dict *dictp2, *dictp3;
1054 unsigned short *lens1, *lens2;
1055 unsigned long fcode;
1056 int hval, disp, indx;
1057
1058 fcode = BSD_KEY(oldcode,finchar);
1059 hval = BSD_HASH(oldcode,finchar,db->hshift);
1060 dictp = dict_ptr (db, hval);
1061
1062
1063 if (dictp->codem1 < max_ent)
1064 {
1065 disp = (hval == 0) ? 1 : hval;
1066 do
1067 {
1068 hval += disp;
1069 if (hval >= db->hsize)
1070 {
1071 hval -= db->hsize;
1072 }
1073 dictp = dict_ptr (db, hval);
1074 }
1075 while (dictp->codem1 < max_ent);
1076 }
1077
1078
1079
1080
1081
1082
1083 dictp2 = dict_ptr (db, max_ent + 1);
1084 indx = dictp2->cptr;
1085 dictp3 = dict_ptr (db, indx);
1086
1087 if (dictp3->codem1 == max_ent)
1088 {
1089 dictp3->codem1 = BADCODEM1;
1090 }
1091
1092 dictp2->cptr = hval;
1093 dictp->codem1 = max_ent;
1094 dictp->f.fcode = fcode;
1095 db->max_ent = ++max_ent;
1096
1097
1098 lens1 = lens_ptr (db, max_ent);
1099 lens2 = lens_ptr (db, oldcode);
1100 *lens1 = *lens2 + 1;
1101
1102
1103 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
1104 {
1105 db->n_bits = ++n_bits;
1106 tgtbitno = 32-n_bits;
1107 }
1108 }
1109 oldcode = incode;
1110 }
1111
1112 ++db->comp_count;
1113 ++db->uncomp_count;
1114 db->comp_bytes += isize - BSD_OVHD - PPP_HDRLEN;
1115 db->uncomp_bytes += explen;
1116
1117 if (bsd_check(db))
1118 {
1119 if (db->debug)
1120 {
1121 printk("bsd_decomp%d: peer should have cleared dictionary on %d\n",
1122 db->unit, db->seqno - 1);
1123 }
1124 }
1125 return explen;
1126 }
1127
1128
1129
1130
1131
1132static struct compressor ppp_bsd_compress = {
1133 .compress_proto = CI_BSD_COMPRESS,
1134 .comp_alloc = bsd_comp_alloc,
1135 .comp_free = bsd_free,
1136 .comp_init = bsd_comp_init,
1137 .comp_reset = bsd_reset,
1138 .compress = bsd_compress,
1139 .comp_stat = bsd_comp_stats,
1140 .decomp_alloc = bsd_decomp_alloc,
1141 .decomp_free = bsd_free,
1142 .decomp_init = bsd_decomp_init,
1143 .decomp_reset = bsd_reset,
1144 .decompress = bsd_decompress,
1145 .incomp = bsd_incomp,
1146 .decomp_stat = bsd_comp_stats,
1147 .owner = THIS_MODULE
1148};
1149
1150
1151
1152
1153
1154static int __init bsdcomp_init(void)
1155{
1156 int answer = ppp_register_compressor(&ppp_bsd_compress);
1157 if (answer == 0)
1158 printk(KERN_INFO "PPP BSD Compression module registered\n");
1159 return answer;
1160}
1161
1162static void __exit bsdcomp_cleanup(void)
1163{
1164 ppp_unregister_compressor(&ppp_bsd_compress);
1165}
1166
1167module_init(bsdcomp_init);
1168module_exit(bsdcomp_cleanup);
1169MODULE_LICENSE("Dual BSD/GPL");
1170MODULE_ALIAS("ppp-compress-" __stringify(CI_BSD_COMPRESS));
1171