2 * lcp.c - PPP Link Control Protocol.
4 * Copyright (c) 1984-2000 Carnegie Mellon University. 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 "Carnegie Mellon University" must not be used to
19 * endorse or promote products derived from this software without
20 * prior written permission. For permission or any legal
21 * details, please contact
22 * Office of Technology Transfer
23 * Carnegie Mellon University
25 * Pittsburgh, PA 15213-3890
26 * (412) 268-4387, fax: (412) 268-7395
27 * tech-transfer@andrew.cmu.edu
29 * 4. Redistributions of any form whatsoever must retain the following
31 * "This product includes software developed by Computing Services
32 * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43 #include "netif/ppp/ppp_opts.h"
44 #if PPP_SUPPORT /* don't build if not configured for use in lwipopts.h */
56 #include "netif/ppp/ppp_impl.h"
58 #include "netif/ppp/fsm.h"
59 #include "netif/ppp/lcp.h"
61 #include "netif/ppp/chap-new.h"
62 #endif /* CHAP_SUPPORT */
63 #include "netif/ppp/magic.h"
66 * When the link comes up we want to be able to wait for a short while,
67 * or until seeing some input from the peer, before starting to send
68 * configure-requests. We do this by delaying the fsm_lowerup call.
70 /* steal a bit in fsm flags word */
71 #define DELAYED_UP 0x80
73 static void lcp_delayed_up(void *arg
);
76 * LCP-related command-line options.
79 int lcp_echo_interval
= 0; /* Interval between LCP echo-requests */
80 int lcp_echo_fails
= 0; /* Tolerance to unanswered echo-requests */
85 static u_int lcp_echo_interval
= LCP_ECHOINTERVAL
; /* Interval between LCP echo-requests */
86 static u_int lcp_echo_fails
= LCP_MAXECHOFAILS
; /* Tolerance to unanswered echo-requests */
91 bool lcp_echo_adaptive
= 0; /* request echo only if the link was idle */
93 bool lax_recv
= 0; /* accept control chars in asyncmap */
94 bool noendpoint
= 0; /* don't send/accept endpoint discriminator */
98 static int noopt (char **);
99 #endif /* PPP_OPTIONS */
101 #ifdef HAVE_MULTILINK
102 static int setendpoint (char **);
103 static void printendpoint (option_t
*, void (*)(void *, char *, ...),
105 #endif /* HAVE_MULTILINK */
108 static option_t lcp_option_list
[] = {
110 { "-all", o_special_noarg
, (void *)noopt
,
111 "Don't request/allow any LCP options" },
113 { "noaccomp", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
114 "Disable address/control compression",
115 OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
116 { "-ac", o_bool
, &lcp_wantoptions
[0].neg_accompression
,
117 "Disable address/control compression",
118 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_accompression
},
120 { "asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
121 "Set asyncmap (for received packets)",
122 OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
123 { "-as", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
124 "Set asyncmap (for received packets)",
125 OPT_ALIAS
| OPT_OR
, &lcp_wantoptions
[0].neg_asyncmap
},
126 { "default-asyncmap", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
127 "Disable asyncmap negotiation",
128 OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
129 &lcp_allowoptions
[0].neg_asyncmap
},
130 { "-am", o_uint32
, &lcp_wantoptions
[0].asyncmap
,
131 "Disable asyncmap negotiation",
132 OPT_ALIAS
| OPT_OR
| OPT_NOARG
| OPT_VAL(~0U) | OPT_A2CLR
,
133 &lcp_allowoptions
[0].neg_asyncmap
},
135 { "nomagic", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
136 "Disable magic number negotiation (looped-back line detection)",
137 OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
138 { "-mn", o_bool
, &lcp_wantoptions
[0].neg_magicnumber
,
139 "Disable magic number negotiation (looped-back line detection)",
140 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_magicnumber
},
142 { "mru", o_int
, &lcp_wantoptions
[0].mru
,
143 "Set MRU (maximum received packet size) for negotiation",
144 OPT_PRIO
, &lcp_wantoptions
[0].neg_mru
},
145 { "default-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
146 "Disable MRU negotiation (use default 1500)",
147 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
148 { "-mru", o_bool
, &lcp_wantoptions
[0].neg_mru
,
149 "Disable MRU negotiation (use default 1500)",
150 OPT_ALIAS
| OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_mru
},
152 { "mtu", o_int
, &lcp_allowoptions
[0].mru
,
153 "Set our MTU", OPT_LIMITS
, NULL
, MAXMRU
, MINMRU
},
155 { "nopcomp", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
156 "Disable protocol field compression",
157 OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
158 { "-pc", o_bool
, &lcp_wantoptions
[0].neg_pcompression
,
159 "Disable protocol field compression",
160 OPT_ALIAS
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_pcompression
},
162 { "passive", o_bool
, &lcp_wantoptions
[0].passive
,
163 "Set passive mode", 1 },
164 { "-p", o_bool
, &lcp_wantoptions
[0].passive
,
165 "Set passive mode", OPT_ALIAS
| 1 },
167 { "silent", o_bool
, &lcp_wantoptions
[0].silent
,
168 "Set silent mode", 1 },
170 { "lcp-echo-failure", o_int
, &lcp_echo_fails
,
171 "Set number of consecutive echo failures to indicate link failure",
173 { "lcp-echo-interval", o_int
, &lcp_echo_interval
,
174 "Set time in seconds between LCP echo requests", OPT_PRIO
},
176 { "lcp-echo-adaptive", o_bool
, &lcp_echo_adaptive
,
177 "Suppress LCP echo requests if traffic was received", 1 },
179 { "lcp-restart", o_int
, &lcp_fsm
[0].timeouttime
,
180 "Set time in seconds between LCP retransmissions", OPT_PRIO
},
181 { "lcp-max-terminate", o_int
, &lcp_fsm
[0].maxtermtransmits
,
182 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO
},
183 { "lcp-max-configure", o_int
, &lcp_fsm
[0].maxconfreqtransmits
,
184 "Set maximum number of LCP configure-request transmissions", OPT_PRIO
},
185 { "lcp-max-failure", o_int
, &lcp_fsm
[0].maxnakloops
,
186 "Set limit on number of LCP configure-naks", OPT_PRIO
},
188 { "receive-all", o_bool
, &lax_recv
,
189 "Accept all received control characters", 1 },
191 #ifdef HAVE_MULTILINK
192 { "mrru", o_int
, &lcp_wantoptions
[0].mrru
,
193 "Maximum received packet size for multilink bundle",
194 OPT_PRIO
, &lcp_wantoptions
[0].neg_mrru
},
196 { "mpshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
197 "Use short sequence numbers in multilink headers",
198 OPT_PRIO
| 1, &lcp_allowoptions
[0].neg_ssnhf
},
199 { "nompshortseq", o_bool
, &lcp_wantoptions
[0].neg_ssnhf
,
200 "Don't use short sequence numbers in multilink headers",
201 OPT_PRIOSUB
| OPT_A2CLR
, &lcp_allowoptions
[0].neg_ssnhf
},
203 { "endpoint", o_special
, (void *) setendpoint
,
204 "Endpoint discriminator for multilink",
205 OPT_PRIO
| OPT_A2PRINTER
, (void *) printendpoint
},
206 #endif /* HAVE_MULTILINK */
208 { "noendpoint", o_bool
, &noendpoint
,
209 "Don't send or accept multilink endpoint discriminator", 1 },
213 #endif /* PPP_OPTIONS */
216 * Callbacks for fsm code. (CI = Configuration Information)
218 static void lcp_resetci(fsm
*f
); /* Reset our CI */
219 static int lcp_cilen(fsm
*f
); /* Return length of our CI */
220 static void lcp_addci(fsm
*f
, u_char
*ucp
, int *lenp
); /* Add our CI to pkt */
221 static int lcp_ackci(fsm
*f
, u_char
*p
, int len
); /* Peer ack'd our CI */
222 static int lcp_nakci(fsm
*f
, u_char
*p
, int len
, int treat_as_reject
); /* Peer nak'd our CI */
223 static int lcp_rejci(fsm
*f
, u_char
*p
, int len
); /* Peer rej'd our CI */
224 static int lcp_reqci(fsm
*f
, u_char
*inp
, int *lenp
, int reject_if_disagree
); /* Rcv peer CI */
225 static void lcp_up(fsm
*f
); /* We're UP */
226 static void lcp_down(fsm
*f
); /* We're DOWN */
227 static void lcp_starting (fsm
*); /* We need lower layer up */
228 static void lcp_finished (fsm
*); /* We need lower layer down */
229 static int lcp_extcode(fsm
*f
, int code
, int id
, u_char
*inp
, int len
);
230 static void lcp_rprotrej(fsm
*f
, u_char
*inp
, int len
);
233 * routines to send LCP echos to peer
236 static void lcp_echo_lowerup(ppp_pcb
*pcb
);
237 static void lcp_echo_lowerdown(ppp_pcb
*pcb
);
238 static void LcpEchoTimeout(void *arg
);
239 static void lcp_received_echo_reply(fsm
*f
, int id
, u_char
*inp
, int len
);
240 static void LcpSendEchoRequest(fsm
*f
);
241 static void LcpLinkFailure(fsm
*f
);
242 static void LcpEchoCheck(fsm
*f
);
244 static const fsm_callbacks lcp_callbacks
= { /* LCP callback routines */
245 lcp_resetci
, /* Reset our Configuration Information */
246 lcp_cilen
, /* Length of our Configuration Information */
247 lcp_addci
, /* Add our Configuration Information */
248 lcp_ackci
, /* ACK our Configuration Information */
249 lcp_nakci
, /* NAK our Configuration Information */
250 lcp_rejci
, /* Reject our Configuration Information */
251 lcp_reqci
, /* Request peer's Configuration Information */
252 lcp_up
, /* Called when fsm reaches OPENED state */
253 lcp_down
, /* Called when fsm leaves OPENED state */
254 lcp_starting
, /* Called when we want the lower layer up */
255 lcp_finished
, /* Called when we want the lower layer down */
256 NULL
, /* Called when Protocol-Reject received */
257 NULL
, /* Retransmission is necessary */
258 lcp_extcode
, /* Called to handle LCP-specific codes */
259 "LCP" /* String name of protocol */
263 * Protocol entry points.
264 * Some of these are called directly.
267 static void lcp_init(ppp_pcb
*pcb
);
268 static void lcp_input(ppp_pcb
*pcb
, u_char
*p
, int len
);
269 static void lcp_protrej(ppp_pcb
*pcb
);
271 static int lcp_printpkt(const u_char
*p
, int plen
,
272 void (*printer
) (void *, const char *, ...), void *arg
);
273 #endif /* PRINTPKT_SUPPORT */
275 const struct protent lcp_protent
= {
286 #endif /* PRINTPKT_SUPPORT */
289 #endif /* PPP_DATAINPUT */
293 #endif /* PRINTPKT_SUPPORT */
297 #endif /* PPP_OPTIONS */
301 #endif /* DEMAND_SUPPORT */
305 * Length of each type of configuration option (in octets)
309 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
311 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
312 #endif /* CHAP_SUPPORT */
313 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
315 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
316 #endif /* LQR_SUPPORT */
319 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
320 (x) == CONFNAK ? "NAK" : "REJ")
324 * noopt - Disable all options (why?).
330 BZERO((char *) &lcp_wantoptions
[0], sizeof (struct lcp_options
));
331 BZERO((char *) &lcp_allowoptions
[0], sizeof (struct lcp_options
));
335 #endif /* PPP_OPTIONS */
337 #ifdef HAVE_MULTILINK
342 if (str_to_epdisc(&lcp_wantoptions
[0].endpoint
, *argv
)) {
343 lcp_wantoptions
[0].neg_endpoint
= 1;
346 option_error("Can't parse '%s' as an endpoint discriminator", *argv
);
351 printendpoint(opt
, printer
, arg
)
353 void (*printer
) (void *, char *, ...);
356 printer(arg
, "%s", epdisc_to_str(&lcp_wantoptions
[0].endpoint
));
358 #endif /* HAVE_MULTILINK */
361 * lcp_init - Initialize LCP.
363 static void lcp_init(ppp_pcb
*pcb
) {
364 fsm
*f
= &pcb
->lcp_fsm
;
365 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
366 lcp_options
*ao
= &pcb
->lcp_allowoptions
;
369 f
->protocol
= PPP_LCP
;
370 f
->callbacks
= &lcp_callbacks
;
374 BZERO(wo
, sizeof(*wo
));
376 wo
->mru
= PPP_DEFMRU
;
377 wo
->neg_asyncmap
= 1;
378 wo
->neg_magicnumber
= 1;
379 wo
->neg_pcompression
= 1;
380 wo
->neg_accompression
= 1;
382 BZERO(ao
, sizeof(*ao
));
384 ao
->mru
= PPP_MAXMRU
;
385 ao
->neg_asyncmap
= 1;
388 ao
->chap_mdtype
= CHAP_MDTYPE_SUPPORTED
;
389 #endif /* CHAP_SUPPORT */
392 #endif /* PAP_SUPPORT */
395 #endif /* EAP_SUPPORT */
396 ao
->neg_magicnumber
= 1;
397 ao
->neg_pcompression
= 1;
398 ao
->neg_accompression
= 1;
399 ao
->neg_endpoint
= 1;
404 * lcp_open - LCP is allowed to come up.
406 void lcp_open(ppp_pcb
*pcb
) {
407 fsm
*f
= &pcb
->lcp_fsm
;
408 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
410 f
->flags
&= ~(OPT_PASSIVE
| OPT_SILENT
);
412 f
->flags
|= OPT_PASSIVE
;
414 f
->flags
|= OPT_SILENT
;
420 * lcp_close - Take LCP down.
422 void lcp_close(ppp_pcb
*pcb
, const char *reason
) {
423 fsm
*f
= &pcb
->lcp_fsm
;
426 if (pcb
->phase
!= PPP_PHASE_DEAD
427 #ifdef HAVE_MULTILINK
428 && pcb
->phase
!= PPP_PHASE_MASTER
429 #endif /* HAVE_MULTILINK */
431 new_phase(pcb
, PPP_PHASE_TERMINATE
);
433 if (f
->flags
& DELAYED_UP
) {
434 UNTIMEOUT(lcp_delayed_up
, f
);
435 f
->state
= PPP_FSM_STOPPED
;
439 fsm_close(f
, reason
);
440 if (oldstate
== PPP_FSM_STOPPED
&& (f
->flags
& (OPT_PASSIVE
|OPT_SILENT
|DELAYED_UP
))) {
442 * This action is not strictly according to the FSM in RFC1548,
443 * but it does mean that the program terminates if you do a
444 * lcp_close() when a connection hasn't been established
445 * because we are in passive/silent mode or because we have
446 * delayed the fsm_lowerup() call and it hasn't happened yet.
448 f
->flags
&= ~DELAYED_UP
;
455 * lcp_lowerup - The lower layer is up.
457 void lcp_lowerup(ppp_pcb
*pcb
) {
458 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
459 fsm
*f
= &pcb
->lcp_fsm
;
461 * Don't use A/C or protocol compression on transmission,
462 * but accept A/C and protocol compressed packets
463 * if we are going to ask for A/C and protocol compression.
465 if (ppp_send_config(pcb
, PPP_MRU
, 0xffffffff, 0, 0) < 0
466 || ppp_recv_config(pcb
, PPP_MRU
, (pcb
->settings
.lax_recv
? 0: 0xffffffff),
467 wo
->neg_pcompression
, wo
->neg_accompression
) < 0)
469 pcb
->peer_mru
= PPP_MRU
;
471 if (pcb
->settings
.listen_time
!= 0) {
472 f
->flags
|= DELAYED_UP
;
473 TIMEOUTMS(lcp_delayed_up
, f
, pcb
->settings
.listen_time
);
480 * lcp_lowerdown - The lower layer is down.
482 void lcp_lowerdown(ppp_pcb
*pcb
) {
483 fsm
*f
= &pcb
->lcp_fsm
;
485 if (f
->flags
& DELAYED_UP
) {
486 f
->flags
&= ~DELAYED_UP
;
487 UNTIMEOUT(lcp_delayed_up
, f
);
494 * lcp_delayed_up - Bring the lower layer up now.
496 static void lcp_delayed_up(void *arg
) {
499 if (f
->flags
& DELAYED_UP
) {
500 f
->flags
&= ~DELAYED_UP
;
507 * lcp_input - Input LCP packet.
509 static void lcp_input(ppp_pcb
*pcb
, u_char
*p
, int len
) {
510 fsm
*f
= &pcb
->lcp_fsm
;
512 if (f
->flags
& DELAYED_UP
) {
513 f
->flags
&= ~DELAYED_UP
;
514 UNTIMEOUT(lcp_delayed_up
, f
);
517 fsm_input(f
, p
, len
);
521 * lcp_extcode - Handle a LCP-specific code.
523 static int lcp_extcode(fsm
*f
, int code
, int id
, u_char
*inp
, int len
) {
524 ppp_pcb
*pcb
= f
->pcb
;
525 lcp_options
*go
= &pcb
->lcp_gotoptions
;
530 lcp_rprotrej(f
, inp
, len
);
534 if (f
->state
!= PPP_FSM_OPENED
)
537 PUTLONG(go
->magicnumber
, magp
);
538 fsm_sdata(f
, ECHOREP
, id
, inp
, len
);
542 lcp_received_echo_reply(f
, id
, inp
, len
);
558 * lcp_rprotrej - Receive an Protocol-Reject.
560 * Figure out which protocol is rejected and inform it.
562 static void lcp_rprotrej(fsm
*f
, u_char
*inp
, int len
) {
564 const struct protent
*protp
;
568 #endif /* PPP_PROTOCOLNAME */
571 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
578 * Protocol-Reject packets received in any state other than the LCP
579 * OPENED state SHOULD be silently discarded.
581 if( f
->state
!= PPP_FSM_OPENED
){
582 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f
->state
));
587 pname
= protocol_name(prot
);
588 #endif /* PPP_PROTOCOLNAME */
591 * Upcall the proper Protocol-Reject routine.
593 for (i
= 0; (protp
= protocols
[i
]) != NULL
; ++i
)
594 if (protp
->protocol
== prot
) {
597 ppp_dbglog("Protocol-Reject for '%s' (0x%x) received", pname
,
600 #endif /* PPP_PROTOCOLNAME */
601 ppp_dbglog("Protocol-Reject for 0x%x received", prot
);
602 (*protp
->protrej
)(f
->pcb
);
608 ppp_warn("Protocol-Reject for unsupported protocol '%s' (0x%x)", pname
,
611 #endif /* #if PPP_PROTOCOLNAME */
612 ppp_warn("Protocol-Reject for unsupported protocol 0x%x", prot
);
617 * lcp_protrej - A Protocol-Reject was received.
620 static void lcp_protrej(ppp_pcb
*pcb
) {
624 ppp_error("Received Protocol-Reject for LCP!");
625 fsm_protreject(&pcb
->lcp_fsm
);
630 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
632 void lcp_sprotrej(ppp_pcb
*pcb
, u_char
*p
, int len
) {
633 fsm
*f
= &pcb
->lcp_fsm
;
635 * Send back the protocol and the information field of the
636 * rejected packet. We only get here if LCP is in the OPENED state.
643 fsm_sdata(f
, PROTREJ
, ++f
->id
,
649 * lcp_resetci - Reset our CI.
651 static void lcp_resetci(fsm
*f
) {
652 ppp_pcb
*pcb
= f
->pcb
;
653 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
654 lcp_options
*go
= &pcb
->lcp_gotoptions
;
655 lcp_options
*ao
= &pcb
->lcp_allowoptions
;
659 /* note: default value is true for allow options */
660 if (pcb
->settings
.user
&& pcb
->settings
.passwd
) {
662 if (pcb
->settings
.refuse_pap
) {
665 #endif /* PAP_SUPPORT */
667 if (pcb
->settings
.refuse_chap
) {
668 ao
->chap_mdtype
&= ~MDTYPE_MD5
;
671 if (pcb
->settings
.refuse_mschap
) {
672 ao
->chap_mdtype
&= ~MDTYPE_MICROSOFT
;
674 if (pcb
->settings
.refuse_mschap_v2
) {
675 ao
->chap_mdtype
&= ~MDTYPE_MICROSOFT_V2
;
677 #endif /* MSCHAP_SUPPORT */
678 ao
->neg_chap
= (ao
->chap_mdtype
!= MDTYPE_NONE
);
679 #endif /* CHAP_SUPPORT */
681 if (pcb
->settings
.refuse_eap
) {
684 #endif /* EAP_SUPPORT */
687 /* note: default value is false for wanted options */
688 if (pcb
->settings
.auth_required
) {
690 if (!pcb
->settings
.refuse_pap
) {
693 #endif /* PAP_SUPPORT */
695 if (!pcb
->settings
.refuse_chap
) {
696 wo
->chap_mdtype
|= MDTYPE_MD5
;
699 if (!pcb
->settings
.refuse_mschap
) {
700 wo
->chap_mdtype
|= MDTYPE_MICROSOFT
;
702 if (!pcb
->settings
.refuse_mschap_v2
) {
703 wo
->chap_mdtype
|= MDTYPE_MICROSOFT_V2
;
705 #endif /* MSCHAP_SUPPORT */
706 wo
->neg_chap
= (wo
->chap_mdtype
!= MDTYPE_NONE
);
707 #endif /* CHAP_SUPPORT */
709 if (!pcb
->settings
.refuse_eap
) {
712 #endif /* EAP_SUPPORT */
714 #endif /* PPP_SERVER */
719 #endif /* PAP_SUPPORT */
722 ao
->chap_mdtype
= MDTYPE_NONE
;
723 #endif /* CHAP_SUPPORT */
726 #endif /* EAP_SUPPORT */
729 PPPDEBUG(LOG_DEBUG
, ("ppp: auth protocols:"));
731 PPPDEBUG(LOG_DEBUG
, (" PAP=%d", ao
->neg_upap
));
732 #endif /* PAP_SUPPORT */
734 PPPDEBUG(LOG_DEBUG
, (" CHAP=%d CHAP_MD5=%d", ao
->neg_chap
, !!(ao
->chap_mdtype
&MDTYPE_MD5
)));
736 PPPDEBUG(LOG_DEBUG
, (" CHAP_MS=%d CHAP_MS2=%d", !!(ao
->chap_mdtype
&MDTYPE_MICROSOFT
), !!(ao
->chap_mdtype
&MDTYPE_MICROSOFT_V2
)));
737 #endif /* MSCHAP_SUPPORT */
738 #endif /* CHAP_SUPPORT */
740 PPPDEBUG(LOG_DEBUG
, (" EAP=%d", ao
->neg_eap
));
741 #endif /* EAP_SUPPORT */
742 PPPDEBUG(LOG_DEBUG
, ("\n"));
744 #endif /* PPP_AUTH_SUPPORT */
746 wo
->magicnumber
= magic();
749 #ifdef HAVE_MULTILINK
752 #endif /* HAVE_MULTILINK */
754 go
->neg_endpoint
= 0;
755 #ifdef HAVE_MULTILINK
757 #endif /* HAVE_MULTILINK */
758 if (pcb
->settings
.noendpoint
)
759 ao
->neg_endpoint
= 0;
760 pcb
->peer_mru
= PPP_MRU
;
768 * lcp_cilen - Return length of our CI.
770 static int lcp_cilen(fsm
*f
) {
771 ppp_pcb
*pcb
= f
->pcb
;
772 lcp_options
*go
= &pcb
->lcp_gotoptions
;
774 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
776 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
777 #endif /* CHAP_SUPPORT */
778 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
779 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
781 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
782 #endif /* LQR_SUPPORT */
783 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
785 * NB: we only ask for one of CHAP, UPAP, or EAP, even if we will
786 * accept more than one. We prefer EAP first, then CHAP, then
789 return (LENCISHORT(go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) +
790 LENCILONG(go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) +
792 LENCISHORT(go
->neg_eap
) +
793 #endif /* EAP_SUPPORT */
794 #if CHAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
796 LENCICHAP(!go
->neg_eap
&& go
->neg_chap
) +
797 #endif /* EAP_SUPPORT */
799 LENCICHAP(go
->neg_chap
) +
800 #endif /* !EAP_SUPPORT */
801 #endif /* CHAP_SUPPORT */
802 #if PAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
803 #if EAP_SUPPORT && CHAP_SUPPORT
804 LENCISHORT(!go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
) +
805 #endif /* EAP_SUPPORT && CHAP_SUPPORT */
806 #if EAP_SUPPORT && !CHAP_SUPPORT
807 LENCISHORT(!go
->neg_eap
&& go
->neg_upap
) +
808 #endif /* EAP_SUPPORT && !CHAP_SUPPORT */
809 #if !EAP_SUPPORT && CHAP_SUPPORT
810 LENCISHORT(!go
->neg_chap
&& go
->neg_upap
) +
811 #endif /* !EAP_SUPPORT && CHAP_SUPPORT */
812 #if !EAP_SUPPORT && !CHAP_SUPPORT
813 LENCISHORT(go
->neg_upap
) +
814 #endif /* !EAP_SUPPORT && !CHAP_SUPPORT */
815 #endif /* PAP_SUPPORT */
817 LENCILQR(go
->neg_lqr
) +
818 #endif /* LQR_SUPPORT */
819 LENCICBCP(go
->neg_cbcp
) +
820 LENCILONG(go
->neg_magicnumber
) +
821 LENCIVOID(go
->neg_pcompression
) +
822 LENCIVOID(go
->neg_accompression
) +
823 #ifdef HAVE_MULTILINK
824 LENCISHORT(go
->neg_mrru
) +
825 #endif /* HAVE_MULTILINK */
826 LENCIVOID(go
->neg_ssnhf
) +
827 (go
->neg_endpoint
? CILEN_CHAR
+ go
->endpoint
.length
: 0));
832 * lcp_addci - Add our desired CIs to a packet.
834 static void lcp_addci(fsm
*f
, u_char
*ucp
, int *lenp
) {
835 ppp_pcb
*pcb
= f
->pcb
;
836 lcp_options
*go
= &pcb
->lcp_gotoptions
;
837 u_char
*start_ucp
= ucp
;
839 #define ADDCIVOID(opt, neg) \
842 PUTCHAR(CILEN_VOID, ucp); \
844 #define ADDCISHORT(opt, neg, val) \
847 PUTCHAR(CILEN_SHORT, ucp); \
848 PUTSHORT(val, ucp); \
851 #define ADDCICHAP(opt, neg, val) \
853 PUTCHAR((opt), ucp); \
854 PUTCHAR(CILEN_CHAP, ucp); \
855 PUTSHORT(PPP_CHAP, ucp); \
856 PUTCHAR((CHAP_DIGEST(val)), ucp); \
858 #endif /* CHAP_SUPPORT */
859 #define ADDCILONG(opt, neg, val) \
862 PUTCHAR(CILEN_LONG, ucp); \
866 #define ADDCILQR(opt, neg, val) \
869 PUTCHAR(CILEN_LQR, ucp); \
870 PUTSHORT(PPP_LQR, ucp); \
873 #endif /* LQR_SUPPORT */
874 #define ADDCICHAR(opt, neg, val) \
877 PUTCHAR(CILEN_CHAR, ucp); \
880 #define ADDCIENDP(opt, neg, class, val, len) \
884 PUTCHAR(CILEN_CHAR + len, ucp); \
885 PUTCHAR(class, ucp); \
886 for (i = 0; i < len; ++i) \
887 PUTCHAR(val[i], ucp); \
890 ADDCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
891 ADDCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
894 ADDCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
895 #endif /* EAP_SUPPORT */
896 #if CHAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
898 ADDCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
899 #endif /* EAP_SUPPORT */
901 ADDCICHAP(CI_AUTHTYPE
, go
->neg_chap
, go
->chap_mdtype
);
902 #endif /* !EAP_SUPPORT */
903 #endif /* CHAP_SUPPORT */
904 #if PAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
905 #if EAP_SUPPORT && CHAP_SUPPORT
906 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
907 #endif /* EAP_SUPPORT && CHAP_SUPPORT */
908 #if EAP_SUPPORT && !CHAP_SUPPORT
909 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_upap
, PPP_PAP
);
910 #endif /* EAP_SUPPORT && !CHAP_SUPPORT */
911 #if !EAP_SUPPORT && CHAP_SUPPORT
912 ADDCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
913 #endif /* !EAP_SUPPORT && CHAP_SUPPORT */
914 #if !EAP_SUPPORT && !CHAP_SUPPORT
915 ADDCISHORT(CI_AUTHTYPE
, go
->neg_upap
, PPP_PAP
);
916 #endif /* !EAP_SUPPORT && !CHAP_SUPPORT */
917 #endif /* PAP_SUPPORT */
919 ADDCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
920 #endif /* LQR_SUPPORT */
921 ADDCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
922 ADDCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
923 ADDCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
924 ADDCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
925 #ifdef HAVE_MULTILINK
926 ADDCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
928 ADDCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
929 ADDCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class_
,
930 go
->endpoint
.value
, go
->endpoint
.length
);
932 if (ucp
- start_ucp
!= *lenp
) {
933 /* this should never happen, because peer_mtu should be 1500 */
934 ppp_error("Bug in lcp_addci: wrong length");
940 * lcp_ackci - Ack our CIs.
941 * This should not modify any state if the Ack is bad.
947 static int lcp_ackci(fsm
*f
, u_char
*p
, int len
) {
948 ppp_pcb
*pcb
= f
->pcb
;
949 lcp_options
*go
= &pcb
->lcp_gotoptions
;
950 u_char cilen
, citype
, cichar
;
955 * CIs must be in exactly the same order that we sent.
956 * Check packet length and CI length at each step.
957 * If we find any deviations, then this packet is bad.
959 #define ACKCIVOID(opt, neg) \
961 if ((len -= CILEN_VOID) < 0) \
963 GETCHAR(citype, p); \
965 if (cilen != CILEN_VOID || \
969 #define ACKCISHORT(opt, neg, val) \
971 if ((len -= CILEN_SHORT) < 0) \
973 GETCHAR(citype, p); \
975 if (cilen != CILEN_SHORT || \
978 GETSHORT(cishort, p); \
979 if (cishort != val) \
982 #define ACKCICHAR(opt, neg, val) \
984 if ((len -= CILEN_CHAR) < 0) \
986 GETCHAR(citype, p); \
988 if (cilen != CILEN_CHAR || \
991 GETCHAR(cichar, p); \
996 #define ACKCICHAP(opt, neg, val) \
998 if ((len -= CILEN_CHAP) < 0) \
1000 GETCHAR(citype, p); \
1001 GETCHAR(cilen, p); \
1002 if (cilen != CILEN_CHAP || \
1005 GETSHORT(cishort, p); \
1006 if (cishort != PPP_CHAP) \
1008 GETCHAR(cichar, p); \
1009 if (cichar != (CHAP_DIGEST(val))) \
1012 #endif /* CHAP_SUPPORT */
1013 #define ACKCILONG(opt, neg, val) \
1015 if ((len -= CILEN_LONG) < 0) \
1017 GETCHAR(citype, p); \
1018 GETCHAR(cilen, p); \
1019 if (cilen != CILEN_LONG || \
1022 GETLONG(cilong, p); \
1023 if (cilong != val) \
1027 #define ACKCILQR(opt, neg, val) \
1029 if ((len -= CILEN_LQR) < 0) \
1031 GETCHAR(citype, p); \
1032 GETCHAR(cilen, p); \
1033 if (cilen != CILEN_LQR || \
1036 GETSHORT(cishort, p); \
1037 if (cishort != PPP_LQR) \
1039 GETLONG(cilong, p); \
1040 if (cilong != val) \
1043 #endif /* LQR_SUPPORT */
1044 #define ACKCIENDP(opt, neg, class, val, vlen) \
1047 if ((len -= CILEN_CHAR + vlen) < 0) \
1049 GETCHAR(citype, p); \
1050 GETCHAR(cilen, p); \
1051 if (cilen != CILEN_CHAR + vlen || \
1054 GETCHAR(cichar, p); \
1055 if (cichar != class) \
1057 for (i = 0; i < vlen; ++i) { \
1058 GETCHAR(cichar, p); \
1059 if (cichar != val[i]) \
1064 ACKCISHORT(CI_MRU
, go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
, go
->mru
);
1065 ACKCILONG(CI_ASYNCMAP
, go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF,
1068 ACKCISHORT(CI_AUTHTYPE
, go
->neg_eap
, PPP_EAP
);
1069 #endif /* EAP_SUPPORT */
1070 #if CHAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
1072 ACKCICHAP(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_chap
, go
->chap_mdtype
);
1073 #endif /* EAP_SUPPORT */
1075 ACKCICHAP(CI_AUTHTYPE
, go
->neg_chap
, go
->chap_mdtype
);
1076 #endif /* !EAP_SUPPORT */
1077 #endif /* CHAP_SUPPORT */
1078 #if PAP_SUPPORT /* cannot be improved, embedding a directive within macro arguments is not portable */
1079 #if EAP_SUPPORT && CHAP_SUPPORT
1080 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
1081 #endif /* EAP_SUPPORT && CHAP_SUPPORT */
1082 #if EAP_SUPPORT && !CHAP_SUPPORT
1083 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_eap
&& go
->neg_upap
, PPP_PAP
);
1084 #endif /* EAP_SUPPORT && !CHAP_SUPPORT */
1085 #if !EAP_SUPPORT && CHAP_SUPPORT
1086 ACKCISHORT(CI_AUTHTYPE
, !go
->neg_chap
&& go
->neg_upap
, PPP_PAP
);
1087 #endif /* !EAP_SUPPORT && CHAP_SUPPORT */
1088 #if !EAP_SUPPORT && !CHAP_SUPPORT
1089 ACKCISHORT(CI_AUTHTYPE
, go
->neg_upap
, PPP_PAP
);
1090 #endif /* !EAP_SUPPORT && !CHAP_SUPPORT */
1091 #endif /* PAP_SUPPORT */
1093 ACKCILQR(CI_QUALITY
, go
->neg_lqr
, go
->lqr_period
);
1094 #endif /* LQR_SUPPORT */
1095 ACKCICHAR(CI_CALLBACK
, go
->neg_cbcp
, CBCP_OPT
);
1096 ACKCILONG(CI_MAGICNUMBER
, go
->neg_magicnumber
, go
->magicnumber
);
1097 ACKCIVOID(CI_PCOMPRESSION
, go
->neg_pcompression
);
1098 ACKCIVOID(CI_ACCOMPRESSION
, go
->neg_accompression
);
1099 #ifdef HAVE_MULTILINK
1100 ACKCISHORT(CI_MRRU
, go
->neg_mrru
, go
->mrru
);
1101 #endif /* HAVE_MULTILINK */
1102 ACKCIVOID(CI_SSNHF
, go
->neg_ssnhf
);
1103 ACKCIENDP(CI_EPDISC
, go
->neg_endpoint
, go
->endpoint
.class_
,
1104 go
->endpoint
.value
, go
->endpoint
.length
);
1107 * If there are any remaining CIs, then this packet is bad.
1113 LCPDEBUG(("lcp_acki: received bad Ack!"));
1119 * lcp_nakci - Peer has sent a NAK for some of our CIs.
1120 * This should not modify any state if the Nak is bad
1121 * or if LCP is in the OPENED state.
1127 static int lcp_nakci(fsm
*f
, u_char
*p
, int len
, int treat_as_reject
) {
1128 ppp_pcb
*pcb
= f
->pcb
;
1129 lcp_options
*go
= &pcb
->lcp_gotoptions
;
1130 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
1131 u_char citype
, cichar
, *next
;
1134 lcp_options no
; /* options we've seen Naks for */
1135 lcp_options try_
; /* options to request next time */
1136 int looped_back
= 0;
1139 BZERO(&no
, sizeof(no
));
1143 * Any Nak'd CIs must be in exactly the same order that we sent.
1144 * Check packet length and CI length at each step.
1145 * If we find any deviations, then this packet is bad.
1147 #define NAKCIVOID(opt, neg) \
1149 len >= CILEN_VOID && \
1150 p[1] == CILEN_VOID && \
1152 len -= CILEN_VOID; \
1153 INCPTR(CILEN_VOID, p); \
1158 #define NAKCICHAP(opt, neg, code) \
1160 len >= CILEN_CHAP && \
1161 p[1] == CILEN_CHAP && \
1163 len -= CILEN_CHAP; \
1165 GETSHORT(cishort, p); \
1166 GETCHAR(cichar, p); \
1170 #endif /* CHAP_SUPPORT */
1171 #define NAKCICHAR(opt, neg, code) \
1173 len >= CILEN_CHAR && \
1174 p[1] == CILEN_CHAR && \
1176 len -= CILEN_CHAR; \
1178 GETCHAR(cichar, p); \
1182 #define NAKCISHORT(opt, neg, code) \
1184 len >= CILEN_SHORT && \
1185 p[1] == CILEN_SHORT && \
1187 len -= CILEN_SHORT; \
1189 GETSHORT(cishort, p); \
1193 #define NAKCILONG(opt, neg, code) \
1195 len >= CILEN_LONG && \
1196 p[1] == CILEN_LONG && \
1198 len -= CILEN_LONG; \
1200 GETLONG(cilong, p); \
1205 #define NAKCILQR(opt, neg, code) \
1207 len >= CILEN_LQR && \
1208 p[1] == CILEN_LQR && \
1212 GETSHORT(cishort, p); \
1213 GETLONG(cilong, p); \
1217 #endif /* LQR_SUPPORT */
1218 #define NAKCIENDP(opt, neg) \
1220 len >= CILEN_CHAR && \
1222 p[1] >= CILEN_CHAR && \
1231 * NOTE! There must be no assignments to individual fields of *go in
1232 * the code below. Any such assignment is a BUG!
1235 * We don't care if they want to send us smaller packets than
1236 * we want. Therefore, accept any MRU less than what we asked for,
1237 * but then ignore the new value when setting the MRU in the kernel.
1238 * If they send us a bigger MRU than what we asked, accept it, up to
1239 * the limit of the default MRU we'd get if we didn't negotiate.
1241 if (go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
) {
1242 NAKCISHORT(CI_MRU
, neg_mru
,
1243 if (cishort
<= wo
->mru
|| cishort
<= PPP_DEFMRU
)
1249 * Add any characters they want to our (receive-side) asyncmap.
1251 if (go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF) {
1252 NAKCILONG(CI_ASYNCMAP
, neg_asyncmap
,
1253 try_
.asyncmap
= go
->asyncmap
| cilong
;
1258 * If they've nak'd our authentication-protocol, check whether
1259 * they are proposing a different protocol, or a different
1260 * hash algorithm for CHAP.
1265 #endif /* CHAP_SUPPORT */
1268 #endif /* PAP_SUPPORT */
1271 #endif /* EAP_SUPPORT */
1273 && len
>= CILEN_SHORT
1274 && p
[0] == CI_AUTHTYPE
&& p
[1] >= CILEN_SHORT
&& p
[1] <= len
) {
1278 no
.neg_chap
= go
->neg_chap
;
1279 #endif /* CHAP_SUPPORT */
1281 no
.neg_upap
= go
->neg_upap
;
1282 #endif /* PAP_SUPPORT */
1284 no
.neg_eap
= go
->neg_eap
;
1285 #endif /* EAP_SUPPORT */
1287 GETSHORT(cishort
, p
);
1290 if (cishort
== PPP_PAP
&& cilen
== CILEN_SHORT
) {
1292 /* If we were asking for EAP, then we need to stop that. */
1296 #endif /* EAP_SUPPORT */
1299 /* If we were asking for CHAP, then we need to stop that. */
1303 #endif /* CHAP_SUPPORT */
1306 * If we weren't asking for CHAP or EAP, then we were asking for
1307 * PAP, in which case this Nak is bad.
1311 #endif /* PAP_SUPPORT */
1314 if (cishort
== PPP_CHAP
&& cilen
== CILEN_CHAP
) {
1317 /* Stop asking for EAP, if we were. */
1320 /* Try to set up to use their suggestion, if possible */
1321 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
))
1322 try_
.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1324 #endif /* EAP_SUPPORT */
1327 * We were asking for our preferred algorithm, they must
1328 * want something different.
1330 if (cichar
!= CHAP_DIGEST(go
->chap_mdtype
)) {
1331 if (CHAP_CANDIGEST(go
->chap_mdtype
, cichar
)) {
1332 /* Use their suggestion if we support it ... */
1333 try_
.chap_mdtype
= CHAP_MDTYPE_D(cichar
);
1335 /* ... otherwise, try our next-preferred algorithm. */
1336 try_
.chap_mdtype
&= ~(CHAP_MDTYPE(try_
.chap_mdtype
));
1337 if (try_
.chap_mdtype
== MDTYPE_NONE
) /* out of algos */
1342 * Whoops, they Nak'd our algorithm of choice
1343 * but then suggested it back to us.
1349 * Stop asking for PAP if we were asking for it.
1353 #endif /* PAP_SUPPORT */
1357 #endif /* CHAP_SUPPORT */
1362 * If we were asking for EAP, and they're Conf-Naking EAP,
1363 * well, that's just strange. Nobody should do that.
1365 if (cishort
== PPP_EAP
&& cilen
== CILEN_SHORT
&& go
->neg_eap
)
1366 ppp_dbglog("Unexpected Conf-Nak for EAP");
1369 * We don't recognize what they're suggesting.
1370 * Stop asking for what we were asking for.
1375 #endif /* EAP_SUPPORT */
1381 #endif /* CHAP_SUPPORT */
1387 #endif /* PAP_SUPPORT */
1390 p
+= cilen
- CILEN_SHORT
;
1396 * If they can't cope with our link quality protocol, we'll have
1397 * to stop asking for LQR. We haven't got any other protocol.
1398 * If they Nak the reporting period, take their value XXX ?
1400 NAKCILQR(CI_QUALITY
, neg_lqr
,
1401 if (cishort
!= PPP_LQR
)
1404 try_
.lqr_period
= cilong
;
1406 #endif /* LQR_SUPPORT */
1409 * Only implementing CBCP...not the rest of the callback options
1411 NAKCICHAR(CI_CALLBACK
, neg_cbcp
,
1413 (void)cichar
; /* if CHAP support is not compiled, cichar is set but not used, which makes some compilers complaining */
1417 * Check for a looped-back line.
1419 NAKCILONG(CI_MAGICNUMBER
, neg_magicnumber
,
1420 try_
.magicnumber
= magic();
1425 * Peer shouldn't send Nak for protocol compression or
1426 * address/control compression requests; they should send
1427 * a Reject instead. If they send a Nak, treat it as a Reject.
1429 NAKCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1430 NAKCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1432 #ifdef HAVE_MULTILINK
1434 * Nak for MRRU option - accept their value if it is smaller
1435 * than the one we want.
1438 NAKCISHORT(CI_MRRU
, neg_mrru
,
1439 if (treat_as_reject
)
1441 else if (cishort
<= wo
->mrru
)
1442 try_
.mrru
= cishort
;
1445 #else /* HAVE_MULTILINK */
1446 LWIP_UNUSED_ARG(treat_as_reject
);
1447 #endif /* HAVE_MULTILINK */
1450 * Nak for short sequence numbers shouldn't be sent, treat it
1453 NAKCIVOID(CI_SSNHF
, neg_ssnhf
);
1456 * Nak of the endpoint discriminator option is not permitted,
1457 * treat it like a reject.
1459 NAKCIENDP(CI_EPDISC
, neg_endpoint
);
1462 * There may be remaining CIs, if the peer is requesting negotiation
1463 * on an option that we didn't include in our request packet.
1464 * If we see an option that we requested, or one we've already seen
1465 * in this packet, then this packet is bad.
1466 * If we wanted to respond by starting to negotiate on the requested
1467 * option(s), we could, but we don't, because except for the
1468 * authentication type and quality protocol, if we are not negotiating
1469 * an option, it is because we were told not to.
1470 * For the authentication type, the Nak from the peer means
1471 * `let me authenticate myself with you' which is a bit pointless.
1472 * For the quality protocol, the Nak means `ask me to send you quality
1473 * reports', but if we didn't ask for them, we don't want them.
1474 * An option we don't recognize represents the peer asking to
1475 * negotiate some option we don't support, so ignore it.
1477 while (len
>= CILEN_VOID
) {
1480 if (cilen
< CILEN_VOID
|| (len
-= cilen
) < 0)
1482 next
= p
+ cilen
- 2;
1486 if ((go
->neg_mru
&& go
->mru
!= PPP_DEFMRU
)
1487 || no
.neg_mru
|| cilen
!= CILEN_SHORT
)
1489 GETSHORT(cishort
, p
);
1490 if (cishort
< PPP_DEFMRU
) {
1496 if ((go
->neg_asyncmap
&& go
->asyncmap
!= 0xFFFFFFFF)
1497 || no
.neg_asyncmap
|| cilen
!= CILEN_LONG
)
1503 || go
->neg_chap
|| no
.neg_chap
1504 #endif /* CHAP_SUPPORT */
1506 || go
->neg_upap
|| no
.neg_upap
1507 #endif /* PAP_SUPPORT */
1509 || go
->neg_eap
|| no
.neg_eap
1510 #endif /* EAP_SUPPORT */
1514 case CI_MAGICNUMBER
:
1515 if (go
->neg_magicnumber
|| no
.neg_magicnumber
||
1516 cilen
!= CILEN_LONG
)
1519 case CI_PCOMPRESSION
:
1520 if (go
->neg_pcompression
|| no
.neg_pcompression
1521 || cilen
!= CILEN_VOID
)
1524 case CI_ACCOMPRESSION
:
1525 if (go
->neg_accompression
|| no
.neg_accompression
1526 || cilen
!= CILEN_VOID
)
1531 if (go
->neg_lqr
|| no
.neg_lqr
|| cilen
!= CILEN_LQR
)
1534 #endif /* LQR_SUPPORT */
1535 #ifdef HAVE_MULTILINK
1537 if (go
->neg_mrru
|| no
.neg_mrru
|| cilen
!= CILEN_SHORT
)
1540 #endif /* HAVE_MULTILINK */
1542 if (go
->neg_ssnhf
|| no
.neg_ssnhf
|| cilen
!= CILEN_VOID
)
1547 if (go
->neg_endpoint
|| no
.neg_endpoint
|| cilen
< CILEN_CHAR
)
1557 * OK, the Nak is good. Now we can update state.
1558 * If there are any options left we ignore them.
1560 if (f
->state
!= PPP_FSM_OPENED
) {
1562 if (++try_
.numloops
>= pcb
->settings
.lcp_loopbackfail
) {
1563 ppp_notice("Serial line is looped back.");
1564 pcb
->err_code
= PPPERR_LOOPBACK
;
1565 lcp_close(f
->pcb
, "Loopback detected");
1575 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1581 * lcp_rejci - Peer has Rejected some of our CIs.
1582 * This should not modify any state if the Reject is bad
1583 * or if LCP is in the OPENED state.
1586 * 0 - Reject was bad.
1587 * 1 - Reject was good.
1589 static int lcp_rejci(fsm
*f
, u_char
*p
, int len
) {
1590 ppp_pcb
*pcb
= f
->pcb
;
1591 lcp_options
*go
= &pcb
->lcp_gotoptions
;
1595 lcp_options try_
; /* options to request next time */
1600 * Any Rejected CIs must be in exactly the same order that we sent.
1601 * Check packet length and CI length at each step.
1602 * If we find any deviations, then this packet is bad.
1604 #define REJCIVOID(opt, neg) \
1606 len >= CILEN_VOID && \
1607 p[1] == CILEN_VOID && \
1609 len -= CILEN_VOID; \
1610 INCPTR(CILEN_VOID, p); \
1613 #define REJCISHORT(opt, neg, val) \
1615 len >= CILEN_SHORT && \
1616 p[1] == CILEN_SHORT && \
1618 len -= CILEN_SHORT; \
1620 GETSHORT(cishort, p); \
1621 /* Check rejected value. */ \
1622 if (cishort != val) \
1627 #if CHAP_SUPPORT && EAP_SUPPORT && PAP_SUPPORT
1628 #define REJCICHAP(opt, neg, val) \
1630 len >= CILEN_CHAP && \
1631 p[1] == CILEN_CHAP && \
1633 len -= CILEN_CHAP; \
1635 GETSHORT(cishort, p); \
1636 GETCHAR(cichar, p); \
1637 /* Check rejected value. */ \
1638 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1641 try_.neg_eap = try_.neg_upap = 0; \
1643 #endif /* CHAP_SUPPORT && EAP_SUPPORT && PAP_SUPPORT */
1645 #if CHAP_SUPPORT && !EAP_SUPPORT && PAP_SUPPORT
1646 #define REJCICHAP(opt, neg, val) \
1648 len >= CILEN_CHAP && \
1649 p[1] == CILEN_CHAP && \
1651 len -= CILEN_CHAP; \
1653 GETSHORT(cishort, p); \
1654 GETCHAR(cichar, p); \
1655 /* Check rejected value. */ \
1656 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1659 try_.neg_upap = 0; \
1661 #endif /* CHAP_SUPPORT && !EAP_SUPPORT && PAP_SUPPORT */
1663 #if CHAP_SUPPORT && EAP_SUPPORT && !PAP_SUPPORT
1664 #define REJCICHAP(opt, neg, val) \
1666 len >= CILEN_CHAP && \
1667 p[1] == CILEN_CHAP && \
1669 len -= CILEN_CHAP; \
1671 GETSHORT(cishort, p); \
1672 GETCHAR(cichar, p); \
1673 /* Check rejected value. */ \
1674 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1679 #endif /* CHAP_SUPPORT && EAP_SUPPORT && !PAP_SUPPORT */
1681 #if CHAP_SUPPORT && !EAP_SUPPORT && !PAP_SUPPORT
1682 #define REJCICHAP(opt, neg, val) \
1684 len >= CILEN_CHAP && \
1685 p[1] == CILEN_CHAP && \
1687 len -= CILEN_CHAP; \
1689 GETSHORT(cishort, p); \
1690 GETCHAR(cichar, p); \
1691 /* Check rejected value. */ \
1692 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1696 #endif /* CHAP_SUPPORT && !EAP_SUPPORT && !PAP_SUPPORT */
1698 #define REJCILONG(opt, neg, val) \
1700 len >= CILEN_LONG && \
1701 p[1] == CILEN_LONG && \
1703 len -= CILEN_LONG; \
1705 GETLONG(cilong, p); \
1706 /* Check rejected value. */ \
1707 if (cilong != val) \
1712 #define REJCILQR(opt, neg, val) \
1714 len >= CILEN_LQR && \
1715 p[1] == CILEN_LQR && \
1719 GETSHORT(cishort, p); \
1720 GETLONG(cilong, p); \
1721 /* Check rejected value. */ \
1722 if (cishort != PPP_LQR || cilong != val) \
1726 #endif /* LQR_SUPPORT */
1727 #define REJCICBCP(opt, neg, val) \
1729 len >= CILEN_CBCP && \
1730 p[1] == CILEN_CBCP && \
1732 len -= CILEN_CBCP; \
1734 GETCHAR(cichar, p); \
1735 /* Check rejected value. */ \
1736 if (cichar != val) \
1740 #define REJCIENDP(opt, neg, class, val, vlen) \
1742 len >= CILEN_CHAR + vlen && \
1744 p[1] == CILEN_CHAR + vlen) { \
1746 len -= CILEN_CHAR + vlen; \
1748 GETCHAR(cichar, p); \
1749 if (cichar != class) \
1751 for (i = 0; i < vlen; ++i) { \
1752 GETCHAR(cichar, p); \
1753 if (cichar != val[i]) \
1759 REJCISHORT(CI_MRU
, neg_mru
, go
->mru
);
1760 REJCILONG(CI_ASYNCMAP
, neg_asyncmap
, go
->asyncmap
);
1762 REJCISHORT(CI_AUTHTYPE
, neg_eap
, PPP_EAP
);
1764 #endif /* EAP_SUPPORT */
1766 REJCICHAP(CI_AUTHTYPE
, neg_chap
, go
->chap_mdtype
);
1767 if (!go
->neg_chap
) {
1768 #endif /* CHAP_SUPPORT */
1770 REJCISHORT(CI_AUTHTYPE
, neg_upap
, PPP_PAP
);
1771 #endif /* PAP_SUPPORT */
1774 #endif /* CHAP_SUPPORT */
1777 #endif /* EAP_SUPPORT */
1779 REJCILQR(CI_QUALITY
, neg_lqr
, go
->lqr_period
);
1780 #endif /* LQR_SUPPORT */
1781 REJCICBCP(CI_CALLBACK
, neg_cbcp
, CBCP_OPT
);
1782 REJCILONG(CI_MAGICNUMBER
, neg_magicnumber
, go
->magicnumber
);
1783 REJCIVOID(CI_PCOMPRESSION
, neg_pcompression
);
1784 REJCIVOID(CI_ACCOMPRESSION
, neg_accompression
);
1785 #ifdef HAVE_MULTILINK
1786 REJCISHORT(CI_MRRU
, neg_mrru
, go
->mrru
);
1787 #endif /* HAVE_MULTILINK */
1788 REJCIVOID(CI_SSNHF
, neg_ssnhf
);
1789 REJCIENDP(CI_EPDISC
, neg_endpoint
, go
->endpoint
.class_
,
1790 go
->endpoint
.value
, go
->endpoint
.length
);
1793 * If there are any remaining CIs, then this packet is bad.
1798 * Now we can update state.
1800 if (f
->state
!= PPP_FSM_OPENED
)
1805 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1811 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1813 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1814 * appropriately. If reject_if_disagree is non-zero, doesn't return
1815 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1817 * inp = Requested CIs
1818 * lenp = Length of requested CIs
1820 static int lcp_reqci(fsm
*f
, u_char
*inp
, int *lenp
, int reject_if_disagree
) {
1821 ppp_pcb
*pcb
= f
->pcb
;
1822 lcp_options
*go
= &pcb
->lcp_gotoptions
;
1823 lcp_options
*ho
= &pcb
->lcp_hisoptions
;
1824 lcp_options
*ao
= &pcb
->lcp_allowoptions
;
1825 u_char
*cip
, *next
; /* Pointer to current and next CIs */
1826 int cilen
, citype
, cichar
; /* Parsed len, type, char value */
1827 u_short cishort
; /* Parsed short value */
1828 u32_t cilong
; /* Parse long value */
1829 int rc
= CONFACK
; /* Final packet return code */
1830 int orc
; /* Individual option return code */
1831 u_char
*p
; /* Pointer to next char to parse */
1832 u_char
*rejp
; /* Pointer to next char in reject frame */
1833 struct pbuf
*nakp
; /* Nak buffer */
1834 u_char
*nakoutp
; /* Pointer to next char in Nak frame */
1835 int l
= *lenp
; /* Length left */
1838 * Reset all his options.
1840 BZERO(ho
, sizeof(*ho
));
1843 * Process all his options.
1846 nakp
= pbuf_alloc(PBUF_RAW
, (u16_t
)(PPP_CTRL_PBUF_MAX_SIZE
), PPP_CTRL_PBUF_TYPE
);
1849 if(nakp
->tot_len
!= nakp
->len
) {
1854 nakoutp
= (u_char
*)nakp
->payload
;
1857 orc
= CONFACK
; /* Assume success */
1858 cip
= p
= next
; /* Remember begining of CI */
1859 if (l
< 2 || /* Not enough data for CI header or */
1860 p
[1] < 2 || /* CI length too small or */
1861 p
[1] > l
) { /* CI length too big? */
1862 LCPDEBUG(("lcp_reqci: bad CI length!"));
1863 orc
= CONFREJ
; /* Reject bad CI */
1864 cilen
= l
; /* Reject till end of packet */
1865 l
= 0; /* Don't loop again */
1869 GETCHAR(citype
, p
); /* Parse CI type */
1870 GETCHAR(cilen
, p
); /* Parse CI length */
1871 l
-= cilen
; /* Adjust remaining length */
1872 next
+= cilen
; /* Step to next CI */
1874 switch (citype
) { /* Check CI type */
1876 if (!ao
->neg_mru
|| /* Allow option? */
1877 cilen
!= CILEN_SHORT
) { /* Check CI length */
1878 orc
= CONFREJ
; /* Reject CI */
1881 GETSHORT(cishort
, p
); /* Parse MRU */
1884 * He must be able to receive at least our minimum.
1885 * No need to check a maximum. If he sends a large number,
1886 * we'll just ignore it.
1888 if (cishort
< PPP_MINMRU
) {
1889 orc
= CONFNAK
; /* Nak CI */
1890 PUTCHAR(CI_MRU
, nakoutp
);
1891 PUTCHAR(CILEN_SHORT
, nakoutp
);
1892 PUTSHORT(PPP_MINMRU
, nakoutp
); /* Give him a hint */
1895 ho
->neg_mru
= 1; /* Remember he sent MRU */
1896 ho
->mru
= cishort
; /* And remember value */
1900 if (!ao
->neg_asyncmap
||
1901 cilen
!= CILEN_LONG
) {
1908 * Asyncmap must have set at least the bits
1909 * which are set in lcp_allowoptions[unit].asyncmap.
1911 if ((ao
->asyncmap
& ~cilong
) != 0) {
1913 PUTCHAR(CI_ASYNCMAP
, nakoutp
);
1914 PUTCHAR(CILEN_LONG
, nakoutp
);
1915 PUTLONG(ao
->asyncmap
| cilong
, nakoutp
);
1918 ho
->neg_asyncmap
= 1;
1919 ho
->asyncmap
= cilong
;
1923 if (cilen
< CILEN_SHORT
||
1927 #endif /* PAP_SUPPORT */
1930 #endif /* CHAP_SUPPORT */
1933 #endif /* EAP_SUPPORT */
1936 * Reject the option if we're not willing to authenticate.
1938 ppp_dbglog("No auth is possible");
1942 GETSHORT(cishort
, p
);
1945 * Authtype must be PAP, CHAP, or EAP.
1947 * Note: if more than one of ao->neg_upap, ao->neg_chap, and
1948 * ao->neg_eap are set, and the peer sends a Configure-Request
1949 * with two or more authenticate-protocol requests, then we will
1950 * reject the second request.
1951 * Whether we end up doing CHAP, UPAP, or EAP depends then on
1952 * the ordering of the CIs in the peer's Configure-Request.
1956 if (cishort
== PPP_PAP
) {
1957 /* we've already accepted CHAP or EAP */
1961 #endif /* CHAP_SUPPORT */
1964 #endif /* EAP_SUPPORT */
1965 || cilen
!= CILEN_SHORT
) {
1966 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1970 if (!ao
->neg_upap
) { /* we don't want to do PAP */
1971 orc
= CONFNAK
; /* NAK it and suggest CHAP or EAP */
1972 PUTCHAR(CI_AUTHTYPE
, nakoutp
);
1975 PUTCHAR(CILEN_SHORT
, nakoutp
);
1976 PUTSHORT(PPP_EAP
, nakoutp
);
1978 #endif /* EAP_SUPPORT */
1980 PUTCHAR(CILEN_CHAP
, nakoutp
);
1981 PUTSHORT(PPP_CHAP
, nakoutp
);
1982 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakoutp
);
1983 #endif /* CHAP_SUPPORT */
1986 #endif /* EAP_SUPPORT */
1992 #endif /* PAP_SUPPORT */
1994 if (cishort
== PPP_CHAP
) {
1995 /* we've already accepted PAP or EAP */
1999 #endif /* PAP_SUPPORT */
2002 #endif /* EAP_SUPPORT */
2003 cilen
!= CILEN_CHAP
) {
2004 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
2008 if (!ao
->neg_chap
) { /* we don't want to do CHAP */
2009 orc
= CONFNAK
; /* NAK it and suggest EAP or PAP */
2010 PUTCHAR(CI_AUTHTYPE
, nakoutp
);
2011 PUTCHAR(CILEN_SHORT
, nakoutp
);
2014 PUTSHORT(PPP_EAP
, nakoutp
);
2016 #endif /* EAP_SUPPORT */
2019 PUTSHORT(PPP_PAP
, nakoutp
);
2022 #endif /* PAP_SUPPORT */
2026 GETCHAR(cichar
, p
); /* get digest type */
2027 if (!(CHAP_CANDIGEST(ao
->chap_mdtype
, cichar
))) {
2029 * We can't/won't do the requested type,
2030 * suggest something else.
2033 PUTCHAR(CI_AUTHTYPE
, nakoutp
);
2034 PUTCHAR(CILEN_CHAP
, nakoutp
);
2035 PUTSHORT(PPP_CHAP
, nakoutp
);
2036 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakoutp
);
2039 ho
->chap_mdtype
= CHAP_MDTYPE_D(cichar
); /* save md type */
2043 #endif /* CHAP_SUPPORT */
2045 if (cishort
== PPP_EAP
) {
2046 /* we've already accepted CHAP or PAP */
2050 #endif /* CHAP_SUPPORT */
2053 #endif /* PAP_SUPPORT */
2054 cilen
!= CILEN_SHORT
) {
2055 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE EAP, rejecting..."));
2059 if (!ao
->neg_eap
) { /* we don't want to do EAP */
2060 orc
= CONFNAK
; /* NAK it and suggest CHAP or PAP */
2061 PUTCHAR(CI_AUTHTYPE
, nakoutp
);
2064 PUTCHAR(CILEN_CHAP
, nakoutp
);
2065 PUTSHORT(PPP_CHAP
, nakoutp
);
2066 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakoutp
);
2068 #endif /* CHAP_SUPPORT */
2071 PUTCHAR(CILEN_SHORT
, nakoutp
);
2072 PUTSHORT(PPP_PAP
, nakoutp
);
2074 #endif /* PAP_SUPPORT */
2081 #endif /* EAP_SUPPORT */
2084 * We don't recognize the protocol they're asking for.
2085 * Nak it with something we're willing to do.
2086 * (At this point we know ao->neg_upap || ao->neg_chap ||
2090 PUTCHAR(CI_AUTHTYPE
, nakoutp
);
2094 PUTCHAR(CILEN_SHORT
, nakoutp
);
2095 PUTSHORT(PPP_EAP
, nakoutp
);
2097 #endif /* EAP_SUPPORT */
2100 PUTCHAR(CILEN_CHAP
, nakoutp
);
2101 PUTSHORT(PPP_CHAP
, nakoutp
);
2102 PUTCHAR(CHAP_DIGEST(ao
->chap_mdtype
), nakoutp
);
2104 #endif /* CHAP_SUPPORT */
2107 PUTCHAR(CILEN_SHORT
, nakoutp
);
2108 PUTSHORT(PPP_PAP
, nakoutp
);
2110 #endif /* PAP_SUPPORT */
2117 cilen
!= CILEN_LQR
) {
2122 GETSHORT(cishort
, p
);
2126 * Check the protocol and the reporting period.
2127 * XXX When should we Nak this, and what with?
2129 if (cishort
!= PPP_LQR
) {
2131 PUTCHAR(CI_QUALITY
, nakoutp
);
2132 PUTCHAR(CILEN_LQR
, nakoutp
);
2133 PUTSHORT(PPP_LQR
, nakoutp
);
2134 PUTLONG(ao
->lqr_period
, nakoutp
);
2138 #endif /* LQR_SUPPORT */
2140 case CI_MAGICNUMBER
:
2141 if (!(ao
->neg_magicnumber
|| go
->neg_magicnumber
) ||
2142 cilen
!= CILEN_LONG
) {
2149 * He must have a different magic number.
2151 if (go
->neg_magicnumber
&&
2152 cilong
== go
->magicnumber
) {
2153 cilong
= magic(); /* Don't put magic() inside macro! */
2155 PUTCHAR(CI_MAGICNUMBER
, nakoutp
);
2156 PUTCHAR(CILEN_LONG
, nakoutp
);
2157 PUTLONG(cilong
, nakoutp
);
2160 ho
->neg_magicnumber
= 1;
2161 ho
->magicnumber
= cilong
;
2165 case CI_PCOMPRESSION
:
2166 if (!ao
->neg_pcompression
||
2167 cilen
!= CILEN_VOID
) {
2171 ho
->neg_pcompression
= 1;
2174 case CI_ACCOMPRESSION
:
2175 if (!ao
->neg_accompression
||
2176 cilen
!= CILEN_VOID
) {
2180 ho
->neg_accompression
= 1;
2183 #ifdef HAVE_MULTILINK
2187 || cilen
!= CILEN_SHORT
) {
2192 GETSHORT(cishort
, p
);
2193 /* possibly should insist on a minimum/maximum MRRU here */
2197 #endif /* HAVE_MULTILINK */
2201 #ifdef HAVE_MULTILINK
2203 #endif /* HAVE_MULTILINK */
2204 || cilen
!= CILEN_VOID
) {
2212 if (!ao
->neg_endpoint
||
2213 cilen
< CILEN_CHAR
||
2214 cilen
> CILEN_CHAR
+ MAX_ENDP_LEN
) {
2219 cilen
-= CILEN_CHAR
;
2220 ho
->neg_endpoint
= 1;
2221 ho
->endpoint
.class_
= cichar
;
2222 ho
->endpoint
.length
= cilen
;
2223 MEMCPY(ho
->endpoint
.value
, p
, cilen
);
2228 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype
));
2234 if (orc
== CONFACK
&& /* Good CI */
2235 rc
!= CONFACK
) /* but prior CI wasnt? */
2236 continue; /* Don't send this one */
2238 if (orc
== CONFNAK
) { /* Nak this CI? */
2239 if (reject_if_disagree
/* Getting fed up with sending NAKs? */
2240 && citype
!= CI_MAGICNUMBER
) {
2241 orc
= CONFREJ
; /* Get tough if so */
2243 if (rc
== CONFREJ
) /* Rejecting prior CI? */
2244 continue; /* Don't send this one */
2248 if (orc
== CONFREJ
) { /* Reject this CI */
2250 if (cip
!= rejp
) /* Need to move rejected CI? */
2251 MEMCPY(rejp
, cip
, cilen
); /* Move it */
2252 INCPTR(cilen
, rejp
); /* Update output pointer */
2257 * If we wanted to send additional NAKs (for unsent CIs), the
2258 * code would go here. The extra NAKs would go at *nakoutp.
2259 * At present there are no cases where we want to ask the
2260 * peer to negotiate an option.
2269 * Copy the Nak'd options from the nak buffer to the caller's buffer.
2271 *lenp
= nakoutp
- (u_char
*)nakp
->payload
;
2272 MEMCPY(inp
, nakp
->payload
, *lenp
);
2282 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc
)));
2283 return (rc
); /* Return final code */
2288 * lcp_up - LCP has come UP.
2290 static void lcp_up(fsm
*f
) {
2291 ppp_pcb
*pcb
= f
->pcb
;
2292 lcp_options
*wo
= &pcb
->lcp_wantoptions
;
2293 lcp_options
*ho
= &pcb
->lcp_hisoptions
;
2294 lcp_options
*go
= &pcb
->lcp_gotoptions
;
2295 lcp_options
*ao
= &pcb
->lcp_allowoptions
;
2298 if (!go
->neg_magicnumber
)
2299 go
->magicnumber
= 0;
2300 if (!ho
->neg_magicnumber
)
2301 ho
->magicnumber
= 0;
2304 * Set our MTU to the smaller of the MTU we wanted and
2305 * the MRU our peer wanted. If we negotiated an MRU,
2306 * set our MRU to the larger of value we wanted and
2307 * the value we got in the negotiation.
2308 * Note on the MTU: the link MTU can be the MRU the peer wanted,
2309 * the interface MTU is set to the lowest of that, the
2310 * MTU we want to use, and our link MRU.
2312 mtu
= ho
->neg_mru
? ho
->mru
: PPP_MRU
;
2313 mru
= go
->neg_mru
? LWIP_MAX(wo
->mru
, go
->mru
): PPP_MRU
;
2314 #ifdef HAVE_MULTILINK
2315 if (!(multilink
&& go
->neg_mrru
&& ho
->neg_mrru
))
2316 #endif /* HAVE_MULTILINK */
2317 netif_set_mtu(pcb
, LWIP_MIN(LWIP_MIN(mtu
, mru
), ao
->mru
));
2318 ppp_send_config(pcb
, mtu
,
2319 (ho
->neg_asyncmap
? ho
->asyncmap
: 0xffffffff),
2320 ho
->neg_pcompression
, ho
->neg_accompression
);
2321 ppp_recv_config(pcb
, mru
,
2322 (pcb
->settings
.lax_recv
? 0: go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
2323 go
->neg_pcompression
, go
->neg_accompression
);
2326 pcb
->peer_mru
= ho
->mru
;
2328 lcp_echo_lowerup(f
->pcb
); /* Enable echo messages */
2330 link_established(pcb
);
2335 * lcp_down - LCP has gone DOWN.
2337 * Alert other protocols.
2339 static void lcp_down(fsm
*f
) {
2340 ppp_pcb
*pcb
= f
->pcb
;
2341 lcp_options
*go
= &pcb
->lcp_gotoptions
;
2343 lcp_echo_lowerdown(f
->pcb
);
2347 ppp_send_config(pcb
, PPP_MRU
, 0xffffffff, 0, 0);
2348 ppp_recv_config(pcb
, PPP_MRU
,
2349 (go
->neg_asyncmap
? go
->asyncmap
: 0xffffffff),
2350 go
->neg_pcompression
, go
->neg_accompression
);
2351 pcb
->peer_mru
= PPP_MRU
;
2356 * lcp_starting - LCP needs the lower layer up.
2358 static void lcp_starting(fsm
*f
) {
2359 ppp_pcb
*pcb
= f
->pcb
;
2365 * lcp_finished - LCP has finished with the lower layer.
2367 static void lcp_finished(fsm
*f
) {
2368 ppp_pcb
*pcb
= f
->pcb
;
2369 link_terminated(pcb
);
2373 #if PRINTPKT_SUPPORT
2375 * lcp_printpkt - print the contents of an LCP packet.
2377 static const char* const lcp_codenames
[] = {
2378 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
2379 "TermReq", "TermAck", "CodeRej", "ProtRej",
2380 "EchoReq", "EchoRep", "DiscReq", "Ident",
2384 static int lcp_printpkt(const u_char
*p
, int plen
,
2385 void (*printer
) (void *, const char *, ...), void *arg
) {
2386 int code
, id
, len
, olen
, i
;
2387 const u_char
*pstart
, *optend
;
2391 if (plen
< HEADERLEN
)
2397 if (len
< HEADERLEN
|| len
> plen
)
2400 if (code
>= 1 && code
<= (int)LWIP_ARRAYSIZE(lcp_codenames
))
2401 printer(arg
, " %s", lcp_codenames
[code
-1]);
2403 printer(arg
, " code=0x%x", code
);
2404 printer(arg
, " id=0x%x", id
);
2411 /* print option list */
2416 if (olen
< 2 || olen
> len
) {
2424 if (olen
== CILEN_SHORT
) {
2426 GETSHORT(cishort
, p
);
2427 printer(arg
, "mru %d", cishort
);
2431 if (olen
== CILEN_LONG
) {
2434 printer(arg
, "asyncmap 0x%x", cilong
);
2438 if (olen
>= CILEN_SHORT
) {
2440 printer(arg
, "auth ");
2441 GETSHORT(cishort
, p
);
2445 printer(arg
, "pap");
2447 #endif /* PAP_SUPPORT */
2450 printer(arg
, "chap");
2454 printer(arg
, " MD5");
2458 case CHAP_MICROSOFT
:
2459 printer(arg
, " MS");
2463 case CHAP_MICROSOFT_V2
:
2464 printer(arg
, " MS-v2");
2467 #endif /* MSCHAP_SUPPORT */
2473 #endif /* CHAP_SUPPORT */
2476 printer(arg
, "eap");
2478 #endif /* EAP_SUPPORT */
2480 printer(arg
, "0x%x", cishort
);
2486 if (olen
>= CILEN_SHORT
) {
2488 printer(arg
, "quality ");
2489 GETSHORT(cishort
, p
);
2492 printer(arg
, "lqr");
2495 printer(arg
, "0x%x", cishort
);
2499 #endif /* LQR_SUPPORT */
2501 if (olen
>= CILEN_CHAR
) {
2503 printer(arg
, "callback ");
2504 GETCHAR(cishort
, p
);
2507 printer(arg
, "CBCP");
2510 printer(arg
, "0x%x", cishort
);
2514 case CI_MAGICNUMBER
:
2515 if (olen
== CILEN_LONG
) {
2518 printer(arg
, "magic 0x%x", cilong
);
2521 case CI_PCOMPRESSION
:
2522 if (olen
== CILEN_VOID
) {
2524 printer(arg
, "pcomp");
2527 case CI_ACCOMPRESSION
:
2528 if (olen
== CILEN_VOID
) {
2530 printer(arg
, "accomp");
2534 if (olen
== CILEN_SHORT
) {
2536 GETSHORT(cishort
, p
);
2537 printer(arg
, "mrru %d", cishort
);
2541 if (olen
== CILEN_VOID
) {
2543 printer(arg
, "ssnhf");
2547 #ifdef HAVE_MULTILINK
2548 if (olen
>= CILEN_CHAR
) {
2551 GETCHAR(epd
.class, p
);
2552 epd
.length
= olen
- CILEN_CHAR
;
2553 if (epd
.length
> MAX_ENDP_LEN
)
2554 epd
.length
= MAX_ENDP_LEN
;
2555 if (epd
.length
> 0) {
2556 MEMCPY(epd
.value
, p
, epd
.length
);
2559 printer(arg
, "endpoint [%s]", epdisc_to_str(&epd
));
2562 printer(arg
, "endpoint");
2568 while (p
< optend
) {
2570 printer(arg
, " %.2x", code
);
2578 if (len
> 0 && *p
>= ' ' && *p
< 0x7f) {
2580 ppp_print_string(p
, len
, printer
, arg
);
2591 printer(arg
, " magic=0x%x", cilong
);
2600 printer(arg
, " magic=0x%x", cilong
);
2603 if (code
== TIMEREM
) {
2607 printer(arg
, " seconds=%u", cilong
);
2612 ppp_print_string(p
, len
, printer
, arg
);
2621 /* print the rest of the bytes in the packet */
2622 for (i
= 0; i
< len
&& i
< 32; ++i
) {
2624 printer(arg
, " %.2x", code
);
2627 printer(arg
, " ...");
2633 #endif /* PRINTPKT_SUPPORT */
2636 * Time to shut down the link because there is nothing out there.
2639 static void LcpLinkFailure(fsm
*f
) {
2640 ppp_pcb
*pcb
= f
->pcb
;
2641 if (f
->state
== PPP_FSM_OPENED
) {
2642 ppp_info("No response to %d echo-requests", pcb
->lcp_echos_pending
);
2643 ppp_notice("Serial link appears to be disconnected.");
2644 pcb
->err_code
= PPPERR_PEERDEAD
;
2645 lcp_close(pcb
, "Peer not responding");
2650 * Timer expired for the LCP echo requests from this process.
2653 static void LcpEchoCheck(fsm
*f
) {
2654 ppp_pcb
*pcb
= f
->pcb
;
2656 LcpSendEchoRequest (f
);
2657 if (f
->state
!= PPP_FSM_OPENED
)
2661 * Start the timer for the next interval.
2663 if (pcb
->lcp_echo_timer_running
)
2664 ppp_warn("assertion lcp_echo_timer_running==0 failed");
2665 TIMEOUT (LcpEchoTimeout
, f
, pcb
->settings
.lcp_echo_interval
);
2666 pcb
->lcp_echo_timer_running
= 1;
2670 * LcpEchoTimeout - Timer expired on the LCP echo
2673 static void LcpEchoTimeout(void *arg
) {
2675 ppp_pcb
*pcb
= f
->pcb
;
2676 if (pcb
->lcp_echo_timer_running
!= 0) {
2677 pcb
->lcp_echo_timer_running
= 0;
2678 LcpEchoCheck ((fsm
*) arg
);
2683 * LcpEchoReply - LCP has received a reply to the echo
2686 static void lcp_received_echo_reply(fsm
*f
, int id
, u_char
*inp
, int len
) {
2687 ppp_pcb
*pcb
= f
->pcb
;
2688 lcp_options
*go
= &pcb
->lcp_gotoptions
;
2690 LWIP_UNUSED_ARG(id
);
2692 /* Check the magic number - don't count replies from ourselves. */
2694 ppp_dbglog("lcp: received short Echo-Reply, length %d", len
);
2697 GETLONG(magic_val
, inp
);
2698 if (go
->neg_magicnumber
2699 && magic_val
== go
->magicnumber
) {
2700 ppp_warn("appear to have received our own echo-reply!");
2704 /* Reset the number of outstanding echo frames */
2705 pcb
->lcp_echos_pending
= 0;
2709 * LcpSendEchoRequest - Send an echo request frame to the peer
2712 static void LcpSendEchoRequest(fsm
*f
) {
2713 ppp_pcb
*pcb
= f
->pcb
;
2714 lcp_options
*go
= &pcb
->lcp_gotoptions
;
2716 u_char pkt
[4], *pktp
;
2719 * Detect the failure of the peer at this point.
2721 if (pcb
->settings
.lcp_echo_fails
!= 0) {
2722 if (pcb
->lcp_echos_pending
>= pcb
->settings
.lcp_echo_fails
) {
2724 pcb
->lcp_echos_pending
= 0;
2728 #if PPP_LCP_ADAPTIVE
2730 * If adaptive echos have been enabled, only send the echo request if
2731 * no traffic was received since the last one.
2733 if (pcb
->settings
.lcp_echo_adaptive
) {
2734 static unsigned int last_pkts_in
= 0;
2736 #if PPP_STATS_SUPPORT
2737 update_link_stats(f
->unit
);
2738 link_stats_valid
= 0;
2739 #endif /* PPP_STATS_SUPPORT */
2741 if (link_stats
.pkts_in
!= last_pkts_in
) {
2742 last_pkts_in
= link_stats
.pkts_in
;
2749 * Make and send the echo request frame.
2751 if (f
->state
== PPP_FSM_OPENED
) {
2752 lcp_magic
= go
->magicnumber
;
2754 PUTLONG(lcp_magic
, pktp
);
2755 fsm_sdata(f
, ECHOREQ
, pcb
->lcp_echo_number
++, pkt
, pktp
- pkt
);
2756 ++pcb
->lcp_echos_pending
;
2761 * lcp_echo_lowerup - Start the timer for the LCP frame
2764 static void lcp_echo_lowerup(ppp_pcb
*pcb
) {
2765 fsm
*f
= &pcb
->lcp_fsm
;
2767 /* Clear the parameters for generating echo frames */
2768 pcb
->lcp_echos_pending
= 0;
2769 pcb
->lcp_echo_number
= 0;
2770 pcb
->lcp_echo_timer_running
= 0;
2772 /* If a timeout interval is specified then start the timer */
2773 if (pcb
->settings
.lcp_echo_interval
!= 0)
2778 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2781 static void lcp_echo_lowerdown(ppp_pcb
*pcb
) {
2782 fsm
*f
= &pcb
->lcp_fsm
;
2784 if (pcb
->lcp_echo_timer_running
!= 0) {
2785 UNTIMEOUT (LcpEchoTimeout
, f
);
2786 pcb
->lcp_echo_timer_running
= 0;
2790 #endif /* PPP_SUPPORT */