suricata
detect-engine-build.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2025 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 #include "suricata-common.h"
19 #include "detect.h"
20 #include "detect-engine.h"
21 #include "detect-parse.h"
22 #include "detect-content.h"
23 
24 #include "detect-engine-build.h"
25 #include "detect-engine-address.h"
26 #include "detect-engine-analyzer.h"
27 #include "detect-engine-iponly.h"
28 #include "detect-engine-mpm.h"
29 #include "detect-engine-siggroup.h"
30 #include "detect-engine-port.h"
32 #include "detect-engine-proto.h"
34 
35 #include "detect-dsize.h"
36 #include "detect-tcp-flags.h"
37 #include "detect-flow.h"
38 #include "detect-config.h"
39 #include "detect-flowbits.h"
40 
41 #include "app-layer-events.h"
42 
44 #include "util-profiling.h"
45 #include "util-validate.h"
46 #include "util-var-name.h"
47 #include "util-conf.h"
48 
49 /* Magic numbers to make the rules of a certain order fall in the same group */
50 #define DETECT_PGSCORE_RULE_PORT_PRIORITIZED 111 /* Rule port group contains a priority port */
51 #define DETECT_PGSCORE_RULE_MPM_FAST_PATTERN 99 /* Rule contains an MPM fast pattern */
52 #define DETECT_PGSCORE_RULE_MPM_NEGATED 77 /* Rule contains a negated MPM */
53 #define DETECT_PGSCORE_RULE_NO_MPM 55 /* Rule does not contain MPM */
54 #define DETECT_PGSCORE_RULE_SYN_ONLY 33 /* Rule needs SYN check */
55 
57 {
58  if (de_ctx == NULL)
59  return;
60 
61  for (Signature *s = de_ctx->sig_list; s != NULL;) {
62  Signature *ns = s->next;
63  SigFree(de_ctx, s);
64  s = ns;
65  }
66  de_ctx->sig_list = NULL;
67 
69  de_ctx->sig_list = NULL;
70 }
71 
72 /** \brief Find a specific signature by sid and gid
73  * \param de_ctx detection engine ctx
74  * \param sid the signature id
75  * \param gid the signature group id
76  *
77  * \retval s sig found
78  * \retval NULL sig not found
79  */
81 {
82  if (de_ctx == NULL)
83  return NULL;
84 
85  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
86  if (s->id == sid && s->gid == gid)
87  return s;
88  }
89 
90  return NULL;
91 }
92 
93 /**
94  * \brief Check if a signature contains the filestore keyword.
95  *
96  * \param s signature
97  *
98  * \retval 0 no
99  * \retval 1 yes
100  */
102 {
103  if (s == NULL)
104  return 0;
105 
106  if (s->flags & SIG_FLAG_FILESTORE)
107  return 1;
108 
109  return 0;
110 }
111 
112 /**
113  * \brief Check if a signature contains the filemagic keyword.
114  *
115  * \param s signature
116  *
117  * \retval 0 no
118  * \retval 1 yes
119  */
121 {
122  if (s == NULL)
123  return 0;
124 
126  return 1;
127 
128  return 0;
129 }
130 
131 /**
132  * \brief Check if a signature contains the filemd5 keyword.
133  *
134  * \param s signature
135  *
136  * \retval 0 no
137  * \retval 1 yes
138  */
140 {
141  if ((s != NULL) && (s->file_flags & FILE_SIG_NEED_MD5))
142  return 1;
143 
144  return 0;
145 }
146 
147 /**
148  * \brief Check if a signature contains the filesha1 keyword.
149  *
150  * \param s signature
151  *
152  * \retval 0 no
153  * \retval 1 yes
154  */
156 {
157  if ((s != NULL) && (s->file_flags & FILE_SIG_NEED_SHA1))
158  return 1;
159 
160  return 0;
161 }
162 
163 /**
164  * \brief Check if a signature contains the filesha256 keyword.
165  *
166  * \param s signature
167  *
168  * \retval 0 no
169  * \retval 1 yes
170  */
172 {
173  if ((s != NULL) && (s->file_flags & FILE_SIG_NEED_SHA256))
174  return 1;
175 
176  return 0;
177 }
178 
179 static bool SignatureInspectsBuffers(const Signature *s)
180 {
181  return (s->init_data->buffer_index > 0);
182 }
183 
184 /** \brief Test is a initialized signature is IP only
185  * \param de_ctx detection engine ctx
186  * \param s the signature
187  * \retval 1 sig is ip only
188  * \retval 2 sig is like ip only
189  * \retval 0 sig is not ip only
190  */
192 {
193  /* explicit hook means no IP-only */
195  return 0;
196 
197  if (s->alproto != ALPROTO_UNKNOWN)
198  return 0;
199 
200  if (s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL)
201  return 0;
202 
203  // may happen for 'config' keyword, postmatch
204  if (s->flags & SIG_FLAG_APPLAYER)
205  return 0;
206 
207  /* if flow dir is set we can't process it in ip-only */
208  if (!(((s->flags & (SIG_FLAG_TOSERVER|SIG_FLAG_TOCLIENT)) == 0) ||
211  return 0;
212 
213  /* for now assume that all registered buffer types are incompatible */
214  if (SignatureInspectsBuffers(s)) {
215  SCReturnInt(0);
216  }
217 
218  /* TMATCH list can be ignored, it contains TAGs and
219  * tags are compatible to IP-only. */
220 
222  for (; sm != NULL; sm = sm->next) {
224  return 0;
225  /* we have enabled flowbits to be compatible with ip only sigs, as long
226  * as the sig only has a "set" flowbits */
227  if (sm->type == DETECT_FLOWBITS &&
228  (((DetectFlowbitsData *)sm->ctx)->cmd != DETECT_FLOWBITS_CMD_SET)) {
229  return 0;
230  }
231  }
233  for ( ; sm != NULL; sm = sm->next) {
235  return 0;
236  /* we have enabled flowbits to be compatible with ip only sigs, as long
237  * as the sig only has a "set" flowbits */
238  if (sm->type == DETECT_FLOWBITS &&
239  (((DetectFlowbitsData *)sm->ctx)->cmd != DETECT_FLOWBITS_CMD_SET) ) {
240  return 0;
241  }
242  }
243 
245  /* Rule is IP only, but contains negated addresses. */
246  return 2;
247  }
248  if (!(de_ctx->flags & DE_QUIET)) {
249  SCLogDebug("IP-ONLY (%" PRIu32 "): source %s, dest %s", s->id,
250  s->flags & SIG_FLAG_SRC_ANY ? "ANY" : "SET",
251  s->flags & SIG_FLAG_DST_ANY ? "ANY" : "SET");
252  }
253  return 1;
254 }
255 
256 /** \internal
257  * \brief Test is a initialized signature is inspecting protocol detection only
258  * \param de_ctx detection engine ctx
259  * \param s the signature
260  * \retval 1 sig is dp only
261  * \retval 0 sig is not dp only
262  */
263 static int SignatureIsPDOnly(const DetectEngineCtx *de_ctx, const Signature *s)
264 {
265  /* explicit hook means no PD-only */
267  return 0;
268 
269  if (s->alproto != ALPROTO_UNKNOWN)
270  return 0;
271 
272  if (s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL)
273  return 0;
274 
275  /* for now assume that all registered buffer types are incompatible */
276  if (SignatureInspectsBuffers(s)) {
277  SCReturnInt(0);
278  }
279 
280  /* TMATCH list can be ignored, it contains TAGs and
281  * tags are compatible to DP-only. */
282 
283  /* match list matches may be compatible to DP only. We follow the same
284  * logic as IP-only so we can use that flag */
285 
287  if (sm == NULL)
288  return 0;
289 
290  int pd = 0;
291  for ( ; sm != NULL; sm = sm->next) {
292  if (sm->type == DETECT_APP_LAYER_PROTOCOL) {
293  pd = 1;
294  } else {
295  /* flowbits are supported for dp only sigs, as long
296  * as the sig only has a "set" flowbits */
297  if (sm->type == DETECT_FLOWBITS) {
298  if ((((DetectFlowbitsData *)sm->ctx)->cmd != DETECT_FLOWBITS_CMD_SET) ) {
299  SCLogDebug("%u: not PD-only: flowbit settings other than 'set'", s->id);
300  return 0;
301  }
302  } else if (sm->type == DETECT_FLOW) {
304  SCLogDebug("%u: not PD-only: flow settings other than toserver/toclient", s->id);
305  return 0;
306  }
307  } else if ( !(sigmatch_table[sm->type].flags & SIGMATCH_IPONLY_COMPAT)) {
308  SCLogDebug("%u: not PD-only: %s not PD/IP-only compat", s->id, sigmatch_table[sm->type].name);
309  return 0;
310  }
311  }
312  }
313 
314  if (pd) {
315  SCLogDebug("PD-ONLY (%" PRIu32 ")", s->id);
316  }
317  return pd;
318 }
319 
320 /**
321  * \internal
322  * \brief Check if the initialized signature is inspecting the packet payload
323  * \param de_ctx detection engine ctx
324  * \param s the signature
325  * \retval 1 sig is inspecting the payload
326  * \retval 0 sig is not inspecting the payload
327  */
328 static int SignatureIsInspectingPayload(DetectEngineCtx *de_ctx, const Signature *s)
329 {
330 
331  if (s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL) {
332  return 1;
333  }
334  return 0;
335 }
336 
337 /**
338  * \internal
339  * \brief check if a signature is decoder event matching only
340  * \param de_ctx detection engine
341  * \param s the signature to test
342  * \retval 0 not a DEOnly sig
343  * \retval 1 DEOnly sig
344  */
345 static int SignatureIsDEOnly(DetectEngineCtx *de_ctx, const Signature *s)
346 {
347  /* explicit hook means no DE-only */
349  SCReturnInt(0);
350 
351  if (s->alproto != ALPROTO_UNKNOWN) {
352  SCReturnInt(0);
353  }
354 
355  if (s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL)
356  {
357  SCReturnInt(0);
358  }
359 
360  /* for now assume that all registered buffer types are incompatible */
361  if (SignatureInspectsBuffers(s)) {
362  SCReturnInt(0);
363  }
364 
365  /* check for conflicting keywords */
367  for ( ;sm != NULL; sm = sm->next) {
369  SCReturnInt(0);
370  }
371 
372  /* need at least one decode event keyword to be considered decode event. */
374  for ( ;sm != NULL; sm = sm->next) {
375  if (sm->type == DETECT_DECODE_EVENT)
376  goto deonly;
377  if (sm->type == DETECT_ENGINE_EVENT)
378  goto deonly;
379  if (sm->type == DETECT_STREAM_EVENT)
380  goto deonly;
381  }
382 
383  SCReturnInt(0);
384 
385 deonly:
386  if (!(de_ctx->flags & DE_QUIET)) {
387  SCLogDebug("DE-ONLY (%" PRIu32 "): source %s, dest %s", s->id,
388  s->flags & SIG_FLAG_SRC_ANY ? "ANY" : "SET",
389  s->flags & SIG_FLAG_DST_ANY ? "ANY" : "SET");
390  }
391 
392  SCReturnInt(1);
393 }
394 
395 #define MASK_TCP_INITDEINIT_FLAGS (TH_SYN|TH_RST|TH_FIN)
396 #define MASK_TCP_UNUSUAL_FLAGS (TH_URG|TH_ECN|TH_CWR)
397 
398 /* Create mask for this packet + it's flow if it has one
399  */
400 void
402  bool app_decoder_events)
403 {
404  if (!(PKT_IS_PSEUDOPKT(p))) {
405  (*mask) |= SIG_MASK_REQUIRE_REAL_PKT;
406  }
407  if (!(p->flags & PKT_NOPAYLOAD_INSPECTION) && p->payload_len > 0) {
408  SCLogDebug("packet has payload");
409  (*mask) |= SIG_MASK_REQUIRE_PAYLOAD;
410  } else if (p->flags & PKT_DETECT_HAS_STREAMDATA) {
411  SCLogDebug("stream data available");
412  (*mask) |= SIG_MASK_REQUIRE_PAYLOAD;
413  } else {
414  SCLogDebug("packet has no payload");
415  (*mask) |= SIG_MASK_REQUIRE_NO_PAYLOAD;
416  }
417 
418  if (p->events.cnt > 0 || app_decoder_events != 0 ||
419  (p->app_layer_events != NULL && p->app_layer_events->cnt)) {
420  SCLogDebug("packet/flow has events set");
422  }
423 
424  if (!(PKT_IS_PSEUDOPKT(p)) && PacketIsTCP(p)) {
425  const TCPHdr *tcph = PacketGetTCP(p);
426  if ((tcph->th_flags & MASK_TCP_INITDEINIT_FLAGS) != 0) {
428  }
429  if ((tcph->th_flags & MASK_TCP_UNUSUAL_FLAGS) != 0) {
431  }
432  }
433 
434  if (p->flags & PKT_HAS_FLOW) {
435  SCLogDebug("packet has flow");
436  (*mask) |= SIG_MASK_REQUIRE_FLOW;
437  }
438 }
439 
440 static int SignatureCreateMask(Signature *s)
441 {
442  SCEnter();
443 
447  }
448  if (s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL) {
450  SCLogDebug("sig requires payload");
451  }
452 
453  SigMatch *sm;
454  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH] ; sm != NULL; sm = sm->next) {
455  switch(sm->type) {
456  case DETECT_FLOWBITS:
457  {
458  /* figure out what flowbit action */
460  if (fb->cmd == DETECT_FLOWBITS_CMD_ISSET) {
461  /* not a mask flag, but still set it here */
463 
464  SCLogDebug("SIG_FLAG_REQUIRE_FLOWVAR set as sig has "
465  "flowbit isset option.");
466  }
467 
468  /* flow is required for any flowbit manipulation */
470  SCLogDebug("sig requires flow to be able to manipulate "
471  "flowbit(s)");
472  break;
473  }
474  case DETECT_FLOWINT:
475  /* flow is required for any flowint manipulation */
477  SCLogDebug("sig requires flow to be able to manipulate "
478  "flowint(s)");
479  break;
480  case DETECT_FLAGS:
481  {
482  DetectFlagsData *fl = (DetectFlagsData *)sm->ctx;
483 
484  if (fl->flags & MASK_TCP_INITDEINIT_FLAGS) {
486  SCLogDebug("sig requires SIG_MASK_REQUIRE_FLAGS_INITDEINIT");
487  }
488  if (fl->flags & MASK_TCP_UNUSUAL_FLAGS) {
490  SCLogDebug("sig requires SIG_MASK_REQUIRE_FLAGS_UNUSUAL");
491  }
492  break;
493  }
494  case DETECT_DSIZE:
495  {
496  DetectU16Data *ds = (DetectU16Data *)sm->ctx;
497  /* LT will include 0, so no payload.
498  * if GT is used in the same rule the
499  * flag will be set anyway. */
500  if (ds->mode == DETECT_UINT_RA || ds->mode == DETECT_UINT_GT ||
501  ds->mode == DETECT_UINT_NE || ds->mode == DETECT_UINT_GTE) {
502 
504  SCLogDebug("sig requires payload");
505 
506  } else if (ds->mode == DETECT_UINT_EQ) {
507  if (ds->arg1 > 0) {
509  SCLogDebug("sig requires payload");
510  } else {
512  SCLogDebug("sig requires no payload");
513  }
514  }
515  break;
516  }
517  case DETECT_DECODE_EVENT:
518  // fallthrough
519  case DETECT_STREAM_EVENT:
520  // fallthrough
522  // fallthrough
523  case DETECT_ENGINE_EVENT:
525  break;
526  }
527  }
528 
529  for (sm = s->init_data->smlists[DETECT_SM_LIST_POSTMATCH]; sm != NULL; sm = sm->next) {
530  switch (sm->type) {
531  case DETECT_CONFIG: {
533  if (fd->scope == CONFIG_SCOPE_FLOW) {
535  }
536  break;
537  }
538  }
539  }
540 
543  SCLogDebug("sig requires flow");
544  }
545 
546  if (s->flags & SIG_FLAG_APPLAYER) {
548  SCLogDebug("sig requires flow");
549  }
550 
551  SCLogDebug("mask %02X", s->mask);
552  SCReturnInt(0);
553 }
554 
555 static void SigInitStandardMpmFactoryContexts(DetectEngineCtx *de_ctx)
556 {
558 }
559 
560 /** \brief Pure-PCRE or bytetest rule */
561 static bool RuleInspectsPayloadHasNoMpm(const Signature *s)
562 {
563  if (s->init_data->mpm_sm == NULL && s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL)
564  return true;
565  return false;
566 }
567 
568 static int RuleGetMpmPatternSize(const Signature *s)
569 {
570  if (s->init_data->mpm_sm == NULL)
571  return -1;
572  int mpm_list = s->init_data->mpm_sm_list;
573  if (mpm_list < 0)
574  return -1;
575  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
576  if (cd == NULL)
577  return -1;
578  return (int)cd->content_len;
579 }
580 
581 static bool RuleMpmIsNegated(const Signature *s)
582 {
583  if (s->flags & SIG_FLAG_MPM_NEG)
584  return true;
585  if (s->init_data->mpm_sm == NULL)
586  return false;
587  int mpm_list = s->init_data->mpm_sm_list;
588  if (mpm_list < 0)
589  return false;
590  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
591  if (cd == NULL)
592  return false;
593  return (cd->flags & DETECT_CONTENT_NEGATED) ? true : false;
594 }
595 
596 static SCJsonBuilder *RulesGroupPrintSghStats(const DetectEngineCtx *de_ctx,
597  const SigGroupHead *sgh, const int add_rules, const int add_mpm_stats)
598 {
599  uint32_t prefilter_cnt = 0;
600  uint32_t mpm_cnt = 0;
601  uint32_t nonmpm_cnt = 0;
602  uint32_t mpm_depth_cnt = 0;
603  uint32_t mpm_endswith_cnt = 0;
604  uint32_t negmpm_cnt = 0;
605  uint32_t any5_cnt = 0;
606  uint32_t payload_no_mpm_cnt = 0;
607  uint32_t syn_cnt = 0;
608 
609  uint32_t mpms_min = 0;
610  uint32_t mpms_max = 0;
611 
612  int max_buffer_type_id = de_ctx->buffer_type_id;
613 
614  struct {
615  uint32_t total;
616  uint32_t cnt;
617  uint32_t min;
618  uint32_t max;
619  } mpm_stats[max_buffer_type_id];
620  memset(mpm_stats, 0x00, sizeof(mpm_stats));
621 
622  uint32_t alstats[g_alproto_max];
623  memset(alstats, 0, g_alproto_max * sizeof(uint32_t));
624  uint32_t mpm_sizes[max_buffer_type_id][256];
625  memset(mpm_sizes, 0, sizeof(mpm_sizes));
626  uint32_t alproto_mpm_bufs[g_alproto_max][max_buffer_type_id];
627  memset(alproto_mpm_bufs, 0, sizeof(alproto_mpm_bufs));
628 
629  DEBUG_VALIDATE_BUG_ON(sgh->init == NULL);
630  if (sgh->init == NULL)
631  return NULL;
632 
633  SCJsonBuilder *js = SCJbNewObject();
634  if (unlikely(js == NULL))
635  return NULL;
636 
637  SCJbSetUint(js, "id", sgh->id);
638 
639  SCJbOpenArray(js, "rules");
640  for (uint32_t x = 0; x < sgh->init->sig_cnt; x++) {
641  const Signature *s = sgh->init->match_array[x];
642  if (s == NULL)
643  continue;
644 
645  int any = 0;
646  if (s->proto.flags & DETECT_PROTO_ANY) {
647  any++;
648  }
649  if (s->flags & SIG_FLAG_DST_ANY) {
650  any++;
651  }
652  if (s->flags & SIG_FLAG_SRC_ANY) {
653  any++;
654  }
655  if (s->flags & SIG_FLAG_DP_ANY) {
656  any++;
657  }
658  if (s->flags & SIG_FLAG_SP_ANY) {
659  any++;
660  }
661  if (any == 5) {
662  any5_cnt++;
663  }
664 
665  prefilter_cnt += (s->init_data->prefilter_sm != NULL);
666  if (s->init_data->mpm_sm == NULL) {
667  nonmpm_cnt++;
668 
669  if (s->sm_arrays[DETECT_SM_LIST_MATCH] != NULL) {
670  SCLogDebug("SGH %p Non-MPM inspecting only packets. Rule %u", sgh, s->id);
671  }
672 
673  DetectPort *sp = s->sp;
674  DetectPort *dp = s->dp;
675 
676  if (s->flags & SIG_FLAG_TOSERVER && (dp->port == 0 && dp->port2 == 65535)) {
677  SCLogDebug("SGH %p Non-MPM toserver and to 'any'. Rule %u", sgh, s->id);
678  }
679  if (s->flags & SIG_FLAG_TOCLIENT && (sp->port == 0 && sp->port2 == 65535)) {
680  SCLogDebug("SGH %p Non-MPM toclient and to 'any'. Rule %u", sgh, s->id);
681  }
682 
684  syn_cnt++;
685  }
686 
687  } else {
688  int mpm_list = s->init_data->mpm_sm_list;
689  BUG_ON(mpm_list < 0);
690  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
691  uint32_t size = cd->content_len < 256 ? cd->content_len : 255;
692 
693  mpm_sizes[mpm_list][size]++;
694  alproto_mpm_bufs[s->alproto][mpm_list]++;
695 
696  if (mpm_list == DETECT_SM_LIST_PMATCH) {
697  if (size == 1) {
698  DetectPort *sp = s->sp;
699  DetectPort *dp = s->dp;
700  if (s->flags & SIG_FLAG_TOSERVER) {
701  if (dp->port == 0 && dp->port2 == 65535) {
702  SCLogDebug("SGH %p toserver 1byte fast_pattern to ANY. Rule %u", sgh, s->id);
703  } else {
704  SCLogDebug("SGH %p toserver 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, dp->port, dp->port2, s->id);
705  }
706  }
707  if (s->flags & SIG_FLAG_TOCLIENT) {
708  if (sp->port == 0 && sp->port2 == 65535) {
709  SCLogDebug("SGH %p toclient 1byte fast_pattern to ANY. Rule %u", sgh, s->id);
710  } else {
711  SCLogDebug("SGH %p toclient 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, sp->port, sp->port2, s->id);
712  }
713  }
714  }
715  }
716 
717  uint32_t w = PatternStrength(cd->content, cd->content_len);
718  if (mpms_min == 0)
719  mpms_min = w;
720  if (w < mpms_min)
721  mpms_min = w;
722  if (w > mpms_max)
723  mpms_max = w;
724 
725  BUG_ON(mpm_list >= max_buffer_type_id);
726  mpm_stats[mpm_list].total += w;
727  mpm_stats[mpm_list].cnt++;
728  if (mpm_stats[mpm_list].min == 0 || w < mpm_stats[mpm_list].min)
729  mpm_stats[mpm_list].min = w;
730  if (w > mpm_stats[mpm_list].max)
731  mpm_stats[mpm_list].max = w;
732 
733  mpm_cnt++;
734 
735  if (w < 10) {
736  SCLogDebug("SGH %p Weak MPM Pattern on %s. Rule %u", sgh, DetectListToString(mpm_list), s->id);
737  }
738  if (w < 10 && any == 5) {
739  SCLogDebug("SGH %p Weak MPM Pattern on %s, rule is 5xAny. Rule %u", sgh, DetectListToString(mpm_list), s->id);
740  }
741 
742  if (cd->flags & DETECT_CONTENT_NEGATED) {
743  SCLogDebug("SGH %p MPM Pattern on %s, is negated. Rule %u", sgh, DetectListToString(mpm_list), s->id);
744  negmpm_cnt++;
745  }
746  if (cd->flags & DETECT_CONTENT_ENDS_WITH) {
747  mpm_endswith_cnt++;
748  }
749  if (cd->flags & DETECT_CONTENT_DEPTH) {
750  mpm_depth_cnt++;
751  }
752  }
753 
754  if (RuleInspectsPayloadHasNoMpm(s)) {
755  SCLogDebug("SGH %p No MPM. Payload inspecting. Rule %u", sgh, s->id);
756  payload_no_mpm_cnt++;
757  }
758 
759  alstats[s->alproto]++;
760 
761  if (add_rules) {
762  SCJsonBuilder *e = SCJbNewObject();
763  if (e != NULL) {
764  SCJbSetUint(e, "sig_id", s->id);
765  SCJbClose(e);
766  SCJbAppendObject(js, e);
767  SCJbFree(e);
768  }
769  }
770  }
771  SCJbClose(js);
772 
773  SCJbOpenObject(js, "stats");
774  SCJbSetUint(js, "total", sgh->init->sig_cnt);
775 
776  SCJbOpenObject(js, "types");
777  SCJbSetUint(js, "mpm", mpm_cnt);
778  SCJbSetUint(js, "non_mpm", nonmpm_cnt);
779  SCJbSetUint(js, "mpm_depth", mpm_depth_cnt);
780  SCJbSetUint(js, "mpm_endswith", mpm_endswith_cnt);
781  SCJbSetUint(js, "negated_mpm", negmpm_cnt);
782  SCJbSetUint(js, "payload_but_no_mpm", payload_no_mpm_cnt);
783  SCJbSetUint(js, "prefilter", prefilter_cnt);
784  SCJbSetUint(js, "syn", syn_cnt);
785  SCJbSetUint(js, "any5", any5_cnt);
786  SCJbClose(js);
787 
788  for (AppProto i = 0; i < g_alproto_max; i++) {
789  if (alstats[i] > 0) {
790  const char *proto_name = (i == ALPROTO_UNKNOWN) ? "payload" : AppProtoToString(i);
791  SCJbOpenObject(js, proto_name);
792  SCJbSetUint(js, "total", alstats[i]);
793 
794  for (int y = 0; y < max_buffer_type_id; y++) {
795  if (alproto_mpm_bufs[i][y] == 0)
796  continue;
797 
798  const char *name;
801  else
803 
804  SCJbSetUint(js, name, alproto_mpm_bufs[i][y]);
805  }
806  SCJbClose(js);
807  }
808  }
809 
810  if (add_mpm_stats) {
811  SCJbOpenObject(js, "mpm");
812 
813  for (int i = 0; i < max_buffer_type_id; i++) {
814  if (mpm_stats[i].cnt > 0) {
815  const char *name;
818  else
820 
821  SCJbOpenArray(js, name);
822 
823  for (int y = 0; y < 256; y++) {
824  if (mpm_sizes[i][y] == 0)
825  continue;
826 
827  SCJsonBuilder *e = SCJbNewObject();
828  if (e != NULL) {
829  SCJbSetUint(e, "size", y);
830  SCJbSetUint(e, "count", mpm_sizes[i][y]);
831  SCJbClose(e);
832  SCJbAppendObject(js, e);
833  SCJbFree(e);
834  }
835  }
836 
837  SCJsonBuilder *e = SCJbNewObject();
838  if (e != NULL) {
839  SCJbSetUint(e, "total", mpm_stats[i].cnt);
840  SCJbSetUint(e, "avg_strength", mpm_stats[i].total / mpm_stats[i].cnt);
841  SCJbSetUint(e, "min_strength", mpm_stats[i].min);
842  SCJbSetUint(e, "max_strength", mpm_stats[i].max);
843  SCJbClose(e);
844  SCJbAppendObject(js, e);
845  SCJbFree(e);
846  }
847 
848  SCJbClose(js);
849  }
850  }
851  SCJbClose(js);
852  }
853  SCJbClose(js);
854 
855  SCJbSetUint(js, "score", sgh->init->score);
856  SCJbClose(js);
857 
858  return js;
859 }
860 
861 static void RulesDumpGrouping(const DetectEngineCtx *de_ctx,
862  const int add_rules, const int add_mpm_stats)
863 {
864  SCJsonBuilder *js = SCJbNewObject();
865  if (unlikely(js == NULL))
866  return;
867 
868  for (int p = 0; p < 256; p++) {
869  if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
870  const char *name = (p == IPPROTO_TCP) ? "tcp" : "udp";
871 
872  SCJbOpenObject(js, name);
873  SCJbOpenArray(js, "toserver");
874  const DetectPort *list =
875  (p == IPPROTO_TCP) ? de_ctx->flow_gh[1].tcp : de_ctx->flow_gh[1].udp;
876  while (list != NULL) {
877  SCJsonBuilder *port = SCJbNewObject();
878  SCJbSetUint(port, "port", list->port);
879  SCJbSetUint(port, "port2", list->port2);
880 
881  SCJsonBuilder *stats =
882  RulesGroupPrintSghStats(de_ctx, list->sh, add_rules, add_mpm_stats);
883  SCJbSetObject(port, "rulegroup", stats);
884  SCJbFree(stats);
885  SCJbClose(port);
886  SCJbAppendObject(js, port);
887  SCJbFree(port);
888 
889  list = list->next;
890  }
891  SCJbClose(js); // toserver array
892 
893  SCJbOpenArray(js, "toclient");
894  list = (p == IPPROTO_TCP) ? de_ctx->flow_gh[0].tcp :
895  de_ctx->flow_gh[0].udp;
896  while (list != NULL) {
897  SCJsonBuilder *port = SCJbNewObject();
898  SCJbSetUint(port, "port", list->port);
899  SCJbSetUint(port, "port2", list->port2);
900 
901  SCJsonBuilder *stats =
902  RulesGroupPrintSghStats(de_ctx, list->sh, add_rules, add_mpm_stats);
903  SCJbSetObject(port, "rulegroup", stats);
904  SCJbFree(stats);
905  SCJbClose(port);
906  SCJbAppendObject(js, port);
907  SCJbFree(port);
908 
909  list = list->next;
910  }
911  SCJbClose(js); // toclient array
912  SCJbClose(js);
913  } else if (p == IPPROTO_ICMP || p == IPPROTO_ICMPV6) {
914  const char *name = (p == IPPROTO_ICMP) ? "icmpv4" : "icmpv6";
915  SCJbOpenObject(js, name);
916  if (de_ctx->flow_gh[1].sgh[p]) {
917  SCJbOpenObject(js, "toserver");
918  SCJsonBuilder *stats = RulesGroupPrintSghStats(
919  de_ctx, de_ctx->flow_gh[1].sgh[p], add_rules, add_mpm_stats);
920  SCJbSetObject(js, "rulegroup", stats);
921  SCJbFree(stats);
922  SCJbClose(js);
923  }
924  if (de_ctx->flow_gh[0].sgh[p]) {
925  SCJbOpenObject(js, "toclient");
926  SCJsonBuilder *stats = RulesGroupPrintSghStats(
927  de_ctx, de_ctx->flow_gh[0].sgh[p], add_rules, add_mpm_stats);
928  SCJbSetObject(js, "rulegroup", stats);
929  SCJbFree(stats);
930  SCJbClose(js);
931  }
932  SCJbClose(js);
933  }
934  }
935  SCJbClose(js);
936 
937  const char *filename = "rule_group.json";
938  const char *log_dir = SCConfigGetLogDirectory();
939  char log_path[PATH_MAX] = "";
940  snprintf(log_path, sizeof(log_path), "%s/%s", log_dir, filename);
941 
942  FILE *fp = fopen(log_path, "w");
943  if (fp != NULL) {
944  fwrite(SCJbPtr(js), SCJbLen(js), 1, fp);
945  (void)fclose(fp);
946  }
947  SCJbFree(js);
948 }
949 
950 static int RulesGroupByIPProto(DetectEngineCtx *de_ctx)
951 {
952  Signature *s = de_ctx->sig_list;
953 
954  SigGroupHead *sgh_ts[256] = {NULL};
955  SigGroupHead *sgh_tc[256] = {NULL};
956 
957  for ( ; s != NULL; s = s->next) {
958  if (s->type == SIG_TYPE_IPONLY)
959  continue;
960 
961  /* traverse over IP protocol list from libc */
962  for (int p = 0; p < 256; p++) {
963  if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
964  continue;
965  }
966  if (!(s->proto.proto[p / 8] & (1<<(p % 8)) || (s->proto.flags & DETECT_PROTO_ANY))) {
967  continue;
968  }
969 
970  /* Signatures that are ICMP, SCTP, not IP only are handled here */
971  if (s->flags & SIG_FLAG_TOCLIENT) {
972  SigGroupHeadAppendSig(de_ctx, &sgh_tc[p], s);
973  }
974  if (s->flags & SIG_FLAG_TOSERVER) {
975  SigGroupHeadAppendSig(de_ctx, &sgh_ts[p], s);
976  }
977  }
978  }
979 
980  /* lets look at deduplicating this list */
983 
984  uint32_t cnt = 0;
985  uint32_t own = 0;
986  uint32_t ref = 0;
987  int p;
988  for (p = 0; p < 256; p++) {
989  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
990  continue;
991  if (sgh_ts[p] == NULL)
992  continue;
993 
994  cnt++;
995 
996  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, sgh_ts[p]);
997  if (lookup_sgh == NULL) {
998  SCLogDebug("proto group %d sgh %p is the original", p, sgh_ts[p]);
999 
1000  SigGroupHeadSetSigCnt(sgh_ts[p], 0);
1001  SigGroupHeadBuildMatchArray(de_ctx, sgh_ts[p], 0);
1002 
1003  SigGroupHeadHashAdd(de_ctx, sgh_ts[p]);
1004  SigGroupHeadStore(de_ctx, sgh_ts[p]);
1005  own++;
1006  } else {
1007  SCLogDebug("proto group %d sgh %p is a copy", p, sgh_ts[p]);
1008 
1009  SigGroupHeadFree(de_ctx, sgh_ts[p]);
1010  sgh_ts[p] = lookup_sgh;
1011  ref++;
1012  }
1013  }
1014  SCLogPerf("OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1015  "toserver", cnt, own, ref);
1016 
1017  cnt = 0;
1018  own = 0;
1019  ref = 0;
1020  for (p = 0; p < 256; p++) {
1021  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1022  continue;
1023  if (sgh_tc[p] == NULL)
1024  continue;
1025 
1026  cnt++;
1027 
1028  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, sgh_tc[p]);
1029  if (lookup_sgh == NULL) {
1030  SCLogDebug("proto group %d sgh %p is the original", p, sgh_tc[p]);
1031 
1032  SigGroupHeadSetSigCnt(sgh_tc[p], 0);
1033  SigGroupHeadBuildMatchArray(de_ctx, sgh_tc[p], 0);
1034 
1035  SigGroupHeadHashAdd(de_ctx, sgh_tc[p]);
1036  SigGroupHeadStore(de_ctx, sgh_tc[p]);
1037  own++;
1038 
1039  } else {
1040  SCLogDebug("proto group %d sgh %p is a copy", p, sgh_tc[p]);
1041 
1042  SigGroupHeadFree(de_ctx, sgh_tc[p]);
1043  sgh_tc[p] = lookup_sgh;
1044  ref++;
1045  }
1046  }
1047  SCLogPerf("OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1048  "toclient", cnt, own, ref);
1049 
1050  for (p = 0; p < 256; p++) {
1051  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1052  continue;
1053 
1054  de_ctx->flow_gh[0].sgh[p] = sgh_tc[p];
1055  de_ctx->flow_gh[1].sgh[p] = sgh_ts[p];
1056  }
1057 
1058  return 0;
1059 }
1060 
1061 static int PortIsPriority(const DetectEngineCtx *de_ctx, const DetectPort *a, int ipproto)
1062 {
1064  if (ipproto == IPPROTO_UDP)
1066 
1067  while (w) {
1068  /* Make sure the priority port falls in the port range of a */
1069  DEBUG_VALIDATE_BUG_ON(a->port > a->port2);
1070  if (a->port == w->port && w->port2 == a->port2) {
1071  return 1;
1072  }
1073  w = w->next;
1074  }
1075 
1076  return 0;
1077 }
1078 
1079 static int RuleSetScore(Signature *s)
1080 {
1081  DetectPort *p = NULL;
1082  if (s->flags & SIG_FLAG_TOSERVER)
1083  p = s->dp;
1084  else if (s->flags & SIG_FLAG_TOCLIENT)
1085  p = s->sp;
1086  else
1087  return 0;
1088 
1089  /* for sigs that don't use 'any' as port, see if we want to
1090  * prioritize poor sigs */
1091  int wl = 0;
1092  if (!(p->port == 0 && p->port2 == 65535)) {
1093  /* pure pcre, bytetest, etc rules */
1094  if (RuleInspectsPayloadHasNoMpm(s)) {
1095  SCLogDebug("Rule %u MPM has 1 byte fast_pattern. Prioritizing SGH's.", s->id);
1097 
1098  } else if (RuleMpmIsNegated(s)) {
1099  SCLogDebug("Rule %u MPM is negated. Prioritizing SGH's.", s->id);
1101 
1102  /* one byte pattern in packet/stream payloads */
1103  } else if (s->init_data->mpm_sm != NULL &&
1105  RuleGetMpmPatternSize(s) == 1) {
1106  SCLogDebug("Rule %u No MPM. Payload inspecting. Prioritizing SGH's.", s->id);
1108 
1110  SCLogDebug("Rule %u Needs SYN, so inspected often. Prioritizing SGH's.", s->id);
1112  }
1113  }
1114 
1115  s->init_data->score = wl;
1116  return wl;
1117 }
1118 
1119 static int SortCompare(const void *a, const void *b)
1120 {
1121  const DetectPort *pa = *(const DetectPort **)a;
1122  const DetectPort *pb = *(const DetectPort **)b;
1123 
1124  if (pa->sh->init->score < pb->sh->init->score) {
1125  return 1;
1126  } else if (pa->sh->init->score > pb->sh->init->score) {
1127  return -1;
1128  }
1129 
1130  if (pa->sh->init->sig_cnt < pb->sh->init->sig_cnt) {
1131  return 1;
1132  } else if (pa->sh->init->sig_cnt > pb->sh->init->sig_cnt) {
1133  return -1;
1134  }
1135 
1136  /* Hack to make the qsort output deterministic across platforms.
1137  * This had to be done because the order of equal elements sorted
1138  * by qsort is undeterministic and showed different output on BSD,
1139  * MacOS and Windows. Sorting based on id makes it deterministic. */
1140  if (pa->sh->id < pb->sh->id)
1141  return -1;
1142 
1143  return 1;
1144 }
1145 
1146 static inline void SortGroupList(
1147  uint32_t *groups, DetectPort **list, int (*CompareFunc)(const void *, const void *))
1148 {
1149  int cnt = 0;
1150  for (DetectPort *x = *list; x != NULL; x = x->next) {
1151  DEBUG_VALIDATE_BUG_ON(x->port > x->port2);
1152  cnt++;
1153  }
1154  if (cnt <= 1)
1155  return;
1156 
1157  /* build temporary array to sort with qsort */
1158  DetectPort **array = (DetectPort **)SCCalloc(cnt, sizeof(DetectPort *));
1159  if (array == NULL)
1160  return;
1161 
1162  int idx = 0;
1163  for (DetectPort *x = *list; x != NULL;) {
1164  /* assign a temporary id to resolve otherwise equal groups */
1165  x->sh->id = idx + 1;
1166  SigGroupHeadSetSigCnt(x->sh, 0);
1167  DetectPort *next = x->next;
1168  x->next = x->prev = x->last = NULL;
1169  DEBUG_VALIDATE_BUG_ON(x->port > x->port2);
1170  array[idx++] = x;
1171  x = next;
1172  }
1173  DEBUG_VALIDATE_BUG_ON(cnt != idx);
1174 
1175  qsort(array, idx, sizeof(DetectPort *), SortCompare);
1176 
1177  /* rebuild the list based on the qsort-ed array */
1178  DetectPort *new_list = NULL, *tail = NULL;
1179  for (int i = 0; i < idx; i++) {
1180  DetectPort *p = array[i];
1181  /* unset temporary group id */
1182  p->sh->id = 0;
1183 
1184  if (new_list == NULL) {
1185  new_list = p;
1186  }
1187  if (tail != NULL) {
1188  tail->next = p;
1189  }
1190  p->prev = tail;
1191  tail = p;
1192  }
1193 
1194  *list = new_list;
1195  *groups = idx;
1196 
1197 #if DEBUG
1198  int dbgcnt = 0;
1199  SCLogDebug("SORTED LIST:");
1200  for (DetectPort *tmp = *list; tmp != NULL; tmp = tmp->next) {
1201  SCLogDebug("item:= [%u:%u]; score: %d; sig_cnt: %d", tmp->port, tmp->port2,
1202  tmp->sh->init->score, tmp->sh->init->sig_cnt);
1203  dbgcnt++;
1204  BUG_ON(dbgcnt > cnt);
1205  }
1206 #endif
1207  SCFree(array);
1208 }
1209 /** \internal
1210  * \brief Create a list of DetectPort objects sorted based on CompareFunc's
1211  * logic.
1212  *
1213  * List can limit the number of groups. In this case an extra "join" group
1214  * is created that contains the sigs belonging to that. It's *appended* to
1215  * the list, meaning that if the list is walked linearly it's found last.
1216  * The joingr is meant to be a catch all.
1217  *
1218  */
1219 static int CreateGroupedPortList(DetectEngineCtx *de_ctx, DetectPort *port_list,
1220  DetectPort **newhead, uint32_t unique_groups,
1221  int (*CompareFunc)(const void *, const void *))
1222 {
1223  DetectPort *tmplist = NULL, *joingr = NULL;
1224  uint32_t groups = 0;
1225 
1226  /* insert the ports into the tmplist, where it will
1227  * be sorted descending on 'cnt' and on whether a group
1228  * is prioritized. */
1229  tmplist = port_list;
1230  SortGroupList(&groups, &tmplist, SortCompare);
1231  uint32_t left = unique_groups;
1232  if (left == 0)
1233  left = groups;
1234 
1235  /* create another list: take the port groups from above
1236  * and add them to the 2nd list until we have met our
1237  * count. The rest is added to the 'join' group. */
1238  DetectPort *tmplist2 = NULL, *tmplist2_tail = NULL;
1239  DetectPort *gr, *next_gr;
1240  for (gr = tmplist; gr != NULL;) {
1241  next_gr = gr->next;
1242 
1243  SCLogDebug("temp list gr %p %u:%u", gr, gr->port, gr->port2);
1244  DetectPortPrint(gr);
1245 
1246  /* if we've set up all the unique groups, add the rest to the
1247  * catch-all joingr */
1248  if (left == 0) {
1249  if (joingr == NULL) {
1250  DetectPortParse(de_ctx, &joingr, "0:65535");
1251  if (joingr == NULL) {
1252  goto error;
1253  }
1254  SCLogDebug("joingr => %u-%u", joingr->port, joingr->port2);
1255  joingr->next = NULL;
1256  }
1257  SigGroupHeadCopySigs(de_ctx, gr->sh, &joingr->sh);
1258 
1259  /* when a group's sigs are added to the joingr, we can free it */
1260  gr->next = NULL;
1261  DetectPortFree(de_ctx, gr);
1262  /* append */
1263  } else {
1264  gr->next = NULL;
1265 
1266  if (tmplist2 == NULL) {
1267  tmplist2 = gr;
1268  tmplist2_tail = gr;
1269  } else {
1270  tmplist2_tail->next = gr;
1271  tmplist2_tail = gr;
1272  }
1273  }
1274 
1275  if (left > 0)
1276  left--;
1277 
1278  gr = next_gr;
1279  }
1280 
1281  /* if present, append the joingr that covers the rest */
1282  if (joingr != NULL) {
1283  SCLogDebug("appending joingr %p %u:%u", joingr, joingr->port, joingr->port2);
1284 
1285  if (tmplist2 == NULL) {
1286  tmplist2 = joingr;
1287  // tmplist2_tail = joingr;
1288  } else {
1289  tmplist2_tail->next = joingr;
1290  // tmplist2_tail = joingr;
1291  }
1292  } else {
1293  SCLogDebug("no joingr");
1294  }
1295 
1296  /* pass back our new list to the caller */
1297  *newhead = tmplist2;
1298  DetectPortPrintList(*newhead);
1299 
1300  return 0;
1301 error:
1302  return -1;
1303 }
1304 
1305 #define UNDEFINED_PORT 0
1306 #define RANGE_PORT 1
1307 #define SINGLE_PORT 2
1309 typedef struct UniquePortPoint_ {
1310  uint16_t port; /* value of the port */
1311  bool single; /* is the port single or part of a range */
1313 
1314 /**
1315  * \brief Function to set unique port points. Consider all the ports
1316  * flattened out on one line, set the points that correspond
1317  * to a valid port. Also store whether the port point stored
1318  * was a single port or part of a range.
1319  *
1320  * \param p Port object to be set
1321  * \param unique_list List of unique port points to be updated
1322  * \param size_list Current size of the list
1323  *
1324  * \return Updated size of the list
1325  */
1326 static inline uint32_t SetUniquePortPoints(
1327  const DetectPort *p, uint8_t *unique_list, uint32_t size_list)
1328 {
1329  if (unique_list[p->port] == UNDEFINED_PORT) {
1330  if (p->port == p->port2) {
1331  unique_list[p->port] = SINGLE_PORT;
1332  } else {
1333  unique_list[p->port] = RANGE_PORT;
1334  }
1335  size_list++;
1336  } else if (((unique_list[p->port] == SINGLE_PORT) && (p->port != p->port2)) ||
1337  ((unique_list[p->port] == RANGE_PORT) && (p->port == p->port2))) {
1338  if ((p->port != UINT16_MAX) && (unique_list[p->port + 1] == UNDEFINED_PORT)) {
1339  unique_list[p->port + 1] = RANGE_PORT;
1340  size_list++;
1341  }
1342  }
1343 
1344  /* Treat right boundary as single point to avoid creating unneeded
1345  * ranges later on */
1346  if (unique_list[p->port2] == UNDEFINED_PORT) {
1347  size_list++;
1348  }
1349  unique_list[p->port2] = SINGLE_PORT;
1350  return size_list;
1351 }
1352 
1353 /**
1354  * \brief Function to set the *final* unique port points and save them
1355  * for later use. The points are already sorted because of the way
1356  * they have been retrieved and saved earlier for use at this point.
1357  *
1358  * \param unique_list List of the unique port points to be used
1359  * \param size_unique_arr Number of unique port points
1360  * \param final_arr List of the final unique port points to be created
1361  */
1362 static inline void SetFinalUniquePortPoints(
1363  const uint8_t *unique_list, const uint32_t size_unique_arr, UniquePortPoint *final_arr)
1364 {
1365  for (uint32_t i = 0, j = 0; i < (UINT16_MAX + 1); i++) {
1366  DEBUG_VALIDATE_BUG_ON(j > size_unique_arr);
1367  if (unique_list[i] == RANGE_PORT) {
1368  final_arr[j].port = (uint16_t)i;
1369  final_arr[j++].single = false;
1370  } else if (unique_list[i] == SINGLE_PORT) {
1371  final_arr[j].port = (uint16_t)i;
1372  final_arr[j++].single = true;
1373  }
1374  }
1375 }
1376 
1377 /**
1378  * \brief Function to create the list of ports with the smallest ranges
1379  * by resolving overlaps and end point conditions. These contain the
1380  * correct SGHs as well after going over the interval tree to find
1381  * any range overlaps.
1382  *
1383  * \param de_ctx Detection Engine Context
1384  * \param unique_list Final list of unique port points
1385  * \param size_list Size of the unique_list
1386  * \param it Pointer to the interval tree
1387  * \param list Pointer to the list where final ports will be stored
1388  *
1389  * \return 0 on success, -1 otherwise
1390  */
1391 static inline int CreatePortList(DetectEngineCtx *de_ctx, const uint8_t *unique_list,
1392  const uint32_t size_list, SCPortIntervalTree *it, DetectPort **list)
1393 {
1394  /* Only do the operations if there is at least one unique port */
1395  if (size_list == 0)
1396  return 0;
1397  UniquePortPoint *final_unique_points =
1398  (UniquePortPoint *)SCCalloc(size_list, sizeof(UniquePortPoint));
1399  if (final_unique_points == NULL)
1400  return -1;
1401  SetFinalUniquePortPoints(unique_list, size_list, final_unique_points);
1402  /* Handle edge case when there is just one unique port */
1403  if (size_list == 1) {
1405  de_ctx, final_unique_points[0].port, final_unique_points[0].port, &it->tree, list);
1406  } else {
1407  UniquePortPoint *p1 = &final_unique_points[0];
1408  UniquePortPoint *p2 = &final_unique_points[1];
1409  uint16_t port = p1 ? p1->port : 0; // just for cppcheck
1410  uint16_t port2 = p2->port;
1411  for (uint32_t i = 1; i < size_list; i++) {
1412  DEBUG_VALIDATE_BUG_ON(port > port2);
1413  if ((p1 && p1->single) && p2->single) {
1414  SCPortIntervalFindOverlappingRanges(de_ctx, port, port, &it->tree, list);
1415  SCPortIntervalFindOverlappingRanges(de_ctx, port2, port2, &it->tree, list);
1416  port = port2 + 1;
1417  } else if (p1 && p1->single) {
1418  SCPortIntervalFindOverlappingRanges(de_ctx, port, port, &it->tree, list);
1419  if ((port2 > port + 1)) {
1421  de_ctx, port + 1, port2 - 1, &it->tree, list);
1422  port = port2;
1423  } else {
1424  port = port + 1;
1425  }
1426  } else if (p2->single) {
1427  /* If port2 is boundary and less or equal to port + 1, create a range
1428  * keeping the boundary away as it is single port */
1429  if ((port2 >= port + 1)) {
1430  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2 - 1, &it->tree, list);
1431  }
1432  /* Deal with port2 as it is a single port */
1433  SCPortIntervalFindOverlappingRanges(de_ctx, port2, port2, &it->tree, list);
1434  port = port2 + 1;
1435  } else {
1436  if ((port2 > port + 1)) {
1437  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2 - 1, &it->tree, list);
1438  port = port2;
1439  } else {
1440  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2, &it->tree, list);
1441  port = port2 + 1;
1442  }
1443  }
1444  /* if the current port matches the p2->port, assign it to p1 so that
1445  * there is a UniquePortPoint object to check other info like whether
1446  * the port with this value is single */
1447  if (port == p2->port) {
1448  p1 = p2;
1449  } else {
1450  p1 = NULL;
1451  }
1452  if (i + 1 < size_list) {
1453  p2 = &final_unique_points[i + 1];
1454  port2 = p2->port;
1455  }
1456  }
1457  }
1458  /* final_unique_points array is no longer needed */
1459  SCFree(final_unique_points);
1460  return 0;
1461 }
1462 
1463 static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, uint8_t ipproto, uint32_t direction)
1464 {
1465  /* step 1: create a hash of 'DetectPort' objects based on all the
1466  * rules. Each object will have a SGH with the sigs added
1467  * that belong to the SGH. */
1469 
1470  uint32_t size_unique_port_arr = 0;
1471  const Signature *s = de_ctx->sig_list;
1472  DetectPort *list = NULL;
1473 
1474  uint8_t *unique_port_points = (uint8_t *)SCCalloc(UINT16_MAX + 1, sizeof(uint8_t));
1475  if (unique_port_points == NULL)
1476  return NULL;
1477 
1478  while (s) {
1479  /* IP Only rules are handled separately */
1480  if (s->type == SIG_TYPE_IPONLY)
1481  goto next;
1482  /* Protocol does not match the Signature protocol and is neither IP or pkthdr */
1483  if (!(s->proto.proto[ipproto / 8] & (1<<(ipproto % 8)) || (s->proto.flags & DETECT_PROTO_ANY)))
1484  goto next;
1485  /* Direction does not match Signature direction */
1486  if (direction == SIG_FLAG_TOSERVER) {
1487  if (!(s->flags & SIG_FLAG_TOSERVER))
1488  goto next;
1489  } else if (direction == SIG_FLAG_TOCLIENT) {
1490  if (!(s->flags & SIG_FLAG_TOCLIENT))
1491  goto next;
1492  }
1493 
1494  /* see if we want to exclude directionless sigs that really care only for
1495  * to_server syn scans/floods */
1499  (!(s->dp->port == 0 && s->dp->port2 == 65535))) {
1500  SCLogWarning("rule %u: SYN-only to port(s) %u:%u "
1501  "w/o direction specified, disabling for toclient direction",
1502  s->id, s->dp->port, s->dp->port2);
1503  goto next;
1504  }
1505 
1506  DetectPort *p = NULL;
1507  if (direction == SIG_FLAG_TOSERVER)
1508  p = s->dp;
1509  else if (direction == SIG_FLAG_TOCLIENT)
1510  p = s->sp;
1511  else
1512  BUG_ON(1);
1513 
1514  int wl = s->init_data->score;
1515  while (p) {
1516  int pwl = PortIsPriority(de_ctx, p, ipproto) ? DETECT_PGSCORE_RULE_PORT_PRIORITIZED : 0;
1517  pwl = MAX(wl,pwl);
1518 
1519  DetectPort *lookup = DetectPortHashLookup(de_ctx, p);
1520  if (lookup) {
1521  SigGroupHeadAppendSig(de_ctx, &lookup->sh, s);
1522  lookup->sh->init->score = MAX(lookup->sh->init->score, pwl);
1523  } else {
1525  BUG_ON(tmp2 == NULL);
1526  SigGroupHeadAppendSig(de_ctx, &tmp2->sh, s);
1527  tmp2->sh->init->score = pwl;
1528  DetectPortHashAdd(de_ctx, tmp2);
1529  size_unique_port_arr =
1530  SetUniquePortPoints(tmp2, unique_port_points, size_unique_port_arr);
1531  }
1532 
1533  p = p->next;
1534  }
1535  next:
1536  s = s->next;
1537  }
1538 
1539  /* step 2: create a list of the smallest port ranges with
1540  * appropriate SGHs */
1541 
1542  /* Create an interval tree of all the given ports to make the search
1543  * for overlaps later on easier */
1545  if (it == NULL)
1546  goto error;
1547 
1548  HashListTableBucket *htb = NULL;
1549  for (htb = HashListTableGetListHead(de_ctx->dport_hash_table); htb != NULL;
1550  htb = HashListTableGetListNext(htb)) {
1552  if (SCPortIntervalInsert(de_ctx, it, p) != SC_OK) {
1553  SCLogDebug("Port was not inserted in the tree");
1554  goto error;
1555  }
1556  }
1557 
1558  /* Create a sorted list of ports in ascending order after resolving overlaps
1559  * and corresponding SGHs */
1560  if (CreatePortList(de_ctx, unique_port_points, size_unique_port_arr, it, &list) < 0)
1561  goto error;
1562 
1563  /* unique_port_points array is no longer needed */
1564  SCFree(unique_port_points);
1565 
1566  /* Port hashes are no longer needed */
1568 
1569  SCLogDebug("rules analyzed");
1570 
1571  /* step 3: group the list and shrink it if necessary */
1572  DetectPort *newlist = NULL;
1573  uint16_t groupmax = (direction == SIG_FLAG_TOCLIENT) ? de_ctx->max_uniq_toclient_groups :
1575  CreateGroupedPortList(de_ctx, list, &newlist, groupmax, SortCompare);
1576  list = newlist;
1577 
1578  /* step 4: deduplicate the SGH's */
1581 
1582  uint32_t cnt = 0;
1583  uint32_t own = 0;
1584  uint32_t ref = 0;
1585  DetectPort *iter;
1586  for (iter = list ; iter != NULL; iter = iter->next) {
1587  BUG_ON (iter->sh == NULL);
1588  DEBUG_VALIDATE_BUG_ON(own + ref != cnt);
1589  cnt++;
1590 
1591  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, iter->sh);
1592  if (lookup_sgh == NULL) {
1593  SCLogDebug("port group %p sgh %p is the original", iter, iter->sh);
1594 
1595  SigGroupHeadSetSigCnt(iter->sh, 0);
1597  SigGroupHeadSetProtoAndDirection(iter->sh, ipproto, direction);
1598  SigGroupHeadHashAdd(de_ctx, iter->sh);
1599  SigGroupHeadStore(de_ctx, iter->sh);
1600  iter->flags |= PORT_SIGGROUPHEAD_COPY;
1601  own++;
1602  } else {
1603  SCLogDebug("port group %p sgh %p is a copy", iter, iter->sh);
1604 
1605  SigGroupHeadFree(de_ctx, iter->sh);
1606  iter->sh = lookup_sgh;
1607  iter->flags |= PORT_SIGGROUPHEAD_COPY;
1608  ref++;
1609  }
1610  }
1611 #if 0
1612  for (iter = list ; iter != NULL; iter = iter->next) {
1613  SCLogInfo("PORT %u-%u %p (sgh=%s, prioritized=%s/%d)",
1614  iter->port, iter->port2, iter->sh,
1615  iter->flags & PORT_SIGGROUPHEAD_COPY ? "ref" : "own",
1616  iter->sh->init->score ? "true" : "false",
1617  iter->sh->init->score);
1618  }
1619 #endif
1620  SCLogPerf("%s %s: %u port groups, %u unique SGH's, %u copies",
1621  ipproto == 6 ? "TCP" : "UDP",
1622  direction == SIG_FLAG_TOSERVER ? "toserver" : "toclient",
1623  cnt, own, ref);
1625  return list;
1626 
1627 error:
1628  if (unique_port_points != NULL)
1629  SCFree(unique_port_points);
1630  if (it != NULL)
1632 
1633  return NULL;
1634 }
1635 
1637 {
1638  BUG_ON(s->type != SIG_TYPE_NOT_SET);
1639  int iponly = 0;
1640 
1642  s->type = SIG_TYPE_APP_TX;
1643  SCLogDebug("%u: set to app_tx due to hook type app", s->id);
1644  SCReturn;
1645  }
1646 
1647  /* see if the sig is dp only */
1648  if (SignatureIsPDOnly(de_ctx, s) == 1) {
1649  s->type = SIG_TYPE_PDONLY;
1650 
1651  /* see if the sig is ip only */
1652  } else if ((iponly = SignatureIsIPOnly(de_ctx, s)) > 0) {
1653  if (iponly == 1) {
1654  s->type = SIG_TYPE_IPONLY;
1655  } else if (iponly == 2) {
1657  }
1658  } else if (SignatureIsDEOnly(de_ctx, s) == 1) {
1659  s->type = SIG_TYPE_DEONLY;
1660 
1661  } else {
1662  const bool has_match = s->init_data->smlists[DETECT_SM_LIST_MATCH] != NULL;
1663  const bool has_pmatch = s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL;
1664  bool has_buffer_frame_engine = false;
1665  bool has_buffer_packet_engine = false;
1666  bool has_buffer_app_engine = false;
1667 
1668  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
1669  const uint32_t id = s->init_data->buffers[x].id;
1670 
1672  has_buffer_packet_engine = true;
1674  has_buffer_frame_engine = true;
1675  } else {
1676  has_buffer_app_engine = true;
1677  }
1678  }
1679 
1680  if (has_buffer_packet_engine) {
1681  s->type = SIG_TYPE_PKT;
1682  } else if (has_buffer_frame_engine || has_buffer_app_engine) {
1683  s->type = SIG_TYPE_APP_TX;
1684  } else if (has_pmatch) {
1687  s->type = SIG_TYPE_PKT;
1688  } else if ((s->flags & (SIG_FLAG_REQUIRE_PACKET | SIG_FLAG_REQUIRE_STREAM)) ==
1690  s->type = SIG_TYPE_STREAM;
1691  } else {
1693  }
1694  } else if (has_match) {
1695  s->type = SIG_TYPE_PKT;
1696 
1697  /* app-layer but no inspect engines */
1698  } else if (s->flags & SIG_FLAG_APPLAYER) {
1699  s->type = SIG_TYPE_APPLAYER;
1700  } else {
1701  s->type = SIG_TYPE_PKT;
1702  }
1703  }
1704 }
1705 
1706 /**
1707  * \brief Preprocess signature, classify ip-only, etc, build sig array
1708  *
1709  * \param de_ctx Pointer to the Detection Engine Context
1710  *
1711  * \retval 0 on success
1712  * \retval -1 on failure
1713  */
1715 {
1716  uint32_t cnt_iponly = 0;
1717  uint32_t cnt_payload = 0;
1718  uint32_t cnt_applayer = 0;
1719  uint32_t cnt_deonly = 0;
1720 
1721  if (!(de_ctx->flags & DE_QUIET)) {
1722  SCLogDebug("building signature grouping structure, stage 1: "
1723  "preprocessing rules...");
1724  }
1725 
1728  if (de_ctx->sig_array == NULL)
1729  goto error;
1730 
1731  /* now for every rule add the source group */
1732  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
1733  de_ctx->sig_array[s->iid] = s;
1734 
1735  SCLogDebug("Signature %" PRIu32 ", internal id %" PRIu32 ", ptrs %p %p ", s->id, s->iid, s,
1736  de_ctx->sig_array[s->iid]);
1737 
1738  if (s->type == SIG_TYPE_PDONLY) {
1739  SCLogDebug("Signature %"PRIu32" is considered \"PD only\"", s->id);
1740  } else if (s->type == SIG_TYPE_IPONLY) {
1741  SCLogDebug("Signature %"PRIu32" is considered \"IP only\"", s->id);
1742  cnt_iponly++;
1743  } else if (SignatureIsInspectingPayload(de_ctx, s) == 1) {
1744  SCLogDebug("Signature %"PRIu32" is considered \"Payload inspecting\"", s->id);
1745  cnt_payload++;
1746  } else if (s->type == SIG_TYPE_DEONLY) {
1747  SCLogDebug("Signature %"PRIu32" is considered \"Decoder Event only\"", s->id);
1748  cnt_deonly++;
1749  } else if (s->flags & SIG_FLAG_APPLAYER) {
1750  SCLogDebug("Signature %"PRIu32" is considered \"Applayer inspecting\"", s->id);
1751  cnt_applayer++;
1752  }
1753 
1754 #ifdef DEBUG
1755  if (SCLogDebugEnabled()) {
1756  uint16_t colen = 0;
1757  char copresent = 0;
1758  SigMatch *sm;
1759  DetectContentData *co;
1760  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH]; sm != NULL; sm = sm->next) {
1761  if (sm->type != DETECT_CONTENT)
1762  continue;
1763 
1764  copresent = 1;
1765  co = (DetectContentData *)sm->ctx;
1766  if (co->content_len > colen)
1767  colen = co->content_len;
1768  }
1769 
1770  if (copresent && colen == 1) {
1771  SCLogDebug("signature %8u content maxlen 1", s->id);
1772  for (int proto = 0; proto < 256; proto++) {
1773  if (s->proto.proto[(proto/8)] & (1<<(proto%8)))
1774  SCLogDebug("=> proto %" PRId32 "", proto);
1775  }
1776  }
1777  }
1778 #endif /* DEBUG */
1779 
1780  if (RuleMpmIsNegated(s)) {
1781  s->flags |= SIG_FLAG_MPM_NEG;
1782  }
1783 
1784  SignatureCreateMask(s);
1787 
1788  RuleSetScore(s);
1789 
1790  /* run buffer type callbacks if any */
1791  for (int x = 0; x < DETECT_SM_LIST_MAX; x++) {
1792  if (s->init_data->smlists[x])
1794  }
1795  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
1797  }
1798 
1799  de_ctx->sig_cnt++;
1800  }
1801 
1802  if (!(de_ctx->flags & DE_QUIET)) {
1803  if (strlen(de_ctx->config_prefix) > 0)
1804  SCLogInfo("tenant id %d: %" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
1805  "rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
1806  " inspect application layer, %" PRIu32 " are decoder event only",
1807  de_ctx->tenant_id, de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer,
1808  cnt_deonly);
1809  else
1810  SCLogInfo("%" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
1811  "rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
1812  " inspect application layer, %" PRIu32 " are decoder event only",
1813  de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer, cnt_deonly);
1814 
1815  SCLogConfig("building signature grouping structure, stage 1: "
1816  "preprocessing rules... complete");
1817  }
1818 
1819  if (DetectFlowbitsAnalyze(de_ctx) != 0)
1820  goto error;
1821 
1822  return 0;
1823 
1824 error:
1825  return -1;
1826 }
1827 
1828 /**
1829  * \internal
1830  * \brief add a decoder event signature to the detection engine ctx
1831  */
1832 static void DetectEngineAddDecoderEventSig(DetectEngineCtx *de_ctx, Signature *s)
1833 {
1834  SCLogDebug("adding signature %"PRIu32" to the decoder event sgh", s->id);
1836 }
1837 
1838 static void DetectEngineAddSigToPreStreamHook(DetectEngineCtx *de_ctx, Signature *s)
1839 {
1840  SCLogDebug("adding signature %" PRIu32 " to the pre_stream hook sgh", s->id);
1841 
1842  if ((s->flags & (SIG_FLAG_TOSERVER | SIG_FLAG_TOCLIENT)) ==
1846  } else if (s->flags & SIG_FLAG_TOSERVER) {
1848  } else if (s->flags & SIG_FLAG_TOCLIENT) {
1850  }
1851 }
1852 
1853 static void DetectEngineAddSigToPreFlowHook(DetectEngineCtx *de_ctx, Signature *s)
1854 {
1855  SCLogDebug("adding signature %" PRIu32 " to the pre_flow hook sgh", s->id);
1857 }
1858 
1859 /**
1860  * \brief Fill the global src group head, with the sigs included
1861  *
1862  * \param de_ctx Pointer to the Detection Engine Context whose Signatures have
1863  * to be processed
1864  *
1865  * \retval 0 On success
1866  * \retval -1 On failure
1867  */
1869 {
1870  SCLogDebug("building signature grouping structure, stage 2: "
1871  "building source address lists...");
1872 
1874 
1875  de_ctx->flow_gh[1].tcp = RulesGroupByPorts(de_ctx, IPPROTO_TCP, SIG_FLAG_TOSERVER);
1876  de_ctx->flow_gh[0].tcp = RulesGroupByPorts(de_ctx, IPPROTO_TCP, SIG_FLAG_TOCLIENT);
1877  de_ctx->flow_gh[1].udp = RulesGroupByPorts(de_ctx, IPPROTO_UDP, SIG_FLAG_TOSERVER);
1878  de_ctx->flow_gh[0].udp = RulesGroupByPorts(de_ctx, IPPROTO_UDP, SIG_FLAG_TOCLIENT);
1879 
1880  /* Setup the other IP Protocols (so not TCP/UDP) */
1881  RulesGroupByIPProto(de_ctx);
1882 
1883  /* now for every rule add the source group to our temp lists */
1884  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
1885  SCLogDebug("s->id %"PRIu32, s->id);
1886  if (s->type == SIG_TYPE_IPONLY) {
1888  } else if (s->type == SIG_TYPE_DEONLY) {
1889  DetectEngineAddDecoderEventSig(de_ctx, s);
1890  } else if (s->type == SIG_TYPE_PKT && s->init_data->hook.type == SIGNATURE_HOOK_TYPE_PKT &&
1892  DetectEngineAddSigToPreStreamHook(de_ctx, s);
1893  } else if (s->type == SIG_TYPE_PKT && s->init_data->hook.type == SIGNATURE_HOOK_TYPE_PKT &&
1895  DetectEngineAddSigToPreFlowHook(de_ctx, s);
1896  }
1897  }
1898 
1901  return 0;
1902 }
1903 
1904 static void DetectEngineBuildDecoderEventSgh(DetectEngineCtx *de_ctx)
1905 {
1906  if (de_ctx->decoder_event_sgh == NULL)
1907  return;
1908 
1909  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1912 }
1913 
1914 static void DetectEngineBuildPreStreamHookSghs(DetectEngineCtx *de_ctx)
1915 {
1916  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1917  if (de_ctx->pre_stream_sgh[0] != NULL) {
1921  }
1922  if (de_ctx->pre_stream_sgh[1] != NULL) {
1926  }
1927 
1928  if (de_ctx->pre_stream_sgh[0] != NULL || de_ctx->pre_stream_sgh[1] != NULL) {
1930  }
1931 }
1932 
1933 static void DetectEngineBuildPreFlowHookSghs(DetectEngineCtx *de_ctx)
1934 {
1935  if (de_ctx->pre_flow_sgh != NULL) {
1936  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1941  }
1942 }
1943 
1945 {
1946  /* prepare the decoder event sgh */
1947  DetectEngineBuildDecoderEventSgh(de_ctx);
1948 
1949  /* pre_flow hook sgh */
1950  DetectEngineBuildPreFlowHookSghs(de_ctx);
1951 
1952  /* pre_stream hook sghs */
1953  DetectEngineBuildPreStreamHookSghs(de_ctx);
1954 
1955  return 0;
1956 }
1957 
1959 {
1960  BUG_ON(de_ctx == NULL);
1961 
1962  SCLogDebug("cleaning up signature grouping structure...");
1963 
1966  de_ctx->decoder_event_sgh = NULL;
1967  if (de_ctx->pre_flow_sgh)
1969  de_ctx->pre_flow_sgh = NULL;
1970  if (de_ctx->pre_stream_sgh[0])
1972  de_ctx->pre_stream_sgh[0] = NULL;
1973  if (de_ctx->pre_stream_sgh[1])
1975  de_ctx->pre_stream_sgh[1] = NULL;
1976 
1977  for (int f = 0; f < FLOW_STATES; f++) {
1978  for (int p = 0; p < 256; p++) {
1979  de_ctx->flow_gh[f].sgh[p] = NULL;
1980  }
1981 
1982  /* free lookup lists */
1984  de_ctx->flow_gh[f].tcp = NULL;
1986  de_ctx->flow_gh[f].udp = NULL;
1987  }
1988 
1989  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
1990  SigGroupHead *sgh = de_ctx->sgh_array[idx];
1991  if (sgh == NULL)
1992  continue;
1993 
1994  SCLogDebug("sgh %p", sgh);
1995  SigGroupHeadFree(de_ctx, sgh);
1996  }
1998  de_ctx->sgh_array = NULL;
1999  de_ctx->sgh_array_cnt = 0;
2000  de_ctx->sgh_array_size = 0;
2001 
2003 
2004  SCLogDebug("cleaning up signature grouping structure... complete");
2005  return 0;
2006 }
2007 
2008 #if 0
2009 static void DbgPrintSigs(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
2010 {
2011  if (sgh == NULL) {
2012  printf("\n");
2013  return;
2014  }
2015 
2016  uint32_t sig;
2017  for (sig = 0; sig < sgh->sig_cnt; sig++) {
2018  printf("%" PRIu32 " ", sgh->match_array[sig]->id);
2019  }
2020  printf("\n");
2021 }
2022 
2023 static void DbgPrintSigs2(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
2024 {
2025  if (sgh == NULL || sgh->init == NULL) {
2026  printf("\n");
2027  return;
2028  }
2029 
2030  uint32_t sig;
2031  for (sig = 0; sig < DetectEngineGetMaxSigId(de_ctx); sig++) {
2032  if (sgh->init->sig_array[(sig/8)] & (1<<(sig%8))) {
2033  printf("%" PRIu32 " ", de_ctx->sig_array[sig]->id);
2034  }
2035  }
2036  printf("\n");
2037 }
2038 #endif
2039 
2040 /** \brief finalize preparing sgh's */
2042 {
2043  SCEnter();
2044 
2045  //SCLogInfo("sgh's %"PRIu32, de_ctx->sgh_array_cnt);
2046 
2047  uint32_t cnt = 0;
2048  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
2049  SigGroupHead *sgh = de_ctx->sgh_array[idx];
2050  if (sgh == NULL)
2051  continue;
2052 
2053  SCLogDebug("sgh %p", sgh);
2054 
2056  SCLogDebug("filestore count %u", sgh->filestore_cnt);
2057 
2059 
2060  sgh->id = idx;
2061  cnt++;
2062  }
2063  SCLogPerf("Unique rule groups: %u", cnt);
2064 
2066 
2067  if (de_ctx->decoder_event_sgh != NULL) {
2068  /* no need to set filestore count here as that would make a
2069  * signature not decode event only. */
2071  }
2072 
2073  int dump_grouping = 0;
2074  (void)SCConfGetBool("detect.profiling.grouping.dump-to-disk", &dump_grouping);
2075 
2076  if (dump_grouping) {
2077  int add_rules = 0;
2078  (void)SCConfGetBool("detect.profiling.grouping.include-rules", &add_rules);
2079  int add_mpm_stats = 0;
2080  (void)SCConfGetBool("detect.profiling.grouping.include-mpm-stats", &add_mpm_stats);
2081 
2082  RulesDumpGrouping(de_ctx, add_rules, add_mpm_stats);
2083  }
2084 
2085  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
2086  SigGroupHead *sgh = de_ctx->sgh_array[idx];
2087  if (sgh == NULL)
2088  continue;
2090  sgh->init = NULL;
2091  }
2092  /* cleanup the hashes now since we won't need them
2093  * after the initialization phase. */
2095 
2096 #ifdef PROFILING
2098 #endif
2099  SCReturnInt(0);
2100 }
2101 
2102 extern bool rule_engine_analysis_set;
2103 /** \internal
2104  * \brief perform final per signature setup tasks
2105  *
2106  * - Create SigMatchData arrays from the init only SigMatch lists
2107  * - Setup per signature inspect engines
2108  * - remove signature init data.
2109  */
2110 static int SigMatchPrepare(DetectEngineCtx *de_ctx)
2111 {
2112  SCEnter();
2113 
2114  Signature *s = de_ctx->sig_list;
2115  for (; s != NULL; s = s->next) {
2116  /* set up inspect engines */
2118 
2119  /* built-ins */
2120  for (int type = 0; type < DETECT_SM_LIST_MAX; type++) {
2121  /* skip PMATCH if it is used in a stream 'app engine' instead */
2123  continue;
2124  SigMatch *sm = s->init_data->smlists[type];
2126  }
2127  /* set up the pkt inspection engines */
2129 
2133  }
2134  /* free lists. Ctx' are xferred to sm_arrays so won't get freed */
2135  for (uint32_t i = 0; i < DETECT_SM_LIST_MAX; i++) {
2136  SigMatch *sm = s->init_data->smlists[i];
2137  while (sm != NULL) {
2138  SigMatch *nsm = sm->next;
2139  SigMatchFree(de_ctx, sm);
2140  sm = nsm;
2141  }
2142  }
2143  for (uint32_t i = 0; i < (uint32_t)s->init_data->transforms.cnt; i++) {
2144  if (s->init_data->transforms.transforms[i].options) {
2145  int transform = s->init_data->transforms.transforms[i].transform;
2146  sigmatch_table[transform].Free(
2148  s->init_data->transforms.transforms[i].options = NULL;
2149  }
2150  }
2151  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
2152  SigMatch *sm = s->init_data->buffers[x].head;
2153  while (sm != NULL) {
2154  SigMatch *nsm = sm->next;
2155  SigMatchFree(de_ctx, sm);
2156  sm = nsm;
2157  }
2158  }
2159  if (s->init_data->cidr_dst != NULL)
2161 
2162  if (s->init_data->cidr_src != NULL)
2164 
2165  SCFree(s->init_data->buffers);
2168  SCFree(s->init_data);
2169  s->init_data = NULL;
2170  }
2171 
2173  SCReturnInt(0);
2174 }
2175 
2176 /**
2177  * \brief Convert the signature list into the runtime match structure.
2178  *
2179  * \param de_ctx Pointer to the Detection Engine Context whose Signatures have
2180  * to be processed
2181  *
2182  * \retval 0 On Success.
2183  * \retval -1 On failure.
2184  */
2186 {
2187  Signature *s = de_ctx->sig_list;
2188 
2189  /* Assign the unique order id of signatures after sorting,
2190  * so the IP Only engine process them in order too. Also
2191  * reset the old signums and assign new signums. We would
2192  * have experienced Sig reordering by now, hence the new
2193  * signums. */
2194  de_ctx->signum = 0;
2195  while (s != NULL) {
2196  s->iid = de_ctx->signum++;
2197 
2198  s = s->next;
2199  }
2200 
2202  return -1;
2203 
2204  SigInitStandardMpmFactoryContexts(de_ctx);
2205 
2206  if (SigPrepareStage1(de_ctx) != 0) {
2207  FatalError("initializing the detection engine failed");
2208  }
2209 
2210  if (SigPrepareStage2(de_ctx) != 0) {
2211  FatalError("initializing the detection engine failed");
2212  }
2213 
2214  if (SigPrepareStage3(de_ctx) != 0) {
2215  FatalError("initializing the detection engine failed");
2216  }
2217  if (SigPrepareStage4(de_ctx) != 0) {
2218  FatalError("initializing the detection engine failed");
2219  }
2220 
2225  if (r != 0) {
2226  FatalError("initializing the detection engine failed");
2227  }
2228 
2229  if (SigMatchPrepare(de_ctx) != 0) {
2230  FatalError("initializing the detection engine failed");
2231  }
2232 
2233 #ifdef PROFILING
2236  de_ctx->profile_match_logging_threshold = UINT_MAX; // disabled
2237 
2238  intmax_t v = 0;
2239  if (SCConfGetInt("detect.profiling.inspect-logging-threshold", &v) == 1)
2240  de_ctx->profile_match_logging_threshold = (uint32_t)v;
2241 #endif
2242 #ifdef PROFILE_RULES
2243  SCProfilingRuleInitCounters(de_ctx);
2244 #endif
2245 
2248  }
2249 
2250  if (EngineModeIsFirewall()) {
2252  }
2253  return 0;
2254 }
2255 
2257 {
2259 
2260  return 0;
2261 }
detect-tcp-flags.h
HashListTableGetListData
#define HashListTableGetListData(hb)
Definition: util-hashlist.h:56
SIG_TYPE_STREAM
@ SIG_TYPE_STREAM
Definition: detect.h:74
DETECT_FLOW_FLAG_TOCLIENT
#define DETECT_FLOW_FLAG_TOCLIENT
Definition: detect-flow.h:28
SignatureInitDataBuffer_::head
SigMatch * head
Definition: detect.h:534
detect-content.h
DETECT_APP_LAYER_EVENT
@ DETECT_APP_LAYER_EVENT
Definition: detect-engine-register.h:204
util-port-interval-tree.h
detect-engine.h
DetectEngineResetMaxSigId
void DetectEngineResetMaxSigId(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:3054
DetectEngineBufferTypeSupportsPacketGetById
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1445
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
SIG_MASK_REQUIRE_REAL_PKT
#define SIG_MASK_REQUIRE_REAL_PKT
Definition: detect.h:316
MASK_TCP_UNUSUAL_FLAGS
#define MASK_TCP_UNUSUAL_FLAGS
Definition: detect-engine-build.c:396
DetectFlagsSignatureNeedsSynOnlyPackets
int DetectFlagsSignatureNeedsSynOnlyPackets(const Signature *s)
Definition: detect-tcp-flags.c:536
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:642
detect-engine-proto.h
detect-dsize.h
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1266
UniquePortPoint_
Definition: detect-engine-build.c:1309
SIG_TYPE_APP_TX
@ SIG_TYPE_APP_TX
Definition: detect.h:77
SigMatchFree
void SigMatchFree(DetectEngineCtx *de_ctx, SigMatch *sm)
free a SigMatch
Definition: detect-parse.c:288
SigTableElmt_::Free
void(* Free)(DetectEngineCtx *, void *)
Definition: detect.h:1444
DetectEngineCtx_::decoder_event_sgh
struct SigGroupHead_ * decoder_event_sgh
Definition: detect.h:1017
DetectPortHashInit
int DetectPortHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the DetectPort hash.
Definition: detect-engine-port.c:1371
DetectEngineCtx_::flow_gh
DetectEngineLookupFlow flow_gh[FLOW_STATES]
Definition: detect.h:959
FILE_SIG_NEED_SHA1
#define FILE_SIG_NEED_SHA1
Definition: detect.h:325
SigPrepareStage4
int SigPrepareStage4(DetectEngineCtx *de_ctx)
finalize preparing sgh's
Definition: detect-engine-build.c:2041
detect-engine-siggroup.h
DetectFlowData_
Definition: detect-flow.h:37
SigTableElmt_::name
const char * name
Definition: detect.h:1457
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1321
DetectEngineBufferRunSetupCallback
void DetectEngineBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s)
Definition: detect-engine.c:1482
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1627
DetectListToHumanString
const char * DetectListToHumanString(int list)
Definition: detect-parse.c:112
SIG_FLAG_INIT_FLOW
#define SIG_FLAG_INIT_FLOW
Definition: detect.h:292
SigFree
void SigFree(DetectEngineCtx *, Signature *)
Definition: detect-parse.c:2057
DumpPatterns
void DumpPatterns(DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:1436
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
DetectFlagsData_::flags
uint8_t flags
Definition: detect-tcp-flags.h:38
SigGroupHeadInitData_::sig_array
uint8_t * sig_array
Definition: detect.h:1601
DetectPortFree
void DetectPortFree(const DetectEngineCtx *de_ctx, DetectPort *dp)
Free a DetectPort and its members.
Definition: detect-engine-port.c:80
DetectEngineCtx_::PreFlowHook
DetectPacketHookFunc PreFlowHook
Definition: detect.h:1158
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:69
DetectEngineCtx_::max_uniq_toclient_groups
uint16_t max_uniq_toclient_groups
Definition: detect.h:990
MpmStoreReportStats
void MpmStoreReportStats(const DetectEngineCtx *de_ctx)
Definition: detect-engine-mpm.c:1472
SignatureInitData_::prefilter_sm
SigMatch * prefilter_sm
Definition: detect.h:625
SignatureInitData_::src_contains_negation
bool src_contains_negation
Definition: detect.h:601
DETECT_FLOW
@ DETECT_FLOW
Definition: detect-engine-register.h:54
Signature_::alproto
AppProto alproto
Definition: detect.h:673
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:275
DETECT_UINT_NE
#define DETECT_UINT_NE
Definition: detect-engine-uint.h:36
IPOnlyDeinit
void IPOnlyDeinit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Deinitialize the IP Only detection engine context.
Definition: detect-engine-iponly.c:952
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
DetectPort_::port
uint16_t port
Definition: detect.h:221
SCPortIntervalFindOverlappingRanges
void SCPortIntervalFindOverlappingRanges(DetectEngineCtx *de_ctx, const uint16_t port, const uint16_t port2, const struct PI *head, DetectPort **list)
Callee function to find all overlapping port ranges as asked by the detection engine during Stage 2 o...
Definition: util-port-interval-tree.c:315
PORT_SIGGROUPHEAD_COPY
#define PORT_SIGGROUPHEAD_COPY
Definition: detect.h:217
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
DETECT_DECODE_EVENT
@ DETECT_DECODE_EVENT
Definition: detect-engine-register.h:122
DETECT_SM_LIST_DYNAMIC_START
@ DETECT_SM_LIST_DYNAMIC_START
Definition: detect.h:138
Packet_::flags
uint32_t flags
Definition: decode.h:544
DetectEngineCtx_::PreStreamHook
DetectPacketHookFunc PreStreamHook
Definition: detect.h:1153
UNDEFINED_PORT
#define UNDEFINED_PORT
Definition: detect-engine-build.c:1305
PatternStrength
uint32_t PatternStrength(uint8_t *pat, uint16_t patlen)
Predict a strength value for patterns.
Definition: detect-engine-mpm.c:937
DetectFlowbitsAnalyze
int DetectFlowbitsAnalyze(DetectEngineCtx *de_ctx)
Definition: detect-flowbits.c:569
DetectSetFastPatternAndItsId
int DetectSetFastPatternAndItsId(DetectEngineCtx *de_ctx)
Figure out the FP and their respective content ids for all the sigs in the engine.
Definition: detect-engine-mpm.c:2459
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:40
SigTableElmt_::flags
uint16_t flags
Definition: detect.h:1448
SCProfilingSghInitCounters
void SCProfilingSghInitCounters(DetectEngineCtx *de_ctx)
Register the keyword profiling counters.
Definition: util-profiling-rulegroups.c:348
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:932
DETECT_PROTO_ANY
#define DETECT_PROTO_ANY
Definition: detect-engine-proto.h:28
SIG_TYPE_PKT_STREAM
@ SIG_TYPE_PKT_STREAM
Definition: detect.h:73
DetectEngineCtx_::pre_stream_sgh
struct SigGroupHead_ * pre_stream_sgh[2]
Definition: detect.h:1155
DetectFlagsSignatureNeedsSynPackets
int DetectFlagsSignatureNeedsSynPackets(const Signature *s)
Definition: detect-tcp-flags.c:517
TransformData_::options
void * options
Definition: detect.h:388
DetectFlowbitsData_::cmd
uint8_t cmd
Definition: detect-flowbits.h:37
HashListTableGetListHead
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
Definition: util-hashlist.c:287
SigGroupHeadSetProtoAndDirection
void SigGroupHeadSetProtoAndDirection(SigGroupHead *sgh, uint8_t ipproto, int dir)
Definition: detect-engine-siggroup.c:486
SIGMATCH_DEONLY_COMPAT
#define SIGMATCH_DEONLY_COMPAT
Definition: detect.h:1653
DETECT_UINT_EQ
#define DETECT_UINT_EQ
Definition: detect-engine-uint.h:35
DetectEngineBufferTypeGetNameById
const char * DetectEngineBufferTypeGetNameById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1308
DetectMpmInitializeBuiltinMpms
void DetectMpmInitializeBuiltinMpms(DetectEngineCtx *de_ctx)
Definition: detect-engine-mpm.c:733
SIG_FLAG_DST_ANY
#define SIG_FLAG_DST_ANY
Definition: detect.h:242
util-var-name.h
SIG_FLAG_REQUIRE_STREAM
#define SIG_FLAG_REQUIRE_STREAM
Definition: detect.h:255
rule_engine_analysis_set
bool rule_engine_analysis_set
Definition: detect-engine-loader.c:56
SCConfGetBool
int SCConfGetBool(const char *name, int *val)
Retrieve a configuration value as a boolean.
Definition: conf.c:497
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
DetectPort_::next
struct DetectPort_ * next
Definition: detect.h:234
DetectEngineCtx_::tcp_priorityports
DetectPort * tcp_priorityports
Definition: detect.h:1068
DetectEngineCtx_::dport_hash_table
HashListTable * dport_hash_table
Definition: detect.h:1066
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:731
SignatureInitData_::init_flags
uint32_t init_flags
Definition: detect.h:608
proto
uint8_t proto
Definition: decode-template.h:0
DetectPort_::sh
struct SigGroupHead_ * sh
Definition: detect.h:231
DetectEngineCtx_::udp_priorityports
DetectPort * udp_priorityports
Definition: detect.h:1069
DetectContentData_
Definition: detect-content.h:93
DETECT_FLOWBITS_CMD_ISSET
#define DETECT_FLOWBITS_CMD_ISSET
Definition: detect-flowbits.h:32
PKT_NOPAYLOAD_INSPECTION
#define PKT_NOPAYLOAD_INSPECTION
Definition: decode.h:1252
SigCleanSignatures
void SigCleanSignatures(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:56
DetectPortPrintList
void DetectPortPrintList(DetectPort *head)
Helper function used to print the list of ports present in this DetectPort list.
Definition: detect-engine-port.c:100
DETECT_UINT_GT
#define DETECT_UINT_GT
Definition: detect-engine-uint.h:32
SigPrepareStage1
int SigPrepareStage1(DetectEngineCtx *de_ctx)
Preprocess signature, classify ip-only, etc, build sig array.
Definition: detect-engine-build.c:1714
DETECT_PGSCORE_RULE_SYN_ONLY
#define DETECT_PGSCORE_RULE_SYN_ONLY
Definition: detect-engine-build.c:54
EngineModeIsFirewall
bool EngineModeIsFirewall(void)
Definition: suricata.c:235
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:272
MAX
#define MAX(x, y)
Definition: suricata-common.h:412
SIG_FLAG_SRC_ANY
#define SIG_FLAG_SRC_ANY
Definition: detect.h:241
SigGroupHeadSetupFiles
void SigGroupHeadSetupFiles(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Set the need hash flag in the sgh.
Definition: detect-engine-siggroup.c:573
SIG_TYPE_APPLAYER
@ SIG_TYPE_APPLAYER
Definition: detect.h:76
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:606
DetectPort_::port2
uint16_t port2
Definition: detect.h:222
detect-engine-prefilter.h
Packet_::app_layer_events
AppLayerDecoderEvents * app_layer_events
Definition: decode.h:632
Packet_::events
PacketEngineEvents events
Definition: decode.h:630
FLOW_STATES
#define FLOW_STATES
Definition: detect.h:912
EngineAnalysisAddAllRulePatterns
void EngineAnalysisAddAllRulePatterns(DetectEngineCtx *de_ctx, const Signature *s)
add all patterns on our stats hash Used to fill the hash later used by DumpPatterns()
Definition: detect-engine-mpm.c:2516
DetectPort_::flags
uint8_t flags
Definition: detect.h:224
DetectPortPrint
void DetectPortPrint(DetectPort *dp)
Helper function that print the DetectPort info.
Definition: detect-engine-port.c:590
FirewallAnalyzer
int FirewallAnalyzer(const DetectEngineCtx *de_ctx)
Definition: detect-engine-analyzer.c:2019
PacketCreateMask
void PacketCreateMask(Packet *p, SignatureMask *mask, AppProto alproto, bool app_decoder_events)
Definition: detect-engine-build.c:401
SIG_FLAG_APPLAYER
#define SIG_FLAG_APPLAYER
Definition: detect.h:249
SigGroupHeadHashInit
int SigGroupHeadHashInit(DetectEngineCtx *de_ctx)
Initializes the hash table in the detection engine context to hold the SigGroupHeads.
Definition: detect-engine-siggroup.c:244
FILE_SIG_NEED_MD5
#define FILE_SIG_NEED_MD5
Definition: detect.h:324
DetectEngineCtx_::sgh_array_size
uint32_t sgh_array_size
Definition: detect.h:1002
SIGNATURE_HOOK_TYPE_APP
@ SIGNATURE_HOOK_TYPE_APP
Definition: detect.h:549
SignatureIsFileSha256Inspecting
int SignatureIsFileSha256Inspecting(const Signature *s)
Check if a signature contains the filesha256 keyword.
Definition: detect-engine-build.c:171
Signature_::next
struct Signature_ * next
Definition: detect.h:750
DetectFlowbitsData_
Definition: detect-flowbits.h:35
HashListTableGetListNext
#define HashListTableGetListNext(hb)
Definition: util-hashlist.h:55
DETECT_APP_LAYER_PROTOCOL
@ DETECT_APP_LAYER_PROTOCOL
Definition: detect-engine-register.h:35
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:127
SigGroupHeadInitData_::score
int score
Definition: detect.h:1606
DetectPortCopySingle
DetectPort * DetectPortCopySingle(DetectEngineCtx *de_ctx, DetectPort *src)
Function that return a copy of DetectPort src sigs.
Definition: detect-engine-port.c:550
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:271
DetectPortParse
int DetectPortParse(const DetectEngineCtx *de_ctx, DetectPort **head, const char *str)
Function for parsing port strings.
Definition: detect-engine-port.c:1183
SigAddressCleanupStage1
int SigAddressCleanupStage1(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:1958
SCPortIntervalInsert
int SCPortIntervalInsert(DetectEngineCtx *de_ctx, SCPortIntervalTree *it, const DetectPort *p)
Function to insert a node in the interval tree.
Definition: util-port-interval-tree.c:109
DetectEngineCtx_::pre_flow_sgh
struct SigGroupHead_ * pre_flow_sgh
Definition: detect.h:1160
SIG_TYPE_PKT
@ SIG_TYPE_PKT
Definition: detect.h:72
TCPHdr_::th_flags
uint8_t th_flags
Definition: decode-tcp.h:155
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:535
SigGroupHeadInitData_::sig_cnt
SigIntId sig_cnt
Definition: detect.h:1620
DETECT_CONTENT_ENDS_WITH
#define DETECT_CONTENT_ENDS_WITH
Definition: detect-content.h:42
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:29
DETECT_FLOWINT
@ DETECT_FLOWINT
Definition: detect-engine-register.h:62
IPOnlyInit
void IPOnlyInit(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Setup the IP Only detection engine context.
Definition: detect-engine-iponly.c:913
SIG_MASK_REQUIRE_ENGINE_EVENT
#define SIG_MASK_REQUIRE_ENGINE_EVENT
Definition: detect.h:318
SIG_TYPE_IPONLY
@ SIG_TYPE_IPONLY
Definition: detect.h:66
SignatureInitData_::mpm_sm
SigMatch * mpm_sm
Definition: detect.h:623
SigFindSignatureBySidGid
Signature * SigFindSignatureBySidGid(DetectEngineCtx *de_ctx, uint32_t sid, uint32_t gid)
Find a specific signature by sid and gid.
Definition: detect-engine-build.c:80
DetectConfigData_::scope
enum ConfigScope scope
Definition: detect-config.h:32
DetectEngineGetMaxSigId
#define DetectEngineGetMaxSigId(de_ctx)
Definition: detect-engine.h:93
DETECT_FLOW_FLAG_TOSERVER
#define DETECT_FLOW_FLAG_TOSERVER
Definition: detect-flow.h:27
FILE_SIG_NEED_MAGIC
#define FILE_SIG_NEED_MAGIC
Definition: detect.h:322
SignatureInitData_::mpm_sm_list
int mpm_sm_list
Definition: detect.h:621
SIG_MASK_REQUIRE_FLOW
#define SIG_MASK_REQUIRE_FLOW
Definition: detect.h:312
SCConfGetInt
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Definition: conf.c:414
SignatureInitData_::cidr_dst
IPOnlyCIDRItem * cidr_dst
Definition: detect.h:618
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
SCEnter
#define SCEnter(...)
Definition: util-debug.h:277
detect-engine-mpm.h
DetectEngineLookupFlow_::sgh
struct SigGroupHead_ * sgh[256]
Definition: detect.h:864
detect.h
SIG_MASK_REQUIRE_FLAGS_INITDEINIT
#define SIG_MASK_REQUIRE_FLAGS_INITDEINIT
Definition: detect.h:313
SCProfilingPrefilterInitCounters
void SCProfilingPrefilterInitCounters(DetectEngineCtx *de_ctx)
Register the prefilter profiling counters.
Definition: util-profiling-prefilter.c:300
SigMatchList2DataArray
SigMatchData * SigMatchList2DataArray(SigMatch *head)
convert SigMatch list to SigMatchData array
Definition: detect-parse.c:2365
PKT_DETECT_HAS_STREAMDATA
#define PKT_DETECT_HAS_STREAMDATA
Definition: decode.h:1305
SigMatch_::next
struct SigMatch_ * next
Definition: detect.h:360
DETECT_CONTENT_NEGATED
#define DETECT_CONTENT_NEGATED
Definition: detect-content.h:40
detect-engine-port.h
DETECT_ENGINE_EVENT
@ DETECT_ENGINE_EVENT
Definition: detect-engine-register.h:226
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:117
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:255
DetectContentPropagateLimits
void DetectContentPropagateLimits(Signature *s)
Definition: detect-content.c:718
SignatureHook_::pkt
struct SignatureHook_::@95::@97 pkt
DetectPort_
Port structure for detection engine.
Definition: detect.h:220
SigGroupHead_::init
SigGroupHeadInitData * init
Definition: detect.h:1644
DetectEngineCtx_::sig_cnt
uint32_t sig_cnt
Definition: detect.h:942
DETECT_PGSCORE_RULE_NO_MPM
#define DETECT_PGSCORE_RULE_NO_MPM
Definition: detect-engine-build.c:53
UniquePortPoint_::single
bool single
Definition: detect-engine-build.c:1311
SignatureInitData_::cidr_src
IPOnlyCIDRItem * cidr_src
Definition: detect.h:618
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
SignatureInitData_::hook
SignatureHook hook
Definition: detect.h:590
SIGNATURE_HOOK_TYPE_NOT_SET
@ SIGNATURE_HOOK_TYPE_NOT_SET
Definition: detect.h:547
SignatureHook_::t
union SignatureHook_::@95 t
DetectProto_::proto
uint8_t proto[256/8]
Definition: detect-engine-proto.h:36
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
AppLayerDecoderEvents_::cnt
uint8_t cnt
Definition: app-layer-events.h:40
IPOnlyPrepare
void IPOnlyPrepare(DetectEngineCtx *de_ctx)
Build the radix trees from the lists of parsed addresses in CIDR format the result should be 4 radix ...
Definition: detect-engine-iponly.c:1138
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2256
DETECT_PGSCORE_RULE_MPM_FAST_PATTERN
#define DETECT_PGSCORE_RULE_MPM_FAST_PATTERN
Definition: detect-engine-build.c:51
SIG_FLAG_REQUIRE_FLOWVAR
#define SIG_FLAG_REQUIRE_FLOWVAR
Definition: detect.h:267
util-profiling.h
FILE_SIG_NEED_SHA256
#define FILE_SIG_NEED_SHA256
Definition: detect.h:326
DetectEngineLookupFlow_::udp
DetectPort * udp
Definition: detect.h:863
SCReturn
#define SCReturn
Definition: util-debug.h:279
Signature_::flags
uint32_t flags
Definition: detect.h:669
Packet_
Definition: decode.h:501
detect-engine-build.h
type
uint16_t type
Definition: decode-vlan.c:106
DETECT_UINT_GTE
#define DETECT_UINT_GTE
Definition: detect-engine-uint.h:33
SCConfigGetLogDirectory
const char * SCConfigGetLogDirectory(void)
Definition: util-conf.c:38
IPOnlyPrint
void IPOnlyPrint(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx)
Print stats of the IP Only engine.
Definition: detect-engine-iponly.c:941
DetectConfigData_
Definition: detect-config.h:29
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
DetectEngineCtx_::max_uniq_toserver_groups
uint16_t max_uniq_toserver_groups
Definition: detect.h:991
IPOnlyAddSignature
void IPOnlyAddSignature(DetectEngineCtx *de_ctx, DetectEngineIPOnlyCtx *io_ctx, Signature *s)
Add a signature to the lists of Addresses in CIDR format (sorted) this step is necessary to build the...
Definition: detect-engine-iponly.c:1410
SC_OK
@ SC_OK
Definition: util-error.h:27
DETECT_CONFIG
@ DETECT_CONFIG
Definition: detect-engine-register.h:229
name
const char * name
Definition: tm-threads.c:2163
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:747
DetectPreFlow
uint8_t DetectPreFlow(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, Packet *p)
Definition: detect.c:2308
SignatureInitData_::rule_state_dependant_sids_array
uint32_t * rule_state_dependant_sids_array
Definition: detect.h:657
DetectEngineCtx_::sgh_array_cnt
uint32_t sgh_array_cnt
Definition: detect.h:1001
SigGroupHeadAppendSig
int SigGroupHeadAppendSig(const DetectEngineCtx *de_ctx, SigGroupHead **sgh, const Signature *s)
Add a Signature to a SigGroupHead.
Definition: detect-engine-siggroup.c:319
DetectEngineCtx_::sgh_array
struct SigGroupHead_ ** sgh_array
Definition: detect.h:1000
UniquePortPoint_::port
uint16_t port
Definition: detect-engine-build.c:1310
SignatureInitData_::dst_contains_negation
bool dst_contains_negation
Definition: detect.h:602
SigGroupHeadFree
void SigGroupHeadFree(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Free a SigGroupHead and its members.
Definition: detect-engine-siggroup.c:163
DetectEngineTransforms::transforms
TransformData transforms[DETECT_TRANSFORMS_MAX]
Definition: detect.h:392
SIG_TYPE_DEONLY
@ SIG_TYPE_DEONLY
Definition: detect.h:71
SIGNATURE_HOOK_PKT_PRE_STREAM
@ SIGNATURE_HOOK_PKT_PRE_STREAM
Definition: detect.h:542
DetectEngineMultiTenantEnabled
bool DetectEngineMultiTenantEnabled(void)
Definition: detect-engine.c:3875
detect-flowbits.h
SIG_MASK_REQUIRE_PAYLOAD
#define SIG_MASK_REQUIRE_PAYLOAD
Definition: detect.h:311
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:225
DETECT_DSIZE
@ DETECT_DSIZE
Definition: detect-engine-register.h:52
Signature_::sp
DetectPort * sp
Definition: detect.h:719
SIG_TYPE_NOT_SET
@ SIG_TYPE_NOT_SET
Definition: detect.h:65
SignatureIsFileSha1Inspecting
int SignatureIsFileSha1Inspecting(const Signature *s)
Check if a signature contains the filesha1 keyword.
Definition: detect-engine-build.c:155
SCPortIntervalTreeInit
SCPortIntervalTree * SCPortIntervalTreeInit(void)
Function to initialize the interval tree.
Definition: util-port-interval-tree.c:58
IPOnlyCIDRListFree
void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead)
This function free a IPOnlyCIDRItem list.
Definition: detect-engine-iponly.c:482
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2185
DetectEngineCtx_::config_prefix
char config_prefix[64]
Definition: detect.h:1051
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:257
SCPortIntervalTree_::tree
struct PI tree
Definition: util-port-interval-tree.h:30
detect-engine-analyzer.h
SIG_FLAG_INIT_STATE_MATCH
#define SIG_FLAG_INIT_STATE_MATCH
Definition: detect.h:296
DetectEngineBufferTypeSupportsFramesGetById
bool DetectEngineBufferTypeSupportsFramesGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1463
EngineAnalysisRules2
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
Definition: detect-engine-analyzer.c:989
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:446
DetectProto_::flags
uint8_t flags
Definition: detect-engine-proto.h:37
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
util-conf.h
DetectMpmPrepareFrameMpms
int DetectMpmPrepareFrameMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
Definition: detect-engine-mpm.c:522
SINGLE_PORT
#define SINGLE_PORT
Definition: detect-engine-build.c:1307
DetectEnginePktInspectionSetup
int DetectEnginePktInspectionSetup(Signature *s)
Definition: detect-engine.c:1861
tail
Host * tail
Definition: host.h:2
Signature_::proto
DetectProto proto
Definition: detect.h:687
suricata-common.h
SIG_MASK_REQUIRE_NO_PAYLOAD
#define SIG_MASK_REQUIRE_NO_PAYLOAD
Definition: detect.h:315
SIG_FLAG_SP_ANY
#define SIG_FLAG_SP_ANY
Definition: detect.h:243
SigGroupHeadStore
void SigGroupHeadStore(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-siggroup.c:109
SigMatch_::type
uint16_t type
Definition: detect.h:357
SigGroupHeadInitData_::match_array
Signature ** match_array
Definition: detect.h:1623
Signature_::file_flags
uint8_t file_flags
Definition: detect.h:684
SigPrepareStage3
int SigPrepareStage3(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:1944
SignatureHook_::type
enum SignatureHookType type
Definition: detect.h:572
DetectPort_::prev
struct DetectPort_ * prev
Definition: detect.h:233
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:234
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:94
MASK_TCP_INITDEINIT_FLAGS
#define MASK_TCP_INITDEINIT_FLAGS
Definition: detect-engine-build.c:395
DetectListToString
const char * DetectListToString(int list)
Definition: detect-parse.c:130
SIGNATURE_HOOK_PKT_PRE_FLOW
@ SIGNATURE_HOOK_PKT_PRE_FLOW
Definition: detect.h:541
DetectEngineCtx_::profile_match_logging_threshold
uint32_t profile_match_logging_threshold
Definition: detect.h:1049
FatalError
#define FatalError(...)
Definition: util-debug.h:510
SIGNATURE_HOOK_TYPE_PKT
@ SIGNATURE_HOOK_TYPE_PKT
Definition: detect.h:548
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:941
DetectMpmPreparePktMpms
int DetectMpmPreparePktMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
Definition: detect-engine-mpm.c:687
SigGroupHeadHashFree
void SigGroupHeadHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by SigGroupHeadHashInit() function.
Definition: detect-engine-siggroup.c:299
SIG_MASK_REQUIRE_FLAGS_UNUSUAL
#define SIG_MASK_REQUIRE_FLAGS_UNUSUAL
Definition: detect.h:314
TransformData_::transform
int transform
Definition: detect.h:387
DETECT_FLOWBITS
@ DETECT_FLOWBITS
Definition: detect-engine-register.h:59
app-layer-events.h
SigGroupHeadHashAdd
int SigGroupHeadHashAdd(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Adds a SigGroupHead to the detection engine context SigGroupHead hash table.
Definition: detect-engine-siggroup.c:266
util-validate.h
detect-flow.h
SCPortIntervalTree_
Definition: util-port-interval-tree.h:29
SigPrepareStage2
int SigPrepareStage2(DetectEngineCtx *de_ctx)
Fill the global src group head, with the sigs included.
Definition: detect-engine-build.c:1868
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SignatureInitData_::buffers
SignatureInitDataBuffer * buffers
Definition: detect.h:647
HtpBodyChunk_::next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:123
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:283
Signature_::dp
DetectPort * dp
Definition: detect.h:719
DETECT_STREAM_EVENT
@ DETECT_STREAM_EVENT
Definition: detect-engine-register.h:227
Signature_::iid
SigIntId iid
Definition: detect.h:680
DETECT_PGSCORE_RULE_PORT_PRIORITIZED
#define DETECT_PGSCORE_RULE_PORT_PRIORITIZED
Definition: detect-engine-build.c:50
SignatureIsFilestoring
int SignatureIsFilestoring(const Signature *s)
Check if a signature contains the filestore keyword.
Definition: detect-engine-build.c:101
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SignatureIsIPOnly
int SignatureIsIPOnly(DetectEngineCtx *de_ctx, const Signature *s)
Test is a initialized signature is IP only.
Definition: detect-engine-build.c:191
DetectMpmPrepareBuiltinMpms
int DetectMpmPrepareBuiltinMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for builtin buffers that are in "single or "shared" mode.
Definition: detect-engine-mpm.c:746
Signature_::id
uint32_t id
Definition: detect.h:713
HashListTableBucket_
Definition: util-hashlist.h:28
detect-engine-iponly.h
SignatureInitData_::score
int score
Definition: detect.h:636
detect-parse.h
SignatureInitDataBuffer_::id
uint32_t id
Definition: detect.h:525
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
DETECT_SM_LIST_MAX
@ DETECT_SM_LIST_MAX
Definition: detect.h:135
SigGroupHeadInitDataFree
void SigGroupHeadInitDataFree(SigGroupHeadInitData *sghid)
Definition: detect-engine-siggroup.c:60
SignatureIsFileMd5Inspecting
int SignatureIsFileMd5Inspecting(const Signature *s)
Check if a signature contains the filemd5 keyword.
Definition: detect-engine-build.c:139
DETECT_PGSCORE_RULE_MPM_NEGATED
#define DETECT_PGSCORE_RULE_MPM_NEGATED
Definition: detect-engine-build.c:52
DetectFlagsData_
Definition: detect-tcp-flags.h:37
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
SignatureSetType
void SignatureSetType(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine-build.c:1636
RANGE_PORT
#define RANGE_PORT
Definition: detect-engine-build.c:1306
PrefilterSetupRuleGroup
int PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-prefilter.c:1176
SCProfilingKeywordInitCounters
void SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx)
Register the keyword profiling counters.
Definition: util-profiling-keywords.c:365
DetectEngineTransforms::cnt
int cnt
Definition: detect.h:393
DetectPortHashAdd
int DetectPortHashAdd(DetectEngineCtx *de_ctx, DetectPort *dp)
Adds a DetectPort to the detection engine context DetectPort hash table.
Definition: detect-engine-port.c:1391
DetectEngineCtx_::sig_array
Signature ** sig_array
Definition: detect.h:950
CONFIG_SCOPE_FLOW
@ CONFIG_SCOPE_FLOW
Definition: util-config.h:51
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:95
DetectEngineCtx_::buffer_type_id
uint32_t buffer_type_id
Definition: detect.h:1081
DetectPreStream
uint8_t DetectPreStream(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, Packet *p)
Definition: detect.c:2318
SigParseApplyDsizeToContent
void SigParseApplyDsizeToContent(Signature *s)
Apply dsize as depth to content matches in the rule.
Definition: detect-dsize.c:327
SignatureInitData_::rule_state_flowbits_ids_array
uint32_t * rule_state_flowbits_ids_array
Definition: detect.h:660
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:934
UniquePortPoint
struct UniquePortPoint_ UniquePortPoint
SignatureInitData_::transforms
DetectEngineTransforms transforms
Definition: detect.h:631
DetectEngineCtx_::io_ctx
DetectEngineIPOnlyCtx io_ctx
Definition: detect.h:970
DetectU16Data
DetectUintData_u16 DetectU16Data
Definition: detect-engine-uint.h:42
DetectPortHashFree
void DetectPortHashFree(DetectEngineCtx *de_ctx)
Frees the hash table - DetectEngineCtx->sgh_hash_table, allocated by DetectPortInit() function.
Definition: detect-engine-port.c:1422
DetectPortHashLookup
DetectPort * DetectPortHashLookup(DetectEngineCtx *de_ctx, DetectPort *dp)
Used to lookup a DetectPort hash from the detection engine context DetectPort hash table.
Definition: detect-engine-port.c:1407
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
DetectEngineCtx_::sig_array_len
uint32_t sig_array_len
Definition: detect.h:951
detect-config.h
DETECT_FLAGS
@ DETECT_FLAGS
Definition: detect-engine-register.h:42
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:281
Signature_::type
enum SignatureType type
Definition: detect.h:671
SignatureIsFilemagicInspecting
int SignatureIsFilemagicInspecting(const Signature *s)
Check if a signature contains the filemagic keyword.
Definition: detect-engine-build.c:120
DetectEngineCtx_::signum
uint32_t signum
Definition: detect.h:953
DetectEngineCtx_::tenant_id
uint32_t tenant_id
Definition: detect.h:939
SigGroupHead_::filestore_cnt
uint16_t filestore_cnt
Definition: detect.h:1633
SignatureInitData_::buffer_index
uint32_t buffer_index
Definition: detect.h:648
DetectMpmPrepareAppMpms
int DetectMpmPrepareAppMpms(DetectEngineCtx *de_ctx)
initialize mpm contexts for applayer buffers that are in "single or "shared" mode.
Definition: detect-engine-mpm.c:295
SIGMATCH_IPONLY_COMPAT
#define SIGMATCH_IPONLY_COMPAT
Definition: detect.h:1651
DetectEngineLookupFlow_::tcp
DetectPort * tcp
Definition: detect.h:862
DetectPortCleanupList
void DetectPortCleanupList(const DetectEngineCtx *de_ctx, DetectPort *head)
Free a DetectPort list and each of its members.
Definition: detect-engine-port.c:124
SIG_TYPE_PDONLY
@ SIG_TYPE_PDONLY
Definition: detect.h:70
SCLogDebugEnabled
int SCLogDebugEnabled(void)
Returns whether debug messages are enabled to be logged or not.
Definition: util-debug.c:767
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
DetectEngineAppInspectionEngine2Signature
int DetectEngineAppInspectionEngine2Signature(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine.c:801
SCPortIntervalTreeFree
void SCPortIntervalTreeFree(DetectEngineCtx *de_ctx, SCPortIntervalTree *it)
Function to free an entire interval tree.
Definition: util-port-interval-tree.c:92
TCPHdr_
Definition: decode-tcp.h:149
detect-engine-address.h
SigGroupHead_::id
uint32_t id
Definition: detect.h:1635
VarNameStoreActivate
int VarNameStoreActivate(void)
Definition: util-var-name.c:214
SIG_FLAG_FILESTORE
#define SIG_FLAG_FILESTORE
Definition: detect.h:269
DETECT_UINT_RA
#define DETECT_UINT_RA
Definition: detect-engine-uint.h:34
SIG_FLAG_DP_ANY
#define SIG_FLAG_DP_ANY
Definition: detect.h:244
DETECT_FLOWBITS_CMD_SET
#define DETECT_FLOWBITS_CMD_SET
Definition: detect-flowbits.h:28
detect-engine-threshold.h
SignatureMask
#define SignatureMask
Definition: decode.h:99
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:390
Signature_::mask
SignatureMask mask
Definition: detect.h:679
SIG_TYPE_LIKE_IPONLY
@ SIG_TYPE_LIKE_IPONLY
Definition: detect.h:67
PacketEngineEvents_::cnt
uint8_t cnt
Definition: decode.h:307
SIG_FLAG_REQUIRE_PACKET
#define SIG_FLAG_REQUIRE_PACKET
Definition: detect.h:254