From: Shanmugam S (shanms) Date: Tue, 9 Mar 2021 16:22:13 +0000 (+0000) Subject: Merge pull request #2766 in SNORT/snort3 from ~SUNIMUKH/snort3:clear_global_counter... X-Git-Tag: 3.1.2.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ccd1c2da9c0132e7a5802e78dfa0fd2aed7e755;p=thirdparty%2Fsnort3.git Merge pull request #2766 in SNORT/snort3 from ~SUNIMUKH/snort3:clear_global_counter to master Squashed commit of the following: commit df425d8fc335ca5891200064f2c03b9b6f7d6892 Author: Sunirmal Mukherjee Date: Tue Feb 23 17:28:05 2021 -0500 module: Introduced new api to clear global active module counters --- diff --git a/src/framework/module.cc b/src/framework/module.cc index 2b3daced4..502c37c33 100644 --- a/src/framework/module.cc +++ b/src/framework/module.cc @@ -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 ) diff --git a/src/framework/module.h b/src/framework/module.h index 9e973c47f..25709bf91 100644 --- a/src/framework/module.h +++ b/src/framework/module.h @@ -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*); diff --git a/src/main/analyzer_command.cc b/src/main/analyzer_command.cc index 4f5fa5b07..8e98e02bf 100644 --- a/src/main/analyzer_command.cc +++ b/src/main/analyzer_command.cc @@ -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**) diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index 34c1d8ee4..a3f75a325 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -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 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 ) diff --git a/src/managers/module_manager.h b/src/managers/module_manager.h index 0a33a0fcb..4cad93b48 100644 --- a/src/managers/module_manager.h +++ b/src/managers/module_manager.h @@ -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 gids; SO_PUBLIC static std::mutex stats_mutex; };