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  int ov[MAX_SUBSTRINGS];
156 
157  ret = DetectParsePcreExec(&parse_regex, itypestr, 0, 0, ov, MAX_SUBSTRINGS);
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 = pcre_get_substring((char *)itypestr, ov, MAX_SUBSTRINGS, i, &str_ptr);
167  if (res < 0) {
168  SCLogError(SC_ERR_PCRE_GET_SUBSTRING, "pcre_get_substring 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) itd->mode = DETECT_ITYPE_GT;
195  else itd->mode = DETECT_ITYPE_LT;
196  } else { /* no "<", ">" */
197  /* we have a range ("<>") */
198  if (args[2] != NULL) {
199  itd->mode = (uint8_t) DETECT_ITYPE_RN;
200  if (StringParseUint8(&itd->type1, 10, 0, args[1]) < 0) {
201  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
202  "valid", args[1]);
203  goto error;
204  }
205  if (StringParseUint8(&itd->type2, 10, 0, args[2]) < 0) {
206  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
207  "valid", args[2]);
208  goto error;
209  }
210  /* we check that the first given value in the range is less than
211  the second, otherwise we swap them */
212  if (itd->type1 > itd->type2) {
213  uint8_t temp = itd->type1;
214  itd->type1 = itd->type2;
215  itd->type2 = temp;
216  }
217  } else { /* we have an equality */
218  itd->mode = DETECT_ITYPE_EQ;
219  if (StringParseUint8(&itd->type1, 10, 0, args[1]) < 0) {
220  SCLogError(SC_ERR_INVALID_ARGUMENT, "specified icmp type %s is not "
221  "valid", args[1]);
222  goto error;
223  }
224  }
225  }
226 
227  for (i = 0; i < (ret-1); i++) {
228  if (args[i] != NULL)
229  SCFree(args[i]);
230  }
231  return itd;
232 
233 error:
234  for (i = 0; i < (ret-1) && i < 3; i++) {
235  if (args[i] != NULL)
236  SCFree(args[i]);
237  }
238  if (itd != NULL)
239  DetectITypeFree(de_ctx, itd);
240  return NULL;
241 }
242 
243 /**
244  * \brief this function is used to add the parsed itype data into the current signature
245  *
246  * \param de_ctx pointer to the Detection Engine Context
247  * \param s pointer to the Current Signature
248  * \param itypestr pointer to the user provided itype options
249  *
250  * \retval 0 on Success
251  * \retval -1 on Failure
252  */
253 static int DetectITypeSetup(DetectEngineCtx *de_ctx, Signature *s, const char *itypestr)
254 {
255 
256  DetectITypeData *itd = NULL;
257  SigMatch *sm = NULL;
258 
259  itd = DetectITypeParse(de_ctx, itypestr);
260  if (itd == NULL) goto error;
261 
262  sm = SigMatchAlloc();
263  if (sm == NULL) goto error;
264 
265  sm->type = DETECT_ITYPE;
266  sm->ctx = (SigMatchCtx *)itd;
267 
270 
271  return 0;
272 
273 error:
274  if (itd != NULL) DetectITypeFree(de_ctx, itd);
275  if (sm != NULL) SCFree(sm);
276  return -1;
277 }
278 
279 /**
280  * \brief this function will free memory associated with DetectITypeData
281  *
282  * \param ptr pointer to DetectITypeData
283  */
285 {
286  DetectITypeData *itd = (DetectITypeData *)ptr;
287  SCFree(itd);
288 }
289 
290 /* prefilter code
291  *
292  * Prefilter uses the U8Hash logic, where we setup a 256 entry array
293  * for each ICMP type. Each array element has the list of signatures
294  * that need to be inspected. */
295 
296 static void PrefilterPacketITypeMatch(DetectEngineThreadCtx *det_ctx,
297  Packet *p, const void *pectx)
298 {
299  if (PKT_IS_PSEUDOPKT(p)) {
300  SCReturn;
301  }
302 
303  uint8_t pitype;
304  if (PKT_IS_ICMPV4(p)) {
305  pitype = ICMPV4_GET_TYPE(p);
306  } else if (PKT_IS_ICMPV6(p)) {
307  pitype = ICMPV6_GET_TYPE(p);
308  } else {
309  /* Packet not ICMPv4 nor ICMPv6 */
310  return;
311  }
312 
313  const PrefilterPacketU8HashCtx *h = pectx;
314  const SigsArray *sa = h->array[pitype];
315  if (sa) {
316  PrefilterAddSids(&det_ctx->pmq, sa->sigs, sa->cnt);
317  }
318 }
319 
320 static void
321 PrefilterPacketITypeSet(PrefilterPacketHeaderValue *v, void *smctx)
322 {
323  const DetectITypeData *a = smctx;
324  v->u8[0] = a->mode;
325  v->u8[1] = a->type1;
326  v->u8[2] = a->type2;
327 }
328 
329 static bool
330 PrefilterPacketITypeCompare(PrefilterPacketHeaderValue v, void *smctx)
331 {
332  const DetectITypeData *a = smctx;
333  if (v.u8[0] == a->mode &&
334  v.u8[1] == a->type1 &&
335  v.u8[2] == a->type2)
336  return TRUE;
337  return FALSE;
338 }
339 
340 static int PrefilterSetupIType(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
341 {
343  PrefilterPacketITypeSet,
344  PrefilterPacketITypeCompare,
345  PrefilterPacketITypeMatch);
346 }
347 
348 static bool PrefilterITypeIsPrefilterable(const Signature *s)
349 {
350  const SigMatch *sm;
351  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
352  switch (sm->type) {
353  case DETECT_ITYPE:
354  return TRUE;
355  }
356  }
357  return FALSE;
358 }
359 
360 #ifdef UNITTESTS
361 
362 #include "detect-engine.h"
363 #include "detect-engine-mpm.h"
364 
365 /**
366  * \test DetectITypeParseTest01 is a test for setting a valid itype value
367  */
368 static int DetectITypeParseTest01(void)
369 {
370  DetectITypeData *itd = NULL;
371  int result = 0;
372  itd = DetectITypeParse(NULL, "8");
373  if (itd != NULL) {
374  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_EQ)
375  result = 1;
376  DetectITypeFree(NULL, itd);
377  }
378  return result;
379 }
380 
381 /**
382  * \test DetectITypeParseTest02 is a test for setting a valid itype value
383  * with ">" operator
384  */
385 static int DetectITypeParseTest02(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_GT)
392  result = 1;
393  DetectITypeFree(NULL, itd);
394  }
395  return result;
396 }
397 
398 /**
399  * \test DetectITypeParseTest03 is a test for setting a valid itype value
400  * with "<" operator
401  */
402 static int DetectITypeParseTest03(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_LT)
409  result = 1;
410  DetectITypeFree(NULL, itd);
411  }
412  return result;
413 }
414 
415 /**
416  * \test DetectITypeParseTest04 is a test for setting a valid itype value
417  * with "<>" operator
418  */
419 static int DetectITypeParseTest04(void)
420 {
421 DetectITypeData *itd = NULL;
422  int result = 0;
423  itd = DetectITypeParse(NULL, "8<>20");
424  if (itd != NULL) {
425  if (itd->type1 == 8 && itd->type2 == 20 && itd->mode == DETECT_ITYPE_RN)
426  result = 1;
427  DetectITypeFree(NULL, itd);
428  }
429  return result;
430 }
431 
432 /**
433  * \test DetectITypeParseTest05 is a test for setting a valid itype value
434  * with spaces all around
435  */
436 static int DetectITypeParseTest05(void)
437 {
438 DetectITypeData *itd = NULL;
439  int result = 0;
440  itd = DetectITypeParse(NULL, " 8 ");
441  if (itd != NULL) {
442  if (itd->type1 == 8 && itd->mode == DETECT_ITYPE_EQ)
443  result = 1;
444  DetectITypeFree(NULL, itd);
445  }
446  return result;
447 }
448 
449 /**
450  * \test DetectITypeParseTest06 is a test for setting a valid itype value
451  * with ">" operator and spaces all around
452  */
453 static int DetectITypeParseTest06(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_GT)
460  result = 1;
461  DetectITypeFree(NULL, itd);
462  }
463  return result;
464 }
465 
466 /**
467  * \test DetectITypeParseTest07 is a test for setting a valid itype value
468  * with "<>" operator and spaces all around
469  */
470 static int DetectITypeParseTest07(void)
471 {
472 DetectITypeData *itd = NULL;
473  int result = 0;
474  itd = DetectITypeParse(NULL, " 8 <> 20 ");
475  if (itd != NULL) {
476  if (itd->type1 == 8 && itd->type2 == 20 && itd->mode == DETECT_ITYPE_RN)
477  result = 1;
478  DetectITypeFree(NULL, itd);
479  }
480  return result;
481 }
482 
483 /**
484  * \test DetectITypeParseTest08 is a test for setting an invalid itype value
485  */
486 static int DetectITypeParseTest08(void)
487 {
488  DetectITypeData *itd = NULL;
489  itd = DetectITypeParse(NULL, "> 8 <> 20");
490  if (itd == NULL)
491  return 1;
492  DetectITypeFree(NULL, itd);
493  return 0;
494 }
495 
496 /**
497  * \test DetectITypeMatchTest01 is a test for checking the working of itype
498  * keyword by creating 5 rules and matching a crafted packet against
499  * them. 4 out of 5 rules shall trigger.
500  */
501 static int DetectITypeMatchTest01(void)
502 {
503 
504  Packet *p = NULL;
505  Signature *s = NULL;
506  ThreadVars th_v;
507  DetectEngineThreadCtx *det_ctx;
508  int result = 0;
509 
510  memset(&th_v, 0, sizeof(th_v));
511 
512  p = UTHBuildPacket(NULL, 0, IPPROTO_ICMP);
513  p->icmpv4h->type = 10;
514 
516  if (de_ctx == NULL) {
517  goto end;
518  }
519 
520  de_ctx->flags |= DE_QUIET;
521 
522  s = de_ctx->sig_list = SigInit(de_ctx,"alert icmp any any -> any any (itype:10; sid:1;)");
523  if (s == NULL) {
524  goto end;
525  }
526 
527  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:<15; sid:2;)");
528  if (s == NULL) {
529  goto end;
530  }
531 
532  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:>20; sid:3;)");
533  if (s == NULL) {
534  goto end;
535  }
536 
537  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:8<>20; sid:4;)");
538  if (s == NULL) {
539  goto end;
540  }
541 
542  s = s->next = SigInit(de_ctx,"alert icmp any any -> any any (itype:20<>8; sid:5;)");
543  if (s == NULL) {
544  goto end;
545  }
546 
547 
549  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
550 
551  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
552  if (PacketAlertCheck(p, 1) == 0) {
553  SCLogDebug("sid 1 did not alert, but should have");
554  goto cleanup;
555  } else if (PacketAlertCheck(p, 2) == 0) {
556  SCLogDebug("sid 2 did not alert, but should have");
557  goto cleanup;
558  } else if (PacketAlertCheck(p, 3)) {
559  SCLogDebug("sid 3 alerted, but should not have");
560  goto cleanup;
561  } else if (PacketAlertCheck(p, 4) == 0) {
562  SCLogDebug("sid 4 did not alert, but should have");
563  goto cleanup;
564  } else if (PacketAlertCheck(p, 5) == 0) {
565  SCLogDebug("sid 5 did not alert, but should have");
566  goto cleanup;
567  }
568 
569  result = 1;
570 
571 cleanup:
574 
575  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
577 
578  UTHFreePackets(&p, 1);
579 end:
580  return result;
581 }
582 
583 /**
584  * \brief this function registers unit tests for DetectIType
585  */
586 void DetectITypeRegisterTests(void)
587 {
588  UtRegisterTest("DetectITypeParseTest01", DetectITypeParseTest01);
589  UtRegisterTest("DetectITypeParseTest02", DetectITypeParseTest02);
590  UtRegisterTest("DetectITypeParseTest03", DetectITypeParseTest03);
591  UtRegisterTest("DetectITypeParseTest04", DetectITypeParseTest04);
592  UtRegisterTest("DetectITypeParseTest05", DetectITypeParseTest05);
593  UtRegisterTest("DetectITypeParseTest06", DetectITypeParseTest06);
594  UtRegisterTest("DetectITypeParseTest07", DetectITypeParseTest07);
595  UtRegisterTest("DetectITypeParseTest08", DetectITypeParseTest08);
596  UtRegisterTest("DetectITypeMatchTest01", DetectITypeMatchTest01);
597 }
598 #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:284
SigTableElmt_::url
const char * url
Definition: detect.h:1214
detect-engine.h
SigTableElmt_::desc
const char * desc
Definition: detect.h:1213
SC_ERR_INVALID_VALUE
@ SC_ERR_INVALID_VALUE
Definition: util-error.h:160
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1201
DETECT_ITYPE_LT
#define DETECT_ITYPE_LT
Definition: detect-itype.c:80
DETECT_ITYPE_RN
#define DETECT_ITYPE_RN
Definition: detect-itype.c:82
SigTableElmt_::name
const char * name
Definition: detect.h:1211
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1147
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1347
MAX_SUBSTRINGS
#define MAX_SUBSTRINGS
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:138
SigInit
Signature * SigInit(DetectEngineCtx *, const char *)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:2056
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1111
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2093
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:294
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
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:39
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1196
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:1199
Signature_::next
struct Signature_ * next
Definition: detect.h:600
DetectITypeData
struct DetectITypeData_ DetectITypeData
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:1010
ICMPV4_GET_TYPE
#define ICMPV4_GET_TYPE(p)
Definition: decode-icmpv4.h:215
res
PoolThreadReserved res
Definition: stream-tcp-private.h:0
DetectSetupParseRegexes
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
Definition: detect-parse.c:2493
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:324
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:89
SC_ERR_INVALID_ARGUMENT
@ SC_ERR_INVALID_ARGUMENT
Definition: util-error.h:43
detect-itype.h
TRUE
#define TRUE
Definition: suricata-common.h:33
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:323
PKT_IS_ICMPV6
#define PKT_IS_ICMPV6(p)
Definition: decode.h:262
SigMatchSignatures
void SigMatchSignatures(ThreadVars *th_v, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1688
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:1953
FALSE
#define FALSE
Definition: suricata-common.h:34
SCReturn
#define SCReturn
Definition: util-debug.h:302
Signature_::flags
uint32_t flags
Definition: detect.h:529
DetectParsePcreExec
int DetectParsePcreExec(DetectParseRegex *parse_regex, const char *str, int start_offset, int options, int *ovector, int ovector_size)
Definition: detect-parse.c:2423
Packet_
Definition: decode.h:414
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:597
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1179
SignatureInitData_::smlists
struct SigMatch_ ** smlists
Definition: detect.h:522
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:1888
SigMatch_::type
uint8_t type
Definition: detect.h:321
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:315
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:2797
SigsArray_::sigs
SigIntId * sigs
Definition: detect-engine-prefilter-common.h:45
suricata-common.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *, void *)
Definition: detect-engine.c:3005
SigsArray_
Definition: detect-engine-prefilter-common.h:44
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:73
DetectParseRegex_
Definition: detect-parse.h:42
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:773
DetectITypeData_::mode
uint8_t mode
Definition: detect-itype.c:88
Packet_::icmpv4h
ICMPV4Hdr * icmpv4h
Definition: decode.h:537
PKT_IS_ICMPV4
#define PKT_IS_ICMPV4(p)
Definition: decode.h:261
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:1198
detect-parse.h
Signature_
Signature container.
Definition: detect.h:528
SigMatch_
a single match condition for a signature
Definition: detect.h:320
ICMPV6_GET_TYPE
#define ICMPV6_GET_TYPE(p)
Definition: decode-icmpv6.h:102
StringParseUint8
int StringParseUint8(uint8_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:359
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2048
PrefilterPacketU8HashCtx_
Definition: detect-engine-prefilter-common.h:50
PrefilterPacketHeaderValue
Definition: detect-engine-prefilter-common.h:21
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:768
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:396
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:1203
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