From: Tom Peters (thopeter) Date: Fri, 22 Feb 2019 20:04:51 +0000 (-0500) Subject: Merge pull request #1519 in SNORT/snort3 from ~MDAGON/snort3:reload_completed to... X-Git-Tag: 3.0.0-251~38 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3622daa011b5a5a4f49d52fd19084cf5f2991594;p=thirdparty%2Fsnort3.git Merge pull request #1519 in SNORT/snort3 from ~MDAGON/snort3:reload_completed to master Squashed commit of the following: commit 50fb4edcab02ba6571435fbdaec5f029da9540ec Author: Maya Dagon Date: Thu Feb 7 13:55:29 2019 -0500 reload: send reload completed message to control channel instead of logging it --- diff --git a/src/main.cc b/src/main.cc index eeabd5c7a..222266e4b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -345,7 +345,7 @@ int main_reload_config(lua_State* L) bool from_shell = ( L != nullptr ); current_request->respond(".. swapping configuration\n", from_shell); - main_broadcast_command(new ACSwap(new Swapper(old, sc, old_tc, tc)), from_shell); + main_broadcast_command(new ACSwap(new Swapper(old, sc, old_tc, tc), current_request, from_shell), from_shell); return 0; } @@ -386,7 +386,7 @@ int main_reload_policy(lua_State* L) bool from_shell = ( L != nullptr ); current_request->respond(".. swapping policy\n", from_shell); - main_broadcast_command(new ACSwap(new Swapper(old, sc)), from_shell); + main_broadcast_command(new ACSwap(new Swapper(old, sc), current_request, from_shell), from_shell); return 0; } @@ -427,7 +427,7 @@ int main_reload_module(lua_State* L) bool from_shell = ( L != nullptr ); current_request->respond(".. swapping module\n", from_shell); - main_broadcast_command(new ACSwap(new Swapper(old, sc)), from_shell); + main_broadcast_command(new ACSwap(new Swapper(old, sc), current_request, from_shell), from_shell); return 0; } @@ -474,7 +474,7 @@ int main_reload_hosts(lua_State* L) bool from_shell = ( L != nullptr ); current_request->respond(".. swapping hosts table\n", from_shell); - main_broadcast_command(new ACSwap(new Swapper(old, tc)), from_shell); + main_broadcast_command(new ACSwap(new Swapper(old, tc), current_request, from_shell), from_shell); return 0; } @@ -515,7 +515,7 @@ int main_delete_inspector(lua_State* L) bool from_shell = ( L != nullptr ); current_request->respond(".. deleted inspector\n", from_shell); - main_broadcast_command(new ACSwap(new Swapper(old, sc)), from_shell); + main_broadcast_command(new ACSwap(new Swapper(old, sc), current_request, from_shell), from_shell); return 0; } diff --git a/src/main/analyzer_command.cc b/src/main/analyzer_command.cc index a40d6048e..479f12283 100644 --- a/src/main/analyzer_command.cc +++ b/src/main/analyzer_command.cc @@ -30,6 +30,7 @@ #include "utils/stats.h" #include "analyzer.h" +#include "request.h" #include "snort.h" #include "snort_config.h" #include "swapper.h" @@ -82,7 +83,7 @@ ACGetStats::~ACGetStats() DropStats(); } -ACSwap::ACSwap(Swapper* ps) : ps(ps) +ACSwap::ACSwap(Swapper* ps, Request* req, bool from_shell) : ps(ps), request(req), from_shell(from_shell) { assert(Swapper::get_reload_in_progress() == false); Swapper::set_reload_in_progress(true); @@ -99,6 +100,7 @@ ACSwap::~ACSwap() delete ps; Swapper::set_reload_in_progress(false); snort::LogMessage("== reload complete\n"); + request->respond("== reload complete\n", from_shell, true); } void ACDAQSwap::execute(Analyzer& analyzer) diff --git a/src/main/analyzer_command.h b/src/main/analyzer_command.h index a93ef21dc..79da9151e 100644 --- a/src/main/analyzer_command.h +++ b/src/main/analyzer_command.h @@ -23,6 +23,7 @@ #include "main/snort_types.h" class Analyzer; +class Request; class Swapper; class AnalyzerCommand @@ -98,12 +99,14 @@ class ACSwap : public AnalyzerCommand { public: ACSwap() = delete; - ACSwap(Swapper* ps); + ACSwap(Swapper* ps, Request* req, bool from_shell); void execute(Analyzer&) override; const char* stringify() override { return "SWAP"; } ~ACSwap() override; private: Swapper *ps; + Request* request; + bool from_shell; }; class ACDAQSwap : public AnalyzerCommand diff --git a/src/main/control_mgmt.cc b/src/main/control_mgmt.cc index dc17f4bd6..0386c8a39 100644 --- a/src/main/control_mgmt.cc +++ b/src/main/control_mgmt.cc @@ -299,5 +299,8 @@ ACShellCmd::~ACShellCmd() ControlConn* control = (control_fd >= 0)? (ControlMgmt::find_control(control_fd) ) : nullptr; if( control ) + { + control->send_queued_response(); control->unblock(); + } } diff --git a/src/main/request.cc b/src/main/request.cc index 8480dccba..5168204c2 100644 --- a/src/main/request.cc +++ b/src/main/request.cc @@ -84,11 +84,15 @@ bool Request::write_response(const char* s) const // FIXIT-L supporting only simple strings for now // could support var args formats -void Request::respond(const char* s, bool queue_response) +void Request::respond(const char* s, bool queue_response, bool remote_only) { + if (remote_only && (fd == STDOUT_FILENO)) + return; + if ( fd < 1 ) { - snort::LogMessage("%s", s); + if (!remote_only) + snort::LogMessage("%s", s); return; } diff --git a/src/main/request.h b/src/main/request.h index c4c56c42a..1d83f1e09 100644 --- a/src/main/request.h +++ b/src/main/request.h @@ -32,7 +32,7 @@ public: bool read(int&); const char* get() { return read_buf; } bool write_response(const char* s) const; - void respond(const char* s, bool queue_response = false); + void respond(const char* s, bool queue_response = false, bool remote_only = false); #ifdef SHELL void send_queued_response(); #endif