Go to the documentation of this file.
55 static bool fp_engine_analysis_set =
false;
58 static char *DetectLoadCompleteSigPathWithKey(
61 const char *defaultpath = NULL;
65 if (sig_file == NULL) {
66 SCLogError(
"invalid sig_file argument - NULL");
78 if (default_rule_path) {
79 defaultpath = default_rule_path->
val;
108 return DetectLoadCompleteSigPathWithKey(
de_ctx,
"default-rule-path", sig_file);
120 int *badsigs,
int *skippedsigs,
const bool firewall_rule)
122 int good = 0, bad = 0, skipped = 0;
125 int lineno = 0, multiline = 0;
131 FILE *fp = fopen(sig_file,
"r");
135 sig_file, strerror(errno));
139 while(fgets(line +
offset, (
int)
sizeof(line) -
offset, fp) != NULL) {
141 size_t len = strlen(line);
144 if (line[0] ==
'\n' || line [0] ==
'\r' || line[0] ==
' ' || line[0] ==
'#' || line[0] ==
'\t')
148 while (
len > 0 && isspace((
unsigned char)line[--
len]));
149 if (line[
len] ==
'\\') {
152 if (
offset <
sizeof(line) - 1) {
162 if (
len > 0 && (line[
len - 1] ==
'\n' || line[
len - 1] ==
'\r')) {
163 line[
len - 1] =
'\0';
179 if (fp_engine_analysis_set) {
190 SCLogError(
"error parsing signature \"%s\" from "
191 "file %s at line %" PRId32
"",
192 line, sig_file, lineno - multiline);
196 "file %s at line %" PRId32
"",
197 line, sig_file, lineno - multiline);
210 SCLogInfo(
"Skipping signature due to missing requirements: %s from file %s at line "
212 line, sig_file, lineno - multiline);
222 *skippedsigs = skipped;
233 int *good_sigs,
int *bad_sigs,
int *skipped_sigs)
237 if (pattern == NULL) {
244 r = glob(pattern, 0, NULL, &files);
246 if (r == GLOB_NOMATCH) {
247 SCLogWarning(
"No rule files match the pattern %s", pattern);
252 SCLogError(
"error expanding template %s: %s", pattern, strerror(errno));
256 for (
size_t i = 0; i < (size_t)files.gl_pathc; i++) {
257 char *fname = files.gl_pathv[i];
258 if (strcmp(
"/dev/null", fname) == 0)
261 char *fname = pattern;
262 if (strcmp(
"/dev/null", fname) == 0)
270 r = DetectLoadSigFile(
de_ctx, fname, good_sigs, bad_sigs, skipped_sigs,
false);
291 int32_t good_sigs = 0;
292 int32_t bad_sigs = 0;
293 int32_t skipped_sigs = 0;
299 &bad_sigs, &skipped_sigs,
true);
302 if (ret != 0 || bad_sigs != 0 || skipped_sigs != 0) {
308 if (good_sigs == 0) {
311 SCLogNotice(
"fw: %d rules loaded from %s.", good_sigs,
320 if (default_fw_rule_path == NULL) {
321 SCLogNotice(
"fw: firewall-rule-path not defined, skip loading firewall rules");
325 if (rule_files == NULL) {
326 SCLogNotice(
"fw: firewall-rule-files not defined, skip loading firewall rules");
332 int32_t good_sigs = 0;
333 int32_t bad_sigs = 0;
334 int32_t skipped_sigs = 0;
336 char *sfile = DetectLoadCompleteSigPathWithKey(
de_ctx,
"firewall-rule-path", file->
val);
337 SCLogNotice(
"fw: rule file full path \"%s\"", sfile);
339 int ret = DetectLoadSigFile(
de_ctx, sfile, &good_sigs, &bad_sigs, &skipped_sigs,
true);
343 if (ret != 0 || bad_sigs != 0 || skipped_sigs != 0) {
349 if (good_sigs == 0) {
352 SCLogNotice(
"fw: %d rules loaded from %s.", good_sigs, file->
val);
377 char varname[128] =
"rule-files";
380 int skipped_sigs = 0;
391 if (LoadFirewallRuleFiles(
de_ctx) < 0) {
402 goto skip_regular_rules;
407 if (!(sig_file != NULL && sig_file_exclusive)) {
409 if (rule_files != NULL) {
411 SCLogWarning(
"Invalid rule-files configuration section: "
412 "expected a list of filenames.");
416 good_sigs = bad_sigs = skipped_sigs = 0;
417 ret = ProcessSigFiles(
418 de_ctx, sfile, sig_stat, &good_sigs, &bad_sigs, &skipped_sigs);
427 if (good_sigs == 0) {
436 if (sig_file != NULL) {
437 ret = ProcessSigFiles(
de_ctx, sig_file, sig_stat, &good_sigs, &bad_sigs, &skipped_sigs);
445 if (good_sigs == 0) {
455 "%d rule files specified, but no rules were loaded!", sig_stat->
total_files);
463 SCLogInfo(
"tenant id %d: %" PRId32
" rule files processed. %" PRId32
464 " rules successfully loaded, %" PRId32
" rules failed, %" PRId32
469 SCLogInfo(
"%" PRId32
" rule files processed. %" PRId32
470 " rules successfully loaded, %" PRId32
" rules failed, %" PRId32
517 static int cur_loader = 0;
518 static void TmThreadWakeupDetectLoaderThreads(
void);
525 if (loader_id == -1) {
526 loader_id = cur_loader;
528 if (cur_loader >= num_loaders)
531 if (loader_id >= num_loaders || loader_id < 0) {
549 TmThreadWakeupDetectLoaderThreads();
551 SCLogDebug(
"%d %p %p", loader_id, Func, func_ctx);
561 for (
int i = 0; i < num_loaders; i++) {
579 if (loader->
result != 0) {
586 SCLogError(
"%d loaders reported errors", errors);
595 memset(loader, 0x00,
sizeof(*loader));
605 if (setting < 1 || setting > 1024) {
606 FatalError(
"invalid multi-detect.loaders setting %" PRIdMAX, setting);
609 num_loaders = (int32_t)setting;
610 SCLogInfo(
"using %d detect loader threads", num_loaders);
616 for (
int i = 0; i < num_loaders; i++) {
617 DetectLoaderInit(&loaders[i]);
624 static void TmThreadWakeupDetectLoaderThreads(
void)
627 for (
int i = 0; i <
TVT_MAX; i++) {
630 if (strncmp(
tv->
name,
"DL#",3) == 0) {
648 for (
int i = 0; i <
TVT_MAX; i++) {
651 if (strncmp(
tv->
name,
"DL#",3) == 0)
666 static TmEcode DetectLoaderThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
738 for (
int i = 0; i < num_loaders; i++) {
743 if (tv_loader == NULL) {
@ RUNMODE_ENGINE_ANALYSIS
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
void DetectLoaderThreadSpawn(void)
spawn the detect loader manager thread
char * PathMergeAlloc(const char *const dir, const char *const fname)
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exclusive)
Load signatures.
const char * firewall_rule_file_exclusive
void SetupEngineAnalysis(DetectEngineCtx *de_ctx, bool *fp_analysis, bool *rule_analysis)
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
void TmThreadWaitForFlag(ThreadVars *tv, uint32_t flags)
Waits till the specified flag(s) is(are) set. We don't bother if the kill flag has been set or not on...
SC_ATOMIC_DECLARE(int, detect_loader_cnt)
struct HtpBodyChunk_ * next
void TmThreadContinueDetectLoaderThreads(void)
Unpauses all threads present in tv_root.
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
main detection engine ctx
#define TAILQ_EMPTY(head)
#define TAILQ_FOREACH(var, head, field)
void(* LoaderFreeFunc)(void *ctx)
void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
De-registers all the signature ordering functions registered.
ThreadVars * tv_root[TVT_MAX]
int(* LoaderFunc)(void *ctx, int loader_id)
#define TAILQ_INSERT_TAIL(head, elm, field)
void DetectParseDupSigHashFree(DetectEngineCtx *de_ctx)
Frees the hash table that is used to cull duplicate sigs.
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
int SCThresholdConfInitContext(DetectEngineCtx *de_ctx)
Inits the context to be used by the Threshold Config parsing API.
void EngineAnalysisRulesFailure(const DetectEngineCtx *de_ctx, const char *line, const char *file, int lineno)
#define TM_THREAD_NAME_MAX
int SCConfNodeIsSequence(const SCConfNode *node)
Check if a node is a sequence or node.
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
void TmThreadContinue(ThreadVars *tv)
Unpauses a thread.
SCDetectRequiresStatus * requirements
#define TAILQ_REMOVE(head, elm, field)
SCRunMode SCRunmodeGet(void)
Get the current run mode.
bool rule_engine_analysis_set
int SigStringAppend(SigFileLoaderStat *sig_stats, const char *sig_file, const char *sig_str, const char *sig_error, int line)
Append a new list member to SigString list.
void DetectLoadersInit(void)
void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
Orders the signatures.
#define SCMutexUnlock(mut)
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
struct timeval last_reload
Per thread variable structure.
TmEcode(* Management)(ThreadVars *, void *)
void SCSigRegisterSignatureOrderingFuncs(DetectEngineCtx *de_ctx)
Lets you register the Signature ordering functions. The order in which the functions are registered s...
#define SCLogWarning(...)
Macro used to log WARNING messages.
void EngineAnalysisRules(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
Prints analysis of loaded rules.
struct ThreadVars_ * next
const char * thread_name_detect_loader
void TmModuleDetectLoaderRegister(void)
#define SCCtrlMutexLock(mut)
TmModule tmm_modules[TMM_SIZE]
struct DetectLoaderThreadData_ DetectLoaderThreadData
#define DETECT_MAX_RULE_SIZE
int(* CacheRuleset)(MpmConfig *)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
#define SCMutexInit(mut, mutattrs)
int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx, LoaderFreeFunc FreeFunc)
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
#define SCCtrlMutexUnlock(mut)
SigFileLoaderStat sig_stat
bool TmThreadsWaitForUnpause(ThreadVars *tv)
Wait for a thread to become unpaused.
void CleanupEngineAnalysis(DetectEngineCtx *de_ctx)
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
ThreadVars * TmThreadCreateCmdThreadByName(const char *name, const char *module, int mucond)
Creates and returns the TV instance for a Command thread (CMD). This function supports only custom sl...
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
#define SCLogError(...)
Macro used to log ERROR messages.
int PathIsRelative(const char *path)
Check if a path is relative.
int DetectLoadersSync(void)
wait for loader tasks to complete
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Signature loader statistics.
Signature * DetectFirewallRuleAppendNew(DetectEngineCtx *de_ctx, const char *sigstr)
Parse and append a Signature into the Detection Engine Context signature list.
#define TM_FLAG_MANAGEMENT_TM