]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4591: Inspector slot
authorRon Dempster (rdempste) <rdempste@cisco.com>
Thu, 30 Jan 2025 18:16:11 +0000 (18:16 +0000)
committerRon Dempster (rdempste) <rdempste@cisco.com>
Thu, 30 Jan 2025 18:16:11 +0000 (18:16 +0000)
Merge in SNORT/snort3 from ~RDEMPSTE/snort3:inspector_slot to master

Squashed commit of the following:

commit c4e59a334e1e81abd3219f4b288589cc2825b83c
Author: Ron Dempster (rdempste) <rdempste@cisco.com>
Date:   Thu Jan 30 10:15:12 2025 -0500

    perf_monitor: update structure clearing to c++ method

commit 7157fa425c4002f5a394da3fe65f158cf8c1270b
Author: Ron Dempster (rdempste) <rdempste@cisco.com>
Date:   Thu Jan 30 10:14:29 2025 -0500

    framework: remove inspector slot and use get_instance_id instead

src/framework/inspector.cc
src/framework/inspector.h
src/managers/inspector_manager.cc
src/managers/test/get_inspector_stubs.h
src/network_inspectors/perf_monitor/flow_ip_tracker.cc

index 6807dc3b8b63d4c469f758b0178fd3290715aebc..1a2e780c46ea82f6bf8e59bec2fa13690bce45d8 100644 (file)
@@ -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] =
 {
index 81eae929f40fcac4581546d1513a2e3a5694102c..e93ea4f6566af1e2481cd35ab4b3e610fb73022c 100644 (file)
@@ -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
index 3eaf0f29849bfe4cf9f9cf99a2a5dbec00b9d0f0..4d258868048631a2bf47b9466cfb51aa760ff2d2 100644 (file)
@@ -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;
 }
 
 //-------------------------------------------------------------------------
index 21a48ad68466c96be2947cfdc795e57133d9f103..135ebd2993cd58bd4bed2d73ce2091be9937336e 100644 (file)
@@ -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() { }
index b036ef635eeb7729b1cd2987112b395ab5459d45..633cc5c38d68b1eb6e2c51cdeea7f2a74e85747a 100644 (file)
@@ -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;