install(FILES ${RNA_INCLUDES}
DESTINATION "${INCLUDE_INSTALL_PATH}/network_inspectors/rna"
-)
\ No newline at end of file
+)
+
+add_subdirectory(test)
#include "log/messages.h"
#include "main/snort_config.h"
+#include "main/swapper.h"
+#include "managers/inspector_manager.h"
+#include "src/main.h"
#ifdef UNIT_TEST
#include "catch/snort_catch.h"
using namespace snort;
//-------------------------------------------------------------------------
-// rna params and pegs
+// rna commands, params, and pegs
//-------------------------------------------------------------------------
+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 const Command rna_cmds[] =
+{
+ { "reload_fingerprint", reload_fingerprint, nullptr,
+ "reload rna database of fingerprint patterns/signatures" },
+ { nullptr, nullptr, nullptr, nullptr }
+};
+
static const Parameter rna_params[] =
{
{ "rna_conf_path", Parameter::PT_STRING, nullptr, nullptr,
- "path to RNA configuration" },
+ "path to rna configuration" },
{ "rna_util_lib_path", Parameter::PT_STRING, nullptr, nullptr,
"path to library for utilities such as fingerprint decoder" },
return true;
}
+const Command* RnaModule::get_commands() const
+{
+ return rna_cmds;
+}
+
RnaModuleConfig* RnaModule::get_config()
{
RnaModuleConfig* tmp = mod_conf;
bool begin(const char*, int, snort::SnortConfig*) override;
bool set(const char*, snort::Value&, snort::SnortConfig*) override;
bool end(const char*, int, snort::SnortConfig*) override;
+
+ const snort::Command* get_commands() const override;
RnaModuleConfig* get_config();
PegCount* get_counts() const override;
const PegInfo* get_pegs() const override;
--- /dev/null
+add_cpputest( rna_module_test
+ SOURCES
+ ../../../framework/parameter.cc
+ $<TARGET_OBJECTS:catch_tests>
+ LIBS
+ ${DNET_LIBRARIES}
+)
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+
+// rna_module_mock.h author Masud Hasan <mashasan@cisco.com>
+
+#ifndef RNA_MODULE_MOCK_H
+#define RNA_MODULE_MOCK_H
+
+bool Swapper::reload_in_progress = false;
+THREAD_LOCAL RnaStats rna_stats;
+THREAD_LOCAL ProfileStats rna_perf_stats;
+static std::string message;
+static Request mock_request;
+
+void Request::respond(const char* msg, bool, bool)
+{
+ message = msg;
+}
+Request& get_current_request()
+{ return mock_request; }
+
+namespace snort
+{
+Inspector* InspectorManager::get_inspector(const char*, bool, const SnortConfig*)
+{ return nullptr; }
+Module::Module(const char*, const char*, const Parameter*, bool) {}
+void Module::sum_stats(bool) {}
+void Module::show_stats() {}
+void Module::reset_stats() {}
+PegCount Module::get_global_count(char const*) const
+{ return 0; }
+void Module::show_interval_stats(std::vector<unsigned int, std::allocator<unsigned int> >&, FILE*)
+{}
+void LogMessage(const char*,...) {}
+void WarningMessage(const char*,...) {}
+SnortConfig::SnortConfig(SnortConfig const*) {}
+SnortConfig::~SnortConfig() {}
+} // end of namespace snort
+
+#endif
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+
+// rna_module_test.cc author Masud Hasan <mashasan@cisco.com>
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "../rna_module.cc"
+
+#include "rna_module_mock.h"
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+
+TEST_GROUP(rna_module_test)
+{
+ void setup() override
+ {
+ MemoryLeakWarningPlugin::turnOffNewDeleteOverloads();
+ }
+ void teardown() override
+ {
+ MemoryLeakWarningPlugin::turnOnNewDeleteOverloads();
+ }
+};
+
+TEST(rna_module_test, reload_fingerprint)
+{
+ // When another reload is pending
+ Swapper::set_reload_in_progress(true);
+ reload_fingerprint(nullptr);
+ Swapper::set_reload_in_progress(false);
+ CHECK_TRUE(message == "== reload pending; retry\n");
+
+ // When rna is not configured
+ reload_fingerprint(nullptr);
+ CHECK_TRUE(message == "== reload fingerprint failed - rna not enabled\n");
+
+ // Reload in progress flag should remain unset at the end
+ CHECK_FALSE(Swapper::get_reload_in_progress());
+}
+
+int main(int argc, char** argv)
+{
+ return CommandLineTestRunner::RunAllTests(argc, argv);
+}