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  DetectU8Data *fl = (DetectU8Data *)sm->ctx;
483 
484  uint8_t arg = 0;
485  if (fl->mode == DetectUintModeBitmask) {
486  arg = fl->arg2;
487  } else if (fl->mode == DetectUintModeNegBitmask && fl->arg2 == 0) {
488  arg = fl->arg1;
489  } else if (fl->mode == DetectUintModeEqual) {
490  arg = fl->arg1;
491  }
492  if (arg & MASK_TCP_INITDEINIT_FLAGS) {
494  SCLogDebug("sig requires SIG_MASK_REQUIRE_FLAGS_INITDEINIT");
495  }
496  if (arg & MASK_TCP_UNUSUAL_FLAGS) {
498  SCLogDebug("sig requires SIG_MASK_REQUIRE_FLAGS_UNUSUAL");
499  }
500 
501  break;
502  }
503  case DETECT_DSIZE:
504  {
505  DetectU16Data *ds = (DetectU16Data *)sm->ctx;
506  /* LT will include 0, so no payload.
507  * if GT is used in the same rule the
508  * flag will be set anyway. */
509  if (ds->mode == DETECT_UINT_RA || ds->mode == DETECT_UINT_GT ||
510  ds->mode == DETECT_UINT_NE || ds->mode == DETECT_UINT_GTE) {
511 
513  SCLogDebug("sig requires payload");
514 
515  } else if (ds->mode == DETECT_UINT_EQ) {
516  if (ds->arg1 > 0) {
518  SCLogDebug("sig requires payload");
519  } else {
521  SCLogDebug("sig requires no payload");
522  }
523  }
524  break;
525  }
526  case DETECT_DECODE_EVENT:
527  // fallthrough
528  case DETECT_STREAM_EVENT:
529  // fallthrough
531  // fallthrough
532  case DETECT_ENGINE_EVENT:
534  break;
535  }
536  }
537 
538  for (sm = s->init_data->smlists[DETECT_SM_LIST_POSTMATCH]; sm != NULL; sm = sm->next) {
539  switch (sm->type) {
540  case DETECT_CONFIG: {
542  if (fd->scope == CONFIG_SCOPE_FLOW) {
544  }
545  break;
546  }
547  }
548  }
549 
552  SCLogDebug("sig requires flow");
553  }
554 
555  if (s->flags & SIG_FLAG_APPLAYER) {
557  SCLogDebug("sig requires flow");
558  }
559 
560  SCLogDebug("mask %02X", s->mask);
561  SCReturnInt(0);
562 }
563 
564 static void SigInitStandardMpmFactoryContexts(DetectEngineCtx *de_ctx)
565 {
567 }
568 
569 /** \brief Pure-PCRE or bytetest rule */
570 static bool RuleInspectsPayloadHasNoMpm(const Signature *s)
571 {
572  if (s->init_data->mpm_sm == NULL && s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL)
573  return true;
574  return false;
575 }
576 
577 static int RuleGetMpmPatternSize(const Signature *s)
578 {
579  if (s->init_data->mpm_sm == NULL)
580  return -1;
581  int mpm_list = s->init_data->mpm_sm_list;
582  if (mpm_list < 0)
583  return -1;
584  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
585  if (cd == NULL)
586  return -1;
587  return (int)cd->content_len;
588 }
589 
590 static bool RuleMpmIsNegated(const Signature *s)
591 {
592  if (s->flags & SIG_FLAG_MPM_NEG)
593  return true;
594  if (s->init_data->mpm_sm == NULL)
595  return false;
596  int mpm_list = s->init_data->mpm_sm_list;
597  if (mpm_list < 0)
598  return false;
599  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
600  if (cd == NULL)
601  return false;
602  return (cd->flags & DETECT_CONTENT_NEGATED) ? true : false;
603 }
604 
605 static SCJsonBuilder *RulesGroupPrintSghStats(const DetectEngineCtx *de_ctx,
606  const SigGroupHead *sgh, const int add_rules, const int add_mpm_stats)
607 {
608  uint32_t prefilter_cnt = 0;
609  uint32_t mpm_cnt = 0;
610  uint32_t nonmpm_cnt = 0;
611  uint32_t mpm_depth_cnt = 0;
612  uint32_t mpm_endswith_cnt = 0;
613  uint32_t negmpm_cnt = 0;
614  uint32_t any5_cnt = 0;
615  uint32_t payload_no_mpm_cnt = 0;
616  uint32_t syn_cnt = 0;
617 
618  uint32_t mpms_min = 0;
619  uint32_t mpms_max = 0;
620 
621  int max_buffer_type_id = de_ctx->buffer_type_id;
622 
623  struct {
624  uint32_t total;
625  uint32_t cnt;
626  uint32_t min;
627  uint32_t max;
628  } mpm_stats[max_buffer_type_id];
629  memset(mpm_stats, 0x00, sizeof(mpm_stats));
630 
631  uint32_t alstats[g_alproto_max];
632  memset(alstats, 0, g_alproto_max * sizeof(uint32_t));
633  uint32_t mpm_sizes[max_buffer_type_id][256];
634  memset(mpm_sizes, 0, sizeof(mpm_sizes));
635  uint32_t alproto_mpm_bufs[g_alproto_max][max_buffer_type_id];
636  memset(alproto_mpm_bufs, 0, sizeof(alproto_mpm_bufs));
637 
638  DEBUG_VALIDATE_BUG_ON(sgh->init == NULL);
639  if (sgh->init == NULL)
640  return NULL;
641 
642  SCJsonBuilder *js = SCJbNewObject();
643  if (unlikely(js == NULL))
644  return NULL;
645 
646  SCJbSetUint(js, "id", sgh->id);
647 
648  SCJbOpenArray(js, "rules");
649  for (uint32_t x = 0; x < sgh->init->sig_cnt; x++) {
650  const Signature *s = sgh->init->match_array[x];
651  if (s == NULL)
652  continue;
653 
654  int any = 0;
655  if (s->proto.flags & DETECT_PROTO_ANY) {
656  any++;
657  }
658  if (s->flags & SIG_FLAG_DST_ANY) {
659  any++;
660  }
661  if (s->flags & SIG_FLAG_SRC_ANY) {
662  any++;
663  }
664  if (s->flags & SIG_FLAG_DP_ANY) {
665  any++;
666  }
667  if (s->flags & SIG_FLAG_SP_ANY) {
668  any++;
669  }
670  if (any == 5) {
671  any5_cnt++;
672  }
673 
674  prefilter_cnt += (s->init_data->prefilter_sm != NULL);
675  if (s->init_data->mpm_sm == NULL) {
676  nonmpm_cnt++;
677 
678  if (s->sm_arrays[DETECT_SM_LIST_MATCH] != NULL) {
679  SCLogDebug("SGH %p Non-MPM inspecting only packets. Rule %u", sgh, s->id);
680  }
681 
682  DetectPort *sp = s->sp;
683  DetectPort *dp = s->dp;
684 
685  if (s->flags & SIG_FLAG_TOSERVER && (dp->port == 0 && dp->port2 == 65535)) {
686  SCLogDebug("SGH %p Non-MPM toserver and to 'any'. Rule %u", sgh, s->id);
687  }
688  if (s->flags & SIG_FLAG_TOCLIENT && (sp->port == 0 && sp->port2 == 65535)) {
689  SCLogDebug("SGH %p Non-MPM toclient and to 'any'. Rule %u", sgh, s->id);
690  }
691 
693  syn_cnt++;
694  }
695 
696  } else {
697  int mpm_list = s->init_data->mpm_sm_list;
698  BUG_ON(mpm_list < 0);
699  const DetectContentData *cd = (const DetectContentData *)s->init_data->mpm_sm->ctx;
700  uint32_t size = cd->content_len < 256 ? cd->content_len : 255;
701 
702  mpm_sizes[mpm_list][size]++;
703  alproto_mpm_bufs[s->alproto][mpm_list]++;
704 
705  if (mpm_list == DETECT_SM_LIST_PMATCH) {
706  if (size == 1) {
707  DetectPort *sp = s->sp;
708  DetectPort *dp = s->dp;
709  if (s->flags & SIG_FLAG_TOSERVER) {
710  if (dp->port == 0 && dp->port2 == 65535) {
711  SCLogDebug("SGH %p toserver 1byte fast_pattern to ANY. Rule %u", sgh, s->id);
712  } else {
713  SCLogDebug("SGH %p toserver 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, dp->port, dp->port2, s->id);
714  }
715  }
716  if (s->flags & SIG_FLAG_TOCLIENT) {
717  if (sp->port == 0 && sp->port2 == 65535) {
718  SCLogDebug("SGH %p toclient 1byte fast_pattern to ANY. Rule %u", sgh, s->id);
719  } else {
720  SCLogDebug("SGH %p toclient 1byte fast_pattern to port(s) %u-%u. Rule %u", sgh, sp->port, sp->port2, s->id);
721  }
722  }
723  }
724  }
725 
726  uint32_t w = PatternStrength(cd->content, cd->content_len);
727  if (mpms_min == 0)
728  mpms_min = w;
729  if (w < mpms_min)
730  mpms_min = w;
731  if (w > mpms_max)
732  mpms_max = w;
733 
734  BUG_ON(mpm_list >= max_buffer_type_id);
735  mpm_stats[mpm_list].total += w;
736  mpm_stats[mpm_list].cnt++;
737  if (mpm_stats[mpm_list].min == 0 || w < mpm_stats[mpm_list].min)
738  mpm_stats[mpm_list].min = w;
739  if (w > mpm_stats[mpm_list].max)
740  mpm_stats[mpm_list].max = w;
741 
742  mpm_cnt++;
743 
744  if (w < 10) {
745  SCLogDebug("SGH %p Weak MPM Pattern on %s. Rule %u", sgh, DetectListToString(mpm_list), s->id);
746  }
747  if (w < 10 && any == 5) {
748  SCLogDebug("SGH %p Weak MPM Pattern on %s, rule is 5xAny. Rule %u", sgh, DetectListToString(mpm_list), s->id);
749  }
750 
751  if (cd->flags & DETECT_CONTENT_NEGATED) {
752  SCLogDebug("SGH %p MPM Pattern on %s, is negated. Rule %u", sgh, DetectListToString(mpm_list), s->id);
753  negmpm_cnt++;
754  }
755  if (cd->flags & DETECT_CONTENT_ENDS_WITH) {
756  mpm_endswith_cnt++;
757  }
758  if (cd->flags & DETECT_CONTENT_DEPTH) {
759  mpm_depth_cnt++;
760  }
761  }
762 
763  if (RuleInspectsPayloadHasNoMpm(s)) {
764  SCLogDebug("SGH %p No MPM. Payload inspecting. Rule %u", sgh, s->id);
765  payload_no_mpm_cnt++;
766  }
767 
768  alstats[s->alproto]++;
769 
770  if (add_rules) {
771  SCJsonBuilder *e = SCJbNewObject();
772  if (e != NULL) {
773  SCJbSetUint(e, "sig_id", s->id);
774  SCJbClose(e);
775  SCJbAppendObject(js, e);
776  SCJbFree(e);
777  }
778  }
779  }
780  SCJbClose(js);
781 
782  SCJbOpenObject(js, "stats");
783  SCJbSetUint(js, "total", sgh->init->sig_cnt);
784 
785  SCJbOpenObject(js, "types");
786  SCJbSetUint(js, "mpm", mpm_cnt);
787  SCJbSetUint(js, "non_mpm", nonmpm_cnt);
788  SCJbSetUint(js, "mpm_depth", mpm_depth_cnt);
789  SCJbSetUint(js, "mpm_endswith", mpm_endswith_cnt);
790  SCJbSetUint(js, "negated_mpm", negmpm_cnt);
791  SCJbSetUint(js, "payload_but_no_mpm", payload_no_mpm_cnt);
792  SCJbSetUint(js, "prefilter", prefilter_cnt);
793  SCJbSetUint(js, "syn", syn_cnt);
794  SCJbSetUint(js, "any5", any5_cnt);
795  SCJbClose(js);
796 
797  for (AppProto i = 0; i < g_alproto_max; i++) {
798  if (alstats[i] > 0) {
799  const char *proto_name = (i == ALPROTO_UNKNOWN) ? "payload" : AppProtoToString(i);
800  SCJbOpenObject(js, proto_name);
801  SCJbSetUint(js, "total", alstats[i]);
802 
803  for (int y = 0; y < max_buffer_type_id; y++) {
804  if (alproto_mpm_bufs[i][y] == 0)
805  continue;
806 
807  const char *name;
810  else
812 
813  SCJbSetUint(js, name, alproto_mpm_bufs[i][y]);
814  }
815  SCJbClose(js);
816  }
817  }
818 
819  if (add_mpm_stats) {
820  SCJbOpenObject(js, "mpm");
821 
822  for (int i = 0; i < max_buffer_type_id; i++) {
823  if (mpm_stats[i].cnt > 0) {
824  const char *name;
827  else
829 
830  SCJbOpenArray(js, name);
831 
832  for (int y = 0; y < 256; y++) {
833  if (mpm_sizes[i][y] == 0)
834  continue;
835 
836  SCJsonBuilder *e = SCJbNewObject();
837  if (e != NULL) {
838  SCJbSetUint(e, "size", y);
839  SCJbSetUint(e, "count", mpm_sizes[i][y]);
840  SCJbClose(e);
841  SCJbAppendObject(js, e);
842  SCJbFree(e);
843  }
844  }
845 
846  SCJsonBuilder *e = SCJbNewObject();
847  if (e != NULL) {
848  SCJbSetUint(e, "total", mpm_stats[i].cnt);
849  SCJbSetUint(e, "avg_strength", mpm_stats[i].total / mpm_stats[i].cnt);
850  SCJbSetUint(e, "min_strength", mpm_stats[i].min);
851  SCJbSetUint(e, "max_strength", mpm_stats[i].max);
852  SCJbClose(e);
853  SCJbAppendObject(js, e);
854  SCJbFree(e);
855  }
856 
857  SCJbClose(js);
858  }
859  }
860  SCJbClose(js);
861  }
862  SCJbClose(js);
863 
864  SCJbSetUint(js, "score", sgh->init->score);
865  SCJbClose(js);
866 
867  return js;
868 }
869 
870 static void RulesDumpGrouping(const DetectEngineCtx *de_ctx,
871  const int add_rules, const int add_mpm_stats)
872 {
873  SCJsonBuilder *js = SCJbNewObject();
874  if (unlikely(js == NULL))
875  return;
876 
877  for (int p = 0; p < 256; p++) {
878  if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
879  const char *name = (p == IPPROTO_TCP) ? "tcp" : "udp";
880 
881  SCJbOpenObject(js, name);
882  SCJbOpenArray(js, "toserver");
883  const DetectPort *list =
884  (p == IPPROTO_TCP) ? de_ctx->flow_gh[1].tcp : de_ctx->flow_gh[1].udp;
885  while (list != NULL) {
886  SCJsonBuilder *port = SCJbNewObject();
887  SCJbSetUint(port, "port", list->port);
888  SCJbSetUint(port, "port2", list->port2);
889 
890  SCJsonBuilder *stats =
891  RulesGroupPrintSghStats(de_ctx, list->sh, add_rules, add_mpm_stats);
892  SCJbSetObject(port, "rulegroup", stats);
893  SCJbFree(stats);
894  SCJbClose(port);
895  SCJbAppendObject(js, port);
896  SCJbFree(port);
897 
898  list = list->next;
899  }
900  SCJbClose(js); // toserver array
901 
902  SCJbOpenArray(js, "toclient");
903  list = (p == IPPROTO_TCP) ? de_ctx->flow_gh[0].tcp :
904  de_ctx->flow_gh[0].udp;
905  while (list != NULL) {
906  SCJsonBuilder *port = SCJbNewObject();
907  SCJbSetUint(port, "port", list->port);
908  SCJbSetUint(port, "port2", list->port2);
909 
910  SCJsonBuilder *stats =
911  RulesGroupPrintSghStats(de_ctx, list->sh, add_rules, add_mpm_stats);
912  SCJbSetObject(port, "rulegroup", stats);
913  SCJbFree(stats);
914  SCJbClose(port);
915  SCJbAppendObject(js, port);
916  SCJbFree(port);
917 
918  list = list->next;
919  }
920  SCJbClose(js); // toclient array
921  SCJbClose(js);
922  } else if (p == IPPROTO_ICMP || p == IPPROTO_ICMPV6) {
923  const char *name = (p == IPPROTO_ICMP) ? "icmpv4" : "icmpv6";
924  SCJbOpenObject(js, name);
925  if (de_ctx->flow_gh[1].sgh[p]) {
926  SCJbOpenObject(js, "toserver");
927  SCJsonBuilder *stats = RulesGroupPrintSghStats(
928  de_ctx, de_ctx->flow_gh[1].sgh[p], add_rules, add_mpm_stats);
929  SCJbSetObject(js, "rulegroup", stats);
930  SCJbFree(stats);
931  SCJbClose(js);
932  }
933  if (de_ctx->flow_gh[0].sgh[p]) {
934  SCJbOpenObject(js, "toclient");
935  SCJsonBuilder *stats = RulesGroupPrintSghStats(
936  de_ctx, de_ctx->flow_gh[0].sgh[p], add_rules, add_mpm_stats);
937  SCJbSetObject(js, "rulegroup", stats);
938  SCJbFree(stats);
939  SCJbClose(js);
940  }
941  SCJbClose(js);
942  }
943  }
944  SCJbClose(js);
945 
946  const char *filename = "rule_group.json";
947  const char *log_dir = SCConfigGetLogDirectory();
948  char log_path[PATH_MAX] = "";
949  snprintf(log_path, sizeof(log_path), "%s/%s", log_dir, filename);
950 
951  FILE *fp = fopen(log_path, "w");
952  if (fp != NULL) {
953  fwrite(SCJbPtr(js), SCJbLen(js), 1, fp);
954  (void)fclose(fp);
955  }
956  SCJbFree(js);
957 }
958 
959 static int RulesGroupByIPProto(DetectEngineCtx *de_ctx)
960 {
961  Signature *s = de_ctx->sig_list;
962 
963  SigGroupHead *sgh_ts[256] = {NULL};
964  SigGroupHead *sgh_tc[256] = {NULL};
965 
966  for ( ; s != NULL; s = s->next) {
967  if (s->type == SIG_TYPE_IPONLY)
968  continue;
969 
970  /* traverse over IP protocol list from libc */
971  for (int p = 0; p < 256; p++) {
972  if (p == IPPROTO_TCP || p == IPPROTO_UDP) {
973  continue;
974  }
975  if (!(s->proto.proto[p / 8] & (1<<(p % 8)) || (s->proto.flags & DETECT_PROTO_ANY))) {
976  continue;
977  }
978 
979  /* Signatures that are ICMP, SCTP, not IP only are handled here */
980  if (s->flags & SIG_FLAG_TOCLIENT) {
981  SigGroupHeadAppendSig(de_ctx, &sgh_tc[p], s);
982  }
983  if (s->flags & SIG_FLAG_TOSERVER) {
984  SigGroupHeadAppendSig(de_ctx, &sgh_ts[p], s);
985  }
986  }
987  }
988 
989  /* lets look at deduplicating this list */
992 
993  uint32_t cnt = 0;
994  uint32_t own = 0;
995  uint32_t ref = 0;
996  int p;
997  for (p = 0; p < 256; p++) {
998  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
999  continue;
1000  if (sgh_ts[p] == NULL)
1001  continue;
1002 
1003  cnt++;
1004 
1005  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, sgh_ts[p]);
1006  if (lookup_sgh == NULL) {
1007  SCLogDebug("proto group %d sgh %p is the original", p, sgh_ts[p]);
1008 
1009  SigGroupHeadSetSigCnt(sgh_ts[p], 0);
1010  SigGroupHeadBuildMatchArray(de_ctx, sgh_ts[p], 0);
1011 
1012  SigGroupHeadHashAdd(de_ctx, sgh_ts[p]);
1013  SigGroupHeadStore(de_ctx, sgh_ts[p]);
1014  own++;
1015  } else {
1016  SCLogDebug("proto group %d sgh %p is a copy", p, sgh_ts[p]);
1017 
1018  SigGroupHeadFree(de_ctx, sgh_ts[p]);
1019  sgh_ts[p] = lookup_sgh;
1020  ref++;
1021  }
1022  }
1023  SCLogPerf("OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1024  "toserver", cnt, own, ref);
1025 
1026  cnt = 0;
1027  own = 0;
1028  ref = 0;
1029  for (p = 0; p < 256; p++) {
1030  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1031  continue;
1032  if (sgh_tc[p] == NULL)
1033  continue;
1034 
1035  cnt++;
1036 
1037  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, sgh_tc[p]);
1038  if (lookup_sgh == NULL) {
1039  SCLogDebug("proto group %d sgh %p is the original", p, sgh_tc[p]);
1040 
1041  SigGroupHeadSetSigCnt(sgh_tc[p], 0);
1042  SigGroupHeadBuildMatchArray(de_ctx, sgh_tc[p], 0);
1043 
1044  SigGroupHeadHashAdd(de_ctx, sgh_tc[p]);
1045  SigGroupHeadStore(de_ctx, sgh_tc[p]);
1046  own++;
1047 
1048  } else {
1049  SCLogDebug("proto group %d sgh %p is a copy", p, sgh_tc[p]);
1050 
1051  SigGroupHeadFree(de_ctx, sgh_tc[p]);
1052  sgh_tc[p] = lookup_sgh;
1053  ref++;
1054  }
1055  }
1056  SCLogPerf("OTHER %s: %u proto groups, %u unique SGH's, %u copies",
1057  "toclient", cnt, own, ref);
1058 
1059  for (p = 0; p < 256; p++) {
1060  if (p == IPPROTO_TCP || p == IPPROTO_UDP)
1061  continue;
1062 
1063  de_ctx->flow_gh[0].sgh[p] = sgh_tc[p];
1064  de_ctx->flow_gh[1].sgh[p] = sgh_ts[p];
1065  }
1066 
1067  return 0;
1068 }
1069 
1070 static int PortIsPriority(const DetectEngineCtx *de_ctx, const DetectPort *a, int ipproto)
1071 {
1073  if (ipproto == IPPROTO_UDP)
1075 
1076  while (w) {
1077  /* Make sure the priority port falls in the port range of a */
1078  DEBUG_VALIDATE_BUG_ON(a->port > a->port2);
1079  if (a->port == w->port && w->port2 == a->port2) {
1080  return 1;
1081  }
1082  w = w->next;
1083  }
1084 
1085  return 0;
1086 }
1087 
1088 static int RuleSetScore(Signature *s)
1089 {
1090  DetectPort *p = NULL;
1091  if (s->flags & SIG_FLAG_TOSERVER)
1092  p = s->dp;
1093  else if (s->flags & SIG_FLAG_TOCLIENT)
1094  p = s->sp;
1095  else
1096  return 0;
1097 
1098  /* for sigs that don't use 'any' as port, see if we want to
1099  * prioritize poor sigs */
1100  int wl = 0;
1101  if (!(p->port == 0 && p->port2 == 65535)) {
1102  /* pure pcre, bytetest, etc rules */
1103  if (RuleInspectsPayloadHasNoMpm(s)) {
1104  SCLogDebug("Rule %u MPM has 1 byte fast_pattern. Prioritizing SGH's.", s->id);
1106 
1107  } else if (RuleMpmIsNegated(s)) {
1108  SCLogDebug("Rule %u MPM is negated. Prioritizing SGH's.", s->id);
1110 
1111  /* one byte pattern in packet/stream payloads */
1112  } else if (s->init_data->mpm_sm != NULL &&
1114  RuleGetMpmPatternSize(s) == 1) {
1115  SCLogDebug("Rule %u No MPM. Payload inspecting. Prioritizing SGH's.", s->id);
1117 
1119  SCLogDebug("Rule %u Needs SYN, so inspected often. Prioritizing SGH's.", s->id);
1121  }
1122  }
1123 
1124  s->init_data->score = wl;
1125  return wl;
1126 }
1127 
1128 static int SortCompare(const void *a, const void *b)
1129 {
1130  const DetectPort *pa = *(const DetectPort **)a;
1131  const DetectPort *pb = *(const DetectPort **)b;
1132 
1133  if (pa->sh->init->score < pb->sh->init->score) {
1134  return 1;
1135  } else if (pa->sh->init->score > pb->sh->init->score) {
1136  return -1;
1137  }
1138 
1139  if (pa->sh->init->sig_cnt < pb->sh->init->sig_cnt) {
1140  return 1;
1141  } else if (pa->sh->init->sig_cnt > pb->sh->init->sig_cnt) {
1142  return -1;
1143  }
1144 
1145  /* Hack to make the qsort output deterministic across platforms.
1146  * This had to be done because the order of equal elements sorted
1147  * by qsort is undeterministic and showed different output on BSD,
1148  * MacOS and Windows. Sorting based on id makes it deterministic. */
1149  if (pa->sh->id < pb->sh->id)
1150  return -1;
1151 
1152  return 1;
1153 }
1154 
1155 static inline void SortGroupList(
1156  uint32_t *groups, DetectPort **list, int (*CompareFunc)(const void *, const void *))
1157 {
1158  int cnt = 0;
1159  for (DetectPort *x = *list; x != NULL; x = x->next) {
1160  DEBUG_VALIDATE_BUG_ON(x->port > x->port2);
1161  cnt++;
1162  }
1163  if (cnt <= 1)
1164  return;
1165 
1166  /* build temporary array to sort with qsort */
1167  DetectPort **array = (DetectPort **)SCCalloc(cnt, sizeof(DetectPort *));
1168  if (array == NULL)
1169  return;
1170 
1171  int idx = 0;
1172  for (DetectPort *x = *list; x != NULL;) {
1173  /* assign a temporary id to resolve otherwise equal groups */
1174  x->sh->id = idx + 1;
1175  SigGroupHeadSetSigCnt(x->sh, 0);
1176  DetectPort *next = x->next;
1177  x->next = x->prev = x->last = NULL;
1178  DEBUG_VALIDATE_BUG_ON(x->port > x->port2);
1179  array[idx++] = x;
1180  x = next;
1181  }
1182  DEBUG_VALIDATE_BUG_ON(cnt != idx);
1183 
1184  qsort(array, idx, sizeof(DetectPort *), SortCompare);
1185 
1186  /* rebuild the list based on the qsort-ed array */
1187  DetectPort *new_list = NULL, *tail = NULL;
1188  for (int i = 0; i < idx; i++) {
1189  DetectPort *p = array[i];
1190  /* unset temporary group id */
1191  p->sh->id = 0;
1192 
1193  if (new_list == NULL) {
1194  new_list = p;
1195  }
1196  if (tail != NULL) {
1197  tail->next = p;
1198  }
1199  p->prev = tail;
1200  tail = p;
1201  }
1202 
1203  *list = new_list;
1204  *groups = idx;
1205 
1206 #if DEBUG
1207  int dbgcnt = 0;
1208  SCLogDebug("SORTED LIST:");
1209  for (DetectPort *tmp = *list; tmp != NULL; tmp = tmp->next) {
1210  SCLogDebug("item:= [%u:%u]; score: %d; sig_cnt: %d", tmp->port, tmp->port2,
1211  tmp->sh->init->score, tmp->sh->init->sig_cnt);
1212  dbgcnt++;
1213  BUG_ON(dbgcnt > cnt);
1214  }
1215 #endif
1216  SCFree(array);
1217 }
1218 /** \internal
1219  * \brief Create a list of DetectPort objects sorted based on CompareFunc's
1220  * logic.
1221  *
1222  * List can limit the number of groups. In this case an extra "join" group
1223  * is created that contains the sigs belonging to that. It's *appended* to
1224  * the list, meaning that if the list is walked linearly it's found last.
1225  * The joingr is meant to be a catch all.
1226  *
1227  */
1228 static int CreateGroupedPortList(DetectEngineCtx *de_ctx, DetectPort *port_list,
1229  DetectPort **newhead, uint32_t unique_groups,
1230  int (*CompareFunc)(const void *, const void *))
1231 {
1232  DetectPort *tmplist = NULL, *joingr = NULL;
1233  uint32_t groups = 0;
1234 
1235  /* insert the ports into the tmplist, where it will
1236  * be sorted descending on 'cnt' and on whether a group
1237  * is prioritized. */
1238  tmplist = port_list;
1239  SortGroupList(&groups, &tmplist, SortCompare);
1240  uint32_t left = unique_groups;
1241  if (left == 0)
1242  left = groups;
1243 
1244  /* create another list: take the port groups from above
1245  * and add them to the 2nd list until we have met our
1246  * count. The rest is added to the 'join' group. */
1247  DetectPort *tmplist2 = NULL, *tmplist2_tail = NULL;
1248  DetectPort *gr, *next_gr;
1249  for (gr = tmplist; gr != NULL;) {
1250  next_gr = gr->next;
1251 
1252  SCLogDebug("temp list gr %p %u:%u", gr, gr->port, gr->port2);
1253  DetectPortPrint(gr);
1254 
1255  /* if we've set up all the unique groups, add the rest to the
1256  * catch-all joingr */
1257  if (left == 0) {
1258  if (joingr == NULL) {
1259  DetectPortParse(de_ctx, &joingr, "0:65535");
1260  if (joingr == NULL) {
1261  goto error;
1262  }
1263  SCLogDebug("joingr => %u-%u", joingr->port, joingr->port2);
1264  joingr->next = NULL;
1265  }
1266  SigGroupHeadCopySigs(de_ctx, gr->sh, &joingr->sh);
1267 
1268  /* when a group's sigs are added to the joingr, we can free it */
1269  gr->next = NULL;
1270  DetectPortFree(de_ctx, gr);
1271  /* append */
1272  } else {
1273  gr->next = NULL;
1274 
1275  if (tmplist2 == NULL) {
1276  tmplist2 = gr;
1277  tmplist2_tail = gr;
1278  } else {
1279  tmplist2_tail->next = gr;
1280  tmplist2_tail = gr;
1281  }
1282  }
1283 
1284  if (left > 0)
1285  left--;
1286 
1287  gr = next_gr;
1288  }
1289 
1290  /* if present, append the joingr that covers the rest */
1291  if (joingr != NULL) {
1292  SCLogDebug("appending joingr %p %u:%u", joingr, joingr->port, joingr->port2);
1293 
1294  if (tmplist2 == NULL) {
1295  tmplist2 = joingr;
1296  // tmplist2_tail = joingr;
1297  } else {
1298  tmplist2_tail->next = joingr;
1299  // tmplist2_tail = joingr;
1300  }
1301  } else {
1302  SCLogDebug("no joingr");
1303  }
1304 
1305  /* pass back our new list to the caller */
1306  *newhead = tmplist2;
1307  DetectPortPrintList(*newhead);
1308 
1309  return 0;
1310 error:
1311  return -1;
1312 }
1313 
1314 #define UNDEFINED_PORT 0
1315 #define RANGE_PORT 1
1316 #define SINGLE_PORT 2
1318 typedef struct UniquePortPoint_ {
1319  uint16_t port; /* value of the port */
1320  bool single; /* is the port single or part of a range */
1322 
1323 /**
1324  * \brief Function to set unique port points. Consider all the ports
1325  * flattened out on one line, set the points that correspond
1326  * to a valid port. Also store whether the port point stored
1327  * was a single port or part of a range.
1328  *
1329  * \param p Port object to be set
1330  * \param unique_list List of unique port points to be updated
1331  * \param size_list Current size of the list
1332  *
1333  * \return Updated size of the list
1334  */
1335 static inline uint32_t SetUniquePortPoints(
1336  const DetectPort *p, uint8_t *unique_list, uint32_t size_list)
1337 {
1338  if (unique_list[p->port] == UNDEFINED_PORT) {
1339  if (p->port == p->port2) {
1340  unique_list[p->port] = SINGLE_PORT;
1341  } else {
1342  unique_list[p->port] = RANGE_PORT;
1343  }
1344  size_list++;
1345  } else if (((unique_list[p->port] == SINGLE_PORT) && (p->port != p->port2)) ||
1346  ((unique_list[p->port] == RANGE_PORT) && (p->port == p->port2))) {
1347  if ((p->port != UINT16_MAX) && (unique_list[p->port + 1] == UNDEFINED_PORT)) {
1348  unique_list[p->port + 1] = RANGE_PORT;
1349  size_list++;
1350  }
1351  }
1352 
1353  /* Treat right boundary as single point to avoid creating unneeded
1354  * ranges later on */
1355  if (unique_list[p->port2] == UNDEFINED_PORT) {
1356  size_list++;
1357  }
1358  unique_list[p->port2] = SINGLE_PORT;
1359  return size_list;
1360 }
1361 
1362 /**
1363  * \brief Function to set the *final* unique port points and save them
1364  * for later use. The points are already sorted because of the way
1365  * they have been retrieved and saved earlier for use at this point.
1366  *
1367  * \param unique_list List of the unique port points to be used
1368  * \param size_unique_arr Number of unique port points
1369  * \param final_arr List of the final unique port points to be created
1370  */
1371 static inline void SetFinalUniquePortPoints(
1372  const uint8_t *unique_list, const uint32_t size_unique_arr, UniquePortPoint *final_arr)
1373 {
1374  for (uint32_t i = 0, j = 0; i < (UINT16_MAX + 1); i++) {
1375  DEBUG_VALIDATE_BUG_ON(j > size_unique_arr);
1376  if (unique_list[i] == RANGE_PORT) {
1377  final_arr[j].port = (uint16_t)i;
1378  final_arr[j++].single = false;
1379  } else if (unique_list[i] == SINGLE_PORT) {
1380  final_arr[j].port = (uint16_t)i;
1381  final_arr[j++].single = true;
1382  }
1383  }
1384 }
1385 
1386 /**
1387  * \brief Function to create the list of ports with the smallest ranges
1388  * by resolving overlaps and end point conditions. These contain the
1389  * correct SGHs as well after going over the interval tree to find
1390  * any range overlaps.
1391  *
1392  * \param de_ctx Detection Engine Context
1393  * \param unique_list Final list of unique port points
1394  * \param size_list Size of the unique_list
1395  * \param it Pointer to the interval tree
1396  * \param list Pointer to the list where final ports will be stored
1397  *
1398  * \return 0 on success, -1 otherwise
1399  */
1400 static inline int CreatePortList(DetectEngineCtx *de_ctx, const uint8_t *unique_list,
1401  const uint32_t size_list, SCPortIntervalTree *it, DetectPort **list)
1402 {
1403  /* Only do the operations if there is at least one unique port */
1404  if (size_list == 0)
1405  return 0;
1406  UniquePortPoint *final_unique_points =
1407  (UniquePortPoint *)SCCalloc(size_list, sizeof(UniquePortPoint));
1408  if (final_unique_points == NULL)
1409  return -1;
1410  SetFinalUniquePortPoints(unique_list, size_list, final_unique_points);
1411  /* Handle edge case when there is just one unique port */
1412  if (size_list == 1) {
1414  de_ctx, final_unique_points[0].port, final_unique_points[0].port, &it->tree, list);
1415  } else {
1416  UniquePortPoint *p1 = &final_unique_points[0];
1417  UniquePortPoint *p2 = &final_unique_points[1];
1418  uint16_t port = p1 ? p1->port : 0; // just for cppcheck
1419  uint16_t port2 = p2->port;
1420  for (uint32_t i = 1; i < size_list; i++) {
1421  DEBUG_VALIDATE_BUG_ON(port > port2);
1422  if ((p1 && p1->single) && p2->single) {
1423  SCPortIntervalFindOverlappingRanges(de_ctx, port, port, &it->tree, list);
1424  SCPortIntervalFindOverlappingRanges(de_ctx, port2, port2, &it->tree, list);
1425  port = port2 + 1;
1426  } else if (p1 && p1->single) {
1427  SCPortIntervalFindOverlappingRanges(de_ctx, port, port, &it->tree, list);
1428  if ((port2 > port + 1)) {
1430  de_ctx, port + 1, port2 - 1, &it->tree, list);
1431  port = port2;
1432  } else {
1433  port = port + 1;
1434  }
1435  } else if (p2->single) {
1436  /* If port2 is boundary and less or equal to port + 1, create a range
1437  * keeping the boundary away as it is single port */
1438  if ((port2 >= port + 1)) {
1439  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2 - 1, &it->tree, list);
1440  }
1441  /* Deal with port2 as it is a single port */
1442  SCPortIntervalFindOverlappingRanges(de_ctx, port2, port2, &it->tree, list);
1443  port = port2 + 1;
1444  } else {
1445  if ((port2 > port + 1)) {
1446  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2 - 1, &it->tree, list);
1447  port = port2;
1448  } else {
1449  SCPortIntervalFindOverlappingRanges(de_ctx, port, port2, &it->tree, list);
1450  port = port2 + 1;
1451  }
1452  }
1453  /* if the current port matches the p2->port, assign it to p1 so that
1454  * there is a UniquePortPoint object to check other info like whether
1455  * the port with this value is single */
1456  if (port == p2->port) {
1457  p1 = p2;
1458  } else {
1459  p1 = NULL;
1460  }
1461  if (i + 1 < size_list) {
1462  p2 = &final_unique_points[i + 1];
1463  port2 = p2->port;
1464  }
1465  }
1466  }
1467  /* final_unique_points array is no longer needed */
1468  SCFree(final_unique_points);
1469  return 0;
1470 }
1471 
1472 static DetectPort *RulesGroupByPorts(DetectEngineCtx *de_ctx, uint8_t ipproto, uint32_t direction)
1473 {
1474  /* step 1: create a hash of 'DetectPort' objects based on all the
1475  * rules. Each object will have a SGH with the sigs added
1476  * that belong to the SGH. */
1478 
1479  uint32_t size_unique_port_arr = 0;
1480  const Signature *s = de_ctx->sig_list;
1481  DetectPort *list = NULL;
1482 
1483  uint8_t *unique_port_points = (uint8_t *)SCCalloc(UINT16_MAX + 1, sizeof(uint8_t));
1484  if (unique_port_points == NULL)
1485  return NULL;
1486 
1487  while (s) {
1488  /* IP Only rules are handled separately */
1489  if (s->type == SIG_TYPE_IPONLY)
1490  goto next;
1491  /* Protocol does not match the Signature protocol and is neither IP or pkthdr */
1492  if (!(s->proto.proto[ipproto / 8] & (1<<(ipproto % 8)) || (s->proto.flags & DETECT_PROTO_ANY)))
1493  goto next;
1494  /* Direction does not match Signature direction */
1495  if (direction == SIG_FLAG_TOSERVER) {
1496  if (!(s->flags & SIG_FLAG_TOSERVER))
1497  goto next;
1498  } else if (direction == SIG_FLAG_TOCLIENT) {
1499  if (!(s->flags & SIG_FLAG_TOCLIENT))
1500  goto next;
1501  }
1502 
1503  /* see if we want to exclude directionless sigs that really care only for
1504  * to_server syn scans/floods */
1508  (!(s->dp->port == 0 && s->dp->port2 == 65535))) {
1509  SCLogWarning("rule %u: SYN-only to port(s) %u:%u "
1510  "w/o direction specified, disabling for toclient direction",
1511  s->id, s->dp->port, s->dp->port2);
1512  goto next;
1513  }
1514 
1515  DetectPort *p = NULL;
1516  if (direction == SIG_FLAG_TOSERVER)
1517  p = s->dp;
1518  else if (direction == SIG_FLAG_TOCLIENT)
1519  p = s->sp;
1520  else
1521  BUG_ON(1);
1522 
1523  int wl = s->init_data->score;
1524  while (p) {
1525  int pwl = PortIsPriority(de_ctx, p, ipproto) ? DETECT_PGSCORE_RULE_PORT_PRIORITIZED : 0;
1526  pwl = MAX(wl,pwl);
1527 
1528  DetectPort *lookup = DetectPortHashLookup(de_ctx, p);
1529  if (lookup) {
1530  SigGroupHeadAppendSig(de_ctx, &lookup->sh, s);
1531  lookup->sh->init->score = MAX(lookup->sh->init->score, pwl);
1532  } else {
1534  BUG_ON(tmp2 == NULL);
1535  SigGroupHeadAppendSig(de_ctx, &tmp2->sh, s);
1536  tmp2->sh->init->score = pwl;
1537  DetectPortHashAdd(de_ctx, tmp2);
1538  size_unique_port_arr =
1539  SetUniquePortPoints(tmp2, unique_port_points, size_unique_port_arr);
1540  }
1541 
1542  p = p->next;
1543  }
1544  next:
1545  s = s->next;
1546  }
1547 
1548  /* step 2: create a list of the smallest port ranges with
1549  * appropriate SGHs */
1550 
1551  /* Create an interval tree of all the given ports to make the search
1552  * for overlaps later on easier */
1554  if (it == NULL)
1555  goto error;
1556 
1557  HashListTableBucket *htb = NULL;
1558  for (htb = HashListTableGetListHead(de_ctx->dport_hash_table); htb != NULL;
1559  htb = HashListTableGetListNext(htb)) {
1561  if (SCPortIntervalInsert(de_ctx, it, p) != SC_OK) {
1562  SCLogDebug("Port was not inserted in the tree");
1563  goto error;
1564  }
1565  }
1566 
1567  /* Create a sorted list of ports in ascending order after resolving overlaps
1568  * and corresponding SGHs */
1569  if (CreatePortList(de_ctx, unique_port_points, size_unique_port_arr, it, &list) < 0)
1570  goto error;
1571 
1572  /* unique_port_points array is no longer needed */
1573  SCFree(unique_port_points);
1574 
1575  /* Port hashes are no longer needed */
1577 
1578  SCLogDebug("rules analyzed");
1579 
1580  /* step 3: group the list and shrink it if necessary */
1581  DetectPort *newlist = NULL;
1582  uint16_t groupmax = (direction == SIG_FLAG_TOCLIENT) ? de_ctx->max_uniq_toclient_groups :
1584  CreateGroupedPortList(de_ctx, list, &newlist, groupmax, SortCompare);
1585  list = newlist;
1586 
1587  /* step 4: deduplicate the SGH's */
1590 
1591  uint32_t cnt = 0;
1592  uint32_t own = 0;
1593  uint32_t ref = 0;
1594  DetectPort *iter;
1595  for (iter = list ; iter != NULL; iter = iter->next) {
1596  BUG_ON (iter->sh == NULL);
1597  DEBUG_VALIDATE_BUG_ON(own + ref != cnt);
1598  cnt++;
1599 
1600  SigGroupHead *lookup_sgh = SigGroupHeadHashLookup(de_ctx, iter->sh);
1601  if (lookup_sgh == NULL) {
1602  SCLogDebug("port group %p sgh %p is the original", iter, iter->sh);
1603 
1604  SigGroupHeadSetSigCnt(iter->sh, 0);
1606  SigGroupHeadSetProtoAndDirection(iter->sh, ipproto, direction);
1607  SigGroupHeadHashAdd(de_ctx, iter->sh);
1608  SigGroupHeadStore(de_ctx, iter->sh);
1609  iter->flags |= PORT_SIGGROUPHEAD_COPY;
1610  own++;
1611  } else {
1612  SCLogDebug("port group %p sgh %p is a copy", iter, iter->sh);
1613 
1614  SigGroupHeadFree(de_ctx, iter->sh);
1615  iter->sh = lookup_sgh;
1616  iter->flags |= PORT_SIGGROUPHEAD_COPY;
1617  ref++;
1618  }
1619  }
1620 #if 0
1621  for (iter = list ; iter != NULL; iter = iter->next) {
1622  SCLogInfo("PORT %u-%u %p (sgh=%s, prioritized=%s/%d)",
1623  iter->port, iter->port2, iter->sh,
1624  iter->flags & PORT_SIGGROUPHEAD_COPY ? "ref" : "own",
1625  iter->sh->init->score ? "true" : "false",
1626  iter->sh->init->score);
1627  }
1628 #endif
1629  SCLogPerf("%s %s: %u port groups, %u unique SGH's, %u copies",
1630  ipproto == 6 ? "TCP" : "UDP",
1631  direction == SIG_FLAG_TOSERVER ? "toserver" : "toclient",
1632  cnt, own, ref);
1634  return list;
1635 
1636 error:
1637  if (unique_port_points != NULL)
1638  SCFree(unique_port_points);
1639  if (it != NULL)
1641 
1642  return NULL;
1643 }
1644 
1646 {
1647  BUG_ON(s->type != SIG_TYPE_NOT_SET);
1648  int iponly = 0;
1649 
1651  s->type = SIG_TYPE_APP_TX;
1652  SCLogDebug("%u: set to app_tx due to hook type app", s->id);
1653  SCReturn;
1654  }
1655 
1656  /* see if the sig is dp only */
1657  if (SignatureIsPDOnly(de_ctx, s) == 1) {
1658  s->type = SIG_TYPE_PDONLY;
1659 
1660  /* see if the sig is ip only */
1661  } else if ((iponly = SignatureIsIPOnly(de_ctx, s)) > 0) {
1662  if (iponly == 1) {
1663  s->type = SIG_TYPE_IPONLY;
1664  } else if (iponly == 2) {
1666  }
1667  } else if (SignatureIsDEOnly(de_ctx, s) == 1) {
1668  s->type = SIG_TYPE_DEONLY;
1669 
1670  } else {
1671  const bool has_match = s->init_data->smlists[DETECT_SM_LIST_MATCH] != NULL;
1672  const bool has_pmatch = s->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL;
1673  bool has_buffer_frame_engine = false;
1674  bool has_buffer_packet_engine = false;
1675  bool has_buffer_app_engine = false;
1676 
1677  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
1678  const uint32_t id = s->init_data->buffers[x].id;
1679 
1681  has_buffer_packet_engine = true;
1683  has_buffer_frame_engine = true;
1684  } else {
1685  has_buffer_app_engine = true;
1686  }
1687  }
1688 
1689  if (has_buffer_packet_engine) {
1690  s->type = SIG_TYPE_PKT;
1691  } else if (has_buffer_frame_engine || has_buffer_app_engine) {
1692  s->type = SIG_TYPE_APP_TX;
1693  } else if (has_pmatch) {
1696  s->type = SIG_TYPE_PKT;
1697  } else if ((s->flags & (SIG_FLAG_REQUIRE_PACKET | SIG_FLAG_REQUIRE_STREAM)) ==
1699  s->type = SIG_TYPE_STREAM;
1700  } else {
1702  }
1703  } else if (has_match) {
1704  s->type = SIG_TYPE_PKT;
1705 
1706  /* app-layer but no inspect engines */
1707  } else if (s->flags & SIG_FLAG_APPLAYER) {
1708  s->type = SIG_TYPE_APPLAYER;
1709  } else {
1710  s->type = SIG_TYPE_PKT;
1711  }
1712  }
1713 }
1714 
1715 /**
1716  * \brief Preprocess signature, classify ip-only, etc, build sig array
1717  *
1718  * \param de_ctx Pointer to the Detection Engine Context
1719  *
1720  * \retval 0 on success
1721  * \retval -1 on failure
1722  */
1724 {
1725  uint32_t cnt_iponly = 0;
1726  uint32_t cnt_payload = 0;
1727  uint32_t cnt_applayer = 0;
1728  uint32_t cnt_deonly = 0;
1729 
1730  if (!(de_ctx->flags & DE_QUIET)) {
1731  SCLogDebug("building signature grouping structure, stage 1: "
1732  "preprocessing rules...");
1733  }
1734 
1737  if (de_ctx->sig_array == NULL)
1738  goto error;
1739 
1740  /* now for every rule add the source group */
1741  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
1742  de_ctx->sig_array[s->iid] = s;
1743 
1744  SCLogDebug("Signature %" PRIu32 ", internal id %" PRIu32 ", ptrs %p %p ", s->id, s->iid, s,
1745  de_ctx->sig_array[s->iid]);
1746 
1747  if (s->type == SIG_TYPE_PDONLY) {
1748  SCLogDebug("Signature %"PRIu32" is considered \"PD only\"", s->id);
1749  } else if (s->type == SIG_TYPE_IPONLY) {
1750  SCLogDebug("Signature %"PRIu32" is considered \"IP only\"", s->id);
1751  cnt_iponly++;
1752  } else if (SignatureIsInspectingPayload(de_ctx, s) == 1) {
1753  SCLogDebug("Signature %"PRIu32" is considered \"Payload inspecting\"", s->id);
1754  cnt_payload++;
1755  } else if (s->type == SIG_TYPE_DEONLY) {
1756  SCLogDebug("Signature %"PRIu32" is considered \"Decoder Event only\"", s->id);
1757  cnt_deonly++;
1758  } else if (s->flags & SIG_FLAG_APPLAYER) {
1759  SCLogDebug("Signature %"PRIu32" is considered \"Applayer inspecting\"", s->id);
1760  cnt_applayer++;
1761  }
1762 
1763 #ifdef DEBUG
1764  if (SCLogDebugEnabled()) {
1765  uint16_t colen = 0;
1766  char copresent = 0;
1767  SigMatch *sm;
1768  DetectContentData *co;
1769  for (sm = s->init_data->smlists[DETECT_SM_LIST_MATCH]; sm != NULL; sm = sm->next) {
1770  if (sm->type != DETECT_CONTENT)
1771  continue;
1772 
1773  copresent = 1;
1774  co = (DetectContentData *)sm->ctx;
1775  if (co->content_len > colen)
1776  colen = co->content_len;
1777  }
1778 
1779  if (copresent && colen == 1) {
1780  SCLogDebug("signature %8u content maxlen 1", s->id);
1781  for (int proto = 0; proto < 256; proto++) {
1782  if (s->proto.proto[(proto/8)] & (1<<(proto%8)))
1783  SCLogDebug("=> proto %" PRId32 "", proto);
1784  }
1785  }
1786  }
1787 #endif /* DEBUG */
1788 
1789  if (RuleMpmIsNegated(s)) {
1790  s->flags |= SIG_FLAG_MPM_NEG;
1791  }
1792 
1793  SignatureCreateMask(s);
1796 
1797  RuleSetScore(s);
1798 
1799  /* run buffer type callbacks if any */
1800  for (int x = 0; x < DETECT_SM_LIST_MAX; x++) {
1801  if (s->init_data->smlists[x])
1803  }
1804  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
1806  }
1807 
1808  de_ctx->sig_cnt++;
1809  }
1810 
1811  if (!(de_ctx->flags & DE_QUIET)) {
1812  if (strlen(de_ctx->config_prefix) > 0)
1813  SCLogInfo("tenant id %d: %" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
1814  "rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
1815  " inspect application layer, %" PRIu32 " are decoder event only",
1816  de_ctx->tenant_id, de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer,
1817  cnt_deonly);
1818  else
1819  SCLogInfo("%" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
1820  "rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
1821  " inspect application layer, %" PRIu32 " are decoder event only",
1822  de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer, cnt_deonly);
1823 
1824  SCLogConfig("building signature grouping structure, stage 1: "
1825  "preprocessing rules... complete");
1826  }
1827 
1828  if (DetectFlowbitsAnalyze(de_ctx) != 0)
1829  goto error;
1830 
1831  return 0;
1832 
1833 error:
1834  return -1;
1835 }
1836 
1837 /**
1838  * \internal
1839  * \brief add a decoder event signature to the detection engine ctx
1840  */
1841 static void DetectEngineAddDecoderEventSig(DetectEngineCtx *de_ctx, Signature *s)
1842 {
1843  SCLogDebug("adding signature %"PRIu32" to the decoder event sgh", s->id);
1845 }
1846 
1847 static void DetectEngineAddSigToPreStreamHook(DetectEngineCtx *de_ctx, Signature *s)
1848 {
1849  SCLogDebug("adding signature %" PRIu32 " to the pre_stream hook sgh", s->id);
1850 
1851  if ((s->flags & (SIG_FLAG_TOSERVER | SIG_FLAG_TOCLIENT)) ==
1855  } else if (s->flags & SIG_FLAG_TOSERVER) {
1857  } else if (s->flags & SIG_FLAG_TOCLIENT) {
1859  }
1860 }
1861 
1862 static void DetectEngineAddSigToPreFlowHook(DetectEngineCtx *de_ctx, Signature *s)
1863 {
1864  SCLogDebug("adding signature %" PRIu32 " to the pre_flow hook sgh", s->id);
1866 }
1867 
1868 /**
1869  * \brief Fill the global src group head, with the sigs included
1870  *
1871  * \param de_ctx Pointer to the Detection Engine Context whose Signatures have
1872  * to be processed
1873  *
1874  * \retval 0 On success
1875  * \retval -1 On failure
1876  */
1878 {
1879  SCLogDebug("building signature grouping structure, stage 2: "
1880  "building source address lists...");
1881 
1883 
1884  de_ctx->flow_gh[1].tcp = RulesGroupByPorts(de_ctx, IPPROTO_TCP, SIG_FLAG_TOSERVER);
1885  de_ctx->flow_gh[0].tcp = RulesGroupByPorts(de_ctx, IPPROTO_TCP, SIG_FLAG_TOCLIENT);
1886  de_ctx->flow_gh[1].udp = RulesGroupByPorts(de_ctx, IPPROTO_UDP, SIG_FLAG_TOSERVER);
1887  de_ctx->flow_gh[0].udp = RulesGroupByPorts(de_ctx, IPPROTO_UDP, SIG_FLAG_TOCLIENT);
1888 
1889  /* Setup the other IP Protocols (so not TCP/UDP) */
1890  RulesGroupByIPProto(de_ctx);
1891 
1892  /* now for every rule add the source group to our temp lists */
1893  for (Signature *s = de_ctx->sig_list; s != NULL; s = s->next) {
1894  SCLogDebug("s->id %"PRIu32, s->id);
1895  if (s->type == SIG_TYPE_IPONLY) {
1897  } else if (s->type == SIG_TYPE_DEONLY) {
1898  DetectEngineAddDecoderEventSig(de_ctx, s);
1899  } else if (s->type == SIG_TYPE_PKT && s->init_data->hook.type == SIGNATURE_HOOK_TYPE_PKT &&
1901  DetectEngineAddSigToPreStreamHook(de_ctx, s);
1902  } else if (s->type == SIG_TYPE_PKT && s->init_data->hook.type == SIGNATURE_HOOK_TYPE_PKT &&
1904  DetectEngineAddSigToPreFlowHook(de_ctx, s);
1905  }
1906  }
1907 
1910  return 0;
1911 }
1912 
1913 static void DetectEngineBuildDecoderEventSgh(DetectEngineCtx *de_ctx)
1914 {
1915  if (de_ctx->decoder_event_sgh == NULL)
1916  return;
1917 
1918  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1921 }
1922 
1923 static void DetectEngineBuildPreStreamHookSghs(DetectEngineCtx *de_ctx)
1924 {
1925  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1926  if (de_ctx->pre_stream_sgh[0] != NULL) {
1930  }
1931  if (de_ctx->pre_stream_sgh[1] != NULL) {
1935  }
1936 
1937  if (de_ctx->pre_stream_sgh[0] != NULL || de_ctx->pre_stream_sgh[1] != NULL) {
1939  }
1940 }
1941 
1942 static void DetectEngineBuildPreFlowHookSghs(DetectEngineCtx *de_ctx)
1943 {
1944  if (de_ctx->pre_flow_sgh != NULL) {
1945  uint32_t max_idx = DetectEngineGetMaxSigId(de_ctx);
1950  }
1951 }
1952 
1954 {
1955  /* prepare the decoder event sgh */
1956  DetectEngineBuildDecoderEventSgh(de_ctx);
1957 
1958  /* pre_flow hook sgh */
1959  DetectEngineBuildPreFlowHookSghs(de_ctx);
1960 
1961  /* pre_stream hook sghs */
1962  DetectEngineBuildPreStreamHookSghs(de_ctx);
1963 
1964  return 0;
1965 }
1966 
1968 {
1969  BUG_ON(de_ctx == NULL);
1970 
1971  SCLogDebug("cleaning up signature grouping structure...");
1972 
1975  de_ctx->decoder_event_sgh = NULL;
1976  if (de_ctx->pre_flow_sgh)
1978  de_ctx->pre_flow_sgh = NULL;
1979  if (de_ctx->pre_stream_sgh[0])
1981  de_ctx->pre_stream_sgh[0] = NULL;
1982  if (de_ctx->pre_stream_sgh[1])
1984  de_ctx->pre_stream_sgh[1] = NULL;
1985 
1986  for (int f = 0; f < FLOW_STATES; f++) {
1987  for (int p = 0; p < 256; p++) {
1988  de_ctx->flow_gh[f].sgh[p] = NULL;
1989  }
1990 
1991  /* free lookup lists */
1993  de_ctx->flow_gh[f].tcp = NULL;
1995  de_ctx->flow_gh[f].udp = NULL;
1996  }
1997 
1998  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
1999  SigGroupHead *sgh = de_ctx->sgh_array[idx];
2000  if (sgh == NULL)
2001  continue;
2002 
2003  SCLogDebug("sgh %p", sgh);
2004  SigGroupHeadFree(de_ctx, sgh);
2005  }
2007  de_ctx->sgh_array = NULL;
2008  de_ctx->sgh_array_cnt = 0;
2009  de_ctx->sgh_array_size = 0;
2010 
2012 
2013  SCLogDebug("cleaning up signature grouping structure... complete");
2014  return 0;
2015 }
2016 
2017 #if 0
2018 static void DbgPrintSigs(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
2019 {
2020  if (sgh == NULL) {
2021  printf("\n");
2022  return;
2023  }
2024 
2025  uint32_t sig;
2026  for (sig = 0; sig < sgh->sig_cnt; sig++) {
2027  printf("%" PRIu32 " ", sgh->match_array[sig]->id);
2028  }
2029  printf("\n");
2030 }
2031 
2032 static void DbgPrintSigs2(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
2033 {
2034  if (sgh == NULL || sgh->init == NULL) {
2035  printf("\n");
2036  return;
2037  }
2038 
2039  uint32_t sig;
2040  for (sig = 0; sig < DetectEngineGetMaxSigId(de_ctx); sig++) {
2041  if (sgh->init->sig_array[(sig/8)] & (1<<(sig%8))) {
2042  printf("%" PRIu32 " ", de_ctx->sig_array[sig]->id);
2043  }
2044  }
2045  printf("\n");
2046 }
2047 #endif
2048 
2049 /** \brief finalize preparing sgh's */
2051 {
2052  SCEnter();
2053 
2054  //SCLogInfo("sgh's %"PRIu32, de_ctx->sgh_array_cnt);
2055 
2056  uint32_t cnt = 0;
2057  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
2058  SigGroupHead *sgh = de_ctx->sgh_array[idx];
2059  if (sgh == NULL)
2060  continue;
2061 
2062  SCLogDebug("sgh %p", sgh);
2063 
2065  SCLogDebug("filestore count %u", sgh->filestore_cnt);
2066 
2068 
2069  sgh->id = idx;
2070  cnt++;
2071  }
2072  SCLogPerf("Unique rule groups: %u", cnt);
2073 
2075 
2076  if (de_ctx->decoder_event_sgh != NULL) {
2077  /* no need to set filestore count here as that would make a
2078  * signature not decode event only. */
2080  }
2081 
2082  int dump_grouping = 0;
2083  (void)SCConfGetBool("detect.profiling.grouping.dump-to-disk", &dump_grouping);
2084 
2085  if (dump_grouping) {
2086  int add_rules = 0;
2087  (void)SCConfGetBool("detect.profiling.grouping.include-rules", &add_rules);
2088  int add_mpm_stats = 0;
2089  (void)SCConfGetBool("detect.profiling.grouping.include-mpm-stats", &add_mpm_stats);
2090 
2091  RulesDumpGrouping(de_ctx, add_rules, add_mpm_stats);
2092  }
2093 
2094  for (uint32_t idx = 0; idx < de_ctx->sgh_array_cnt; idx++) {
2095  SigGroupHead *sgh = de_ctx->sgh_array[idx];
2096  if (sgh == NULL)
2097  continue;
2099  sgh->init = NULL;
2100  }
2101  /* cleanup the hashes now since we won't need them
2102  * after the initialization phase. */
2104 
2105 #ifdef PROFILING
2107 #endif
2108  SCReturnInt(0);
2109 }
2110 
2111 extern bool rule_engine_analysis_set;
2112 /** \internal
2113  * \brief perform final per signature setup tasks
2114  *
2115  * - Create SigMatchData arrays from the init only SigMatch lists
2116  * - Setup per signature inspect engines
2117  * - remove signature init data.
2118  */
2119 static int SigMatchPrepare(DetectEngineCtx *de_ctx)
2120 {
2121  SCEnter();
2122 
2123  Signature *s = de_ctx->sig_list;
2124  for (; s != NULL; s = s->next) {
2125  /* set up inspect engines */
2127 
2128  /* built-ins */
2129  for (int type = 0; type < DETECT_SM_LIST_MAX; type++) {
2130  /* skip PMATCH if it is used in a stream 'app engine' instead */
2132  continue;
2133  SigMatch *sm = s->init_data->smlists[type];
2135  }
2136  /* set up the pkt inspection engines */
2138 
2142  }
2143  /* free lists. Ctx' are xferred to sm_arrays so won't get freed */
2144  for (uint32_t i = 0; i < DETECT_SM_LIST_MAX; i++) {
2145  SigMatch *sm = s->init_data->smlists[i];
2146  while (sm != NULL) {
2147  SigMatch *nsm = sm->next;
2148  SigMatchFree(de_ctx, sm);
2149  sm = nsm;
2150  }
2151  }
2152  for (uint32_t i = 0; i < (uint32_t)s->init_data->transforms.cnt; i++) {
2153  if (s->init_data->transforms.transforms[i].options) {
2154  int transform = s->init_data->transforms.transforms[i].transform;
2155  sigmatch_table[transform].Free(
2157  s->init_data->transforms.transforms[i].options = NULL;
2158  }
2159  }
2160  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
2161  SigMatch *sm = s->init_data->buffers[x].head;
2162  while (sm != NULL) {
2163  SigMatch *nsm = sm->next;
2164  SigMatchFree(de_ctx, sm);
2165  sm = nsm;
2166  }
2167  }
2168  if (s->init_data->cidr_dst != NULL)
2170 
2171  if (s->init_data->cidr_src != NULL)
2173 
2174  SCFree(s->init_data->buffers);
2177  SCFree(s->init_data);
2178  s->init_data = NULL;
2179  }
2180 
2182  SCReturnInt(0);
2183 }
2184 
2185 /**
2186  * \brief Convert the signature list into the runtime match structure.
2187  *
2188  * \param de_ctx Pointer to the Detection Engine Context whose Signatures have
2189  * to be processed
2190  *
2191  * \retval 0 On Success.
2192  * \retval -1 On failure.
2193  */
2195 {
2196  Signature *s = de_ctx->sig_list;
2197 
2198  /* Assign the unique order id of signatures after sorting,
2199  * so the IP Only engine process them in order too. Also
2200  * reset the old signums and assign new signums. We would
2201  * have experienced Sig reordering by now, hence the new
2202  * signums. */
2203  de_ctx->signum = 0;
2204  while (s != NULL) {
2205  s->iid = de_ctx->signum++;
2206 
2207  s = s->next;
2208  }
2209 
2211  return -1;
2212 
2213  SigInitStandardMpmFactoryContexts(de_ctx);
2214 
2215  if (SigPrepareStage1(de_ctx) != 0) {
2216  FatalError("initializing the detection engine failed");
2217  }
2218 
2219  if (SigPrepareStage2(de_ctx) != 0) {
2220  FatalError("initializing the detection engine failed");
2221  }
2222 
2223  if (SigPrepareStage3(de_ctx) != 0) {
2224  FatalError("initializing the detection engine failed");
2225  }
2226  if (SigPrepareStage4(de_ctx) != 0) {
2227  FatalError("initializing the detection engine failed");
2228  }
2229 
2234  if (r != 0) {
2235  FatalError("initializing the detection engine failed");
2236  }
2237 
2238  if (SigMatchPrepare(de_ctx) != 0) {
2239  FatalError("initializing the detection engine failed");
2240  }
2241 
2242 #ifdef PROFILING
2245  de_ctx->profile_match_logging_threshold = UINT_MAX; // disabled
2246 
2247  intmax_t v = 0;
2248  if (SCConfGetInt("detect.profiling.inspect-logging-threshold", &v) == 1)
2249  de_ctx->profile_match_logging_threshold = (uint32_t)v;
2250 #endif
2251 #ifdef PROFILE_RULES
2252  SCProfilingRuleInitCounters(de_ctx);
2253 #endif
2254 
2257  }
2258 
2259  if (EngineModeIsFirewall()) {
2261  }
2262  return 0;
2263 }
2264 
2266 {
2268 
2269  return 0;
2270 }
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:203
util-port-interval-tree.h
detect-engine.h
DetectEngineResetMaxSigId
void DetectEngineResetMaxSigId(DetectEngineCtx *de_ctx)
Definition: detect-engine.c:3046
DetectEngineBufferTypeSupportsPacketGetById
bool DetectEngineBufferTypeSupportsPacketGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1436
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:171
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:1268
UniquePortPoint_
Definition: detect-engine-build.c:1318
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:1373
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:2050
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:1323
DetectEngineBufferRunSetupCallback
void DetectEngineBufferRunSetupCallback(const DetectEngineCtx *de_ctx, const int id, Signature *s)
Definition: detect-engine.c:1473
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:1435
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
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
SigTableElmt_::flags
uint32_t flags
Definition: detect.h:1448
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:1522
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:279
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:954
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:1314
PatternStrength
uint32_t PatternStrength(uint8_t *pat, uint16_t patlen)
Predict a strength value for patterns.
Definition: detect-engine-mpm.c:987
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:2509
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:40
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:152
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:783
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:1254
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:1723
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:2566
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:2017
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:1185
SigAddressCleanupStage1
int SigAddressCleanupStage1(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:1967
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
SignatureHook_::t
union SignatureHook_::@93 t
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
SignatureHook_::pkt
struct SignatureHook_::@93::@95 pkt
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:915
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:92
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:281
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:1307
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:225
DetectU8Data
DetectUintData_u8 DetectU8Data
Definition: detect-engine-uint.h:43
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:259
DetectContentPropagateLimits
void DetectContentPropagateLimits(Signature *s)
Definition: detect-content.c:722
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:1320
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
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:37
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:1140
SigGroupCleanup
int SigGroupCleanup(DetectEngineCtx *de_ctx)
Definition: detect-engine-build.c:2265
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:283
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:943
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:1412
SC_OK
@ SC_OK
Definition: util-error.h:27
DETECT_CONFIG
@ DETECT_CONFIG
Definition: detect-engine-register.h:228
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:1319
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:3870
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:229
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:2194
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:1454
EngineAnalysisRules2
void EngineAnalysisRules2(const DetectEngineCtx *de_ctx, const Signature *s)
Definition: detect-engine-analyzer.c:988
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:570
SINGLE_PORT
#define SINGLE_PORT
Definition: detect-engine-build.c:1316
DetectEnginePktInspectionSetup
int DetectEnginePktInspectionSetup(Signature *s)
Definition: detect-engine.c:1852
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:1953
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:238
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:514
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:737
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:1877
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:226
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:796
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
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
SignatureSetType
void SignatureSetType(DetectEngineCtx *de_ctx, Signature *s)
Definition: detect-engine-build.c:1645
RANGE_PORT
#define RANGE_PORT
Definition: detect-engine-build.c:1315
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:1393
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:1424
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:1409
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:285
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:341
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