2 * ccp.c - PPP Compression Control Protocol.
4 * Copyright (c) 1994-2002 Paul Mackerras. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. The name(s) of the authors of this software must not be used to
14 * endorse or promote products derived from this software without
15 * prior written permission.
17 * 3. Redistributions of any form whatsoever must retain the following
19 * "This product includes software developed by Paul Mackerras
20 * <paulus@samba.org>".
22 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
23 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
25 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
27 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
28 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
31 #define RCSID "$Id: ccp.c,v 1.50 2005/06/26 19:34:41 carlsonj Exp $"
39 #include <net/ppp-comp.h>
42 #include "chap_ms.h" /* mppe_xxxx_key, mppe_keys_set */
43 #include "lcp.h" /* lcp_close(), lcp_fsm */
46 static const char rcsid
[] = RCSID
;
49 * Unfortunately there is a bug in zlib which means that using a
50 * size of 8 (window size = 256) for Deflate compression will cause
51 * buffer overruns and kernel crashes in the deflate module.
52 * Until this is fixed we only accept sizes in the range 9 .. 15.
53 * Thanks to James Carlson for pointing this out.
55 #define DEFLATE_MIN_WORKS 9
58 * Command-line options.
60 static int setbsdcomp
__P((char **));
61 static int setdeflate
__P((char **));
62 static char bsd_value
[8];
63 static char deflate_value
[8];
65 static option_t ccp_option_list
[] = {
66 { "noccp", o_bool
, &ccp_protent
.enabled_flag
,
67 "Disable CCP negotiation" },
68 { "-ccp", o_bool
, &ccp_protent
.enabled_flag
,
69 "Disable CCP negotiation", OPT_ALIAS
},
71 { "bsdcomp", o_special
, (void *)setbsdcomp
,
72 "Request BSD-Compress packet compression",
73 OPT_PRIO
| OPT_A2STRVAL
| OPT_STATIC
, bsd_value
},
74 { "nobsdcomp", o_bool
, &ccp_wantoptions
[0].bsd_compress
,
75 "don't allow BSD-Compress", OPT_PRIOSUB
| OPT_A2CLR
,
76 &ccp_allowoptions
[0].bsd_compress
},
77 { "-bsdcomp", o_bool
, &ccp_wantoptions
[0].bsd_compress
,
78 "don't allow BSD-Compress", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
79 &ccp_allowoptions
[0].bsd_compress
},
81 { "deflate", o_special
, (void *)setdeflate
,
82 "request Deflate compression",
83 OPT_PRIO
| OPT_A2STRVAL
| OPT_STATIC
, deflate_value
},
84 { "nodeflate", o_bool
, &ccp_wantoptions
[0].deflate
,
85 "don't allow Deflate compression", OPT_PRIOSUB
| OPT_A2CLR
,
86 &ccp_allowoptions
[0].deflate
},
87 { "-deflate", o_bool
, &ccp_wantoptions
[0].deflate
,
88 "don't allow Deflate compression", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
89 &ccp_allowoptions
[0].deflate
},
91 { "nodeflatedraft", o_bool
, &ccp_wantoptions
[0].deflate_draft
,
92 "don't use draft deflate #", OPT_A2COPY
,
93 &ccp_allowoptions
[0].deflate_draft
},
95 { "predictor1", o_bool
, &ccp_wantoptions
[0].predictor_1
,
96 "request Predictor-1", OPT_PRIO
| 1 },
97 { "nopredictor1", o_bool
, &ccp_wantoptions
[0].predictor_1
,
98 "don't allow Predictor-1", OPT_PRIOSUB
| OPT_A2CLR
,
99 &ccp_allowoptions
[0].predictor_1
},
100 { "-predictor1", o_bool
, &ccp_wantoptions
[0].predictor_1
,
101 "don't allow Predictor-1", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
102 &ccp_allowoptions
[0].predictor_1
},
104 { "lzs", o_bool
, &ccp_wantoptions
[0].lzs
,
105 "request Stac LZS", 1, &ccp_allowoptions
[0].lzs
, OPT_PRIO
},
106 { "+lzs", o_bool
, &ccp_wantoptions
[0].lzs
,
107 "request Stac LZS", 1, &ccp_allowoptions
[0].lzs
, OPT_ALIAS
| OPT_PRIO
},
108 { "nolzs", o_bool
, &ccp_wantoptions
[0].lzs
,
109 "don't allow Stac LZS", OPT_PRIOSUB
| OPT_A2CLR
,
110 &ccp_allowoptions
[0].lzs
},
111 { "-lzs", o_bool
, &ccp_wantoptions
[0].lzs
,
112 "don't allow Stac LZS", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
113 &ccp_allowoptions
[0].lzs
},
116 { "mppc", o_bool
, &ccp_wantoptions
[0].mppc
,
117 "request MPPC compression", 1, &ccp_allowoptions
[0].mppc
, OPT_PRIO
},
118 { "+mppc", o_bool
, &ccp_wantoptions
[0].mppc
,
119 "request MPPC compression", 1, &ccp_allowoptions
[0].mppc
,
120 OPT_ALIAS
| OPT_PRIO
},
121 { "nomppc", o_bool
, &ccp_wantoptions
[0].mppc
,
122 "don't allow MPPC compression", OPT_PRIOSUB
| OPT_A2CLR
,
123 &ccp_allowoptions
[0].mppc
},
124 { "-mppc", o_bool
, &ccp_wantoptions
[0].mppc
,
125 "don't allow MPPC compression", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
126 &ccp_allowoptions
[0].mppc
},
128 { "require-mppe", o_bool
, &ccp_wantoptions
[0].mppe
,
129 "require MPPE encryption", 1, &ccp_allowoptions
[0].mppe
, OPT_PRIO
},
130 { "+mppe", o_bool
, &ccp_wantoptions
[0].mppe
,
131 "require MPPE encryption", 1, &ccp_allowoptions
[0].mppe
,
132 OPT_ALIAS
| OPT_PRIO
},
133 { "nomppe", o_bool
, &ccp_wantoptions
[0].mppe
,
134 "don't allow MPPE encryption", OPT_PRIOSUB
| OPT_A2CLR
,
135 &ccp_allowoptions
[0].mppe
},
136 { "-mppe", o_bool
, &ccp_wantoptions
[0].mppe
,
137 "don't allow MPPE encryption", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
138 &ccp_allowoptions
[0].mppe
},
140 { "require-mppe-40", o_bool
, &ccp_wantoptions
[0].mppe_40
,
141 "require MPPE 40-bit encryption", 1, &ccp_allowoptions
[0].mppe_40
,
143 { "+mppe-40", o_bool
, &ccp_wantoptions
[0].mppe_40
,
144 "require MPPE 40-bit encryption", 1, &ccp_allowoptions
[0].mppe_40
,
145 OPT_ALIAS
| OPT_PRIO
},
146 { "nomppe-40", o_bool
, &ccp_wantoptions
[0].mppe_40
,
147 "don't allow MPPE 40-bit encryption", OPT_PRIOSUB
| OPT_A2CLR
,
148 &ccp_allowoptions
[0].mppe_40
},
149 { "-mppe-40", o_bool
, &ccp_wantoptions
[0].mppe_40
,
150 "don't allow MPPE 40-bit encryption", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
151 &ccp_allowoptions
[0].mppe_40
},
153 { "require-mppe-56", o_bool
, &ccp_wantoptions
[0].mppe_56
,
154 "require MPPE 56-bit encryption", 1, &ccp_allowoptions
[0].mppe_56
,
156 { "+mppe-56", o_bool
, &ccp_wantoptions
[0].mppe_56
,
157 "require MPPE 56-bit encryption", 1, &ccp_allowoptions
[0].mppe_56
,
158 OPT_ALIAS
| OPT_PRIO
},
159 { "nomppe-56", o_bool
, &ccp_wantoptions
[0].mppe_56
,
160 "don't allow MPPE 56-bit encryption", OPT_PRIOSUB
| OPT_A2CLR
,
161 &ccp_allowoptions
[0].mppe_56
},
162 { "-mppe-56", o_bool
, &ccp_wantoptions
[0].mppe_56
,
163 "don't allow MPPE 56-bit encryption", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
164 &ccp_allowoptions
[0].mppe_56
},
166 { "require-mppe-128", o_bool
, &ccp_wantoptions
[0].mppe_128
,
167 "require MPPE 128-bit encryption", 1, &ccp_allowoptions
[0].mppe_128
,
169 { "+mppe-128", o_bool
, &ccp_wantoptions
[0].mppe_128
,
170 "require MPPE 128-bit encryption", 1, &ccp_allowoptions
[0].mppe_128
,
171 OPT_ALIAS
| OPT_PRIO
},
172 { "nomppe-128", o_bool
, &ccp_wantoptions
[0].mppe_128
,
173 "don't allow MPPE 128-bit encryption", OPT_PRIOSUB
| OPT_A2CLR
,
174 &ccp_allowoptions
[0].mppe_128
},
175 { "-mppe-128", o_bool
, &ccp_wantoptions
[0].mppe_128
,
176 "don't allow MPPE 128-bit encryption", OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
,
177 &ccp_allowoptions
[0].mppe_128
},
179 { "nomppe-stateful", o_bool
, &ccp_wantoptions
[0].mppe_stateless
,
180 "disallow MPPE stateful mode", 1, &ccp_allowoptions
[0].mppe_stateless
,
182 { "mppe-stateful", o_bool
, &ccp_wantoptions
[0].mppe_stateless
,
183 "allow MPPE stateful mode", OPT_PRIOSUB
| OPT_A2CLR
,
184 &ccp_allowoptions
[0].mppe_stateless
},
191 * Protocol entry points from main code.
193 static void ccp_init
__P((int unit
));
194 static void ccp_open
__P((int unit
));
195 static void ccp_close
__P((int unit
, char *));
196 static void ccp_lowerup
__P((int unit
));
197 static void ccp_lowerdown
__P((int));
198 static void ccp_input
__P((int unit
, u_char
*pkt
, int len
));
199 static void ccp_protrej
__P((int unit
));
200 static int ccp_printpkt
__P((u_char
*pkt
, int len
,
201 void (*printer
) __P((void *, char *, ...)),
203 static void ccp_datainput
__P((int unit
, u_char
*pkt
, int len
));
205 struct protent ccp_protent
= {
225 fsm ccp_fsm
[NUM_PPP
];
226 ccp_options ccp_wantoptions
[NUM_PPP
]; /* what to request the peer to use */
227 ccp_options ccp_gotoptions
[NUM_PPP
]; /* what the peer agreed to do */
228 ccp_options ccp_allowoptions
[NUM_PPP
]; /* what we'll agree to do */
229 ccp_options ccp_hisoptions
[NUM_PPP
]; /* what we agreed to do */
232 * Callbacks for fsm code.
234 static void ccp_resetci
__P((fsm
*));
235 static int ccp_cilen
__P((fsm
*));
236 static void ccp_addci
__P((fsm
*, u_char
*, int *));
237 static int ccp_ackci
__P((fsm
*, u_char
*, int));
238 static int ccp_nakci
__P((fsm
*, u_char
*, int, int));
239 static int ccp_rejci
__P((fsm
*, u_char
*, int));
240 static int ccp_reqci
__P((fsm
*, u_char
*, int *, int));
241 static void ccp_up
__P((fsm
*));
242 static void ccp_down
__P((fsm
*));
243 static int ccp_extcode
__P((fsm
*, int, int, u_char
*, int));
244 static void ccp_rack_timeout
__P((void *));
245 static char *method_name
__P((ccp_options
*, ccp_options
*));
247 static fsm_callbacks ccp_callbacks
= {
266 * Do we want / did we get any compression?
268 #define ANY_COMPRESS(opt) ((opt).deflate || (opt).bsd_compress \
269 || (opt).predictor_1 || (opt).predictor_2 \
270 || (opt).lzs || (opt).mppc || (opt).mppe)
273 * Local state (mainly for handling reset-reqs and reset-acks).
275 static int ccp_localstate
[NUM_PPP
];
276 #define RACK_PENDING 1 /* waiting for reset-ack */
277 #define RREQ_REPEAT 2 /* send another reset-req if no reset-ack */
279 #define RACKTIMEOUT 1 /* second */
281 static int all_rejected
[NUM_PPP
]; /* we rejected all peer's options */
294 abits
= rbits
= strtol(str
, &endp
, 0);
295 if (endp
!= str
&& *endp
== ',') {
297 abits
= strtol(str
, &endp
, 0);
299 if (*endp
!= 0 || endp
== str
) {
300 option_error("invalid parameter '%s' for bsdcomp option", *argv
);
303 if ((rbits
!= 0 && (rbits
< BSD_MIN_BITS
|| rbits
> BSD_MAX_BITS
))
304 || (abits
!= 0 && (abits
< BSD_MIN_BITS
|| abits
> BSD_MAX_BITS
))) {
305 option_error("bsdcomp option values must be 0 or %d .. %d",
306 BSD_MIN_BITS
, BSD_MAX_BITS
);
310 ccp_wantoptions
[0].bsd_compress
= 1;
311 ccp_wantoptions
[0].bsd_bits
= rbits
;
313 ccp_wantoptions
[0].bsd_compress
= 0;
315 ccp_allowoptions
[0].bsd_compress
= 1;
316 ccp_allowoptions
[0].bsd_bits
= abits
;
318 ccp_allowoptions
[0].bsd_compress
= 0;
319 slprintf(bsd_value
, sizeof(bsd_value
),
320 rbits
== abits
? "%d": "%d,%d", rbits
, abits
);
333 abits
= rbits
= strtol(str
, &endp
, 0);
334 if (endp
!= str
&& *endp
== ',') {
336 abits
= strtol(str
, &endp
, 0);
338 if (*endp
!= 0 || endp
== str
) {
339 option_error("invalid parameter '%s' for deflate option", *argv
);
342 if ((rbits
!= 0 && (rbits
< DEFLATE_MIN_SIZE
|| rbits
> DEFLATE_MAX_SIZE
))
343 || (abits
!= 0 && (abits
< DEFLATE_MIN_SIZE
344 || abits
> DEFLATE_MAX_SIZE
))) {
345 option_error("deflate option values must be 0 or %d .. %d",
346 DEFLATE_MIN_SIZE
, DEFLATE_MAX_SIZE
);
349 if (rbits
== DEFLATE_MIN_SIZE
|| abits
== DEFLATE_MIN_SIZE
) {
350 if (rbits
== DEFLATE_MIN_SIZE
)
351 rbits
= DEFLATE_MIN_WORKS
;
352 if (abits
== DEFLATE_MIN_SIZE
)
353 abits
= DEFLATE_MIN_WORKS
;
354 warn("deflate option value of %d changed to %d to avoid zlib bug",
355 DEFLATE_MIN_SIZE
, DEFLATE_MIN_WORKS
);
358 ccp_wantoptions
[0].deflate
= 1;
359 ccp_wantoptions
[0].deflate_size
= rbits
;
361 ccp_wantoptions
[0].deflate
= 0;
363 ccp_allowoptions
[0].deflate
= 1;
364 ccp_allowoptions
[0].deflate_size
= abits
;
366 ccp_allowoptions
[0].deflate
= 0;
367 slprintf(deflate_value
, sizeof(deflate_value
),
368 rbits
== abits
? "%d": "%d,%d", rbits
, abits
);
374 * ccp_init - initialize CCP.
380 fsm
*f
= &ccp_fsm
[unit
];
383 f
->protocol
= PPP_CCP
;
384 f
->callbacks
= &ccp_callbacks
;
387 memset(&ccp_wantoptions
[unit
], 0, sizeof(ccp_options
));
388 memset(&ccp_gotoptions
[unit
], 0, sizeof(ccp_options
));
389 memset(&ccp_allowoptions
[unit
], 0, sizeof(ccp_options
));
390 memset(&ccp_hisoptions
[unit
], 0, sizeof(ccp_options
));
392 ccp_wantoptions
[0].deflate
= 1;
393 ccp_wantoptions
[0].deflate_size
= DEFLATE_MAX_SIZE
;
394 ccp_wantoptions
[0].deflate_correct
= 1;
395 ccp_wantoptions
[0].deflate_draft
= 1;
396 ccp_allowoptions
[0].deflate
= 1;
397 ccp_allowoptions
[0].deflate_size
= DEFLATE_MAX_SIZE
;
398 ccp_allowoptions
[0].deflate_correct
= 1;
399 ccp_allowoptions
[0].deflate_draft
= 1;
401 ccp_wantoptions
[0].bsd_compress
= 1;
402 ccp_wantoptions
[0].bsd_bits
= BSD_MAX_BITS
;
403 ccp_allowoptions
[0].bsd_compress
= 1;
404 ccp_allowoptions
[0].bsd_bits
= BSD_MAX_BITS
;
406 ccp_allowoptions
[0].predictor_1
= 1;
408 ccp_wantoptions
[0].lzs
= 0; /* Stac LZS - will be enabled in the future */
409 ccp_wantoptions
[0].lzs_mode
= LZS_MODE_SEQ
;
410 ccp_wantoptions
[0].lzs_hists
= 1;
411 ccp_allowoptions
[0].lzs
= 0; /* Stac LZS - will be enabled in the future */
412 ccp_allowoptions
[0].lzs_mode
= LZS_MODE_SEQ
;
413 ccp_allowoptions
[0].lzs_hists
= 1;
416 /* by default allow and request MPPC... */
417 ccp_wantoptions
[0].mppc
= ccp_allowoptions
[0].mppc
= 1;
419 /* ... and allow but don't request MPPE */
420 ccp_allowoptions
[0].mppe
= 1;
421 ccp_allowoptions
[0].mppe_40
= 1;
422 ccp_allowoptions
[0].mppe_56
= 1;
423 ccp_allowoptions
[0].mppe_128
= 1;
424 ccp_allowoptions
[0].mppe_stateless
= 1;
425 ccp_wantoptions
[0].mppe
= 0;
426 ccp_wantoptions
[0].mppe_40
= 0;
427 ccp_wantoptions
[0].mppe_56
= 0;
428 ccp_wantoptions
[0].mppe_128
= 0;
429 ccp_wantoptions
[0].mppe_stateless
= 0;
434 * ccp_open - CCP is allowed to come up.
440 fsm
*f
= &ccp_fsm
[unit
];
442 if (f
->state
!= OPENED
)
443 ccp_flags_set(unit
, 1, 0);
446 * Find out which compressors the kernel supports before
447 * deciding whether to open in silent mode.
450 if (!ANY_COMPRESS(ccp_gotoptions
[unit
]))
451 f
->flags
|= OPT_SILENT
;
457 * ccp_close - Terminate CCP.
460 ccp_close(unit
, reason
)
464 ccp_flags_set(unit
, 0, 0);
465 fsm_close(&ccp_fsm
[unit
], reason
);
469 * ccp_lowerup - we may now transmit CCP packets.
475 fsm_lowerup(&ccp_fsm
[unit
]);
479 * ccp_lowerdown - we may not transmit CCP packets.
485 fsm_lowerdown(&ccp_fsm
[unit
]);
489 * ccp_input - process a received CCP packet.
492 ccp_input(unit
, p
, len
)
497 fsm
*f
= &ccp_fsm
[unit
];
501 * Check for a terminate-request so we can print a message.
504 fsm_input(f
, p
, len
);
505 if (oldstate
== OPENED
&& p
[0] == TERMREQ
&& f
->state
!= OPENED
) {
506 notice("Compression disabled by peer.");
508 if (ccp_wantoptions
[unit
].mppe
) {
509 error("MPPE disabled, closing LCP");
510 lcp_close(unit
, "MPPE disabled by peer");
516 * If we get a terminate-ack and we're not asking for compression,
519 if (oldstate
== REQSENT
&& p
[0] == TERMACK
520 && !ANY_COMPRESS(ccp_gotoptions
[unit
]))
521 ccp_close(unit
, "No compression negotiated");
525 * Handle a CCP-specific code.
528 ccp_extcode(f
, code
, id
, p
, len
)
536 if (f
->state
!= OPENED
)
538 /* send a reset-ack, which the transmitter will see and
539 reset its compression state. */
541 /* In case of MPPE/MPPC or LZS we shouldn't send CCP_RESETACK,
542 but we do it in order to reset compressor; CCP_RESETACK is
543 then silently discarded. See functions ppp_send_frame and
544 ppp_ccp_peek in ppp_generic.c (Linux only !!!). All the
545 confusion is caused by the fact that CCP code is splited
546 into two parts - one part is handled by pppd, the other one
547 is handled by kernel. */
549 fsm_sdata(f
, CCP_RESETACK
, id
, NULL
, 0);
553 if (ccp_localstate
[f
->unit
] & RACK_PENDING
&& id
== f
->reqid
) {
554 ccp_localstate
[f
->unit
] &= ~(RACK_PENDING
| RREQ_REPEAT
);
555 UNTIMEOUT(ccp_rack_timeout
, f
);
567 * ccp_protrej - peer doesn't talk CCP.
573 ccp_flags_set(unit
, 0, 0);
574 fsm_lowerdown(&ccp_fsm
[unit
]);
577 if (ccp_wantoptions
[unit
].mppe
) {
578 error("MPPE required but peer negotiation failed");
579 lcp_close(unit
, "MPPE required but peer negotiation failed");
585 * ccp_resetci - initialize at start of negotiation.
591 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
592 u_char opt_buf
[CCP_MAX_OPTION_LENGTH
];
594 *go
= ccp_wantoptions
[f
->unit
];
595 all_rejected
[f
->unit
] = 0;
598 if (go
->mppe
|| go
->mppc
) {
599 ccp_options
*ao
= &ccp_allowoptions
[f
->unit
];
600 int auth_mschap_bits
= auth_done
[f
->unit
];
604 * Start with a basic sanity check: mschap[v2] auth must be in
605 * exactly one direction. RFC 3079 says that the keys are
606 * 'derived from the credentials of the peer that initiated the call',
607 * however the PPP protocol doesn't have such a concept, and pppd
608 * cannot get this info externally. Instead we do the best we can.
609 * NB: If MPPE is required, all other compression opts are invalid.
610 * So, we return right away if we can't do it.
612 if (ccp_wantoptions
[f
->unit
].mppe
) {
613 /* Leave only the mschap auth bits set */
614 auth_mschap_bits
&= (CHAP_MS_WITHPEER
| CHAP_MS_PEER
|
615 CHAP_MS2_WITHPEER
| CHAP_MS2_PEER
);
616 /* Count the mschap auths */
617 auth_mschap_bits
>>= CHAP_MS_SHIFT
;
620 numbits
+= auth_mschap_bits
& 1;
621 auth_mschap_bits
>>= 1;
622 } while (auth_mschap_bits
);
624 error("MPPE required, but auth done in both directions.");
625 lcp_close(f
->unit
, "MPPE required but not available");
629 error("MPPE required, but MS-CHAP[v2] auth not performed.");
630 lcp_close(f
->unit
, "MPPE required but not available");
634 /* A plugin (eg radius) may not have obtained key material. */
635 if (!mppe_keys_set
) {
636 error("MPPE required, but keys are not available. "
637 "Possible plugin problem?");
638 lcp_close(f
->unit
, "MPPE required but not available");
644 * Check whether the kernel knows about the various
645 * compression methods we might request. Key material
649 opt_buf
[0] = CI_MPPE
;
650 opt_buf
[1] = CILEN_MPPE
;
654 opt_buf
[5] = MPPE_MPPC
;
655 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
, 0) <= 0)
659 opt_buf
[0] = CI_MPPE
;
660 opt_buf
[1] = CILEN_MPPE
;
661 opt_buf
[2] = MPPE_STATELESS
;
664 opt_buf
[5] = MPPE_40BIT
;
665 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+ MPPE_MAX_KEY_LEN
, 0) <= 0)
669 opt_buf
[0] = CI_MPPE
;
670 opt_buf
[1] = CILEN_MPPE
;
671 opt_buf
[2] = MPPE_STATELESS
;
674 opt_buf
[5] = MPPE_56BIT
;
675 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+ MPPE_MAX_KEY_LEN
, 0) <= 0)
679 opt_buf
[0] = CI_MPPE
;
680 opt_buf
[1] = CILEN_MPPE
;
681 opt_buf
[2] = MPPE_STATELESS
;
684 opt_buf
[5] = MPPE_128BIT
;
685 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+ MPPE_MAX_KEY_LEN
, 0) <= 0)
688 if (!go
->mppe_40
&& !go
->mppe_56
&& !go
->mppe_128
) {
689 if (ccp_wantoptions
[f
->unit
].mppe
) {
690 error("MPPE required, but kernel has no support.");
691 lcp_close(f
->unit
, "MPPE required but not available");
693 go
->mppe
= go
->mppe_stateless
= 0;
695 /* MPPE is not compatible with other compression types */
696 if (ccp_wantoptions
[f
->unit
].mppe
) {
697 ao
->bsd_compress
= go
->bsd_compress
= 0;
698 ao
->predictor_1
= go
->predictor_1
= 0;
699 ao
->predictor_2
= go
->predictor_2
= 0;
700 ao
->deflate
= go
->deflate
= 0;
701 ao
->lzs
= go
->lzs
= 0;
708 opt_buf
[1] = CILEN_LZS
;
709 opt_buf
[2] = go
->lzs_hists
>> 8;
710 opt_buf
[3] = go
->lzs_hists
& 0xff;
711 opt_buf
[4] = LZS_MODE_SEQ
;
712 if (ccp_test(f
->unit
, opt_buf
, CILEN_LZS
, 0) <= 0)
715 if (go
->bsd_compress
) {
716 opt_buf
[0] = CI_BSD_COMPRESS
;
717 opt_buf
[1] = CILEN_BSD_COMPRESS
;
718 opt_buf
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
, BSD_MIN_BITS
);
719 if (ccp_test(f
->unit
, opt_buf
, CILEN_BSD_COMPRESS
, 0) <= 0)
720 go
->bsd_compress
= 0;
723 if (go
->deflate_correct
) {
724 opt_buf
[0] = CI_DEFLATE
;
725 opt_buf
[1] = CILEN_DEFLATE
;
726 opt_buf
[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS
);
727 opt_buf
[3] = DEFLATE_CHK_SEQUENCE
;
728 if (ccp_test(f
->unit
, opt_buf
, CILEN_DEFLATE
, 0) <= 0)
729 go
->deflate_correct
= 0;
731 if (go
->deflate_draft
) {
732 opt_buf
[0] = CI_DEFLATE_DRAFT
;
733 opt_buf
[1] = CILEN_DEFLATE
;
734 opt_buf
[2] = DEFLATE_MAKE_OPT(DEFLATE_MIN_WORKS
);
735 opt_buf
[3] = DEFLATE_CHK_SEQUENCE
;
736 if (ccp_test(f
->unit
, opt_buf
, CILEN_DEFLATE
, 0) <= 0)
737 go
->deflate_draft
= 0;
739 if (!go
->deflate_correct
&& !go
->deflate_draft
)
742 if (go
->predictor_1
) {
743 opt_buf
[0] = CI_PREDICTOR_1
;
744 opt_buf
[1] = CILEN_PREDICTOR_1
;
745 if (ccp_test(f
->unit
, opt_buf
, CILEN_PREDICTOR_1
, 0) <= 0)
748 if (go
->predictor_2
) {
749 opt_buf
[0] = CI_PREDICTOR_2
;
750 opt_buf
[1] = CILEN_PREDICTOR_2
;
751 if (ccp_test(f
->unit
, opt_buf
, CILEN_PREDICTOR_2
, 0) <= 0)
757 * ccp_cilen - Return total length of our configuration info.
763 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
765 return (go
->bsd_compress
? CILEN_BSD_COMPRESS
: 0)
766 + (go
->deflate
? CILEN_DEFLATE
: 0)
767 + (go
->predictor_1
? CILEN_PREDICTOR_1
: 0)
768 + (go
->predictor_2
? CILEN_PREDICTOR_2
: 0)
769 + (go
->lzs
? CILEN_LZS
: 0)
770 + ((go
->mppe
|| go
->mppc
)? CILEN_MPPE
: 0);
774 * ccp_addci - put our requests in a packet.
777 ccp_addci(f
, p
, lenp
)
783 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
784 ccp_options
*ao
= &ccp_allowoptions
[f
->unit
];
785 ccp_options
*wo
= &ccp_wantoptions
[f
->unit
];
789 * Add the compression types that we can receive, in decreasing
790 * preference order. Get the kernel to allocate the first one
791 * in case it gets Acked.
794 if (go
->mppe
|| go
->mppc
|| (!wo
->mppe
&& ao
->mppe
)) {
795 u_char opt_buf
[CILEN_MPPE
+ MPPE_MAX_KEY_LEN
];
799 p
[2] = (go
->mppe_stateless
? MPPE_STATELESS
: 0);
802 p
[5] = (go
->mppe_40
? MPPE_40BIT
: 0) | (go
->mppe_56
? MPPE_56BIT
: 0) |
803 (go
->mppe_128
? MPPE_128BIT
: 0) | (go
->mppc
? MPPE_MPPC
: 0);
805 BCOPY(p
, opt_buf
, CILEN_MPPE
);
806 BCOPY(mppe_recv_key
, &opt_buf
[CILEN_MPPE
], MPPE_MAX_KEY_LEN
);
807 res
= ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+ MPPE_MAX_KEY_LEN
, 0);
811 /* This shouldn't happen, we've already tested it! */
812 go
->mppe
= go
->mppe_40
= go
->mppe_56
= go
->mppe_128
=
813 go
->mppe_stateless
= go
->mppc
= 0;
814 if (ccp_wantoptions
[f
->unit
].mppe
)
815 lcp_close(f
->unit
, "MPPE required but not available in kernel");
822 p
[2] = go
->lzs_hists
>> 8;
823 p
[3] = go
->lzs_hists
& 0xff;
825 res
= ccp_test(f
->unit
, p
, CILEN_LZS
, 0);
832 p
[0] = go
->deflate_correct
? CI_DEFLATE
: CI_DEFLATE_DRAFT
;
833 p
[1] = CILEN_DEFLATE
;
834 p
[2] = DEFLATE_MAKE_OPT(go
->deflate_size
);
835 p
[3] = DEFLATE_CHK_SEQUENCE
;
840 if (go
->deflate_size
< DEFLATE_MIN_WORKS
) {
844 res
= ccp_test(f
->unit
, p
, CILEN_DEFLATE
, 0);
848 } else if (res
< 0) {
853 p
[2] = DEFLATE_MAKE_OPT(go
->deflate_size
);
856 if (p
!= p0
&& go
->deflate_correct
&& go
->deflate_draft
) {
857 p
[0] = CI_DEFLATE_DRAFT
;
858 p
[1] = CILEN_DEFLATE
;
859 p
[2] = p
[2 - CILEN_DEFLATE
];
860 p
[3] = DEFLATE_CHK_SEQUENCE
;
864 if (go
->bsd_compress
) {
865 p
[0] = CI_BSD_COMPRESS
;
866 p
[1] = CILEN_BSD_COMPRESS
;
867 p
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
, go
->bsd_bits
);
869 p
+= CILEN_BSD_COMPRESS
; /* not the first option */
872 if (go
->bsd_bits
< BSD_MIN_BITS
) {
873 go
->bsd_compress
= 0;
876 res
= ccp_test(f
->unit
, p
, CILEN_BSD_COMPRESS
, 0);
878 p
+= CILEN_BSD_COMPRESS
;
880 } else if (res
< 0) {
881 go
->bsd_compress
= 0;
885 p
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
, go
->bsd_bits
);
889 /* XXX Should Predictor 2 be preferable to Predictor 1? */
890 if (go
->predictor_1
) {
891 p
[0] = CI_PREDICTOR_1
;
892 p
[1] = CILEN_PREDICTOR_1
;
893 if (p
== p0
&& ccp_test(f
->unit
, p
, CILEN_PREDICTOR_1
, 0) <= 0) {
896 p
+= CILEN_PREDICTOR_1
;
899 if (go
->predictor_2
) {
900 p
[0] = CI_PREDICTOR_2
;
901 p
[1] = CILEN_PREDICTOR_2
;
902 if (p
== p0
&& ccp_test(f
->unit
, p
, CILEN_PREDICTOR_2
, 0) <= 0) {
905 p
+= CILEN_PREDICTOR_2
;
909 go
->method
= (p
> p0
)? p0
[0]: -1;
915 * ccp_ackci - process a received configure-ack, and return
916 * 1 if the packet was OK.
924 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
925 ccp_options
*ao
= &ccp_allowoptions
[f
->unit
];
926 ccp_options
*wo
= &ccp_wantoptions
[f
->unit
];
930 if (go
->mppe
|| go
->mppc
|| (!wo
->mppe
&& ao
->mppe
)) {
932 || p
[1] != CILEN_MPPE
|| p
[0] != CI_MPPE
933 || p
[2] != (go
->mppe_stateless
? MPPE_STATELESS
: 0)
936 || (p
[5] != ((go
->mppe_40
? MPPE_40BIT
: 0) |
937 (go
->mppc
? MPPE_MPPC
: 0))
938 && p
[5] != ((go
->mppe_56
? MPPE_56BIT
: 0) |
939 (go
->mppc
? MPPE_MPPC
: 0))
940 && p
[5] != ((go
->mppe_128
? MPPE_128BIT
: 0) |
941 (go
->mppc
? MPPE_MPPC
: 0))))
943 if (go
->mppe_40
|| go
->mppe_56
|| go
->mppe_128
)
947 /* Cope with first/fast ack */
948 if (p
== p0
&& len
== 0)
953 if (len
< CILEN_LZS
|| p
[0] != CI_LZS
|| p
[1] != CILEN_LZS
954 || p
[2] != go
->lzs_hists
>>8 || p
[3] != (go
->lzs_hists
&0xff)
955 || p
[4] != LZS_MODE_SEQ
)
959 /* XXX Cope with first/fast ack */
960 if (p
== p0
&& len
== 0)
964 if (len
< CILEN_DEFLATE
965 || p
[0] != (go
->deflate_correct
? CI_DEFLATE
: CI_DEFLATE_DRAFT
)
966 || p
[1] != CILEN_DEFLATE
967 || p
[2] != DEFLATE_MAKE_OPT(go
->deflate_size
)
968 || p
[3] != DEFLATE_CHK_SEQUENCE
)
971 len
-= CILEN_DEFLATE
;
972 /* XXX Cope with first/fast ack */
975 if (go
->deflate_correct
&& go
->deflate_draft
) {
976 if (len
< CILEN_DEFLATE
977 || p
[0] != CI_DEFLATE_DRAFT
978 || p
[1] != CILEN_DEFLATE
979 || p
[2] != DEFLATE_MAKE_OPT(go
->deflate_size
)
980 || p
[3] != DEFLATE_CHK_SEQUENCE
)
983 len
-= CILEN_DEFLATE
;
986 if (go
->bsd_compress
) {
987 if (len
< CILEN_BSD_COMPRESS
988 || p
[0] != CI_BSD_COMPRESS
|| p
[1] != CILEN_BSD_COMPRESS
989 || p
[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION
, go
->bsd_bits
))
991 p
+= CILEN_BSD_COMPRESS
;
992 len
-= CILEN_BSD_COMPRESS
;
993 /* XXX Cope with first/fast ack */
994 if (p
== p0
&& len
== 0)
997 if (go
->predictor_1
) {
998 if (len
< CILEN_PREDICTOR_1
999 || p
[0] != CI_PREDICTOR_1
|| p
[1] != CILEN_PREDICTOR_1
)
1001 p
+= CILEN_PREDICTOR_1
;
1002 len
-= CILEN_PREDICTOR_1
;
1003 /* XXX Cope with first/fast ack */
1004 if (p
== p0
&& len
== 0)
1007 if (go
->predictor_2
) {
1008 if (len
< CILEN_PREDICTOR_2
1009 || p
[0] != CI_PREDICTOR_2
|| p
[1] != CILEN_PREDICTOR_2
)
1011 p
+= CILEN_PREDICTOR_2
;
1012 len
-= CILEN_PREDICTOR_2
;
1013 /* XXX Cope with first/fast ack */
1014 if (p
== p0
&& len
== 0)
1024 * ccp_nakci - process received configure-nak.
1025 * Returns 1 if the nak was OK.
1028 ccp_nakci(f
, p
, len
, treat_as_reject
)
1032 int treat_as_reject
;
1034 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
1035 ccp_options
*ao
= &ccp_allowoptions
[f
->unit
];
1036 ccp_options
*wo
= &ccp_wantoptions
[f
->unit
];
1037 ccp_options no
; /* options we've seen already */
1038 ccp_options
try; /* options to ask for next time */
1040 memset(&no
, 0, sizeof(no
));
1044 if ((go
->mppe
|| go
->mppc
|| (!wo
->mppe
&& ao
->mppe
)) &&
1045 len
>= CILEN_MPPE
&& p
[0] == CI_MPPE
&& p
[1] == CILEN_MPPE
) {
1049 if (!(p
[5] & MPPE_MPPC
))
1061 if (go
->mppe_stateless
)
1062 no
.mppe_stateless
= 1;
1065 if ((p
[5] & MPPE_40BIT
))
1068 try.mppe_40
= (p
[5] == 0) ? 1 : 0;
1071 if ((p
[5] & MPPE_56BIT
))
1074 try.mppe_56
= (p
[5] == 0) ? 1 : 0;
1077 if ((p
[5] & MPPE_128BIT
))
1080 try.mppe_128
= (p
[5] == 0) ? 1 : 0;
1083 if (ao
->mppe_stateless
) {
1084 if ((p
[2] & MPPE_STATELESS
) || wo
->mppe_stateless
)
1085 try.mppe_stateless
= 1;
1087 try.mppe_stateless
= 0;
1090 if (!try.mppe_56
&& !try.mppe_40
&& !try.mppe_128
) {
1091 try.mppe
= try.mppe_stateless
= 0;
1093 /* we require encryption, but peer doesn't support it
1094 so we close connection */
1095 wo
->mppc
= wo
->mppe
= wo
->mppe_stateless
= wo
->mppe_40
=
1096 wo
->mppe_56
= wo
->mppe_128
= 0;
1097 lcp_close(f
->unit
, "MPPE required but cannot negotiate MPPE "
1101 if (wo
->mppe
&& (wo
->mppe_40
!= try.mppe_40
) &&
1102 (wo
->mppe_56
!= try.mppe_56
) && (wo
->mppe_128
!= try.mppe_128
)) {
1103 /* cannot negotiate key length */
1104 wo
->mppc
= wo
->mppe
= wo
->mppe_stateless
= wo
->mppe_40
=
1105 wo
->mppe_56
= wo
->mppe_128
= 0;
1106 lcp_close(f
->unit
, "Cannot negotiate MPPE key length");
1108 if (try.mppe_40
&& try.mppe_56
&& try.mppe_128
)
1109 try.mppe_40
= try.mppe_56
= 0;
1111 if (try.mppe_56
&& try.mppe_128
)
1114 if (try.mppe_40
&& try.mppe_128
)
1117 if (try.mppe_40
&& try.mppe_56
)
1125 if (go
->lzs
&& len
>= CILEN_LZS
&& p
[0] == CI_LZS
&& p
[1] == CILEN_LZS
) {
1127 if (((p
[2]<<8)|p
[3]) > 1 || (p
[4] != LZS_MODE_SEQ
&&
1128 p
[4] != LZS_MODE_EXT
))
1131 try.lzs_mode
= p
[4];
1132 try.lzs_hists
= (p
[2] << 8) | p
[3];
1138 if (go
->deflate
&& len
>= CILEN_DEFLATE
1139 && p
[0] == (go
->deflate_correct
? CI_DEFLATE
: CI_DEFLATE_DRAFT
)
1140 && p
[1] == CILEN_DEFLATE
) {
1143 * Peer wants us to use a different code size or something.
1144 * Stop asking for Deflate if we don't understand his suggestion.
1146 if (DEFLATE_METHOD(p
[2]) != DEFLATE_METHOD_VAL
1147 || DEFLATE_SIZE(p
[2]) < DEFLATE_MIN_WORKS
1148 || p
[3] != DEFLATE_CHK_SEQUENCE
)
1150 else if (DEFLATE_SIZE(p
[2]) < go
->deflate_size
)
1151 try.deflate_size
= DEFLATE_SIZE(p
[2]);
1153 len
-= CILEN_DEFLATE
;
1154 if (go
->deflate_correct
&& go
->deflate_draft
1155 && len
>= CILEN_DEFLATE
&& p
[0] == CI_DEFLATE_DRAFT
1156 && p
[1] == CILEN_DEFLATE
) {
1158 len
-= CILEN_DEFLATE
;
1162 if (go
->bsd_compress
&& len
>= CILEN_BSD_COMPRESS
1163 && p
[0] == CI_BSD_COMPRESS
&& p
[1] == CILEN_BSD_COMPRESS
) {
1164 no
.bsd_compress
= 1;
1166 * Peer wants us to use a different number of bits
1167 * or a different version.
1169 if (BSD_VERSION(p
[2]) != BSD_CURRENT_VERSION
)
1170 try.bsd_compress
= 0;
1171 else if (BSD_NBITS(p
[2]) < go
->bsd_bits
)
1172 try.bsd_bits
= BSD_NBITS(p
[2]);
1173 p
+= CILEN_BSD_COMPRESS
;
1174 len
-= CILEN_BSD_COMPRESS
;
1178 * Predictor-1 and 2 have no options, so they can't be Naked.
1180 * There may be remaining options but we ignore them.
1183 if (f
->state
!= OPENED
)
1189 * ccp_rejci - reject some of our suggested compression methods.
1192 ccp_rejci(f
, p
, len
)
1197 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
1198 ccp_options
try; /* options to request next time */
1203 * Cope with empty configure-rejects by ceasing to send
1204 * configure-requests.
1206 if (len
== 0 && all_rejected
[f
->unit
])
1210 if ((go
->mppe
|| go
->mppc
) && len
>= CILEN_MPPE
1211 && p
[0] == CI_MPPE
&& p
[1] == CILEN_MPPE
) {
1212 ccp_options
*wo
= &ccp_wantoptions
[f
->unit
];
1213 if (p
[2] != (go
->mppe_stateless
? MPPE_STATELESS
: 0) ||
1216 p
[5] != ((go
->mppe_40
? MPPE_40BIT
: 0) |
1217 (go
->mppe_56
? MPPE_56BIT
: 0) |
1218 (go
->mppe_128
? MPPE_128BIT
: 0) |
1219 (go
->mppc
? MPPE_MPPC
: 0)))
1231 if (go
->mppe_stateless
)
1232 try.mppe_stateless
= 0;
1233 if (!try.mppe_56
&& !try.mppe_40
&& !try.mppe_128
)
1234 try.mppe
= try.mppe_stateless
= 0;
1235 if (wo
->mppe
) { /* we want MPPE but cannot negotiate key length */
1236 wo
->mppc
= wo
->mppe
= wo
->mppe_stateless
= wo
->mppe_40
=
1237 wo
->mppe_56
= wo
->mppe_128
= 0;
1238 lcp_close(f
->unit
, "MPPE required but cannot negotiate MPPE "
1246 if (go
->lzs
&& len
>= CILEN_LZS
&& p
[0] == CI_LZS
&& p
[1] == CILEN_LZS
) {
1247 if (p
[2] != go
->lzs_hists
>>8 || p
[3] != (go
->lzs_hists
&0xff)
1248 || p
[4] != go
->lzs_mode
)
1254 if (go
->deflate_correct
&& len
>= CILEN_DEFLATE
1255 && p
[0] == CI_DEFLATE
&& p
[1] == CILEN_DEFLATE
) {
1256 if (p
[2] != DEFLATE_MAKE_OPT(go
->deflate_size
)
1257 || p
[3] != DEFLATE_CHK_SEQUENCE
)
1258 return 0; /* Rej is bad */
1259 try.deflate_correct
= 0;
1261 len
-= CILEN_DEFLATE
;
1263 if (go
->deflate_draft
&& len
>= CILEN_DEFLATE
1264 && p
[0] == CI_DEFLATE_DRAFT
&& p
[1] == CILEN_DEFLATE
) {
1265 if (p
[2] != DEFLATE_MAKE_OPT(go
->deflate_size
)
1266 || p
[3] != DEFLATE_CHK_SEQUENCE
)
1267 return 0; /* Rej is bad */
1268 try.deflate_draft
= 0;
1270 len
-= CILEN_DEFLATE
;
1272 if (!try.deflate_correct
&& !try.deflate_draft
)
1274 if (go
->bsd_compress
&& len
>= CILEN_BSD_COMPRESS
1275 && p
[0] == CI_BSD_COMPRESS
&& p
[1] == CILEN_BSD_COMPRESS
) {
1276 if (p
[2] != BSD_MAKE_OPT(BSD_CURRENT_VERSION
, go
->bsd_bits
))
1278 try.bsd_compress
= 0;
1279 p
+= CILEN_BSD_COMPRESS
;
1280 len
-= CILEN_BSD_COMPRESS
;
1282 if (go
->predictor_1
&& len
>= CILEN_PREDICTOR_1
1283 && p
[0] == CI_PREDICTOR_1
&& p
[1] == CILEN_PREDICTOR_1
) {
1284 try.predictor_1
= 0;
1285 p
+= CILEN_PREDICTOR_1
;
1286 len
-= CILEN_PREDICTOR_1
;
1288 if (go
->predictor_2
&& len
>= CILEN_PREDICTOR_2
1289 && p
[0] == CI_PREDICTOR_2
&& p
[1] == CILEN_PREDICTOR_2
) {
1290 try.predictor_2
= 0;
1291 p
+= CILEN_PREDICTOR_2
;
1292 len
-= CILEN_PREDICTOR_2
;
1298 if (f
->state
!= OPENED
)
1305 * ccp_reqci - processed a received configure-request.
1306 * Returns CONFACK, CONFNAK or CONFREJ and the packet modified
1310 ccp_reqci(f
, p
, lenp
, dont_nak
)
1316 int ret
, newret
, res
;
1317 u_char
*p0
, *retp
, p2
, p5
;
1318 int len
, clen
, type
, nb
;
1319 ccp_options
*ho
= &ccp_hisoptions
[f
->unit
];
1320 ccp_options
*ao
= &ccp_allowoptions
[f
->unit
];
1321 ccp_options
*wo
= &ccp_wantoptions
[f
->unit
];
1323 u_char opt_buf
[CILEN_MPPE
+ MPPE_MAX_KEY_LEN
];
1331 memset(ho
, 0, sizeof(ccp_options
));
1332 ho
->method
= (len
> 0)? p
[0]: -1;
1336 if (len
< 2 || p
[1] < 2 || p
[1] > len
) {
1348 if ((!ao
->mppc
&& !ao
->mppe
) || clen
!= CILEN_MPPE
) {
1354 /* not sure what they want, tell 'em what we got */
1355 if (((p
[2] & ~MPPE_STATELESS
) != 0 || p
[3] != 0 || p
[4] != 0 ||
1356 (p
[5] & ~(MPPE_40BIT
| MPPE_56BIT
| MPPE_128BIT
|
1357 MPPE_MPPC
)) != 0 || p
[5] == 0) ||
1358 (p
[2] == 0 && p
[3] == 0 && p
[4] == 0 && p
[5] == 0)) {
1362 if ((p
[5] & MPPE_MPPC
)) {
1365 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1366 opt_buf
[2] = opt_buf
[3] = opt_buf
[4] = 0;
1367 opt_buf
[5] = MPPE_MPPC
;
1368 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
, 1) <= 0) {
1375 if (wo
->mppe
|| ao
->mppe
) {
1385 if ((p
[2] & MPPE_STATELESS
)) {
1386 if (ao
->mppe_stateless
) {
1387 if (wo
->mppe_stateless
)
1388 ho
->mppe_stateless
= 1;
1392 p
[2] &= ~MPPE_STATELESS
;
1397 p
[2] &= ~MPPE_STATELESS
;
1400 if (wo
->mppe_stateless
&& !dont_nak
) {
1401 wo
->mppe_stateless
= 0;
1403 p
[2] |= MPPE_STATELESS
;
1407 if ((p
[5] & ~MPPE_MPPC
) == (MPPE_40BIT
|MPPE_56BIT
|MPPE_128BIT
)) {
1411 p
[5] &= ~(MPPE_40BIT
|MPPE_56BIT
);
1412 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1413 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1415 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1416 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1418 p
[5] |= (MPPE_40BIT
|MPPE_56BIT
);
1419 p
[5] &= ~MPPE_128BIT
;
1420 goto check_mppe_56_40
;
1424 p
[5] &= ~MPPE_128BIT
;
1425 goto check_mppe_56_40
;
1427 if ((p
[5] & ~MPPE_MPPC
) == (MPPE_56BIT
|MPPE_128BIT
)) {
1431 p
[5] &= ~MPPE_56BIT
;
1432 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1433 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1435 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1436 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1439 p
[5] &= ~MPPE_128BIT
;
1444 p
[5] &= ~MPPE_128BIT
;
1447 if ((p
[5] & ~MPPE_MPPC
) == (MPPE_40BIT
|MPPE_128BIT
)) {
1451 p
[5] &= ~MPPE_40BIT
;
1452 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1453 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1455 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1456 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1459 p
[5] &= ~MPPE_128BIT
;
1464 p
[5] &= ~MPPE_128BIT
;
1467 if ((p
[5] & ~MPPE_MPPC
) == MPPE_128BIT
) {
1470 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1471 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1473 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1474 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1476 p
[5] &= ~MPPE_128BIT
;
1481 p
[5] &= ~MPPE_128BIT
;
1486 if ((p
[5] & ~MPPE_MPPC
) == (MPPE_40BIT
|MPPE_56BIT
)) {
1490 p
[5] &= ~MPPE_40BIT
;
1491 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1492 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1494 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1495 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1498 p
[5] &= ~MPPE_56BIT
;
1504 p
[5] &= ~MPPE_56BIT
;
1508 if ((p
[5] & ~MPPE_MPPC
) == MPPE_56BIT
) {
1511 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1512 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1514 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1515 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1517 p
[5] &= ~MPPE_56BIT
;
1522 p
[5] &= ~MPPE_56BIT
;
1527 if ((p
[5] & ~MPPE_MPPC
) == MPPE_40BIT
) {
1530 BCOPY(p
, opt_buf
, CILEN_MPPE
);
1531 BCOPY(mppe_send_key
, &opt_buf
[CILEN_MPPE
],
1533 if (ccp_test(f
->unit
, opt_buf
, CILEN_MPPE
+
1534 MPPE_MAX_KEY_LEN
, 1) <= 0) {
1536 p
[5] &= ~MPPE_40BIT
;
1541 p
[5] &= ~MPPE_40BIT
;
1545 if (!ho
->mppe_40
&& !ho
->mppe_56
&& !ho
->mppe_128
) {
1546 if (wo
->mppe_40
|| wo
->mppe_56
|| wo
->mppe_128
) {
1548 p
[2] |= (wo
->mppe_stateless
? MPPE_STATELESS
: 0);
1549 p
[5] |= (wo
->mppe_40
? MPPE_40BIT
: 0) |
1550 (wo
->mppe_56
? MPPE_56BIT
: 0) |
1551 (wo
->mppe_128
? MPPE_128BIT
: 0) |
1552 (wo
->mppc
? MPPE_MPPC
: 0);
1554 ho
->mppe
= ho
->mppe_stateless
= 0;
1557 /* MPPE is not compatible with other compression types */
1559 ao
->bsd_compress
= 0;
1560 ao
->predictor_1
= 0;
1561 ao
->predictor_2
= 0;
1566 if ((!ho
->mppc
|| !ao
->mppc
) && !ho
->mppe
) {
1569 /* We cannot accept this. */
1571 /* Give the peer our idea of what can be used,
1572 so it can choose and confirm */
1573 ho
->mppe
= ao
->mppe
;
1577 * I have commented the code below because according to RFC1547
1578 * MTU is only information for higher level protocols about
1579 * "the maximum allowable length for a packet (q.v.) transmitted
1580 * over a point-to-point link without incurring network layer
1581 * fragmentation." Of course a PPP implementation should be able
1582 * to handle overhead added by MPPE - in our case apropriate code
1583 * is located in drivers/net/ppp_generic.c in the kernel sources.
1585 * According to RFC1661:
1586 * - when negotiated MRU is less than 1500 octets, a PPP
1587 * implementation must still be able to receive at least 1500
1589 * - when PFC is negotiated, a PPP implementation is still
1590 * required to receive frames with uncompressed protocol field.
1592 * So why not to handle MPPE overhead without changing MTU value?
1593 * I am sure that RFC3078, unfortunately silently, assumes that.
1597 * We need to decrease the interface MTU by MPPE_PAD
1598 * because MPPE frames **grow**. The kernel [must]
1599 * allocate MPPE_PAD extra bytes in xmit buffers.
1602 mtu = netif_get_mtu(f->unit);
1604 netif_set_mtu(f->unit, mtu - MPPE_PAD);
1607 if (ccp_wantoptions[f->unit].mppe) {
1608 error("Cannot adjust MTU needed by MPPE.");
1609 lcp_close(f->unit, "Cannot adjust MTU needed by MPPE.");
1617 if (!ao
->lzs
|| clen
!= CILEN_LZS
) {
1623 ho
->lzs_hists
= (p
[2] << 8) | p
[3];
1624 ho
->lzs_mode
= p
[4];
1625 if ((ho
->lzs_hists
!= ao
->lzs_hists
) ||
1626 (ho
->lzs_mode
!= ao
->lzs_mode
)) {
1629 p
[2] = ao
->lzs_hists
>> 8;
1630 p
[3] = ao
->lzs_hists
& 0xff;
1631 p
[4] = ao
->lzs_mode
;
1636 if (p
== p0
&& ccp_test(f
->unit
, p
, CILEN_LZS
, 1) <= 0) {
1642 case CI_DEFLATE_DRAFT
:
1643 if (!ao
->deflate
|| clen
!= CILEN_DEFLATE
1644 || (!ao
->deflate_correct
&& type
== CI_DEFLATE
)
1645 || (!ao
->deflate_draft
&& type
== CI_DEFLATE_DRAFT
)) {
1651 ho
->deflate_size
= nb
= DEFLATE_SIZE(p
[2]);
1652 if (DEFLATE_METHOD(p
[2]) != DEFLATE_METHOD_VAL
1653 || p
[3] != DEFLATE_CHK_SEQUENCE
1654 || nb
> ao
->deflate_size
|| nb
< DEFLATE_MIN_WORKS
) {
1657 p
[2] = DEFLATE_MAKE_OPT(ao
->deflate_size
);
1658 p
[3] = DEFLATE_CHK_SEQUENCE
;
1659 /* fall through to test this #bits below */
1665 * Check whether we can do Deflate with the window
1666 * size they want. If the window is too big, reduce
1667 * it until the kernel can cope and nak with that.
1668 * We only check this for the first option.
1672 res
= ccp_test(f
->unit
, p
, CILEN_DEFLATE
, 1);
1674 break; /* it's OK now */
1675 if (res
< 0 || nb
== DEFLATE_MIN_WORKS
|| dont_nak
) {
1677 p
[2] = DEFLATE_MAKE_OPT(ho
->deflate_size
);
1682 p
[2] = DEFLATE_MAKE_OPT(nb
);
1687 case CI_BSD_COMPRESS
:
1688 if (!ao
->bsd_compress
|| clen
!= CILEN_BSD_COMPRESS
) {
1693 ho
->bsd_compress
= 1;
1694 ho
->bsd_bits
= nb
= BSD_NBITS(p
[2]);
1695 if (BSD_VERSION(p
[2]) != BSD_CURRENT_VERSION
1696 || nb
> ao
->bsd_bits
|| nb
< BSD_MIN_BITS
) {
1699 p
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
, ao
->bsd_bits
);
1700 /* fall through to test this #bits below */
1706 * Check whether we can do BSD-Compress with the code
1707 * size they want. If the code size is too big, reduce
1708 * it until the kernel can cope and nak with that.
1709 * We only check this for the first option.
1713 res
= ccp_test(f
->unit
, p
, CILEN_BSD_COMPRESS
, 1);
1716 if (res
< 0 || nb
== BSD_MIN_BITS
|| dont_nak
) {
1718 p
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
,
1724 p
[2] = BSD_MAKE_OPT(BSD_CURRENT_VERSION
, nb
);
1729 case CI_PREDICTOR_1
:
1730 if (!ao
->predictor_1
|| clen
!= CILEN_PREDICTOR_1
) {
1735 ho
->predictor_1
= 1;
1737 && ccp_test(f
->unit
, p
, CILEN_PREDICTOR_1
, 1) <= 0) {
1742 case CI_PREDICTOR_2
:
1743 if (!ao
->predictor_2
|| clen
!= CILEN_PREDICTOR_2
) {
1748 ho
->predictor_2
= 1;
1750 && ccp_test(f
->unit
, p
, CILEN_PREDICTOR_2
, 1) <= 0) {
1760 if (newret
== CONFNAK
&& dont_nak
)
1762 if (!(newret
== CONFACK
|| (newret
== CONFNAK
&& ret
== CONFREJ
))) {
1763 /* we're returning this option */
1764 if (newret
== CONFREJ
&& ret
== CONFNAK
)
1768 BCOPY(p
, retp
, clen
);
1776 if (ret
!= CONFACK
) {
1777 if (ret
== CONFREJ
&& *lenp
== retp
- p0
)
1778 all_rejected
[f
->unit
] = 1;
1786 * Make a string name for a compression method (or 2).
1789 method_name(opt
, opt2
)
1790 ccp_options
*opt
, *opt2
;
1792 static char result
[64];
1794 if (!ANY_COMPRESS(*opt
))
1796 switch (opt
->method
) {
1801 char *q
= result
+ sizeof(result
); /* 1 past result */
1805 slprintf(p
, q
- p
, "MPPC/MPPE ");
1808 slprintf(p
, q
- p
, "MPPE ");
1811 if (opt
->mppe_128
) {
1812 slprintf(p
, q
- p
, "128-bit ");
1814 } else if (opt
->mppe_56
) {
1815 slprintf(p
, q
- p
, "56-bit ");
1817 } else if (opt
->mppe_40
) {
1818 slprintf(p
, q
- p
, "40-bit ");
1821 if (opt
->mppe_stateless
)
1822 slprintf(p
, q
- p
, "stateless");
1824 slprintf(p
, q
- p
, "stateful");
1825 } else if (opt
->mppc
)
1826 slprintf(p
, q
- p
, "MPPC");
1833 case CI_DEFLATE_DRAFT
:
1834 if (opt2
!= NULL
&& opt2
->deflate_size
!= opt
->deflate_size
)
1835 slprintf(result
, sizeof(result
), "Deflate%s (%d/%d)",
1836 (opt
->method
== CI_DEFLATE_DRAFT
? "(old#)": ""),
1837 opt
->deflate_size
, opt2
->deflate_size
);
1839 slprintf(result
, sizeof(result
), "Deflate%s (%d)",
1840 (opt
->method
== CI_DEFLATE_DRAFT
? "(old#)": ""),
1843 case CI_BSD_COMPRESS
:
1844 if (opt2
!= NULL
&& opt2
->bsd_bits
!= opt
->bsd_bits
)
1845 slprintf(result
, sizeof(result
), "BSD-Compress (%d/%d)",
1846 opt
->bsd_bits
, opt2
->bsd_bits
);
1848 slprintf(result
, sizeof(result
), "BSD-Compress (%d)",
1851 case CI_PREDICTOR_1
:
1852 return "Predictor 1";
1853 case CI_PREDICTOR_2
:
1854 return "Predictor 2";
1856 slprintf(result
, sizeof(result
), "Method %d", opt
->method
);
1862 * CCP has come up - inform the kernel driver and log a message.
1868 ccp_options
*go
= &ccp_gotoptions
[f
->unit
];
1869 ccp_options
*ho
= &ccp_hisoptions
[f
->unit
];
1872 ccp_flags_set(f
->unit
, 1, 1);
1873 if (ANY_COMPRESS(*go
)) {
1874 if (ANY_COMPRESS(*ho
)) {
1875 if (go
->method
== ho
->method
) {
1876 notice("%s compression enabled", method_name(go
, ho
));
1878 strlcpy(method1
, method_name(go
, NULL
), sizeof(method1
));
1879 notice("%s / %s compression enabled",
1880 method1
, method_name(ho
, NULL
));
1883 notice("%s receive compression enabled", method_name(go
, NULL
));
1884 } else if (ANY_COMPRESS(*ho
))
1885 notice("%s transmit compression enabled", method_name(ho
, NULL
));
1887 if (go
->mppe
|| go
->mppc
) {
1888 BZERO(mppe_recv_key
, MPPE_MAX_KEY_LEN
);
1889 BZERO(mppe_send_key
, MPPE_MAX_KEY_LEN
);
1890 continue_networks(f
->unit
); /* Bring up IP et al */
1896 * CCP has gone down - inform the kernel driver.
1902 if (ccp_localstate
[f
->unit
] & RACK_PENDING
)
1903 UNTIMEOUT(ccp_rack_timeout
, f
);
1904 ccp_localstate
[f
->unit
] = 0;
1905 ccp_flags_set(f
->unit
, 1, 0);
1907 if (ccp_gotoptions
[f
->unit
].mppe
) {
1908 ccp_gotoptions
[f
->unit
].mppe
= 0;
1909 if (lcp_fsm
[f
->unit
].state
== OPENED
) {
1910 /* If LCP is not already going down, make sure it does. */
1911 error("MPPE disabled");
1912 lcp_close(f
->unit
, "MPPE disabled");
1919 * Print the contents of a CCP packet.
1921 static char *ccp_codenames
[] = {
1922 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1923 "TermReq", "TermAck", "CodeRej",
1924 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
1925 "ResetReq", "ResetAck",
1929 ccp_printpkt(p
, plen
, printer
, arg
)
1932 void (*printer
) __P((void *, char *, ...));
1935 u_char
*p0
, *optend
;
1940 if (plen
< HEADERLEN
)
1944 len
= (p
[2] << 8) + p
[3];
1945 if (len
< HEADERLEN
|| len
> plen
)
1948 if (code
>= 1 && code
<= sizeof(ccp_codenames
) / sizeof(char *)
1949 && ccp_codenames
[code
-1] != NULL
)
1950 printer(arg
, " %s", ccp_codenames
[code
-1]);
1952 printer(arg
, " code=0x%x", code
);
1953 printer(arg
, " id=0x%x", id
);
1962 /* print list of possible compression methods */
1966 if (optlen
< 2 || optlen
> len
)
1970 optend
= p
+ optlen
;
1974 if (optlen
>= CILEN_MPPE
) {
1975 printer(arg
, "mppe %s %s %s %s %s %s",
1976 (p
[2] & MPPE_STATELESS
)? "+H": "-H",
1977 (p
[5] & MPPE_56BIT
)? "+M": "-M",
1978 (p
[5] & MPPE_128BIT
)? "+S": "-S",
1979 (p
[5] & MPPE_40BIT
)? "+L": "-L",
1980 (p
[5] & MPPE_D_BIT
)? "+D": "-D",
1981 (p
[5] & MPPE_MPPC
)? "+C": "-C");
1982 if ((p
[5] & ~(MPPE_56BIT
| MPPE_128BIT
| MPPE_40BIT
|
1983 MPPE_D_BIT
| MPPE_MPPC
)) ||
1984 (p
[2] & ~MPPE_STATELESS
))
1985 printer(arg
, " (%.2x %.2x %.2x %.2x)",
1986 p
[2], p
[3], p
[4], p
[5]);
1992 if (optlen
>= CILEN_LZS
) {
1993 printer(arg
, "lzs %.2x %.2x %.2x", p
[2], p
[3], p
[4]);
1998 case CI_DEFLATE_DRAFT
:
1999 if (optlen
>= CILEN_DEFLATE
) {
2000 printer(arg
, "deflate%s %d",
2001 (code
== CI_DEFLATE_DRAFT
? "(old#)": ""),
2002 DEFLATE_SIZE(p
[2]));
2003 if (DEFLATE_METHOD(p
[2]) != DEFLATE_METHOD_VAL
)
2004 printer(arg
, " method %d", DEFLATE_METHOD(p
[2]));
2005 if (p
[3] != DEFLATE_CHK_SEQUENCE
)
2006 printer(arg
, " check %d", p
[3]);
2010 case CI_BSD_COMPRESS
:
2011 if (optlen
>= CILEN_BSD_COMPRESS
) {
2012 printer(arg
, "bsd v%d %d", BSD_VERSION(p
[2]),
2014 p
+= CILEN_BSD_COMPRESS
;
2017 case CI_PREDICTOR_1
:
2018 if (optlen
>= CILEN_PREDICTOR_1
) {
2019 printer(arg
, "predictor 1");
2020 p
+= CILEN_PREDICTOR_1
;
2023 case CI_PREDICTOR_2
:
2024 if (optlen
>= CILEN_PREDICTOR_2
) {
2025 printer(arg
, "predictor 2");
2026 p
+= CILEN_PREDICTOR_2
;
2031 printer(arg
, " %.2x", *p
++);
2038 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
2039 print_string((char *)p
, len
, printer
, arg
);
2046 /* dump out the rest of the packet in hex */
2048 printer(arg
, " %.2x", *p
++);
2054 * We have received a packet that the decompressor failed to
2055 * decompress. Here we would expect to issue a reset-request, but
2056 * Motorola has a patent on resetting the compressor as a result of
2057 * detecting an error in the decompressed data after decompression.
2058 * (See US patent 5,130,993; international patent publication number
2059 * WO 91/10289; Australian patent 73296/91.)
2061 * So we ask the kernel whether the error was detected after
2062 * decompression; if it was, we take CCP down, thus disabling
2063 * compression :-(, otherwise we issue the reset-request.
2066 ccp_datainput(unit
, pkt
, len
)
2074 if (f
->state
== OPENED
) {
2075 if (ccp_fatal_error(unit
)) {
2077 * Disable compression by taking CCP down.
2079 error("Lost compression sync: disabling compression");
2080 ccp_close(unit
, "Lost compression sync");
2082 /* My module dosn't need this. J.D., 2003-07-06 */
2084 * If we were doing MPPE, we must also take the link down.
2086 if (ccp_gotoptions
[unit
].mppe
) {
2087 error("Too many MPPE errors, closing LCP");
2088 lcp_close(unit
, "Too many MPPE errors");
2093 * When LZS or MPPE/MPPC is negotiated we just send CCP_RESETREQ
2094 * and don't wait for CCP_RESETACK
2096 if ((ccp_gotoptions
[f
->unit
].method
== CI_LZS
) ||
2097 (ccp_gotoptions
[f
->unit
].method
== CI_MPPE
)) {
2098 fsm_sdata(f
, CCP_RESETREQ
, f
->reqid
= ++f
->id
, NULL
, 0);
2102 * Send a reset-request to reset the peer's compressor.
2103 * We don't do that if we are still waiting for an
2104 * acknowledgement to a previous reset-request.
2106 if (!(ccp_localstate
[f
->unit
] & RACK_PENDING
)) {
2107 fsm_sdata(f
, CCP_RESETREQ
, f
->reqid
= ++f
->id
, NULL
, 0);
2108 TIMEOUT(ccp_rack_timeout
, f
, RACKTIMEOUT
);
2109 ccp_localstate
[f
->unit
] |= RACK_PENDING
;
2111 ccp_localstate
[f
->unit
] |= RREQ_REPEAT
;
2117 * Timeout waiting for reset-ack.
2120 ccp_rack_timeout(arg
)
2125 if (f
->state
== OPENED
&& ccp_localstate
[f
->unit
] & RREQ_REPEAT
) {
2126 fsm_sdata(f
, CCP_RESETREQ
, f
->reqid
, NULL
, 0);
2127 TIMEOUT(ccp_rack_timeout
, f
, RACKTIMEOUT
);
2128 ccp_localstate
[f
->unit
] &= ~RREQ_REPEAT
;
2130 ccp_localstate
[f
->unit
] &= ~RACK_PENDING
;