]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2255 in SNORT/snort3 from ~KAMURTHI/snort3:reload_3rd_resp to...
authorShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Tue, 16 Jun 2020 18:21:34 +0000 (18:21 +0000)
committerShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Tue, 16 Jun 2020 18:21:34 +0000 (18:21 +0000)
Squashed commit of the following:

commit 56e9ed1693d8cff155e18118be8f056f9145e0df
Author: Kanimozhi Murthi <kamurthi@cisco.com>
Date:   Tue Jun 9 12:54:56 2020 -0400

    appid:Add response message to reload_third_party

src/main.cc
src/main.h
src/network_inspectors/appid/appid_module.cc

index 43d284409a055030b45d24a72c59d33948ef4dfb..6726f02f7fb03a7ef644752beae8cd50b0157876 100644 (file)
@@ -87,7 +87,6 @@ static const char* prompt = "o\")~ ";
 
 const char* get_prompt()
 { return prompt; }
-
 static bool use_shell(const SnortConfig* sc)
 {
 #ifdef SHELL
@@ -117,6 +116,11 @@ static Request* current_request = &request;
 static int current_fd = -1;
 #endif
 
+Request& get_current_request()
+{
+    return *current_request;
+}
+
 //-------------------------------------------------------------------------
 // pig foo
 //-------------------------------------------------------------------------
index e01d556d993490163838a116d72454f3c08f9b40..d23e158cdebeb9ab640ef77f879d41dbb3c210a3 100644 (file)
 #ifndef MAIN_H
 #define MAIN_H
 
+#include "main/request.h"
+
 struct lua_State;
 
 const char* get_prompt();
+Request& get_current_request();
 
 // commands provided by the snort module
 int main_delete_inspector(lua_State* = nullptr);
index 81699528d287761f9ae40cc433a5dc771a692f96..2c1585f6eb2a41694f5c5467a37bb54225f1d91b 100644 (file)
@@ -35,6 +35,7 @@
 #include "main/thread_config.h"
 #include "managers/inspector_manager.h"
 #include "profiler/profiler.h"
+#include "src/main.h"
 #include "trace/trace.h"
 #include "utils/util.h"
 
@@ -127,11 +128,15 @@ class ACThirdPartyAppIdContextSwap : public AnalyzerCommand
 {
 public:
     bool execute(Analyzer&, void**) override;
-    ACThirdPartyAppIdContextSwap(ThirdPartyAppIdContext* tp_ctxt): tp_ctxt(tp_ctxt) { }
+    ACThirdPartyAppIdContextSwap(ThirdPartyAppIdContext* tp_ctxt, Request& current_request,
+        bool from_shell): tp_ctxt(tp_ctxt),request(current_request),
+        from_shell(from_shell) { }
     ~ACThirdPartyAppIdContextSwap() override;
     const char* stringify() override { return "THIRD-PARTY_CONTEXT_SWAP"; }
 private:
     ThirdPartyAppIdContext* tp_ctxt =  nullptr;
+    Request& request;
+    bool from_shell;
 };
 
 bool ACThirdPartyAppIdContextSwap::execute(Analyzer&, void**)
@@ -141,7 +146,7 @@ bool ACThirdPartyAppIdContextSwap::execute(Analyzer&, void**)
     assert(inspector);
     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");
+    request.respond("== swapping third-party configuration\n", from_shell);
     tp_appid_thread_ctxt->tfini();
     tp_appid_ctxt->tinit();
     tp_appid_thread_ctxt = tp_appid_ctxt;
@@ -154,6 +159,7 @@ ACThirdPartyAppIdContextSwap::~ACThirdPartyAppIdContextSwap()
     delete tp_ctxt;
     Swapper::set_reload_in_progress(false);
     LogMessage("== reload third-party complete\n");
+    request.respond("== reload third-party complete\n", from_shell, true);
 }
 
 static int enable_debug(lua_State* L)
@@ -198,30 +204,32 @@ static int disable_debug(lua_State*)
     return 0;
 }
 
-static int reload_third_party(lua_State*)
+static int reload_third_party(lua_State* L)
 {
+    bool from_shell = ( L != nullptr );
+    Request& current_request = get_current_request();
     if (Swapper::get_reload_in_progress())
     {
-        LogMessage("== reload pending; retry\n");
+        current_request.respond("== reload pending; retry\n", from_shell);
         return 0;
     }
     Swapper::set_reload_in_progress(true);
-    LogMessage(".. reloading third-party\n");
+    current_request.respond(".. reloading third-party\n", from_shell);
     AppIdInspector* inspector = (AppIdInspector*) InspectorManager::get_inspector(MOD_NAME);
     if (!inspector)
     {
-        LogMessage("== reload third-party failed - appid not enabled\n");
+        current_request.respond("== reload third-party failed - appid not enabled\n", from_shell);
         return 0;
     }
     AppIdContext& ctxt = inspector->get_ctxt();
     ThirdPartyAppIdContext* old_ctxt = ctxt.get_tp_appid_ctxt();
     if (!old_ctxt)
     {
-        LogMessage("== reload third-party failed - third-party module doesn't exist\n");
+        current_request.respond("== reload third-party failed - third-party module doesn't exist\n", from_shell);
         return 0;
     }
     ctxt.create_tp_appid_ctxt();
-    main_broadcast_command(new ACThirdPartyAppIdContextSwap(old_ctxt), true);
+    main_broadcast_command(new ACThirdPartyAppIdContextSwap(old_ctxt, current_request, from_shell), from_shell);
     return 0;
 }