]> Pileus Git - ~andy/fetchmail/blobdiff - interface.c
Fix a compilation screwup.
[~andy/fetchmail] / interface.c
index d93b096d5a6c84f3c6fb97267dc6953110755ed5..794bb9801464a481f9d18af7c28388fc8bc492eb 100644 (file)
@@ -43,6 +43,7 @@
 #include "config.h"
 #include "fetchmail.h"
 #include "i18n.h"
+#include "tunable.h"
 
 typedef struct {
        struct in_addr addr, dstaddr, netmask;
@@ -56,6 +57,14 @@ struct interface_pair_s {
 
 static char *netdevfmt;
 
+/*
+ * Count of packets to see on an interface before monitor considers it up.
+ * Needed because when pppd shuts down the link, the packet counts go up
+ * by two (one rx and one tx?, maybe).  A value of 2 seems to do the trick,
+ * but we'll give it some extra.
+ */
+#define MONITOR_SLOP           5
+
 #if defined(linux)
 
 void interface_init(void)
@@ -77,7 +86,7 @@ void interface_init(void)
 
        if (major >= 2 && minor >= 2)
            /* Linux 2.2 -- transmit packet count in 10th field */
-           netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %*d %d %*d %d";
+           netdevfmt = "%d %d %*d %*d %*d %d %*d %*d %*d %d %*d %*d %d";
     }
 }
 
@@ -460,17 +469,36 @@ int interface_approve(struct hostdata *hp)
                      hp->monitor, hp->monitor_io);
 #endif
        /* if monitoring, check link for activity if it is up */
-       if (get_ifinfo(hp->monitor, &ifinfo) &&
-                       hp->monitor_io == ifinfo.rx_packets +
-                               ifinfo.tx_packets) {
+       if (get_ifinfo(hp->monitor, &ifinfo))
+       {
+           int diff = (ifinfo.rx_packets + ifinfo.tx_packets)
+                                                       - hp->monitor_io;
+
+           /*
+            * There are three cases here:
+            *
+            * (a) If the new packet count is less than the recorded one,
+            * probably pppd was restarted while fetchmail was running.
+            * Don't skip.
+            *
+            * (b) newpacket count is greater than the old packet count,
+            * but the difference is small and may just reflect the overhead
+            * of a link shutdown.  Skip.
+            *
+            * (c) newpacket count is greater than the old packet count,
+            * and the difference is large. Connection is live.  Don't skip.
+            */
+           if (diff >= 0 && diff <= MONITOR_SLOP)
+           {
                (void) report(stdout, 
                              _("skipping poll of %s, %s inactive\n"),
                              hp->pollname, hp->monitor);
                return(FALSE);
+           }
        }
 
 #ifdef ACTIVITY_DEBUG
-       error(0, 0, _("activity on %s was %d, is %d"),
+       report(stdout, _("activity on %s was %d, is %d\n"),
              hp->monitor, hp->monitor_io,
              ifinfo.rx_packets + ifinfo.tx_packets);
 #endif