*/
#ifndef lint
-static char rcsid[] = "$Id: lcp.c,v 1.3 1994/04/18 04:00:25 paulus Exp $";
+static char rcsid[] = "$Id: lcp.c,v 1.16 1994/12/12 22:54:59 paulus Exp $";
#endif
/*
* TODO:
- * Option tracing.
- * Test restart.
*/
#include <stdio.h>
+#include <string.h>
#include <syslog.h>
+#include <assert.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
-
-#include <net/if.h>
-#include <net/if_ppp.h>
#include <netinet/in.h>
-#include <string.h>
-
#include "pppd.h"
-#include "ppp.h"
#include "fsm.h"
#include "lcp.h"
#include "magic.h"
#include "upap.h"
#include "ipcp.h"
+#ifdef _linux_ /* Needs ppp ioctls */
+#include <net/if.h>
+#include <net/if_ppp.h>
+#endif
+
/* global vars */
-fsm lcp_fsm[NPPP]; /* LCP fsm structure (global)*/
-lcp_options lcp_wantoptions[NPPP]; /* Options that we want to request */
-lcp_options lcp_gotoptions[NPPP]; /* Options that peer ack'd */
-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 */
+fsm lcp_fsm[NUM_PPP]; /* LCP fsm structure (global)*/
+lcp_options lcp_wantoptions[NUM_PPP]; /* Options that we want to request */
+lcp_options lcp_gotoptions[NUM_PPP]; /* Options that peer ack'd */
+lcp_options lcp_allowoptions[NUM_PPP]; /* Options we allow peer to request */
+lcp_options lcp_hisoptions[NUM_PPP]; /* Options that we ack'd */
+u_int32_t xmit_accm[NUM_PPP][8]; /* extended transmit ACCM */
+
+static u_int32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
+static u_int32_t lcp_echo_number = 0; /* ID number of next echo frame */
+static u_int32_t lcp_echo_timer_running = 0; /* TRUE if a timer is running */
+
+#ifdef _linux_
+u_int32_t idle_timer_running = 0;
+extern int idle_time_limit;
+#endif
/*
* Callbacks for fsm code. (CI = Configuration Information)
*/
-static void lcp_resetci __ARGS((fsm *)); /* Reset our CI */
-static int lcp_cilen __ARGS((fsm *)); /* Return length of our CI */
-static void lcp_addci __ARGS((fsm *, u_char *, int *)); /* Add our CI to pkt */
-static int lcp_ackci __ARGS((fsm *, u_char *, int)); /* Peer ack'd our CI */
-static int lcp_nakci __ARGS((fsm *, u_char *, int)); /* Peer nak'd our CI */
-static int lcp_rejci __ARGS((fsm *, u_char *, int)); /* Peer rej'd our CI */
-static int lcp_reqci __ARGS((fsm *, u_char *, int *, int)); /* Rcv peer CI */
-static void lcp_up __ARGS((fsm *)); /* We're UP */
-static void lcp_down __ARGS((fsm *)); /* We're DOWN */
-static void lcp_starting __ARGS((fsm *)); /* We need lower layer up */
-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));
+static void lcp_resetci __P((fsm *)); /* Reset our CI */
+static int lcp_cilen __P((fsm *)); /* Return length of our CI */
+static void lcp_addci __P((fsm *, u_char *, int *)); /* Add our CI to pkt */
+static int lcp_ackci __P((fsm *, u_char *, int)); /* Peer ack'd our CI */
+static int lcp_nakci __P((fsm *, u_char *, int)); /* Peer nak'd our CI */
+static int lcp_rejci __P((fsm *, u_char *, int)); /* Peer rej'd our CI */
+static int lcp_reqci __P((fsm *, u_char *, int *, int)); /* Rcv peer CI */
+static void lcp_up __P((fsm *)); /* We're UP */
+static void lcp_down __P((fsm *)); /* We're DOWN */
+static void lcp_starting __P((fsm *)); /* We need lower layer up */
+static void lcp_finished __P((fsm *)); /* We need lower layer down */
+static int lcp_extcode __P((fsm *, int, int, u_char *, int));
+static void lcp_rprotrej __P((fsm *, u_char *, int));
+
+/*
+ * routines to send LCP echos to peer
+ */
+
+static void lcp_echo_lowerup __P((int));
+static void lcp_echo_lowerdown __P((int));
+static void LcpEchoTimeout __P((caddr_t));
+static void lcp_received_echo_reply __P((fsm *, int, u_char *, int));
+static void LcpSendEchoRequest __P((fsm *));
+static void LcpLinkFailure __P((fsm *));
static fsm_callbacks lcp_callbacks = { /* LCP callback routines */
lcp_resetci, /* Reset our Configuration Information */
lcp_options *ao = &lcp_allowoptions[unit];
f->unit = unit;
- f->protocol = LCP;
+ f->protocol = PPP_LCP;
f->callbacks = &lcp_callbacks;
fsm_init(f);
lcp_close(unit)
int unit;
{
- fsm_close(&lcp_fsm[unit]);
+ fsm *f = &lcp_fsm[unit];
+
+ if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
+ /*
+ * This action is not strictly according to the FSM in RFC1548,
+ * but it does mean that the program terminates if you do a
+ * lcp_close(0) in passive/silent mode when a connection hasn't
+ * been established.
+ */
+ f->state = CLOSED;
+ lcp_finished(f);
+
+ } else
+ fsm_close(&lcp_fsm[unit]);
+}
+
+#ifdef _linux_
+static void IdleTimeCheck __P((caddr_t));
+
+/*
+ * Timer expired for the LCP echo requests from this process.
+ */
+
+static void
+RestartIdleTimer (f)
+ fsm *f;
+{
+ u_long delta;
+ 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 IP activity. It may be a read or write frame
+ */
+ latest = ddinfo.ip_sjiffies < ddinfo.ip_rjiffies ? ddinfo.ip_sjiffies
+ : 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 = (idle_time_limit * HZ) - latest;
+ if (((int) delta < HZ || (int) latest < 0L) && f->state == OPENED) {
+ syslog (LOG_NOTICE, "No IP frames exchanged within idle time limit");
+ lcp_close(f->unit); /* Reset connection */
+ phase = PHASE_TERMINATE; /* Mark it down */
+ } else {
+ delta = (delta + HZ - 1) / HZ;
+ if (delta == 0)
+ delta = (u_long) idle_time_limit;
+ assert (idle_timer_running==0);
+ TIMEOUT (IdleTimeCheck, (caddr_t) f, delta);
+ idle_timer_running = 1;
+ }
}
+/*
+ * IdleTimeCheck - Timer expired on the IDLE detection for IP frames
+ */
+
+static void
+IdleTimeCheck (arg)
+ caddr_t arg;
+{
+ if (idle_timer_running != 0) {
+ idle_timer_running = 0;
+ RestartIdleTimer ((fsm *) arg);
+ }
+}
+#endif
/*
* lcp_lowerup - The lower layer is up.
{
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);
- peer_mru[unit] = MTU;
+ ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
+ ppp_recv_config(unit, PPP_MRU, 0x00000000, 0, 0);
+ peer_mru[unit] = PPP_MRU;
lcp_allowoptions[unit].asyncmap = xmit_accm[unit][0];
fsm_lowerup(&lcp_fsm[unit]);
u_char *p;
int len;
{
- fsm_input(&lcp_fsm[unit], p, len);
+ int oldstate;
+ fsm *f = &lcp_fsm[unit];
+ lcp_options *go = &lcp_gotoptions[f->unit];
+
+ oldstate = f->state;
+ fsm_input(f, p, len);
+ if (oldstate == REQSENT && f->state == ACKSENT) {
+ /*
+ * The peer will probably send us an ack soon and then
+ * immediately start sending packets with the negotiated
+ * options. So as to be ready when that happens, we set
+ * our receive side to accept packets as negotiated now.
+ */
+ ppp_recv_config(f->unit, PPP_MRU,
+ go->neg_asyncmap? go->asyncmap: 0x00000000,
+ go->neg_pcompression, go->neg_accompression);
+ }
}
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);
fsm_sdata(f, ECHOREP, id, inp, len);
break;
case ECHOREP:
+ lcp_received_echo_reply(f, id, inp, len);
+ break;
+
case DISCREQ:
break;
lcp_wantoptions[f->unit].magicnumber = magic();
lcp_wantoptions[f->unit].numloops = 0;
lcp_gotoptions[f->unit] = lcp_wantoptions[f->unit];
- peer_mru[f->unit] = MTU;
+ peer_mru[f->unit] = PPP_MRU;
}
if (neg) { \
PUTCHAR(opt, ucp); \
PUTCHAR(CILEN_LQR, ucp); \
- PUTSHORT(LQR, ucp); \
+ PUTSHORT(PPP_LQR, ucp); \
PUTLONG(val, ucp); \
}
ADDCISHORT(CI_MRU, go->neg_mru, go->mru);
ADDCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
- ADDCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
- ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
+ ADDCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
+ ADDCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
ADDCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
ADDCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
ADDCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
lcp_options *go = &lcp_gotoptions[f->unit];
u_char cilen, citype, cichar;
u_short cishort;
- u_long cilong;
+ u_int32_t cilong;
/*
* CIs must be in exactly the same order that we sent.
citype != opt) \
goto bad; \
GETSHORT(cishort, p); \
- if (cishort != LQR) \
+ if (cishort != PPP_LQR) \
goto bad; \
GETLONG(cilong, p); \
if (cilong != val) \
ACKCISHORT(CI_MRU, go->neg_mru, go->mru);
ACKCILONG(CI_ASYNCMAP, go->neg_asyncmap, go->asyncmap);
- ACKCICHAP(CI_AUTHTYPE, go->neg_chap, CHAP, go->chap_mdtype);
- ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, UPAP);
+ ACKCICHAP(CI_AUTHTYPE, go->neg_chap, PPP_CHAP, go->chap_mdtype);
+ ACKCISHORT(CI_AUTHTYPE, !go->neg_chap && go->neg_upap, PPP_PAP);
ACKCILQR(CI_QUALITY, go->neg_lqr, go->lqr_period);
ACKCILONG(CI_MAGICNUMBER, go->neg_magicnumber, go->magicnumber);
ACKCIVOID(CI_PCOMPRESSION, go->neg_pcompression);
lcp_options *wo = &lcp_wantoptions[f->unit];
u_char cilen, citype, cichar, *next;
u_short cishort;
- u_long cilong;
+ u_int32_t cilong;
lcp_options no; /* options we've seen Naks for */
lcp_options try; /* options to request next time */
int looped_back = 0;
* 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 != PPP_LQR)
+ try.neg_lqr = 0;
+ else
+ try.lqr_period = cilong;
+ );
/*
* Check for a looped-back line.
*/
if (f->state != OPENED) {
*go = try;
if (looped_back && try.numloops % lcp_warnloops == 0)
- LCPDEBUG((LOG_INFO, "The line appears to be looped back."));
+ syslog(LOG_WARNING, "Serial line appears to be looped back.");
}
return 1;
lcp_options *go = &lcp_gotoptions[f->unit];
u_char cichar;
u_short cishort;
- u_long cilong;
+ u_int32_t cilong;
u_char *start = p;
int plen = len;
lcp_options try; /* options to request next time */
GETSHORT(cishort, p); \
GETLONG(cilong, p); \
/* Check rejected value. */ \
- if (cishort != LQR || cichar != val) \
+ if (cishort != PPP_LQR || cilong != val) \
goto bad; \
try.neg = 0; \
LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
REJCISHORT(CI_MRU, neg_mru, go->mru);
REJCILONG(CI_ASYNCMAP, neg_asyncmap, go->asyncmap);
- REJCICHAP(CI_AUTHTYPE, neg_chap, CHAP, go->chap_mdtype);
+ REJCICHAP(CI_AUTHTYPE, neg_chap, PPP_CHAP, go->chap_mdtype);
if (!go->neg_chap) {
- REJCISHORT(CI_AUTHTYPE, neg_upap, UPAP);
+ REJCISHORT(CI_AUTHTYPE, neg_upap, PPP_PAP);
}
REJCILQR(CI_QUALITY, neg_lqr, go->lqr_period);
REJCILONG(CI_MAGICNUMBER, neg_magicnumber, go->magicnumber);
u_char *cip, *next; /* Pointer to current and next CIs */
u_char cilen, citype, cichar;/* Parsed len, type, char value */
u_short cishort; /* Parsed short value */
- u_long cilong; /* Parse long value */
+ u_int32_t cilong; /* Parse long value */
int rc = CONFACK; /* Final packet return code */
int orc; /* Individual option return code */
u_char *p; /* Pointer to next char to parse */
break;
}
GETLONG(cilong, p);
- LCPDEBUG((LOG_INFO, "(%lx)", cilong));
+ LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
/*
* Asyncmap must have set at least the bits
if ((ao->asyncmap & ~cilong) != 0) {
orc = CONFNAK;
if( !reject_if_disagree ){
- DECPTR(sizeof (long), p);
+ DECPTR(sizeof(u_int32_t), p);
PUTLONG(ao->asyncmap | cilong, p);
}
break;
* the ordering of the CIs in the peer's Configure-Request.
*/
- if (cishort == UPAP) {
+ if (cishort == PPP_PAP) {
if (!ao->neg_upap || /* we don't want to do PAP */
ho->neg_chap || /* or we've already accepted CHAP */
cilen != CILEN_SHORT) {
ho->neg_upap = 1;
break;
}
- if (cishort == CHAP) {
+ if (cishort == PPP_CHAP) {
if (!ao->neg_chap || /* we don't want to do CHAP */
ho->neg_upap || /* or we've already accepted UPAP */
cilen != CILEN_CHAP) {
GETSHORT(cishort, p);
GETLONG(cilong, p);
- LCPDEBUG((LOG_INFO, "(%x %lx)", cishort, cilong));
- if (cishort != LQR) {
+ LCPDEBUG((LOG_INFO, "(%x %x)", cishort, (unsigned int) cilong));
+ if (cishort != PPP_LQR) {
orc = CONFREJ;
break;
}
break;
}
GETLONG(cilong, p);
- LCPDEBUG((LOG_INFO, "(%lx)", cilong));
+ LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
/*
* He must have a different magic number.
if (go->neg_magicnumber &&
cilong == go->magicnumber) {
orc = CONFNAK;
- DECPTR(sizeof (long), p);
+ DECPTR(sizeof(u_int32_t), p);
cilong = magic(); /* Don't put magic() inside macro! */
PUTLONG(cilong, p);
break;
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,
* set our MRU to the larger of value we wanted and
* the value we got in the negotiation.
*/
- ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: MTU)),
+ ppp_send_config(f->unit, MIN(ao->mru, (ho->neg_mru? ho->mru: PPP_MRU)),
(ho->neg_asyncmap? ho->asyncmap: 0xffffffff),
ho->neg_pcompression, ho->neg_accompression);
- ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): MTU),
- (go->neg_asyncmap? go->asyncmap: 0xffffffff),
+ /*
+ * If the asyncmap hasn't been negotiated, we really should
+ * set the receive asyncmap to ffffffff, but we set it to 0
+ * for backwards contemptibility.
+ */
+ ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
+ (go->neg_asyncmap? go->asyncmap: 0x00000000),
go->neg_pcompression, go->neg_accompression);
if (ho->neg_mru)
ChapLowerUp(f->unit); /* Enable CHAP */
upap_lowerup(f->unit); /* Enable UPAP */
ipcp_lowerup(f->unit); /* Enable IPCP */
+ ccp_lowerup(f->unit); /* Enable CCP */
+ lcp_echo_lowerup(f->unit); /* Enable echo messages */
link_established(f->unit);
}
lcp_down(f)
fsm *f;
{
+ lcp_echo_lowerdown(f->unit);
+ ccp_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);
- peer_mru[f->unit] = MTU;
+ ppp_send_config(f->unit, PPP_MRU, 0xffffffff, 0, 0);
+ ppp_recv_config(f->unit, PPP_MRU, 0x00000000, 0, 0);
+ peer_mru[f->unit] = PPP_MRU;
link_down(f->unit);
}
lcp_printpkt(p, plen, printer, arg)
u_char *p;
int plen;
- void (*printer) __ARGS((void *, char *, ...));
+ void (*printer) __P((void *, char *, ...));
void *arg;
{
int code, id, len, olen;
u_char *pstart, *optend;
u_short cishort;
- u_long cilong;
+ u_int32_t cilong;
if (plen < HEADERLEN)
return 0;
printer(arg, "auth ");
GETSHORT(cishort, p);
switch (cishort) {
- case UPAP:
+ case PPP_PAP:
printer(arg, "upap");
break;
- case CHAP:
+ case PPP_CHAP:
printer(arg, "chap");
break;
default:
printer(arg, "quality ");
GETSHORT(cishort, p);
switch (cishort) {
- case LQR:
+ case PPP_LQR:
printer(arg, "lqr");
break;
default:
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_close(f->unit); /* Reset connection */
+ }
+}
+
+/*
+ * Timer expired for the LCP echo requests from this process.
+ */
+
+static void
+LcpEchoCheck (f)
+ fsm *f;
+{
+ u_int32_t delta;
+#ifdef __linux__
+ struct ppp_ddinfo ddinfo;
+ u_int32_t 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_int32_t magic;
+
+ /* Check the magic number - don't count replies from ourselves. */
+ if (len < 4) {
+ syslog(LOG_DEBUG, "lcp: received short Echo-Reply, length %d", len);
+ return;
+ }
+ GETLONG(magic, inp);
+ if (lcp_gotoptions[f->unit].neg_magicnumber
+ && magic == lcp_gotoptions[f->unit].magicnumber) {
+ syslog(LOG_WARNING, "appear to have received our own echo-reply!");
+ 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_int32_t 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);
+#ifdef _linux_
+ /* If a idle time limit is given then start it */
+ if (idle_time_limit != 0)
+ RestartIdleTimer (f);
+#endif
+}
+
+/*
+ * 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;
+ }
+#ifdef _linux_
+ /* If a idle time limit is running then stop it */
+ if (idle_timer_running != 0) {
+ UNTIMEOUT (IdleTimeCheck, (caddr_t) f);
+ idle_timer_running = 0;
+ }
+#endif
+}