2 * ccp.c - PPP Compression Control Protocol.
4 * Copyright (c) 1994 The Australian National University.
7 * Permission to use, copy, modify, and distribute this software and its
8 * documentation is hereby granted, provided that the above copyright
9 * notice appears in all copies. This software is provided without any
10 * warranty, express or implied. The Australian National University
11 * makes no representations about the suitability of this software for
14 * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
15 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
17 * THE AUSTRALIAN NATIONAL UNIVERSITY HAVE BEEN ADVISED OF THE POSSIBILITY
20 * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
24 * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27 * $FreeBSD: src/usr.sbin/pppd/ccp.c,v 1.10 1999/08/28 01:19:00 peter Exp $
28 * $DragonFly: src/usr.sbin/pppd/ccp.c,v 1.5 2005/11/24 23:42:54 swildner Exp $
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
39 #include <net/ppp_layer/ppp_comp.h>
42 * Protocol entry points from main code.
44 static void ccp_init(int unit);
45 static void ccp_open(int unit);
46 static void ccp_close(int unit, char *);
47 static void ccp_lowerup(int unit);
48 static void ccp_lowerdown(int);
49 static void ccp_input(int unit, u_char *pkt, int len);
50 static void ccp_protrej(int unit);
51 static int ccp_printpkt(u_char *pkt, int len,
52 void (*printer)(void *, char *, ...),
54 static void ccp_datainput(int unit, u_char *pkt, int len);
56 struct protent ccp_protent = {
75 ccp_options ccp_wantoptions[NUM_PPP]; /* what to request the peer to use */
76 ccp_options ccp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
77 ccp_options ccp_allowoptions[NUM_PPP]; /* what we'll agree to do */
78 ccp_options ccp_hisoptions[NUM_PPP]; /* what we agreed to do */
81 * Callbacks for fsm code.
83 static void ccp_resetci(fsm *);
84 static int ccp_cilen(fsm *);
85 static void ccp_addci(fsm *, u_char *, int *);
86 static int ccp_ackci(fsm *, u_char *, int);
87 static int ccp_nakci(fsm *, u_char *, int);
88 static int ccp_rejci(fsm *, u_char *, int);
89 static int ccp_reqci(fsm *, u_char *, int *, int);
90 static void ccp_up(fsm *);
91 static void ccp_down(fsm *);
92 static int ccp_extcode(fsm *, int, int, u_char *, int);
93 static void ccp_rack_timeout(void *);
94 static char *method_name(ccp_options *, ccp_options *);
96 static fsm_callbacks ccp_callbacks = {
115 * Do we want / did we get any compression?
117 #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
118 || (opt).predictor_1 || (opt).predictor_2)
121 * Local state (mainly for handling reset-reqs and reset-acks).
123 static int ccp_localstate[NUM_PPP];
124 #define RACK_PENDING 1 /* waiting for reset-ack */
125 #define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
127 #define RACKTIMEOUT 1 /* second */
129 static int all_rejected[NUM_PPP]; /* we rejected all peer's options */
132 * ccp_init - initialize CCP.
137 fsm *f = &ccp_fsm[unit];
140 f->protocol = PPP_CCP;
141 f->callbacks = &ccp_callbacks;
144 memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
145 memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
146 memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
147 memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
149 ccp_wantoptions[0].deflate = 1;
150 ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
151 ccp_wantoptions[0].deflate_correct = 1;
152 ccp_wantoptions[0].deflate_draft = 1;
153 ccp_allowoptions[0].deflate = 1;
154 ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
155 ccp_allowoptions[0].deflate_correct = 1;
156 ccp_allowoptions[0].deflate_draft = 1;
158 ccp_wantoptions[0].bsd_compress = 1;
159 ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
160 ccp_allowoptions[0].bsd_compress = 1;
161 ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
163 ccp_allowoptions[0].predictor_1 = 1;
167 * ccp_open - CCP is allowed to come up.
172 fsm *f = &ccp_fsm[unit];
174 if (f->state != OPENED)
175 ccp_flags_set(unit, 1, 0);
178 * Find out which compressors the kernel supports before
179 * deciding whether to open in silent mode.
182 if (!ANY_COMPRESS(ccp_gotoptions[unit]))
183 f->flags |= OPT_SILENT;
189 * ccp_close - Terminate CCP.
192 ccp_close(int unit, char *reason)
194 ccp_flags_set(unit, 0, 0);
195 fsm_close(&ccp_fsm[unit], reason);
199 * ccp_lowerup - we may now transmit CCP packets.
202 ccp_lowerup(int unit)
204 fsm_lowerup(&ccp_fsm[unit]);
208 * ccp_lowerdown - we may not transmit CCP packets.
211 ccp_lowerdown(int unit)
213 fsm_lowerdown(&ccp_fsm[unit]);
217 * ccp_input - process a received CCP packet.
220 ccp_input(int unit, u_char *p, int len)
222 fsm *f = &ccp_fsm[unit];
226 * Check for a terminate-request so we can print a message.
229 fsm_input(f, p, len);
230 if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED)
231 syslog(LOG_NOTICE, "Compression disabled by peer.");
234 * If we get a terminate-ack and we're not asking for compression,
237 if (oldstate == REQSENT && p[0] == TERMACK
238 && !ANY_COMPRESS(ccp_gotoptions[unit]))
239 ccp_close(unit, "No compression negotiated");
243 * Handle a CCP-specific code.
246 ccp_extcode(fsm *f, int code, int id, u_char *p, int len)
250 if (f->state != OPENED)
252 /* send a reset-ack, which the transmitter will see and
253 reset its compression state. */
254 fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
258 if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
259 ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
260 UNTIMEOUT(ccp_rack_timeout, f);
272 * ccp_protrej - peer doesn't talk CCP.
275 ccp_protrej(int unit)
277 ccp_flags_set(unit, 0, 0);
278 fsm_lowerdown(&ccp_fsm[unit]);
282 * ccp_resetci - initialize at start of negotiation.
287 ccp_options *go = &ccp_gotoptions[f->unit];
290 *go = ccp_wantoptions[f->unit];
291 all_rejected[f->unit] = 0;
294 * Check whether the kernel knows about the various
295 * compression methods we might request.
297 if (go->bsd_compress) {
298 opt_buf[0] = CI_BSD_COMPRESS;
299 opt_buf[1] = CILEN_BSD_COMPRESS;
300 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
301 if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
302 go->bsd_compress = 0;
305 if (go->deflate_correct) {
306 opt_buf[0] = CI_DEFLATE;
307 opt_buf[1] = CILEN_DEFLATE;
308 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
309 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
310 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
311 go->deflate_correct = 0;
313 if (go->deflate_draft) {
314 opt_buf[0] = CI_DEFLATE_DRAFT;
315 opt_buf[1] = CILEN_DEFLATE;
316 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
317 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
318 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
319 go->deflate_draft = 0;
321 if (!go->deflate_correct && !go->deflate_draft)
324 if (go->predictor_1) {
325 opt_buf[0] = CI_PREDICTOR_1;
326 opt_buf[1] = CILEN_PREDICTOR_1;
327 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
330 if (go->predictor_2) {
331 opt_buf[0] = CI_PREDICTOR_2;
332 opt_buf[1] = CILEN_PREDICTOR_2;
333 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
339 * ccp_cilen - Return total length of our configuration info.
344 ccp_options *go = &ccp_gotoptions[f->unit];
346 return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
347 + (go->deflate? CILEN_DEFLATE: 0)
348 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
349 + (go->predictor_2? CILEN_PREDICTOR_2: 0);
353 * ccp_addci - put our requests in a packet.
356 ccp_addci(fsm *f, u_char *p, int *lenp)
359 ccp_options *go = &ccp_gotoptions[f->unit];
363 * Add the compression types that we can receive, in decreasing
364 * preference order. Get the kernel to allocate the first one
365 * in case it gets Acked.
368 p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
369 p[1] = CILEN_DEFLATE;
370 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
371 p[3] = DEFLATE_CHK_SEQUENCE;
373 res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
378 if (res < 0 || go->deflate_size <= DEFLATE_MIN_SIZE) {
383 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
385 if (p != p0 && go->deflate_correct && go->deflate_draft) {
386 p[0] = CI_DEFLATE_DRAFT;
387 p[1] = CILEN_DEFLATE;
388 p[2] = p[2 - CILEN_DEFLATE];
389 p[3] = DEFLATE_CHK_SEQUENCE;
393 if (go->bsd_compress) {
394 p[0] = CI_BSD_COMPRESS;
395 p[1] = CILEN_BSD_COMPRESS;
396 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
398 p += CILEN_BSD_COMPRESS; /* not the first option */
401 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
403 p += CILEN_BSD_COMPRESS;
406 if (res < 0 || go->bsd_bits <= BSD_MIN_BITS) {
407 go->bsd_compress = 0;
411 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
415 /* XXX Should Predictor 2 be preferable to Predictor 1? */
416 if (go->predictor_1) {
417 p[0] = CI_PREDICTOR_1;
418 p[1] = CILEN_PREDICTOR_1;
419 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
422 p += CILEN_PREDICTOR_1;
425 if (go->predictor_2) {
426 p[0] = CI_PREDICTOR_2;
427 p[1] = CILEN_PREDICTOR_2;
428 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
431 p += CILEN_PREDICTOR_2;
435 go->method = (p > p0)? p0[0]: -1;
441 * ccp_ackci - process a received configure-ack, and return
442 * 1 iff the packet was OK.
445 ccp_ackci(fsm *f, u_char *p, int len)
447 ccp_options *go = &ccp_gotoptions[f->unit];
451 if (len < CILEN_DEFLATE
452 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
453 || p[1] != CILEN_DEFLATE
454 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
455 || p[3] != DEFLATE_CHK_SEQUENCE)
458 len -= CILEN_DEFLATE;
459 /* XXX Cope with first/fast ack */
462 if (go->deflate_correct && go->deflate_draft) {
463 if (len < CILEN_DEFLATE
464 || p[0] != CI_DEFLATE_DRAFT
465 || p[1] != CILEN_DEFLATE
466 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
467 || p[3] != DEFLATE_CHK_SEQUENCE)
470 len -= CILEN_DEFLATE;
473 if (go->bsd_compress) {
474 if (len < CILEN_BSD_COMPRESS
475 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
476 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
478 p += CILEN_BSD_COMPRESS;
479 len -= CILEN_BSD_COMPRESS;
480 /* XXX Cope with first/fast ack */
481 if (p == p0 && len == 0)
484 if (go->predictor_1) {
485 if (len < CILEN_PREDICTOR_1
486 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
488 p += CILEN_PREDICTOR_1;
489 len -= CILEN_PREDICTOR_1;
490 /* XXX Cope with first/fast ack */
491 if (p == p0 && len == 0)
494 if (go->predictor_2) {
495 if (len < CILEN_PREDICTOR_2
496 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
498 p += CILEN_PREDICTOR_2;
499 len -= CILEN_PREDICTOR_2;
500 /* XXX Cope with first/fast ack */
501 if (p == p0 && len == 0)
511 * ccp_nakci - process received configure-nak.
512 * Returns 1 iff the nak was OK.
515 ccp_nakci(fsm *f, u_char *p, int len)
517 ccp_options *go = &ccp_gotoptions[f->unit];
518 ccp_options no; /* options we've seen already */
519 ccp_options try; /* options to ask for next time */
521 memset(&no, 0, sizeof(no));
524 if (go->deflate && len >= CILEN_DEFLATE
525 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
526 && p[1] == CILEN_DEFLATE) {
529 * Peer wants us to use a different code size or something.
530 * Stop asking for Deflate if we don't understand his suggestion.
532 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
533 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_SIZE
534 || p[3] != DEFLATE_CHK_SEQUENCE)
536 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
537 try.deflate_size = DEFLATE_SIZE(p[2]);
539 len -= CILEN_DEFLATE;
540 if (go->deflate_correct && go->deflate_draft
541 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
542 && p[1] == CILEN_DEFLATE) {
544 len -= CILEN_DEFLATE;
548 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
549 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
552 * Peer wants us to use a different number of bits
553 * or a different version.
555 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
556 try.bsd_compress = 0;
557 else if (BSD_NBITS(p[2]) < go->bsd_bits)
558 try.bsd_bits = BSD_NBITS(p[2]);
559 p += CILEN_BSD_COMPRESS;
560 len -= CILEN_BSD_COMPRESS;
564 * Predictor-1 and 2 have no options, so they can't be Naked.
566 * XXX What should we do with any remaining options?
572 if (f->state != OPENED)
578 * ccp_rejci - reject some of our suggested compression methods.
581 ccp_rejci(fsm *f, u_char *p, int len)
583 ccp_options *go = &ccp_gotoptions[f->unit];
584 ccp_options try; /* options to request next time */
589 * Cope with empty configure-rejects by ceasing to send
590 * configure-requests.
592 if (len == 0 && all_rejected[f->unit])
595 if (go->deflate && len >= CILEN_DEFLATE
596 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
597 && p[1] == CILEN_DEFLATE) {
598 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
599 || p[3] != DEFLATE_CHK_SEQUENCE)
600 return 0; /* Rej is bad */
601 if (go->deflate_correct)
602 try.deflate_correct = 0;
604 try.deflate_draft = 0;
606 len -= CILEN_DEFLATE;
607 if (go->deflate_correct && go->deflate_draft
608 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
609 && p[1] == CILEN_DEFLATE) {
610 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
611 || p[3] != DEFLATE_CHK_SEQUENCE)
612 return 0; /* Rej is bad */
613 try.deflate_draft = 0;
615 len -= CILEN_DEFLATE;
617 if (!try.deflate_correct && !try.deflate_draft)
620 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
621 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
622 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
624 try.bsd_compress = 0;
625 p += CILEN_BSD_COMPRESS;
626 len -= CILEN_BSD_COMPRESS;
628 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
629 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
631 p += CILEN_PREDICTOR_1;
632 len -= CILEN_PREDICTOR_1;
634 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
635 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
637 p += CILEN_PREDICTOR_2;
638 len -= CILEN_PREDICTOR_2;
644 if (f->state != OPENED)
651 * ccp_reqci - processed a received configure-request.
652 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
656 ccp_reqci(fsm *f, u_char *p, int *lenp, int dont_nak)
658 int ret, newret, res;
660 int len, clen, type, nb;
661 ccp_options *ho = &ccp_hisoptions[f->unit];
662 ccp_options *ao = &ccp_allowoptions[f->unit];
668 memset(ho, 0, sizeof(ccp_options));
669 ho->method = (len > 0)? p[0]: -1;
673 if (len < 2 || p[1] < 2 || p[1] > len) {
684 case CI_DEFLATE_DRAFT:
685 if (!ao->deflate || clen != CILEN_DEFLATE
686 || (!ao->deflate_correct && type == CI_DEFLATE)
687 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
693 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
694 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
695 || p[3] != DEFLATE_CHK_SEQUENCE
696 || nb > ao->deflate_size || nb < DEFLATE_MIN_SIZE) {
699 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
700 p[3] = DEFLATE_CHK_SEQUENCE;
701 /* fall through to test this #bits below */
707 * Check whether we can do Deflate with the window
708 * size they want. If the window is too big, reduce
709 * it until the kernel can cope and nak with that.
710 * We only check this for the first option.
714 res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
716 break; /* it's OK now */
717 if (res < 0 || nb == DEFLATE_MIN_SIZE || dont_nak) {
719 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
724 p[2] = DEFLATE_MAKE_OPT(nb);
729 case CI_BSD_COMPRESS:
730 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
735 ho->bsd_compress = 1;
736 ho->bsd_bits = nb = BSD_NBITS(p[2]);
737 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
738 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
741 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
742 /* fall through to test this #bits below */
748 * Check whether we can do BSD-Compress with the code
749 * size they want. If the code size is too big, reduce
750 * it until the kernel can cope and nak with that.
751 * We only check this for the first option.
755 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
758 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
760 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
766 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
772 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
779 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
785 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
792 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
802 if (newret == CONFNAK && dont_nak)
804 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
805 /* we're returning this option */
806 if (newret == CONFREJ && ret == CONFNAK)
810 BCOPY(p, retp, clen);
818 if (ret != CONFACK) {
819 if (ret == CONFREJ && *lenp == retp - p0)
820 all_rejected[f->unit] = 1;
828 * Make a string name for a compression method (or 2).
831 method_name(ccp_options *opt, ccp_options *opt2)
833 static char result[64];
835 if (!ANY_COMPRESS(*opt))
837 switch (opt->method) {
839 case CI_DEFLATE_DRAFT:
840 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
841 sprintf(result, "Deflate%s (%d/%d)",
842 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
843 opt->deflate_size, opt2->deflate_size);
845 sprintf(result, "Deflate%s (%d)",
846 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
849 case CI_BSD_COMPRESS:
850 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
851 sprintf(result, "BSD-Compress (%d/%d)", opt->bsd_bits,
854 sprintf(result, "BSD-Compress (%d)", opt->bsd_bits);
857 return "Predictor 1";
859 return "Predictor 2";
861 sprintf(result, "Method %d", opt->method);
867 * CCP has come up - inform the kernel driver and log a message.
872 ccp_options *go = &ccp_gotoptions[f->unit];
873 ccp_options *ho = &ccp_hisoptions[f->unit];
876 ccp_flags_set(f->unit, 1, 1);
877 if (ANY_COMPRESS(*go)) {
878 if (ANY_COMPRESS(*ho)) {
879 if (go->method == ho->method) {
880 syslog(LOG_NOTICE, "%s compression enabled",
881 method_name(go, ho));
883 strcpy(method1, method_name(go, NULL));
884 syslog(LOG_NOTICE, "%s / %s compression enabled",
885 method1, method_name(ho, NULL));
888 syslog(LOG_NOTICE, "%s receive compression enabled",
889 method_name(go, NULL));
890 } else if (ANY_COMPRESS(*ho))
891 syslog(LOG_NOTICE, "%s transmit compression enabled",
892 method_name(ho, NULL));
896 * CCP has gone down - inform the kernel driver.
901 if (ccp_localstate[f->unit] & RACK_PENDING)
902 UNTIMEOUT(ccp_rack_timeout, f);
903 ccp_localstate[f->unit] = 0;
904 ccp_flags_set(f->unit, 1, 0);
908 * Print the contents of a CCP packet.
910 static char *ccp_codenames[] = {
911 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
912 "TermReq", "TermAck", "CodeRej",
913 NULL, NULL, NULL, NULL, NULL, NULL,
914 "ResetReq", "ResetAck",
918 ccp_printpkt(u_char *p, int plen, void (*printer)(void *, char *, ...),
926 if (plen < HEADERLEN)
930 len = (p[2] << 8) + p[3];
931 if (len < HEADERLEN || len > plen)
934 if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
935 && ccp_codenames[code-1] != NULL)
936 printer(arg, " %s", ccp_codenames[code-1]);
938 printer(arg, " code=0x%x", code);
939 printer(arg, " id=0x%x", id);
948 /* print list of possible compression methods */
952 if (optlen < 2 || optlen > len)
959 case CI_DEFLATE_DRAFT:
960 if (optlen >= CILEN_DEFLATE) {
961 printer(arg, "deflate%s %d",
962 (code == CI_DEFLATE_DRAFT? "(old#)": ""),
964 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
965 printer(arg, " method %d", DEFLATE_METHOD(p[2]));
966 if (p[3] != DEFLATE_CHK_SEQUENCE)
967 printer(arg, " check %d", p[3]);
971 case CI_BSD_COMPRESS:
972 if (optlen >= CILEN_BSD_COMPRESS) {
973 printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
975 p += CILEN_BSD_COMPRESS;
979 if (optlen >= CILEN_PREDICTOR_1) {
980 printer(arg, "predictor 1");
981 p += CILEN_PREDICTOR_1;
985 if (optlen >= CILEN_PREDICTOR_2) {
986 printer(arg, "predictor 2");
987 p += CILEN_PREDICTOR_2;
992 printer(arg, " %.2x", *p++);
999 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1000 print_string(p, len, printer, arg);
1007 /* dump out the rest of the packet in hex */
1009 printer(arg, " %.2x", *p++);
1015 * We have received a packet that the decompressor failed to
1016 * decompress. Here we would expect to issue a reset-request, but
1017 * Motorola has a patent on resetting the compressor as a result of
1018 * detecting an error in the decompressed data after decompression.
1019 * (See US patent 5,130,993; international patent publication number
1020 * WO 91/10289; Australian patent 73296/91.)
1022 * So we ask the kernel whether the error was detected after
1023 * decompression; if it was, we take CCP down, thus disabling
1024 * compression :-(, otherwise we issue the reset-request.
1027 ccp_datainput(int unit, u_char *pkt, int len)
1032 if (f->state == OPENED) {
1033 if (ccp_fatal_error(unit)) {
1035 * Disable compression by taking CCP down.
1037 syslog(LOG_ERR, "Lost compression sync: disabling compression");
1038 ccp_close(unit, "Lost compression sync");
1041 * Send a reset-request to reset the peer's compressor.
1042 * We don't do that if we are still waiting for an
1043 * acknowledgement to a previous reset-request.
1045 if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
1046 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1047 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1048 ccp_localstate[f->unit] |= RACK_PENDING;
1050 ccp_localstate[f->unit] |= RREQ_REPEAT;
1056 * Timeout waiting for reset-ack.
1059 ccp_rack_timeout(void *arg)
1063 if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
1064 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1065 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1066 ccp_localstate[f->unit] &= ~RREQ_REPEAT;
1068 ccp_localstate[f->unit] &= ~RACK_PENDING;