suricata
detect-engine-siggroup.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 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  * Signature grouping part of the detection engine.
24  */
25 
26 #include "suricata-common.h"
27 #include "decode.h"
28 
29 #include "flow-var.h"
30 
31 #include "app-layer-protos.h"
32 
33 #include "detect.h"
34 #include "detect-parse.h"
35 #include "detect-engine.h"
36 #include "detect-engine-build.h"
37 #include "detect-engine-address.h"
38 #include "detect-engine-mpm.h"
39 #include "detect-engine-siggroup.h"
41 
42 #include "detect-content.h"
43 #include "detect-uricontent.h"
44 #include "detect-tcp-flags.h"
45 
46 #include "util-hash.h"
47 #include "util-hashlist.h"
48 
49 #include "util-error.h"
50 #include "util-debug.h"
51 #include "util-validate.h"
52 #include "util-cidr.h"
53 #include "util-unittest.h"
54 #include "util-unittest-helper.h"
55 #include "util-memcmp.h"
56 
57 /* prototypes */
59 
61 {
62  if (sghid->match_array != NULL) {
63  SCFree(sghid->match_array);
64  sghid->match_array = NULL;
65  }
66  if (sghid->sig_array != NULL) {
67  SCFreeAligned(sghid->sig_array);
68  sghid->sig_array = NULL;
69  }
70  if (sghid->app_mpms != NULL) {
71  SCFree(sghid->app_mpms);
72  }
73  if (sghid->pkt_mpms != NULL) {
74  SCFree(sghid->pkt_mpms);
75  }
76  if (sghid->frame_mpms != NULL) {
77  SCFree(sghid->frame_mpms);
78  }
79 
84 
85  SCFree(sghid);
86 }
87 
88 static SigGroupHeadInitData *SigGroupHeadInitDataAlloc(uint32_t size)
89 {
91  if (unlikely(sghid == NULL))
92  return NULL;
93 
94  /* initialize the signature bitarray */
95  size = sghid->sig_size = size + 16 - (size % 16);
96  void *ptr = SCMallocAligned(sghid->sig_size, 16);
97  if (ptr == NULL)
98  goto error;
99  memset(ptr, 0, size);
100  sghid->sig_array = ptr;
101 
102  return sghid;
103 error:
105  return NULL;
106 }
107 
109 {
110  void *ptmp;
111  //printf("de_ctx->sgh_array_cnt %u, de_ctx->sgh_array_size %u, de_ctx->sgh_array %p\n", de_ctx->sgh_array_cnt, de_ctx->sgh_array_size, de_ctx->sgh_array);
114  } else {
115  int increase = 16;
116  ptmp = SCRealloc(de_ctx->sgh_array,
117  sizeof(SigGroupHead *) * (increase + de_ctx->sgh_array_size));
118  if (ptmp == NULL) {
120  de_ctx->sgh_array = NULL;
121  return;
122  }
123  de_ctx->sgh_array = ptmp;
124 
125  de_ctx->sgh_array_size += increase;
127  }
129 }
130 
131 /**
132  * \brief Alloc a SigGroupHead and its signature bit_array.
133  *
134  * \param size Size of the sig_array that has to be created for this
135  * SigGroupHead.
136  *
137  * \retval sgh Pointer to the newly init SigGroupHead on success; or NULL in
138  * case of error.
139  */
140 static SigGroupHead *SigGroupHeadAlloc(const DetectEngineCtx *de_ctx, uint32_t size)
141 {
142  SigGroupHead *sgh = SCCalloc(1, sizeof(SigGroupHead));
143  if (unlikely(sgh == NULL))
144  return NULL;
145 
146  sgh->init = SigGroupHeadInitDataAlloc(size);
147  if (sgh->init == NULL)
148  goto error;
149 
150  return sgh;
151 
152 error:
153  SigGroupHeadFree(de_ctx, sgh);
154  return NULL;
155 }
156 
157 /**
158  * \brief Free a SigGroupHead and its members.
159  *
160  * \param sgh Pointer to the SigGroupHead that has to be freed.
161  */
163 {
164  if (sgh == NULL)
165  return;
166 
167  SCLogDebug("sgh %p", sgh);
168 
169  if (sgh->non_pf_other_store_array != NULL) {
171  sgh->non_pf_other_store_array = NULL;
172  sgh->non_pf_other_store_cnt = 0;
173  }
174 
175  if (sgh->non_pf_syn_store_array != NULL) {
177  sgh->non_pf_syn_store_array = NULL;
178  sgh->non_pf_syn_store_cnt = 0;
179  }
180 
181  if (sgh->init != NULL) {
183  sgh->init = NULL;
184  }
185 
187  SCFree(sgh);
188 
189  return;
190 }
191 
192 /**
193  * \brief The hash function to be the used by the hash table -
194  * DetectEngineCtx->sgh_hash_table.
195  *
196  * \param ht Pointer to the hash table.
197  * \param data Pointer to the SigGroupHead.
198  * \param datalen Not used in our case.
199  *
200  * \retval hash The generated hash value.
201  */
202 static uint32_t SigGroupHeadHashFunc(HashListTable *ht, void *data, uint16_t datalen)
203 {
204  SigGroupHead *sgh = (SigGroupHead *)data;
205  uint32_t hash = 0;
206  uint32_t b = 0;
207 
208  SCLogDebug("hashing sgh %p", sgh);
209 
210  for (b = 0; b < sgh->init->sig_size; b++)
211  hash += sgh->init->sig_array[b];
212 
213  hash %= ht->array_size;
214  SCLogDebug("hash %"PRIu32" (sig_size %"PRIu32")", hash, sgh->init->sig_size);
215  return hash;
216 }
217 
218 /**
219  * \brief The Compare function to be used by the SigGroupHead hash table -
220  * DetectEngineCtx->sgh_hash_table.
221  *
222  * \param data1 Pointer to the first SigGroupHead.
223  * \param len1 Not used.
224  * \param data2 Pointer to the second SigGroupHead.
225  * \param len2 Not used.
226  *
227  * \retval 1 If the 2 SigGroupHeads sent as args match.
228  * \retval 0 If the 2 SigGroupHeads sent as args do not match.
229  */
230 static char SigGroupHeadCompareFunc(void *data1, uint16_t len1, void *data2,
231  uint16_t len2)
232 {
233  SigGroupHead *sgh1 = (SigGroupHead *)data1;
234  SigGroupHead *sgh2 = (SigGroupHead *)data2;
235 
236  if (data1 == NULL || data2 == NULL)
237  return 0;
238 
239  if (sgh1->init->sig_size != sgh2->init->sig_size)
240  return 0;
241 
242  if (SCMemcmp(sgh1->init->sig_array, sgh2->init->sig_array, sgh1->init->sig_size) != 0)
243  return 0;
244 
245  return 1;
246 }
247 
248 /**
249  * \brief Initializes the hash table in the detection engine context to hold the
250  * SigGroupHeads.
251  *
252  * \param de_ctx Pointer to the detection engine context.
253  *
254  * \retval 0 On success.
255  * \retval -1 On failure.
256  */
258 {
259  de_ctx->sgh_hash_table = HashListTableInit(4096, SigGroupHeadHashFunc,
260  SigGroupHeadCompareFunc, NULL);
261  if (de_ctx->sgh_hash_table == NULL)
262  goto error;
263 
264  return 0;
265 
266 error:
267  return -1;
268 }
269 
270 /**
271  * \brief Adds a SigGroupHead to the detection engine context SigGroupHead
272  * hash table.
273  *
274  * \param de_ctx Pointer to the detection engine context.
275  * \param sgh Pointer to the SigGroupHead.
276  *
277  * \retval ret 0 on Successfully adding the SigGroupHead; -1 on failure.
278  */
280 {
281  int ret = HashListTableAdd(de_ctx->sgh_hash_table, (void *)sgh, 0);
282 
283  return ret;
284 }
285 
286 /**
287  * \brief Used to lookup a SigGroupHead hash from the detection engine context
288  * SigGroupHead hash table.
289  *
290  * \param de_ctx Pointer to the detection engine context.
291  * \param sgh Pointer to the SigGroupHead.
292  *
293  * \retval rsgh On success a pointer to the SigGroupHead if the SigGroupHead is
294  * found in the hash table; NULL on failure.
295  */
297 {
298  SCEnter();
299 
301  (void *)sgh, 0);
302 
303  SCReturnPtr(rsgh, "SigGroupHead");
304 }
305 
306 /**
307  * \brief Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by
308  * SigGroupHeadHashInit() function.
309  *
310  * \param de_ctx Pointer to the detection engine context.
311  */
313 {
314  if (de_ctx->sgh_hash_table == NULL)
315  return;
316 
318  de_ctx->sgh_hash_table = NULL;
319 
320  return;
321 }
322 
323 /**
324  * \brief Add a Signature to a SigGroupHead.
325  *
326  * \param de_ctx Pointer to the detection engine context.
327  * \param sgh Pointer to a SigGroupHead. Can be NULL also.
328  * \param s Pointer to the Signature that has to be added to the
329  * SigGroupHead.
330  *
331  * \retval 0 On success.
332  * \retval -1 On failure.
333  */
335  const Signature *s)
336 {
337  if (de_ctx == NULL)
338  return 0;
339 
340  /* see if we have a head already */
341  if (*sgh == NULL) {
342  *sgh = SigGroupHeadAlloc(de_ctx, DetectEngineGetMaxSigId(de_ctx) / 8 + 1);
343  if (*sgh == NULL)
344  goto error;
345  }
346 
347  /* enable the sig in the bitarray */
348  (*sgh)->init->sig_array[s->num / 8] |= 1 << (s->num % 8);
349  (*sgh)->init->max_sig_id = MAX(s->num, (*sgh)->init->max_sig_id);
350  return 0;
351 
352 error:
353  return -1;
354 }
355 
356 /**
357  * \brief Clears the bitarray holding the sids for this SigGroupHead.
358  *
359  * \param sgh Pointer to the SigGroupHead.
360  *
361  * \retval 0 Always.
362  */
364 {
365  if (sgh == NULL)
366  return 0;
367 
368  if (sgh->init->sig_array != NULL)
369  memset(sgh->init->sig_array, 0, sgh->init->sig_size);
370 
371  sgh->init->sig_cnt = 0;
372 
373  return 0;
374 }
375 
376 #ifdef __SSE2__
377 #include <emmintrin.h>
378 static void MergeBitarrays(const uint8_t *src, uint8_t *dst, const uint32_t size)
379 {
380 #define BYTES 16
381  const uint8_t *srcptr = src;
382  uint8_t *dstptr = dst;
383  for (uint32_t i = 0; i < size; i += 16) {
384  __m128i s = _mm_load_si128((const __m128i *)srcptr);
385  __m128i d = _mm_load_si128((const __m128i *)dstptr);
386  d = _mm_or_si128(s, d);
387  _mm_store_si128((__m128i *)dstptr, d);
388  srcptr += BYTES;
389  dstptr += BYTES;
390  }
391 }
392 #endif
393 
394 /**
395  * \brief Copies the bitarray holding the sids from the source SigGroupHead to
396  * the destination SigGroupHead.
397  *
398  * \param de_ctx Pointer to the detection engine context.
399  * \param src Pointer to the source SigGroupHead.
400  * \param dst Pointer to the destination SigGroupHead.
401  *
402  * \retval 0 On success.
403  * \retval -1 On failure.
404  */
406 {
407  if (src == NULL || de_ctx == NULL)
408  return 0;
409 
410  if (*dst == NULL) {
411  *dst = SigGroupHeadAlloc(de_ctx, DetectEngineGetMaxSigId(de_ctx) / 8 + 1);
412  if (*dst == NULL)
413  goto error;
414  }
415  DEBUG_VALIDATE_BUG_ON(src->init->sig_size != (*dst)->init->sig_size);
416 
417 #ifdef __SSE2__
418  MergeBitarrays(src->init->sig_array, (*dst)->init->sig_array, src->init->sig_size);
419 #else
420  /* do the copy */
421  for (uint32_t idx = 0; idx < src->init->sig_size; idx++)
422  (*dst)->init->sig_array[idx] = (*dst)->init->sig_array[idx] | src->init->sig_array[idx];
423 #endif
424  if (src->init->score)
425  (*dst)->init->score = MAX((*dst)->init->score, src->init->score);
426 
427  if (src->init->max_sig_id)
428  (*dst)->init->max_sig_id = MAX((*dst)->init->max_sig_id, src->init->max_sig_id);
429  return 0;
430 
431 error:
432  return -1;
433 }
434 
435 #ifdef HAVE_POPCNT64
436 #include <x86intrin.h>
437 static uint32_t Popcnt(const uint8_t *array, const uint32_t size)
438 {
439  /* input needs to be a multiple of 8 for u64 casts to work */
440  DEBUG_VALIDATE_BUG_ON(size < 8);
441  DEBUG_VALIDATE_BUG_ON(size % 8);
442 
443  uint32_t cnt = 0;
444  uint64_t *ptr = (uint64_t *)array;
445  for (uint64_t idx = 0; idx < size; idx += 8) {
446  cnt += _popcnt64(*ptr);
447  ptr++;
448  }
449  return cnt;
450 }
451 #endif
452 
453 /**
454  * \brief Updates the SigGroupHead->sig_cnt with the total count of all the
455  * Signatures present in this SigGroupHead.
456  *
457  * \param sgh Pointer to the SigGroupHead.
458  * \param max_idx Maximum sid of the all the Signatures present in this
459  * SigGroupHead.
460  */
461 void SigGroupHeadSetSigCnt(SigGroupHead *sgh, uint32_t max_idx)
462 {
463  sgh->init->max_sig_id = MAX(max_idx, sgh->init->max_sig_id);
464 #ifdef HAVE_POPCNT64
465  sgh->init->sig_cnt = Popcnt(sgh->init->sig_array, sgh->init->sig_size);
466 #else
467  uint32_t cnt = 0;
468  for (uint32_t sig = 0; sig < sgh->init->max_sig_id + 1; sig++) {
469  if (sgh->init->sig_array[sig / 8] & (1 << (sig % 8)))
470  cnt++;
471  }
472  sgh->init->sig_cnt = cnt;
473 #endif
474  return;
475 }
476 
477 /**
478  * \brief Finds if two Signature Group Heads are the same.
479  *
480  * \param sgha First SGH to be compared
481  * \param sghb Secornd SGH to be compared
482  *
483  * \return true if they're a match, false otherwise
484  */
485 bool SigGroupHeadEqual(const SigGroupHead *sgha, const SigGroupHead *sghb)
486 {
487  if (sgha == NULL || sghb == NULL)
488  return false;
489 
490  if (sgha->init->sig_size != sghb->init->sig_size)
491  return false;
492 
493  if (sgha->init->max_sig_id != sghb->init->max_sig_id)
494  return false;
495 
496  if (SCMemcmp(sgha->init->sig_array, sghb->init->sig_array, sgha->init->sig_size) != 0)
497  return false;
498 
499  return true;
500 }
501 
503  uint8_t ipproto, int dir)
504 {
505  if (sgh && sgh->init) {
506  SCLogDebug("setting proto %u and dir %d on sgh %p", ipproto, dir, sgh);
507  sgh->init->protos[ipproto] = 1;
508  sgh->init->direction |= dir;
509  }
510 }
511 
512 /**
513  * \brief Helper function used to print the list of sids for the Signatures
514  * present in this SigGroupHead.
515  *
516  * \param de_ctx Pointer to the detection engine context.
517  * \param sgh Pointer to the SigGroupHead.
518  */
520 {
521  SCEnter();
522 
523  if (sgh == NULL) {
524  SCReturn;
525  }
526 
527  uint32_t u;
528 
529  SCLogDebug("The Signatures present in this SigGroupHead are: ");
530  for (u = 0; u < (sgh->init->sig_size * 8); u++) {
531  if (sgh->init->sig_array[u / 8] & (1 << (u % 8))) {
532  SCLogDebug("%" PRIu32, u);
533  printf("s->num %"PRIu32" ", u);
534  }
535  }
536 
537  SCReturn;
538 }
539 
540 /**
541  * \brief Create an array with all the internal ids of the sigs that this
542  * sig group head will check for.
543  *
544  * \param de_ctx Pointer to the detection engine context.
545  * \param sgh Pointer to the SigGroupHead.
546  * \param max_idx The maximum value of the sid in the SigGroupHead arg.
547  *
548  * \retval 0 success
549  * \retval -1 error
550  */
552  uint32_t max_idx)
553 {
554  Signature *s = NULL;
555  uint32_t idx = 0;
556  uint32_t sig = 0;
557 
558  if (sgh == NULL)
559  return 0;
560 
561  BUG_ON(sgh->init->match_array != NULL);
562  sgh->init->max_sig_id = MAX(sgh->init->max_sig_id, max_idx);
563 
564  sgh->init->match_array = SCCalloc(sgh->init->sig_cnt, sizeof(Signature *));
565  if (sgh->init->match_array == NULL)
566  return -1;
567 
568  for (sig = 0; sig < sgh->init->max_sig_id + 1; sig++) {
569  if (!(sgh->init->sig_array[(sig / 8)] & (1 << (sig % 8))) )
570  continue;
571 
572  s = de_ctx->sig_array[sig];
573  if (s == NULL)
574  continue;
575 
576  sgh->init->match_array[idx] = s;
577  idx++;
578  }
579 
580  return 0;
581 }
582 
583 /**
584  * \brief Set the need hash flag in the sgh.
585  *
586  * \param de_ctx detection engine ctx for the signatures
587  * \param sgh sig group head to update
588  */
590 {
591  if (sgh == NULL)
592  return;
593 
594  for (uint32_t sig = 0; sig < sgh->init->sig_cnt; sig++) {
595  const Signature *s = sgh->init->match_array[sig];
596  if (s == NULL)
597  continue;
598 
601  }
604  SCLogDebug("sgh %p has filemd5", sgh);
605  }
608  SCLogDebug("sgh %p has filesha1", sgh);
609  }
612  SCLogDebug("sgh %p has filesha256", sgh);
613  }
614 #ifdef HAVE_MAGIC
616  sgh->flags |= SIG_GROUP_HEAD_HAVEFILEMAGIC;
617  }
618 #endif
619  if (SignatureIsFilestoring(s)) {
620  // should be insured by caller that we do not overflow
621  DEBUG_VALIDATE_BUG_ON(sgh->filestore_cnt == UINT16_MAX);
622  sgh->filestore_cnt++;
623  }
624  }
625 
626  return;
627 }
628 
629 /** \brief build an array of rule id's for sigs with no prefilter
630  * Also updated de_ctx::non_pf_store_cnt_max to track the highest cnt
631  */
633 {
634  Signature *s = NULL;
635  uint32_t sig = 0;
636  uint32_t non_pf = 0;
637  uint32_t non_pf_syn = 0;
638 
639  if (sgh == NULL)
640  return 0;
641 
642  BUG_ON(sgh->non_pf_other_store_array != NULL);
643 
644  for (sig = 0; sig < sgh->init->sig_cnt; sig++) {
645  s = sgh->init->match_array[sig];
646  if (s == NULL)
647  continue;
648 
649  if (!(s->flags & SIG_FLAG_PREFILTER) || (s->flags & SIG_FLAG_MPM_NEG)) {
651  non_pf++;
652  }
653  non_pf_syn++;
654  }
655  }
656 
657  if (non_pf == 0 && non_pf_syn == 0) {
658  sgh->non_pf_other_store_array = NULL;
659  sgh->non_pf_syn_store_array = NULL;
660  return 0;
661  }
662 
663  if (non_pf > 0) {
665  BUG_ON(sgh->non_pf_other_store_array == NULL);
666  }
667 
668  if (non_pf_syn > 0) {
669  sgh->non_pf_syn_store_array = SCCalloc(non_pf_syn, sizeof(SignatureNonPrefilterStore));
670  BUG_ON(sgh->non_pf_syn_store_array == NULL);
671  }
672 
673  for (sig = 0; sig < sgh->init->sig_cnt; sig++) {
674  s = sgh->init->match_array[sig];
675  if (s == NULL)
676  continue;
677 
678  if (!(s->flags & SIG_FLAG_PREFILTER) || (s->flags & SIG_FLAG_MPM_NEG)) {
680  BUG_ON(sgh->non_pf_other_store_cnt >= non_pf);
681  BUG_ON(sgh->non_pf_other_store_array == NULL);
685  sgh->non_pf_other_store_cnt++;
686  }
687 
688  BUG_ON(sgh->non_pf_syn_store_cnt >= non_pf_syn);
689  BUG_ON(sgh->non_pf_syn_store_array == NULL);
693  sgh->non_pf_syn_store_cnt++;
694  }
695  }
696 
697  /* track highest cnt for any sgh in our de_ctx */
698  uint32_t max = MAX(sgh->non_pf_other_store_cnt, sgh->non_pf_syn_store_cnt);
699  if (max > de_ctx->non_pf_store_cnt_max)
701 
702  return 0;
703 }
704 
705 /**
706  * \brief Check if a SigGroupHead contains a Signature, whose sid is sent as an
707  * argument.
708  *
709  * \param de_ctx Pointer to the detection engine context.
710  * \param sgh Pointer to the SigGroupHead that has to be checked for the
711  * presence of a Signature.
712  * \param sid The Signature id(sid) that has to be checked in the SigGroupHead.
713  *
714  * \retval 1 On successfully finding the sid in the SigGroupHead.
715  * \retval 0 If the sid is not found in the SigGroupHead
716  */
718  uint32_t sid)
719 {
720  SCEnter();
721 
722  uint32_t sig = 0;
723  Signature *s = NULL;
724  uint32_t max_sid = DetectEngineGetMaxSigId(de_ctx);
725 
726  if (sgh == NULL) {
727  SCReturnInt(0);
728  }
729 
730  for (sig = 0; sig < max_sid; sig++) {
731  if (sgh->init->sig_array == NULL) {
732  SCReturnInt(0);
733  }
734 
735  /* Check if the SigGroupHead has an entry for the sid */
736  if ( !(sgh->init->sig_array[sig / 8] & (1 << (sig % 8))) )
737  continue;
738 
739  /* If we have reached here, we have an entry for sid in the SigGroupHead.
740  * Retrieve the Signature from the detection engine context */
741  s = de_ctx->sig_array[sig];
742  if (s == NULL)
743  continue;
744 
745  /* If the retrieved Signature matches the sid arg, we have a match */
746  if (s->id == sid) {
747  SCReturnInt(1);
748  }
749  }
750 
751  SCReturnInt(0);
752 }
753 
754 /*----------------------------------Unittests---------------------------------*/
755 
756 #ifdef UNITTESTS
757 
759 
760 /**
761  * \test Check if a SigGroupHead hash table is properly allocated and
762  * deallocated when calling SigGroupHeadHashInit() and
763  * SigGroupHeadHashFree() respectively.
764  */
765 static int SigGroupHeadTest01(void)
766 {
768 
771 
774 
775  PASS;
776 }
777 
778 /**
779  * \test Check if a SigGroupHeadAppendSig() correctly appends a sid to a
780  * SigGroupHead() and SigGroupHeadContainsSigId() correctly indicates
781  * the presence of a sid.
782  */
783 static int SigGroupHeadTest02(void)
784 {
785  SigGroupHead *sh = NULL;
786 
789 
790  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
791  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
792  "content:\"test2\"; content:\"test3\"; sid:1;)");
793  FAIL_IF_NULL(s);
794 
795  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
796  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
797  "content:\"test2\"; content:\"test3\"; sid:2;)");
798  FAIL_IF_NULL(s);
799 
800  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
801  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
802  "content:\"test2\"; content:\"test3\"; sid:3;)");
803  FAIL_IF_NULL(s);
804 
805  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
806  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
807  "content:\"test2\"; content:\"test3\"; sid:4;)");
808  FAIL_IF_NULL(s);
809 
810  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
811  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
812  "content:\"test2\"; content:\"test3\"; sid:5;)");
813  FAIL_IF_NULL(s);
814 
816 
820 
821  SigGroupHeadSetSigCnt(sh, 4);
822 
823  FAIL_IF_NOT(sh->init->sig_cnt == 3);
829 
831 
833 
834  PASS;
835 }
836 
837 /**
838  * \test Check if a SigGroupHeadAppendSig(), correctly appends a sid to a
839  * SigGroupHead() and SigGroupHeadContainsSigId(), correctly indicates
840  * the presence of a sid and SigGroupHeadClearSigs(), correctly clears
841  * the SigGroupHead->sig_array and SigGroupHead->sig_cnt.
842  */
843 static int SigGroupHeadTest03(void)
844 {
845  SigGroupHead *sh = NULL;
846 
849 
850  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
851  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
852  "content:\"test2\"; content:\"test3\"; sid:1;)");
853  FAIL_IF_NULL(s);
854 
855  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
856  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
857  "content:\"test2\"; content:\"test3\"; sid:2;)");
858  FAIL_IF_NULL(s);
859 
860  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
861  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
862  "content:\"test2\"; content:\"test3\"; sid:3;)");
863  FAIL_IF_NULL(s);
864 
865  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
866  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
867  "content:\"test2\"; content:\"test3\"; sid:4;)");
868  FAIL_IF_NULL(s);
869 
870  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
871  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
872  "content:\"test2\"; content:\"test3\"; sid:5;)");
873  FAIL_IF_NULL(s);
874 
876 
880 
881  SigGroupHeadSetSigCnt(sh, 4);
882 
883  FAIL_IF_NOT(sh->init->sig_cnt == 3);
889 
891 
892  FAIL_IF_NOT(sh->init->sig_cnt == 0);
898 
900 
902 
903  PASS;
904 }
905 
906 /**
907  * \test Check if SigGroupHeadCopySigs(), correctly copies the sig_array from
908  * the source to the destination SigGroupHead.
909  */
910 static int SigGroupHeadTest04(void)
911 {
912  SigGroupHead *src_sh = NULL;
913  SigGroupHead *dst_sh = NULL;
915 
917 
918  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
919  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
920  "content:\"test2\"; content:\"test3\"; sid:1;)");
921  FAIL_IF_NULL(s);
922 
923  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
924  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
925  "content:\"test2\"; content:\"test3\"; sid:2;)");
926  FAIL_IF_NULL(s);
927 
928  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
929  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
930  "content:\"test2\"; content:\"test3\"; sid:3;)");
931  FAIL_IF_NULL(s);
932 
933  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
934  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
935  "content:\"test2\"; content:\"test3\"; sid:4;)");
936  FAIL_IF_NULL(s);
937 
938  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
939  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
940  "content:\"test2\"; content:\"test3\"; sid:5;)");
941  FAIL_IF_NULL(s);
942 
944 
948 
949  SigGroupHeadSetSigCnt(src_sh, 4);
950 
951  FAIL_IF_NOT(src_sh->init->sig_cnt == 3);
952  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, src_sh, 1) == 1);
953  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, src_sh, 2) == 0);
954  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, src_sh, 3) == 1);
955  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, src_sh, 4) == 0);
956  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, src_sh, 5) == 1);
957 
958  SigGroupHeadCopySigs(de_ctx, src_sh, &dst_sh);
959 
960  SigGroupHeadSetSigCnt(dst_sh, 4);
961 
962  FAIL_IF_NOT(dst_sh->init->sig_cnt == 3);
963  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, dst_sh, 1) == 1);
964  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, dst_sh, 2) == 0);
965  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, dst_sh, 3) == 1);
966  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, dst_sh, 4) == 0);
967  FAIL_IF_NOT(SigGroupHeadContainsSigId(de_ctx, dst_sh, 5) == 1);
968 
969  SigGroupHeadFree(de_ctx, src_sh);
970  SigGroupHeadFree(de_ctx, dst_sh);
971 
973 
974  PASS;
975 }
976 
977 /**
978  * \test Check if SigGroupHeadBuildMatchArray(), correctly updates the
979  * match array with the sids.
980  */
981 static int SigGroupHeadTest05(void)
982 {
983  SigGroupHead *sh = NULL;
985 
987 
988  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
989  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
990  "content:\"test2\"; content:\"test3\"; sid:1;)");
991  FAIL_IF_NULL(s);
992 
993  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
994  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
995  "content:\"test2\"; content:\"test3\"; sid:2;)");
996  FAIL_IF_NULL(s);
997 
998  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
999  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
1000  "content:\"test2\"; content:\"test3\"; sid:3;)");
1001  FAIL_IF_NULL(s);
1002 
1003  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
1004  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
1005  "content:\"test2\"; content:\"test3\"; sid:4;)");
1006  FAIL_IF_NULL(s);
1007 
1008  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
1009  "(msg:\"SigGroupHead tests\"; content:\"test1\"; "
1010  "content:\"test2\"; content:\"test3\"; sid:5;)");
1011  FAIL_IF_NULL(s);
1012 
1014 
1018 
1019  SigGroupHeadSetSigCnt(sh, 4);
1021 
1022  /* matching an array to a queue structure (sig_list) constructed by SigInit()
1023 
1024  FAIL_IF_NOT(sh->init->match_array[0] == de_ctx->sig_list);
1025  FAIL_IF_NOT(sh->init->match_array[1] == de_ctx->sig_list->next->next);
1026  FAIL_IF_NOT(sh->init->match_array[2] == de_ctx->sig_list->next->next->next->next);
1027  */
1028 
1029  // matching an array to a stack structure (sig_list) constructed by DetectEngineAppendSig()
1033 
1034  SigGroupHeadFree(de_ctx, sh);
1035 
1037 
1038  PASS;
1039 }
1040 
1041 /**
1042  * \test ICMP(?) sig grouping bug.
1043  */
1044 static int SigGroupHeadTest06(void)
1045 {
1047  DetectEngineThreadCtx *det_ctx = NULL;
1048  ThreadVars th_v;
1049 
1050  memset(&th_v, 0, sizeof(ThreadVars));
1051 
1052  Packet *p = UTHBuildPacketSrcDst(NULL, 0, IPPROTO_ICMP, "192.168.1.1", "1.2.3.4");
1053  FAIL_IF_NULL(p);
1054  FAIL_IF_NOT(PacketIsICMPv4(p));
1055 
1056  p->l4.hdrs.icmpv4h->type = 5;
1057  p->l4.hdrs.icmpv4h->code = 1;
1058 
1059  /* originally ip's were
1060  p.src.addr_data32[0] = 0xe08102d3;
1061  p.dst.addr_data32[0] = 0x3001a8c0;
1062  */
1063 
1065 
1066  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp 192.168.0.0/16 any -> any any "
1067  "(icode:>1; itype:11; sid:1; rev:1;)");
1068  FAIL_IF_NULL(s);
1069 
1070  s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> 192.168.0.0/16 any "
1071  "(icode:1; itype:5; sid:2; rev:1;)");
1072  FAIL_IF_NULL(s);
1073 
1075  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1076 
1077  AddressDebugPrint(&p->dst);
1078 
1079  const SigGroupHead *sgh = SigMatchSignaturesGetSgh(de_ctx, p);
1080  FAIL_IF_NULL(sgh);
1081 
1083  UTHFreePackets(&p, 1);
1084 
1085  PASS;
1086 }
1087 #endif
1088 
1090 {
1091 #ifdef UNITTESTS
1092  UtRegisterTest("SigGroupHeadTest01", SigGroupHeadTest01);
1093  UtRegisterTest("SigGroupHeadTest02", SigGroupHeadTest02);
1094  UtRegisterTest("SigGroupHeadTest03", SigGroupHeadTest03);
1095  UtRegisterTest("SigGroupHeadTest04", SigGroupHeadTest04);
1096  UtRegisterTest("SigGroupHeadTest05", SigGroupHeadTest05);
1097  UtRegisterTest("SigGroupHeadTest06", SigGroupHeadTest06);
1098 #endif
1099 }
detect-tcp-flags.h
DetectEngineCtx_::sgh_hash_table
HashListTable * sgh_hash_table
Definition: detect.h:872
SigGroupHead_::non_pf_syn_store_cnt
uint32_t non_pf_syn_store_cnt
Definition: detect.h:1460
SIG_GROUP_HEAD_HAVEFILEMD5
#define SIG_GROUP_HEAD_HAVEFILEMD5
Definition: detect.h:1326
detect-content.h
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
util-hashlist.h
detect-engine-siggroup.h
SigGroupHead_::flags
uint16_t flags
Definition: detect.h:1449
Signature_::num
SigIntId num
Definition: detect.h:608
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1448
SIG_GROUP_HEAD_HAVEFILESIZE
#define SIG_GROUP_HEAD_HAVEFILESIZE
Definition: detect.h:1327
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SigGroupHeadBuildNonPrefilterArray
int SigGroupHeadBuildNonPrefilterArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
build an array of rule id's for sigs with no prefilter Also updated de_ctx::non_pf_store_cnt_max to t...
Definition: detect-engine-siggroup.c:632
SigGroupHeadEqual
bool SigGroupHeadEqual(const SigGroupHead *sgha, const SigGroupHead *sghb)
Finds if two Signature Group Heads are the same.
Definition: detect-engine-siggroup.c:485
SigGroupHeadInitData_::sig_array
uint8_t * sig_array
Definition: detect.h:1423
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
Signature_::alproto
AppProto alproto
Definition: detect.h:601
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
SignatureNonPrefilterStore_::id
SigIntId id
Definition: detect.h:1072
DetectEngineCtx_::non_pf_store_cnt_max
uint32_t non_pf_store_cnt_max
Definition: detect.h:863
AddressDebugPrint
void AddressDebugPrint(Address *a)
Debug print function for printing addresses.
Definition: decode.c:752
UTHBuildPacketSrcDst
Packet * UTHBuildPacketSrcDst(uint8_t *payload, uint16_t payload_len, uint8_t ipproto, const char *src, const char *dst)
UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports.
Definition: util-unittest-helper.c:400
util-hash.h
SIG_GROUP_HEAD_HAVEFILESHA1
#define SIG_GROUP_HEAD_HAVEFILESHA1
Definition: detect.h:1328
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:839
DetectFlagsSignatureNeedsSynPackets
int DetectFlagsSignatureNeedsSynPackets(const Signature *s)
Definition: detect-tcp-flags.c:515
SigGroupHeadSetProtoAndDirection
void SigGroupHeadSetProtoAndDirection(SigGroupHead *sgh, uint8_t ipproto, int dir)
Definition: detect-engine-siggroup.c:502
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2533
SigPrepareStage1
int SigPrepareStage1(DetectEngineCtx *)
Preprocess signature, classify ip-only, etc, build sig array.
Definition: detect-engine-build.c:1721
SigGroupHeadPrintSigs
void SigGroupHeadPrintSigs(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Helper function used to print the list of sids for the Signatures present in this SigGroupHead.
Definition: detect-engine-siggroup.c:519
HashListTableLookup
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
Definition: util-hashlist.c:245
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2620
MAX
#define MAX(x, y)
Definition: suricata-common.h:395
SigGroupHeadSetupFiles
void SigGroupHeadSetupFiles(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Set the need hash flag in the sgh.
Definition: detect-engine-siggroup.c:589
SignatureIsFilesizeInspecting
int SignatureIsFilesizeInspecting(const Signature *s)
Check if a signature contains the filesize keyword.
Definition: detect-engine-build.c:185
SignatureNonPrefilterStore_
Definition: detect.h:1071
detect-engine-prefilter.h
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
SigGroupHeadRegisterTests
void SigGroupHeadRegisterTests(void)
Definition: detect-engine-siggroup.c:1089
HashListTableAdd
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
Definition: util-hashlist.c:114
SigGroupHeadHashInit
int SigGroupHeadHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the SigGroupHeads.
Definition: detect-engine-siggroup.c:257
HashListTable_::array_size
uint32_t array_size
Definition: util-hashlist.h:41
util-memcmp.h
DetectEngineCtx_::sgh_array_size
uint32_t sgh_array_size
Definition: detect.h:907
SigGroupHeadInitData_::pkt_mpms
MpmCtx ** pkt_mpms
Definition: detect.h:1432
SignatureIsFileSha256Inspecting
int SignatureIsFileSha256Inspecting(const Signature *s)
Check if a signature contains the filesha256 keyword.
Definition: detect-engine-build.c:169
Signature_::next
struct Signature_ * next
Definition: detect.h:668
util-cidr.h
HashListTableInit
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hashlist.c: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
SigGroupHeadBuildMatchArray
int SigGroupHeadBuildMatchArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh, uint32_t max_idx)
Create an array with all the internal ids of the sigs that this sig group head will check for.
Definition: detect-engine-siggroup.c:551
SigGroupHeadInitData_::sig_cnt
SigIntId sig_cnt
Definition: detect.h:1441
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
util-error.h
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectEngineThreadCtx_
Definition: detect.h:1095
SigGroupHeadInitData_::tx_engines
PrefilterEngineList * tx_engines
Definition: detect.h:1437
DetectEngineGetMaxSigId
#define DetectEngineGetMaxSigId(de_ctx)
Definition: detect-engine.h:105
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
SignatureNonPrefilterStore_::alproto
AppProto alproto
Definition: detect.h:1074
SigGroupHead_::init
SigGroupHeadInitData * init
Definition: detect.h:1471
SigGroupHeadInitData_::direction
uint32_t direction
Definition: detect.h:1427
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:300
PacketL4::L4Hdrs::icmpv4h
ICMPV4Hdr * icmpv4h
Definition: decode.h:458
SCReturn
#define SCReturn
Definition: util-debug.h:273
Signature_::flags
uint32_t flags
Definition: detect.h:597
ICMPV4Hdr_::type
uint8_t type
Definition: decode-icmpv4.h:166
Packet_
Definition: decode.h:488
SCFreeAligned
#define SCFreeAligned(p)
Definition: util-mem.h:77
detect-engine-build.h
Packet_::l4
struct PacketL4 l4
Definition: decode.h:590
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:287
SigGroupHeadInitData_::max_sig_id
uint32_t max_sig_id
Definition: detect.h:1429
DetectEngineCtx_::sgh_array_cnt
uint32_t sgh_array_cnt
Definition: detect.h:906
SigGroupHeadAppendSig
int SigGroupHeadAppendSig(const DetectEngineCtx *de_ctx, SigGroupHead **sgh, const Signature *s)
Add a Signature to a SigGroupHead.
Definition: detect-engine-siggroup.c:334
DetectEngineCtx_::sgh_array
struct SigGroupHead_ ** sgh_array
Definition: detect.h:905
HashListTable_
Definition: util-hashlist.h:37
SigGroupHeadFree
void SigGroupHeadFree(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Free a SigGroupHead and its members.
Definition: detect-engine-siggroup.c:162
SigGroupHeadInitData_::app_mpms
MpmCtx ** app_mpms
Definition: detect.h:1431
SignatureIsFileSha1Inspecting
int SignatureIsFileSha1Inspecting(const Signature *s)
Check if a signature contains the filesha1 keyword.
Definition: detect-engine-build.c:153
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2150
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:252
SigGroupHeadInitData_::pkt_engines
PrefilterEngineList * pkt_engines
Definition: detect.h:1435
SigGroupHeadSetSigCnt
void SigGroupHeadSetSigCnt(SigGroupHead *sgh, uint32_t max_idx)
Updates the SigGroupHead->sig_cnt with the total count of all the Signatures present in this SigGroup...
Definition: detect-engine-siggroup.c:461
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *, void *, void **)
initialize thread specific detection engine context
Definition: detect-engine.c:3244
SigGroupHead_::non_pf_other_store_array
SignatureNonPrefilterStore * non_pf_other_store_array
Definition: detect.h:1461
suricata-common.h
SigGroupHeadStore
void SigGroupHeadStore(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-siggroup.c:108
SigGroupHeadInitData_::frame_engines
PrefilterEngineList * frame_engines
Definition: detect.h:1438
SigGroupHeadInitData_::payload_engines
PrefilterEngineList * payload_engines
Definition: detect.h:1436
HashListTableFree
void HashListTableFree(HashListTable *ht)
Definition: util-hashlist.c:88
SigGroupHeadInitData_::match_array
Signature ** match_array
Definition: detect.h:1444
SigGroupHead_::non_pf_other_store_cnt
uint32_t non_pf_other_store_cnt
Definition: detect.h:1459
SCMallocAligned
#define SCMallocAligned(size, align)
Definition: util-mem.h:68
SigGroupHeadInitData_::sig_size
uint32_t sig_size
Definition: detect.h:1424
PrefilterCleanupRuleGroup
void PrefilterCleanupRuleGroup(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-prefilter.c:378
ICMPV4Hdr_::code
uint8_t code
Definition: decode-icmpv4.h:167
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:847
SigGroupHeadHashFree
void SigGroupHeadHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by SigGroupHeadHashInit() function.
Definition: detect-engine-siggroup.c:312
SigGroupHeadHashAdd
int SigGroupHeadHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Adds a SigGroupHead to the detection engine context SigGroupHead hash table.
Definition: detect-engine-siggroup.c:279
util-validate.h
SigGroupHeadInitData_
Definition: detect.h:1420
SigGroupHeadHashLookup
SigGroupHead * SigGroupHeadHashLookup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Used to lookup a SigGroupHead hash from the detection engine context SigGroupHead hash table.
Definition: detect-engine-siggroup.c:296
SignatureIsFilestoring
int SignatureIsFilestoring(const Signature *s)
Check if a signature contains the filestore keyword.
Definition: detect-engine-build.c:99
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Signature_::id
uint32_t id
Definition: detect.h:631
detect-parse.h
src
uint16_t src
Definition: app-layer-dnp3.h:5
Signature_
Signature container.
Definition: detect.h:596
SigGroupHeadInitDataFree
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid)
Definition: detect-engine-siggroup.c:60
SigGroupHeadContainsSigId
int SigGroupHeadContainsSigId(DetectEngineCtx *de_ctx, SigGroupHead *sgh, uint32_t sid)
Check if a SigGroupHead contains a Signature, whose sid is sent as an argument.
Definition: detect-engine-siggroup.c:717
SignatureIsFileMd5Inspecting
int SignatureIsFileMd5Inspecting(const Signature *s)
Check if a signature contains the filemd5 keyword.
Definition: detect-engine-build.c:137
PacketL4::hdrs
union PacketL4::L4Hdrs hdrs
SigGroupHeadInitData_::protos
uint8_t protos[256]
Definition: detect.h:1426
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2494
app-layer-protos.h
DetectEngineCtx_::sig_array
Signature ** sig_array
Definition: detect.h:856
Packet_::dst
Address dst
Definition: decode.h:493
SigGroupHead_::non_pf_syn_store_array
SignatureNonPrefilterStore * non_pf_syn_store_array
Definition: detect.h:1463
SignatureNonPrefilterStore_::mask
SignatureMask mask
Definition: detect.h:1073
detect-uricontent.h
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SIG_GROUP_HEAD_HAVEFILESHA256
#define SIG_GROUP_HEAD_HAVEFILESHA256
Definition: detect.h:1329
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:275
SignatureIsFilemagicInspecting
int SignatureIsFilemagicInspecting(const Signature *s)
Check if a signature contains the filemagic keyword.
Definition: detect-engine-build.c:118
SigGroupHead_::filestore_cnt
uint16_t filestore_cnt
Definition: detect.h:1454
flow-var.h
PrefilterFreeEnginesList
void PrefilterFreeEnginesList(PrefilterEngineList *list)
Definition: detect-engine-prefilter.c:350
SCMemcmp
#define SCMemcmp(a, b, c)
Definition: util-memcmp.h:290
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
SIG_FLAG_PREFILTER
#define SIG_FLAG_PREFILTER
Definition: detect.h:273
detect-engine-address.h
SigMatchSignaturesGetSgh
const SigGroupHead * SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx, const Packet *p)
Get the SigGroupHead for a packet.
Definition: detect.c:215
SigGroupHeadCopySigs
int SigGroupHeadCopySigs(DetectEngineCtx *de_ctx, SigGroupHead *src, SigGroupHead **dst)
Copies the bitarray holding the sids from the source SigGroupHead to the destination SigGroupHead.
Definition: detect-engine-siggroup.c:405
Signature_::mask
SignatureMask mask
Definition: detect.h:607
SigGroupHeadClearSigs
int SigGroupHeadClearSigs(SigGroupHead *)
Clears the bitarray holding the sids for this SigGroupHead.
Definition: detect-engine-siggroup.c:363
SigGroupHeadInitData_::frame_mpms
MpmCtx ** frame_mpms
Definition: detect.h:1433
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:450