ConfigLogger::log_flag("log_all_sessions", log_all_sessions);
ConfigLogger::log_flag("log_stats", log_stats);
ConfigLogger::log_value("memcap", memcap);
+
+ ConfigLogger::log_flag("load_odp_detectors_in_ctrl", load_odp_detectors_in_ctrl);
}
void AppIdContext::pterm()
{
odp_ctxt->get_client_disco_mgr().initialize();
odp_ctxt->get_service_disco_mgr().initialize();
- LuaDetectorManager::initialize(*this, 1);
+ LuaDetectorManager::initialize(*this, 1, config.load_odp_detectors_in_ctrl);
odp_ctxt->initialize();
// do not reload third party on reload_config()
size_t memcap = 0;
bool list_odp_detectors = false;
bool log_all_sessions = false;
+ bool load_odp_detectors_in_ctrl = false;
SnortProtocolId snortId_for_unsynchronized;
SnortProtocolId snortId_for_ftp_data;
SnortProtocolId snortId_for_http2;
appid_mute = PacketTracer::get_mute();
AppIdStatistics::initialize_manager(*config);
- LuaDetectorManager::initialize(*ctxt);
+
+ if (ctxt->config.load_odp_detectors_in_ctrl)
+ LuaDetectorManager::init_thread_manager(*ctxt);
+ else
+ LuaDetectorManager::initialize(*ctxt);
+
AppIdServiceState::initialize(config->memcap);
assert(!tp_appid_thread_ctxt);
tp_appid_thread_ctxt = ctxt->get_tp_appid_ctxt();
{
//FIXIT-M: RELOAD - if app_info_table is associated with an object
appid_forecast_pterm();
- LuaDetectorManager::terminate();
+ LuaDetectorManager::terminate(true);
AppIdContext::pterm();
//end of 'FIXIT-M: RELOAD' comment above
openssl_cleanup();
"print third party configuration on startup" },
{ "log_all_sessions", Parameter::PT_BOOL, nullptr, "false",
"enable logging of all appid sessions" },
+ { "load_odp_detectors_in_ctrl", Parameter::PT_BOOL, nullptr, "false",
+ "load odp detectors in control thread" },
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
config->list_odp_detectors = v.get_bool();
else if ( v.is("log_all_sessions") )
config->log_all_sessions = v.get_bool();
+ else if ( v.is("load_odp_detectors_in_ctrl") )
+ config->load_odp_detectors_in_ctrl = v.get_bool();
return true;
}
THREAD_LOCAL LuaDetectorManager* lua_detector_mgr = nullptr;
static THREAD_LOCAL SF_LIST allocated_detector_flow_list;
+static std::vector<LuaDetectorManager*> lua_detector_mgr_list;
bool get_lua_field(lua_State* L, int table, const char* field, std::string& out)
{
LuaDetectorManager::~LuaDetectorManager()
{
- auto L = lua_detector_mgr? lua_detector_mgr->L : nullptr;
+ auto L = this->L;
if (L)
{
if (init(L))
cb_detectors.clear(); // do not free Lua objects in cb_detectors
}
-void LuaDetectorManager::initialize(AppIdContext& ctxt, int is_control)
+void LuaDetectorManager::initialize(AppIdContext& ctxt, int is_control, bool reload)
{
// FIXIT-M: RELOAD - When reload is supported, remove this line which prevents re-initialize
if (lua_detector_mgr)
if (ctxt.config.list_odp_detectors)
lua_detector_mgr->list_lua_detectors();
+
+ if (reload)
+ {
+ LogMessage("AppId Lua-Detectors : loading lua detectors in control thread\n");
+ unsigned max_threads = ThreadConfig::get_instance_max();
+ for (unsigned i = 0 ; i < max_threads; i++)
+ {
+ lua_detector_mgr_list.emplace_back(new LuaDetectorManager(ctxt, 0));
+
+ if (!lua_detector_mgr_list[i]->L)
+ FatalError("Error - appid: can not create new luaState, instance=%u\n", i);
+
+ lua_detector_mgr_list[i]->initialize_lua_detectors();
+ }
+ }
+}
+
+void LuaDetectorManager::init_thread_manager(const AppIdContext& ctxt)
+{
+ lua_detector_mgr = lua_detector_mgr_list[get_instance_id()];
+ lua_detector_mgr->activate_lua_detectors();
+ if (ctxt.config.list_odp_detectors)
+ lua_detector_mgr->list_lua_detectors();
}
-void LuaDetectorManager::terminate()
+void LuaDetectorManager::terminate(bool is_control)
{
+ unsigned size = lua_detector_mgr_list.size();
+ if (size and !is_control)
+ return;
+
if (!lua_detector_mgr)
return;
delete lua_detector_mgr;
lua_detector_mgr = nullptr;
+
+ if (size)
+ {
+ for (unsigned i = 0; i < size; i++)
+ delete lua_detector_mgr_list[i];
+ lua_detector_mgr_list.clear();
+ }
}
void LuaDetectorManager::add_detector_flow(DetectorFlow* df)
#include <lua/lua.h>
#include "main/thread.h"
+#include "main/thread_config.h"
#include "protocols/protocol_ids.h"
#include "application_ids.h"
public:
LuaDetectorManager(AppIdContext&, int);
~LuaDetectorManager();
- static void initialize(AppIdContext&, int is_control=0);
- static void terminate();
+ static void initialize(AppIdContext&, int is_control=0, bool reload=false);
+ static void init_thread_manager(const AppIdContext&);
+ static void terminate(bool is_control=false);
static void add_detector_flow(DetectorFlow*);
static void free_detector_flows();
// FIXIT-M: RELOAD - When reload is supported, move this variable to a separate location