suricata
detect-itype.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 Gerardo Iglesias <iglesiasg@gmail.com>
22  *
23  * Implements itype keyword support
24  */
25 
26 #include "suricata-common.h"
27 #include "debug.h"
28 #include "decode.h"
29 
30 #include "detect.h"
31 #include "detect-parse.h"
33 
34 #include "detect-itype.h"
35 
36 #include "util-byte.h"
37 #include "util-unittest.h"
38 #include "util-unittest-helper.h"
39 #include "util-debug.h"
40 
41 /**
42  *\brief Regex for parsing our itype options
43  */
44 #define PARSE_REGEX "^\\s*(<|>)?\\s*([0-9]+)\\s*(?:<>\\s*([0-9]+))?\\s*$"
45 
46 static DetectParseRegex parse_regex;
47 
48 static int DetectITypeMatch(DetectEngineThreadCtx *, Packet *,
49  const Signature *, const SigMatchCtx *);
50 static int DetectITypeSetup(DetectEngineCtx *, Signature *, const char *);
51 #ifdef UNITTESTS
52 static void DetectITypeRegisterTests(void);
53 #endif
54 void DetectITypeFree(DetectEngineCtx *, void *);
55 
56 static int PrefilterSetupIType(DetectEngineCtx *de_ctx, SigGroupHead *sgh);
57 static bool PrefilterITypeIsPrefilterable(const Signature *s);
58 
59 /**
60  * \brief Registration function for itype: keyword
61  */
63 {
64  sigmatch_table[DETECT_ITYPE].name = "itype";
65  sigmatch_table[DETECT_ITYPE].desc = "match on a specific ICMP type";
66  sigmatch_table[DETECT_ITYPE].url = "/rules/header-keywords.html#itype";
67  sigmatch_table[DETECT_ITYPE].Match = DetectITypeMatch;
68  sigmatch_table[DETECT_ITYPE].Setup = DetectITypeSetup;
70 #ifdef UNITTESTS
71  sigmatch_table[DETECT_ITYPE].RegisterTests = DetectITypeRegisterTests;
72 #endif
73  sigmatch_table[DETECT_ITYPE].SupportsPrefilter = PrefilterITypeIsPrefilterable;
74  sigmatch_table[DETECT_ITYPE].SetupPrefilter = PrefilterSetupIType;
75 
76  DetectSetupParseRegexes(PARSE_REGEX, &parse_regex);
77 }
78 
79 #define DETECT_ITYPE_EQ PREFILTER_U8HASH_MODE_EQ /**< "equal" operator */
80 #define DETECT_ITYPE_LT PREFILTER_U8HASH_MODE_LT /**< "less than" operator */
81 #define DETECT_ITYPE_GT PREFILTER_U8HASH_MODE_GT /**< "greater than" operator */
82 #define DETECT_ITYPE_RN PREFILTER_U8HASH_MODE_RA /**< "range" operator */
83 
84 typedef struct DetectITypeData_ {
85  uint8_t type1;
86  uint8_t type2;
87 
88  uint8_t mode;
90 
91 static inline int ITypeMatch(const uint8_t ptype, const uint8_t mode,
92  const uint8_t dtype1, const uint8_t dtype2)
93 {
94  switch (mode) {
95  case DETECT_ITYPE_EQ:
96  return (ptype == dtype1) ? 1 : 0;
97 
98  case DETECT_ITYPE_LT:
99  return (ptype < dtype1) ? 1 : 0;
100 
101  case DETECT_ITYPE_GT:
102  return (ptype > dtype1) ? 1 : 0;
103 
104  case DETECT_ITYPE_RN:
105  return (ptype > dtype1 && ptype < dtype2) ? 1 : 0;
106  }
107  return 0;
108 }
109 
110 /**
111  * \brief This function is used to match itype rule option set on a packet with those passed via itype:
112  *
113  * \param t pointer to thread vars
114  * \param det_ctx pointer to the pattern matcher thread
115  * \param p pointer to the current packet
116  * \param m pointer to the sigmatch that we will cast into DetectITypeData
117  *
118  * \retval 0 no match
119  * \retval 1 match
120  */
121 static int DetectITypeMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
122  const Signature *s, const SigMatchCtx *ctx)
123 {
124  if (PKT_IS_PSEUDOPKT(p))
125  return 0;
126 
127  uint8_t pitype;
128  if (PKT_IS_ICMPV4(p)) {
129  pitype = ICMPV4_GET_TYPE(p);
130  } else if (PKT_IS_ICMPV6(p)) {
131  pitype = ICMPV6_GET_TYPE(p);
132  } else {
133  /* Packet not ICMPv4 nor ICMPv6 */
134  return 0;
135  }
136 
137  const DetectITypeData *itd = (const DetectITypeData *)ctx;
138  return ITypeMatch(pitype, itd->mode, itd->type1, itd->type2);
139 }
140 
141 /**
142  * \brief This function is used to parse itype options passed via itype: keyword
143  *
144  * \param de_ctx Pointer to the detection engine context
145  * \param itypestr Pointer to the user provided itype options
146  *
147  * \retval itd pointer to DetectITypeData on success
148  * \retval NULL on failure
149  */
150 static DetectITypeData *DetectITypeParse(DetectEngineCtx *de_ctx, const char *itypestr)
151 {
152  DetectITypeData *itd = NULL;
153  char *args[3] = {NULL, NULL, NULL};
154  int ret = 0, res = 0;
155  size_t pcre2_len;
156 
157  ret = DetectParsePcreExec(&parse_regex, itypestr, 0, 0);
158  if (ret < 1 || ret > 4) {
159  SCLogError(SC_ERR_PCRE_MATCH, "pcre_exec parse error, ret %" PRId32 ", string %s", ret, itypestr);
160  goto error;
161  }
162 
163  int i;
164  const char *str_ptr;
165  for (i = 1; i < ret; i++) {
166  res = SC_Pcre2SubstringGet(parse_regex.match, i, (PCRE2_UCHAR8 **)&str_ptr, &pcre2_len);
167  if (res < 0) {
168  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre2_substring_get_bynumber failed");
169  goto error;
170  }
171  args[i-1] = (char *)str_ptr;
172  }
173 
174  itd = SCMalloc(sizeof(DetectITypeData));
175  if (unlikely(itd == NULL))
176  goto error;
177  itd->type1 = 0;
178  itd->type2 = 0;
179  itd->mode = 0;
180 
181  /* we have either "<" or ">" */
182  if (args[0] != NULL && strlen(args[0]) != 0) {
183  /* we have a third part ("<> y"), therefore it's invalid */
184  if (args[2] != NULL) {
185  SCLogError(SC_ERR_INVALID_VALUE, "itype: invalid value");
186  goto error;
187  }
188  /* we have only a comparison ("<", ">") */
189  if (StringParseUint8(&itd->type1, 10, 0, args[1]) < 0) {
190  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
191  "valid", args[1]);
192  goto error;
193  }
194  if ((strcmp(args[0], ">")) == 0) {
195  if (itd->type1 == 255) {
197  "specified icmp type >%s is not "
198  "valid",
199  args[1]);
200  goto error;
201  }
202  itd->mode = DETECT_ITYPE_GT;
203  } else {
204  if (itd->type1 == 0) {
206  "specified icmp type <%s is not "
207  "valid",
208  args[1]);
209  goto error;
210  }
211  itd->mode = DETECT_ITYPE_LT;
212  }
213  } else { /* no "<", ">" */
214  /* we have a range ("<>") */
215  if (args[2] != NULL) {
216  itd->mode = (uint8_t) DETECT_ITYPE_RN;
217  if (StringParseUint8(&itd->type1, 10, 0, args[1]) < 0) {
218  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
219  "valid", args[1]);
220  goto error;
221  }
222  if (StringParseUint8(&itd->type2, 10, 0, args[2]) < 0) {
223  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
224  "valid", args[2]);
225  goto error;
226  }
227  /* we check that the first given value in the range is less than
228  the second, otherwise we swap them */
229  if (itd->type1 > itd->type2) {
230  uint8_t temp = itd->type1;
231  itd->type1 = itd->type2;
232  itd->type2 = temp;
233  }
234  } else { /* we have an equality */
235  itd->mode = DETECT_ITYPE_EQ;
236  if (StringParseUint8(&itd->type1, 10, 0, args[1]) < 0) {
237  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
238  "valid", args[1]);
239  goto error;
240  }
241  }
242  }
243 
244  for (i = 0; i < (ret-1); i++) {
245  if (args[i] != NULL)
246  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
247  }
248  return itd;
249 
250 error:
251  for (i = 0; i < (ret-1) && i < 3; i++) {
252  if (args[i] != NULL)
253  pcre2_substring_free((PCRE2_UCHAR8 *)args[i]);
254  }
255  if (itd != NULL)
256  DetectITypeFree(de_ctx, itd);
257  return NULL;
258 }
259 
260 /**
261  * \brief this function is used to add the parsed itype data into the current signature
262  *
263  * \param de_ctx pointer to the Detection Engine Context
264  * \param s pointer to the Current Signature
265  * \param itypestr pointer to the user provided itype options
266  *
267  * \retval 0 on Success
268  * \retval -1 on Failure
269  */
270 static int DetectITypeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *itypestr)
271 {
272 
273  DetectITypeData *itd = NULL;
274  SigMatch *sm = NULL;
275 
276  itd = DetectITypeParse(de_ctx, itypestr);
277  if (itd == NULL) goto error;
278 
279  sm = SigMatchAlloc();
280  if (sm == NULL) goto error;
281 
282  sm->type = DETECT_ITYPE;
283  sm->ctx = (SigMatchCtx *)itd;
284 
287 
288  return 0;
289 
290 error:
291  if (itd != NULL) DetectITypeFree(de_ctx, itd);
292  if (sm != NULL) SCFree(sm);
293  return -1;
294 }
295 
296 /**
297  * \brief this function will free memory associated with DetectITypeData
298  *
299  * \param ptr pointer to DetectITypeData
300  */
302 {
303  DetectITypeData *itd = (DetectITypeData *)ptr;
304  SCFree(itd);
305 }
306 
307 /* prefilter code
308  *
309  * Prefilter uses the U8Hash logic, where we setup a 256 entry array
310  * for each ICMP type. Each array element has the list of signatures
311  * that need to be inspected. */
312 
313 static void PrefilterPacketITypeMatch(DetectEngineThreadCtx *det_ctx,
314  Packet *p, const void *pectx)
315 {
316  if (PKT_IS_PSEUDOPKT(p)) {
317  SCReturn;
318  }
319 
320  uint8_t pitype;
321  if (PKT_IS_ICMPV4(p)) {
322  pitype = ICMPV4_GET_TYPE(p);
323  } else if (PKT_IS_ICMPV6(p)) {
324  pitype = ICMPV6_GET_TYPE(p);
325  } else {
326  /* Packet not ICMPv4 nor ICMPv6 */
327  return;
328  }
329 
330  const PrefilterPacketU8HashCtx *h = pectx;
331  const SigsArray *sa = h->array[pitype];
332  if (sa) {
333  PrefilterAddSids(&det_ctx->pmq, sa->sigs, sa->cnt);
334  }
335 }
336 
337 static void
338 PrefilterPacketITypeSet(PrefilterPacketHeaderValue *v, void *smctx)
339 {
340  const DetectITypeData *a = smctx;
341  v->u8[0] = a->mode;
342  v->u8[1] = a->type1;
343  v->u8[2] = a->type2;
344 }
345 
346 static bool
347 PrefilterPacketITypeCompare(PrefilterPacketHeaderValue v, void *smctx)
348 {
349  const DetectITypeData *a = smctx;
350  if (v.u8[0] == a->mode &&
351  v.u8[1] == a->type1 &&
352  v.u8[2] == a->type2)
353  return true;
354  return false;
355 }
356 
357 static int PrefilterSetupIType(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
358 {
360  PrefilterPacketITypeSet,
361  PrefilterPacketITypeCompare,
362  PrefilterPacketITypeMatch);
363 }
364 
365 static bool PrefilterITypeIsPrefilterable(const Signature *s)
366 {
367  const SigMatch *sm;
368  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
369  switch (sm->type) {
370  case DETECT_ITYPE:
371  return true;
372  }
373  }
374  return false;
375 }
376 
377 #ifdef UNITTESTS
378 
379 #include "detect-engine.h"
380 #include "detect-engine-mpm.h"
381 
382 /**
383  * \test DetectITypeParseTest01 is a test for setting a valid itype value
384  */
385 static int DetectITypeParseTest01(void)
386 {
387  DetectITypeData *itd = NULL;
388  int result = 0;
389  itd = DetectITypeParse(NULL, "8");
390  if (itd != NULL) {
391  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_EQ)
392  result = 1;
393  DetectITypeFree(NULL, itd);
394  }
395  return result;
396 }
397 
398 /**
399  * \test DetectITypeParseTest02 is a test for setting a valid itype value
400  * with ">" operator
401  */
402 static int DetectITypeParseTest02(void)
403 {
404 DetectITypeData *itd = NULL;
405  int result = 0;
406  itd = DetectITypeParse(NULL, ">8");
407  if (itd != NULL) {
408  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_GT)
409  result = 1;
410  DetectITypeFree(NULL, itd);
411  }
412  return result;
413 }
414 
415 /**
416  * \test DetectITypeParseTest03 is a test for setting a valid itype value
417  * with "<" operator
418  */
419 static int DetectITypeParseTest03(void)
420 {
421  DetectITypeData *itd = NULL;
422  int result = 0;
423  itd = DetectITypeParse(NULL, "<8");
424  if (itd != NULL) {
425  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_LT)
426  result = 1;
427  DetectITypeFree(NULL, itd);
428  }
429  return result;
430 }
431 
432 /**
433  * \test DetectITypeParseTest04 is a test for setting a valid itype value
434  * with "<>" operator
435  */
436 static int DetectITypeParseTest04(void)
437 {
438 DetectITypeData *itd = NULL;
439  int result = 0;
440  itd = DetectITypeParse(NULL, "8<>20");
441  if (itd != NULL) {
442  if (itd->type1 == 8 && itd->type2 == 20 && itd->mode == DETECT_ITYPE_RN)
443  result = 1;
444  DetectITypeFree(NULL, itd);
445  }
446  return result;
447 }
448 
449 /**
450  * \test DetectITypeParseTest05 is a test for setting a valid itype value
451  * with spaces all around
452  */
453 static int DetectITypeParseTest05(void)
454 {
455 DetectITypeData *itd = NULL;
456  int result = 0;
457  itd = DetectITypeParse(NULL, " 8 ");
458  if (itd != NULL) {
459  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_EQ)
460  result = 1;
461  DetectITypeFree(NULL, itd);
462  }
463  return result;
464 }
465 
466 /**
467  * \test DetectITypeParseTest06 is a test for setting a valid itype value
468  * with ">" operator and spaces all around
469  */
470 static int DetectITypeParseTest06(void)
471 {
472 DetectITypeData *itd = NULL;
473  int result = 0;
474  itd = DetectITypeParse(NULL, " > 8 ");
475  if (itd != NULL) {
476  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_GT)
477  result = 1;
478  DetectITypeFree(NULL, itd);
479  }
480  return result;
481 }
482 
483 /**
484  * \test DetectITypeParseTest07 is a test for setting a valid itype value
485  * with "<>" operator and spaces all around
486  */
487 static int DetectITypeParseTest07(void)
488 {
489 DetectITypeData *itd = NULL;
490  int result = 0;
491  itd = DetectITypeParse(NULL, " 8 <> 20 ");
492  if (itd != NULL) {
493  if (itd->type1 == 8 && itd->type2 == 20 && itd->mode == DETECT_ITYPE_RN)
494  result = 1;
495  DetectITypeFree(NULL, itd);
496  }
497  return result;
498 }
499 
500 /**
501  * \test DetectITypeParseTest08 is a test for setting an invalid itype value
502  */
503 static int DetectITypeParseTest08(void)
504 {
505  DetectITypeData *itd = NULL;
506  itd = DetectITypeParse(NULL, "> 8 <> 20");
507  if (itd == NULL)
508  return 1;
509  DetectITypeFree(NULL, itd);
510  return 0;
511 }
512 
513 /**
514  * \test DetectITypeMatchTest01 is a test for checking the working of itype
515  * keyword by creating 5 rules and matching a crafted packet against
516  * them. 4 out of 5 rules shall trigger.
517  */
518 static int DetectITypeMatchTest01(void)
519 {
520 
521  Packet *p = NULL;
522  Signature *s = NULL;
523  ThreadVars th_v;
524  DetectEngineThreadCtx *det_ctx;
525  int result = 0;
526 
527  memset(&th_v, 0, sizeof(th_v));
528 
529  p = UTHBuildPacket(NULL, 0, IPPROTO_ICMP);
530  p->icmpv4h->type = 10;
531 
533  if (de_ctx == NULL) {
534  goto end;
535  }
536 
537  de_ctx->flags |= DE_QUIET;
538 
539  s = de_ctx->sig_list = SigInit(de_ctx,"alert icmp any any -> any any (itype:10; sid:1;)");
540  if (s == NULL) {
541  goto end;
542  }
543 
544  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:<15; sid:2;)");
545  if (s == NULL) {
546  goto end;
547  }
548 
549  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:>20; sid:3;)");
550  if (s == NULL) {
551  goto end;
552  }
553 
554  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:8<>20; sid:4;)");
555  if (s == NULL) {
556  goto end;
557  }
558 
559  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:20<>8; sid:5;)");
560  if (s == NULL) {
561  goto end;
562  }
563 
564 
566  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
567 
568  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
569  if (PacketAlertCheck(p, 1) == 0) {
570  SCLogDebug("sid 1 did not alert, but should have");
571  goto cleanup;
572  } else if (PacketAlertCheck(p, 2) == 0) {
573  SCLogDebug("sid 2 did not alert, but should have");
574  goto cleanup;
575  } else if (PacketAlertCheck(p, 3)) {
576  SCLogDebug("sid 3 alerted, but should not have");
577  goto cleanup;
578  } else if (PacketAlertCheck(p, 4) == 0) {
579  SCLogDebug("sid 4 did not alert, but should have");
580  goto cleanup;
581  } else if (PacketAlertCheck(p, 5) == 0) {
582  SCLogDebug("sid 5 did not alert, but should have");
583  goto cleanup;
584  }
585 
586  result = 1;
587 
588 cleanup:
591 
592  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
594 
595  UTHFreePackets(&p, 1);
596 end:
597  return result;
598 }
599 
600 /**
601  * \brief this function registers unit tests for DetectIType
602  */
603 void DetectITypeRegisterTests(void)
604 {
605  UtRegisterTest("DetectITypeParseTest01", DetectITypeParseTest01);
606  UtRegisterTest("DetectITypeParseTest02", DetectITypeParseTest02);
607  UtRegisterTest("DetectITypeParseTest03", DetectITypeParseTest03);
608  UtRegisterTest("DetectITypeParseTest04", DetectITypeParseTest04);
609  UtRegisterTest("DetectITypeParseTest05", DetectITypeParseTest05);
610  UtRegisterTest("DetectITypeParseTest06", DetectITypeParseTest06);
611  UtRegisterTest("DetectITypeParseTest07", DetectITypeParseTest07);
612  UtRegisterTest("DetectITypeParseTest08", DetectITypeParseTest08);
613  UtRegisterTest("DetectITypeMatchTest01", DetectITypeMatchTest01);
614 }
615 #endif /* UNITTESTS */
util-byte.h
DetectITypeRegister
void DetectITypeRegister(void)
Registration function for itype: keyword.
Definition: detect-itype.c:62
DetectITypeFree
void DetectITypeFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectITypeData
Definition: detect-itype.c:301
DetectParseRegex::match
pcre2_match_data * match
Definition: detect-parse.h:45
SigTableElmt_::url
const char * url
Definition: detect.h:1270
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1269
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options)
Definition: detect-parse.c:2474
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1257
DETECT_ITYPE_LT
#define DETECT_ITYPE_LT
Definition: detect-itype.c:80
DetectParseRegex
Definition: detect-parse.h:42
DETECT_ITYPE_RN
#define DETECT_ITYPE_RN
Definition: detect-itype.c:82
SigTableElmt_::name
const char * name
Definition: detect.h:1267
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1224
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1425
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
PrefilterPacketU8HashCtx_::array
SigsArray * array[256]
Definition: detect-engine-prefilter-common.h:51
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
DetectITypeData_::type2
uint8_t type2
Definition: detect-itype.c:86
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:137
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2115
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1167
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:811
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2433
PrefilterPacketHeaderValue::u8
uint8_t u8[16]
Definition: detect-engine-prefilter-common.h:22
DetectITypeData_::type1
uint8_t type1
Definition: detect-itype.c:85
DE_QUIET
#define DE_QUIET
Definition: detect.h:295
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:337
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1790
SC_ERR_PCRE_GET_SUBSTRING
@ SC_ERR_PCRE_GET_SUBSTRING
Definition: util-error.h:34
SigCleanSignatures
void SigCleanSignatures(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:42
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1252
DETECT_ITYPE
@ DETECT_ITYPE
Definition: detect-engine-register.h:45
util-unittest.h
util-unittest-helper.h
PARSE_REGEX
#define PARSE_REGEX
Regex for parsing our itype options.
Definition: detect-itype.c:44
SigTableElmt_::SetupPrefilter
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
Definition: detect.h:1255
Signature_::next
struct Signature_ * next
Definition: detect.h:622
DetectITypeData
struct DetectITypeData_ DetectITypeData
StringParseUint8
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
Definition: util-byte.c:359
decode.h
util-debug.h
SC_ERR_PCRE_MATCH
@ SC_ERR_PCRE_MATCH
Definition: util-error.h:32
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1060
ICMPV4_GET_TYPE
#define ICMPV4_GET_TYPE(p)
Definition: decode-icmpv4.h:235
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2597
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:325
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:89
SC_Pcre2SubstringGet
int SC_Pcre2SubstringGet(pcre2_match_data *match_data, uint32_t number, PCRE2_UCHAR **bufferptr, PCRE2_SIZE *bufflen)
Definition: detect-parse.c:2585
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
detect-itype.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:324
PKT_IS_ICMPV6
#define PKT_IS_ICMPV6(p)
Definition: decode.h:267
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2016
SCReturn
#define SCReturn
Definition: util-debug.h:302
Signature_::flags
uint32_t flags
Definition: detect.h:549
Packet_
Definition: decode.h:427
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:619
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1235
SignatureInitData_::smlists
struct SigMatch_ ** smlists
Definition: detect.h:542
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:1948
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:316
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3142
SigsArray_::sigs
SigIntId * sigs
Definition: detect-engine-prefilter-common.h:45
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3354
SigMatch_::type
uint16_t type
Definition: detect.h:322
SigsArray_
Definition: detect-engine-prefilter-common.h:44
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:257
SigsArray_::cnt
uint32_t cnt
Definition: detect-engine-prefilter-common.h:46
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:817
DetectITypeData_::mode
uint8_t mode
Definition: detect-itype.c:88
Packet_::icmpv4h
ICMPV4Hdr * icmpv4h
Definition: decode.h:555
PKT_IS_ICMPV4
#define PKT_IS_ICMPV4(p)
Definition: decode.h:266
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
DETECT_ITYPE_GT
#define DETECT_ITYPE_GT
Definition: detect-itype.c:81
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SigTableElmt_::SupportsPrefilter
bool(* SupportsPrefilter)(const Signature *s)
Definition: detect.h:1254
detect-parse.h
Signature_
Signature container.
Definition: detect.h:548
SigMatch_
a single match condition for a signature
Definition: detect.h:321
ICMPV6_GET_TYPE
#define ICMPV6_GET_TYPE(p)
Definition: decode-icmpv6.h:102
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2394
PrefilterPacketU8HashCtx_
Definition: detect-engine-prefilter-common.h:50
PrefilterPacketHeaderValue
Definition: detect-engine-prefilter-common.h:21
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:812
detect-engine-prefilter-common.h
PrefilterSetupPacketHeaderU8Hash
int PrefilterSetupPacketHeaderU8Hash(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:407
DETECT_ITYPE_EQ
#define DETECT_ITYPE_EQ
Definition: detect-itype.c:79
DetectITypeData_
Definition: detect-itype.c:84
SigMatchAppendSMToList
void SigMatchAppendSMToList(Signature *s, SigMatch *new, int list)
Append a SigMatch to the list type.
Definition: detect-parse.c:349
debug.h
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1259
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:223
UTHFreePackets
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:468