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.4 2003/11/03 19:31:40 eirikn 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.
138 fsm *f = &ccp_fsm[unit];
141 f->protocol = PPP_CCP;
142 f->callbacks = &ccp_callbacks;
145 memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
146 memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
147 memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
148 memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
150 ccp_wantoptions[0].deflate = 1;
151 ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
152 ccp_wantoptions[0].deflate_correct = 1;
153 ccp_wantoptions[0].deflate_draft = 1;
154 ccp_allowoptions[0].deflate = 1;
155 ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
156 ccp_allowoptions[0].deflate_correct = 1;
157 ccp_allowoptions[0].deflate_draft = 1;
159 ccp_wantoptions[0].bsd_compress = 1;
160 ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
161 ccp_allowoptions[0].bsd_compress = 1;
162 ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
164 ccp_allowoptions[0].predictor_1 = 1;
168 * ccp_open - CCP is allowed to come up.
174 fsm *f = &ccp_fsm[unit];
176 if (f->state != OPENED)
177 ccp_flags_set(unit, 1, 0);
180 * Find out which compressors the kernel supports before
181 * deciding whether to open in silent mode.
184 if (!ANY_COMPRESS(ccp_gotoptions[unit]))
185 f->flags |= OPT_SILENT;
191 * ccp_close - Terminate CCP.
194 ccp_close(unit, reason)
198 ccp_flags_set(unit, 0, 0);
199 fsm_close(&ccp_fsm[unit], reason);
203 * ccp_lowerup - we may now transmit CCP packets.
209 fsm_lowerup(&ccp_fsm[unit]);
213 * ccp_lowerdown - we may not transmit CCP packets.
219 fsm_lowerdown(&ccp_fsm[unit]);
223 * ccp_input - process a received CCP packet.
226 ccp_input(unit, p, len)
231 fsm *f = &ccp_fsm[unit];
235 * Check for a terminate-request so we can print a message.
238 fsm_input(f, p, len);
239 if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED)
240 syslog(LOG_NOTICE, "Compression disabled by peer.");
243 * If we get a terminate-ack and we're not asking for compression,
246 if (oldstate == REQSENT && p[0] == TERMACK
247 && !ANY_COMPRESS(ccp_gotoptions[unit]))
248 ccp_close(unit, "No compression negotiated");
252 * Handle a CCP-specific code.
255 ccp_extcode(f, code, id, p, len)
263 if (f->state != OPENED)
265 /* send a reset-ack, which the transmitter will see and
266 reset its compression state. */
267 fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
271 if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
272 ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
273 UNTIMEOUT(ccp_rack_timeout, f);
285 * ccp_protrej - peer doesn't talk CCP.
291 ccp_flags_set(unit, 0, 0);
292 fsm_lowerdown(&ccp_fsm[unit]);
296 * ccp_resetci - initialize at start of negotiation.
302 ccp_options *go = &ccp_gotoptions[f->unit];
305 *go = ccp_wantoptions[f->unit];
306 all_rejected[f->unit] = 0;
309 * Check whether the kernel knows about the various
310 * compression methods we might request.
312 if (go->bsd_compress) {
313 opt_buf[0] = CI_BSD_COMPRESS;
314 opt_buf[1] = CILEN_BSD_COMPRESS;
315 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
316 if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
317 go->bsd_compress = 0;
320 if (go->deflate_correct) {
321 opt_buf[0] = CI_DEFLATE;
322 opt_buf[1] = CILEN_DEFLATE;
323 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
324 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
325 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
326 go->deflate_correct = 0;
328 if (go->deflate_draft) {
329 opt_buf[0] = CI_DEFLATE_DRAFT;
330 opt_buf[1] = CILEN_DEFLATE;
331 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_SIZE);
332 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
333 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
334 go->deflate_draft = 0;
336 if (!go->deflate_correct && !go->deflate_draft)
339 if (go->predictor_1) {
340 opt_buf[0] = CI_PREDICTOR_1;
341 opt_buf[1] = CILEN_PREDICTOR_1;
342 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
345 if (go->predictor_2) {
346 opt_buf[0] = CI_PREDICTOR_2;
347 opt_buf[1] = CILEN_PREDICTOR_2;
348 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
354 * ccp_cilen - Return total length of our configuration info.
360 ccp_options *go = &ccp_gotoptions[f->unit];
362 return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
363 + (go->deflate? CILEN_DEFLATE: 0)
364 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
365 + (go->predictor_2? CILEN_PREDICTOR_2: 0);
369 * ccp_addci - put our requests in a packet.
372 ccp_addci(f, p, lenp)
378 ccp_options *go = &ccp_gotoptions[f->unit];
382 * Add the compression types that we can receive, in decreasing
383 * preference order. Get the kernel to allocate the first one
384 * in case it gets Acked.
387 p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
388 p[1] = CILEN_DEFLATE;
389 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
390 p[3] = DEFLATE_CHK_SEQUENCE;
392 res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
397 if (res < 0 || go->deflate_size <= DEFLATE_MIN_SIZE) {
402 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
404 if (p != p0 && go->deflate_correct && go->deflate_draft) {
405 p[0] = CI_DEFLATE_DRAFT;
406 p[1] = CILEN_DEFLATE;
407 p[2] = p[2 - CILEN_DEFLATE];
408 p[3] = DEFLATE_CHK_SEQUENCE;
412 if (go->bsd_compress) {
413 p[0] = CI_BSD_COMPRESS;
414 p[1] = CILEN_BSD_COMPRESS;
415 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
417 p += CILEN_BSD_COMPRESS; /* not the first option */
420 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
422 p += CILEN_BSD_COMPRESS;
425 if (res < 0 || go->bsd_bits <= BSD_MIN_BITS) {
426 go->bsd_compress = 0;
430 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
434 /* XXX Should Predictor 2 be preferable to Predictor 1? */
435 if (go->predictor_1) {
436 p[0] = CI_PREDICTOR_1;
437 p[1] = CILEN_PREDICTOR_1;
438 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
441 p += CILEN_PREDICTOR_1;
444 if (go->predictor_2) {
445 p[0] = CI_PREDICTOR_2;
446 p[1] = CILEN_PREDICTOR_2;
447 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
450 p += CILEN_PREDICTOR_2;
454 go->method = (p > p0)? p0[0]: -1;
460 * ccp_ackci - process a received configure-ack, and return
461 * 1 iff the packet was OK.
469 ccp_options *go = &ccp_gotoptions[f->unit];
473 if (len < CILEN_DEFLATE
474 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
475 || p[1] != CILEN_DEFLATE
476 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
477 || p[3] != DEFLATE_CHK_SEQUENCE)
480 len -= CILEN_DEFLATE;
481 /* XXX Cope with first/fast ack */
484 if (go->deflate_correct && go->deflate_draft) {
485 if (len < CILEN_DEFLATE
486 || p[0] != CI_DEFLATE_DRAFT
487 || p[1] != CILEN_DEFLATE
488 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
489 || p[3] != DEFLATE_CHK_SEQUENCE)
492 len -= CILEN_DEFLATE;
495 if (go->bsd_compress) {
496 if (len < CILEN_BSD_COMPRESS
497 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
498 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
500 p += CILEN_BSD_COMPRESS;
501 len -= CILEN_BSD_COMPRESS;
502 /* XXX Cope with first/fast ack */
503 if (p == p0 && len == 0)
506 if (go->predictor_1) {
507 if (len < CILEN_PREDICTOR_1
508 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
510 p += CILEN_PREDICTOR_1;
511 len -= CILEN_PREDICTOR_1;
512 /* XXX Cope with first/fast ack */
513 if (p == p0 && len == 0)
516 if (go->predictor_2) {
517 if (len < CILEN_PREDICTOR_2
518 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
520 p += CILEN_PREDICTOR_2;
521 len -= CILEN_PREDICTOR_2;
522 /* XXX Cope with first/fast ack */
523 if (p == p0 && len == 0)
533 * ccp_nakci - process received configure-nak.
534 * Returns 1 iff the nak was OK.
542 ccp_options *go = &ccp_gotoptions[f->unit];
543 ccp_options no; /* options we've seen already */
544 ccp_options try; /* options to ask for next time */
546 memset(&no, 0, sizeof(no));
549 if (go->deflate && len >= CILEN_DEFLATE
550 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
551 && p[1] == CILEN_DEFLATE) {
554 * Peer wants us to use a different code size or something.
555 * Stop asking for Deflate if we don't understand his suggestion.
557 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
558 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_SIZE
559 || p[3] != DEFLATE_CHK_SEQUENCE)
561 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
562 try.deflate_size = DEFLATE_SIZE(p[2]);
564 len -= CILEN_DEFLATE;
565 if (go->deflate_correct && go->deflate_draft
566 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
567 && p[1] == CILEN_DEFLATE) {
569 len -= CILEN_DEFLATE;
573 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
574 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
577 * Peer wants us to use a different number of bits
578 * or a different version.
580 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
581 try.bsd_compress = 0;
582 else if (BSD_NBITS(p[2]) < go->bsd_bits)
583 try.bsd_bits = BSD_NBITS(p[2]);
584 p += CILEN_BSD_COMPRESS;
585 len -= CILEN_BSD_COMPRESS;
589 * Predictor-1 and 2 have no options, so they can't be Naked.
591 * XXX What should we do with any remaining options?
597 if (f->state != OPENED)
603 * ccp_rejci - reject some of our suggested compression methods.
611 ccp_options *go = &ccp_gotoptions[f->unit];
612 ccp_options try; /* options to request next time */
617 * Cope with empty configure-rejects by ceasing to send
618 * configure-requests.
620 if (len == 0 && all_rejected[f->unit])
623 if (go->deflate && len >= CILEN_DEFLATE
624 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
625 && p[1] == CILEN_DEFLATE) {
626 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
627 || p[3] != DEFLATE_CHK_SEQUENCE)
628 return 0; /* Rej is bad */
629 if (go->deflate_correct)
630 try.deflate_correct = 0;
632 try.deflate_draft = 0;
634 len -= CILEN_DEFLATE;
635 if (go->deflate_correct && go->deflate_draft
636 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
637 && p[1] == CILEN_DEFLATE) {
638 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
639 || p[3] != DEFLATE_CHK_SEQUENCE)
640 return 0; /* Rej is bad */
641 try.deflate_draft = 0;
643 len -= CILEN_DEFLATE;
645 if (!try.deflate_correct && !try.deflate_draft)
648 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
649 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
650 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
652 try.bsd_compress = 0;
653 p += CILEN_BSD_COMPRESS;
654 len -= CILEN_BSD_COMPRESS;
656 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
657 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
659 p += CILEN_PREDICTOR_1;
660 len -= CILEN_PREDICTOR_1;
662 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
663 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
665 p += CILEN_PREDICTOR_2;
666 len -= CILEN_PREDICTOR_2;
672 if (f->state != OPENED)
679 * ccp_reqci - processed a received configure-request.
680 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
684 ccp_reqci(f, p, lenp, dont_nak)
690 int ret, newret, res;
692 int len, clen, type, nb;
693 ccp_options *ho = &ccp_hisoptions[f->unit];
694 ccp_options *ao = &ccp_allowoptions[f->unit];
700 memset(ho, 0, sizeof(ccp_options));
701 ho->method = (len > 0)? p[0]: -1;
705 if (len < 2 || p[1] < 2 || p[1] > len) {
716 case CI_DEFLATE_DRAFT:
717 if (!ao->deflate || clen != CILEN_DEFLATE
718 || (!ao->deflate_correct && type == CI_DEFLATE)
719 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
725 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
726 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
727 || p[3] != DEFLATE_CHK_SEQUENCE
728 || nb > ao->deflate_size || nb < DEFLATE_MIN_SIZE) {
731 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
732 p[3] = DEFLATE_CHK_SEQUENCE;
733 /* fall through to test this #bits below */
739 * Check whether we can do Deflate with the window
740 * size they want. If the window is too big, reduce
741 * it until the kernel can cope and nak with that.
742 * We only check this for the first option.
746 res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
748 break; /* it's OK now */
749 if (res < 0 || nb == DEFLATE_MIN_SIZE || dont_nak) {
751 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
756 p[2] = DEFLATE_MAKE_OPT(nb);
761 case CI_BSD_COMPRESS:
762 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
767 ho->bsd_compress = 1;
768 ho->bsd_bits = nb = BSD_NBITS(p[2]);
769 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
770 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
773 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
774 /* fall through to test this #bits below */
780 * Check whether we can do BSD-Compress with the code
781 * size they want. If the code size is too big, reduce
782 * it until the kernel can cope and nak with that.
783 * We only check this for the first option.
787 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
790 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
792 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
798 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
804 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
811 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
817 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
824 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
834 if (newret == CONFNAK && dont_nak)
836 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
837 /* we're returning this option */
838 if (newret == CONFREJ && ret == CONFNAK)
842 BCOPY(p, retp, clen);
850 if (ret != CONFACK) {
851 if (ret == CONFREJ && *lenp == retp - p0)
852 all_rejected[f->unit] = 1;
860 * Make a string name for a compression method (or 2).
863 method_name(opt, opt2)
864 ccp_options *opt, *opt2;
866 static char result[64];
868 if (!ANY_COMPRESS(*opt))
870 switch (opt->method) {
872 case CI_DEFLATE_DRAFT:
873 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
874 sprintf(result, "Deflate%s (%d/%d)",
875 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
876 opt->deflate_size, opt2->deflate_size);
878 sprintf(result, "Deflate%s (%d)",
879 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
882 case CI_BSD_COMPRESS:
883 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
884 sprintf(result, "BSD-Compress (%d/%d)", opt->bsd_bits,
887 sprintf(result, "BSD-Compress (%d)", opt->bsd_bits);
890 return "Predictor 1";
892 return "Predictor 2";
894 sprintf(result, "Method %d", opt->method);
900 * CCP has come up - inform the kernel driver and log a message.
906 ccp_options *go = &ccp_gotoptions[f->unit];
907 ccp_options *ho = &ccp_hisoptions[f->unit];
910 ccp_flags_set(f->unit, 1, 1);
911 if (ANY_COMPRESS(*go)) {
912 if (ANY_COMPRESS(*ho)) {
913 if (go->method == ho->method) {
914 syslog(LOG_NOTICE, "%s compression enabled",
915 method_name(go, ho));
917 strcpy(method1, method_name(go, NULL));
918 syslog(LOG_NOTICE, "%s / %s compression enabled",
919 method1, method_name(ho, NULL));
922 syslog(LOG_NOTICE, "%s receive compression enabled",
923 method_name(go, NULL));
924 } else if (ANY_COMPRESS(*ho))
925 syslog(LOG_NOTICE, "%s transmit compression enabled",
926 method_name(ho, NULL));
930 * CCP has gone down - inform the kernel driver.
936 if (ccp_localstate[f->unit] & RACK_PENDING)
937 UNTIMEOUT(ccp_rack_timeout, f);
938 ccp_localstate[f->unit] = 0;
939 ccp_flags_set(f->unit, 1, 0);
943 * Print the contents of a CCP packet.
945 static char *ccp_codenames[] = {
946 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
947 "TermReq", "TermAck", "CodeRej",
948 NULL, NULL, NULL, NULL, NULL, NULL,
949 "ResetReq", "ResetAck",
953 ccp_printpkt(p, plen, printer, arg)
956 void (*printer)(void *, char *, ...);
964 if (plen < HEADERLEN)
968 len = (p[2] << 8) + p[3];
969 if (len < HEADERLEN || len > plen)
972 if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
973 && ccp_codenames[code-1] != NULL)
974 printer(arg, " %s", ccp_codenames[code-1]);
976 printer(arg, " code=0x%x", code);
977 printer(arg, " id=0x%x", id);
986 /* print list of possible compression methods */
990 if (optlen < 2 || optlen > len)
997 case CI_DEFLATE_DRAFT:
998 if (optlen >= CILEN_DEFLATE) {
999 printer(arg, "deflate%s %d",
1000 (code == CI_DEFLATE_DRAFT? "(old#)": ""),
1001 DEFLATE_SIZE(p[2]));
1002 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
1003 printer(arg, " method %d", DEFLATE_METHOD(p[2]));
1004 if (p[3] != DEFLATE_CHK_SEQUENCE)
1005 printer(arg, " check %d", p[3]);
1009 case CI_BSD_COMPRESS:
1010 if (optlen >= CILEN_BSD_COMPRESS) {
1011 printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
1013 p += CILEN_BSD_COMPRESS;
1016 case CI_PREDICTOR_1:
1017 if (optlen >= CILEN_PREDICTOR_1) {
1018 printer(arg, "predictor 1");
1019 p += CILEN_PREDICTOR_1;
1022 case CI_PREDICTOR_2:
1023 if (optlen >= CILEN_PREDICTOR_2) {
1024 printer(arg, "predictor 2");
1025 p += CILEN_PREDICTOR_2;
1030 printer(arg, " %.2x", *p++);
1037 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1038 print_string(p, len, printer, arg);
1045 /* dump out the rest of the packet in hex */
1047 printer(arg, " %.2x", *p++);
1053 * We have received a packet that the decompressor failed to
1054 * decompress. Here we would expect to issue a reset-request, but
1055 * Motorola has a patent on resetting the compressor as a result of
1056 * detecting an error in the decompressed data after decompression.
1057 * (See US patent 5,130,993; international patent publication number
1058 * WO 91/10289; Australian patent 73296/91.)
1060 * So we ask the kernel whether the error was detected after
1061 * decompression; if it was, we take CCP down, thus disabling
1062 * compression :-(, otherwise we issue the reset-request.
1065 ccp_datainput(unit, pkt, len)
1073 if (f->state == OPENED) {
1074 if (ccp_fatal_error(unit)) {
1076 * Disable compression by taking CCP down.
1078 syslog(LOG_ERR, "Lost compression sync: disabling compression");
1079 ccp_close(unit, "Lost compression sync");
1082 * Send a reset-request to reset the peer's compressor.
1083 * We don't do that if we are still waiting for an
1084 * acknowledgement to a previous reset-request.
1086 if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
1087 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1088 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1089 ccp_localstate[f->unit] |= RACK_PENDING;
1091 ccp_localstate[f->unit] |= RREQ_REPEAT;
1097 * Timeout waiting for reset-ack.
1100 ccp_rack_timeout(arg)
1105 if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
1106 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1107 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1108 ccp_localstate[f->unit] &= ~RREQ_REPEAT;
1110 ccp_localstate[f->unit] &= ~RACK_PENDING;