]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2010 in SNORT/snort3 from ~SATHIRKA/snort3:navl_reload_multithrea...
authorShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Fri, 28 Feb 2020 21:18:07 +0000 (21:18 +0000)
committerShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Fri, 28 Feb 2020 21:18:07 +0000 (21:18 +0000)
Squashed commit of the following:

commit 481482201b9e05af0fed08f8cec583c001e52f5b
Author: Sreeja Athirkandathil Narayanan <sathirka@cisco.com>
Date:   Thu Feb 13 14:14:58 2020 -0500

    appid: Support third-party reload when snort is running with  multiple packet threads

src/network_inspectors/appid/appid_inspector.cc
src/network_inspectors/appid/appid_module.cc

index 59252e68ec616230b5e610c54206349f68530b85..d7759375162dccb5f553c9d1c9e83e53d2b29a9e 100644 (file)
@@ -152,6 +152,10 @@ void AppIdInspector::tinit()
     LuaDetectorManager::initialize(*ctxt);
     AppIdServiceState::initialize(config->memcap);
     appidDebug = new AppIdDebug();
+    assert(!tp_appid_thread_ctxt);
+    tp_appid_thread_ctxt = ctxt->get_tp_appid_ctxt();
+    if (tp_appid_thread_ctxt)
+        tp_appid_thread_ctxt->tinit();
     if (ctxt->config.log_all_sessions)
         appidDebug->set_enabled(true);
 }
@@ -175,20 +179,6 @@ void AppIdInspector::eval(Packet* p)
     Profile profile(appid_perf_stats);
     appid_stats.packets++;
 
-    ThirdPartyAppIdContext* tp_appid_ctxt = ctxt->get_tp_appid_ctxt();
-    if (tp_appid_thread_ctxt != tp_appid_ctxt)
-    {
-        if (tp_appid_thread_ctxt)
-        {
-            tp_appid_thread_ctxt->tfini();
-
-            // FIXIT-H: Assuming one packet thread
-            delete tp_appid_thread_ctxt;
-        }
-        tp_appid_ctxt->tinit();
-        tp_appid_thread_ctxt = tp_appid_ctxt;
-    }
-
     if (p->flow)
     {
         AppIdDiscovery::do_application_discovery(p, *this, tp_appid_thread_ctxt);
index b3a304c70aaba3b3ac19e4442803dd3d7042a833..070a5275ee11c4b1d262819bffdba02e8ffd7966 100644 (file)
@@ -128,6 +128,38 @@ bool AcAppIdDebug::execute(Analyzer&, void**)
     return true;
 }
 
+class ACThirdPartyAppIdContextSwap : public AnalyzerCommand
+{
+public:
+    bool execute(Analyzer&, void**) override;
+    ACThirdPartyAppIdContextSwap(ThirdPartyAppIdContext* tp_ctxt): tp_ctxt(tp_ctxt) { }
+    ~ACThirdPartyAppIdContextSwap() override;
+    const char* stringify() override { return "THIRD-PARTY_CONTEXT_SWAP"; }
+private:
+    ThirdPartyAppIdContext* tp_ctxt =  nullptr;
+};
+
+bool ACThirdPartyAppIdContextSwap::execute(Analyzer&, void**)
+{
+    assert(tp_appid_thread_ctxt);
+    AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
+    ThirdPartyAppIdContext* tp_appid_ctxt = inspector->get_ctxt().get_tp_appid_ctxt();
+    assert(tp_appid_thread_ctxt != tp_appid_ctxt);
+    LogMessage("== swapping third-party configuration\n");
+    tp_appid_thread_ctxt->tfini();
+    tp_appid_ctxt->tinit();
+    tp_appid_thread_ctxt = tp_appid_ctxt;
+
+    return true;
+}
+
+ACThirdPartyAppIdContextSwap::~ACThirdPartyAppIdContextSwap()
+{
+    delete tp_ctxt;
+    Swapper::set_reload_in_progress(false);
+    LogMessage("== reload third-party complete\n");
+}
+
 static int enable_debug(lua_State* L)
 {
     int proto = luaL_optint(L, 1, 0);
@@ -177,20 +209,18 @@ static int reload_third_party(lua_State*)
         LogMessage("== reload pending; retry\n");
         return 0;
     }
-
-    if (ThreadConfig::get_instance_max() != 1)
-        LogMessage("Third-party reload not supported with more than one packet thread.");
-    else
+    Swapper::set_reload_in_progress(true);
+    LogMessage(".. reloading third-party\n");
+    AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
+    AppIdContext& ctxt = inspector->get_ctxt();
+    ThirdPartyAppIdContext* old_ctxt = ctxt.get_tp_appid_ctxt();
+    if (!old_ctxt)
     {
-        Swapper::set_reload_in_progress(true);
-        LogMessage(".. reloading third-party\n");
-        AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME, true);
-        AppIdContext& ctxt = inspector->get_ctxt();
-        ctxt.create_tp_appid_ctxt();
-        Swapper::set_reload_in_progress(false);
-        LogMessage("== reload third-party complete\n");
+        LogMessage("== reload third-party failed - third-party module doesn't exist\n");
+        return 0;
     }
-
+    ctxt.create_tp_appid_ctxt();
+    main_broadcast_command(new ACThirdPartyAppIdContextSwap(old_ctxt), true);
     return 0;
 }