]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #1519 in SNORT/snort3 from ~MDAGON/snort3:reload_completed to...
authorTom Peters (thopeter) <thopeter@cisco.com>
Fri, 22 Feb 2019 20:04:51 +0000 (15:04 -0500)
committerTom Peters (thopeter) <thopeter@cisco.com>
Fri, 22 Feb 2019 20:04:51 +0000 (15:04 -0500)
Squashed commit of the following:

commit 50fb4edcab02ba6571435fbdaec5f029da9540ec
Author: Maya Dagon <mdagon@cisco.com>
Date:   Thu Feb 7 13:55:29 2019 -0500

    reload: send reload completed message to control channel instead of logging it

src/main.cc
src/main/analyzer_command.cc
src/main/analyzer_command.h
src/main/control_mgmt.cc
src/main/request.cc
src/main/request.h

index eeabd5c7a9fbc03e7f5bcd9e4d47d24cd5fa6104..222266e4b592acccc3281ac65f96473ee730aa0a 100644 (file)
@@ -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;
 }
index a40d6048e1c22ae8bb3fe54c0ed3eebb5eaee9a7..479f1228362d3f3d5f7498ecbdce8eb362640a3d 100644 (file)
@@ -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)
index a93ef21dc3199b32e824b17eb5a5d7e5277c629a..79da9151e2da058d022cb2d36745355d0f79db58 100644 (file)
@@ -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
index dc17f4bd64b124b9fab9707bf7200bb40d3b0ada..0386c8a393f6046185e88cbf148831a9491f6798 100644 (file)
@@ -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();
+    }
 }
index 8480dccba1bd4a0f2e3fad090153ea380396eea7..5168204c20d781ad38fdddf1507aef09cb4a1137 100644 (file)
@@ -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;
     }
 
index c4c56c42ae1c747fab03ff0556309f83e45f63d5..1d83f1e09ae00a2cd8c2d0e5121f17a9a6701415 100644 (file)
@@ -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