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-helper.h"
41 #include "util-debug.h"
42 
43 /**
44  * \brief Regex for parsing our flow options
45  */
46 #define PARSE_REGEX "^\\s*([A-z_]+)\\s*(?:,\\s*([A-z_]+))?\\s*(?:,\\s*([A-z_]+))?\\s*$"
47 
48 static DetectParseRegex parse_regex;
49 
51  const Signature *, const SigMatchCtx *);
52 static int DetectFlowSetup (DetectEngineCtx *, Signature *, const char *);
53 #ifdef UNITTESTS
54 static void DetectFlowRegisterTests(void);
55 #endif
56 void DetectFlowFree(DetectEngineCtx *, void *);
57 
58 static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh);
59 static bool PrefilterFlowIsPrefilterable(const Signature *s);
60 
61 /**
62  * \brief Registration function for flow: keyword
63  */
64 void DetectFlowRegister (void)
65 {
67  sigmatch_table[DETECT_FLOW].desc = "match on direction and state of the flow";
68  sigmatch_table[DETECT_FLOW].url = "/rules/flow-keywords.html#flow";
70  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  /* all but pre_flow */
82 
83  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
84 }
85 
86 /**
87  * \param pflags packet flags (p->flags)
88  * \param pflowflags packet flow flags (p->flowflags)
89  * \param dflags detect flow flags
90  * \param match_cnt number of matches to trigger
91  */
92 static inline int FlowMatch(const uint32_t pflags, const uint8_t pflowflags, const uint16_t dflags,
93  const uint16_t match_cnt)
94 {
95  uint8_t cnt = 0;
96 
97  if ((dflags & DETECT_FLOW_FLAG_NO_FRAG) &&
98  (!(pflags & PKT_REBUILT_FRAGMENT))) {
99  cnt++;
100  } else if ((dflags & DETECT_FLOW_FLAG_ONLY_FRAG) &&
101  (pflags & PKT_REBUILT_FRAGMENT)) {
102  cnt++;
103  }
104 
105  if ((dflags & DETECT_FLOW_FLAG_TOSERVER) && (pflowflags & FLOW_PKT_TOSERVER)) {
106  cnt++;
107  } else if ((dflags & DETECT_FLOW_FLAG_TOCLIENT) && (pflowflags & FLOW_PKT_TOCLIENT)) {
108  cnt++;
109  }
110 
111  if ((dflags & DETECT_FLOW_FLAG_ESTABLISHED) && (pflowflags & FLOW_PKT_ESTABLISHED)) {
112  cnt++;
113  } else if (dflags & DETECT_FLOW_FLAG_NOT_ESTABLISHED && (!(pflowflags & FLOW_PKT_ESTABLISHED))) {
114  cnt++;
115  } else if (dflags & DETECT_FLOW_FLAG_STATELESS) {
116  cnt++;
117  }
118 
119  return (match_cnt == cnt) ? 1 : 0;
120 }
121 
122 /**
123  * \brief This function is used to match flow flags set on a packet with those passed via flow:
124  *
125  * \param t pointer to thread vars
126  * \param det_ctx pointer to the pattern matcher thread
127  * \param p pointer to the current packet
128  * \param m pointer to the sigmatch that we will cast into DetectFlowData
129  *
130  * \retval 0 no match
131  * \retval 1 match
132  */
134  const Signature *s, const SigMatchCtx *ctx)
135 {
136  SCEnter();
137 
138  SCLogDebug("pkt %p", p);
139 
140  if (p->flowflags & FLOW_PKT_TOSERVER) {
141  SCLogDebug("FLOW_PKT_TOSERVER");
142  } else if (p->flowflags & FLOW_PKT_TOCLIENT) {
143  SCLogDebug("FLOW_PKT_TOCLIENT");
144  }
145 
147  SCLogDebug("FLOW_PKT_ESTABLISHED");
148  }
149 
150  const DetectFlowData *fd = (const DetectFlowData *)ctx;
151 
152  const int ret = FlowMatch(p->flags, p->flowflags, fd->flags, fd->match_cnt);
153  SCLogDebug("returning %" PRId32 " fd->match_cnt %" PRId32 " fd->flags 0x%02X p->flowflags 0x%02X",
154  ret, fd->match_cnt, fd->flags, p->flowflags);
155  SCReturnInt(ret);
156 }
157 
158 /**
159  * \brief This function is used to parse flow options passed via flow: keyword
160  *
161  * \param de_ctx Pointer to the detection engine context
162  * \param flowstr Pointer to the user provided flow options
163  * \param[out] parse_flags keyword flags only used during parsing
164  *
165  * \retval fd pointer to DetectFlowData on success
166  * \retval NULL on failure
167  */
168 static DetectFlowData *DetectFlowParse(
169  DetectEngineCtx *de_ctx, const char *flowstr, uint16_t *parse_flags)
170 {
171  DetectFlowData *fd = NULL;
172  char *args[3] = {NULL,NULL,NULL};
173  int res = 0;
174  size_t pcre2len;
175  char str1[16] = "", str2[16] = "", str3[16] = "";
176  pcre2_match_data *match = NULL;
177 
178  int ret = DetectParsePcreExec(&parse_regex, &match, flowstr, 0, 0);
179  if (ret < 1 || ret > 4) {
180  SCLogError("parse error, ret %" PRId32 ", string %s", ret, flowstr);
181  goto error;
182  }
183 
184  if (ret > 1) {
185  pcre2len = sizeof(str1);
186  res = SC_Pcre2SubstringCopy(match, 1, (PCRE2_UCHAR8 *)str1, &pcre2len);
187  if (res < 0) {
188  SCLogError("pcre2_substring_copy_bynumber failed");
189  goto error;
190  }
191  args[0] = (char *)str1;
192 
193  if (ret > 2) {
194  pcre2len = sizeof(str2);
195  res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)str2, &pcre2len);
196  if (res < 0) {
197  SCLogError("pcre2_substring_copy_bynumber failed");
198  goto error;
199  }
200  args[1] = (char *)str2;
201  }
202  if (ret > 3) {
203  pcre2len = sizeof(str3);
204  res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)str3, &pcre2len);
205  if (res < 0) {
206  SCLogError("pcre2_substring_copy_bynumber failed");
207  goto error;
208  }
209  args[2] = (char *)str3;
210  }
211  }
212 
213  fd = SCMalloc(sizeof(DetectFlowData));
214  if (unlikely(fd == NULL))
215  goto error;
216  fd->flags = 0;
217  fd->match_cnt = 0;
218 
219  for (int i = 0; i < (ret - 1); i++) {
220  if (args[i]) {
221  /* inspect our options and set the flags */
222  if (strcasecmp(args[i], "established") == 0) {
224  SCLogError("DETECT_FLOW_FLAG_ESTABLISHED flag is already set");
225  goto error;
226  } else if (fd->flags & DETECT_FLOW_FLAG_NOT_ESTABLISHED) {
227  SCLogError("cannot set DETECT_FLOW_FLAG_ESTABLISHED, "
228  "DETECT_FLOW_FLAG_NOT_ESTABLISHED already set");
229  goto error;
230  } else if (fd->flags & DETECT_FLOW_FLAG_STATELESS) {
231  SCLogError("DETECT_FLOW_FLAG_STATELESS already set");
232  goto error;
233  }
235  fd->match_cnt++;
236  } else if (strcasecmp(args[i], "not_established") == 0) {
238  SCLogError("DETECT_FLOW_FLAG_NOT_ESTABLISHED flag is already set");
239  goto error;
240  } else if (fd->flags & DETECT_FLOW_FLAG_ESTABLISHED) {
241  SCLogError("cannot set DETECT_FLOW_FLAG_NOT_ESTABLISHED, "
242  "DETECT_FLOW_FLAG_ESTABLISHED already set");
243  goto error;
244  }
246  fd->match_cnt++;
247  } else if (strcasecmp(args[i], "stateless") == 0) {
248  if (fd->flags & DETECT_FLOW_FLAG_STATELESS) {
249  SCLogError("DETECT_FLOW_FLAG_STATELESS flag is already set");
250  goto error;
251  } else if (fd->flags & DETECT_FLOW_FLAG_ESTABLISHED) {
252  SCLogError("cannot set DETECT_FLOW_FLAG_STATELESS, "
253  "DETECT_FLOW_FLAG_ESTABLISHED already set");
254  goto error;
255  }
257  fd->match_cnt++;
258  } else if (strcasecmp(args[i], "to_client") == 0 || strcasecmp(args[i], "from_server") == 0) {
259  if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
260  SCLogError("cannot set DETECT_FLOW_FLAG_TOCLIENT flag is already set");
261  goto error;
262  } else if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
263  SCLogError("cannot set to_client, DETECT_FLOW_FLAG_TOSERVER already set");
264  goto error;
265  }
267  fd->match_cnt++;
268  } else if (strcasecmp(args[i], "to_server") == 0 || strcasecmp(args[i], "from_client") == 0){
269  if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
270  SCLogError("cannot set DETECT_FLOW_FLAG_TOSERVER flag is already set");
271  goto error;
272  } else if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
273  SCLogError("cannot set to_server, DETECT_FLOW_FLAG_TO_CLIENT flag already set");
274  goto error;
275  }
277  fd->match_cnt++;
278  } else if (strcasecmp(args[i], "no_frag") == 0) {
279  if (fd->flags & DETECT_FLOW_FLAG_NO_FRAG) {
280  SCLogError("cannot set no_frag flag is already set");
281  goto error;
282  } else if (fd->flags & DETECT_FLOW_FLAG_ONLY_FRAG) {
283  SCLogError("cannot set no_frag flag, only_frag already set");
284  goto error;
285  }
287  fd->match_cnt++;
288  } else if (strcasecmp(args[i], "only_frag") == 0) {
289  if (fd->flags & DETECT_FLOW_FLAG_ONLY_FRAG) {
290  SCLogError("cannot set only_frag flag is already set");
291  goto error;
292  } else if (fd->flags & DETECT_FLOW_FLAG_NO_FRAG) {
293  SCLogError("cannot set only_frag flag, no_frag already set");
294  goto error;
295  }
297  fd->match_cnt++;
298 
299  /* special case: these only affect parsing, not matching */
300 
301  } else if (strcasecmp(args[i], "only_stream") == 0) {
302  if (*parse_flags & DETECT_FLOW_FLAG_ONLYSTREAM) {
303  SCLogError("cannot set only_stream flag is already set");
304  goto error;
305  } else if (*parse_flags & DETECT_FLOW_FLAG_NOSTREAM) {
306  SCLogError(
307  "cannot set only_stream flag, DETECT_FLOW_FLAG_NOSTREAM already set");
308  goto error;
309  }
310  *parse_flags |= DETECT_FLOW_FLAG_ONLYSTREAM;
311  } else if (strcasecmp(args[i], "no_stream") == 0) {
312  if (*parse_flags & DETECT_FLOW_FLAG_NOSTREAM) {
313  SCLogError("cannot set no_stream flag is already set");
314  goto error;
315  } else if (*parse_flags & DETECT_FLOW_FLAG_ONLYSTREAM) {
316  SCLogError(
317  "cannot set no_stream flag, DETECT_FLOW_FLAG_ONLYSTREAM already set");
318  goto error;
319  }
320  *parse_flags |= DETECT_FLOW_FLAG_NOSTREAM;
321  } else {
322  SCLogError("invalid flow option \"%s\"", args[i]);
323  goto error;
324  }
325  }
326  }
327  pcre2_match_data_free(match);
328  return fd;
329 
330 error:
331  if (match) {
332  pcre2_match_data_free(match);
333  }
334  if (fd != NULL)
335  DetectFlowFree(de_ctx, fd);
336  return NULL;
337 
338 }
339 
341 {
342 #define SIG_FLAG_BOTH (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)
343  BUG_ON(flags == 0);
346 
347  SCLogDebug("want %08x", flags & SIG_FLAG_BOTH);
348  SCLogDebug("have %08x", s->flags & SIG_FLAG_BOTH);
349 
350  if (flags & SIG_FLAG_TOSERVER) {
351  if ((s->flags & SIG_FLAG_BOTH) == SIG_FLAG_BOTH) {
352  /* both is set if we just have 'flow:established' */
353  s->flags &= ~SIG_FLAG_TOCLIENT;
354  } else if (s->flags & SIG_FLAG_TOCLIENT) {
355  return -1;
356  }
357  s->flags |= SIG_FLAG_TOSERVER;
358  } else {
359  if ((s->flags & SIG_FLAG_BOTH) == SIG_FLAG_BOTH) {
360  /* both is set if we just have 'flow:established' */
361  s->flags &= ~SIG_FLAG_TOSERVER;
362  } else if (s->flags & SIG_FLAG_TOSERVER) {
363  return -1;
364  }
365  s->flags |= SIG_FLAG_TOCLIENT;
366  }
367  return 0;
368 #undef SIG_FLAG_BOTH
369 }
370 
371 /**
372  * \brief this function is used to add the parsed flowdata into the current signature
373  *
374  * \param de_ctx pointer to the Detection Engine Context
375  * \param s pointer to the Current Signature
376  * \param flowstr pointer to the user provided flow options
377  *
378  * \retval 0 on Success
379  * \retval -1 on Failure
380  */
381 int DetectFlowSetup (DetectEngineCtx *de_ctx, Signature *s, const char *flowstr)
382 {
383  uint16_t parse_flags = 0;
384 
385  /* ensure only one flow option */
387  SCLogError("A signature may have only one flow option.");
388  return -1;
389  }
390 
391  DetectFlowData *fd = DetectFlowParse(de_ctx, flowstr, &parse_flags);
392  if (fd == NULL)
393  return -1;
394 
395  bool appendsm = true;
396  /* set the signature direction flags */
397  if (fd->flags & DETECT_FLOW_FLAG_TOSERVER) {
398  if (s->flags & SIG_FLAG_TXBOTHDIR) {
399  SCLogError(
400  "rule %u means to use both directions, cannot specify a flow direction", s->id);
401  goto error;
402  }
403  if (s->flags & SIG_FLAG_TOCLIENT) {
404  SCLogError("rule %u has flow to_server but a hook to_client", s->id);
405  goto error;
406  }
407  s->flags |= SIG_FLAG_TOSERVER;
408  } else if (fd->flags & DETECT_FLOW_FLAG_TOCLIENT) {
409  if (s->flags & SIG_FLAG_TXBOTHDIR) {
410  SCLogError(
411  "rule %u means to use both directions, cannot specify a flow direction", s->id);
412  goto error;
413  }
414  if (s->flags & SIG_FLAG_TOSERVER) {
415  SCLogError("rule %u has flow to_client but a hook to_server", s->id);
416  goto error;
417  }
418  s->flags |= SIG_FLAG_TOCLIENT;
419  } else {
420  /* if direction wasn't already set, e.g. by rule hook, assume both */
421  if ((s->flags & (SIG_FLAG_TOSERVER | SIG_FLAG_TOCLIENT)) == 0) {
422  s->flags |= SIG_FLAG_TOSERVER;
423  s->flags |= SIG_FLAG_TOCLIENT;
424  }
425  }
426  if (fd->flags == 0 || fd->flags == DETECT_FLOW_FLAG_TOSERVER ||
428  /* no direct flow is needed for just direction,
429  * no sigmatch is needed either. */
430  appendsm = false;
431  } else {
433  }
434 
435  if (appendsm) {
437  de_ctx, s, DETECT_FLOW, (SigMatchCtx *)fd, DETECT_SM_LIST_MATCH) == NULL) {
438  goto error;
439  }
440  } else {
441  DetectFlowFree(de_ctx, fd);
442  }
443 
444  if (parse_flags & DETECT_FLOW_FLAG_ONLYSTREAM) {
446  }
447  if (parse_flags & DETECT_FLOW_FLAG_NOSTREAM) {
449  }
450  return 0;
451 
452 error:
453  if (fd != NULL)
454  DetectFlowFree(de_ctx, fd);
455  return -1;
456 
457 }
458 
459 /**
460  * \brief this function will free memory associated with DetectFlowData
461  *
462  * \param fd pointer to DetectFlowData
463  */
465 {
466  DetectFlowData *fd = (DetectFlowData *)ptr;
467  SCFree(fd);
468 }
469 
470 static void
471 PrefilterPacketFlowMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
472 {
473  SCEnter();
474 
475  const PrefilterPacketHeaderCtx *ctx = pectx;
476 
477  if (!PrefilterPacketHeaderExtraMatch(ctx, p))
478  return;
479 
480  if (FlowMatch(p->flags, p->flowflags, ctx->v1.u16[0], ctx->v1.u16[1])) {
481  SCLogDebug("match: adding sids");
482  PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt);
483  }
484  SCReturn;
485 }
486 
487 static void
488 PrefilterPacketFlowSet(PrefilterPacketHeaderValue *v, void *smctx)
489 {
490  const DetectFlowData *fb = smctx;
491  v->u16[0] = fb->flags;
492  v->u16[1] = fb->match_cnt;
493 }
494 
495 static bool
496 PrefilterPacketFlowCompare(PrefilterPacketHeaderValue v, void *smctx)
497 {
498  const DetectFlowData *fb = smctx;
499  return v.u16[0] == fb->flags && v.u16[1] == fb->match_cnt;
500 }
501 
502 static int PrefilterSetupFlow(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
503 {
504  return PrefilterSetupPacketHeader(de_ctx, sgh, DETECT_FLOW, 0, PrefilterPacketFlowSet,
505  PrefilterPacketFlowCompare, PrefilterPacketFlowMatch);
506 }
507 
508 static bool PrefilterFlowIsPrefilterable(const Signature *s)
509 {
510  return PrefilterIsPrefilterableById(s, DETECT_FLOW);
511 }
512 
513 #ifdef UNITTESTS
514 #include "detect-engine-alert.h"
515 
516 /**
517  * \test DetectFlowTestParse01 is a test to make sure that we return "something"
518  * when given valid flow opt
519  */
520 static int DetectFlowTestParse01 (void)
521 {
522  uint16_t parsed_flags = 0;
523  DetectFlowData *fd = DetectFlowParse(NULL, "established", &parsed_flags);
524  FAIL_IF_NULL(fd);
525  FAIL_IF_NOT(parsed_flags == 0);
526  DetectFlowFree(NULL, fd);
527  PASS;
528 }
529 
530 /**
531  * \test DetectFlowTestParse02 is a test for setting the established flow opt
532  */
533 static int DetectFlowTestParse02 (void)
534 {
535  uint16_t parsed_flags = 0;
536  DetectFlowData *fd = DetectFlowParse(NULL, "established", &parsed_flags);
537  FAIL_IF_NULL(fd);
539  fd->match_cnt == 1);
540  DetectFlowFree(NULL, fd);
541  PASS;
542 }
543 
544 /**
545  * \test DetectFlowTestParse03 is a test for setting the stateless flow opt
546  */
547 static int DetectFlowTestParse03 (void)
548 {
549  uint16_t parsed_flags = 0;
550  DetectFlowData *fd = DetectFlowParse(NULL, "stateless", &parsed_flags);
551  FAIL_IF_NULL(fd);
553  DetectFlowFree(NULL, fd);
554  PASS;
555 }
556 
557 /**
558  * \test DetectFlowTestParse04 is a test for setting the to_client flow opt
559  */
560 static int DetectFlowTestParse04 (void)
561 {
562  uint16_t parsed_flags = 0;
563  DetectFlowData *fd = DetectFlowParse(NULL, "to_client", &parsed_flags);
564  FAIL_IF_NULL(fd);
566  DetectFlowFree(NULL, fd);
567  PASS;
568 }
569 
570 /**
571  * \test DetectFlowTestParse05 is a test for setting the to_server flow opt
572  */
573 static int DetectFlowTestParse05 (void)
574 {
575  uint16_t parsed_flags = 0;
576  DetectFlowData *fd = DetectFlowParse(NULL, "to_server", &parsed_flags);
577  FAIL_IF_NULL(fd);
579  DetectFlowFree(NULL, fd);
580  PASS;
581 }
582 
583 /**
584  * \test DetectFlowTestParse06 is a test for setting the from_server flow opt
585  */
586 static int DetectFlowTestParse06 (void)
587 {
588  uint16_t parsed_flags = 0;
589  DetectFlowData *fd = DetectFlowParse(NULL, "from_server", &parsed_flags);
590  FAIL_IF_NULL(fd);
592  DetectFlowFree(NULL, fd);
593  PASS;
594 }
595 
596 /**
597  * \test DetectFlowTestParse07 is a test for setting the from_client flow opt
598  */
599 static int DetectFlowTestParse07 (void)
600 {
601  uint16_t parsed_flags = 0;
602  DetectFlowData *fd = DetectFlowParse(NULL, "from_client", &parsed_flags);
603  FAIL_IF_NULL(fd);
605  DetectFlowFree(NULL, fd);
606  PASS;
607 }
608 
609 /**
610  * \test DetectFlowTestParse08 is a test for setting the established,to_client flow opts
611  */
612 static int DetectFlowTestParse08 (void)
613 {
614  uint16_t parsed_flags = 0;
615  DetectFlowData *fd = DetectFlowParse(NULL, "established,to_client", &parsed_flags);
616  FAIL_IF_NULL(fd);
618  DetectFlowFree(NULL, fd);
619  PASS;
620 }
621 
622 /**
623  * \test DetectFlowTestParse09 is a test for setting the to_client,stateless flow opts (order of state,dir reversed)
624  */
625 static int DetectFlowTestParse09 (void)
626 {
627  uint16_t parsed_flags = 0;
628  DetectFlowData *fd = DetectFlowParse(NULL, "to_client,stateless", &parsed_flags);
629  FAIL_IF_NULL(fd);
632  fd->match_cnt == 2);
633  DetectFlowFree(NULL, fd);
634  PASS;
635 }
636 
637 /**
638  * \test DetectFlowTestParse10 is a test for setting the from_server,stateless flow opts (order of state,dir reversed)
639  */
640 static int DetectFlowTestParse10 (void)
641 {
642  uint16_t parsed_flags = 0;
643  DetectFlowData *fd = DetectFlowParse(NULL, "from_server,stateless", &parsed_flags);
644  FAIL_IF_NULL(fd);
647  fd->match_cnt == 2);
648  DetectFlowFree(NULL, fd);
649  PASS;
650 }
651 
652 /**
653  * \test DetectFlowTestParse11 is a test for setting the from_server,stateless flow opts with spaces all around
654  */
655 static int DetectFlowTestParse11 (void)
656 {
657  uint16_t parsed_flags = 0;
658  DetectFlowData *fd = DetectFlowParse(NULL, " from_server , stateless ", &parsed_flags);
659  FAIL_IF_NULL(fd);
662  fd->match_cnt == 2);
663  DetectFlowFree(NULL, fd);
664  PASS;
665 }
666 
667 /**
668  * \test DetectFlowTestParseNocase01 is a test to make sure that we return "something"
669  * when given valid flow opt
670  */
671 static int DetectFlowTestParseNocase01 (void)
672 {
673  uint16_t parsed_flags = 0;
674  DetectFlowData *fd = DetectFlowParse(NULL, "ESTABLISHED", &parsed_flags);
675  FAIL_IF_NULL(fd);
676  DetectFlowFree(NULL, fd);
677  PASS;
678 }
679 
680 /**
681  * \test DetectFlowTestParseNocase02 is a test for setting the established flow opt
682  */
683 static int DetectFlowTestParseNocase02 (void)
684 {
685  uint16_t parsed_flags = 0;
686  DetectFlowData *fd = DetectFlowParse(NULL, "ESTABLISHED", &parsed_flags);
687  FAIL_IF_NULL(fd);
689  fd->match_cnt == 1);
690  DetectFlowFree(NULL, fd);
691  PASS;
692 }
693 
694 /**
695  * \test DetectFlowTestParseNocase03 is a test for setting the stateless flow opt
696  */
697 static int DetectFlowTestParseNocase03 (void)
698 {
699  uint16_t parsed_flags = 0;
700  DetectFlowData *fd = DetectFlowParse(NULL, "STATELESS", &parsed_flags);
701  FAIL_IF_NULL(fd);
703  DetectFlowFree(NULL, fd);
704  PASS;
705 }
706 
707 /**
708  * \test DetectFlowTestParseNocase04 is a test for setting the to_client flow opt
709  */
710 static int DetectFlowTestParseNocase04 (void)
711 {
712  uint16_t parsed_flags = 0;
713  DetectFlowData *fd = DetectFlowParse(NULL, "TO_CLIENT", &parsed_flags);
714  FAIL_IF_NULL(fd);
716  DetectFlowFree(NULL, fd);
717  PASS;
718 }
719 
720 /**
721  * \test DetectFlowTestParseNocase05 is a test for setting the to_server flow opt
722  */
723 static int DetectFlowTestParseNocase05 (void)
724 {
725  uint16_t parsed_flags = 0;
726  DetectFlowData *fd = DetectFlowParse(NULL, "TO_SERVER", &parsed_flags);
727  FAIL_IF_NULL(fd);
729  DetectFlowFree(NULL, fd);
730  PASS;
731 }
732 
733 /**
734  * \test DetectFlowTestParseNocase06 is a test for setting the from_server flow opt
735  */
736 static int DetectFlowTestParseNocase06 (void)
737 {
738  uint16_t parsed_flags = 0;
739  DetectFlowData *fd = DetectFlowParse(NULL, "FROM_SERVER", &parsed_flags);
740  FAIL_IF_NULL(fd);
742  DetectFlowFree(NULL, fd);
743  PASS;
744 }
745 
746 /**
747  * \test DetectFlowTestParseNocase07 is a test for setting the from_client flow opt
748  */
749 static int DetectFlowTestParseNocase07 (void)
750 {
751  uint16_t parsed_flags = 0;
752  DetectFlowData *fd = DetectFlowParse(NULL, "FROM_CLIENT", &parsed_flags);
753  FAIL_IF_NULL(fd);
755  DetectFlowFree(NULL, fd);
756  PASS;
757 }
758 
759 /**
760  * \test DetectFlowTestParseNocase08 is a test for setting the established,to_client flow opts
761  */
762 static int DetectFlowTestParseNocase08 (void)
763 {
764  uint16_t parsed_flags = 0;
765  DetectFlowData *fd = DetectFlowParse(NULL, "ESTABLISHED,TO_CLIENT", &parsed_flags);
766  FAIL_IF_NULL(fd);
769  fd->match_cnt == 2);
770  DetectFlowFree(NULL, fd);
771  PASS;
772 }
773 
774 /**
775  * \test DetectFlowTestParseNocase09 is a test for setting the to_client,stateless flow opts (order of state,dir reversed)
776  */
777 static int DetectFlowTestParseNocase09 (void)
778 {
779  uint16_t parsed_flags = 0;
780  DetectFlowData *fd = DetectFlowParse(NULL, "TO_CLIENT,STATELESS", &parsed_flags);
781  FAIL_IF_NULL(fd);
784  fd->match_cnt == 2);
785  DetectFlowFree(NULL, fd);
786  PASS;
787 }
788 
789 /**
790  * \test DetectFlowTestParseNocase10 is a test for setting the from_server,stateless flow opts (order of state,dir reversed)
791  */
792 static int DetectFlowTestParseNocase10 (void)
793 {
794  uint16_t parsed_flags = 0;
795  DetectFlowData *fd = DetectFlowParse(NULL, "FROM_SERVER,STATELESS", &parsed_flags);
796  FAIL_IF_NULL(fd);
799  fd->match_cnt == 2);
800  DetectFlowFree(NULL, fd);
801  PASS;
802 }
803 
804 /**
805  * \test DetectFlowTestParseNocase11 is a test for setting the from_server,stateless flow opts with spaces all around
806  */
807 static int DetectFlowTestParseNocase11 (void)
808 {
809  uint16_t parsed_flags = 0;
810  DetectFlowData *fd = DetectFlowParse(NULL, " FROM_SERVER , STATELESS ", &parsed_flags);
811  FAIL_IF_NULL(fd);
814  fd->match_cnt == 2);
815  DetectFlowFree(NULL, fd);
816  PASS;
817 }
818 
819 /**
820  * \test DetectFlowTestParse12 is a test for setting an invalid separator :
821  */
822 static int DetectFlowTestParse12 (void)
823 {
824  uint16_t parsed_flags = 0;
825  DetectFlowData *fd = DetectFlowParse(NULL, "from_server:stateless", &parsed_flags);
826  FAIL_IF_NOT_NULL(fd);
827  PASS;
828 }
829 
830 /**
831  * \test DetectFlowTestParse13 is a test for an invalid option
832  */
833 static int DetectFlowTestParse13 (void)
834 {
835  uint16_t parsed_flags = 0;
836  DetectFlowData *fd = DetectFlowParse(NULL, "invalidoptiontest", &parsed_flags);
837  FAIL_IF_NOT_NULL(fd);
838  PASS;
839 }
840 
841 /**
842  * \test DetectFlowTestParse14 is a test for a empty option
843  */
844 static int DetectFlowTestParse14 (void)
845 {
846  uint16_t parsed_flags = 0;
847  DetectFlowData *fd = DetectFlowParse(NULL, "", &parsed_flags);
848  FAIL_IF_NOT_NULL(fd);
849  PASS;
850 }
851 
852 /**
853  * \test DetectFlowTestParse15 is a test for an invalid combo of options established,stateless
854  */
855 static int DetectFlowTestParse15 (void)
856 {
857  uint16_t parsed_flags = 0;
858  DetectFlowData *fd = DetectFlowParse(NULL, "established,stateless", &parsed_flags);
859  FAIL_IF_NOT_NULL(fd);
860  PASS;
861 }
862 
863 /**
864  * \test DetectFlowTestParse16 is a test for an invalid combo of options to_client,to_server
865  */
866 static int DetectFlowTestParse16 (void)
867 {
868  uint16_t parsed_flags = 0;
869  DetectFlowData *fd = DetectFlowParse(NULL, "to_client,to_server", &parsed_flags);
870  FAIL_IF_NOT_NULL(fd);
871  PASS;
872 }
873 
874 /**
875  * \test DetectFlowTestParse16 is a test for an invalid combo of options to_client,from_server
876  * flowbit flags are the same
877  */
878 static int DetectFlowTestParse17 (void)
879 {
880  uint16_t parsed_flags = 0;
881  DetectFlowData *fd = DetectFlowParse(NULL, "to_client,from_server", &parsed_flags);
882  FAIL_IF_NOT_NULL(fd);
883  PASS;
884 }
885 
886 /**
887  * \test DetectFlowTestParse18 is a test for setting the from_server,stateless,only_stream flow opts (order of state,dir reversed)
888  */
889 static int DetectFlowTestParse18 (void)
890 {
891  uint16_t parsed_flags = 0;
892  DetectFlowData *fd =
893  DetectFlowParse(NULL, "from_server,established,only_stream", &parsed_flags);
894  FAIL_IF_NULL(fd);
896  FAIL_IF_NOT(parsed_flags == DETECT_FLOW_FLAG_ONLYSTREAM);
897  FAIL_IF_NOT(fd->match_cnt == 2);
898  DetectFlowFree(NULL, fd);
899  PASS;
900 }
901 
902 /**
903  * \test DetectFlowTestParseNocase18 is a test for setting the from_server,stateless,only_stream flow opts (order of state,dir reversed)
904  */
905 static int DetectFlowTestParseNocase18 (void)
906 {
907  uint16_t parsed_flags = 0;
908  DetectFlowData *fd =
909  DetectFlowParse(NULL, "FROM_SERVER,ESTABLISHED,ONLY_STREAM", &parsed_flags);
910  FAIL_IF_NULL(fd);
912  FAIL_IF_NOT(parsed_flags == DETECT_FLOW_FLAG_ONLYSTREAM);
913  FAIL_IF_NOT(fd->match_cnt == 2);
914  DetectFlowFree(NULL, fd);
915  PASS;
916 }
917 
918 
919 /**
920  * \test DetectFlowTestParse19 is a test for one to many options passed to DetectFlowParse
921  */
922 static int DetectFlowTestParse19 (void)
923 {
924  uint16_t parsed_flags = 0;
925  DetectFlowData *fd =
926  DetectFlowParse(NULL, "from_server,established,only_stream,a", &parsed_flags);
927  FAIL_IF_NOT_NULL(fd);
928  PASS;
929 }
930 
931 /**
932  * \test DetectFlowTestParse20 is a test for setting from_server, established, no_stream
933  */
934 static int DetectFlowTestParse20 (void)
935 {
936  uint16_t parsed_flags = 0;
937  DetectFlowData *fd = DetectFlowParse(NULL, "from_server,established,no_stream", &parsed_flags);
938  FAIL_IF_NULL(fd);
940  FAIL_IF_NOT(parsed_flags == DETECT_FLOW_FLAG_NOSTREAM);
941  FAIL_IF_NOT(fd->match_cnt == 2);
942  DetectFlowFree(NULL, fd);
943  PASS;
944 }
945 
946 /**
947  * \test DetectFlowTestParse20 is a test for setting from_server, established, no_stream
948  */
949 static int DetectFlowTestParseNocase20 (void)
950 {
951  uint16_t parsed_flags = 0;
952  DetectFlowData *fd = DetectFlowParse(NULL, "FROM_SERVER,ESTABLISHED,NO_STREAM", &parsed_flags);
953  FAIL_IF_NULL(fd);
955  FAIL_IF_NOT(parsed_flags == DETECT_FLOW_FLAG_NOSTREAM);
956  FAIL_IF_NOT(fd->match_cnt == 2);
957  DetectFlowFree(NULL, fd);
958  PASS;
959 }
960 
961 /**
962  * \test DetectFlowTestParse21 is a test for an invalid opt between to valid opts
963  */
964 static int DetectFlowTestParse21 (void)
965 {
966  uint16_t parsed_flags = 0;
967  DetectFlowData *fd = DetectFlowParse(NULL, "from_server,a,no_stream", &parsed_flags);
968  FAIL_IF_NOT_NULL(fd);
969  PASS;
970 }
971 
972 /**
973  * \test DetectFlowTestParse22 is a test for setting the established,not_established flow opts both
974  */
975 static int DetectFlowTestParse22(void)
976 {
977  uint16_t parsed_flags = 0;
978  DetectFlowData *fd = DetectFlowParse(NULL, "established,not_established", &parsed_flags);
979  FAIL_IF_NOT_NULL(fd);
980  fd = DetectFlowParse(NULL, "not_established,established", &parsed_flags);
981  FAIL_IF_NOT_NULL(fd);
982  PASS;
983 }
984 
985 static int DetectFlowSigTest01(void)
986 {
987  uint8_t *buf = (uint8_t *)"supernovaduper";
988  uint16_t buflen = strlen((char *)buf);
991  memset(&dtv, 0, sizeof(DecodeThreadVars));
992  memset(&th_v, 0, sizeof(th_v));
994 
995  Packet *p = UTHBuildPacket(buf, buflen, IPPROTO_TCP);
996  FAIL_IF_NULL(p);
997 
998  const char *sig1 = "alert tcp any any -> any any (msg:\"dummy\"; "
999  "content:\"nova\"; flow:no_stream; sid:1;)";
1000 
1003  de_ctx->flags |= DE_QUIET;
1004 
1005  de_ctx->sig_list = SigInit(de_ctx, sig1);
1007 
1009  DetectEngineThreadCtx *det_ctx = NULL;
1010  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1011  FAIL_IF_NULL(det_ctx);
1012 
1013  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1014  FAIL_IF(PacketAlertCheck(p, 1) != 1);
1015 
1016  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1018  UTHFreePacket(p);
1019 
1021  PASS;
1022 }
1023 
1024 /**
1025  * \test Test parsing of the not_established keyword.
1026  */
1027 static int DetectFlowTestParseNotEstablished(void)
1028 {
1029  uint16_t parsed_flags = 0;
1030  DetectFlowData *fd = DetectFlowParse(NULL, "not_established", &parsed_flags);
1031  FAIL_IF_NULL(fd);
1033  DetectFlowFree(NULL, fd);
1034  PASS;
1035 }
1036 
1037 /**
1038  * \test Test parsing of the "no_frag" flow argument.
1039  */
1040 static int DetectFlowTestParseNoFrag(void)
1041 {
1042  uint16_t parsed_flags = 0;
1043  DetectFlowData *fd = DetectFlowParse(NULL, "no_frag", &parsed_flags);
1044  FAIL_IF_NULL(fd);
1046  DetectFlowFree(NULL, fd);
1047  PASS;
1048 }
1049 
1050 /**
1051  * \test Test parsing of the "only_frag" flow argument.
1052  */
1053 static int DetectFlowTestParseOnlyFrag(void)
1054 {
1055  uint16_t parsed_flags = 0;
1056  DetectFlowData *fd = DetectFlowParse(NULL, "only_frag", &parsed_flags);
1057  FAIL_IF_NULL(fd);
1059  DetectFlowFree(NULL, fd);
1060  PASS;
1061 }
1062 
1063 /**
1064  * \test Test that parsing of only_frag and no_frag together fails.
1065  */
1066 static int DetectFlowTestParseNoFragOnlyFrag(void)
1067 {
1068  uint16_t parsed_flags = 0;
1069  DetectFlowData *fd = DetectFlowParse(NULL, "no_frag,only_frag", &parsed_flags);
1070  FAIL_IF_NOT_NULL(fd);
1071  PASS;
1072 }
1073 
1074 /**
1075  * \test Test no_frag matching.
1076  */
1077 static int DetectFlowTestNoFragMatch(void)
1078 {
1079  uint16_t parsed_flags = 0;
1080  uint32_t pflags = 0;
1081  DetectFlowData *fd = DetectFlowParse(NULL, "no_frag", &parsed_flags);
1082  FAIL_IF_NULL(fd);
1084  FAIL_IF_NOT(fd->match_cnt == 1);
1085  FAIL_IF_NOT(FlowMatch(pflags, 0, fd->flags, fd->match_cnt));
1086  pflags |= PKT_REBUILT_FRAGMENT;
1087  FAIL_IF(FlowMatch(pflags, 0, fd->flags, fd->match_cnt));
1088  DetectFlowFree(NULL, fd);
1089  PASS;
1090 }
1091 
1092 /**
1093  * \test Test only_frag matching.
1094  */
1095 static int DetectFlowTestOnlyFragMatch(void)
1096 {
1097  uint16_t parsed_flags = 0;
1098  uint32_t pflags = 0;
1099  DetectFlowData *fd = DetectFlowParse(NULL, "only_frag", &parsed_flags);
1100  FAIL_IF_NULL(fd);
1102  FAIL_IF_NOT(fd->match_cnt == 1);
1103  FAIL_IF(FlowMatch(pflags, 0, fd->flags, fd->match_cnt));
1104  pflags |= PKT_REBUILT_FRAGMENT;
1105  FAIL_IF_NOT(FlowMatch(pflags, 0, fd->flags, fd->match_cnt));
1106  DetectFlowFree(NULL, fd);
1107  PASS;
1108 }
1109 
1110 /**
1111  * \brief this function registers unit tests for DetectFlow
1112  */
1113 static void DetectFlowRegisterTests(void)
1114 {
1115  UtRegisterTest("DetectFlowTestParse01", DetectFlowTestParse01);
1116  UtRegisterTest("DetectFlowTestParse02", DetectFlowTestParse02);
1117  UtRegisterTest("DetectFlowTestParse03", DetectFlowTestParse03);
1118  UtRegisterTest("DetectFlowTestParse04", DetectFlowTestParse04);
1119  UtRegisterTest("DetectFlowTestParse05", DetectFlowTestParse05);
1120  UtRegisterTest("DetectFlowTestParse06", DetectFlowTestParse06);
1121  UtRegisterTest("DetectFlowTestParse07", DetectFlowTestParse07);
1122  UtRegisterTest("DetectFlowTestParse08", DetectFlowTestParse08);
1123  UtRegisterTest("DetectFlowTestParse09", DetectFlowTestParse09);
1124  UtRegisterTest("DetectFlowTestParse10", DetectFlowTestParse10);
1125  UtRegisterTest("DetectFlowTestParse11", DetectFlowTestParse11);
1126  UtRegisterTest("DetectFlowTestParseNocase01", DetectFlowTestParseNocase01);
1127  UtRegisterTest("DetectFlowTestParseNocase02", DetectFlowTestParseNocase02);
1128  UtRegisterTest("DetectFlowTestParseNocase03", DetectFlowTestParseNocase03);
1129  UtRegisterTest("DetectFlowTestParseNocase04", DetectFlowTestParseNocase04);
1130  UtRegisterTest("DetectFlowTestParseNocase05", DetectFlowTestParseNocase05);
1131  UtRegisterTest("DetectFlowTestParseNocase06", DetectFlowTestParseNocase06);
1132  UtRegisterTest("DetectFlowTestParseNocase07", DetectFlowTestParseNocase07);
1133  UtRegisterTest("DetectFlowTestParseNocase08", DetectFlowTestParseNocase08);
1134  UtRegisterTest("DetectFlowTestParseNocase09", DetectFlowTestParseNocase09);
1135  UtRegisterTest("DetectFlowTestParseNocase10", DetectFlowTestParseNocase10);
1136  UtRegisterTest("DetectFlowTestParseNocase11", DetectFlowTestParseNocase11);
1137  UtRegisterTest("DetectFlowTestParse12", DetectFlowTestParse12);
1138  UtRegisterTest("DetectFlowTestParse13", DetectFlowTestParse13);
1139  UtRegisterTest("DetectFlowTestParse14", DetectFlowTestParse14);
1140  UtRegisterTest("DetectFlowTestParse15", DetectFlowTestParse15);
1141  UtRegisterTest("DetectFlowTestParse16", DetectFlowTestParse16);
1142  UtRegisterTest("DetectFlowTestParse17", DetectFlowTestParse17);
1143  UtRegisterTest("DetectFlowTestParse18", DetectFlowTestParse18);
1144  UtRegisterTest("DetectFlowTestParseNocase18", DetectFlowTestParseNocase18);
1145  UtRegisterTest("DetectFlowTestParse19", DetectFlowTestParse19);
1146  UtRegisterTest("DetectFlowTestParse20", DetectFlowTestParse20);
1147  UtRegisterTest("DetectFlowTestParseNocase20", DetectFlowTestParseNocase20);
1148  UtRegisterTest("DetectFlowTestParse21", DetectFlowTestParse21);
1149  UtRegisterTest("DetectFlowTestParse22", DetectFlowTestParse22);
1150  UtRegisterTest("DetectFlowTestParseNotEstablished",
1151  DetectFlowTestParseNotEstablished);
1152  UtRegisterTest("DetectFlowTestParseNoFrag", DetectFlowTestParseNoFrag);
1153  UtRegisterTest("DetectFlowTestParseOnlyFrag",
1154  DetectFlowTestParseOnlyFrag);
1155  UtRegisterTest("DetectFlowTestParseNoFragOnlyFrag",
1156  DetectFlowTestParseNoFragOnlyFrag);
1157  UtRegisterTest("DetectFlowTestNoFragMatch", DetectFlowTestNoFragMatch);
1158  UtRegisterTest("DetectFlowTestOnlyFragMatch", DetectFlowTestOnlyFragMatch);
1159 
1160  UtRegisterTest("DetectFlowSigTest01", DetectFlowSigTest01);
1161 }
1162 #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
SigTableElmt_::url
const char * url
Definition: detect.h:1545
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:1544
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:78
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1529
DetectFlowData_
Definition: detect-flow.h:37
DetectParseRegex
Definition: detect-parse.h:94
DETECT_FLOW_FLAG_NOSTREAM
#define DETECT_FLOW_FLAG_NOSTREAM
Definition: detect-flow.h:33
SigTableElmt_::name
const char * name
Definition: detect.h:1542
DETECT_TABLE_PACKET_FILTER_FLAG
#define DETECT_TABLE_PACKET_FILTER_FLAG
Definition: detect.h:575
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1730
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:295
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:101
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1533
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:61
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
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:144
Packet_::flags
uint32_t flags
Definition: decode.h:562
DetectFlowData_::match_cnt
uint8_t match_cnt
Definition: detect-flow.h:39
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1429
ctx
struct Thresholds ctx
DetectFlowData_::flags
uint16_t flags
Definition: detect-flow.h:38
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:236
SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_REQUIRE_STREAM
Definition: detect.h:258
SIG_FLAG_TXBOTHDIR
#define SIG_FLAG_TXBOTHDIR
Definition: detect.h:253
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
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:241
DETECT_TABLE_APP_TD_FLAG
#define DETECT_TABLE_APP_TD_FLAG
Definition: detect.h:578
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:3305
p
Packet * p
Definition: fuzz_dataset.c:30
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:625
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
Definition: detect-parse.c:4025
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:547
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:275
DETECT_TABLE_APP_FILTER_FLAG
#define DETECT_TABLE_APP_FILTER_FLAG
Definition: detect.h:577
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1524
DetectFlowSetupImplicit
int DetectFlowSetupImplicit(Signature *s, uint32_t flags)
Definition: detect-flow.c:340
PrefilterPacketHeaderValue::u16
uint16_t u16[8]
Definition: detect-engine-prefilter-common.h:25
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
DETECT_TABLE_PACKET_TD_FLAG
#define DETECT_TABLE_PACKET_TD_FLAG
Definition: detect.h:576
SigTableElmt_::SetupPrefilter
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
Definition: detect.h:1527
DETECT_FLOW_FLAG_ONLYSTREAM
#define DETECT_FLOW_FLAG_ONLYSTREAM
Definition: detect-flow.h:32
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:274
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
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1316
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our flow options.
Definition: detect-flow.c:46
DETECT_FLOW_FLAG_TOSERVER
#define DETECT_FLOW_FLAG_TOSERVER
Definition: detect-flow.h:27
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:4151
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
SigTableElmt_::tables
uint8_t tables
Definition: detect.h:1537
SCSigMatchAppendSMToList
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:424
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3660
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:118
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3624
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:322
SCReturn
#define SCReturn
Definition: util-debug.h:286
Signature_::flags
uint32_t flags
Definition: detect.h:693
Packet_
Definition: decode.h:516
detect-engine-build.h
detect-engine-alert.h
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:775
PrefilterSetupPacketHeader
int PrefilterSetupPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh, int sm_type, SignatureMask mask, 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:470
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1504
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:237
SIG_FLAG_REQUIRE_STREAM_ONLY
#define SIG_FLAG_REQUIRE_STREAM_ONLY
Definition: detect.h:264
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2300
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:35
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1332
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:355
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
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 *tv, void *data)
Definition: detect-engine.c:3905
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:1005
DetectFlowRegister
void DetectFlowRegister(void)
Registration function for flow: keyword.
Definition: detect-flow.c:64
SIG_FLAG_BOTH
#define SIG_FLAG_BOTH
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
PKT_REBUILT_FRAGMENT
#define PKT_REBUILT_FRAGMENT
Definition: decode.h:1347
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
DETECT_TABLE_PACKET_PRE_STREAM_FLAG
#define DETECT_TABLE_PACKET_PRE_STREAM_FLAG
Definition: detect.h:574
SCFree
#define SCFree(p)
Definition: util-mem.h:61
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:995
SigTableElmt_::SupportsPrefilter
bool(* SupportsPrefilter)(const Signature *s)
Definition: detect.h:1526
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:470
Signature_::id
uint32_t id
Definition: detect.h:741
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:464
Signature_
Signature container.
Definition: detect.h:692
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:238
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
SC_Pcre2SubstringCopy
int SC_Pcre2SubstringCopy(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR *buffer, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:4127
SIGMATCH_SUPPORT_FIREWALL
#define SIGMATCH_SUPPORT_FIREWALL
Definition: detect-engine-register.h:336
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:133
PrefilterPacketHeaderValue
Definition: detect-engine-prefilter-common.h:23
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
detect-engine-prefilter-common.h
flow.h
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1428
flow-var.h
DETECT_FLOW_FLAG_NO_FRAG
#define DETECT_FLOW_FLAG_NO_FRAG
Definition: detect-flow.h:34
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1531
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:257