Merge in SNORT/snort3 from ~OSTEPANO/snort3:chp_heap_fix to master
Squashed commit of the following:
commit
4a19f21de3a022a1b88234f6def378a7a8e0941a
Author: Oleksandr Stepanov <ostepano@cisco.com>
Date: Thu Jul 6 05:59:00 2023 -0400
appid: cache CHP glossary before detectors reload
odp_ctxt.get_app_info_mgr().cleanup_appid_info_table();
delete &odp_ctxt;
AppIdContext& ctxt = inspector.get_ctxt();
+ LuaDetectorManager::cleanup_after_swap();
if (ctxt.config.app_detector_dir)
{
std::string file_path = std::string(ctxt.config.app_detector_dir) + "/custom/userappid.conf";
LuaDetectorManager::clear_lua_detector_mgrs();
ctxt.create_odp_ctxt();
assert(odp_thread_local_ctxt);
+ odp_thread_local_ctxt->get_lua_detector_mgr().set_ignore_chp_cleanup(true);
delete odp_thread_local_ctxt;
odp_thread_local_ctxt = new OdpThreadContext;
LUA_LOG_TRACE = 5,
};
-static std::unordered_map<AppId, CHPApp*>* CHP_glossary = nullptr; // tracks http multipatterns
+static CHPGlossary* CHP_glossary = nullptr; // tracks http multipatterns
+static CHPGlossary* old_CHP_glossary = nullptr;
void init_chp_glossary()
{
- CHP_glossary = new std::unordered_map<AppId, CHPApp*>;
+ if(CHP_glossary)
+ old_CHP_glossary = CHP_glossary;
+ CHP_glossary = new CHPGlossary;
}
-void free_chp_glossary()
+static void free_chp_glossary(CHPGlossary*& glossary)
{
- if (!CHP_glossary)
+
+ if (!glossary)
return;
- for (auto& entry : *CHP_glossary)
+ for (auto& entry : *glossary)
{
if (entry.second)
snort_free(entry.second);
}
- delete CHP_glossary;
- CHP_glossary = nullptr;
+ delete glossary;
+ glossary = nullptr;
+}
+
+void free_current_chp_glossary(){
+ free_chp_glossary(CHP_glossary);
+}
+
+void free_old_chp_glossary()
+{
+ free_chp_glossary(old_CHP_glossary);
}
static inline int convert_string_to_address(const char* string, SfIp* address)
{ return cd; }
};
+typedef std::unordered_map<AppId, CHPApp*> CHPGlossary;
+
int register_detector(lua_State*);
void init_chp_glossary();
int init(lua_State*, int result=0);
-void free_chp_glossary();
+void free_current_chp_glossary();
+void free_old_chp_glossary();
void check_detector_callback(const snort::Packet& p, AppIdSession& asd, AppidSessionDirection dir,
AppId app_id, AppidChangeBits& change_bits, AppInfoTableEntry* entry = nullptr);
if (L)
{
- if (init(L))
- free_chp_glossary();
+ if (init(L) and !ignore_chp_cleanup)
+ free_current_chp_glossary();
for ( auto& lua_object : allocated_objects )
{
lua_detector_mgr->list_lua_detectors();
}
+void LuaDetectorManager::cleanup_after_swap()
+{
+ free_old_chp_glossary();
+}
+
void LuaDetectorManager::clear_lua_detector_mgrs()
{
lua_detector_mgr_list.clear();
static void initialize(const snort::SnortConfig*, AppIdContext&, bool is_control=false,
bool reload=false);
static void init_thread_manager(const snort::SnortConfig*, const AppIdContext&);
+ static void cleanup_after_swap();
static void clear_lua_detector_mgrs();
void set_detector_flow(DetectorFlow* df)
{
return detector_flow;
}
+
+ void set_ignore_chp_cleanup(bool value)
+ {
+ ignore_chp_cleanup = value;
+ }
+
void free_detector_flow();
lua_State* L;
bool insert_cb_detector(AppId app_id, LuaObject* ud);
size_t num_odp_detectors = 0;
std::map<AppId, LuaObject*> cb_detectors;
DetectorFlow* detector_flow = nullptr;
+ bool ignore_chp_cleanup = false;
};
#endif