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 */
48 * Unfortunately there is a bug in zlib which means that using a
49 * size of 8 (window size = 256) for Deflate compression will cause
50 * buffer overruns and kernel crashes in the deflate module.
51 * Until this is fixed we only accept sizes in the range 9 .. 15.
52 * Thanks to James Carlson for pointing this out.
54 #define DEFLATE_MIN_WORKS 9
57 * Command-line options.
59 static int setbsdcomp __P((char **));
60 static int setdeflate __P((char **));
61 static char bsd_value[8];
62 static char deflate_value[8];
68 bool refuse_mppe_stateful = 1; /* Allow stateful mode? */
71 static option_t ccp_option_list[] = {
72 { "noccp", o_bool, &ccp_protent.enabled_flag,
73 "Disable CCP negotiation" },
74 { "-ccp", o_bool, &ccp_protent.enabled_flag,
75 "Disable CCP negotiation", OPT_ALIAS },
77 { "bsdcomp", o_special, (void *)setbsdcomp,
78 "Request BSD-Compress packet compression",
79 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, bsd_value },
80 { "nobsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
81 "don't allow BSD-Compress", OPT_PRIOSUB | OPT_A2CLR,
82 &ccp_allowoptions[0].bsd_compress },
83 { "-bsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
84 "don't allow BSD-Compress", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
85 &ccp_allowoptions[0].bsd_compress },
87 { "deflate", o_special, (void *)setdeflate,
88 "request Deflate compression",
89 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, deflate_value },
90 { "nodeflate", o_bool, &ccp_wantoptions[0].deflate,
91 "don't allow Deflate compression", OPT_PRIOSUB | OPT_A2CLR,
92 &ccp_allowoptions[0].deflate },
93 { "-deflate", o_bool, &ccp_wantoptions[0].deflate,
94 "don't allow Deflate compression", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
95 &ccp_allowoptions[0].deflate },
97 { "nodeflatedraft", o_bool, &ccp_wantoptions[0].deflate_draft,
98 "don't use draft deflate #", OPT_A2COPY,
99 &ccp_allowoptions[0].deflate_draft },
101 { "predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
102 "request Predictor-1", OPT_PRIO | 1 },
103 { "nopredictor1", o_bool, &ccp_wantoptions[0].predictor_1,
104 "don't allow Predictor-1", OPT_PRIOSUB | OPT_A2CLR,
105 &ccp_allowoptions[0].predictor_1 },
106 { "-predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
107 "don't allow Predictor-1", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
108 &ccp_allowoptions[0].predictor_1 },
111 /* MPPE options are symmetrical ... we only set wantoptions here */
112 { "require-mppe", o_bool, &ccp_wantoptions[0].mppe,
113 "require MPPE encryption",
114 OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
115 { "+mppe", o_bool, &ccp_wantoptions[0].mppe,
116 "require MPPE encryption",
117 OPT_ALIAS | OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
118 { "nomppe", o_bool, &ccp_wantoptions[0].mppe,
119 "don't allow MPPE encryption", OPT_PRIO },
120 { "-mppe", o_bool, &ccp_wantoptions[0].mppe,
121 "don't allow MPPE encryption", OPT_ALIAS | OPT_PRIO },
123 /* We use ccp_allowoptions[0].mppe as a junk var ... it is reset later */
124 { "require-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
125 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
126 &ccp_wantoptions[0].mppe },
127 { "+mppe-40", o_bool, &ccp_allowoptions[0].mppe,
128 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
129 &ccp_wantoptions[0].mppe },
130 { "nomppe-40", o_bool, &ccp_allowoptions[0].mppe,
131 "don't allow MPPE 40-bit encryption",
132 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40, &ccp_wantoptions[0].mppe },
133 { "-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
134 "don't allow MPPE 40-bit encryption",
135 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40,
136 &ccp_wantoptions[0].mppe },
138 { "require-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
139 "require MPPE 128-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
140 &ccp_wantoptions[0].mppe },
141 { "+mppe-128", o_bool, &ccp_allowoptions[0].mppe,
142 "require MPPE 128-bit encryption",
143 OPT_ALIAS | OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
144 &ccp_wantoptions[0].mppe },
145 { "nomppe-128", o_bool, &ccp_allowoptions[0].mppe,
146 "don't allow MPPE 128-bit encryption",
147 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128, &ccp_wantoptions[0].mppe },
148 { "-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
149 "don't allow MPPE 128-bit encryption",
150 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128,
151 &ccp_wantoptions[0].mppe },
153 /* strange one; we always request stateless, but will we allow stateful? */
154 { "mppe-stateful", o_bool, &refuse_mppe_stateful,
155 "allow MPPE stateful mode", OPT_PRIO },
156 { "nomppe-stateful", o_bool, &refuse_mppe_stateful,
157 "disallow MPPE stateful mode", OPT_PRIO | 1 },
164 * Protocol entry points from main code.
166 static void ccp_init __P((int unit));
167 static void ccp_open __P((int unit));
168 static void ccp_close __P((int unit, char *));
169 static void ccp_lowerup __P((int unit));
170 static void ccp_lowerdown __P((int));
171 static void ccp_input __P((int unit, u_char *pkt, int len));
172 static void ccp_protrej __P((int unit));
173 static int ccp_printpkt __P((u_char *pkt, int len,
174 void (*printer) __P((void *, char *, ...)),
176 static void ccp_datainput __P((int unit, u_char *pkt, int len));
178 struct protent ccp_protent = {
198 fsm ccp_fsm[NUM_PPP];
199 ccp_options ccp_wantoptions[NUM_PPP]; /* what to request the peer to use */
200 ccp_options ccp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
201 ccp_options ccp_allowoptions[NUM_PPP]; /* what we'll agree to do */
202 ccp_options ccp_hisoptions[NUM_PPP]; /* what we agreed to do */
205 * Callbacks for fsm code.
207 static void ccp_resetci __P((fsm *));
208 static int ccp_cilen __P((fsm *));
209 static void ccp_addci __P((fsm *, u_char *, int *));
210 static int ccp_ackci __P((fsm *, u_char *, int));
211 static int ccp_nakci __P((fsm *, u_char *, int, int));
212 static int ccp_rejci __P((fsm *, u_char *, int));
213 static int ccp_reqci __P((fsm *, u_char *, int *, int));
214 static void ccp_up __P((fsm *));
215 static void ccp_down __P((fsm *));
216 static int ccp_extcode __P((fsm *, int, int, u_char *, int));
217 static void ccp_rack_timeout __P((void *));
218 static char *method_name __P((ccp_options *, ccp_options *));
220 static fsm_callbacks ccp_callbacks = {
239 * Do we want / did we get any compression?
241 #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
242 || (opt).predictor_1 || (opt).predictor_2 \
246 * Local state (mainly for handling reset-reqs and reset-acks).
248 static int ccp_localstate[NUM_PPP];
249 #define RACK_PENDING 1 /* waiting for reset-ack */
250 #define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
252 #define RACKTIMEOUT 1 /* second */
254 static int all_rejected[NUM_PPP]; /* we rejected all peer's options */
267 abits = rbits = strtol(str, &endp, 0);
268 if (endp != str && *endp == ',') {
270 abits = strtol(str, &endp, 0);
272 if (*endp != 0 || endp == str) {
273 option_error("invalid parameter '%s' for bsdcomp option", *argv);
276 if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
277 || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
278 option_error("bsdcomp option values must be 0 or %d .. %d",
279 BSD_MIN_BITS, BSD_MAX_BITS);
283 ccp_wantoptions[0].bsd_compress = 1;
284 ccp_wantoptions[0].bsd_bits = rbits;
286 ccp_wantoptions[0].bsd_compress = 0;
288 ccp_allowoptions[0].bsd_compress = 1;
289 ccp_allowoptions[0].bsd_bits = abits;
291 ccp_allowoptions[0].bsd_compress = 0;
292 slprintf(bsd_value, sizeof(bsd_value),
293 rbits == abits? "%d": "%d,%d", rbits, abits);
306 abits = rbits = strtol(str, &endp, 0);
307 if (endp != str && *endp == ',') {
309 abits = strtol(str, &endp, 0);
311 if (*endp != 0 || endp == str) {
312 option_error("invalid parameter '%s' for deflate option", *argv);
315 if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
316 || (abits != 0 && (abits < DEFLATE_MIN_SIZE
317 || abits > DEFLATE_MAX_SIZE))) {
318 option_error("deflate option values must be 0 or %d .. %d",
319 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
322 if (rbits == DEFLATE_MIN_SIZE || abits == DEFLATE_MIN_SIZE) {
323 if (rbits == DEFLATE_MIN_SIZE)
324 rbits = DEFLATE_MIN_WORKS;
325 if (abits == DEFLATE_MIN_SIZE)
326 abits = DEFLATE_MIN_WORKS;
327 warn("deflate option value of %d changed to %d to avoid zlib bug",
328 DEFLATE_MIN_SIZE, DEFLATE_MIN_WORKS);
331 ccp_wantoptions[0].deflate = 1;
332 ccp_wantoptions[0].deflate_size = rbits;
334 ccp_wantoptions[0].deflate = 0;
336 ccp_allowoptions[0].deflate = 1;
337 ccp_allowoptions[0].deflate_size = abits;
339 ccp_allowoptions[0].deflate = 0;
340 slprintf(deflate_value, sizeof(deflate_value),
341 rbits == abits? "%d": "%d,%d", rbits, abits);
347 * ccp_init - initialize CCP.
353 fsm *f = &ccp_fsm[unit];
356 f->protocol = PPP_CCP;
357 f->callbacks = &ccp_callbacks;
360 memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
361 memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
362 memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
363 memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
365 ccp_wantoptions[0].deflate = 1;
366 ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
367 ccp_wantoptions[0].deflate_correct = 1;
368 ccp_wantoptions[0].deflate_draft = 1;
369 ccp_allowoptions[0].deflate = 1;
370 ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
371 ccp_allowoptions[0].deflate_correct = 1;
372 ccp_allowoptions[0].deflate_draft = 1;
374 ccp_wantoptions[0].bsd_compress = 1;
375 ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
376 ccp_allowoptions[0].bsd_compress = 1;
377 ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
379 ccp_allowoptions[0].predictor_1 = 1;
383 * ccp_open - CCP is allowed to come up.
389 fsm *f = &ccp_fsm[unit];
391 if (f->state != OPENED)
392 ccp_flags_set(unit, 1, 0);
395 * Find out which compressors the kernel supports before
396 * deciding whether to open in silent mode.
399 if (!ANY_COMPRESS(ccp_gotoptions[unit]))
400 f->flags |= OPT_SILENT;
406 * ccp_close - Terminate CCP.
409 ccp_close(unit, reason)
413 ccp_flags_set(unit, 0, 0);
414 fsm_close(&ccp_fsm[unit], reason);
418 * ccp_lowerup - we may now transmit CCP packets.
424 fsm_lowerup(&ccp_fsm[unit]);
428 * ccp_lowerdown - we may not transmit CCP packets.
434 fsm_lowerdown(&ccp_fsm[unit]);
438 * ccp_input - process a received CCP packet.
441 ccp_input(unit, p, len)
446 fsm *f = &ccp_fsm[unit];
450 * Check for a terminate-request so we can print a message.
453 fsm_input(f, p, len);
454 if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED) {
455 notice("Compression disabled by peer.");
457 if (ccp_gotoptions[unit].mppe) {
458 error("MPPE disabled, closing LCP");
459 lcp_close(unit, "MPPE disabled by peer");
465 * If we get a terminate-ack and we're not asking for compression,
468 if (oldstate == REQSENT && p[0] == TERMACK
469 && !ANY_COMPRESS(ccp_gotoptions[unit]))
470 ccp_close(unit, "No compression negotiated");
474 * Handle a CCP-specific code.
477 ccp_extcode(f, code, id, p, len)
485 if (f->state != OPENED)
487 /* send a reset-ack, which the transmitter will see and
488 reset its compression state. */
489 fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
493 if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
494 ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
495 UNTIMEOUT(ccp_rack_timeout, f);
507 * ccp_protrej - peer doesn't talk CCP.
513 ccp_flags_set(unit, 0, 0);
514 fsm_lowerdown(&ccp_fsm[unit]);
517 if (ccp_gotoptions[unit].mppe) {
518 error("MPPE required but peer negotiation failed");
519 lcp_close(unit, "MPPE required but peer negotiation failed");
526 * ccp_resetci - initialize at start of negotiation.
532 ccp_options *go = &ccp_gotoptions[f->unit];
533 u_char opt_buf[CCP_MAX_OPTION_LENGTH];
535 *go = ccp_wantoptions[f->unit];
536 all_rejected[f->unit] = 0;
540 ccp_options *ao = &ccp_allowoptions[f->unit];
541 int auth_mschap_bits = auth_done[f->unit];
545 * Start with a basic sanity check: mschap[v2] auth must be in
546 * exactly one direction. RFC 3079 says that the keys are
547 * 'derived from the credentials of the peer that initiated the call',
548 * however the PPP protocol doesn't have such a concept, and pppd
549 * cannot get this info externally. Instead we do the best we can.
550 * NB: If MPPE is required, all other compression opts are invalid.
551 * So, we return right away if we can't do it.
554 /* Leave only the mschap auth bits set */
555 auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
556 CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
557 /* Count the mschap auths */
558 auth_mschap_bits >>= CHAP_MS_SHIFT;
561 numbits += auth_mschap_bits & 1;
562 auth_mschap_bits >>= 1;
563 } while (auth_mschap_bits);
565 error("MPPE required, but auth done in both directions.");
566 lcp_close(f->unit, "MPPE required but not available");
570 error("MPPE required, but MS-CHAP[v2] auth not performed.");
571 lcp_close(f->unit, "MPPE required but not available");
575 /* A plugin (eg radius) may not have obtained key material. */
576 if (!mppe_keys_set) {
577 error("MPPE required, but keys are not available. "
578 "Possible plugin problem?");
579 lcp_close(f->unit, "MPPE required but not available");
583 /* LM auth not supported for MPPE */
584 if (auth_done[f->unit] & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) {
585 /* This might be noise */
586 if (go->mppe & MPPE_OPT_40) {
587 notice("Disabling 40-bit MPPE; MS-CHAP LM not supported");
588 go->mppe &= ~MPPE_OPT_40;
589 ccp_wantoptions[f->unit].mppe &= ~MPPE_OPT_40;
593 /* Last check: can we actually negotiate something? */
594 if (!(go->mppe & (MPPE_OPT_40 | MPPE_OPT_128))) {
595 /* Could be misconfig, could be 40-bit disabled above. */
596 error("MPPE required, but both 40-bit and 128-bit disabled.");
597 lcp_close(f->unit, "MPPE required but not available");
603 /* MPPE is not compatible with other compression types */
604 ao->bsd_compress = go->bsd_compress = 0;
605 ao->predictor_1 = go->predictor_1 = 0;
606 ao->predictor_2 = go->predictor_2 = 0;
607 ao->deflate = go->deflate = 0;
612 * Check whether the kernel knows about the various
613 * compression methods we might request.
617 opt_buf[0] = CI_MPPE;
618 opt_buf[1] = CILEN_MPPE;
619 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
620 /* Key material unimportant here. */
621 if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0) {
622 error("MPPE required, but kernel has no support.");
623 lcp_close(f->unit, "MPPE required but not available");
627 if (go->bsd_compress) {
628 opt_buf[0] = CI_BSD_COMPRESS;
629 opt_buf[1] = CILEN_BSD_COMPRESS;
630 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
631 if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
632 go->bsd_compress = 0;
635 if (go->deflate_correct) {
636 opt_buf[0] = CI_DEFLATE;
637 opt_buf[1] = CILEN_DEFLATE;
638 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
639 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
640 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
641 go->deflate_correct = 0;
643 if (go->deflate_draft) {
644 opt_buf[0] = CI_DEFLATE_DRAFT;
645 opt_buf[1] = CILEN_DEFLATE;
646 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
647 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
648 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
649 go->deflate_draft = 0;
651 if (!go->deflate_correct && !go->deflate_draft)
654 if (go->predictor_1) {
655 opt_buf[0] = CI_PREDICTOR_1;
656 opt_buf[1] = CILEN_PREDICTOR_1;
657 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
660 if (go->predictor_2) {
661 opt_buf[0] = CI_PREDICTOR_2;
662 opt_buf[1] = CILEN_PREDICTOR_2;
663 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
669 * ccp_cilen - Return total length of our configuration info.
675 ccp_options *go = &ccp_gotoptions[f->unit];
677 return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
678 + (go->deflate && go->deflate_correct? CILEN_DEFLATE: 0)
679 + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0)
680 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
681 + (go->predictor_2? CILEN_PREDICTOR_2: 0)
682 + (go->mppe? CILEN_MPPE: 0);
686 * ccp_addci - put our requests in a packet.
689 ccp_addci(f, p, lenp)
695 ccp_options *go = &ccp_gotoptions[f->unit];
699 * Add the compression types that we can receive, in decreasing
700 * preference order. Get the kernel to allocate the first one
701 * in case it gets Acked.
705 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
707 p[0] = opt_buf[0] = CI_MPPE;
708 p[1] = opt_buf[1] = CILEN_MPPE;
709 MPPE_OPTS_TO_CI(go->mppe, &p[2]);
710 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
711 BCOPY(mppe_recv_key, &opt_buf[CILEN_MPPE], MPPE_MAX_KEY_LEN);
712 res = ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0);
716 /* This shouldn't happen, we've already tested it! */
717 lcp_close(f->unit, "MPPE required but not available in kernel");
721 p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
722 p[1] = CILEN_DEFLATE;
723 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
724 p[3] = DEFLATE_CHK_SEQUENCE;
729 if (go->deflate_size < DEFLATE_MIN_WORKS) {
733 res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
737 } else if (res < 0) {
742 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
745 if (p != p0 && go->deflate_correct && go->deflate_draft) {
746 p[0] = CI_DEFLATE_DRAFT;
747 p[1] = CILEN_DEFLATE;
748 p[2] = p[2 - CILEN_DEFLATE];
749 p[3] = DEFLATE_CHK_SEQUENCE;
753 if (go->bsd_compress) {
754 p[0] = CI_BSD_COMPRESS;
755 p[1] = CILEN_BSD_COMPRESS;
756 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
758 p += CILEN_BSD_COMPRESS; /* not the first option */
761 if (go->bsd_bits < BSD_MIN_BITS) {
762 go->bsd_compress = 0;
765 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
767 p += CILEN_BSD_COMPRESS;
769 } else if (res < 0) {
770 go->bsd_compress = 0;
774 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
778 /* XXX Should Predictor 2 be preferable to Predictor 1? */
779 if (go->predictor_1) {
780 p[0] = CI_PREDICTOR_1;
781 p[1] = CILEN_PREDICTOR_1;
782 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
785 p += CILEN_PREDICTOR_1;
788 if (go->predictor_2) {
789 p[0] = CI_PREDICTOR_2;
790 p[1] = CILEN_PREDICTOR_2;
791 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
794 p += CILEN_PREDICTOR_2;
798 go->method = (p > p0)? p0[0]: -1;
804 * ccp_ackci - process a received configure-ack, and return
805 * 1 iff the packet was OK.
813 ccp_options *go = &ccp_gotoptions[f->unit];
818 u_char opt_buf[CILEN_MPPE];
820 opt_buf[0] = CI_MPPE;
821 opt_buf[1] = CILEN_MPPE;
822 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
823 if (len < CILEN_MPPE || memcmp(opt_buf, p, CILEN_MPPE))
827 /* XXX Cope with first/fast ack */
833 if (len < CILEN_DEFLATE
834 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
835 || p[1] != CILEN_DEFLATE
836 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
837 || p[3] != DEFLATE_CHK_SEQUENCE)
840 len -= CILEN_DEFLATE;
841 /* XXX Cope with first/fast ack */
844 if (go->deflate_correct && go->deflate_draft) {
845 if (len < CILEN_DEFLATE
846 || p[0] != CI_DEFLATE_DRAFT
847 || p[1] != CILEN_DEFLATE
848 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
849 || p[3] != DEFLATE_CHK_SEQUENCE)
852 len -= CILEN_DEFLATE;
855 if (go->bsd_compress) {
856 if (len < CILEN_BSD_COMPRESS
857 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
858 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
860 p += CILEN_BSD_COMPRESS;
861 len -= CILEN_BSD_COMPRESS;
862 /* XXX Cope with first/fast ack */
863 if (p == p0 && len == 0)
866 if (go->predictor_1) {
867 if (len < CILEN_PREDICTOR_1
868 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
870 p += CILEN_PREDICTOR_1;
871 len -= CILEN_PREDICTOR_1;
872 /* XXX Cope with first/fast ack */
873 if (p == p0 && len == 0)
876 if (go->predictor_2) {
877 if (len < CILEN_PREDICTOR_2
878 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
880 p += CILEN_PREDICTOR_2;
881 len -= CILEN_PREDICTOR_2;
882 /* XXX Cope with first/fast ack */
883 if (p == p0 && len == 0)
893 * ccp_nakci - process received configure-nak.
894 * Returns 1 iff the nak was OK.
897 ccp_nakci(f, p, len, treat_as_reject)
903 ccp_options *go = &ccp_gotoptions[f->unit];
904 ccp_options no; /* options we've seen already */
905 ccp_options try; /* options to ask for next time */
907 memset(&no, 0, sizeof(no));
911 if (go->mppe && len >= CILEN_MPPE
912 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
915 * Peer wants us to use a different strength or other setting.
916 * Fail if we aren't willing to use his suggestion.
918 MPPE_CI_TO_OPTS(&p[2], try.mppe);
919 if ((try.mppe & MPPE_OPT_STATEFUL) && refuse_mppe_stateful) {
920 error("Refusing MPPE stateful mode offered by peer");
922 } else if (((go->mppe | MPPE_OPT_STATEFUL) & try.mppe) != try.mppe) {
923 /* Peer must have set options we didn't request (suggest) */
928 error("MPPE required but peer negotiation failed");
929 lcp_close(f->unit, "MPPE required but peer negotiation failed");
933 if (go->deflate && len >= CILEN_DEFLATE
934 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
935 && p[1] == CILEN_DEFLATE) {
938 * Peer wants us to use a different code size or something.
939 * Stop asking for Deflate if we don't understand his suggestion.
941 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
942 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_WORKS
943 || p[3] != DEFLATE_CHK_SEQUENCE)
945 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
946 try.deflate_size = DEFLATE_SIZE(p[2]);
948 len -= CILEN_DEFLATE;
949 if (go->deflate_correct && go->deflate_draft
950 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
951 && p[1] == CILEN_DEFLATE) {
953 len -= CILEN_DEFLATE;
957 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
958 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
961 * Peer wants us to use a different number of bits
962 * or a different version.
964 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
965 try.bsd_compress = 0;
966 else if (BSD_NBITS(p[2]) < go->bsd_bits)
967 try.bsd_bits = BSD_NBITS(p[2]);
968 p += CILEN_BSD_COMPRESS;
969 len -= CILEN_BSD_COMPRESS;
973 * Predictor-1 and 2 have no options, so they can't be Naked.
975 * There may be remaining options but we ignore them.
978 if (f->state != OPENED)
984 * ccp_rejci - reject some of our suggested compression methods.
992 ccp_options *go = &ccp_gotoptions[f->unit];
993 ccp_options try; /* options to request next time */
998 * Cope with empty configure-rejects by ceasing to send
999 * configure-requests.
1001 if (len == 0 && all_rejected[f->unit])
1005 if (go->mppe && len >= CILEN_MPPE
1006 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
1007 error("MPPE required but peer refused");
1008 lcp_close(f->unit, "MPPE required but peer refused");
1013 if (go->deflate_correct && len >= CILEN_DEFLATE
1014 && p[0] == CI_DEFLATE && p[1] == CILEN_DEFLATE) {
1015 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1016 || p[3] != DEFLATE_CHK_SEQUENCE)
1017 return 0; /* Rej is bad */
1018 try.deflate_correct = 0;
1020 len -= CILEN_DEFLATE;
1022 if (go->deflate_draft && len >= CILEN_DEFLATE
1023 && p[0] == CI_DEFLATE_DRAFT && p[1] == CILEN_DEFLATE) {
1024 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1025 || p[3] != DEFLATE_CHK_SEQUENCE)
1026 return 0; /* Rej is bad */
1027 try.deflate_draft = 0;
1029 len -= CILEN_DEFLATE;
1031 if (!try.deflate_correct && !try.deflate_draft)
1033 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
1034 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
1035 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
1037 try.bsd_compress = 0;
1038 p += CILEN_BSD_COMPRESS;
1039 len -= CILEN_BSD_COMPRESS;
1041 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
1042 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
1043 try.predictor_1 = 0;
1044 p += CILEN_PREDICTOR_1;
1045 len -= CILEN_PREDICTOR_1;
1047 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
1048 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
1049 try.predictor_2 = 0;
1050 p += CILEN_PREDICTOR_2;
1051 len -= CILEN_PREDICTOR_2;
1057 if (f->state != OPENED)
1064 * ccp_reqci - processed a received configure-request.
1065 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
1069 ccp_reqci(f, p, lenp, dont_nak)
1075 int ret, newret, res;
1077 int len, clen, type, nb;
1078 ccp_options *ho = &ccp_hisoptions[f->unit];
1079 ccp_options *ao = &ccp_allowoptions[f->unit];
1081 bool rej_for_ci_mppe = 1; /* Are we rejecting based on a bad/missing */
1082 /* CI_MPPE, or due to other options? */
1089 memset(ho, 0, sizeof(ccp_options));
1090 ho->method = (len > 0)? p[0]: -1;
1094 if (len < 2 || p[1] < 2 || p[1] > len) {
1106 if (!ao->mppe || clen != CILEN_MPPE) {
1110 MPPE_CI_TO_OPTS(&p[2], ho->mppe);
1112 /* Nak if anything unsupported or unknown are set. */
1113 if (ho->mppe & MPPE_OPT_UNSUPPORTED) {
1115 ho->mppe &= ~MPPE_OPT_UNSUPPORTED;
1117 if (ho->mppe & MPPE_OPT_UNKNOWN) {
1119 ho->mppe &= ~MPPE_OPT_UNKNOWN;
1122 /* Check state opt */
1123 if (ho->mppe & MPPE_OPT_STATEFUL) {
1125 * We can Nak and request stateless, but it's a
1126 * lot easier to just assume the peer will request
1127 * it if he can do it; stateful mode is bad over
1128 * the Internet -- which is where we expect MPPE.
1130 if (refuse_mppe_stateful) {
1131 error("Refusing MPPE stateful mode offered by peer");
1137 /* Find out which of {S,L} are set. */
1138 if ((ho->mppe & MPPE_OPT_128)
1139 && (ho->mppe & MPPE_OPT_40)) {
1140 /* Both are set, negotiate the strongest. */
1142 if (ao->mppe & MPPE_OPT_128)
1143 ho->mppe &= ~MPPE_OPT_40;
1144 else if (ao->mppe & MPPE_OPT_40)
1145 ho->mppe &= ~MPPE_OPT_128;
1150 } else if (ho->mppe & MPPE_OPT_128) {
1151 if (!(ao->mppe & MPPE_OPT_128)) {
1155 } else if (ho->mppe & MPPE_OPT_40) {
1156 if (!(ao->mppe & MPPE_OPT_40)) {
1161 /* Neither are set. */
1162 /* We cannot accept this. */
1164 /* Give the peer our idea of what can be used,
1165 so it can choose and confirm */
1166 ho->mppe = ao->mppe;
1169 /* rebuild the opts */
1170 MPPE_OPTS_TO_CI(ho->mppe, &p[2]);
1171 if (newret == CONFACK) {
1172 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
1175 BCOPY(p, opt_buf, CILEN_MPPE);
1176 BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
1178 if (ccp_test(f->unit, opt_buf,
1179 CILEN_MPPE + MPPE_MAX_KEY_LEN, 1) <= 0) {
1180 /* This shouldn't happen, we've already tested it! */
1181 error("MPPE required, but kernel has no support.");
1182 lcp_close(f->unit, "MPPE required but not available");
1187 * We need to decrease the interface MTU by MPPE_PAD
1188 * because MPPE frames **grow**. The kernel [must]
1189 * allocate MPPE_PAD extra bytes in xmit buffers.
1191 mtu = netif_get_mtu(f->unit);
1193 netif_set_mtu(f->unit, mtu - MPPE_PAD);
1199 * We have accepted MPPE or are willing to negotiate
1200 * MPPE parameters. A CONFREJ is due to subsequent
1201 * (non-MPPE) processing.
1203 rej_for_ci_mppe = 0;
1207 case CI_DEFLATE_DRAFT:
1208 if (!ao->deflate || clen != CILEN_DEFLATE
1209 || (!ao->deflate_correct && type == CI_DEFLATE)
1210 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
1216 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
1217 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
1218 || p[3] != DEFLATE_CHK_SEQUENCE
1219 || nb > ao->deflate_size || nb < DEFLATE_MIN_WORKS) {
1222 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
1223 p[3] = DEFLATE_CHK_SEQUENCE;
1224 /* fall through to test this #bits below */
1230 * Check whether we can do Deflate with the window
1231 * size they want. If the window is too big, reduce
1232 * it until the kernel can cope and nak with that.
1233 * We only check this for the first option.
1237 res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
1239 break; /* it's OK now */
1240 if (res < 0 || nb == DEFLATE_MIN_WORKS || dont_nak) {
1242 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
1247 p[2] = DEFLATE_MAKE_OPT(nb);
1252 case CI_BSD_COMPRESS:
1253 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
1258 ho->bsd_compress = 1;
1259 ho->bsd_bits = nb = BSD_NBITS(p[2]);
1260 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
1261 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
1264 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
1265 /* fall through to test this #bits below */
1271 * Check whether we can do BSD-Compress with the code
1272 * size they want. If the code size is too big, reduce
1273 * it until the kernel can cope and nak with that.
1274 * We only check this for the first option.
1278 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
1281 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
1283 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
1289 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
1294 case CI_PREDICTOR_1:
1295 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
1300 ho->predictor_1 = 1;
1302 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
1307 case CI_PREDICTOR_2:
1308 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
1313 ho->predictor_2 = 1;
1315 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
1325 if (newret == CONFNAK && dont_nak)
1327 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
1328 /* we're returning this option */
1329 if (newret == CONFREJ && ret == CONFNAK)
1333 BCOPY(p, retp, clen);
1341 if (ret != CONFACK) {
1342 if (ret == CONFREJ && *lenp == retp - p0)
1343 all_rejected[f->unit] = 1;
1348 if (ret == CONFREJ && ao->mppe && rej_for_ci_mppe) {
1349 error("MPPE required but peer negotiation failed");
1350 lcp_close(f->unit, "MPPE required but peer negotiation failed");
1357 * Make a string name for a compression method (or 2).
1360 method_name(opt, opt2)
1361 ccp_options *opt, *opt2;
1363 static char result[64];
1365 if (!ANY_COMPRESS(*opt))
1367 switch (opt->method) {
1372 char *q = result + sizeof(result); /* 1 past result */
1374 slprintf(p, q - p, "MPPE ");
1376 if (opt->mppe & MPPE_OPT_128) {
1377 slprintf(p, q - p, "128-bit ");
1380 if (opt->mppe & MPPE_OPT_40) {
1381 slprintf(p, q - p, "40-bit ");
1384 if (opt->mppe & MPPE_OPT_STATEFUL)
1385 slprintf(p, q - p, "stateful");
1387 slprintf(p, q - p, "stateless");
1393 case CI_DEFLATE_DRAFT:
1394 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
1395 slprintf(result, sizeof(result), "Deflate%s (%d/%d)",
1396 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1397 opt->deflate_size, opt2->deflate_size);
1399 slprintf(result, sizeof(result), "Deflate%s (%d)",
1400 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1403 case CI_BSD_COMPRESS:
1404 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
1405 slprintf(result, sizeof(result), "BSD-Compress (%d/%d)",
1406 opt->bsd_bits, opt2->bsd_bits);
1408 slprintf(result, sizeof(result), "BSD-Compress (%d)",
1411 case CI_PREDICTOR_1:
1412 return "Predictor 1";
1413 case CI_PREDICTOR_2:
1414 return "Predictor 2";
1416 slprintf(result, sizeof(result), "Method %d", opt->method);
1422 * CCP has come up - inform the kernel driver and log a message.
1428 ccp_options *go = &ccp_gotoptions[f->unit];
1429 ccp_options *ho = &ccp_hisoptions[f->unit];
1432 ccp_flags_set(f->unit, 1, 1);
1433 if (ANY_COMPRESS(*go)) {
1434 if (ANY_COMPRESS(*ho)) {
1435 if (go->method == ho->method) {
1436 notice("%s compression enabled", method_name(go, ho));
1438 strlcpy(method1, method_name(go, NULL), sizeof(method1));
1439 notice("%s / %s compression enabled",
1440 method1, method_name(ho, NULL));
1443 notice("%s receive compression enabled", method_name(go, NULL));
1444 } else if (ANY_COMPRESS(*ho))
1445 notice("%s transmit compression enabled", method_name(ho, NULL));
1448 BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN);
1449 BZERO(mppe_send_key, MPPE_MAX_KEY_LEN);
1450 continue_networks(f->unit); /* Bring up IP et al */
1456 * CCP has gone down - inform the kernel driver.
1462 if (ccp_localstate[f->unit] & RACK_PENDING)
1463 UNTIMEOUT(ccp_rack_timeout, f);
1464 ccp_localstate[f->unit] = 0;
1465 ccp_flags_set(f->unit, 1, 0);
1467 if (ccp_gotoptions[f->unit].mppe) {
1468 ccp_gotoptions[f->unit].mppe = 0;
1469 if (lcp_fsm[f->unit].state == OPENED) {
1470 /* If LCP is not already going down, make sure it does. */
1471 error("MPPE disabled");
1472 lcp_close(f->unit, "MPPE disabled");
1479 * Print the contents of a CCP packet.
1481 static char *ccp_codenames[] = {
1482 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1483 "TermReq", "TermAck", "CodeRej",
1484 NULL, NULL, NULL, NULL, NULL, NULL,
1485 "ResetReq", "ResetAck",
1489 ccp_printpkt(p, plen, printer, arg)
1492 void (*printer) __P((void *, char *, ...));
1495 u_char *p0, *optend;
1500 if (plen < HEADERLEN)
1504 len = (p[2] << 8) + p[3];
1505 if (len < HEADERLEN || len > plen)
1508 if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
1509 && ccp_codenames[code-1] != NULL)
1510 printer(arg, " %s", ccp_codenames[code-1]);
1512 printer(arg, " code=0x%x", code);
1513 printer(arg, " id=0x%x", id);
1522 /* print list of possible compression methods */
1526 if (optlen < 2 || optlen > len)
1530 optend = p + optlen;
1534 if (optlen >= CILEN_MPPE) {
1537 MPPE_CI_TO_OPTS(&p[2], mppe_opts);
1538 printer(arg, "mppe %s %s %s %s %s %s%s",
1539 (p[2] & MPPE_H_BIT)? "+H": "-H",
1540 (p[5] & MPPE_M_BIT)? "+M": "-M",
1541 (p[5] & MPPE_S_BIT)? "+S": "-S",
1542 (p[5] & MPPE_L_BIT)? "+L": "-L",
1543 (p[5] & MPPE_D_BIT)? "+D": "-D",
1544 (p[5] & MPPE_C_BIT)? "+C": "-C",
1545 (mppe_opts & MPPE_OPT_UNKNOWN)? " +U": "");
1546 if (mppe_opts & MPPE_OPT_UNKNOWN)
1547 printer(arg, " (%.2x %.2x %.2x %.2x)",
1548 p[2], p[3], p[4], p[5]);
1554 case CI_DEFLATE_DRAFT:
1555 if (optlen >= CILEN_DEFLATE) {
1556 printer(arg, "deflate%s %d",
1557 (code == CI_DEFLATE_DRAFT? "(old#)": ""),
1558 DEFLATE_SIZE(p[2]));
1559 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
1560 printer(arg, " method %d", DEFLATE_METHOD(p[2]));
1561 if (p[3] != DEFLATE_CHK_SEQUENCE)
1562 printer(arg, " check %d", p[3]);
1566 case CI_BSD_COMPRESS:
1567 if (optlen >= CILEN_BSD_COMPRESS) {
1568 printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
1570 p += CILEN_BSD_COMPRESS;
1573 case CI_PREDICTOR_1:
1574 if (optlen >= CILEN_PREDICTOR_1) {
1575 printer(arg, "predictor 1");
1576 p += CILEN_PREDICTOR_1;
1579 case CI_PREDICTOR_2:
1580 if (optlen >= CILEN_PREDICTOR_2) {
1581 printer(arg, "predictor 2");
1582 p += CILEN_PREDICTOR_2;
1587 printer(arg, " %.2x", *p++);
1594 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1595 print_string((char *)p, len, printer, arg);
1602 /* dump out the rest of the packet in hex */
1604 printer(arg, " %.2x", *p++);
1610 * We have received a packet that the decompressor failed to
1611 * decompress. Here we would expect to issue a reset-request, but
1612 * Motorola has a patent on resetting the compressor as a result of
1613 * detecting an error in the decompressed data after decompression.
1614 * (See US patent 5,130,993; international patent publication number
1615 * WO 91/10289; Australian patent 73296/91.)
1617 * So we ask the kernel whether the error was detected after
1618 * decompression; if it was, we take CCP down, thus disabling
1619 * compression :-(, otherwise we issue the reset-request.
1622 ccp_datainput(unit, pkt, len)
1630 if (f->state == OPENED) {
1631 if (ccp_fatal_error(unit)) {
1633 * Disable compression by taking CCP down.
1635 error("Lost compression sync: disabling compression");
1636 ccp_close(unit, "Lost compression sync");
1639 * If we were doing MPPE, we must also take the link down.
1641 if (ccp_gotoptions[unit].mppe) {
1642 error("Too many MPPE errors, closing LCP");
1643 lcp_close(unit, "Too many MPPE errors");
1648 * Send a reset-request to reset the peer's compressor.
1649 * We don't do that if we are still waiting for an
1650 * acknowledgement to a previous reset-request.
1652 if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
1653 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1654 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1655 ccp_localstate[f->unit] |= RACK_PENDING;
1657 ccp_localstate[f->unit] |= RREQ_REPEAT;
1663 * Timeout waiting for reset-ack.
1666 ccp_rack_timeout(arg)
1671 if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
1672 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1673 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1674 ccp_localstate[f->unit] &= ~RREQ_REPEAT;
1676 ccp_localstate[f->unit] &= ~RACK_PENDING;