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.
21 static char rcsid[] = "$Id: lcp.c,v 1.33 1998/11/07 06:59:27 paulus Exp $";
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
46 * LCP-related command-line options.
48 int lcp_echo_interval = 0; /* Interval between LCP echo-requests */
49 int lcp_echo_fails = 0; /* Tolerance to unanswered echo-requests */
51 static int setescape __P((char **));
53 static option_t lcp_option_list[] = {
55 { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
56 "Disable address/control compression",
57 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
58 { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
59 "Disable address/control compression",
60 OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
61 { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
62 "Disable asyncmap negotiation",
63 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
64 { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
65 "Disable asyncmap negotiation",
66 OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
67 { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
68 "Set asyncmap (for received packets)",
69 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
70 { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
71 "Set asyncmap (for received packets)",
72 OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
73 { "nomagicnumber", o_bool, &lcp_wantoptions[0].neg_magicnumber,
74 "Disable magic number negotiation (looped-back line detection)",
75 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
76 { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
77 "Disable magic number negotiation (looped-back line detection)",
78 OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
79 { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
80 "Disable MRU negotiation (use default 1500)",
81 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
82 { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
83 "Disable MRU negotiation (use default 1500)",
84 OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
85 { "mru", o_int, &lcp_wantoptions[0].mru,
86 "Set MRU (maximum received packet size) for negotiation",
87 0, &lcp_wantoptions[0].neg_mru },
88 { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
89 "Disable protocol field compression",
90 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
91 { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
92 "Disable protocol field compression",
93 OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
94 { "-p", o_bool, &lcp_wantoptions[0].passive,
95 "Set passive mode", 1 },
96 { "passive", o_bool, &lcp_wantoptions[0].passive,
97 "Set passive mode", 1 },
98 { "silent", o_bool, &lcp_wantoptions[0].silent,
99 "Set silent mode", 1 },
100 { "escape", o_special, setescape,
101 "List of character codes to escape on transmission" },
102 { "lcp-echo-failure", o_int, &lcp_echo_fails,
103 "Set number of consecutive echo failures to indicate link failure" },
104 { "lcp-echo-interval", o_int, &lcp_echo_interval,
105 "Set time in seconds between LCP echo requests" },
106 { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
107 "Set time in seconds between LCP retransmissions" },
108 { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
109 "Set maximum number of LCP terminate-request transmissions" },
110 { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
111 "Set maximum number of LCP configure-request transmissions" },
112 { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
113 "Set limit on number of LCP configure-naks" },
118 fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
119 lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
120 lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
121 lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
122 lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
123 u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
125 static u_int32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
126 static u_int32_t lcp_echo_number = 0; /* ID number of next echo frame */
127 static u_int32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */
129 static u_char nak_buffer[PPP_MRU]; /* where we construct a nak packet */
132 * Callbacks for fsm code. (CI = Configuration Information)
134 static void lcp_resetci __P((fsm *)); /* Reset our CI */
135 static int lcp_cilen __P((fsm *)); /* Return length of our CI */
136 static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
137 static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
138 static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
139 static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
140 static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
141 static void lcp_up __P((fsm *)); /* We're UP */
142 static void lcp_down __P((fsm *)); /* We're DOWN */
143 static void lcp_starting __P((fsm *)); /* We need lower layer up */
144 static void lcp_finished __P((fsm *)); /* We need lower layer down */
145 static int lcp_extcode __P((fsm *, int, int, u_char *, int));
146 static void lcp_rprotrej __P((fsm *, u_char *, int));
149 * routines to send LCP echos to peer
152 static void lcp_echo_lowerup __P((int));
153 static void lcp_echo_lowerdown __P((int));
154 static void LcpEchoTimeout __P((void *));
155 static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
156 static void LcpSendEchoRequest __P((fsm *));
157 static void LcpLinkFailure __P((fsm *));
158 static void LcpEchoCheck __P((fsm *));
160 static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
161 lcp_resetci, /* Reset our Configuration Information */
162 lcp_cilen, /* Length of our Configuration Information */
163 lcp_addci, /* Add our Configuration Information */
164 lcp_ackci, /* ACK our Configuration Information */
165 lcp_nakci, /* NAK our Configuration Information */
166 lcp_rejci, /* Reject our Configuration Information */
167 lcp_reqci, /* Request peer's Configuration Information */
168 lcp_up, /* Called when fsm reaches OPENED state */
169 lcp_down, /* Called when fsm leaves OPENED state */
170 lcp_starting, /* Called when we want the lower layer up */
171 lcp_finished, /* Called when we want the lower layer down */
172 NULL, /* Called when Protocol-Reject received */
173 NULL, /* Retransmission is necessary */
174 lcp_extcode, /* Called to handle LCP-specific codes */
175 "LCP" /* String name of protocol */
179 * Protocol entry points.
180 * Some of these are called directly.
183 static void lcp_init __P((int));
184 static void lcp_input __P((int, u_char *, int));
185 static void lcp_protrej __P((int));
186 static int lcp_printpkt __P((u_char *, int,
187 void (*) __P((void *, char *, ...)), void *));
189 struct protent lcp_protent = {
208 int lcp_loopbackfail = DEFLOOPBACKFAIL;
211 * Length of each type of configuration option (in octets)
215 #define CILEN_SHORT 4 /* CILEN_VOID + sizeof(short) */
216 #define CILEN_CHAP 5 /* CILEN_VOID + sizeof(short) + 1 */
217 #define CILEN_LONG 6 /* CILEN_VOID + sizeof(long) */
218 #define CILEN_LQR 8 /* CILEN_VOID + sizeof(short) + sizeof(long) */
221 #define CODENAME(x) ((x) == CONFACK ? "ACK" : \
222 (x) == CONFNAK ? "NAK" : "REJ")
226 * setescape - add chars to the set we escape on transmission.
238 n = strtol(p, &endp, 16);
240 option_error("escape parameter contains invalid hex number '%s'",
245 if (n < 0 || (0x20 <= n && n <= 0x3F) || n == 0x5E || n > 0xFF) {
246 option_error("can't escape character 0x%x", n);
249 xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
250 while (*p == ',' || *p == ' ')
257 * lcp_init - Initialize LCP.
263 fsm *f = &lcp_fsm[unit];
264 lcp_options *wo = &lcp_wantoptions[unit];
265 lcp_options *ao = &lcp_allowoptions[unit];
268 f->protocol = PPP_LCP;
269 f->callbacks = &lcp_callbacks;
275 wo->restart = 0; /* Set to 1 in kernels or multi-line
279 wo->neg_asyncmap = 0;
281 wo->neg_chap = 0; /* Set to 1 on server */
282 wo->neg_upap = 0; /* Set to 1 on server */
283 wo->chap_mdtype = CHAP_DIGEST_MD5;
284 wo->neg_magicnumber = 1;
285 wo->neg_pcompression = 1;
286 wo->neg_accompression = 1;
287 wo->neg_lqr = 0; /* no LQR implementation yet */
292 ao->neg_asyncmap = 1;
295 ao->chap_mdtype = CHAP_DIGEST_MD5;
297 ao->neg_magicnumber = 1;
298 ao->neg_pcompression = 1;
299 ao->neg_accompression = 1;
300 ao->neg_lqr = 0; /* no LQR implementation yet */
307 memset(xmit_accm[unit], 0, sizeof(xmit_accm[0]));
308 xmit_accm[unit][3] = 0x60000000;
313 * lcp_open - LCP is allowed to come up.
319 fsm *f = &lcp_fsm[unit];
320 lcp_options *wo = &lcp_wantoptions[unit];
324 f->flags |= OPT_PASSIVE;
326 f->flags |= OPT_SILENT;
332 * lcp_close - Take LCP down.
335 lcp_close(unit, reason)
339 fsm *f = &lcp_fsm[unit];
341 if (phase != PHASE_DEAD)
342 phase = PHASE_TERMINATE;
343 if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
345 * This action is not strictly according to the FSM in RFC1548,
346 * but it does mean that the program terminates if you do a
347 * lcp_close() in passive/silent mode when a connection hasn't
354 fsm_close(&lcp_fsm[unit], reason);
359 * lcp_lowerup - The lower layer is up.
365 lcp_options *wo = &lcp_wantoptions[unit];
368 * Don't use A/C or protocol compression on transmission,
369 * but accept A/C and protocol compressed packets
370 * if we are going to ask for A/C and protocol compression.
372 ppp_set_xaccm(unit, xmit_accm[unit]);
373 ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
374 ppp_recv_config(unit, PPP_MRU, 0xffffffff,
375 wo->neg_pcompression, wo->neg_accompression);
376 peer_mru[unit] = PPP_MRU;
377 lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
379 fsm_lowerup(&lcp_fsm[unit]);
384 * lcp_lowerdown - The lower layer is down.
390 fsm_lowerdown(&lcp_fsm[unit]);
395 * lcp_input - Input LCP packet.
398 lcp_input(unit, p, len)
403 fsm *f = &lcp_fsm[unit];
405 fsm_input(f, p, len);
410 * lcp_extcode - Handle a LCP-specific code.
413 lcp_extcode(f, code, id, inp, len)
423 lcp_rprotrej(f, inp, len);
427 if (f->state != OPENED)
429 LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id));
431 PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
432 fsm_sdata(f, ECHOREP, id, inp, len);
436 lcp_received_echo_reply(f, id, inp, len);
450 * lcp_rprotrej - Receive an Protocol-Reject.
452 * Figure out which protocol is rejected and inform it.
455 lcp_rprotrej(f, inp, len)
461 struct protent *protp;
464 LCPDEBUG((LOG_INFO, "lcp_rprotrej."));
466 if (len < sizeof (u_short)) {
468 "lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
475 "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!",
479 * Protocol-Reject packets received in any state other than the LCP
480 * OPENED state SHOULD be silently discarded.
482 if( f->state != OPENED ){
483 LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d",
489 * Upcall the proper Protocol-Reject routine.
491 for (i = 0; (protp = protocols[i]) != NULL; ++i)
492 if (protp->protocol == prot && protp->enabled_flag) {
493 (*protp->protrej)(f->unit);
497 syslog(LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x",
503 * lcp_protrej - A Protocol-Reject was received.
513 LCPDEBUG((LOG_WARNING,
514 "lcp_protrej: Received Protocol-Reject for LCP!"));
515 fsm_protreject(&lcp_fsm[unit]);
520 * lcp_sprotrej - Send a Protocol-Reject for some protocol.
523 lcp_sprotrej(unit, p, len)
529 * Send back the protocol and the information field of the
530 * rejected packet. We only get here if LCP is in the OPENED state.
535 fsm_sdata(&lcp_fsm[unit], PROTREJ, ++lcp_fsm[unit].id,
541 * lcp_resetci - Reset our CI.
547 lcp_wantoptions[f->unit].magicnumber = magic();
548 lcp_wantoptions[f->unit].numloops = 0;
549 lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
550 peer_mru[f->unit] = PPP_MRU;
556 * lcp_cilen - Return length of our CI.
562 lcp_options *go = &lcp_gotoptions[f->unit];
564 #define LENCIVOID(neg) ((neg) ? CILEN_VOID : 0)
565 #define LENCICHAP(neg) ((neg) ? CILEN_CHAP : 0)
566 #define LENCISHORT(neg) ((neg) ? CILEN_SHORT : 0)
567 #define LENCILONG(neg) ((neg) ? CILEN_LONG : 0)
568 #define LENCILQR(neg) ((neg) ? CILEN_LQR: 0)
569 #define LENCICBCP(neg) ((neg) ? CILEN_CBCP: 0)
571 * NB: we only ask for one of CHAP and UPAP, even if we will
574 return (LENCISHORT(go->neg_mru && go->mru != DEFMRU) +
575 LENCILONG(go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) +
576 LENCICHAP(go->neg_chap) +
577 LENCISHORT(!go->neg_chap && go->neg_upap) +
578 LENCILQR(go->neg_lqr) +
579 LENCICBCP(go->neg_cbcp) +
580 LENCILONG(go->neg_magicnumber) +
581 LENCIVOID(go->neg_pcompression) +
582 LENCIVOID(go->neg_accompression));
587 * lcp_addci - Add our desired CIs to a packet.
590 lcp_addci(f, ucp, lenp)
595 lcp_options *go = &lcp_gotoptions[f->unit];
596 u_char *start_ucp = ucp;
598 #define ADDCIVOID(opt, neg) \
601 PUTCHAR(CILEN_VOID, ucp); \
603 #define ADDCISHORT(opt, neg, val) \
606 PUTCHAR(CILEN_SHORT, ucp); \
607 PUTSHORT(val, ucp); \
609 #define ADDCICHAP(opt, neg, val, digest) \
612 PUTCHAR(CILEN_CHAP, ucp); \
613 PUTSHORT(val, ucp); \
614 PUTCHAR(digest, ucp); \
616 #define ADDCILONG(opt, neg, val) \
619 PUTCHAR(CILEN_LONG, ucp); \
622 #define ADDCILQR(opt, neg, val) \
625 PUTCHAR(CILEN_LQR, ucp); \
626 PUTSHORT(PPP_LQR, ucp); \
629 #define ADDCICHAR(opt, neg, val) \
632 PUTCHAR(CILEN_CHAR, ucp); \
636 ADDCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
637 ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
639 ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
640 ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
641 ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
642 ADDCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
643 ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
644 ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
645 ADDCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
647 if (ucp - start_ucp != *lenp) {
648 /* this should never happen, because peer_mtu should be 1500 */
649 syslog(LOG_ERR, "Bug in lcp_addci: wrong length");
655 * lcp_ackci - Ack our CIs.
656 * This should not modify any state if the Ack is bad.
668 lcp_options *go = &lcp_gotoptions[f->unit];
669 u_char cilen, citype, cichar;
674 * CIs must be in exactly the same order that we sent.
675 * Check packet length and CI length at each step.
676 * If we find any deviations, then this packet is bad.
678 #define ACKCIVOID(opt, neg) \
680 if ((len -= CILEN_VOID) < 0) \
682 GETCHAR(citype, p); \
684 if (cilen != CILEN_VOID || \
688 #define ACKCISHORT(opt, neg, val) \
690 if ((len -= CILEN_SHORT) < 0) \
692 GETCHAR(citype, p); \
694 if (cilen != CILEN_SHORT || \
697 GETSHORT(cishort, p); \
698 if (cishort != val) \
701 #define ACKCICHAR(opt, neg, val) \
703 if ((len -= CILEN_CHAR) < 0) \
705 GETCHAR(citype, p); \
707 if (cilen != CILEN_CHAR || \
710 GETCHAR(cichar, p); \
714 #define ACKCICHAP(opt, neg, val, digest) \
716 if ((len -= CILEN_CHAP) < 0) \
718 GETCHAR(citype, p); \
720 if (cilen != CILEN_CHAP || \
723 GETSHORT(cishort, p); \
724 if (cishort != val) \
726 GETCHAR(cichar, p); \
727 if (cichar != digest) \
730 #define ACKCILONG(opt, neg, val) \
732 if ((len -= CILEN_LONG) < 0) \
734 GETCHAR(citype, p); \
736 if (cilen != CILEN_LONG || \
739 GETLONG(cilong, p); \
743 #define ACKCILQR(opt, neg, val) \
745 if ((len -= CILEN_LQR) < 0) \
747 GETCHAR(citype, p); \
749 if (cilen != CILEN_LQR || \
752 GETSHORT(cishort, p); \
753 if (cishort != PPP_LQR) \
755 GETLONG(cilong, p); \
760 ACKCISHORT(CI_MRU, go->neg_mru && go->mru != DEFMRU, go->mru);
761 ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF,
763 ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
764 ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
765 ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
766 ACKCICHAR(CI_CALLBACK, go->neg_cbcp, CBCP_OPT);
767 ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
768 ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
769 ACKCIVOID(CI_ACCOMPRESSION, go->neg_accompression);
772 * If there are any remaining CIs, then this packet is bad.
778 LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!"));
784 * lcp_nakci - Peer has sent a NAK for some of our CIs.
785 * This should not modify any state if the Nak is bad
786 * or if LCP is in the OPENED state.
798 lcp_options *go = &lcp_gotoptions[f->unit];
799 lcp_options *wo = &lcp_wantoptions[f->unit];
800 u_char citype, cichar, *next;
803 lcp_options no; /* options we've seen Naks for */
804 lcp_options try; /* options to request next time */
808 BZERO(&no, sizeof(no));
812 * Any Nak'd CIs must be in exactly the same order that we sent.
813 * Check packet length and CI length at each step.
814 * If we find any deviations, then this packet is bad.
816 #define NAKCIVOID(opt, neg, code) \
818 len >= CILEN_VOID && \
819 p[1] == CILEN_VOID && \
822 INCPTR(CILEN_VOID, p); \
826 #define NAKCICHAP(opt, neg, code) \
828 len >= CILEN_CHAP && \
829 p[1] == CILEN_CHAP && \
833 GETSHORT(cishort, p); \
834 GETCHAR(cichar, p); \
838 #define NAKCICHAR(opt, neg, code) \
840 len >= CILEN_CHAR && \
841 p[1] == CILEN_CHAR && \
845 GETCHAR(cichar, p); \
849 #define NAKCISHORT(opt, neg, code) \
851 len >= CILEN_SHORT && \
852 p[1] == CILEN_SHORT && \
854 len -= CILEN_SHORT; \
856 GETSHORT(cishort, p); \
860 #define NAKCILONG(opt, neg, code) \
862 len >= CILEN_LONG && \
863 p[1] == CILEN_LONG && \
867 GETLONG(cilong, p); \
871 #define NAKCILQR(opt, neg, code) \
873 len >= CILEN_LQR && \
874 p[1] == CILEN_LQR && \
878 GETSHORT(cishort, p); \
879 GETLONG(cilong, p); \
885 * We don't care if they want to send us smaller packets than
886 * we want. Therefore, accept any MRU less than what we asked for,
887 * but then ignore the new value when setting the MRU in the kernel.
888 * If they send us a bigger MRU than what we asked, accept it, up to
889 * the limit of the default MRU we'd get if we didn't negotiate.
891 if (go->neg_mru && go->mru != DEFMRU) {
892 NAKCISHORT(CI_MRU, neg_mru,
893 if (cishort <= wo->mru || cishort <= DEFMRU)
899 * Add any characters they want to our (receive-side) asyncmap.
901 if (go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF) {
902 NAKCILONG(CI_ASYNCMAP, neg_asyncmap,
903 try.asyncmap = go->asyncmap | cilong;
908 * If they've nak'd our authentication-protocol, check whether
909 * they are proposing a different protocol, or a different
910 * hash algorithm for CHAP.
912 if ((go->neg_chap || go->neg_upap)
913 && len >= CILEN_SHORT
914 && p[0] == CI_AUTHTYPE && p[1] >= CILEN_SHORT && p[1] <= len) {
917 no.neg_chap = go->neg_chap;
918 no.neg_upap = go->neg_upap;
920 GETSHORT(cishort, p);
921 if (cishort == PPP_PAP && cilen == CILEN_SHORT) {
923 * If we were asking for CHAP, they obviously don't want to do it.
924 * If we weren't asking for CHAP, then we were asking for PAP,
925 * in which case this Nak is bad.
931 } else if (cishort == PPP_CHAP && cilen == CILEN_CHAP) {
935 * We were asking for CHAP/MD5; they must want a different
936 * algorithm. If they can't do MD5, we'll have to stop
939 if (cichar != go->chap_mdtype)
943 * Stop asking for PAP if we were asking for it.
950 * We don't recognize what they're suggesting.
951 * Stop asking for what we were asking for.
957 p += cilen - CILEN_SHORT;
962 * If they can't cope with our link quality protocol, we'll have
963 * to stop asking for LQR. We haven't got any other protocol.
964 * If they Nak the reporting period, take their value XXX ?
966 NAKCILQR(CI_QUALITY, neg_lqr,
967 if (cishort != PPP_LQR)
970 try.lqr_period = cilong;
974 * Only implementing CBCP...not the rest of the callback options
976 NAKCICHAR(CI_CALLBACK, neg_cbcp,
981 * Check for a looped-back line.
983 NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
984 try.magicnumber = magic();
989 * Peer shouldn't send Nak for protocol compression or
990 * address/control compression requests; they should send
991 * a Reject instead. If they send a Nak, treat it as a Reject.
993 NAKCIVOID(CI_PCOMPRESSION, neg_pcompression,
994 try.neg_pcompression = 0;
996 NAKCIVOID(CI_ACCOMPRESSION, neg_accompression,
997 try.neg_accompression = 0;
1001 * There may be remaining CIs, if the peer is requesting negotiation
1002 * on an option that we didn't include in our request packet.
1003 * If we see an option that we requested, or one we've already seen
1004 * in this packet, then this packet is bad.
1005 * If we wanted to respond by starting to negotiate on the requested
1006 * option(s), we could, but we don't, because except for the
1007 * authentication type and quality protocol, if we are not negotiating
1008 * an option, it is because we were told not to.
1009 * For the authentication type, the Nak from the peer means
1010 * `let me authenticate myself with you' which is a bit pointless.
1011 * For the quality protocol, the Nak means `ask me to send you quality
1012 * reports', but if we didn't ask for them, we don't want them.
1013 * An option we don't recognize represents the peer asking to
1014 * negotiate some option we don't support, so ignore it.
1016 while (len > CILEN_VOID) {
1019 if (cilen < CILEN_VOID || (len -= cilen) < 0)
1021 next = p + cilen - 2;
1025 if ((go->neg_mru && go->mru != DEFMRU)
1026 || no.neg_mru || cilen != CILEN_SHORT)
1028 GETSHORT(cishort, p);
1029 if (cishort < DEFMRU)
1033 if ((go->neg_asyncmap && go->asyncmap != 0xFFFFFFFF)
1034 || no.neg_asyncmap || cilen != CILEN_LONG)
1038 if (go->neg_chap || no.neg_chap || go->neg_upap || no.neg_upap)
1041 case CI_MAGICNUMBER:
1042 if (go->neg_magicnumber || no.neg_magicnumber ||
1043 cilen != CILEN_LONG)
1046 case CI_PCOMPRESSION:
1047 if (go->neg_pcompression || no.neg_pcompression
1048 || cilen != CILEN_VOID)
1051 case CI_ACCOMPRESSION:
1052 if (go->neg_accompression || no.neg_accompression
1053 || cilen != CILEN_VOID)
1057 if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
1064 /* If there is still anything left, this packet is bad. */
1069 * OK, the Nak is good. Now we can update state.
1071 if (f->state != OPENED) {
1073 if (++try.numloops >= lcp_loopbackfail) {
1074 syslog(LOG_NOTICE, "Serial line is looped back.");
1075 lcp_close(f->unit, "Loopback detected");
1085 LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!"));
1091 * lcp_rejci - Peer has Rejected some of our CIs.
1092 * This should not modify any state if the Reject is bad
1093 * or if LCP is in the OPENED state.
1096 * 0 - Reject was bad.
1097 * 1 - Reject was good.
1100 lcp_rejci(f, p, len)
1105 lcp_options *go = &lcp_gotoptions[f->unit];
1109 lcp_options try; /* options to request next time */
1114 * Any Rejected CIs must be in exactly the same order that we sent.
1115 * Check packet length and CI length at each step.
1116 * If we find any deviations, then this packet is bad.
1118 #define REJCIVOID(opt, neg) \
1120 len >= CILEN_VOID && \
1121 p[1] == CILEN_VOID && \
1123 len -= CILEN_VOID; \
1124 INCPTR(CILEN_VOID, p); \
1126 LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \
1128 #define REJCISHORT(opt, neg, val) \
1130 len >= CILEN_SHORT && \
1131 p[1] == CILEN_SHORT && \
1133 len -= CILEN_SHORT; \
1135 GETSHORT(cishort, p); \
1136 /* Check rejected value. */ \
1137 if (cishort != val) \
1140 LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \
1142 #define REJCICHAP(opt, neg, val, digest) \
1144 len >= CILEN_CHAP && \
1145 p[1] == CILEN_CHAP && \
1147 len -= CILEN_CHAP; \
1149 GETSHORT(cishort, p); \
1150 GETCHAR(cichar, p); \
1151 /* Check rejected value. */ \
1152 if (cishort != val || cichar != digest) \
1156 LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \
1158 #define REJCILONG(opt, neg, val) \
1160 len >= CILEN_LONG && \
1161 p[1] == CILEN_LONG && \
1163 len -= CILEN_LONG; \
1165 GETLONG(cilong, p); \
1166 /* Check rejected value. */ \
1167 if (cilong != val) \
1170 LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \
1172 #define REJCILQR(opt, neg, val) \
1174 len >= CILEN_LQR && \
1175 p[1] == CILEN_LQR && \
1179 GETSHORT(cishort, p); \
1180 GETLONG(cilong, p); \
1181 /* Check rejected value. */ \
1182 if (cishort != PPP_LQR || cilong != val) \
1185 LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
1187 #define REJCICBCP(opt, neg, val) \
1189 len >= CILEN_CBCP && \
1190 p[1] == CILEN_CBCP && \
1192 len -= CILEN_CBCP; \
1194 GETCHAR(cichar, p); \
1195 /* Check rejected value. */ \
1196 if (cichar != val) \
1199 LCPDEBUG((LOG_INFO,"lcp_rejci rejected Callback opt %d", opt)); \
1202 REJCISHORT(CI_MRU, neg_mru, go->mru);
1203 REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
1204 REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
1205 if (!go->neg_chap) {
1206 REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
1208 REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
1209 REJCICBCP(CI_CALLBACK, neg_cbcp, CBCP_OPT);
1210 REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
1211 REJCIVOID(CI_PCOMPRESSION, neg_pcompression);
1212 REJCIVOID(CI_ACCOMPRESSION, neg_accompression);
1215 * If there are any remaining CIs, then this packet is bad.
1220 * Now we can update state.
1222 if (f->state != OPENED)
1227 LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!"));
1233 * lcp_reqci - Check the peer's requested CIs and send appropriate response.
1235 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
1236 * appropriately. If reject_if_disagree is non-zero, doesn't return
1237 * CONFNAK; returns CONFREJ if it can't return CONFACK.
1240 lcp_reqci(f, inp, lenp, reject_if_disagree)
1242 u_char *inp; /* Requested CIs */
1243 int *lenp; /* Length of requested CIs */
1244 int reject_if_disagree;
1246 lcp_options *go = &lcp_gotoptions[f->unit];
1247 lcp_options *ho = &lcp_hisoptions[f->unit];
1248 lcp_options *ao = &lcp_allowoptions[f->unit];
1249 u_char *cip, *next; /* Pointer to current and next CIs */
1250 int cilen, citype, cichar; /* Parsed len, type, char value */
1251 u_short cishort; /* Parsed short value */
1252 u_int32_t cilong; /* Parse long value */
1253 int rc = CONFACK; /* Final packet return code */
1254 int orc; /* Individual option return code */
1255 u_char *p; /* Pointer to next char to parse */
1256 u_char *rejp; /* Pointer to next char in reject frame */
1257 u_char *nakp; /* Pointer to next char in Nak frame */
1258 int l = *lenp; /* Length left */
1261 * Reset all his options.
1263 BZERO(ho, sizeof(*ho));
1266 * Process all his options.
1272 orc = CONFACK; /* Assume success */
1273 cip = p = next; /* Remember begining of CI */
1274 if (l < 2 || /* Not enough data for CI header or */
1275 p[1] < 2 || /* CI length too small or */
1276 p[1] > l) { /* CI length too big? */
1277 LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!"));
1278 orc = CONFREJ; /* Reject bad CI */
1279 cilen = l; /* Reject till end of packet */
1280 l = 0; /* Don't loop again */
1284 GETCHAR(citype, p); /* Parse CI type */
1285 GETCHAR(cilen, p); /* Parse CI length */
1286 l -= cilen; /* Adjust remaining length */
1287 next += cilen; /* Step to next CI */
1289 switch (citype) { /* Check CI type */
1291 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU"));
1292 if (!ao->neg_mru || /* Allow option? */
1293 cilen != CILEN_SHORT) { /* Check CI length */
1294 orc = CONFREJ; /* Reject CI */
1297 GETSHORT(cishort, p); /* Parse MRU */
1298 LCPDEBUG((LOG_INFO, "(%d)", cishort));
1301 * He must be able to receive at least our minimum.
1302 * No need to check a maximum. If he sends a large number,
1303 * we'll just ignore it.
1305 if (cishort < MINMRU) {
1306 orc = CONFNAK; /* Nak CI */
1307 PUTCHAR(CI_MRU, nakp);
1308 PUTCHAR(CILEN_SHORT, nakp);
1309 PUTSHORT(MINMRU, nakp); /* Give him a hint */
1312 ho->neg_mru = 1; /* Remember he sent MRU */
1313 ho->mru = cishort; /* And remember value */
1317 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP"));
1318 if (!ao->neg_asyncmap ||
1319 cilen != CILEN_LONG) {
1324 LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
1327 * Asyncmap must have set at least the bits
1328 * which are set in lcp_allowoptions[unit].asyncmap.
1330 if ((ao->asyncmap & ~cilong) != 0) {
1332 PUTCHAR(CI_ASYNCMAP, nakp);
1333 PUTCHAR(CILEN_LONG, nakp);
1334 PUTLONG(ao->asyncmap | cilong, nakp);
1337 ho->neg_asyncmap = 1;
1338 ho->asyncmap = cilong;
1342 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE"));
1343 if (cilen < CILEN_SHORT ||
1344 !(ao->neg_upap || ao->neg_chap)) {
1346 * Reject the option if we're not willing to authenticate.
1351 GETSHORT(cishort, p);
1352 LCPDEBUG((LOG_INFO, "(%x)", cishort));
1355 * Authtype must be UPAP or CHAP.
1357 * Note: if both ao->neg_upap and ao->neg_chap are set,
1358 * and the peer sends a Configure-Request with two
1359 * authenticate-protocol requests, one for CHAP and one
1360 * for UPAP, then we will reject the second request.
1361 * Whether we end up doing CHAP or UPAP depends then on
1362 * the ordering of the CIs in the peer's Configure-Request.
1365 if (cishort == PPP_PAP) {
1366 if (ho->neg_chap || /* we've already accepted CHAP */
1367 cilen != CILEN_SHORT) {
1368 LCPDEBUG((LOG_WARNING,
1369 "lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
1373 if (!ao->neg_upap) { /* we don't want to do PAP */
1374 orc = CONFNAK; /* NAK it and suggest CHAP */
1375 PUTCHAR(CI_AUTHTYPE, nakp);
1376 PUTCHAR(CILEN_CHAP, nakp);
1377 PUTSHORT(PPP_CHAP, nakp);
1378 PUTCHAR(ao->chap_mdtype, nakp);
1384 if (cishort == PPP_CHAP) {
1385 if (ho->neg_upap || /* we've already accepted PAP */
1386 cilen != CILEN_CHAP) {
1388 "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
1392 if (!ao->neg_chap) { /* we don't want to do CHAP */
1393 orc = CONFNAK; /* NAK it and suggest PAP */
1394 PUTCHAR(CI_AUTHTYPE, nakp);
1395 PUTCHAR(CILEN_SHORT, nakp);
1396 PUTSHORT(PPP_PAP, nakp);
1399 GETCHAR(cichar, p); /* get digest type*/
1400 if (cichar != CHAP_DIGEST_MD5
1402 && cichar != CHAP_MICROSOFT
1406 PUTCHAR(CI_AUTHTYPE, nakp);
1407 PUTCHAR(CILEN_CHAP, nakp);
1408 PUTSHORT(PPP_CHAP, nakp);
1409 PUTCHAR(ao->chap_mdtype, nakp);
1412 ho->chap_mdtype = cichar; /* save md type */
1418 * We don't recognize the protocol they're asking for.
1419 * Nak it with something we're willing to do.
1420 * (At this point we know ao->neg_upap || ao->neg_chap.)
1423 PUTCHAR(CI_AUTHTYPE, nakp);
1425 PUTCHAR(CILEN_CHAP, nakp);
1426 PUTSHORT(PPP_CHAP, nakp);
1427 PUTCHAR(ao->chap_mdtype, nakp);
1429 PUTCHAR(CILEN_SHORT, nakp);
1430 PUTSHORT(PPP_PAP, nakp);
1435 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY"));
1437 cilen != CILEN_LQR) {
1442 GETSHORT(cishort, p);
1444 LCPDEBUG((LOG_INFO, "(%x %x)", cishort, (unsigned int) cilong));
1447 * Check the protocol and the reporting period.
1448 * XXX When should we Nak this, and what with?
1450 if (cishort != PPP_LQR) {
1452 PUTCHAR(CI_QUALITY, nakp);
1453 PUTCHAR(CILEN_LQR, nakp);
1454 PUTSHORT(PPP_LQR, nakp);
1455 PUTLONG(ao->lqr_period, nakp);
1460 case CI_MAGICNUMBER:
1461 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER"));
1462 if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
1463 cilen != CILEN_LONG) {
1468 LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
1471 * He must have a different magic number.
1473 if (go->neg_magicnumber &&
1474 cilong == go->magicnumber) {
1475 cilong = magic(); /* Don't put magic() inside macro! */
1477 PUTCHAR(CI_MAGICNUMBER, nakp);
1478 PUTCHAR(CILEN_LONG, nakp);
1479 PUTLONG(cilong, nakp);
1482 ho->neg_magicnumber = 1;
1483 ho->magicnumber = cilong;
1487 case CI_PCOMPRESSION:
1488 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION"));
1489 if (!ao->neg_pcompression ||
1490 cilen != CILEN_VOID) {
1494 ho->neg_pcompression = 1;
1497 case CI_ACCOMPRESSION:
1498 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION"));
1499 if (!ao->neg_accompression ||
1500 cilen != CILEN_VOID) {
1504 ho->neg_accompression = 1;
1508 LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d",
1515 LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc)));
1516 if (orc == CONFACK && /* Good CI */
1517 rc != CONFACK) /* but prior CI wasnt? */
1518 continue; /* Don't send this one */
1520 if (orc == CONFNAK) { /* Nak this CI? */
1521 if (reject_if_disagree /* Getting fed up with sending NAKs? */
1522 && citype != CI_MAGICNUMBER) {
1523 orc = CONFREJ; /* Get tough if so */
1525 if (rc == CONFREJ) /* Rejecting prior CI? */
1526 continue; /* Don't send this one */
1530 if (orc == CONFREJ) { /* Reject this CI */
1532 if (cip != rejp) /* Need to move rejected CI? */
1533 BCOPY(cip, rejp, cilen); /* Move it */
1534 INCPTR(cilen, rejp); /* Update output pointer */
1539 * If we wanted to send additional NAKs (for unsent CIs), the
1540 * code would go here. The extra NAKs would go at *nakp.
1541 * At present there are no cases where we want to ask the
1542 * peer to negotiate an option.
1551 * Copy the Nak'd options from the nak_buffer to the caller's buffer.
1553 *lenp = nakp - nak_buffer;
1554 BCOPY(nak_buffer, inp, *lenp);
1561 LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc)));
1562 return (rc); /* Return final code */
1567 * lcp_up - LCP has come UP.
1573 lcp_options *wo = &lcp_wantoptions[f->unit];
1574 lcp_options *ho = &lcp_hisoptions[f->unit];
1575 lcp_options *go = &lcp_gotoptions[f->unit];
1576 lcp_options *ao = &lcp_allowoptions[f->unit];
1578 if (!go->neg_magicnumber)
1579 go->magicnumber = 0;
1580 if (!ho->neg_magicnumber)
1581 ho->magicnumber = 0;
1584 * Set our MTU to the smaller of the MTU we wanted and
1585 * the MRU our peer wanted. If we negotiated an MRU,
1586 * set our MRU to the larger of value we wanted and
1587 * the value we got in the negotiation.
1589 ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
1590 (ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
1591 ho->neg_pcompression, ho->neg_accompression);
1592 ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
1593 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1594 go->neg_pcompression, go->neg_accompression);
1597 peer_mru[f->unit] = ho->mru;
1599 lcp_echo_lowerup(f->unit); /* Enable echo messages */
1601 link_established(f->unit);
1606 * lcp_down - LCP has gone DOWN.
1608 * Alert other protocols.
1614 lcp_options *go = &lcp_gotoptions[f->unit];
1616 lcp_echo_lowerdown(f->unit);
1620 ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
1621 ppp_recv_config(f->unit, PPP_MRU,
1622 (go->neg_asyncmap? go->asyncmap: 0xffffffff),
1623 go->neg_pcompression, go->neg_accompression);
1624 peer_mru[f->unit] = PPP_MRU;
1629 * lcp_starting - LCP needs the lower layer up.
1635 link_required(f->unit);
1640 * lcp_finished - LCP has finished with the lower layer.
1646 link_terminated(f->unit);
1651 * lcp_printpkt - print the contents of an LCP packet.
1653 static char *lcp_codenames[] = {
1654 "ConfReq", "ConfAck", "ConfNak", "ConfRej",
1655 "TermReq", "TermAck", "CodeRej", "ProtRej",
1656 "EchoReq", "EchoRep", "DiscReq"
1660 lcp_printpkt(p, plen, printer, arg)
1663 void (*printer) __P((void *, char *, ...));
1666 int code, id, len, olen;
1667 u_char *pstart, *optend;
1671 if (plen < HEADERLEN)
1677 if (len < HEADERLEN || len > plen)
1680 if (code >= 1 && code <= sizeof(lcp_codenames) / sizeof(char *))
1681 printer(arg, " %s", lcp_codenames[code-1]);
1683 printer(arg, " code=0x%x", code);
1684 printer(arg, " id=0x%x", id);
1691 /* print option list */
1696 if (olen < 2 || olen > len) {
1704 if (olen == CILEN_SHORT) {
1706 GETSHORT(cishort, p);
1707 printer(arg, "mru %d", cishort);
1711 if (olen == CILEN_LONG) {
1714 printer(arg, "asyncmap 0x%x", cilong);
1718 if (olen >= CILEN_SHORT) {
1720 printer(arg, "auth ");
1721 GETSHORT(cishort, p);
1724 printer(arg, "pap");
1727 printer(arg, "chap");
1730 case CHAP_DIGEST_MD5:
1731 printer(arg, " MD5");
1735 case CHAP_MICROSOFT:
1736 printer(arg, " m$oft");
1744 printer(arg, "0x%x", cishort);
1749 if (olen >= CILEN_SHORT) {
1751 printer(arg, "quality ");
1752 GETSHORT(cishort, p);
1755 printer(arg, "lqr");
1758 printer(arg, "0x%x", cishort);
1763 if (olen >= CILEN_CHAR) {
1765 printer(arg, "callback ");
1766 GETSHORT(cishort, p);
1769 printer(arg, "CBCP");
1772 printer(arg, "0x%x", cishort);
1776 case CI_MAGICNUMBER:
1777 if (olen == CILEN_LONG) {
1780 printer(arg, "magic 0x%x", cilong);
1783 case CI_PCOMPRESSION:
1784 if (olen == CILEN_VOID) {
1786 printer(arg, "pcomp");
1789 case CI_ACCOMPRESSION:
1790 if (olen == CILEN_VOID) {
1792 printer(arg, "accomp");
1796 while (p < optend) {
1798 printer(arg, " %.2x", code);
1806 if (len > 0 && *p >= ' ' && *p < 0x7f) {
1808 print_string(p, len, printer, arg);
1819 printer(arg, " magic=0x%x", cilong);
1826 /* print the rest of the bytes in the packet */
1827 for (; len > 0; --len) {
1829 printer(arg, " %.2x", code);
1836 * Time to shut down the link because there is nothing out there.
1840 void LcpLinkFailure (f)
1843 if (f->state == OPENED) {
1844 syslog(LOG_INFO, "No response to %d echo-requests", lcp_echos_pending);
1845 syslog(LOG_NOTICE, "Serial link appears to be disconnected.");
1846 lcp_close(f->unit, "Peer not responding");
1851 * Timer expired for the LCP echo requests from this process.
1858 LcpSendEchoRequest (f);
1861 * Start the timer for the next interval.
1863 assert (lcp_echo_timer_running==0);
1864 TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
1865 lcp_echo_timer_running = 1;
1869 * LcpEchoTimeout - Timer expired on the LCP echo
1873 LcpEchoTimeout (arg)
1876 if (lcp_echo_timer_running != 0) {
1877 lcp_echo_timer_running = 0;
1878 LcpEchoCheck ((fsm *) arg);
1883 * LcpEchoReply - LCP has received a reply to the echo
1887 lcp_received_echo_reply (f, id, inp, len)
1889 int id; u_char *inp; int len;
1893 /* Check the magic number - don't count replies from ourselves. */
1895 syslog(LOG_DEBUG, "lcp: received short Echo-Reply, length %d", len);
1898 GETLONG(magic, inp);
1899 if (lcp_gotoptions[f->unit].neg_magicnumber
1900 && magic == lcp_gotoptions[f->unit].magicnumber) {
1901 syslog(LOG_WARNING, "appear to have received our own echo-reply!");
1905 /* Reset the number of outstanding echo frames */
1906 lcp_echos_pending = 0;
1910 * LcpSendEchoRequest - Send an echo request frame to the peer
1914 LcpSendEchoRequest (f)
1917 u_int32_t lcp_magic;
1918 u_char pkt[4], *pktp;
1921 * Detect the failure of the peer at this point.
1923 if (lcp_echo_fails != 0) {
1924 if (lcp_echos_pending >= lcp_echo_fails) {
1926 lcp_echos_pending = 0;
1931 * Make and send the echo request frame.
1933 if (f->state == OPENED) {
1934 lcp_magic = lcp_gotoptions[f->unit].magicnumber;
1936 PUTLONG(lcp_magic, pktp);
1937 fsm_sdata(f, ECHOREQ, lcp_echo_number++ & 0xFF, pkt, pktp - pkt);
1938 ++lcp_echos_pending;
1943 * lcp_echo_lowerup - Start the timer for the LCP frame
1947 lcp_echo_lowerup (unit)
1950 fsm *f = &lcp_fsm[unit];
1952 /* Clear the parameters for generating echo frames */
1953 lcp_echos_pending = 0;
1954 lcp_echo_number = 0;
1955 lcp_echo_timer_running = 0;
1957 /* If a timeout interval is specified then start the timer */
1958 if (lcp_echo_interval != 0)
1963 * lcp_echo_lowerdown - Stop the timer for the LCP frame
1967 lcp_echo_lowerdown (unit)
1970 fsm *f = &lcp_fsm[unit];
1972 if (lcp_echo_timer_running != 0) {
1973 UNTIMEOUT (LcpEchoTimeout, f);
1974 lcp_echo_timer_running = 0;