suricata
detect-engine-loader.c
Go to the documentation of this file.
1 /* Copyright (C) 2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  */
23 
24 #include "suricata-common.h"
25 #include "suricata.h"
26 #include "conf.h"
27 #include "detect.h"
28 #include "detect-parse.h"
29 
30 #include "runmodes.h"
31 #include "threads.h"
32 #include "threadvars.h"
33 #include "tm-threads.h"
34 #include "queue.h"
35 #include "util-signal.h"
36 
37 #include "detect-engine-loader.h"
38 #include "detect-engine-build.h"
39 #include "detect-engine-analyzer.h"
40 #include "detect-engine-mpm.h"
41 #include "detect-engine-sigorder.h"
42 
43 #include "util-detect.h"
44 #include "util-threshold-config.h"
45 #include "util-path.h"
46 
47 #ifdef HAVE_GLOB_H
48 #include <glob.h>
49 #endif
50 
51 extern int rule_reload;
52 extern int engine_analysis;
53 static int fp_engine_analysis_set = 0;
55 
56 /**
57  * \brief Create the path if default-rule-path was specified
58  * \param sig_file The name of the file
59  * \retval str Pointer to the string path + sig_file
60  */
61 char *DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
62 {
63  const char *defaultpath = NULL;
64  char *path = NULL;
65  char varname[128];
66 
67  if (sig_file == NULL) {
68  SCLogError("invalid sig_file argument - NULL");
69  return NULL;
70  }
71 
72  /* If we have a configuration prefix, only use it if the primary configuration node
73  * is not marked as final, as that means it was provided on the command line with
74  * a --set. */
75  ConfNode *default_rule_path = ConfGetNode("default-rule-path");
76  if ((!default_rule_path || !default_rule_path->final) && strlen(de_ctx->config_prefix) > 0) {
77  snprintf(varname, sizeof(varname), "%s.default-rule-path",
79  default_rule_path = ConfGetNode(varname);
80  }
81  if (default_rule_path) {
82  defaultpath = default_rule_path->val;
83  }
84 
85  /* Path not specified */
86  if (PathIsRelative(sig_file)) {
87  if (defaultpath) {
88  SCLogDebug("Default path: %s", defaultpath);
89  size_t path_len = sizeof(char) * (strlen(defaultpath) +
90  strlen(sig_file) + 2);
91  path = SCMalloc(path_len);
92  if (unlikely(path == NULL))
93  return NULL;
94  strlcpy(path, defaultpath, path_len);
95 #if defined OS_WIN32 || defined __CYGWIN__
96  if (path[strlen(path) - 1] != '\\')
97  strlcat(path, "\\\\", path_len);
98 #else
99  if (path[strlen(path) - 1] != '/')
100  strlcat(path, "/", path_len);
101 #endif
102  strlcat(path, sig_file, path_len);
103  } else {
104  path = SCStrdup(sig_file);
105  if (unlikely(path == NULL))
106  return NULL;
107  }
108  } else {
109  path = SCStrdup(sig_file);
110  if (unlikely(path == NULL))
111  return NULL;
112  }
113  return path;
114 }
115 
116 /**
117  * \brief Load a file with signatures
118  * \param de_ctx Pointer to the detection engine context
119  * \param sig_file Filename to load signatures from
120  * \param goodsigs_tot Will store number of valid signatures in the file
121  * \param badsigs_tot Will store number of invalid signatures in the file
122  * \retval 0 on success, -1 on error
123  */
124 static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file,
125  int *goodsigs, int *badsigs)
126 {
127  Signature *sig = NULL;
128  int good = 0, bad = 0;
129  char line[DETECT_MAX_RULE_SIZE] = "";
130  size_t offset = 0;
131  int lineno = 0, multiline = 0;
132 
133  (*goodsigs) = 0;
134  (*badsigs) = 0;
135 
136  FILE *fp = fopen(sig_file, "r");
137  if (fp == NULL) {
138  SCLogError("opening rule file %s:"
139  " %s.",
140  sig_file, strerror(errno));
141  return -1;
142  }
143 
144  while(fgets(line + offset, (int)sizeof(line) - offset, fp) != NULL) {
145  lineno++;
146  size_t len = strlen(line);
147 
148  /* ignore comments and empty lines */
149  if (line[0] == '\n' || line [0] == '\r' || line[0] == ' ' || line[0] == '#' || line[0] == '\t')
150  continue;
151 
152  /* Check for multiline rules. */
153  while (len > 0 && isspace((unsigned char)line[--len]));
154  if (line[len] == '\\') {
155  multiline++;
156  offset = len;
157  if (offset < sizeof(line) - 1) {
158  /* We have room for more. */
159  continue;
160  }
161  /* No more room in line buffer, continue, rule will fail
162  * to parse. */
163  }
164 
165  /* Check if we have a trailing newline, and remove it */
166  len = strlen(line);
167  if (len > 0 && (line[len - 1] == '\n' || line[len - 1] == '\r')) {
168  line[len - 1] = '\0';
169  }
170 
171  /* Reset offset. */
172  offset = 0;
173 
174  de_ctx->rule_file = sig_file;
175  de_ctx->rule_line = lineno - multiline;
176 
177  sig = DetectEngineAppendSig(de_ctx, line);
178  if (sig != NULL) {
179  if (rule_engine_analysis_set || fp_engine_analysis_set) {
180  RetrieveFPForSig(de_ctx, sig);
181  if (fp_engine_analysis_set) {
182  EngineAnalysisFP(de_ctx, sig, line);
183  }
185  EngineAnalysisRules(de_ctx, sig, line);
186  }
187  }
188  SCLogDebug("signature %"PRIu32" loaded", sig->id);
189  good++;
190  } else {
191  if (!de_ctx->sigerror_silent) {
192  SCLogError("error parsing signature \"%s\" from "
193  "file %s at line %" PRId32 "",
194  line, sig_file, lineno - multiline);
195 
196  if (!SigStringAppend(&de_ctx->sig_stat, sig_file, line, de_ctx->sigerror, (lineno - multiline))) {
197  SCLogError("Error adding sig \"%s\" from "
198  "file %s at line %" PRId32 "",
199  line, sig_file, lineno - multiline);
200  }
201  if (de_ctx->sigerror) {
202  de_ctx->sigerror = NULL;
203  }
204  }
206  EngineAnalysisRulesFailure(line, sig_file, lineno - multiline);
207  }
208  if (!de_ctx->sigerror_ok) {
209  bad++;
210  }
211  }
212  multiline = 0;
213  }
214  fclose(fp);
215 
216  *goodsigs = good;
217  *badsigs = bad;
218  return 0;
219 }
220 
221 /**
222  * \brief Expands wildcards and reads signatures from each matching file
223  * \param de_ctx Pointer to the detection engine context
224  * \param sig_file Filename (or pattern) holding signatures
225  * \retval -1 on error
226  */
227 static int ProcessSigFiles(DetectEngineCtx *de_ctx, char *pattern,
228  SigFileLoaderStat *st, int *good_sigs, int *bad_sigs)
229 {
230  int r = 0;
231 
232  if (pattern == NULL) {
233  SCLogError("opening rule file null");
234  return -1;
235  }
236 
237 #ifdef HAVE_GLOB_H
238  glob_t files;
239  r = glob(pattern, 0, NULL, &files);
240 
241  if (r == GLOB_NOMATCH) {
242  SCLogWarning("No rule files match the pattern %s", pattern);
243  ++(st->bad_files);
244  ++(st->total_files);
245  return -1;
246  } else if (r != 0) {
247  SCLogError("error expanding template %s: %s", pattern, strerror(errno));
248  return -1;
249  }
250 
251  for (size_t i = 0; i < (size_t)files.gl_pathc; i++) {
252  char *fname = files.gl_pathv[i];
253  if (strcmp("/dev/null", fname) == 0)
254  continue;
255 #else
256  char *fname = pattern;
257  if (strcmp("/dev/null", fname) == 0)
258  return 0;
259 #endif
260  SCLogConfig("Loading rule file: %s", fname);
261  r = DetectLoadSigFile(de_ctx, fname, good_sigs, bad_sigs);
262  if (r < 0) {
263  ++(st->bad_files);
264  }
265 
266  ++(st->total_files);
267 
268  st->good_sigs_total += *good_sigs;
269  st->bad_sigs_total += *bad_sigs;
270 
271 #ifdef HAVE_GLOB_H
272  }
273  globfree(&files);
274 #endif
275  return r;
276 }
277 
278 /**
279  * \brief Load signatures
280  * \param de_ctx Pointer to the detection engine context
281  * \param sig_file Filename (or pattern) holding signatures
282  * \param sig_file_exclusive File passed in 'sig_file' should be loaded exclusively.
283  * \retval -1 on error
284  */
285 int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_exclusive)
286 {
287  SCEnter();
288 
289  ConfNode *rule_files;
290  ConfNode *file = NULL;
291  SigFileLoaderStat *sig_stat = &de_ctx->sig_stat;
292  int ret = 0;
293  char *sfile = NULL;
294  char varname[128] = "rule-files";
295  int good_sigs = 0;
296  int bad_sigs = 0;
297 
298  if (strlen(de_ctx->config_prefix) > 0) {
299  snprintf(varname, sizeof(varname), "%s.rule-files",
301  }
302 
304  fp_engine_analysis_set = SetupFPAnalyzer();
306  }
307 
308  /* ok, let's load signature files from the general config */
309  if (!(sig_file != NULL && sig_file_exclusive == TRUE)) {
310  rule_files = ConfGetNode(varname);
311  if (rule_files != NULL) {
312  if (!ConfNodeIsSequence(rule_files)) {
313  SCLogWarning("Invalid rule-files configuration section: "
314  "expected a list of filenames.");
315  }
316  else {
317  TAILQ_FOREACH(file, &rule_files->head, next) {
318  sfile = DetectLoadCompleteSigPath(de_ctx, file->val);
319  good_sigs = bad_sigs = 0;
320  ret = ProcessSigFiles(de_ctx, sfile, sig_stat, &good_sigs, &bad_sigs);
321  SCFree(sfile);
322 
323  if (de_ctx->failure_fatal && ret != 0) {
324  /* Some rules failed to load, just exit as
325  * errors would have already been logged. */
326  exit(EXIT_FAILURE);
327  }
328 
329  if (good_sigs == 0) {
330  SCLogConfig("No rules loaded from %s.", file->val);
331  }
332  }
333  }
334  }
335  }
336 
337  /* If a Signature file is specified from command-line, parse it too */
338  if (sig_file != NULL) {
339  ret = ProcessSigFiles(de_ctx, sig_file, sig_stat, &good_sigs, &bad_sigs);
340 
341  if (ret != 0) {
342  if (de_ctx->failure_fatal == 1) {
343  exit(EXIT_FAILURE);
344  }
345  }
346 
347  if (good_sigs == 0) {
348  SCLogConfig("No rules loaded from %s", sig_file);
349  }
350  }
351 
352  /* now we should have signatures to work with */
353  if (sig_stat->good_sigs_total <= 0) {
354  if (sig_stat->total_files > 0) {
355  SCLogWarning(
356  "%d rule files specified, but no rules were loaded!", sig_stat->total_files);
357  } else {
358  SCLogInfo("No signatures supplied.");
359  goto end;
360  }
361  } else {
362  /* we report the total of files and rules successfully loaded and failed */
363  SCLogInfo("%" PRId32 " rule files processed. %" PRId32 " rules successfully loaded, %" PRId32 " rules failed",
364  sig_stat->total_files, sig_stat->good_sigs_total, sig_stat->bad_sigs_total);
365  }
366 
367  if ((sig_stat->bad_sigs_total || sig_stat->bad_files) && de_ctx->failure_fatal) {
368  ret = -1;
369  goto end;
370  }
371 
375 
377  ret = -1;
378  goto end;
379  }
380 
381  /* Setup the signature group lookup structure and pattern matchers */
382  if (SigGroupBuild(de_ctx) < 0)
383  goto end;
384 
385  ret = 0;
386 
387  end:
388  gettimeofday(&de_ctx->last_reload, NULL);
392  }
393  if (fp_engine_analysis_set) {
395  }
396  }
397 
399  SCReturnInt(ret);
400 }
401 
402 #define NLOADERS 4
403 static DetectLoaderControl *loaders = NULL;
404 static int cur_loader = 0;
406 static int num_loaders = NLOADERS;
407 
408 /** \param loader -1 for auto select
409  * \retval loader_id or negative in case of error */
410 int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx)
411 {
412  if (loader_id == -1) {
413  loader_id = cur_loader;
414  cur_loader++;
415  if (cur_loader >= num_loaders)
416  cur_loader = 0;
417  }
418  if (loader_id >= num_loaders || loader_id < 0) {
419  return -ERANGE;
420  }
421 
422  DetectLoaderControl *loader = &loaders[loader_id];
423 
424  DetectLoaderTask *t = SCCalloc(1, sizeof(*t));
425  if (t == NULL)
426  return -ENOMEM;
427 
428  t->Func = Func;
429  t->ctx = func_ctx;
430 
431  SCMutexLock(&loader->m);
432  TAILQ_INSERT_TAIL(&loader->task_list, t, next);
433  SCMutexUnlock(&loader->m);
434 
436 
437  SCLogDebug("%d %p %p", loader_id, Func, func_ctx);
438  return loader_id;
439 }
440 
441 /** \brief wait for loader tasks to complete
442  * \retval result 0 for ok, -1 for errors */
444 {
445  SCLogDebug("waiting");
446  int errors = 0;
447  int i;
448  for (i = 0; i < num_loaders; i++) {
449  int done = 0;
450  DetectLoaderControl *loader = &loaders[i];
451  while (!done) {
452  SCMutexLock(&loader->m);
453  if (TAILQ_EMPTY(&loader->task_list)) {
454  done = 1;
455  }
456  SCMutexUnlock(&loader->m);
457  }
458  SCMutexLock(&loader->m);
459  if (loader->result != 0) {
460  errors++;
461  loader->result = 0;
462  }
463  SCMutexUnlock(&loader->m);
464 
465  }
466  if (errors) {
467  SCLogError("%d loaders reported errors", errors);
468  return -1;
469  }
470  SCLogDebug("done");
471  return 0;
472 }
473 
474 static void DetectLoaderInit(DetectLoaderControl *loader)
475 {
476  memset(loader, 0x00, sizeof(*loader));
477  SCMutexInit(&loader->m, NULL);
478  TAILQ_INIT(&loader->task_list);
479 }
480 
482 {
483  intmax_t setting = NLOADERS;
484  (void)ConfGetInt("multi-detect.loaders", &setting);
485 
486  if (setting < 1 || setting > 1024) {
487  SCLogError("invalid multi-detect.loaders setting %" PRIdMAX, setting);
488  exit(EXIT_FAILURE);
489  }
490  num_loaders = (int32_t)setting;
491 
492  SCLogInfo("using %d detect loader threads", num_loaders);
493 
494  BUG_ON(loaders != NULL);
495  loaders = SCCalloc(num_loaders, sizeof(DetectLoaderControl));
496  BUG_ON(loaders == NULL);
497 
498  int i;
499  for (i = 0; i < num_loaders; i++) {
500  DetectLoaderInit(&loaders[i]);
501  }
502 }
503 
504 /**
505  * \brief Unpauses all threads present in tv_root
506  */
508 {
509  ThreadVars *tv = NULL;
510  int i = 0;
511 
513  for (i = 0; i < TVT_MAX; i++) {
514  tv = tv_root[i];
515  while (tv != NULL) {
516  if (strncmp(tv->name,"DL#",3) == 0) {
517  BUG_ON(tv->ctrl_cond == NULL);
518  pthread_cond_broadcast(tv->ctrl_cond);
519  }
520  tv = tv->next;
521  }
522  }
524 
525  return;
526 }
527 
528 /**
529  * \brief Unpauses all threads present in tv_root
530  */
532 {
533  ThreadVars *tv = NULL;
534  int i = 0;
535 
537  for (i = 0; i < TVT_MAX; i++) {
538  tv = tv_root[i];
539  while (tv != NULL) {
540  if (strncmp(tv->name,"DL#",3) == 0)
542 
543  tv = tv->next;
544  }
545  }
547 
548  return;
549 }
550 
551 
552 SC_ATOMIC_DECLARE(int, detect_loader_cnt);
553 
554 typedef struct DetectLoaderThreadData_ {
555  uint32_t instance;
557 
558 static TmEcode DetectLoaderThreadInit(ThreadVars *t, const void *initdata, void **data)
559 {
561  if (ftd == NULL)
562  return TM_ECODE_FAILED;
563 
564  ftd->instance = SC_ATOMIC_ADD(detect_loader_cnt, 1); /* id's start at 0 */
565  SCLogDebug("detect loader instance %u", ftd->instance);
566 
567  /* pass thread data back to caller */
568  *data = ftd;
569 
570  return TM_ECODE_OK;
571 }
572 
573 static TmEcode DetectLoaderThreadDeinit(ThreadVars *t, void *data)
574 {
575  SCFree(data);
576  return TM_ECODE_OK;
577 }
578 
579 
580 static TmEcode DetectLoader(ThreadVars *th_v, void *thread_data)
581 {
582  DetectLoaderThreadData *ftd = (DetectLoaderThreadData *)thread_data;
583  BUG_ON(ftd == NULL);
584 
586  SCLogDebug("loader thread started");
587  while (1)
588  {
589  if (TmThreadsCheckFlag(th_v, THV_PAUSE)) {
593  }
594 
595  /* see if we have tasks */
596 
597  DetectLoaderControl *loader = &loaders[ftd->instance];
598  SCMutexLock(&loader->m);
599 
600  DetectLoaderTask *task = NULL, *tmptask = NULL;
601  TAILQ_FOREACH_SAFE(task, &loader->task_list, next, tmptask) {
602  int r = task->Func(task->ctx, ftd->instance);
603  loader->result |= r;
604  TAILQ_REMOVE(&loader->task_list, task, next);
605  SCFree(task->ctx);
606  SCFree(task);
607  }
608 
609  SCMutexUnlock(&loader->m);
610 
611  if (TmThreadsCheckFlag(th_v, THV_KILL)) {
612  break;
613  }
614 
615  /* just wait until someone wakes us up */
617  SCCtrlCondWait(th_v->ctrl_cond, th_v->ctrl_mutex);
619 
620  SCLogDebug("woke up...");
621  }
622 
626 
627  return TM_ECODE_OK;
628 }
629 
630 /** \brief spawn the detect loader manager thread */
632 {
633  int i;
634  for (i = 0; i < num_loaders; i++) {
635  ThreadVars *tv_loader = NULL;
636 
637  char name[TM_THREAD_NAME_MAX];
638  snprintf(name, sizeof(name), "%s#%02d", thread_name_detect_loader, i+1);
639 
640  tv_loader = TmThreadCreateCmdThreadByName(name,
641  "DetectLoader", 1);
642  BUG_ON(tv_loader == NULL);
643 
644  if (tv_loader == NULL) {
645  printf("ERROR: TmThreadsCreate failed\n");
646  exit(1);
647  }
648  if (TmThreadSpawn(tv_loader) != TM_ECODE_OK) {
649  printf("ERROR: TmThreadSpawn failed\n");
650  exit(1);
651  }
652  }
653  return;
654 }
655 
657 {
658  tmm_modules[TMM_DETECTLOADER].name = "DetectLoader";
659  tmm_modules[TMM_DETECTLOADER].ThreadInit = DetectLoaderThreadInit;
660  tmm_modules[TMM_DETECTLOADER].ThreadDeinit = DetectLoaderThreadDeinit;
661  tmm_modules[TMM_DETECTLOADER].Management = DetectLoader;
664  SCLogDebug("%s registered", tmm_modules[TMM_DETECTLOADER].name);
665 
666  SC_ATOMIC_INIT(detect_loader_cnt);
667 }
TmModule_::cap_flags
uint8_t cap_flags
Definition: tm-modules.h:73
DetectLoaderControl_
Definition: detect-engine-loader.h:42
SigFileLoaderStat_::bad_files
int bad_files
Definition: detect.h:765
tm-threads.h
ConfGetInt
int ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:397
SCCtrlCondWait
#define SCCtrlCondWait
Definition: threads-debug.h:386
len
uint8_t len
Definition: app-layer-dnp3.h:2
TmThreadSpawn
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
Definition: tm-threads.c:1648
DetectLoaderThreadSpawn
void DetectLoaderThreadSpawn(void)
spawn the detect loader manager thread
Definition: detect-engine-loader.c:631
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
ThreadVars_::name
char name[16]
Definition: threadvars.h:64
TAILQ_INIT
#define TAILQ_INIT(head)
Definition: queue.h:262
SC_ATOMIC_INIT
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
Definition: util-atomic.h:315
ConfNode_::val
char * val
Definition: conf.h:34
DetectEngineCtx_::rule_file
char * rule_file
Definition: detect.h:895
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectLoaderTask_::ctx
void * ctx
Definition: detect-engine-loader.h:38
DetectEngineCtx_::sigerror_silent
bool sigerror_silent
Definition: detect.h:897
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
TmThreadWakeupDetectLoaderThreads
void TmThreadWakeupDetectLoaderThreads(void)
Unpauses all threads present in tv_root.
Definition: detect-engine-loader.c:507
TmThreadsSetFlag
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
Definition: tm-threads.c:99
CleanupFPAnalyzer
void CleanupFPAnalyzer(void)
Definition: detect-engine-analyzer.c:395
TmThreadWaitForFlag
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...
Definition: tm-threads.c:1767
SC_ATOMIC_DECLARE
SC_ATOMIC_DECLARE(int, detect_loader_cnt)
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
THV_DEINIT
#define THV_DEINIT
Definition: threadvars.h:44
ConfGetNode
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Definition: conf.c:181
threads.h
TmThreadContinueDetectLoaderThreads
void TmThreadContinueDetectLoaderThreads(void)
Unpauses all threads present in tv_root.
Definition: detect-engine-loader.c:531
SC_ATOMIC_ADD
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
Definition: util-atomic.h:333
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:801
THV_RUNNING
#define THV_RUNNING
Definition: threadvars.h:54
TAILQ_EMPTY
#define TAILQ_EMPTY(head)
Definition: queue.h:248
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:252
SCSigSignatureOrderingModuleCleanup
void SCSigSignatureOrderingModuleCleanup(DetectEngineCtx *de_ctx)
De-registers all the signature ordering functions registered.
Definition: detect-engine-sigorder.c:827
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
tv_root
ThreadVars * tv_root[TVT_MAX]
Definition: tm-threads.c:80
LoaderFunc
int(* LoaderFunc)(void *ctx, int loader_id)
Definition: detect-engine-loader.h:34
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:294
DetectParseDupSigHashFree
void DetectParseDupSigHashFree(DetectEngineCtx *de_ctx)
Frees the hash table that is used to cull duplicate sigs.
Definition: detect-parse.c:2312
DetectEngineCtx_::sigerror_ok
bool sigerror_ok
Definition: detect.h:898
DetectLoaderControl_::result
int result
Definition: detect-engine-loader.h:44
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2493
SCThresholdConfInitContext
int SCThresholdConfInitContext(DetectEngineCtx *de_ctx)
Inits the context to be used by the Threshold Config parsing API.
Definition: util-threshold-config.c:241
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
THV_PAUSE
#define THV_PAUSE
Definition: threadvars.h:37
CleanupRuleAnalyzer
void CleanupRuleAnalyzer(void)
Definition: detect-engine-analyzer.c:419
TM_THREAD_NAME_MAX
#define TM_THREAD_NAME_MAX
Definition: tm-threads.h:49
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
TmModule_::ThreadDeinit
TmEcode(* ThreadDeinit)(ThreadVars *, void *)
Definition: tm-modules.h:49
THV_RUNNING_DONE
#define THV_RUNNING_DONE
Definition: threadvars.h:45
TmThreadsUnsetFlag
void TmThreadsUnsetFlag(ThreadVars *tv, uint32_t flag)
Unset a thread flag.
Definition: tm-threads.c:107
util-signal.h
NLOADERS
#define NLOADERS
Definition: detect-engine-loader.c:402
TmThreadContinue
void TmThreadContinue(ThreadVars *tv)
Unpauses a thread.
Definition: tm-threads.c:1781
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:312
SigStringAppend
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.
Definition: util-detect.c:104
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
strlcat
size_t strlcat(char *, const char *src, size_t siz)
Definition: util-strlcatu.c:45
DetectLoadersInit
void DetectLoadersInit(void)
Definition: detect-engine-loader.c:481
SCSigOrderSignatures
void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
Orders the signatures.
Definition: detect-engine-sigorder.c:735
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
SigLoadSignatures
int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_exclusive)
Load signatures.
Definition: detect-engine-loader.c:285
DetectEngineCtx_::last_reload
struct timeval last_reload
Definition: detect.h:973
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
TmThreadTestThreadUnPaused
void TmThreadTestThreadUnPaused(ThreadVars *tv)
Tests if the thread represented in the arg has been unpaused or not.
Definition: tm-threads.c:1749
TmModule_::Management
TmEcode(* Management)(ThreadVars *, void *)
Definition: tm-modules.h:65
THV_KILL
#define THV_KILL
Definition: threadvars.h:39
ConfNode_::final
int final
Definition: conf.h:39
SCSigRegisterSignatureOrderingFuncs
void SCSigRegisterSignatureOrderingFuncs(DetectEngineCtx *de_ctx)
Lets you register the Signature ordering functions. The order in which the functions are registered s...
Definition: detect-engine-sigorder.c:807
rule_engine_analysis_set
int rule_engine_analysis_set
Definition: detect-engine-loader.c:54
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
EngineAnalysisRules
void EngineAnalysisRules(const DetectEngineCtx *de_ctx, const Signature *s, const char *line)
Prints analysis of loaded rules.
Definition: detect-engine-analyzer.c:1256
rule_reload
int rule_reload
engine_analysis
int engine_analysis
TRUE
#define TRUE
Definition: suricata-common.h:33
ThreadVars_::next
struct ThreadVars_ * next
Definition: threadvars.h:124
DetectLoaderThreadData_::instance
uint32_t instance
Definition: detect-engine-loader.c:555
SigFileLoaderStat_::bad_sigs_total
int bad_sigs_total
Definition: detect.h:768
util-detect.h
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:295
tv_root_lock
SCMutex tv_root_lock
Definition: tm-threads.c:83
thread_name_detect_loader
const char * thread_name_detect_loader
Definition: runmodes.c:87
TmModuleDetectLoaderRegister
void TmModuleDetectLoaderRegister(void)
Definition: detect-engine-loader.c:656
SCCtrlMutexLock
#define SCCtrlMutexLock(mut)
Definition: threads-debug.h:376
detect-engine-build.h
tmm_modules
TmModule tmm_modules[TMM_SIZE]
Definition: tm-modules.c:33
DetectLoaderThreadData
struct DetectLoaderThreadData_ DetectLoaderThreadData
ThreadVars_::ctrl_cond
SCCtrlCondT * ctrl_cond
Definition: threadvars.h:132
conf.h
DETECT_MAX_RULE_SIZE
#define DETECT_MAX_RULE_SIZE
Definition: detect.h:45
TmEcode
TmEcode
Definition: tm-threads-common.h:83
DetectLoaderThreadData_
Definition: detect-engine-loader.c:554
queue.h
TmModule_::name
const char * name
Definition: tm-modules.h:44
runmodes.h
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:224
TAILQ_FOREACH_SAFE
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:329
SCMutexInit
#define SCMutexInit(mut, mutattrs)
Definition: threads-debug.h:116
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1934
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:925
detect-engine-analyzer.h
DetectLoaderTask_
Definition: detect-engine-loader.h:36
THV_PAUSED
#define THV_PAUSED
Definition: threadvars.h:38
THV_INIT_DONE
#define THV_INIT_DONE
Definition: threadvars.h:36
SCCtrlMutexUnlock
#define SCCtrlMutexUnlock(mut)
Definition: threads-debug.h:378
DetectEngineCtx_::sig_stat
SigFileLoaderStat sig_stat
Definition: detect.h:976
EngineAnalysisFP
void EngineAnalysisFP(const DetectEngineCtx *de_ctx, const Signature *s, char *line)
Definition: detect-engine-analyzer.c:157
suricata-common.h
TMM_DETECTLOADER
@ TMM_DETECTLOADER
Definition: tm-threads-common.h:75
util-path.h
DetectLoaderControl_::m
SCMutex m
Definition: detect-engine-loader.h:45
SigFileLoaderStat_::total_files
int total_files
Definition: detect.h:766
ConfNodeIsSequence
int ConfNodeIsSequence(const ConfNode *node)
Check if a node is a sequence or node.
Definition: conf.c:944
TmModule_::ThreadInit
TmEcode(* ThreadInit)(ThreadVars *, const void *, void **)
Definition: tm-modules.h:47
SetupFPAnalyzer
int SetupFPAnalyzer(void)
Sets up the fast pattern analyzer according to the config.
Definition: detect-engine-analyzer.c:290
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
TmThreadCreateCmdThreadByName
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...
Definition: tm-threads.c:1122
EngineAnalysisRulesFailure
void EngineAnalysisRulesFailure(char *line, char *file, int lineno)
Definition: detect-engine-analyzer.c:554
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
RunmodeGetCurrent
int RunmodeGetCurrent(void)
Definition: suricata.c:254
threadvars.h
detect-engine-sigorder.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
TVT_MAX
@ TVT_MAX
Definition: tm-threads-common.h:94
RUNMODE_ENGINE_ANALYSIS
@ RUNMODE_ENGINE_ANALYSIS
Definition: runmodes.h:56
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SigFileLoaderStat_::good_sigs_total
int good_sigs_total
Definition: detect.h:767
ConfNode_
Definition: conf.h:32
Signature_::id
uint32_t id
Definition: detect.h:591
PathIsRelative
int PathIsRelative(const char *path)
Check if a path is relative.
Definition: util-path.c:69
detect-parse.h
Signature_
Signature container.
Definition: detect.h:557
DetectLoadersSync
int DetectLoadersSync(void)
wait for loader tasks to complete
Definition: detect-engine-loader.c:443
DetectLoaderQueueTask
int DetectLoaderQueueTask(int loader_id, LoaderFunc Func, void *func_ctx)
Definition: detect-engine-loader.c:410
suricata.h
SetupRuleAnalyzer
int SetupRuleAnalyzer(void)
Sets up the rule analyzer according to the config.
Definition: detect-engine-analyzer.c:339
DetectLoaderTask_::Func
LoaderFunc Func
Definition: detect-engine-loader.h:37
DetectLoadCompleteSigPath
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
Definition: detect-engine-loader.c:61
DetectEngineCtx_::sigerror
const char * sigerror
Definition: detect.h:896
ThreadVars_::ctrl_mutex
SCCtrlMutex * ctrl_mutex
Definition: threadvars.h:131
DetectEngineCtx_::rule_line
int rule_line
Definition: detect.h:894
TmThreadsCheckFlag
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.
Definition: tm-threads.c:91
THV_CLOSED
#define THV_CLOSED
Definition: threadvars.h:41
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
detect-engine-loader.h
SigFileLoaderStat_
Signature loader statistics.
Definition: detect.h:763
TmModule_::flags
uint8_t flags
Definition: tm-modules.h:76
DetectEngineCtx_::failure_fatal
int failure_fatal
Definition: detect.h:802
util-threshold-config.h
TM_FLAG_MANAGEMENT_TM
#define TM_FLAG_MANAGEMENT_TM
Definition: tm-modules.h:36
RetrieveFPForSig
void RetrieveFPForSig(const DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine-mpm.c:1068