suricata
detect-dsize.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Implements the dsize keyword
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 
29 #include "detect.h"
30 #include "detect-parse.h"
32 #include "detect-engine-build.h"
33 
34 #include "flow-var.h"
35 
36 #include "detect-content.h"
37 #include "detect-dsize.h"
38 
39 #include "util-unittest.h"
40 #include "util-debug.h"
41 #include "util-byte.h"
42 
43 #include "pkt-var.h"
44 #include "host.h"
45 #include "util-profiling.h"
46 
47 static int DetectDsizeMatch (DetectEngineThreadCtx *, Packet *,
48  const Signature *, const SigMatchCtx *);
49 static int DetectDsizeSetup (DetectEngineCtx *, Signature *s, const char *str);
50 #ifdef UNITTESTS
51 static void DsizeRegisterTests(void);
52 #endif
53 static void DetectDsizeFree(DetectEngineCtx *, void *);
54 
55 static int PrefilterSetupDsize(DetectEngineCtx *de_ctx, SigGroupHead *sgh);
56 static bool PrefilterDsizeIsPrefilterable(const Signature *s);
57 
58 /**
59  * \brief Registration function for dsize: keyword
60  */
62 {
63  sigmatch_table[DETECT_DSIZE].name = "dsize";
64  sigmatch_table[DETECT_DSIZE].desc = "match on the size of the packet payload";
65  sigmatch_table[DETECT_DSIZE].url = "/rules/payload-keywords.html#dsize";
66  sigmatch_table[DETECT_DSIZE].Match = DetectDsizeMatch;
67  sigmatch_table[DETECT_DSIZE].Setup = DetectDsizeSetup;
68  sigmatch_table[DETECT_DSIZE].Free = DetectDsizeFree;
70 #ifdef UNITTESTS
71  sigmatch_table[DETECT_DSIZE].RegisterTests = DsizeRegisterTests;
72 #endif
73  sigmatch_table[DETECT_DSIZE].SupportsPrefilter = PrefilterDsizeIsPrefilterable;
74  sigmatch_table[DETECT_DSIZE].SetupPrefilter = PrefilterSetupDsize;
75 }
76 
77 /**
78  * \internal
79  * \brief This function is used to match flags on a packet with those passed via dsize:
80  *
81  * \param t pointer to thread vars
82  * \param det_ctx pointer to the pattern matcher thread
83  * \param p pointer to the current packet
84  * \param s pointer to the Signature
85  * \param m pointer to the sigmatch
86  *
87  * \retval 0 no match
88  * \retval 1 match
89  */
90 static int DetectDsizeMatch (DetectEngineThreadCtx *det_ctx, Packet *p,
91  const Signature *s, const SigMatchCtx *ctx)
92 {
93  SCEnter();
94  int ret = 0;
95 
97 
98  const DetectU16Data *dd = (const DetectU16Data *)ctx;
99 
100  SCLogDebug("p->payload_len %"PRIu16"", p->payload_len);
101 
102  ret = DetectU16Match(p->payload_len, dd);
103 
104  SCReturnInt(ret);
105 }
106 
107 /**
108  * \internal
109  * \brief this function is used to add the parsed dsize into the current signature
110  *
111  * \param de_ctx pointer to the Detection Engine Context
112  * \param s pointer to the Current Signature
113  * \param rawstr pointer to the user provided flags options
114  *
115  * \retval 0 on Success
116  * \retval -1 on Failure
117  */
118 static int DetectDsizeSetup (DetectEngineCtx *de_ctx, Signature *s, const char *rawstr)
119 {
120  DetectU16Data *dd = NULL;
121 
123  SCLogError("Can't use 2 or more dsizes in "
124  "the same sig. Invalidating signature.");
125  return -1;
126  }
127 
128  SCLogDebug("\'%s\'", rawstr);
129 
130  dd = DetectU16Parse(rawstr);
131  if (dd == NULL) {
132  SCLogError("Parsing \'%s\' failed", rawstr);
133  return -1;
134  }
135 
136  /* Okay so far so good, lets get this into a SigMatch
137  * and put it in the Signature. */
140  if (sm == NULL) {
141  SCDetectU16Free(dd);
142  return -1;
143  }
144 
145  SCLogDebug("dd->arg1 %" PRIu16 ", dd->arg2 %" PRIu16 ", dd->mode %" PRIu8 "", dd->arg1,
146  dd->arg2, dd->mode);
147  /* tell the sig it has a dsize to speed up engine init */
149  s->flags |= SIG_FLAG_DSIZE;
150 
151  if (s->init_data->dsize_sm == NULL) {
152  s->init_data->dsize_sm = sm;
153  }
154 
155  return 0;
156 }
157 
158 /**
159  * \internal
160  * \brief this function will free memory associated with DetectU16Data
161  *
162  * \param de pointer to DetectU16Data
163  */
164 void DetectDsizeFree(DetectEngineCtx *de_ctx, void *de_ptr)
165 {
166  SCDetectU16Free(de_ptr);
167 }
168 
169 /* prefilter code */
170 
171 static void
172 PrefilterPacketDsizeMatch(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
173 {
174  const PrefilterPacketHeaderCtx *ctx = pectx;
175  if (!PrefilterPacketHeaderExtraMatch(ctx, p))
176  return;
177 
178  const uint16_t dsize = p->payload_len;
179  DetectU16Data du16;
180  du16.mode = ctx->v1.u8[0];
181  du16.arg1 = ctx->v1.u16[1];
182  du16.arg2 = ctx->v1.u16[2];
183 
184  if (DetectU16Match(dsize, &du16)) {
185  SCLogDebug("packet matches dsize %u", dsize);
186  PrefilterAddSids(&det_ctx->pmq, ctx->sigs_array, ctx->sigs_cnt);
187  }
188 }
189 
190 static int PrefilterSetupDsize(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
191 {
193  PrefilterPacketU16Set, PrefilterPacketU16Compare, PrefilterPacketDsizeMatch);
194 }
195 
196 static bool PrefilterDsizeIsPrefilterable(const Signature *s)
197 {
198  return PrefilterIsPrefilterableById(s, DETECT_DSIZE);
199 }
200 
201 /** \brief get max dsize "depth"
202  * \param s signature to get dsize value from
203  * \retval depth or negative value
204  */
205 int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize)
206 {
207  if (s->flags & SIG_FLAG_DSIZE && s->init_data->dsize_sm != NULL) {
208  const DetectU16Data *dd = (const DetectU16Data *)s->init_data->dsize_sm->ctx;
209 
210  switch (dd->mode) {
211  case DETECT_UINT_LT:
212  case DETECT_UINT_EQ:
213  case DETECT_UINT_NE:
214  *dsize = dd->arg1;
215  SCReturnInt(0);
216  case DETECT_UINT_RA:
217  *dsize = dd->arg2;
218  SCReturnInt(0);
219  case DETECT_UINT_GT:
220  default:
221  SCReturnInt(-2);
222  }
223  }
224  SCReturnInt(-1);
225 }
226 
227 /** \brief set prefilter dsize pair
228  * \param s signature to get dsize value from
229  */
231 {
232  if (s->flags & SIG_FLAG_DSIZE && s->init_data->dsize_sm != NULL) {
233  const DetectU16Data *dd = (const DetectU16Data *)s->init_data->dsize_sm->ctx;
234 
235  uint16_t low = 0;
236  uint16_t high = 65535;
237 
238  switch (dd->mode) {
239  case DETECT_UINT_LT:
240  low = 0;
241  high = dd->arg1;
242  break;
243  case DETECT_UINT_LTE:
244  low = 0;
245  high = dd->arg1 + 1;
246  break;
247  case DETECT_UINT_EQ:
248  case DETECT_UINT_NE:
249  low = dd->arg1;
250  high = dd->arg1;
251  break;
252  case DETECT_UINT_RA:
253  low = dd->arg1;
254  high = dd->arg2;
255  break;
256  case DETECT_UINT_GT:
257  low = dd->arg1;
258  high = 65535;
259  break;
260  case DETECT_UINT_GTE:
261  low = dd->arg1 - 1;
262  high = 65535;
263  break;
264  }
265  s->dsize_mode = dd->mode;
266  s->dsize_low = low;
267  s->dsize_high = high;
268 
269  SCLogDebug("low %u, high %u, mode %u", low, high, dd->mode);
270  }
271 }
272 
273 /**
274  * \brief Determine the required dsize for the signature
275  * \param s signature to get dsize value from
276  *
277  * Note that negated content does not contribute to the maximum
278  * required dsize value. However, each negated content's values
279  * must not exceed the dsize value. See SigParseRequiredContentSize.
280  *
281  * \retval -1 Signature doesn't have a dsize keyword
282  * \retval >= 0 Dsize value required to not exclude content matches
283  */
285 {
286  SCEnter();
287 
288  if (!(s->flags & SIG_FLAG_DSIZE)) {
289  SCReturnInt(-1);
290  }
291 
292  uint16_t dsize;
293  if (SigParseGetMaxDsize(s, &dsize) < 0) {
294  /* nothing to do */
295  SCReturnInt(-1);
296  }
297 
298  int total_length, offset;
300  s, dsize, s->init_data->smlists[DETECT_SM_LIST_PMATCH], &total_length, &offset);
301  SCLogDebug("dsize: %d len: %d; offset: %d [%s]", dsize, total_length, offset, s->sig_str);
302 
303  if (total_length > dsize) {
304  SCLogDebug("required_dsize: %d exceeds dsize: %d", total_length, dsize);
305  return total_length;
306  }
307 
308  if ((total_length + offset) > dsize) {
309  SCLogDebug("length + offset: %d exceeds dsize: %d", total_length + offset, dsize);
310  return total_length + offset;
311  }
312 
313  SCReturnInt(-1);
314 }
315 
316 /**
317  * \brief Apply dsize as depth to content matches in the rule
318  * \param s signature to get dsize value from
319  */
321 {
322  SCEnter();
323 
324  if (s->flags & SIG_FLAG_DSIZE) {
326 
327  uint16_t dsize;
328  if (SigParseGetMaxDsize(s, &dsize) < 0) {
329  /* nothing to do */
330  return;
331  }
332 
334  for ( ; sm != NULL; sm = sm->next) {
335  if (sm->type != DETECT_CONTENT) {
336  continue;
337  }
338 
340  if (cd == NULL) {
341  continue;
342  }
343 
344  if (cd->depth == 0 || cd->depth >= dsize) {
346  cd->depth = (uint16_t)dsize;
347  SCLogDebug("updated %u, content %u to have depth %u "
348  "because of dsize.", s->id, cd->id, cd->depth);
349  }
350  }
351  }
352 }
353 
354 /*
355  * ONLY TESTS BELOW THIS COMMENT
356  */
357 
358 #ifdef UNITTESTS
359 #include "util-unittest-helper.h"
360 #include "detect-engine.h"
361 #include "detect-engine-alert.h"
362 #include "packet.h"
363 
364 /**
365  * \test this is a test for a valid dsize value 1
366  *
367  */
368 static int DsizeTestParse01(void)
369 {
370  DetectU16Data *dd = DetectU16Parse("1");
371  FAIL_IF_NULL(dd);
372  FAIL_IF_NOT(dd->arg1 == 1);
373  FAIL_IF_NOT(dd->arg2 == 0);
374 
375  DetectDsizeFree(NULL, dd);
376  PASS;
377 }
378 
379 /**
380  * \test this is a test for a valid dsize value >10
381  *
382  */
383 static int DsizeTestParse02(void)
384 {
385  DetectU16Data *dd = DetectU16Parse(">10");
386  FAIL_IF_NULL(dd);
387  FAIL_IF_NOT(dd->arg1 == 10);
388  FAIL_IF_NOT(dd->mode == DETECT_UINT_GT);
389  DetectDsizeFree(NULL, dd);
390  PASS;
391 }
392 
393 /**
394  * \test this is a test for a valid dsize value <100
395  *
396  */
397 static int DsizeTestParse03(void)
398 {
399  DetectU16Data *dd = DetectU16Parse("<100");
400  FAIL_IF_NULL(dd);
401  FAIL_IF_NOT(dd->arg1 == 100);
402  FAIL_IF_NOT(dd->mode == DETECT_UINT_LT);
403 
404  DetectDsizeFree(NULL, dd);
405  PASS;
406 }
407 
408 /**
409  * \test this is a test for a valid dsize value 1<>3
410  *
411  */
412 static int DsizeTestParse04(void)
413 {
414  DetectU16Data *dd = DetectU16Parse("1<>3");
415  FAIL_IF_NULL(dd);
416  FAIL_IF_NOT(dd->arg1 == 1);
417  FAIL_IF_NOT(dd->arg2 == 3);
418  FAIL_IF_NOT(dd->mode == DETECT_UINT_RA);
419 
420  DetectDsizeFree(NULL, dd);
421  PASS;
422 }
423 
424 /**
425  * \test this is a test for a valid dsize value 1 <> 3
426  *
427  */
428 static int DsizeTestParse05(void)
429 {
430  DetectU16Data *dd = DetectU16Parse(" 1 <> 3 ");
431  FAIL_IF_NULL(dd);
432  FAIL_IF_NOT(dd->arg1 == 1);
433  FAIL_IF_NOT(dd->arg2 == 3);
434  FAIL_IF_NOT(dd->mode == DETECT_UINT_RA);
435 
436  DetectDsizeFree(NULL, dd);
437  PASS;
438 }
439 
440 /**
441  * \test this is test for a valid dsize value > 2
442  *
443  */
444 static int DsizeTestParse06(void)
445 {
446  DetectU16Data *dd = DetectU16Parse("> 2 ");
447  FAIL_IF_NULL(dd);
448  FAIL_IF_NOT(dd->arg1 == 2);
449  FAIL_IF_NOT(dd->mode == DETECT_UINT_GT);
450 
451  DetectDsizeFree(NULL, dd);
452  PASS;
453 }
454 
455 /**
456  * \test test for a valid dsize value < 12
457  *
458  */
459 static int DsizeTestParse07(void)
460 {
461  DetectU16Data *dd = DetectU16Parse("< 12 ");
462  FAIL_IF_NULL(dd);
463  FAIL_IF_NOT(dd->arg1 == 12);
464  FAIL_IF_NOT(dd->mode == DETECT_UINT_LT);
465 
466  DetectDsizeFree(NULL, dd);
467  PASS;
468 }
469 
470 /**
471  * \test test for a valid dsize value 12
472  *
473  */
474 static int DsizeTestParse08(void)
475 {
476  DetectU16Data *dd = DetectU16Parse(" 12 ");
477  FAIL_IF_NULL(dd);
478  FAIL_IF_NOT(dd->arg1 == 12);
479  FAIL_IF_NOT(dd->mode == DETECT_UINT_EQ);
480 
481  DetectDsizeFree(NULL, dd);
482  PASS;
483 }
484 
485 /**
486  * \test this is a test for a valid dsize value !1
487  *
488  */
489 static int DsizeTestParse09(void)
490 {
491  DetectU16Data *dd = DetectU16Parse("!1");
492  FAIL_IF_NULL(dd);
493  DetectDsizeFree(NULL, dd);
494  PASS;
495 }
496 
497 /**
498  * \test this is a test for a valid dsize value ! 1
499  *
500  */
501 static int DsizeTestParse10(void)
502 {
503  DetectU16Data *dd = DetectU16Parse("! 1");
504  FAIL_IF_NULL(dd);
505  DetectDsizeFree(NULL, dd);
506  PASS;
507 }
508 
509 /**
510  * \test this is a test for invalid dsize values
511  * A, >10<>10, <>10, 1<>, "", " ", 2<>1, 1!
512  *
513  */
514 static int DsizeTestParse11(void)
515 {
516  const char *strings[] = { "A", ">10<>10", "<>10", "1<>", "", " ", "2<>1", "1!", NULL };
517  for (int i = 0; strings[i]; i++) {
518  DetectU16Data *dd = DetectU16Parse(strings[i]);
519  FAIL_IF_NOT_NULL(dd);
520  }
521 
522  PASS;
523 }
524 
525 /**
526  * \test this is a test for positive ! dsize matching
527  *
528  */
529 static int DsizeTestMatch01(void)
530 {
531  uint16_t psize = 1;
532  uint16_t dsizelow = 2;
533  uint16_t dsizehigh = 0;
534  DetectU16Data du16;
535  du16.mode = DETECT_UINT_NE;
536  du16.arg1 = dsizelow;
537  du16.arg2 = dsizehigh;
538  FAIL_IF_NOT(DetectU16Match(psize, &du16));
539 
540  PASS;
541 }
542 
543 /**
544  * \test this is a test for negative ! dsize matching
545  *
546  */
547 static int DsizeTestMatch02(void)
548 {
549  uint16_t psize = 1;
550  uint16_t dsizelow = 1;
551  uint16_t dsizehigh = 0;
552  DetectU16Data du16;
553  du16.mode = DETECT_UINT_NE;
554  du16.arg1 = dsizelow;
555  du16.arg2 = dsizehigh;
556  FAIL_IF(DetectU16Match(psize, &du16));
557 
558  PASS;
559 }
560 
561 /**
562  * \test DetectDsizeIcmpv6Test01 is a test for checking the working of
563  * dsize keyword by creating 2 rules and matching a crafted packet
564  * against them. Only the first one shall trigger.
565  */
566 static int DetectDsizeIcmpv6Test01(void)
567 {
568  static uint8_t raw_icmpv6[] = {
569  0x60, 0x00, 0x00, 0x00, 0x00, 0x30, 0x3a, 0xff,
570  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
571  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
572  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
573  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
574  0x01, 0x00, 0x7b, 0x85, 0x00, 0x00, 0x00, 0x00,
575  0x60, 0x4b, 0xe8, 0xbd, 0x00, 0x00, 0x3b, 0xff,
576  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
578  0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
579  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
580 
581  Packet *p = PacketGetFromAlloc();
582  FAIL_IF_NULL(p);
583 
585  ThreadVars th_v;
586  DetectEngineThreadCtx *det_ctx = NULL;
587 
588  memset(&dtv, 0, sizeof(DecodeThreadVars));
589  memset(&th_v, 0, sizeof(ThreadVars));
590  StatsThreadInit(&th_v.stats);
591 
593  p->src.family = AF_INET6;
594  p->dst.family = AF_INET6;
595 
596  DecodeIPV6(&th_v, &dtv, p, raw_icmpv6, sizeof(raw_icmpv6));
597 
600 
601  de_ctx->flags |= DE_QUIET;
602 
604  "alert icmp any any -> any any "
605  "(msg:\"ICMP Large ICMP Packet\"; dsize:>8; sid:1; rev:4;)");
606  FAIL_IF_NULL(s);
607 
609  "alert icmp any any -> any any "
610  "(msg:\"ICMP Large ICMP Packet\"; dsize:>800; sid:2; rev:4;)");
611  FAIL_IF_NULL(s);
612 
614  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
615 
616  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
617  FAIL_IF(PacketAlertCheck(p, 1) == 0);
618  FAIL_IF(PacketAlertCheck(p, 2));
619 
620  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
622 
623  PacketFree(p);
624  FlowShutdown();
625  StatsThreadCleanup(&th_v.stats);
626  PASS;
627 }
628 
629 /**
630  * \brief this function registers unit tests for dsize
631  */
632 static void DsizeRegisterTests(void)
633 {
634  UtRegisterTest("DsizeTestParse01", DsizeTestParse01);
635  UtRegisterTest("DsizeTestParse02", DsizeTestParse02);
636  UtRegisterTest("DsizeTestParse03", DsizeTestParse03);
637  UtRegisterTest("DsizeTestParse04", DsizeTestParse04);
638  UtRegisterTest("DsizeTestParse05", DsizeTestParse05);
639  UtRegisterTest("DsizeTestParse06", DsizeTestParse06);
640  UtRegisterTest("DsizeTestParse07", DsizeTestParse07);
641  UtRegisterTest("DsizeTestParse08", DsizeTestParse08);
642  UtRegisterTest("DsizeTestParse09", DsizeTestParse09);
643  UtRegisterTest("DsizeTestParse10", DsizeTestParse10);
644  UtRegisterTest("DsizeTestParse11", DsizeTestParse11);
645  UtRegisterTest("DsizeTestMatch01", DsizeTestMatch01);
646  UtRegisterTest("DsizeTestMatch02", DsizeTestMatch02);
647 
648  UtRegisterTest("DetectDsizeIcmpv6Test01", DetectDsizeIcmpv6Test01);
649 }
650 #endif /* UNITTESTS */
util-byte.h
SIGMATCH_INFO_UINT16
#define SIGMATCH_INFO_UINT16
Definition: detect.h:1689
host.h
DetectDsizeRegister
void DetectDsizeRegister(void)
Registration function for dsize: keyword.
Definition: detect-dsize.c:61
SigTableElmt_::url
const char * url
Definition: detect.h:1461
detect-content.h
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SIG_MASK_REQUIRE_REAL_PKT
#define SIG_MASK_REQUIRE_REAL_PKT
Definition: detect.h:316
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:642
PrefilterPacketU16Set
void PrefilterPacketU16Set(PrefilterPacketHeaderValue *v, void *smctx)
Definition: detect-engine-uint.c:126
SigTableElmt_::desc
const char * desc
Definition: detect.h:1460
detect-dsize.h
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
Signature_::sig_str
char * sig_str
Definition: detect.h:745
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1445
SigTableElmt_::name
const char * name
Definition: detect.h:1458
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1323
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1628
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DETECT_UINT_LT
#define DETECT_UINT_LT
Definition: detect-engine-uint.h:37
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:69
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1449
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DETECT_UINT_NE
#define DETECT_UINT_NE
Definition: detect-engine-uint.h:36
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:142
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1348
ctx
struct Thresholds ctx
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:933
SigParseGetMaxDsize
int SigParseGetMaxDsize(const Signature *s, uint16_t *dsize)
get max dsize "depth"
Definition: detect-dsize.c:205
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2634
DETECT_UINT_EQ
#define DETECT_UINT_EQ
Definition: detect-engine-uint.h:35
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:2418
DetectContentData_
Definition: detect-content.h:93
SIGMATCH_SUPPORT_FIREWALL
#define SIGMATCH_SUPPORT_FIREWALL
Definition: detect.h:1681
DETECT_UINT_GT
#define DETECT_UINT_GT
Definition: detect-engine-uint.h:32
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3447
SigTableElmt_::Setup
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
Definition: detect.h:1440
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:606
Signature_::dsize_low
uint16_t dsize_low
Definition: detect.h:675
util-unittest.h
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
SigTableElmt_::SetupPrefilter
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
Definition: detect.h:1443
FlowInitConfig
void FlowInitConfig(bool quiet)
initialize the configuration
Definition: flow.c:549
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:19
DetectEngineThreadCtx_
Definition: detect.h:1245
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
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:388
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
pkt-var.h
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3364
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:360
PacketFree
void PacketFree(Packet *p)
Return a malloced packet.
Definition: decode.c:223
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:117
DetectContentData_::id
PatIntId id
Definition: detect-content.h:105
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
SigParseSetDsizePair
void SigParseSetDsizePair(Signature *s)
set prefilter dsize pair
Definition: detect-dsize.c:230
util-profiling.h
Signature_::flags
uint32_t flags
Definition: detect.h:669
DetectContentData_::depth
uint16_t depth
Definition: detect-content.h:106
Packet_
Definition: decode.h:501
detect-engine-build.h
DETECT_UINT_GTE
#define DETECT_UINT_GTE
Definition: detect-engine-uint.h:33
SigParseRequiredContentSize
void SigParseRequiredContentSize(const Signature *s, const uint64_t max_size, const SigMatch *sm, int *len, int *offset)
Determine the size needed to accommodate the content elements of a signature.
Definition: detect-content.c:405
DecodeIPV6
int DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint16_t len)
Definition: decode-ipv6.c:549
detect-engine-alert.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:747
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:1420
DETECT_DSIZE
@ DETECT_DSIZE
Definition: detect-engine-register.h:52
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2194
dtv
DecodeThreadVars * dtv
Definition: fuzz_decodepcapfile.c:34
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1249
SigMatchCtx_
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
Definition: detect.h:351
SignatureInitData_::dsize_sm
SigMatch * dsize_sm
Definition: detect.h:615
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
DetectU16Match
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
Definition: detect-engine-uint.c:107
DetectU16Parse
DetectUintData_u16 * DetectU16Parse(const char *u16str)
This function is used to parse u16 options passed via some u16 keyword.
Definition: detect-engine-uint.c:121
PrefilterPacketU16Compare
bool PrefilterPacketU16Compare(PrefilterPacketHeaderValue v, void *smctx)
Definition: detect-engine-uint.c:134
suricata-common.h
SigMatch_::type
uint16_t type
Definition: detect.h:357
Signature_::dsize_high
uint16_t dsize_high
Definition: detect.h:676
FlowShutdown
void FlowShutdown(void)
shutdown the flow engine
Definition: flow.c:693
packet.h
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3601
PacketGetFromAlloc
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Definition: decode.c:262
DETECT_UINT_LTE
#define DETECT_UINT_LTE
Definition: detect-engine-uint.h:38
str
#define str(s)
Definition: suricata-common.h:308
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:274
DecodeThreadVars_
Structure to hold thread specific data for all decode modules.
Definition: decode.h:963
SigTableElmt_::SupportsPrefilter
bool(* SupportsPrefilter)(const Signature *s)
Definition: detect.h:1442
Signature_::id
uint32_t id
Definition: detect.h:713
detect-parse.h
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2595
Signature_::dsize_mode
uint8_t dsize_mode
Definition: detect.h:677
Address_::family
char family
Definition: decode.h:113
Packet_::dst
Address dst
Definition: decode.h:506
FLOW_QUIET
#define FLOW_QUIET
Definition: flow.h:43
SigParseApplyDsizeToContent
void SigParseApplyDsizeToContent(Signature *s)
Apply dsize as depth to content matches in the rule.
Definition: detect-dsize.c:320
DetectGetLastSMFromLists
SigMatch * DetectGetLastSMFromLists(const Signature *s,...)
Returns the sm with the largest index (added latest) from the lists passed to us.
Definition: detect-parse.c:564
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:935
detect-engine-prefilter-common.h
DetectU16Data
DetectUintData_u16 DetectU16Data
Definition: detect-engine-uint.h:42
SigParseMaxRequiredDsize
int SigParseMaxRequiredDsize(const Signature *s)
Determine the required dsize for the signature.
Definition: detect-dsize.c:284
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:121
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:288
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1345
flow-var.h
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
Packet_::src
Address src
Definition: decode.h:505
DETECT_UINT_RA
#define DETECT_UINT_RA
Definition: detect-engine-uint.h:34
SigTableElmt_::RegisterTests
void(* RegisterTests)(void)
Definition: detect.h:1447
SIG_FLAG_DSIZE
#define SIG_FLAG_DSIZE
Definition: detect.h:248
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:254