From: Eric Leblond Date: Tue, 31 Dec 2013 14:04:33 +0000 (+0100) Subject: device list: clean and display stat at exit X-Git-Tag: suricata-2.0rc1~238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a8c787a2658a27bd8e920dd234870b2dbde82b75;p=thirdparty%2Fsuricata.git device list: clean and display stat at exit This patch adds a cleaning function to device list. This also permits to display per-interface statistics during the exit. --- diff --git a/src/suricata.c b/src/suricata.c index b031160459..b788c90d3d 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -2295,6 +2295,7 @@ int main(int argc, char **argv) TagDestroyCtx(); + LiveDeviceListClean(); RunModeShutDown(); OutputDeregisterAll(); TimeDeinit(); diff --git a/src/util-device.c b/src/util-device.c index 55e7286df4..35d3aef4dc 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -159,6 +159,29 @@ int LiveBuildDeviceList(char * runmode) return i; } +int LiveDeviceListClean() +{ + SCEnter(); + LiveDevice *pd; + + TAILQ_FOREACH(pd, &live_devices, next) { + SCLogNotice("Stats for '%s': pkts: %u, drop: %u (%.2f%%), invalid chksum: %u", + 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); + SC_ATOMIC_DESTROY(pd->drop); + SC_ATOMIC_DESTROY(pd->invalid_checksums); + SCFree(pd); + } + + SCReturnInt(TM_ECODE_OK); +} + #ifdef BUILD_UNIX_SOCKET TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *answer, void *data) { diff --git a/src/util-device.h b/src/util-device.h index 55aff3ca08..cfd85b64fb 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); +int LiveDeviceListClean(void); #ifdef BUILD_UNIX_SOCKET TmEcode LiveDeviceIfaceStat(json_t *cmd, json_t *server_msg, void *data);