]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
run-mode: remove duplicate var; add setter function
authorJason Ish <jason.ish@oisf.net>
Wed, 24 Apr 2024 17:25:19 +0000 (11:25 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 25 Apr 2024 04:52:27 +0000 (06:52 +0200)
Remove the global "run_mode" var as it was a duplicate of the runmode on
the "instance" struct. For direct access outside of suricata.c, use the
getter function.

Also expose a setter function for unit tests that need to change it.

26 files changed:
src/detect-engine-loader.c
src/detect-engine.c
src/detect-replace.c
src/flow-manager.c
src/flow.c
src/log-pcap.c
src/output-json.c
src/runmodes.c
src/suricata.c
src/suricata.h
src/tests/fuzz/fuzz_applayerparserparse.c
src/tests/fuzz/fuzz_applayerprotodetectgetproto.c
src/tests/fuzz/fuzz_confyamlloadstring.c
src/tests/fuzz/fuzz_decodepcapfile.c
src/tests/fuzz/fuzz_mimedecparseline.c
src/tests/fuzz/fuzz_predefpcap_aware.c
src/tests/fuzz/fuzz_siginit.c
src/tests/fuzz/fuzz_sigpcap.c
src/tests/fuzz/fuzz_sigpcap_aware.c
src/util-conf.c
src/util-dpdk.c
src/util-logopenfile.c
src/util-plugin.c
src/util-privs.c
src/util-reference-config.c
src/util-threshold-config.c

index 8a02ae148e2f74f428d93d8686927b82d965639c..9fd5eef4a21c8612b35cf3c2a677061b1ac19bec 100644 (file)
@@ -304,7 +304,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exc
                 de_ctx->config_prefix);
     }
 
-    if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
+    if (SCRunmodeGet() == RUNMODE_ENGINE_ANALYSIS) {
         SetupEngineAnalysis(de_ctx, &fp_engine_analysis_set, &rule_engine_analysis_set);
     }
 
@@ -405,7 +405,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exc
 
  end:
     gettimeofday(&de_ctx->last_reload, NULL);
-    if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
+    if (SCRunmodeGet() == RUNMODE_ENGINE_ANALYSIS) {
         CleanupEngineAnalysis(de_ctx);
     }
 
index 75a198e8fabd8352d29f2fa6dfd25c771d0a34c6..21ce4906f58b20c8abdb19e0e89cc39927b94801 100644 (file)
@@ -2457,7 +2457,7 @@ static DetectEngineCtx *DetectEngineCtxInitReal(
 
     SCClassConfInit(de_ctx);
     if (!SCClassConfLoadClassificationConfigFile(de_ctx, NULL)) {
-        if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+        if (SCRunmodeGet() == RUNMODE_CONF_TEST)
             goto error;
     }
 
@@ -2466,7 +2466,7 @@ static DetectEngineCtx *DetectEngineCtxInitReal(
     }
     SCReferenceConfInit(de_ctx);
     if (SCRConfLoadReferenceConfigFile(de_ctx, NULL) < 0) {
-        if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+        if (SCRunmodeGet() == RUNMODE_CONF_TEST)
             goto error;
     }
 
@@ -2698,7 +2698,7 @@ static int DetectEngineCtxLoadConf(DetectEngineCtx *de_ctx)
         }
     }
 
