From d2537361f49dad67b809f6b3e1ef044e0e49817d Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 24 Apr 2024 11:25:19 -0600 Subject: [PATCH] run-mode: remove duplicate var; add setter function 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. --- src/detect-engine-loader.c | 4 +- src/detect-engine.c | 6 +- src/detect-replace.c | 58 +++++++++---------- src/flow-manager.c | 3 - src/flow.c | 3 - src/log-pcap.c | 2 +- src/output-json.c | 3 +- src/runmodes.c | 2 +- src/suricata.c | 20 +++---- src/suricata.h | 16 ++++- src/tests/fuzz/fuzz_applayerparserparse.c | 2 +- .../fuzz/fuzz_applayerprotodetectgetproto.c | 2 +- src/tests/fuzz/fuzz_confyamlloadstring.c | 2 +- src/tests/fuzz/fuzz_decodepcapfile.c | 2 +- src/tests/fuzz/fuzz_mimedecparseline.c | 2 +- src/tests/fuzz/fuzz_predefpcap_aware.c | 4 +- src/tests/fuzz/fuzz_siginit.c | 2 +- src/tests/fuzz/fuzz_sigpcap.c | 4 +- src/tests/fuzz/fuzz_sigpcap_aware.c | 4 +- src/util-conf.c | 2 +- src/util-dpdk.c | 6 +- src/util-logopenfile.c | 2 +- src/util-plugin.c | 2 +- src/util-privs.c | 5 +- src/util-reference-config.c | 2 +- src/util-threshold-config.c | 4 +- 26 files changed, 81 insertions(+), 83 deletions(-) diff --git a/src/detect-engine-loader.c b/src/detect-engine-loader.c index 8a02ae148e..9fd5eef4a2 100644 --- a/src/detect-engine-loader.c +++ b/src/detect-engine-loader.c @@ -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); } diff --git a/src/detect-engine.c b/src/detect-engine.c index 75a198e8fa..21ce4906f5 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -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; } diff --git a/src/detect-replace.c b/src/detect-replace.c index a5d0387457..63244553b0 100644 --- a/src/detect-replace.c +++ b/src/detect-replace.c @@ -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; } diff --git a/src/flow-manager.c b/src/flow-manager.c index 279910cb85..caf91f9148 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -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; diff --git a/src/flow.c b/src/flow.c index 7e4629d4b1..2be14e8d00 100644 --- a/src/flow.c +++ b/src/flow.c @@ -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 * diff --git a/src/log-pcap.c b/src/log-pcap.c index fdd0280fc8..f4ee094832 100644 --- a/src/log-pcap.c +++ b/src/log-pcap.c @@ -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 { diff --git a/src/output-json.c b/src/output-json.c index a886a3aa81..63558e514f 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -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; } diff --git a/src/runmodes.c b/src/runmodes.c index a9bb444528..e732ab9596 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -229,7 +229,7 @@ char *RunmodeGetActive(void) */ const char *RunModeGetMainMode(void) { - int mainmode = RunmodeGetCurrent(); + int mainmode = SCRunmodeGet(); return RunModeTranslateModeToName(mainmode); } diff --git a/src/suricata.c b/src/suricata.c index b1af2a5d6b..6d316771f9 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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); diff --git a/src/suricata.h b/src/suricata.h index f2ca5e574e..f5cc7ff4b4 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -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); diff --git a/src/tests/fuzz/fuzz_applayerparserparse.c b/src/tests/fuzz/fuzz_applayerparserparse.c index 0ee263fc0b..0b17edf886 100644 --- a/src/tests/fuzz/fuzz_applayerparserparse.c +++ b/src/tests/fuzz/fuzz_applayerparserparse.c @@ -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 diff --git a/src/tests/fuzz/fuzz_applayerprotodetectgetproto.c b/src/tests/fuzz/fuzz_applayerprotodetectgetproto.c index 598e7cc03f..86cf71d96f 100644 --- a/src/tests/fuzz/fuzz_applayerprotodetectgetproto.c +++ b/src/tests/fuzz/fuzz_applayerprotodetectgetproto.c @@ -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(); } diff --git a/src/tests/fuzz/fuzz_confyamlloadstring.c b/src/tests/fuzz/fuzz_confyamlloadstring.c index f5f9ed3983..4e9e7335ac 100644 --- a/src/tests/fuzz/fuzz_confyamlloadstring.c +++ b/src/tests/fuzz/fuzz_confyamlloadstring.c @@ -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; } diff --git a/src/tests/fuzz/fuzz_decodepcapfile.c b/src/tests/fuzz/fuzz_decodepcapfile.c index cf508697f0..2b616dd690 100644 --- a/src/tests/fuzz/fuzz_decodepcapfile.c +++ b/src/tests/fuzz/fuzz_decodepcapfile.c @@ -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/"); diff --git a/src/tests/fuzz/fuzz_mimedecparseline.c b/src/tests/fuzz/fuzz_mimedecparseline.c index 432ce7de95..e067162d89 100644 --- a/src/tests/fuzz/fuzz_mimedecparseline.c +++ b/src/tests/fuzz/fuzz_mimedecparseline.c @@ -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; } diff --git a/src/tests/fuzz/fuzz_predefpcap_aware.c b/src/tests/fuzz/fuzz_predefpcap_aware.c index c20e3d341d..f15641dc83 100644 --- a/src/tests/fuzz/fuzz_predefpcap_aware.c +++ b/src/tests/fuzz/fuzz_predefpcap_aware.c @@ -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)); diff --git a/src/tests/fuzz/fuzz_siginit.c b/src/tests/fuzz/fuzz_siginit.c index 80514b2d9a..a98148cfac 100644 --- a/src/tests/fuzz/fuzz_siginit.c +++ b/src/tests/fuzz/fuzz_siginit.c @@ -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(); diff --git a/src/tests/fuzz/fuzz_sigpcap.c b/src/tests/fuzz/fuzz_sigpcap.c index e5bd56deb4..99d05d6d98 100644 --- a/src/tests/fuzz/fuzz_sigpcap.c +++ b/src/tests/fuzz/fuzz_sigpcap.c @@ -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)); diff --git a/src/tests/fuzz/fuzz_sigpcap_aware.c b/src/tests/fuzz/fuzz_sigpcap_aware.c index d245476985..7b343f72f0 100644 --- a/src/tests/fuzz/fuzz_sigpcap_aware.c +++ b/src/tests/fuzz/fuzz_sigpcap_aware.c @@ -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)); diff --git a/src/util-conf.c b/src/util-conf.c index 9bf5586bd9..302c918dcf 100644 --- a/src/util-conf.c +++ b/src/util-conf.c @@ -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 { diff --git a/src/util-dpdk.c b/src/util-dpdk.c index 13329a81d1..8bffa60d27 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -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); } diff --git a/src/util-logopenfile.c b/src/util-logopenfile.c index b58bdd43ef..a6bdf45a3e 100644 --- a/src/util-logopenfile.c +++ b/src/util-logopenfile.c @@ -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; } diff --git a/src/util-plugin.c b/src/util-plugin.c index 6d34ff0e66..7a9b467daa 100644 --- a/src/util-plugin.c +++ b/src/util-plugin.c @@ -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); diff --git a/src/util-privs.c b/src/util-privs.c index 3a1ea48515..905c56b512 100644 --- a/src/util-privs.c +++ b/src/util-privs.c @@ -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: diff --git a/src/util-reference-config.c b/src/util-reference-config.c index 89cc1d2388..3ee4dd85df 100644 --- a/src/util-reference-config.c +++ b/src/util-reference-config.c @@ -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)) diff --git a/src/util-threshold-config.c b/src/util-threshold-config.c index 70cc41a73e..aa99915880 100644 --- a/src/util-threshold-config.c +++ b/src/util-threshold-config.c @@ -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);