]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
added peg counts
authorCarter Waxman <cwaxman@cisco.com>
Thu, 21 Apr 2016 17:05:46 +0000 (13:05 -0400)
committerCarter Waxman <cwaxman@cisco.com>
Thu, 21 Apr 2016 17:05:46 +0000 (13:05 -0400)
src/network_inspectors/packet_capture/capture_module.cc
src/network_inspectors/packet_capture/capture_module.h
src/network_inspectors/packet_capture/packet_capture.cc

index 66f0d5bc754034ced2825ecdca2bdfd2daaa3341..0c1eb3a03a0b237eb42f980c6bbc920365877cea 100644 (file)
 #include "profiler/profiler.h"
 #include "utils/util.h"
 
-THREAD_LOCAL SimpleStats cap_count_stats;
+const PegInfo cap_names[] =
+{
+    { "processed", "packets processed against filter" },
+    { "captured", "packets matching dumped after matching filter" },
+    { nullptr, nullptr }
+};
+
+THREAD_LOCAL CaptureStats cap_count_stats;
 THREAD_LOCAL ProfileStats cap_prof_stats;
 
 static const Parameter s_params[] =
@@ -49,7 +56,7 @@ void CaptureModule::get_config(CaptureConfig& cfg)
 }
 
 const PegInfo* CaptureModule::get_pegs() const
-{ return simple_pegs; }
+{ return cap_names; }
 
 PegCount* CaptureModule::get_counts() const
 { return (PegCount*)&cap_count_stats; }
index 845c2c5b218a96400e2e5ab7498658793b3d22c7..7f77b92e2ece5782d871ea7c60e307f61587e538 100644 (file)
@@ -49,7 +49,13 @@ private:
     CaptureConfig config;
 };
 
-extern THREAD_LOCAL SimpleStats cap_count_stats;
+struct CaptureStats
+{
+    PegCount checked;
+    PegCount matched;
+};
+
+extern THREAD_LOCAL CaptureStats cap_count_stats;
 extern THREAD_LOCAL ProfileStats cap_prof_stats;
 
 #endif
index 34368bed20c10c6c652cef09fecca679cee046d7..ae1ab393ecddbe118316510dd287fb25a2667f53 100644 (file)
@@ -106,9 +106,15 @@ void PacketCapture::eval(Packet* p)
     {
         if ( !capture_initialized() )
             capture_init();
+        
         if ( !bpf.bf_insns || sfbpf_filter(bpf.bf_insns, p->pkt,
                 p->pkth->caplen, p->pkth->pktlen) )
+        {
             write_packet(p);
+            cap_count_stats.matched++;
+        }
+
+        cap_count_stats.checked++;
     }
     else if ( capture_initialized() )
         capture_term();
@@ -439,6 +445,8 @@ TEST_CASE("bpf filter", "[PacketCapture]")
 
     CaptureModule mod;
     MockPacketCapture cap(&mod);
+
+    mod.sum_stats();
     
     packet_capture_enable("ip host 10.82.240.82");
     packet_capture_enable(""); //Test double-enable guard
@@ -458,6 +466,9 @@ TEST_CASE("bpf filter", "[PacketCapture]")
     cap.eval(&p);
     CHECK ( cap.write_packet_called );
 
+    CHECK ( cap_count_stats.checked == 3 );
+    CHECK ( cap_count_stats.matched == 2 );
+
     fseek(cap.fh, 0, SEEK_SET);
     auto pcap = pcap_fopen_offline(cap.fh, nullptr);