]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/lcp.c
pppd: Do not call update_link_stats() for every LcpSendEchoRequest() call
[ppp.git] / pppd / lcp.c
index 8ed2778bfb672084181a0b27834dfcfdbb875abb..d7ea47106376cc3e3a43a6c7d55ed40a137994c2 100644 (file)
@@ -56,7 +56,6 @@
 #include "chap-new.h"
 #include "magic.h"
 
-static const char rcsid[] = RCSID;
 
 /*
  * When the link comes up we want to be able to wait for a short while,
@@ -73,6 +72,7 @@ static void lcp_delayed_up __P((void *));
  */
 int    lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
 int    lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
+bool   lcp_echo_adaptive = 0;  /* request echo only if the link was idle */
 bool   lax_recv = 0;           /* accept control chars in asyncmap */
 bool   noendpoint = 0;         /* don't send/accept endpoint discriminator */
 
@@ -151,6 +151,8 @@ static option_t lcp_option_list[] = {
       OPT_PRIO },
     { "lcp-echo-interval", o_int, &lcp_echo_interval,
       "Set time in seconds between LCP echo requests", OPT_PRIO },
+    { "lcp-echo-adaptive", o_bool, &lcp_echo_adaptive,
+      "Suppress LCP echo requests if traffic was received", 1 },
     { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
       "Set time in seconds between LCP retransmissions", OPT_PRIO },
     { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
@@ -2331,6 +2333,20 @@ LcpSendEchoRequest (f)
        }
     }
 
+    /*
+     * If adaptive echos have been enabled, only send the echo request if
+     * no traffic was received since the last one.
+     */
+    if (lcp_echo_adaptive) {
+       static unsigned int last_pkts_in = 0;
+       struct pppd_stats cur_stats;
+
+       if (get_ppp_stats(f->unit, &cur_stats) && cur_stats.pkts_in != last_pkts_in) {
+           last_pkts_in = cur_stats.pkts_in;
+           return;
+       }
+    }
+
     /*
      * Make and send the echo request frame.
      */