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 = (struct bsd_db *) state;
328
329 if (db)
330 {
331
332
333
334 if (db->dict)
335 {
336 vfree (db->dict);
337 db->dict = NULL;
338 }
339
340
341
342 if (db->lens)
343 {
344 vfree (db->lens);
345 db->lens = NULL;
346 }
347
348
349
350 kfree (db);
351 MOD_DEC_USE_COUNT;
352 }
353 }
354
355
356
357
358
359static void *bsd_alloc (unsigned char *options, int opt_len, int decomp)
360 {
361 int bits;
362 unsigned int hsize, hshift, maxmaxcode;
363 struct bsd_db *db;
364
365 if (opt_len != 3 || options[0] != CI_BSD_COMPRESS || options[1] != 3
366 || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
367 {
368 return NULL;
369 }
370
371 bits = BSD_NBITS(options[2]);
372
373 switch (bits)
374 {
375 case 9:
376 case 10:
377 case 11:
378 case 12:
379 hsize = 5003;
380 hshift = 4;
381 break;
382 case 13:
383 hsize = 9001;
384 hshift = 5;
385 break;
386 case 14:
387 hsize = 18013;
388 hshift = 6;
389 break;
390 case 15:
391 hsize = 35023;
392 hshift = 7;
393 break;
394 case 16:
395
396
397
398 default:
399 return NULL;
400 }
401
402
403
404 maxmaxcode = MAXCODE(bits);
405 db = (struct bsd_db *) kmalloc (sizeof (struct bsd_db),
406 GFP_KERNEL);
407 if (!db)
408 {
409 return NULL;
410 }
411
412 memset (db, 0, sizeof(struct bsd_db));
413
414
415
416
417 db->dict = (struct bsd_dict *) vmalloc (hsize *
418 sizeof (struct bsd_dict));
419 if (!db->dict)
420 {
421 bsd_free (db);
422 return NULL;
423 }
424
425 MOD_INC_USE_COUNT;
426
427
428
429 if (!decomp)
430 {
431 db->lens = NULL;
432 }
433
434
435
436 else
437 {
438 db->lens = (unsigned short *) vmalloc ((maxmaxcode + 1) *
439 sizeof (db->lens[0]));
440 if (!db->lens)
441 {
442 bsd_free (db);
443 return (NULL);
444 }
445 }
446
447
448
449 db->totlen = sizeof (struct bsd_db) +
450 (sizeof (struct bsd_dict) * hsize);
451
452 db->hsize = hsize;
453 db->hshift = hshift;
454 db->maxmaxcode = maxmaxcode;
455 db->maxbits = bits;
456
457 return (void *) db;
458 }
459
460static void *bsd_comp_alloc (unsigned char *options, int opt_len)
461 {
462 return bsd_alloc (options, opt_len, 0);
463 }
464
465static void *bsd_decomp_alloc (unsigned char *options, int opt_len)
466 {
467 return bsd_alloc (options, opt_len, 1);
468 }
469
470
471
472
473
474static int bsd_init (void *state, unsigned char *options,
475 int opt_len, int unit, int debug, int decomp)
476 {
477 struct bsd_db *db = state;
478 int indx;
479
480 if ((opt_len != 3) || (options[0] != CI_BSD_COMPRESS) || (options[1] != 3)
481 || (BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
482 || (BSD_NBITS(options[2]) != db->maxbits)
483 || (decomp && db->lens == NULL))
484 {
485 return 0;
486 }
487
488 if (decomp)
489 {
490 indx = LAST;
491 do
492 {
493 db->lens[indx] = 1;
494 }
495 while (indx-- > 0);
496 }
497
498 indx = db->hsize;
499 while (indx-- != 0)
500 {
501 db->dict[indx].codem1 = BADCODEM1;
502 db->dict[indx].cptr = 0;
503 }
504
505 db->unit = unit;
506 db->mru = 0;
507#ifndef DEBUG
508 if (debug)
509#endif
510 db->debug = 1;
511
512 bsd_reset(db);
513
514 return 1;
515 }
516
517static int bsd_comp_init (void *state, unsigned char *options,
518 int opt_len, int unit, int opthdr, int debug)
519 {
520 return bsd_init (state, options, opt_len, unit, debug, 0);
521 }
522
523static int bsd_decomp_init (void *state, unsigned char *options,
524 int opt_len, int unit, int opthdr, int mru,
525 int debug)
526 {
527 return bsd_init (state, options, opt_len, unit, debug, 1);
528 }
529
530
531
532
533
534#define dict_ptrx(p,idx) &(p->dict[idx])
535#define lens_ptrx(p,idx) &(p->lens[idx])
536
537#ifdef DEBUG
538static unsigned short *lens_ptr(struct bsd_db *db, int idx)
539 {
540 if ((unsigned int) idx > (unsigned int) db->maxmaxcode)
541 {
542 printk ("<9>ppp: lens_ptr(%d) > max\n", idx);
543 idx = 0;
544 }
545 return lens_ptrx (db, idx);
546 }
547
548static struct bsd_dict *dict_ptr(struct bsd_db *db, int idx)
549 {
550 if ((unsigned int) idx >= (unsigned int) db->hsize)
551 {
552 printk ("<9>ppp: dict_ptr(%d) > max\n", idx);
553 idx = 0;
554 }
555 return dict_ptrx (db, idx);
556 }
557
558#else
559#define lens_ptr(db,idx) lens_ptrx(db,idx)
560#define dict_ptr(db,idx) dict_ptrx(db,idx)
561#endif
562
563
564
565
566
567
568
569
570
571
572
573
574static int bsd_compress (void *state, unsigned char *rptr, unsigned char *obuf,
575 int isize, int osize)
576 {
577 struct bsd_db *db;
578 int hshift;
579 unsigned int max_ent;
580 unsigned int n_bits;
581 unsigned int bitno;
582 unsigned long accm;
583 int ent;
584 unsigned long fcode;
585 struct bsd_dict *dictp;
586 unsigned char c;
587 int hval;
588 int disp;
589 int ilen;
590 int mxcode;
591 unsigned char *wptr;
592 int olen;
593
594#define PUTBYTE(v) \
595 { \
596 ++olen; \
597 if (wptr) \
598 { \
599 *wptr++ = (unsigned char) (v); \
600 if (olen >= osize) \
601 { \
602 wptr = NULL; \
603 } \
604 } \
605 }
606
607#define OUTPUT(ent) \
608 { \
609 bitno -= n_bits; \
610 accm |= ((ent) << bitno); \
611 do \
612 { \
613 PUTBYTE(accm >> 24); \
614 accm <<= 8; \
615 bitno += 8; \
616 } \
617 while (bitno <= 24); \
618 }
619
620
621
622
623
624
625
626 ent = PPP_PROTOCOL(rptr);
627 if (ent < 0x21 || ent > 0xf9)
628 {
629 return 0;
630 }
631
632 db = (struct bsd_db *) state;
633 hshift = db->hshift;
634 max_ent = db->max_ent;
635 n_bits = db->n_bits;
636 bitno = 32;
637 accm = 0;
638 mxcode = MAXCODE (n_bits);
639
640
641 wptr = obuf;
642 olen = PPP_HDRLEN + BSD_OVHD;
643
644 if (osize > isize)
645 {
646 osize = isize;
647 }
648
649
650 if (wptr)
651 {
652 *wptr++ = PPP_ADDRESS(rptr);
653 *wptr++ = PPP_CONTROL(rptr);
654 *wptr++ = 0;
655 *wptr++ = PPP_COMP;
656 *wptr++ = db->seqno >> 8;
657 *wptr++ = db->seqno;
658 }
659
660
661 rptr += PPP_HDRLEN;
662 isize -= PPP_HDRLEN;
663 ilen = ++isize;
664
665 while (--ilen > 0)
666 {
667 c = *rptr++;
668 fcode = BSD_KEY (ent, c);
669 hval = BSD_HASH (ent, c, hshift);
670 dictp = dict_ptr (db, hval);
671
672
673 if (dictp->codem1 >= max_ent)
674 {
675 goto nomatch;
676 }
677
678 if (dictp->f.fcode == fcode)
679 {
680 ent = dictp->codem1 + 1;
681 continue;
682 }
683
684
685 disp = (hval == 0) ? 1 : hval;
686
687 do
688 {
689 hval += disp;
690 if (hval >= db->hsize)
691 {
692 hval -= db->hsize;
693 }
694 dictp = dict_ptr (db, hval);
695 if (dictp->codem1 >= max_ent)
696 {
697 goto nomatch;
698 }
699 }
700 while (dictp->f.fcode != fcode);
701
702 ent = dictp->codem1 + 1;
703 continue;
704
705nomatch:
706 OUTPUT(ent);
707
708
709 if (max_ent < db->maxmaxcode)
710 {
711 struct bsd_dict *dictp2;
712 struct bsd_dict *dictp3;
713 int indx;
714
715
716 if (max_ent >= mxcode)
717 {
718 db->n_bits = ++n_bits;
719 mxcode = MAXCODE (n_bits);
720 }
721
722
723
724
725
726 dictp2 = dict_ptr (db, max_ent + 1);
727 indx = dictp2->cptr;
728 dictp3 = dict_ptr (db, indx);
729
730 if (dictp3->codem1 == max_ent)
731 {
732 dictp3->codem1 = BADCODEM1;
733 }
734
735 dictp2->cptr = hval;
736 dictp->codem1 = max_ent;
737 dictp->f.fcode = fcode;
738 db->max_ent = ++max_ent;
739
740 if (db->lens)
741 {
742 unsigned short *len1 = lens_ptr (db, max_ent);
743 unsigned short *len2 = lens_ptr (db, ent);
744 *len1 = *len2 + 1;
745 }
746 }
747 ent = c;
748 }
749
750 OUTPUT(ent);
751
752 db->bytes_out += olen - PPP_HDRLEN - BSD_OVHD;
753 db->uncomp_bytes += isize;
754 db->in_count += isize;
755 ++db->uncomp_count;
756 ++db->seqno;
757
758 if (bitno < 32)
759 {
760 ++db->bytes_out;
761 }
762
763
764
765
766
767 if (bsd_check(db))
768 {
769 OUTPUT (CLEAR);
770 }
771
772
773
774
775
776
777 if (bitno != 32)
778 {
779 PUTBYTE((accm | (0xff << (bitno-8))) >> 24);
780 }
781
782
783
784
785
786
787 if (max_ent >= mxcode && max_ent < db->maxmaxcode)
788 {
789 db->n_bits++;
790 }
791
792
793 if (wptr == NULL)
794 {
795 ++db->incomp_count;
796 db->incomp_bytes += isize;
797 olen = 0;
798 }
799 else
800 {
801 ++db->comp_count;
802 db->comp_bytes += olen;
803 }
804
805
806 return olen;
807#undef OUTPUT
808#undef PUTBYTE
809 }
810
811
812
813
814
815
816static void bsd_incomp (void *state, unsigned char *ibuf, int icnt)
817 {
818 (void) bsd_compress (state, ibuf, (char *) 0, icnt, 0);
819 }
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838static int bsd_decompress (void *state, unsigned char *ibuf, int isize,
839 unsigned char *obuf, int osize)
840 {
841 struct bsd_db *db;
842 unsigned int max_ent;
843 unsigned long accm;
844 unsigned int bitno;
845 unsigned int n_bits;
846 unsigned int tgtbitno;
847 struct bsd_dict *dictp;
848 int explen;
849 int seq;
850 unsigned int incode;
851 unsigned int oldcode;
852 unsigned int finchar;
853 unsigned char *p;
854 unsigned char *wptr;
855 int adrs;
856 int ctrl;
857 int ilen;
858 int codelen;
859 int extra;
860
861 db = (struct bsd_db *) state;
862 max_ent = db->max_ent;
863 accm = 0;
864 bitno = 32;
865 n_bits = db->n_bits;
866 tgtbitno = 32 - n_bits;
867
868
869
870
871
872
873 adrs = PPP_ADDRESS (ibuf);
874 ctrl = PPP_CONTROL (ibuf);
875
876 seq = (ibuf[4] << 8) + ibuf[5];
877
878 ibuf += (PPP_HDRLEN + 2);
879 ilen = isize - (PPP_HDRLEN + 2);
880
881
882
883
884
885
886 if (seq != db->seqno)
887 {
888 if (db->debug)
889 {
890 printk("bsd_decomp%d: bad sequence # %d, expected %d\n",
891 db->unit, seq, db->seqno - 1);
892 }
893 return DECOMP_ERROR;
894 }
895
896 ++db->seqno;
897 db->bytes_out += ilen;
898
899
900
901
902
903
904 wptr = obuf;
905 *wptr++ = adrs;
906 *wptr++ = ctrl;
907 *wptr++ = 0;
908
909 oldcode = CLEAR;
910 explen = 3;
911
912
913
914
915
916
917 for (;;)
918 {
919 if (ilen-- <= 0)
920 {
921 db->in_count += (explen - 3);
922 break;
923 }
924
925
926
927
928
929
930
931 bitno -= 8;
932 accm |= *ibuf++ << bitno;
933 if (tgtbitno < bitno)
934 {
935 continue;
936 }
937
938 incode = accm >> tgtbitno;
939 accm <<= n_bits;
940 bitno += n_bits;
941
942
943
944
945
946 if (incode == CLEAR)
947 {
948 if (ilen > 0)
949 {
950 if (db->debug)
951 {
952 printk("bsd_decomp%d: bad CLEAR\n", db->unit);
953 }
954 return DECOMP_FATALERROR;
955 }
956
957 bsd_clear(db);
958 break;
959 }
960
961 if ((incode > max_ent + 2) || (incode > db->maxmaxcode)
962 || (incode > max_ent && oldcode == CLEAR))
963 {
964 if (db->debug)
965 {
966 printk("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
967 db->unit, incode, oldcode);
968 printk("max_ent=0x%x explen=%d seqno=%d\n",
969 max_ent, explen, db->seqno);
970 }
971 return DECOMP_FATALERROR;
972 }
973
974
975 if (incode > max_ent)
976 {
977 finchar = oldcode;
978 extra = 1;
979 }
980 else
981 {
982 finchar = incode;
983 extra = 0;
984 }
985
986 codelen = *(lens_ptr (db, finchar));
987 explen += codelen + extra;
988 if (explen > osize)
989 {
990 if (db->debug)
991 {
992 printk("bsd_decomp%d: ran out of mru\n", db->unit);
993#ifdef DEBUG
994 printk(" len=%d, finchar=0x%x, codelen=%d, explen=%d\n",
995 ilen, finchar, codelen, explen);
996#endif
997 }
998 return DECOMP_FATALERROR;
999 }
1000
1001
1002
1003
1004
1005 wptr += codelen;
1006 p = wptr;
1007 while (finchar > LAST)
1008 {
1009 struct bsd_dict *dictp2 = dict_ptr (db, finchar);
1010
1011 dictp = dict_ptr (db, dictp2->cptr);
1012#ifdef DEBUG
1013 if (--codelen <= 0 || dictp->codem1 != finchar-1)
1014 {
1015 if (codelen <= 0)
1016 {
1017 printk("bsd_decomp%d: fell off end of chain ", db->unit);
1018 printk("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
1019 incode, finchar, dictp2->cptr, max_ent);
1020 }
1021 else
1022 {
1023 if (dictp->codem1 != finchar-1)
1024 {
1025 printk("bsd_decomp%d: bad code chain 0x%x "
1026 "finchar=0x%x ",
1027 db->unit, incode, finchar);
1028
1029 printk("oldcode=0x%x cptr=0x%x codem1=0x%x\n",
1030 oldcode, dictp2->cptr, dictp->codem1);
1031 }
1032 }
1033 return DECOMP_FATALERROR;
1034 }
1035#endif
1036 *--p = dictp->f.hs.suffix;
1037 finchar = dictp->f.hs.prefix;
1038 }
1039 *--p = finchar;
1040
1041#ifdef DEBUG
1042 if (--codelen != 0)
1043 {
1044 printk("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n",
1045 db->unit, codelen, incode, max_ent);
1046 }
1047#endif
1048
1049 if (extra)
1050 {
1051 *wptr++ = finchar;
1052 }
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062 if (oldcode != CLEAR && max_ent < db->maxmaxcode)
1063 {
1064 struct bsd_dict *dictp2, *dictp3;
1065 unsigned short *lens1, *lens2;
1066 unsigned long fcode;
1067 int hval, disp, indx;
1068
1069 fcode = BSD_KEY(oldcode,finchar);
1070 hval = BSD_HASH(oldcode,finchar,db->hshift);
1071 dictp = dict_ptr (db, hval);
1072
1073
1074 if (dictp->codem1 < max_ent)
1075 {
1076 disp = (hval == 0) ? 1 : hval;
1077 do
1078 {
1079 hval += disp;
1080 if (hval >= db->hsize)
1081 {
1082 hval -= db->hsize;
1083 }
1084 dictp = dict_ptr (db, hval);
1085 }
1086 while (dictp->codem1 < max_ent);
1087 }
1088
1089
1090
1091
1092
1093
1094 dictp2 = dict_ptr (db, max_ent + 1);
1095 indx = dictp2->cptr;
1096 dictp3 = dict_ptr (db, indx);
1097
1098 if (dictp3->codem1 == max_ent)
1099 {
1100 dictp3->codem1 = BADCODEM1;
1101 }
1102
1103 dictp2->cptr = hval;
1104 dictp->codem1 = max_ent;
1105 dictp->f.fcode = fcode;
1106 db->max_ent = ++max_ent;
1107
1108
1109 lens1 = lens_ptr (db, max_ent);
1110 lens2 = lens_ptr (db, oldcode);
1111 *lens1 = *lens2 + 1;
1112
1113
1114 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
1115 {
1116 db->n_bits = ++n_bits;
1117 tgtbitno = 32-n_bits;
1118 }
1119 }
1120 oldcode = incode;
1121 }
1122
1123 ++db->comp_count;
1124 ++db->uncomp_count;
1125 db->comp_bytes += isize - BSD_OVHD - PPP_HDRLEN;
1126 db->uncomp_bytes += explen;
1127
1128 if (bsd_check(db))
1129 {
1130 if (db->debug)
1131 {
1132 printk("bsd_decomp%d: peer should have cleared dictionary on %d\n",
1133 db->unit, db->seqno - 1);
1134 }
1135 }
1136 return explen;
1137 }
1138
1139
1140
1141
1142
1143static struct compressor ppp_bsd_compress = {
1144 CI_BSD_COMPRESS,
1145 bsd_comp_alloc,
1146 bsd_free,
1147 bsd_comp_init,
1148 bsd_reset,
1149 bsd_compress,
1150 bsd_comp_stats,
1151 bsd_decomp_alloc,
1152 bsd_free,
1153 bsd_decomp_init,
1154 bsd_reset,
1155 bsd_decompress,
1156 bsd_incomp,
1157 bsd_comp_stats
1158};
1159
1160
1161
1162
1163
1164int __init bsdcomp_init(void)
1165{
1166 int answer = ppp_register_compressor(&ppp_bsd_compress);
1167 if (answer == 0)
1168 printk(KERN_INFO "PPP BSD Compression module registered\n");
1169 return answer;
1170}
1171
1172void __exit bsdcomp_cleanup(void)
1173{
1174 ppp_unregister_compressor(&ppp_bsd_compress);
1175}
1176
1177module_init(bsdcomp_init);
1178module_exit(bsdcomp_cleanup);
1179MODULE_LICENSE("Dual BSD/GPL");
1180