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.56 2001/02/22 03:16:26 paulus 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 **));
57 static int setescape __P((char **));
60 static int setendpoint __P((char **));
61 #endif /* HAVE_MULTILINK */
63 static option_t lcp_option_list[] = {
65 { "-all", o_special_noarg, (void *)noopt,
66 "Don't request/allow any LCP options" },
67 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
68 "Disable address/control compression",
69 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
70 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
71 "Disable address/control compression",
72 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
73 { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
74 "Disable asyncmap negotiation",
75 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
76 { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
77 "Disable asyncmap negotiation",
78 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
79 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
80 "Set asyncmap (for received packets)",
81 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
82 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
83 "Set asyncmap (for received packets)",
84 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
85 { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
86 "Disable magic number negotiation (looped-back line detection)",
87 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
88 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
89 "Disable magic number negotiation (looped-back line detection)",
90 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
91 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
92 "Disable MRU negotiation (use default 1500)",
93 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
94 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
95 "Disable MRU negotiation (use default 1500)",
96 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
97 { "mru", o_int, &lcp_wantoptions[0].mru,
98 "Set MRU (maximum received packet size) for negotiation",
99 0, &lcp_wantoptions[0].neg_mru },
100 { "mtu", o_int, &lcp_allowoptions[0].mru,
101 "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
102 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
103 "Disable protocol field compression",
104 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
105 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
106 "Disable protocol field compression",
107 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
108 { "-p", o_bool, &lcp_wantoptions[0].passive,
109 "Set passive mode", 1 },
110 { "passive", o_bool, &lcp_wantoptions[0].passive,
111 "Set passive mode", 1 },
112 { "silent", o_bool, &lcp_wantoptions[0].silent,
113 "Set silent mode", 1 },
114 { "escape", o_special, (void *)setescape,
115 "List of character codes to escape on transmission" },
116 { "lcp-echo-failure", o_int, &lcp_echo_fails,
117 "Set number of consecutive echo failures to indicate link failure" },
118 { "lcp-echo-interval", o_int, &lcp_echo_interval,
119 "Set time in seconds between LCP echo requests" },
120 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
121 "Set time in seconds between LCP retransmissions" },
122 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
123 "Set maximum number of LCP terminate-request transmissions" },
124 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
125 "Set maximum number of LCP configure-request transmissions" },
126 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
127 "Set limit on number of LCP configure-naks" },
128 { "receive-all", o_bool, &lax_recv,
129 "Accept all received control characters", 1 },
130 #ifdef HAVE_MULTILINK
131 { "mrru", o_int, &lcp_wantoptions[0].mrru,
132 "Maximum received packet size for multilink bundle",
133 0, &lcp_wantoptions[0].neg_mrru },
134 { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
135 "Use short sequence numbers in multilink headers",
136 OPT_A2COPY | 1, &lcp_allowoptions[0].neg_ssnhf },
137 { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
138 "Don't use short sequence numbers in multilink headers",
139 OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf },
140 { "endpoint", o_special, setendpoint,
141 "Endpoint discriminator for multilink" },
142 #endif /* HAVE_MULTILINK */
143 { "noendpoint", o_bool, &noendpoint,
144 "Don't send or accept multilink endpoint discriminator", 1 },
149 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
150 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
151 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
152 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
153 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
154 u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
156 static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
157 static int lcp_echo_number = 0; /* ID number of next echo frame */
158 static int lcp_echo_timer_running = 0; /* set if a timer is running */
160 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
163 * Callbacks for fsm code. (CI = Configuration Information)
165 static void lcp_resetci __P((fsm *)); /* Reset our CI */
166 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
167 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
168 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
169 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
170 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
171 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
172 static void lcp_up __P((fsm *)); /* We're UP */
173 static void lcp_down __P((fsm *)); /* We're DOWN */
174 static void lcp_starting __P((fsm *)); /* We need lower layer up */
175 static void lcp_finished __P((fsm *)); /* We need lower layer down */
176 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
177 static void lcp_rprotrej __P((fsm *, u_char *, int));
180 * routines to send LCP echos to peer
183 static void lcp_echo_lowerup __P((int));
184 static void lcp_echo_lowerdown __P((int));
185 static void LcpEchoTimeout __P((void *));
186 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
187 static void LcpSendEchoRequest __P((fsm *));
188 static void LcpLinkFailure __P((fsm *));
189 static void LcpEchoCheck __P((fsm *));
191 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
192 lcp_resetci, /* Reset our Configuration Information */
193 lcp_cilen, /* Length of our Configuration Information */
194 lcp_addci, /* Add our Configuration Information */
195 lcp_ackci, /* ACK our Configuration Information */
196 lcp_nakci, /* NAK our Configuration Information */
197 lcp_rejci, /* Reject our Configuration Information */
198 lcp_reqci, /* Request peer's Configuration Information */
199 lcp_up, /* Called when fsm reaches OPENED state */
200 lcp_down, /* Called when fsm leaves OPENED state */
201 lcp_starting, /* Called when we want the lower layer up */
202 lcp_finished, /* Called when we want the lower layer down */
203 NULL, /* Called when Protocol-Reject received */
204 NULL, /* Retransmission is necessary */
205 lcp_extcode, /* Called to handle LCP-specific codes */
206 "LCP" /* String name of protocol */
210 * Protocol entry points.
211 * Some of these are called directly.
214 static void lcp_init __P((int));
215 static void lcp_input __P((int, u_char *, int));
216 static void lcp_protrej __P((int));
217 static int lcp_printpkt __P((u_char *, int,
218 void (*) __P((void *, char *, ...)), void *));
220 struct protent lcp_protent = {
240 int lcp_loopbackfail = DEFLOOPBACKFAIL;
243 * Length of each type of configuration option (in octets)
247 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
248 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
249 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
250 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
253 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
254 (x) == CONFNAK ? "NAK" : "REJ")
257 * noopt - Disable all options (why?).
263 BZERO((char *) &lcp_wantoptions[0], sizeof (struct lcp_options));
264 BZERO((char *) &lcp_allowoptions[0], sizeof (struct lcp_options));
270 * setescape - add chars to the set we escape on transmission.
282 n = strtol(p, &endp, 16);
284 option_error("escape parameter contains invalid hex number '%s'",
289 if (n < 0 || n == 0x5E || n > 0xFF) {
290 option_error("can't escape character 0x%x", n);
293 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
294 while (*p == ',' || *p == ' ')
300 #ifdef HAVE_MULTILINK
305 if (str_to_epdisc(&lcp_wantoptions[0].endpoint, *argv)) {
306 lcp_wantoptions[0].neg_endpoint = 1;
309 option_error("Can't parse '%s' as an endpoint discriminator", *argv);
312 #endif /* HAVE_MULTILINK */
315 * lcp_init - Initialize LCP.
321 fsm *f = &lcp_fsm[unit];
322 lcp_options *wo = &lcp_wantoptions[unit];
323 lcp_options *ao = &lcp_allowoptions[unit];
326 f->protocol = PPP_LCP;
327 f->callbacks = &lcp_callbacks;
331 BZERO(wo, sizeof(*wo));
334 wo->neg_asyncmap = 1;
335 wo->chap_mdtype = CHAP_DIGEST_MD5;
336 wo->neg_magicnumber = 1;
337 wo->neg_pcompression = 1;
338 wo->neg_accompression = 1;
340 BZERO(ao, sizeof(*ao));
343 ao->neg_asyncmap = 1;
345 ao->chap_mdtype = CHAP_DIGEST_MD5;
347 ao->neg_magicnumber = 1;
348 ao->neg_pcompression = 1;
349 ao->neg_accompression = 1;
353 ao->neg_endpoint = 1;
355 BZERO(xmit_accm[unit], sizeof(xmit_accm[0]));
356 xmit_accm[unit][3] = 0x60000000;
361 * lcp_open - LCP is allowed to come up.
367 fsm *f = &lcp_fsm[unit];
368 lcp_options *wo = &lcp_wantoptions[unit];
370 f->flags &= ~(OPT_PASSIVE | OPT_SILENT);
372 f->flags |= OPT_PASSIVE;
374 f->flags |= OPT_SILENT;
380 * lcp_close - Take LCP down.
383 lcp_close(unit, reason)
387 fsm *f = &lcp_fsm[unit];
389 if (phase != PHASE_DEAD)
390 new_phase(PHASE_TERMINATE);
391 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
393 * This action is not strictly according to the FSM in RFC1548,
394 * but it does mean that the program terminates if you do a
395 * lcp_close() in passive/silent mode when a connection hasn't
402 fsm_close(&lcp_fsm[unit], reason);
407 * lcp_lowerup - The lower layer is up.
413 lcp_options *wo = &lcp_wantoptions[unit];
414 fsm *f = &lcp_fsm[unit];
417 * Don't use A/C or protocol compression on transmission,
418 * but accept A/C and protocol compressed packets
419 * if we are going to ask for A/C and protocol compression.
421 ppp_set_xaccm(unit, xmit_accm[unit]);
422 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
423 ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
424 wo->neg_pcompression, wo->neg_accompression);
425 peer_mru[unit] = PPP_MRU;
426 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
428 if (listen_time != 0) {
429 f->flags |= DELAYED_UP;
430 timeout(lcp_delayed_up, f, 0, listen_time * 1000);
437 * lcp_lowerdown - The lower layer is down.
443 fsm *f = &lcp_fsm[unit];
445 if (f->flags & DELAYED_UP)
446 f->flags &= ~DELAYED_UP;
448 fsm_lowerdown(&lcp_fsm[unit]);
453 * lcp_delayed_up - Bring the lower layer up now.
461 if (f->flags & DELAYED_UP) {
462 f->flags &= ~DELAYED_UP;
469 * lcp_input - Input LCP packet.
472 lcp_input(unit, p, len)
477 fsm *f = &lcp_fsm[unit];
479 if (f->flags & DELAYED_UP) {
480 f->flags &= ~DELAYED_UP;
483 fsm_input(f, p, len);
488 * lcp_extcode - Handle a LCP-specific code.
491 lcp_extcode(f, code, id, inp, len)
501 lcp_rprotrej(f, inp, len);
505 if (f->state != OPENED)
508 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
509 fsm_sdata(f, ECHOREP, id, inp, len);
513 lcp_received_echo_reply(f, id, inp, len);
527 * lcp_rprotrej - Receive an Protocol-Reject.
529 * Figure out which protocol is rejected and inform it.
532 lcp_rprotrej(f, inp, len)
538 struct protent *protp;
542 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
549 * Protocol-Reject packets received in any state other than the LCP
550 * OPENED state SHOULD be silently discarded.
552 if( f->state != OPENED ){
553 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
558 * Upcall the proper Protocol-Reject routine.
560 for (i = 0; (protp = protocols[i]) != NULL; ++i)
561 if (protp->protocol == prot && protp->enabled_flag) {
562 (*protp->protrej)(f->unit);
566 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
571 * lcp_protrej - A Protocol-Reject was received.
581 error("Received Protocol-Reject for LCP!");
582 fsm_protreject(&lcp_fsm[unit]);
587 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
590 lcp_sprotrej(unit, p, len)
596 * Send back the protocol and the information field of the
597 * rejected packet. We only get here if LCP is in the OPENED state.
602 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
608 * lcp_resetci - Reset our CI.
614 lcp_options *wo = &lcp_wantoptions[f->unit];
615 lcp_options *go = &lcp_gotoptions[f->unit];
616 lcp_options *ao = &lcp_allowoptions[f->unit];
618 wo->magicnumber = magic();
624 go->neg_endpoint = 0;
627 ao->neg_endpoint = 0;
628 peer_mru[f->unit] = PPP_MRU;
634 * lcp_cilen - Return length of our CI.
640 lcp_options *go = &lcp_gotoptions[f->unit];
642 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
643 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
644 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
645 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
646 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
647 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
649 * NB: we only ask for one of CHAP and UPAP, even if we will
652 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
653 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
654 LENCICHAP(go->neg_chap) +
655 LENCISHORT(!go->neg_chap && go->neg_upap) +
656 LENCILQR(go->neg_lqr) +
657 LENCICBCP(go->neg_cbcp) +
658 LENCILONG(go->neg_magicnumber) +
659 LENCIVOID(go->neg_pcompression) +
660 LENCIVOID(go->neg_accompression) +
661 LENCISHORT(go->neg_mrru) +
662 LENCIVOID(go->neg_ssnhf) +
663 (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
668 * lcp_addci - Add our desired CIs to a packet.
671 lcp_addci(f, ucp, lenp)
676 lcp_options *go = &lcp_gotoptions[f->unit];
677 u_char *start_ucp = ucp;
679 #define ADDCIVOID(opt, neg) \
682 PUTCHAR(CILEN_VOID, ucp); \
684 #define ADDCISHORT(opt, neg, val) \
687 PUTCHAR(CILEN_SHORT, ucp); \
688 PUTSHORT(val, ucp); \
690 #define ADDCICHAP(opt, neg, val, digest) \
693 PUTCHAR(CILEN_CHAP, ucp); \
694 PUTSHORT(val, ucp); \
695 PUTCHAR(digest, ucp); \
697 #define ADDCILONG(opt, neg, val) \
700 PUTCHAR(CILEN_LONG, ucp); \
703 #define ADDCILQR(opt, neg, val) \
706 PUTCHAR(CILEN_LQR, ucp); \
707 PUTSHORT(PPP_LQR, ucp); \
710 #define ADDCICHAR(opt, neg, val) \
713 PUTCHAR(CILEN_CHAR, ucp); \
716 #define ADDCIENDP(opt, neg, class, val, len) \
720 PUTCHAR(CILEN_CHAR + len, ucp); \
721 PUTCHAR(class, ucp); \
722 for (i = 0; i < len; ++i) \
723 PUTCHAR(val[i], ucp); \
726 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
727 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
729 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
730 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
731 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
732 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
733 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
734 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
735 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
736 ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
737 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
738 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
739 go->endpoint.value, go->endpoint.length);
741 if (ucp - start_ucp != *lenp) {
742 /* this should never happen, because peer_mtu should be 1500 */
743 error("Bug in lcp_addci: wrong length");
749 * lcp_ackci - Ack our CIs.
750 * This should not modify any state if the Ack is bad.
762 lcp_options *go = &lcp_gotoptions[f->unit];
763 u_char cilen, citype, cichar;
768 * CIs must be in exactly the same order that we sent.
769 * Check packet length and CI length at each step.
770 * If we find any deviations, then this packet is bad.
772 #define ACKCIVOID(opt, neg) \
774 if ((len -= CILEN_VOID) < 0) \
776 GETCHAR(citype, p); \
778 if (cilen != CILEN_VOID || \
782 #define ACKCISHORT(opt, neg, val) \
784 if ((len -= CILEN_SHORT) < 0) \
786 GETCHAR(citype, p); \
788 if (cilen != CILEN_SHORT || \
791 GETSHORT(cishort, p); \
792 if (cishort != val) \
795 #define ACKCICHAR(opt, neg, val) \
797 if ((len -= CILEN_CHAR) < 0) \
799 GETCHAR(citype, p); \
801 if (cilen != CILEN_CHAR || \
804 GETCHAR(cichar, p); \
808 #define ACKCICHAP(opt, neg, val, digest) \
810 if ((len -= CILEN_CHAP) < 0) \
812 GETCHAR(citype, p); \
814 if (cilen != CILEN_CHAP || \
817 GETSHORT(cishort, p); \
818 if (cishort != val) \
820 GETCHAR(cichar, p); \
821 if (cichar != digest) \
824 #define ACKCILONG(opt, neg, val) \
826 if ((len -= CILEN_LONG) < 0) \
828 GETCHAR(citype, p); \
830 if (cilen != CILEN_LONG || \
833 GETLONG(cilong, p); \
837 #define ACKCILQR(opt, neg, val) \
839 if ((len -= CILEN_LQR) < 0) \
841 GETCHAR(citype, p); \
843 if (cilen != CILEN_LQR || \
846 GETSHORT(cishort, p); \
847 if (cishort != PPP_LQR) \
849 GETLONG(cilong, p); \
853 #define ACKCIENDP(opt, neg, class, val, vlen) \
856 if ((len -= CILEN_CHAR + vlen) < 0) \
858 GETCHAR(citype, p); \
860 if (cilen != CILEN_CHAR + vlen || \
863 GETCHAR(cichar, p); \
864 if (cichar != class) \
866 for (i = 0; i < vlen; ++i) { \
867 GETCHAR(cichar, p); \
868 if (cichar != val[i]) \
873 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
874 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
876 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
877 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
878 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
879 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
880 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
881 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
882 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
883 ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
884 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
885 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
886 go->endpoint.value, go->endpoint.length);
889 * If there are any remaining CIs, then this packet is bad.
895 LCPDEBUG(("lcp_acki: received bad Ack!"));
901 * lcp_nakci - Peer has sent a NAK for some of our CIs.
902 * This should not modify any state if the Nak is bad
903 * or if LCP is in the OPENED state.
915 lcp_options *go = &lcp_gotoptions[f->unit];
916 lcp_options *wo = &lcp_wantoptions[f->unit];
917 u_char citype, cichar, *next;
920 lcp_options no; /* options we've seen Naks for */
921 lcp_options try; /* options to request next time */
925 BZERO(&no, sizeof(no));
929 * Any Nak'd CIs must be in exactly the same order that we sent.
930 * Check packet length and CI length at each step.
931 * If we find any deviations, then this packet is bad.
933 #define NAKCIVOID(opt, neg) \
935 len >= CILEN_VOID && \
936 p[1] == CILEN_VOID && \
939 INCPTR(CILEN_VOID, p); \
943 #define NAKCICHAP(opt, neg, code) \
945 len >= CILEN_CHAP && \
946 p[1] == CILEN_CHAP && \
950 GETSHORT(cishort, p); \
951 GETCHAR(cichar, p); \
955 #define NAKCICHAR(opt, neg, code) \
957 len >= CILEN_CHAR && \
958 p[1] == CILEN_CHAR && \
962 GETCHAR(cichar, p); \
966 #define NAKCISHORT(opt, neg, code) \
968 len >= CILEN_SHORT && \
969 p[1] == CILEN_SHORT && \
971 len -= CILEN_SHORT; \
973 GETSHORT(cishort, p); \
977 #define NAKCILONG(opt, neg, code) \
979 len >= CILEN_LONG && \
980 p[1] == CILEN_LONG && \
984 GETLONG(cilong, p); \
988 #define NAKCILQR(opt, neg, code) \
990 len >= CILEN_LQR && \
991 p[1] == CILEN_LQR && \
995 GETSHORT(cishort, p); \
996 GETLONG(cilong, p); \
1000 #define NAKCIENDP(opt, neg) \
1002 len >= CILEN_CHAR && \
1004 p[1] >= CILEN_CHAR && \
1013 * We don't care if they want to send us smaller packets than
1014 * we want. Therefore, accept any MRU less than what we asked for,
1015 * but then ignore the new value when setting the MRU in the kernel.
1016 * If they send us a bigger MRU than what we asked, accept it, up to
1017 * the limit of the default MRU we'd get if we didn't negotiate.
1019 if (go->neg_mru && go->mru != DEFMRU) {
1020 NAKCISHORT(CI_MRU, neg_mru,
1021 if (cishort <= wo->mru || cishort <= DEFMRU)
1027 * Add any characters they want to our (receive-side) asyncmap.
1029 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
1030 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
1031 try.asyncmap = go->asyncmap | cilong;
1036 * If they've nak'd our authentication-protocol, check whether
1037 * they are proposing a different protocol, or a different
1038 * hash algorithm for CHAP.
1040 if ((go->neg_chap || go->neg_upap)
1041 && len >= CILEN_SHORT
1042 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
1045 no.neg_chap = go->neg_chap;
1046 no.neg_upap = go->neg_upap;
1048 GETSHORT(cishort, p);
1049 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
1051 * If we were asking for CHAP, they obviously don't want to do it.
1052 * If we weren't asking for CHAP, then we were asking for PAP,
1053 * in which case this Nak is bad.
1059 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
1063 * We were asking for CHAP/MD5; they must want a different
1064 * algorithm. If they can't do MD5, we can ask for M$-CHAP
1065 * if we support it, otherwise we'll have to stop
1068 if (cichar != go->chap_mdtype) {
1070 if (cichar == CHAP_MICROSOFT)
1071 go->chap_mdtype = CHAP_MICROSOFT;
1078 * Stop asking for PAP if we were asking for it.
1085 * We don't recognize what they're suggesting.
1086 * Stop asking for what we were asking for.
1092 p += cilen - CILEN_SHORT;
1097 * If they can't cope with our link quality protocol, we'll have
1098 * to stop asking for LQR. We haven't got any other protocol.
1099 * If they Nak the reporting period, take their value XXX ?
1101 NAKCILQR(CI_QUALITY, neg_lqr,
1102 if (cishort != PPP_LQR)
1105 try.lqr_period = cilong;
1109 * Only implementing CBCP...not the rest of the callback options
1111 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1116 * Check for a looped-back line.
1118 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1119 try.magicnumber = magic();
1124 * Peer shouldn't send Nak for protocol compression or
1125 * address/control compression requests; they should send
1126 * a Reject instead. If they send a Nak, treat it as a Reject.
1128 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1129 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1132 * Nak for MRRU option - accept their value if it is smaller
1133 * than the one we want.
1136 NAKCISHORT(CI_MRRU, neg_mrru,
1137 if (cishort <= wo->mrru)
1143 * Nak for short sequence numbers shouldn't be sent, treat it
1146 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1149 * Nak of the endpoint discriminator option is not permitted,
1150 * treat it like a reject.
1152 NAKCIENDP(CI_EPDISC, neg_endpoint);
1155 * There may be remaining CIs, if the peer is requesting negotiation
1156 * on an option that we didn't include in our request packet.
1157 * If we see an option that we requested, or one we've already seen
1158 * in this packet, then this packet is bad.
1159 * If we wanted to respond by starting to negotiate on the requested
1160 * option(s), we could, but we don't, because except for the
1161 * authentication type and quality protocol, if we are not negotiating
1162 * an option, it is because we were told not to.
1163 * For the authentication type, the Nak from the peer means
1164 * `let me authenticate myself with you' which is a bit pointless.
1165 * For the quality protocol, the Nak means `ask me to send you quality
1166 * reports', but if we didn't ask for them, we don't want them.
1167 * An option we don't recognize represents the peer asking to
1168 * negotiate some option we don't support, so ignore it.
1170 while (len > CILEN_VOID) {
1173 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1175 next = p + cilen - 2;
1179 if ((go->neg_mru && go->mru != DEFMRU)
1180 || no.neg_mru || cilen != CILEN_SHORT)
1182 GETSHORT(cishort, p);
1183 if (cishort < DEFMRU) {
1189 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1190 || no.neg_asyncmap || cilen != CILEN_LONG)
1194 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
1197 case CI_MAGICNUMBER:
1198 if (go->neg_magicnumber || no.neg_magicnumber ||
1199 cilen != CILEN_LONG)
1202 case CI_PCOMPRESSION:
1203 if (go->neg_pcompression || no.neg_pcompression
1204 || cilen != CILEN_VOID)
1207 case CI_ACCOMPRESSION:
1208 if (go->neg_accompression || no.neg_accompression
1209 || cilen != CILEN_VOID)
1213 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1217 if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT)
1221 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1226 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1234 * OK, the Nak is good. Now we can update state.
1235 * If there are any options left we ignore them.
1237 if (f->state != OPENED) {
1239 if (++try.numloops >= lcp_loopbackfail) {
1240 notice("Serial line is looped back.");
1241 lcp_close(f->unit, "Loopback detected");
1242 status = EXIT_LOOPBACK;
1252 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1258 * lcp_rejci - Peer has Rejected some of our CIs.
1259 * This should not modify any state if the Reject is bad
1260 * or if LCP is in the OPENED state.
1263 * 0 - Reject was bad.
1264 * 1 - Reject was good.
1267 lcp_rejci(f, p, len)
1272 lcp_options *go = &lcp_gotoptions[f->unit];
1276 lcp_options try; /* options to request next time */
1281 * Any Rejected CIs must be in exactly the same order that we sent.
1282 * Check packet length and CI length at each step.
1283 * If we find any deviations, then this packet is bad.
1285 #define REJCIVOID(opt, neg) \
1287 len >= CILEN_VOID && \
1288 p[1] == CILEN_VOID && \
1290 len -= CILEN_VOID; \
1291 INCPTR(CILEN_VOID, p); \
1294 #define REJCISHORT(opt, neg, val) \
1296 len >= CILEN_SHORT && \
1297 p[1] == CILEN_SHORT && \
1299 len -= CILEN_SHORT; \
1301 GETSHORT(cishort, p); \
1302 /* Check rejected value. */ \
1303 if (cishort != val) \
1307 #define REJCICHAP(opt, neg, val, digest) \
1309 len >= CILEN_CHAP && \
1310 p[1] == CILEN_CHAP && \
1312 len -= CILEN_CHAP; \
1314 GETSHORT(cishort, p); \
1315 GETCHAR(cichar, p); \
1316 /* Check rejected value. */ \
1317 if (cishort != val || cichar != digest) \
1322 #define REJCILONG(opt, neg, val) \
1324 len >= CILEN_LONG && \
1325 p[1] == CILEN_LONG && \
1327 len -= CILEN_LONG; \
1329 GETLONG(cilong, p); \
1330 /* Check rejected value. */ \
1331 if (cilong != val) \
1335 #define REJCILQR(opt, neg, val) \
1337 len >= CILEN_LQR && \
1338 p[1] == CILEN_LQR && \
1342 GETSHORT(cishort, p); \
1343 GETLONG(cilong, p); \
1344 /* Check rejected value. */ \
1345 if (cishort != PPP_LQR || cilong != val) \
1349 #define REJCICBCP(opt, neg, val) \
1351 len >= CILEN_CBCP && \
1352 p[1] == CILEN_CBCP && \
1354 len -= CILEN_CBCP; \
1356 GETCHAR(cichar, p); \
1357 /* Check rejected value. */ \
1358 if (cichar != val) \
1362 #define REJCIENDP(opt, neg, class, val, vlen) \
1364 len >= CILEN_CHAR + vlen && \
1366 p[1] == CILEN_CHAR + vlen) { \
1368 len -= CILEN_CHAR + vlen; \
1370 GETCHAR(cichar, p); \
1371 if (cichar != class) \
1373 for (i = 0; i < vlen; ++i) { \
1374 GETCHAR(cichar, p); \
1375 if (cichar != val[i]) \
1381 REJCISHORT(CI_MRU, neg_mru, go->mru);
1382 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1383 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
1384 if (!go->neg_chap) {
1385 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1387 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1388 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1389 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1390 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1391 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1392 REJCISHORT(CI_MRRU, neg_mrru, go->mrru);
1393 REJCIVOID(CI_SSNHF, neg_ssnhf);
1394 REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class,
1395 go->endpoint.value, go->endpoint.length);
1398 * If there are any remaining CIs, then this packet is bad.
1403 * Now we can update state.
1405 if (f->state != OPENED)
1410 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1416 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1418 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1419 * appropriately. If reject_if_disagree is non-zero, doesn't return
1420 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1423 lcp_reqci(f, inp, lenp, reject_if_disagree)
1425 u_char *inp; /* Requested CIs */
1426 int *lenp; /* Length of requested CIs */
1427 int reject_if_disagree;
1429 lcp_options *go = &lcp_gotoptions[f->unit];
1430 lcp_options *ho = &lcp_hisoptions[f->unit];
1431 lcp_options *ao = &lcp_allowoptions[f->unit];
1432 u_char *cip, *next; /* Pointer to current and next CIs */
1433 int cilen, citype, cichar; /* Parsed len, type, char value */
1434 u_short cishort; /* Parsed short value */
1435 u_int32_t cilong; /* Parse long value */
1436 int rc = CONFACK; /* Final packet return code */
1437 int orc; /* Individual option return code */
1438 u_char *p; /* Pointer to next char to parse */
1439 u_char *rejp; /* Pointer to next char in reject frame */
1440 u_char *nakp; /* Pointer to next char in Nak frame */
1441 int l = *lenp; /* Length left */
1444 * Reset all his options.
1446 BZERO(ho, sizeof(*ho));
1449 * Process all his options.
1455 orc = CONFACK; /* Assume success */
1456 cip = p = next; /* Remember begining of CI */
1457 if (l < 2 || /* Not enough data for CI header or */
1458 p[1] < 2 || /* CI length too small or */
1459 p[1] > l) { /* CI length too big? */
1460 LCPDEBUG(("lcp_reqci: bad CI length!"));
1461 orc = CONFREJ; /* Reject bad CI */
1462 cilen = l; /* Reject till end of packet */
1463 l = 0; /* Don't loop again */
1467 GETCHAR(citype, p); /* Parse CI type */
1468 GETCHAR(cilen, p); /* Parse CI length */
1469 l -= cilen; /* Adjust remaining length */
1470 next += cilen; /* Step to next CI */
1472 switch (citype) { /* Check CI type */
1474 if (!ao->neg_mru || /* Allow option? */
1475 cilen != CILEN_SHORT) { /* Check CI length */
1476 orc = CONFREJ; /* Reject CI */
1479 GETSHORT(cishort, p); /* Parse MRU */
1482 * He must be able to receive at least our minimum.
1483 * No need to check a maximum. If he sends a large number,
1484 * we'll just ignore it.
1486 if (cishort < MINMRU) {
1487 orc = CONFNAK; /* Nak CI */
1488 PUTCHAR(CI_MRU, nakp);
1489 PUTCHAR(CILEN_SHORT, nakp);
1490 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1493 ho->neg_mru = 1; /* Remember he sent MRU */
1494 ho->mru = cishort; /* And remember value */
1498 if (!ao->neg_asyncmap ||
1499 cilen != CILEN_LONG) {
1506 * Asyncmap must have set at least the bits
1507 * which are set in lcp_allowoptions[unit].asyncmap.
1509 if ((ao->asyncmap & ~cilong) != 0) {
1511 PUTCHAR(CI_ASYNCMAP, nakp);
1512 PUTCHAR(CILEN_LONG, nakp);
1513 PUTLONG(ao->asyncmap | cilong, nakp);
1516 ho->neg_asyncmap = 1;
1517 ho->asyncmap = cilong;
1521 if (cilen < CILEN_SHORT ||
1522 !(ao->neg_upap || ao->neg_chap)) {
1524 * Reject the option if we're not willing to authenticate.
1529 GETSHORT(cishort, p);
1532 * Authtype must be PAP or CHAP.
1534 * Note: if both ao->neg_upap and ao->neg_chap are set,
1535 * and the peer sends a Configure-Request with two
1536 * authenticate-protocol requests, one for CHAP and one
1537 * for UPAP, then we will reject the second request.
1538 * Whether we end up doing CHAP or UPAP depends then on
1539 * the ordering of the CIs in the peer's Configure-Request.
1542 if (cishort == PPP_PAP) {
1543 if (ho->neg_chap || /* we've already accepted CHAP */
1544 cilen != CILEN_SHORT) {
1545 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1549 if (!ao->neg_upap) { /* we don't want to do PAP */
1550 orc = CONFNAK; /* NAK it and suggest CHAP */
1551 PUTCHAR(CI_AUTHTYPE, nakp);
1552 PUTCHAR(CILEN_CHAP, nakp);
1553 PUTSHORT(PPP_CHAP, nakp);
1554 PUTCHAR(ao->chap_mdtype, nakp);
1555 /* XXX if we can do CHAP_MICROSOFT as well, we should
1556 probably put in another option saying so */
1562 if (cishort == PPP_CHAP) {
1563 if (ho->neg_upap || /* we've already accepted PAP */
1564 cilen != CILEN_CHAP) {
1565 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1569 if (!ao->neg_chap) { /* we don't want to do CHAP */
1570 orc = CONFNAK; /* NAK it and suggest PAP */
1571 PUTCHAR(CI_AUTHTYPE, nakp);
1572 PUTCHAR(CILEN_SHORT, nakp);
1573 PUTSHORT(PPP_PAP, nakp);
1576 GETCHAR(cichar, p); /* get digest type*/
1577 if (cichar != CHAP_DIGEST_MD5
1579 && cichar != CHAP_MICROSOFT
1583 PUTCHAR(CI_AUTHTYPE, nakp);
1584 PUTCHAR(CILEN_CHAP, nakp);
1585 PUTSHORT(PPP_CHAP, nakp);
1586 PUTCHAR(ao->chap_mdtype, nakp);
1589 ho->chap_mdtype = cichar; /* save md type */
1595 * We don't recognize the protocol they're asking for.
1596 * Nak it with something we're willing to do.
1597 * (At this point we know ao->neg_upap || ao->neg_chap.)
1600 PUTCHAR(CI_AUTHTYPE, nakp);
1602 PUTCHAR(CILEN_CHAP, nakp);
1603 PUTSHORT(PPP_CHAP, nakp);
1604 PUTCHAR(ao->chap_mdtype, nakp);
1606 PUTCHAR(CILEN_SHORT, nakp);
1607 PUTSHORT(PPP_PAP, nakp);
1613 cilen != CILEN_LQR) {
1618 GETSHORT(cishort, p);
1622 * Check the protocol and the reporting period.
1623 * XXX When should we Nak this, and what with?
1625 if (cishort != PPP_LQR) {
1627 PUTCHAR(CI_QUALITY, nakp);
1628 PUTCHAR(CILEN_LQR, nakp);
1629 PUTSHORT(PPP_LQR, nakp);
1630 PUTLONG(ao->lqr_period, nakp);
1635 case CI_MAGICNUMBER:
1636 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1637 cilen != CILEN_LONG) {
1644 * He must have a different magic number.
1646 if (go->neg_magicnumber &&
1647 cilong == go->magicnumber) {
1648 cilong = magic(); /* Don't put magic() inside macro! */
1650 PUTCHAR(CI_MAGICNUMBER, nakp);
1651 PUTCHAR(CILEN_LONG, nakp);
1652 PUTLONG(cilong, nakp);
1655 ho->neg_magicnumber = 1;
1656 ho->magicnumber = cilong;
1660 case CI_PCOMPRESSION:
1661 if (!ao->neg_pcompression ||
1662 cilen != CILEN_VOID) {
1666 ho->neg_pcompression = 1;
1669 case CI_ACCOMPRESSION:
1670 if (!ao->neg_accompression ||
1671 cilen != CILEN_VOID) {
1675 ho->neg_accompression = 1;
1679 if (!ao->neg_mrru || !multilink ||
1680 cilen != CILEN_SHORT) {
1685 GETSHORT(cishort, p);
1686 /* possibly should insist on a minimum/maximum MRRU here */
1692 if (!ao->neg_ssnhf || !multilink ||
1693 cilen != CILEN_VOID) {
1701 if (!ao->neg_endpoint ||
1702 cilen < CILEN_CHAR ||
1703 cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1708 cilen -= CILEN_CHAR;
1709 ho->neg_endpoint = 1;
1710 ho->endpoint.class = cichar;
1711 ho->endpoint.length = cilen;
1712 BCOPY(p, ho->endpoint.value, cilen);
1717 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1723 if (orc == CONFACK && /* Good CI */
1724 rc != CONFACK) /* but prior CI wasnt? */
1725 continue; /* Don't send this one */
1727 if (orc == CONFNAK) { /* Nak this CI? */
1728 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1729 && citype != CI_MAGICNUMBER) {
1730 orc = CONFREJ; /* Get tough if so */
1732 if (rc == CONFREJ) /* Rejecting prior CI? */
1733 continue; /* Don't send this one */
1737 if (orc == CONFREJ) { /* Reject this CI */
1739 if (cip != rejp) /* Need to move rejected CI? */
1740 BCOPY(cip, rejp, cilen); /* Move it */
1741 INCPTR(cilen, rejp); /* Update output pointer */
1746 * If we wanted to send additional NAKs (for unsent CIs), the
1747 * code would go here. The extra NAKs would go at *nakp.
1748 * At present there are no cases where we want to ask the
1749 * peer to negotiate an option.
1758 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1760 *lenp = nakp - nak_buffer;
1761 BCOPY(nak_buffer, inp, *lenp);
1768 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1769 return (rc); /* Return final code */
1774 * lcp_up - LCP has come UP.
1780 lcp_options *wo = &lcp_wantoptions[f->unit];
1781 lcp_options *ho = &lcp_hisoptions[f->unit];
1782 lcp_options *go = &lcp_gotoptions[f->unit];
1783 lcp_options *ao = &lcp_allowoptions[f->unit];
1785 if (!go->neg_magicnumber)
1786 go->magicnumber = 0;
1787 if (!ho->neg_magicnumber)
1788 ho->magicnumber = 0;
1791 * Set our MTU to the smaller of the MTU we wanted and
1792 * the MRU our peer wanted. If we negotiated an MRU,
1793 * set our MRU to the larger of value we wanted and
1794 * the value we got in the negotiation.
1796 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
1797 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1798 ho->neg_pcompression, ho->neg_accompression);
1799 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
1800 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
1801 go->neg_pcompression, go->neg_accompression);
1804 peer_mru[f->unit] = ho->mru;
1806 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1808 link_established(f->unit);
1813 * lcp_down - LCP has gone DOWN.
1815 * Alert other protocols.
1821 lcp_options *go = &lcp_gotoptions[f->unit];
1823 lcp_echo_lowerdown(f->unit);
1827 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1828 ppp_recv_config(f->unit, PPP_MRU,
1829 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1830 go->neg_pcompression, go->neg_accompression);
1831 peer_mru[f->unit] = PPP_MRU;
1836 * lcp_starting - LCP needs the lower layer up.
1842 link_required(f->unit);
1847 * lcp_finished - LCP has finished with the lower layer.
1853 link_terminated(f->unit);
1858 * lcp_printpkt - print the contents of an LCP packet.
1860 static char *lcp_codenames[] = {
1861 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1862 "TermReq", "TermAck", "CodeRej", "ProtRej",
1863 "EchoReq", "EchoRep", "DiscReq"
1867 lcp_printpkt(p, plen, printer, arg)
1870 void (*printer) __P((void *, char *, ...));
1873 int code, id, len, olen, i;
1874 u_char *pstart, *optend;
1878 if (plen < HEADERLEN)
1884 if (len < HEADERLEN || len > plen)
1887 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1888 printer(arg, " %s", lcp_codenames[code-1]);
1890 printer(arg, " code=0x%x", code);
1891 printer(arg, " id=0x%x", id);
1898 /* print option list */
1903 if (olen < 2 || olen > len) {
1911 if (olen == CILEN_SHORT) {
1913 GETSHORT(cishort, p);
1914 printer(arg, "mru %d", cishort);
1918 if (olen == CILEN_LONG) {
1921 printer(arg, "asyncmap 0x%x", cilong);
1925 if (olen >= CILEN_SHORT) {
1927 printer(arg, "auth ");
1928 GETSHORT(cishort, p);
1931 printer(arg, "pap");
1934 printer(arg, "chap");
1937 case CHAP_DIGEST_MD5:
1938 printer(arg, " MD5");
1942 case CHAP_MICROSOFT:
1943 printer(arg, " m$oft");
1951 printer(arg, "0x%x", cishort);
1956 if (olen >= CILEN_SHORT) {
1958 printer(arg, "quality ");
1959 GETSHORT(cishort, p);
1962 printer(arg, "lqr");
1965 printer(arg, "0x%x", cishort);
1970 if (olen >= CILEN_CHAR) {
1972 printer(arg, "callback ");
1973 GETCHAR(cishort, p);
1976 printer(arg, "CBCP");
1979 printer(arg, "0x%x", cishort);
1983 case CI_MAGICNUMBER:
1984 if (olen == CILEN_LONG) {
1987 printer(arg, "magic 0x%x", cilong);
1990 case CI_PCOMPRESSION:
1991 if (olen == CILEN_VOID) {
1993 printer(arg, "pcomp");
1996 case CI_ACCOMPRESSION:
1997 if (olen == CILEN_VOID) {
1999 printer(arg, "accomp");
2003 if (olen == CILEN_SHORT) {
2005 GETSHORT(cishort, p);
2006 printer(arg, "mrru %d", cishort);
2010 if (olen == CILEN_VOID) {
2012 printer(arg, "ssnhf");
2016 #ifdef HAVE_MULTILINK
2017 if (olen >= CILEN_CHAR) {
2020 GETCHAR(epd.class, p);
2021 epd.length = olen - CILEN_CHAR;
2022 if (epd.length > MAX_ENDP_LEN)
2023 epd.length = MAX_ENDP_LEN;
2024 if (epd.length > 0) {
2025 BCOPY(p, epd.value, epd.length);
2028 printer(arg, "endpoint [%s]", epdisc_to_str(&epd));
2031 printer(arg, "endpoint");
2035 while (p < optend) {
2037 printer(arg, " %.2x", code);
2045 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2047 print_string((char *)p, len, printer, arg);
2058 printer(arg, " magic=0x%x", cilong);
2065 /* print the rest of the bytes in the packet */
2066 for (i = 0; i < len && i < 32; ++i) {
2068 printer(arg, " %.2x", code);
2071 printer(arg, " ...");
2079 * Time to shut down the link because there is nothing out there.
2083 void LcpLinkFailure (f)
2086 if (f->state == OPENED) {
2087 info("No response to %d echo-requests", lcp_echos_pending);
2088 notice("Serial link appears to be disconnected.");
2089 lcp_close(f->unit, "Peer not responding");
2090 status = EXIT_PEER_DEAD;
2095 * Timer expired for the LCP echo requests from this process.
2102 LcpSendEchoRequest (f);
2103 if (f->state != OPENED)
2107 * Start the timer for the next interval.
2109 if (lcp_echo_timer_running)
2110 warn("assertion lcp_echo_timer_running==0 failed");
2111 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2112 lcp_echo_timer_running = 1;
2116 * LcpEchoTimeout - Timer expired on the LCP echo
2120 LcpEchoTimeout (arg)
2123 if (lcp_echo_timer_running != 0) {
2124 lcp_echo_timer_running = 0;
2125 LcpEchoCheck ((fsm *) arg);
2130 * LcpEchoReply - LCP has received a reply to the echo
2134 lcp_received_echo_reply (f, id, inp, len)
2142 /* Check the magic number - don't count replies from ourselves. */
2144 dbglog("lcp: received short Echo-Reply, length %d", len);
2147 GETLONG(magic, inp);
2148 if (lcp_gotoptions[f->unit].neg_magicnumber
2149 && magic == lcp_gotoptions[f->unit].magicnumber) {
2150 warn("appear to have received our own echo-reply!");
2154 /* Reset the number of outstanding echo frames */
2155 lcp_echos_pending = 0;
2159 * LcpSendEchoRequest - Send an echo request frame to the peer
2163 LcpSendEchoRequest (f)
2166 u_int32_t lcp_magic;
2167 u_char pkt[4], *pktp;
2170 * Detect the failure of the peer at this point.
2172 if (lcp_echo_fails != 0) {
2173 if (lcp_echos_pending >= lcp_echo_fails) {
2175 lcp_echos_pending = 0;
2180 * Make and send the echo request frame.
2182 if (f->state == OPENED) {
2183 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2185 PUTLONG(lcp_magic, pktp);
2186 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2187 ++lcp_echos_pending;
2192 * lcp_echo_lowerup - Start the timer for the LCP frame
2196 lcp_echo_lowerup (unit)
2199 fsm *f = &lcp_fsm[unit];
2201 /* Clear the parameters for generating echo frames */
2202 lcp_echos_pending = 0;
2203 lcp_echo_number = 0;
2204 lcp_echo_timer_running = 0;
2206 /* If a timeout interval is specified then start the timer */
2207 if (lcp_echo_interval != 0)
2212 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2216 lcp_echo_lowerdown (unit)
2219 fsm *f = &lcp_fsm[unit];
2221 if (lcp_echo_timer_running != 0) {
2222 UNTIMEOUT (LcpEchoTimeout, f);
2223 lcp_echo_timer_running = 0;