]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed pause/resume
authorRuss Combs <rucombs@cisco.com>
Mon, 6 Oct 2014 12:25:56 +0000 (08:25 -0400)
committerRuss Combs <rucombs@cisco.com>
Mon, 6 Oct 2014 12:25:56 +0000 (08:25 -0400)
ChangeLog
src/main.cc
src/main.h
src/main/analyzer.cc
src/main/snort.cc
src/main/snort.h
src/managers/module_manager.cc

index 267392febb38ddb038991bea44b1ac9bb3a968e4..e5f597bdafdc72155d5b4d2e85a4c6a9632e8f5e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,7 @@
 -- made some packet data available to alert_luajit
 -- fixed flow init when not bound
 -- tweaked stats output - no section if all counts zero
+-- fixed pause/resume
 
 122
 -- pulled thread pinning from Josh
index 9365e608178296f25bc59fda1bcfb36b2672adb4..292d9730062bfaa98eb99a10491a3b98796051c7 100644 (file)
@@ -73,10 +73,16 @@ static Swapper* swapper = NULL;
 static int exit_logged = 0;
 static bool paused = false;
 
+static bool pause_enabled = false;
+static bool shell_enabled = false;
+
 const struct timespec main_sleep = { 0, 100000000 }; // 0.1 sec
 
 static const char* prompt = "o\")~ ";
 
+const char* get_prompt()
+{ return prompt; }
+
 //-------------------------------------------------------------------------
 // swap foo
 //-------------------------------------------------------------------------
@@ -542,7 +548,7 @@ static bool service_users()
     FD_ZERO(&inputs);
     int max_fd = -1;
 
-    if ( snort_conf->run_flags & RUN_FLAG__SHELL )
+    if ( shell_enabled )
     {
         FD_SET(STDIN_FILENO, &inputs);
         max_fd = STDIN_FILENO;
@@ -653,7 +659,7 @@ static bool set_mode()
     if ( snort_conf->run_flags & RUN_FLAG__PAUSE )
     {
         LogMessage("Paused; resume to start packet processing\n");
-        paused = true;
+        paused = pause_enabled = true;
     }
     else
         LogMessage("Commencing packet processing\n");
@@ -661,6 +667,7 @@ static bool set_mode()
     if ( snort_conf->run_flags & RUN_FLAG__SHELL )
     {
         LogMessage("Entering command shell\n");
+        shell_enabled = true;
         request.set(STDOUT_FILENO, "");
         request.show_prompt();
     }
@@ -673,10 +680,10 @@ static inline bool dont_stop()
     if ( paused || Trough_Next() )
         return true;
 
-    if ( snort_conf->run_flags & RUN_FLAG__PAUSE )
+    if ( pause_enabled )
     {
         LogMessage("== pausing\n");
-        snort_conf->run_flags &= ~RUN_FLAG__PAUSE;
+        pause_enabled = false;
         paused = true;
         return true;
     }
@@ -688,7 +695,7 @@ static void main_loop()
     unsigned idx = max_pigs, swine = 0;
     init_main_thread_sig();
 
-    while ( !exit_logged && (dont_stop() || swine) )
+    while ( !exit_logged && (swine || dont_stop()) )
     {
         if ( ++idx >= max_pigs )
             idx = 0;
index de98f191e50f5880923a54fa5a81637b90f528e0..0062779a80ca06153440c70105ca147f5bdfeccd 100644 (file)
@@ -23,6 +23,8 @@
 
 struct lua_State;
 
+const char* get_prompt();
+
 int main_dump_plugins(lua_State* = nullptr);
 int main_dump_stats(lua_State* = nullptr);
 int main_rotate_stats(lua_State* = nullptr);
index 2ecc8c8e12c5ba3a74388d26a9bb192dd065cf30..046fdad028f768207d16bf068389eb5152cdc1a7 100644 (file)
@@ -99,7 +99,7 @@ bool Analyzer::handle(AnalyzerCommand ac)
         break;
 
     case AC_ROTATE:
-        snort_rotate();
+        snort_thread_rotate();
         command = AC_NONE;
         break;
 
@@ -138,7 +138,7 @@ void Analyzer::analyze()
         // conditions; that means the idle processing may not be useful
         // or that we need a hook to do things periodically even when
         // traffic is available
-        snort_idle();
+        snort_thread_idle();
     }
 }
 