-    if (run_mode == RUNMODE_UNITTEST) {
+    if (RunmodeIsUnittests()) {
         de_ctx->sgh_mpm_ctx_cnf = ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL;
     }
 
index a5d0387457e5055b538eb11ab7d0f55c7038e5c2..63244553b052d328ce98ca82493e86fc2e78eabb 100644 (file)
@@ -30,8 +30,6 @@
 
 #include "runmodes.h"
 
-extern int run_mode;
-
 #include "decode.h"
 
 #include "detect.h"
@@ -100,7 +98,7 @@ int DetectReplaceSetup(DetectEngineCtx *de_ctx, Signature *s, const char *replac
         return -1;
     }
 
-    switch (run_mode) {
+    switch (SCRunmodeGet()) {
         case RUNMODE_NFQ:
         case RUNMODE_IPFW:
             break;
@@ -355,15 +353,15 @@ static int DetectReplaceLongPatternMatchTestWrp(const char *sig, uint32_t sid, c
     uint16_t psize = sizeof(raw_eth_pkt);
 
     /* would be unittest */
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
     ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)sizeof(raw_eth_pkt),
                              sig, sid, p, &psize);
     if (ret == 1) {
         SCLogDebug("replace: test1 phase1");
         ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
     }
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     return ret;
 }
 
@@ -390,15 +388,15 @@ static int DetectReplaceLongPatternMatchTestUDPWrp(const char *sig, uint32_t sid
     uint8_t p[sizeof(raw_eth_pkt)];
     uint16_t psize = sizeof(raw_eth_pkt);
 
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
     ret = DetectReplaceLongPatternMatchTest(raw_eth_pkt, (uint16_t)sizeof(raw_eth_pkt),
                              sig, sid, p, &psize);
     if (ret == 1) {
         SCLogDebug("replace: test1 phase1 ok: %" PRIuMAX" vs %d",(uintmax_t)sizeof(raw_eth_pkt),psize);
         ret = DetectReplaceLongPatternMatchTest(p, psize, sig_rep, sid_rep, NULL, NULL);
     }
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     return ret;
 }
 
@@ -605,8 +603,8 @@ static int DetectReplaceMatchTest15(void)
  */
 static int DetectReplaceParseTest01(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -616,7 +614,7 @@ static int DetectReplaceParseTest01(void)
             "alert udp any any -> any any "
             "(msg:\"test\"; content:\"doh\"; replace:\"; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -626,8 +624,8 @@ static int DetectReplaceParseTest01(void)
  */
 static int DetectReplaceParseTest02(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -637,7 +635,7 @@ static int DetectReplaceParseTest02(void)
             "alert http any any -> any any "
             "(msg:\"test\"; content:\"doh\"; replace:\"bon\"; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -648,8 +646,8 @@ static int DetectReplaceParseTest02(void)
  */
 static int DetectReplaceParseTest03(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
 
@@ -660,7 +658,7 @@ static int DetectReplaceParseTest03(void)
             "alert tcp any any -> any any "
             "(msg:\"test\"; content:\"doh\"; replace:\"don\"; http_header; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -670,8 +668,8 @@ static int DetectReplaceParseTest03(void)
  */
 static int DetectReplaceParseTest04(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -680,7 +678,7 @@ static int DetectReplaceParseTest04(void)
     FAIL_IF_NOT_NULL(DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
                                                    "(msg:\"test\"; replace:\"don\"; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -690,8 +688,8 @@ static int DetectReplaceParseTest04(void)
  */
 static int DetectReplaceParseTest05(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -701,7 +699,7 @@ static int DetectReplaceParseTest05(void)
             "alert tcp any any -> any any "
             "(msg:\"test\"; replace:\"don\"; content:\"doh\"; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -711,8 +709,8 @@ static int DetectReplaceParseTest05(void)
  */
 static int DetectReplaceParseTest06(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -722,7 +720,7 @@ static int DetectReplaceParseTest06(void)
             "alert tcp any any -> any any "
             "(msg:\"test\"; content:\"don\"; replace:\"donut\"; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
@@ -732,8 +730,8 @@ static int DetectReplaceParseTest06(void)
  */
 static int DetectReplaceParseTest07(void)
 {
-    int run_mode_backup = run_mode;
-    run_mode = RUNMODE_NFQ;
+    int run_mode_backup = SCRunmodeGet();
+    SCRunmodeSet(RUNMODE_NFQ);
 
     DetectEngineCtx *de_ctx = DetectEngineCtxInit();
     FAIL_IF_NULL(de_ctx);
@@ -744,7 +742,7 @@ static int DetectReplaceParseTest07(void)
                                           "(msg:\"test\"; content:\"don\"; replace:\"dou\"; "
                                           "content:\"jpg\"; http_header; sid:238012;)"));
 
-    run_mode = run_mode_backup;
+    SCRunmodeSet(run_mode_backup);
     DetectEngineCtxFree(de_ctx);
     PASS;
 }
index 279910cb85babaebce0438a56710a309d8105746..caf91f91486ad0042ab88b0746132d665f95fa38 100644 (file)
@@ -66,9 +66,6 @@
 
 #include "runmode-unix-socket.h"
 
-/* Run mode selected at suricata.c */
-extern int run_mode;
-
 /** queue to pass flows to cleanup/log thread(s) */
 FlowQueue flow_recycle_q;
 
index 7e4629d4b111e630d919fe190102b3ef2c13e282..2be14e8d00a19526ccad2f8114bff3bf78cfb2fe 100644 (file)
@@ -108,9 +108,6 @@ void FlowRegisterTests(void);
 void FlowInitFlowProto(void);
 int FlowSetProtoFreeFunc(uint8_t, void (*Free)(void *));
 
-/* Run mode selected at suricata.c */
-extern int run_mode;
-
 /**
  *  \brief Update memcap value
  *
index fdd0280fc853df27de6cdde6adad0ac89741d74a..f4ee094832267b88e4f8896b38e5039ccad296ba 100644 (file)
@@ -1091,7 +1091,7 @@ static TmEcode PcapLogDataInit(ThreadVars *t, const void *initdata, void **data)
 
     /* Don't early initialize output files if in a PCAP file (offline)
      * mode. */
-    if (!IsRunModeOffline(RunmodeGetCurrent())) {
+    if (!IsRunModeOffline(SCRunmodeGet())) {
         if (pl->mode == LOGMODE_MULTI) {
             PcapLogOpenFileCtx(td->pcap_log);
         } else {
index a886a3aa815fade4d97c70bd4416943cb7c0cdfa..63558e514f20d7bc6709e1ceb161ea5b258e984c 100644 (file)
@@ -1178,8 +1178,7 @@ OutputInitResult OutputJsonInitCtx(ConfNode *conf)
         const char *pcapfile_s = ConfNodeLookupChildValue(conf, "pcap-file");
         if (pcapfile_s != NULL && ConfValIsTrue(pcapfile_s)) {
             json_ctx->file_ctx->is_pcap_offline =
-                (RunmodeGetCurrent() == RUNMODE_PCAP_FILE ||
-                 RunmodeGetCurrent() == RUNMODE_UNIX_SOCKET);
+                    (SCRunmodeGet() == RUNMODE_PCAP_FILE || SCRunmodeGet() == RUNMODE_UNIX_SOCKET);
         }
         json_ctx->file_ctx->type = log_filetype;
     }
index a9bb44452855dd17e3252d686bf4f6902ade22a9..e732ab9596fce22b2e8f4df65a13dabd149ab8ba 100644 (file)
@@ -229,7 +229,7 @@ char *RunmodeGetActive(void)
  */
 const char *RunModeGetMainMode(void)
 {
-    int mainmode = RunmodeGetCurrent();
+    int mainmode = SCRunmodeGet();
 
     return RunModeTranslateModeToName(mainmode);
 }
index b1af2a5d6bdfcdcaa3fc15ff718dc02d731efe70..6d316771f9a06337c404542d80607217b240364f 100644 (file)
@@ -171,9 +171,6 @@ SC_ATOMIC_DECLARE(unsigned int, engine_stage);
 /** suricata engine control flags */
 volatile uint8_t suricata_ctl_flags = 0;
 
-/** Run mode selected */
-int run_mode = RUNMODE_UNKNOWN;
-
 /** Engine mode: inline (ENGINE_MODE_IPS) or just
   * detection mode (ENGINE_MODE_IDS by default) */
 static enum EngineMode g_engine_mode = ENGINE_MODE_UNKNOWN;
@@ -256,16 +253,21 @@ void EngineModeSetIDS(void)
 #ifdef UNITTESTS
 int RunmodeIsUnittests(void)
 {
-    if (run_mode == RUNMODE_UNITTEST)
+    if (suricata.run_mode == RUNMODE_UNITTEST)
         return 1;
 
     return 0;
 }
 #endif
 
-int RunmodeGetCurrent(void)
+int SCRunmodeGet(void)
+{
+    return suricata.run_mode;
+}
+
+void SCRunmodeSet(int run_mode)
 {
-    return run_mode;
+    suricata.run_mode = run_mode;
 }
 
 /** signal handlers
@@ -2385,8 +2387,6 @@ int SCFinalizeRunMode(void)
         default:
             break;
     }
-    /* Set the global run mode and offline flag. */
-    run_mode = suri->run_mode;
 
     if (!CheckValidDaemonModes(suri->daemon, suri->run_mode)) {
         return TM_ECODE_FAILED;
@@ -2984,7 +2984,7 @@ void SuricataInit(void)
         goto out;
     }
 
-    if (run_mode == RUNMODE_DPDK)
+    if (suricata.run_mode == RUNMODE_DPDK)
         prerun_snap = SystemHugepageSnapshotCreate();
 
     SCSetStartTime(&suricata);
@@ -3066,7 +3066,7 @@ void SuricataPostInit(void)
     OnNotifyRunning();
 
     PostRunStartedDetectSetup(&suricata);
-    if (run_mode == RUNMODE_DPDK) { // only DPDK uses hpages at the moment
+    if (suricata.run_mode == RUNMODE_DPDK) { // only DPDK uses hpages at the moment
         SystemHugepageSnapshot *postrun_snap = SystemHugepageSnapshotCreate();
         SystemHugepageEvaluateHugepages(prerun_snap, postrun_snap);
         SystemHugepageSnapshotDestroy(prerun_snap);
index f2ca5e574e0261212801f732440b2a7f42571832..f5cc7ff4b4d69cccaccd13036f7ec4f0cd73a0ee 100644 (file)
@@ -185,11 +185,21 @@ int RunmodeIsUnittests(void);
 #else
 #define RunmodeIsUnittests() 0
 #endif
-int RunmodeGetCurrent(void);
+int SCRunmodeGet(void);
 
-int SuriHasSigFile(void);
+/**
+ * \brief Get the current run mode.
+ */
+int SCRunmodeGet(void);
+
+/**
+ * \brief Set the current run mode.
+ *
+ * Mainly exposed outside of suricata.c as a unit-test helper.
+ */
+void SCRunmodeSet(int run_mode);
 
-extern int run_mode;
+int SuriHasSigFile(void);
 
 void SuricataPreInit(const char *progname);
 void SuricataInit(void);
index 0ee263fc0b0c94f1ed5393bfe689a431efda72f9..0b17edf88691ceeb4385d474dea2424e6658295f 100644 (file)
@@ -86,7 +86,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         setenv("SC_LOG_FILE", "/dev/null", 0);
 
         InitGlobal();
-        run_mode = RUNMODE_PCAP_FILE;
+        SCRunmodeSet(RUNMODE_PCAP_FILE);
         GlobalsInitPreConfig();
 
         //redirect logs to /tmp
index 598e7cc03ff6df85c7ea4aa34075067583078427..86cf71d96feafa035981a695ef6fef3dc08ccfe0 100644 (file)
@@ -36,7 +36,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
     if (alpd_tctx == NULL) {
         //global init
         InitGlobal();
-        run_mode = RUNMODE_UNITTEST;
+        SCRunmodeSet(RUNMODE_UNITTEST);
         if (ConfYamlLoadString(configNoChecksum, strlen(configNoChecksum)) != 0) {
             abort();
         }
index f5f9ed39831e85fca12075f8b82c25c63f788afb..4e9e7335ac4d428cc64190637cadcda99463e5d5 100644 (file)
@@ -21,7 +21,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         setenv("SC_LOG_FILE", "/dev/null", 0);
         //global init
         InitGlobal();
-        run_mode = RUNMODE_UNITTEST;
+        SCRunmodeSet(RUNMODE_UNITTEST);
         initialized = 1;
     }
 
index cf508697f05bbc159d60c5903e0708449b87f50e..2b616dd6906e3f6b90cb70927fd1f1ecd5436bba 100644 (file)
@@ -43,7 +43,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         setenv("SC_LOG_FILE", "/dev/null", 0);
 
         InitGlobal();
-        run_mode = RUNMODE_PCAP_FILE;
+        SCRunmodeSet(RUNMODE_PCAP_FILE);
 
         //redirect logs to /tmp
         ConfigSetLogDirectory("/tmp/");
index 432ce7de95233e91d0fbecc7d409ee49f9ee840d..e067162d89a79990be0510058cec4fc5cff549e1 100644 (file)
@@ -32,7 +32,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         setenv("SC_LOG_FILE", "/dev/null", 0);
         //global init
         InitGlobal();
-        run_mode = RUNMODE_UNITTEST;
+        SCRunmodeSet(RUNMODE_UNITTEST);
         initialized = 1;
     }
 
index c20e3d341d527df67f03198986217c4158ab4031..f15641dc831735bab4b7ec1b77fad9a95e599e40 100644 (file)
@@ -69,7 +69,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         InitGlobal();
 
         GlobalsInitPreConfig();
-        run_mode = RUNMODE_PCAP_FILE;
+        SCRunmodeSet(RUNMODE_PCAP_FILE);
         // redirect logs to /tmp
         ConfigSetLogDirectory("/tmp/");
         // disables checksums validation for fuzzing
@@ -85,7 +85,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         surifuzz.delayed_detect = 1;
 
         PostConfLoadedSetup(&surifuzz);
-        PreRunPostPrivsDropInit(run_mode);
+        PreRunPostPrivsDropInit(SCRunmodeGet());
         PostConfLoadedDetectSetup(&surifuzz);
 
         memset(&tv, 0, sizeof(tv));
index 80514b2d9a5244536b95a679fdeac9ccf929223f..a98148cfac8d762011fd3d39f30d4261ee30c509 100644 (file)
@@ -23,7 +23,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         setenv("SC_LOG_FILE", "/dev/null", 0);
         //global init
         InitGlobal();
-        run_mode = RUNMODE_UNITTEST;
+        SCRunmodeSet(RUNMODE_UNITTEST);
         MpmTableSetup();
         SpmTableSetup();
         EngineModeSetIDS();
index e5bd56deb476ca18f16b36af8468a56371e4f19d..99d05d6d98b697a91dac67a09f98832ce2dd6cff 100644 (file)
@@ -63,7 +63,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         InitGlobal();
 
         GlobalsInitPreConfig();
-        run_mode = RUNMODE_PCAP_FILE;
+        SCRunmodeSet(RUNMODE_PCAP_FILE);
         //redirect logs to /tmp
         ConfigSetLogDirectory("/tmp/");
         //disables checksums validation for fuzzing
@@ -78,7 +78,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         surifuzz.delayed_detect = 1;
 
         PostConfLoadedSetup(&surifuzz);
-        PreRunPostPrivsDropInit(run_mode);
+        PreRunPostPrivsDropInit(SCRunmodeGet());
         PostConfLoadedDetectSetup(&surifuzz);
 
         memset(&tv, 0, sizeof(tv));
index d2454769859b43b853e416eaecc47cdfda9f9830..7b343f72f016aaac1a19fcb67e2a777c01baa95f 100644 (file)
@@ -89,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         InitGlobal();
 
         GlobalsInitPreConfig();
-        run_mode = RUNMODE_PCAP_FILE;
+        SCRunmodeSet(RUNMODE_PCAP_FILE);
         // redirect logs to /tmp
         ConfigSetLogDirectory("/tmp/");
         // disables checksums validation for fuzzing
@@ -104,7 +104,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
         surifuzz.delayed_detect = 1;
 
         PostConfLoadedSetup(&surifuzz);
-        PreRunPostPrivsDropInit(run_mode);
+        PreRunPostPrivsDropInit(SCRunmodeGet());
         PostConfLoadedDetectSetup(&surifuzz);
 
         memset(&tv, 0, sizeof(tv));
index 9bf5586bd970d1f106999fc99340238baf251b84..302c918dcfc309738cd1025fa54ac761f8f75e03 100644 (file)
@@ -150,7 +150,7 @@ int ConfUnixSocketIsEnable(void)
 #ifdef OS_WIN32
         return 0;
 #else
-        if (!IsRunModeOffline(RunmodeGetCurrent())) {
+        if (!IsRunModeOffline(SCRunmodeGet())) {
             SCLogInfo("Running in live mode, activating unix socket");
             return 1;
         } else {
index 13329a81d13a7b003cee3434bae71f12234c96db..8bffa60d27cb06d2edba41c36ee96f2f7aceba22 100644 (file)
@@ -29,7 +29,7 @@
 void DPDKCleanupEAL(void)
 {
 #ifdef HAVE_DPDK
-    if (run_mode == RUNMODE_DPDK) {
+    if (SCRunmodeGet() == RUNMODE_DPDK) {
         int retval = rte_eal_cleanup();
         if (retval != 0)
             SCLogError("EAL cleanup failed: %s", strerror(-retval));
@@ -41,7 +41,7 @@ void DPDKCloseDevice(LiveDevice *ldev)
 {
     (void)ldev; // avoid warnings of unused variable
 #ifdef HAVE_DPDK
-    if (run_mode == RUNMODE_DPDK) {
+    if (SCRunmodeGet() == RUNMODE_DPDK) {
         uint16_t port_id;
         int retval = rte_eth_dev_get_port_by_name(ldev->dev, &port_id);
         if (retval < 0) {
@@ -59,7 +59,7 @@ void DPDKFreeDevice(LiveDevice *ldev)
 {
     (void)ldev; // avoid warnings of unused variable
 #ifdef HAVE_DPDK
-    if (run_mode == RUNMODE_DPDK) {
+    if (SCRunmodeGet() == RUNMODE_DPDK) {
         SCLogDebug("%s: releasing packet mempool", ldev->dev);
         rte_mempool_free(ldev->dpdk_vars.pkt_mp);
     }
index b58bdd43efc77dce8a0153c2b3d10e61ec651282..a6bdf45a3e00345dc200f0858103ed0056698f0f 100644 (file)
@@ -608,7 +608,7 @@ SCConfLogOpenGeneric(ConfNode *conf,
 
 #ifdef BUILD_WITH_UNIXSOCKET
     /* If a socket and running live, do non-blocking writes. */
-    if (log_ctx->is_sock && !IsRunModeOffline(RunmodeGetCurrent())) {
+    if (log_ctx->is_sock && !IsRunModeOffline(SCRunmodeGet())) {
         SCLogInfo("Setting logging socket of non-blocking in live mode.");
         log_ctx->send_flags |= MSG_DONTWAIT;
     }
index 6d34ff0e66b36480ea5a885e71d08be10951198a..7a9b467daaac6278081a4654cfc9e60223775a81 100644 (file)
@@ -121,7 +121,7 @@ void SCPluginsLoad(const char *capture_plugin_name, const char *capture_plugin_a
         }
     }
 
-    if (run_mode == RUNMODE_PLUGIN) {
+    if (SCRunmodeGet() == RUNMODE_PLUGIN) {
         SCCapturePlugin *capture = SCPluginFindCaptureByName(capture_plugin_name);
         if (capture == NULL) {
             FatalError("No capture plugin found with name %s", capture_plugin_name);
index 3a1ea485159a3d6f6ea30dd5e581c50995776f5f..905c56b51210a877933b334a1c29a68361708573 100644 (file)
@@ -46,9 +46,6 @@
 /** flag indicating if we'll be using caps */
 extern bool sc_set_caps;
 
-/** our current runmode */
-extern int run_mode;
-
 /**
  * \brief   Drop the privileges of the main thread
  */
@@ -59,7 +56,7 @@ void SCDropMainThreadCaps(uint32_t userid, uint32_t groupid)
 
     capng_clear(CAPNG_SELECT_BOTH);
 
-    switch (run_mode) {
+    switch (SCRunmodeGet()) {
         case RUNMODE_PCAP_DEV:
         case RUNMODE_AFP_DEV:
         case RUNMODE_AFXDP_DEV:
index 89cc1d23881ccacea2d4a7dfee7f8ddf8547b4d7..3ee4dd85dfc24ea3a4c347f4128d9a3f64fbcb35 100644 (file)
@@ -321,7 +321,7 @@ static int SCRConfIsLineBlankOrComment(char *line)
 static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
 {
     char line[1024];
-    int runmode = RunmodeGetCurrent();
+    int runmode = SCRunmodeGet();
     bool is_conf_test_mode = runmode == RUNMODE_CONF_TEST;
     while (fgets(line, sizeof(line), fd) != NULL) {
         if (SCRConfIsLineBlankOrComment(line))
index 70cc41a73e91ef5e1f9bf2607e0ccb2ddded7005..aa9991588003d0894efb7fea184f9f0944a73a73 100644 (file)
@@ -186,7 +186,7 @@ int SCThresholdConfInitContext(DetectEngineCtx *de_ctx)
         SCLogWarning("Error loading threshold configuration from %s", filename);
         SCThresholdConfDeInitContext(de_ctx, fd);
         /* maintain legacy behavior so no errors unless config testing */
-        if (RunmodeGetCurrent() == RUNMODE_CONF_TEST) {
+        if (SCRunmodeGet() == RUNMODE_CONF_TEST) {
             ret = -1;
         }
         return ret;
@@ -996,7 +996,7 @@ int SCThresholdConfParseFile(DetectEngineCtx *de_ctx, FILE *fp)
         esc_pos = SCThresholdConfLineIsMultiline(line);
         if (esc_pos == 0) {
             if (SCThresholdConfAddThresholdtype(line, de_ctx) < 0) {
-                if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+                if (SCRunmodeGet() == RUNMODE_CONF_TEST)
                     return -1;
             } else {
                 SCLogDebug("Adding threshold.config rule num %" PRIu32 "( %s )", rule_num, line);