#ifdef DEBUG_MSGS
unsigned ac_ref_count = ac->get();
trace_logf(snort, "[%u] Queuing command %s for execution (refcount %u)\n",
- idx, ac->stringify(), ac_ref_count);
+ idx, ac->stringify(), ac_ref_count);
#else
ac->get();
#endif
if (ac_ref_count == 0)
{
trace_logf(snort, "[%u] Destroying completed command %s\n",
- idx, ac->stringify());
+ idx, ac->stringify());
delete ac;
}
#ifdef DEBUG_MSGS
else
trace_logf(snort, "[%u] Reaped ongoing command %s (refcount %u)\n",
- idx, ac->stringify(), ac_ref_count);
+ idx, ac->stringify(), ac_ref_count);
#endif
}
void snort::main_broadcast_command(AnalyzerCommand* ac, bool from_shell)
{
unsigned dispatched = 0;
-
+
ac = get_command(ac, from_shell);
trace_logf(snort, "Broadcasting %s command\n", ac->stringify());
int main_resume(lua_State* L)
{
- bool from_shell = ( L != nullptr );
+ const bool from_shell = ( L != nullptr );
+
+ int pkt_num = 0;
+ if (from_shell)
+ {
+ const int num_of_args = lua_gettop(L);
+ if (num_of_args)
+ {
+ pkt_num = lua_tonumber(L, 1);
+ if (pkt_num < 1)
+ {
+ current_request->respond("Invalid usage of resume(n), n should be a number > 0\n");
+ return 0;
+ }
+ }
+ }
current_request->respond("== resuming\n", from_shell);
- main_broadcast_command(new ACResume(), from_shell);
+ main_broadcast_command(new ACResume(pkt_num), from_shell);
paused = false;
return 0;
}
PluginManager::dump_plugins();
return 0;
}
+
#endif
int main_quit(lua_State* L)
// The main analyzer loop is terminated by a command returning false or an error during acquire
while (!exit_requested)
{
- if ( Snort::get_pause())
+ TestPause& s_pause = Snort::get_test_pause();
+ if (s_pause.get_pause())
{
pause();
- Snort::clear_pause();
+ s_pause.clear_pause();
+ s_pause.set_pause_cnt(0);
snort::LogMessage("== paused\n");
}
if (handle_command())
get_state_string());
}
-void Analyzer::resume()
+void Analyzer::resume(int pkt_cnt)
{
if (state == State::PAUSED)
+ {
+ TestPause& s_pause = Snort::get_test_pause();
+ s_pause.set_pause_cnt(pkt_cnt);
set_state(State::RUNNING);
+ }
else
ErrorMessage("Analyzer: Received RESUME command while in state %s\n",
get_state_string());
void run(bool paused = false);
void stop();
void pause();
- void resume();
+ void resume(int pkt_cnt);
void reload_daq();
private:
void ACResume::execute(Analyzer& analyzer)
{
- analyzer.resume();
+ analyzer.resume(pkt_count);
}
void ACRotate::execute(Analyzer&)
class ACResume : public AnalyzerCommand
{
public:
+ ACResume(int n): pkt_count(n){}
void execute(Analyzer&) override;
const char* stringify() override { return "RESUME"; }
+private:
+ int pkt_count;
};
class ACRotate : public AnalyzerCommand
ContextSwitcher* Snort::get_switcher()
{ return s_switcher; }
+// Test util - used for pause-after-n and resume(n)
+static THREAD_LOCAL TestPause s_pause;
+
+TestPause& Snort::get_test_pause()
+{ return s_pause; }
+
+void TestPause::set_pause_cnt(int cnt)
+{ pause_cnt = cnt ? (cnt + pc.total_from_daq) : 0; }
+
//-------------------------------------------------------------------------
// perf stats
// FIXIT-M move these to appropriate modules
pcap, SFDAQ::get_snap_len());
}
+
//-------------------------------------------------------------------------
// initialization
//-------------------------------------------------------------------------
bool Snort::initializing = true;
bool Snort::reloading = false;
bool Snort::privileges_dropped = false;
-bool Snort::pause = false;
-bool Snort::was_paused = false;
bool Snort::is_starting()
{ return initializing; }
if ( SnortConfig::get_conf()->pkt_cnt && pc.total_from_daq >= SnortConfig::get_conf()->pkt_cnt )
SFDAQ::break_loop(-1);
-#ifdef REG_TEST
- else if ( SnortConfig::get_conf()->pkt_pause_cnt && !was_paused &&
- pc.total_from_daq >= SnortConfig::get_conf()->pkt_pause_cnt )
+
+ // Check for resume(n)
+ else if ((s_pause.pause_cnt && pc.total_from_daq >= s_pause.pause_cnt)
+#ifdef REG_TEST // pause-after-n
+ || ( SnortConfig::get_conf()->pkt_pause_cnt && !s_pause.was_paused &&
+ pc.total_from_daq >= SnortConfig::get_conf()->pkt_pause_cnt )
+#endif
+ )
{
SFDAQ::break_loop(0);
- was_paused = pause = true;
- }
-#endif
+ s_pause.was_paused = s_pause.pause = true;
+ }
else if ( break_time() )
SFDAQ::break_loop(0);
typedef void (* MainHook_f)(Packet*);
+class TestPause
+{
+public:
+ bool get_pause() { return pause; }
+ void clear_pause() { pause = false; }
+ void set_pause_cnt(int cnt);
+
+public:
+ bool pause = false;
+ bool was_paused = false;
+ uint64_t pause_cnt = 0;
+};
+
class Snort
{
public:
static ContextSwitcher* get_switcher();
SO_PUBLIC static Packet* get_packet();
-
- static bool get_pause() { return pause; }
- static void clear_pause() { pause = false; }
+ static TestPause& get_test_pause();
private:
static void init(int, char**);
static bool initializing;
static bool reloading;
static bool privileges_dropped;
- static bool pause;
- static bool was_paused;
};
+
}
#endif
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
+static const Parameter s_pktnum[] =
+{
+ { "pkt_num", Parameter::PT_INT, "1:", nullptr,
+ "resume and pause after pkt_num packets" },
+
+ { nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
+};
+
static const Command snort_cmds[] =
{
{ "show_plugins", main_dump_plugins, nullptr, "show available plugins" },
//{ "process", main_process, nullptr, "process given pcap" },
{ "pause", main_pause, nullptr, "suspend packet processing" },
- { "resume", main_resume, nullptr, "continue packet processing" },
+ { "resume", main_resume, s_pktnum, "continue packet processing. "
+ "If number of packet is specified, will resume for n packets and pause" },
{ "detach", main_detach, nullptr, "exit shell w/o shutdown" },
{ "quit", main_quit, nullptr, "shutdown and dump-stats" },
{ "help", main_help, nullptr, "this output" },
#ifdef REG_TEST
{ "--pause-after-n", Parameter::PT_INT, "1:", nullptr,
- "<count> pause after count packets, to be used with single packet thread only", },
+ "<count> pause after count packets", },
#endif
{ "--parsing-follows-files", Parameter::PT_IMPLIED, nullptr, nullptr,