2 * ccp.c - PPP Compression Control Protocol.
4 * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. The name(s) of the authors of this software must not be used to
14 * endorse or promote products derived from this software without
15 * prior written permission.
17 * 3. Redistributions of any form whatsoever must retain the following
19 * "This product includes software developed by Paul Mackerras
20 * <paulus@samba.org>".
22 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #define RCSID "$Id: ccp.c,v 1.50 2005/06/26 19:34:41 carlsonj Exp $"
39 #include <net/ppp-comp.h>
42 #include "chap_ms.h" /* mppe_xxxx_key, mppe_keys_set */
43 #include "lcp.h" /* lcp_close(), lcp_fsm */
46 static const char rcsid[] = RCSID;
49 * Unfortunately there is a bug in zlib which means that using a
50 * size of 8 (window size = 256) for Deflate compression will cause
51 * buffer overruns and kernel crashes in the deflate module.
52 * Until this is fixed we only accept sizes in the range 9 .. 15.
53 * Thanks to James Carlson for pointing this out.
55 #define DEFLATE_MIN_WORKS 9
58 * Command-line options.
60 static int setbsdcomp __P((char **));
61 static int setdeflate __P((char **));
62 static char bsd_value[8];
63 static char deflate_value[8];
69 bool refuse_mppe_stateful = 1; /* Allow stateful mode? */
72 static option_t ccp_option_list[] = {
73 { "noccp", o_bool, &ccp_protent.enabled_flag,
74 "Disable CCP negotiation" },
75 { "-ccp", o_bool, &ccp_protent.enabled_flag,
76 "Disable CCP negotiation", OPT_ALIAS },
78 { "bsdcomp", o_special, (void *)setbsdcomp,
79 "Request BSD-Compress packet compression",
80 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, bsd_value },
81 { "nobsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
82 "don't allow BSD-Compress", OPT_PRIOSUB | OPT_A2CLR,
83 &ccp_allowoptions[0].bsd_compress },
84 { "-bsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
85 "don't allow BSD-Compress", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
86 &ccp_allowoptions[0].bsd_compress },
88 { "deflate", o_special, (void *)setdeflate,
89 "request Deflate compression",
90 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, deflate_value },
91 { "nodeflate", o_bool, &ccp_wantoptions[0].deflate,
92 "don't allow Deflate compression", OPT_PRIOSUB | OPT_A2CLR,
93 &ccp_allowoptions[0].deflate },
94 { "-deflate", o_bool, &ccp_wantoptions[0].deflate,
95 "don't allow Deflate compression", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
96 &ccp_allowoptions[0].deflate },
98 { "nodeflatedraft", o_bool, &ccp_wantoptions[0].deflate_draft,
99 "don't use draft deflate #", OPT_A2COPY,
100 &ccp_allowoptions[0].deflate_draft },
102 { "predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
103 "request Predictor-1", OPT_PRIO | 1 },
104 { "nopredictor1", o_bool, &ccp_wantoptions[0].predictor_1,
105 "don't allow Predictor-1", OPT_PRIOSUB | OPT_A2CLR,
106 &ccp_allowoptions[0].predictor_1 },
107 { "-predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
108 "don't allow Predictor-1", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
109 &ccp_allowoptions[0].predictor_1 },
112 /* MPPE options are symmetrical ... we only set wantoptions here */
113 { "require-mppe", o_bool, &ccp_wantoptions[0].mppe,
114 "require MPPE encryption",
115 OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
116 { "+mppe", o_bool, &ccp_wantoptions[0].mppe,
117 "require MPPE encryption",
118 OPT_ALIAS | OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
119 { "nomppe", o_bool, &ccp_wantoptions[0].mppe,
120 "don't allow MPPE encryption", OPT_PRIO },
121 { "-mppe", o_bool, &ccp_wantoptions[0].mppe,
122 "don't allow MPPE encryption", OPT_ALIAS | OPT_PRIO },
124 /* We use ccp_allowoptions[0].mppe as a junk var ... it is reset later */
125 { "require-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
126 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
127 &ccp_wantoptions[0].mppe },
128 { "+mppe-40", o_bool, &ccp_allowoptions[0].mppe,
129 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
130 &ccp_wantoptions[0].mppe },
131 { "nomppe-40", o_bool, &ccp_allowoptions[0].mppe,
132 "don't allow MPPE 40-bit encryption",
133 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40, &ccp_wantoptions[0].mppe },
134 { "-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
135 "don't allow MPPE 40-bit encryption",
136 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40,
137 &ccp_wantoptions[0].mppe },
139 { "require-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
140 "require MPPE 128-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
141 &ccp_wantoptions[0].mppe },
142 { "+mppe-128", o_bool, &ccp_allowoptions[0].mppe,
143 "require MPPE 128-bit encryption",
144 OPT_ALIAS | OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
145 &ccp_wantoptions[0].mppe },
146 { "nomppe-128", o_bool, &ccp_allowoptions[0].mppe,
147 "don't allow MPPE 128-bit encryption",
148 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128, &ccp_wantoptions[0].mppe },
149 { "-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
150 "don't allow MPPE 128-bit encryption",
151 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128,
152 &ccp_wantoptions[0].mppe },
154 /* strange one; we always request stateless, but will we allow stateful? */
155 { "mppe-stateful", o_bool, &refuse_mppe_stateful,
156 "allow MPPE stateful mode", OPT_PRIO },
157 { "nomppe-stateful", o_bool, &refuse_mppe_stateful,
158 "disallow MPPE stateful mode", OPT_PRIO | 1 },
165 * Protocol entry points from main code.
167 static void ccp_init __P((int unit));
168 static void ccp_open __P((int unit));
169 static void ccp_close __P((int unit, char *));
170 static void ccp_lowerup __P((int unit));
171 static void ccp_lowerdown __P((int));
172 static void ccp_input __P((int unit, u_char *pkt, int len));
173 static void ccp_protrej __P((int unit));
174 static int ccp_printpkt __P((u_char *pkt, int len,
175 void (*printer) __P((void *, char *, ...)),
177 static void ccp_datainput __P((int unit, u_char *pkt, int len));
179 struct protent ccp_protent = {
199 fsm ccp_fsm[NUM_PPP];
200 ccp_options ccp_wantoptions[NUM_PPP]; /* what to request the peer to use */
201 ccp_options ccp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
202 ccp_options ccp_allowoptions[NUM_PPP]; /* what we'll agree to do */
203 ccp_options ccp_hisoptions[NUM_PPP]; /* what we agreed to do */
206 * Callbacks for fsm code.
208 static void ccp_resetci __P((fsm *));
209 static int ccp_cilen __P((fsm *));
210 static void ccp_addci __P((fsm *, u_char *, int *));
211 static int ccp_ackci __P((fsm *, u_char *, int));
212 static int ccp_nakci __P((fsm *, u_char *, int, int));
213 static int ccp_rejci __P((fsm *, u_char *, int));
214 static int ccp_reqci __P((fsm *, u_char *, int *, int));
215 static void ccp_up __P((fsm *));
216 static void ccp_down __P((fsm *));
217 static int ccp_extcode __P((fsm *, int, int, u_char *, int));
218 static void ccp_rack_timeout __P((void *));
219 static char *method_name __P((ccp_options *, ccp_options *));
221 static fsm_callbacks ccp_callbacks = {
240 * Do we want / did we get any compression?
242 #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
243 || (opt).predictor_1 || (opt).predictor_2 \
247 * Local state (mainly for handling reset-reqs and reset-acks).
249 static int ccp_localstate[NUM_PPP];
250 #define RACK_PENDING 1 /* waiting for reset-ack */
251 #define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
253 #define RACKTIMEOUT 1 /* second */
255 static int all_rejected[NUM_PPP]; /* we rejected all peer's options */
268 abits = rbits = strtol(str, &endp, 0);
269 if (endp != str && *endp == ',') {
271 abits = strtol(str, &endp, 0);
273 if (*endp != 0 || endp == str) {
274 option_error("invalid parameter '%s' for bsdcomp option", *argv);
277 if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
278 || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
279 option_error("bsdcomp option values must be 0 or %d .. %d",
280 BSD_MIN_BITS, BSD_MAX_BITS);
284 ccp_wantoptions[0].bsd_compress = 1;
285 ccp_wantoptions[0].bsd_bits = rbits;
287 ccp_wantoptions[0].bsd_compress = 0;
289 ccp_allowoptions[0].bsd_compress = 1;
290 ccp_allowoptions[0].bsd_bits = abits;
292 ccp_allowoptions[0].bsd_compress = 0;
293 slprintf(bsd_value, sizeof(bsd_value),
294 rbits == abits? "%d": "%d,%d", rbits, abits);
307 abits = rbits = strtol(str, &endp, 0);
308 if (endp != str && *endp == ',') {
310 abits = strtol(str, &endp, 0);
312 if (*endp != 0 || endp == str) {
313 option_error("invalid parameter '%s' for deflate option", *argv);
316 if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
317 || (abits != 0 && (abits < DEFLATE_MIN_SIZE
318 || abits > DEFLATE_MAX_SIZE))) {
319 option_error("deflate option values must be 0 or %d .. %d",
320 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
323 if (rbits == DEFLATE_MIN_SIZE || abits == DEFLATE_MIN_SIZE) {
324 if (rbits == DEFLATE_MIN_SIZE)
325 rbits = DEFLATE_MIN_WORKS;
326 if (abits == DEFLATE_MIN_SIZE)
327 abits = DEFLATE_MIN_WORKS;
328 warn("deflate option value of %d changed to %d to avoid zlib bug",
329 DEFLATE_MIN_SIZE, DEFLATE_MIN_WORKS);
332 ccp_wantoptions[0].deflate = 1;
333 ccp_wantoptions[0].deflate_size = rbits;
335 ccp_wantoptions[0].deflate = 0;
337 ccp_allowoptions[0].deflate = 1;
338 ccp_allowoptions[0].deflate_size = abits;
340 ccp_allowoptions[0].deflate = 0;
341 slprintf(deflate_value, sizeof(deflate_value),
342 rbits == abits? "%d": "%d,%d", rbits, abits);
348 * ccp_init - initialize CCP.
354 fsm *f = &ccp_fsm[unit];
357 f->protocol = PPP_CCP;
358 f->callbacks = &ccp_callbacks;
361 memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
362 memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
363 memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
364 memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
366 ccp_wantoptions[0].deflate = 1;
367 ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
368 ccp_wantoptions[0].deflate_correct = 1;
369 ccp_wantoptions[0].deflate_draft = 1;
370 ccp_allowoptions[0].deflate = 1;
371 ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
372 ccp_allowoptions[0].deflate_correct = 1;
373 ccp_allowoptions[0].deflate_draft = 1;
375 ccp_wantoptions[0].bsd_compress = 1;
376 ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
377 ccp_allowoptions[0].bsd_compress = 1;
378 ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
380 ccp_allowoptions[0].predictor_1 = 1;
384 * ccp_open - CCP is allowed to come up.
390 fsm *f = &ccp_fsm[unit];
392 if (f->state != OPENED)
393 ccp_flags_set(unit, 1, 0);
396 * Find out which compressors the kernel supports before
397 * deciding whether to open in silent mode.
400 if (!ANY_COMPRESS(ccp_gotoptions[unit]))
401 f->flags |= OPT_SILENT;
407 * ccp_close - Terminate CCP.
410 ccp_close(unit, reason)
414 ccp_flags_set(unit, 0, 0);
415 fsm_close(&ccp_fsm[unit], reason);
419 * ccp_lowerup - we may now transmit CCP packets.
425 fsm_lowerup(&ccp_fsm[unit]);
429 * ccp_lowerdown - we may not transmit CCP packets.
435 fsm_lowerdown(&ccp_fsm[unit]);
439 * ccp_input - process a received CCP packet.
442 ccp_input(unit, p, len)
447 fsm *f = &ccp_fsm[unit];
451 * Check for a terminate-request so we can print a message.
454 fsm_input(f, p, len);
455 if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED) {
456 notice("Compression disabled by peer.");
458 if (ccp_gotoptions[unit].mppe) {
459 error("MPPE disabled, closing LCP");
460 lcp_close(unit, "MPPE disabled by peer");
466 * If we get a terminate-ack and we're not asking for compression,
469 if (oldstate == REQSENT && p[0] == TERMACK
470 && !ANY_COMPRESS(ccp_gotoptions[unit]))
471 ccp_close(unit, "No compression negotiated");
475 * Handle a CCP-specific code.
478 ccp_extcode(f, code, id, p, len)
486 if (f->state != OPENED)
488 /* send a reset-ack, which the transmitter will see and
489 reset its compression state. */
490 fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
494 if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
495 ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
496 UNTIMEOUT(ccp_rack_timeout, f);
508 * ccp_protrej - peer doesn't talk CCP.
514 ccp_flags_set(unit, 0, 0);
515 fsm_lowerdown(&ccp_fsm[unit]);
518 if (ccp_gotoptions[unit].mppe) {
519 error("MPPE required but peer negotiation failed");
520 lcp_close(unit, "MPPE required but peer negotiation failed");
527 * ccp_resetci - initialize at start of negotiation.
533 ccp_options *go = &ccp_gotoptions[f->unit];
534 u_char opt_buf[CCP_MAX_OPTION_LENGTH];
536 *go = ccp_wantoptions[f->unit];
537 all_rejected[f->unit] = 0;
541 ccp_options *ao = &ccp_allowoptions[f->unit];
542 int auth_mschap_bits = auth_done[f->unit];
546 * Start with a basic sanity check: mschap[v2] auth must be in
547 * exactly one direction. RFC 3079 says that the keys are
548 * 'derived from the credentials of the peer that initiated the call',
549 * however the PPP protocol doesn't have such a concept, and pppd
550 * cannot get this info externally. Instead we do the best we can.
551 * NB: If MPPE is required, all other compression opts are invalid.
552 * So, we return right away if we can't do it.
555 /* Leave only the mschap auth bits set */
556 auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
557 CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
558 /* Count the mschap auths */
559 auth_mschap_bits >>= CHAP_MS_SHIFT;
562 numbits += auth_mschap_bits & 1;
563 auth_mschap_bits >>= 1;
564 } while (auth_mschap_bits);
566 error("MPPE required, but auth done in both directions.");
567 lcp_close(f->unit, "MPPE required but not available");
571 error("MPPE required, but MS-CHAP[v2] auth not performed.");
572 lcp_close(f->unit, "MPPE required but not available");
576 /* A plugin (eg radius) may not have obtained key material. */
577 if (!mppe_keys_set) {
578 error("MPPE required, but keys are not available. "
579 "Possible plugin problem?");
580 lcp_close(f->unit, "MPPE required but not available");
584 /* LM auth not supported for MPPE */
585 if (auth_done[f->unit] & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) {
586 /* This might be noise */
587 if (go->mppe & MPPE_OPT_40) {
588 notice("Disabling 40-bit MPPE; MS-CHAP LM not supported");
589 go->mppe &= ~MPPE_OPT_40;
590 ccp_wantoptions[f->unit].mppe &= ~MPPE_OPT_40;
594 /* Last check: can we actually negotiate something? */
595 if (!(go->mppe & (MPPE_OPT_40 | MPPE_OPT_128))) {
596 /* Could be misconfig, could be 40-bit disabled above. */
597 error("MPPE required, but both 40-bit and 128-bit disabled.");
598 lcp_close(f->unit, "MPPE required but not available");
604 /* MPPE is not compatible with other compression types */
605 ao->bsd_compress = go->bsd_compress = 0;
606 ao->predictor_1 = go->predictor_1 = 0;
607 ao->predictor_2 = go->predictor_2 = 0;
608 ao->deflate = go->deflate = 0;
613 * Check whether the kernel knows about the various
614 * compression methods we might request.
618 opt_buf[0] = CI_MPPE;
619 opt_buf[1] = CILEN_MPPE;
620 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
621 /* Key material unimportant here. */
622 if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0) {
623 error("MPPE required, but kernel has no support.");
624 lcp_close(f->unit, "MPPE required but not available");
628 if (go->bsd_compress) {
629 opt_buf[0] = CI_BSD_COMPRESS;
630 opt_buf[1] = CILEN_BSD_COMPRESS;
631 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
632 if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
633 go->bsd_compress = 0;
636 if (go->deflate_correct) {
637 opt_buf[0] = CI_DEFLATE;
638 opt_buf[1] = CILEN_DEFLATE;
639 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
640 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
641 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
642 go->deflate_correct = 0;
644 if (go->deflate_draft) {
645 opt_buf[0] = CI_DEFLATE_DRAFT;
646 opt_buf[1] = CILEN_DEFLATE;
647 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
648 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
649 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
650 go->deflate_draft = 0;
652 if (!go->deflate_correct && !go->deflate_draft)
655 if (go->predictor_1) {
656 opt_buf[0] = CI_PREDICTOR_1;
657 opt_buf[1] = CILEN_PREDICTOR_1;
658 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
661 if (go->predictor_2) {
662 opt_buf[0] = CI_PREDICTOR_2;
663 opt_buf[1] = CILEN_PREDICTOR_2;
664 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
670 * ccp_cilen - Return total length of our configuration info.
676 ccp_options *go = &ccp_gotoptions[f->unit];
678 return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
679 + (go->deflate && go->deflate_correct? CILEN_DEFLATE: 0)
680 + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0)
681 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
682 + (go->predictor_2? CILEN_PREDICTOR_2: 0)
683 + (go->mppe? CILEN_MPPE: 0);
687 * ccp_addci - put our requests in a packet.
690 ccp_addci(f, p, lenp)
696 ccp_options *go = &ccp_gotoptions[f->unit];
700 * Add the compression types that we can receive, in decreasing
701 * preference order. Get the kernel to allocate the first one
702 * in case it gets Acked.
706 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
708 p[0] = opt_buf[0] = CI_MPPE;
709 p[1] = opt_buf[1] = CILEN_MPPE;
710 MPPE_OPTS_TO_CI(go->mppe, &p[2]);
711 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
712 BCOPY(mppe_recv_key, &opt_buf[CILEN_MPPE], MPPE_MAX_KEY_LEN);
713 res = ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0);
717 /* This shouldn't happen, we've already tested it! */
718 lcp_close(f->unit, "MPPE required but not available in kernel");
722 p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
723 p[1] = CILEN_DEFLATE;
724 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
725 p[3] = DEFLATE_CHK_SEQUENCE;
730 if (go->deflate_size < DEFLATE_MIN_WORKS) {
734 res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
738 } else if (res < 0) {
743 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
746 if (p != p0 && go->deflate_correct && go->deflate_draft) {
747 p[0] = CI_DEFLATE_DRAFT;
748 p[1] = CILEN_DEFLATE;
749 p[2] = p[2 - CILEN_DEFLATE];
750 p[3] = DEFLATE_CHK_SEQUENCE;
754 if (go->bsd_compress) {
755 p[0] = CI_BSD_COMPRESS;
756 p[1] = CILEN_BSD_COMPRESS;
757 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
759 p += CILEN_BSD_COMPRESS; /* not the first option */
762 if (go->bsd_bits < BSD_MIN_BITS) {
763 go->bsd_compress = 0;
766 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
768 p += CILEN_BSD_COMPRESS;
770 } else if (res < 0) {
771 go->bsd_compress = 0;
775 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
779 /* XXX Should Predictor 2 be preferable to Predictor 1? */
780 if (go->predictor_1) {
781 p[0] = CI_PREDICTOR_1;
782 p[1] = CILEN_PREDICTOR_1;
783 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
786 p += CILEN_PREDICTOR_1;
789 if (go->predictor_2) {
790 p[0] = CI_PREDICTOR_2;
791 p[1] = CILEN_PREDICTOR_2;
792 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
795 p += CILEN_PREDICTOR_2;
799 go->method = (p > p0)? p0[0]: -1;
805 * ccp_ackci - process a received configure-ack, and return
806 * 1 iff the packet was OK.
814 ccp_options *go = &ccp_gotoptions[f->unit];
819 u_char opt_buf[CILEN_MPPE];
821 opt_buf[0] = CI_MPPE;
822 opt_buf[1] = CILEN_MPPE;
823 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
824 if (len < CILEN_MPPE || memcmp(opt_buf, p, CILEN_MPPE))
828 /* XXX Cope with first/fast ack */
834 if (len < CILEN_DEFLATE
835 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
836 || p[1] != CILEN_DEFLATE
837 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
838 || p[3] != DEFLATE_CHK_SEQUENCE)
841 len -= CILEN_DEFLATE;
842 /* XXX Cope with first/fast ack */
845 if (go->deflate_correct && go->deflate_draft) {
846 if (len < CILEN_DEFLATE
847 || p[0] != CI_DEFLATE_DRAFT
848 || p[1] != CILEN_DEFLATE
849 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
850 || p[3] != DEFLATE_CHK_SEQUENCE)
853 len -= CILEN_DEFLATE;
856 if (go->bsd_compress) {
857 if (len < CILEN_BSD_COMPRESS
858 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
859 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
861 p += CILEN_BSD_COMPRESS;
862 len -= CILEN_BSD_COMPRESS;
863 /* XXX Cope with first/fast ack */
864 if (p == p0 && len == 0)
867 if (go->predictor_1) {
868 if (len < CILEN_PREDICTOR_1
869 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
871 p += CILEN_PREDICTOR_1;
872 len -= CILEN_PREDICTOR_1;
873 /* XXX Cope with first/fast ack */
874 if (p == p0 && len == 0)
877 if (go->predictor_2) {
878 if (len < CILEN_PREDICTOR_2
879 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
881 p += CILEN_PREDICTOR_2;
882 len -= CILEN_PREDICTOR_2;
883 /* XXX Cope with first/fast ack */
884 if (p == p0 && len == 0)
894 * ccp_nakci - process received configure-nak.
895 * Returns 1 iff the nak was OK.
898 ccp_nakci(f, p, len, treat_as_reject)
904 ccp_options *go = &ccp_gotoptions[f->unit];
905 ccp_options no; /* options we've seen already */
906 ccp_options try; /* options to ask for next time */
908 memset(&no, 0, sizeof(no));
912 if (go->mppe && len >= CILEN_MPPE
913 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
916 * Peer wants us to use a different strength or other setting.
917 * Fail if we aren't willing to use his suggestion.
919 MPPE_CI_TO_OPTS(&p[2], try.mppe);
920 if ((try.mppe & MPPE_OPT_STATEFUL) && refuse_mppe_stateful) {
921 error("Refusing MPPE stateful mode offered by peer");
923 } else if (((go->mppe | MPPE_OPT_STATEFUL) & try.mppe) != try.mppe) {
924 /* Peer must have set options we didn't request (suggest) */
929 error("MPPE required but peer negotiation failed");
930 lcp_close(f->unit, "MPPE required but peer negotiation failed");
934 if (go->deflate && len >= CILEN_DEFLATE
935 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
936 && p[1] == CILEN_DEFLATE) {
939 * Peer wants us to use a different code size or something.
940 * Stop asking for Deflate if we don't understand his suggestion.
942 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
943 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_WORKS
944 || p[3] != DEFLATE_CHK_SEQUENCE)
946 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
947 try.deflate_size = DEFLATE_SIZE(p[2]);
949 len -= CILEN_DEFLATE;
950 if (go->deflate_correct && go->deflate_draft
951 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
952 && p[1] == CILEN_DEFLATE) {
954 len -= CILEN_DEFLATE;
958 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
959 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
962 * Peer wants us to use a different number of bits
963 * or a different version.
965 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
966 try.bsd_compress = 0;
967 else if (BSD_NBITS(p[2]) < go->bsd_bits)
968 try.bsd_bits = BSD_NBITS(p[2]);
969 p += CILEN_BSD_COMPRESS;
970 len -= CILEN_BSD_COMPRESS;
974 * Predictor-1 and 2 have no options, so they can't be Naked.
976 * There may be remaining options but we ignore them.
979 if (f->state != OPENED)
985 * ccp_rejci - reject some of our suggested compression methods.
993 ccp_options *go = &ccp_gotoptions[f->unit];
994 ccp_options try; /* options to request next time */
999 * Cope with empty configure-rejects by ceasing to send
1000 * configure-requests.
1002 if (len == 0 && all_rejected[f->unit])
1006 if (go->mppe && len >= CILEN_MPPE
1007 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
1008 error("MPPE required but peer refused");
1009 lcp_close(f->unit, "MPPE required but peer refused");
1014 if (go->deflate_correct && len >= CILEN_DEFLATE
1015 && p[0] == CI_DEFLATE && p[1] == CILEN_DEFLATE) {
1016 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1017 || p[3] != DEFLATE_CHK_SEQUENCE)
1018 return 0; /* Rej is bad */
1019 try.deflate_correct = 0;
1021 len -= CILEN_DEFLATE;
1023 if (go->deflate_draft && len >= CILEN_DEFLATE
1024 && p[0] == CI_DEFLATE_DRAFT && p[1] == CILEN_DEFLATE) {
1025 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1026 || p[3] != DEFLATE_CHK_SEQUENCE)
1027 return 0; /* Rej is bad */
1028 try.deflate_draft = 0;
1030 len -= CILEN_DEFLATE;
1032 if (!try.deflate_correct && !try.deflate_draft)
1034 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
1035 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
1036 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
1038 try.bsd_compress = 0;
1039 p += CILEN_BSD_COMPRESS;
1040 len -= CILEN_BSD_COMPRESS;
1042 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
1043 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
1044 try.predictor_1 = 0;
1045 p += CILEN_PREDICTOR_1;
1046 len -= CILEN_PREDICTOR_1;
1048 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
1049 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
1050 try.predictor_2 = 0;
1051 p += CILEN_PREDICTOR_2;
1052 len -= CILEN_PREDICTOR_2;
1058 if (f->state != OPENED)
1065 * ccp_reqci - processed a received configure-request.
1066 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
1070 ccp_reqci(f, p, lenp, dont_nak)
1076 int ret, newret, res;
1078 int len, clen, type, nb;
1079 ccp_options *ho = &ccp_hisoptions[f->unit];
1080 ccp_options *ao = &ccp_allowoptions[f->unit];
1082 bool rej_for_ci_mppe = 1; /* Are we rejecting based on a bad/missing */
1083 /* CI_MPPE, or due to other options? */
1090 memset(ho, 0, sizeof(ccp_options));
1091 ho->method = (len > 0)? p[0]: -1;
1095 if (len < 2 || p[1] < 2 || p[1] > len) {
1107 if (!ao->mppe || clen != CILEN_MPPE) {
1111 MPPE_CI_TO_OPTS(&p[2], ho->mppe);
1113 /* Nak if anything unsupported or unknown are set. */
1114 if (ho->mppe & MPPE_OPT_UNSUPPORTED) {
1116 ho->mppe &= ~MPPE_OPT_UNSUPPORTED;
1118 if (ho->mppe & MPPE_OPT_UNKNOWN) {
1120 ho->mppe &= ~MPPE_OPT_UNKNOWN;
1123 /* Check state opt */
1124 if (ho->mppe & MPPE_OPT_STATEFUL) {
1126 * We can Nak and request stateless, but it's a
1127 * lot easier to just assume the peer will request
1128 * it if he can do it; stateful mode is bad over
1129 * the Internet -- which is where we expect MPPE.
1131 if (refuse_mppe_stateful) {
1132 error("Refusing MPPE stateful mode offered by peer");
1138 /* Find out which of {S,L} are set. */
1139 if ((ho->mppe & MPPE_OPT_128)
1140 && (ho->mppe & MPPE_OPT_40)) {
1141 /* Both are set, negotiate the strongest. */
1143 if (ao->mppe & MPPE_OPT_128)
1144 ho->mppe &= ~MPPE_OPT_40;
1145 else if (ao->mppe & MPPE_OPT_40)
1146 ho->mppe &= ~MPPE_OPT_128;
1151 } else if (ho->mppe & MPPE_OPT_128) {
1152 if (!(ao->mppe & MPPE_OPT_128)) {
1156 } else if (ho->mppe & MPPE_OPT_40) {
1157 if (!(ao->mppe & MPPE_OPT_40)) {
1162 /* Neither are set. */
1163 /* We cannot accept this. */
1165 /* Give the peer our idea of what can be used,
1166 so it can choose and confirm */
1167 ho->mppe = ao->mppe;
1170 /* rebuild the opts */
1171 MPPE_OPTS_TO_CI(ho->mppe, &p[2]);
1172 if (newret == CONFACK) {
1173 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
1176 BCOPY(p, opt_buf, CILEN_MPPE);
1177 BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
1179 if (ccp_test(f->unit, opt_buf,
1180 CILEN_MPPE + MPPE_MAX_KEY_LEN, 1) <= 0) {
1181 /* This shouldn't happen, we've already tested it! */
1182 error("MPPE required, but kernel has no support.");
1183 lcp_close(f->unit, "MPPE required but not available");
1188 * We need to decrease the interface MTU by MPPE_PAD
1189 * because MPPE frames **grow**. The kernel [must]
1190 * allocate MPPE_PAD extra bytes in xmit buffers.
1192 mtu = netif_get_mtu(f->unit);
1194 netif_set_mtu(f->unit, mtu - MPPE_PAD);
1200 * We have accepted MPPE or are willing to negotiate
1201 * MPPE parameters. A CONFREJ is due to subsequent
1202 * (non-MPPE) processing.
1204 rej_for_ci_mppe = 0;
1208 case CI_DEFLATE_DRAFT:
1209 if (!ao->deflate || clen != CILEN_DEFLATE
1210 || (!ao->deflate_correct && type == CI_DEFLATE)
1211 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
1217 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
1218 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
1219 || p[3] != DEFLATE_CHK_SEQUENCE
1220 || nb > ao->deflate_size || nb < DEFLATE_MIN_WORKS) {
1223 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
1224 p[3] = DEFLATE_CHK_SEQUENCE;
1225 /* fall through to test this #bits below */
1231 * Check whether we can do Deflate with the window
1232 * size they want. If the window is too big, reduce
1233 * it until the kernel can cope and nak with that.
1234 * We only check this for the first option.
1238 res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
1240 break; /* it's OK now */
1241 if (res < 0 || nb == DEFLATE_MIN_WORKS || dont_nak) {
1243 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
1248 p[2] = DEFLATE_MAKE_OPT(nb);
1253 case CI_BSD_COMPRESS:
1254 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
1259 ho->bsd_compress = 1;
1260 ho->bsd_bits = nb = BSD_NBITS(p[2]);
1261 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
1262 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
1265 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
1266 /* fall through to test this #bits below */
1272 * Check whether we can do BSD-Compress with the code
1273 * size they want. If the code size is too big, reduce
1274 * it until the kernel can cope and nak with that.
1275 * We only check this for the first option.
1279 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
1282 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
1284 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
1290 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
1295 case CI_PREDICTOR_1:
1296 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
1301 ho->predictor_1 = 1;
1303 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
1308 case CI_PREDICTOR_2:
1309 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
1314 ho->predictor_2 = 1;
1316 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
1326 if (newret == CONFNAK && dont_nak)
1328 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
1329 /* we're returning this option */
1330 if (newret == CONFREJ && ret == CONFNAK)
1334 BCOPY(p, retp, clen);
1342 if (ret != CONFACK) {
1343 if (ret == CONFREJ && *lenp == retp - p0)
1344 all_rejected[f->unit] = 1;
1349 if (ret == CONFREJ && ao->mppe && rej_for_ci_mppe) {
1350 error("MPPE required but peer negotiation failed");
1351 lcp_close(f->unit, "MPPE required but peer negotiation failed");
1358 * Make a string name for a compression method (or 2).
1361 method_name(opt, opt2)
1362 ccp_options *opt, *opt2;
1364 static char result[64];
1366 if (!ANY_COMPRESS(*opt))
1368 switch (opt->method) {
1373 char *q = result + sizeof(result); /* 1 past result */
1375 slprintf(p, q - p, "MPPE ");
1377 if (opt->mppe & MPPE_OPT_128) {
1378 slprintf(p, q - p, "128-bit ");
1381 if (opt->mppe & MPPE_OPT_40) {
1382 slprintf(p, q - p, "40-bit ");
1385 if (opt->mppe & MPPE_OPT_STATEFUL)
1386 slprintf(p, q - p, "stateful");
1388 slprintf(p, q - p, "stateless");
1394 case CI_DEFLATE_DRAFT:
1395 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
1396 slprintf(result, sizeof(result), "Deflate%s (%d/%d)",
1397 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1398 opt->deflate_size, opt2->deflate_size);
1400 slprintf(result, sizeof(result), "Deflate%s (%d)",
1401 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1404 case CI_BSD_COMPRESS:
1405 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
1406 slprintf(result, sizeof(result), "BSD-Compress (%d/%d)",
1407 opt->bsd_bits, opt2->bsd_bits);
1409 slprintf(result, sizeof(result), "BSD-Compress (%d)",
1412 case CI_PREDICTOR_1:
1413 return "Predictor 1";
1414 case CI_PREDICTOR_2:
1415 return "Predictor 2";
1417 slprintf(result, sizeof(result), "Method %d", opt->method);
1423 * CCP has come up - inform the kernel driver and log a message.
1429 ccp_options *go = &ccp_gotoptions[f->unit];
1430 ccp_options *ho = &ccp_hisoptions[f->unit];
1433 ccp_flags_set(f->unit, 1, 1);
1434 if (ANY_COMPRESS(*go)) {
1435 if (ANY_COMPRESS(*ho)) {
1436 if (go->method == ho->method) {
1437 notice("%s compression enabled", method_name(go, ho));
1439 strlcpy(method1, method_name(go, NULL), sizeof(method1));
1440 notice("%s / %s compression enabled",
1441 method1, method_name(ho, NULL));
1444 notice("%s receive compression enabled", method_name(go, NULL));
1445 } else if (ANY_COMPRESS(*ho))
1446 notice("%s transmit compression enabled", method_name(ho, NULL));
1449 BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN);
1450 BZERO(mppe_send_key, MPPE_MAX_KEY_LEN);
1451 continue_networks(f->unit); /* Bring up IP et al */
1457 * CCP has gone down - inform the kernel driver.
1463 if (ccp_localstate[f->unit] & RACK_PENDING)
1464 UNTIMEOUT(ccp_rack_timeout, f);
1465 ccp_localstate[f->unit] = 0;
1466 ccp_flags_set(f->unit, 1, 0);
1468 if (ccp_gotoptions[f->unit].mppe) {
1469 ccp_gotoptions[f->unit].mppe = 0;
1470 if (lcp_fsm[f->unit].state == OPENED) {
1471 /* If LCP is not already going down, make sure it does. */
1472 error("MPPE disabled");
1473 lcp_close(f->unit, "MPPE disabled");
1480 * Print the contents of a CCP packet.
1482 static char *ccp_codenames[] = {
1483 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1484 "TermReq", "TermAck", "CodeRej",
1485 NULL, NULL, NULL, NULL, NULL, NULL,
1486 "ResetReq", "ResetAck",
1490 ccp_printpkt(p, plen, printer, arg)
1493 void (*printer) __P((void *, char *, ...));
1496 u_char *p0, *optend;
1501 if (plen < HEADERLEN)
1505 len = (p[2] << 8) + p[3];
1506 if (len < HEADERLEN || len > plen)
1509 if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
1510 && ccp_codenames[code-1] != NULL)
1511 printer(arg, " %s", ccp_codenames[code-1]);
1513 printer(arg, " code=0x%x", code);
1514 printer(arg, " id=0x%x", id);
1523 /* print list of possible compression methods */
1527 if (optlen < 2 || optlen > len)
1531 optend = p + optlen;
1535 if (optlen >= CILEN_MPPE) {
1538 MPPE_CI_TO_OPTS(&p[2], mppe_opts);
1539 printer(arg, "mppe %s %s %s %s %s %s%s",
1540 (p[2] & MPPE_H_BIT)? "+H": "-H",
1541 (p[5] & MPPE_M_BIT)? "+M": "-M",
1542 (p[5] & MPPE_S_BIT)? "+S": "-S",
1543 (p[5] & MPPE_L_BIT)? "+L": "-L",
1544 (p[5] & MPPE_D_BIT)? "+D": "-D",
1545 (p[5] & MPPE_C_BIT)? "+C": "-C",
1546 (mppe_opts & MPPE_OPT_UNKNOWN)? " +U": "");
1547 if (mppe_opts & MPPE_OPT_UNKNOWN)
1548 printer(arg, " (%.2x %.2x %.2x %.2x)",
1549 p[2], p[3], p[4], p[5]);
1555 case CI_DEFLATE_DRAFT:
1556 if (optlen >= CILEN_DEFLATE) {
1557 printer(arg, "deflate%s %d",
1558 (code == CI_DEFLATE_DRAFT? "(old#)": ""),
1559 DEFLATE_SIZE(p[2]));
1560 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
1561 printer(arg, " method %d", DEFLATE_METHOD(p[2]));
1562 if (p[3] != DEFLATE_CHK_SEQUENCE)
1563 printer(arg, " check %d", p[3]);
1567 case CI_BSD_COMPRESS:
1568 if (optlen >= CILEN_BSD_COMPRESS) {
1569 printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
1571 p += CILEN_BSD_COMPRESS;
1574 case CI_PREDICTOR_1:
1575 if (optlen >= CILEN_PREDICTOR_1) {
1576 printer(arg, "predictor 1");
1577 p += CILEN_PREDICTOR_1;
1580 case CI_PREDICTOR_2:
1581 if (optlen >= CILEN_PREDICTOR_2) {
1582 printer(arg, "predictor 2");
1583 p += CILEN_PREDICTOR_2;
1588 printer(arg, " %.2x", *p++);
1595 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1596 print_string((char *)p, len, printer, arg);
1603 /* dump out the rest of the packet in hex */
1605 printer(arg, " %.2x", *p++);
1611 * We have received a packet that the decompressor failed to
1612 * decompress. Here we would expect to issue a reset-request, but
1613 * Motorola has a patent on resetting the compressor as a result of
1614 * detecting an error in the decompressed data after decompression.
1615 * (See US patent 5,130,993; international patent publication number
1616 * WO 91/10289; Australian patent 73296/91.)
1618 * So we ask the kernel whether the error was detected after
1619 * decompression; if it was, we take CCP down, thus disabling
1620 * compression :-(, otherwise we issue the reset-request.
1623 ccp_datainput(unit, pkt, len)
1631 if (f->state == OPENED) {
1632 if (ccp_fatal_error(unit)) {
1634 * Disable compression by taking CCP down.
1636 error("Lost compression sync: disabling compression");
1637 ccp_close(unit, "Lost compression sync");
1640 * If we were doing MPPE, we must also take the link down.
1642 if (ccp_gotoptions[unit].mppe) {
1643 error("Too many MPPE errors, closing LCP");
1644 lcp_close(unit, "Too many MPPE errors");
1649 * Send a reset-request to reset the peer's compressor.
1650 * We don't do that if we are still waiting for an
1651 * acknowledgement to a previous reset-request.
1653 if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
1654 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1655 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1656 ccp_localstate[f->unit] |= RACK_PENDING;
1658 ccp_localstate[f->unit] |= RREQ_REPEAT;
1664 * Timeout waiting for reset-ack.
1667 ccp_rack_timeout(arg)
1672 if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
1673 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1674 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1675 ccp_localstate[f->unit] &= ~RREQ_REPEAT;
1677 ccp_localstate[f->unit] &= ~RACK_PENDING;