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 #define RCSID "$Id: lcp.c,v 1.76 2006/05/22 00:04:07 paulus Exp $"
61 * When the link comes up we want to be able to wait for a short while,
62 * or until seeing some input from the peer, before starting to send
63 * configure-requests. We do this by delaying the fsm_lowerup call.
65 /* steal a bit in fsm flags word */
66 #define DELAYED_UP 0x100
68 static void lcp_delayed_up __P((void *));
71 * LCP-related command-line options.
73 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
74 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
75 bool lcp_echo_adaptive = 0; /* request echo only if the link was idle */
76 bool lax_recv = 0; /* accept control chars in asyncmap */
77 bool noendpoint = 0; /* don't send/accept endpoint discriminator */
79 static int noopt __P((char **));
82 static int setendpoint __P((char **));
83 static void printendpoint __P((option_t *, void (*)(void *, char *, ...),
85 #endif /* HAVE_MULTILINK */
87 static option_t lcp_option_list[] = {
89 { "-all", o_special_noarg, (void *)noopt,
90 "Don't request/allow any LCP options" },
92 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
93 "Disable address/control compression",
94 OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
95 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
96 "Disable address/control compression",
97 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
99 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
100 "Set asyncmap (for received packets)",
101 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
102 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
103 "Set asyncmap (for received packets)",
104 OPT_ALIAS | OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
105 { "default-asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
106 "Disable asyncmap negotiation",
107 OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
108 &lcp_allowoptions[0].neg_asyncmap },
109 { "-am", o_uint32, &lcp_wantoptions[0].asyncmap,
110 "Disable asyncmap negotiation",
111 OPT_ALIAS | OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
112 &lcp_allowoptions[0].neg_asyncmap },
114 { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
115 "Disable magic number negotiation (looped-back line detection)",
116 OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
117 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
118 "Disable magic number negotiation (looped-back line detection)",
119 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
121 { "mru", o_int, &lcp_wantoptions[0].mru,
122 "Set MRU (maximum received packet size) for negotiation",
123 OPT_PRIO, &lcp_wantoptions[0].neg_mru },
124 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
125 "Disable MRU negotiation (use default 1500)",
126 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
127 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
128 "Disable MRU negotiation (use default 1500)",
129 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
131 { "mtu", o_int, &lcp_allowoptions[0].mru,
132 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
134 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
135 "Disable protocol field compression",
136 OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
137 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
138 "Disable protocol field compression",
139 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
141 { "passive", o_bool, &lcp_wantoptions[0].passive,
142 "Set passive mode", 1 },
143 { "-p", o_bool, &lcp_wantoptions[0].passive,
144 "Set passive mode", OPT_ALIAS | 1 },
146 { "silent", o_bool, &lcp_wantoptions[0].silent,
147 "Set silent mode", 1 },
149 { "lcp-echo-failure", o_int, &lcp_echo_fails,
150 "Set number of consecutive echo failures to indicate link failure",
152 { "lcp-echo-interval", o_int, &lcp_echo_interval,
153 "Set time in seconds between LCP echo requests", OPT_PRIO },
154 { "lcp-echo-adaptive", o_bool, &lcp_echo_adaptive,
155 "Suppress LCP echo requests if traffic was received", 1 },
156 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
157 "Set time in seconds between LCP retransmissions", OPT_PRIO },
158 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
159 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO },
160 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
161 "Set maximum number of LCP configure-request transmissions", OPT_PRIO },
162 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
163 "Set limit on number of LCP configure-naks", OPT_PRIO },
165 { "receive-all", o_bool, &lax_recv,
166 "Accept all received control characters", 1 },
168 #ifdef HAVE_MULTILINK
169 { "mrru", o_int, &lcp_wantoptions[0].mrru,
170 "Maximum received packet size for multilink bundle",
171 OPT_PRIO, &lcp_wantoptions[0].neg_mrru },
173 { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
174 "Use short sequence numbers in multilink headers",
175 OPT_PRIO | 1, &lcp_allowoptions[0].neg_ssnhf },
176 { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
177 "Don't use short sequence numbers in multilink headers",
178 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_ssnhf },
180 { "endpoint", o_special, (void *) setendpoint,
181 "Endpoint discriminator for multilink",
182 OPT_PRIO | OPT_A2PRINTER, (void *) printendpoint },
183 #endif /* HAVE_MULTILINK */
185 { "noendpoint", o_bool, &noendpoint,
186 "Don't send or accept multilink endpoint discriminator", 1 },
192 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
193 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
194 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
195 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
196 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
198 static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
199 static int lcp_echo_number = 0; /* ID number of next echo frame */
200 static int lcp_echo_timer_running = 0; /* set if a timer is running */
202 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
205 * Callbacks for fsm code. (CI = Configuration Information)
207 static void lcp_resetci __P((fsm *)); /* Reset our CI */
208 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
209 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
210 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
211 static int lcp_nakci __P((fsm *, u_char *, int, int)); /* Peer nak'd our CI */
212 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
213 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
214 static void lcp_up __P((fsm *)); /* We're UP */
215 static void lcp_down __P((fsm *)); /* We're DOWN */
216 static void lcp_starting __P((fsm *)); /* We need lower layer up */
217 static void lcp_finished __P((fsm *)); /* We need lower layer down */
218 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
219 static void lcp_rprotrej __P((fsm *, u_char *, int));
222 * routines to send LCP echos to peer
225 static void lcp_echo_lowerup __P((int));
226 static void lcp_echo_lowerdown __P((int));
227 static void LcpEchoTimeout __P((void *));
228 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
229 static void LcpSendEchoRequest __P((fsm *));
230 static void LcpLinkFailure __P((fsm *));
231 static void LcpEchoCheck __P((fsm *));
233 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
234 lcp_resetci, /* Reset our Configuration Information */
235 lcp_cilen, /* Length of our Configuration Information */
236 lcp_addci, /* Add our Configuration Information */
237 lcp_ackci, /* ACK our Configuration Information */
238 lcp_nakci, /* NAK our Configuration Information */
239 lcp_rejci, /* Reject our Configuration Information */
240 lcp_reqci, /* Request peer's Configuration Information */
241 lcp_up, /* Called when fsm reaches OPENED state */
242 lcp_down, /* Called when fsm leaves OPENED state */
243 lcp_starting, /* Called when we want the lower layer up */
244 lcp_finished, /* Called when we want the lower layer down */
245 NULL, /* Called when Protocol-Reject received */
246 NULL, /* Retransmission is necessary */
247 lcp_extcode, /* Called to handle LCP-specific codes */
248 "LCP" /* String name of protocol */
252 * Protocol entry points.
253 * Some of these are called directly.
256 static void lcp_init __P((int));
257 static void lcp_input __P((int, u_char *, int));
258 static void lcp_protrej __P((int));
259 static int lcp_printpkt __P((u_char *, int,
260 void (*) __P((void *, char *, ...)), void *));
262 struct protent lcp_protent = {
282 int lcp_loopbackfail = DEFLOOPBACKFAIL;
285 * Length of each type of configuration option (in octets)
289 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
290 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
291 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
292 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
295 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
296 (x) == CONFNAK ? "NAK" : "REJ")
299 * noopt - Disable all options (why?).
305 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
306 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
311 #ifdef HAVE_MULTILINK
316 if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) {
317 lcp_wantoptions[0].neg_endpoint = 1;
320 option_error("Can't parse '%s' as an endpoint discriminator", *argv);
325 printendpoint(opt, printer, arg)
327 void (*printer) __P((void *, char *, ...));
330 printer(arg, "%s", epdisc_to_str(&lcp_wantoptions[0].endpoint));
332 #endif /* HAVE_MULTILINK */
335 * lcp_init - Initialize LCP.
341 fsm *f = &lcp_fsm[unit];
342 lcp_options *wo = &lcp_wantoptions[unit];
343 lcp_options *ao = &lcp_allowoptions[unit];
346 f->protocol = PPP_LCP;
347 f->callbacks = &lcp_callbacks;
351 BZERO(wo, sizeof(*wo));
354 wo->neg_asyncmap = 1;
355 wo->neg_magicnumber = 1;
356 wo->neg_pcompression = 1;
357 wo->neg_accompression = 1;
359 BZERO(ao, sizeof(*ao));
362 ao->neg_asyncmap = 1;
364 ao->chap_mdtype = chap_mdtype_all;
367 ao->neg_magicnumber = 1;
368 ao->neg_pcompression = 1;
369 ao->neg_accompression = 1;
370 ao->neg_endpoint = 1;
375 * lcp_open - LCP is allowed to come up.
381 fsm *f = &lcp_fsm[unit];
382 lcp_options *wo = &lcp_wantoptions[unit];
384 f->flags &= ~(OPT_PASSIVE | OPT_SILENT);
386 f->flags |= OPT_PASSIVE;
388 f->flags |= OPT_SILENT;
394 * lcp_close - Take LCP down.
397 lcp_close(unit, reason)
401 fsm *f = &lcp_fsm[unit];
404 if (phase != PHASE_DEAD && phase != PHASE_MASTER)
405 new_phase(PHASE_TERMINATE);
407 if (f->flags & DELAYED_UP) {
408 untimeout(lcp_delayed_up, f);
413 fsm_close(f, reason);
414 if (oldstate == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT|DELAYED_UP)) {
416 * This action is not strictly according to the FSM in RFC1548,
417 * but it does mean that the program terminates if you do a
418 * lcp_close() when a connection hasn't been established
419 * because we are in passive/silent mode or because we have
420 * delayed the fsm_lowerup() call and it hasn't happened yet.
422 f->flags &= ~DELAYED_UP;
429 * lcp_lowerup - The lower layer is up.
435 lcp_options *wo = &lcp_wantoptions[unit];
436 fsm *f = &lcp_fsm[unit];
439 * Don't use A/C or protocol compression on transmission,
440 * but accept A/C and protocol compressed packets
441 * if we are going to ask for A/C and protocol compression.
443 if (ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0) < 0
444 || ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
445 wo->neg_pcompression, wo->neg_accompression) < 0)
447 peer_mru[unit] = PPP_MRU;
449 if (listen_time != 0) {
450 f->flags |= DELAYED_UP;
451 timeout(lcp_delayed_up, f, 0, listen_time * 1000);
458 * lcp_lowerdown - The lower layer is down.
464 fsm *f = &lcp_fsm[unit];
466 if (f->flags & DELAYED_UP) {
467 f->flags &= ~DELAYED_UP;
468 untimeout(lcp_delayed_up, f);
470 fsm_lowerdown(&lcp_fsm[unit]);
475 * lcp_delayed_up - Bring the lower layer up now.
483 if (f->flags & DELAYED_UP) {
484 f->flags &= ~DELAYED_UP;
491 * lcp_input - Input LCP packet.
494 lcp_input(unit, p, len)
499 fsm *f = &lcp_fsm[unit];
501 if (f->flags & DELAYED_UP) {
502 f->flags &= ~DELAYED_UP;
503 untimeout(lcp_delayed_up, f);
506 fsm_input(f, p, len);
510 * lcp_extcode - Handle a LCP-specific code.
513 lcp_extcode(f, code, id, inp, len)
523 lcp_rprotrej(f, inp, len);
527 if (f->state != OPENED)
530 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
531 fsm_sdata(f, ECHOREP, id, inp, len);
535 lcp_received_echo_reply(f, id, inp, len);
551 * lcp_rprotrej - Receive an Protocol-Reject.
553 * Figure out which protocol is rejected and inform it.
556 lcp_rprotrej(f, inp, len)
562 struct protent *protp;
567 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
574 * Protocol-Reject packets received in any state other than the LCP
575 * OPENED state SHOULD be silently discarded.
577 if( f->state != OPENED ){
578 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
582 pname = protocol_name(prot);
585 * Upcall the proper Protocol-Reject routine.
587 for (i = 0; (protp = protocols[i]) != NULL; ++i)
588 if (protp->protocol == prot && protp->enabled_flag) {
590 dbglog("Protocol-Reject for 0x%x received", prot);
592 dbglog("Protocol-Reject for '%s' (0x%x) received", pname,
594 (*protp->protrej)(f->unit);
599 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
601 warn("Protocol-Reject for unsupported protocol '%s' (0x%x)", pname,
607 * lcp_protrej - A Protocol-Reject was received.
617 error("Received Protocol-Reject for LCP!");
618 fsm_protreject(&lcp_fsm[unit]);
623 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
626 lcp_sprotrej(unit, p, len)
632 * Send back the protocol and the information field of the
633 * rejected packet. We only get here if LCP is in the OPENED state.
638 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
644 * lcp_resetci - Reset our CI.
650 lcp_options *wo = &lcp_wantoptions[f->unit];
651 lcp_options *go = &lcp_gotoptions[f->unit];
652 lcp_options *ao = &lcp_allowoptions[f->unit];
654 wo->magicnumber = magic();
660 go->neg_endpoint = 0;
663 ao->neg_endpoint = 0;
664 peer_mru[f->unit] = PPP_MRU;
670 * lcp_cilen - Return length of our CI.
676 lcp_options *go = &lcp_gotoptions[f->unit];
678 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
679 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
680 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
681 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
682 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
683 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
685 * NB: we only ask for one of CHAP, UPAP, or EAP, even if we will
686 * accept more than one. We prefer EAP first, then CHAP, then
689 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
690 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
691 LENCISHORT(go->neg_eap) +
692 LENCICHAP(!go->neg_eap && go->neg_chap) +
693 LENCISHORT(!go->neg_eap && !go->neg_chap && go->neg_upap) +
694 LENCILQR(go->neg_lqr) +
695 LENCICBCP(go->neg_cbcp) +
696 LENCILONG(go->neg_magicnumber) +
697 LENCIVOID(go->neg_pcompression) +
698 LENCIVOID(go->neg_accompression) +
699 LENCISHORT(go->neg_mrru) +
700 LENCIVOID(go->neg_ssnhf) +
701 (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
706 * lcp_addci - Add our desired CIs to a packet.
709 lcp_addci(f, ucp, lenp)
714 lcp_options *go = &lcp_gotoptions[f->unit];
715 u_char *start_ucp = ucp;
717 #define ADDCIVOID(opt, neg) \
720 PUTCHAR(CILEN_VOID, ucp); \
722 #define ADDCISHORT(opt, neg, val) \
725 PUTCHAR(CILEN_SHORT, ucp); \
726 PUTSHORT(val, ucp); \
728 #define ADDCICHAP(opt, neg, val) \
730 PUTCHAR((opt), ucp); \
731 PUTCHAR(CILEN_CHAP, ucp); \
732 PUTSHORT(PPP_CHAP, ucp); \
733 PUTCHAR((CHAP_DIGEST(val)), ucp); \
735 #define ADDCILONG(opt, neg, val) \
738 PUTCHAR(CILEN_LONG, ucp); \
741 #define ADDCILQR(opt, neg, val) \
744 PUTCHAR(CILEN_LQR, ucp); \
745 PUTSHORT(PPP_LQR, ucp); \
748 #define ADDCICHAR(opt, neg, val) \
751 PUTCHAR(CILEN_CHAR, ucp); \
754 #define ADDCIENDP(opt, neg, class, val, len) \
758 PUTCHAR(CILEN_CHAR + len, ucp); \
759 PUTCHAR(class, ucp); \
760 for (i = 0; i < len; ++i) \
761 PUTCHAR(val[i], ucp); \
764 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
765 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
767 ADDCISHORT(CI_AUTHTYPE, go->neg_eap, PPP_EAP);
768 ADDCICHAP(CI_AUTHTYPE, !go->neg_eap && go->neg_chap, go->chap_mdtype);
769 ADDCISHORT(CI_AUTHTYPE, !go->neg_eap && !go->neg_chap && go->neg_upap,
771 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
772 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
773 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
774 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
775 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
776 ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
777 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
778 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
779 go->endpoint.value, go->endpoint.length);
781 if (ucp - start_ucp != *lenp) {
782 /* this should never happen, because peer_mtu should be 1500 */
783 error("Bug in lcp_addci: wrong length");
789 * lcp_ackci - Ack our CIs.
790 * This should not modify any state if the Ack is bad.
802 lcp_options *go = &lcp_gotoptions[f->unit];
803 u_char cilen, citype, cichar;
808 * CIs must be in exactly the same order that we sent.
809 * Check packet length and CI length at each step.
810 * If we find any deviations, then this packet is bad.
812 #define ACKCIVOID(opt, neg) \
814 if ((len -= CILEN_VOID) < 0) \
816 GETCHAR(citype, p); \
818 if (cilen != CILEN_VOID || \
822 #define ACKCISHORT(opt, neg, val) \
824 if ((len -= CILEN_SHORT) < 0) \
826 GETCHAR(citype, p); \
828 if (cilen != CILEN_SHORT || \
831 GETSHORT(cishort, p); \
832 if (cishort != val) \
835 #define ACKCICHAR(opt, neg, val) \
837 if ((len -= CILEN_CHAR) < 0) \
839 GETCHAR(citype, p); \
841 if (cilen != CILEN_CHAR || \
844 GETCHAR(cichar, p); \
848 #define ACKCICHAP(opt, neg, val) \
850 if ((len -= CILEN_CHAP) < 0) \
852 GETCHAR(citype, p); \
854 if (cilen != CILEN_CHAP || \
857 GETSHORT(cishort, p); \
858 if (cishort != PPP_CHAP) \
860 GETCHAR(cichar, p); \
861 if (cichar != (CHAP_DIGEST(val))) \
864 #define ACKCILONG(opt, neg, val) \
866 if ((len -= CILEN_LONG) < 0) \
868 GETCHAR(citype, p); \
870 if (cilen != CILEN_LONG || \
873 GETLONG(cilong, p); \
877 #define ACKCILQR(opt, neg, val) \
879 if ((len -= CILEN_LQR) < 0) \
881 GETCHAR(citype, p); \
883 if (cilen != CILEN_LQR || \
886 GETSHORT(cishort, p); \
887 if (cishort != PPP_LQR) \
889 GETLONG(cilong, p); \
893 #define ACKCIENDP(opt, neg, class, val, vlen) \
896 if ((len -= CILEN_CHAR + vlen) < 0) \
898 GETCHAR(citype, p); \
900 if (cilen != CILEN_CHAR + vlen || \
903 GETCHAR(cichar, p); \
904 if (cichar != class) \
906 for (i = 0; i < vlen; ++i) { \
907 GETCHAR(cichar, p); \
908 if (cichar != val[i]) \
913 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
914 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
916 ACKCISHORT(CI_AUTHTYPE, go->neg_eap, PPP_EAP);
917 ACKCICHAP(CI_AUTHTYPE, !go->neg_eap && go->neg_chap, go->chap_mdtype);
918 ACKCISHORT(CI_AUTHTYPE, !go->neg_eap && !go->neg_chap && go->neg_upap,
920 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
921 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
922 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
923 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
924 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
925 ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
926 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
927 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
928 go->endpoint.value, go->endpoint.length);
931 * If there are any remaining CIs, then this packet is bad.
937 LCPDEBUG(("lcp_acki: received bad Ack!"));
943 * lcp_nakci - Peer has sent a NAK for some of our CIs.
944 * This should not modify any state if the Nak is bad
945 * or if LCP is in the OPENED state.
952 lcp_nakci(f, p, len, treat_as_reject)
958 lcp_options *go = &lcp_gotoptions[f->unit];
959 lcp_options *wo = &lcp_wantoptions[f->unit];
960 u_char citype, cichar, *next;
963 lcp_options no; /* options we've seen Naks for */
964 lcp_options try; /* options to request next time */
968 BZERO(&no, sizeof(no));
972 * Any Nak'd CIs must be in exactly the same order that we sent.
973 * Check packet length and CI length at each step.
974 * If we find any deviations, then this packet is bad.
976 #define NAKCIVOID(opt, neg) \
978 len >= CILEN_VOID && \
979 p[1] == CILEN_VOID && \
982 INCPTR(CILEN_VOID, p); \
986 #define NAKCICHAP(opt, neg, code) \
988 len >= CILEN_CHAP && \
989 p[1] == CILEN_CHAP && \
993 GETSHORT(cishort, p); \
994 GETCHAR(cichar, p); \
998 #define NAKCICHAR(opt, neg, code) \
1000 len >= CILEN_CHAR && \
1001 p[1] == CILEN_CHAR && \
1003 len -= CILEN_CHAR; \
1005 GETCHAR(cichar, p); \
1009 #define NAKCISHORT(opt, neg, code) \
1011 len >= CILEN_SHORT && \
1012 p[1] == CILEN_SHORT && \
1014 len -= CILEN_SHORT; \
1016 GETSHORT(cishort, p); \
1020 #define NAKCILONG(opt, neg, code) \
1022 len >= CILEN_LONG && \
1023 p[1] == CILEN_LONG && \
1025 len -= CILEN_LONG; \
1027 GETLONG(cilong, p); \
1031 #define NAKCILQR(opt, neg, code) \
1033 len >= CILEN_LQR && \
1034 p[1] == CILEN_LQR && \
1038 GETSHORT(cishort, p); \
1039 GETLONG(cilong, p); \
1043 #define NAKCIENDP(opt, neg) \
1045 len >= CILEN_CHAR && \
1047 p[1] >= CILEN_CHAR && \
1056 * NOTE! There must be no assignments to individual fields of *go in
1057 * the code below. Any such assignment is a BUG!
1060 * We don't care if they want to send us smaller packets than
1061 * we want. Therefore, accept any MRU less than what we asked for,
1062 * but then ignore the new value when setting the MRU in the kernel.
1063 * If they send us a bigger MRU than what we asked, accept it, up to
1064 * the limit of the default MRU we'd get if we didn't negotiate.
1066 if (go->neg_mru && go->mru != DEFMRU) {
1067 NAKCISHORT(CI_MRU, neg_mru,
1068 if (cishort <= wo->mru || cishort <= DEFMRU)
1074 * Add any characters they want to our (receive-side) asyncmap.
1076 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
1077 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
1078 try.asyncmap = go->asyncmap | cilong;
1083 * If they've nak'd our authentication-protocol, check whether
1084 * they are proposing a different protocol, or a different
1085 * hash algorithm for CHAP.
1087 if ((go->neg_chap || go->neg_upap || go->neg_eap)
1088 && len >= CILEN_SHORT
1089 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
1092 no.neg_chap = go->neg_chap;
1093 no.neg_upap = go->neg_upap;
1094 no.neg_eap = go->neg_eap;
1096 GETSHORT(cishort, p);
1097 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
1098 /* If we were asking for EAP, then we need to stop that. */
1102 /* If we were asking for CHAP, then we need to stop that. */
1103 else if (go->neg_chap)
1106 * If we weren't asking for CHAP or EAP, then we were asking for
1107 * PAP, in which case this Nak is bad.
1112 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
1114 /* Stop asking for EAP, if we were. */
1117 /* Try to set up to use their suggestion, if possible */
1118 if (CHAP_CANDIGEST(go->chap_mdtype, cichar))
1119 try.chap_mdtype = CHAP_MDTYPE_D(cichar);
1120 } else if (go->neg_chap) {
1122 * We were asking for our preferred algorithm, they must
1123 * want something different.
1125 if (cichar != CHAP_DIGEST(go->chap_mdtype)) {
1126 if (CHAP_CANDIGEST(go->chap_mdtype, cichar)) {
1127 /* Use their suggestion if we support it ... */
1128 try.chap_mdtype = CHAP_MDTYPE_D(cichar);
1130 /* ... otherwise, try our next-preferred algorithm. */
1131 try.chap_mdtype &= ~(CHAP_MDTYPE(try.chap_mdtype));
1132 if (try.chap_mdtype == MDTYPE_NONE) /* out of algos */
1137 * Whoops, they Nak'd our algorithm of choice
1138 * but then suggested it back to us.
1144 * Stop asking for PAP if we were asking for it.
1152 * If we were asking for EAP, and they're Conf-Naking EAP,
1153 * well, that's just strange. Nobody should do that.
1155 if (cishort == PPP_EAP && cilen == CILEN_SHORT && go->neg_eap)
1156 dbglog("Unexpected Conf-Nak for EAP");
1159 * We don't recognize what they're suggesting.
1160 * Stop asking for what we were asking for.
1164 else if (go->neg_chap)
1168 p += cilen - CILEN_SHORT;
1173 * If they can't cope with our link quality protocol, we'll have
1174 * to stop asking for LQR. We haven't got any other protocol.
1175 * If they Nak the reporting period, take their value XXX ?
1177 NAKCILQR(CI_QUALITY, neg_lqr,
1178 if (cishort != PPP_LQR)
1181 try.lqr_period = cilong;
1185 * Only implementing CBCP...not the rest of the callback options
1187 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1192 * Check for a looped-back line.
1194 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1195 try.magicnumber = magic();
1200 * Peer shouldn't send Nak for protocol compression or
1201 * address/control compression requests; they should send
1202 * a Reject instead. If they send a Nak, treat it as a Reject.
1204 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1205 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1208 * Nak for MRRU option - accept their value if it is smaller
1209 * than the one we want.
1212 NAKCISHORT(CI_MRRU, neg_mrru,
1213 if (treat_as_reject)
1215 else if (cishort <= wo->mrru)
1221 * Nak for short sequence numbers shouldn't be sent, treat it
1224 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1227 * Nak of the endpoint discriminator option is not permitted,
1228 * treat it like a reject.
1230 NAKCIENDP(CI_EPDISC, neg_endpoint);
1233 * There may be remaining CIs, if the peer is requesting negotiation
1234 * on an option that we didn't include in our request packet.
1235 * If we see an option that we requested, or one we've already seen
1236 * in this packet, then this packet is bad.
1237 * If we wanted to respond by starting to negotiate on the requested
1238 * option(s), we could, but we don't, because except for the
1239 * authentication type and quality protocol, if we are not negotiating
1240 * an option, it is because we were told not to.
1241 * For the authentication type, the Nak from the peer means
1242 * `let me authenticate myself with you' which is a bit pointless.
1243 * For the quality protocol, the Nak means `ask me to send you quality
1244 * reports', but if we didn't ask for them, we don't want them.
1245 * An option we don't recognize represents the peer asking to
1246 * negotiate some option we don't support, so ignore it.
1248 while (len >= CILEN_VOID) {
1251 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1253 next = p + cilen - 2;
1257 if ((go->neg_mru && go->mru != DEFMRU)
1258 || no.neg_mru || cilen != CILEN_SHORT)
1260 GETSHORT(cishort, p);
1261 if (cishort < DEFMRU) {
1267 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1268 || no.neg_asyncmap || cilen != CILEN_LONG)
1272 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap ||
1273 go->neg_eap || no.neg_eap)
1276 case CI_MAGICNUMBER:
1277 if (go->neg_magicnumber || no.neg_magicnumber ||
1278 cilen != CILEN_LONG)
1281 case CI_PCOMPRESSION:
1282 if (go->neg_pcompression || no.neg_pcompression
1283 || cilen != CILEN_VOID)
1286 case CI_ACCOMPRESSION:
1287 if (go->neg_accompression || no.neg_accompression
1288 || cilen != CILEN_VOID)
1292 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1296 if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT)
1300 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1305 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1313 * OK, the Nak is good. Now we can update state.
1314 * If there are any options left we ignore them.
1316 if (f->state != OPENED) {
1318 if (++try.numloops >= lcp_loopbackfail) {
1319 notice("Serial line is looped back.");
1320 status = EXIT_LOOPBACK;
1321 lcp_close(f->unit, "Loopback detected");
1331 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1337 * lcp_rejci - Peer has Rejected some of our CIs.
1338 * This should not modify any state if the Reject is bad
1339 * or if LCP is in the OPENED state.
1342 * 0 - Reject was bad.
1343 * 1 - Reject was good.
1346 lcp_rejci(f, p, len)
1351 lcp_options *go = &lcp_gotoptions[f->unit];
1355 lcp_options try; /* options to request next time */
1360 * Any Rejected CIs must be in exactly the same order that we sent.
1361 * Check packet length and CI length at each step.
1362 * If we find any deviations, then this packet is bad.
1364 #define REJCIVOID(opt, neg) \
1366 len >= CILEN_VOID && \
1367 p[1] == CILEN_VOID && \
1369 len -= CILEN_VOID; \
1370 INCPTR(CILEN_VOID, p); \
1373 #define REJCISHORT(opt, neg, val) \
1375 len >= CILEN_SHORT && \
1376 p[1] == CILEN_SHORT && \
1378 len -= CILEN_SHORT; \
1380 GETSHORT(cishort, p); \
1381 /* Check rejected value. */ \
1382 if (cishort != val) \
1386 #define REJCICHAP(opt, neg, val) \
1388 len >= CILEN_CHAP && \
1389 p[1] == CILEN_CHAP && \
1391 len -= CILEN_CHAP; \
1393 GETSHORT(cishort, p); \
1394 GETCHAR(cichar, p); \
1395 /* Check rejected value. */ \
1396 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1399 try.neg_eap = try.neg_upap = 0; \
1401 #define REJCILONG(opt, neg, val) \
1403 len >= CILEN_LONG && \
1404 p[1] == CILEN_LONG && \
1406 len -= CILEN_LONG; \
1408 GETLONG(cilong, p); \
1409 /* Check rejected value. */ \
1410 if (cilong != val) \
1414 #define REJCILQR(opt, neg, val) \
1416 len >= CILEN_LQR && \
1417 p[1] == CILEN_LQR && \
1421 GETSHORT(cishort, p); \
1422 GETLONG(cilong, p); \
1423 /* Check rejected value. */ \
1424 if (cishort != PPP_LQR || cilong != val) \
1428 #define REJCICBCP(opt, neg, val) \
1430 len >= CILEN_CBCP && \
1431 p[1] == CILEN_CBCP && \
1433 len -= CILEN_CBCP; \
1435 GETCHAR(cichar, p); \
1436 /* Check rejected value. */ \
1437 if (cichar != val) \
1441 #define REJCIENDP(opt, neg, class, val, vlen) \
1443 len >= CILEN_CHAR + vlen && \
1445 p[1] == CILEN_CHAR + vlen) { \
1447 len -= CILEN_CHAR + vlen; \
1449 GETCHAR(cichar, p); \
1450 if (cichar != class) \
1452 for (i = 0; i < vlen; ++i) { \
1453 GETCHAR(cichar, p); \
1454 if (cichar != val[i]) \
1460 REJCISHORT(CI_MRU, neg_mru, go->mru);
1461 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1462 REJCISHORT(CI_AUTHTYPE, neg_eap, PPP_EAP);
1464 REJCICHAP(CI_AUTHTYPE, neg_chap, go->chap_mdtype);
1465 if (!go->neg_chap) {
1466 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1469 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1470 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1471 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1472 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1473 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1474 REJCISHORT(CI_MRRU, neg_mrru, go->mrru);
1475 REJCIVOID(CI_SSNHF, neg_ssnhf);
1476 REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class,
1477 go->endpoint.value, go->endpoint.length);
1480 * If there are any remaining CIs, then this packet is bad.
1485 * Now we can update state.
1487 if (f->state != OPENED)
1492 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1498 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1500 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1501 * appropriately. If reject_if_disagree is non-zero, doesn't return
1502 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1505 lcp_reqci(f, inp, lenp, reject_if_disagree)
1507 u_char *inp; /* Requested CIs */
1508 int *lenp; /* Length of requested CIs */
1509 int reject_if_disagree;
1511 lcp_options *go = &lcp_gotoptions[f->unit];
1512 lcp_options *ho = &lcp_hisoptions[f->unit];
1513 lcp_options *ao = &lcp_allowoptions[f->unit];
1514 u_char *cip, *next; /* Pointer to current and next CIs */
1515 int cilen, citype, cichar; /* Parsed len, type, char value */
1516 u_short cishort; /* Parsed short value */
1517 u_int32_t cilong; /* Parse long value */
1518 int rc = CONFACK; /* Final packet return code */
1519 int orc; /* Individual option return code */
1520 u_char *p; /* Pointer to next char to parse */
1521 u_char *rejp; /* Pointer to next char in reject frame */
1522 u_char *nakp; /* Pointer to next char in Nak frame */
1523 int l = *lenp; /* Length left */
1526 * Reset all his options.
1528 BZERO(ho, sizeof(*ho));
1531 * Process all his options.
1537 orc = CONFACK; /* Assume success */
1538 cip = p = next; /* Remember begining of CI */
1539 if (l < 2 || /* Not enough data for CI header or */
1540 p[1] < 2 || /* CI length too small or */
1541 p[1] > l) { /* CI length too big? */
1542 LCPDEBUG(("lcp_reqci: bad CI length!"));
1543 orc = CONFREJ; /* Reject bad CI */
1544 cilen = l; /* Reject till end of packet */
1545 l = 0; /* Don't loop again */
1549 GETCHAR(citype, p); /* Parse CI type */
1550 GETCHAR(cilen, p); /* Parse CI length */
1551 l -= cilen; /* Adjust remaining length */
1552 next += cilen; /* Step to next CI */
1554 switch (citype) { /* Check CI type */
1556 if (!ao->neg_mru || /* Allow option? */
1557 cilen != CILEN_SHORT) { /* Check CI length */
1558 orc = CONFREJ; /* Reject CI */
1561 GETSHORT(cishort, p); /* Parse MRU */
1564 * He must be able to receive at least our minimum.
1565 * No need to check a maximum. If he sends a large number,
1566 * we'll just ignore it.
1568 if (cishort < MINMRU) {
1569 orc = CONFNAK; /* Nak CI */
1570 PUTCHAR(CI_MRU, nakp);
1571 PUTCHAR(CILEN_SHORT, nakp);
1572 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1575 ho->neg_mru = 1; /* Remember he sent MRU */
1576 ho->mru = cishort; /* And remember value */
1580 if (!ao->neg_asyncmap ||
1581 cilen != CILEN_LONG) {
1588 * Asyncmap must have set at least the bits
1589 * which are set in lcp_allowoptions[unit].asyncmap.
1591 if ((ao->asyncmap & ~cilong) != 0) {
1593 PUTCHAR(CI_ASYNCMAP, nakp);
1594 PUTCHAR(CILEN_LONG, nakp);
1595 PUTLONG(ao->asyncmap | cilong, nakp);
1598 ho->neg_asyncmap = 1;
1599 ho->asyncmap = cilong;
1603 if (cilen < CILEN_SHORT ||
1604 !(ao->neg_upap || ao->neg_chap || ao->neg_eap)) {
1606 * Reject the option if we're not willing to authenticate.
1608 dbglog("No auth is possible");
1612 GETSHORT(cishort, p);
1615 * Authtype must be PAP, CHAP, or EAP.
1617 * Note: if more than one of ao->neg_upap, ao->neg_chap, and
1618 * ao->neg_eap are set, and the peer sends a Configure-Request
1619 * with two or more authenticate-protocol requests, then we will
1620 * reject the second request.
1621 * Whether we end up doing CHAP, UPAP, or EAP depends then on
1622 * the ordering of the CIs in the peer's Configure-Request.
1625 if (cishort == PPP_PAP) {
1626 /* we've already accepted CHAP or EAP */
1627 if (ho->neg_chap || ho->neg_eap ||
1628 cilen != CILEN_SHORT) {
1629 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1633 if (!ao->neg_upap) { /* we don't want to do PAP */
1634 orc = CONFNAK; /* NAK it and suggest CHAP or EAP */
1635 PUTCHAR(CI_AUTHTYPE, nakp);
1637 PUTCHAR(CILEN_SHORT, nakp);
1638 PUTSHORT(PPP_EAP, nakp);
1640 PUTCHAR(CILEN_CHAP, nakp);
1641 PUTSHORT(PPP_CHAP, nakp);
1642 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1649 if (cishort == PPP_CHAP) {
1650 /* we've already accepted PAP or EAP */
1651 if (ho->neg_upap || ho->neg_eap ||
1652 cilen != CILEN_CHAP) {
1653 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1657 if (!ao->neg_chap) { /* we don't want to do CHAP */
1658 orc = CONFNAK; /* NAK it and suggest EAP or PAP */
1659 PUTCHAR(CI_AUTHTYPE, nakp);
1660 PUTCHAR(CILEN_SHORT, nakp);
1662 PUTSHORT(PPP_EAP, nakp);
1664 PUTSHORT(PPP_PAP, nakp);
1668 GETCHAR(cichar, p); /* get digest type */
1669 if (!(CHAP_CANDIGEST(ao->chap_mdtype, cichar))) {
1671 * We can't/won't do the requested type,
1672 * suggest something else.
1675 PUTCHAR(CI_AUTHTYPE, nakp);
1676 PUTCHAR(CILEN_CHAP, nakp);
1677 PUTSHORT(PPP_CHAP, nakp);
1678 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1681 ho->chap_mdtype = CHAP_MDTYPE_D(cichar); /* save md type */
1685 if (cishort == PPP_EAP) {
1686 /* we've already accepted CHAP or PAP */
1687 if (ho->neg_chap || ho->neg_upap || cilen != CILEN_SHORT) {
1688 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE EAP, rejecting..."));
1692 if (!ao->neg_eap) { /* we don't want to do EAP */
1693 orc = CONFNAK; /* NAK it and suggest CHAP or PAP */
1694 PUTCHAR(CI_AUTHTYPE, nakp);
1696 PUTCHAR(CILEN_CHAP, nakp);
1697 PUTSHORT(PPP_CHAP, nakp);
1698 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1700 PUTCHAR(CILEN_SHORT, nakp);
1701 PUTSHORT(PPP_PAP, nakp);
1710 * We don't recognize the protocol they're asking for.
1711 * Nak it with something we're willing to do.
1712 * (At this point we know ao->neg_upap || ao->neg_chap ||
1716 PUTCHAR(CI_AUTHTYPE, nakp);
1718 PUTCHAR(CILEN_SHORT, nakp);
1719 PUTSHORT(PPP_EAP, nakp);
1720 } else if (ao->neg_chap) {
1721 PUTCHAR(CILEN_CHAP, nakp);
1722 PUTSHORT(PPP_CHAP, nakp);
1723 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1725 PUTCHAR(CILEN_SHORT, nakp);
1726 PUTSHORT(PPP_PAP, nakp);
1732 cilen != CILEN_LQR) {
1737 GETSHORT(cishort, p);
1741 * Check the protocol and the reporting period.
1742 * XXX When should we Nak this, and what with?
1744 if (cishort != PPP_LQR) {
1746 PUTCHAR(CI_QUALITY, nakp);
1747 PUTCHAR(CILEN_LQR, nakp);
1748 PUTSHORT(PPP_LQR, nakp);
1749 PUTLONG(ao->lqr_period, nakp);
1754 case CI_MAGICNUMBER:
1755 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1756 cilen != CILEN_LONG) {
1763 * He must have a different magic number.
1765 if (go->neg_magicnumber &&
1766 cilong == go->magicnumber) {
1767 cilong = magic(); /* Don't put magic() inside macro! */
1769 PUTCHAR(CI_MAGICNUMBER, nakp);
1770 PUTCHAR(CILEN_LONG, nakp);
1771 PUTLONG(cilong, nakp);
1774 ho->neg_magicnumber = 1;
1775 ho->magicnumber = cilong;
1779 case CI_PCOMPRESSION:
1780 if (!ao->neg_pcompression ||
1781 cilen != CILEN_VOID) {
1785 ho->neg_pcompression = 1;
1788 case CI_ACCOMPRESSION:
1789 if (!ao->neg_accompression ||
1790 cilen != CILEN_VOID) {
1794 ho->neg_accompression = 1;
1798 if (!ao->neg_mrru || !multilink ||
1799 cilen != CILEN_SHORT) {
1804 GETSHORT(cishort, p);
1805 /* possibly should insist on a minimum/maximum MRRU here */
1811 if (!ao->neg_ssnhf || !multilink ||
1812 cilen != CILEN_VOID) {
1820 if (!ao->neg_endpoint ||
1821 cilen < CILEN_CHAR ||
1822 cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1827 cilen -= CILEN_CHAR;
1828 ho->neg_endpoint = 1;
1829 ho->endpoint.class = cichar;
1830 ho->endpoint.length = cilen;
1831 BCOPY(p, ho->endpoint.value, cilen);
1836 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1842 if (orc == CONFACK && /* Good CI */
1843 rc != CONFACK) /* but prior CI wasnt? */
1844 continue; /* Don't send this one */
1846 if (orc == CONFNAK) { /* Nak this CI? */
1847 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1848 && citype != CI_MAGICNUMBER) {
1849 orc = CONFREJ; /* Get tough if so */
1851 if (rc == CONFREJ) /* Rejecting prior CI? */
1852 continue; /* Don't send this one */
1856 if (orc == CONFREJ) { /* Reject this CI */
1858 if (cip != rejp) /* Need to move rejected CI? */
1859 BCOPY(cip, rejp, cilen); /* Move it */
1860 INCPTR(cilen, rejp); /* Update output pointer */
1865 * If we wanted to send additional NAKs (for unsent CIs), the
1866 * code would go here. The extra NAKs would go at *nakp.
1867 * At present there are no cases where we want to ask the
1868 * peer to negotiate an option.
1877 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1879 *lenp = nakp - nak_buffer;
1880 BCOPY(nak_buffer, inp, *lenp);
1887 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1888 return (rc); /* Return final code */
1893 * lcp_up - LCP has come UP.
1899 lcp_options *wo = &lcp_wantoptions[f->unit];
1900 lcp_options *ho = &lcp_hisoptions[f->unit];
1901 lcp_options *go = &lcp_gotoptions[f->unit];
1902 lcp_options *ao = &lcp_allowoptions[f->unit];
1905 if (!go->neg_magicnumber)
1906 go->magicnumber = 0;
1907 if (!ho->neg_magicnumber)
1908 ho->magicnumber = 0;
1911 * Set our MTU to the smaller of the MTU we wanted and
1912 * the MRU our peer wanted. If we negotiated an MRU,
1913 * set our MRU to the larger of value we wanted and
1914 * the value we got in the negotiation.
1915 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1916 * the interface MTU is set to the lowest of that, the
1917 * MTU we want to use, and our link MRU.
1919 mtu = ho->neg_mru? ho->mru: PPP_MRU;
1920 mru = go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU;
1921 #ifdef HAVE_MULTILINK
1922 if (!(multilink && go->neg_mrru && ho->neg_mrru))
1923 #endif /* HAVE_MULTILINK */
1924 netif_set_mtu(f->unit, MIN(MIN(mtu, mru), ao->mru));
1925 ppp_send_config(f->unit, mtu,
1926 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1927 ho->neg_pcompression, ho->neg_accompression);
1928 ppp_recv_config(f->unit, mru,
1929 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
1930 go->neg_pcompression, go->neg_accompression);
1933 peer_mru[f->unit] = ho->mru;
1935 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1937 link_established(f->unit);
1942 * lcp_down - LCP has gone DOWN.
1944 * Alert other protocols.
1950 lcp_options *go = &lcp_gotoptions[f->unit];
1952 lcp_echo_lowerdown(f->unit);
1956 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1957 ppp_recv_config(f->unit, PPP_MRU,
1958 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1959 go->neg_pcompression, go->neg_accompression);
1960 peer_mru[f->unit] = PPP_MRU;
1965 * lcp_starting - LCP needs the lower layer up.
1971 link_required(f->unit);
1976 * lcp_finished - LCP has finished with the lower layer.
1982 link_terminated(f->unit);
1987 * lcp_printpkt - print the contents of an LCP packet.
1989 static char *lcp_codenames[] = {
1990 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1991 "TermReq", "TermAck", "CodeRej", "ProtRej",
1992 "EchoReq", "EchoRep", "DiscReq", "Ident",
1997 lcp_printpkt(p, plen, printer, arg)
2000 void (*printer) __P((void *, char *, ...));
2003 int code, id, len, olen, i;
2004 u_char *pstart, *optend;
2008 if (plen < HEADERLEN)
2014 if (len < HEADERLEN || len > plen)
2017 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
2018 printer(arg, " %s", lcp_codenames[code-1]);
2020 printer(arg, " code=0x%x", code);
2021 printer(arg, " id=0x%x", id);
2028 /* print option list */
2033 if (olen < 2 || olen > len) {
2041 if (olen == CILEN_SHORT) {
2043 GETSHORT(cishort, p);
2044 printer(arg, "mru %d", cishort);
2048 if (olen == CILEN_LONG) {
2051 printer(arg, "asyncmap 0x%x", cilong);
2055 if (olen >= CILEN_SHORT) {
2057 printer(arg, "auth ");
2058 GETSHORT(cishort, p);
2061 printer(arg, "pap");
2064 printer(arg, "chap");
2068 printer(arg, " MD5");
2071 case CHAP_MICROSOFT:
2072 printer(arg, " MS");
2076 case CHAP_MICROSOFT_V2:
2077 printer(arg, " MS-v2");
2084 printer(arg, "eap");
2087 printer(arg, "0x%x", cishort);
2092 if (olen >= CILEN_SHORT) {
2094 printer(arg, "quality ");
2095 GETSHORT(cishort, p);
2098 printer(arg, "lqr");
2101 printer(arg, "0x%x", cishort);
2106 if (olen >= CILEN_CHAR) {
2108 printer(arg, "callback ");
2109 GETCHAR(cishort, p);
2112 printer(arg, "CBCP");
2115 printer(arg, "0x%x", cishort);
2119 case CI_MAGICNUMBER:
2120 if (olen == CILEN_LONG) {
2123 printer(arg, "magic 0x%x", cilong);
2126 case CI_PCOMPRESSION:
2127 if (olen == CILEN_VOID) {
2129 printer(arg, "pcomp");
2132 case CI_ACCOMPRESSION:
2133 if (olen == CILEN_VOID) {
2135 printer(arg, "accomp");
2139 if (olen == CILEN_SHORT) {
2141 GETSHORT(cishort, p);
2142 printer(arg, "mrru %d", cishort);
2146 if (olen == CILEN_VOID) {
2148 printer(arg, "ssnhf");
2152 #ifdef HAVE_MULTILINK
2153 if (olen >= CILEN_CHAR) {
2156 GETCHAR(epd.class, p);
2157 epd.length = olen - CILEN_CHAR;
2158 if (epd.length > MAX_ENDP_LEN)
2159 epd.length = MAX_ENDP_LEN;
2160 if (epd.length > 0) {
2161 BCOPY(p, epd.value, epd.length);
2164 printer(arg, "endpoint [%s]", epdisc_to_str(&epd));
2167 printer(arg, "endpoint");
2171 while (p < optend) {
2173 printer(arg, " %.2x", code);
2181 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2183 print_string((char *)p, len, printer, arg);
2194 printer(arg, " magic=0x%x", cilong);
2203 printer(arg, " magic=0x%x", cilong);
2206 if (code == TIMEREM) {
2210 printer(arg, " seconds=%u", cilong);
2215 print_string((char *)p, len, printer, arg);
2222 /* print the rest of the bytes in the packet */
2223 for (i = 0; i < len && i < 32; ++i) {
2225 printer(arg, " %.2x", code);
2228 printer(arg, " ...");
2236 * Time to shut down the link because there is nothing out there.
2240 void LcpLinkFailure (f)
2243 if (f->state == OPENED) {
2244 info("No response to %d echo-requests", lcp_echos_pending);
2245 notice("Serial link appears to be disconnected.");
2246 status = EXIT_PEER_DEAD;
2247 lcp_close(f->unit, "Peer not responding");
2252 * Timer expired for the LCP echo requests from this process.
2259 LcpSendEchoRequest (f);
2260 if (f->state != OPENED)
2264 * Start the timer for the next interval.
2266 if (lcp_echo_timer_running)
2267 warn("assertion lcp_echo_timer_running==0 failed");
2268 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2269 lcp_echo_timer_running = 1;
2273 * LcpEchoTimeout - Timer expired on the LCP echo
2277 LcpEchoTimeout (arg)
2280 if (lcp_echo_timer_running != 0) {
2281 lcp_echo_timer_running = 0;
2282 LcpEchoCheck ((fsm *) arg);
2287 * LcpEchoReply - LCP has received a reply to the echo
2291 lcp_received_echo_reply (f, id, inp, len)
2299 /* Check the magic number - don't count replies from ourselves. */
2301 dbglog("lcp: received short Echo-Reply, length %d", len);
2304 GETLONG(magic, inp);
2305 if (lcp_gotoptions[f->unit].neg_magicnumber
2306 && magic == lcp_gotoptions[f->unit].magicnumber) {
2307 warn("appear to have received our own echo-reply!");
2311 /* Reset the number of outstanding echo frames */
2312 lcp_echos_pending = 0;
2316 * LcpSendEchoRequest - Send an echo request frame to the peer
2320 LcpSendEchoRequest (f)
2323 u_int32_t lcp_magic;
2324 u_char pkt[4], *pktp;
2327 * Detect the failure of the peer at this point.
2329 if (lcp_echo_fails != 0) {
2330 if (lcp_echos_pending >= lcp_echo_fails) {
2332 lcp_echos_pending = 0;
2337 * If adaptive echos have been enabled, only send the echo request if
2338 * no traffic was received since the last one.
2340 if (lcp_echo_adaptive) {
2341 static unsigned int last_pkts_in = 0;
2343 update_link_stats(f->unit);
2344 link_stats_valid = 0;
2346 if (link_stats.pkts_in != last_pkts_in) {
2347 last_pkts_in = link_stats.pkts_in;
2353 * Make and send the echo request frame.
2355 if (f->state == OPENED) {
2356 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2358 PUTLONG(lcp_magic, pktp);
2359 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2360 ++lcp_echos_pending;
2365 * lcp_echo_lowerup - Start the timer for the LCP frame
2369 lcp_echo_lowerup (unit)
2372 fsm *f = &lcp_fsm[unit];
2374 /* Clear the parameters for generating echo frames */
2375 lcp_echos_pending = 0;
2376 lcp_echo_number = 0;
2377 lcp_echo_timer_running = 0;
2379 /* If a timeout interval is specified then start the timer */
2380 if (lcp_echo_interval != 0)
2385 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2389 lcp_echo_lowerdown (unit)
2392 fsm *f = &lcp_fsm[unit];
2394 if (lcp_echo_timer_running != 0) {
2395 UNTIMEOUT (LcpEchoTimeout, f);
2396 lcp_echo_timer_running = 0;