From: Eric Leblond Date: Thu, 27 Feb 2014 17:03:13 +0000 (+0100) Subject: util-device: add function to avoid stat display X-Git-Tag: suricata-2.0rc2~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6b2ca63d9d162082083889e01bf7fca619b61b50;p=thirdparty%2Fsuricata.git util-device: add function to avoid stat display In the case of running mode like NFQ there is no need possibility to compute the statistics as it is done in LiveDevice (drop and checksum count are meaningless). This patch adds a function that allow running mode to disable the display of the counters at exit. --- diff --git a/src/util-device.c b/src/util-device.c index 27d34ba8f2..6359973bfa 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -31,6 +31,8 @@ static TAILQ_HEAD(, LiveDevice_) live_devices = TAILQ_HEAD_INITIALIZER(live_devices); +/** if set to 0 when we don't have real devices */ +static int live_devices_stats = 1; /** * \brief Add a pcap device for monitoring @@ -159,18 +161,29 @@ int LiveBuildDeviceList(char * runmode) return i; } +/** Call this function to disable stat on live devices + * + * This can be useful in the case, this is not a real interface. + */ +void LiveDeviceHasNoStats() +{ + live_devices_stats = 0; +} + int LiveDeviceListClean() { SCEnter(); LiveDevice *pd, *tpd; TAILQ_FOREACH_SAFE(pd, &live_devices, next, tpd) { - SCLogNotice("Stats for '%s': pkts: %" PRIu64", drop: %" PRIu64 " (%.2f%%), invalid chksum: %" PRIu64, + if (live_devices_stats) { + SCLogNotice("Stats for '%s': pkts: %" PRIu64", drop: %" PRIu64 " (%.2f%%), invalid chksum: %" PRIu64, pd->dev, SC_ATOMIC_GET(pd->pkts), SC_ATOMIC_GET(pd->drop), 100 * (SC_ATOMIC_GET(pd->drop) * 1.0) / SC_ATOMIC_GET(pd->pkts), SC_ATOMIC_GET(pd->invalid_checksums)); + } if (pd->dev) SCFree(pd->dev); SC_ATOMIC_DESTROY(pd->pkts); diff --git a/src/util-device.h b/src/util-device.h index 455c2d2e26..6744d923e4 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -37,6 +37,7 @@ int LiveGetDeviceCount(void); char *LiveGetDeviceName(int number); LiveDevice *LiveGetDevice(char *dev); int LiveBuildDeviceList(char * base); +void LiveDeviceHasNoStats(void); int LiveDeviceListClean(void); #ifdef BUILD_UNIX_SOCKET