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. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * 3. The name(s) of the authors of this software must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission.
22 * 4. Redistributions of any form whatsoever must retain the following
24 * "This product includes software developed by Paul Mackerras
25 * <paulus@samba.org>".
27 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
28 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
30 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
31 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
32 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
33 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
36 #define RCSID "$Id: ccp.c,v 1.41 2002/12/04 23:03:32 paulus Exp $"
44 #include <net/ppp-comp.h>
47 #include "chap_ms.h" /* mppe_xxxx_key */
48 #include "lcp.h" /* lcp_close(), lcp_fsm */
51 static const char rcsid[] = RCSID;
54 * Unfortunately there is a bug in zlib which means that using a
55 * size of 8 (window size = 256) for Deflate compression will cause
56 * buffer overruns and kernel crashes in the deflate module.
57 * Until this is fixed we only accept sizes in the range 9 .. 15.
58 * Thanks to James Carlson for pointing this out.
60 #define DEFLATE_MIN_WORKS 9
63 * Command-line options.
65 static int setbsdcomp __P((char **));
66 static int setdeflate __P((char **));
67 static char bsd_value[8];
68 static char deflate_value[8];
74 bool refuse_mppe_stateful = 1; /* Allow stateful mode? */
77 static option_t ccp_option_list[] = {
78 { "noccp", o_bool, &ccp_protent.enabled_flag,
79 "Disable CCP negotiation" },
80 { "-ccp", o_bool, &ccp_protent.enabled_flag,
81 "Disable CCP negotiation", OPT_ALIAS },
83 { "bsdcomp", o_special, (void *)setbsdcomp,
84 "Request BSD-Compress packet compression",
85 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, bsd_value },
86 { "nobsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
87 "don't allow BSD-Compress", OPT_PRIOSUB | OPT_A2CLR,
88 &ccp_allowoptions[0].bsd_compress },
89 { "-bsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
90 "don't allow BSD-Compress", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
91 &ccp_allowoptions[0].bsd_compress },
93 { "deflate", o_special, (void *)setdeflate,
94 "request Deflate compression",
95 OPT_PRIO | OPT_A2STRVAL | OPT_STATIC, deflate_value },
96 { "nodeflate", o_bool, &ccp_wantoptions[0].deflate,
97 "don't allow Deflate compression", OPT_PRIOSUB | OPT_A2CLR,
98 &ccp_allowoptions[0].deflate },
99 { "-deflate", o_bool, &ccp_wantoptions[0].deflate,
100 "don't allow Deflate compression", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
101 &ccp_allowoptions[0].deflate },
103 { "nodeflatedraft", o_bool, &ccp_wantoptions[0].deflate_draft,
104 "don't use draft deflate #", OPT_A2COPY,
105 &ccp_allowoptions[0].deflate_draft },
107 { "predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
108 "request Predictor-1", OPT_PRIO | 1 },
109 { "nopredictor1", o_bool, &ccp_wantoptions[0].predictor_1,
110 "don't allow Predictor-1", OPT_PRIOSUB | OPT_A2CLR,
111 &ccp_allowoptions[0].predictor_1 },
112 { "-predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
113 "don't allow Predictor-1", OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR,
114 &ccp_allowoptions[0].predictor_1 },
117 /* MPPE options are symmetrical ... we only set wantoptions here */
118 { "require-mppe", o_bool, &ccp_wantoptions[0].mppe,
119 "require MPPE encryption",
120 OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
121 { "+mppe", o_bool, &ccp_wantoptions[0].mppe,
122 "require MPPE encryption",
123 OPT_ALIAS | OPT_PRIO | MPPE_OPT_40 | MPPE_OPT_128 },
124 { "nomppe", o_bool, &ccp_wantoptions[0].mppe,
125 "don't allow MPPE encryption", OPT_PRIO },
126 { "-mppe", o_bool, &ccp_wantoptions[0].mppe,
127 "don't allow MPPE encryption", OPT_ALIAS | OPT_PRIO },
129 /* We use ccp_allowoptions[0].mppe as a junk var ... it is reset later */
130 { "require-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
131 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
132 &ccp_wantoptions[0].mppe },
133 { "+mppe-40", o_bool, &ccp_allowoptions[0].mppe,
134 "require MPPE 40-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_40,
135 &ccp_wantoptions[0].mppe },
136 { "nomppe-40", o_bool, &ccp_allowoptions[0].mppe,
137 "don't allow MPPE 40-bit encryption",
138 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40, &ccp_wantoptions[0].mppe },
139 { "-mppe-40", o_bool, &ccp_allowoptions[0].mppe,
140 "don't allow MPPE 40-bit encryption",
141 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_40,
142 &ccp_wantoptions[0].mppe },
144 { "require-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
145 "require MPPE 128-bit encryption", OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
146 &ccp_wantoptions[0].mppe },
147 { "+mppe-128", o_bool, &ccp_allowoptions[0].mppe,
148 "require MPPE 128-bit encryption",
149 OPT_ALIAS | OPT_PRIO | OPT_A2OR | MPPE_OPT_128,
150 &ccp_wantoptions[0].mppe },
151 { "nomppe-128", o_bool, &ccp_allowoptions[0].mppe,
152 "don't allow MPPE 128-bit encryption",
153 OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128, &ccp_wantoptions[0].mppe },
154 { "-mppe-128", o_bool, &ccp_allowoptions[0].mppe,
155 "don't allow MPPE 128-bit encryption",
156 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLRB | MPPE_OPT_128,
157 &ccp_wantoptions[0].mppe },
159 /* strange one; we always request stateless, but will we allow stateful? */
160 { "mppe-stateful", o_bool, &refuse_mppe_stateful,
161 "allow MPPE stateful mode", OPT_PRIO },
162 { "nomppe-stateful", o_bool, &refuse_mppe_stateful,
163 "disallow MPPE stateful mode", OPT_PRIO | 1 },
170 * Protocol entry points from main code.
172 static void ccp_init __P((int unit));
173 static void ccp_open __P((int unit));
174 static void ccp_close __P((int unit, char *));
175 static void ccp_lowerup __P((int unit));
176 static void ccp_lowerdown __P((int));
177 static void ccp_input __P((int unit, u_char *pkt, int len));
178 static void ccp_protrej __P((int unit));
179 static int ccp_printpkt __P((u_char *pkt, int len,
180 void (*printer) __P((void *, char *, ...)),
182 static void ccp_datainput __P((int unit, u_char *pkt, int len));
184 struct protent ccp_protent = {
204 fsm ccp_fsm[NUM_PPP];
205 ccp_options ccp_wantoptions[NUM_PPP]; /* what to request the peer to use */
206 ccp_options ccp_gotoptions[NUM_PPP]; /* what the peer agreed to do */
207 ccp_options ccp_allowoptions[NUM_PPP]; /* what we'll agree to do */
208 ccp_options ccp_hisoptions[NUM_PPP]; /* what we agreed to do */
211 * Callbacks for fsm code.
213 static void ccp_resetci __P((fsm *));
214 static int ccp_cilen __P((fsm *));
215 static void ccp_addci __P((fsm *, u_char *, int *));
216 static int ccp_ackci __P((fsm *, u_char *, int));
217 static int ccp_nakci __P((fsm *, u_char *, int));
218 static int ccp_rejci __P((fsm *, u_char *, int));
219 static int ccp_reqci __P((fsm *, u_char *, int *, int));
220 static void ccp_up __P((fsm *));
221 static void ccp_down __P((fsm *));
222 static int ccp_extcode __P((fsm *, int, int, u_char *, int));
223 static void ccp_rack_timeout __P((void *));
224 static char *method_name __P((ccp_options *, ccp_options *));
226 static fsm_callbacks ccp_callbacks = {
245 * Do we want / did we get any compression?
247 #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
248 || (opt).predictor_1 || (opt).predictor_2 \
252 * Local state (mainly for handling reset-reqs and reset-acks).
254 static int ccp_localstate[NUM_PPP];
255 #define RACK_PENDING 1 /* waiting for reset-ack */
256 #define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
258 #define RACKTIMEOUT 1 /* second */
260 static int all_rejected[NUM_PPP]; /* we rejected all peer's options */
273 abits = rbits = strtol(str, &endp, 0);
274 if (endp != str && *endp == ',') {
276 abits = strtol(str, &endp, 0);
278 if (*endp != 0 || endp == str) {
279 option_error("invalid parameter '%s' for bsdcomp option", *argv);
282 if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
283 || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
284 option_error("bsdcomp option values must be 0 or %d .. %d",
285 BSD_MIN_BITS, BSD_MAX_BITS);
289 ccp_wantoptions[0].bsd_compress = 1;
290 ccp_wantoptions[0].bsd_bits = rbits;
292 ccp_wantoptions[0].bsd_compress = 0;
294 ccp_allowoptions[0].bsd_compress = 1;
295 ccp_allowoptions[0].bsd_bits = abits;
297 ccp_allowoptions[0].bsd_compress = 0;
298 slprintf(bsd_value, sizeof(bsd_value),
299 rbits == abits? "%d": "%d,%d", rbits, abits);
312 abits = rbits = strtol(str, &endp, 0);
313 if (endp != str && *endp == ',') {
315 abits = strtol(str, &endp, 0);
317 if (*endp != 0 || endp == str) {
318 option_error("invalid parameter '%s' for deflate option", *argv);
321 if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
322 || (abits != 0 && (abits < DEFLATE_MIN_SIZE
323 || abits > DEFLATE_MAX_SIZE))) {
324 option_error("deflate option values must be 0 or %d .. %d",
325 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
328 if (rbits == DEFLATE_MIN_SIZE || abits == DEFLATE_MIN_SIZE) {
329 if (rbits == DEFLATE_MIN_SIZE)
330 rbits = DEFLATE_MIN_WORKS;
331 if (abits == DEFLATE_MIN_SIZE)
332 abits = DEFLATE_MIN_WORKS;
333 warn("deflate option value of %d changed to %d to avoid zlib bug",
334 DEFLATE_MIN_SIZE, DEFLATE_MIN_WORKS);
337 ccp_wantoptions[0].deflate = 1;
338 ccp_wantoptions[0].deflate_size = rbits;
340 ccp_wantoptions[0].deflate = 0;
342 ccp_allowoptions[0].deflate = 1;
343 ccp_allowoptions[0].deflate_size = abits;
345 ccp_allowoptions[0].deflate = 0;
346 slprintf(deflate_value, sizeof(deflate_value),
347 rbits == abits? "%d": "%d,%d", rbits, abits);
353 * ccp_init - initialize CCP.
359 fsm *f = &ccp_fsm[unit];
362 f->protocol = PPP_CCP;
363 f->callbacks = &ccp_callbacks;
366 memset(&ccp_wantoptions[unit], 0, sizeof(ccp_options));
367 memset(&ccp_gotoptions[unit], 0, sizeof(ccp_options));
368 memset(&ccp_allowoptions[unit], 0, sizeof(ccp_options));
369 memset(&ccp_hisoptions[unit], 0, sizeof(ccp_options));
371 ccp_wantoptions[0].deflate = 1;
372 ccp_wantoptions[0].deflate_size = DEFLATE_MAX_SIZE;
373 ccp_wantoptions[0].deflate_correct = 1;
374 ccp_wantoptions[0].deflate_draft = 1;
375 ccp_allowoptions[0].deflate = 1;
376 ccp_allowoptions[0].deflate_size = DEFLATE_MAX_SIZE;
377 ccp_allowoptions[0].deflate_correct = 1;
378 ccp_allowoptions[0].deflate_draft = 1;
380 ccp_wantoptions[0].bsd_compress = 1;
381 ccp_wantoptions[0].bsd_bits = BSD_MAX_BITS;
382 ccp_allowoptions[0].bsd_compress = 1;
383 ccp_allowoptions[0].bsd_bits = BSD_MAX_BITS;
385 ccp_allowoptions[0].predictor_1 = 1;
389 * ccp_open - CCP is allowed to come up.
395 fsm *f = &ccp_fsm[unit];
397 if (f->state != OPENED)
398 ccp_flags_set(unit, 1, 0);
401 * Find out which compressors the kernel supports before
402 * deciding whether to open in silent mode.
405 if (!ANY_COMPRESS(ccp_gotoptions[unit]))
406 f->flags |= OPT_SILENT;
412 * ccp_close - Terminate CCP.
415 ccp_close(unit, reason)
419 ccp_flags_set(unit, 0, 0);
420 fsm_close(&ccp_fsm[unit], reason);
424 * ccp_lowerup - we may now transmit CCP packets.
430 fsm_lowerup(&ccp_fsm[unit]);
434 * ccp_lowerdown - we may not transmit CCP packets.
440 fsm_lowerdown(&ccp_fsm[unit]);
444 * ccp_input - process a received CCP packet.
447 ccp_input(unit, p, len)
452 fsm *f = &ccp_fsm[unit];
456 * Check for a terminate-request so we can print a message.
459 fsm_input(f, p, len);
460 if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED) {
461 notice("Compression disabled by peer.");
463 if (ccp_gotoptions[unit].mppe) {
464 error("MPPE disabled, closing LCP");
465 lcp_close(unit, "MPPE disabled by peer");
471 * If we get a terminate-ack and we're not asking for compression,
474 if (oldstate == REQSENT && p[0] == TERMACK
475 && !ANY_COMPRESS(ccp_gotoptions[unit]))
476 ccp_close(unit, "No compression negotiated");
480 * Handle a CCP-specific code.
483 ccp_extcode(f, code, id, p, len)
491 if (f->state != OPENED)
493 /* send a reset-ack, which the transmitter will see and
494 reset its compression state. */
495 fsm_sdata(f, CCP_RESETACK, id, NULL, 0);
499 if (ccp_localstate[f->unit] & RACK_PENDING && id == f->reqid) {
500 ccp_localstate[f->unit] &= ~(RACK_PENDING | RREQ_REPEAT);
501 UNTIMEOUT(ccp_rack_timeout, f);
513 * ccp_protrej - peer doesn't talk CCP.
519 ccp_flags_set(unit, 0, 0);
520 fsm_lowerdown(&ccp_fsm[unit]);
523 if (ccp_gotoptions[unit].mppe) {
524 error("MPPE required but peer negotiation failed");
525 lcp_close(unit, "MPPE required but peer negotiation failed");
532 * ccp_resetci - initialize at start of negotiation.
538 ccp_options *go = &ccp_gotoptions[f->unit];
539 u_char opt_buf[CCP_MAX_OPTION_LENGTH];
541 *go = ccp_wantoptions[f->unit];
542 all_rejected[f->unit] = 0;
546 ccp_options *ao = &ccp_allowoptions[f->unit];
547 int auth_mschap_bits = auth_done[f->unit];
551 * Start with a basic sanity check: mschap[v2] auth must be in
552 * exactly one direction. RFC 3079 says that the keys are
553 * 'derived from the credentials of the peer that initiated the call',
554 * however the PPP protocol doesn't have such a concept, and pppd
555 * cannot get this info externally. Instead we do the best we can.
556 * NB: If MPPE is required, all other compression opts are invalid.
557 * So, we return right away if we can't do it.
560 /* Leave only the mschap auth bits set */
561 auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
562 CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
563 /* Count the mschap auths */
564 auth_mschap_bits >>= CHAP_MS_SHIFT;
567 numbits += auth_mschap_bits & 1;
568 auth_mschap_bits >>= 1;
569 } while (auth_mschap_bits);
571 error("MPPE required, but auth done in both directions.");
572 lcp_close(f->unit, "MPPE required but not available");
576 error("MPPE required, but MS-CHAP[v2] auth not performed.");
577 lcp_close(f->unit, "MPPE required but not available");
581 /* LM auth not supported for MPPE */
582 if (auth_done[f->unit] & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) {
583 /* This might be noise */
584 if (go->mppe & MPPE_OPT_40) {
585 notice("Disabling 40-bit MPPE; MS-CHAP LM not supported");
586 go->mppe &= ~MPPE_OPT_40;
587 ccp_wantoptions[f->unit].mppe &= ~MPPE_OPT_40;
591 /* Last check: can we actually negotiate something? */
592 if (!(go->mppe & (MPPE_OPT_40 | MPPE_OPT_128))) {
593 /* Could be misconfig, could be 40-bit disabled above. */
594 error("MPPE required, but both 40-bit and 128-bit disabled.");
595 lcp_close(f->unit, "MPPE required but not available");
601 /* MPPE is not compatible with other compression types */
602 ao->bsd_compress = go->bsd_compress = 0;
603 ao->predictor_1 = go->predictor_1 = 0;
604 ao->predictor_2 = go->predictor_2 = 0;
605 ao->deflate = go->deflate = 0;
610 * Check whether the kernel knows about the various
611 * compression methods we might request.
615 opt_buf[0] = CI_MPPE;
616 opt_buf[1] = CILEN_MPPE;
617 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
618 /* Key material unimportant here. */
619 if (ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0) <= 0) {
620 error("MPPE required, but kernel has no support.");
621 lcp_close(f->unit, "MPPE required but not available");
625 if (go->bsd_compress) {
626 opt_buf[0] = CI_BSD_COMPRESS;
627 opt_buf[1] = CILEN_BSD_COMPRESS;
628 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, BSD_MIN_BITS);
629 if (ccp_test(f->unit, opt_buf, CILEN_BSD_COMPRESS, 0) <= 0)
630 go->bsd_compress = 0;
633 if (go->deflate_correct) {
634 opt_buf[0] = CI_DEFLATE;
635 opt_buf[1] = CILEN_DEFLATE;
636 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
637 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
638 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
639 go->deflate_correct = 0;
641 if (go->deflate_draft) {
642 opt_buf[0] = CI_DEFLATE_DRAFT;
643 opt_buf[1] = CILEN_DEFLATE;
644 opt_buf[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS);
645 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
646 if (ccp_test(f->unit, opt_buf, CILEN_DEFLATE, 0) <= 0)
647 go->deflate_draft = 0;
649 if (!go->deflate_correct && !go->deflate_draft)
652 if (go->predictor_1) {
653 opt_buf[0] = CI_PREDICTOR_1;
654 opt_buf[1] = CILEN_PREDICTOR_1;
655 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
658 if (go->predictor_2) {
659 opt_buf[0] = CI_PREDICTOR_2;
660 opt_buf[1] = CILEN_PREDICTOR_2;
661 if (ccp_test(f->unit, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
667 * ccp_cilen - Return total length of our configuration info.
673 ccp_options *go = &ccp_gotoptions[f->unit];
675 return (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
676 + (go->deflate? CILEN_DEFLATE: 0)
677 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
678 + (go->predictor_2? CILEN_PREDICTOR_2: 0)
679 + (go->mppe? CILEN_MPPE: 0);
683 * ccp_addci - put our requests in a packet.
686 ccp_addci(f, p, lenp)
692 ccp_options *go = &ccp_gotoptions[f->unit];
696 * Add the compression types that we can receive, in decreasing
697 * preference order. Get the kernel to allocate the first one
698 * in case it gets Acked.
702 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
704 p[0] = opt_buf[0] = CI_MPPE;
705 p[1] = opt_buf[1] = CILEN_MPPE;
706 MPPE_OPTS_TO_CI(go->mppe, &p[2]);
707 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
708 BCOPY(mppe_recv_key, &opt_buf[CILEN_MPPE], MPPE_MAX_KEY_LEN);
709 res = ccp_test(f->unit, opt_buf, CILEN_MPPE + MPPE_MAX_KEY_LEN, 0);
713 /* This shouldn't happen, we've already tested it! */
714 lcp_close(f->unit, "MPPE required but not available in kernel");
718 p[0] = go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT;
719 p[1] = CILEN_DEFLATE;
720 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
721 p[3] = DEFLATE_CHK_SEQUENCE;
723 if (go->deflate_size < DEFLATE_MIN_WORKS) {
727 res = ccp_test(f->unit, p, CILEN_DEFLATE, 0);
731 } else if (res < 0) {
736 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
738 if (p != p0 && go->deflate_correct && go->deflate_draft) {
739 p[0] = CI_DEFLATE_DRAFT;
740 p[1] = CILEN_DEFLATE;
741 p[2] = p[2 - CILEN_DEFLATE];
742 p[3] = DEFLATE_CHK_SEQUENCE;
746 if (go->bsd_compress) {
747 p[0] = CI_BSD_COMPRESS;
748 p[1] = CILEN_BSD_COMPRESS;
749 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
751 p += CILEN_BSD_COMPRESS; /* not the first option */
754 if (go->bsd_bits < BSD_MIN_BITS) {
755 go->bsd_compress = 0;
758 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 0);
760 p += CILEN_BSD_COMPRESS;
762 } else if (res < 0) {
763 go->bsd_compress = 0;
767 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
771 /* XXX Should Predictor 2 be preferable to Predictor 1? */
772 if (go->predictor_1) {
773 p[0] = CI_PREDICTOR_1;
774 p[1] = CILEN_PREDICTOR_1;
775 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 0) <= 0) {
778 p += CILEN_PREDICTOR_1;
781 if (go->predictor_2) {
782 p[0] = CI_PREDICTOR_2;
783 p[1] = CILEN_PREDICTOR_2;
784 if (p == p0 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 0) <= 0) {
787 p += CILEN_PREDICTOR_2;
791 go->method = (p > p0)? p0[0]: -1;
797 * ccp_ackci - process a received configure-ack, and return
798 * 1 iff the packet was OK.
806 ccp_options *go = &ccp_gotoptions[f->unit];
811 u_char opt_buf[CILEN_MPPE];
813 opt_buf[0] = CI_MPPE;
814 opt_buf[1] = CILEN_MPPE;
815 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
816 if (len < CILEN_MPPE || memcmp(opt_buf, p, CILEN_MPPE))
820 /* XXX Cope with first/fast ack */
826 if (len < CILEN_DEFLATE
827 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
828 || p[1] != CILEN_DEFLATE
829 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
830 || p[3] != DEFLATE_CHK_SEQUENCE)
833 len -= CILEN_DEFLATE;
834 /* XXX Cope with first/fast ack */
837 if (go->deflate_correct && go->deflate_draft) {
838 if (len < CILEN_DEFLATE
839 || p[0] != CI_DEFLATE_DRAFT
840 || p[1] != CILEN_DEFLATE
841 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
842 || p[3] != DEFLATE_CHK_SEQUENCE)
845 len -= CILEN_DEFLATE;
848 if (go->bsd_compress) {
849 if (len < CILEN_BSD_COMPRESS
850 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
851 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
853 p += CILEN_BSD_COMPRESS;
854 len -= CILEN_BSD_COMPRESS;
855 /* XXX Cope with first/fast ack */
856 if (p == p0 && len == 0)
859 if (go->predictor_1) {
860 if (len < CILEN_PREDICTOR_1
861 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
863 p += CILEN_PREDICTOR_1;
864 len -= CILEN_PREDICTOR_1;
865 /* XXX Cope with first/fast ack */
866 if (p == p0 && len == 0)
869 if (go->predictor_2) {
870 if (len < CILEN_PREDICTOR_2
871 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
873 p += CILEN_PREDICTOR_2;
874 len -= CILEN_PREDICTOR_2;
875 /* XXX Cope with first/fast ack */
876 if (p == p0 && len == 0)
886 * ccp_nakci - process received configure-nak.
887 * Returns 1 iff the nak was OK.
895 ccp_options *go = &ccp_gotoptions[f->unit];
896 ccp_options no; /* options we've seen already */
897 ccp_options try; /* options to ask for next time */
899 memset(&no, 0, sizeof(no));
903 if (go->mppe && len >= CILEN_MPPE
904 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
907 * Peer wants us to use a different strength or other setting.
908 * Fail if we aren't willing to use his suggestion.
910 MPPE_CI_TO_OPTS(&p[2], try.mppe);
911 if ((try.mppe & MPPE_OPT_STATEFUL) && refuse_mppe_stateful)
913 else if ((go->mppe & try.mppe) != try.mppe)
914 /* Peer must have set options we didn't request (suggest) */
918 error("MPPE required but peer negotiation failed");
919 lcp_close(f->unit, "MPPE required but peer negotiation failed");
923 if (go->deflate && len >= CILEN_DEFLATE
924 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
925 && p[1] == CILEN_DEFLATE) {
928 * Peer wants us to use a different code size or something.
929 * Stop asking for Deflate if we don't understand his suggestion.
931 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
932 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_WORKS
933 || p[3] != DEFLATE_CHK_SEQUENCE)
935 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
936 try.deflate_size = DEFLATE_SIZE(p[2]);
938 len -= CILEN_DEFLATE;
939 if (go->deflate_correct && go->deflate_draft
940 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
941 && p[1] == CILEN_DEFLATE) {
943 len -= CILEN_DEFLATE;
947 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
948 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
951 * Peer wants us to use a different number of bits
952 * or a different version.
954 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
955 try.bsd_compress = 0;
956 else if (BSD_NBITS(p[2]) < go->bsd_bits)
957 try.bsd_bits = BSD_NBITS(p[2]);
958 p += CILEN_BSD_COMPRESS;
959 len -= CILEN_BSD_COMPRESS;
963 * Predictor-1 and 2 have no options, so they can't be Naked.
965 * There may be remaining options but we ignore them.
968 if (f->state != OPENED)
974 * ccp_rejci - reject some of our suggested compression methods.
982 ccp_options *go = &ccp_gotoptions[f->unit];
983 ccp_options try; /* options to request next time */
988 * Cope with empty configure-rejects by ceasing to send
989 * configure-requests.
991 if (len == 0 && all_rejected[f->unit])
995 if (go->mppe && len >= CILEN_MPPE
996 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
997 error("MPPE required but peer refused");
998 lcp_close(f->unit, "MPPE required but peer refused");
1003 if (go->deflate && len >= CILEN_DEFLATE
1004 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
1005 && p[1] == CILEN_DEFLATE) {
1006 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1007 || p[3] != DEFLATE_CHK_SEQUENCE)
1008 return 0; /* Rej is bad */
1009 if (go->deflate_correct)
1010 try.deflate_correct = 0;
1012 try.deflate_draft = 0;
1014 len -= CILEN_DEFLATE;
1015 if (go->deflate_correct && go->deflate_draft
1016 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
1017 && p[1] == CILEN_DEFLATE) {
1018 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1019 || p[3] != DEFLATE_CHK_SEQUENCE)
1020 return 0; /* Rej is bad */
1021 try.deflate_draft = 0;
1023 len -= CILEN_DEFLATE;
1025 if (!try.deflate_correct && !try.deflate_draft)
1028 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
1029 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
1030 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
1032 try.bsd_compress = 0;
1033 p += CILEN_BSD_COMPRESS;
1034 len -= CILEN_BSD_COMPRESS;
1036 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
1037 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
1038 try.predictor_1 = 0;
1039 p += CILEN_PREDICTOR_1;
1040 len -= CILEN_PREDICTOR_1;
1042 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
1043 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
1044 try.predictor_2 = 0;
1045 p += CILEN_PREDICTOR_2;
1046 len -= CILEN_PREDICTOR_2;
1052 if (f->state != OPENED)
1059 * ccp_reqci - processed a received configure-request.
1060 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
1064 ccp_reqci(f, p, lenp, dont_nak)
1070 int ret, newret, res;
1072 int len, clen, type, nb;
1073 ccp_options *ho = &ccp_hisoptions[f->unit];
1074 ccp_options *ao = &ccp_allowoptions[f->unit];
1076 bool seen_ci_mppe = 0;
1083 memset(ho, 0, sizeof(ccp_options));
1084 ho->method = (len > 0)? p[0]: -1;
1088 if (len < 2 || p[1] < 2 || p[1] > len) {
1100 if (!ao->mppe || clen != CILEN_MPPE) {
1105 MPPE_CI_TO_OPTS(&p[2], ho->mppe);
1107 /* Nak if anything unsupported or unknown are set. */
1108 if (ho->mppe & MPPE_OPT_UNSUPPORTED) {
1110 ho->mppe &= ~MPPE_OPT_UNSUPPORTED;
1112 if (ho->mppe & MPPE_OPT_UNKNOWN) {
1114 ho->mppe &= ~MPPE_OPT_UNKNOWN;
1117 /* Check state opt */
1118 if (ho->mppe & MPPE_OPT_STATEFUL) {
1119 if (refuse_mppe_stateful) {
1121 * We can Nak and request stateless, but it's a
1122 * lot easier to just assume the peer will request
1123 * it if he can do it; stateful mode is bad over
1124 * the Internet -- which is where we expect MPPE.
1133 /* Find out which of {S,L} are set. */
1134 if ((ho->mppe & MPPE_OPT_128)
1135 && (ho->mppe & MPPE_OPT_40)) {
1136 /* Both are set, negotiate the strongest. */
1138 if (ao->mppe & MPPE_OPT_128)
1139 ho->mppe &= ~MPPE_OPT_40;
1140 else if (ao->mppe & MPPE_OPT_40)
1141 ho->mppe &= ~MPPE_OPT_128;
1146 } else if (ho->mppe & MPPE_OPT_128) {
1147 if (!(ao->mppe & MPPE_OPT_128)) {
1151 } else if (ho->mppe & MPPE_OPT_40) {
1152 if (!(ao->mppe & MPPE_OPT_40)) {
1157 /* Neither are set. */
1162 /* rebuild the opts */
1163 MPPE_OPTS_TO_CI(ho->mppe, &p[2]);
1164 if (newret == CONFACK) {
1165 u_char opt_buf[CILEN_MPPE + MPPE_MAX_KEY_LEN];
1168 BCOPY(p, opt_buf, CILEN_MPPE);
1169 BCOPY(mppe_send_key, &opt_buf[CILEN_MPPE],
1171 if (ccp_test(f->unit, opt_buf,
1172 CILEN_MPPE + MPPE_MAX_KEY_LEN, 1) <= 0) {
1173 /* This shouldn't happen, we've already tested it! */
1174 error("MPPE required, but kernel has no support.");
1175 lcp_close(f->unit, "MPPE required but not available");
1180 * We need to decrease the interface MTU by MPPE_PAD
1181 * because MPPE frames **grow**. The kernel [must]
1182 * allocate MPPE_PAD extra bytes in xmit buffers.
1184 mtu = netif_get_mtu(f->unit);
1186 netif_set_mtu(f->unit, mtu - MPPE_PAD);
1194 case CI_DEFLATE_DRAFT:
1195 if (!ao->deflate || clen != CILEN_DEFLATE
1196 || (!ao->deflate_correct && type == CI_DEFLATE)
1197 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
1203 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
1204 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
1205 || p[3] != DEFLATE_CHK_SEQUENCE
1206 || nb > ao->deflate_size || nb < DEFLATE_MIN_WORKS) {
1209 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
1210 p[3] = DEFLATE_CHK_SEQUENCE;
1211 /* fall through to test this #bits below */
1217 * Check whether we can do Deflate with the window
1218 * size they want. If the window is too big, reduce
1219 * it until the kernel can cope and nak with that.
1220 * We only check this for the first option.
1224 res = ccp_test(f->unit, p, CILEN_DEFLATE, 1);
1226 break; /* it's OK now */
1227 if (res < 0 || nb == DEFLATE_MIN_WORKS || dont_nak) {
1229 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
1234 p[2] = DEFLATE_MAKE_OPT(nb);
1239 case CI_BSD_COMPRESS:
1240 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
1245 ho->bsd_compress = 1;
1246 ho->bsd_bits = nb = BSD_NBITS(p[2]);
1247 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
1248 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
1251 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
1252 /* fall through to test this #bits below */
1258 * Check whether we can do BSD-Compress with the code
1259 * size they want. If the code size is too big, reduce
1260 * it until the kernel can cope and nak with that.
1261 * We only check this for the first option.
1265 res = ccp_test(f->unit, p, CILEN_BSD_COMPRESS, 1);
1268 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
1270 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
1276 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
1281 case CI_PREDICTOR_1:
1282 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
1287 ho->predictor_1 = 1;
1289 && ccp_test(f->unit, p, CILEN_PREDICTOR_1, 1) <= 0) {
1294 case CI_PREDICTOR_2:
1295 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
1300 ho->predictor_2 = 1;
1302 && ccp_test(f->unit, p, CILEN_PREDICTOR_2, 1) <= 0) {
1312 if (newret == CONFNAK && dont_nak)
1314 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
1315 /* we're returning this option */
1316 if (newret == CONFREJ && ret == CONFNAK)
1320 BCOPY(p, retp, clen);
1328 if (ret != CONFACK) {
1329 if (ret == CONFREJ && *lenp == retp - p0)
1330 all_rejected[f->unit] = 1;
1335 if (ret == CONFREJ && ao->mppe && !seen_ci_mppe) {
1336 error("MPPE required but peer negotiation failed");
1337 lcp_close(f->unit, "MPPE required but peer negotiation failed");
1344 * Make a string name for a compression method (or 2).
1347 method_name(opt, opt2)
1348 ccp_options *opt, *opt2;
1350 static char result[64];
1352 if (!ANY_COMPRESS(*opt))
1354 switch (opt->method) {
1359 char *q = result + sizeof(result); /* 1 past result */
1361 slprintf(p, q - p, "MPPE ");
1363 if (opt->mppe & MPPE_OPT_128) {
1364 slprintf(p, q - p, "128-bit ");
1367 if (opt->mppe & MPPE_OPT_40) {
1368 slprintf(p, q - p, "40-bit ");
1371 if (opt->mppe & MPPE_OPT_STATEFUL)
1372 slprintf(p, q - p, "stateful");
1374 slprintf(p, q - p, "stateless");
1380 case CI_DEFLATE_DRAFT:
1381 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
1382 slprintf(result, sizeof(result), "Deflate%s (%d/%d)",
1383 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1384 opt->deflate_size, opt2->deflate_size);
1386 slprintf(result, sizeof(result), "Deflate%s (%d)",
1387 (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
1390 case CI_BSD_COMPRESS:
1391 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
1392 slprintf(result, sizeof(result), "BSD-Compress (%d/%d)",
1393 opt->bsd_bits, opt2->bsd_bits);
1395 slprintf(result, sizeof(result), "BSD-Compress (%d)",
1398 case CI_PREDICTOR_1:
1399 return "Predictor 1";
1400 case CI_PREDICTOR_2:
1401 return "Predictor 2";
1403 slprintf(result, sizeof(result), "Method %d", opt->method);
1409 * CCP has come up - inform the kernel driver and log a message.
1415 ccp_options *go = &ccp_gotoptions[f->unit];
1416 ccp_options *ho = &ccp_hisoptions[f->unit];
1419 ccp_flags_set(f->unit, 1, 1);
1420 if (ANY_COMPRESS(*go)) {
1421 if (ANY_COMPRESS(*ho)) {
1422 if (go->method == ho->method) {
1423 notice("%s compression enabled", method_name(go, ho));
1425 strlcpy(method1, method_name(go, NULL), sizeof(method1));
1426 notice("%s / %s compression enabled",
1427 method1, method_name(ho, NULL));
1430 notice("%s receive compression enabled", method_name(go, NULL));
1431 } else if (ANY_COMPRESS(*ho))
1432 notice("%s transmit compression enabled", method_name(ho, NULL));
1435 BZERO(mppe_recv_key, MPPE_MAX_KEY_LEN);
1436 BZERO(mppe_send_key, MPPE_MAX_KEY_LEN);
1437 continue_networks(f->unit); /* Bring up IP et al */
1443 * CCP has gone down - inform the kernel driver.
1449 if (ccp_localstate[f->unit] & RACK_PENDING)
1450 UNTIMEOUT(ccp_rack_timeout, f);
1451 ccp_localstate[f->unit] = 0;
1452 ccp_flags_set(f->unit, 1, 0);
1454 if (ccp_gotoptions[f->unit].mppe) {
1455 ccp_gotoptions[f->unit].mppe = 0;
1456 if (lcp_fsm[f->unit].state == OPENED) {
1457 /* If LCP is not already going down, make sure it does. */
1458 error("MPPE disabled");
1459 lcp_close(f->unit, "MPPE disabled");
1466 * Print the contents of a CCP packet.
1468 static char *ccp_codenames[] = {
1469 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1470 "TermReq", "TermAck", "CodeRej",
1471 NULL, NULL, NULL, NULL, NULL, NULL,
1472 "ResetReq", "ResetAck",
1476 ccp_printpkt(p, plen, printer, arg)
1479 void (*printer) __P((void *, char *, ...));
1482 u_char *p0, *optend;
1487 if (plen < HEADERLEN)
1491 len = (p[2] << 8) + p[3];
1492 if (len < HEADERLEN || len > plen)
1495 if (code >= 1 && code <= sizeof(ccp_codenames) / sizeof(char *)
1496 && ccp_codenames[code-1] != NULL)
1497 printer(arg, " %s", ccp_codenames[code-1]);
1499 printer(arg, " code=0x%x", code);
1500 printer(arg, " id=0x%x", id);
1509 /* print list of possible compression methods */
1513 if (optlen < 2 || optlen > len)
1517 optend = p + optlen;
1521 if (optlen >= CILEN_MPPE) {
1524 MPPE_CI_TO_OPTS(&p[2], mppe_opts);
1525 printer(arg, "mppe %s %s %s %s %s %s%s",
1526 (p[2] & MPPE_H_BIT)? "+H": "-H",
1527 (p[5] & MPPE_M_BIT)? "+M": "-M",
1528 (p[5] & MPPE_S_BIT)? "+S": "-S",
1529 (p[5] & MPPE_L_BIT)? "+L": "-L",
1530 (p[5] & MPPE_D_BIT)? "+D": "-D",
1531 (p[5] & MPPE_C_BIT)? "+C": "-C",
1532 (mppe_opts & MPPE_OPT_UNKNOWN)? " +U": "");
1533 if (mppe_opts & MPPE_OPT_UNKNOWN)
1534 printer(arg, " (%.2x %.2x %.2x %.2x)",
1535 p[2], p[3], p[4], p[5]);
1541 case CI_DEFLATE_DRAFT:
1542 if (optlen >= CILEN_DEFLATE) {
1543 printer(arg, "deflate%s %d",
1544 (code == CI_DEFLATE_DRAFT? "(old#)": ""),
1545 DEFLATE_SIZE(p[2]));
1546 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
1547 printer(arg, " method %d", DEFLATE_METHOD(p[2]));
1548 if (p[3] != DEFLATE_CHK_SEQUENCE)
1549 printer(arg, " check %d", p[3]);
1553 case CI_BSD_COMPRESS:
1554 if (optlen >= CILEN_BSD_COMPRESS) {
1555 printer(arg, "bsd v%d %d", BSD_VERSION(p[2]),
1557 p += CILEN_BSD_COMPRESS;
1560 case CI_PREDICTOR_1:
1561 if (optlen >= CILEN_PREDICTOR_1) {
1562 printer(arg, "predictor 1");
1563 p += CILEN_PREDICTOR_1;
1566 case CI_PREDICTOR_2:
1567 if (optlen >= CILEN_PREDICTOR_2) {
1568 printer(arg, "predictor 2");
1569 p += CILEN_PREDICTOR_2;
1574 printer(arg, " %.2x", *p++);
1581 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1582 print_string((char *)p, len, printer, arg);
1589 /* dump out the rest of the packet in hex */
1591 printer(arg, " %.2x", *p++);
1597 * We have received a packet that the decompressor failed to
1598 * decompress. Here we would expect to issue a reset-request, but
1599 * Motorola has a patent on resetting the compressor as a result of
1600 * detecting an error in the decompressed data after decompression.
1601 * (See US patent 5,130,993; international patent publication number
1602 * WO 91/10289; Australian patent 73296/91.)
1604 * So we ask the kernel whether the error was detected after
1605 * decompression; if it was, we take CCP down, thus disabling
1606 * compression :-(, otherwise we issue the reset-request.
1609 ccp_datainput(unit, pkt, len)
1617 if (f->state == OPENED) {
1618 if (ccp_fatal_error(unit)) {
1620 * Disable compression by taking CCP down.
1622 error("Lost compression sync: disabling compression");
1623 ccp_close(unit, "Lost compression sync");
1626 * If we were doing MPPE, we must also take the link down.
1628 if (ccp_gotoptions[unit].mppe) {
1629 error("Too many MPPE errors, closing LCP");
1630 lcp_close(unit, "Too many MPPE errors");
1635 * Send a reset-request to reset the peer's compressor.
1636 * We don't do that if we are still waiting for an
1637 * acknowledgement to a previous reset-request.
1639 if (!(ccp_localstate[f->unit] & RACK_PENDING)) {
1640 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1641 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1642 ccp_localstate[f->unit] |= RACK_PENDING;
1644 ccp_localstate[f->unit] |= RREQ_REPEAT;
1650 * Timeout waiting for reset-ack.
1653 ccp_rack_timeout(arg)
1658 if (f->state == OPENED && ccp_localstate[f->unit] & RREQ_REPEAT) {
1659 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1660 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1661 ccp_localstate[f->unit] &= ~RREQ_REPEAT;
1663 ccp_localstate[f->unit] &= ~RACK_PENDING;