X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Flcp.c;h=cd0f6f85eb52c61b0c20c15d6af3b052b8ecd44e;hp=e1eb6f2a4bfbe1896fbc3edaaf999ec551e46041;hb=4b3147e69bffe5b8b7aa2af95e2abfcec36b4880;hpb=e5e66630876a7fa7b8bcca319dac26466e39ed51 diff --git a/pppd/lcp.c b/pppd/lcp.c index e1eb6f2..cd0f6f8 100644 --- a/pppd/lcp.c +++ b/pppd/lcp.c @@ -18,17 +18,16 @@ */ #ifndef lint -static char rcsid[] = "$Id: lcp.c,v 1.4 1994/05/09 04:32:41 paulus Exp $"; +static char rcsid[] = "$Id: lcp.c,v 1.5 1994/05/24 11:23:13 paulus Exp $"; #endif /* * TODO: - * Option tracing. - * Test restart. */ #include #include +#include #include #include #include @@ -57,6 +56,13 @@ lcp_options lcp_allowoptions[NPPP]; /* Options we allow peer to request */ lcp_options lcp_hisoptions[NPPP]; /* Options that we ack'd */ u_long xmit_accm[NPPP][8]; /* extended transmit ACCM */ +static u_long lcp_echos_pending = 0; /* Number of outstanding echo msgs */ +static u_long lcp_echo_number = 0; /* ID number of next echo frame */ +static u_long lcp_echo_timer_running = 0; /* TRUE if a timer is running */ + +u_long lcp_echo_interval = 0; +u_long lcp_echo_fails = 0; + /* * Callbacks for fsm code. (CI = Configuration Information) */ @@ -74,6 +80,17 @@ static void lcp_finished __ARGS((fsm *)); /* We need lower layer down */ static int lcp_extcode __ARGS((fsm *, int, int, u_char *, int)); static void lcp_rprotrej __ARGS((fsm *, u_char *, int)); +/* + * routines to send LCP echos to peer + */ + +static void lcp_echo_lowerup __ARGS((int)); +static void lcp_echo_lowerdown __ARGS((int)); +static void LcpEchoTimeout __ARGS((caddr_t)); +static void lcp_received_echo_reply __ARGS((fsm *, int, u_char *, int)); +static void LcpSendEchoRequest __ARGS((fsm *)); +static void LcpLinkFailure __ARGS((fsm *)); + static fsm_callbacks lcp_callbacks = { /* LCP callback routines */ lcp_resetci, /* Reset our Configuration Information */ lcp_cilen, /* Length of our Configuration Information */ @@ -210,7 +227,7 @@ lcp_lowerup(unit) sifdown(unit); ppp_set_xaccm(unit, xmit_accm[unit]); ppp_send_config(unit, MTU, 0xffffffff, 0, 0); - ppp_recv_config(unit, MTU, 0, 0, 0); + ppp_recv_config(unit, MTU, 0x00000000, 0, 0); peer_mru[unit] = MTU; lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0]; @@ -252,19 +269,28 @@ lcp_extcode(f, code, id, inp, len) u_char *inp; int len; { + u_char *magp; + switch( code ){ case PROTREJ: lcp_rprotrej(f, inp, len); break; case ECHOREQ: - if( f->state != OPENED ) + if (f->state != OPENED) break; LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id)); + magp = inp; + PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp); + if (len < CILEN_LONG) + len = CILEN_LONG; fsm_sdata(f, ECHOREP, id, inp, len); break; case ECHOREP: + lcp_received_echo_reply(f, id, inp, len); + break; + case DISCREQ: break; @@ -699,12 +725,12 @@ lcp_nakci(f, p, len) * to stop asking for LQR. We haven't got any other protocol. * If they Nak the reporting period, take their value XXX ? */ - NAKCILONG(CI_QUALITY, neg_lqr, - if (cishort != LQR) - try.neg_lqr = 0; - else - try.lqr_period = cilong; - ); + NAKCILQR(CI_QUALITY, neg_lqr, + if (cishort != LQR) + try.neg_lqr = 0; + else + try.lqr_period = cilong; + ); /* * Check for a looped-back line. */ @@ -894,7 +920,7 @@ lcp_rejci(f, p, len) GETSHORT(cishort, p); \ GETLONG(cilong, p); \ /* Check rejected value. */ \ - if (cishort != LQR || cichar != val) \ + if (cishort != LQR || cilong != val) \ goto bad; \ try.neg = 0; \ LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \ @@ -1231,6 +1257,11 @@ lcp_up(f) lcp_options *go = &lcp_gotoptions[f->unit]; lcp_options *ao = &lcp_allowoptions[f->unit]; + if (!go->neg_magicnumber) + go->magicnumber = 0; + if (!ho->neg_magicnumber) + ho->magicnumber = 0; + /* * Set our MTU to the smaller of the MTU we wanted and * the MRU our peer wanted. If we negotiated an MRU, @@ -1250,6 +1281,7 @@ lcp_up(f) ChapLowerUp(f->unit); /* Enable CHAP */ upap_lowerup(f->unit); /* Enable UPAP */ ipcp_lowerup(f->unit); /* Enable IPCP */ + lcp_echo_lowerup(f->unit); /* Enable echo messages */ link_established(f->unit); } @@ -1264,13 +1296,14 @@ static void lcp_down(f) fsm *f; { + lcp_echo_lowerdown(f->unit); ipcp_lowerdown(f->unit); ChapLowerDown(f->unit); upap_lowerdown(f->unit); sifdown(f->unit); ppp_send_config(f->unit, MTU, 0xffffffff, 0, 0); - ppp_recv_config(f->unit, MTU, 0, 0, 0); + ppp_recv_config(f->unit, MTU, 0x00000000, 0, 0); peer_mru[f->unit] = MTU; link_down(f->unit); @@ -1434,3 +1467,173 @@ lcp_printpkt(p, plen, printer, arg) return p - pstart; } + +/* + * Time to shut down the link because there is nothing out there. + */ + +static +void LcpLinkFailure (f) + fsm *f; +{ + if (f->state == OPENED) { + syslog (LOG_NOTICE, "Excessive lack of response to LCP echo frames."); + lcp_lowerdown(f->unit); /* Reset connection */ + } +} + +/* + * Timer expired for the LCP echo requests from this process. + */ + +static void +LcpEchoCheck (f) + fsm *f; +{ + u_long delta; +#ifdef __linux__ + struct ppp_ddinfo ddinfo; + u_long latest; +/* + * Read the time since the last packet was received. + */ + if (ioctl (fd, PPPIOCGTIME, &ddinfo) < 0) { + syslog (LOG_ERR, "ioctl(PPPIOCGTIME): %m"); + die (1); + } +/* + * Choose the most recient frame received. It may be an IP or NON-IP frame. + */ + latest = ddinfo.nip_rjiffies < ddinfo.ip_rjiffies ? ddinfo.nip_rjiffies + : ddinfo.ip_rjiffies; +/* + * Compute the time since the last packet was received. If the timer + * has expired then send the echo request and reset the timer to maximum. + */ + delta = (lcp_echo_interval * HZ) - latest; + if (delta < HZ || latest < 0L) { + LcpSendEchoRequest (f); + delta = lcp_echo_interval * HZ; + } + delta /= HZ; + +#else /* Other implementations do not have ability to find delta */ + LcpSendEchoRequest (f); + delta = lcp_echo_interval; +#endif + +/* + * Start the timer for the next interval. + */ + assert (lcp_echo_timer_running==0); + TIMEOUT (LcpEchoTimeout, (caddr_t) f, delta); + lcp_echo_timer_running = 1; +} + +/* + * LcpEchoTimeout - Timer expired on the LCP echo + */ + +static void +LcpEchoTimeout (arg) + caddr_t arg; +{ + if (lcp_echo_timer_running != 0) { + lcp_echo_timer_running = 0; + LcpEchoCheck ((fsm *) arg); + } +} + +/* + * LcpEchoReply - LCP has received a reply to the echo + */ + +static void +lcp_received_echo_reply (f, id, inp, len) + fsm *f; + int id; u_char *inp; int len; +{ + u_long magic; + + /* Check the magic number - don't count replies from ourselves. */ + if (len < CILEN_LONG) + return; + GETLONG(magic, inp); + if (lcp_gotoptions[f->unit].neg_magicnumber + && magic == lcp_gotoptions[f->unit].magicnumber) + return; + + /* Reset the number of outstanding echo frames */ + lcp_echos_pending = 0; +} + +/* + * LcpSendEchoRequest - Send an echo request frame to the peer + */ + +static void +LcpSendEchoRequest (f) + fsm *f; +{ + u_long lcp_magic; + u_char pkt[4], *pktp; + +/* + * Detect the failure of the peer at this point. + */ + if (lcp_echo_fails != 0) { + if (lcp_echos_pending++ >= lcp_echo_fails) { + LcpLinkFailure(f); + lcp_echos_pending = 0; + } + } +/* + * Make and send the echo request frame. + */ + if (f->state == OPENED) { + lcp_magic = lcp_gotoptions[f->unit].neg_magicnumber + ? lcp_gotoptions[f->unit].magicnumber + : 0L; + pktp = pkt; + PUTLONG(lcp_magic, pktp); + + fsm_sdata(f, ECHOREQ, + lcp_echo_number++ & 0xFF, pkt, pktp - pkt); + } +} + +/* + * lcp_echo_lowerup - Start the timer for the LCP frame + */ + +static void +lcp_echo_lowerup (unit) + int unit; +{ + fsm *f = &lcp_fsm[unit]; + + /* Clear the parameters for generating echo frames */ + lcp_echos_pending = 0; + lcp_echo_number = 0; + lcp_echo_timer_running = 0; + + /* If a timeout interval is specified then start the timer */ + if (lcp_echo_interval != 0) + LcpEchoCheck (f); +} + +/* + * lcp_echo_lowerdown - Stop the timer for the LCP frame + */ + +static void +lcp_echo_lowerdown (unit) + int unit; +{ + fsm *f = &lcp_fsm[unit]; + + if (lcp_echo_timer_running != 0) { + UNTIMEOUT (LcpEchoTimeout, (caddr_t) f); + lcp_echo_timer_running = 0; + } +}