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