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