suricata
detect-flow.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2020 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  * FLOW part of the detection engine.
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 
29 #include "detect.h"
30 #include "detect-parse.h"
31 #include "detect-engine.h"
33 #include "detect-engine-build.h"
34 
35 #include "flow.h"
36 #include "flow-var.h"
37 
38 #include "detect-flow.h"
39 
40 #include "util-unittest.h"
41 #include "util-unittest-helper.h"
42 #include "util-debug.h"
43 
44 /**
45  * \brief Regex for parsing our flow options
46  */
47 #define PARSE_REGEX "^\\s*([A-z_]+)\\s*(?:,\\s*([A-z_]+))?\\s*(?:,\\s*([A-z_]+))?\\s*$"
48 
49 static DetectParseRegex parse_regex;
50 
52  const Signature *, const SigMatchCtx *);
53 static int DetectFlowSetup (DetectEngineCtx *, Signature *, const char *);
54 #ifdef UNITTESTS
55 static void DetectFlowRegisterTests(void);
56 #endif
57 void DetectFlowFree(DetectEngineCtx *, void *);
58 
59 static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh);
60 static bool PrefilterFlowIsPrefilterable(const Signature *s);
61 
62 /**
63  * \brief Registration function for flow: keyword
64  */
65 void DetectFlowRegister (void)
66 {
68  sigmatch_table[DETECT_FLOW].desc = "match on direction and state of the flow";
69  sigmatch_table[DETECT_FLOW].url = "/rules/flow-keywords.html#flow";
71  sigmatch_table[DETECT_FLOW].Setup = DetectFlowSetup;
73 #ifdef UNITTESTS
74  sigmatch_table[DETECT_FLOW].RegisterTests = DetectFlowRegisterTests;
75 #endif
76  sigmatch_table[DETECT_FLOW].SupportsPrefilter = PrefilterFlowIsPrefilterable;
77  sigmatch_table[DETECT_FLOW].SetupPrefilter = PrefilterSetupFlow;
78 
79  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
80 }
81 
82 /**
83  * \param pflags packet flags (p->flags)
84  * \param pflowflags packet flow flags (p->flowflags)
85  * \param tflags detection flags (det_ctx->flags)
86  * \param dflags detect flow flags
87  * \param match_cnt number of matches to trigger
88  */
89 static inline int FlowMatch(const uint32_t pflags, const uint8_t pflowflags, const uint16_t tflags,
90  const uint16_t dflags, const uint16_t match_cnt)
91 {
92  uint8_t cnt = 0;
93 
94  if ((dflags & DETECT_FLOW_FLAG_NO_FRAG) &&
95  (!(pflags & PKT_REBUILT_FRAGMENT))) {
96  cnt++;
97  } else if ((dflags & DETECT_FLOW_FLAG_ONLY_FRAG) &&
98  (pflags & PKT_REBUILT_FRAGMENT)) {
99  cnt++;
100  }
101 
102  if ((dflags & DETECT_FLOW_FLAG_TOSERVER) && (pflowflags & FLOW_PKT_TOSERVER)) {
103  cnt++;
104  } else if ((dflags & DETECT_FLOW_FLAG_TOCLIENT) && (pflowflags & FLOW_PKT_TOCLIENT)) {
105  cnt++;
106  }
107 
108  if ((dflags & DETECT_FLOW_FLAG_ESTABLISHED) && (pflowflags & FLOW_PKT_ESTABLISHED)) {
109  cnt++;
110  } else if (dflags & DETECT_FLOW_FLAG_NOT_ESTABLISHED && (!(pflowflags & FLOW_PKT_ESTABLISHED))) {
111  cnt++;
112  } else if (dflags & DETECT_FLOW_FLAG_STATELESS) {
113  cnt++;
114  }
115 
117  if (dflags & DETECT_FLOW_FLAG_ONLYSTREAM)
118  cnt++;
119  } else {
120  if (dflags & DETECT_FLOW_FLAG_NOSTREAM)
121  cnt++;
122  }
123 
124  return (match_cnt == cnt) ? 1 : 0;
125 }
126 
127 /**
128  * \brief This function is used to match flow flags set on a packet with those passed via flow:
129  *
130  * \param t pointer to thread vars
131  * \param det_ctx pointer to the pattern matcher thread
132  * \param p pointer to the current packet
133  * \param m pointer to the sigmatch that we will cast into DetectFlowData
134  *
135  * \retval 0 no match
136  * \retval 1 match
137  */
139  const Signature *s, const SigMatchCtx *ctx)
140 {
141  SCEnter();
142 
143  SCLogDebug("pkt %p", p);
144 
145  if (p->flowflags & FLOW_PKT_TOSERVER) {
146  SCLogDebug("FLOW_PKT_TOSERVER");
147  } else if (p->flowflags & FLOW_PKT_TOCLIENT) {
148  SCLogDebug("FLOW_PKT_TOCLIENT");
149  }
150 
151  if (p->flowflags & FLOW_PKT_ESTABLISHED) {
152  SCLogDebug("FLOW_PKT_ESTABLISHED");
153  }
154 
155  const DetectFlowData *fd = (const DetectFlowData *)ctx;
156 
157  const int ret = FlowMatch(p->flags, p->flowflags, det_ctx->flags, fd->flags, fd->match_cnt);
158  SCLogDebug("returning %" PRId32 " fd->match_cnt %" PRId32 " fd->flags 0x%02X p->flowflags 0x%02X",
159  ret, fd->match_cnt, fd->flags, p->flowflags);
160  SCReturnInt(ret);
161 }
162 
163 /**
164  * \brief This function is used to parse flow options passed via flow: keyword
165  *
166  * \param de_ctx Pointer to the detection engine context
167  * \param flowstr Pointer to the user provided flow options
168  *
169  * \retval fd pointer to DetectFlowData on success
170  * \retval NULL on failure
171  */
172 static DetectFlowData *DetectFlowParse (DetectEngineCtx *de_ctx, const char *flowstr)
173 {
174  DetectFlowData *fd = NULL;
175  char *args[3] = {NULL,NULL,NULL};
176  int ret = 0, res = 0;
177  size_t pcre2len;
178  char str1[16] = "", str2[16] = "", str3[16] = "";
179 
180  ret = DetectParsePcreExec(&parse_regex, flowstr, 0, 0);
181  if (ret < 1 || ret > 4) {
182  SCLogError(SC_ERR_PCRE_MATCH, "parse error, ret %" PRId32 ", string %s", ret, flowstr);
183  goto error;
184  }
185 
186  if (ret > 1) {
187  pcre2len = sizeof(str1);
188  res = SC_Pcre2SubstringCopy(parse_regex.match, 1, (PCRE2_UCHAR8 *)str1, &pcre2len);
189  if (res < 0) {
190  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
191  goto error;
192  }
193  args[0] = (char *)str1;
194 
195  if (ret > 2) {
196  pcre2len = sizeof(str2);
197  res = pcre2_substring_copy_bynumber(
198  parse_regex.match, 2, (PCRE2_UCHAR8 *)str2, &pcre2len);
199  if (res < 0) {
200  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
201  goto error;
202  }
203  args[1] = (char *)str2;
204  }
205  if (ret > 3) {
206  pcre2len = sizeof(str3);
207  res = pcre2_substring_copy_bynumber(
208  parse_regex.match, 3, (PCRE2_UCHAR8 *)str3, &pcre2len);
209  if (res < 0) {
210  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_copy_bynumber failed");
211  goto error;
212  }
213  args[2] = (char *)str3;
214  }
215  }
216 
217  fd = SCMalloc(sizeof(DetectFlowData));
218  if (unlikely(fd == NULL))
219  goto error;
220  fd->flags = 0;
221  fd->match_cnt = 0;
222 
223  int i;
224  for (i = 0; i < (ret - 1); i++) {
225  if (args[i]) {
226  /* inspect our options and set the flags */
227  if (strcasecmp(args[i], "established") == 0) {
229  SCLogError(SC_ERR_FLAGS_MODIFIER, "DETECT_FLOW_FLAG_ESTABLISHED flag is already set");
230  goto error;
231  } else if (fd->flags & DETECT_FLOW_FLAG_STATELESS) {
232  SCLogError(SC_ERR_FLAGS_MODIFIER, "DETECT_FLOW_FLAG_STATELESS already set");
233  goto error;
234  }
236  } else if (strcasecmp(args[i], "not_established") == 0) {
238  SCLogError(SC_ERR_FLAGS_MODIFIER, "DETECT_FLOW_FLAG_NOT_ESTABLISHED flag is already set");
239  goto error;
240  } else if (fd->flags & DETECT_FLOW_FLAG_NOT_ESTABLISHED) {
241  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set DETECT_FLOW_FLAG_NOT_ESTABLISHED, DETECT_FLOW_FLAG_ESTABLISHED already set");
242  goto error;
243  }
245  } else if (strcasecmp(args[i], "stateless") == 0) {
246  if (fd->flags & DETECT_FLOW_FLAG_STATELESS) {
247  SCLogError(SC_ERR_FLAGS_MODIFIER, "DETECT_FLOW_FLAG_STATELESS flag is already set");
248  goto error;
249  } else if (fd->flags & DETECT_FLOW_FLAG_ESTABLISHED) {
250  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set DETECT_FLOW_FLAG_STATELESS, DETECT_FLOW_FLAG_ESTABLISHED already set");
251  goto error;
252  }
254  } else if (strcasecmp(args[i], "to_client") == 0 || strcasecmp(args[i], "from_server") == 0) {
255  if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
256  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set DETECT_FLOW_FLAG_TOCLIENT flag is already set");
257  goto error;
258  } else if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
259  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set to_client, DETECT_FLOW_FLAG_TOSERVER already set");
260  goto error;
261  }
263  } else if (strcasecmp(args[i], "to_server") == 0 || strcasecmp(args[i], "from_client") == 0){
264  if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
265  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set DETECT_FLOW_FLAG_TOSERVER flag is already set");
266  goto error;
267  } else if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
268  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set to_server, DETECT_FLOW_FLAG_TO_CLIENT flag already set");
269  goto error;
270  }
272  } else if (strcasecmp(args[i], "only_stream") == 0) {
274  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set only_stream flag is already set");
275  goto error;
276  } else if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM) {
277  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set only_stream flag, DETECT_FLOW_FLAG_NOSTREAM already set");
278  goto error;
279  }
281  } else if (strcasecmp(args[i], "no_stream") == 0) {
282  if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM) {
283  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set no_stream flag is already set");
284  goto error;
285  } else if (fd->flags & DETECT_FLOW_FLAG_ONLYSTREAM) {
286  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set no_stream flag, DETECT_FLOW_FLAG_ONLYSTREAM already set");
287  goto error;
288  }
290  } else if (strcasecmp(args[i], "no_frag") == 0) {
291  if (fd->flags & DETECT_FLOW_FLAG_NO_FRAG) {
292  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set no_frag flag is already set");
293  goto error;
294  } else if (fd->flags & DETECT_FLOW_FLAG_ONLY_FRAG) {
295  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set no_frag flag, only_frag already set");
296  goto error;
297  }
299  } else if (strcasecmp(args[i], "only_frag") == 0) {
300  if (fd->flags & DETECT_FLOW_FLAG_ONLY_FRAG) {
301  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set only_frag flag is already set");
302  goto error;
303  } else if (fd->flags & DETECT_FLOW_FLAG_NO_FRAG) {
304  SCLogError(SC_ERR_FLAGS_MODIFIER, "cannot set only_frag flag, no_frag already set");
305  goto error;
306  }
308  } else {
309  SCLogError(SC_ERR_INVALID_VALUE, "invalid flow option \"%s\"", args[i]);
310  goto error;
311  }
312 
313  fd->match_cnt++;
314  //printf("args[%" PRId32 "]: %s match_cnt: %" PRId32 " flags: 0x%02X\n", i, args[i], fd->match_cnt, fd->flags);
315  }
316  }
317  return fd;
318 
319 error:
320  if (fd != NULL)
321  DetectFlowFree(de_ctx, fd);
322  return NULL;
323 
324 }
325 
327 {
328 #define SIG_FLAG_BOTH (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)
329  BUG_ON(flags == 0);
332 
333  SCLogDebug("want %08lx", flags & SIG_FLAG_BOTH);
334  SCLogDebug("have %08lx", s->flags & SIG_FLAG_BOTH);
335 
336  if (flags & SIG_FLAG_TOSERVER) {
337  if ((s->flags & SIG_FLAG_BOTH) == SIG_FLAG_BOTH) {
338  /* both is set if we just have 'flow:established' */
339  s->flags &= ~SIG_FLAG_TOCLIENT;
340  } else if (s->flags & SIG_FLAG_TOCLIENT) {
341  return -1;
342  }
343  s->flags |= SIG_FLAG_TOSERVER;
344  } else {
345  if ((s->flags & SIG_FLAG_BOTH) == SIG_FLAG_BOTH) {
346  /* both is set if we just have 'flow:established' */
347  s->flags &= ~SIG_FLAG_TOSERVER;
348  } else if (s->flags & SIG_FLAG_TOSERVER) {
349  return -1;
350  }
351  s->flags |= SIG_FLAG_TOCLIENT;
352  }
353  return 0;
354 #undef SIG_FLAG_BOTH
355 }
356 
357 /**
358  * \brief this function is used to add the parsed flowdata into the current signature
359  *
360  * \param de_ctx pointer to the Detection Engine Context
361  * \param s pointer to the Current Signature
362  * \param flowstr pointer to the user provided flow options
363  *
364  * \retval 0 on Success
365  * \retval -1 on Failure
366  */
367 int DetectFlowSetup (DetectEngineCtx *de_ctx, Signature *s, const char *flowstr)
368 {
369  /* ensure only one flow option */
371  SCLogError (SC_ERR_INVALID_SIGNATURE, "A signature may have only one flow option.");
372  return -1;
373  }
374 
375  DetectFlowData *fd = DetectFlowParse(de_ctx, flowstr);
376  if (fd == NULL)
377  return -1;
378 
379  SigMatch *sm = SigMatchAlloc();
380  if (sm == NULL)
381  goto error;
382 
383  sm->type = DETECT_FLOW;
384  sm->ctx = (SigMatchCtx *)fd;
385 
386  /* set the signature direction flags */
387  if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
388  s->flags |= SIG_FLAG_TOSERVER;
389  } else if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
390  s->flags |= SIG_FLAG_TOCLIENT;
391  } else {
392  s->flags |= SIG_FLAG_TOSERVER;
393  s->flags |= SIG_FLAG_TOCLIENT;
394  }
397  }
398  if (fd->flags & DETECT_FLOW_FLAG_NOSTREAM) {
400  } else if (fd->flags == DETECT_FLOW_FLAG_TOSERVER ||
402  {
403  /* no direct flow is needed for just direction,
404  * no sigmatch is needed either. */
405  SigMatchFree(de_ctx, sm);
406  sm = NULL;
407  } else {
409  }
410 
411  if (sm != NULL) {
413  }
414  return 0;
415 
416 error:
417  if (fd != NULL)
418  DetectFlowFree(de_ctx, fd);
419  return -1;
420 
421 }
422 
423 /**
424  * \brief this function will free memory associated with DetectFlowData
425  *
426  * \param fd pointer to DetectFlowData
427  */
429 {
430  DetectFlowData *fd = (DetectFlowData *)ptr;
431  SCFree(fd);
432 }
433 
434 static void
435 PrefilterPacketFlowMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
436 {
437  const PrefilterPacketHeaderCtx *ctx = pectx;
438 
439  if (!PrefilterPacketHeaderExtraMatch(ctx, p))
440  return;
441 
442  if (FlowMatch(p->flags, p->flowflags, det_ctx->flags, ctx->v1.u16[0], ctx->v1.u16[1])) {
443  PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt);
444  }
445 }
446 
447 static void
448 PrefilterPacketFlowSet(PrefilterPacketHeaderValue *v, void *smctx)
449 {
450  const DetectFlowData *fb = smctx;
451  v->u16[0] = fb->flags;
452  v->u16[1] = fb->match_cnt;
453 }
454 
455 static bool
456 PrefilterPacketFlowCompare(PrefilterPacketHeaderValue v, void *smctx)
457 {
458  const DetectFlowData *fb = smctx;
459  if (v.u16[0] == fb->flags && v.u16[1] == fb->match_cnt) {
460  return true;
461  }
462  return false;
463 }
464 
465 static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
466 {
468  PrefilterPacketFlowSet,
469  PrefilterPacketFlowCompare,
470  PrefilterPacketFlowMatch);
471 }
472 
473 static bool PrefilterFlowIsPrefilterable(const Signature *s)
474 {
475  const SigMatch *sm;
476  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
477  switch (sm->type) {
478  case DETECT_FLOW:
479  return true;
480  }
481  }
482  return false;
483 }
484 
485 #ifdef UNITTESTS
486 
487 /**
488  * \test DetectFlowTestParse01 is a test to make sure that we return "something"
489  * when given valid flow opt
490  */
491 static int DetectFlowTestParse01 (void)
492 {
493  DetectFlowData *fd = NULL;
494  fd = DetectFlowParse(NULL, "established");
495  FAIL_IF_NULL(fd);
496  DetectFlowFree(NULL, fd);
497  PASS;
498 }
499 
500 /**
501  * \test DetectFlowTestParse02 is a test for setting the established flow opt
502  */
503 static int DetectFlowTestParse02 (void)
504 {
505  DetectFlowData *fd = NULL;
506  fd = DetectFlowParse(NULL, "established");
507  FAIL_IF_NULL(fd);
509  fd->match_cnt == 1);
510  PASS;
511 }
512 
513 /**
514  * \test DetectFlowTestParse03 is a test for setting the stateless flow opt
515  */
516 static int DetectFlowTestParse03 (void)
517 {
518  DetectFlowData *fd = NULL;
519  fd = DetectFlowParse(NULL, "stateless");
520  FAIL_IF_NULL(fd);
522  DetectFlowFree(NULL, fd);
523  PASS;
524 }
525 
526 /**
527  * \test DetectFlowTestParse04 is a test for setting the to_client flow opt
528  */
529 static int DetectFlowTestParse04 (void)
530 {
531  DetectFlowData *fd = NULL;
532  fd = DetectFlowParse(NULL, "to_client");
533  FAIL_IF_NULL(fd);
535  DetectFlowFree(NULL, fd);
536  PASS;
537 }
538 
539 /**
540  * \test DetectFlowTestParse05 is a test for setting the to_server flow opt
541  */
542 static int DetectFlowTestParse05 (void)
543 {
544  DetectFlowData *fd = NULL;
545  fd = DetectFlowParse(NULL, "to_server");
546  FAIL_IF_NULL(fd);
548  DetectFlowFree(NULL, fd);
549  PASS;
550 }
551 
552 /**
553  * \test DetectFlowTestParse06 is a test for setting the from_server flow opt
554  */
555 static int DetectFlowTestParse06 (void)
556 {
557  DetectFlowData *fd = NULL;
558  fd = DetectFlowParse(NULL, "from_server");
559  FAIL_IF_NULL(fd);
561  DetectFlowFree(NULL, fd);
562  PASS;
563 }
564 
565 /**
566  * \test DetectFlowTestParse07 is a test for setting the from_client flow opt
567  */
568 static int DetectFlowTestParse07 (void)
569 {
570  DetectFlowData *fd = NULL;
571  fd = DetectFlowParse(NULL, "from_client");
572  FAIL_IF_NULL(fd);
574  DetectFlowFree(NULL, fd);
575  PASS;
576 }
577 
578 /**
579  * \test DetectFlowTestParse08 is a test for setting the established,to_client flow opts
580  */
581 static int DetectFlowTestParse08 (void)
582 {
583  DetectFlowData *fd = NULL;
584  fd = DetectFlowParse(NULL, "established,to_client");
585  FAIL_IF_NULL(fd);
587  DetectFlowFree(NULL, fd);
588  PASS;
589 }
590 
591 /**
592  * \test DetectFlowTestParse09 is a test for setting the to_client,stateless flow opts (order of state,dir reversed)
593  */
594 static int DetectFlowTestParse09 (void)
595 {
596  DetectFlowData *fd = NULL;
597  fd = DetectFlowParse(NULL, "to_client,stateless");
598  FAIL_IF_NULL(fd);
601  fd->match_cnt == 2);
602  DetectFlowFree(NULL, fd);
603  PASS;
604 }
605 
606 /**
607  * \test DetectFlowTestParse10 is a test for setting the from_server,stateless flow opts (order of state,dir reversed)
608  */
609 static int DetectFlowTestParse10 (void)
610 {
611  DetectFlowData *fd = NULL;
612  fd = DetectFlowParse(NULL, "from_server,stateless");
613  FAIL_IF_NULL(fd);
616  fd->match_cnt == 2);
617  DetectFlowFree(NULL, fd);
618  PASS;
619 }
620 
621 /**
622  * \test DetectFlowTestParse11 is a test for setting the from_server,stateless flow opts with spaces all around
623  */
624 static int DetectFlowTestParse11 (void)
625 {
626  DetectFlowData *fd = NULL;
627  fd = DetectFlowParse(NULL, " from_server , stateless ");
628  FAIL_IF_NULL(fd);
631  fd->match_cnt == 2);
632  DetectFlowFree(NULL, fd);
633  PASS;
634 }
635 
636 /**
637  * \test DetectFlowTestParseNocase01 is a test to make sure that we return "something"
638  * when given valid flow opt
639  */
640 static int DetectFlowTestParseNocase01 (void)
641 {
642  DetectFlowData *fd = NULL;
643  fd = DetectFlowParse(NULL, "ESTABLISHED");
644  FAIL_IF_NULL(fd);
645  DetectFlowFree(NULL, fd);
646  PASS;
647 }
648 
649 /**
650  * \test DetectFlowTestParseNocase02 is a test for setting the established flow opt
651  */
652 static int DetectFlowTestParseNocase02 (void)
653 {
654  DetectFlowData *fd = NULL;
655  fd = DetectFlowParse(NULL, "ESTABLISHED");
656  FAIL_IF_NULL(fd);
658  fd->match_cnt == 1);
659  DetectFlowFree(NULL, fd);
660  PASS;
661 }
662 
663 /**
664  * \test DetectFlowTestParseNocase03 is a test for setting the stateless flow opt
665  */
666 static int DetectFlowTestParseNocase03 (void)
667 {
668  DetectFlowData *fd = NULL;
669  fd = DetectFlowParse(NULL, "STATELESS");
670  FAIL_IF_NULL(fd);
672  PASS;
673 }
674 
675 /**
676  * \test DetectFlowTestParseNocase04 is a test for setting the to_client flow opt
677  */
678 static int DetectFlowTestParseNocase04 (void)
679 {
680  DetectFlowData *fd = NULL;
681  fd = DetectFlowParse(NULL, "TO_CLIENT");
682  FAIL_IF_NULL(fd);
684  DetectFlowFree(NULL, fd);
685  PASS;
686 }
687 
688 /**
689  * \test DetectFlowTestParseNocase05 is a test for setting the to_server flow opt
690  */
691 static int DetectFlowTestParseNocase05 (void)
692 {
693  DetectFlowData *fd = NULL;
694  fd = DetectFlowParse(NULL, "TO_SERVER");
695  FAIL_IF_NULL(fd);
697  DetectFlowFree(NULL, fd);
698  PASS;
699 }
700 
701 /**
702  * \test DetectFlowTestParseNocase06 is a test for setting the from_server flow opt
703  */
704 static int DetectFlowTestParseNocase06 (void)
705 {
706  DetectFlowData *fd = NULL;
707  fd = DetectFlowParse(NULL, "FROM_SERVER");
708  FAIL_IF_NULL(fd);
710  DetectFlowFree(NULL, fd);
711  PASS;
712 }
713 
714 /**
715  * \test DetectFlowTestParseNocase07 is a test for setting the from_client flow opt
716  */
717 static int DetectFlowTestParseNocase07 (void)
718 {
719  DetectFlowData *fd = NULL;
720  fd = DetectFlowParse(NULL, "FROM_CLIENT");
721  FAIL_IF_NULL(fd);
723  DetectFlowFree(NULL, fd);
724  PASS;
725 }
726 
727 /**
728  * \test DetectFlowTestParseNocase08 is a test for setting the established,to_client flow opts
729  */
730 static int DetectFlowTestParseNocase08 (void)
731 {
732  DetectFlowData *fd = NULL;
733  fd = DetectFlowParse(NULL, "ESTABLISHED,TO_CLIENT");
734  FAIL_IF_NULL(fd);
737  fd->match_cnt == 2);
738  DetectFlowFree(NULL, fd);
739  PASS;
740 }
741 
742 /**
743  * \test DetectFlowTestParseNocase09 is a test for setting the to_client,stateless flow opts (order of state,dir reversed)
744  */
745 static int DetectFlowTestParseNocase09 (void)
746 {
747  DetectFlowData *fd = NULL;
748  fd = DetectFlowParse(NULL, "TO_CLIENT,STATELESS");
749  FAIL_IF_NULL(fd);
752  fd->match_cnt == 2);
753  DetectFlowFree(NULL, fd);
754  PASS;
755 }
756 
757 /**
758  * \test DetectFlowTestParseNocase10 is a test for setting the from_server,stateless flow opts (order of state,dir reversed)
759  */
760 static int DetectFlowTestParseNocase10 (void)
761 {
762  DetectFlowData *fd = NULL;
763  fd = DetectFlowParse(NULL, "FROM_SERVER,STATELESS");
764  FAIL_IF_NULL(fd);
767  fd->match_cnt == 2);
768  DetectFlowFree(NULL, fd);
769  PASS;
770 }
771 
772 /**
773  * \test DetectFlowTestParseNocase11 is a test for setting the from_server,stateless flow opts with spaces all around
774  */
775 static int DetectFlowTestParseNocase11 (void)
776 {
777  DetectFlowData *fd = NULL;
778  fd = DetectFlowParse(NULL, " FROM_SERVER , STATELESS ");
779  FAIL_IF_NULL(fd);
782  fd->match_cnt == 2);
783  DetectFlowFree(NULL, fd);
784  PASS;
785 }
786 
787 /**
788  * \test DetectFlowTestParse12 is a test for setting an invalid seperator :
789  */
790 static int DetectFlowTestParse12 (void)
791 {
792  DetectFlowData *fd = NULL;
793  fd = DetectFlowParse(NULL, "from_server:stateless");
794  FAIL_IF_NOT_NULL(fd);
795  PASS;
796 }
797 
798 /**
799  * \test DetectFlowTestParse13 is a test for an invalid option
800  */
801 static int DetectFlowTestParse13 (void)
802 {
803  DetectFlowData *fd = NULL;
804  fd = DetectFlowParse(NULL, "invalidoptiontest");
805  FAIL_IF_NOT_NULL(fd);
806  PASS;
807 }
808 
809 /**
810  * \test DetectFlowTestParse14 is a test for a empty option
811  */
812 static int DetectFlowTestParse14 (void)
813 {
814  DetectFlowData *fd = NULL;
815  fd = DetectFlowParse(NULL, "");
816  FAIL_IF_NOT_NULL(fd);
817  PASS;
818 }
819 
820 /**
821  * \test DetectFlowTestParse15 is a test for an invalid combo of options established,stateless
822  */
823 static int DetectFlowTestParse15 (void)
824 {
825  DetectFlowData *fd = NULL;
826  fd = DetectFlowParse(NULL, "established,stateless");
827  FAIL_IF_NOT_NULL(fd);
828  PASS;
829 }
830 
831 /**
832  * \test DetectFlowTestParse16 is a test for an invalid combo of options to_client,to_server
833  */
834 static int DetectFlowTestParse16 (void)
835 {
836  DetectFlowData *fd = NULL;
837  fd = DetectFlowParse(NULL, "to_client,to_server");
838  FAIL_IF_NOT_NULL(fd);
839  PASS;
840 }
841 
842 /**
843  * \test DetectFlowTestParse16 is a test for an invalid combo of options to_client,from_server
844  * flowbit flags are the same
845  */
846 static int DetectFlowTestParse17 (void)
847 {
848  DetectFlowData *fd = NULL;
849  fd = DetectFlowParse(NULL, "to_client,from_server");
850  FAIL_IF_NOT_NULL(fd);
851  PASS;
852 }
853 
854 /**
855  * \test DetectFlowTestParse18 is a test for setting the from_server,stateless,only_stream flow opts (order of state,dir reversed)
856  */
857 static int DetectFlowTestParse18 (void)
858 {
859  DetectFlowData *fd = NULL;
860  fd = DetectFlowParse(NULL, "from_server,established,only_stream");
861  FAIL_IF_NULL(fd);
865  fd->match_cnt == 3);
866  DetectFlowFree(NULL, fd);
867  PASS;
868 }
869 
870 /**
871  * \test DetectFlowTestParseNocase18 is a test for setting the from_server,stateless,only_stream flow opts (order of state,dir reversed)
872  */
873 static int DetectFlowTestParseNocase18 (void)
874 {
875  DetectFlowData *fd = NULL;
876  fd = DetectFlowParse(NULL, "FROM_SERVER,ESTABLISHED,ONLY_STREAM");
877  FAIL_IF_NULL(fd);
881  fd->match_cnt == 3);
882  DetectFlowFree(NULL, fd);
883  PASS;
884 }
885 
886 
887 /**
888  * \test DetectFlowTestParse19 is a test for one to many options passed to DetectFlowParse
889  */
890 static int DetectFlowTestParse19 (void)
891 {
892  DetectFlowData *fd = NULL;
893  fd = DetectFlowParse(NULL, "from_server,established,only_stream,a");
894  FAIL_IF_NOT_NULL(fd);
895  PASS;
896 }
897 
898 /**
899  * \test DetectFlowTestParse20 is a test for setting from_server, established, no_stream
900  */
901 static int DetectFlowTestParse20 (void)
902 {
903  DetectFlowData *fd = NULL;
904  fd = DetectFlowParse(NULL, "from_server,established,no_stream");
905  FAIL_IF_NULL(fd);
909  fd->match_cnt == 3);
910  DetectFlowFree(NULL, fd);
911  PASS;
912 }
913 
914 /**
915  * \test DetectFlowTestParse20 is a test for setting from_server, established, no_stream
916  */
917 static int DetectFlowTestParseNocase20 (void)
918 {
919  DetectFlowData *fd = NULL;
920  fd = DetectFlowParse(NULL, "FROM_SERVER,ESTABLISHED,NO_STREAM");
921  FAIL_IF_NULL(fd);
925  fd->match_cnt == 3);
926  DetectFlowFree(NULL, fd);
927  PASS;
928 }
929 
930 /**
931  * \test DetectFlowTestParse21 is a test for an invalid opt between to valid opts
932  */
933 static int DetectFlowTestParse21 (void)
934 {
935  DetectFlowData *fd = NULL;
936  fd = DetectFlowParse(NULL, "from_server,a,no_stream");
937  FAIL_IF_NOT_NULL(fd);
938  PASS;
939 }
940 
941 static int DetectFlowSigTest01(void)
942 {
943  uint8_t *buf = (uint8_t *)"supernovaduper";
944  uint16_t buflen = strlen((char *)buf);
945  ThreadVars th_v;
947  memset(&dtv, 0, sizeof(DecodeThreadVars));
948  memset(&th_v, 0, sizeof(th_v));
949 
950  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
951  FAIL_IF_NULL(p);
952 
953  const char *sig1 = "alert tcp any any -> any any (msg:\"dummy\"; "
954  "content:\"nova\"; flow:no_stream; sid:1;)";
955 
958  de_ctx->flags |= DE_QUIET;
959 
960  de_ctx->sig_list = SigInit(de_ctx, sig1);
962 
964  DetectEngineThreadCtx *det_ctx = NULL;
965  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
966  FAIL_IF_NULL(det_ctx);
967 
968  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
969  FAIL_IF(PacketAlertCheck(p, 1) != 1);
970 
971  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
973  UTHFreePacket(p);
974 
975  PASS;
976 }
977 
978 /**
979  * \test Test parsing of the not_established keyword.
980  */
981 static int DetectFlowTestParseNotEstablished(void)
982 {
983  DetectFlowData *fd = NULL;
984  fd = DetectFlowParse(NULL, "not_established");
985  FAIL_IF_NULL(fd);
987  DetectFlowFree(NULL, fd);
988  PASS;
989 }
990 
991 /**
992  * \test Test parsing of the "no_frag" flow argument.
993  */
994 static int DetectFlowTestParseNoFrag(void)
995 {
996  DetectFlowData *fd = NULL;
997  fd = DetectFlowParse(NULL, "no_frag");
998  FAIL_IF_NULL(fd);
1000  DetectFlowFree(NULL, fd);
1001  PASS;
1002 }
1003 
1004 /**
1005  * \test Test parsing of the "only_frag" flow argument.
1006  */
1007 static int DetectFlowTestParseOnlyFrag(void)
1008 {
1009  DetectFlowData *fd = NULL;
1010  fd = DetectFlowParse(NULL, "only_frag");
1011  FAIL_IF_NULL(fd);
1013  DetectFlowFree(NULL, fd);
1014  PASS;
1015 }
1016 
1017 /**
1018  * \test Test that parsing of only_frag and no_frag together fails.
1019  */
1020 static int DetectFlowTestParseNoFragOnlyFrag(void)
1021 {
1022  DetectFlowData *fd = NULL;
1023  fd = DetectFlowParse(NULL, "no_frag,only_frag");
1024  FAIL_IF_NOT_NULL(fd);
1025  PASS;
1026 }
1027 
1028 /**
1029  * \test Test no_frag matching.
1030  */
1031 static int DetectFlowTestNoFragMatch(void)
1032 {
1033  uint32_t pflags = 0;
1034  DetectFlowData *fd = DetectFlowParse(NULL, "no_frag");
1035  FAIL_IF_NULL(fd);
1037  FAIL_IF_NOT(fd->match_cnt == 1);
1038  FAIL_IF_NOT(FlowMatch(pflags, 0, 0, fd->flags, fd->match_cnt));
1039  pflags |= PKT_REBUILT_FRAGMENT;
1040  FAIL_IF(FlowMatch(pflags, 0, 0, fd->flags, fd->match_cnt));
1041  PASS;
1042 }
1043 
1044 /**
1045  * \test Test only_frag matching.
1046  */
1047 static int DetectFlowTestOnlyFragMatch(void)
1048 {
1049  uint32_t pflags = 0;
1050  DetectFlowData *fd = DetectFlowParse(NULL, "only_frag");
1051  FAIL_IF_NULL(fd);
1053  FAIL_IF_NOT(fd->match_cnt == 1);
1054  FAIL_IF(FlowMatch(pflags, 0, 0, fd->flags, fd->match_cnt));
1055  pflags |= PKT_REBUILT_FRAGMENT;
1056  FAIL_IF_NOT(FlowMatch(pflags, 0, 0, fd->flags, fd->match_cnt));
1057  PASS;
1058 }
1059 
1060 /**
1061  * \brief this function registers unit tests for DetectFlow
1062  */
1063 static void DetectFlowRegisterTests(void)
1064 {
1065  UtRegisterTest("DetectFlowTestParse01", DetectFlowTestParse01);
1066  UtRegisterTest("DetectFlowTestParse02", DetectFlowTestParse02);
1067  UtRegisterTest("DetectFlowTestParse03", DetectFlowTestParse03);
1068  UtRegisterTest("DetectFlowTestParse04", DetectFlowTestParse04);
1069  UtRegisterTest("DetectFlowTestParse05", DetectFlowTestParse05);
1070  UtRegisterTest("DetectFlowTestParse06", DetectFlowTestParse06);
1071  UtRegisterTest("DetectFlowTestParse07", DetectFlowTestParse07);
1072  UtRegisterTest("DetectFlowTestParse08", DetectFlowTestParse08);
1073  UtRegisterTest("DetectFlowTestParse09", DetectFlowTestParse09);
1074  UtRegisterTest("DetectFlowTestParse10", DetectFlowTestParse10);
1075  UtRegisterTest("DetectFlowTestParse11", DetectFlowTestParse11);
1076  UtRegisterTest("DetectFlowTestParseNocase01", DetectFlowTestParseNocase01);
1077  UtRegisterTest("DetectFlowTestParseNocase02", DetectFlowTestParseNocase02);
1078  UtRegisterTest("DetectFlowTestParseNocase03", DetectFlowTestParseNocase03);
1079  UtRegisterTest("DetectFlowTestParseNocase04", DetectFlowTestParseNocase04);
1080  UtRegisterTest("DetectFlowTestParseNocase05", DetectFlowTestParseNocase05);
1081  UtRegisterTest("DetectFlowTestParseNocase06", DetectFlowTestParseNocase06);
1082  UtRegisterTest("DetectFlowTestParseNocase07", DetectFlowTestParseNocase07);
1083  UtRegisterTest("DetectFlowTestParseNocase08", DetectFlowTestParseNocase08);
1084  UtRegisterTest("DetectFlowTestParseNocase09", DetectFlowTestParseNocase09);
1085  UtRegisterTest("DetectFlowTestParseNocase10", DetectFlowTestParseNocase10);
1086  UtRegisterTest("DetectFlowTestParseNocase11", DetectFlowTestParseNocase11);
1087  UtRegisterTest("DetectFlowTestParse12", DetectFlowTestParse12);
1088  UtRegisterTest("DetectFlowTestParse13", DetectFlowTestParse13);
1089  UtRegisterTest("DetectFlowTestParse14", DetectFlowTestParse14);
1090  UtRegisterTest("DetectFlowTestParse15", DetectFlowTestParse15);
1091  UtRegisterTest("DetectFlowTestParse16", DetectFlowTestParse16);
1092  UtRegisterTest("DetectFlowTestParse17", DetectFlowTestParse17);
1093  UtRegisterTest("DetectFlowTestParse18", DetectFlowTestParse18);
1094  UtRegisterTest("DetectFlowTestParseNocase18", DetectFlowTestParseNocase18);
1095  UtRegisterTest("DetectFlowTestParse19", DetectFlowTestParse19);
1096  UtRegisterTest("DetectFlowTestParse20", DetectFlowTestParse20);
1097  UtRegisterTest("DetectFlowTestParseNocase20", DetectFlowTestParseNocase20);
1098  UtRegisterTest("DetectFlowTestParse21", DetectFlowTestParse21);
1099  UtRegisterTest("DetectFlowTestParseNotEstablished",
1100  DetectFlowTestParseNotEstablished);
1101  UtRegisterTest("DetectFlowTestParseNoFrag", DetectFlowTestParseNoFrag);
1102  UtRegisterTest("DetectFlowTestParseOnlyFrag",
1103  DetectFlowTestParseOnlyFrag);
1104  UtRegisterTest("DetectFlowTestParseNoFragOnlyFrag",
1105  DetectFlowTestParseNoFragOnlyFrag);
1106  UtRegisterTest("DetectFlowTestNoFragMatch", DetectFlowTestNoFragMatch);
1107  UtRegisterTest("DetectFlowTestOnlyFragMatch", DetectFlowTestOnlyFragMatch);
1108 
1109  UtRegisterTest("DetectFlowSigTest01", DetectFlowSigTest01);
1110 }
1111 #endif /* UNITTESTS */
DETECT_FLOW_FLAG_TOCLIENT
#define DETECT_FLOW_FLAG_TOCLIENT
Definition: detect-flow.h:28
DETECT_FLOW_FLAG_STATELESS
#define DETECT_FLOW_FLAG_STATELESS
Definition: detect-flow.h:31
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
SigTableElmt_::url
const char * url
Definition: detect.h:1248
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SigTableElmt_::desc
const char * desc
Definition: detect.h:1247
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2475
SigMatchFree
void SigMatchFree(DetectEngineCtx *de_ctx, SigMatch *sm)
free a SigMatch
Definition: detect-parse.c:250
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1235
DetectFlowData_
Definition: detect-flow.h:37
DetectParseRegex
Definition: detect-parse.h:42
DETECT_FLOW_FLAG_NOSTREAM
#define DETECT_FLOW_FLAG_NOSTREAM
Definition: detect-flow.h:33
SigTableElmt_::name
const char * name
Definition: detect.h:1245
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1403
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:252
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:52
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:296
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:142
Packet_::flags
uint32_t flags
Definition: decode.h:469
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2116
DetectFlowData_::match_cnt
uint8_t match_cnt
Definition: detect-flow.h:39
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1141
DetectFlowData_::flags
uint16_t flags
Definition: detect-flow.h:38
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:785
SC_ERR_INVALID_SIGNATURE
@ SC_ERR_INVALID_SIGNATURE
Definition: util-error.h:69
PrefilterPacketHeaderCtx_::sigs_array
SigIntId * sigs_array
Definition: detect-engine-prefilter-common.h:43
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2445
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:223
SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_REQUIRE_STREAM
Definition: detect.h:218
DetectEngineThreadCtx_::flags
uint16_t flags
Definition: detect.h:1102
DE_QUIET
#define DE_QUIET
Definition: detect.h:288
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:338
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1785
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:503
PrefilterPacketHeaderCtx_::sigs_cnt
uint32_t sigs_cnt
Definition: detect-engine-prefilter-common.h:42
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:465
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:231
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1230
DetectFlowSetupImplicit
int DetectFlowSetupImplicit(Signature *s, uint32_t flags)
Definition: detect-flow.c:326
PrefilterPacketHeaderValue::u16
uint16_t u16[8]
Definition: detect-engine-prefilter-common.h:25
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
SigTableElmt_::SetupPrefilter
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
Definition: detect.h:1233
DETECT_FLOW_FLAG_ONLYSTREAM
#define DETECT_FLOW_FLAG_ONLYSTREAM
Definition: detect-flow.h:32
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:230
PrefilterPacketHeaderCtx_
Definition: detect-engine-prefilter-common.h:35
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
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1034
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our flow options.
Definition: detect-flow.c:47
DETECT_FLOW_FLAG_TOSERVER
#define DETECT_FLOW_FLAG_TOSERVER
Definition: detect-flow.h:27
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2598
SCEnter
#define SCEnter(...)
Definition: util-debug.h:298
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:318
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:80
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:317
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:281
Signature_::flags
uint32_t flags
Definition: detect.h:541
Packet_
Definition: decode.h:434
detect-engine-build.h
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:611
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1213
SignatureInitData_::smlists
struct SigMatch_ ** smlists
Definition: detect.h:534
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:224
SigMatchAlloc
SigMatch * SigMatchAlloc(void)
Definition: detect-parse.c:235
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:1953
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:32
PrefilterPacketHeaderCtx_::v1
PrefilterPacketHeaderValue v1
Definition: detect-engine-prefilter-common.h:36
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:309
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3154
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3368
SigMatch_::type
uint16_t type
Definition: detect.h:315
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:255
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:791
DetectFlowRegister
void DetectFlowRegister(void)
Registration function for flow: keyword.
Definition: detect-flow.c:65
SIG_FLAG_BOTH
#define SIG_FLAG_BOTH
PrefilterSetupPacketHeader
int PrefilterSetupPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh, int sm_type, void(*Set)(PrefilterPacketHeaderValue *v, void *), bool(*Compare)(PrefilterPacketHeaderValue v, void *), void(*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
Definition: detect-engine-prefilter-common.c:417
DETECT_FLOW_FLAG_NOT_ESTABLISHED
#define DETECT_FLOW_FLAG_NOT_ESTABLISHED
Definition: detect-flow.h:30
detect-flow.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
DETECT_FLOW_FLAG_ONLY_FRAG
#define DETECT_FLOW_FLAG_ONLY_FRAG
Definition: detect-flow.h:35
DETECT_ENGINE_THREAD_CTX_STREAM_CONTENT_MATCH
#define DETECT_ENGINE_THREAD_CTX_STREAM_CONTENT_MATCH
Definition: detect.h:276
PKT_REBUILT_FRAGMENT
#define PKT_REBUILT_FRAGMENT
Definition: decode.h:1205
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:664
SigTableElmt_::SupportsPrefilter
bool(* SupportsPrefilter)(const Signature *s)
Definition: detect.h:1232
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:486
DETECT_FLOW_FLAG_ESTABLISHED
#define DETECT_FLOW_FLAG_ESTABLISHED
Definition: detect-flow.h:29
detect-parse.h
DetectFlowFree
void DetectFlowFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectFlowData
Definition: detect-flow.c:428
Signature_
Signature container.
Definition: detect.h:540
SigMatch_
a single match condition for a signature
Definition: detect.h:314
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:225
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2406
SC_Pcre2SubstringCopy
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:2574
SC_ERR_FLAGS_MODIFIER
@ SC_ERR_FLAGS_MODIFIER
Definition: util-error.h:133
DetectFlowMatch
int DetectFlowMatch(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
This function is used to match flow flags set on a packet with those passed via flow:
Definition: detect-flow.c:138
PrefilterPacketHeaderValue
Definition: detect-engine-prefilter-common.h:23
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:786
detect-engine-prefilter-common.h
flow.h
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:302
flow-var.h
DETECT_FLOW_FLAG_NO_FRAG
#define DETECT_FLOW_FLAG_NO_FRAG
Definition: detect-flow.h:34
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1237
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:217