From: Russ Combs Date: Mon, 6 Oct 2014 12:25:56 +0000 (-0400) Subject: fixed pause/resume X-Git-Tag: 3.0.0-233~1397^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7573eaa200c76d1ead85058ebb25ca455061c353;p=thirdparty%2Fsnort3.git fixed pause/resume --- diff --git a/ChangeLog b/ChangeLog index 267392feb..e5f597bda 100644 --- 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 diff --git a/src/main.cc b/src/main.cc index 9365e6081..292d97300 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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; diff --git a/src/main.h b/src/main.h index de98f191e..0062779a8 100644 --- a/src/main.h +++ b/src/main.h @@ -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); diff --git a/src/main/analyzer.cc b/src/main/analyzer.cc index 2ecc8c8e1..046fdad02 100644 --- a/src/main/analyzer.cc +++ b/src/main/analyzer.cc @@ -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(); } } diff --git a/src/main/snort.cc b/src/main/snort.cc index f5966320e..2887634ad 100644 --- a/src/main/snort.cc +++ b/src/main/snort.cc @@ -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(); } diff --git a/src/main/snort.h b/src/main/snort.h index 901eb85a1..790e10795 100644 --- a/src/main/snort.h +++ b/src/main/snort.h @@ -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*); diff --git a/src/managers/module_manager.cc b/src/managers/module_manager.cc index db798be59..413806310 100644 --- a/src/managers/module_manager.cc +++ b/src/managers/module_manager.cc @@ -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); }