]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #2524 in SNORT/snort3 from ~SMINUT/snort3:fp_proc to master
authorMasud Hasan (mashasan) <mashasan@cisco.com>
Mon, 5 Oct 2020 21:15:01 +0000 (21:15 +0000)
committerMasud Hasan (mashasan) <mashasan@cisco.com>
Mon, 5 Oct 2020 21:15:01 +0000 (21:15 +0000)
Squashed commit of the following:

commit dd6cf66f0414833b39cf2691b8c11c71f9b4bc8d
Author: Silviu Minut <sminut@cisco.com>
Date:   Thu Oct 1 17:03:09 2020 -0400

    rna: set the thread local fingerprint processors during reload_config

src/network_inspectors/rna/rna_module.cc
src/network_inspectors/rna/rna_module.h
src/network_inspectors/rna/test/rna_module_test.cc

index 9e26d9d151d0814af94684c5cb7e9104c0a7ad10..fef5a6eacd5fd6be5c9aaee6e91195cc90922902 100644 (file)
@@ -33,6 +33,7 @@
 #include "log/messages.h"
 #include "lua/lua.h"
 #include "main/snort_config.h"
+#include "main/snort.h"
 #include "managers/module_manager.h"
 #include "utils/util.h"
 
@@ -75,6 +76,13 @@ static inline string format_dump_mac(const uint8_t mac[MAC_SIZE])
     return ss.str();
 }
 
+bool FpProcReloadTuner::tinit()
+{
+    set_tcp_fp_processor(mod_conf->tcp_processor);
+    set_ua_fp_processor(mod_conf->ua_processor);
+    return false;  // no work to do after this
+}
+
 static const Command rna_cmds[] =
 {
     { "dump_macs", dump_mac_cache, nullptr,
@@ -302,6 +310,13 @@ bool RnaModule::end(const char* fqn, int index, SnortConfig* sc)
 
         if ( mod_conf->ua_processor )
             mod_conf->ua_processor->make_mpse(sc);
+
+        if ( (mod_conf->tcp_processor || mod_conf->ua_processor) && Snort::is_reloading() )
+        {
+            fprt.mod_conf = mod_conf;
+            sc->register_reload_resource_tuner(fprt);
+        }
+
     }
 
     if ( index > 0 and mod_conf->tcp_processor and !strcmp(fqn, "rna.tcp_fingerprints") )
index c22f420f69f599f6c2d5ec0f5f5fba18ade54ab1..fe4747da0d517ad9d72cec392adfece0c2078c91 100644 (file)
@@ -22,6 +22,7 @@
 #define RNA_MODULE_H
 
 #include "framework/module.h"
+#include "main/snort_config.h"
 #include "main/snort_debug.h"
 #include "profiler/profiler.h"
 
@@ -49,6 +50,24 @@ extern THREAD_LOCAL RnaStats rna_stats;
 extern THREAD_LOCAL snort::ProfileStats rna_perf_stats;
 extern THREAD_LOCAL const snort::Trace* rna_trace;
 
+
+// A tuner for initializing fingerprint processors during reload
+class FpProcReloadTuner : public snort::ReloadResourceTuner
+{
+public:
+    FpProcReloadTuner() = default;
+
+    bool tinit() override;
+
+    bool tune_packet_context() override
+    { return true; }
+
+    bool tune_idle_context() override
+    { return true; }
+
+    RnaModuleConfig* mod_conf = nullptr;
+};
+
 class RnaModule : public snort::Module
 {
 public:
@@ -78,6 +97,8 @@ private:
 
     RawFingerprint fingerprint;
 
+    FpProcReloadTuner fprt;
+
     bool is_valid_fqn(const char* fqn) const;
 };
 
index 9b3924175fdbd799474527c57eb5deaffa7a387e..d088c402edde570dbc0b72102127958a85fe6679 100644 (file)
 #include <CppUTest/TestHarness.h>
 #include <CppUTestExt/MockSupport.h>
 
+void set_tcp_fp_processor(TcpFpProcessor*) { }
+void set_ua_fp_processor(UaFpProcessor*) { }
+
+namespace snort
+{
+    bool Snort::is_reloading() { return false; }
+}
+
 TEST_GROUP(rna_module_test)
 {
 };