suricata
detect-engine-prefilter.c
Go to the documentation of this file.
1 /* Copyright (C) 2016-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 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Prefilter engine
24  *
25  * Prefilter engines have as purpose to check for a critical common part of
26  * a set of rules. If the condition is present in the traffic, the rules
27  * will have to be inspected individually. Otherwise, the rules can be
28  * skipped.
29  *
30  * The best example of this is the MPM. From each rule take a pattern and
31  * add it to the MPM state machine. Inspect that in one step and only
32  * individually inspect the rules that had a match in MPM.
33  *
34  * This prefilter API is designed to abstract this logic so that it becomes
35  * easier to add other types of prefilters.
36  *
37  * The prefilter engines are structured as a simple list of engines. Each
38  * engine checks for a condition using it's callback function and private
39  * data. It then adds the rule match candidates to the PrefilterRuleStore
40  * structure.
41  *
42  * After the engines have run the resulting list of match candidates is
43  * sorted by the rule id's so that the individual inspection happens in
44  * the correct order.
45  */
46 
47 #include "suricata-common.h"
48 #include "suricata.h"
49 
50 #include "detect-engine.h"
52 #include "detect-engine-mpm.h"
53 #include "detect-engine-frame.h"
54 #include "detect-engine-uint.h"
55 
56 #include "app-layer-parser.h"
57 #include "app-layer-htp.h"
58 
59 #include "util-profiling.h"
60 #include "util-validate.h"
61 #include "util-hash-string.h"
62 
63 static int PrefilterStoreGetId(DetectEngineCtx *de_ctx,
64  const char *name, void (*FreeFunc)(void *));
65 static const PrefilterStore *PrefilterStoreGetStore(const DetectEngineCtx *de_ctx,
66  const uint32_t id);
67 
68 static inline void QuickSortSigIntId(SigIntId *sids, uint32_t n)
69 {
70  if (n < 2)
71  return;
72  SigIntId p = sids[n / 2];
73  SigIntId *l = sids;
74  SigIntId *r = sids + n - 1;
75  while (l <= r) {
76  if (*l < p)
77  l++;
78  else if (*r > p)
79  r--;
80  else {
81  SigIntId t = *l;
82  *l = *r;
83  *r = t;
84  l++;
85  r--;
86  }
87  }
88  QuickSortSigIntId(sids, (uint32_t)(r - sids) + 1);
89  QuickSortSigIntId(l, (uint32_t)(sids + n - l));
90 }
91 
92 /**
93  * \brief run prefilter engines on a transaction
94  */
96  const SigGroupHead *sgh,
97  Packet *p,
98  const uint8_t ipproto,
99  const uint8_t flow_flags,
100  const AppProto alproto,
101  void *alstate,
102  DetectTransaction *tx)
103 {
104  /* reset rule store */
105  det_ctx->pmq.rule_id_array_cnt = 0;
106 
107  SCLogDebug("packet %" PRIu64 " tx %p progress %d tx->detect_progress %02x", PcapPacketCntGet(p),
108  tx->tx_ptr, tx->tx_progress, tx->detect_progress);
109 
110  PrefilterEngine *engine = sgh->tx_engines;
111  do {
112  // based on flow alproto, and engine, we get right tx_ptr
113  void *tx_ptr = DetectGetInnerTx(tx->tx_ptr, alproto, engine->alproto, flow_flags);
114  if (tx_ptr == NULL) {
115  // incompatible engine->alproto with flow alproto
116  goto next;
117  }
118 
119  if (engine->ctx.tx_min_progress != -1) {
120 #ifdef DEBUG
121  const char *pname = AppLayerParserGetStateNameById(ipproto, engine->alproto,
122  engine->ctx.tx_min_progress, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT));
123  SCLogDebug("engine %p min_progress %d %s:%s", engine, engine->ctx.tx_min_progress,
124  AppProtoToString(engine->alproto), pname);
125 #endif
126  /* if engine needs tx state to be higher, break out. */
127  if (engine->ctx.tx_min_progress > tx->tx_progress)
128  break;
129  if (tx->tx_progress > engine->ctx.tx_min_progress) {
130  SCLogDebug("tx->tx_progress %u > engine->ctx.tx_min_progress %d", tx->tx_progress,
131  engine->ctx.tx_min_progress);
132 
133  /* if state value is at or beyond engine state, we can skip it. It means we ran at
134  * least once already. */
135  if (tx->detect_progress > engine->ctx.tx_min_progress) {
136  SCLogDebug("tx already marked progress as beyond engine: %u > %u",
137  tx->detect_progress, engine->ctx.tx_min_progress);
138  goto next;
139  } else {
140  SCLogDebug("tx->tx_progress %u > engine->ctx.tx_min_progress %d: "
141  "tx->detect_progress %u",
142  tx->tx_progress, engine->ctx.tx_min_progress, tx->detect_progress);
143  }
144  }
145 #ifdef DEBUG
146  uint32_t old = det_ctx->pmq.rule_id_array_cnt;
147 #endif
148  PREFILTER_PROFILING_START(det_ctx);
149  engine->cb.PrefilterTx(det_ctx, engine->pectx, p, p->flow, tx_ptr, tx->tx_id,
150  tx->tx_data_ptr, flow_flags);
151  PREFILTER_PROFILING_END(det_ctx, engine->gid);
152  SCLogDebug("engine %p min_progress %d %s:%s: results %u", engine,
153  engine->ctx.tx_min_progress, AppProtoToString(engine->alproto), pname,
154  det_ctx->pmq.rule_id_array_cnt - old);
155 
156  if (tx->tx_progress > engine->ctx.tx_min_progress && engine->is_last_for_progress &&
157  tx->tx_ptr == tx_ptr) {
158  /* track with an offset of one, so that tx->progress 0 complete is tracked
159  * as 1, progress 1 as 2, etc. This is to allow 0 to mean: nothing tracked, even
160  * though a parser may use 0 as a valid value. */
161  // tx->tx_ptr == tx_ptr ensures we do not use a dns engine progress
162  // to update a HTTP2 tx detect_progress in case of DOH2
163  tx->detect_progress = engine->ctx.tx_min_progress + 1;
164  SCLogDebug("tx->tx_progress %d engine->ctx.tx_min_progress %d "
165  "engine->is_last_for_progress %d => tx->detect_progress updated to %02x",
166  tx->tx_progress, engine->ctx.tx_min_progress, engine->is_last_for_progress,
167  tx->detect_progress);
168  }
169  } else {
170  PREFILTER_PROFILING_START(det_ctx);
171  engine->cb.PrefilterTx(det_ctx, engine->pectx, p, p->flow, tx_ptr, tx->tx_id,
172  tx->tx_data_ptr, flow_flags);
173  PREFILTER_PROFILING_END(det_ctx, engine->gid);
174  }
175  next:
176  if (engine->is_last)
177  break;
178  engine++;
179  } while (1);
180 
181  /* Sort the rule list to lets look at pmq.
182  * NOTE due to merging of 'stream' pmqs we *MAY* have duplicate entries */
183  if (likely(det_ctx->pmq.rule_id_array_cnt > 1)) {
185  QuickSortSigIntId(det_ctx->pmq.rule_id_array, det_ctx->pmq.rule_id_array_cnt);
187  }
188 }
189 
190 /** \brief invoke post-rule match "prefilter" engines
191  *
192  * Invoke prefilter engines that depend on a rule match to run.
193  * e.g. the flowbits:set prefilter that adds sids that depend on
194  * a flowbit "set" to the match array.
195  */
197  DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, Flow *f)
198 {
199  SCLogDebug("post-rule-match engines %p", sgh->post_rule_match_engines);
200  if (sgh->post_rule_match_engines) {
202  do {
203  SCLogDebug("running post-rule-match engine");
204  PREFILTER_PROFILING_START(det_ctx);
205  engine->cb.PrefilterPostRule(det_ctx, engine->pectx, p, f);
206  PREFILTER_PROFILING_END(det_ctx, engine->gid);
207 
208  if (engine->is_last)
209  break;
210  engine++;
211  } while (1);
212 
213  if (det_ctx->pmq.rule_id_array_cnt > 1) {
214  QuickSortSigIntId(det_ctx->pmq.rule_id_array, det_ctx->pmq.rule_id_array_cnt);
215  }
216  }
217 }
218 
219 void Prefilter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p,
220  const uint8_t flags, const SignatureMask mask)
221 {
222  SCEnter();
223 #if 0
224  /* TODO review this check */
225  SCLogDebug("sgh %p frame_engines %p", sgh, sgh->frame_engines);
226  if (p->proto == IPPROTO_TCP && sgh->frame_engines && p->flow &&
227  p->flow->alproto != ALPROTO_UNKNOWN && p->flow->alparser != NULL) {
229  PrefilterFrames(det_ctx, sgh, p, flags, p->flow->alproto);
231  }
232 #endif
233  if (sgh->pkt_engines) {
235  /* run packet engines */
236  PrefilterEngine *engine = sgh->pkt_engines;
237  do {
238  /* run engine if:
239  * mask matches
240  * no hook is used OR hook matches
241  */
242  if (((engine->ctx.pkt.mask & mask) == engine->ctx.pkt.mask) &&
243  (engine->ctx.pkt.hook == 0 || (p->pkt_hooks & BIT_U16(engine->ctx.pkt.hook)))) {
244  PREFILTER_PROFILING_START(det_ctx);
245  engine->cb.Prefilter(det_ctx, p, engine->pectx);
246  PREFILTER_PROFILING_END(det_ctx, engine->gid);
247  }
248 
249  if (engine->is_last)
250  break;
251  engine++;
252  } while (1);
254  }
255 
256  /* run payload inspecting engines */
257  if (sgh->payload_engines &&
260  {
262  PrefilterEngine *engine = sgh->payload_engines;
263  while (1) {
264  PREFILTER_PROFILING_START(det_ctx);
265  engine->cb.Prefilter(det_ctx, p, engine->pectx);
266  PREFILTER_PROFILING_END(det_ctx, engine->gid);
267 
268  if (engine->is_last)
269  break;
270  engine++;
271  }
273  }
274 
275  /* Sort the rule list to lets look at pmq.
276  * NOTE due to merging of 'stream' pmqs we *MAY* have duplicate entries */
277  if (likely(det_ctx->pmq.rule_id_array_cnt > 1)) {
279  QuickSortSigIntId(det_ctx->pmq.rule_id_array, det_ctx->pmq.rule_id_array_cnt);
281  }
282  SCReturn;
283 }
284 
286  SignatureMask mask, enum SignatureHookPkt hook, void *pectx, void (*FreeFunc)(void *pectx),
287  const char *name)
288 {
289  if (sgh == NULL || PrefilterFunc == NULL || pectx == NULL)
290  return -1;
291 
292  PrefilterEngineList *e = SCMallocAligned(sizeof(*e), CLS);
293  if (e == NULL)
294  return -1;
295  memset(e, 0x00, sizeof(*e));
296 
297  // TODO right now we represent the hook in a u8 in the prefilter engine for space reasons.
298  BUG_ON(hook >= 8);
299 
300  e->Prefilter = PrefilterFunc;
301  e->pectx = pectx;
302  e->Free = FreeFunc;
303  e->pkt_mask = mask;
304  e->pkt_hook = hook;
305 
306  if (sgh->init->pkt_engines == NULL) {
307  sgh->init->pkt_engines = e;
308  } else {
310  while (t->next != NULL) {
311  t = t->next;
312  }
313 
314  t->next = e;
315  e->id = t->id + 1;
316  }
317 
318  e->name = name;
319  e->gid = PrefilterStoreGetId(de_ctx, e->name, e->Free);
320  return 0;
321 }
322 
324  PrefilterPktFn PrefilterFunc, void *pectx, void (*FreeFunc)(void *pectx), const char *name)
325 {
326  if (sgh == NULL || PrefilterFunc == NULL || pectx == NULL)
327  return -1;
328 
329  PrefilterEngineList *e = SCMallocAligned(sizeof(*e), CLS);
330  if (e == NULL)
331  return -1;
332  memset(e, 0x00, sizeof(*e));
333 
334  e->Prefilter = PrefilterFunc;
335  e->pectx = pectx;
336  e->Free = FreeFunc;
337 
338  if (sgh->init->payload_engines == NULL) {
339  sgh->init->payload_engines = e;
340  } else {
342  while (t->next != NULL) {
343  t = t->next;
344  }
345 
346  t->next = e;
347  e->id = t->id + 1;
348  }
349 
350  e->name = name;
351  e->gid = PrefilterStoreGetId(de_ctx, e->name, e->Free);
352  return 0;
353 }
354 
356  PrefilterTxFn PrefilterTxFunc, AppProto alproto, int tx_min_progress, void *pectx,
357  void (*FreeFunc)(void *pectx), const char *name)
358 {
359  if (sgh == NULL || PrefilterTxFunc == NULL || pectx == NULL)
360  return -1;
361 
362  PrefilterEngineList *e = SCMallocAligned(sizeof(*e), CLS);
363  if (e == NULL)
364  return -1;
365  memset(e, 0x00, sizeof(*e));
366 
367  e->PrefilterTx = PrefilterTxFunc;
368  e->pectx = pectx;
369  e->alproto = alproto;
370  // TODO change function prototype ?
371  DEBUG_VALIDATE_BUG_ON(tx_min_progress > INT8_MAX);
372  e->tx_min_progress = (uint8_t)tx_min_progress;
373  e->Free = FreeFunc;
374 
375  if (sgh->init->tx_engines == NULL) {
376  sgh->init->tx_engines = e;
377  } else {
379  while (t->next != NULL) {
380  t = t->next;
381  }
382 
383  t->next = e;
384  e->id = t->id + 1;
385  }
386 
387  e->name = name;
388  e->gid = PrefilterStoreGetId(de_ctx, e->name, e->Free);
389  return 0;
390 }
391 
393  PrefilterFrameFn PrefilterFrameFunc, AppProto alproto, uint8_t frame_type, void *pectx,
394  void (*FreeFunc)(void *pectx), const char *name)
395 {
396  if (sgh == NULL || PrefilterFrameFunc == NULL || pectx == NULL)
397  return -1;
398 
399  PrefilterEngineList *e = SCMallocAligned(sizeof(*e), CLS);
400  if (e == NULL)
401  return -1;
402  memset(e, 0x00, sizeof(*e));
403 
404  e->frame_type = frame_type;
405  e->alproto = alproto;
406  e->PrefilterFrame = PrefilterFrameFunc;
407  e->pectx = pectx;
408  e->Free = FreeFunc;
409 
410  if (sgh->init->frame_engines == NULL) {
411  sgh->init->frame_engines = e;
412  } else {
414  while (t->next != NULL) {
415  t = t->next;
416  }
417 
418  t->next = e;
419  e->id = t->id + 1;
420  }
421 
422  e->name = name;
423  e->gid = PrefilterStoreGetId(de_ctx, e->name, e->Free);
424  return 0;
425 }
426 
428  void (*PrefilterPostRuleFunc)(
429  DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f),
430  void *pectx, void (*FreeFunc)(void *pectx), const char *name)
431 {
432  if (sgh == NULL || PrefilterPostRuleFunc == NULL || pectx == NULL)
433  return -1;
434 
435  PrefilterEngineList *e = SCMallocAligned(sizeof(*e), CLS);
436  if (e == NULL)
437  return -1;
438  memset(e, 0x00, sizeof(*e));
439  e->PrefilterPostRule = PrefilterPostRuleFunc;
440  e->pectx = pectx;
441  e->Free = FreeFunc;
442 
443  if (sgh->init->post_rule_match_engines == NULL) {
444  sgh->init->post_rule_match_engines = e;
445  } else {
447  while (t->next != NULL) {
448  t = t->next;
449  }
450 
451  t->next = e;
452  e->id = t->id + 1;
453  }
454 
455  e->name = name;
456  e->gid = PrefilterStoreGetId(de_ctx, e->name, e->Free);
457  return 0;
458 }
459 
460 static void PrefilterFreeEngineList(PrefilterEngineList *e)
461 {
462  if (e->Free && e->pectx) {
463  e->Free(e->pectx);
464  }
465  SCFreeAligned(e);
466 }
467 
469 {
470  PrefilterEngineList *t = list;
471 
472  while (t != NULL) {
474  PrefilterFreeEngineList(t);
475  t = next;
476  }
477 }
478 
479 static void PrefilterFreeEngines(const DetectEngineCtx *de_ctx, PrefilterEngine *list)
480 {
481  PrefilterEngine *t = list;
482 
483  while (1) {
484  const PrefilterStore *s = PrefilterStoreGetStore(de_ctx, t->gid);
485  if (s && s->FreeFunc && t->pectx) {
486  s->FreeFunc(t->pectx);
487  }
488 
489  if (t->is_last)
490  break;
491  t++;
492  }
493  SCFreeAligned(list);
494 }
495 
497 {
498  if (sgh->pkt_engines) {
499  PrefilterFreeEngines(de_ctx, sgh->pkt_engines);
500  sgh->pkt_engines = NULL;
501  }
502  if (sgh->payload_engines) {
503  PrefilterFreeEngines(de_ctx, sgh->payload_engines);
504  sgh->payload_engines = NULL;
505  }
506  if (sgh->tx_engines) {
507  PrefilterFreeEngines(de_ctx, sgh->tx_engines);
508  sgh->tx_engines = NULL;
509  }
510  if (sgh->frame_engines) {
511  PrefilterFreeEngines(de_ctx, sgh->frame_engines);
512  sgh->frame_engines = NULL;
513  }
514  if (sgh->post_rule_match_engines) {
515  PrefilterFreeEngines(de_ctx, sgh->post_rule_match_engines);
516  sgh->post_rule_match_engines = NULL;
517  }
518 }
519 
520 static int PrefilterSetupRuleGroupSortHelper(const void *a, const void *b)
521 {
522  const PrefilterEngine *s0 = a;
523  const PrefilterEngine *s1 = b;
524  if (s1->ctx.tx_min_progress == s0->ctx.tx_min_progress) {
525  if (s1->alproto == s0->alproto) {
526  return s0->local_id > s1->local_id ? 1 : -1;
527  } else {
528  return s0->alproto > s1->alproto ? 1 : -1;
529  }
530  } else {
531  return s0->ctx.tx_min_progress > s1->ctx.tx_min_progress ? 1 : -1;
532  }
533 }
534 
535 /** prefilter engine data for the non-prefilter engine for the prefilter API */
537  uint32_t sid : 30;
538  uint32_t type : 2; /**< type for `value` field below: 0:alproto 1:dport 2:dsize */
539  uint16_t value;
540  /* since we have 2 more bytes available due to padding, we can add some additional
541  * filters here. */
542  union {
543  struct {
545  } pkt;
546  struct {
547  /* filter for frame type */
548  uint8_t type;
549  } frame;
550  struct {
551  uint8_t foo; // TODO unused
552  } app;
553  };
554 };
555 
557  uint32_t size;
558  struct PrefilterNonPFDataSig array[];
559 };
560 
562  uint32_t size;
563  uint32_t array[];
564 };
565 
566 /** \internal
567  * \brief wrapper for use in APIs */
568 static void PrefilterNonPFDataFree(void *data)
569 {
570  SCFree(data);
571 }
572 
573 static void PrefilterTxNonPF(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f,
574  void *tx, const uint64_t tx_id, const AppLayerTxData *tx_data, const uint8_t flags)
575 {
576  const struct PrefilterNonPFDataTx *data = (const struct PrefilterNonPFDataTx *)pectx;
577  SCLogDebug("adding %u sids", data->size);
578  PrefilterAddSids(&det_ctx->pmq, data->array, data->size);
579 }
580 
581 #ifdef NONPF_PKT_STATS
582 static thread_local uint64_t prefilter_pkt_nonpf_called = 0;
583 static thread_local uint64_t prefilter_pkt_nonpf_mask_fail = 0;
584 static thread_local uint64_t prefilter_pkt_nonpf_alproto_fail = 0;
585 static thread_local uint64_t prefilter_pkt_nonpf_dsize_fail = 0;
586 static thread_local uint64_t prefilter_pkt_nonpf_dport_fail = 0;
587 static thread_local uint64_t prefilter_pkt_nonpf_sids = 0;
588 #define NONPF_PKT_STATS_INCR(s) (s)++
589 #else
590 #define NONPF_PKT_STATS_INCR(s)
591 #endif
592 
594 {
595 #ifdef NONPF_PKT_STATS
596  SCLogDebug("prefilter non-pf: called:%" PRIu64 ", mask_fail:%" PRIu64 ", alproto fail:%" PRIu64
597  ", dport fail:%" PRIu64 ", dsize fail:%" PRIu64 ", sids:%" PRIu64
598  ", avg sids:%" PRIu64,
599  prefilter_pkt_nonpf_called, prefilter_pkt_nonpf_mask_fail,
600  prefilter_pkt_nonpf_alproto_fail, prefilter_pkt_nonpf_dport_fail,
601  prefilter_pkt_nonpf_dsize_fail, prefilter_pkt_nonpf_sids,
602  prefilter_pkt_nonpf_called ? prefilter_pkt_nonpf_sids / prefilter_pkt_nonpf_called : 0);
603 #endif
604 }
605 
606 static void PrefilterPktNonPF(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
607 {
608  const uint16_t alproto = p->flow ? p->flow->alproto : ALPROTO_UNKNOWN;
609  const SignatureMask mask = p->sig_mask;
610  const struct PrefilterNonPFData *data = (const struct PrefilterNonPFData *)pectx;
611  SCLogDebug("adding %u sids", data->size);
612  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_called);
613  for (uint32_t i = 0; i < data->size; i++) {
614  const struct PrefilterNonPFDataSig *ds = &data->array[i];
615  const SignatureMask rule_mask = ds->pkt.sig_mask;
616  if ((rule_mask & mask) == rule_mask) {
617  switch (ds->type) {
618  case 0:
619  if (ds->value == ALPROTO_UNKNOWN || AppProtoEquals(ds->value, alproto)) {
620  const uint32_t sid = ds->sid;
621  PrefilterAddSids(&det_ctx->pmq, &sid, 1);
622  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_sids);
623  } else {
624  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_alproto_fail);
625  }
626  break;
627  case 1:
628  if (ds->value == p->dp) {
629  const uint32_t sid = ds->sid;
630  PrefilterAddSids(&det_ctx->pmq, &sid, 1);
631  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_sids);
632  } else {
633  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_dport_fail);
634  }
635  break;
636  case 2:
637  if (ds->value == p->payload_len) {
638  const uint32_t sid = ds->sid;
639  PrefilterAddSids(&det_ctx->pmq, &sid, 1);
640  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_sids);
641  } else {
642  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_dsize_fail);
643  }
644  break;
645  }
646  } else {
647  NONPF_PKT_STATS_INCR(prefilter_pkt_nonpf_mask_fail);
648  }
649  }
650 }
651 
652 static void PrefilterPktNonPFHookFlowStart(
653  DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
654 {
656  PrefilterPktNonPF(det_ctx, p, pectx);
657  }
658 }
659 
660 /** \internal
661  * \brief engine to select the non-prefilter rules for frames
662  * Checks the alproto and type as well.
663  * Direction needs no checking as the rule groups are per direction. */
664 static void PrefilterFrameNonPF(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
665  const Frames *frames, const Frame *frame)
666 {
667  DEBUG_VALIDATE_BUG_ON(p->flow == NULL);
668  const uint16_t alproto = p->flow->alproto;
669  const struct PrefilterNonPFData *data = (const struct PrefilterNonPFData *)pectx;
670  SCLogDebug("adding %u sids", data->size);
671  for (uint32_t i = 0; i < data->size; i++) {
672  const struct PrefilterNonPFDataSig *ds = &data->array[i];
673  if (ds->frame.type == frame->type &&
674  (ds->value == ALPROTO_UNKNOWN || AppProtoEquals(ds->value, alproto))) {
675  const uint32_t sid = ds->sid;
676  PrefilterAddSids(&det_ctx->pmq, &sid, 1);
677  }
678  }
679 }
680 
681 /* helper funcs for the non prefilter names hash */
682 
683 static uint32_t NonPFNamesHash(HashTable *h, void *data, uint16_t _len)
684 {
685  const char *str = data;
686  return StringHashDjb2((const uint8_t *)str, (uint16_t)strlen(str)) % h->array_size;
687 }
688 
689 static char NonPFNamesCompare(void *data1, uint16_t _len1, void *data2, uint16_t len2)
690 {
691  const char *s1 = data1;
692  const char *s2 = data2;
693  return StringHashCompareFunc(data1, (uint16_t)strlen(s1), data2, (uint16_t)strlen(s2));
694 }
695 
696 static void NonPFNamesFree(void *data)
697 {
698  SCFree(data);
699 }
700 
701 /* helper funcs for assembling non-prefilter engines */
702 
703 struct TxNonPFData {
705  int dir; /**< 0: toserver, 1: toclient */
706  int progress; /**< progress state value to register at */
707  int sig_list; /**< special handling: normally 0, but for special cases (app-layer-state,
708  app-layer-event) use the list id to create separate engines */
709  uint32_t sigs_cnt;
711  const char *engine_name; /**< pointer to name owned by DetectEngineCtx::non_pf_engine_names */
712 };
713 
714 static uint32_t TxNonPFHash(HashListTable *h, void *data, uint16_t _len)
715 {
716  struct TxNonPFData *d = data;
717  return (d->alproto + d->progress + d->dir + d->sig_list) % h->array_size;
718 }
719 
720 static char TxNonPFCompare(void *data1, uint16_t _len1, void *data2, uint16_t len2)
721 {
722  struct TxNonPFData *d1 = data1;
723  struct TxNonPFData *d2 = data2;
724  return d1->alproto == d2->alproto && d1->progress == d2->progress && d1->dir == d2->dir &&
725  d1->sig_list == d2->sig_list;
726 }
727 
728 static void TxNonPFFree(void *data)
729 {
730  struct TxNonPFData *d = data;
731  SCFree(d->sigs);
732  SCFree(d);
733 }
734 
735 static int TxNonPFAddSig(DetectEngineCtx *de_ctx, HashListTable *tx_engines_hash,
736  const AppProto alproto, const int dir, const int16_t progress, const int sig_list,
737  const char *name, const Signature *s)
738 {
739  const uint32_t max_sids = DetectEngineGetMaxSigId(de_ctx);
740 
741  struct TxNonPFData lookup = {
742  .alproto = alproto,
743  .dir = dir,
744  .progress = progress,
745  .sig_list = sig_list,
746  .sigs_cnt = 0,
747  .sigs = NULL,
748  .engine_name = NULL,
749  };
750  struct TxNonPFData *e = HashListTableLookup(tx_engines_hash, &lookup, 0);
751  if (e != NULL) {
752  bool found = false;
753  // avoid adding same sid multiple times
754  for (uint32_t y = 0; y < e->sigs_cnt; y++) {
755  if (e->sigs[y].sid == s->iid) {
756  found = true;
757  break;
758  }
759  }
760  if (!found) {
761  BUG_ON(e->sigs_cnt == max_sids);
762  e->sigs[e->sigs_cnt].sid = s->iid;
763  e->sigs[e->sigs_cnt].value = alproto;
764  e->sigs_cnt++;
765  }
766  return 0;
767  }
768 
769  struct TxNonPFData *add = SCCalloc(1, sizeof(*add));
770  if (add == NULL) {
771  return -1;
772  }
773  add->dir = dir;
774  add->alproto = alproto;
775  add->progress = progress;
776  add->sig_list = sig_list;
777  add->sigs = SCCalloc(max_sids, sizeof(struct PrefilterNonPFDataSig));
778  if (add->sigs == NULL) {
779  SCFree(add);
780  return -1;
781  }
782  add->sigs_cnt = 0;
783  add->sigs[add->sigs_cnt].sid = s->iid;
784  add->sigs[add->sigs_cnt].value = alproto;
785  add->sigs_cnt++;
786 
787  char engine_name[128];
788  snprintf(engine_name, sizeof(engine_name), "%s:%s:non_pf:%s", AppProtoToString(alproto), name,
789  dir == 0 ? "toserver" : "toclient");
790  char *engine_name_heap = SCStrdup(engine_name);
791  if (engine_name_heap == NULL) {
792  SCFree(add->sigs);
793  SCFree(add);
794  return -1;
795  }
796  int result = HashTableAdd(
797  de_ctx->non_pf_engine_names, engine_name_heap, (uint16_t)strlen(engine_name_heap));
798  if (result != 0) {
799  SCFree(add->sigs);
800  SCFree(add);
801  return -1;
802  }
803 
804  add->engine_name = engine_name_heap;
805  SCLogDebug("engine_name_heap %s", engine_name_heap);
806 
807  int ret = HashListTableAdd(tx_engines_hash, add, 0);
808  if (ret != 0) {
809  SCFree(add->sigs);
810  SCFree(add);
811  return -1;
812  }
813 
814  return 0;
815 }
816 
817 /** \internal
818  * \brief setup non-prefilter rules in special "non-prefilter" engines that are registered in the
819  * prefilter logic.
820  *
821  * \retval 0 ok
822  * \retval -1 error
823  */
824 static int SetupNonPrefilter(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
825 {
826  const uint32_t max_sids = DetectEngineGetMaxSigId(de_ctx);
827  SCLogDebug("max_sids %u", max_sids);
828  struct PrefilterNonPFDataSig *pkt_non_pf_array = SCCalloc(max_sids, sizeof(*pkt_non_pf_array));
829  if (pkt_non_pf_array == NULL) {
830  return -1;
831  }
832  uint32_t pkt_non_pf_array_size = 0;
833  struct PrefilterNonPFDataSig *frame_non_pf_array =
834  SCCalloc(max_sids, sizeof(*frame_non_pf_array));
835  if (frame_non_pf_array == NULL) {
836  SCFree(pkt_non_pf_array);
837  return -1;
838  }
839  uint32_t frame_non_pf_array_size = 0;
840 
841  struct PrefilterNonPFDataSig *pkt_hook_flow_start_non_pf_array =
842  SCCalloc(max_sids, sizeof(*pkt_hook_flow_start_non_pf_array));
843  if (pkt_hook_flow_start_non_pf_array == NULL) {
844  SCFree(pkt_non_pf_array);
845  SCFree(frame_non_pf_array);
846  return -1;
847  }
848  uint32_t pkt_hook_flow_start_non_pf_array_size = 0;
849  SignatureMask pkt_hook_flow_start_mask = 0;
850  bool pkt_hook_flow_start_mask_init = false;
851 
852  HashListTable *tx_engines_hash =
853  HashListTableInit(256, TxNonPFHash, TxNonPFCompare, TxNonPFFree);
854  if (tx_engines_hash == NULL) {
855  SCFree(pkt_non_pf_array);
856  SCFree(pkt_hook_flow_start_non_pf_array);
857  SCFree(frame_non_pf_array);
858  return -1;
859  }
860 
861  if (de_ctx->non_pf_engine_names == NULL) {
863  HashTableInit(512, NonPFNamesHash, NonPFNamesCompare, NonPFNamesFree);
864  if (de_ctx->non_pf_engine_names == NULL) {
865  SCFree(pkt_non_pf_array);
866  SCFree(pkt_hook_flow_start_non_pf_array);
867  SCFree(frame_non_pf_array);
868  HashListTableFree(tx_engines_hash);
869  return -1;
870  }
871  }
872 
873  SignatureMask pkt_mask = 0;
874  bool pkt_mask_init = false;
875 #ifdef NONPF_PKT_STATS
876  uint32_t nonpf_pkt_alproto = 0;
877  uint32_t nonpf_pkt_dsize = 0;
878  uint32_t nonpf_pkt_dport = 0;
879 #endif
880  const int app_events_list_id = DetectBufferTypeGetByName("app-layer-events");
881  SCLogDebug("app_events_list_id %d", app_events_list_id);
882  const int app_state_list_id = DetectBufferTypeGetByName("app-layer-state");
883  SCLogDebug("app_state_list_id %d", app_state_list_id);
884  for (uint32_t sig = 0; sig < sgh->init->sig_cnt; sig++) {
885  Signature *s = sgh->init->match_array[sig];
886  if (s == NULL)
887  continue;
888  SCLogDebug("checking sid %u for non-prefilter", s->id);
889  if (s->init_data->mpm_sm != NULL && (s->flags & SIG_FLAG_MPM_NEG) == 0)
890  continue;
891  if (s->init_data->prefilter_sm != NULL)
892  continue;
894  continue;
895  SCLogDebug("setting up sid %u for non-prefilter", s->id);
896 
897  uint8_t frame_type = 0; /**< only a single type per rule */
898  bool tx_non_pf = false;
899  bool frame_non_pf = false;
900  bool pkt_non_pf = false;
901 
904  // TODO code duplication with regular pkt case below
905 
906  /* for pkt non prefilter, we have some space in the structure,
907  * so we can squeeze another filter */
908  uint8_t type;
909  uint16_t value;
910  if ((s->flags & SIG_FLAG_DSIZE) && s->dsize_mode == DETECT_UINT_EQ) {
911  SCLogDebug("dsize extra match");
912  type = 2;
913  value = s->dsize_low;
914  } else if (s->dp != NULL && s->dp->next == NULL && s->dp->port == s->dp->port2) {
915  type = 1;
916  value = s->dp->port;
917  } else {
918  type = 0;
919  value = s->alproto;
920  }
921  pkt_hook_flow_start_non_pf_array[pkt_hook_flow_start_non_pf_array_size].sid = s->iid;
922  pkt_hook_flow_start_non_pf_array[pkt_hook_flow_start_non_pf_array_size].value = value;
923  pkt_hook_flow_start_non_pf_array[pkt_hook_flow_start_non_pf_array_size].type = type;
924  pkt_hook_flow_start_non_pf_array[pkt_hook_flow_start_non_pf_array_size].pkt.sig_mask =
925  s->mask;
926  pkt_hook_flow_start_non_pf_array_size++;
927 
928  if (pkt_hook_flow_start_mask_init) {
929  pkt_hook_flow_start_mask &= s->mask;
930  } else {
931  pkt_hook_flow_start_mask = s->mask;
932  pkt_hook_flow_start_mask_init = true;
933  }
934 
935  SCLogDebug("flow_start hook");
936  continue; // done for this sig
937  }
938 
939  for (uint32_t x = 0; x < s->init_data->buffer_index; x++) {
940  const int list_id = s->init_data->buffers[x].id;
942  if (buf == NULL)
943  continue;
944  /* for now, exclude app-layer-events, as they are not tied to a specific
945  * progress value like other keywords. */
946  SCLogDebug("list_id %d buf %p", list_id, buf);
947  if (list_id == app_events_list_id)
948  continue;
949  if (buf->packet) {
950  SCLogDebug("packet buf");
951  /* packet is handled below */
952  pkt_non_pf = true;
953  } else if (buf->frame) {
955  f != NULL; f = f->next) {
956  if (!((((s->flags & SIG_FLAG_TOSERVER) != 0 && f->dir == 0) ||
957  ((s->flags & SIG_FLAG_TOCLIENT) != 0 && f->dir == 1)) &&
958  list_id == (int)f->sm_list &&
959  AppProtoEquals(s->alproto, f->alproto)))
960  continue;
961 
962  SCLogDebug("frame '%s' type %u", buf->name, f->type);
963  frame_type = f->type;
964  frame_non_pf = true;
965 
966  frame_non_pf_array[frame_non_pf_array_size].sid = s->iid;
967  frame_non_pf_array[frame_non_pf_array_size].value = s->alproto;
968  frame_non_pf_array[frame_non_pf_array_size].frame.type = frame_type;
969  frame_non_pf_array_size++;
970  break;
971  }
972 
973  } else {
974  SCLogDebug("x %u list_id %d", x, list_id);
976  app != NULL; app = app->next) {
977  SCLogDebug("app %p proto %s list_d %d sig dir %0x", app,
978  AppProtoToString(app->alproto), app->sm_list,
980 
981  /* skip if:
982  * - not in our dir
983  * - not our list
984  * - app proto mismatch. Both sig and app can have proto or unknown */
985  if (!((((s->flags & SIG_FLAG_TOSERVER) != 0 && app->dir == 0) ||
986  ((s->flags & SIG_FLAG_TOCLIENT) != 0 && app->dir == 1)) &&
987  list_id == (int)app->sm_list &&
988  (s->alproto == ALPROTO_UNKNOWN || app->alproto == ALPROTO_UNKNOWN ||
989  AppProtoEquals(s->alproto, app->alproto))))
990  continue;
991 
992  int sig_list = 0;
993  if (list_id == app_state_list_id)
994  sig_list = app_state_list_id;
995  if (TxNonPFAddSig(de_ctx, tx_engines_hash, app->alproto, app->dir,
996  app->progress, sig_list, buf->name, s) != 0) {
997  goto error;
998  }
999  tx_non_pf = true;
1000  }
1001  }
1002  }
1003  /* handle hook only rules */
1004  if (!tx_non_pf && s->init_data->hook.type == SIGNATURE_HOOK_TYPE_APP) {
1005  const int dir = (s->flags & SIG_FLAG_TOSERVER) ? 0 : 1;
1006  const char *pname = AppLayerParserGetStateNameById(IPPROTO_TCP, // TODO
1007  s->alproto, s->init_data->hook.t.app.app_progress,
1008  dir == 0 ? STREAM_TOSERVER : STREAM_TOCLIENT);
1009 
1010  if (TxNonPFAddSig(de_ctx, tx_engines_hash, s->alproto, dir,
1011  (int16_t)s->init_data->hook.t.app.app_progress, s->init_data->hook.sm_list,
1012  pname, s) != 0) {
1013  goto error;
1014  }
1015  tx_non_pf = true;
1016  }
1017  /* mark as prefiltered as the sig is now part of a engine */
1018  // s->flags |= SIG_FLAG_PREFILTER;
1019  // TODO doesn't work for sigs that are in multiple sgh's
1020 
1021  /* default to pkt if there was no tx or frame match */
1022  if (!(tx_non_pf || frame_non_pf)) {
1023  if (!pkt_non_pf) {
1024  SCLogDebug("not frame, not tx, so pkt");
1025  }
1026  pkt_non_pf = true;
1027  }
1028 
1029  SCLogDebug("setting up sid %u for non-prefilter: %s", s->id,
1030  tx_non_pf ? "tx engine" : (frame_non_pf ? "frame engine" : "pkt engine"));
1031 
1032  if (pkt_non_pf) {
1033  /* for pkt non prefilter, we have some space in the structure,
1034  * so we can squeeze another filter */
1035  uint8_t type;
1036  uint16_t value;
1037  if ((s->flags & SIG_FLAG_DSIZE) && s->dsize_mode == DETECT_UINT_EQ) {
1038  SCLogDebug("dsize extra match");
1039  type = 2;
1040  value = s->dsize_low;
1041 #ifdef NONPF_PKT_STATS
1042  nonpf_pkt_dsize++;
1043 #endif
1044  } else if (s->dp != NULL && s->dp->next == NULL && s->dp->port == s->dp->port2) {
1045  type = 1;
1046  value = s->dp->port;
1047 #ifdef NONPF_PKT_STATS
1048  nonpf_pkt_dport++;
1049 #endif
1050  } else {
1051  type = 0;
1052  value = s->alproto;
1053 #ifdef NONPF_PKT_STATS
1054  nonpf_pkt_alproto++;
1055 #endif
1056  }
1057 
1058  pkt_non_pf_array[pkt_non_pf_array_size].sid = s->iid;
1059  pkt_non_pf_array[pkt_non_pf_array_size].value = value;
1060  pkt_non_pf_array[pkt_non_pf_array_size].type = type;
1061  pkt_non_pf_array[pkt_non_pf_array_size].pkt.sig_mask = s->mask;
1062  pkt_non_pf_array_size++;
1063 
1064  if (pkt_mask_init) {
1065  pkt_mask &= s->mask;
1066  } else {
1067  pkt_mask = s->mask;
1068  pkt_mask_init = true;
1069  }
1070  }
1071  }
1072 
1073  /* for each unique sig set, add an engine */
1074  for (HashListTableBucket *b = HashListTableGetListHead(tx_engines_hash); b != NULL;
1075  b = HashListTableGetListNext(b)) {
1076  struct TxNonPFData *t = HashListTableGetListData(b);
1077  SCLogDebug("%s engine for %s hook %d has %u non-pf sigs",
1078  t->dir == 0 ? "toserver" : "toclient", AppProtoToString(t->alproto), t->progress,
1079  t->sigs_cnt);
1080 
1081  if (((sgh->init->direction & SIG_FLAG_TOSERVER) && t->dir == 1) ||
1082  ((sgh->init->direction & SIG_FLAG_TOCLIENT) && t->dir == 0)) {
1083  SCLogDebug("skipped");
1084  continue;
1085  }
1086 
1087  /* register special progress value to indicate we need to run it all the time */
1088  int engine_progress = t->progress;
1089  if (t->sig_list == app_state_list_id) {
1090  SCLogDebug("engine %s for state list", t->engine_name);
1091  engine_progress = -1;
1092  }
1093 
1094  struct PrefilterNonPFDataTx *data =
1095  SCCalloc(1, sizeof(*data) + t->sigs_cnt * sizeof(data->array[0]));
1096  if (data == NULL)
1097  goto error;
1098  data->size = t->sigs_cnt;
1099  for (uint32_t i = 0; i < t->sigs_cnt; i++) {
1100  data->array[i] = t->sigs[i].sid;
1101  }
1102  if (PrefilterAppendTxEngine(de_ctx, sgh, PrefilterTxNonPF, t->alproto, engine_progress,
1103  (void *)data, PrefilterNonPFDataFree, t->engine_name) < 0) {
1104  SCFree(data);
1105  goto error;
1106  }
1107  }
1108  HashListTableFree(tx_engines_hash);
1109  tx_engines_hash = NULL;
1110 
1111  if (pkt_non_pf_array_size) {
1112  struct PrefilterNonPFData *data =
1113  SCCalloc(1, sizeof(*data) + pkt_non_pf_array_size * sizeof(data->array[0]));
1114  if (data == NULL)
1115  goto error;
1116  data->size = pkt_non_pf_array_size;
1117  memcpy((uint8_t *)&data->array, pkt_non_pf_array,
1118  pkt_non_pf_array_size * sizeof(data->array[0]));
1119  enum SignatureHookPkt hook = SIGNATURE_HOOK_PKT_NOT_SET; // TODO review
1120  if (PrefilterAppendEngine(de_ctx, sgh, PrefilterPktNonPF, pkt_mask, hook, (void *)data,
1121  PrefilterNonPFDataFree, "packet:non_pf") < 0) {
1122  SCFree(data);
1123  goto error;
1124  }
1125  }
1126  if (pkt_hook_flow_start_non_pf_array_size) {
1127  struct PrefilterNonPFData *data = SCCalloc(
1128  1, sizeof(*data) + pkt_hook_flow_start_non_pf_array_size * sizeof(data->array[0]));
1129  if (data == NULL)
1130  goto error;
1131  data->size = pkt_hook_flow_start_non_pf_array_size;
1132  memcpy((uint8_t *)&data->array, pkt_hook_flow_start_non_pf_array,
1133  pkt_hook_flow_start_non_pf_array_size * sizeof(data->array[0]));
1134  SCLogDebug("packet:flow_start:non_pf added with %u rules", data->size);
1136  if (PrefilterAppendEngine(de_ctx, sgh,
1137  PrefilterPktNonPFHookFlowStart, // TODO no longer needed to have a dedicated
1138  // callback
1139  pkt_hook_flow_start_mask, hook, (void *)data, PrefilterNonPFDataFree,
1140  "packet:flow_start:non_pf") < 0) {
1141  SCFree(data);
1142  goto error;
1143  }
1144  }
1145  if (frame_non_pf_array_size) {
1146  SCLogDebug("%u frame non-pf sigs", frame_non_pf_array_size);
1147  struct PrefilterNonPFData *data =
1148  SCCalloc(1, sizeof(*data) + frame_non_pf_array_size * sizeof(data->array[0]));
1149  if (data == NULL)
1150  goto error;
1151  data->size = frame_non_pf_array_size;
1152  memcpy((uint8_t *)&data->array, frame_non_pf_array,
1153  frame_non_pf_array_size * sizeof(data->array[0]));
1154  if (PrefilterAppendFrameEngine(de_ctx, sgh, PrefilterFrameNonPF, ALPROTO_UNKNOWN,
1155  FRAME_ANY_TYPE, (void *)data, PrefilterNonPFDataFree, "frame:non_pf") < 0) {
1156  SCFree(data);
1157  goto error;
1158  }
1159  }
1160 
1161  SCFree(pkt_hook_flow_start_non_pf_array);
1162  pkt_hook_flow_start_non_pf_array = NULL;
1163  SCFree(pkt_non_pf_array);
1164  pkt_non_pf_array = NULL;
1165  SCFree(frame_non_pf_array);
1166  frame_non_pf_array = NULL;
1167  return 0;
1168 
1169 error:
1170  if (tx_engines_hash) {
1171  HashListTableFree(tx_engines_hash);
1172  }
1173  SCFree(pkt_hook_flow_start_non_pf_array);
1174  SCFree(pkt_non_pf_array);
1175  SCFree(frame_non_pf_array);
1176  return -1;
1177 }
1178 
1180 {
1181  int r = PatternMatchPrepareGroup(de_ctx, sgh);
1182  if (r != 0) {
1183  FatalError("failed to set up pattern matching");
1184  }
1185 
1186  /* set up engines if needed - when prefilter is set to auto we run
1187  * all engines, otherwise only those that have been forced by the
1188  * prefilter keyword. */
1190  for (int i = 0; i < DETECT_TBLSIZE; i++) {
1191  if (sigmatch_table[i].SetupPrefilter != NULL &&
1192  (setting == DETECT_PREFILTER_AUTO || de_ctx->sm_types_prefilter[i])) {
1194  }
1195  }
1196 
1197  if (SetupNonPrefilter(de_ctx, sgh) != 0) {
1198  return -1;
1199  }
1200 
1201  /* we have lists of engines in sgh->init now. Lets setup the
1202  * match arrays */
1203  PrefilterEngineList *el;
1204  if (sgh->init->pkt_engines != NULL) {
1205  uint32_t cnt = 0;
1206  for (el = sgh->init->pkt_engines ; el != NULL; el = el->next) {
1207  cnt++;
1208  }
1209  sgh->pkt_engines = SCMallocAligned(cnt * sizeof(PrefilterEngine), CLS);
1210  if (sgh->pkt_engines == NULL) {
1211  return -1;
1212  }
1213  memset(sgh->pkt_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
1214 
1215  PrefilterEngine *e = sgh->pkt_engines;
1216  for (el = sgh->init->pkt_engines ; el != NULL; el = el->next) {
1217  e->local_id = el->id;
1218  e->cb.Prefilter = el->Prefilter;
1219  e->ctx.pkt.mask = el->pkt_mask;
1220  // TODO right now we represent the hook in a u8 in the prefilter engine for space
1221  // reasons.
1222  BUG_ON(el->pkt_hook >= 8);
1223  e->ctx.pkt.hook = (uint8_t)el->pkt_hook;
1224  e->pectx = el->pectx;
1225  el->pectx = NULL; // e now owns the ctx
1226  e->gid = el->gid;
1227  if (el->next == NULL) {
1228  e->is_last = true;
1229  }
1230  e++;
1231  }
1232  }
1233  if (sgh->init->payload_engines != NULL) {
1234  uint32_t cnt = 0;
1235  for (el = sgh->init->payload_engines ; el != NULL; el = el->next) {
1236  cnt++;
1237  }
1239  if (sgh->payload_engines == NULL) {
1240  return -1;
1241  }
1242  memset(sgh->payload_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
1243 
1244  PrefilterEngine *e = sgh->payload_engines;
1245  for (el = sgh->init->payload_engines ; el != NULL; el = el->next) {
1246  e->local_id = el->id;
1247  e->cb.Prefilter = el->Prefilter;
1248  e->ctx.pkt.mask = el->pkt_mask;
1249  // TODO right now we represent the hook in a u8 in the prefilter engine for space
1250  // reasons.
1251  BUG_ON(el->pkt_hook >= 8);
1252  e->ctx.pkt.hook = (uint8_t)el->pkt_hook;
1253  e->pectx = el->pectx;
1254  el->pectx = NULL; // e now owns the ctx
1255  e->gid = el->gid;
1256  if (el->next == NULL) {
1257  e->is_last = true;
1258  }
1259  e++;
1260  }
1261  }
1262  if (sgh->init->tx_engines != NULL) {
1263  uint32_t cnt = 0;
1264  for (el = sgh->init->tx_engines ; el != NULL; el = el->next) {
1265  cnt++;
1266  }
1267  sgh->tx_engines = SCMallocAligned(cnt * sizeof(PrefilterEngine), CLS);
1268  if (sgh->tx_engines == NULL) {
1269  return -1;
1270  }
1271  memset(sgh->tx_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
1272 
1273  uint16_t local_id = 0;
1274  PrefilterEngine *e = sgh->tx_engines;
1275  for (el = sgh->init->tx_engines ; el != NULL; el = el->next) {
1276  e->local_id = local_id++;
1277  e->alproto = el->alproto;
1279  e->cb.PrefilterTx = el->PrefilterTx;
1280  e->pectx = el->pectx;
1281  el->pectx = NULL; // e now owns the ctx
1282  e->gid = el->gid;
1283  e++;
1284  }
1285 
1286  /* sort by tx_min_progress, then alproto, then local_id */
1287  qsort(sgh->tx_engines, local_id, sizeof(PrefilterEngine),
1288  PrefilterSetupRuleGroupSortHelper);
1289  sgh->tx_engines[local_id - 1].is_last = true;
1290  sgh->tx_engines[local_id - 1].is_last_for_progress = true;
1291 
1292  PrefilterEngine *engine;
1293 
1294  /* per alproto to set is_last_for_progress per alproto because the inspect
1295  * loop skips over engines that are not the correct alproto */
1296  for (AppProto a = ALPROTO_FAILED + 1; a < g_alproto_max; a++) {
1297  int last_tx_progress = 0;
1298  bool last_tx_progress_set = false;
1299  PrefilterEngine *prev_engine = NULL;
1300  engine = sgh->tx_engines;
1301  do {
1302  if (engine->ctx.tx_min_progress != -1)
1303  BUG_ON(engine->ctx.tx_min_progress < last_tx_progress);
1304  if (engine->alproto == a) {
1305  if (last_tx_progress_set && engine->ctx.tx_min_progress > last_tx_progress) {
1306  if (prev_engine) {
1307  prev_engine->is_last_for_progress = true;
1308  }
1309  }
1310 
1311  last_tx_progress_set = true;
1312  prev_engine = engine;
1313  } else {
1314  if (prev_engine) {
1315  prev_engine->is_last_for_progress = true;
1316  }
1317  }
1318  last_tx_progress = engine->ctx.tx_min_progress;
1319  if (engine->is_last)
1320  break;
1321  engine++;
1322  } while (1);
1323  }
1324 #ifdef DEBUG
1325  SCLogDebug("sgh %p", sgh);
1326  engine = sgh->tx_engines;
1327  do {
1328  SCLogDebug("engine: gid %u alproto %s tx_min_progress %d is_last %s "
1329  "is_last_for_progress %s",
1330  engine->gid, AppProtoToString(engine->alproto), engine->ctx.tx_min_progress,
1331  engine->is_last ? "true" : "false",
1332  engine->is_last_for_progress ? "true" : "false");
1333  if (engine->is_last)
1334  break;
1335  engine++;
1336  } while (1);
1337 #endif
1338  }
1339  if (sgh->init->frame_engines != NULL) {
1340  uint32_t cnt = 0;
1341  for (el = sgh->init->frame_engines; el != NULL; el = el->next) {
1342  cnt++;
1343  }
1345  if (sgh->frame_engines == NULL) {
1346  return -1;
1347  }
1348  memset(sgh->frame_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
1349 
1350  PrefilterEngine *e = sgh->frame_engines;
1351  for (el = sgh->init->frame_engines; el != NULL; el = el->next) {
1352  e->local_id = el->id;
1353  e->ctx.frame_type = el->frame_type;
1354  e->cb.PrefilterFrame = el->PrefilterFrame;
1355  e->alproto = el->alproto;
1356  e->pectx = el->pectx;
1357  el->pectx = NULL; // e now owns the ctx
1358  e->gid = el->gid;
1359  if (el->next == NULL) {
1360  e->is_last = true;
1361  }
1362  e++;
1363  }
1364  }
1365 
1366  if (sgh->init->post_rule_match_engines != NULL) {
1367  uint32_t cnt = 0;
1368  for (el = sgh->init->post_rule_match_engines; el != NULL; el = el->next) {
1369  cnt++;
1370  }
1372  if (sgh->post_rule_match_engines == NULL) {
1373  return -1;
1374  }
1375  memset(sgh->post_rule_match_engines, 0x00, (cnt * sizeof(PrefilterEngine)));
1376 
1377  uint16_t local_id = 0;
1379  for (el = sgh->init->post_rule_match_engines; el != NULL; el = el->next) {
1380  e->local_id = local_id++;
1382  e->pectx = el->pectx;
1383  el->pectx = NULL; // e now owns the ctx
1384  e->gid = el->gid;
1385  e->is_last = (el->next == NULL);
1386  e++;
1387  }
1388  SCLogDebug("sgh %p max local_id %u", sgh, local_id);
1389  }
1390 
1391  return 0;
1392 }
1393 
1394 /* hash table for assigning a unique id to each engine type. */
1395 
1396 static uint32_t PrefilterStoreHashFunc(HashListTable *ht, void *data, uint16_t datalen)
1397 {
1398  PrefilterStore *ctx = data;
1399 
1400  uint32_t hash = (uint32_t)strlen(ctx->name);
1401 
1402  for (size_t u = 0; u < strlen(ctx->name); u++) {
1403  hash += ctx->name[u];
1404  }
1405 
1406  hash %= ht->array_size;
1407  return hash;
1408 }
1409 
1410 static char PrefilterStoreCompareFunc(void *data1, uint16_t len1,
1411  void *data2, uint16_t len2)
1412 {
1413  PrefilterStore *ctx1 = data1;
1414  PrefilterStore *ctx2 = data2;
1415  return (strcmp(ctx1->name, ctx2->name) == 0);
1416 }
1417 
1418 static void PrefilterStoreFreeFunc(void *ptr)
1419 {
1420  SCFree(ptr);
1421 }
1422 
1424 {
1425  if (de_ctx->prefilter_hash_table != NULL) {
1427  }
1428 }
1429 
1431 {
1433 
1435  PrefilterStoreHashFunc,
1436  PrefilterStoreCompareFunc,
1437  PrefilterStoreFreeFunc);
1439 }
1440 
1441 static int PrefilterStoreGetId(DetectEngineCtx *de_ctx,
1442  const char *name, void (*FreeFunc)(void *))
1443 {
1444  PrefilterStore ctx = { name, FreeFunc, 0 };
1445 
1447 
1448  SCLogDebug("looking up %s", name);
1449 
1451  if (rctx != NULL) {
1452  return rctx->id;
1453  }
1454 
1455  PrefilterStore *actx = SCCalloc(1, sizeof(*actx));
1456  if (actx == NULL) {
1457  return -1;
1458  }
1459 
1460  actx->name = name;
1461  actx->FreeFunc = FreeFunc;
1462  actx->id = de_ctx->prefilter_id++;
1463  SCLogDebug("prefilter engine %s has profile id %u", actx->name, actx->id);
1464 
1465  int ret = HashListTableAdd(de_ctx->prefilter_hash_table, actx, 0);
1466  if (ret != 0) {
1467  SCFree(actx);
1468  return -1;
1469  }
1470 
1471  int r = actx->id;
1472  return r;
1473 }
1474 
1475 /** \warning slow */
1476 static const PrefilterStore *PrefilterStoreGetStore(const DetectEngineCtx *de_ctx,
1477  const uint32_t id)
1478 {
1479 
1480  const PrefilterStore *store = NULL;
1481  if (de_ctx->prefilter_hash_table != NULL) {
1483  for ( ; hb != NULL; hb = HashListTableGetListNext(hb)) {
1485  if (ctx->id == id) {
1486  store = ctx;
1487  break;
1488  }
1489  }
1490  }
1491  return store;
1492 }
1493 
1494 #include "util-print.h"
1495 
1496 typedef struct PrefilterMpmCtx {
1497  int list_id;
1498  union {
1501  };
1502  const MpmCtx *mpm_ctx;
1505 
1506 /** \brief Generic Mpm prefilter callback for simple InspectionSingleBufferGetDataPtr
1507  *
1508  * \param det_ctx detection engine thread ctx
1509  * \param p packet to inspect
1510  * \param f flow to inspect
1511  * \param txv tx to inspect
1512  * \param pectx inspection context
1513  */
1514 static void PrefilterMpmTxSingle(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p,
1515  Flow *f, void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
1516 {
1517  SCEnter();
1518 
1519  const PrefilterMpmCtx *ctx = (const PrefilterMpmCtx *)pectx;
1520  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
1521  SCLogDebug("running on list %d", ctx->list_id);
1522 
1524  det_ctx, ctx->transforms, f, flags, txv, ctx->list_id, ctx->GetDataSingle);
1525  if (buffer == NULL)
1526  return;
1527 
1528  const uint32_t data_len = buffer->inspect_len;
1529  const uint8_t *data = buffer->inspect;
1530 
1531  SCLogDebug("mpm'ing buffer:");
1532  // PrintRawDataFp(stdout, data, data_len);
1533 
1534  if (data != NULL && data_len >= mpm_ctx->minlen) {
1535  (void)mpm_table[mpm_ctx->mpm_type].Search(
1536  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
1537  PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
1538  }
1539 }
1540 
1541 /** \brief Generic Mpm prefilter callback
1542  *
1543  * \param det_ctx detection engine thread ctx
1544  * \param p packet to inspect
1545  * \param f flow to inspect
1546  * \param txv tx to inspect
1547  * \param pectx inspection context
1548  */
1549 static void PrefilterMpm(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f,
1550  void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
1551 {
1552  SCEnter();
1553 
1554  const PrefilterMpmCtx *ctx = (const PrefilterMpmCtx *)pectx;
1555  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
1556  SCLogDebug("running on list %d", ctx->list_id);
1557 
1558  InspectionBuffer *buffer = ctx->GetData(det_ctx, ctx->transforms, f, flags, txv, ctx->list_id);
1559  if (buffer == NULL)
1560  return;
1561 
1562  const uint32_t data_len = buffer->inspect_len;
1563  const uint8_t *data = buffer->inspect;
1564 
1565  SCLogDebug("mpm'ing buffer:");
1566  //PrintRawDataFp(stdout, data, data_len);
1567 
1568  if (data != NULL && data_len >= mpm_ctx->minlen) {
1569  (void)mpm_table[mpm_ctx->mpm_type].Search(
1570  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
1571  PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
1572  }
1573 }
1574 
1575 static void PrefilterGenericMpmFree(void *ptr)
1576 {
1577  SCFree(ptr);
1578 }
1579 
1581  const DetectBufferMpmRegistry *mpm_reg, int list_id)
1582 {
1583  SCEnter();
1584  PrefilterMpmCtx *pectx = SCCalloc(1, sizeof(*pectx));
1585  if (pectx == NULL)
1586  return -1;
1587  pectx->list_id = list_id;
1588  pectx->GetData = mpm_reg->app_v2.GetData;
1589  pectx->mpm_ctx = mpm_ctx;
1590  pectx->transforms = &mpm_reg->transforms;
1591 
1593  mpm_reg->app_v2.alproto, mpm_reg->app_v2.tx_min_progress,
1594  pectx, PrefilterGenericMpmFree, mpm_reg->pname);
1595  if (r != 0) {
1596  SCFree(pectx);
1597  }
1598  return r;
1599 }
1600 
1602  const DetectBufferMpmRegistry *mpm_reg, int list_id)
1603 {
1604  SCEnter();
1605  PrefilterMpmCtx *pectx = SCCalloc(1, sizeof(*pectx));
1606  if (pectx == NULL)
1607  return -1;
1608  pectx->list_id = list_id;
1609  pectx->GetDataSingle = mpm_reg->app_v2.GetDataSingle;
1610  pectx->mpm_ctx = mpm_ctx;
1611  pectx->transforms = &mpm_reg->transforms;
1612 
1613  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMpmTxSingle, mpm_reg->app_v2.alproto,
1614  mpm_reg->app_v2.tx_min_progress, pectx, PrefilterGenericMpmFree, mpm_reg->pname);
1615  if (r != 0) {
1616  SCFree(pectx);
1617  }
1618  return r;
1619 }
1620 
1621 static void PrefilterMultiGenericMpmFree(void *ptr)
1622 {
1623  // PrefilterMpmListId
1624  SCFree(ptr);
1625 }
1626 
1627 static void PrefilterMultiMpm(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f,
1628  void *txv, const uint64_t idx, const AppLayerTxData *_txd, const uint8_t flags)
1629 {
1630  SCEnter();
1631 
1632  const PrefilterMpmListId *ctx = (const PrefilterMpmListId *)pectx;
1633  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
1634  SCLogDebug("running on list %d", ctx->list_id);
1635  uint32_t local_id = 0;
1636 
1637  do {
1638  // loop until we get a NULL
1640  det_ctx, ctx->transforms, f, flags, txv, ctx->list_id, local_id, ctx->GetData);
1641  if (buffer == NULL)
1642  break;
1643 
1644  if (buffer->inspect_len >= mpm_ctx->minlen) {
1645  (void)mpm_table[mpm_ctx->mpm_type].Search(
1646  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, buffer->inspect, buffer->inspect_len);
1647  PREFILTER_PROFILING_ADD_BYTES(det_ctx, buffer->inspect_len);
1648  }
1649 
1650  local_id++;
1651  } while (1);
1652 }
1653 
1655  const DetectBufferMpmRegistry *mpm_reg, int list_id)
1656 {
1657  SCEnter();
1658  PrefilterMpmListId *pectx = SCCalloc(1, sizeof(*pectx));
1659  if (pectx == NULL)
1660  return -1;
1661  pectx->list_id = list_id;
1662  pectx->GetData = mpm_reg->app_v2.GetMultiData;
1663  pectx->mpm_ctx = mpm_ctx;
1664  pectx->transforms = &mpm_reg->transforms;
1665 
1666  int r = PrefilterAppendTxEngine(de_ctx, sgh, PrefilterMultiMpm, mpm_reg->app_v2.alproto,
1667  mpm_reg->app_v2.tx_min_progress, pectx, PrefilterMultiGenericMpmFree, mpm_reg->pname);
1668  if (r != 0) {
1669  SCFree(pectx);
1670  }
1671  return r;
1672 }
1673 
1674 /* generic mpm for pkt engines */
1675 
1676 typedef struct PrefilterMpmPktCtx {
1677  int list_id;
1679  const MpmCtx *mpm_ctx;
1682 
1683 /** \brief Generic Mpm prefilter callback
1684  *
1685  * \param det_ctx detection engine thread ctx
1686  * \param p packet to inspect
1687  * \param f flow to inspect
1688  * \param txv tx to inspect
1689  * \param pectx inspection context
1690  */
1691 static void PrefilterMpmPkt(DetectEngineThreadCtx *det_ctx,
1692  Packet *p, const void *pectx)
1693 {
1694  SCEnter();
1695 
1696  const PrefilterMpmPktCtx *ctx = (const PrefilterMpmPktCtx *)pectx;
1697  const MpmCtx *mpm_ctx = ctx->mpm_ctx;
1698  SCLogDebug("running on list %d", ctx->list_id);
1699 
1700  InspectionBuffer *buffer = ctx->GetData(det_ctx, ctx->transforms,
1701  p, ctx->list_id);
1702  if (buffer == NULL)
1703  return;
1704 
1705  const uint32_t data_len = buffer->inspect_len;
1706  const uint8_t *data = buffer->inspect;
1707 
1708  SCLogDebug("mpm'ing buffer:");
1709  //PrintRawDataFp(stdout, data, data_len);
1710 
1711  if (data != NULL && data_len >= mpm_ctx->minlen) {
1712  (void)mpm_table[mpm_ctx->mpm_type].Search(
1713  mpm_ctx, &det_ctx->mtc, &det_ctx->pmq, data, data_len);
1714  PREFILTER_PROFILING_ADD_BYTES(det_ctx, data_len);
1715  }
1716 }
1717 
1718 static void PrefilterMpmPktFree(void *ptr)
1719 {
1720  SCFree(ptr);
1721 }
1722 
1724  const DetectBufferMpmRegistry *mpm_reg, int list_id)
1725 {
1726  SCEnter();
1727  PrefilterMpmPktCtx *pectx = SCCalloc(1, sizeof(*pectx));
1728  if (pectx == NULL)
1729  return -1;
1730  pectx->list_id = list_id;
1731  pectx->GetData = mpm_reg->pkt_v1.GetData;
1732  pectx->mpm_ctx = mpm_ctx;
1733  pectx->transforms = &mpm_reg->transforms;
1734 
1735  enum SignatureHookPkt hook = SIGNATURE_HOOK_PKT_NOT_SET; // TODO review
1736  int r = PrefilterAppendEngine(
1737  de_ctx, sgh, PrefilterMpmPkt, 0, hook, pectx, PrefilterMpmPktFree, mpm_reg->pname);
1738  if (r != 0) {
1739  SCFree(pectx);
1740  }
1741  return r;
1742 }
1743 
1744 #define QUEUE_STEP 16
1747  DetectEngineThreadCtx *det_ctx, const Signature *s, const int type, const uint32_t value)
1748 {
1749  if (det_ctx->post_rule_work_queue.q == NULL) {
1750  det_ctx->post_rule_work_queue.q =
1752  if (det_ctx->post_rule_work_queue.q == NULL) {
1754  return;
1755  }
1757  } else if (det_ctx->post_rule_work_queue.len == det_ctx->post_rule_work_queue.size) {
1758  void *ptr = SCRealloc(
1759  det_ctx->post_rule_work_queue.q, (det_ctx->post_rule_work_queue.size + QUEUE_STEP) *
1760  sizeof(PostRuleMatchWorkQueueItem));
1761  if (ptr == NULL) {
1763  return;
1764  }
1765  det_ctx->post_rule_work_queue.q = ptr;
1766  det_ctx->post_rule_work_queue.size += QUEUE_STEP;
1767  }
1769  det_ctx->post_rule_work_queue.q[det_ctx->post_rule_work_queue.len].value = value;
1770 #ifdef DEBUG
1771  det_ctx->post_rule_work_queue.q[det_ctx->post_rule_work_queue.len].id = s->iid;
1772 #endif
1773  det_ctx->post_rule_work_queue.len++;
1774  SCLogDebug("det_ctx->post_rule_work_queue.len %u", det_ctx->post_rule_work_queue.len);
1775 }
HashListTableGetListData
#define HashListTableGetListData(hb)
Definition: util-hashlist.h:56
PrefilterGenericMpmPktRegister
int PrefilterGenericMpmPktRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1723
detect-engine-uint.h
PrefilterEngineList_::frame_type
uint8_t frame_type
Definition: detect.h:1547
SigGroupHead_::tx_engines
PrefilterEngine * tx_engines
Definition: detect.h:1650
DetectEngineAppInspectionEngine_
Definition: detect.h:416
DetectGetMultiData
InspectionBuffer * DetectGetMultiData(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id, uint32_t index, InspectionMultiBufferGetDataPtr GetBuf)
Definition: detect-engine.c:2125
Packet_::proto
uint8_t proto
Definition: decode.h:527
util-hash-string.h
DetectTransaction_::tx_data_ptr
struct AppLayerTxData * tx_data_ptr
Definition: detect-engine-prefilter.h:34
PrefilterEngineList_::Prefilter
PrefilterPktFn Prefilter
Definition: detect.h:1557
MpmCtx_::mpm_type
uint8_t mpm_type
Definition: util-mpm.h:99
detect-engine.h
PrefilterNonPFDataSig::sid
uint32_t sid
Definition: detect-engine-prefilter.c:537
PrefilterEngine_::PrefilterPostRule
void(* PrefilterPostRule)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f)
Definition: detect.h:1601
DetectGetSingleData
InspectionBuffer * DetectGetSingleData(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id, InspectionSingleBufferGetDataPtr GetBuf)
Definition: detect-engine.c:2108
sigmatch_table
SigTableElmt * sigmatch_table
Definition: detect-parse.c:79
PostRuleMatchWorkQueueAppend
void PostRuleMatchWorkQueueAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, const int type, const uint32_t value)
Definition: detect-engine-prefilter.c:1746
AppLayerParserGetStateNameById
const char * AppLayerParserGetStateNameById(uint8_t ipproto, AppProto alproto, const int id, const uint8_t direction)
Definition: app-layer-parser.c:1641
SignatureHook_::sm_list
int sm_list
Definition: detect.h:574
PatternMatchPrepareGroup
int PatternMatchPrepareGroup(DetectEngineCtx *de_ctx, SigGroupHead *sh)
Prepare the pattern matcher ctx in a sig group head.
Definition: detect-engine-mpm.c:2326
PrefilterMpmPktCtx
struct PrefilterMpmPktCtx PrefilterMpmPktCtx
PrefilterStore_::FreeFunc
void(* FreeFunc)(void *)
Definition: detect-engine-prefilter.h:49
PostRuleMatchWorkQueue::len
uint32_t len
Definition: detect.h:1235
PostRuleMatchWorkQueueItem::sm_type
int sm_type
Definition: detect.h:1224
PREFILTER_PROFILING_END
#define PREFILTER_PROFILING_END(ctx, profile_id)
Definition: util-profiling.h:276
PrefilterStore_
Definition: detect-engine-prefilter.h:47
CLS
#define CLS
Definition: suricata-common.h:69
PrefilterRuleStore_::rule_id_array_cnt
uint32_t rule_id_array_cnt
Definition: util-prefilter.h:40
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1638
PostRuleMatchWorkQueueItem
Definition: detect.h:1223
PrefilterNonPFData::size
uint32_t size
Definition: detect-engine-prefilter.c:557
DetectEngineTransforms
Definition: detect.h:391
PrefilterEngineList_::id
uint16_t id
Definition: detect.h:1539
PROF_DETECT_PF_PAYLOAD
@ PROF_DETECT_PF_PAYLOAD
Definition: suricata-common.h:463
BIT_U16
#define BIT_U16(n)
Definition: suricata-common.h:416
SignatureInitData_::prefilter_sm
SigMatch * prefilter_sm
Definition: detect.h:626
PcapPacketCntGet
uint64_t PcapPacketCntGet(const Packet *p)
Definition: decode.c:1107
Signature_::alproto
AppProto alproto
Definition: detect.h:677
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
QUEUE_STEP
#define QUEUE_STEP
Definition: detect-engine-prefilter.c:1744
TxNonPFData::progress
int progress
Definition: detect-engine-prefilter.c:706
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
DetectPort_::port
uint16_t port
Definition: detect.h:220
SignatureHook_::app
struct SignatureHook_::@87::@88 app
DetectBufferMpmRegistry_::app_v2
struct DetectBufferMpmRegistry_::@90::@92 app_v2
name
const char * name
Definition: detect-engine-proto.c:48
PrefilterSingleMpmRegister
int PrefilterSingleMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1601
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:86
PrefilterMpmCtx::GetData
InspectionBufferGetDataPtr GetData
Definition: detect-engine-prefilter.c:1499
InspectionBuffer
Definition: detect-engine-inspect-buffer.h:34
SignatureHook_::t
union SignatureHook_::@87 t
PrefilterAppendEngine
int PrefilterAppendEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterPktFn PrefilterFunc, SignatureMask mask, enum SignatureHookPkt hook, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:285
Packet_::flags
uint32_t flags
Definition: decode.h:551
Frame
Definition: app-layer-frames.h:43
Flow_
Flow data structure.
Definition: flow.h:347
PrefilterEngine_::tx_min_progress
int8_t tx_min_progress
Definition: detect.h:1586
PREFILTER_PROFILING_START
#define PREFILTER_PROFILING_START(det_ctx)
Definition: util-profiling.h:260
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1358
AppProtoToString
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
Definition: app-layer-protos.c:41
ctx
struct Thresholds ctx
PrefilterEngineList_::name
const char * name
Definition: detect.h:1568
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:937
SIGNATURE_HOOK_PKT_NOT_SET
@ SIGNATURE_HOOK_PKT_NOT_SET
Definition: detect.h:540
HashListTableGetListHead
HashListTableBucket * HashListTableGetListHead(HashListTable *ht)
Definition: util-hashlist.c:287
DETECT_UINT_EQ
#define DETECT_UINT_EQ
Definition: detect-engine-uint.h:35
PrefilterNonPFData
Definition: detect-engine-prefilter.c:556
InspectionBufferGetPktDataPtr
InspectionBuffer *(* InspectionBufferGetPktDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Packet *p, const int list_id)
Definition: detect.h:479
PrefilterEngine_::cb
union PrefilterEngine_::@105 cb
PrefilterDeinit
void PrefilterDeinit(DetectEngineCtx *de_ctx)
Definition: detect-engine-prefilter.c:1423
TxNonPFData::engine_name
const char * engine_name
Definition: detect-engine-prefilter.c:711
HashTable_
Definition: util-hash.h:35
DetectEngineSetEvent
void DetectEngineSetEvent(DetectEngineThreadCtx *det_ctx, uint8_t e)
Definition: detect-engine.c:5047
Packet_::sig_mask
SignatureMask sig_mask
Definition: decode.h:542
Frames
Definition: app-layer-frames.h:58
DetectBufferMpmRegistry_
one time registration of keywords at start up
Definition: detect.h:767
DetectPort_::next
struct DetectPort_ * next
Definition: detect.h:233
PrefilterNonPFDataTx
Definition: detect-engine-prefilter.c:561
PrefilterMpmPktCtx
Definition: detect-engine-prefilter.c:1676
detect-engine-frame.h
SigGroupHead_::payload_engines
PrefilterEngine * payload_engines
Definition: detect.h:1649
DetectEngineCtx_::prefilter_setting
enum DetectEnginePrefilterSetting prefilter_setting
Definition: detect.h:1072
DetectBufferType_
Definition: detect.h:449
PKT_NOPAYLOAD_INSPECTION
#define PKT_NOPAYLOAD_INSPECTION
Definition: decode.h:1279
PrefilterNonPFData::array
struct PrefilterNonPFDataSig array[]
Definition: detect-engine-prefilter.c:558
PostRuleMatchWorkQueue::size
uint32_t size
Definition: detect.h:1236
PACKET_PROFILING_DETECT_END
#define PACKET_PROFILING_DETECT_END(p, id)
Definition: util-profiling.h:221
HashListTableLookup
void * HashListTableLookup(HashListTable *ht, void *data, uint16_t datalen)
Definition: util-hashlist.c:245
TxNonPFData::sig_list
int sig_list
Definition: detect-engine-prefilter.c:707
PrefilterEngine_::local_id
uint16_t local_id
Definition: detect.h:1574
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:536
PrefilterEngineList_::Free
void(* Free)(void *pectx)
Definition: detect.h:1566
StringHashCompareFunc
char StringHashCompareFunc(void *data1, uint16_t datalen1, void *data2, uint16_t datalen2)
Definition: util-hash-string.c:38
SIG_FLAG_TOCLIENT
#define SIG_FLAG_TOCLIENT
Definition: detect.h:271
PrefilterAppendFrameEngine
int PrefilterAppendFrameEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterFrameFn PrefilterFrameFunc, AppProto alproto, uint8_t frame_type, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:392
DetectBufferMpmRegistry_::transforms
DetectEngineTransforms transforms
Definition: detect.h:780
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:610
Signature_::dsize_low
uint16_t dsize_low
Definition: detect.h:679
DetectPort_::port2
uint16_t port2
Definition: detect.h:221
DetectEngineCtx_::non_pf_engine_names
HashTable * non_pf_engine_names
Definition: detect.h:1150
DetectTransaction_::tx_progress
const int tx_progress
Definition: detect-engine-prefilter.h:43
detect-engine-prefilter.h
PrefilterMultiGenericMpmRegister
int PrefilterMultiGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1654
PrefilterNonPFDataSig::foo
uint8_t foo
Definition: detect-engine-prefilter.c:551
PrefilterStore_::id
uint32_t id
Definition: detect-engine-prefilter.h:50
DetectBufferTypeGetByName
int DetectBufferTypeGetByName(const char *name)
Definition: detect-engine.c:1278
HashListTableAdd
int HashListTableAdd(HashListTable *ht, void *data, uint16_t datalen)
Definition: util-hashlist.c:114
HashTable_::array_size
uint32_t array_size
Definition: util-hash.h:37
DetectBufferMpmRegistry_::pkt_v1
struct DetectBufferMpmRegistry_::@90::@93 pkt_v1
DETECT_PREFILTER_AUTO
@ DETECT_PREFILTER_AUTO
Definition: detect.h:902
HashListTable_::array_size
uint32_t array_size
Definition: util-hashlist.h:41
PrefilterEngine_::is_last_for_progress
bool is_last_for_progress
Definition: detect.h:1591
PROF_DETECT_PF_SORT1
@ PROF_DETECT_PF_SORT1
Definition: suricata-common.h:466
DetectEngineCtx_::prefilter_id
uint32_t prefilter_id
Definition: detect.h:1103
FRAME_ANY_TYPE
#define FRAME_ANY_TYPE
Definition: app-layer-frames.h:28
PrefilterEngineList_::next
struct PrefilterEngineList_ * next
Definition: detect.h:1563
SigTableElmt_::SetupPrefilter
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
Definition: detect.h:1453
SIGNATURE_HOOK_TYPE_APP
@ SIGNATURE_HOOK_TYPE_APP
Definition: detect.h:550
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:471
HashListTableGetListNext
#define HashListTableGetListNext(hb)
Definition: util-hashlist.h:55
PrefilterMpmListId
Definition: detect-engine-mpm.h:123
DetectEngineCtx_::prefilter_hash_table
HashListTable * prefilter_hash_table
Definition: detect.h:1104
SIG_FLAG_TOSERVER
#define SIG_FLAG_TOSERVER
Definition: detect.h:270
app-layer-htp.h
HashListTableInit
HashListTable * HashListTableInit(uint32_t size, uint32_t(*Hash)(struct HashListTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hashlist.c:35
DetectBufferMpmRegistry_::pname
char pname[DETECT_PROFILE_NAME_LEN]
Definition: detect.h:769
PrefilterEngineList_::pkt_hook
enum SignatureHookPkt pkt_hook
Definition: detect.h:1551
PrefilterEngineList_::alproto
AppProto alproto
Definition: detect.h:1542
SigGroupHeadInitData_::sig_cnt
SigIntId sig_cnt
Definition: detect.h:1631
AppLayerTxData
Definition: app-layer-parser.h:177
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:19
g_alproto_max
AppProto g_alproto_max
Definition: app-layer-protos.c:30
Prefilter
void Prefilter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t flags, const SignatureMask mask)
Definition: detect-engine-prefilter.c:219
DetectEngineThreadCtx_
Definition: detect.h:1252
PrefilterEngine_
Definition: detect.h:1573
SigGroupHeadInitData_::tx_engines
PrefilterEngineList * tx_engines
Definition: detect.h:1626
DetectTransaction_::detect_progress
uint8_t detect_progress
Definition: detect-engine-prefilter.h:39
SignatureInitData_::mpm_sm
SigMatch * mpm_sm
Definition: detect.h:624
DetectEngineGetMaxSigId
#define DetectEngineGetMaxSigId(de_ctx)
Definition: detect-engine.h:93
PROF_DETECT_PF_PKT
@ PROF_DETECT_PF_PKT
Definition: suricata-common.h:462
PrefilterEngineList_::PrefilterFrame
PrefilterFrameFn PrefilterFrame
Definition: detect.h:1559
PrefilterEngine_::ctx
union PrefilterEngine_::@104 ctx
PrefilterEngineList_::pectx
void * pectx
Definition: detect.h:1555
util-print.h
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
detect-engine-mpm.h
PrefilterEngineList_::PrefilterTx
PrefilterTxFn PrefilterTx
Definition: detect.h:1558
DetectEngineCtx_::sm_types_prefilter
bool * sm_types_prefilter
Definition: detect.h:1119
TxNonPFData
Definition: detect-engine-prefilter.c:703
SignatureHookPkt
SignatureHookPkt
Definition: detect.h:539
PrefilterEngineList_::gid
uint32_t gid
Definition: detect.h:1570
PrefilterMpmPktCtx::GetData
InspectionBufferGetPktDataPtr GetData
Definition: detect-engine-prefilter.c:1678
PKT_DETECT_HAS_STREAMDATA
#define PKT_DETECT_HAS_STREAMDATA
Definition: decode.h:1332
InspectionSingleBufferGetDataPtr
bool(* InspectionSingleBufferGetDataPtr)(const void *txv, const uint8_t flow_flags, const uint8_t **buf, uint32_t *buf_len)
Definition: detect-engine-helper.h:45
FLOW_PKT_TOCLIENT_FIRST
#define FLOW_PKT_TOCLIENT_FIRST
Definition: flow.h:228
PrefilterMpmCtx
struct PrefilterMpmCtx PrefilterMpmCtx
NONPF_PKT_STATS_INCR
#define NONPF_PKT_STATS_INCR(s)
Definition: detect-engine-prefilter.c:590
DetectEngineCtx_::frame_inspect_engines
DetectEngineFrameInspectionEngine * frame_inspect_engines
Definition: detect.h:1099
PrefilterGenericMpmRegister
int PrefilterGenericMpmRegister(DetectEngineCtx *de_ctx, SigGroupHead *sgh, MpmCtx *mpm_ctx, const DetectBufferMpmRegistry *mpm_reg, int list_id)
Definition: detect-engine-prefilter.c:1580
PrefilterFrameFn
void(* PrefilterFrameFn)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, const struct Frames *frames, const struct Frame *frame)
Definition: detect.h:1531
HashTableAdd
int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:120
PrefilterNonPFDataTx::array
uint32_t array[]
Definition: detect-engine-prefilter.c:563
SigGroupHead_::init
SigGroupHeadInitData * init
Definition: detect.h:1655
SignatureHook_::pkt
struct SignatureHook_::@87::@89 pkt
PrefilterMpmListId::transforms
const DetectEngineTransforms * transforms
Definition: detect-engine-mpm.h:127
app-layer-parser.h
MpmCtx_::minlen
uint16_t minlen
Definition: util-mpm.h:108
Packet_::pkt_hooks
uint16_t pkt_hooks
Definition: decode.h:545
PrefilterNonPFDataSig::type
uint8_t type
Definition: detect-engine-prefilter.c:548
SignatureInitData_::hook
SignatureHook hook
Definition: detect.h:591
SigGroupHeadInitData_::direction
uint32_t direction
Definition: detect.h:1616
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:317
PrefilterEngine_::pkt
struct PrefilterEngine_::@104::@106 pkt
util-profiling.h
DetectTransaction_::tx_id
const uint64_t tx_id
Definition: detect-engine-prefilter.h:33
SigIntId
#define SigIntId
Definition: detect-engine-state.h:38
SCReturn
#define SCReturn
Definition: util-debug.h:286
PrefilterEngine_::alproto
AppProto alproto
Definition: detect.h:1577
Signature_::flags
uint32_t flags
Definition: detect.h:673
PrefilterMpmListId::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-mpm.h:125
Packet_
Definition: decode.h:505
SCFreeAligned
#define SCFreeAligned(p)
Definition: util-mem.h:77
Flow_::type
uint8_t type
Definition: flow.h:354
type
uint16_t type
Definition: decode-vlan.c:106
DetectBufferType_::packet
bool packet
Definition: detect.h:455
DetectEngineFrameInspectionEngine
Definition: detect.h:509
DetectEngineBufferTypeGetById
const DetectBufferType * DetectEngineBufferTypeGetById(const DetectEngineCtx *de_ctx, const int id)
Definition: detect-engine.c:1298
PrefilterEngine_::PrefilterFrame
PrefilterFrameFn PrefilterFrame
Definition: detect.h:1600
PrefilterEngine_::frame_type
uint8_t frame_type
Definition: detect.h:1587
DetectBufferType_::name
char name[64]
Definition: detect.h:450
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:751
HashListTable_
Definition: util-hashlist.h:37
PrefilterTxFn
void(* PrefilterTxFn)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f, void *tx, const uint64_t tx_id, const AppLayerTxData *tx_data, const uint8_t flags)
Definition: detect.h:1535
MpmTableElmt_::Search
uint32_t(* Search)(const struct MpmCtx_ *, struct MpmThreadCtx_ *, PrefilterRuleStore *, const uint8_t *, uint32_t)
Definition: util-mpm.h:186
SigGroupHead_::frame_engines
PrefilterEngine * frame_engines
Definition: detect.h:1651
PrefilterMpmCtx::list_id
int list_id
Definition: detect-engine-prefilter.c:1497
DetectEngineThreadCtx_::mtc
MpmThreadCtx mtc
Definition: detect.h:1354
Flow_::next
struct Flow_ * next
Definition: flow.h:394
PrefilterMpmPktCtx::list_id
int list_id
Definition: detect-engine-prefilter.c:1677
PrefilterAppendPayloadEngine
int PrefilterAppendPayloadEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterPktFn PrefilterFunc, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:323
PrefilterEngineList_::tx_min_progress
int8_t tx_min_progress
Definition: detect.h:1545
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
SIG_FLAG_MPM_NEG
#define SIG_FLAG_MPM_NEG
Definition: detect.h:256
SigGroupHeadInitData_::pkt_engines
PrefilterEngineList * pkt_engines
Definition: detect.h:1624
SigGroupHead_::post_rule_match_engines
PrefilterEngine * post_rule_match_engines
Definition: detect.h:1652
DetectBufferType_::frame
bool frame
Definition: detect.h:456
cnt
uint32_t cnt
Definition: tmqh-packetpool.h:7
PREFILTER_PROFILING_ADD_BYTES
#define PREFILTER_PROFILING_ADD_BYTES(det_ctx, bytes)
Definition: util-profiling.h:286
Packet_::flow
struct Flow_ * flow
Definition: decode.h:553
PrefilterNonPFDataSig::type
uint32_t type
Definition: detect-engine-prefilter.c:538
flags
uint8_t flags
Definition: decode-gre.h:0
PrefilterNonPFDataTx::size
uint32_t size
Definition: detect-engine-prefilter.c:562
suricata-common.h
SigGroupHeadInitData_::frame_engines
PrefilterEngineList * frame_engines
Definition: detect.h:1627
SigGroupHeadInitData_::payload_engines
PrefilterEngineList * payload_engines
Definition: detect.h:1625
PrefilterNonPFDataSig::sig_mask
SignatureMask sig_mask
Definition: detect-engine-prefilter.c:544
HashListTableFree
void HashListTableFree(HashListTable *ht)
Definition: util-hashlist.c:88
SigGroupHeadInitData_::match_array
Signature ** match_array
Definition: detect.h:1634
PROF_DETECT_PF_RECORD
@ PROF_DETECT_PF_RECORD
Definition: suricata-common.h:465
SCMallocAligned
#define SCMallocAligned(size, align)
Definition: util-mem.h:68
DetectEnginePrefilterSetting
DetectEnginePrefilterSetting
Definition: detect.h:900
SignatureHook_::type
enum SignatureHookType type
Definition: detect.h:573
DetectTransaction_
Definition: detect-engine-prefilter.h:31
PrefilterEngineList_::PrefilterPostRule
void(* PrefilterPostRule)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f)
Definition: detect.h:1560
PrefilterEngineList_
Definition: detect.h:1538
PrefilterCleanupRuleGroup
void PrefilterCleanupRuleGroup(const DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-prefilter.c:496
PostRuleMatchWorkQueue::q
PostRuleMatchWorkQueueItem * q
Definition: detect.h:1234
PrefilterEngine_::gid
uint32_t gid
Definition: detect.h:1606
PrefilterNonPFDataSig::app
struct PrefilterNonPFDataSig::@53::@57 app
SCStrdup
#define SCStrdup(s)
Definition: util-mem.h:56
FatalError
#define FatalError(...)
Definition: util-debug.h:517
SIGNATURE_HOOK_TYPE_PKT
@ SIGNATURE_HOOK_TYPE_PKT
Definition: detect.h:549
PrefilterMpmPktCtx::transforms
const DetectEngineTransforms * transforms
Definition: detect-engine-prefilter.c:1680
PrefilterAppendTxEngine
int PrefilterAppendTxEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, PrefilterTxFn PrefilterTxFunc, AppProto alproto, int tx_min_progress, void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:355
PrefilterPktFn
void(* PrefilterPktFn)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx)
Definition: detect.h:1530
PrefilterMpmCtx
Definition: detect-engine-prefilter.c:1496
PrefilterMpmListId::GetData
InspectionMultiBufferGetDataPtr GetData
Definition: detect-engine-mpm.h:126
util-validate.h
DetectTransaction_::tx_ptr
void * tx_ptr
Definition: detect-engine-prefilter.h:32
InspectionBuffer::inspect_len
uint32_t inspect_len
Definition: detect-engine-inspect-buffer.h:37
SignatureInitData_::buffers
SignatureInitDataBuffer * buffers
Definition: detect.h:651
DetectEngineCtx_::app_inspect_engines
DetectEngineAppInspectionEngine * app_inspect_engines
Definition: detect.h:1095
PrefilterEngine_::pectx
void * pectx
Definition: detect.h:1595
PrefilterAppendPostRuleEngine
int PrefilterAppendPostRuleEngine(DetectEngineCtx *de_ctx, SigGroupHead *sgh, void(*PrefilterPostRuleFunc)(DetectEngineThreadCtx *det_ctx, const void *pectx, Packet *p, Flow *f), void *pectx, void(*FreeFunc)(void *pectx), const char *name)
Definition: detect-engine-prefilter.c:427
Signature_::dp
DetectPort * dp
Definition: detect.h:723
PrefilterInit
void PrefilterInit(DetectEngineCtx *de_ctx)
Definition: detect-engine-prefilter.c:1430
InspectionBuffer::inspect
const uint8_t * inspect
Definition: detect-engine-inspect-buffer.h:35
PACKET_PROFILING_DETECT_START
#define PACKET_PROFILING_DETECT_START(p, id)
Definition: util-profiling.h:214
str
#define str(s)
Definition: suricata-common.h:308
PrefilterMpmCtx::transforms
const DetectEngineTransforms * transforms
Definition: detect-engine-prefilter.c:1503
DETECT_TBLSIZE
int DETECT_TBLSIZE
Definition: detect-engine-register.c:265
TxNonPFData::dir
int dir
Definition: detect-engine-prefilter.c:705
Signature_::iid
SigIntId iid
Definition: detect.h:684
TxNonPFData::sigs_cnt
uint32_t sigs_cnt
Definition: detect-engine-prefilter.c:709
PrefilterStore_::name
const char * name
Definition: detect-engine-prefilter.h:48
SCFree
#define SCFree(p)
Definition: util-mem.h:61
SigGroupHeadInitData_::post_rule_match_engines
PrefilterEngineList * post_rule_match_engines
Definition: detect.h:1628
Signature_::id
uint32_t id
Definition: detect.h:717
HashListTableBucket_
Definition: util-hashlist.h:28
PrefilterMpmPktCtx::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-prefilter.c:1679
PrefilterNonPFDataSig
Definition: detect-engine-prefilter.c:536
SignatureInitDataBuffer_::id
uint32_t id
Definition: detect.h:526
Signature_
Signature container.
Definition: detect.h:672
PrefilterEngineList_::pkt_mask
SignatureMask pkt_mask
Definition: detect.h:1549
PrefilterMpmListId::list_id
int list_id
Definition: detect-engine-mpm.h:124
TxNonPFData::alproto
AppProto alproto
Definition: detect-engine-prefilter.c:704
HashTableInit
HashTable * HashTableInit(uint32_t size, uint32_t(*Hash)(struct HashTable_ *, void *, uint16_t), char(*Compare)(void *, uint16_t, void *, uint16_t), void(*Free)(void *))
Definition: util-hash.c:35
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
ALPROTO_FAILED
@ ALPROTO_FAILED
Definition: app-layer-protos.h:33
PostRuleMatchWorkQueueItem::value
uint32_t value
Definition: detect.h:1225
Signature_::dsize_mode
uint8_t dsize_mode
Definition: detect.h:681
mpm_table
MpmTableElmt mpm_table[MPM_TABLE_SIZE]
Definition: util-mpm.c:47
PrefilterSetupRuleGroup
int PrefilterSetupRuleGroup(DetectEngineCtx *de_ctx, SigGroupHead *sgh)
Definition: detect-engine-prefilter.c:1179
SIGNATURE_HOOK_PKT_FLOW_START
@ SIGNATURE_HOOK_PKT_FLOW_START
Definition: detect.h:541
PrefilterEngine_::is_last
bool is_last
Definition: detect.h:1590
suricata.h
InspectionBufferGetDataPtr
InspectionBuffer *(* InspectionBufferGetDataPtr)(struct DetectEngineThreadCtx_ *det_ctx, const DetectEngineTransforms *transforms, Flow *f, const uint8_t flow_flags, void *txv, const int list_id)
Definition: detect-engine-helper.h:39
PrefilterPostRuleMatch
void PrefilterPostRuleMatch(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, Flow *f)
invoke post-rule match "prefilter" engines
Definition: detect-engine-prefilter.c:196
DetectGetInnerTx
void * DetectGetInnerTx(void *tx_ptr, AppProto alproto, AppProto engine_alproto, uint8_t flow_flags)
Definition: detect.c:1166
PrefilterNonPFDataSig::pkt
struct PrefilterNonPFDataSig::@53::@55 pkt
likely
#define likely(expr)
Definition: util-optimize.h:32
PrefilterMpmCtx::GetDataSingle
InspectionSingleBufferGetDataPtr GetDataSingle
Definition: detect-engine-prefilter.c:1500
PrefilterNonPFDataSig::value
uint16_t value
Definition: detect-engine-prefilter.c:539
PrefilterMpm
struct PrefilterMpm PrefilterMpm
SigGroupHead_::pkt_engines
PrefilterEngine * pkt_engines
Definition: detect.h:1648
PrefilterEngine_::Prefilter
PrefilterPktFn Prefilter
Definition: detect.h:1598
PrefilterEngine_::PrefilterTx
PrefilterTxFn PrefilterTx
Definition: detect.h:1599
MpmCtx_
Definition: util-mpm.h:97
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:443
Packet_::dp
Port dp
Definition: decode.h:520
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
PrefilterNonPFDataSig::frame
struct PrefilterNonPFDataSig::@53::@56 frame
PrefilterMpm
Definition: detect-dns-response.c:39
SignatureInitData_::buffer_index
uint32_t buffer_index
Definition: detect.h:652
PrefilterFreeEnginesList
void PrefilterFreeEnginesList(PrefilterEngineList *list)
Definition: detect-engine-prefilter.c:468
FLOW_PKT_TOSERVER_FIRST
#define FLOW_PKT_TOSERVER_FIRST
Definition: flow.h:227
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
SIG_FLAG_PREFILTER
#define SIG_FLAG_PREFILTER
Definition: detect.h:277
PrefilterMpmCtx::mpm_ctx
const MpmCtx * mpm_ctx
Definition: detect-engine-prefilter.c:1502
DetectRunPrefilterTx
void DetectRunPrefilterTx(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t ipproto, const uint8_t flow_flags, const AppProto alproto, void *alstate, DetectTransaction *tx)
run prefilter engines on a transaction
Definition: detect-engine-prefilter.c:95
DetectEngineThreadCtx_::post_rule_work_queue
PostRuleMatchWorkQueue post_rule_work_queue
Definition: detect.h:1356
SIG_FLAG_DSIZE
#define SIG_FLAG_DSIZE
Definition: detect.h:247
StringHashDjb2
uint32_t StringHashDjb2(const uint8_t *data, uint32_t datalen)
Definition: util-hash-string.c:22
SignatureMask
#define SignatureMask
Definition: decode.h:100
Signature_::mask
SignatureMask mask
Definition: detect.h:683
DETECT_EVENT_POST_MATCH_QUEUE_FAILED
@ DETECT_EVENT_POST_MATCH_QUEUE_FAILED
Definition: detect.h:1494
PrefilterRuleStore_::rule_id_array
SigIntId * rule_id_array
Definition: util-prefilter.h:38
PrefilterPktNonPFStatsDump
void PrefilterPktNonPFStatsDump(void)
Definition: detect-engine-prefilter.c:593
TxNonPFData::sigs
struct PrefilterNonPFDataSig * sigs
Definition: detect-engine-prefilter.c:710