From: Ron Dempster (rdempste) Date: Thu, 30 Jan 2025 18:16:11 +0000 (+0000) Subject: Pull request #4591: Inspector slot X-Git-Tag: 3.6.3.0~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08c0abf6920c9bc64a3b33dab897d72a12d92f87;p=thirdparty%2Fsnort3.git Pull request #4591: Inspector slot Merge in SNORT/snort3 from ~RDEMPSTE/snort3:inspector_slot to master Squashed commit of the following: commit c4e59a334e1e81abd3219f4b288589cc2825b83c Author: Ron Dempster (rdempste) Date: Thu Jan 30 10:15:12 2025 -0500 perf_monitor: update structure clearing to c++ method commit 7157fa425c4002f5a394da3fe65f158cf8c1270b Author: Ron Dempster (rdempste) Date: Thu Jan 30 10:14:29 2025 -0500 framework: remove inspector slot and use get_instance_id instead --- diff --git a/src/framework/inspector.cc b/src/framework/inspector.cc index 6807dc3b8..1a2e780c4 100644 --- a/src/framework/inspector.cc +++ b/src/framework/inspector.cc @@ -42,10 +42,6 @@ public: using namespace snort; -#ifndef _WIN64 -unsigned THREAD_LOCAL Inspector::slot = 0; -#endif - //------------------------------------------------------------------------- // packet handler stuff //------------------------------------------------------------------------- @@ -122,10 +118,10 @@ bool Inspector::likes(Packet* p) } void Inspector::add_ref() -{ ++ref_count[get_slot()]; } +{ ++ref_count[get_instance_id()]; } void Inspector::rem_ref() -{ --ref_count[get_slot()]; } +{ --ref_count[get_instance_id()]; } void Inspector::add_global_ref() { ++ref_count[0]; } @@ -147,10 +143,10 @@ void Inspector::copy_thread_storage(Inspector* ins) } void Inspector::set_thread_specific_data(void* tsd) -{ thread_specific_data->data[get_slot()] = tsd; } +{ thread_specific_data->data[get_instance_id()] = tsd; } void* Inspector::get_thread_specific_data() const -{ return thread_specific_data->data[get_slot()]; } +{ return thread_specific_data->data[get_instance_id()]; } static const char* InspectorTypeNames[IT_MAX] = { diff --git a/src/framework/inspector.h b/src/framework/inspector.h index 81eae929f..e93ea4f65 100644 --- a/src/framework/inspector.h +++ b/src/framework/inspector.h @@ -43,7 +43,7 @@ struct SnortConfig; struct Packet; // this is the current version of the api -#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 1) +#define INSAPI_VERSION ((BASE_API_VERSION << 16) | 2) struct InspectionBuffer { @@ -201,13 +201,6 @@ public: virtual const uint8_t* adjust_log_packet(Packet*, uint16_t&) { return nullptr; } - static unsigned get_slot() -#ifndef _WIN64 - { return slot; } -#else - { return get_instance_id(); } -#endif - protected: // main thread functions Inspector(); // internal init only at this point @@ -221,12 +214,6 @@ private: const char* alias_name = nullptr; uint64_t network_policy_user_id = 0; bool network_policy_user_id_set = false; - -#ifndef _WIN64 -private: - friend class InspectorManager; - static THREAD_LOCAL unsigned slot; -#endif }; // at present there is no sequencing among like types except that appid diff --git a/src/managers/inspector_manager.cc b/src/managers/inspector_manager.cc index 3eaf0f298..4d2588680 100644 --- a/src/managers/inspector_manager.cc +++ b/src/managers/inspector_manager.cc @@ -293,7 +293,7 @@ void InspectorList::tterm(PHObjectList* handlers) void InspectorList::tterm_removed() { for ( auto& ri : removed_ilist ) - ri.instance->tterm(ri.handlers[Inspector::get_slot()]); + ri.instance->tterm(ri.handlers[get_instance_id()]); } static PHInstance* get_instance(InspectorList* il, const char* keyword); @@ -459,7 +459,7 @@ void TrafficPolicy::vectorize(SnortConfig*) PHObjectList* TrafficPolicy::get_specific_handlers() { - unsigned slot = Inspector::get_slot(); + unsigned slot = get_instance_id(); assert(ts_handlers); PHObjectList* handlers = ts_handlers->olists[slot]; if (!handlers) @@ -607,7 +607,7 @@ void SingleInstanceInspectorPolicy::tterm(PHObjectList* handlers) void SingleInstanceInspectorPolicy::tterm_removed() { if (removed_instance) - removed_instance->tterm(s_tl_handlers[Inspector::get_slot()]); + removed_instance->tterm(s_tl_handlers[get_instance_id()]); } void SingleInstanceInspectorPolicy::print_config(SnortConfig* sc, const char* title) @@ -1352,13 +1352,10 @@ void PHInstance::tterm(PHObjectList* handlers) void InspectorManager::thread_init(const SnortConfig* sc) { SnortConfig::update_thread_reload_id(); -#ifndef _WIN64 - Inspector::slot = get_instance_id(); -#endif // Initial build out of this thread's configured plugin registry PHObjectList* g_handlers = new PHObjectList; - s_tl_handlers[Inspector::get_slot()] = g_handlers; + s_tl_handlers[get_instance_id()] = g_handlers; for ( auto* p : sc->framework_config->clist ) { PHObject& phg = get_thread_local_plugin(p->api, g_handlers); @@ -1401,7 +1398,7 @@ void InspectorManager::thread_reinit(const SnortConfig* sc) sc->policy_map->set_inspector_tinit_complete(instance_id, true); // Update this thread's configured plugin registry with any newly configured inspectors - PHObjectList* g_handlers = s_tl_handlers[Inspector::get_slot()]; + PHObjectList* g_handlers = s_tl_handlers[get_instance_id()]; for ( auto* p : sc->framework_config->clist ) { PHObject& phg = get_thread_local_plugin(p->api, g_handlers); @@ -1471,7 +1468,7 @@ void InspectorManager::thread_stop_removed(const SnortConfig* sc) void InspectorManager::thread_stop(const SnortConfig* sc) { // If thread_init() was never called, we have nothing to do. - PHObjectList* g_handlers = s_tl_handlers[Inspector::get_slot()]; + PHObjectList* g_handlers = s_tl_handlers[get_instance_id()]; if ( !g_handlers ) return; @@ -1503,7 +1500,7 @@ void InspectorManager::thread_stop(const SnortConfig* sc) void InspectorManager::thread_term() { // If thread_init() was never called, we have nothing to do. - PHObjectList* handlers = s_tl_handlers[Inspector::get_slot()]; + PHObjectList* handlers = s_tl_handlers[get_instance_id()]; if ( !handlers ) return; @@ -1514,7 +1511,7 @@ void InspectorManager::thread_term() phg.api.tterm(); } delete handlers; - s_tl_handlers[Inspector::get_slot()] = nullptr; + s_tl_handlers[get_instance_id()] = nullptr; } //------------------------------------------------------------------------- diff --git a/src/managers/test/get_inspector_stubs.h b/src/managers/test/get_inspector_stubs.h index 21a48ad68..135ebd299 100644 --- a/src/managers/test/get_inspector_stubs.h +++ b/src/managers/test/get_inspector_stubs.h @@ -61,7 +61,6 @@ void DetectionEngine::disable_content(Packet*) { } unsigned SnortConfig::get_thread_reload_id() { return 1; } void SnortConfig::update_thread_reload_id() { } -THREAD_LOCAL unsigned Inspector::slot = 0; bool Inspector::is_inactive() { return true; } Inspector::Inspector() { ref_count = nullptr; } Inspector::~Inspector() { } diff --git a/src/network_inspectors/perf_monitor/flow_ip_tracker.cc b/src/network_inspectors/perf_monitor/flow_ip_tracker.cc index b036ef635..633cc5c38 100644 --- a/src/network_inspectors/perf_monitor/flow_ip_tracker.cc +++ b/src/network_inspectors/perf_monitor/flow_ip_tracker.cc @@ -90,7 +90,7 @@ FlowStateValue* FlowIPTracker::find_stats(const SfIp* src_addr, const SfIp* dst_ if ( ip_map->insert(&key, nullptr) != HASH_OK ) return nullptr; value = (FlowStateValue*)ip_map->get_user_data(); - memset(value, 0, sizeof(FlowStateValue)); + *value = {}; } return value;