detect/analysis: Move globals to engine ctx

Issue: 6239

This commit moves the global variables associated with engine analysis
into the detect engine context. Doing so provides encapsulation of the
analysis components as well as thread-safe operation in a multi-tenant
(context) deployment.
pull/9349/head
Jeff Lucovsky 3 years ago committed by Victor Julien
parent 4fd3205bf0
commit c8615bcd47

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2012 Open Information Security Foundation /* Copyright (C) 2007-2023 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -26,20 +26,17 @@
#include <stdint.h> #include <stdint.h>
int SetupFPAnalyzer(void); struct DetectEngineCtx_;
void CleanupFPAnalyzer(void);
int SetupRuleAnalyzer(void); void SetupEngineAnalysis(struct DetectEngineCtx_ *de_ctx, bool *, bool *);
void CleanupRuleAnalyzer (void); void CleanupEngineAnalysis(struct DetectEngineCtx_ *de_ctx);
int PerCentEncodingSetup (void); void EngineAnalysisFP(const struct DetectEngineCtx_ *de_ctx, const Signature *s, char *line);
void EngineAnalysisRules(
const struct DetectEngineCtx_ *de_ctx, const Signature *s, const char *line);
void EngineAnalysisRulesFailure(
const struct DetectEngineCtx_ *de_ctx, char *line, char *file, int lineno);
void EngineAnalysisFP(const DetectEngineCtx *de_ctx, void EngineAnalysisRules2(const struct DetectEngineCtx_ *de_ctx, const Signature *s);
const Signature *s, char *line);
void EngineAnalysisRules(const DetectEngineCtx *de_ctx,
const Signature *s, const char *line);
void EngineAnalysisRulesFailure(char *line, char *file, int lineno);
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s);
#endif /* __DETECT_ENGINE_ANALYZER_H__ */ #endif /* __DETECT_ENGINE_ANALYZER_H__ */

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2020 Open Information Security Foundation /* Copyright (C) 2007-2023 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -1896,7 +1896,7 @@ int SigAddressPrepareStage4(DetectEngineCtx *de_ctx)
SCReturnInt(0); SCReturnInt(0);
} }
extern int rule_engine_analysis_set; extern bool rule_engine_analysis_set;
/** \internal /** \internal
* \brief perform final per signature setup tasks * \brief perform final per signature setup tasks
* *

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Open Information Security Foundation /* Copyright (C) 2021-2023 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -50,8 +50,8 @@
extern int rule_reload; extern int rule_reload;
extern int engine_analysis; extern int engine_analysis;
static int fp_engine_analysis_set = 0; static bool fp_engine_analysis_set = false;
int rule_engine_analysis_set = 0; bool rule_engine_analysis_set = false;
/** /**
* \brief Create the path if default-rule-path was specified * \brief Create the path if default-rule-path was specified
@ -203,7 +203,7 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file,
} }
} }
if (rule_engine_analysis_set) { if (rule_engine_analysis_set) {
EngineAnalysisRulesFailure(line, sig_file, lineno - multiline); EngineAnalysisRulesFailure(de_ctx, line, sig_file, lineno - multiline);
} }
if (!de_ctx->sigerror_ok) { if (!de_ctx->sigerror_ok) {
bad++; bad++;
@ -301,8 +301,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
} }
if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) { if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
fp_engine_analysis_set = SetupFPAnalyzer(); SetupEngineAnalysis(de_ctx, &fp_engine_analysis_set, &rule_engine_analysis_set);
rule_engine_analysis_set = SetupRuleAnalyzer();
} }
/* ok, let's load signature files from the general config */ /* ok, let's load signature files from the general config */
@ -387,12 +386,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
end: end:
gettimeofday(&de_ctx->last_reload, NULL); gettimeofday(&de_ctx->last_reload, NULL);
if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) { if (RunmodeGetCurrent() == RUNMODE_ENGINE_ANALYSIS) {
if (rule_engine_analysis_set) { CleanupEngineAnalysis(de_ctx);
CleanupRuleAnalyzer();
}
if (fp_engine_analysis_set) {
CleanupFPAnalyzer();
}
} }
DetectParseDupSigHashFree(de_ctx); DetectParseDupSigHashFree(de_ctx);

@ -413,7 +413,7 @@ struct FBAnalyze {
uint32_t toggle_sids_size; uint32_t toggle_sids_size;
}; };
extern int rule_engine_analysis_set; extern bool rule_engine_analysis_set;
static void DetectFlowbitsAnalyzeDump(const DetectEngineCtx *de_ctx, static void DetectFlowbitsAnalyzeDump(const DetectEngineCtx *de_ctx,
struct FBAnalyze *array, uint32_t elements); struct FBAnalyze *array, uint32_t elements);

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2022 Open Information Security Foundation /* Copyright (C) 2007-2023 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -1021,6 +1021,9 @@ typedef struct DetectEngineCtx_ {
pcre2_code *reference_conf_regex; pcre2_code *reference_conf_regex;
pcre2_match_data *reference_conf_regex_match; pcre2_match_data *reference_conf_regex_match;
/* --engine-analysis */
struct EngineAnalysisCtx_ *ea;
} DetectEngineCtx; } DetectEngineCtx;
/* Engine groups profiles (low, medium, high, custom) */ /* Engine groups profiles (low, medium, high, custom) */

Loading…
Cancel
Save