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.48 2000/03/27 06:02:59 paulus Exp $";
36 static const char rcsid[] = RCSID;
39 * LCP-related command-line options.
41 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
42 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
43 bool lax_recv = 0; /* accept control chars in asyncmap */
45 static int setescape __P((char **));
47 static option_t lcp_option_list[] = {
49 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
50 "Disable address/control compression",
51 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
52 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
53 "Disable address/control compression",
54 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
55 { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
56 "Disable asyncmap negotiation",
57 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
58 { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
59 "Disable asyncmap negotiation",
60 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
61 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
62 "Set asyncmap (for received packets)",
63 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
64 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
65 "Set asyncmap (for received packets)",
66 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
67 { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
68 "Disable magic number negotiation (looped-back line detection)",
69 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
70 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
71 "Disable magic number negotiation (looped-back line detection)",
72 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
73 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
74 "Disable MRU negotiation (use default 1500)",
75 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
76 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
77 "Disable MRU negotiation (use default 1500)",
78 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
79 { "mru", o_int, &lcp_wantoptions[0].mru,
80 "Set MRU (maximum received packet size) for negotiation",
81 0, &lcp_wantoptions[0].neg_mru },
82 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
83 "Disable protocol field compression",
84 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
85 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
86 "Disable protocol field compression",
87 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
88 { "-p", o_bool, &lcp_wantoptions[0].passive,
89 "Set passive mode", 1 },
90 { "passive", o_bool, &lcp_wantoptions[0].passive,
91 "Set passive mode", 1 },
92 { "silent", o_bool, &lcp_wantoptions[0].silent,
93 "Set silent mode", 1 },
94 { "escape", o_special, setescape,
95 "List of character codes to escape on transmission" },
96 { "lcp-echo-failure", o_int, &lcp_echo_fails,
97 "Set number of consecutive echo failures to indicate link failure" },
98 { "lcp-echo-interval", o_int, &lcp_echo_interval,
99 "Set time in seconds between LCP echo requests" },
100 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
101 "Set time in seconds between LCP retransmissions" },
102 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
103 "Set maximum number of LCP terminate-request transmissions" },
104 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
105 "Set maximum number of LCP configure-request transmissions" },
106 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
107 "Set limit on number of LCP configure-naks" },
108 { "receive-all", o_bool, &lax_recv,
109 "Accept all received control characters", 1 },
110 #ifdef HAVE_MULTILINK
111 { "mpshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
112 "Use short sequence numbers in multilink headers",
113 OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf },
114 { "nompshortseq", o_bool, &lcp_wantoptions[0].neg_ssnhf,
115 "Don't use short sequence numbers in multilink headers",
116 OPT_A2COPY, &lcp_allowoptions[0].neg_ssnhf },
117 #endif /* HAVE_MULTILINK */
122 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
123 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
124 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
125 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
126 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
127 u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
129 static int lcp_echos_pending = 0; /* Number of outstanding echo msgs */
130 static int lcp_echo_number = 0; /* ID number of next echo frame */
131 static int lcp_echo_timer_running = 0; /* set if a timer is running */
133 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
136 * Callbacks for fsm code. (CI = Configuration Information)
138 static void lcp_resetci __P((fsm *)); /* Reset our CI */
139 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
140 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
141 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
142 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
143 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
144 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
145 static void lcp_up __P((fsm *)); /* We're UP */
146 static void lcp_down __P((fsm *)); /* We're DOWN */
147 static void lcp_starting __P((fsm *)); /* We need lower layer up */
148 static void lcp_finished __P((fsm *)); /* We need lower layer down */
149 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
150 static void lcp_rprotrej __P((fsm *, u_char *, int));
153 * routines to send LCP echos to peer
156 static void lcp_echo_lowerup __P((int));
157 static void lcp_echo_lowerdown __P((int));
158 static void LcpEchoTimeout __P((void *));
159 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
160 static void LcpSendEchoRequest __P((fsm *));
161 static void LcpLinkFailure __P((fsm *));
162 static void LcpEchoCheck __P((fsm *));
164 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
165 lcp_resetci, /* Reset our Configuration Information */
166 lcp_cilen, /* Length of our Configuration Information */
167 lcp_addci, /* Add our Configuration Information */
168 lcp_ackci, /* ACK our Configuration Information */
169 lcp_nakci, /* NAK our Configuration Information */
170 lcp_rejci, /* Reject our Configuration Information */
171 lcp_reqci, /* Request peer's Configuration Information */
172 lcp_up, /* Called when fsm reaches OPENED state */
173 lcp_down, /* Called when fsm leaves OPENED state */
174 lcp_starting, /* Called when we want the lower layer up */
175 lcp_finished, /* Called when we want the lower layer down */
176 NULL, /* Called when Protocol-Reject received */
177 NULL, /* Retransmission is necessary */
178 lcp_extcode, /* Called to handle LCP-specific codes */
179 "LCP" /* String name of protocol */
183 * Protocol entry points.
184 * Some of these are called directly.
187 static void lcp_init __P((int));
188 static void lcp_input __P((int, u_char *, int));
189 static void lcp_protrej __P((int));
190 static int lcp_printpkt __P((u_char *, int,
191 void (*) __P((void *, char *, ...)), void *));
193 struct protent lcp_protent = {
213 int lcp_loopbackfail = DEFLOOPBACKFAIL;
216 * Length of each type of configuration option (in octets)
220 #define CILEN_SHORT 4 /* CILEN_VOID + 2 */
221 #define CILEN_CHAP 5 /* CILEN_VOID + 2 + 1 */
222 #define CILEN_LONG 6 /* CILEN_VOID + 4 */
223 #define CILEN_LQR 8 /* CILEN_VOID + 2 + 4 */
226 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
227 (x) == CONFNAK ? "NAK" : "REJ")
231 * setescape - add chars to the set we escape on transmission.
243 n = strtol(p, &endp, 16);
245 option_error("escape parameter contains invalid hex number '%s'",
250 if (n < 0 || n == 0x5E || n > 0xFF) {
251 option_error("can't escape character 0x%x", n);
254 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
255 while (*p == ',' || *p == ' ')
262 * lcp_init - Initialize LCP.
268 fsm *f = &lcp_fsm[unit];
269 lcp_options *wo = &lcp_wantoptions[unit];
270 lcp_options *ao = &lcp_allowoptions[unit];
273 f->protocol = PPP_LCP;
274 f->callbacks = &lcp_callbacks;
280 wo->restart = 0; /* Set to 1 in kernels or multi-line
284 wo->neg_asyncmap = 1;
286 wo->neg_chap = 0; /* Set to 1 on server */
287 wo->neg_upap = 0; /* Set to 1 on server */
288 wo->chap_mdtype = CHAP_DIGEST_MD5;
289 wo->neg_magicnumber = 1;
290 wo->neg_pcompression = 1;
291 wo->neg_accompression = 1;
292 wo->neg_lqr = 0; /* no LQR implementation yet */
297 ao->neg_asyncmap = 1;
300 ao->chap_mdtype = CHAP_DIGEST_MD5;
302 ao->neg_magicnumber = 1;
303 ao->neg_pcompression = 1;
304 ao->neg_accompression = 1;
305 ao->neg_lqr = 0; /* no LQR implementation yet */
312 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
313 xmit_accm[unit][3] = 0x60000000;
318 * lcp_open - LCP is allowed to come up.
324 fsm *f = &lcp_fsm[unit];
325 lcp_options *wo = &lcp_wantoptions[unit];
329 f->flags |= OPT_PASSIVE;
331 f->flags |= OPT_SILENT;
337 * lcp_close - Take LCP down.
340 lcp_close(unit, reason)
344 fsm *f = &lcp_fsm[unit];
346 if (phase != PHASE_DEAD)
347 new_phase(PHASE_TERMINATE);
348 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
350 * This action is not strictly according to the FSM in RFC1548,
351 * but it does mean that the program terminates if you do a
352 * lcp_close() in passive/silent mode when a connection hasn't
359 fsm_close(&lcp_fsm[unit], reason);
364 * lcp_lowerup - The lower layer is up.
370 lcp_options *wo = &lcp_wantoptions[unit];
373 * Don't use A/C or protocol compression on transmission,
374 * but accept A/C and protocol compressed packets
375 * if we are going to ask for A/C and protocol compression.
377 ppp_set_xaccm(unit, xmit_accm[unit]);
378 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
379 ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
380 wo->neg_pcompression, wo->neg_accompression);
381 peer_mru[unit] = PPP_MRU;
382 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
384 fsm_lowerup(&lcp_fsm[unit]);
389 * lcp_lowerdown - The lower layer is down.
395 fsm_lowerdown(&lcp_fsm[unit]);
400 * lcp_input - Input LCP packet.
403 lcp_input(unit, p, len)
408 fsm *f = &lcp_fsm[unit];
410 fsm_input(f, p, len);
415 * lcp_extcode - Handle a LCP-specific code.
418 lcp_extcode(f, code, id, inp, len)
428 lcp_rprotrej(f, inp, len);
432 if (f->state != OPENED)
435 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
436 fsm_sdata(f, ECHOREP, id, inp, len);
440 lcp_received_echo_reply(f, id, inp, len);
454 * lcp_rprotrej - Receive an Protocol-Reject.
456 * Figure out which protocol is rejected and inform it.
459 lcp_rprotrej(f, inp, len)
465 struct protent *protp;
469 LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
476 * Protocol-Reject packets received in any state other than the LCP
477 * OPENED state SHOULD be silently discarded.
479 if( f->state != OPENED ){
480 LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
485 * Upcall the proper Protocol-Reject routine.
487 for (i = 0; (protp = protocols[i]) != NULL; ++i)
488 if (protp->protocol == prot && protp->enabled_flag) {
489 (*protp->protrej)(f->unit);
493 warn("Protocol-Reject for unsupported protocol 0x%x", prot);
498 * lcp_protrej - A Protocol-Reject was received.
508 error("Received Protocol-Reject for LCP!");
509 fsm_protreject(&lcp_fsm[unit]);
514 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
517 lcp_sprotrej(unit, p, len)
523 * Send back the protocol and the information field of the
524 * rejected packet. We only get here if LCP is in the OPENED state.
529 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
535 * lcp_resetci - Reset our CI.
541 lcp_options *wo = &lcp_wantoptions[f->unit];
543 wo->magicnumber = magic();
545 if (!wo->neg_multilink)
547 lcp_gotoptions[f->unit] = *wo;
548 peer_mru[f->unit] = PPP_MRU;
554 * lcp_cilen - Return length of our CI.
560 lcp_options *go = &lcp_gotoptions[f->unit];
562 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
563 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
564 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
565 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
566 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
567 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
569 * NB: we only ask for one of CHAP and UPAP, even if we will
572 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
573 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
574 LENCICHAP(go->neg_chap) +
575 LENCISHORT(!go->neg_chap && go->neg_upap) +
576 LENCILQR(go->neg_lqr) +
577 LENCICBCP(go->neg_cbcp) +
578 LENCILONG(go->neg_magicnumber) +
579 LENCIVOID(go->neg_pcompression) +
580 LENCIVOID(go->neg_accompression) +
581 LENCISHORT(go->neg_multilink) +
582 LENCIVOID(go->neg_ssnhf) +
583 (go->neg_endpoint? CILEN_CHAR + go->endp_len: 0));
588 * lcp_addci - Add our desired CIs to a packet.
591 lcp_addci(f, ucp, lenp)
596 lcp_options *go = &lcp_gotoptions[f->unit];
597 u_char *start_ucp = ucp;
599 #define ADDCIVOID(opt, neg) \
602 PUTCHAR(CILEN_VOID, ucp); \
604 #define ADDCISHORT(opt, neg, val) \
607 PUTCHAR(CILEN_SHORT, ucp); \
608 PUTSHORT(val, ucp); \
610 #define ADDCICHAP(opt, neg, val, digest) \
613 PUTCHAR(CILEN_CHAP, ucp); \
614 PUTSHORT(val, ucp); \
615 PUTCHAR(digest, ucp); \
617 #define ADDCILONG(opt, neg, val) \
620 PUTCHAR(CILEN_LONG, ucp); \
623 #define ADDCILQR(opt, neg, val) \
626 PUTCHAR(CILEN_LQR, ucp); \
627 PUTSHORT(PPP_LQR, ucp); \
630 #define ADDCICHAR(opt, neg, val) \
633 PUTCHAR(CILEN_CHAR, ucp); \
636 #define ADDCIENDP(opt, neg, class, val, len) \
640 PUTCHAR(CILEN_CHAR + len, ucp); \
641 PUTCHAR(class, ucp); \
642 for (i = 0; i < len; ++i) \
643 PUTCHAR(val[i], ucp); \
646 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
647 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
649 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
650 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
651 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
652 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
653 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
654 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
655 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
656 ADDCISHORT(CI_MRRU, go->neg_multilink, go->mrru);
657 ADDCIVOID(CI_SSNHF, go->neg_ssnhf);
658 ADDCIENDP(CI_EPDISC, go->neg_endpoint, go->endp_class, go->endpoint,
661 if (ucp - start_ucp != *lenp) {
662 /* this should never happen, because peer_mtu should be 1500 */
663 error("Bug in lcp_addci: wrong length");
669 * lcp_ackci - Ack our CIs.
670 * This should not modify any state if the Ack is bad.
682 lcp_options *go = &lcp_gotoptions[f->unit];
683 u_char cilen, citype, cichar;
688 * CIs must be in exactly the same order that we sent.
689 * Check packet length and CI length at each step.
690 * If we find any deviations, then this packet is bad.
692 #define ACKCIVOID(opt, neg) \
694 if ((len -= CILEN_VOID) < 0) \
696 GETCHAR(citype, p); \
698 if (cilen != CILEN_VOID || \
702 #define ACKCISHORT(opt, neg, val) \
704 if ((len -= CILEN_SHORT) < 0) \
706 GETCHAR(citype, p); \
708 if (cilen != CILEN_SHORT || \
711 GETSHORT(cishort, p); \
712 if (cishort != val) \
715 #define ACKCICHAR(opt, neg, val) \
717 if ((len -= CILEN_CHAR) < 0) \
719 GETCHAR(citype, p); \
721 if (cilen != CILEN_CHAR || \
724 GETCHAR(cichar, p); \
728 #define ACKCICHAP(opt, neg, val, digest) \
730 if ((len -= CILEN_CHAP) < 0) \
732 GETCHAR(citype, p); \
734 if (cilen != CILEN_CHAP || \
737 GETSHORT(cishort, p); \
738 if (cishort != val) \
740 GETCHAR(cichar, p); \
741 if (cichar != digest) \
744 #define ACKCILONG(opt, neg, val) \
746 if ((len -= CILEN_LONG) < 0) \
748 GETCHAR(citype, p); \
750 if (cilen != CILEN_LONG || \
753 GETLONG(cilong, p); \
757 #define ACKCILQR(opt, neg, val) \
759 if ((len -= CILEN_LQR) < 0) \
761 GETCHAR(citype, p); \
763 if (cilen != CILEN_LQR || \
766 GETSHORT(cishort, p); \
767 if (cishort != PPP_LQR) \
769 GETLONG(cilong, p); \
773 #define ACKCIENDP(opt, neg, class, val, vlen) \
776 if ((len -= CILEN_CHAR + vlen) < 0) \
778 GETCHAR(citype, p); \
780 if (cilen != CILEN_CHAR + vlen || \
783 GETCHAR(cichar, p); \
784 if (cichar != class) \
786 for (i = 0; i < vlen; ++i) { \
787 GETCHAR(cichar, p); \
788 if (cichar != val[i]) \
793 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
794 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
796 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
797 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
798 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
799 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
800 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
801 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
802 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
803 ACKCISHORT(CI_MRRU, go->neg_multilink, go->mrru);
804 ACKCIVOID(CI_SSNHF, go->neg_ssnhf);
805 ACKCIENDP(CI_EPDISC, go->neg_endpoint, go->endp_class, go->endpoint,
809 * If there are any remaining CIs, then this packet is bad.
815 LCPDEBUG(("lcp_acki: received bad Ack!"));
821 * lcp_nakci - Peer has sent a NAK for some of our CIs.
822 * This should not modify any state if the Nak is bad
823 * or if LCP is in the OPENED state.
835 lcp_options *go = &lcp_gotoptions[f->unit];
836 lcp_options *wo = &lcp_wantoptions[f->unit];
837 u_char citype, cichar, *next;
840 lcp_options no; /* options we've seen Naks for */
841 lcp_options try; /* options to request next time */
845 BZERO(&no, sizeof(no));
849 * Any Nak'd CIs must be in exactly the same order that we sent.
850 * Check packet length and CI length at each step.
851 * If we find any deviations, then this packet is bad.
853 #define NAKCIVOID(opt, neg) \
855 len >= CILEN_VOID && \
856 p[1] == CILEN_VOID && \
859 INCPTR(CILEN_VOID, p); \
863 #define NAKCICHAP(opt, neg, code) \
865 len >= CILEN_CHAP && \
866 p[1] == CILEN_CHAP && \
870 GETSHORT(cishort, p); \
871 GETCHAR(cichar, p); \
875 #define NAKCICHAR(opt, neg, code) \
877 len >= CILEN_CHAR && \
878 p[1] == CILEN_CHAR && \
882 GETCHAR(cichar, p); \
886 #define NAKCISHORT(opt, neg, code) \
888 len >= CILEN_SHORT && \
889 p[1] == CILEN_SHORT && \
891 len -= CILEN_SHORT; \
893 GETSHORT(cishort, p); \
897 #define NAKCILONG(opt, neg, code) \
899 len >= CILEN_LONG && \
900 p[1] == CILEN_LONG && \
904 GETLONG(cilong, p); \
908 #define NAKCILQR(opt, neg, code) \
910 len >= CILEN_LQR && \
911 p[1] == CILEN_LQR && \
915 GETSHORT(cishort, p); \
916 GETLONG(cilong, p); \
920 #define NAKCIENDP(opt, neg) \
922 len >= CILEN_CHAR && \
924 p[1] >= CILEN_CHAR && \
933 * We don't care if they want to send us smaller packets than
934 * we want. Therefore, accept any MRU less than what we asked for,
935 * but then ignore the new value when setting the MRU in the kernel.
936 * If they send us a bigger MRU than what we asked, accept it, up to
937 * the limit of the default MRU we'd get if we didn't negotiate.
939 if (go->neg_mru && go->mru != DEFMRU) {
940 NAKCISHORT(CI_MRU, neg_mru,
941 if (cishort <= wo->mru || cishort <= DEFMRU)
947 * Add any characters they want to our (receive-side) asyncmap.
949 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
950 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
951 try.asyncmap = go->asyncmap | cilong;
956 * If they've nak'd our authentication-protocol, check whether
957 * they are proposing a different protocol, or a different
958 * hash algorithm for CHAP.
960 if ((go->neg_chap || go->neg_upap)
961 && len >= CILEN_SHORT
962 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
965 no.neg_chap = go->neg_chap;
966 no.neg_upap = go->neg_upap;
968 GETSHORT(cishort, p);
969 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
971 * If we were asking for CHAP, they obviously don't want to do it.
972 * If we weren't asking for CHAP, then we were asking for PAP,
973 * in which case this Nak is bad.
979 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
983 * We were asking for CHAP/MD5; they must want a different
984 * algorithm. If they can't do MD5, we can ask for M$-CHAP
985 * if we support it, otherwise we'll have to stop
988 if (cichar != go->chap_mdtype) {
990 if (cichar == CHAP_MICROSOFT)
991 go->chap_mdtype = CHAP_MICROSOFT;
998 * Stop asking for PAP if we were asking for it.
1005 * We don't recognize what they're suggesting.
1006 * Stop asking for what we were asking for.
1012 p += cilen - CILEN_SHORT;
1017 * If they can't cope with our link quality protocol, we'll have
1018 * to stop asking for LQR. We haven't got any other protocol.
1019 * If they Nak the reporting period, take their value XXX ?
1021 NAKCILQR(CI_QUALITY, neg_lqr,
1022 if (cishort != PPP_LQR)
1025 try.lqr_period = cilong;
1029 * Only implementing CBCP...not the rest of the callback options
1031 NAKCICHAR(CI_CALLBACK, neg_cbcp,
1036 * Check for a looped-back line.
1038 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
1039 try.magicnumber = magic();
1044 * Peer shouldn't send Nak for protocol compression or
1045 * address/control compression requests; they should send
1046 * a Reject instead. If they send a Nak, treat it as a Reject.
1048 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression);
1049 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression);
1052 * Nak for MRRU option - accept their value if it is smaller
1053 * than the one we want.
1055 if (go->neg_multilink) {
1056 NAKCISHORT(CI_MRRU, neg_multilink,
1057 if (cishort <= wo->mrru)
1063 * Nak for short sequence numbers shouldn't be sent, treat it
1066 NAKCIVOID(CI_SSNHF, neg_ssnhf);
1069 * Nak of the endpoint discriminator option is not permitted,
1070 * treat it like a reject.
1072 NAKCIENDP(CI_EPDISC, neg_endpoint);
1075 * There may be remaining CIs, if the peer is requesting negotiation
1076 * on an option that we didn't include in our request packet.
1077 * If we see an option that we requested, or one we've already seen
1078 * in this packet, then this packet is bad.
1079 * If we wanted to respond by starting to negotiate on the requested
1080 * option(s), we could, but we don't, because except for the
1081 * authentication type and quality protocol, if we are not negotiating
1082 * an option, it is because we were told not to.
1083 * For the authentication type, the Nak from the peer means
1084 * `let me authenticate myself with you' which is a bit pointless.
1085 * For the quality protocol, the Nak means `ask me to send you quality
1086 * reports', but if we didn't ask for them, we don't want them.
1087 * An option we don't recognize represents the peer asking to
1088 * negotiate some option we don't support, so ignore it.
1090 while (len > CILEN_VOID) {
1093 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1095 next = p + cilen - 2;
1099 if ((go->neg_mru && go->mru != DEFMRU)
1100 || no.neg_mru || cilen != CILEN_SHORT)
1102 GETSHORT(cishort, p);
1103 if (cishort < DEFMRU) {
1109 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1110 || no.neg_asyncmap || cilen != CILEN_LONG)
1114 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
1117 case CI_MAGICNUMBER:
1118 if (go->neg_magicnumber || no.neg_magicnumber ||
1119 cilen != CILEN_LONG)
1122 case CI_PCOMPRESSION:
1123 if (go->neg_pcompression || no.neg_pcompression
1124 || cilen != CILEN_VOID)
1127 case CI_ACCOMPRESSION:
1128 if (go->neg_accompression || no.neg_accompression
1129 || cilen != CILEN_VOID)
1133 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1137 if (go->neg_multilink || no.neg_multilink || cilen != CILEN_SHORT)
1141 if (go->neg_ssnhf || no.neg_ssnhf || cilen != CILEN_VOID)
1146 if (go->neg_endpoint || no.neg_endpoint || cilen < CILEN_CHAR)
1154 * OK, the Nak is good. Now we can update state.
1155 * If there are any options left we ignore them.
1157 if (f->state != OPENED) {
1159 if (++try.numloops >= lcp_loopbackfail) {
1160 notice("Serial line is looped back.");
1161 lcp_close(f->unit, "Loopback detected");
1162 status = EXIT_LOOPBACK;
1172 LCPDEBUG(("lcp_nakci: received bad Nak!"));
1178 * lcp_rejci - Peer has Rejected some of our CIs.
1179 * This should not modify any state if the Reject is bad
1180 * or if LCP is in the OPENED state.
1183 * 0 - Reject was bad.
1184 * 1 - Reject was good.
1187 lcp_rejci(f, p, len)
1192 lcp_options *go = &lcp_gotoptions[f->unit];
1196 lcp_options try; /* options to request next time */
1201 * Any Rejected CIs must be in exactly the same order that we sent.
1202 * Check packet length and CI length at each step.
1203 * If we find any deviations, then this packet is bad.
1205 #define REJCIVOID(opt, neg) \
1207 len >= CILEN_VOID && \
1208 p[1] == CILEN_VOID && \
1210 len -= CILEN_VOID; \
1211 INCPTR(CILEN_VOID, p); \
1214 #define REJCISHORT(opt, neg, val) \
1216 len >= CILEN_SHORT && \
1217 p[1] == CILEN_SHORT && \
1219 len -= CILEN_SHORT; \
1221 GETSHORT(cishort, p); \
1222 /* Check rejected value. */ \
1223 if (cishort != val) \
1227 #define REJCICHAP(opt, neg, val, digest) \
1229 len >= CILEN_CHAP && \
1230 p[1] == CILEN_CHAP && \
1232 len -= CILEN_CHAP; \
1234 GETSHORT(cishort, p); \
1235 GETCHAR(cichar, p); \
1236 /* Check rejected value. */ \
1237 if (cishort != val || cichar != digest) \
1242 #define REJCILONG(opt, neg, val) \
1244 len >= CILEN_LONG && \
1245 p[1] == CILEN_LONG && \
1247 len -= CILEN_LONG; \
1249 GETLONG(cilong, p); \
1250 /* Check rejected value. */ \
1251 if (cilong != val) \
1255 #define REJCILQR(opt, neg, val) \
1257 len >= CILEN_LQR && \
1258 p[1] == CILEN_LQR && \
1262 GETSHORT(cishort, p); \
1263 GETLONG(cilong, p); \
1264 /* Check rejected value. */ \
1265 if (cishort != PPP_LQR || cilong != val) \
1269 #define REJCICBCP(opt, neg, val) \
1271 len >= CILEN_CBCP && \
1272 p[1] == CILEN_CBCP && \
1274 len -= CILEN_CBCP; \
1276 GETCHAR(cichar, p); \
1277 /* Check rejected value. */ \
1278 if (cichar != val) \
1282 #define REJCIENDP(opt, neg, class, val, vlen) \
1284 len >= CILEN_CHAR + vlen && \
1286 p[1] == CILEN_CHAR + vlen) { \
1288 len -= CILEN_CHAR + vlen; \
1290 GETCHAR(cichar, p); \
1291 if (cichar != class) \
1293 for (i = 0; i < vlen; ++i) { \
1294 GETCHAR(cichar, p); \
1295 if (cichar != val[i]) \
1301 REJCISHORT(CI_MRU, neg_mru, go->mru);
1302 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1303 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
1304 if (!go->neg_chap) {
1305 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1307 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1308 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1309 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1310 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1311 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1312 REJCISHORT(CI_MRRU, neg_multilink, go->mrru);
1313 REJCIVOID(CI_SSNHF, neg_ssnhf);
1314 REJCIENDP(CI_EPDISC, neg_endpoint, go->endp_class, go->endpoint,
1318 * If there are any remaining CIs, then this packet is bad.
1323 * Now we can update state.
1325 if (f->state != OPENED)
1330 LCPDEBUG(("lcp_rejci: received bad Reject!"));
1336 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1338 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1339 * appropriately. If reject_if_disagree is non-zero, doesn't return
1340 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1343 lcp_reqci(f, inp, lenp, reject_if_disagree)
1345 u_char *inp; /* Requested CIs */
1346 int *lenp; /* Length of requested CIs */
1347 int reject_if_disagree;
1349 lcp_options *go = &lcp_gotoptions[f->unit];
1350 lcp_options *ho = &lcp_hisoptions[f->unit];
1351 lcp_options *ao = &lcp_allowoptions[f->unit];
1352 u_char *cip, *next; /* Pointer to current and next CIs */
1353 int cilen, citype, cichar; /* Parsed len, type, char value */
1354 u_short cishort; /* Parsed short value */
1355 u_int32_t cilong; /* Parse long value */
1356 int rc = CONFACK; /* Final packet return code */
1357 int orc; /* Individual option return code */
1358 u_char *p; /* Pointer to next char to parse */
1359 u_char *rejp; /* Pointer to next char in reject frame */
1360 u_char *nakp; /* Pointer to next char in Nak frame */
1361 int l = *lenp; /* Length left */
1364 * Reset all his options.
1366 BZERO(ho, sizeof(*ho));
1369 * Process all his options.
1375 orc = CONFACK; /* Assume success */
1376 cip = p = next; /* Remember begining of CI */
1377 if (l < 2 || /* Not enough data for CI header or */
1378 p[1] < 2 || /* CI length too small or */
1379 p[1] > l) { /* CI length too big? */
1380 LCPDEBUG(("lcp_reqci: bad CI length!"));
1381 orc = CONFREJ; /* Reject bad CI */
1382 cilen = l; /* Reject till end of packet */
1383 l = 0; /* Don't loop again */
1387 GETCHAR(citype, p); /* Parse CI type */
1388 GETCHAR(cilen, p); /* Parse CI length */
1389 l -= cilen; /* Adjust remaining length */
1390 next += cilen; /* Step to next CI */
1392 switch (citype) { /* Check CI type */
1394 if (!ao->neg_mru || /* Allow option? */
1395 cilen != CILEN_SHORT) { /* Check CI length */
1396 orc = CONFREJ; /* Reject CI */
1399 GETSHORT(cishort, p); /* Parse MRU */
1402 * He must be able to receive at least our minimum.
1403 * No need to check a maximum. If he sends a large number,
1404 * we'll just ignore it.
1406 if (cishort < MINMRU) {
1407 orc = CONFNAK; /* Nak CI */
1408 PUTCHAR(CI_MRU, nakp);
1409 PUTCHAR(CILEN_SHORT, nakp);
1410 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1413 ho->neg_mru = 1; /* Remember he sent MRU */
1414 ho->mru = cishort; /* And remember value */
1418 if (!ao->neg_asyncmap ||
1419 cilen != CILEN_LONG) {
1426 * Asyncmap must have set at least the bits
1427 * which are set in lcp_allowoptions[unit].asyncmap.
1429 if ((ao->asyncmap & ~cilong) != 0) {
1431 PUTCHAR(CI_ASYNCMAP, nakp);
1432 PUTCHAR(CILEN_LONG, nakp);
1433 PUTLONG(ao->asyncmap | cilong, nakp);
1436 ho->neg_asyncmap = 1;
1437 ho->asyncmap = cilong;
1441 if (cilen < CILEN_SHORT ||
1442 !(ao->neg_upap || ao->neg_chap)) {
1444 * Reject the option if we're not willing to authenticate.
1449 GETSHORT(cishort, p);
1452 * Authtype must be PAP or CHAP.
1454 * Note: if both ao->neg_upap and ao->neg_chap are set,
1455 * and the peer sends a Configure-Request with two
1456 * authenticate-protocol requests, one for CHAP and one
1457 * for UPAP, then we will reject the second request.
1458 * Whether we end up doing CHAP or UPAP depends then on
1459 * the ordering of the CIs in the peer's Configure-Request.
1462 if (cishort == PPP_PAP) {
1463 if (ho->neg_chap || /* we've already accepted CHAP */
1464 cilen != CILEN_SHORT) {
1465 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1469 if (!ao->neg_upap) { /* we don't want to do PAP */
1470 orc = CONFNAK; /* NAK it and suggest CHAP */
1471 PUTCHAR(CI_AUTHTYPE, nakp);
1472 PUTCHAR(CILEN_CHAP, nakp);
1473 PUTSHORT(PPP_CHAP, nakp);
1474 PUTCHAR(ao->chap_mdtype, nakp);
1475 /* XXX if we can do CHAP_MICROSOFT as well, we should
1476 probably put in another option saying so */
1482 if (cishort == PPP_CHAP) {
1483 if (ho->neg_upap || /* we've already accepted PAP */
1484 cilen != CILEN_CHAP) {
1485 LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1489 if (!ao->neg_chap) { /* we don't want to do CHAP */
1490 orc = CONFNAK; /* NAK it and suggest PAP */
1491 PUTCHAR(CI_AUTHTYPE, nakp);
1492 PUTCHAR(CILEN_SHORT, nakp);
1493 PUTSHORT(PPP_PAP, nakp);
1496 GETCHAR(cichar, p); /* get digest type*/
1497 if (cichar != CHAP_DIGEST_MD5
1499 && cichar != CHAP_MICROSOFT
1503 PUTCHAR(CI_AUTHTYPE, nakp);
1504 PUTCHAR(CILEN_CHAP, nakp);
1505 PUTSHORT(PPP_CHAP, nakp);
1506 PUTCHAR(ao->chap_mdtype, nakp);
1509 ho->chap_mdtype = cichar; /* save md type */
1515 * We don't recognize the protocol they're asking for.
1516 * Nak it with something we're willing to do.
1517 * (At this point we know ao->neg_upap || ao->neg_chap.)
1520 PUTCHAR(CI_AUTHTYPE, nakp);
1522 PUTCHAR(CILEN_CHAP, nakp);
1523 PUTSHORT(PPP_CHAP, nakp);
1524 PUTCHAR(ao->chap_mdtype, nakp);
1526 PUTCHAR(CILEN_SHORT, nakp);
1527 PUTSHORT(PPP_PAP, nakp);
1533 cilen != CILEN_LQR) {
1538 GETSHORT(cishort, p);
1542 * Check the protocol and the reporting period.
1543 * XXX When should we Nak this, and what with?
1545 if (cishort != PPP_LQR) {
1547 PUTCHAR(CI_QUALITY, nakp);
1548 PUTCHAR(CILEN_LQR, nakp);
1549 PUTSHORT(PPP_LQR, nakp);
1550 PUTLONG(ao->lqr_period, nakp);
1555 case CI_MAGICNUMBER:
1556 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1557 cilen != CILEN_LONG) {
1564 * He must have a different magic number.
1566 if (go->neg_magicnumber &&
1567 cilong == go->magicnumber) {
1568 cilong = magic(); /* Don't put magic() inside macro! */
1570 PUTCHAR(CI_MAGICNUMBER, nakp);
1571 PUTCHAR(CILEN_LONG, nakp);
1572 PUTLONG(cilong, nakp);
1575 ho->neg_magicnumber = 1;
1576 ho->magicnumber = cilong;
1580 case CI_PCOMPRESSION:
1581 if (!ao->neg_pcompression ||
1582 cilen != CILEN_VOID) {
1586 ho->neg_pcompression = 1;
1589 case CI_ACCOMPRESSION:
1590 if (!ao->neg_accompression ||
1591 cilen != CILEN_VOID) {
1595 ho->neg_accompression = 1;
1599 if (!ao->neg_multilink ||
1600 cilen != CILEN_SHORT) {
1605 GETSHORT(cishort, p);
1606 /* possibly should insist on a minimum/maximum MRRU here */
1607 ho->neg_multilink = 1;
1612 if (!ao->neg_ssnhf ||
1613 cilen != CILEN_VOID) {
1621 if (!ao->neg_endpoint ||
1622 cilen < CILEN_CHAR ||
1623 cilen > CILEN_CHAR + MAX_ENDP_LEN) {
1628 cilen -= CILEN_CHAR;
1629 ho->neg_endpoint = 1;
1630 ho->endp_class = cichar;
1631 ho->endp_len = cilen;
1632 BCOPY(p, ho->endpoint, cilen);
1637 LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
1643 if (orc == CONFACK && /* Good CI */
1644 rc != CONFACK) /* but prior CI wasnt? */
1645 continue; /* Don't send this one */
1647 if (orc == CONFNAK) { /* Nak this CI? */
1648 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1649 && citype != CI_MAGICNUMBER) {
1650 orc = CONFREJ; /* Get tough if so */
1652 if (rc == CONFREJ) /* Rejecting prior CI? */
1653 continue; /* Don't send this one */
1657 if (orc == CONFREJ) { /* Reject this CI */
1659 if (cip != rejp) /* Need to move rejected CI? */
1660 BCOPY(cip, rejp, cilen); /* Move it */
1661 INCPTR(cilen, rejp); /* Update output pointer */
1666 * If we wanted to send additional NAKs (for unsent CIs), the
1667 * code would go here. The extra NAKs would go at *nakp.
1668 * At present there are no cases where we want to ask the
1669 * peer to negotiate an option.
1678 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1680 *lenp = nakp - nak_buffer;
1681 BCOPY(nak_buffer, inp, *lenp);
1688 LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
1689 return (rc); /* Return final code */
1694 * lcp_up - LCP has come UP.
1700 lcp_options *wo = &lcp_wantoptions[f->unit];
1701 lcp_options *ho = &lcp_hisoptions[f->unit];
1702 lcp_options *go = &lcp_gotoptions[f->unit];
1703 lcp_options *ao = &lcp_allowoptions[f->unit];
1705 if (!go->neg_magicnumber)
1706 go->magicnumber = 0;
1707 if (!ho->neg_magicnumber)
1708 ho->magicnumber = 0;
1711 * Set our MTU to the smaller of the MTU we wanted and
1712 * the MRU our peer wanted. If we negotiated an MRU,
1713 * set our MRU to the larger of value we wanted and
1714 * the value we got in the negotiation.
1716 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
1717 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1718 ho->neg_pcompression, ho->neg_accompression);
1719 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
1720 (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
1721 go->neg_pcompression, go->neg_accompression);
1724 peer_mru[f->unit] = ho->mru;
1726 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1728 link_established(f->unit);
1733 * lcp_down - LCP has gone DOWN.
1735 * Alert other protocols.
1741 lcp_options *go = &lcp_gotoptions[f->unit];
1743 lcp_echo_lowerdown(f->unit);
1747 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1748 ppp_recv_config(f->unit, PPP_MRU,
1749 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1750 go->neg_pcompression, go->neg_accompression);
1751 peer_mru[f->unit] = PPP_MRU;
1756 * lcp_starting - LCP needs the lower layer up.
1762 link_required(f->unit);
1767 * lcp_finished - LCP has finished with the lower layer.
1773 link_terminated(f->unit);
1778 * lcp_printpkt - print the contents of an LCP packet.
1780 static char *lcp_codenames[] = {
1781 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1782 "TermReq", "TermAck", "CodeRej", "ProtRej",
1783 "EchoReq", "EchoRep", "DiscReq"
1786 static char *endp_class_names[] = {
1787 "null", "local", "IP", "MAC", "magic", "phone"
1791 lcp_printpkt(p, plen, printer, arg)
1794 void (*printer) __P((void *, char *, ...));
1797 int code, id, len, olen, i;
1798 u_char *pstart, *optend;
1803 if (plen < HEADERLEN)
1809 if (len < HEADERLEN || len > plen)
1812 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1813 printer(arg, " %s", lcp_codenames[code-1]);
1815 printer(arg, " code=0x%x", code);
1816 printer(arg, " id=0x%x", id);
1823 /* print option list */
1828 if (olen < 2 || olen > len) {
1836 if (olen == CILEN_SHORT) {
1838 GETSHORT(cishort, p);
1839 printer(arg, "mru %d", cishort);
1843 if (olen == CILEN_LONG) {
1846 printer(arg, "asyncmap 0x%x", cilong);
1850 if (olen >= CILEN_SHORT) {
1852 printer(arg, "auth ");
1853 GETSHORT(cishort, p);
1856 printer(arg, "pap");
1859 printer(arg, "chap");
1862 case CHAP_DIGEST_MD5:
1863 printer(arg, " MD5");
1867 case CHAP_MICROSOFT:
1868 printer(arg, " m$oft");
1876 printer(arg, "0x%x", cishort);
1881 if (olen >= CILEN_SHORT) {
1883 printer(arg, "quality ");
1884 GETSHORT(cishort, p);
1887 printer(arg, "lqr");
1890 printer(arg, "0x%x", cishort);
1895 if (olen >= CILEN_CHAR) {
1897 printer(arg, "callback ");
1898 GETCHAR(cishort, p);
1901 printer(arg, "CBCP");
1904 printer(arg, "0x%x", cishort);
1908 case CI_MAGICNUMBER:
1909 if (olen == CILEN_LONG) {
1912 printer(arg, "magic 0x%x", cilong);
1915 case CI_PCOMPRESSION:
1916 if (olen == CILEN_VOID) {
1918 printer(arg, "pcomp");
1921 case CI_ACCOMPRESSION:
1922 if (olen == CILEN_VOID) {
1924 printer(arg, "accomp");
1928 if (olen == CILEN_SHORT) {
1930 GETSHORT(cishort, p);
1931 printer(arg, "mrru %d", cishort);
1935 if (olen == CILEN_VOID) {
1937 printer(arg, "ssnhf");
1941 if (olen >= CILEN_CHAR) {
1945 printer(arg, "endpoint [%s]:",
1946 endp_class_names[cichar]);
1948 printer(arg, "endpoint [%d]:");
1952 while (p < optend) {
1954 printer(arg, " %.2x", code);
1962 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1964 print_string(p, len, printer, arg);
1975 printer(arg, " magic=0x%x", cilong);
1982 /* print the rest of the bytes in the packet */
1983 for (i = 0; i < len && i < 32; ++i) {
1985 printer(arg, " %.2x", code);
1988 printer(arg, " ...");
1996 * Time to shut down the link because there is nothing out there.
2000 void LcpLinkFailure (f)
2003 if (f->state == OPENED) {
2004 info("No response to %d echo-requests", lcp_echos_pending);
2005 notice("Serial link appears to be disconnected.");
2006 lcp_close(f->unit, "Peer not responding");
2007 status = EXIT_PEER_DEAD;
2012 * Timer expired for the LCP echo requests from this process.
2019 LcpSendEchoRequest (f);
2020 if (f->state != OPENED)
2024 * Start the timer for the next interval.
2026 if (lcp_echo_timer_running)
2027 warn("assertion lcp_echo_timer_running==0 failed");
2028 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
2029 lcp_echo_timer_running = 1;
2033 * LcpEchoTimeout - Timer expired on the LCP echo
2037 LcpEchoTimeout (arg)
2040 if (lcp_echo_timer_running != 0) {
2041 lcp_echo_timer_running = 0;
2042 LcpEchoCheck ((fsm *) arg);
2047 * LcpEchoReply - LCP has received a reply to the echo
2051 lcp_received_echo_reply (f, id, inp, len)
2059 /* Check the magic number - don't count replies from ourselves. */
2061 dbglog("lcp: received short Echo-Reply, length %d", len);
2064 GETLONG(magic, inp);
2065 if (lcp_gotoptions[f->unit].neg_magicnumber
2066 && magic == lcp_gotoptions[f->unit].magicnumber) {
2067 warn("appear to have received our own echo-reply!");
2071 /* Reset the number of outstanding echo frames */
2072 lcp_echos_pending = 0;
2076 * LcpSendEchoRequest - Send an echo request frame to the peer
2080 LcpSendEchoRequest (f)
2083 u_int32_t lcp_magic;
2084 u_char pkt[4], *pktp;
2087 * Detect the failure of the peer at this point.
2089 if (lcp_echo_fails != 0) {
2090 if (lcp_echos_pending >= lcp_echo_fails) {
2092 lcp_echos_pending = 0;
2097 * Make and send the echo request frame.
2099 if (f->state == OPENED) {
2100 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
2102 PUTLONG(lcp_magic, pktp);
2103 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
2104 ++lcp_echos_pending;
2109 * lcp_echo_lowerup - Start the timer for the LCP frame
2113 lcp_echo_lowerup (unit)
2116 fsm *f = &lcp_fsm[unit];
2118 /* Clear the parameters for generating echo frames */
2119 lcp_echos_pending = 0;
2120 lcp_echo_number = 0;
2121 lcp_echo_timer_running = 0;
2123 /* If a timeout interval is specified then start the timer */
2124 if (lcp_echo_interval != 0)
2129 * lcp_echo_lowerdown - Stop the timer for the LCP frame
2133 lcp_echo_lowerdown (unit)
2136 fsm *f = &lcp_fsm[unit];
2138 if (lcp_echo_timer_running != 0) {
2139 UNTIMEOUT (LcpEchoTimeout, f);
2140 lcp_echo_timer_running = 0;