2 * lcp.c - PPP Link Control Protocol.
4 * Copyright (c) 1989 Carnegie Mellon University.
7 * Redistribution and use in source and binary forms are permitted
8 * provided that the above copyright notice and this paragraph are
9 * duplicated in all such forms and that any documentation,
10 * advertising materials, and other materials related to such
11 * distribution and use acknowledge that the software was developed
12 * by Carnegie Mellon University. The name of the
13 * University may not be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 #define RCSID "$Id: lcp.c,v 1.63 2002/11/02 19:48:12 carlsonj Exp $"
36 static const char rcsid[] = RCSID;
39 * When the link comes up we want to be able to wait for a short while,
40 * or until seeing some input from the peer, before starting to send
41 * configure-requests. We do this by delaying the fsm_lowerup call.
43 /* steal a bit in fsm flags word */
44 #define DELAYED_UP 0x100
46 static void lcp_delayed_up __P((void *));
49 * LCP-related command-line options.
51 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
52 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
53 bool lax_recv = 0; /* accept control chars in asyncmap */
54 bool noendpoint = 0; /* don't send/accept endpoint discriminator */
56 static int noopt __P((char **));
59 static int setendpoint __P((char **));
60 static void printendpoint __P((option_t *, void (*)(void *, char *, ...),
62 #endif /* HAVE_MULTILINK */
64 static option_t lcp_option_list[] = {
66 { "-all", o_special_noarg, (void *)noopt,
67 "Don't request/allow any LCP options" },
69 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
70 "Disable address/control compression",
71 OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
72 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
73 "Disable address/control compression",
74 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_accompression },
76 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
77 "Set asyncmap (for received packets)",
78 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
79 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
80 "Set asyncmap (for received packets)",
81 OPT_ALIAS | OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
82 { "default-asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
83 "Disable asyncmap negotiation",
84 OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
85 &lcp_allowoptions[0].neg_asyncmap },
86 { "-am", o_uint32, &lcp_wantoptions[0].asyncmap,
87 "Disable asyncmap negotiation",
88 OPT_ALIAS | OPT_OR | OPT_NOARG | OPT_VAL(~0U) | OPT_A2CLR,
89 &lcp_allowoptions[0].neg_asyncmap },
91 { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
92 "Disable magic number negotiation (looped-back line detection)",
93 OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
94 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
95 "Disable magic number negotiation (looped-back line detection)",
96 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_magicnumber },
98 { "mru", o_int, &lcp_wantoptions[0].mru,
99 "Set MRU (maximum received packet size) for negotiation",
100 OPT_PRIO, &lcp_wantoptions[0].neg_mru },
101 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
102 "Disable MRU negotiation (use default 1500)",
103 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
104 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
105 "Disable MRU negotiation (use default 1500)",
106 OPT_ALIAS | OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_mru },
108 { "mtu", o_int, &lcp_allowoptions[0].mru,
109 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
111 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
112 "Disable protocol field compression",
113 OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
114 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
115 "Disable protocol field compression",
116 OPT_ALIAS | OPT_A2CLR, &lcp_allowoptions[0].neg_pcompression },
118 { "passive", o_bool, &lcp_wantoptions[0].passive,
119 "Set passive mode", 1 },
120 { "-p", o_bool, &lcp_wantoptions[0].passive,
121 "Set passive mode", OPT_ALIAS | 1 },
123 { "silent", o_bool, &lcp_wantoptions[0].silent,
124 "Set silent mode", 1 },
126 { "lcp-echo-failure", o_int, &lcp_echo_fails,
127 "Set number of consecutive echo failures to indicate link failure",
129 { "lcp-echo-interval", o_int, &lcp_echo_interval,
130 "Set time in seconds between LCP echo requests", OPT_PRIO },
131 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
132 "Set time in seconds between LCP retransmissions", OPT_PRIO },
133 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
134 "Set maximum number of LCP terminate-request transmissions", OPT_PRIO },
135 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
136 "Set maximum number of LCP configure-request transmissions", OPT_PRIO },
137 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
138 "Set limit on number of LCP configure-naks", OPT_PRIO },
140 { "receive-all", o_bool, &lax_recv,
141 "Accept all received control characters", 1 },
143 #ifdef HAVE_MULTILINK
144 { "mrru", o_int, &lcp_wantoptions[0].mrru,
145 "Maximum received packet size for multilink bundle",
146 OPT_PRIO, &lcp_wantoptions[0].neg_mrru },
148 { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
149 "Use short sequence numbers in multilink headers",
150 OPT_PRIO | 1, &lcp_allowoptions[0].neg_ssnhf },
151 { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
152 "Don't use short sequence numbers in multilink headers",
153 OPT_PRIOSUB | OPT_A2CLR, &lcp_allowoptions[0].neg_ssnhf },
155 { "endpoint", o_special, (void *) setendpoint,
156 "Endpoint discriminator for multilink",
157 OPT_PRIO | OPT_A2PRINTER, (void *) printendpoint },
158 #endif /* HAVE_MULTILINK */
160 { "noendpoint", o_bool, &noendpoint,
161 "Don't send or accept multilink endpoint discriminator", 1 },
167 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
168 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
169 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
170 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
171 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
173 static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
174 static int lcp_echo_number = 0; /* ID number of next echo frame */
175 static int lcp_echo_timer_running = 0; /* set if a timer is running */
177 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
180 * Callbacks for fsm code. (CI = Configuration Information)
182 static void lcp_resetci __P((fsm *)); /* Reset our CI */
183 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
184 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
185 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
186 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
187 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
188 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
189 static void lcp_up __P((fsm *)); /* We're UP */
190 static void lcp_down __P((fsm *)); /* We're DOWN */
191 static void lcp_starting __P((fsm *)); /* We need lower layer up */
192 static void lcp_finished __P((fsm *)); /* We need lower layer down */
193 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
194 static void lcp_rprotrej __P((fsm *, u_char *, int));
197 * routines to send LCP echos to peer
200 static void lcp_echo_lowerup __P((int));
201 static void lcp_echo_lowerdown __P((int));
202 static void LcpEchoTimeout __P((void *));
203 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
204 static void LcpSendEchoRequest __P((fsm *));
205 static void LcpLinkFailure __P((fsm *));
206 static void LcpEchoCheck __P((fsm *));
208 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
209 lcp_resetci, /* Reset our Configuration Information */
210 lcp_cilen, /* Length of our Configuration Information */
211 lcp_addci, /* Add our Configuration Information */
212 lcp_ackci, /* ACK our Configuration Information */
213 lcp_nakci, /* NAK our Configuration Information */
214 lcp_rejci, /* Reject our Configuration Information */
215 lcp_reqci, /* Request peer's Configuration Information */
216 lcp_up, /* Called when fsm reaches OPENED state */
217 lcp_down, /* Called when fsm leaves OPENED state */
218 lcp_starting, /* Called when we want the lower layer up */
219 lcp_finished, /* Called when we want the lower layer down */
220 NULL, /* Called when Protocol-Reject received */
221 NULL, /* Retransmission is necessary */
222 lcp_extcode, /* Called to handle LCP-specific codes */
223 "LCP" /* String name of protocol */
227 * Protocol entry points.
228 * Some of these are called directly.
231 static void lcp_init __P((int));
232 static void lcp_input __P((int, u_char *, int));
233 static void lcp_protrej __P((int));
234 static int lcp_printpkt __P((u_char *, int,
235 void (*) __P((void *, char *, ...)), void *));
237 struct protent lcp_protent = {
257 int lcp_loopbackfail = DEFLOOPBACKFAIL;
260 * Length of each type of configuration option (in octets)
264 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
265 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
266 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
267 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
270 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
271 (x) == CONFNAK ? "NAK" : "REJ")
274 * noopt - Disable all options (why?).
280 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
281 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
286 #ifdef HAVE_MULTILINK
291 if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) {
292 lcp_wantoptions[0].neg_endpoint = 1;
295 option_error("Can't parse '%s' as an endpoint discriminator", *argv);
300 printendpoint(opt, printer, arg)
302 void (*printer) __P((void *, char *, ...));
305 printer(arg, "%s", epdisc_to_str(&lcp_wantoptions[0].endpoint));
307 #endif /* HAVE_MULTILINK */
310 * lcp_init - Initialize LCP.
316 fsm *f = &lcp_fsm[unit];
317 lcp_options *wo = &lcp_wantoptions[unit];
318 lcp_options *ao = &lcp_allowoptions[unit];
321 f->protocol = PPP_LCP;
322 f->callbacks = &lcp_callbacks;
326 BZERO(wo, sizeof(*wo));
329 wo->neg_asyncmap = 1;
330 wo->neg_magicnumber = 1;
331 wo->neg_pcompression = 1;
332 wo->neg_accompression = 1;
334 BZERO(ao, sizeof(*ao));
337 ao->neg_asyncmap = 1;
339 ao->chap_mdtype = MDTYPE_ALL;
342 ao->neg_magicnumber = 1;
343 ao->neg_pcompression = 1;
344 ao->neg_accompression = 1;
348 ao->neg_endpoint = 1;
353 * lcp_open - LCP is allowed to come up.
359 fsm *f = &lcp_fsm[unit];
360 lcp_options *wo = &lcp_wantoptions[unit];
362 f->flags &= ~(OPT_PASSIVE | OPT_SILENT);
364 f->flags |= OPT_PASSIVE;
366 f->flags |= OPT_SILENT;
372 * lcp_close - Take LCP down.
375 lcp_close(unit, reason)
379 fsm *f = &lcp_fsm[unit];
381 if (phase != PHASE_DEAD)
382 new_phase(PHASE_TERMINATE);
383 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
385 * This action is not strictly according to the FSM in RFC1548,
386 * but it does mean that the program terminates if you do a
387 * lcp_close() in passive/silent mode when a connection hasn't
394 fsm_close(&lcp_fsm[unit], reason);
399 * lcp_lowerup - The lower layer is up.
405 lcp_options *wo = &lcp_wantoptions[unit];
406 fsm *f = &lcp_fsm[unit];
409 * Don't use A/C or protocol compression on transmission,
410 * but accept A/C and protocol compressed packets
411 * if we are going to ask for A/C and protocol compression.
413 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
414 ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
415 wo->neg_pcompression, wo->neg_accompression);
416 peer_mru[unit] = PPP_MRU;
418 if (listen_time != 0) {
419 f->flags |= DELAYED_UP;
420 timeout(lcp_delayed_up, f, 0, listen_time * 1000);
427 * lcp_lowerdown - The lower layer is down.
433 fsm *f = &lcp_fsm[unit];
435 if (f->flags & DELAYED_UP)
436 f->flags &= ~DELAYED_UP;
438 fsm_lowerdown(&lcp_fsm[unit]);
443 * lcp_delayed_up - Bring the lower layer up now.
451 if (f->flags & DELAYED_UP) {
452 f->flags &= ~DELAYED_UP;
459 * lcp_input - Input LCP packet.
462 lcp_input(unit, p, len)
467 fsm *f = &lcp_fsm[unit];
469 if (f->flags & DELAYED_UP) {
470 f->flags &= ~DELAYED_UP;
473 fsm_input(f, p, len);
478 * lcp_extcode - Handle a LCP-specific code.
481 lcp_extcode(f, code, id, inp, len)
491 lcp_rprotrej(f, inp, len);
495 if (f->state != OPENED)
498 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
499 fsm_sdata(f, ECHOREP, id, inp, len);
503 lcp_received_echo_reply(f, id, inp, len);
517 * lcp_rprotrej - Receive an Protocol-Reject.
519 * Figure out which protocol is rejected and inform it.
522 lcp_rprotrej(f, inp, len)
528 struct protent *protp;
532 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
539 * Protocol-Reject packets received in any state other than the LCP
540 * OPENED state SHOULD be silently discarded.
542 if( f->state != OPENED ){
543 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
548 * Upcall the proper Protocol-Reject routine.
550 for (i = 0; (protp = protocols[i]) != NULL; ++i)
551 if (protp->protocol == prot && protp->enabled_flag) {
552 (*protp->protrej)(f->unit);
556 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
561 * lcp_protrej - A Protocol-Reject was received.
571 error("Received Protocol-Reject for LCP!");
572 fsm_protreject(&lcp_fsm[unit]);
577 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
580 lcp_sprotrej(unit, p, len)
586 * Send back the protocol and the information field of the
587 * rejected packet. We only get here if LCP is in the OPENED state.
592 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
598 * lcp_resetci - Reset our CI.
604 lcp_options *wo = &lcp_wantoptions[f->unit];
605 lcp_options *go = &lcp_gotoptions[f->unit];
606 lcp_options *ao = &lcp_allowoptions[f->unit];
608 wo->magicnumber = magic();
614 go->neg_endpoint = 0;
617 ao->neg_endpoint = 0;
618 peer_mru[f->unit] = PPP_MRU;
624 * lcp_cilen - Return length of our CI.
630 lcp_options *go = &lcp_gotoptions[f->unit];
632 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
633 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
634 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
635 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
636 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
637 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
639 * NB: we only ask for one of CHAP, UPAP, or EAP, even if we will
640 * accept more than one. We prefer EAP first, then CHAP, then
643 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
644 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
645 LENCISHORT(go->neg_eap) +
646 LENCICHAP(!go->neg_eap && go->neg_chap) +
647 LENCISHORT(!go->neg_eap && !go->neg_chap && go->neg_upap) +
648 LENCILQR(go->neg_lqr) +
649 LENCICBCP(go->neg_cbcp) +
650 LENCILONG(go->neg_magicnumber) +
651 LENCIVOID(go->neg_pcompression) +
652 LENCIVOID(go->neg_accompression) +
653 LENCISHORT(go->neg_mrru) +
654 LENCIVOID(go->neg_ssnhf) +
655 (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
660 * lcp_addci - Add our desired CIs to a packet.
663 lcp_addci(f, ucp, lenp)
668 lcp_options *go = &lcp_gotoptions[f->unit];
669 u_char *start_ucp = ucp;
671 #define ADDCIVOID(opt, neg) \
674 PUTCHAR(CILEN_VOID, ucp); \
676 #define ADDCISHORT(opt, neg, val) \
679 PUTCHAR(CILEN_SHORT, ucp); \
680 PUTSHORT(val, ucp); \
682 #define ADDCICHAP(opt, neg, val) \
684 PUTCHAR((opt), ucp); \
685 PUTCHAR(CILEN_CHAP, ucp); \
686 PUTSHORT(PPP_CHAP, ucp); \
687 PUTCHAR((CHAP_DIGEST(val)), ucp); \
689 #define ADDCILONG(opt, neg, val) \
692 PUTCHAR(CILEN_LONG, ucp); \
695 #define ADDCILQR(opt, neg, val) \
698 PUTCHAR(CILEN_LQR, ucp); \
699 PUTSHORT(PPP_LQR, ucp); \
702 #define ADDCICHAR(opt, neg, val) \
705 PUTCHAR(CILEN_CHAR, ucp); \
708 #define ADDCIENDP(opt, neg, class, val, len) \
712 PUTCHAR(CILEN_CHAR + len, ucp); \
713 PUTCHAR(class, ucp); \
714 for (i = 0; i < len; ++i) \
715 PUTCHAR(val[i], ucp); \
718 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
719 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
721 ADDCISHORT(CI_AUTHTYPE, go->neg_eap, PPP_EAP);
722 ADDCICHAP(CI_AUTHTYPE, !go->neg_eap && go->neg_chap, go->chap_mdtype);
723 ADDCISHORT(CI_AUTHTYPE, !go->neg_eap && !go->neg_chap && go->neg_upap,
725 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
726 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
727 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
728 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
729 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
730 ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
731 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
732 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
733 go->endpoint.value, go->endpoint.length);
735 if (ucp - start_ucp != *lenp) {
736 /* this should never happen, because peer_mtu should be 1500 */
737 error("Bug in lcp_addci: wrong length");
743 * lcp_ackci - Ack our CIs.
744 * This should not modify any state if the Ack is bad.
756 lcp_options *go = &lcp_gotoptions[f->unit];
757 u_char cilen, citype, cichar;
762 * CIs must be in exactly the same order that we sent.
763 * Check packet length and CI length at each step.
764 * If we find any deviations, then this packet is bad.
766 #define ACKCIVOID(opt, neg) \
768 if ((len -= CILEN_VOID) < 0) \
770 GETCHAR(citype, p); \
772 if (cilen != CILEN_VOID || \
776 #define ACKCISHORT(opt, neg, val) \
778 if ((len -= CILEN_SHORT) < 0) \
780 GETCHAR(citype, p); \
782 if (cilen != CILEN_SHORT || \
785 GETSHORT(cishort, p); \
786 if (cishort != val) \
789 #define ACKCICHAR(opt, neg, val) \
791 if ((len -= CILEN_CHAR) < 0) \
793 GETCHAR(citype, p); \
795 if (cilen != CILEN_CHAR || \
798 GETCHAR(cichar, p); \
802 #define ACKCICHAP(opt, neg, val) \
804 if ((len -= CILEN_CHAP) < 0) \
806 GETCHAR(citype, p); \
808 if (cilen != CILEN_CHAP || \
811 GETSHORT(cishort, p); \
812 if (cishort != PPP_CHAP) \
814 GETCHAR(cichar, p); \
815 if (cichar != (CHAP_DIGEST(val))) \
818 #define ACKCILONG(opt, neg, val) \
820 if ((len -= CILEN_LONG) < 0) \
822 GETCHAR(citype, p); \
824 if (cilen != CILEN_LONG || \
827 GETLONG(cilong, p); \
831 #define ACKCILQR(opt, neg, val) \
833 if ((len -= CILEN_LQR) < 0) \
835 GETCHAR(citype, p); \
837 if (cilen != CILEN_LQR || \
840 GETSHORT(cishort, p); \
841 if (cishort != PPP_LQR) \
843 GETLONG(cilong, p); \
847 #define ACKCIENDP(opt, neg, class, val, vlen) \
850 if ((len -= CILEN_CHAR + vlen) < 0) \
852 GETCHAR(citype, p); \
854 if (cilen != CILEN_CHAR + vlen || \
857 GETCHAR(cichar, p); \
858 if (cichar != class) \
860 for (i = 0; i < vlen; ++i) { \
861 GETCHAR(cichar, p); \
862 if (cichar != val[i]) \
867 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
868 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
870 ACKCISHORT(CI_AUTHTYPE, go->neg_eap, PPP_EAP);
871 ACKCICHAP(CI_AUTHTYPE, !go->neg_eap && go->neg_chap, go->chap_mdtype);
872 ACKCISHORT(CI_AUTHTYPE, !go->neg_eap && !go->neg_chap && go->neg_upap,
874 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
875 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
876 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
877 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
878 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
879 ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
880 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
881 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
882 go->endpoint.value, go->endpoint.length);
885 * If there are any remaining CIs, then this packet is bad.
891 LCPDEBUG(("lcp_acki: received bad Ack!"));
897 * lcp_nakci - Peer has sent a NAK for some of our CIs.
898 * This should not modify any state if the Nak is bad
899 * or if LCP is in the OPENED state.
911 lcp_options *go = &lcp_gotoptions[f->unit];
912 lcp_options *wo = &lcp_wantoptions[f->unit];
913 u_char citype, cichar, *next;
916 lcp_options no; /* options we've seen Naks for */
917 lcp_options try; /* options to request next time */
921 BZERO(&no, sizeof(no));
925 * Any Nak'd CIs must be in exactly the same order that we sent.
926 * Check packet length and CI length at each step.
927 * If we find any deviations, then this packet is bad.
929 #define NAKCIVOID(opt, neg) \
931 len >= CILEN_VOID && \
932 p[1] == CILEN_VOID && \
935 INCPTR(CILEN_VOID, p); \
939 #define NAKCICHAP(opt, neg, code) \
941 len >= CILEN_CHAP && \
942 p[1] == CILEN_CHAP && \
946 GETSHORT(cishort, p); \
947 GETCHAR(cichar, p); \
951 #define NAKCICHAR(opt, neg, code) \
953 len >= CILEN_CHAR && \
954 p[1] == CILEN_CHAR && \
958 GETCHAR(cichar, p); \
962 #define NAKCISHORT(opt, neg, code) \
964 len >= CILEN_SHORT && \
965 p[1] == CILEN_SHORT && \
967 len -= CILEN_SHORT; \
969 GETSHORT(cishort, p); \
973 #define NAKCILONG(opt, neg, code) \
975 len >= CILEN_LONG && \
976 p[1] == CILEN_LONG && \
980 GETLONG(cilong, p); \
984 #define NAKCILQR(opt, neg, code) \
986 len >= CILEN_LQR && \
987 p[1] == CILEN_LQR && \
991 GETSHORT(cishort, p); \
992 GETLONG(cilong, p); \
996 #define NAKCIENDP(opt, neg) \
998 len >= CILEN_CHAR && \
1000 p[1] >= CILEN_CHAR && \
1009 * We don't care if they want to send us smaller packets than
1010 * we want. Therefore, accept any MRU less than what we asked for,
1011 * but then ignore the new value when setting the MRU in the kernel.
1012 * If they send us a bigger MRU than what we asked, accept it, up to
1013 * the limit of the default MRU we'd get if we didn't negotiate.
1015 if (go->neg_mru && go->mru != DEFMRU) {
1016 NAKCISHORT(CI_MRU, neg_mru,
1017 if (cishort <= wo->mru || cishort <= DEFMRU)
1023 * Add any characters they want to our (receive-side) asyncmap.
1025 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
1026 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
1027 try.asyncmap = go->asyncmap | cilong;
1032 * If they've nak'd our authentication-protocol, check whether
1033 * they are proposing a different protocol, or a different
1034 * hash algorithm for CHAP.
1036 if ((go->neg_chap || go->neg_upap || go->neg_eap)
1037 && len >= CILEN_SHORT
1038 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
1041 no.neg_chap = go->neg_chap;
1042 no.neg_upap = go->neg_upap;
1043 no.neg_eap = go->neg_eap;
1045 GETSHORT(cishort, p);
1046 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
1047 /* If we were asking for EAP, then we need to stop that. */
1051 /* If we were asking for CHAP, then we need to stop that. */
1052 else if (go->neg_chap)
1055 * If we weren't asking for CHAP or EAP, then we were asking for
1056 * PAP, in which case this Nak is bad.
1061 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
1063 /* Stop asking for EAP, if we were. */
1066 /* Try to set up to use their suggestion, if possible */
1067 if (CHAP_CANDIGEST(go->chap_mdtype, cichar))
1068 go->chap_mdtype = CHAP_MDTYPE_D(cichar);
1069 } else if (go->neg_chap) {
1071 * We were asking for our preferred algorithm, they must
1072 * want something different.
1074 if (cichar != CHAP_DIGEST(go->chap_mdtype)) {
1075 if (CHAP_CANDIGEST(go->chap_mdtype, cichar)) {
1076 /* Use their suggestion if we support it ... */
1077 go->chap_mdtype = CHAP_MDTYPE_D(cichar);
1079 /* ... otherwise, try our next-preferred algorithm. */
1080 try.chap_mdtype &= ~(CHAP_MDTYPE(try.chap_mdtype));
1081 if (try.chap_mdtype == MDTYPE_NONE) /* out of algos */
1086 * Whoops, they Nak'd our algorithm of choice
1087 * but then suggested it back to us.
1093 * Stop asking for PAP if we were asking for it.
1101 * If we were asking for EAP, and they're Conf-Naking EAP,
1102 * well, that's just strange. Nobody should do that.
1104 if (cishort == PPP_EAP && cilen == CILEN_SHORT && go->neg_eap)
1105 dbglog("Unexpected Conf-Nak for EAP");
1108 * We don't recognize what they're suggesting.
1109 * Stop asking for what we were asking for.
1113 else if (go->neg_chap)
1117 p += cilen - CILEN_SHORT;
1122 * If they can't cope with our link quality protocol, we'll have
1123 * to stop asking for LQR. We haven't got any other protocol.
1124 * If they Nak the reporting period, take their value XXX ?
1126 NAKCILQR(CI_QUALITY, neg_lqr,
1127 if (cishort != PPP_LQR)
1130 try.lqr_period = cilong;
1134 * Only implementing CBCP...not the rest of the callback options
1136 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1141 * Check for a looped-back line.
1143 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1144 try.magicnumber = magic();
1149 * Peer shouldn't send Nak for protocol compression or
1150 * address/control compression requests; they should send
1151 * a Reject instead. If they send a Nak, treat it as a Reject.
1153 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1154 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1157 * Nak for MRRU option - accept their value if it is smaller
1158 * than the one we want.
1161 NAKCISHORT(CI_MRRU, neg_mrru,
1162 if (cishort <= wo->mrru)
1168 * Nak for short sequence numbers shouldn't be sent, treat it
1171 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1174 * Nak of the endpoint discriminator option is not permitted,
1175 * treat it like a reject.
1177 NAKCIENDP(CI_EPDISC, neg_endpoint);
1180 * There may be remaining CIs, if the peer is requesting negotiation
1181 * on an option that we didn't include in our request packet.
1182 * If we see an option that we requested, or one we've already seen
1183 * in this packet, then this packet is bad.
1184 * If we wanted to respond by starting to negotiate on the requested
1185 * option(s), we could, but we don't, because except for the
1186 * authentication type and quality protocol, if we are not negotiating
1187 * an option, it is because we were told not to.
1188 * For the authentication type, the Nak from the peer means
1189 * `let me authenticate myself with you' which is a bit pointless.
1190 * For the quality protocol, the Nak means `ask me to send you quality
1191 * reports', but if we didn't ask for them, we don't want them.
1192 * An option we don't recognize represents the peer asking to
1193 * negotiate some option we don't support, so ignore it.
1195 while (len > CILEN_VOID) {
1198 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1200 next = p + cilen - 2;
1204 if ((go->neg_mru && go->mru != DEFMRU)
1205 || no.neg_mru || cilen != CILEN_SHORT)
1207 GETSHORT(cishort, p);
1208 if (cishort < DEFMRU) {
1214 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1215 || no.neg_asyncmap || cilen != CILEN_LONG)
1219 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap ||
1220 go->neg_eap || no.neg_eap)
1223 case CI_MAGICNUMBER:
1224 if (go->neg_magicnumber || no.neg_magicnumber ||
1225 cilen != CILEN_LONG)
1228 case CI_PCOMPRESSION:
1229 if (go->neg_pcompression || no.neg_pcompression
1230 || cilen != CILEN_VOID)
1233 case CI_ACCOMPRESSION:
1234 if (go->neg_accompression || no.neg_accompression
1235 || cilen != CILEN_VOID)
1239 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1243 if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT)
1247 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1252 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1260 * OK, the Nak is good. Now we can update state.
1261 * If there are any options left we ignore them.
1263 if (f->state != OPENED) {
1265 if (++try.numloops >= lcp_loopbackfail) {
1266 notice("Serial line is looped back.");
1267 lcp_close(f->unit, "Loopback detected");
1268 status = EXIT_LOOPBACK;
1278 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1284 * lcp_rejci - Peer has Rejected some of our CIs.
1285 * This should not modify any state if the Reject is bad
1286 * or if LCP is in the OPENED state.
1289 * 0 - Reject was bad.
1290 * 1 - Reject was good.
1293 lcp_rejci(f, p, len)
1298 lcp_options *go = &lcp_gotoptions[f->unit];
1302 lcp_options try; /* options to request next time */
1307 * Any Rejected CIs must be in exactly the same order that we sent.
1308 * Check packet length and CI length at each step.
1309 * If we find any deviations, then this packet is bad.
1311 #define REJCIVOID(opt, neg) \
1313 len >= CILEN_VOID && \
1314 p[1] == CILEN_VOID && \
1316 len -= CILEN_VOID; \
1317 INCPTR(CILEN_VOID, p); \
1320 #define REJCISHORT(opt, neg, val) \
1322 len >= CILEN_SHORT && \
1323 p[1] == CILEN_SHORT && \
1325 len -= CILEN_SHORT; \
1327 GETSHORT(cishort, p); \
1328 /* Check rejected value. */ \
1329 if (cishort != val) \
1333 #define REJCICHAP(opt, neg, val) \
1335 len >= CILEN_CHAP && \
1336 p[1] == CILEN_CHAP && \
1338 len -= CILEN_CHAP; \
1340 GETSHORT(cishort, p); \
1341 GETCHAR(cichar, p); \
1342 /* Check rejected value. */ \
1343 if ((cishort != PPP_CHAP) || (cichar != (CHAP_DIGEST(val)))) \
1346 try.neg_eap = try.neg_upap = 0; \
1348 #define REJCILONG(opt, neg, val) \
1350 len >= CILEN_LONG && \
1351 p[1] == CILEN_LONG && \
1353 len -= CILEN_LONG; \
1355 GETLONG(cilong, p); \
1356 /* Check rejected value. */ \
1357 if (cilong != val) \
1361 #define REJCILQR(opt, neg, val) \
1363 len >= CILEN_LQR && \
1364 p[1] == CILEN_LQR && \
1368 GETSHORT(cishort, p); \
1369 GETLONG(cilong, p); \
1370 /* Check rejected value. */ \
1371 if (cishort != PPP_LQR || cilong != val) \
1375 #define REJCICBCP(opt, neg, val) \
1377 len >= CILEN_CBCP && \
1378 p[1] == CILEN_CBCP && \
1380 len -= CILEN_CBCP; \
1382 GETCHAR(cichar, p); \
1383 /* Check rejected value. */ \
1384 if (cichar != val) \
1388 #define REJCIENDP(opt, neg, class, val, vlen) \
1390 len >= CILEN_CHAR + vlen && \
1392 p[1] == CILEN_CHAR + vlen) { \
1394 len -= CILEN_CHAR + vlen; \
1396 GETCHAR(cichar, p); \
1397 if (cichar != class) \
1399 for (i = 0; i < vlen; ++i) { \
1400 GETCHAR(cichar, p); \
1401 if (cichar != val[i]) \
1407 REJCISHORT(CI_MRU, neg_mru, go->mru);
1408 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1409 REJCISHORT(CI_AUTHTYPE, neg_eap, PPP_EAP);
1411 REJCICHAP(CI_AUTHTYPE, neg_chap, go->chap_mdtype);
1412 if (!go->neg_chap) {
1413 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1416 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1417 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1418 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1419 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1420 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1421 REJCISHORT(CI_MRRU, neg_mrru, go->mrru);
1422 REJCIVOID(CI_SSNHF, neg_ssnhf);
1423 REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class,
1424 go->endpoint.value, go->endpoint.length);
1427 * If there are any remaining CIs, then this packet is bad.
1432 * Now we can update state.
1434 if (f->state != OPENED)
1439 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1445 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1447 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1448 * appropriately. If reject_if_disagree is non-zero, doesn't return
1449 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1452 lcp_reqci(f, inp, lenp, reject_if_disagree)
1454 u_char *inp; /* Requested CIs */
1455 int *lenp; /* Length of requested CIs */
1456 int reject_if_disagree;
1458 lcp_options *go = &lcp_gotoptions[f->unit];
1459 lcp_options *ho = &lcp_hisoptions[f->unit];
1460 lcp_options *ao = &lcp_allowoptions[f->unit];
1461 u_char *cip, *next; /* Pointer to current and next CIs */
1462 int cilen, citype, cichar; /* Parsed len, type, char value */
1463 u_short cishort; /* Parsed short value */
1464 u_int32_t cilong; /* Parse long value */
1465 int rc = CONFACK; /* Final packet return code */
1466 int orc; /* Individual option return code */
1467 u_char *p; /* Pointer to next char to parse */
1468 u_char *rejp; /* Pointer to next char in reject frame */
1469 u_char *nakp; /* Pointer to next char in Nak frame */
1470 int l = *lenp; /* Length left */
1473 * Reset all his options.
1475 BZERO(ho, sizeof(*ho));
1478 * Process all his options.
1484 orc = CONFACK; /* Assume success */
1485 cip = p = next; /* Remember begining of CI */
1486 if (l < 2 || /* Not enough data for CI header or */
1487 p[1] < 2 || /* CI length too small or */
1488 p[1] > l) { /* CI length too big? */
1489 LCPDEBUG(("lcp_reqci: bad CI length!"));
1490 orc = CONFREJ; /* Reject bad CI */
1491 cilen = l; /* Reject till end of packet */
1492 l = 0; /* Don't loop again */
1496 GETCHAR(citype, p); /* Parse CI type */
1497 GETCHAR(cilen, p); /* Parse CI length */
1498 l -= cilen; /* Adjust remaining length */
1499 next += cilen; /* Step to next CI */
1501 switch (citype) { /* Check CI type */
1503 if (!ao->neg_mru || /* Allow option? */
1504 cilen != CILEN_SHORT) { /* Check CI length */
1505 orc = CONFREJ; /* Reject CI */
1508 GETSHORT(cishort, p); /* Parse MRU */
1511 * He must be able to receive at least our minimum.
1512 * No need to check a maximum. If he sends a large number,
1513 * we'll just ignore it.
1515 if (cishort < MINMRU) {
1516 orc = CONFNAK; /* Nak CI */
1517 PUTCHAR(CI_MRU, nakp);
1518 PUTCHAR(CILEN_SHORT, nakp);
1519 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1522 ho->neg_mru = 1; /* Remember he sent MRU */
1523 ho->mru = cishort; /* And remember value */
1527 if (!ao->neg_asyncmap ||
1528 cilen != CILEN_LONG) {
1535 * Asyncmap must have set at least the bits
1536 * which are set in lcp_allowoptions[unit].asyncmap.
1538 if ((ao->asyncmap & ~cilong) != 0) {
1540 PUTCHAR(CI_ASYNCMAP, nakp);
1541 PUTCHAR(CILEN_LONG, nakp);
1542 PUTLONG(ao->asyncmap | cilong, nakp);
1545 ho->neg_asyncmap = 1;
1546 ho->asyncmap = cilong;
1550 if (cilen < CILEN_SHORT ||
1551 !(ao->neg_upap || ao->neg_chap || ao->neg_eap)) {
1553 * Reject the option if we're not willing to authenticate.
1555 dbglog("No auth is possible");
1559 GETSHORT(cishort, p);
1562 * Authtype must be PAP, CHAP, or EAP.
1564 * Note: if more than one of ao->neg_upap, ao->neg_chap, and
1565 * ao->neg_eap are set, and the peer sends a Configure-Request
1566 * with two or more authenticate-protocol requests, then we will
1567 * reject the second request.
1568 * Whether we end up doing CHAP, UPAP, or EAP depends then on
1569 * the ordering of the CIs in the peer's Configure-Request.
1572 if (cishort == PPP_PAP) {
1573 /* we've already accepted CHAP or EAP */
1574 if (ho->neg_chap || ho->neg_eap ||
1575 cilen != CILEN_SHORT) {
1576 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1580 if (!ao->neg_upap) { /* we don't want to do PAP */
1581 orc = CONFNAK; /* NAK it and suggest CHAP or EAP */
1583 PUTCHAR(CILEN_SHORT, nakp);
1584 PUTSHORT(PPP_EAP, nakp);
1586 PUTCHAR(CI_AUTHTYPE, nakp);
1587 PUTCHAR(CILEN_CHAP, nakp);
1588 PUTSHORT(PPP_CHAP, nakp);
1589 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1596 if (cishort == PPP_CHAP) {
1597 /* we've already accepted PAP or EAP */
1598 if (ho->neg_upap || ho->neg_eap ||
1599 cilen != CILEN_CHAP) {
1600 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1604 if (!ao->neg_chap) { /* we don't want to do CHAP */
1605 orc = CONFNAK; /* NAK it and suggest EAP or PAP */
1606 PUTCHAR(CI_AUTHTYPE, nakp);
1607 PUTCHAR(CILEN_SHORT, nakp);
1609 PUTSHORT(PPP_EAP, nakp);
1611 PUTSHORT(PPP_PAP, nakp);
1615 GETCHAR(cichar, p); /* get digest type */
1616 if (!(CHAP_CANDIGEST(ao->chap_mdtype, cichar))) {
1618 * We can't/won't do the requested type,
1619 * suggest something else.
1622 PUTCHAR(CI_AUTHTYPE, nakp);
1623 PUTCHAR(CILEN_CHAP, nakp);
1624 PUTSHORT(PPP_CHAP, nakp);
1625 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1628 ho->chap_mdtype = CHAP_MDTYPE_D(cichar); /* save md type */
1632 if (cishort == PPP_EAP) {
1633 /* we've already accepted CHAP or PAP */
1634 if (ho->neg_chap || ho->neg_upap || cilen != CILEN_SHORT) {
1635 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE EAP, rejecting..."));
1639 if (!ao->neg_eap) { /* we don't want to do EAP */
1640 orc = CONFNAK; /* NAK it and suggest CHAP or PAP */
1641 PUTCHAR(CI_AUTHTYPE, nakp);
1643 PUTCHAR(CILEN_CHAP, nakp);
1644 PUTSHORT(PPP_CHAP, nakp);
1645 PUTCHAR(ao->chap_mdtype, nakp);
1647 PUTCHAR(CILEN_SHORT, nakp);
1648 PUTSHORT(PPP_PAP, nakp);
1657 * We don't recognize the protocol they're asking for.
1658 * Nak it with something we're willing to do.
1659 * (At this point we know ao->neg_upap || ao->neg_chap ||
1663 PUTCHAR(CI_AUTHTYPE, nakp);
1665 PUTCHAR(CILEN_SHORT, nakp);
1666 PUTSHORT(PPP_EAP, nakp);
1667 } else if (ao->neg_chap) {
1668 PUTCHAR(CILEN_CHAP, nakp);
1669 PUTSHORT(PPP_CHAP, nakp);
1670 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1672 PUTCHAR(CILEN_SHORT, nakp);
1673 PUTSHORT(PPP_PAP, nakp);
1679 cilen != CILEN_LQR) {
1684 GETSHORT(cishort, p);
1688 * Check the protocol and the reporting period.
1689 * XXX When should we Nak this, and what with?
1691 if (cishort != PPP_LQR) {
1693 PUTCHAR(CI_QUALITY, nakp);
1694 PUTCHAR(CILEN_LQR, nakp);
1695 PUTSHORT(PPP_LQR, nakp);
1696 PUTLONG(ao->lqr_period, nakp);
1701 case CI_MAGICNUMBER:
1702 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1703 cilen != CILEN_LONG) {
1710 * He must have a different magic number.
1712 if (go->neg_magicnumber &&
1713 cilong == go->magicnumber) {
1714 cilong = magic(); /* Don't put magic() inside macro! */
1716 PUTCHAR(CI_MAGICNUMBER, nakp);
1717 PUTCHAR(CILEN_LONG, nakp);
1718 PUTLONG(cilong, nakp);
1721 ho->neg_magicnumber = 1;
1722 ho->magicnumber = cilong;
1726 case CI_PCOMPRESSION:
1727 if (!ao->neg_pcompression ||
1728 cilen != CILEN_VOID) {
1732 ho->neg_pcompression = 1;
1735 case CI_ACCOMPRESSION:
1736 if (!ao->neg_accompression ||
1737 cilen != CILEN_VOID) {
1741 ho->neg_accompression = 1;
1745 if (!ao->neg_mrru || !multilink ||
1746 cilen != CILEN_SHORT) {
1751 GETSHORT(cishort, p);
1752 /* possibly should insist on a minimum/maximum MRRU here */
1758 if (!ao->neg_ssnhf || !multilink ||
1759 cilen != CILEN_VOID) {
1767 if (!ao->neg_endpoint ||
1768 cilen < CILEN_CHAR ||
1769 cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1774 cilen -= CILEN_CHAR;
1775 ho->neg_endpoint = 1;
1776 ho->endpoint.class = cichar;
1777 ho->endpoint.length = cilen;
1778 BCOPY(p, ho->endpoint.value, cilen);
1783 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1789 if (orc == CONFACK && /* Good CI */
1790 rc != CONFACK) /* but prior CI wasnt? */
1791 continue; /* Don't send this one */
1793 if (orc == CONFNAK) { /* Nak this CI? */
1794 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1795 && citype != CI_MAGICNUMBER) {
1796 orc = CONFREJ; /* Get tough if so */
1798 if (rc == CONFREJ) /* Rejecting prior CI? */
1799 continue; /* Don't send this one */
1803 if (orc == CONFREJ) { /* Reject this CI */
1805 if (cip != rejp) /* Need to move rejected CI? */
1806 BCOPY(cip, rejp, cilen); /* Move it */
1807 INCPTR(cilen, rejp); /* Update output pointer */
1812 * If we wanted to send additional NAKs (for unsent CIs), the
1813 * code would go here. The extra NAKs would go at *nakp.
1814 * At present there are no cases where we want to ask the
1815 * peer to negotiate an option.
1824 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1826 *lenp = nakp - nak_buffer;
1827 BCOPY(nak_buffer, inp, *lenp);
1834 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1835 return (rc); /* Return final code */
1840 * lcp_up - LCP has come UP.
1846 lcp_options *wo = &lcp_wantoptions[f->unit];
1847 lcp_options *ho = &lcp_hisoptions[f->unit];
1848 lcp_options *go = &lcp_gotoptions[f->unit];
1849 lcp_options *ao = &lcp_allowoptions[f->unit];
1852 if (!go->neg_magicnumber)
1853 go->magicnumber = 0;
1854 if (!ho->neg_magicnumber)
1855 ho->magicnumber = 0;
1858 * Set our MTU to the smaller of the MTU we wanted and
1859 * the MRU our peer wanted. If we negotiated an MRU,
1860 * set our MRU to the larger of value we wanted and
1861 * the value we got in the negotiation.
1862 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1863 * the interface MTU is set to the lowest of that, the
1864 * MTU we want to use, and our link MRU.
1866 mtu = ho->neg_mru? ho->mru: PPP_MRU;
1867 mru = go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU;
1868 #ifdef HAVE_MULTILINK
1869 if (!(multilink && go->neg_mrru && ho->neg_mrru))
1870 #endif /* HAVE_MULTILINK */
1871 netif_set_mtu(f->unit, MIN(MIN(mtu, mru), ao->mru));
1872 ppp_send_config(f->unit, mtu,
1873 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1874 ho->neg_pcompression, ho->neg_accompression);
1875 ppp_recv_config(f->unit, mru,
1876 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
1877 go->neg_pcompression, go->neg_accompression);
1880 peer_mru[f->unit] = ho->mru;
1882 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1884 link_established(f->unit);
1889 * lcp_down - LCP has gone DOWN.
1891 * Alert other protocols.
1897 lcp_options *go = &lcp_gotoptions[f->unit];
1899 lcp_echo_lowerdown(f->unit);
1903 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1904 ppp_recv_config(f->unit, PPP_MRU,
1905 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1906 go->neg_pcompression, go->neg_accompression);
1907 peer_mru[f->unit] = PPP_MRU;
1912 * lcp_starting - LCP needs the lower layer up.
1918 link_required(f->unit);
1923 * lcp_finished - LCP has finished with the lower layer.
1929 link_terminated(f->unit);
1934 * lcp_printpkt - print the contents of an LCP packet.
1936 static char *lcp_codenames[] = {
1937 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1938 "TermReq", "TermAck", "CodeRej", "ProtRej",
1939 "EchoReq", "EchoRep", "DiscReq"
1943 lcp_printpkt(p, plen, printer, arg)
1946 void (*printer) __P((void *, char *, ...));
1949 int code, id, len, olen, i;
1950 u_char *pstart, *optend;
1954 if (plen < HEADERLEN)
1960 if (len < HEADERLEN || len > plen)
1963 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1964 printer(arg, " %s", lcp_codenames[code-1]);
1966 printer(arg, " code=0x%x", code);
1967 printer(arg, " id=0x%x", id);
1974 /* print option list */
1979 if (olen < 2 || olen > len) {
1987 if (olen == CILEN_SHORT) {
1989 GETSHORT(cishort, p);
1990 printer(arg, "mru %d", cishort);
1994 if (olen == CILEN_LONG) {
1997 printer(arg, "asyncmap 0x%x", cilong);
2001 if (olen >= CILEN_SHORT) {
2003 printer(arg, "auth ");
2004 GETSHORT(cishort, p);
2007 printer(arg, "pap");
2010 printer(arg, "chap");
2013 case CHAP_DIGEST_MD5:
2014 printer(arg, " MD5");
2018 case CHAP_MICROSOFT:
2019 printer(arg, " MS");
2023 case CHAP_MICROSOFT_V2:
2024 printer(arg, " MS-v2");
2032 printer(arg, "eap");
2035 printer(arg, "0x%x", cishort);
2040 if (olen >= CILEN_SHORT) {
2042 printer(arg, "quality ");
2043 GETSHORT(cishort, p);
2046 printer(arg, "lqr");
2049 printer(arg, "0x%x", cishort);
2054 if (olen >= CILEN_CHAR) {
2056 printer(arg, "callback ");
2057 GETCHAR(cishort, p);
2060 printer(arg, "CBCP");
2063 printer(arg, "0x%x", cishort);
2067 case CI_MAGICNUMBER:
2068 if (olen == CILEN_LONG) {
2071 printer(arg, "magic 0x%x", cilong);
2074 case CI_PCOMPRESSION:
2075 if (olen == CILEN_VOID) {
2077 printer(arg, "pcomp");
2080 case CI_ACCOMPRESSION:
2081 if (olen == CILEN_VOID) {
2083 printer(arg, "accomp");
2087 if (olen == CILEN_SHORT) {
2089 GETSHORT(cishort, p);
2090 printer(arg, "mrru %d", cishort);
2094 if (olen == CILEN_VOID) {
2096 printer(arg, "ssnhf");
2100 #ifdef HAVE_MULTILINK
2101 if (olen >= CILEN_CHAR) {
2104 GETCHAR(epd.class, p);
2105 epd.length = olen - CILEN_CHAR;
2106 if (epd.length > MAX_ENDP_LEN)
2107 epd.length = MAX_ENDP_LEN;
2108 if (epd.length > 0) {
2109 BCOPY(p, epd.value, epd.length);
2112 printer(arg, "endpoint [%s]", epdisc_to_str(&epd));
2115 printer(arg, "endpoint");
2119 while (p < optend) {
2121 printer(arg, " %.2x", code);
2129 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2131 print_string((char *)p, len, printer, arg);
2142 printer(arg, " magic=0x%x", cilong);
2149 /* print the rest of the bytes in the packet */
2150 for (i = 0; i < len && i < 32; ++i) {
2152 printer(arg, " %.2x", code);
2155 printer(arg, " ...");
2163 * Time to shut down the link because there is nothing out there.
2167 void LcpLinkFailure (f)
2170 if (f->state == OPENED) {
2171 info("No response to %d echo-requests", lcp_echos_pending);
2172 notice("Serial link appears to be disconnected.");
2173 lcp_close(f->unit, "Peer not responding");
2174 status = EXIT_PEER_DEAD;
2179 * Timer expired for the LCP echo requests from this process.
2186 LcpSendEchoRequest (f);
2187 if (f->state != OPENED)
2191 * Start the timer for the next interval.
2193 if (lcp_echo_timer_running)
2194 warn("assertion lcp_echo_timer_running==0 failed");
2195 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2196 lcp_echo_timer_running = 1;
2200 * LcpEchoTimeout - Timer expired on the LCP echo
2204 LcpEchoTimeout (arg)
2207 if (lcp_echo_timer_running != 0) {
2208 lcp_echo_timer_running = 0;
2209 LcpEchoCheck ((fsm *) arg);
2214 * LcpEchoReply - LCP has received a reply to the echo
2218 lcp_received_echo_reply (f, id, inp, len)
2226 /* Check the magic number - don't count replies from ourselves. */
2228 dbglog("lcp: received short Echo-Reply, length %d", len);
2231 GETLONG(magic, inp);
2232 if (lcp_gotoptions[f->unit].neg_magicnumber
2233 && magic == lcp_gotoptions[f->unit].magicnumber) {
2234 warn("appear to have received our own echo-reply!");
2238 /* Reset the number of outstanding echo frames */
2239 lcp_echos_pending = 0;
2243 * LcpSendEchoRequest - Send an echo request frame to the peer
2247 LcpSendEchoRequest (f)
2250 u_int32_t lcp_magic;
2251 u_char pkt[4], *pktp;
2254 * Detect the failure of the peer at this point.
2256 if (lcp_echo_fails != 0) {
2257 if (lcp_echos_pending >= lcp_echo_fails) {
2259 lcp_echos_pending = 0;
2264 * Make and send the echo request frame.
2266 if (f->state == OPENED) {
2267 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2269 PUTLONG(lcp_magic, pktp);
2270 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2271 ++lcp_echos_pending;
2276 * lcp_echo_lowerup - Start the timer for the LCP frame
2280 lcp_echo_lowerup (unit)
2283 fsm *f = &lcp_fsm[unit];
2285 /* Clear the parameters for generating echo frames */
2286 lcp_echos_pending = 0;
2287 lcp_echo_number = 0;
2288 lcp_echo_timer_running = 0;
2290 /* If a timeout interval is specified then start the timer */
2291 if (lcp_echo_interval != 0)
2296 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2300 lcp_echo_lowerdown (unit)
2303 fsm *f = &lcp_fsm[unit];
2305 if (lcp_echo_timer_running != 0) {
2306 UNTIMEOUT (LcpEchoTimeout, f);
2307 lcp_echo_timer_running = 0;