]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4041: packet_io: fix incorrect counters caused by data plane counters...
authorARUNKUMAR KAYAMBU -X (akayambu - XORIANT CORPORATION at Cisco) <akayambu@cisco.com>
Tue, 24 Oct 2023 14:46:30 +0000 (14:46 +0000)
committerOleksii Shumeiko -X (oshumeik - SOFTSERVE INC at Cisco) <oshumeik@cisco.com>
Tue, 24 Oct 2023 14:46:30 +0000 (14:46 +0000)
Merge in SNORT/snort3 from ~AKAYAMBU/snort3:daq_counter_fix to master

Squashed commit of the following:

commit 4ed5cf5bc6c597417789b18c15b03efa2843db69
Author: Arunkumar Kayambu <akayambu@cisco.com>
Date:   Fri Oct 6 08:21:47 2023 -0400

    packet_io: fix incorrect counters caused by data plane counters reset

src/packet_io/sfdaq_instance.cc
src/packet_io/sfdaq_module.cc

index 2cea141c6bf5b6349f33a5426b213e2fb464a11d..df424f5f48d13326589d9b15d888ab8e002a4101 100644 (file)
@@ -292,14 +292,6 @@ const DAQ_Stats_t* SFDAQInstance::get_stats()
         int rval = daq_instance_get_stats(instance, &daq_instance_stats);
         if (rval != DAQ_SUCCESS)
             LogMessage("Couldn't query DAQ stats: %s (%d)\n", daq_instance_get_error(instance), rval);
-
-        // Some DAQ modules don't provide hardware numbers, so we default HW RX to the SW equivalent
-        // (this means outstanding packets = 0)
-        if (daq_instance_stats.hw_packets_received == 0)
-        {
-            daq_instance_stats.hw_packets_received = daq_instance_stats.packets_received +
-                daq_instance_stats.packets_filtered;
-        }
     }
 
     return &daq_instance_stats;
index 39fb65939f534224e2ec74e5d350232b378793c6..33f12723245ec786956b47fe60f0eae58ab638c3 100644 (file)
@@ -250,22 +250,32 @@ void SFDAQModule::prep_counts(bool dump_stats)
     DAQ_Stats_t daq_stats_delta = new_daq_stats - prev_daq_stats;
 
     daq_stats.pcaps = Trough::get_file_count();
-    daq_stats.received = daq_stats_delta.hw_packets_received;
     daq_stats.analyzed = daq_stats_delta.packets_received;
-    daq_stats.dropped = daq_stats_delta.hw_packets_dropped;
     daq_stats.filtered = daq_stats_delta.packets_filtered;
-    daq_stats.injected =  daq_stats_delta.packets_injected;
+    daq_stats.injected = daq_stats_delta.packets_injected;
+
+    // Data plane stats is reset
+    if ( new_daq_stats.hw_packets_dropped < prev_daq_stats.hw_packets_dropped ||
+            new_daq_stats.hw_packets_received < prev_daq_stats.hw_packets_received )
+    {
+        daq_stats.dropped = new_daq_stats.hw_packets_dropped;
+        daq_stats.received = new_daq_stats.hw_packets_received;
+    }
+    else
+    {
+        daq_stats.dropped = daq_stats_delta.hw_packets_dropped;
+        daq_stats.received = daq_stats_delta.hw_packets_received;
+    }
 
     for ( unsigned i = 0; i < MAX_DAQ_VERDICT; i++ )
         daq_stats.verdicts[i] = daq_stats_delta.verdicts[i];
 
     daq_stats.outstanding = new_daq_stats.hw_packets_received -
         new_daq_stats.packets_filtered - new_daq_stats.packets_received;
-
     if ( daq_stats.outstanding > daq_stats.outstanding_max )
         daq_stats.outstanding_max = daq_stats.outstanding;
 
-    if(!dump_stats)
+    if ( !dump_stats )
         prev_daq_stats = new_daq_stats;
 }