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.60 2002/04/02 13:54:59 dfs 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;
341 ao->neg_magicnumber = 1;
342 ao->neg_pcompression = 1;
343 ao->neg_accompression = 1;
347 ao->neg_endpoint = 1;
352 * lcp_open - LCP is allowed to come up.
358 fsm *f = &lcp_fsm[unit];
359 lcp_options *wo = &lcp_wantoptions[unit];
361 f->flags &= ~(OPT_PASSIVE | OPT_SILENT);
363 f->flags |= OPT_PASSIVE;
365 f->flags |= OPT_SILENT;
371 * lcp_close - Take LCP down.
374 lcp_close(unit, reason)
378 fsm *f = &lcp_fsm[unit];
380 if (phase != PHASE_DEAD)
381 new_phase(PHASE_TERMINATE);
382 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
384 * This action is not strictly according to the FSM in RFC1548,
385 * but it does mean that the program terminates if you do a
386 * lcp_close() in passive/silent mode when a connection hasn't
393 fsm_close(&lcp_fsm[unit], reason);
398 * lcp_lowerup - The lower layer is up.
404 lcp_options *wo = &lcp_wantoptions[unit];
405 fsm *f = &lcp_fsm[unit];
408 * Don't use A/C or protocol compression on transmission,
409 * but accept A/C and protocol compressed packets
410 * if we are going to ask for A/C and protocol compression.
412 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
413 ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
414 wo->neg_pcompression, wo->neg_accompression);
415 peer_mru[unit] = PPP_MRU;
417 if (listen_time != 0) {
418 f->flags |= DELAYED_UP;
419 timeout(lcp_delayed_up, f, 0, listen_time * 1000);
426 * lcp_lowerdown - The lower layer is down.
432 fsm *f = &lcp_fsm[unit];
434 if (f->flags & DELAYED_UP)
435 f->flags &= ~DELAYED_UP;
437 fsm_lowerdown(&lcp_fsm[unit]);
442 * lcp_delayed_up - Bring the lower layer up now.
450 if (f->flags & DELAYED_UP) {
451 f->flags &= ~DELAYED_UP;
458 * lcp_input - Input LCP packet.
461 lcp_input(unit, p, len)
466 fsm *f = &lcp_fsm[unit];
468 if (f->flags & DELAYED_UP) {
469 f->flags &= ~DELAYED_UP;
472 fsm_input(f, p, len);
477 * lcp_extcode - Handle a LCP-specific code.
480 lcp_extcode(f, code, id, inp, len)
490 lcp_rprotrej(f, inp, len);
494 if (f->state != OPENED)
497 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
498 fsm_sdata(f, ECHOREP, id, inp, len);
502 lcp_received_echo_reply(f, id, inp, len);
516 * lcp_rprotrej - Receive an Protocol-Reject.
518 * Figure out which protocol is rejected and inform it.
521 lcp_rprotrej(f, inp, len)
527 struct protent *protp;
531 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
538 * Protocol-Reject packets received in any state other than the LCP
539 * OPENED state SHOULD be silently discarded.
541 if( f->state != OPENED ){
542 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
547 * Upcall the proper Protocol-Reject routine.
549 for (i = 0; (protp = protocols[i]) != NULL; ++i)
550 if (protp->protocol == prot && protp->enabled_flag) {
551 (*protp->protrej)(f->unit);
555 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
560 * lcp_protrej - A Protocol-Reject was received.
570 error("Received Protocol-Reject for LCP!");
571 fsm_protreject(&lcp_fsm[unit]);
576 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
579 lcp_sprotrej(unit, p, len)
585 * Send back the protocol and the information field of the
586 * rejected packet. We only get here if LCP is in the OPENED state.
591 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
597 * lcp_resetci - Reset our CI.
603 lcp_options *wo = &lcp_wantoptions[f->unit];
604 lcp_options *go = &lcp_gotoptions[f->unit];
605 lcp_options *ao = &lcp_allowoptions[f->unit];
607 wo->magicnumber = magic();
613 go->neg_endpoint = 0;
616 ao->neg_endpoint = 0;
617 peer_mru[f->unit] = PPP_MRU;
623 * lcp_cilen - Return length of our CI.
629 lcp_options *go = &lcp_gotoptions[f->unit];
631 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
632 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
633 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
634 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
635 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
636 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
638 * NB: we only ask for one of CHAP and UPAP, even if we will
641 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
642 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
643 LENCICHAP(go->neg_chap) +
644 LENCISHORT(!go->neg_chap && go->neg_upap) +
645 LENCILQR(go->neg_lqr) +
646 LENCICBCP(go->neg_cbcp) +
647 LENCILONG(go->neg_magicnumber) +
648 LENCIVOID(go->neg_pcompression) +
649 LENCIVOID(go->neg_accompression) +
650 LENCISHORT(go->neg_mrru) +
651 LENCIVOID(go->neg_ssnhf) +
652 (go->neg_endpoint? CILEN_CHAR + go->endpoint.length: 0));
657 * lcp_addci - Add our desired CIs to a packet.
660 lcp_addci(f, ucp, lenp)
665 lcp_options *go = &lcp_gotoptions[f->unit];
666 u_char *start_ucp = ucp;
668 #define ADDCIVOID(opt, neg) \
671 PUTCHAR(CILEN_VOID, ucp); \
673 #define ADDCISHORT(opt, neg, val) \
676 PUTCHAR(CILEN_SHORT, ucp); \
677 PUTSHORT(val, ucp); \
679 #define ADDCICHAP(opt, neg, val, digest) \
681 PUTCHAR((opt), ucp); \
682 PUTCHAR(CILEN_CHAP, ucp); \
683 PUTSHORT((val), ucp); \
684 PUTCHAR((digest), ucp); \
686 #define ADDCILONG(opt, neg, val) \
689 PUTCHAR(CILEN_LONG, ucp); \
692 #define ADDCILQR(opt, neg, val) \
695 PUTCHAR(CILEN_LQR, ucp); \
696 PUTSHORT(PPP_LQR, ucp); \
699 #define ADDCICHAR(opt, neg, val) \
702 PUTCHAR(CILEN_CHAR, ucp); \
705 #define ADDCIENDP(opt, neg, class, val, len) \
709 PUTCHAR(CILEN_CHAR + len, ucp); \
710 PUTCHAR(class, ucp); \
711 for (i = 0; i < len; ++i) \
712 PUTCHAR(val[i], ucp); \
715 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
716 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
718 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP,CHAP_DIGEST(go->chap_mdtype));
719 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
720 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
721 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
722 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
723 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
724 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
725 ADDCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
726 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
727 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
728 go->endpoint.value, go->endpoint.length);
730 if (ucp - start_ucp != *lenp) {
731 /* this should never happen, because peer_mtu should be 1500 */
732 error("Bug in lcp_addci: wrong length");
738 * lcp_ackci - Ack our CIs.
739 * This should not modify any state if the Ack is bad.
751 lcp_options *go = &lcp_gotoptions[f->unit];
752 u_char cilen, citype, cichar;
757 * CIs must be in exactly the same order that we sent.
758 * Check packet length and CI length at each step.
759 * If we find any deviations, then this packet is bad.
761 #define ACKCIVOID(opt, neg) \
763 if ((len -= CILEN_VOID) < 0) \
765 GETCHAR(citype, p); \
767 if (cilen != CILEN_VOID || \
771 #define ACKCISHORT(opt, neg, val) \
773 if ((len -= CILEN_SHORT) < 0) \
775 GETCHAR(citype, p); \
777 if (cilen != CILEN_SHORT || \
780 GETSHORT(cishort, p); \
781 if (cishort != val) \
784 #define ACKCICHAR(opt, neg, val) \
786 if ((len -= CILEN_CHAR) < 0) \
788 GETCHAR(citype, p); \
790 if (cilen != CILEN_CHAR || \
793 GETCHAR(cichar, p); \
797 #define ACKCICHAP(opt, neg, val, digest) \
799 if ((len -= CILEN_CHAP) < 0) \
801 GETCHAR(citype, p); \
803 if (cilen != CILEN_CHAP || \
806 GETSHORT(cishort, p); \
807 if (cishort != (val)) \
809 GETCHAR(cichar, p); \
810 if (cichar != (digest)) \
813 #define ACKCILONG(opt, neg, val) \
815 if ((len -= CILEN_LONG) < 0) \
817 GETCHAR(citype, p); \
819 if (cilen != CILEN_LONG || \
822 GETLONG(cilong, p); \
826 #define ACKCILQR(opt, neg, val) \
828 if ((len -= CILEN_LQR) < 0) \
830 GETCHAR(citype, p); \
832 if (cilen != CILEN_LQR || \
835 GETSHORT(cishort, p); \
836 if (cishort != PPP_LQR) \
838 GETLONG(cilong, p); \
842 #define ACKCIENDP(opt, neg, class, val, vlen) \
845 if ((len -= CILEN_CHAR + vlen) < 0) \
847 GETCHAR(citype, p); \
849 if (cilen != CILEN_CHAR + vlen || \
852 GETCHAR(cichar, p); \
853 if (cichar != class) \
855 for (i = 0; i < vlen; ++i) { \
856 GETCHAR(cichar, p); \
857 if (cichar != val[i]) \
862 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
863 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
865 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP,CHAP_DIGEST(go->chap_mdtype));
866 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
867 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
868 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
869 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
870 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
871 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
872 ACKCISHORT(CI_MRRU, go->neg_mrru, go->mrru);
873 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
874 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endpoint.class,
875 go->endpoint.value, go->endpoint.length);
878 * If there are any remaining CIs, then this packet is bad.
884 LCPDEBUG(("lcp_acki: received bad Ack!"));
890 * lcp_nakci - Peer has sent a NAK for some of our CIs.
891 * This should not modify any state if the Nak is bad
892 * or if LCP is in the OPENED state.
904 lcp_options *go = &lcp_gotoptions[f->unit];
905 lcp_options *wo = &lcp_wantoptions[f->unit];
906 u_char citype, cichar, *next;
909 lcp_options no; /* options we've seen Naks for */
910 lcp_options try; /* options to request next time */
914 BZERO(&no, sizeof(no));
918 * Any Nak'd CIs must be in exactly the same order that we sent.
919 * Check packet length and CI length at each step.
920 * If we find any deviations, then this packet is bad.
922 #define NAKCIVOID(opt, neg) \
924 len >= CILEN_VOID && \
925 p[1] == CILEN_VOID && \
928 INCPTR(CILEN_VOID, p); \
932 #define NAKCICHAP(opt, neg, code) \
934 len >= CILEN_CHAP && \
935 p[1] == CILEN_CHAP && \
939 GETSHORT(cishort, p); \
940 GETCHAR(cichar, p); \
944 #define NAKCICHAR(opt, neg, code) \
946 len >= CILEN_CHAR && \
947 p[1] == CILEN_CHAR && \
951 GETCHAR(cichar, p); \
955 #define NAKCISHORT(opt, neg, code) \
957 len >= CILEN_SHORT && \
958 p[1] == CILEN_SHORT && \
960 len -= CILEN_SHORT; \
962 GETSHORT(cishort, p); \
966 #define NAKCILONG(opt, neg, code) \
968 len >= CILEN_LONG && \
969 p[1] == CILEN_LONG && \
973 GETLONG(cilong, p); \
977 #define NAKCILQR(opt, neg, code) \
979 len >= CILEN_LQR && \
980 p[1] == CILEN_LQR && \
984 GETSHORT(cishort, p); \
985 GETLONG(cilong, p); \
989 #define NAKCIENDP(opt, neg) \
991 len >= CILEN_CHAR && \
993 p[1] >= CILEN_CHAR && \
1002 * We don't care if they want to send us smaller packets than
1003 * we want. Therefore, accept any MRU less than what we asked for,
1004 * but then ignore the new value when setting the MRU in the kernel.
1005 * If they send us a bigger MRU than what we asked, accept it, up to
1006 * the limit of the default MRU we'd get if we didn't negotiate.
1008 if (go->neg_mru && go->mru != DEFMRU) {
1009 NAKCISHORT(CI_MRU, neg_mru,
1010 if (cishort <= wo->mru || cishort <= DEFMRU)
1016 * Add any characters they want to our (receive-side) asyncmap.
1018 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
1019 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
1020 try.asyncmap = go->asyncmap | cilong;
1025 * If they've nak'd our authentication-protocol, check whether
1026 * they are proposing a different protocol, or a different
1027 * hash algorithm for CHAP.
1029 if ((go->neg_chap || go->neg_upap)
1030 && len >= CILEN_SHORT
1031 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
1034 no.neg_chap = go->neg_chap;
1035 no.neg_upap = go->neg_upap;
1037 GETSHORT(cishort, p);
1038 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
1040 * If we were asking for CHAP, they obviously don't want to do it.
1041 * If we weren't asking for CHAP, then we were asking for PAP,
1042 * in which case this Nak is bad.
1048 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
1052 * We were asking for our preferred algorithm, they must
1053 * want something different.
1055 if (cichar != CHAP_DIGEST(go->chap_mdtype)) {
1056 if (CHAP_CANDIGEST(go->chap_mdtype, cichar)) {
1057 /* Use their suggestion if we support it ... */
1058 go->chap_mdtype = CHAP_MDTYPE_D(cichar);
1060 /* ... otherwise, try our next-preferred algorithm. */
1061 go->chap_mdtype &= ~(CHAP_MDTYPE(go->chap_mdtype));
1062 if (go->chap_mdtype == MDTYPE_NONE) /* out of algos */
1067 * Whoops, they Nak'd our algorithm of choice
1068 * but then suggested it back to us.
1074 * Stop asking for PAP if we were asking for it.
1081 * We don't recognize what they're suggesting.
1082 * Stop asking for what we were asking for.
1088 p += cilen - CILEN_SHORT;
1093 * If they can't cope with our link quality protocol, we'll have
1094 * to stop asking for LQR. We haven't got any other protocol.
1095 * If they Nak the reporting period, take their value XXX ?
1097 NAKCILQR(CI_QUALITY, neg_lqr,
1098 if (cishort != PPP_LQR)
1101 try.lqr_period = cilong;
1105 * Only implementing CBCP...not the rest of the callback options
1107 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1112 * Check for a looped-back line.
1114 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1115 try.magicnumber = magic();
1120 * Peer shouldn't send Nak for protocol compression or
1121 * address/control compression requests; they should send
1122 * a Reject instead. If they send a Nak, treat it as a Reject.
1124 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1125 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1128 * Nak for MRRU option - accept their value if it is smaller
1129 * than the one we want.
1132 NAKCISHORT(CI_MRRU, neg_mrru,
1133 if (cishort <= wo->mrru)
1139 * Nak for short sequence numbers shouldn't be sent, treat it
1142 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1145 * Nak of the endpoint discriminator option is not permitted,
1146 * treat it like a reject.
1148 NAKCIENDP(CI_EPDISC, neg_endpoint);
1151 * There may be remaining CIs, if the peer is requesting negotiation
1152 * on an option that we didn't include in our request packet.
1153 * If we see an option that we requested, or one we've already seen
1154 * in this packet, then this packet is bad.
1155 * If we wanted to respond by starting to negotiate on the requested
1156 * option(s), we could, but we don't, because except for the
1157 * authentication type and quality protocol, if we are not negotiating
1158 * an option, it is because we were told not to.
1159 * For the authentication type, the Nak from the peer means
1160 * `let me authenticate myself with you' which is a bit pointless.
1161 * For the quality protocol, the Nak means `ask me to send you quality
1162 * reports', but if we didn't ask for them, we don't want them.
1163 * An option we don't recognize represents the peer asking to
1164 * negotiate some option we don't support, so ignore it.
1166 while (len > CILEN_VOID) {
1169 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1171 next = p + cilen - 2;
1175 if ((go->neg_mru && go->mru != DEFMRU)
1176 || no.neg_mru || cilen != CILEN_SHORT)
1178 GETSHORT(cishort, p);
1179 if (cishort < DEFMRU) {
1185 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1186 || no.neg_asyncmap || cilen != CILEN_LONG)
1190 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
1193 case CI_MAGICNUMBER:
1194 if (go->neg_magicnumber || no.neg_magicnumber ||
1195 cilen != CILEN_LONG)
1198 case CI_PCOMPRESSION:
1199 if (go->neg_pcompression || no.neg_pcompression
1200 || cilen != CILEN_VOID)
1203 case CI_ACCOMPRESSION:
1204 if (go->neg_accompression || no.neg_accompression
1205 || cilen != CILEN_VOID)
1209 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1213 if (go->neg_mrru || no.neg_mrru || cilen != CILEN_SHORT)
1217 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1222 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1230 * OK, the Nak is good. Now we can update state.
1231 * If there are any options left we ignore them.
1233 if (f->state != OPENED) {
1235 if (++try.numloops >= lcp_loopbackfail) {
1236 notice("Serial line is looped back.");
1237 lcp_close(f->unit, "Loopback detected");
1238 status = EXIT_LOOPBACK;
1248 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1254 * lcp_rejci - Peer has Rejected some of our CIs.
1255 * This should not modify any state if the Reject is bad
1256 * or if LCP is in the OPENED state.
1259 * 0 - Reject was bad.
1260 * 1 - Reject was good.
1263 lcp_rejci(f, p, len)
1268 lcp_options *go = &lcp_gotoptions[f->unit];
1272 lcp_options try; /* options to request next time */
1277 * Any Rejected CIs must be in exactly the same order that we sent.
1278 * Check packet length and CI length at each step.
1279 * If we find any deviations, then this packet is bad.
1281 #define REJCIVOID(opt, neg) \
1283 len >= CILEN_VOID && \
1284 p[1] == CILEN_VOID && \
1286 len -= CILEN_VOID; \
1287 INCPTR(CILEN_VOID, p); \
1290 #define REJCISHORT(opt, neg, val) \
1292 len >= CILEN_SHORT && \
1293 p[1] == CILEN_SHORT && \
1295 len -= CILEN_SHORT; \
1297 GETSHORT(cishort, p); \
1298 /* Check rejected value. */ \
1299 if (cishort != val) \
1303 #define REJCICHAP(opt, neg, val, digest) \
1305 len >= CILEN_CHAP && \
1306 p[1] == CILEN_CHAP && \
1308 len -= CILEN_CHAP; \
1310 GETSHORT(cishort, p); \
1311 GETCHAR(cichar, p); \
1312 /* Check rejected value. */ \
1313 if ((cishort != (val)) || (cichar != (digest))) \
1318 #define REJCILONG(opt, neg, val) \
1320 len >= CILEN_LONG && \
1321 p[1] == CILEN_LONG && \
1323 len -= CILEN_LONG; \
1325 GETLONG(cilong, p); \
1326 /* Check rejected value. */ \
1327 if (cilong != val) \
1331 #define REJCILQR(opt, neg, val) \
1333 len >= CILEN_LQR && \
1334 p[1] == CILEN_LQR && \
1338 GETSHORT(cishort, p); \
1339 GETLONG(cilong, p); \
1340 /* Check rejected value. */ \
1341 if (cishort != PPP_LQR || cilong != val) \
1345 #define REJCICBCP(opt, neg, val) \
1347 len >= CILEN_CBCP && \
1348 p[1] == CILEN_CBCP && \
1350 len -= CILEN_CBCP; \
1352 GETCHAR(cichar, p); \
1353 /* Check rejected value. */ \
1354 if (cichar != val) \
1358 #define REJCIENDP(opt, neg, class, val, vlen) \
1360 len >= CILEN_CHAR + vlen && \
1362 p[1] == CILEN_CHAR + vlen) { \
1364 len -= CILEN_CHAR + vlen; \
1366 GETCHAR(cichar, p); \
1367 if (cichar != class) \
1369 for (i = 0; i < vlen; ++i) { \
1370 GETCHAR(cichar, p); \
1371 if (cichar != val[i]) \
1377 REJCISHORT(CI_MRU, neg_mru, go->mru);
1378 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1379 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, CHAP_DIGEST(go->chap_mdtype));
1380 if (!go->neg_chap) {
1381 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1383 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1384 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1385 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1386 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1387 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1388 REJCISHORT(CI_MRRU, neg_mrru, go->mrru);
1389 REJCIVOID(CI_SSNHF, neg_ssnhf);
1390 REJCIENDP(CI_EPDISC, neg_endpoint, go->endpoint.class,
1391 go->endpoint.value, go->endpoint.length);
1394 * If there are any remaining CIs, then this packet is bad.
1399 * Now we can update state.
1401 if (f->state != OPENED)
1406 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1412 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1414 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1415 * appropriately. If reject_if_disagree is non-zero, doesn't return
1416 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1419 lcp_reqci(f, inp, lenp, reject_if_disagree)
1421 u_char *inp; /* Requested CIs */
1422 int *lenp; /* Length of requested CIs */
1423 int reject_if_disagree;
1425 lcp_options *go = &lcp_gotoptions[f->unit];
1426 lcp_options *ho = &lcp_hisoptions[f->unit];
1427 lcp_options *ao = &lcp_allowoptions[f->unit];
1428 u_char *cip, *next; /* Pointer to current and next CIs */
1429 int cilen, citype, cichar; /* Parsed len, type, char value */
1430 u_short cishort; /* Parsed short value */
1431 u_int32_t cilong; /* Parse long value */
1432 int rc = CONFACK; /* Final packet return code */
1433 int orc; /* Individual option return code */
1434 u_char *p; /* Pointer to next char to parse */
1435 u_char *rejp; /* Pointer to next char in reject frame */
1436 u_char *nakp; /* Pointer to next char in Nak frame */
1437 int l = *lenp; /* Length left */
1440 * Reset all his options.
1442 BZERO(ho, sizeof(*ho));
1445 * Process all his options.
1451 orc = CONFACK; /* Assume success */
1452 cip = p = next; /* Remember begining of CI */
1453 if (l < 2 || /* Not enough data for CI header or */
1454 p[1] < 2 || /* CI length too small or */
1455 p[1] > l) { /* CI length too big? */
1456 LCPDEBUG(("lcp_reqci: bad CI length!"));
1457 orc = CONFREJ; /* Reject bad CI */
1458 cilen = l; /* Reject till end of packet */
1459 l = 0; /* Don't loop again */
1463 GETCHAR(citype, p); /* Parse CI type */
1464 GETCHAR(cilen, p); /* Parse CI length */
1465 l -= cilen; /* Adjust remaining length */
1466 next += cilen; /* Step to next CI */
1468 switch (citype) { /* Check CI type */
1470 if (!ao->neg_mru || /* Allow option? */
1471 cilen != CILEN_SHORT) { /* Check CI length */
1472 orc = CONFREJ; /* Reject CI */
1475 GETSHORT(cishort, p); /* Parse MRU */
1478 * He must be able to receive at least our minimum.
1479 * No need to check a maximum. If he sends a large number,
1480 * we'll just ignore it.
1482 if (cishort < MINMRU) {
1483 orc = CONFNAK; /* Nak CI */
1484 PUTCHAR(CI_MRU, nakp);
1485 PUTCHAR(CILEN_SHORT, nakp);
1486 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1489 ho->neg_mru = 1; /* Remember he sent MRU */
1490 ho->mru = cishort; /* And remember value */
1494 if (!ao->neg_asyncmap ||
1495 cilen != CILEN_LONG) {
1502 * Asyncmap must have set at least the bits
1503 * which are set in lcp_allowoptions[unit].asyncmap.
1505 if ((ao->asyncmap & ~cilong) != 0) {
1507 PUTCHAR(CI_ASYNCMAP, nakp);
1508 PUTCHAR(CILEN_LONG, nakp);
1509 PUTLONG(ao->asyncmap | cilong, nakp);
1512 ho->neg_asyncmap = 1;
1513 ho->asyncmap = cilong;
1517 if (cilen < CILEN_SHORT ||
1518 !(ao->neg_upap || ao->neg_chap)) {
1520 * Reject the option if we're not willing to authenticate.
1525 GETSHORT(cishort, p);
1528 * Authtype must be PAP or CHAP.
1530 * Note: if both ao->neg_upap and ao->neg_chap are set,
1531 * and the peer sends a Configure-Request with two
1532 * authenticate-protocol requests, one for CHAP and one
1533 * for UPAP, then we will reject the second request.
1534 * Whether we end up doing CHAP or UPAP depends then on
1535 * the ordering of the CIs in the peer's Configure-Request.
1538 if (cishort == PPP_PAP) {
1539 if (ho->neg_chap || /* we've already accepted CHAP */
1540 cilen != CILEN_SHORT) {
1541 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1545 if (!ao->neg_upap) { /* we don't want to do PAP */
1546 orc = CONFNAK; /* NAK it and suggest CHAP */
1547 PUTCHAR(CI_AUTHTYPE, nakp);
1548 PUTCHAR(CILEN_CHAP, nakp);
1549 PUTSHORT(PPP_CHAP, nakp);
1550 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1556 if (cishort == PPP_CHAP) {
1557 if (ho->neg_upap || /* we've already accepted PAP */
1558 cilen != CILEN_CHAP) {
1559 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1563 if (!ao->neg_chap) { /* we don't want to do CHAP */
1564 orc = CONFNAK; /* NAK it and suggest PAP */
1565 PUTCHAR(CI_AUTHTYPE, nakp);
1566 PUTCHAR(CILEN_SHORT, nakp);
1567 PUTSHORT(PPP_PAP, nakp);
1570 GETCHAR(cichar, p); /* get digest type */
1571 if (!(CHAP_CANDIGEST(ao->chap_mdtype, cichar))) {
1573 * We can't/won't do the requested type,
1574 * suggest something else.
1577 PUTCHAR(CI_AUTHTYPE, nakp);
1578 PUTCHAR(CILEN_CHAP, nakp);
1579 PUTSHORT(PPP_CHAP, nakp);
1580 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1583 ho->chap_mdtype = CHAP_MDTYPE_D(cichar); /* save md type */
1589 * We don't recognize the protocol they're asking for.
1590 * Nak it with something we're willing to do.
1591 * (At this point we know ao->neg_upap || ao->neg_chap.)
1594 PUTCHAR(CI_AUTHTYPE, nakp);
1596 PUTCHAR(CILEN_CHAP, nakp);
1597 PUTSHORT(PPP_CHAP, nakp);
1598 PUTCHAR(CHAP_DIGEST(ao->chap_mdtype), nakp);
1600 PUTCHAR(CILEN_SHORT, nakp);
1601 PUTSHORT(PPP_PAP, nakp);
1607 cilen != CILEN_LQR) {
1612 GETSHORT(cishort, p);
1616 * Check the protocol and the reporting period.
1617 * XXX When should we Nak this, and what with?
1619 if (cishort != PPP_LQR) {
1621 PUTCHAR(CI_QUALITY, nakp);
1622 PUTCHAR(CILEN_LQR, nakp);
1623 PUTSHORT(PPP_LQR, nakp);
1624 PUTLONG(ao->lqr_period, nakp);
1629 case CI_MAGICNUMBER:
1630 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1631 cilen != CILEN_LONG) {
1638 * He must have a different magic number.
1640 if (go->neg_magicnumber &&
1641 cilong == go->magicnumber) {
1642 cilong = magic(); /* Don't put magic() inside macro! */
1644 PUTCHAR(CI_MAGICNUMBER, nakp);
1645 PUTCHAR(CILEN_LONG, nakp);
1646 PUTLONG(cilong, nakp);
1649 ho->neg_magicnumber = 1;
1650 ho->magicnumber = cilong;
1654 case CI_PCOMPRESSION:
1655 if (!ao->neg_pcompression ||
1656 cilen != CILEN_VOID) {
1660 ho->neg_pcompression = 1;
1663 case CI_ACCOMPRESSION:
1664 if (!ao->neg_accompression ||
1665 cilen != CILEN_VOID) {
1669 ho->neg_accompression = 1;
1673 if (!ao->neg_mrru || !multilink ||
1674 cilen != CILEN_SHORT) {
1679 GETSHORT(cishort, p);
1680 /* possibly should insist on a minimum/maximum MRRU here */
1686 if (!ao->neg_ssnhf || !multilink ||
1687 cilen != CILEN_VOID) {
1695 if (!ao->neg_endpoint ||
1696 cilen < CILEN_CHAR ||
1697 cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1702 cilen -= CILEN_CHAR;
1703 ho->neg_endpoint = 1;
1704 ho->endpoint.class = cichar;
1705 ho->endpoint.length = cilen;
1706 BCOPY(p, ho->endpoint.value, cilen);
1711 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1717 if (orc == CONFACK && /* Good CI */
1718 rc != CONFACK) /* but prior CI wasnt? */
1719 continue; /* Don't send this one */
1721 if (orc == CONFNAK) { /* Nak this CI? */
1722 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1723 && citype != CI_MAGICNUMBER) {
1724 orc = CONFREJ; /* Get tough if so */
1726 if (rc == CONFREJ) /* Rejecting prior CI? */
1727 continue; /* Don't send this one */
1731 if (orc == CONFREJ) { /* Reject this CI */
1733 if (cip != rejp) /* Need to move rejected CI? */
1734 BCOPY(cip, rejp, cilen); /* Move it */
1735 INCPTR(cilen, rejp); /* Update output pointer */
1740 * If we wanted to send additional NAKs (for unsent CIs), the
1741 * code would go here. The extra NAKs would go at *nakp.
1742 * At present there are no cases where we want to ask the
1743 * peer to negotiate an option.
1752 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1754 *lenp = nakp - nak_buffer;
1755 BCOPY(nak_buffer, inp, *lenp);
1762 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1763 return (rc); /* Return final code */
1768 * lcp_up - LCP has come UP.
1774 lcp_options *wo = &lcp_wantoptions[f->unit];
1775 lcp_options *ho = &lcp_hisoptions[f->unit];
1776 lcp_options *go = &lcp_gotoptions[f->unit];
1777 lcp_options *ao = &lcp_allowoptions[f->unit];
1780 if (!go->neg_magicnumber)
1781 go->magicnumber = 0;
1782 if (!ho->neg_magicnumber)
1783 ho->magicnumber = 0;
1786 * Set our MTU to the smaller of the MTU we wanted and
1787 * the MRU our peer wanted. If we negotiated an MRU,
1788 * set our MRU to the larger of value we wanted and
1789 * the value we got in the negotiation.
1790 * Note on the MTU: the link MTU can be the MRU the peer wanted,
1791 * the interface MTU is set to the lower of that and the
1792 * MTU we want to use.
1794 mtu = ho->neg_mru? ho->mru: PPP_MRU;
1795 #ifdef HAVE_MULTILINK
1796 if (!(multilink && go->neg_mrru && ho->neg_mrru))
1797 #endif /* HAVE_MULTILINK */
1798 netif_set_mtu(f->unit, MIN(mtu, ao->mru));
1799 ppp_send_config(f->unit, mtu,
1800 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1801 ho->neg_pcompression, ho->neg_accompression);
1802 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
1803 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
1804 go->neg_pcompression, go->neg_accompression);
1807 peer_mru[f->unit] = ho->mru;
1809 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1811 link_established(f->unit);
1816 * lcp_down - LCP has gone DOWN.
1818 * Alert other protocols.
1824 lcp_options *go = &lcp_gotoptions[f->unit];
1826 lcp_echo_lowerdown(f->unit);
1830 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1831 ppp_recv_config(f->unit, PPP_MRU,
1832 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1833 go->neg_pcompression, go->neg_accompression);
1834 peer_mru[f->unit] = PPP_MRU;
1839 * lcp_starting - LCP needs the lower layer up.
1845 link_required(f->unit);
1850 * lcp_finished - LCP has finished with the lower layer.
1856 link_terminated(f->unit);
1861 * lcp_printpkt - print the contents of an LCP packet.
1863 static char *lcp_codenames[] = {
1864 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1865 "TermReq", "TermAck", "CodeRej", "ProtRej",
1866 "EchoReq", "EchoRep", "DiscReq"
1870 lcp_printpkt(p, plen, printer, arg)
1873 void (*printer) __P((void *, char *, ...));
1876 int code, id, len, olen, i;
1877 u_char *pstart, *optend;
1881 if (plen < HEADERLEN)
1887 if (len < HEADERLEN || len > plen)
1890 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1891 printer(arg, " %s", lcp_codenames[code-1]);
1893 printer(arg, " code=0x%x", code);
1894 printer(arg, " id=0x%x", id);
1901 /* print option list */
1906 if (olen < 2 || olen > len) {
1914 if (olen == CILEN_SHORT) {
1916 GETSHORT(cishort, p);
1917 printer(arg, "mru %d", cishort);
1921 if (olen == CILEN_LONG) {
1924 printer(arg, "asyncmap 0x%x", cilong);
1928 if (olen >= CILEN_SHORT) {
1930 printer(arg, "auth ");
1931 GETSHORT(cishort, p);
1934 printer(arg, "pap");
1937 printer(arg, "chap");
1940 case CHAP_DIGEST_MD5:
1941 printer(arg, " MD5");
1945 case CHAP_MICROSOFT:
1946 printer(arg, " MS");
1950 case CHAP_MICROSOFT_V2:
1951 printer(arg, " MS-v2");
1959 printer(arg, "0x%x", cishort);
1964 if (olen >= CILEN_SHORT) {
1966 printer(arg, "quality ");
1967 GETSHORT(cishort, p);
1970 printer(arg, "lqr");
1973 printer(arg, "0x%x", cishort);
1978 if (olen >= CILEN_CHAR) {
1980 printer(arg, "callback ");
1981 GETCHAR(cishort, p);
1984 printer(arg, "CBCP");
1987 printer(arg, "0x%x", cishort);
1991 case CI_MAGICNUMBER:
1992 if (olen == CILEN_LONG) {
1995 printer(arg, "magic 0x%x", cilong);
1998 case CI_PCOMPRESSION:
1999 if (olen == CILEN_VOID) {
2001 printer(arg, "pcomp");
2004 case CI_ACCOMPRESSION:
2005 if (olen == CILEN_VOID) {
2007 printer(arg, "accomp");
2011 if (olen == CILEN_SHORT) {
2013 GETSHORT(cishort, p);
2014 printer(arg, "mrru %d", cishort);
2018 if (olen == CILEN_VOID) {
2020 printer(arg, "ssnhf");
2024 #ifdef HAVE_MULTILINK
2025 if (olen >= CILEN_CHAR) {
2028 GETCHAR(epd.class, p);
2029 epd.length = olen - CILEN_CHAR;
2030 if (epd.length > MAX_ENDP_LEN)
2031 epd.length = MAX_ENDP_LEN;
2032 if (epd.length > 0) {
2033 BCOPY(p, epd.value, epd.length);
2036 printer(arg, "endpoint [%s]", epdisc_to_str(&epd));
2039 printer(arg, "endpoint");
2043 while (p < optend) {
2045 printer(arg, " %.2x", code);
2053 if (len > 0 && *p >= ' ' && *p < 0x7f) {
2055 print_string((char *)p, len, printer, arg);
2066 printer(arg, " magic=0x%x", cilong);
2073 /* print the rest of the bytes in the packet */
2074 for (i = 0; i < len && i < 32; ++i) {
2076 printer(arg, " %.2x", code);
2079 printer(arg, " ...");
2087 * Time to shut down the link because there is nothing out there.
2091 void LcpLinkFailure (f)
2094 if (f->state == OPENED) {
2095 info("No response to %d echo-requests", lcp_echos_pending);
2096 notice("Serial link appears to be disconnected.");
2097 lcp_close(f->unit, "Peer not responding");
2098 status = EXIT_PEER_DEAD;
2103 * Timer expired for the LCP echo requests from this process.
2110 LcpSendEchoRequest (f);
2111 if (f->state != OPENED)
2115 * Start the timer for the next interval.
2117 if (lcp_echo_timer_running)
2118 warn("assertion lcp_echo_timer_running==0 failed");
2119 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2120 lcp_echo_timer_running = 1;
2124 * LcpEchoTimeout - Timer expired on the LCP echo
2128 LcpEchoTimeout (arg)
2131 if (lcp_echo_timer_running != 0) {
2132 lcp_echo_timer_running = 0;
2133 LcpEchoCheck ((fsm *) arg);
2138 * LcpEchoReply - LCP has received a reply to the echo
2142 lcp_received_echo_reply (f, id, inp, len)
2150 /* Check the magic number - don't count replies from ourselves. */
2152 dbglog("lcp: received short Echo-Reply, length %d", len);
2155 GETLONG(magic, inp);
2156 if (lcp_gotoptions[f->unit].neg_magicnumber
2157 && magic == lcp_gotoptions[f->unit].magicnumber) {
2158 warn("appear to have received our own echo-reply!");
2162 /* Reset the number of outstanding echo frames */
2163 lcp_echos_pending = 0;
2167 * LcpSendEchoRequest - Send an echo request frame to the peer
2171 LcpSendEchoRequest (f)
2174 u_int32_t lcp_magic;
2175 u_char pkt[4], *pktp;
2178 * Detect the failure of the peer at this point.
2180 if (lcp_echo_fails != 0) {
2181 if (lcp_echos_pending >= lcp_echo_fails) {
2183 lcp_echos_pending = 0;
2188 * Make and send the echo request frame.
2190 if (f->state == OPENED) {
2191 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2193 PUTLONG(lcp_magic, pktp);
2194 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2195 ++lcp_echos_pending;
2200 * lcp_echo_lowerup - Start the timer for the LCP frame
2204 lcp_echo_lowerup (unit)
2207 fsm *f = &lcp_fsm[unit];
2209 /* Clear the parameters for generating echo frames */
2210 lcp_echos_pending = 0;
2211 lcp_echo_number = 0;
2212 lcp_echo_timer_running = 0;
2214 /* If a timeout interval is specified then start the timer */
2215 if (lcp_echo_interval != 0)
2220 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2224 lcp_echo_lowerdown (unit)
2227 fsm *f = &lcp_fsm[unit];
2229 if (lcp_echo_timer_running != 0) {
2230 UNTIMEOUT (LcpEchoTimeout, f);
2231 lcp_echo_timer_running = 0;