]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/lcp.c
Ignore NAK'd options we don't recognize.
[ppp.git] / pppd / lcp.c
index 672ecb911bacfd78e04301b2df23053290999dc5..f9d6c1cc9b9c2fd91bae5f623ae987085a4d5313 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: lcp.c,v 1.17 1995/04/24 05:58:06 paulus Exp $";
+static char rcsid[] = "$Id: lcp.c,v 1.21 1995/08/10 06:51:06 paulus Exp $";
 #endif
 
 /*
@@ -45,7 +45,7 @@ static char rcsid[] = "$Id: lcp.c,v 1.17 1995/04/24 05:58:06 paulus Exp $";
 
 #ifdef _linux_         /* Needs ppp ioctls */
 #include <net/if.h>
-#include <net/if_ppp.h>
+#include <linux/if_ppp.h>
 #endif
 
 /* global vars */
@@ -113,7 +113,7 @@ static fsm_callbacks lcp_callbacks = {      /* LCP callback routines */
     "LCP"                      /* String name of protocol */
 };
 
-int lcp_warnloops = DEFWARNLOOPS; /* Warn about a loopback this often */
+int lcp_loopbackfail = DEFLOOPBACKFAIL;
 
 /*
  * Length of each type of configuration option (in octets)
@@ -232,32 +232,25 @@ RestartIdleTimer (f)
     fsm *f;
 {
     u_long             delta;
-    struct ppp_ddinfo  ddinfo;
-    u_long             latest;
+    struct ppp_idle    ddinfo;
 /*
  * Read the time since the last packet was received.
  */
-    if (ioctl (fd, PPPIOCGTIME, &ddinfo) < 0) {
-        syslog (LOG_ERR, "ioctl(PPPIOCGTIME): %m");
+    if (ioctl (fd, PPPIOCGIDLE, &ddinfo) < 0) {
+        syslog (LOG_ERR, "ioctl(PPPIOCGIDLE): %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.
+ *  has expired then disconnect the line.
  */
-    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");
+    delta = idle_time_limit - (u_long) ddinfo.recv_idle;
+    if (((int) delta <= 0L) && (f->state == OPENED)) {
+        syslog (LOG_NOTICE, "No IP frames received 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)
+        if ((int) delta <= 0L)
            delta = (u_long) idle_time_limit;
         assert (idle_timer_running==0);
         TIMEOUT (IdleTimeCheck, (caddr_t) f, delta);
@@ -862,7 +855,6 @@ lcp_nakci(f, p, len)
      */
     NAKCILONG(CI_MAGICNUMBER, neg_magicnumber,
              try.magicnumber = magic();
-             ++try.numloops;
              looped_back = 1;
              );
 
@@ -886,11 +878,13 @@ lcp_nakci(f, p, len)
      * `let me authenticate myself with you' which is a bit pointless.
      * For the quality protocol, the Nak means `ask me to send you quality
      * reports', but if we didn't ask for them, we don't want them.
+     * An option we don't recognize represents the peer asking to
+     * negotiate some option we don't support, so ignore it.
      */
     while (len > CILEN_VOID) {
        GETCHAR(citype, p);
        GETCHAR(cilen, p);
-       if( (len -= cilen) < 0 )
+       if ((len -= cilen) < 0)
            goto bad;
        next = p + cilen - 2;
 
@@ -926,8 +920,6 @@ lcp_nakci(f, p, len)
            if (go->neg_lqr || no.neg_lqr || cilen != CILEN_LQR)
                goto bad;
            break;
-       default:
-           goto bad;
        }
        p = next;
     }
@@ -940,9 +932,14 @@ lcp_nakci(f, p, len)
      * OK, the Nak is good.  Now we can update state.
      */
     if (f->state != OPENED) {
+       if (looped_back) {
+           if (++try.numloops >= lcp_loopbackfail) {
+               syslog(LOG_NOTICE, "Serial line is looped back.");
+               lcp_close(f->unit);
+           }
+       } else
+           try.numloops = 0;
        *go = try;
-       if (looped_back && try.numloops % lcp_warnloops == 0)
-           syslog(LOG_WARNING, "Serial line appears to be looped back.");
     }
 
     return 1;
@@ -1368,9 +1365,10 @@ endswitch:
            continue;                   /* Don't send this one */
 
        if (orc == CONFNAK) {           /* Nak this CI? */
-           if (reject_if_disagree)     /* Getting fed up with sending NAKs? */
+           if (reject_if_disagree      /* Getting fed up with sending NAKs? */
+               && citype != CI_MAGICNUMBER) {
                orc = CONFREJ;          /* Get tough if so */
-           else {
+           else {
                if (rc == CONFREJ)      /* Rejecting prior CI? */
                    continue;           /* Don't send this one */
                rc = CONFNAK;
@@ -1666,43 +1664,36 @@ static void
 LcpEchoCheck (f)
     fsm *f;
 {
-    u_int32_t delta;
+    long int delta;
 #ifdef __linux__
-    struct ppp_ddinfo ddinfo;
-    u_int32_t latest;
+    struct ppp_idle    ddinfo;
 /*
  * Read the time since the last packet was received.
  */
-    if (ioctl (fd, PPPIOCGTIME, &ddinfo) < 0) {
-        syslog (LOG_ERR, "ioctl(PPPIOCGTIME): %m");
+    if (ioctl (fd, PPPIOCGIDLE, &ddinfo) < 0) {
+        syslog (LOG_ERR, "ioctl(PPPIOCGIDLE): %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) {
+    delta = (long int) lcp_echo_interval - (long int) ddinfo.recv_idle;
+    if (delta < 0L) {
         LcpSendEchoRequest (f);
-        delta = lcp_echo_interval * HZ;
+        delta = (int) lcp_echo_interval;
     }
-    delta /= HZ;
 
 #else /* Other implementations do not have ability to find delta */
     LcpSendEchoRequest (f);
-    delta = lcp_echo_interval;
+    delta = (int) lcp_echo_interval;
 #endif
 
 /*
  * Start the timer for the next interval.
  */
     assert (lcp_echo_timer_running==0);
-    TIMEOUT (LcpEchoTimeout, (caddr_t) f, delta);
+    TIMEOUT (LcpEchoTimeout, (caddr_t) f, (u_int32_t) delta);
     lcp_echo_timer_running = 1;
 }