From: Victor Julien Date: Mon, 9 Dec 2013 11:12:01 +0000 (+0100) Subject: pcap: fix stats dump logic X-Git-Tag: suricata-2.0beta2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0beb7ed7819a706712cf8401e650001309305de2;p=thirdparty%2Fsuricata.git pcap: fix stats dump logic 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. --- diff --git a/src/source-pcap.c b/src/source-pcap.c index 27a4c2dfab..09b7b39408 100644 --- a/src/source-pcap.c +++ b/src/source-pcap.c @@ -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(¤t_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;