suricata
detect-flowbits.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 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  * \author Breno Silva <breno.silva@gmail.com>
23  *
24  * Implements the flowbits keyword
25  */
26 
27 #include "suricata-common.h"
28 #include "decode.h"
29 #include "action-globals.h"
30 #include "detect.h"
31 #include "threads.h"
32 #include "flow.h"
33 #include "flow-bit.h"
34 #include "flow-util.h"
35 #include "detect-flowbits.h"
36 #include "util-spm.h"
37 
38 #include "app-layer-parser.h"
39 
40 #include "detect-parse.h"
41 #include "detect-engine.h"
42 #include "detect-engine-mpm.h"
43 #include "detect-engine-state.h"
44 #include "detect-engine-build.h"
45 
46 #include "util-var-name.h"
47 #include "util-unittest.h"
48 #include "util-debug.h"
49 #include "util-conf.h"
50 
51 #define PARSE_REGEX "^([a-z]+)(?:,\\s*(.*))?"
52 static DetectParseRegex parse_regex;
53 
54 #define MAX_TOKENS 100
55 
57  const Signature *, const SigMatchCtx *);
58 static int DetectFlowbitSetup (DetectEngineCtx *, Signature *, const char *);
59 static int FlowbitOrAddData(DetectEngineCtx *, DetectFlowbitsData *, char *);
60 void DetectFlowbitFree (DetectEngineCtx *, void *);
61 #ifdef UNITTESTS
62 void FlowBitsRegisterTests(void);
63 #endif
64 
66 {
67  sigmatch_table[DETECT_FLOWBITS].name = "flowbits";
68  sigmatch_table[DETECT_FLOWBITS].desc = "operate on flow flag";
69  sigmatch_table[DETECT_FLOWBITS].url = "/rules/flow-keywords.html#flowbits";
71  sigmatch_table[DETECT_FLOWBITS].Setup = DetectFlowbitSetup;
73 #ifdef UNITTESTS
75 #endif
76  /* this is compatible to ip-only signatures */
78 
79  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
80 }
81 
82 static int FlowbitOrAddData(DetectEngineCtx *de_ctx, DetectFlowbitsData *cd, char *arrptr)
83 {
84  char *strarr[MAX_TOKENS];
85  char *token;
86  char *saveptr = NULL;
87  uint8_t i = 0;
88 
89  while ((token = strtok_r(arrptr, "|", &saveptr))) {
90  // Check for leading/trailing spaces in the token
91  while(isspace((unsigned char)*token))
92  token++;
93  if (*token == 0)
94  goto next;
95  char *end = token + strlen(token) - 1;
96  while(end > token && isspace((unsigned char)*end))
97  *(end--) = '\0';
98 
99  // Check for spaces in between the flowbit names
100  if (strchr(token, ' ') != NULL) {
101  SCLogError("Spaces are not allowed in flowbit names.");
102  return -1;
103  }
104 
105  if (i == MAX_TOKENS) {
106  SCLogError("Number of flowbits exceeds "
107  "maximum allowed: %d.",
108  MAX_TOKENS);
109  return -1;
110  }
111  strarr[i++] = token;
112  next:
113  arrptr = NULL;
114  }
115  if (i == 0) {
116  SCLogError("No valid flowbits specified");
117  return -1;
118  }
119 
120  cd->or_list_size = i;
121  cd->or_list = SCCalloc(cd->or_list_size, sizeof(uint32_t));
122  if (unlikely(cd->or_list == NULL))
123  return -1;
124  for (uint8_t j = 0; j < cd->or_list_size ; j++) {
125  cd->or_list[j] = VarNameStoreRegister(strarr[j], VAR_TYPE_FLOW_BIT);
127  }
128 
129  return 1;
130 }
131 
132 static int DetectFlowbitMatchToggle (Packet *p, const DetectFlowbitsData *fd)
133 {
134  if (p->flow == NULL)
135  return 0;
136 
137  FlowBitToggle(p->flow,fd->idx);
138 
139  return 1;
140 }
141 
142 static int DetectFlowbitMatchUnset (Packet *p, const DetectFlowbitsData *fd)
143 {
144  if (p->flow == NULL)
145  return 0;
146 
147  FlowBitUnset(p->flow,fd->idx);
148 
149  return 1;
150 }
151 
152 static int DetectFlowbitMatchSet (Packet *p, const DetectFlowbitsData *fd)
153 {
154  if (p->flow == NULL)
155  return 0;
156 
157  FlowBitSet(p->flow,fd->idx);
158 
159  return 1;
160 }
161 
162 static int DetectFlowbitMatchIsset (Packet *p, const DetectFlowbitsData *fd)
163 {
164  if (p->flow == NULL)
165  return 0;
166  if (fd->or_list_size > 0) {
167  for (uint8_t i = 0; i < fd->or_list_size; i++) {
168  if (FlowBitIsset(p->flow, fd->or_list[i]) == 1)
169  return 1;
170  }
171  return 0;
172  }
173 
174  return FlowBitIsset(p->flow,fd->idx);
175 }
176 
177 static int DetectFlowbitMatchIsnotset (Packet *p, const DetectFlowbitsData *fd)
178 {
179  if (p->flow == NULL)
180  return 0;
181  if (fd->or_list_size > 0) {
182  for (uint8_t i = 0; i < fd->or_list_size; i++) {
183  if (FlowBitIsnotset(p->flow, fd->or_list[i]) == 1)
184  return 1;
185  }
186  return 0;
187  }
188  return FlowBitIsnotset(p->flow,fd->idx);
189 }
190 
191 /*
192  * returns 0: no match
193  * 1: match
194  * -1: error
195  */
196 
198  const Signature *s, const SigMatchCtx *ctx)
199 {
200  const DetectFlowbitsData *fd = (const DetectFlowbitsData *)ctx;
201  if (fd == NULL)
202  return 0;
203 
204  switch (fd->cmd) {
206  return DetectFlowbitMatchIsset(p,fd);
208  return DetectFlowbitMatchIsnotset(p,fd);
210  return DetectFlowbitMatchSet(p,fd);
212  return DetectFlowbitMatchUnset(p,fd);
214  return DetectFlowbitMatchToggle(p,fd);
215  default:
216  SCLogError("unknown cmd %" PRIu32 "", fd->cmd);
217  return 0;
218  }
219 
220  return 0;
221 }
222 
223 static int DetectFlowbitParse(const char *str, char *cmd, int cmd_len, char *name,
224  int name_len)
225 {
226  int rc;
227  size_t pcre2len;
228  pcre2_match_data *match = NULL;
229 
230  int count = DetectParsePcreExec(&parse_regex, &match, str, 0, 0);
231  if (count != 2 && count != 3) {
232  SCLogError("\"%s\" is not a valid setting for flowbits.", str);
233  goto error;
234  }
235 
236  pcre2len = cmd_len;
237  rc = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)cmd, &pcre2len);
238  if (rc < 0) {
239  SCLogError("pcre2_substring_copy_bynumber failed");
240  goto error;
241  }
242 
243  if (count == 3) {
244  pcre2len = name_len;
245  rc = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)name, &pcre2len);
246  if (rc < 0) {
247  SCLogError("pcre2_substring_copy_bynumber failed");
248  goto error;
249  }
250 
251  /* Trim trailing whitespace. */
252  while (strlen(name) > 0 && isblank(name[strlen(name) - 1])) {
253  name[strlen(name) - 1] = '\0';
254  }
255 
256  if (strchr(name, '|') == NULL) {
257  /* Validate name, spaces are not allowed. */
258  for (size_t i = 0; i < strlen(name); i++) {
259  if (isblank(name[i])) {
260  SCLogError("spaces not allowed in flowbit names");
261  goto error;
262  }
263  }
264  }
265  }
266 
267  pcre2_match_data_free(match);
268  return 1;
269 
270 error:
271  if (match) {
272  pcre2_match_data_free(match);
273  }
274  return 0;
275 }
276 
277 int DetectFlowbitSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
278 {
279  DetectFlowbitsData *cd = NULL;
280  uint8_t fb_cmd = 0;
281  char fb_cmd_str[16] = "", fb_name[256] = "";
282 
283  if (!DetectFlowbitParse(rawstr, fb_cmd_str, sizeof(fb_cmd_str), fb_name,
284  sizeof(fb_name))) {
285  return -1;
286  }
287 
288  if (strcmp(fb_cmd_str,"noalert") == 0) {
289  if (strlen(fb_name) != 0)
290  goto error;
291  s->action &= ~ACTION_ALERT;
292  return 0;
293  } else if (strcmp(fb_cmd_str,"isset") == 0) {
294  fb_cmd = DETECT_FLOWBITS_CMD_ISSET;
295  } else if (strcmp(fb_cmd_str,"isnotset") == 0) {
297  } else if (strcmp(fb_cmd_str,"set") == 0) {
298  fb_cmd = DETECT_FLOWBITS_CMD_SET;
299  } else if (strcmp(fb_cmd_str,"unset") == 0) {
300  fb_cmd = DETECT_FLOWBITS_CMD_UNSET;
301  } else if (strcmp(fb_cmd_str,"toggle") == 0) {
303  } else {
304  SCLogError("ERROR: flowbits action \"%s\" is not supported.", fb_cmd_str);
305  goto error;
306  }
307 
308  switch (fb_cmd) {
314  default:
315  if (strlen(fb_name) == 0)
316  goto error;
317  break;
318  }
319 
320  cd = SCCalloc(1, sizeof(DetectFlowbitsData));
321  if (unlikely(cd == NULL))
322  goto error;
323  if (strchr(fb_name, '|') != NULL) {
324  int retval = FlowbitOrAddData(de_ctx, cd, fb_name);
325  if (retval == -1) {
326  goto error;
327  }
328  cd->cmd = fb_cmd;
329  } else {
332  cd->cmd = fb_cmd;
333  cd->or_list_size = 0;
334  cd->or_list = NULL;
335  SCLogDebug("idx %" PRIu32 ", cmd %s, name %s",
336  cd->idx, fb_cmd_str, strlen(fb_name) ? fb_name : "(none)");
337  }
338  /* Okay so far so good, lets get this into a SigMatch
339  * and put it in the Signature. */
340 
341  switch (fb_cmd) {
342  /* noalert can't happen here */
345  /* checks, so packet list */
347  DETECT_SM_LIST_MATCH) == NULL) {
348  goto error;
349  }
350  break;
351 
355  /* modifiers, only run when entire sig has matched */
357  DETECT_SM_LIST_POSTMATCH) == NULL) {
358  goto error;
359  }
360  break;
361 
362  // suppress coverity warning as scan-build-7 warns w/o this.
363  // coverity[deadcode : FALSE]
364  default:
365  goto error;
366  }
367 
368  return 0;
369 
370 error:
371  if (cd != NULL)
373  return -1;
374 }
375 
377 {
379  if (fd == NULL)
380  return;
382  if (fd->or_list != NULL) {
383  for (uint8_t i = 0; i < fd->or_list_size; i++) {
385  }
386  SCFree(fd->or_list);
387  }
388  SCFree(fd);
389 }
390 
391 struct FBAnalyze {
394 
395  uint32_t *set_sids;
396  uint32_t set_sids_idx;
397  uint32_t set_sids_size;
398 
399  uint32_t *isset_sids;
400  uint32_t isset_sids_idx;
401  uint32_t isset_sids_size;
402 
403  uint32_t *isnotset_sids;
406 
407  uint32_t *unset_sids;
408  uint32_t unset_sids_idx;
409  uint32_t unset_sids_size;
410 
411  uint32_t *toggle_sids;
412  uint32_t toggle_sids_idx;
414 };
415 
416 extern bool rule_engine_analysis_set;
417 static void DetectFlowbitsAnalyzeDump(const DetectEngineCtx *de_ctx,
418  struct FBAnalyze *array, uint32_t elements);
419 
421 {
422  const uint32_t max_fb_id = de_ctx->max_fb_id;
423  if (max_fb_id == 0)
424  return 0;
425 
426 #define MAX_SIDS 8
427  uint32_t array_size = max_fb_id + 1;
428  struct FBAnalyze *array = SCCalloc(array_size, sizeof(struct FBAnalyze));
429 
430  if (array == NULL) {
431  SCLogError("Unable to allocate flowbit analyze array");
432  return -1;
433  }
434 
435  SCLogDebug("fb analyzer array size: %"PRIu64,
436  (uint64_t)(array_size * sizeof(struct FBAnalyze)));
437 
438  /* fill flowbit array, updating counters per sig */
439  for (uint32_t i = 0; i < de_ctx->sig_array_len; i++) {
440  const Signature *s = de_ctx->sig_array[i];
441 
442  /* see if the signature uses stateful matching */
443  bool has_state = (s->init_data->buffer_index != 0);
444 
445  for (const SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
446  switch (sm->type) {
447  case DETECT_FLOWBITS:
448  {
449  /* figure out the flowbit action */
450  const DetectFlowbitsData *fb = (DetectFlowbitsData *)sm->ctx;
451  // Handle flowbit array in case of ORed flowbits
452  for (uint8_t k = 0; k < fb->or_list_size; k++) {
453  array[fb->or_list[k]].cnts[fb->cmd]++;
454  if (has_state)
455  array[fb->or_list[k]].state_cnts[fb->cmd]++;
456  if (fb->cmd == DETECT_FLOWBITS_CMD_ISSET) {
457  if (array[fb->or_list[k]].isset_sids_idx >= array[fb->or_list[k]].isset_sids_size) {
458  uint32_t old_size = array[fb->or_list[k]].isset_sids_size;
459  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
460 
461  void *ptr = SCRealloc(array[fb->or_list[k]].isset_sids, new_size * sizeof(uint32_t));
462  if (ptr == NULL)
463  goto end;
464  array[fb->or_list[k]].isset_sids_size = new_size;
465  array[fb->or_list[k]].isset_sids = ptr;
466  }
467 
468  array[fb->or_list[k]].isset_sids[array[fb->or_list[k]].isset_sids_idx] = s->num;
469  array[fb->or_list[k]].isset_sids_idx++;
470  } else if (fb->cmd == DETECT_FLOWBITS_CMD_ISNOTSET) {
471  if (array[fb->or_list[k]].isnotset_sids_idx >= array[fb->or_list[k]].isnotset_sids_size) {
472  uint32_t old_size = array[fb->or_list[k]].isnotset_sids_size;
473  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
474 
475  void *ptr = SCRealloc(array[fb->or_list[k]].isnotset_sids, new_size * sizeof(uint32_t));
476  if (ptr == NULL)
477  goto end;
478  array[fb->or_list[k]].isnotset_sids_size = new_size;
479  array[fb->or_list[k]].isnotset_sids = ptr;
480  }
481 
482  array[fb->or_list[k]].isnotset_sids[array[fb->or_list[k]].isnotset_sids_idx] = s->num;
483  array[fb->or_list[k]].isnotset_sids_idx++;
484  }
485  }
486  if (fb->or_list_size == 0) {
487  array[fb->idx].cnts[fb->cmd]++;
488  if (has_state)
489  array[fb->idx].state_cnts[fb->cmd]++;
490  if (fb->cmd == DETECT_FLOWBITS_CMD_ISSET) {
491  if (array[fb->idx].isset_sids_idx >= array[fb->idx].isset_sids_size) {
492  uint32_t old_size = array[fb->idx].isset_sids_size;
493  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
494 
495  void *ptr = SCRealloc(array[fb->idx].isset_sids, new_size * sizeof(uint32_t));
496  if (ptr == NULL)
497  goto end;
498  array[fb->idx].isset_sids_size = new_size;
499  array[fb->idx].isset_sids = ptr;
500  }
501 
502  array[fb->idx].isset_sids[array[fb->idx].isset_sids_idx] = s->num;
503  array[fb->idx].isset_sids_idx++;
504  } else if (fb->cmd == DETECT_FLOWBITS_CMD_ISNOTSET) {
505  if (array[fb->idx].isnotset_sids_idx >= array[fb->idx].isnotset_sids_size) {
506  uint32_t old_size = array[fb->idx].isnotset_sids_size;
507  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
508 
509  void *ptr = SCRealloc(array[fb->idx].isnotset_sids, new_size * sizeof(uint32_t));
510  if (ptr == NULL)
511  goto end;
512  array[fb->idx].isnotset_sids_size = new_size;
513  array[fb->idx].isnotset_sids = ptr;
514  }
515 
516  array[fb->idx].isnotset_sids[array[fb->idx].isnotset_sids_idx] = s->num;
517  array[fb->idx].isnotset_sids_idx++;
518  }
519  }
520  }
521  }
522  }
523  for (const SigMatch *sm = s->init_data->smlists[DETECT_SM_LIST_POSTMATCH] ; sm != NULL; sm = sm->next) {
524  switch (sm->type) {
525  case DETECT_FLOWBITS:
526  {
527  /* figure out what flowbit action */
528  const DetectFlowbitsData *fb = (DetectFlowbitsData *)sm->ctx;
529  array[fb->idx].cnts[fb->cmd]++;
530  if (has_state)
531  array[fb->idx].state_cnts[fb->cmd]++;
532  if (fb->cmd == DETECT_FLOWBITS_CMD_SET) {
533  if (array[fb->idx].set_sids_idx >= array[fb->idx].set_sids_size) {
534  uint32_t old_size = array[fb->idx].set_sids_size;
535  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
536 
537  void *ptr = SCRealloc(array[fb->idx].set_sids, new_size * sizeof(uint32_t));
538  if (ptr == NULL)
539  goto end;
540  array[fb->idx].set_sids_size = new_size;
541  array[fb->idx].set_sids = ptr;
542  }
543 
544  array[fb->idx].set_sids[array[fb->idx].set_sids_idx] = s->num;
545  array[fb->idx].set_sids_idx++;
546  }
547  else if (fb->cmd == DETECT_FLOWBITS_CMD_UNSET) {
548  if (array[fb->idx].unset_sids_idx >= array[fb->idx].unset_sids_size) {
549  uint32_t old_size = array[fb->idx].unset_sids_size;
550  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
551 
552  void *ptr = SCRealloc(array[fb->idx].unset_sids, new_size * sizeof(uint32_t));
553  if (ptr == NULL)
554  goto end;
555  array[fb->idx].unset_sids_size = new_size;
556  array[fb->idx].unset_sids = ptr;
557  }
558 
559  array[fb->idx].unset_sids[array[fb->idx].unset_sids_idx] = s->num;
560  array[fb->idx].unset_sids_idx++;
561  }
562  else if (fb->cmd == DETECT_FLOWBITS_CMD_TOGGLE) {
563  if (array[fb->idx].toggle_sids_idx >= array[fb->idx].toggle_sids_size) {
564  uint32_t old_size = array[fb->idx].toggle_sids_size;
565  uint32_t new_size = MAX(2 * old_size, MAX_SIDS);
566 
567  void *ptr = SCRealloc(array[fb->idx].toggle_sids, new_size * sizeof(uint32_t));
568  if (ptr == NULL)
569  goto end;
570  array[fb->idx].toggle_sids_size = new_size;
571  array[fb->idx].toggle_sids = ptr;
572  }
573 
574  array[fb->idx].toggle_sids[array[fb->idx].toggle_sids_idx] = s->num;
575  array[fb->idx].toggle_sids_idx++;
576  }
577  }
578  }
579  }
580  }
581 
582  /* walk array to see if all bits make sense */
583  for (uint32_t i = 0; i < array_size; i++) {
584  const char *varname = VarNameStoreSetupLookup(i, VAR_TYPE_FLOW_BIT);
585  if (varname == NULL)
586  continue;
587 
588  bool to_state = false;
589 
590  if (array[i].cnts[DETECT_FLOWBITS_CMD_ISSET] &&
591  array[i].cnts[DETECT_FLOWBITS_CMD_TOGGLE] == 0 &&
592  array[i].cnts[DETECT_FLOWBITS_CMD_SET] == 0) {
593 
594  const Signature *s = de_ctx->sig_array[array[i].isset_sids[0]];
595  SCLogWarning("flowbit '%s' is checked but not "
596  "set. Checked in %u and %u other sigs",
597  varname, s->id, array[i].isset_sids_idx - 1);
598  }
599  if (array[i].state_cnts[DETECT_FLOWBITS_CMD_ISSET] &&
600  array[i].state_cnts[DETECT_FLOWBITS_CMD_SET] == 0)
601  {
602  SCLogDebug("flowbit %s/%u: isset in state, set not in state", varname, i);
603  }
604 
605  /* if signature depends on 'stateful' flowbits, then turn the
606  * sig into a stateful sig itself */
607  if (array[i].cnts[DETECT_FLOWBITS_CMD_ISSET] > 0 &&
608  array[i].state_cnts[DETECT_FLOWBITS_CMD_ISSET] == 0 &&
610  {
611  SCLogDebug("flowbit %s/%u: isset not in state, set in state", varname, i);
612  to_state = true;
613  }
614 
615  SCLogDebug("ALL flowbit %s/%u: sets %u toggles %u unsets %u isnotsets %u issets %u", varname, i,
618  array[i].cnts[DETECT_FLOWBITS_CMD_ISSET]);
619  SCLogDebug("STATE flowbit %s/%u: sets %u toggles %u unsets %u isnotsets %u issets %u", varname, i,
623  for (uint32_t x = 0; x < array[i].set_sids_idx; x++) {
624  SCLogDebug("SET flowbit %s/%u: SID %u", varname, i,
625  de_ctx->sig_array[array[i].set_sids[x]]->id);
626  }
627  for (uint32_t x = 0; x < array[i].isset_sids_idx; x++) {
628  Signature *s = de_ctx->sig_array[array[i].isset_sids[x]];
629  SCLogDebug("GET flowbit %s/%u: SID %u", varname, i, s->id);
630 
631  if (to_state) {
633  SCLogDebug("made SID %u stateful because it depends on "
634  "stateful rules that set flowbit %s", s->id, varname);
635  }
636  }
637  }
638 
640  DetectFlowbitsAnalyzeDump(de_ctx, array, array_size);
641  }
642 
643 end:
644  for (uint32_t i = 0; i < array_size; i++) {
645  SCFree(array[i].set_sids);
646  SCFree(array[i].unset_sids);
647  SCFree(array[i].isset_sids);
648  SCFree(array[i].isnotset_sids);
649  SCFree(array[i].toggle_sids);
650  }
651  SCFree(array);
652 
653  return 0;
654 }
655 
657 static void DetectFlowbitsAnalyzeDump(const DetectEngineCtx *de_ctx,
658  struct FBAnalyze *array, uint32_t elements)
659 {
660  JsonBuilder *js = jb_new_object();
661  if (js == NULL)
662  return;
663 
664  jb_open_array(js, "flowbits");
665  for (uint32_t x = 0; x < elements; x++) {
666  const char *varname = VarNameStoreSetupLookup(x, VAR_TYPE_FLOW_BIT);
667  if (varname == NULL)
668  continue;
669 
670  const struct FBAnalyze *e = &array[x];
671 
672  jb_start_object(js);
673  jb_set_string(js, "name", varname);
674  jb_set_uint(js, "internal_id", x);
675  jb_set_uint(js, "set_cnt", e->cnts[DETECT_FLOWBITS_CMD_SET]);
676  jb_set_uint(js, "unset_cnt", e->cnts[DETECT_FLOWBITS_CMD_UNSET]);
677  jb_set_uint(js, "toggle_cnt", e->cnts[DETECT_FLOWBITS_CMD_TOGGLE]);
678  jb_set_uint(js, "isset_cnt", e->cnts[DETECT_FLOWBITS_CMD_ISSET]);
679  jb_set_uint(js, "isnotset_cnt", e->cnts[DETECT_FLOWBITS_CMD_ISNOTSET]);
680 
681  // sets
682  if (e->cnts[DETECT_FLOWBITS_CMD_SET]) {
683  jb_open_array(js, "sets");
684  for (uint32_t i = 0; i < e->set_sids_idx; i++) {
685  const Signature *s = de_ctx->sig_array[e->set_sids[i]];
686  jb_append_uint(js, s->id);
687  }
688  jb_close(js);
689  }
690  // gets
692  jb_open_array(js, "isset");
693  for (uint32_t i = 0; i < e->isset_sids_idx; i++) {
694  const Signature *s = de_ctx->sig_array[e->isset_sids[i]];
695  jb_append_uint(js, s->id);
696  }
697  jb_close(js);
698  }
699  // isnotset
701  jb_open_array(js, "isnotset");
702  for (uint32_t i = 0; i < e->isnotset_sids_idx; i++) {
703  const Signature *s = de_ctx->sig_array[e->isnotset_sids[i]];
704  jb_append_uint(js, s->id);
705  }
706  jb_close(js);
707  }
708  // unset
710  jb_open_array(js, "unset");
711  for (uint32_t i = 0; i < e->unset_sids_idx; i++) {
712  const Signature *s = de_ctx->sig_array[e->unset_sids[i]];
713  jb_append_uint(js, s->id);
714  }
715  jb_close(js);
716  }
717  // toggle
719  jb_open_array(js, "toggle");
720  for (uint32_t i = 0; i < e->toggle_sids_idx; i++) {
721  const Signature *s = de_ctx->sig_array[e->toggle_sids[i]];
722  jb_append_uint(js, s->id);
723  }
724  jb_close(js);
725  }
726  jb_close(js);
727  }
728  jb_close(js); // array
729  jb_close(js); // object
730 
731  const char *filename = "flowbits.json";
732  const char *log_dir = ConfigGetLogDirectory();
733  char log_path[PATH_MAX] = "";
734  snprintf(log_path, sizeof(log_path), "%s/%s", log_dir, filename);
735 
737  FILE *fp = fopen(log_path, "w");
738  if (fp != NULL) {
739  fwrite(jb_ptr(js), jb_len(js), 1, fp);
740  fprintf(fp, "\n");
741  fclose(fp);
742  }
744 
745  jb_free(js);
746 }
747 
748 #ifdef UNITTESTS
749 
750 static int FlowBitsTestParse01(void)
751 {
752  char command[16] = "", name[16] = "";
753 
754  /* Single argument version. */
755  FAIL_IF(!DetectFlowbitParse("noalert", command, sizeof(command), name,
756  sizeof(name)));
757  FAIL_IF(strcmp(command, "noalert") != 0);
758 
759  /* No leading or trailing spaces. */
760  FAIL_IF(!DetectFlowbitParse("set,flowbit", command, sizeof(command), name,
761  sizeof(name)));
762  FAIL_IF(strcmp(command, "set") != 0);
763  FAIL_IF(strcmp(name, "flowbit") != 0);
764 
765  /* Leading space. */
766  FAIL_IF(!DetectFlowbitParse("set, flowbit", command, sizeof(command), name,
767  sizeof(name)));
768  FAIL_IF(strcmp(command, "set") != 0);
769  FAIL_IF(strcmp(name, "flowbit") != 0);
770 
771  /* Trailing space. */
772  FAIL_IF(!DetectFlowbitParse("set,flowbit ", command, sizeof(command), name,
773  sizeof(name)));
774  FAIL_IF(strcmp(command, "set") != 0);
775  FAIL_IF(strcmp(name, "flowbit") != 0);
776 
777  /* Leading and trailing space. */
778  FAIL_IF(!DetectFlowbitParse("set, flowbit ", command, sizeof(command), name,
779  sizeof(name)));
780  FAIL_IF(strcmp(command, "set") != 0);
781  FAIL_IF(strcmp(name, "flowbit") != 0);
782 
783  /* Spaces are not allowed in the name. */
784  FAIL_IF(DetectFlowbitParse("set,namewith space", command, sizeof(command),
785  name, sizeof(name)));
786 
787  PASS;
788 }
789 
790 /**
791  * \test FlowBitsTestSig01 is a test for a valid noalert flowbits option
792  *
793  * \retval 1 on success
794  * \retval 0 on failure
795  */
796 
797 static int FlowBitsTestSig01(void)
798 {
799  Signature *s = NULL;
800  DetectEngineCtx *de_ctx = NULL;
801 
804 
805  de_ctx->flags |= DE_QUIET;
806 
807  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Noalert\"; flowbits:noalert,wrongusage; content:\"GET \"; sid:1;)");
808  FAIL_IF_NOT_NULL(s);
809 
812  PASS;
813 }
814 
815 /**
816  * \test FlowBitsTestSig02 is a test for a valid isset,set,isnotset,unset,toggle flowbits options
817  *
818  * \retval 1 on success
819  * \retval 0 on failure
820  */
821 
822 static int FlowBitsTestSig02(void)
823 {
824  Signature *s = NULL;
825  ThreadVars th_v;
826  DetectEngineCtx *de_ctx = NULL;
827 
828  memset(&th_v, 0, sizeof(th_v));
829 
832 
833  de_ctx->flags |= DE_QUIET;
834 
835  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isset rule need an option\"; flowbits:isset; content:\"GET \"; sid:1;)");
836  FAIL_IF_NOT_NULL(s);
837 
838  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isnotset rule need an option\"; flowbits:isnotset; content:\"GET \"; sid:2;)");
839  FAIL_IF_NOT_NULL(s);
840 
841  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"set rule need an option\"; flowbits:set; content:\"GET \"; sid:3;)");
842  FAIL_IF_NOT_NULL(s);
843 
844  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"unset rule need an option\"; flowbits:unset; content:\"GET \"; sid:4;)");
845  FAIL_IF_NOT_NULL(s);
846 
847  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"toggle rule need an option\"; flowbits:toggle; content:\"GET \"; sid:5;)");
848  FAIL_IF_NOT_NULL(s);
849 
850  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"!set is not an option\"; flowbits:!set,myerr; content:\"GET \"; sid:6;)");
851  FAIL_IF_NOT_NULL(s);
852 
855 
856  PASS;
857 }
858 
859 /**
860  * \test FlowBitsTestSig03 is a test for a invalid flowbits option
861  *
862  * \retval 1 on success
863  * \retval 0 on failure
864  */
865 
866 static int FlowBitsTestSig03(void)
867 {
868  Signature *s = NULL;
869  DetectEngineCtx *de_ctx = NULL;
870 
873 
874  de_ctx->flags |= DE_QUIET;
875 
876  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Unknown cmd\"; flowbits:wrongcmd; content:\"GET \"; sid:1;)");
877  FAIL_IF_NOT_NULL(s);
878 
881  PASS;
882 }
883 
884 /**
885  * \test FlowBitsTestSig04 is a test check idx value
886  *
887  * \retval 1 on success
888  * \retval 0 on failure
889  */
890 
891 static int FlowBitsTestSig04(void)
892 {
893  Signature *s = NULL;
894  DetectEngineCtx *de_ctx = NULL;
895  int idx = 0;
898 
899  de_ctx->flags |= DE_QUIET;
900 
901  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"isset option\"; flowbits:isset,fbt; content:\"GET \"; sid:1;)");
902  FAIL_IF_NULL(s);
903 
905  FAIL_IF(idx == 0);
906 
909  PASS;
910 }
911 
912 /**
913  * \test FlowBitsTestSig05 is a test check noalert flag
914  *
915  * \retval 1 on success
916  * \retval 0 on failure
917  */
918 
919 static int FlowBitsTestSig05(void)
920 {
921  Signature *s = NULL;
922  DetectEngineCtx *de_ctx = NULL;
923 
926 
927  de_ctx->flags |= DE_QUIET;
928 
929  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Noalert\"; flowbits:noalert; content:\"GET \"; sid:1;)");
930  FAIL_IF_NULL(s);
931  FAIL_IF((s->action & ACTION_ALERT) != 0);
932 
935  PASS;
936 }
937 
938 /**
939  * \test FlowBitsTestSig06 is a test set flowbits option
940  *
941  * \retval 1 on success
942  * \retval 0 on failure
943  */
944 
945 static int FlowBitsTestSig06(void)
946 {
947  uint8_t *buf = (uint8_t *)
948  "GET /one/ HTTP/1.1\r\n"
949  "Host: one.example.org\r\n"
950  "\r\n";
951  uint16_t buflen = strlen((char *)buf);
952  Packet *p = PacketGetFromAlloc();
953  FAIL_IF_NULL(p);
954  Signature *s = NULL;
955  ThreadVars th_v;
956  DetectEngineThreadCtx *det_ctx = NULL;
957  DetectEngineCtx *de_ctx = NULL;
958  Flow f;
959  GenericVar flowvar, *gv = NULL;
960  int result = 0;
961  uint32_t idx = 0;
962 
963  memset(&th_v, 0, sizeof(th_v));
964  memset(&f, 0, sizeof(Flow));
965  memset(&flowvar, 0, sizeof(GenericVar));
966 
967  FLOW_INITIALIZE(&f);
968  p->flow = &f;
969  p->flow->flowvar = &flowvar;
970 
971  p->src.family = AF_INET;
972  p->dst.family = AF_INET;
973  p->payload = buf;
974  p->payload_len = buflen;
975  p->proto = IPPROTO_TCP;
976  p->flags |= PKT_HAS_FLOW;
978 
981 
982  de_ctx->flags |= DE_QUIET;
983 
984  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Flowbit set\"; flowbits:set,myflow; sid:10;)");
985  FAIL_IF_NULL(s);
986 
987  idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
989  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
990 
991  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
992 
993  gv = p->flow->flowvar;
994  FAIL_IF_NULL(gv);
995  for ( ; gv != NULL; gv = gv->next) {
996  if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
997  result = 1;
998  }
999  }
1000  FAIL_IF_NOT(result);
1001 
1002  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1004 
1005  FLOW_DESTROY(&f);
1006 
1007  SCFree(p);
1008  PASS;
1009 }
1010 
1011 /**
1012  * \test FlowBitsTestSig07 is a test unset flowbits option
1013  *
1014  * \retval 1 on success
1015  * \retval 0 on failure
1016  */
1017 
1018 static int FlowBitsTestSig07(void)
1019 {
1020  uint8_t *buf = (uint8_t *)
1021  "GET /one/ HTTP/1.1\r\n"
1022  "Host: one.example.org\r\n"
1023  "\r\n";
1024  uint16_t buflen = strlen((char *)buf);
1025  Packet *p = PacketGetFromAlloc();
1026  FAIL_IF_NULL(p);
1027  Signature *s = NULL;
1028  ThreadVars th_v;
1029  DetectEngineThreadCtx *det_ctx = NULL;
1030  DetectEngineCtx *de_ctx = NULL;
1031  Flow f;
1032  GenericVar flowvar, *gv = NULL;
1033  int result = 0;
1034  uint32_t idx = 0;
1035 
1036  memset(&th_v, 0, sizeof(th_v));
1037  memset(&f, 0, sizeof(Flow));
1038  memset(&flowvar, 0, sizeof(GenericVar));
1039 
1040  FLOW_INITIALIZE(&f);
1041  p->flow = &f;
1042  p->flow->flowvar = &flowvar;
1043 
1044  p->src.family = AF_INET;
1045  p->dst.family = AF_INET;
1046  p->payload = buf;
1047  p->payload_len = buflen;
1048  p->proto = IPPROTO_TCP;
1049 
1052 
1053  de_ctx->flags |= DE_QUIET;
1054 
1055  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Flowbit set\"; flowbits:set,myflow2; sid:10;)");
1056  FAIL_IF_NULL(s);
1057 
1058  s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Flowbit unset\"; flowbits:unset,myflow2; sid:11;)");
1059  FAIL_IF_NULL(s);
1060 
1061  idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
1063  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1064 
1065  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1066 
1067  gv = p->flow->flowvar;
1068  FAIL_IF_NULL(gv);
1069 
1070  for ( ; gv != NULL; gv = gv->next) {
1071  if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
1072  result = 1;
1073  }
1074  }
1075  FAIL_IF(result);
1076 
1077  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1079 
1080  FLOW_DESTROY(&f);
1081 
1082  SCFree(p);
1083  PASS;
1084 }
1085 
1086 /**
1087  * \test FlowBitsTestSig08 is a test toggle flowbits option
1088  *
1089  * \retval 1 on success
1090  * \retval 0 on failure
1091  */
1092 
1093 static int FlowBitsTestSig08(void)
1094 {
1095  uint8_t *buf = (uint8_t *)
1096  "GET /one/ HTTP/1.1\r\n"
1097  "Host: one.example.org\r\n"
1098  "\r\n";
1099  uint16_t buflen = strlen((char *)buf);
1100  Packet *p = PacketGetFromAlloc();
1101  if (unlikely(p == NULL))
1102  return 0;
1103  Signature *s = NULL;
1104  ThreadVars th_v;
1105  DetectEngineThreadCtx *det_ctx = NULL;
1106  DetectEngineCtx *de_ctx = NULL;
1107  Flow f;
1108  GenericVar flowvar, *gv = NULL;
1109  int result = 0;
1110  uint32_t idx = 0;
1111 
1112  memset(&th_v, 0, sizeof(th_v));
1113  memset(&f, 0, sizeof(Flow));
1114  memset(&flowvar, 0, sizeof(GenericVar));
1115 
1116  FLOW_INITIALIZE(&f);
1117  p->flow = &f;
1118  p->flow->flowvar = &flowvar;
1119 
1120  p->src.family = AF_INET;
1121  p->dst.family = AF_INET;
1122  p->payload = buf;
1123  p->payload_len = buflen;
1124  p->proto = IPPROTO_TCP;
1125 
1128 
1129  de_ctx->flags |= DE_QUIET;
1130 
1131  s = de_ctx->sig_list = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Flowbit set\"; flowbits:set,myflow2; sid:10;)");
1132  FAIL_IF_NULL(s);
1133 
1134  s = s->next = SigInit(de_ctx,"alert ip any any -> any any (msg:\"Flowbit unset\"; flowbits:toggle,myflow2; sid:11;)");
1135  FAIL_IF_NULL(s);
1136 
1137  idx = VarNameStoreRegister("myflow", VAR_TYPE_FLOW_BIT);
1139  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1140 
1141  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1142 
1143  gv = p->flow->flowvar;
1144  FAIL_IF_NULL(gv);
1145 
1146  for ( ; gv != NULL; gv = gv->next) {
1147  if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
1148  result = 1;
1149  }
1150  }
1151  FAIL_IF(result);
1152 
1153  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1155 
1156  FLOW_DESTROY(&f);
1157 
1158  SCFree(p);
1159  PASS;
1160 }
1161 
1162 /**
1163  * \brief this function registers unit tests for FlowBits
1164  */
1166 {
1167  UtRegisterTest("FlowBitsTestParse01", FlowBitsTestParse01);
1168  UtRegisterTest("FlowBitsTestSig01", FlowBitsTestSig01);
1169  UtRegisterTest("FlowBitsTestSig02", FlowBitsTestSig02);
1170  UtRegisterTest("FlowBitsTestSig03", FlowBitsTestSig03);
1171  UtRegisterTest("FlowBitsTestSig04", FlowBitsTestSig04);
1172  UtRegisterTest("FlowBitsTestSig05", FlowBitsTestSig05);
1173  UtRegisterTest("FlowBitsTestSig06", FlowBitsTestSig06);
1174  UtRegisterTest("FlowBitsTestSig07", FlowBitsTestSig07);
1175  UtRegisterTest("FlowBitsTestSig08", FlowBitsTestSig08);
1176 }
1177 #endif /* UNITTESTS */
FBAnalyze::cnts
uint16_t cnts[DETECT_FLOWBITS_CMD_MAX]
Definition: detect-flowbits.c:392
GenericVar_::type
uint8_t type
Definition: util-var.h:51
FBAnalyze::isset_sids
uint32_t * isset_sids
Definition: detect-flowbits.c:399
SigTableElmt_::url
const char * url
Definition: detect.h:1304
Packet_::proto
uint8_t proto
Definition: decode.h:501
FBAnalyze::isnotset_sids_idx
uint32_t isnotset_sids_idx
Definition: detect-flowbits.c:404
g_flowbits_dump_write_m
SCMutex g_flowbits_dump_write_m
Definition: detect-flowbits.c:656
DetectFlowbitsData_::or_list_size
uint8_t or_list_size
Definition: detect-flowbits.h:38
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:586
DETECT_FLOWBITS_CMD_MAX
#define DETECT_FLOWBITS_CMD_MAX
Definition: detect-flowbits.h:33
SigTableElmt_::desc
const char * desc
Definition: detect.h:1303
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:127
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1273
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1291
flow-util.h
DetectParseRegex
Definition: detect-parse.h:62
SigTableElmt_::name
const char * name
Definition: detect.h:1301
Signature_::num
SigIntId num
Definition: detect.h:613
FBAnalyze::isnotset_sids
uint32_t * isnotset_sids
Definition: detect-flowbits.c:403
FlowBitsRegisterTests
void FlowBitsRegisterTests(void)
this function registers unit tests for FlowBits
Definition: detect-flowbits.c:1165
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
MAX_SIDS
#define MAX_SIDS
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
FBAnalyze::unset_sids_size
uint32_t unset_sids_size
Definition: detect-flowbits.c:409
MAX_TOKENS
#define MAX_TOKENS
Definition: detect-flowbits.c:54
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
DETECT_FLOWBITS_CMD_ISNOTSET
#define DETECT_FLOWBITS_CMD_ISNOTSET
Definition: detect-flowbits.h:31
Packet_::payload
uint8_t * payload
Definition: decode.h:580
action-globals.h
Packet_::flags
uint32_t flags
Definition: decode.h:516
threads.h
Flow_
Flow data structure.
Definition: flow.h:360
DetectFlowbitsAnalyze
int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
Definition: detect-flowbits.c:420
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1295
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:841
DetectFlowbitsData_::cmd
uint8_t cmd
Definition: detect-flowbits.h:37
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2597
flow-bit.h
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:232
util-var-name.h
DE_QUIET
#define DE_QUIET
Definition: detect.h:323
VarNameStoreSetupLookup
const char * VarNameStoreSetupLookup(const uint32_t id, const enum VarTypes type)
Definition: util-var-name.c:188
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1926
SCMUTEX_INITIALIZER
#define SCMUTEX_INITIALIZER
Definition: threads-debug.h:121
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:553
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:2641
DETECT_FLOWBITS_CMD_TOGGLE
#define DETECT_FLOWBITS_CMD_TOGGLE
Definition: detect-flowbits.h:29
DETECT_FLOWBITS_CMD_ISSET
#define DETECT_FLOWBITS_CMD_ISSET
Definition: detect-flowbits.h:32
VarNameStoreRegister
uint32_t VarNameStoreRegister(const char *name, const enum VarTypes type)
Definition: util-var-name.c:155
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:510
MAX
#define MAX(x, y)
Definition: suricata-common.h:395
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1286
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:581
util-unittest.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
Signature_::next
struct Signature_ * next
Definition: detect.h:673
FlowBitUnset
void FlowBitUnset(Flow *f, uint32_t idx)
Definition: flow-bit.c:89
DetectFlowbitsData_
Definition: detect-flowbits.h:35
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:124
FLOW_INITIALIZE
#define FLOW_INITIALIZE(f)
Definition: flow-util.h:38
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
GenericVar_::next
struct GenericVar_ * next
Definition: util-var.h:54
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
PARSE_REGEX
#define PARSE_REGEX
Definition: detect-flowbits.c:51
DetectEngineThreadCtx_
Definition: detect.h:1090
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2767
FlowBitSet
void FlowBitSet(Flow *f, uint32_t idx)
Definition: flow-bit.c:84
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
VarNameStoreUnregister
void VarNameStoreUnregister(const uint32_t id, const enum VarTypes type)
Definition: util-var-name.c:201
FBAnalyze::toggle_sids_idx
uint32_t toggle_sids_idx
Definition: detect-flowbits.c:412
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:353
FBAnalyze::set_sids_size
uint32_t set_sids_size
Definition: detect-flowbits.c:397
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:114
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2285
app-layer-parser.h
GenericVar_::idx
uint32_t idx
Definition: util-var.h:53
FBAnalyze::unset_sids
uint32_t * unset_sids
Definition: detect-flowbits.c:407
DetectFlowbitFree
void DetectFlowbitFree(DetectEngineCtx *, void *)
Definition: detect-flowbits.c:376
Signature_::action
uint8_t action
Definition: detect.h:616
DetectFlowbitsRegister
void DetectFlowbitsRegister(void)
Definition: detect-flowbits.c:65
FBAnalyze::set_sids
uint32_t * set_sids
Definition: detect-flowbits.c:395
DetectEngineCtx_::max_fb_id
uint32_t max_fb_id
Definition: detect.h:900
ACTION_ALERT
#define ACTION_ALERT
Definition: action-globals.h:29
Packet_
Definition: decode.h:479
detect-engine-build.h
DetectFlowbitsData_::idx
uint32_t idx
Definition: detect-flowbits.h:36
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:670
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1269
FBAnalyze::toggle_sids
uint32_t * toggle_sids
Definition: detect-flowbits.c:411
FBAnalyze::isset_sids_idx
uint32_t isset_sids_idx
Definition: detect-flowbits.c:400
detect-flowbits.h
FlowBitToggle
void FlowBitToggle(Flow *f, uint32_t idx)
Definition: flow-bit.c:94
Flow_::flowvar
GenericVar * flowvar
Definition: flow.h:495
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2161
FBAnalyze::unset_sids_idx
uint32_t unset_sids_idx
Definition: detect-flowbits.c:408
FBAnalyze::toggle_sids_size
uint32_t toggle_sids_size
Definition: detect-flowbits.c:413
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
SIG_FLAG_INIT_STATE_MATCH
#define SIG_FLAG_INIT_STATE_MATCH
Definition: detect.h:292
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:344
util-conf.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:518
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3312
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
VAR_TYPE_FLOW_BIT
@ VAR_TYPE_FLOW_BIT
Definition: util-var.h:36
FBAnalyze::state_cnts
uint16_t state_cnts[DETECT_FLOWBITS_CMD_MAX]
Definition: detect-flowbits.c:393
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3539
GenericVar_
Definition: util-var.h:50
util-spm.h
FBAnalyze::set_sids_idx
uint32_t set_sids_idx
Definition: detect-flowbits.c:396
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:849
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:60
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:232
ConfigGetLogDirectory
const char * ConfigGetLogDirectory(void)
Definition: util-conf.c:38
FlowBitIsset
int FlowBitIsset(Flow *f, uint32_t idx)
Definition: flow-bit.c:104
str
#define str(s)
Definition: suricata-common.h:291
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
FBAnalyze::isset_sids_size
uint32_t isset_sids_size
Definition: detect-flowbits.c:401
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DetectFlowbitsData_::or_list
uint32_t * or_list
Definition: detect-flowbits.h:39
Signature_::id
uint32_t id
Definition: detect.h:636
DETECT_FLOWBITS_CMD_UNSET
#define DETECT_FLOWBITS_CMD_UNSET
Definition: detect-flowbits.h:30
detect-parse.h
Signature_
Signature container.
Definition: detect.h:601
SigMatch_
a single match condition for a signature
Definition: detect.h:349
FBAnalyze::isnotset_sids_size
uint32_t isnotset_sids_size
Definition: detect-flowbits.c:405
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2558
DetectFlowbitMatch
int DetectFlowbitMatch(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect-flowbits.c:197
DetectEngineCtx_::sig_array
Signature ** sig_array
Definition: detect.h:858
Address_::family
char family
Definition: decode.h:115
Packet_::dst
Address dst
Definition: decode.h:484
SigMatchAppendSMToList
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:436
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:843
flow.h
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectEngineCtx_::sig_array_len
uint32_t sig_array_len
Definition: detect.h:859
FBAnalyze
Definition: detect-flowbits.c:391
SignatureInitData_::buffer_index
uint32_t buffer_index
Definition: detect.h:592
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect.h:1487
SCMutex
#define SCMutex
Definition: threads-debug.h:114
rule_engine_analysis_set
bool rule_engine_analysis_set
Definition: detect-engine-loader.c:55
FLOW_DESTROY
#define FLOW_DESTROY(f)
Definition: flow-util.h:121
Packet_::src
Address src
Definition: decode.h:483
FlowBitIsnotset
int FlowBitIsnotset(Flow *f, uint32_t idx)
Definition: flow-bit.c:116
DETECT_FLOWBITS_CMD_SET
#define DETECT_FLOWBITS_CMD_SET
Definition: detect-flowbits.h:28
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1293