]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Pull request #4620: main: allow toggling generation of instance_map output
authorMichael Matirko (mmatirko) <mmatirko@cisco.com>
Tue, 18 Feb 2025 16:34:25 +0000 (16:34 +0000)
committerSteven Baigal (sbaigal) <sbaigal@cisco.com>
Tue, 18 Feb 2025 16:34:25 +0000 (16:34 +0000)
Merge in SNORT/snort3 from ~MMATIRKO/snort3:toggle_map to master

Squashed commit of the following:

commit 63701bbedc562453be74a1c0323f3038cbaa821f
Author: Michael Matirko <mmatirko@cisco.com>
Date:   Fri Feb 14 16:13:29 2025 -0500

    main: allow toggling generation of instance_map output

src/main/snort_config.cc
src/main/snort_config.h
src/main/snort_module.cc
src/main/thread.cc

index f7e736e47d2a2ff54eac42dd7b020d3699a41061..05de97829fbcfc96b5f315e5a73f24948faeacd4 100644 (file)
@@ -578,6 +578,14 @@ void SnortConfig::set_chroot_dir(const char* directory)
         chroot_dir.clear();
 }
 
+void SnortConfig::set_create_instance_file(bool enabled)
+{
+    if (enabled)
+        run_flags |= RUN_FLAG__CREATE_INST_FILE;
+    else
+        run_flags &= ~RUN_FLAG__CREATE_INST_FILE;
+}
+
 void SnortConfig::set_create_pid_file(bool enabled)
 {
     if (enabled)
index adcbf5fcea9a272cb30de9d535a7984123bce0df..01dc09868ba1e496aec2b7fc16aa4d49479fded2 100644 (file)
@@ -73,8 +73,10 @@ enum RunFlag
     RUN_FLAG__TEST_FEATURES       = 0x00400000,
     RUN_FLAG__GEN_DUMP_CONFIG     = 0x00800000,
 
+    RUN_FLAG__CREATE_INST_FILE    = 0x01000000,
+
 #ifdef SHELL
-    RUN_FLAG__SHELL               = 0x01000000,
+    RUN_FLAG__SHELL               = 0x02000000,
 #endif
 };
 
@@ -452,6 +454,7 @@ public:
     void set_alert_mode(const char*);
     void set_chroot_dir(const char*);
     void set_create_pid_file(bool);
+    void set_create_instance_file(bool);
     void set_pid_filename(const char*);
     void set_max_procs(uint8_t);
     void set_daemon(bool);
@@ -616,6 +619,9 @@ public:
     bool gen_dump_config() const
     { return run_flags & RUN_FLAG__GEN_DUMP_CONFIG; }
 
+    bool create_inst_file() const
+    { return run_flags & RUN_FLAG__CREATE_INST_FILE; }
+
     // other stuff
     uint8_t min_ttl() const
     { return get_network_policy()->min_ttl; }
index 25163e08411a8474236051c2331403d42b9806cf..4333987848d4be5b1fff82b4cdb5b9158e1122d3 100644 (file)
@@ -367,6 +367,9 @@ static const Parameter s_params[] =
       "<file> to create unix socket" },
 #endif
 
+    { "--create-instance-file", Parameter::PT_IMPLIED, nullptr, nullptr,
+      "create instance mappings file for this Snort process at startup" },
+
     { "--create-pidfile", Parameter::PT_STRING, "(optional)", nullptr,
       "create PID file, even when not in Daemon mode" },
 
@@ -910,6 +913,9 @@ bool SnortModule::set(const char*, Value& v, SnortConfig* sc)
     else if ( is(v, "--max-procs") )
         sc->set_max_procs(v.get_uint8());
 
+    else if ( is(v, "--create-instance-file") )
+        sc->set_create_instance_file(true);
+
     else if ( is(v, "--daq") )
         module_config = sc->daq_config->add_module_config(v.get_string());
 
index 0629ace57f3fb2ccbd8339b557de36262d525527..5478472d9db007bafbbc516dfd2ecc59c62fa169 100644 (file)
@@ -62,6 +62,10 @@ namespace snort
 
 void populate_instance_maps()
 {
+    const SnortConfig* sc = SnortConfig::get_conf();
+    if (!sc->create_inst_file())
+        return;
+
     std::string path;
 
     get_instance_file(path, INST_MAP_NAME);
@@ -83,6 +87,10 @@ void populate_instance_maps()
 
 void invalidate_instance_maps()
 {
+    const SnortConfig* sc = SnortConfig::get_conf();
+    if (!sc->create_inst_file())
+        return;
+
     std::string path;
 
     get_instance_file(path, INST_MAP_NAME);