]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2766 in SNORT/snort3 from ~SUNIMUKH/snort3:clear_global_counter...
authorShanmugam S (shanms) <shanms@cisco.com>
Tue, 9 Mar 2021 16:22:13 +0000 (16:22 +0000)
committerShanmugam S (shanms) <shanms@cisco.com>
Tue, 9 Mar 2021 16:22:13 +0000 (16:22 +0000)
Squashed commit of the following:

commit df425d8fc335ca5891200064f2c03b9b6f7d6892
Author: Sunirmal Mukherjee <sunimukh@cisco.com>
Date:   Tue Feb 23 17:28:05 2021 -0500

    module: Introduced new api to clear global active module counters

src/framework/module.cc
src/framework/module.h
src/main/analyzer_command.cc
src/managers/module_manager.cc
src/managers/module_manager.h

index 2b3daced4e2045971648f315f45e3ff7483e5639..502c37c3323e59b9a3a65ae2daaf36efd63e8d10 100644 (file)
@@ -67,6 +67,24 @@ Module::Module(const char* s, const char* h, const Parameter* p, bool is_list)
     params = p;
 }
 
+void Module::clear_global_active_counters()
+{
+    PegCount* p = get_counts();
+
+    if ( !p )
+        return;
+
+    const PegInfo* q = get_pegs();
+
+    assert(q);
+
+    for ( int i = 0; i < num_counts; i++ )
+    {
+        if ( q[i].type == CountType::NOW )
+            counts[i] = 0;
+    }
+}
+
 void Module::sum_stats(bool accumulate_now_stats)
 {
     if ( num_counts < 0 )
index 9e973c47fa6bc508f554920c2b207d24c0f1a614..25709bf91361b173cb9e8b4e9c8e5f53613c6028 100644 (file)
@@ -174,6 +174,7 @@ public:
     virtual void show_stats();
     virtual void reset_stats();
     virtual void show_dynamic_stats() {}
+    void clear_global_active_counters();
 
     // Wrappers to check that lists are not tables
     bool verified_begin(const char*, int, SnortConfig*);
index 4f5fa5b07a620c0818ef177dd59a6350a13565ae..8e98e02bfcd321333257a7bb86e9d89379a5c94d 100644 (file)
@@ -93,6 +93,7 @@ ACGetStats::~ACGetStats()
     // shell instead of the logs when initiated by a shell command
     DropStats();
     LogMessage("==================================================\n"); // Marking End of stats
+    ModuleManager::clear_global_active_counters();
 }
 
 bool ACResetStats::execute(Analyzer&, void**)
index 34c1d8ee40e54d39bb0b9e04fa8e6883706988b7..a3f75a3252ea45d8e2f6a5e21c2f3d11d8f31548 100644 (file)
@@ -1413,6 +1413,17 @@ void ModuleManager::reset_stats(SnortConfig*)
     }
 }
 
+void ModuleManager::clear_global_active_counters()
+{
+    auto mod_hooks = get_all_modhooks();
+
+    for ( auto* mh : mod_hooks )
+    {
+        lock_guard<mutex> lock(stats_mutex);
+        mh->mod->clear_global_active_counters();
+    }
+}
+
 void ModuleManager::reset_stats(clear_counter_type_t type)
 {
     if ( type != TYPE_MODULE and type != TYPE_UNKNOWN )
index 0a33a0fcb2daf7acc4215f67cf6212522ff5e116..4cad93b48364b8d2b671e0eef5efb63a4812c5ee 100644 (file)
@@ -90,6 +90,8 @@ public:
     static void reset_stats(SnortConfig*);
     static void reset_stats(clear_counter_type_t);
 
+    static void clear_global_active_counters();
+
     static std::set<uint32_t> gids;
     SO_PUBLIC static std::mutex stats_mutex;
 };