#include "config.h"
#include "fetchmail.h"
#include "i18n.h"
+#include "tunable.h"
typedef struct {
struct in_addr addr, dstaddr, netmask;
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)
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";
}
}
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