]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2006 in SNORT/snort3 from ~SBAIGAL/snort3:revert_so_reload to...
authorSteve Chew (stechew) <stechew@cisco.com>
Fri, 14 Feb 2020 01:04:46 +0000 (01:04 +0000)
committerSteve Chew (stechew) <stechew@cisco.com>
Fri, 14 Feb 2020 01:04:46 +0000 (01:04 +0000)
Squashed commit of the following:

commit b75c6217776b5d124c7ae002a1f9432e305a82c3
Author: Steven Baigal (sbaigal) <sbaigal@cisco.com>
Date:   Thu Feb 13 18:00:27 2020 -0500

    Revert "Merge pull request #1963 in SNORT/snort3 from ~SBAIGAL/snort3:so_reload to master"

    This reverts commit e6293b0e23bc8620560896d15930f1725db33d0e.

commit 68842c56dd0a9bc484fe0ecf95e816c54b9f70cd
Author: Steven Baigal (sbaigal) <sbaigal@cisco.com>
Date:   Thu Feb 13 18:00:09 2020 -0500

    Revert "Merge pull request #2003 in SNORT/snort3 from ~SBAIGAL/snort3:soapi_version_bump to master"

    This reverts commit 1b256c379cc1ca49626817c2edd11fab713ecb94.

14 files changed:
src/framework/so_rule.h
src/ips_options/ips_so.cc
src/main.cc
src/main/help.cc
src/main/snort.cc
src/main/snort.h
src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_module.cc
src/managers/plugin_manager.cc
src/managers/plugin_manager.h
src/managers/so_manager.cc
src/managers/so_manager.h
src/parser/parse_rule.cc

index b5ec8b0e40537679d31f5d8271f65f1ddb74067a..3a2b7b6d4516a7913474310bc14f057e02b586cd 100644 (file)
@@ -35,7 +35,7 @@ struct Packet;
 }
 
 // this is the current version of the api
-#define SOAPI_VERSION ((BASE_API_VERSION << 16) | 1)
+#define SOAPI_VERSION ((BASE_API_VERSION << 16) | 0)
 
 //-------------------------------------------------------------------------
 // rule format is:  header ( [<stub opts>;] soid:<tag>; [<remaining opts>;] )
index 3e2f3e7c8fa15bda950a1422eaf378371148b8cf..e32932b99e6b37e6ea8b621e1c4b97c2b30835db 100644 (file)
@@ -40,7 +40,7 @@ static THREAD_LOCAL ProfileStats soPerfStats;
 class SoOption : public IpsOption
 {
 public:
-    SoOption(const char*, const char*, bool, SoEvalFunc f, void* v, SnortConfig*);
+    SoOption(const char*, const char*, bool, SoEvalFunc f, void* v);
     ~SoOption() override;
 
     uint32_t hash() const override;
@@ -57,11 +57,10 @@ private:
     bool relative_flag;
     SoEvalFunc func;
     void* data;
-    SnortConfig* cfg;
 };
 
 SoOption::SoOption(
-    const char* id, const char* s, bool r, SoEvalFunc f, void* v, SnortConfig* sc)
+    const char* id, const char* s, bool r, SoEvalFunc f, void* v)
     : IpsOption(s_name)
 {
     soid = id;
@@ -69,12 +68,12 @@ SoOption::SoOption(
     relative_flag = r;
     func = f;
     data = v;
-    cfg = sc;
 }
 
 SoOption::~SoOption()
 {
-    SoManager::delete_so_data(soid, data, cfg);
+    if ( data )
+        SoManager::delete_so_data(soid, data);
 }
 
 uint32_t SoOption::hash() const
@@ -143,14 +142,12 @@ public:
 public:
     string name;
     bool relative_flag;
-    SnortConfig* cfg;
 };
 
-bool SoModule::begin(const char*, int, SnortConfig* sc)
+bool SoModule::begin(const char*, int, SnortConfig*)
 {
     name.clear();
     relative_flag = false;
-    cfg = sc;
     return true;
 }
 
