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