From: Shravan Rangarajuvenkata (shrarang) Date: Wed, 5 Aug 2020 19:24:58 +0000 (+0000) Subject: Merge pull request #2371 in SNORT/snort3 from ~SATHIRKA/snort3:odp_reload_dynamic_cac... X-Git-Tag: 3.0.2-4~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cda1e621b9d6d4918f9380d8f4b1ac806b7bc5ef;p=thirdparty%2Fsnort3.git Merge pull request #2371 in SNORT/snort3 from ~SATHIRKA/snort3:odp_reload_dynamic_cache to master Squashed commit of the following: commit c8fd1962f309aaa6fae49b0b437404e04adb0e8a Author: Sreeja Athirkandathil Narayanan Date: Mon Aug 3 15:25:33 2020 -0400 appid: Clear service appid entries in dynamic host cache on ODP reload --- diff --git a/src/host_tracker/host_tracker.cc b/src/host_tracker/host_tracker.cc index 496c12832..2b15ff49b 100644 --- a/src/host_tracker/host_tracker.cc +++ b/src/host_tracker/host_tracker.cc @@ -121,6 +121,18 @@ AppId HostTracker::get_appid(Port port, IpProtocol proto, bool inferred_only, bo return APP_ID_NONE; } +void HostTracker::remove_inferred_services() +{ + std::lock_guard lck(host_tracker_lock); + for ( auto s = services.begin(); s != services.end(); ) + { + if (s->inferred_appid) + s = services.erase(s); + else + s++; + } +} + static inline string to_time_string(uint32_t p_time) { time_t raw_time = (time_t) p_time; diff --git a/src/host_tracker/host_tracker.h b/src/host_tracker/host_tracker.h index a7e0965c6..639481e34 100644 --- a/src/host_tracker/host_tracker.h +++ b/src/host_tracker/host_tracker.h @@ -110,6 +110,8 @@ public: AppId get_appid(Port port, IpProtocol proto, bool inferred_only = false, bool allow_port_wildcard = false); + void remove_inferred_services(); + // This should be updated whenever HostTracker data members are changed void stringify(std::string& str); diff --git a/src/network_inspectors/appid/appid_module.cc b/src/network_inspectors/appid/appid_module.cc index 20ebe58bf..e7c523a88 100644 --- a/src/network_inspectors/appid/appid_module.cc +++ b/src/network_inspectors/appid/appid_module.cc @@ -28,6 +28,7 @@ #include #include +#include "host_tracker/host_cache.h" #include "log/messages.h" #include "main/analyzer_command.h" #include "main/snort.h" @@ -283,6 +284,15 @@ static int reload_third_party(lua_State* L) return 0; } +static void clear_dynamic_host_cache_services() +{ + auto hosts = host_cache.get_all_data(); + for ( auto& h : hosts ) + { + h.second->remove_inferred_services(); + } +} + static int reload_odp(lua_State* L) { bool from_shell = ( L != nullptr ); @@ -303,6 +313,7 @@ static int reload_odp(lua_State* L) AppIdContext& ctxt = inspector->get_ctxt(); OdpContext& old_odp_ctxt = ctxt.get_odp_ctxt(); + clear_dynamic_host_cache_services(); AppIdPegCounts::cleanup_peg_info(); LuaDetectorManager::clear_lua_detector_mgrs(); ctxt.create_odp_ctxt();