@@ -194,14 +191,14 @@ static IpsOption* so_ctor(Module* p, OptTreeNode* otn)
         ParseError("no soid before so:%s", name);
         return nullptr;
     }
-    SoEvalFunc func = SoManager::get_so_eval(otn->soid, name, &data, m->cfg);
+    SoEvalFunc func = SoManager::get_so_eval(otn->soid, name, &data);
 
     if ( !func )
     {
         ParseError("can't link so:%s", name);
         return nullptr;
     }
-    return new SoOption(otn->soid, name, relative_flag, func, data, m->cfg);
+    return new SoOption(otn->soid, name, relative_flag, func, data);
 }
 
 static void so_dtor(IpsOption* p)
index 70b0616477a09e534e7ea7a8577cfc0c93f9148e..fc447ace8118934a5c1f0116113b44e1b2e4e6b9 100644 (file)
@@ -329,24 +329,16 @@ int main_reload_config(lua_State* L)
         return 0;
     }
     const char* fname =  nullptr;
-    const char* plugin_path =  nullptr;
 
     if ( L )
     {
         Lua::ManageStack(L, 1);
         fname = luaL_checkstring(L, 1);
-        if (lua_gettop(L) > 1)
-        {
-            plugin_path = luaL_checkstring(L, 2);
-#ifdef REG_TEST
-            LogMessage("reload plugin_path: %s\n", plugin_path);
-#endif
-        }
     }
 
     current_request->respond(".. reloading configuration\n");
     SnortConfig* old = SnortConfig::get_conf();
