]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pcap: fix stats dump logic
authorVictor Julien <victor@inliniac.net>
Mon, 9 Dec 2013 11:12:01 +0000 (12:12 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 9 Dec 2013 15:02:08 +0000 (16:02 +0100)
pcap has a callback function that is called for each packet. Once a
second, it's meant to 'dump stats'. However, the timing logic was
broken, so it would actually dump stats for each packet.

By moving the stats second timer into the thread vars, next calls of
the callback will be able to use the stored time.

src/source-pcap.c

index 27a4c2dfab85a46af048d99782e0716fb6696fd1..09b7b3940856f98fe91c9008753a54795db7272b 100644 (file)
@@ -75,6 +75,8 @@ typedef struct PcapThreadVars_
     /* ptr to string from config */
     char *bpf_filter;
 
+    time_t last_stats_dump;
+
     /* data link type for the thread */
     int datalink;
 
@@ -229,7 +231,6 @@ void PcapCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) {
 
     PcapThreadVars *ptv = (PcapThreadVars *)user;
     Packet *p = PacketGetFromQueueOrAlloc();
-    time_t last_dump = 0;
     struct timeval current_time;
 
     if (unlikely(p == NULL)) {
@@ -277,9 +278,9 @@ void PcapCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt) {
 
     /* Trigger one dump of stats every second */
     TimeGet(&current_time);
-    if (current_time.tv_sec != last_dump) {
+    if (current_time.tv_sec != ptv->last_stats_dump) {
         PcapDumpCounters(ptv);
-        last_dump = current_time.tv_sec;
+        ptv->last_stats_dump = current_time.tv_sec;
     }
 
     SCReturn;