]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2287 in SNORT/snort3 from ~RDEMPSTE/snort3:global_dbus to master
authorRon Dempster (rdempste) <rdempste@cisco.com>
Mon, 29 Jun 2020 12:52:45 +0000 (12:52 +0000)
committerRon Dempster (rdempste) <rdempste@cisco.com>
Mon, 29 Jun 2020 12:52:45 +0000 (12:52 +0000)
Squashed commit of the following:

commit d593b95de75610cdabac982bd92891394e4fbfbf
Author: rdempste <rdempste@cisco.com>
Date:   Wed Jun 24 16:12:21 2020 -0400

    framework: fix global data bus cloning during reload module and policy

src/flow/test/flow_stash_test.cc
src/framework/data_bus.cc
src/framework/data_bus.h
src/main/policy.cc
src/main/policy.h
src/main/snort.cc
src/main/snort_config.cc

index 425ad4185f408475d4383a497ea200bddbadc68d..797705b3a3f9bac0e565e0d9e462426b59e325be 100644 (file)
@@ -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);
index fa456b85377d89b3ad52425b982a7db34beb1656..525c7354ce08a0dc8073d936b77d0740f52f79d2 100644 (file)
@@ -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)
index 82ebd64895f3abef3ccacdde97fc467123f57803..f355301a39965c4d78c7d2c4ef3720fa3cb13b7e 100644 (file)
@@ -85,7 +85,6 @@ protected:
 // FIXIT-P evaluate perf; focus is on correctness
 typedef std::vector<DataHandler*> DataList;
 typedef std::unordered_map<std::string, DataList> DataMap;
-typedef std::unordered_set<const char*> 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;
 };
 }
 
index a698b25ca7eaf7564d530af4dd48e4d25139711b..ef637275d2dec094ddef7277eea39de22c744d03 100644 (file)
@@ -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
 //-------------------------------------------------------------------------
index 25c7567d2795f5eac018964ed0353f92ae718fd5..0fa0a5c6083839ab0188377d2df8e26cca92b9a1 100644 (file)
@@ -128,7 +128,6 @@ public:
     ~InspectionPolicy();
 
     void configure();
-    void clone_dbus(snort::SnortConfig*, const char*);
 
 public:
     PolicyId policy_id = 0;
index 881f792126c0caf9c5073cf2546513bbbf6ac63c..f175cc29ffe5872caa8dc5bcd195e98a0b2ebbd1 100644 (file)
@@ -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;
index fa6e393e3408b933f8bad17797e4f45529865d69..46e9abccbe3e086a7426460eae8b9497f7af67eb 100644 (file)
@@ -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));