-    SnortConfig* sc = Snort::get_reload_config(fname, plugin_path);
+    SnortConfig* sc = Snort::get_reload_config(fname);
 
     if ( !sc )
     {
@@ -364,12 +356,10 @@ int main_reload_config(lua_State* L)
 
     if ( !tc )
     {
-        // FIXIT-L it does not seem a valid check, delete old config if come to it
         current_request->respond("== reload failed - bad config\n");
         SnortConfig::set_parser_conf(nullptr);
         return 0;
     }
-    PluginManager::reload_so_plugins_cleanup(sc, true);
     SnortConfig::set_conf(sc);
     proc_stats.conf_reloads++;
 
index fa9e689a4c341e4bc0e40f5789cf2ef2bcb72a68..1599a62b14b84a282913e7298d66a182161cf1fc 100644 (file)
@@ -155,7 +155,6 @@ enum HelpType
     SnortConfig::set_conf(new SnortConfig);
     ScriptManager::load_scripts(sc->script_paths);
     PluginManager::load_plugins(sc->plugin_path);
-    PluginManager::load_so_plugins(sc);
     ModuleManager::init();
 
     switch ( ht )
@@ -173,7 +172,7 @@ enum HelpType
         ModuleManager::dump_rules(val);
         break;
     case HT_DDR:
-        SoManager::dump_rule_stubs(val, sc);
+        SoManager::dump_rule_stubs(val);
         break;
     case HT_DFL:
         ModuleManager::dump_defaults(val);
index 273a8c4fb9dd68615e757e353b1685287c309ae2..738b585abff4f240a81660e1367e0c4da7249d14 100644 (file)
@@ -155,7 +155,7 @@ void Snort::init(int argc, char** argv)
      * Set the global snort_conf that will be used during run time */
     sc->merge(snort_cmd_line_conf);
     SnortConfig::set_conf(sc);
-    PluginManager::load_so_plugins(sc);
+
 #ifdef PIGLET
     if ( !Piglet::piglet_mode() )
 #endif
@@ -421,7 +421,6 @@ void Snort::cleanup()
 
 void Snort::reload_failure_cleanup(SnortConfig* sc)
 {
-    PluginManager::reload_so_plugins_cleanup(sc, false);
     parser_term(sc);
     delete sc;
     reloading = false;
@@ -429,7 +428,7 @@ void Snort::reload_failure_cleanup(SnortConfig* sc)
 
 // FIXIT-M refactor this so startup and reload call the same core function to
 // instantiate things that can be reloaded
-SnortConfig* Snort::get_reload_config(const char* fname, const char* plugin_path)
+SnortConfig* Snort::get_reload_config(const char* fname)
 {
     reloading = true;
     ModuleManager::reset_errors();
@@ -446,8 +445,6 @@ SnortConfig* Snort::get_reload_config(const char* fname, const char* plugin_path
         return nullptr;
     }
 
-    PluginManager::reload_so_plugins(plugin_path, sc);
-
     sc->setup();
 
 #ifdef SHELL
index 3efeb7fc4636cc140d3182baa0cd7d6f66607a60..efe5a9e7503c80123ea9f739262d93b00ea903e6 100644 (file)
@@ -38,7 +38,7 @@ struct SnortConfig;
 class Snort
 {
 public:
-    static SnortConfig* get_reload_config(const char* fname, const char* plugin_path = nullptr);
+    static SnortConfig* get_reload_config(const char* fname);
     static SnortConfig* get_updated_policy(SnortConfig*, const char* fname, const char* iname);
     static SnortConfig* get_updated_module(SnortConfig*, const char* name);
     static void setup(int argc, char* argv[]);
index 8666ca5d8fcd31dfd87b2550ddb335dd65d2ad45..9e1157fef3831086f6c21c5b0aa6fd4bbb5b3b40 100644 (file)
@@ -47,7 +47,6 @@
 #include "managers/ips_manager.h"
 #include "managers/module_manager.h"
 #include "managers/mpse_manager.h"
-#include "managers/so_manager.h"
 #include "memory/memory_config.h"
 #include "packet_io/sfdaq.h"
 #include "packet_io/sfdaq_config.h"
@@ -210,7 +209,6 @@ void SnortConfig::init(const SnortConfig* const other_conf, ProtocolReference* p
         memset(evalOrder, 0, sizeof(evalOrder));
         proto_ref = new ProtocolReference(protocol_reference);
         flowbits_ginit(this);
-        so_rules = new SoRules;
     }
     else
     {
@@ -306,7 +304,6 @@ SnortConfig::~SnortConfig()
     delete memory;
     delete daq_config;
     delete proto_ref;
-    delete so_rules;
 
     reload_tuners.clear();
 
index 4c099518cd0dd6f7e1cdb47d106522092abc7422..a636d806e55ac4770fb8b1af93c5542ae24e22ec 100644 (file)
@@ -136,14 +136,12 @@ struct HighAvailabilityConfig;
 struct IpsActionsConfig;
 struct LatencyConfig;
 struct MemoryConfig;
-struct Plugins;
 struct PORT_RULE_MAP;
 struct RateFilterConfig;
 struct ReferenceSystemNode;
 struct RuleListNode;
 struct RulePortTables;
 struct SFDAQConfig;
-struct SoRules;
 struct ThresholdConfig;
 struct VarNode;
 
@@ -415,8 +413,7 @@ public:
     //Reload inspector related
 
     bool cloned = false;
-    Plugins* plugins = nullptr;
-    SoRules* so_rules = nullptr;
+
 private:
     std::list<ReloadResourceTuner*> reload_tuners;
 
index 805451e6ffd8397d66b4f8dc1972c5411e2823f8..b6b9e684172d75d98d010c104621ec0610d3346d 100644 (file)
@@ -65,14 +65,6 @@ static const Parameter s_reload[] =
     { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
 };
 
-static const Parameter s_reload_w_path[] =
-{
-    { "filename", Parameter::PT_STRING, "(optional)", nullptr,
-      "[<plugin path>] name of file to load" },
-
-    { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
-};
-
 static const Parameter s_delete[] =
 {
     { "inspector", Parameter::PT_STRING, nullptr, nullptr,
@@ -106,7 +98,7 @@ static const Command snort_cmds[] =
 
     { "dump_stats", main_dump_stats, nullptr, "show summary statistics" },
     { "rotate_stats", main_rotate_stats, nullptr, "roll perfmonitor log files" },
-    { "reload_config", main_reload_config, s_reload_w_path, "load new configuration" },
+    { "reload_config", main_reload_config, s_reload, "load new configuration" },
     { "reload_policy", main_reload_policy, s_reload, "reload part or all of the default policy" },
     { "reload_module", main_reload_module, s_module, "reload module" },
     { "reload_daq", main_reload_daq, nullptr, "reload daq module" },
index 59b706f588fdee17cdda9a841990c82f77d9be83..a0ea0c35dd74c977e875b81e5002b94500dc8a57 100644 (file)
@@ -36,7 +36,6 @@
 #include "helpers/directory.h"
 #include "helpers/markup.h"
 #include "log/messages.h"
-#include "main/snort_config.h"
 
 #ifdef PIGLET
 #include "piglet/piglet_api.h"
@@ -138,6 +137,7 @@ struct Plugin
 };
 
 typedef std::map<string, Plugin> PlugMap;
+static PlugMap plug_map;
 
 struct RefCount
 {
@@ -149,14 +149,7 @@ struct RefCount
 };
 
 typedef std::map<void*, RefCount> RefMap;
-
-struct Plugins
-{
-    PlugMap plug_map;
-    RefMap ref_map;
-};
-
-static Plugins s_plugins;
+static RefMap ref_map;
 
 static void set_key(string& key, Symbol* sym, const char* name)
 {
@@ -185,16 +178,8 @@ static bool compatible_builds(const char* plug_opts)
     return true;
 }
 
-static bool plugin_is_reloadable(const BaseApi* api)
-{
-    if (api->type == PT_SO_RULE)
-        return true;
-    else
-        return false;
-}
-
 static bool register_plugin(
-    const BaseApi* api, void* handle, const char* file, SnortConfig* sc)
+    const BaseApi* api, void* handle, const char* file)
 {
     if ( api->type >= PT_MAX )
         return false;
@@ -221,22 +206,20 @@ static bool register_plugin(
         return false;
     }
 
-    if (sc and !plugin_is_reloadable(api))
-        return false;
+    // validate api ?
 
     string key;
     set_key(key, sym, api->name);
 
-    Plugin& p = (sc ? sc->plugins->plug_map[key] : s_plugins.plug_map[key]);
-    RefMap& p_ref = (sc ? sc->plugins->ref_map : s_plugins.ref_map);
+    Plugin& p = plug_map[key];
+
     if ( p.api )
     {
-        if ( p.api->version > api->version)
+        if ( p.api->version >= api->version)
             return false;  // keep the old one
 
-        if ( p.handle && p_ref[p.handle].count )
-            --p_ref[p.handle].count;
-        // TODO, replace/release cleanup
+        if ( p.handle && !--ref_map[p.handle].count )
+            dlclose(p.handle); // drop the old one
     }
 
     p.key = key;
@@ -245,26 +228,27 @@ static bool register_plugin(
     p.source = file;
 
     if ( handle )
-        ++p_ref[handle].count;
+        ++ref_map[handle].count;
 
     return true;
 }
 
 static void load_list(
-    const BaseApi** api, void* handle = nullptr, const char* file = "static", SnortConfig* sc = nullptr)
+    const BaseApi** api, void* handle = nullptr, const char* file = "static")
 {
     bool keep = false;
 
     while ( *api )
     {
-        keep = register_plugin(*api, handle, file, sc) || keep;
+        keep = register_plugin(*api, handle, file) || keep;
+        //printf("loaded %s\n", (*api)->name);
         ++api;
     }
     if ( handle && !keep )
         dlclose(handle);
 }
 
-static bool load_lib(const char* file, SnortConfig* sc)
+static bool load_lib(const char* file)
 {
     struct stat fs;
     void* handle;
@@ -288,7 +272,7 @@ static bool load_lib(const char* file, SnortConfig* sc)
         dlclose(handle);
         return false;
     }
-    load_list(api, handle, file, sc);
+    load_list(api, handle, file);
     return true;
 }
 
@@ -330,7 +314,7 @@ static void add_plugin(Plugin& p)
         break;
 
     case PT_SO_RULE:
-        // SO rules are added later
+        SoManager::add_plugin((const SoApi*)p.api);
         break;
 
     case PT_LOGGER:
@@ -353,7 +337,7 @@ static void add_plugin(Plugin& p)
     }
 }
 
-static void load_plugins(const std::string& paths, SnortConfig* sc = nullptr)
+static void load_plugins(const std::string& paths)
 {
     struct stat sb;
     stringstream paths_stream(paths);
@@ -374,36 +358,38 @@ static void load_plugins(const std::string& paths, SnortConfig* sc = nullptr)
             Directory d(path.c_str(), lib_pattern);
 
             while ( const char* f = d.next() )
-                load_lib(f, sc);
+                load_lib(f);
         }
         else
         {
             if ( path.find("/") == string::npos )
                 path = "./" + path;
 
-            load_lib(path.c_str(), sc);
+            load_lib(path.c_str());
         }
     }
 }
 
 static void add_plugins()
 {
-    for (auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+    PlugMap::iterator it;
+
+    for ( it = plug_map.begin(); it != plug_map.end(); ++it )
         add_plugin(it->second);
 }
 
 static void unload_plugins()
 {
-    for (auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+    for ( PlugMap::iterator it = plug_map.begin(); it != plug_map.end(); ++it )
     {
         if ( it->second.handle )
-            --s_plugins.ref_map[it->second.handle].count;
+            --ref_map[it->second.handle].count;
 
         it->second.clear();
     }
 
 #ifndef REG_TEST
-    for ( RefMap::iterator it = s_plugins.ref_map.begin(); it != s_plugins.ref_map.end(); ++it )
+    for ( RefMap::iterator it = ref_map.begin(); it != ref_map.end(); ++it )
         dlclose(it->first);
 #endif
 }
@@ -431,58 +417,11 @@ void PluginManager::load_plugins(const std::string& paths)
     add_plugins();
 }
 
-void PluginManager::reload_so_plugins(const char* paths, SnortConfig* sc)
-{
-    sc->plugins = new Plugins;
-    sc->plugins->plug_map = s_plugins.plug_map;
-    sc->plugins->ref_map = s_plugins.ref_map;
-    if (paths)
-        ::load_plugins(paths, sc);
-    load_so_plugins(sc, true);
-}
-
-void PluginManager::reload_so_plugins_cleanup(SnortConfig* sc, bool keep)
-{
-    if (!sc->plugins)
-        return;
-
-    if (keep)
-    {
-        // set the new plugins to current
-        s_plugins.plug_map.clear();
-        s_plugins.plug_map = sc->plugins->plug_map;
-        sc->plugins->plug_map.clear();
-
-        s_plugins.ref_map.clear();
-        s_plugins.ref_map = sc->plugins->ref_map;
-        sc->plugins->ref_map.clear();
-    }
-    else
-    {
-        // close newly opened SO,
-        for (auto i = sc->plugins->ref_map.begin(); i != sc->plugins->ref_map.end(); ++i)
-        {
-            if (s_plugins.ref_map.find(i->first) == s_plugins.ref_map.end())
-                dlclose(i->first);
-        }
-        sc->plugins->plug_map.clear();
-        sc->plugins->ref_map.clear();
-    }
-    delete sc->plugins;
-    sc->plugins = nullptr;
-}
-
-void PluginManager::load_so_plugins(SnortConfig* sc, bool is_reload)
-{
-    auto p = is_reload ? sc->plugins->plug_map : s_plugins.plug_map;
-    for (auto it = p.begin(); it != p.end(); ++it )
-        if (it->second.api->type == PT_SO_RULE)
-            SoManager::add_plugin((const SoApi*)it->second.api, sc);
-}
-
 void PluginManager::list_plugins()
 {
-    for (auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+    PlugMap::iterator it;
+
+    for ( it = plug_map.begin(); it != plug_map.end(); ++it )
     {
         Plugin& p = it->second;
         cout << Markup::item();
@@ -495,7 +434,9 @@ void PluginManager::list_plugins()
 
 void PluginManager::show_plugins()
 {
-    for (auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+    PlugMap::iterator it;
+
+    for ( it = plug_map.begin(); it != plug_map.end(); ++it )
     {
         Plugin& p = it->second;
 
@@ -523,6 +464,7 @@ void PluginManager::release_plugins()
     ActionManager::release_plugins();
     InspectorManager::release_plugins();
     IpsManager::release_plugins();
+    SoManager::release_plugins();
     MpseManager::release_plugins();
     CodecManager::release_plugins();
     ConnectorManager::release_plugins();
@@ -538,9 +480,9 @@ const BaseApi* PluginManager::get_api(PlugType type, const char* name)
     string key;
     set_key(key, symbols+type, name);
 
-    auto it = s_plugins.plug_map.find(key);
+    const PlugMap::iterator it = plug_map.find(key);
 
-    if ( it != s_plugins.plug_map.end() )
+    if ( it != plug_map.end() )
         return it->second.api;
 
     return nullptr;
@@ -549,7 +491,7 @@ const BaseApi* PluginManager::get_api(PlugType type, const char* name)
 #ifdef PIGLET
 PlugType PluginManager::get_type_from_name(const std::string& name)
 {
-    for ( auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+    for ( auto it = plug_map.begin(); it != plug_map.end(); ++it )
     {
         const auto* api = it->second.api;
         if ( name == api->name )
@@ -620,7 +562,8 @@ const char* PluginManager::get_available_plugins(PlugType t)
 {
     static std::string s;
     s.clear();
-    for ( auto it = s_plugins.plug_map.begin(); it != s_plugins.plug_map.end(); ++it )
+
+    for ( auto it = plug_map.begin(); it != plug_map.end(); ++it )
     {
         const auto* api = it->second.api;
 
@@ -634,3 +577,4 @@ const char* PluginManager::get_available_plugins(PlugType t)
     }
     return s.c_str();
 }
+
index 7a31742105db81599831ef26c08580359173cdc6..a8a13d52fd8997b46aeb57036053c8e33aaa6d94 100644 (file)
@@ -67,9 +67,6 @@ public:
         const char* name);
 
     static const char* get_available_plugins(PlugType);
-    static void load_so_plugins(snort::SnortConfig*, bool is_reload = false);
-    static void reload_so_plugins(const char*, snort::SnortConfig*);
-    static void reload_so_plugins_cleanup(snort::SnortConfig*, bool);
 };
 
 #endif
index 1ebc92a2f91973db5b854fcd3a6cf05ad9bf1c65..1bf2b3437e56795804fa96b7f1e0c410d732e45a 100644 (file)
 #include <cstring>
 #include <iomanip>
 #include <iostream>
+#include <list>
 #include <sstream>
 
 #include "log/messages.h"
-#include "main/snort_config.h"
-#include "managers/plugin_manager.h"
 #include "parser/parse_so_rule.h"
 
 using namespace snort;
 using namespace std;
 
+static list<const SoApi*> s_rules;
+
 //-------------------------------------------------------------------------
 // plugins
 //-------------------------------------------------------------------------
-SoRules::~SoRules()
+
+void SoManager::add_plugin(const SoApi* api)
 {
-    api.clear();
+    s_rules.emplace_back(api);
 }
 
-void SoManager::add_plugin(const SoApi* api, SnortConfig* sc)
+void SoManager::release_plugins()
 {
-    sc->so_rules->api.emplace_back(api);
+    s_rules.clear();
 }
 
 void SoManager::dump_plugins()
 {
     Dumper d("SO Rules");
 
-    for ( auto* p : SnortConfig::get_conf()->so_rules->api )
+    for ( auto* p : s_rules )
         d.dump(p->base.name, p->base.version);
 }
 
@@ -184,18 +186,18 @@ static const char* revert(const uint8_t* data, unsigned len)
 
 //-------------------------------------------------------------------------
 
-static const SoApi* get_so_api(const char* soid, SnortConfig* sc = nullptr)
+static const SoApi* get_so_api(const char* soid)
 {
-    for ( auto* p : (sc ? sc->so_rules->api : SnortConfig::get_conf()->so_rules->api) )
+    for ( auto* p : s_rules )
         if ( !strcmp(p->base.name, soid) )
             return p;
 
     return nullptr;
 }
 
-const char* SoManager::get_so_rule(const char* soid, SnortConfig* sc)
+const char* SoManager::get_so_rule(const char* soid)
 {
-    const SoApi* api = get_so_api(soid, sc);
+    const SoApi* api = get_so_api(soid);
 
     if ( !api )
         return nullptr;
@@ -205,9 +207,9 @@ const char* SoManager::get_so_rule(const char* soid, SnortConfig* sc)
     return rule;
 }
 
-SoEvalFunc SoManager::get_so_eval(const char* soid, const char* so, void** data, SnortConfig* sc)
+SoEvalFunc SoManager::get_so_eval(const char* soid, const char* so, void** data)
 {
-    const SoApi* api = get_so_api(soid, sc);
+    const SoApi* api = get_so_api(soid);
 
     if ( !api || !api->ctor )
         return nullptr;
@@ -215,11 +217,9 @@ SoEvalFunc SoManager::get_so_eval(const char* soid, const char* so, void** data,
     return api->ctor(so, data);
 }
 
-void SoManager::delete_so_data(const char* soid, void* pv, SnortConfig* sc)
+void SoManager::delete_so_data(const char* soid, void* pv)
 {
-    if (!pv)
-        return;
-    const SoApi* api = get_so_api(soid, sc);
+    const SoApi* api = get_so_api(soid);
 
     if ( api && api->dtor )
         api->dtor(pv);
@@ -227,11 +227,11 @@ void SoManager::delete_so_data(const char* soid, void* pv, SnortConfig* sc)
 
 //-------------------------------------------------------------------------
 
-void SoManager::dump_rule_stubs(const char*, SnortConfig* sc)
+void SoManager::dump_rule_stubs(const char*)
 {
     unsigned c = 0;
 
-    for ( auto* p : sc->so_rules->api )
+    for ( auto* p : s_rules )
     {
         const char* rule = revert(p->rule, p->length);
 
index 8fa938719ed65d6e4014233fc5a00abdedcb0d8a..ae30f0a7dd2901a3f3ac1db3f8f1d00790e58f89 100644 (file)
 
 // Factory for shared object rules.
 // Runtime is same as for text rules.
-#include <list>
+
 #include "framework/so_rule.h"
 
 namespace snort
 {
 struct SnortConfig;
 }
+struct SoApi;
 
 //-------------------------------------------------------------------------
-struct SoRules
-{
-    std::list<const SoApi*> api;
-    ~SoRules();
-};
 
 class SoManager
 {
 public:
-    static void add_plugin(const SoApi*, snort::SnortConfig*);
+    static void add_plugin(const SoApi*);
     static void dump_plugins();
+    static void release_plugins();
 
     static void instantiate(const SoApi*);
 
     // soid is arg to soid option, so is arg to so option
-    static const char* get_so_rule(const char* soid, snort::SnortConfig* sc = nullptr);
-    static SoEvalFunc get_so_eval(const char* soid, const char* so,
-        void** data, snort::SnortConfig* sc = nullptr);
-    static void delete_so_data(const char* soid, void*, snort::SnortConfig* sc = nullptr);
+    static const char* get_so_rule(const char* soid);
+    static SoEvalFunc get_so_eval(const char* soid, const char* so, void** data);
+    static void delete_so_data(const char* soid, void*);
 
     static void rule_to_hex(const char* file);
     static void rule_to_text(const char* file);
-    static void dump_rule_stubs(const char*, snort::SnortConfig*);
+    static void dump_rule_stubs(const char*);
 };
 
 #endif
index 4cba6699e4e632df95ec323059e2b0a26a212b0c..e01b2621dac78a7e36d1bd80f83e2b47f789ce80 100644 (file)
@@ -1143,7 +1143,7 @@ void parse_rule_close(SnortConfig* sc, RuleTreeNode& rtn, OptTreeNode* otn)
         if ( rtn.dip )
             sfvar_free(rtn.dip);
 
-        const char* rule = SoManager::get_so_rule(otn->soid, sc);
+        const char* rule = SoManager::get_so_rule(otn->soid);
         IpsManager::reset_options();
 
         if ( !rule )