snort_config.h
snort_debug.h
snort_types.h
+ swapper.h
thread.h
thread_config.h
)
snort_module.h
snort_module.cc
swapper.cc
- swapper.h
thread.cc
thread_config.h
thread_config.cc
// used to make thread local, pointer-based config swaps by packet threads
+#include "main/snort_types.h"
+
namespace snort
{
struct SnortConfig;
class Analyzer;
-class Swapper
+class SO_PUBLIC Swapper
{
public:
Swapper(snort::SnortConfig*);
}
snort::TcpFpProcessor* get_tcp_fp_processor();
-void set_tcp_fp_processor(snort::TcpFpProcessor*);
+SO_PUBLIC void set_tcp_fp_processor(snort::TcpFpProcessor*);
struct FpFingerprintState
{
return nullptr;
}
+void RnaInspector::set_fp_processor(TcpFpProcessor* tfp)
+{
+ if ( mod_conf )
+ {
+ delete mod_conf->processor;
+ mod_conf->processor = tfp;
+ }
+}
//-------------------------------------------------------------------------
// api stuff
void tterm() override;
snort::TcpFpProcessor* get_or_create_fp_processor();
+ void set_fp_processor(snort::TcpFpProcessor* tfp);
private:
void load_rna_conf();
#include "log/messages.h"
#include "lua/lua.h"
#include "main/snort_config.h"
-#include "main/swapper.h"
-#include "managers/inspector_manager.h"
#include "managers/module_manager.h"
-#include "src/main.h"
#include "utils/util.h"
#include "rna_fingerprint_tcp.h"
return 0;
}
-static int reload_fingerprint(lua_State*)
-{
- // This should be initialized from lua parameter when the rest of this command is implemented
- bool from_shell = false;
-
- Request& current_request = get_current_request();
-
- if (Swapper::get_reload_in_progress())
- {
- current_request.respond("== reload pending; retry\n", from_shell);
- return 0;
- }
-
- if (!InspectorManager::get_inspector(RNA_NAME))
- {
- current_request.respond("== reload fingerprint failed - rna not enabled\n", from_shell);
- return 0;
- }
-
- // Check here if rna utility library and fingerprint database are present; fail if absent
-
- Swapper::set_reload_in_progress(true);
- current_request.respond(".. reloading fingerprint\n", from_shell);
-
- // Reinitialize here fingerprint database; broadcast command if it is in thread local context
-
- current_request.respond("== reload fingerprint complete\n", from_shell);
- Swapper::set_reload_in_progress(false);
- return 0;
-}
-
static inline string format_dump_mac(const uint8_t mac[MAC_SIZE])
{
stringstream ss;
static const Command rna_cmds[] =
{
- { "reload_fingerprint", reload_fingerprint, nullptr,
- "reload rna database of fingerprint patterns/signatures" },
{ "dump_macs", dump_mac_cache, nullptr,
"dump rna's internal MAC trackers" },
{ nullptr, nullptr, nullptr, nullptr }
#include "../rna_mac_cache.cc"
-bool Swapper::reload_in_progress = false;
THREAD_LOCAL RnaStats rna_stats;
THREAD_LOCAL ProfileStats rna_perf_stats;
-static Request mock_request;
const char* luaL_optlstring(lua_State*, int, const char*, size_t*) { return nullptr; }
-Request& get_current_request()
-{ return mock_request; }
-
namespace snort
{
-Inspector* InspectorManager::get_inspector(const char*, bool, const SnortConfig*)
-{ return nullptr; }
-
Module* ModuleManager::get_module(const char*)
{ return nullptr; }
#include <CppUTest/TestHarness.h>
#include <CppUTestExt/MockSupport.h>
-void Request::respond(const char* msg, bool, bool)
-{
- mock().actualCall("respond").onObject(this).withParameter("msg", msg);
-}
-
TEST_GROUP(rna_module_test)
{
};
-TEST(rna_module_test, reload_fingerprint)
-{
- // When another reload is pending
- mock().expectOneCall("respond").onObject(&mock_request).withParameter("msg", "== reload pending; retry\n");
- Swapper::set_reload_in_progress(true);
- reload_fingerprint(nullptr);
- Swapper::set_reload_in_progress(false);
- mock().checkExpectations();
-
- // When rna is not configured
- mock().expectOneCall("respond").onObject(&mock_request).withParameter("msg", "== reload fingerprint failed - rna not enabled\n");
- reload_fingerprint(nullptr);
- mock().checkExpectations();
-
- // Reload in progress flag should remain unset at the end
- CHECK_FALSE(Swapper::get_reload_in_progress());
-
- mock().clear();
-}
-
TEST(rna_module_test, push_tcp_fingerprints)
{
// In plain English, we test that the RNA module pushes tcp fingerprints