From: Shravan Rangarajuvenkata (shrarang) Date: Tue, 16 Jun 2020 18:21:34 +0000 (+0000) Subject: Merge pull request #2255 in SNORT/snort3 from ~KAMURTHI/snort3:reload_3rd_resp to... X-Git-Tag: 3.0.1-5~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=335e85ca32aa168828238bff75e7fe2962f3f98d;p=thirdparty%2Fsnort3.git Merge pull request #2255 in SNORT/snort3 from ~KAMURTHI/snort3:reload_3rd_resp to master Squashed commit of the following: commit 56e9ed1693d8cff155e18118be8f056f9145e0df Author: Kanimozhi Murthi Date: Tue Jun 9 12:54:56 2020 -0400 appid:Add response message to reload_third_party --- diff --git a/src/main.cc b/src/main.cc index 43d284409..6726f02f7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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 //------------------------------------------------------------------------- diff --git a/src/main.h b/src/main.h index e01d556d9..d23e158cd 100644 --- a/src/main.h +++ b/src/main.h @@ -21,9 +21,12 @@ #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); diff --git a/src/network_inspectors/appid/appid_module.cc b/src/network_inspectors/appid/appid_module.cc index 81699528d..2c1585f6e 100644 --- a/src/network_inspectors/appid/appid_module.cc +++ b/src/network_inspectors/appid/appid_module.cc @@ -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; }