]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
device list: clean and display stat at exit
authorEric Leblond <eric@regit.org>
Tue, 31 Dec 2013 14:04:33 +0000 (15:04 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Jan 2014 13:47:43 +0000 (14:47 +0100)
This patch adds a cleaning function to device list. This also
permits to display per-interface statistics during the exit.

src/suricata.c
src/util-device.c
src/util-device.h

index b031160459730b4753b9d48498445bae1621612f..b788c90d3d1c8ca75849b582f1851d3d56b3a25b 100644 (file)
@@ -2295,6 +2295,7 @@ int main(int argc, char **argv)
 
     TagDestroyCtx();
 
+    LiveDeviceListClean();
     RunModeShutDown();
     OutputDeregisterAll();
     TimeDeinit();
index 55e7286df4bfe3caa958ac515e2abd1ce6c3754e..35d3aef4dc0d88faaca809c2dcf785c7492cba3b 100644 (file)
@@ -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)
 {
index 55aff3ca08faa4f5f49b027e780d82ea8ce065ec..cfd85b64fb70c4f93746e798c91d056ecb8b08ff 100644 (file)
@@ -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);