]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricata: expose and break out configuration loading
authorJason Ish <jason.ish@oisf.net>
Mon, 4 Mar 2024 23:08:08 +0000 (17:08 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 25 Mar 2024 16:36:29 +0000 (17:36 +0100)
Expose LoadYamlConfig as SCLoadYamlConfig and remove it from
SuricataInit. This is required to allow the library user the ability
customize the loading of the configuration, for example doing some
programmatic configuration then loading a configuration file.

examples/lib/simple/main.c
src/main.c
src/suricata.c
src/suricata.h

index 0e728e9732e2e2877d9748ca40834d27716a6319..f9c09fb0f55085e5ca147a7f6df3d8f96bbb4437 100644 (file)
@@ -40,6 +40,13 @@ int main(int argc, char **argv)
             exit(EXIT_FAILURE);
     }
 
+    /* Load configuration file, could be done earlier but must be done
+     * before SuricataInit, but even then its still optional as you
+     * may be programmatically configuration Suricata. */
+    if (SCLoadYamlConfig() != TM_ECODE_OK) {
+        exit(EXIT_FAILURE);
+    }
+
     SuricataInit();
     SuricataPostInit();
 
index 714efda118850bf125912ca03e0cce69d0333fa0..f9fcbf5e2c0445df13d3cc0e7f9425fc778dba76 100644 (file)
@@ -44,7 +44,13 @@ int main(int argc, char **argv)
             exit(EXIT_FAILURE);
     }
 
-    /* Initialization tasks: Loading config, setup logging */
+    /* Load yaml configuration file if provided. */
+    if (SCLoadYamlConfig() != TM_ECODE_OK) {
+        exit(EXIT_FAILURE);
+    }
+
+    /* Initialization tasks: apply configuration, drop privileges,
+     * etc. */
     SuricataInit();
 
     /* Post-initialization tasks: wait on thread start/running and get ready for the main loop. */
index 3bc86f446ac1bc0b2fdf561c671fde3d716b9956..d59e0b8601660aa928803a2a87c3fbf47f16bbb8 100644 (file)
@@ -955,10 +955,12 @@ void RegisterAllModules(void)
     TmModuleDecodeDPDKRegister();
 }
 
-static TmEcode LoadYamlConfig(SCInstance *suri)
+TmEcode SCLoadYamlConfig(void)
 {
     SCEnter();
 
+    SCInstance *suri = &suricata;
+
     if (suri->conf_filename == NULL)
         suri->conf_filename = DEFAULT_CONF_FILE;
 
@@ -2904,11 +2906,6 @@ void SuricataInit(void)
     /* Initializations for global vars, queues, etc (memsets, mutex init..) */
     GlobalsInitPreConfig();
 
-    /* Load yaml configuration file if provided. */
-    if (LoadYamlConfig(&suricata) != TM_ECODE_OK) {
-        exit(EXIT_FAILURE);
-    }
-
     if (suricata.run_mode == RUNMODE_DUMP_CONFIG) {
         ConfDump();
         exit(EXIT_SUCCESS);
index 9ec80ddc832360af18dc095b4cbf54143e851cb7..f2ca5e574e0261212801f732440b2a7f42571832 100644 (file)
@@ -203,6 +203,7 @@ void PostConfLoadedDetectSetup(SCInstance *suri);
 int SCFinalizeRunMode(void);
 TmEcode SCParseCommandLine(int argc, char **argv);
 int SCStartInternalRunMode(int argc, char **argv);
+TmEcode SCLoadYamlConfig(void);
 
 void PreRunInit(const int runmode);
 void PreRunPostPrivsDropInit(const int runmode);