From: Ron Dempster (rdempste) Date: Mon, 29 Jun 2020 12:52:45 +0000 (+0000) Subject: Merge pull request #2287 in SNORT/snort3 from ~RDEMPSTE/snort3:global_dbus to master X-Git-Tag: 3.0.2-1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63d825d40d8492dfa5e86d2ac9453f254da62531;p=thirdparty%2Fsnort3.git Merge pull request #2287 in SNORT/snort3 from ~RDEMPSTE/snort3:global_dbus to master Squashed commit of the following: commit d593b95de75610cdabac982bd92891394e4fbfbf Author: rdempste Date: Wed Jun 24 16:12:21 2020 -0400 framework: fix global data bus cloning during reload module and policy --- diff --git a/src/flow/test/flow_stash_test.cc b/src/flow/test/flow_stash_test.cc index 425ad4185..797705b3a 100644 --- a/src/flow/test/flow_stash_test.cc +++ b/src/flow/test/flow_stash_test.cc @@ -88,8 +88,7 @@ DataBus::~DataBus() delete h; } -void DataBus::add_mapped_module(const char*) {} -void DataBus::clone(DataBus& ) {} +void DataBus::clone(DataBus&, const char*) {} void DataBus::subscribe(const char* key, DataHandler* h) { DB->_subscribe(key, h); diff --git a/src/framework/data_bus.cc b/src/framework/data_bus.cc index fa456b853..525c7354c 100644 --- a/src/framework/data_bus.cc +++ b/src/framework/data_bus.cc @@ -77,21 +77,13 @@ DataBus::~DataBus() else delete h; } - - mapped_module.clear(); } -void DataBus::add_mapped_module(const char* name) -{ - if ( name ) - mapped_module.emplace(name); -} - -void DataBus::clone(DataBus& from) +void DataBus::clone(DataBus& from, const char* exclude_name) { for ( auto& p : from.map ) for ( auto* h : p.second ) - if ( mapped_module.count(h->module_name) == 0 ) + if ( nullptr == exclude_name || 0 != strcmp(exclude_name, h->module_name) ) { h->cloned = true; _subscribe(p.first.c_str(), h); @@ -154,10 +146,6 @@ void DataBus::_subscribe(const char* key, DataHandler* h) { DataList& v = map[key]; v.emplace_back(h); - - // Track fresh subscriptions to distinguish during cloning - if ( !h->cloned ) - add_mapped_module(h->module_name); } void DataBus::_unsubscribe(const char* key, DataHandler* h) diff --git a/src/framework/data_bus.h b/src/framework/data_bus.h index 82ebd6489..f355301a3 100644 --- a/src/framework/data_bus.h +++ b/src/framework/data_bus.h @@ -85,7 +85,6 @@ protected: // FIXIT-P evaluate perf; focus is on correctness typedef std::vector DataList; typedef std::unordered_map DataMap; -typedef std::unordered_set DataModule; class SO_PUBLIC DataBus { @@ -94,8 +93,7 @@ public: ~DataBus(); // configure time methods - main thread only - void clone(DataBus& from); - void add_mapped_module(const char*); + void clone(DataBus& from, const char* exclude_name = nullptr); // FIXIT-L ideally these would not be static or would take an inspection policy* static void subscribe(const char* key, DataHandler*); @@ -119,7 +117,6 @@ private: private: DataMap map; - DataModule mapped_module; }; } diff --git a/src/main/policy.cc b/src/main/policy.cc index a698b25ca..ef637275d 100644 --- a/src/main/policy.cc +++ b/src/main/policy.cc @@ -97,14 +97,6 @@ void InspectionPolicy::configure() dbus.subscribe(PACKET_EVENT, new AltPktHandler); } -void InspectionPolicy::clone_dbus(SnortConfig* from, const char* exclude_module) -{ - // Clone subscriptions from another config if they are not excluded - // (e.g., reloading module) and not already subscribed - dbus.add_mapped_module(exclude_module); - dbus.clone(from->policy_map->get_inspection_policy()->dbus); -} - //------------------------------------------------------------------------- // detection policy //------------------------------------------------------------------------- diff --git a/src/main/policy.h b/src/main/policy.h index 25c7567d2..0fa0a5c60 100644 --- a/src/main/policy.h +++ b/src/main/policy.h @@ -128,7 +128,6 @@ public: ~InspectionPolicy(); void configure(); - void clone_dbus(snort::SnortConfig*, const char*); public: PolicyId policy_id = 0; diff --git a/src/main/snort.cc b/src/main/snort.cc index 881f79212..f175cc29f 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -528,6 +528,7 @@ SnortConfig* Snort::get_updated_policy( reset_parse_errors(); SnortConfig* sc = new SnortConfig(other_conf); + sc->global_dbus->clone(*other_conf->global_dbus, iname); if ( fname ) { @@ -569,9 +570,6 @@ SnortConfig* Snort::get_updated_policy( } other_conf->cloned = true; - sc->policy_map->get_inspection_policy()->clone_dbus(other_conf, iname); - sc->global_dbus->add_mapped_module(iname); - sc->global_dbus->clone(*other_conf->global_dbus); InspectorManager::update_policy(sc); reloading = false; return sc; @@ -582,6 +580,7 @@ SnortConfig* Snort::get_updated_module(SnortConfig* other_conf, const char* name reloading = true; SnortConfig* sc = new SnortConfig(other_conf); + sc->global_dbus->clone(*other_conf->global_dbus, name); if ( name ) { @@ -610,9 +609,6 @@ SnortConfig* Snort::get_updated_module(SnortConfig* other_conf, const char* name } other_conf->cloned = true; - sc->policy_map->get_inspection_policy()->clone_dbus(other_conf, name); - sc->global_dbus->add_mapped_module(name); - sc->global_dbus->clone(*other_conf->global_dbus); InspectorManager::update_policy(sc); reloading = false; return sc; diff --git a/src/main/snort_config.cc b/src/main/snort_config.cc index fa6e393e3..46e9abccb 100644 --- a/src/main/snort_config.cc +++ b/src/main/snort_config.cc @@ -208,6 +208,7 @@ SnortConfig::~SnortConfig() { if ( cloned ) { + delete global_dbus; policy_map->set_cloned(true); delete policy_map; return; @@ -322,6 +323,7 @@ void SnortConfig::post_setup() void SnortConfig::clone(const SnortConfig* const conf) { *this = *conf; + global_dbus = new DataBus(); if (conf->homenet.get_family() != 0) memcpy(&homenet, &conf->homenet, sizeof(homenet));