index f5966320e527312ee7cb99ad440e9690c4464444..2887634ad0e96914cc154355613b020ec8338c5b 100644 (file)
@@ -77,6 +77,7 @@ using namespace std;
 #include "ips_options/ips_flowbits.h"
 #include "event_queue.h"
 #include "framework/mpse.h"
+#include "main.h"
 #include "main/build.h"
 #include "main/snort_config.h"
 #include "main/shell.h"
@@ -294,7 +295,7 @@ static void SnortInit(int argc, char **argv)
     snort_conf = snort_cmd_line_conf;
 
     LogMessage("--------------------------------------------------\n");
-    LogMessage("o\")~  Snort++ %s-%s\n", VERSION, BUILD);
+    LogMessage("%s  Snort++ %s-%s\n", get_prompt(), VERSION, BUILD);
     LogMessage("--------------------------------------------------\n");
 
     ModuleManager::init();
@@ -476,7 +477,7 @@ static void CleanExit(int)
     SnortCleanup();
     snort_conf = &tmp;
 
-    LogMessage("Snort exiting\n");
+    LogMessage("%s  Snort exiting\n", get_prompt());
     closelog();
 }
 
@@ -899,14 +900,14 @@ DAQ_Verdict packet_callback(
     return verdict;
 }
 
-void snort_idle()
+void snort_thread_idle()
 {
     if ( flow_con )
         flow_con->timeout_flows(16384, time(NULL));
     pc.idle++;
 }
 
-void snort_rotate()
+void snort_thread_rotate()
 {
     SetRotatePerfFileFlag();
 }
index 901eb85a1a98b9b997edc8eda5277452721967c5..790e107952bbdee1b9cc35040bdc93874a5289ec 100644 (file)
@@ -55,8 +55,8 @@ bool snort_is_starting();
 void snort_thread_init(const char* intf);
 void snort_thread_term();
 
-void snort_idle();
-void snort_rotate();
+void snort_thread_idle();
+void snort_thread_rotate();
 
 void CapturePacket();
 void DecodeRebuiltPacket (Packet*, const DAQ_PktHdr_t*, const uint8_t* pkt, Flow*);
index db798be59ac8c21828ccebde895df2026862e8ee..4138063103f9fa89463563394d9fdd9daab3b9e4 100644 (file)
@@ -413,6 +413,7 @@ SO_PUBLIC bool open_table(const char* s, int idx)
     if ( !h || (h->api && h->api->type == PT_IPS_OPTION) )
         return false;
 
+    //printf("open %s %d\n", s, idx);
     Module* m = h->mod;
 
     if (strcmp(m->get_name(), s))
@@ -458,6 +459,8 @@ SO_PUBLIC void close_table(const char* s, int idx)
     string key = fqn;
     set_top(key);
 
+    //printf("close %s %d\n", s, idx);
+
     if ( ModHook* h = get_hook(key.c_str()) )
     {
         if ( !h->mod->end(s, idx, s_config) )
@@ -475,18 +478,21 @@ SO_PUBLIC void close_table(const char* s, int idx)
 
 SO_PUBLIC bool set_bool(const char* fqn, bool b)
 {
+    //printf("bool %s %d\n", fqn, b);
     Value v(b);
     return set_value(fqn, v);
 }
 
 SO_PUBLIC bool set_number(const char* fqn, double d)
 {
+    //printf("real %s %f\n", fqn, d);
     Value v(d);
     return set_value(fqn, v);
 }
 
 SO_PUBLIC bool set_string(const char* fqn, const char* s)
 {
+    //printf("string %s %s\n", fqn, s);
     Value v(s);
     return set_value(fqn, v);
 }