]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2371 in SNORT/snort3 from ~SATHIRKA/snort3:odp_reload_dynamic_cac...
authorShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Wed, 5 Aug 2020 19:24:58 +0000 (19:24 +0000)
committerShravan Rangarajuvenkata (shrarang) <shrarang@cisco.com>
Wed, 5 Aug 2020 19:24:58 +0000 (19:24 +0000)
Squashed commit of the following:

commit c8fd1962f309aaa6fae49b0b437404e04adb0e8a
Author: Sreeja Athirkandathil Narayanan <sathirka@cisco.com>
Date:   Mon Aug 3 15:25:33 2020 -0400

    appid: Clear service appid entries in dynamic host cache on ODP reload

src/host_tracker/host_tracker.cc
src/host_tracker/host_tracker.h
src/network_inspectors/appid/appid_module.cc

index 496c12832695bedda8238e1d2aab64e0a37fce79..2b15ff49ba944e243f36fc0e170c2fd01c9d44af 100644 (file)
@@ -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<std::mutex> 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;
index a7e0965c62e82e13b5f4cc609763278e1eea7db1..639481e3433979042eacea5c62aa28062991edf9 100644 (file)
@@ -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);
 
index 20ebe58bf558b09aa62b3398c7d17374c1e5c710..e7c523a880908e6d0bac08fcb6508eb5f8aa308e 100644 (file)
@@ -28,6 +28,7 @@
 #include <climits>
 #include <lua.hpp>
 
+#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();