31 #include "netif/ppp/ppp_opts.h" 32 #if PPP_SUPPORT && CCP_SUPPORT 37 #include "netif/ppp/ppp_impl.h" 39 #include "netif/ppp/fsm.h" 40 #include "netif/ppp/ccp.h" 43 #include "netif/ppp/lcp.h" 44 #include "netif/ppp/mppe.h" 54 #define DEFLATE_MIN_WORKS 9 60 static int setbsdcomp (
char **);
61 static int setdeflate (
char **);
62 static char bsd_value[8];
63 static char deflate_value[8];
69 bool refuse_mppe_stateful = 1;
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 },
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 },
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 },
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 },
168 static void ccp_init(ppp_pcb *pcb);
169 static void ccp_open(ppp_pcb *pcb);
170 static void ccp_close(ppp_pcb *pcb,
const char *reason);
171 static void ccp_lowerup(ppp_pcb *pcb);
172 static void ccp_lowerdown(ppp_pcb *pcb);
173 static void ccp_input(ppp_pcb *pcb, u_char *pkt,
int len);
174 static void ccp_protrej(ppp_pcb *pcb);
176 static int ccp_printpkt(
const u_char *p,
int plen,
void (*printer) (
void *,
const char *, ...),
void *arg);
179 static void ccp_datainput(ppp_pcb *pcb, u_char *pkt,
int len);
182 const struct protent ccp_protent = {
214 static void ccp_resetci (fsm *);
215 static int ccp_cilen (fsm *);
216 static void ccp_addci (fsm *, u_char *,
int *);
217 static int ccp_ackci (fsm *, u_char *,
int);
218 static int ccp_nakci (fsm *, u_char *,
int,
int);
219 static int ccp_rejci (fsm *, u_char *,
int);
220 static int ccp_reqci (fsm *, u_char *,
int *,
int);
221 static void ccp_up (fsm *);
222 static void ccp_down (fsm *);
223 static int ccp_extcode (fsm *,
int,
int, u_char *,
int);
224 static void ccp_rack_timeout (
void *);
225 static const char *method_name (ccp_options *, ccp_options *);
227 static const fsm_callbacks ccp_callbacks = {
248 static int ccp_anycompress(ccp_options *opt) {
253 #
if BSDCOMPRESS_SUPPORT
254 || (opt)->bsd_compress
256 #
if PREDICTOR_SUPPORT
257 || (opt)->predictor_1 || (opt)->predictor_2
268 #define RACK_PENDING 1 269 #define RREQ_REPEAT 2 271 #define RACKTIMEOUT 1 285 abits = rbits = strtol(str, &endp, 0);
286 if (endp != str && *endp ==
',') {
288 abits = strtol(str, &endp, 0);
290 if (*endp != 0 || endp == str) {
291 option_error(
"invalid parameter '%s' for bsdcomp option", *argv);
294 if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
295 || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
296 option_error(
"bsdcomp option values must be 0 or %d .. %d",
297 BSD_MIN_BITS, BSD_MAX_BITS);
301 ccp_wantoptions[0].bsd_compress = 1;
302 ccp_wantoptions[0].bsd_bits = rbits;
304 ccp_wantoptions[0].bsd_compress = 0;
306 ccp_allowoptions[0].bsd_compress = 1;
307 ccp_allowoptions[0].bsd_bits = abits;
309 ccp_allowoptions[0].bsd_compress = 0;
310 ppp_slprintf(bsd_value,
sizeof(bsd_value),
311 rbits == abits?
"%d":
"%d,%d", rbits, abits);
324 abits = rbits = strtol(str, &endp, 0);
325 if (endp != str && *endp ==
',') {
327 abits = strtol(str, &endp, 0);
329 if (*endp != 0 || endp == str) {
330 option_error(
"invalid parameter '%s' for deflate option", *argv);
333 if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
334 || (abits != 0 && (abits < DEFLATE_MIN_SIZE
335 || abits > DEFLATE_MAX_SIZE))) {
336 option_error(
"deflate option values must be 0 or %d .. %d",
337 DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
340 if (rbits == DEFLATE_MIN_SIZE || abits == DEFLATE_MIN_SIZE) {
341 if (rbits == DEFLATE_MIN_SIZE)
342 rbits = DEFLATE_MIN_WORKS;
343 if (abits == DEFLATE_MIN_SIZE)
344 abits = DEFLATE_MIN_WORKS;
345 warn(
"deflate option value of %d changed to %d to avoid zlib bug",
346 DEFLATE_MIN_SIZE, DEFLATE_MIN_WORKS);
349 ccp_wantoptions[0].deflate = 1;
350 ccp_wantoptions[0].deflate_size = rbits;
352 ccp_wantoptions[0].deflate = 0;
354 ccp_allowoptions[0].deflate = 1;
355 ccp_allowoptions[0].deflate_size = abits;
357 ccp_allowoptions[0].deflate = 0;
358 ppp_slprintf(deflate_value,
sizeof(deflate_value),
359 rbits == abits?
"%d":
"%d,%d", rbits, abits);
368 static void ccp_init(ppp_pcb *pcb) {
369 fsm *f = &pcb->ccp_fsm;
372 f->protocol = PPP_CCP;
373 f->callbacks = &ccp_callbacks;
377 memset(wo, 0,
sizeof(*wo));
378 memset(go, 0,
sizeof(*go));
379 memset(ao, 0,
sizeof(*ao));
380 memset(ho, 0,
sizeof(*ho));
385 wo->deflate_size = DEFLATE_MAX_SIZE;
386 wo->deflate_correct = 1;
387 wo->deflate_draft = 1;
389 ao->deflate_size = DEFLATE_MAX_SIZE;
390 ao->deflate_correct = 1;
391 ao->deflate_draft = 1;
394 #if BSDCOMPRESS_SUPPORT 395 wo->bsd_compress = 1;
396 wo->bsd_bits = BSD_MAX_BITS;
397 ao->bsd_compress = 1;
398 ao->bsd_bits = BSD_MAX_BITS;
401 #if PREDICTOR_SUPPORT 409 static void ccp_open(ppp_pcb *pcb) {
410 fsm *f = &pcb->ccp_fsm;
411 ccp_options *go = &pcb->ccp_gotoptions;
413 if (f->state != PPP_FSM_OPENED)
414 ccp_set(pcb, 1, 0, 0, 0);
421 if (!ccp_anycompress(go))
422 f->flags |= OPT_SILENT;
430 static void ccp_close(ppp_pcb *pcb,
const char *reason) {
431 fsm *f = &pcb->ccp_fsm;
432 ccp_set(pcb, 0, 0, 0, 0);
433 fsm_close(f, reason);
439 static void ccp_lowerup(ppp_pcb *pcb) {
440 fsm *f = &pcb->ccp_fsm;
447 static void ccp_lowerdown(ppp_pcb *pcb) {
448 fsm *f = &pcb->ccp_fsm;
455 static void ccp_input(ppp_pcb *pcb, u_char *p,
int len) {
456 fsm *f = &pcb->ccp_fsm;
457 ccp_options *go = &pcb->ccp_gotoptions;
464 fsm_input(f, p, len);
465 if (oldstate == PPP_FSM_OPENED && p[0] == TERMREQ && f->state != PPP_FSM_OPENED) {
466 ppp_notice(
"Compression disabled by peer.");
469 ppp_error(
"MPPE disabled, closing LCP");
470 lcp_close(pcb,
"MPPE disabled by peer");
479 if (oldstate == PPP_FSM_REQSENT && p[0] == TERMACK
480 && !ccp_anycompress(go))
481 ccp_close(pcb,
"No compression negotiated");
487 static int ccp_extcode(fsm *f,
int code,
int id, u_char *p,
int len) {
488 ppp_pcb *pcb = f->pcb;
494 if (f->state != PPP_FSM_OPENED)
499 fsm_sdata(f, CCP_RESETACK,
id, NULL, 0);
503 if ((pcb->ccp_localstate & RACK_PENDING) &&
id == f->reqid) {
504 pcb->ccp_localstate &= ~(RACK_PENDING | RREQ_REPEAT);
505 UNTIMEOUT(ccp_rack_timeout, f);
506 ccp_reset_decomp(pcb);
520 static void ccp_protrej(ppp_pcb *pcb) {
521 fsm *f = &pcb->ccp_fsm;
523 ccp_options *go = &pcb->ccp_gotoptions;
526 ccp_set(pcb, 0, 0, 0, 0);
531 ppp_error(
"MPPE required but peer negotiation failed");
532 lcp_close(pcb,
"MPPE required but peer negotiation failed");
541 static void ccp_resetci(fsm *f) {
542 ppp_pcb *pcb = f->pcb;
543 ccp_options *go = &pcb->ccp_gotoptions;
544 ccp_options *wo = &pcb->ccp_wantoptions;
546 ccp_options *ao = &pcb->ccp_allowoptions;
548 #if DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT || PREDICTOR_SUPPORT 549 u_char opt_buf[CCP_MAX_OPTION_LENGTH];
551 #if DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT 556 if (pcb->settings.require_mppe) {
557 wo->mppe = ao->mppe =
558 (pcb->settings.refuse_mppe_40 ? 0 : MPPE_OPT_40)
559 | (pcb->settings.refuse_mppe_128 ? 0 : MPPE_OPT_128);
564 pcb->ccp_all_rejected = 0;
568 int auth_mschap_bits = pcb->auth_done;
582 auth_mschap_bits &= (CHAP_MS_WITHPEER | CHAP_MS_PEER |
583 CHAP_MS2_WITHPEER | CHAP_MS2_PEER);
585 auth_mschap_bits >>= CHAP_MS_SHIFT;
588 numbits += auth_mschap_bits & 1;
589 auth_mschap_bits >>= 1;
590 }
while (auth_mschap_bits);
592 ppp_error(
"MPPE required, but auth done in both directions.");
593 lcp_close(pcb,
"MPPE required but not available");
597 ppp_error(
"MPPE required, but MS-CHAP[v2] auth not performed.");
598 lcp_close(pcb,
"MPPE required but not available");
603 if (!pcb->mppe_keys_set) {
604 ppp_error(
"MPPE required, but keys are not available. " 605 "Possible plugin problem?");
606 lcp_close(pcb,
"MPPE required but not available");
611 if (pcb->auth_done & (CHAP_MS_WITHPEER | CHAP_MS_PEER)) {
613 if (go->mppe & MPPE_OPT_40) {
614 ppp_notice(
"Disabling 40-bit MPPE; MS-CHAP LM not supported");
615 go->mppe &= ~MPPE_OPT_40;
616 wo->mppe &= ~MPPE_OPT_40;
621 if (!(go->mppe & (MPPE_OPT_40 | MPPE_OPT_128))) {
623 ppp_error(
"MPPE required, but both 40-bit and 128-bit disabled.");
624 lcp_close(pcb,
"MPPE required but not available");
631 #if BSDCOMPRESS_SUPPORT 632 ao->bsd_compress = go->bsd_compress = 0;
634 #if PREDICTOR_SUPPORT 635 ao->predictor_1 = go->predictor_1 = 0;
636 ao->predictor_2 = go->predictor_2 = 0;
639 ao->deflate = go->deflate = 0;
648 #if BSDCOMPRESS_SUPPORT 652 if (go->bsd_compress) {
653 opt_buf[0] = CI_BSD_COMPRESS;
654 opt_buf[1] = CILEN_BSD_COMPRESS;
656 if (go->bsd_bits < BSD_MIN_BITS) {
657 go->bsd_compress = 0;
660 opt_buf[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
661 res = ccp_test(pcb, opt_buf, CILEN_BSD_COMPRESS, 0);
664 }
else if (res < 0) {
665 go->bsd_compress = 0;
677 if (go->deflate_correct) {
678 opt_buf[0] = CI_DEFLATE;
679 opt_buf[1] = CILEN_DEFLATE;
680 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
682 if (go->deflate_size < DEFLATE_MIN_WORKS) {
683 go->deflate_correct = 0;
686 opt_buf[2] = DEFLATE_MAKE_OPT(go->deflate_size);
687 res = ccp_test(pcb, opt_buf, CILEN_DEFLATE, 0);
690 }
else if (res < 0) {
691 go->deflate_correct = 0;
697 if (go->deflate_draft) {
698 opt_buf[0] = CI_DEFLATE_DRAFT;
699 opt_buf[1] = CILEN_DEFLATE;
700 opt_buf[3] = DEFLATE_CHK_SEQUENCE;
702 if (go->deflate_size < DEFLATE_MIN_WORKS) {
703 go->deflate_draft = 0;
706 opt_buf[2] = DEFLATE_MAKE_OPT(go->deflate_size);
707 res = ccp_test(pcb, opt_buf, CILEN_DEFLATE, 0);
710 }
else if (res < 0) {
711 go->deflate_draft = 0;
717 if (!go->deflate_correct && !go->deflate_draft)
721 #if PREDICTOR_SUPPORT 725 if (go->predictor_1) {
726 opt_buf[0] = CI_PREDICTOR_1;
727 opt_buf[1] = CILEN_PREDICTOR_1;
728 if (ccp_test(pcb, opt_buf, CILEN_PREDICTOR_1, 0) <= 0)
731 if (go->predictor_2) {
732 opt_buf[0] = CI_PREDICTOR_2;
733 opt_buf[1] = CILEN_PREDICTOR_2;
734 if (ccp_test(pcb, opt_buf, CILEN_PREDICTOR_2, 0) <= 0)
743 static int ccp_cilen(fsm *f) {
744 ppp_pcb *pcb = f->pcb;
745 ccp_options *go = &pcb->ccp_gotoptions;
748 #if BSDCOMPRESS_SUPPORT 749 + (go->bsd_compress? CILEN_BSD_COMPRESS: 0)
752 + (go->deflate && go->deflate_correct? CILEN_DEFLATE: 0)
753 + (go->deflate && go->deflate_draft? CILEN_DEFLATE: 0)
755 #
if PREDICTOR_SUPPORT
756 + (go->predictor_1? CILEN_PREDICTOR_1: 0)
757 + (go->predictor_2? CILEN_PREDICTOR_2: 0)
760 + (go->mppe? CILEN_MPPE: 0)
768 static void ccp_addci(fsm *f, u_char *p,
int *lenp) {
769 ppp_pcb *pcb = f->pcb;
770 ccp_options *go = &pcb->ccp_gotoptions;
781 MPPE_OPTS_TO_CI(go->mppe, &p[2]);
782 mppe_init(pcb, &pcb->mppe_decomp, go->mppe);
788 if (go->deflate_correct) {
790 p[1] = CILEN_DEFLATE;
791 p[2] = DEFLATE_MAKE_OPT(go->deflate_size);
792 p[3] = DEFLATE_CHK_SEQUENCE;
795 if (go->deflate_draft) {
796 p[0] = CI_DEFLATE_DRAFT;
797 p[1] = CILEN_DEFLATE;
798 p[2] = p[2 - CILEN_DEFLATE];
799 p[3] = DEFLATE_CHK_SEQUENCE;
804 #if BSDCOMPRESS_SUPPORT 805 if (go->bsd_compress) {
806 p[0] = CI_BSD_COMPRESS;
807 p[1] = CILEN_BSD_COMPRESS;
808 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits);
809 p += CILEN_BSD_COMPRESS;
812 #if PREDICTOR_SUPPORT 814 if (go->predictor_1) {
815 p[0] = CI_PREDICTOR_1;
816 p[1] = CILEN_PREDICTOR_1;
817 p += CILEN_PREDICTOR_1;
819 if (go->predictor_2) {
820 p[0] = CI_PREDICTOR_2;
821 p[1] = CILEN_PREDICTOR_2;
822 p += CILEN_PREDICTOR_2;
826 go->method = (p > p0)? p0[0]: 0;
835 static int ccp_ackci(fsm *f, u_char *p,
int len) {
836 ppp_pcb *pcb = f->pcb;
837 ccp_options *go = &pcb->ccp_gotoptions;
838 #if BSDCOMPRESS_SUPPORT || PREDICTOR_SUPPORT 844 u_char opt_buf[CILEN_MPPE];
846 opt_buf[0] = CI_MPPE;
847 opt_buf[1] = CILEN_MPPE;
848 MPPE_OPTS_TO_CI(go->mppe, &opt_buf[2]);
849 if (len < CILEN_MPPE || memcmp(opt_buf, p, CILEN_MPPE))
860 if (len < CILEN_DEFLATE
861 || p[0] != (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
862 || p[1] != CILEN_DEFLATE
863 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
864 || p[3] != DEFLATE_CHK_SEQUENCE)
867 len -= CILEN_DEFLATE;
871 if (go->deflate_correct && go->deflate_draft) {
872 if (len < CILEN_DEFLATE
873 || p[0] != CI_DEFLATE_DRAFT
874 || p[1] != CILEN_DEFLATE
875 || p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
876 || p[3] != DEFLATE_CHK_SEQUENCE)
879 len -= CILEN_DEFLATE;
883 #if BSDCOMPRESS_SUPPORT 884 if (go->bsd_compress) {
885 if (len < CILEN_BSD_COMPRESS
886 || p[0] != CI_BSD_COMPRESS || p[1] != CILEN_BSD_COMPRESS
887 || p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
889 p += CILEN_BSD_COMPRESS;
890 len -= CILEN_BSD_COMPRESS;
892 if (p == p0 && len == 0)
896 #if PREDICTOR_SUPPORT 897 if (go->predictor_1) {
898 if (len < CILEN_PREDICTOR_1
899 || p[0] != CI_PREDICTOR_1 || p[1] != CILEN_PREDICTOR_1)
901 p += CILEN_PREDICTOR_1;
902 len -= CILEN_PREDICTOR_1;
904 if (p == p0 && len == 0)
907 if (go->predictor_2) {
908 if (len < CILEN_PREDICTOR_2
909 || p[0] != CI_PREDICTOR_2 || p[1] != CILEN_PREDICTOR_2)
911 p += CILEN_PREDICTOR_2;
912 len -= CILEN_PREDICTOR_2;
914 if (p == p0 && len == 0)
928 static int ccp_nakci(fsm *f, u_char *p,
int len,
int treat_as_reject) {
929 ppp_pcb *pcb = f->pcb;
930 ccp_options *go = &pcb->ccp_gotoptions;
934 #if !MPPE_SUPPORT && !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT 939 memset(&no, 0,
sizeof(no));
943 if (go->mppe && len >= CILEN_MPPE
944 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
950 MPPE_CI_TO_OPTS(&p[2], try_.mppe);
951 if ((try_.mppe & MPPE_OPT_STATEFUL) && pcb->settings.refuse_mppe_stateful) {
952 ppp_error(
"Refusing MPPE stateful mode offered by peer");
954 }
else if (((go->mppe | MPPE_OPT_STATEFUL) & try_.mppe) != try_.mppe) {
960 ppp_error(
"MPPE required but peer negotiation failed");
961 lcp_close(pcb,
"MPPE required but peer negotiation failed");
966 if (go->deflate && len >= CILEN_DEFLATE
967 && p[0] == (go->deflate_correct? CI_DEFLATE: CI_DEFLATE_DRAFT)
968 && p[1] == CILEN_DEFLATE) {
974 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
975 || DEFLATE_SIZE(p[2]) < DEFLATE_MIN_WORKS
976 || p[3] != DEFLATE_CHK_SEQUENCE)
978 else if (DEFLATE_SIZE(p[2]) < go->deflate_size)
979 try_.deflate_size = DEFLATE_SIZE(p[2]);
981 len -= CILEN_DEFLATE;
982 if (go->deflate_correct && go->deflate_draft
983 && len >= CILEN_DEFLATE && p[0] == CI_DEFLATE_DRAFT
984 && p[1] == CILEN_DEFLATE) {
986 len -= CILEN_DEFLATE;
990 #if BSDCOMPRESS_SUPPORT 991 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
992 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
998 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION)
999 try_.bsd_compress = 0;
1000 else if (BSD_NBITS(p[2]) < go->bsd_bits)
1001 try_.bsd_bits = BSD_NBITS(p[2]);
1002 p += CILEN_BSD_COMPRESS;
1003 len -= CILEN_BSD_COMPRESS;
1013 if (f->state != PPP_FSM_OPENED)
1021 static int ccp_rejci(fsm *f, u_char *p,
int len) {
1022 ppp_pcb *pcb = f->pcb;
1023 ccp_options *go = &pcb->ccp_gotoptions;
1032 if (len == 0 && pcb->ccp_all_rejected)
1036 if (go->mppe && len >= CILEN_MPPE
1037 && p[0] == CI_MPPE && p[1] == CILEN_MPPE) {
1038 ppp_error(
"MPPE required but peer refused");
1039 lcp_close(pcb,
"MPPE required but peer refused");
1045 if (go->deflate_correct && len >= CILEN_DEFLATE
1046 && p[0] == CI_DEFLATE && p[1] == CILEN_DEFLATE) {
1047 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1048 || p[3] != DEFLATE_CHK_SEQUENCE)
1050 try_.deflate_correct = 0;
1052 len -= CILEN_DEFLATE;
1054 if (go->deflate_draft && len >= CILEN_DEFLATE
1055 && p[0] == CI_DEFLATE_DRAFT && p[1] == CILEN_DEFLATE) {
1056 if (p[2] != DEFLATE_MAKE_OPT(go->deflate_size)
1057 || p[3] != DEFLATE_CHK_SEQUENCE)
1059 try_.deflate_draft = 0;
1061 len -= CILEN_DEFLATE;
1063 if (!try_.deflate_correct && !try_.deflate_draft)
1066 #if BSDCOMPRESS_SUPPORT 1067 if (go->bsd_compress && len >= CILEN_BSD_COMPRESS
1068 && p[0] == CI_BSD_COMPRESS && p[1] == CILEN_BSD_COMPRESS) {
1069 if (p[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION, go->bsd_bits))
1071 try_.bsd_compress = 0;
1072 p += CILEN_BSD_COMPRESS;
1073 len -= CILEN_BSD_COMPRESS;
1076 #if PREDICTOR_SUPPORT 1077 if (go->predictor_1 && len >= CILEN_PREDICTOR_1
1078 && p[0] == CI_PREDICTOR_1 && p[1] == CILEN_PREDICTOR_1) {
1079 try_.predictor_1 = 0;
1080 p += CILEN_PREDICTOR_1;
1081 len -= CILEN_PREDICTOR_1;
1083 if (go->predictor_2 && len >= CILEN_PREDICTOR_2
1084 && p[0] == CI_PREDICTOR_2 && p[1] == CILEN_PREDICTOR_2) {
1085 try_.predictor_2 = 0;
1086 p += CILEN_PREDICTOR_2;
1087 len -= CILEN_PREDICTOR_2;
1094 if (f->state != PPP_FSM_OPENED)
1105 static int ccp_reqci(fsm *f, u_char *p,
int *lenp,
int dont_nak) {
1106 ppp_pcb *pcb = f->pcb;
1107 ccp_options *ho = &pcb->ccp_hisoptions;
1108 ccp_options *ao = &pcb->ccp_allowoptions;
1110 #if DEFLATE_SUPPORT || BSDCOMPRESS_SUPPORT 1115 int len, clen, type;
1117 u8_t rej_for_ci_mppe = 1;
1125 memset(ho, 0,
sizeof(ccp_options));
1126 ho->method = (len > 0)? p[0]: 0;
1130 if (len < 2 || p[1] < 2 || p[1] > len) {
1142 if (!ao->mppe || clen != CILEN_MPPE) {
1146 MPPE_CI_TO_OPTS(&p[2], ho->mppe);
1149 if (ho->mppe & MPPE_OPT_UNSUPPORTED) {
1151 ho->mppe &= ~MPPE_OPT_UNSUPPORTED;
1153 if (ho->mppe & MPPE_OPT_UNKNOWN) {
1155 ho->mppe &= ~MPPE_OPT_UNKNOWN;
1159 if (ho->mppe & MPPE_OPT_STATEFUL) {
1166 if (pcb->settings.refuse_mppe_stateful) {
1167 ppp_error(
"Refusing MPPE stateful mode offered by peer");
1174 if ((ho->mppe & MPPE_OPT_128)
1175 && (ho->mppe & MPPE_OPT_40)) {
1178 if (ao->mppe & MPPE_OPT_128)
1179 ho->mppe &= ~MPPE_OPT_40;
1180 else if (ao->mppe & MPPE_OPT_40)
1181 ho->mppe &= ~MPPE_OPT_128;
1186 }
else if (ho->mppe & MPPE_OPT_128) {
1187 if (!(ao->mppe & MPPE_OPT_128)) {
1191 }
else if (ho->mppe & MPPE_OPT_40) {
1192 if (!(ao->mppe & MPPE_OPT_40)) {
1202 ho->mppe = ao->mppe;
1206 MPPE_OPTS_TO_CI(ho->mppe, &p[2]);
1207 if (newret == CONFACK) {
1210 mppe_init(pcb, &pcb->mppe_comp, ho->mppe);
1216 mtu = netif_get_mtu(pcb);
1218 netif_set_mtu(pcb, mtu - MPPE_PAD);
1228 rej_for_ci_mppe = 0;
1233 case CI_DEFLATE_DRAFT:
1234 if (!ao->deflate || clen != CILEN_DEFLATE
1235 || (!ao->deflate_correct && type == CI_DEFLATE)
1236 || (!ao->deflate_draft && type == CI_DEFLATE_DRAFT)) {
1242 ho->deflate_size = nb = DEFLATE_SIZE(p[2]);
1243 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL
1244 || p[3] != DEFLATE_CHK_SEQUENCE
1245 || nb > ao->deflate_size || nb < DEFLATE_MIN_WORKS) {
1248 p[2] = DEFLATE_MAKE_OPT(ao->deflate_size);
1249 p[3] = DEFLATE_CHK_SEQUENCE;
1263 res = ccp_test(pcb, p, CILEN_DEFLATE, 1);
1266 if (res < 0 || nb == DEFLATE_MIN_WORKS || dont_nak) {
1268 p[2] = DEFLATE_MAKE_OPT(ho->deflate_size);
1273 p[2] = DEFLATE_MAKE_OPT(nb);
1278 #if BSDCOMPRESS_SUPPORT 1279 case CI_BSD_COMPRESS:
1280 if (!ao->bsd_compress || clen != CILEN_BSD_COMPRESS) {
1285 ho->bsd_compress = 1;
1286 ho->bsd_bits = nb = BSD_NBITS(p[2]);
1287 if (BSD_VERSION(p[2]) != BSD_CURRENT_VERSION
1288 || nb > ao->bsd_bits || nb < BSD_MIN_BITS) {
1291 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, ao->bsd_bits);
1305 res = ccp_test(pcb, p, CILEN_BSD_COMPRESS, 1);
1308 if (res < 0 || nb == BSD_MIN_BITS || dont_nak) {
1310 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION,
1316 p[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION, nb);
1321 #if PREDICTOR_SUPPORT 1322 case CI_PREDICTOR_1:
1323 if (!ao->predictor_1 || clen != CILEN_PREDICTOR_1) {
1328 ho->predictor_1 = 1;
1330 && ccp_test(pcb, p, CILEN_PREDICTOR_1, 1) <= 0) {
1335 case CI_PREDICTOR_2:
1336 if (!ao->predictor_2 || clen != CILEN_PREDICTOR_2) {
1341 ho->predictor_2 = 1;
1343 && ccp_test(pcb, p, CILEN_PREDICTOR_2, 1) <= 0) {
1354 if (newret == CONFNAK && dont_nak)
1356 if (!(newret == CONFACK || (newret == CONFNAK && ret == CONFREJ))) {
1358 if (newret == CONFREJ && ret == CONFNAK)
1362 MEMCPY(retp, p, clen);
1370 if (ret != CONFACK) {
1371 if (ret == CONFREJ && *lenp == retp - p0)
1372 pcb->ccp_all_rejected = 1;
1377 if (ret == CONFREJ && ao->mppe && rej_for_ci_mppe) {
1378 ppp_error(
"MPPE required but peer negotiation failed");
1379 lcp_close(pcb,
"MPPE required but peer negotiation failed");
1388 static const char *method_name(ccp_options *opt, ccp_options *opt2) {
1389 static char result[64];
1390 #if !DEFLATE_SUPPORT && !BSDCOMPRESS_SUPPORT 1394 if (!ccp_anycompress(opt))
1396 switch (opt->method) {
1401 char *q = result +
sizeof(result);
1403 ppp_slprintf(p, q - p,
"MPPE ");
1405 if (opt->mppe & MPPE_OPT_128) {
1406 ppp_slprintf(p, q - p,
"128-bit ");
1409 if (opt->mppe & MPPE_OPT_40) {
1410 ppp_slprintf(p, q - p,
"40-bit ");
1413 if (opt->mppe & MPPE_OPT_STATEFUL)
1414 ppp_slprintf(p, q - p,
"stateful");
1416 ppp_slprintf(p, q - p,
"stateless");
1423 case CI_DEFLATE_DRAFT:
1424 if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
1425 ppp_slprintf(result,
sizeof(result),
"Deflate%s (%d/%d)",
1426 (opt->method == CI_DEFLATE_DRAFT?
"(old#)":
""),
1427 opt->deflate_size, opt2->deflate_size);
1429 ppp_slprintf(result,
sizeof(result),
"Deflate%s (%d)",
1430 (opt->method == CI_DEFLATE_DRAFT?
"(old#)":
""),
1434 #if BSDCOMPRESS_SUPPORT 1435 case CI_BSD_COMPRESS:
1436 if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
1437 ppp_slprintf(result,
sizeof(result),
"BSD-Compress (%d/%d)",
1438 opt->bsd_bits, opt2->bsd_bits);
1440 ppp_slprintf(result,
sizeof(result),
"BSD-Compress (%d)",
1444 #if PREDICTOR_SUPPORT 1445 case CI_PREDICTOR_1:
1446 return "Predictor 1";
1447 case CI_PREDICTOR_2:
1448 return "Predictor 2";
1451 ppp_slprintf(result,
sizeof(result),
"Method %d", opt->method);
1459 static void ccp_up(fsm *f) {
1460 ppp_pcb *pcb = f->pcb;
1461 ccp_options *go = &pcb->ccp_gotoptions;
1462 ccp_options *ho = &pcb->ccp_hisoptions;
1465 ccp_set(pcb, 1, 1, go->method, ho->method);
1466 if (ccp_anycompress(go)) {
1467 if (ccp_anycompress(ho)) {
1468 if (go->method == ho->method) {
1469 ppp_notice(
"%s compression enabled", method_name(go, ho));
1471 ppp_strlcpy(method1, method_name(go, NULL),
sizeof(method1));
1472 ppp_notice(
"%s / %s compression enabled",
1473 method1, method_name(ho, NULL));
1476 ppp_notice(
"%s receive compression enabled", method_name(go, NULL));
1477 }
else if (ccp_anycompress(ho))
1478 ppp_notice(
"%s transmit compression enabled", method_name(ho, NULL));
1481 continue_networks(pcb);
1489 static void ccp_down(fsm *f) {
1490 ppp_pcb *pcb = f->pcb;
1492 ccp_options *go = &pcb->ccp_gotoptions;
1495 if (pcb->ccp_localstate & RACK_PENDING)
1496 UNTIMEOUT(ccp_rack_timeout, f);
1497 pcb->ccp_localstate = 0;
1498 ccp_set(pcb, 1, 0, 0, 0);
1502 if (pcb->lcp_fsm.state == PPP_FSM_OPENED) {
1504 ppp_error(
"MPPE disabled");
1505 lcp_close(pcb,
"MPPE disabled");
1511 #if PRINTPKT_SUPPORT 1515 static const char*
const ccp_codenames[] = {
1516 "ConfReq",
"ConfAck",
"ConfNak",
"ConfRej",
1517 "TermReq",
"TermAck",
"CodeRej",
1518 NULL, NULL, NULL, NULL, NULL, NULL,
1519 "ResetReq",
"ResetAck",
1522 static int ccp_printpkt(
const u_char *p,
int plen,
void (*printer) (
void *,
const char *, ...),
void *arg) {
1523 const u_char *p0, *optend;
1528 if (plen < HEADERLEN)
1532 len = (p[2] << 8) + p[3];
1533 if (len < HEADERLEN || len > plen)
1536 if (code >= 1 && code <= (
int)LWIP_ARRAYSIZE(ccp_codenames) && ccp_codenames[code-1] != NULL)
1537 printer(arg,
" %s", ccp_codenames[code-1]);
1539 printer(arg,
" code=0x%x", code);
1540 printer(arg,
" id=0x%x",
id);
1553 if (optlen < 2 || optlen > len)
1557 optend = p + optlen;
1561 if (optlen >= CILEN_MPPE) {
1564 MPPE_CI_TO_OPTS(&p[2], mppe_opts);
1565 printer(arg,
"mppe %s %s %s %s %s %s%s",
1566 (p[2] & MPPE_H_BIT)?
"+H":
"-H",
1567 (p[5] & MPPE_M_BIT)?
"+M":
"-M",
1568 (p[5] & MPPE_S_BIT)?
"+S":
"-S",
1569 (p[5] & MPPE_L_BIT)?
"+L":
"-L",
1570 (p[5] & MPPE_D_BIT)?
"+D":
"-D",
1571 (p[5] & MPPE_C_BIT)?
"+C":
"-C",
1572 (mppe_opts & MPPE_OPT_UNKNOWN)?
" +U":
"");
1573 if (mppe_opts & MPPE_OPT_UNKNOWN)
1574 printer(arg,
" (%.2x %.2x %.2x %.2x)",
1575 p[2], p[3], p[4], p[5]);
1582 case CI_DEFLATE_DRAFT:
1583 if (optlen >= CILEN_DEFLATE) {
1584 printer(arg,
"deflate%s %d",
1585 (code == CI_DEFLATE_DRAFT?
"(old#)":
""),
1586 DEFLATE_SIZE(p[2]));
1587 if (DEFLATE_METHOD(p[2]) != DEFLATE_METHOD_VAL)
1588 printer(arg,
" method %d", DEFLATE_METHOD(p[2]));
1589 if (p[3] != DEFLATE_CHK_SEQUENCE)
1590 printer(arg,
" check %d", p[3]);
1595 #if BSDCOMPRESS_SUPPORT 1596 case CI_BSD_COMPRESS:
1597 if (optlen >= CILEN_BSD_COMPRESS) {
1598 printer(arg,
"bsd v%d %d", BSD_VERSION(p[2]),
1600 p += CILEN_BSD_COMPRESS;
1604 #if PREDICTOR_SUPPORT 1605 case CI_PREDICTOR_1:
1606 if (optlen >= CILEN_PREDICTOR_1) {
1607 printer(arg,
"predictor 1");
1608 p += CILEN_PREDICTOR_1;
1611 case CI_PREDICTOR_2:
1612 if (optlen >= CILEN_PREDICTOR_2) {
1613 printer(arg,
"predictor 2");
1614 p += CILEN_PREDICTOR_2;
1622 printer(arg,
" %.2x", *p++);
1629 if (len > 0 && *p >=
' ' && *p < 0x7f) {
1630 ppp_print_string(p, len, printer, arg);
1641 printer(arg,
" %.2x", *p++);
1660 static void ccp_datainput(ppp_pcb *pcb, u_char *pkt,
int len) {
1663 ccp_options *go = &pcb->ccp_gotoptions;
1669 if (f->state == PPP_FSM_OPENED) {
1670 if (ccp_fatal_error(pcb)) {
1674 ppp_error(
"Lost compression sync: disabling compression");
1675 ccp_close(pcb,
"Lost compression sync");
1681 ppp_error(
"Too many MPPE errors, closing LCP");
1682 lcp_close(pcb,
"Too many MPPE errors");
1691 if (!(pcb->ccp_localstate & RACK_PENDING)) {
1692 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1693 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1694 pcb->ccp_localstate |= RACK_PENDING;
1696 pcb->ccp_localstate |= RREQ_REPEAT;
1706 void ccp_resetrequest(ppp_pcb *pcb) {
1707 fsm *f = &pcb->ccp_fsm;
1709 if (f->state != PPP_FSM_OPENED)
1717 if (!(pcb->ccp_localstate & RACK_PENDING)) {
1718 fsm_sdata(f, CCP_RESETREQ, f->reqid = ++f->id, NULL, 0);
1719 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1720 pcb->ccp_localstate |= RACK_PENDING;
1722 pcb->ccp_localstate |= RREQ_REPEAT;
1728 static void ccp_rack_timeout(
void *arg) {
1730 ppp_pcb *pcb = f->pcb;
1732 if (f->state == PPP_FSM_OPENED && (pcb->ccp_localstate & RREQ_REPEAT)) {
1733 fsm_sdata(f, CCP_RESETREQ, f->reqid, NULL, 0);
1734 TIMEOUT(ccp_rack_timeout, f, RACKTIMEOUT);
1735 pcb->ccp_localstate &= ~RREQ_REPEAT;
1737 pcb->ccp_localstate &= ~RACK_PENDING;
#define LWIP_UNUSED_ARG(x)