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);
}
end:
gettimeofday(&de_ctx->last_reload, NULL);
- if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
+ if (SCRunmodeGet() == RUNMODE_ENGINE_ANALYSIS) {
CleanupEngineAnalysis(de_ctx);
}
SCClassConfInit(de_ctx);
if (!SCClassConfLoadClassificationConfigFile(de_ctx, NULL)) {
- if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+ if (SCRunmodeGet() == RUNMODE_CONF_TEST)
goto error;
}
}
SCReferenceConfInit(de_ctx);
if (SCRConfLoadReferenceConfigFile(de_ctx, NULL) < 0) {
- if (RunmodeGetCurrent() == RUNMODE_CONF_TEST)
+ if (SCRunmodeGet() == RUNMODE_CONF_TEST)
goto error;
}
}
}
- if (run_mode == RUNMODE_UNITTEST) {
+ if (RunmodeIsUnittests()) {
de_ctx->sgh_mpm_ctx_cnf = ENGINE_SGH_MPM_FACTORY_CONTEXT_FULL;
}
#include "runmodes.h"
-extern int run_mode;
-
#include "decode.h"
#include "detect.h"
return -1;
}
- switch (run_mode) {
+ switch (SCRunmodeGet()) {
case RUNMODE_NFQ:
case RUNMODE_IPFW:
break;
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;
}
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;
}
*/
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);
"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;
}
*/
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);
"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;
}
*/
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();
"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;
}
*/
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);
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;
}
*/
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);
"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;
}
*/
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);
"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;
}
*/
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);
"(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;
}
#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;
void FlowInitFlowProto(void);
int FlowSetProtoFreeFunc(uint8_t, void (*Free)(void *));
-/* Run mode selected at suricata.c */
-extern int run_mode;
-
/**
* \brief Update memcap value
*
/* 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 {
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;
}
*/
const char *RunModeGetMainMode(void)
{
- int mainmode = RunmodeGetCurrent();
+ int mainmode = SCRunmodeGet();
return RunModeTranslateModeToName(mainmode);
}
/** 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;
#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
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;
goto out;
}
- if (run_mode == RUNMODE_DPDK)
+ if (suricata.run_mode == RUNMODE_DPDK)
prerun_snap = SystemHugepageSnapshotCreate();
SCSetStartTime(&suricata);
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);
#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);
setenv("SC_LOG_FILE", "/dev/null", 0);
InitGlobal();
- run_mode = RUNMODE_PCAP_FILE;
+ SCRunmodeSet(RUNMODE_PCAP_FILE);
GlobalsInitPreConfig();
//redirect logs to /tmp
if (alpd_tctx == NULL) {
//global init
InitGlobal();
- run_mode = RUNMODE_UNITTEST;
+ SCRunmodeSet(RUNMODE_UNITTEST);
if (ConfYamlLoadString(configNoChecksum, strlen(configNoChecksum)) != 0) {
abort();
}
setenv("SC_LOG_FILE", "/dev/null", 0);
//global init
InitGlobal();
- run_mode = RUNMODE_UNITTEST;
+ SCRunmodeSet(RUNMODE_UNITTEST);
initialized = 1;
}
setenv("SC_LOG_FILE", "/dev/null", 0);
InitGlobal();
- run_mode = RUNMODE_PCAP_FILE;
+ SCRunmodeSet(RUNMODE_PCAP_FILE);
//redirect logs to /tmp
ConfigSetLogDirectory("/tmp/");
setenv("SC_LOG_FILE", "/dev/null", 0);
//global init
InitGlobal();
- run_mode = RUNMODE_UNITTEST;
+ SCRunmodeSet(RUNMODE_UNITTEST);
initialized = 1;
}
InitGlobal();
GlobalsInitPreConfig();
- run_mode = RUNMODE_PCAP_FILE;
+ SCRunmodeSet(RUNMODE_PCAP_FILE);
// redirect logs to /tmp
ConfigSetLogDirectory("/tmp/");
// disables checksums validation for fuzzing
surifuzz.delayed_detect = 1;
PostConfLoadedSetup(&surifuzz);
- PreRunPostPrivsDropInit(run_mode);
+ PreRunPostPrivsDropInit(SCRunmodeGet());
PostConfLoadedDetectSetup(&surifuzz);
memset(&tv, 0, sizeof(tv));
setenv("SC_LOG_FILE", "/dev/null", 0);
//global init
InitGlobal();
- run_mode = RUNMODE_UNITTEST;
+ SCRunmodeSet(RUNMODE_UNITTEST);
MpmTableSetup();
SpmTableSetup();
EngineModeSetIDS();
InitGlobal();
GlobalsInitPreConfig();
- run_mode = RUNMODE_PCAP_FILE;
+ SCRunmodeSet(RUNMODE_PCAP_FILE);
//redirect logs to /tmp
ConfigSetLogDirectory("/tmp/");
//disables checksums validation for fuzzing
surifuzz.delayed_detect = 1;
PostConfLoadedSetup(&surifuzz);
- PreRunPostPrivsDropInit(run_mode);
+ PreRunPostPrivsDropInit(SCRunmodeGet());
PostConfLoadedDetectSetup(&surifuzz);
memset(&tv, 0, sizeof(tv));
InitGlobal();
GlobalsInitPreConfig();
- run_mode = RUNMODE_PCAP_FILE;
+ SCRunmodeSet(RUNMODE_PCAP_FILE);
// redirect logs to /tmp
ConfigSetLogDirectory("/tmp/");
// disables checksums validation for fuzzing
surifuzz.delayed_detect = 1;
PostConfLoadedSetup(&surifuzz);
- PreRunPostPrivsDropInit(run_mode);
+ PreRunPostPrivsDropInit(SCRunmodeGet());
PostConfLoadedDetectSetup(&surifuzz);
memset(&tv, 0, sizeof(tv));
#ifdef OS_WIN32
return 0;
#else
- if (!IsRunModeOffline(RunmodeGetCurrent())) {
+ if (!IsRunModeOffline(SCRunmodeGet())) {
SCLogInfo("Running in live mode, activating unix socket");
return 1;
} else {
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));
{
(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) {
{
(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);
}
#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;
}
}
}
- 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);
/** 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
*/
capng_clear(CAPNG_SELECT_BOTH);
- switch (run_mode) {
+ switch (SCRunmodeGet()) {
case RUNMODE_PCAP_DEV:
case RUNMODE_AFP_DEV:
case RUNMODE_AFXDP_DEV:
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))
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;
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);