suricata
detect.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2022 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Basic detection engine
24  */
25 
26 #include "suricata-common.h"
27 #include "suricata.h"
28 #include "conf.h"
29 
30 #include "decode.h"
31 #include "packet.h"
32 #include "flow.h"
33 #include "stream-tcp.h"
34 #include "app-layer.h"
35 #include "app-layer-parser.h"
36 #include "app-layer-frames.h"
37 
38 #include "detect.h"
39 #include "detect-dsize.h"
40 #include "detect-engine.h"
41 #include "detect-engine-build.h"
42 #include "detect-engine-frame.h"
43 #include "detect-engine-profile.h"
44 
45 #include "detect-engine-alert.h"
46 #include "detect-engine-siggroup.h"
47 #include "detect-engine-address.h"
48 #include "detect-engine-proto.h"
49 #include "detect-engine-port.h"
50 #include "detect-engine-mpm.h"
51 #include "detect-engine-iponly.h"
54 #include "detect-engine-state.h"
55 #include "detect-engine-analyzer.h"
56 
57 #include "detect-engine-payload.h"
58 #include "detect-engine-event.h"
59 
60 #include "detect-filestore.h"
61 #include "detect-flowvar.h"
62 #include "detect-replace.h"
63 
64 #include "util-validate.h"
65 #include "util-detect.h"
66 #include "util-profiling.h"
67 
68 #include "action-globals.h"
69 
70 typedef struct DetectRunScratchpad {
72  const uint8_t flow_flags; /* flow/state flags: STREAM_* */
73  const bool app_decoder_events;
74  const SigGroupHead *sgh;
77 
78 /* prototypes */
79 static DetectRunScratchpad DetectRunSetup(const DetectEngineCtx *de_ctx,
80  DetectEngineThreadCtx *det_ctx, Packet * const p, Flow * const pflow);
81 static void DetectRunInspectIPOnly(ThreadVars *tv, const DetectEngineCtx *de_ctx,
82  DetectEngineThreadCtx *det_ctx, Flow * const pflow, Packet * const p);
83 static inline void DetectRunGetRuleGroup(const DetectEngineCtx *de_ctx,
84  Packet * const p, Flow * const pflow, DetectRunScratchpad *scratch);
85 static inline void DetectRunPrefilterPkt(ThreadVars *tv,
87  DetectRunScratchpad *scratch);
88 static inline void DetectRulePacketRules(ThreadVars * const tv,
89  DetectEngineCtx * const de_ctx, DetectEngineThreadCtx * const det_ctx,
90  Packet * const p, Flow * const pflow, const DetectRunScratchpad *scratch);
91 static void DetectRunTx(ThreadVars *tv, DetectEngineCtx *de_ctx,
92  DetectEngineThreadCtx *det_ctx, Packet *p,
93  Flow *f, DetectRunScratchpad *scratch);
94 static void DetectRunFrames(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
95  Packet *p, Flow *f, DetectRunScratchpad *scratch);
96 static inline void DetectRunPostRules(ThreadVars *tv, DetectEngineCtx *de_ctx,
97  DetectEngineThreadCtx *det_ctx, Packet * const p, Flow * const pflow,
98  DetectRunScratchpad *scratch);
99 static void DetectRunCleanup(DetectEngineThreadCtx *det_ctx,
100  Packet *p, Flow * const pflow);
101 
102 /** \internal
103  */
104 static void DetectRun(ThreadVars *th_v,
106  Packet *p)
107 {
108  SCEnter();
109  SCLogDebug("p->pcap_cnt %" PRIu64 " direction %s pkt_src %s", p->pcap_cnt,
110  p->flow ? (FlowGetPacketDirection(p->flow, p) == TOSERVER ? "toserver" : "toclient")
111  : "noflow",
112  PktSrcToString(p->pkt_src));
113 
114  /* bail early if packet should not be inspected */
115  if (p->flags & PKT_NOPACKET_INSPECTION) {
116  /* nothing to do */
117  SCReturn;
118  }
119 
120  /* Load the Packet's flow early, even though it might not be needed.
121  * Mark as a constant pointer, although the flow itself can change. */
122  Flow * const pflow = p->flow;
123 
124  DetectRunScratchpad scratch = DetectRunSetup(de_ctx, det_ctx, p, pflow);
125 
126  /* run the IPonly engine */
127  DetectRunInspectIPOnly(th_v, de_ctx, det_ctx, pflow, p);
128 
129  /* get our rule group */
130  DetectRunGetRuleGroup(de_ctx, p, pflow, &scratch);
131  /* if we didn't get a sig group head, we
132  * have nothing to do.... */
133  if (scratch.sgh == NULL) {
134  SCLogDebug("no sgh for this packet, nothing to match against");
135  goto end;
136  }
137 
138  /* run the prefilters for packets */
139  DetectRunPrefilterPkt(th_v, de_ctx, det_ctx, p, &scratch);
140 
142  /* inspect the rules against the packet */
143  DetectRulePacketRules(th_v, de_ctx, det_ctx, p, pflow, &scratch);
145 
146  /* run tx/state inspection. Don't call for ICMP error msgs. */
147  if (pflow && pflow->alstate && likely(pflow->proto == p->proto)) {
148  if (p->proto == IPPROTO_TCP) {
149  if ((p->flags & PKT_STREAM_EST) == 0) {
150  goto end;
151  }
152  const TcpSession *ssn = p->flow->protoctx;
153  if (ssn && (ssn->flags & STREAMTCP_FLAG_APP_LAYER_DISABLED) == 0) {
154  // PACKET_PROFILING_DETECT_START(p, PROF_DETECT_TX);
155  DetectRunFrames(th_v, de_ctx, det_ctx, p, pflow, &scratch);
156  // PACKET_PROFILING_DETECT_END(p, PROF_DETECT_TX);
157  }
158  // no update to transactions
159  if (!PKT_IS_PSEUDOPKT(p) && p->app_update_direction == 0 &&
160  ((PKT_IS_TOSERVER(p) && (p->flow->flags & FLOW_TS_APP_UPDATED) == 0) ||
161  (PKT_IS_TOCLIENT(p) && (p->flow->flags & FLOW_TC_APP_UPDATED) == 0))) {
162  goto end;
163  }
164  } else if (p->proto == IPPROTO_UDP) {
165  DetectRunFrames(th_v, de_ctx, det_ctx, p, pflow, &scratch);
166  }
167 
169  DetectRunTx(th_v, de_ctx, det_ctx, p, pflow, &scratch);
171  /* see if we need to increment the inspect_id and reset the de_state */
174  pflow, pflow->alparser, pflow->alstate, scratch.flow_flags, (scratch.sgh == NULL));
176  }
177 
178 end:
179  DetectRunPostRules(th_v, de_ctx, det_ctx, p, pflow, &scratch);
180 
181  DetectRunCleanup(det_ctx, p, pflow);
182  SCReturn;
183 }
184 
185 static void DetectRunPostMatch(ThreadVars *tv,
186  DetectEngineThreadCtx *det_ctx, Packet *p,
187  const Signature *s)
188 {
189  /* run the packet match functions */
191  if (smd != NULL) {
193 
194  SCLogDebug("running match functions, sm %p", smd);
195 
196  while (1) {
198  (void)sigmatch_table[smd->type].Match(det_ctx, p, s, smd->ctx);
199  KEYWORD_PROFILING_END(det_ctx, smd->type, 1);
200  if (smd->is_last)
201  break;
202  smd++;
203  }
204  }
205 }
206 
207 /**
208  * \brief Get the SigGroupHead for a packet.
209  *
210  * \param de_ctx detection engine context
211  * \param p packet
212  *
213  * \retval sgh the SigGroupHead or NULL if non applies to the packet
214  */
216  const Packet *p)
217 {
218  SCEnter();
219  SigGroupHead *sgh = NULL;
220 
221  /* if the packet proto is 0 (not set), we're inspecting it against
222  * the decoder events sgh we have. */
223  if (p->proto == 0 && p->events.cnt > 0) {
224  SCReturnPtr(de_ctx->decoder_event_sgh, "SigGroupHead");
225  } else if (p->proto == 0) {
226  if (!(PKT_IS_IPV4(p) || PKT_IS_IPV6(p))) {
227  /* not IP, so nothing to do */
228  SCReturnPtr(NULL, "SigGroupHead");
229  }
230  }
231 
232  /* select the flow_gh */
233  const int dir = (p->flowflags & FLOW_PKT_TOCLIENT) == 0;
234 
235  int proto = IP_GET_IPPROTO(p);
236  if (proto == IPPROTO_TCP) {
237  DetectPort *list = de_ctx->flow_gh[dir].tcp;
238  SCLogDebug("tcp toserver %p, tcp toclient %p: going to use %p", de_ctx->flow_gh[1].tcp,
239  de_ctx->flow_gh[0].tcp, de_ctx->flow_gh[dir].tcp);
240  const uint16_t port = dir ? p->dp : p->sp;
241  SCLogDebug("tcp port %u -> %u:%u", port, p->sp, p->dp);
242  DetectPort *sghport = DetectPortLookupGroup(list, port);
243  if (sghport != NULL)
244  sgh = sghport->sh;
245  SCLogDebug("TCP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
246  dir ? "toserver" : "toclient", sghport, sgh);
247  } else if (proto == IPPROTO_UDP) {
248  DetectPort *list = de_ctx->flow_gh[dir].udp;
249  uint16_t port = dir ? p->dp : p->sp;
250  DetectPort *sghport = DetectPortLookupGroup(list, port);
251  if (sghport != NULL)
252  sgh = sghport->sh;
253  SCLogDebug("UDP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
254  dir ? "toserver" : "toclient", sghport, sgh);
255  } else {
256  sgh = de_ctx->flow_gh[dir].sgh[proto];
257  }
258 
259  SCReturnPtr(sgh, "SigGroupHead");
260 }
261 
262 static inline void DetectPrefilterMergeSort(DetectEngineCtx *de_ctx,
263  DetectEngineThreadCtx *det_ctx)
264 {
265  SigIntId mpm, nonmpm;
266  SigIntId *mpm_ptr = det_ctx->pmq.rule_id_array;
267  SigIntId *nonmpm_ptr = det_ctx->non_pf_id_array;
268  uint32_t m_cnt = det_ctx->pmq.rule_id_array_cnt;
269  uint32_t n_cnt = det_ctx->non_pf_id_cnt;
270  SigIntId *final_ptr;
271  uint32_t final_cnt;
272  SigIntId id;
273  SigIntId previous_id = (SigIntId)-1;
274  Signature **sig_array = de_ctx->sig_array;
275  Signature **match_array = det_ctx->match_array;
276  Signature *s;
277 
278  SCLogDebug("PMQ rule id array count %d", det_ctx->pmq.rule_id_array_cnt);
279 
280  /* Load first values. */
281  if (likely(m_cnt)) {
282  mpm = *mpm_ptr;
283  } else {
284  /* mpm list is empty */
285  final_ptr = nonmpm_ptr;
286  final_cnt = n_cnt;
287  goto final;
288  }
289  if (likely(n_cnt)) {
290  nonmpm = *nonmpm_ptr;
291  } else {
292  /* non-mpm list is empty. */
293  final_ptr = mpm_ptr;
294  final_cnt = m_cnt;
295  goto final;
296  }
297  while (1) {
298  if (mpm < nonmpm) {
299  /* Take from mpm list */
300  id = mpm;
301 
302  s = sig_array[id];
303  /* As the mpm list can contain duplicates, check for that here. */
304  if (likely(id != previous_id)) {
305  *match_array++ = s;
306  previous_id = id;
307  }
308  if (unlikely(--m_cnt == 0)) {
309  /* mpm list is now empty */
310  final_ptr = nonmpm_ptr;
311  final_cnt = n_cnt;
312  goto final;
313  }
314  mpm_ptr++;
315  mpm = *mpm_ptr;
316  } else if (mpm > nonmpm) {
317  id = nonmpm;
318 
319  s = sig_array[id];
320  /* As the mpm list can contain duplicates, check for that here. */
321  if (likely(id != previous_id)) {
322  *match_array++ = s;
323  previous_id = id;
324  }
325  if (unlikely(--n_cnt == 0)) {
326  final_ptr = mpm_ptr;
327  final_cnt = m_cnt;
328  goto final;
329  }
330  nonmpm_ptr++;
331  nonmpm = *nonmpm_ptr;
332 
333  } else { /* implied mpm == nonmpm */
334  /* special case: if on both lists, it's a negated mpm pattern */
335 
336  /* mpm list may have dups, so skip past them here */
337  while (--m_cnt != 0) {
338  mpm_ptr++;
339  mpm = *mpm_ptr;
340  if (mpm != nonmpm)
341  break;
342  }
343  /* if mpm is done, update nonmpm_ptrs and jump to final */
344  if (unlikely(m_cnt == 0)) {
345  n_cnt--;
346 
347  /* mpm list is now empty */
348  final_ptr = ++nonmpm_ptr;
349  final_cnt = n_cnt;
350  goto final;
351  }
352  /* otherwise, if nonmpm is done jump to final for mpm
353  * mpm ptrs already updated */
354  if (unlikely(--n_cnt == 0)) {
355  final_ptr = mpm_ptr;
356  final_cnt = m_cnt;
357  goto final;
358  }
359 
360  /* not at end of the lists, update nonmpm. Mpm already
361  * updated in while loop above. */
362  nonmpm_ptr++;
363  nonmpm = *nonmpm_ptr;
364  }
365  }
366 
367  final: /* Only one list remaining. Just walk that list. */
368 
369  while (final_cnt-- > 0) {
370  id = *final_ptr++;
371  s = sig_array[id];
372 
373  /* As the mpm list can contain duplicates, check for that here. */
374  if (likely(id != previous_id)) {
375  *match_array++ = s;
376  previous_id = id;
377  }
378  }
379 
380  det_ctx->match_array_cnt = match_array - det_ctx->match_array;
381  DEBUG_VALIDATE_BUG_ON((det_ctx->pmq.rule_id_array_cnt + det_ctx->non_pf_id_cnt) < det_ctx->match_array_cnt);
382  PMQ_RESET(&det_ctx->pmq);
383 }
384 
385 /** \internal
386  * \brief build non-prefilter list based on the rule group list we've set.
387  */
388 static inline void DetectPrefilterBuildNonPrefilterList(
389  DetectEngineThreadCtx *det_ctx, const SignatureMask mask, const AppProto alproto)
390 {
391  for (uint32_t x = 0; x < det_ctx->non_pf_store_cnt; x++) {
392  /* only if the mask matches this rule can possibly match,
393  * so build the non_mpm array only for match candidates */
394  const SignatureMask rule_mask = det_ctx->non_pf_store_ptr[x].mask;
395  const AppProto rule_alproto = det_ctx->non_pf_store_ptr[x].alproto;
396  if ((rule_mask & mask) == rule_mask &&
397  (rule_alproto == 0 || AppProtoEquals(rule_alproto, alproto))) {
398  det_ctx->non_pf_id_array[det_ctx->non_pf_id_cnt++] = det_ctx->non_pf_store_ptr[x].id;
399  }
400  }
401 }
402 
403 /** \internal
404  * \brief select non-mpm list
405  * Based on the packet properties, select the non-mpm list to use
406  * \todo move non_pf_store* into scratchpad */
407 static inline void
408 DetectPrefilterSetNonPrefilterList(const Packet *p, DetectEngineThreadCtx *det_ctx, DetectRunScratchpad *scratch)
409 {
410  if ((p->proto == IPPROTO_TCP) && (p->tcph != NULL) && (p->tcph->th_flags & TH_SYN)) {
411  det_ctx->non_pf_store_ptr = scratch->sgh->non_pf_syn_store_array;
412  det_ctx->non_pf_store_cnt = scratch->sgh->non_pf_syn_store_cnt;
413  } else {
414  det_ctx->non_pf_store_ptr = scratch->sgh->non_pf_other_store_array;
415  det_ctx->non_pf_store_cnt = scratch->sgh->non_pf_other_store_cnt;
416  }
417  SCLogDebug("sgh non_pf ptr %p cnt %u (syn %p/%u, other %p/%u)",
418  det_ctx->non_pf_store_ptr, det_ctx->non_pf_store_cnt,
419  scratch->sgh->non_pf_syn_store_array, scratch->sgh->non_pf_syn_store_cnt,
421 }
422 
423 /** \internal
424  * \brief update flow's file tracking flags based on the detection engine
425  * A set of flags is prepared that is sent to the File API. The
426  File API may reject one or more based on the global force settings.
427  */
428 static inline void
429 DetectPostInspectFileFlagsUpdate(Flow *f, const SigGroupHead *sgh, uint8_t direction)
430 {
431  uint16_t flow_file_flags = FLOWFILE_INIT;
432 
433  if (sgh == NULL) {
434  SCLogDebug("requesting disabling all file features for flow");
435  flow_file_flags = FLOWFILE_NONE;
436  } else {
437  if (sgh->filestore_cnt == 0) {
438  SCLogDebug("requesting disabling filestore for flow");
439  flow_file_flags |= (FLOWFILE_NO_STORE_TS|FLOWFILE_NO_STORE_TC);
440  }
441 #ifdef HAVE_MAGIC
442  if (!(sgh->flags & SIG_GROUP_HEAD_HAVEFILEMAGIC)) {
443  SCLogDebug("requesting disabling magic for flow");
444  flow_file_flags |= (FLOWFILE_NO_MAGIC_TS|FLOWFILE_NO_MAGIC_TC);
445  }
446 #endif
447  if (!(sgh->flags & SIG_GROUP_HEAD_HAVEFILEMD5)) {
448  SCLogDebug("requesting disabling md5 for flow");
449  flow_file_flags |= (FLOWFILE_NO_MD5_TS|FLOWFILE_NO_MD5_TC);
450  }
451  if (!(sgh->flags & SIG_GROUP_HEAD_HAVEFILESHA1)) {
452  SCLogDebug("requesting disabling sha1 for flow");
453  flow_file_flags |= (FLOWFILE_NO_SHA1_TS|FLOWFILE_NO_SHA1_TC);
454  }
455  if (!(sgh->flags & SIG_GROUP_HEAD_HAVEFILESHA256)) {
456  SCLogDebug("requesting disabling sha256 for flow");
457  flow_file_flags |= (FLOWFILE_NO_SHA256_TS|FLOWFILE_NO_SHA256_TC);
458  }
459  if (!(sgh->flags & SIG_GROUP_HEAD_HAVEFILESIZE)) {
460  SCLogDebug("requesting disabling filesize for flow");
461  flow_file_flags |= (FLOWFILE_NO_SIZE_TS|FLOWFILE_NO_SIZE_TC);
462  }
463  }
464  if (flow_file_flags != 0) {
465  FileUpdateFlowFileFlags(f, flow_file_flags, direction);
466  }
467 }
468 
469 static inline void
470 DetectRunPostGetFirstRuleGroup(const Packet *p, Flow *pflow, const SigGroupHead *sgh)
471 {
472  if ((p->flowflags & FLOW_PKT_TOSERVER) && !(pflow->flags & FLOW_SGH_TOSERVER)) {
473  /* first time we see this toserver sgh, store it */
474  pflow->sgh_toserver = sgh;
475  pflow->flags |= FLOW_SGH_TOSERVER;
476 
477  if (p->proto == IPPROTO_TCP && (sgh == NULL || !(sgh->flags & SIG_GROUP_HEAD_HAVERAWSTREAM))) {
478  if (pflow->protoctx != NULL) {
479  TcpSession *ssn = pflow->protoctx;
480  SCLogDebug("STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.client");
482  }
483  }
484 
485  DetectPostInspectFileFlagsUpdate(pflow,
486  pflow->sgh_toserver, STREAM_TOSERVER);
487 
488  } else if ((p->flowflags & FLOW_PKT_TOCLIENT) && !(pflow->flags & FLOW_SGH_TOCLIENT)) {
489  pflow->sgh_toclient = sgh;
490  pflow->flags |= FLOW_SGH_TOCLIENT;
491 
492  if (p->proto == IPPROTO_TCP && (sgh == NULL || !(sgh->flags & SIG_GROUP_HEAD_HAVERAWSTREAM))) {
493  if (pflow->protoctx != NULL) {
494  TcpSession *ssn = pflow->protoctx;
495  SCLogDebug("STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.server");
497  }
498  }
499 
500  DetectPostInspectFileFlagsUpdate(pflow,
501  pflow->sgh_toclient, STREAM_TOCLIENT);
502  }
503 }
504 
505 static inline void DetectRunGetRuleGroup(
506  const DetectEngineCtx *de_ctx,
507  Packet * const p, Flow * const pflow,
508  DetectRunScratchpad *scratch)
509 {
510  const SigGroupHead *sgh = NULL;
511 
512  if (pflow) {
513  bool use_flow_sgh = false;
514  /* Get the stored sgh from the flow (if any). Make sure we're not using
515  * the sgh for icmp error packets part of the same stream. */
516  if (IP_GET_IPPROTO(p) == pflow->proto) { /* filter out icmp */
518  if ((p->flowflags & FLOW_PKT_TOSERVER) && (pflow->flags & FLOW_SGH_TOSERVER)) {
519  sgh = pflow->sgh_toserver;
520  SCLogDebug("sgh = pflow->sgh_toserver; => %p", sgh);
521  use_flow_sgh = true;
522  } else if ((p->flowflags & FLOW_PKT_TOCLIENT) && (pflow->flags & FLOW_SGH_TOCLIENT)) {
523  sgh = pflow->sgh_toclient;
524  SCLogDebug("sgh = pflow->sgh_toclient; => %p", sgh);
525  use_flow_sgh = true;
526  }
528  }
529 
530  if (!(use_flow_sgh)) {
534 
535  /* HACK: prevent the wrong sgh (or NULL) from being stored in the
536  * flow's sgh pointers */
538  ; /* no-op */
539  } else {
540  /* store the found sgh (or NULL) in the flow to save us
541  * from looking it up again for the next packet.
542  * Also run other tasks */
543  DetectRunPostGetFirstRuleGroup(p, pflow, sgh);
544  }
545  }
546  } else { /* p->flags & PKT_HAS_FLOW */
547  /* no flow */
548 
552  }
553 
554  scratch->sgh = sgh;
555 }
556 
557 static void DetectRunInspectIPOnly(ThreadVars *tv, const DetectEngineCtx *de_ctx,
558  DetectEngineThreadCtx *det_ctx,
559  Flow * const pflow, Packet * const p)
560 {
561  if (pflow) {
562  /* set the iponly stuff */
563  if (pflow->flags & FLOW_TOCLIENT_IPONLY_SET)
565  if (pflow->flags & FLOW_TOSERVER_IPONLY_SET)
567 
570  {
571  SCLogDebug("testing against \"ip-only\" signatures");
572 
574  IPOnlyMatchPacket(tv, de_ctx, det_ctx, &de_ctx->io_ctx, p);
576 
577  /* save in the flow that we scanned this direction... */
578  FlowSetIPOnlyFlag(pflow, p->flowflags & FLOW_PKT_TOSERVER ? 1 : 0);
579  }
580  } else { /* p->flags & PKT_HAS_FLOW */
581  /* no flow */
582 
583  /* Even without flow we should match the packet src/dst */
585  IPOnlyMatchPacket(tv, de_ctx, det_ctx, &de_ctx->io_ctx, p);
587  }
588 }
589 
590 /** \internal
591  * \brief inspect the rule header: protocol, ports, etc
592  * \retval bool false if no match, true if match */
593 static inline bool DetectRunInspectRuleHeader(const Packet *p, const Flow *f, const Signature *s,
594  const uint32_t sflags, const uint8_t s_proto_flags)
595 {
596  /* check if this signature has a requirement for flowvars of some type
597  * and if so, if we actually have any in the flow. If not, the sig
598  * can't match and we skip it. */
599  if ((p->flags & PKT_HAS_FLOW) && (sflags & SIG_FLAG_REQUIRE_FLOWVAR)) {
600  DEBUG_VALIDATE_BUG_ON(f == NULL);
601 
602  /* no flowvars? skip this sig */
603  const bool fv = f->flowvar != NULL;
604  if (fv == false) {
605  SCLogDebug("skipping sig as the flow has no flowvars and sig "
606  "has SIG_FLAG_REQUIRE_FLOWVAR flag set.");
607  return false;
608  }
609  }
610 
611  if ((s_proto_flags & DETECT_PROTO_IPV4) && !PKT_IS_IPV4(p)) {
612  SCLogDebug("ip version didn't match");
613  return false;
614  }
615  if ((s_proto_flags & DETECT_PROTO_IPV6) && !PKT_IS_IPV6(p)) {
616  SCLogDebug("ip version didn't match");
617  return false;
618  }
619 
620  if (DetectProtoContainsProto(&s->proto, IP_GET_IPPROTO(p)) == 0) {
621  SCLogDebug("proto didn't match");
622  return false;
623  }
624 
625  /* check the source & dst port in the sig */
626  if (p->proto == IPPROTO_TCP || p->proto == IPPROTO_UDP || p->proto == IPPROTO_SCTP) {
627  if (!(sflags & SIG_FLAG_DP_ANY)) {
628  if (p->flags & PKT_IS_FRAGMENT)
629  return false;
630  const DetectPort *dport = DetectPortLookupGroup(s->dp, p->dp);
631  if (dport == NULL) {
632  SCLogDebug("dport didn't match.");
633  return false;
634  }
635  }
636  if (!(sflags & SIG_FLAG_SP_ANY)) {
637  if (p->flags & PKT_IS_FRAGMENT)
638  return false;
639  const DetectPort *sport = DetectPortLookupGroup(s->sp, p->sp);
640  if (sport == NULL) {
641  SCLogDebug("sport didn't match.");
642  return false;
643  }
644  }
645  } else if ((sflags & (SIG_FLAG_DP_ANY|SIG_FLAG_SP_ANY)) != (SIG_FLAG_DP_ANY|SIG_FLAG_SP_ANY)) {
646  SCLogDebug("port-less protocol and sig needs ports");
647  return false;
648  }
649 
650  /* check the destination address */
651  if (!(sflags & SIG_FLAG_DST_ANY)) {
652  if (PKT_IS_IPV4(p)) {
654  return false;
655  } else if (PKT_IS_IPV6(p)) {
657  return false;
658  }
659  }
660  /* check the source address */
661  if (!(sflags & SIG_FLAG_SRC_ANY)) {
662  if (PKT_IS_IPV4(p)) {
664  return false;
665  } else if (PKT_IS_IPV6(p)) {
667  return false;
668  }
669  }
670 
671  return true;
672 }
673 
674 /** \internal
675  * \brief run packet/stream prefilter engines
676  */
677 static inline void DetectRunPrefilterPkt(
678  ThreadVars *tv,
680  DetectEngineThreadCtx *det_ctx,
681  Packet *p,
682  DetectRunScratchpad *scratch
683 )
684 {
685  DetectPrefilterSetNonPrefilterList(p, det_ctx, scratch);
686 
687  /* create our prefilter mask */
688  PacketCreateMask(p, &scratch->pkt_mask, scratch->alproto, scratch->app_decoder_events);
689 
690  /* build and prefilter non_pf list against the mask of the packet */
692  det_ctx->non_pf_id_cnt = 0;
693  if (likely(det_ctx->non_pf_store_cnt > 0)) {
694  DetectPrefilterBuildNonPrefilterList(det_ctx, scratch->pkt_mask, scratch->alproto);
695  }
697 
698  /* run the prefilter engines */
699  Prefilter(det_ctx, scratch->sgh, p, scratch->flow_flags);
700  /* create match list if we have non-pf and/or pf */
701  if (det_ctx->non_pf_store_cnt || det_ctx->pmq.rule_id_array_cnt) {
702 #ifdef PROFILING
703  if (tv) {
704  StatsAddUI64(tv, det_ctx->counter_mpm_list, (uint64_t)det_ctx->pmq.rule_id_array_cnt);
705  }
706 #endif
708  DetectPrefilterMergeSort(de_ctx, det_ctx);
710  }
711 
712 #ifdef PROFILING
713  if (tv) {
715  (uint64_t)det_ctx->non_pf_store_cnt);
716  /* non mpm sigs after mask prefilter */
718  (uint64_t)det_ctx->non_pf_id_cnt);
719  }
720 #endif
721 }
722 
723 static inline void DetectRulePacketRules(
724  ThreadVars * const tv,
725  DetectEngineCtx * const de_ctx,
726  DetectEngineThreadCtx * const det_ctx,
727  Packet * const p,
728  Flow * const pflow,
729  const DetectRunScratchpad *scratch
730 )
731 {
732  const Signature *next_s = NULL;
733 
734  /* inspect the sigs against the packet */
735  /* Prefetch the next signature. */
736  SigIntId match_cnt = det_ctx->match_array_cnt;
737 #ifdef PROFILING
738  if (tv) {
740  (uint64_t)match_cnt);
741  }
742 #endif
743  Signature **match_array = det_ctx->match_array;
744 
745  SGH_PROFILING_RECORD(det_ctx, scratch->sgh);
746 #ifdef PROFILING
747  if (match_cnt >= de_ctx->profile_match_logging_threshold)
748  RulesDumpMatchArray(det_ctx, scratch->sgh, p);
749 #endif
750 
751  uint32_t sflags, next_sflags = 0;
752  if (match_cnt) {
753  next_s = *match_array++;
754  next_sflags = next_s->flags;
755  }
756  while (match_cnt--) {
758  uint8_t alert_flags = 0;
759 #ifdef PROFILE_RULES
760  bool smatch = false; /* signature match */
761 #endif
762  const Signature *s = next_s;
763  sflags = next_sflags;
764  if (match_cnt) {
765  next_s = *match_array++;
766  next_sflags = next_s->flags;
767  }
768  const uint8_t s_proto_flags = s->proto.flags;
769 
770  SCLogDebug("inspecting signature id %"PRIu32"", s->id);
771 
772  if (s->app_inspect != NULL) {
773  goto next; // handle sig in DetectRunTx
774  }
775  if (s->frame_inspect != NULL) {
776  goto next; // handle sig in DetectRunFrame
777  }
778 
779  /* don't run mask check for stateful rules.
780  * There we depend on prefilter */
781  if ((s->mask & scratch->pkt_mask) != s->mask) {
782  SCLogDebug("mask mismatch %x & %x != %x", s->mask, scratch->pkt_mask, s->mask);
783  goto next;
784  }
785 
786  if (SigDsizePrefilter(p, s, sflags))
787  goto next;
788 
789  /* if the sig has alproto and the session as well they should match */
790  if (likely(sflags & SIG_FLAG_APPLAYER)) {
791  if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, scratch->alproto)) {
792  SCLogDebug("alproto mismatch");
793  goto next;
794  }
795  }
796 
797  if (DetectRunInspectRuleHeader(p, pflow, s, sflags, s_proto_flags) == false) {
798  goto next;
799  }
800 
801  if (DetectEnginePktInspectionRun(tv, det_ctx, s, pflow, p, &alert_flags) == false) {
802  goto next;
803  }
804 
805 #ifdef PROFILE_RULES
806  smatch = true;
807 #endif
808  DetectRunPostMatch(tv, det_ctx, p, s);
809 
810  uint64_t txid = PACKET_ALERT_NOTX;
811  if ((alert_flags & PACKET_ALERT_FLAG_STREAM_MATCH) ||
812  (s->alproto != ALPROTO_UNKNOWN && pflow->proto == IPPROTO_UDP)) {
813  // if there is a stream match (TCP), or
814  // a UDP specific app-layer signature,
815  // try to use the good tx for the packet direction
816  if (pflow->alstate) {
817  uint8_t dir =
818  (p->flowflags & FLOW_PKT_TOCLIENT) ? STREAM_TOCLIENT : STREAM_TOSERVER;
820  alert_flags |= PACKET_ALERT_FLAG_TX;
821  }
822  }
823  AlertQueueAppend(det_ctx, s, p, txid, alert_flags);
824 next:
825  DetectVarProcessList(det_ctx, pflow, p);
826  DetectReplaceFree(det_ctx);
827  RULE_PROFILING_END(det_ctx, s, smatch, p);
828 
829  det_ctx->flags = 0;
830  continue;
831  }
832 }
833 
834 static DetectRunScratchpad DetectRunSetup(
835  const DetectEngineCtx *de_ctx,
836  DetectEngineThreadCtx *det_ctx,
837  Packet * const p, Flow * const pflow)
838 {
839  AppProto alproto = ALPROTO_UNKNOWN;
840  uint8_t flow_flags = 0; /* flow/state flags */
841  bool app_decoder_events = false;
842 
844 
845 #ifdef UNITTESTS
846  p->alerts.cnt = 0;
847  p->alerts.discarded = 0;
848  p->alerts.suppressed = 0;
849 #endif
850  det_ctx->filestore_cnt = 0;
851  det_ctx->base64_decoded_len = 0;
852  det_ctx->raw_stream_progress = 0;
853  det_ctx->match_array_cnt = 0;
854 
855  det_ctx->alert_queue_size = 0;
856  p->alerts.drop.action = 0;
857 
858 #ifdef DEBUG
859  if (p->flags & PKT_STREAM_ADD) {
860  det_ctx->pkt_stream_add_cnt++;
861  }
862 #endif
863 
864  /* grab the protocol state we will detect on */
865  if (p->flags & PKT_HAS_FLOW) {
866  DEBUG_VALIDATE_BUG_ON(pflow == NULL);
867 
868  if (p->flowflags & FLOW_PKT_TOSERVER) {
869  flow_flags = STREAM_TOSERVER;
870  SCLogDebug("flag STREAM_TOSERVER set");
871  } else if (p->flowflags & FLOW_PKT_TOCLIENT) {
872  flow_flags = STREAM_TOCLIENT;
873  SCLogDebug("flag STREAM_TOCLIENT set");
874  }
875  SCLogDebug("p->flowflags 0x%02x", p->flowflags);
876 
877  if (p->flags & PKT_STREAM_EOF) {
878  flow_flags |= STREAM_EOF;
879  SCLogDebug("STREAM_EOF set");
880  }
881 
882  /* store tenant_id in the flow so that we can use it
883  * for creating pseudo packets */
884  if (p->tenant_id > 0 && pflow->tenant_id == 0) {
885  pflow->tenant_id = p->tenant_id;
886  }
887 
888  /* live ruleswap check for flow updates */
889  if (pflow->de_ctx_version == 0) {
890  /* first time this flow is inspected, set id */
891  pflow->de_ctx_version = de_ctx->version;
892  } else if (pflow->de_ctx_version != de_ctx->version) {
893  /* first time we inspect flow with this de_ctx, reset */
894  pflow->flags &= ~FLOW_SGH_TOSERVER;
895  pflow->flags &= ~FLOW_SGH_TOCLIENT;
896  pflow->sgh_toserver = NULL;
897  pflow->sgh_toclient = NULL;
898 
899  pflow->de_ctx_version = de_ctx->version;
900  GenericVarFree(pflow->flowvar);
901  pflow->flowvar = NULL;
902 
904  }
905 
906  /* Retrieve the app layer state and protocol and the tcp reassembled
907  * stream chunks. */
908  if ((p->proto == IPPROTO_TCP && (p->flags & PKT_STREAM_EST)) ||
909  (p->proto == IPPROTO_UDP) ||
911  {
912  /* update flow flags with knowledge on disruptions */
913  flow_flags = FlowGetDisruptionFlags(pflow, flow_flags);
914  alproto = FlowGetAppProtocol(pflow);
915  if (p->proto == IPPROTO_TCP && pflow->protoctx &&
918  }
919  SCLogDebug("alproto %u", alproto);
920  } else {
921  SCLogDebug("packet doesn't have established flag set (proto %d)", p->proto);
922  }
923 
924  app_decoder_events = AppLayerParserHasDecoderEvents(pflow->alparser);
925  }
926 
927  DetectRunScratchpad pad = { alproto, flow_flags, app_decoder_events, NULL, 0 };
929  return pad;
930 }
931 
932 static inline void DetectRunPostRules(
933  ThreadVars *tv,
935  DetectEngineThreadCtx *det_ctx,
936  Packet * const p,
937  Flow * const pflow,
938  DetectRunScratchpad *scratch)
939 {
940  /* so now let's iterate the alerts and remove the ones after a pass rule
941  * matched (if any). This is done inside PacketAlertFinalize() */
942  /* PR: installed "tag" keywords are handled after the threshold inspection */
943 
945  PacketAlertFinalize(de_ctx, det_ctx, p);
946  if (p->alerts.cnt > 0) {
947  StatsAddUI64(tv, det_ctx->counter_alerts, (uint64_t)p->alerts.cnt);
948  }
949  if (p->alerts.discarded > 0) {
950  StatsAddUI64(tv, det_ctx->counter_alerts_overflow, (uint64_t)p->alerts.discarded);
951  }
952  if (p->alerts.suppressed > 0) {
953  StatsAddUI64(tv, det_ctx->counter_alerts_suppressed, (uint64_t)p->alerts.suppressed);
954  }
956 }
957 
958 static void DetectRunCleanup(DetectEngineThreadCtx *det_ctx,
959  Packet *p, Flow * const pflow)
960 {
962  InspectionBufferClean(det_ctx);
963 
964  if (pflow != NULL) {
965  /* update inspected tracker for raw reassembly */
966  if (p->proto == IPPROTO_TCP && pflow->protoctx != NULL &&
969  det_ctx->raw_stream_progress);
970  }
971  }
973  SCReturn;
974 }
975 
977 {
979  det_ctx->tx_candidates = SCCalloc(size, sizeof(RuleMatchCandidateTx));
980  if (det_ctx->tx_candidates == NULL) {
981  FatalError("failed to allocate %" PRIu64 " bytes",
982  (uint64_t)(size * sizeof(RuleMatchCandidateTx)));
983  }
984  det_ctx->tx_candidates_size = size;
985  SCLogDebug("array initialized to %u elements (%"PRIu64" bytes)",
986  size, (uint64_t)(size * sizeof(RuleMatchCandidateTx)));
987 }
988 
990 {
991  SCFree(det_ctx->tx_candidates);
992  det_ctx->tx_candidates_size = 0;
993 }
994 
995 /* if size >= cur_space */
996 static inline bool RuleMatchCandidateTxArrayHasSpace(const DetectEngineThreadCtx *det_ctx,
997  const uint32_t need)
998 {
999  if (det_ctx->tx_candidates_size >= need)
1000  return 1;
1001  return 0;
1002 }
1003 
1004 /* realloc */
1005 static int RuleMatchCandidateTxArrayExpand(DetectEngineThreadCtx *det_ctx, const uint32_t needed)
1006 {
1007  const uint32_t old_size = det_ctx->tx_candidates_size;
1008  uint32_t new_size = needed;
1009  void *ptmp = SCRealloc(det_ctx->tx_candidates, (new_size * sizeof(RuleMatchCandidateTx)));
1010  if (ptmp == NULL) {
1011  FatalError("failed to expand to %" PRIu64 " bytes",
1012  (uint64_t)(new_size * sizeof(RuleMatchCandidateTx)));
1013  // TODO can this be handled more gracefully?
1014  }
1015  det_ctx->tx_candidates = ptmp;
1016  det_ctx->tx_candidates_size = new_size;
1017  SCLogDebug("array expanded from %u to %u elements (%"PRIu64" bytes -> %"PRIu64" bytes)",
1018  old_size, new_size, (uint64_t)(old_size * sizeof(RuleMatchCandidateTx)),
1019  (uint64_t)(new_size * sizeof(RuleMatchCandidateTx))); (void)old_size;
1020  return 1;
1021 }
1022 
1023 /** \internal
1024  * \brief sort helper for sorting match candidates by id: ascending
1025  *
1026  * The id field is set from Signature::num, so we sort the candidates to match the signature
1027  * sort order (ascending), where candidates that have flags go first.
1028  */
1029 static int
1030 DetectRunTxSortHelper(const void *a, const void *b)
1031 {
1032  const RuleMatchCandidateTx *s0 = a;
1033  const RuleMatchCandidateTx *s1 = b;
1034  if (s1->id == s0->id) {
1035  if (s1->flags && !s0->flags)
1036  return 1;
1037  else if (!s1->flags && s0->flags)
1038  return -1;
1039  return 0;
1040  } else
1041  return s0->id > s1->id ? 1 : -1;
1042 }
1043 
1044 #if 0
1045 #define TRACE_SID_TXS(sid,txs,...) \
1046  do { \
1047  char _trace_buf[2048]; \
1048  snprintf(_trace_buf, sizeof(_trace_buf), __VA_ARGS__); \
1049  SCLogNotice("%p/%"PRIu64"/%u: %s", txs->tx_ptr, txs->tx_id, sid, _trace_buf); \
1050  } while(0)
1051 #else
1052 #define TRACE_SID_TXS(sid,txs,...)
1053 #endif
1054 
1055 /** \internal
1056  * \brief inspect a rule against a transaction
1057  *
1058  * Inspect a rule. New detection or continued stateful
1059  * detection.
1060  *
1061  * \param stored_flags pointer to stored flags or NULL.
1062  * If stored_flags is set it means we're continuing
1063  * inspection from an earlier run.
1064  *
1065  * \retval bool true sig matched, false didn't match
1066  */
1067 static bool DetectRunTxInspectRule(ThreadVars *tv,
1069  DetectEngineThreadCtx *det_ctx,
1070  Packet *p,
1071  Flow *f,
1072  const uint8_t in_flow_flags, // direction, EOF, etc
1073  void *alstate,
1074  DetectTransaction *tx,
1075  const Signature *s,
1076  uint32_t *stored_flags,
1077  RuleMatchCandidateTx *can,
1078  DetectRunScratchpad *scratch)
1079 {
1080  const uint8_t flow_flags = in_flow_flags;
1081  const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1082  uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
1083  int total_matches = 0;
1084  uint16_t file_no_match = 0;
1085  bool retval = false;
1086  bool mpm_before_progress = false; // is mpm engine before progress?
1087  bool mpm_in_progress = false; // is mpm engine in a buffer we will revisit?
1088 
1089  TRACE_SID_TXS(s->id, tx, "starting %s", direction ? "toclient" : "toserver");
1090 
1091  /* for a new inspection we inspect pkt header and packet matches */
1092  if (likely(stored_flags == NULL)) {
1093  TRACE_SID_TXS(s->id, tx, "first inspect, run packet matches");
1094  if (DetectRunInspectRuleHeader(p, f, s, s->flags, s->proto.flags) == false) {
1095  TRACE_SID_TXS(s->id, tx, "DetectRunInspectRuleHeader() no match");
1096  return false;
1097  }
1098  if (DetectEnginePktInspectionRun(tv, det_ctx, s, f, p, NULL) == false) {
1099  TRACE_SID_TXS(s->id, tx, "DetectEnginePktInspectionRun no match");
1100  return false;
1101  }
1102  /* stream mpm and negated mpm sigs can end up here with wrong proto */
1103  if (!(AppProtoEquals(s->alproto, f->alproto) || s->alproto == ALPROTO_UNKNOWN)) {
1104  TRACE_SID_TXS(s->id, tx, "alproto mismatch");
1105  return false;
1106  }
1107  }
1108 
1109  const DetectEngineAppInspectionEngine *engine = s->app_inspect;
1110  do {
1111  TRACE_SID_TXS(s->id, tx, "engine %p inspect_flags %x", engine, inspect_flags);
1112  if (!(inspect_flags & BIT_U32(engine->id)) &&
1113  direction == engine->dir)
1114  {
1115  const bool skip_engine = (engine->alproto != 0 && engine->alproto != f->alproto);
1116  /* special case: file_data on 'alert tcp' will have engines
1117  * in the list that are not for us. */
1118  if (unlikely(skip_engine)) {
1119  engine = engine->next;
1120  continue;
1121  }
1122 
1123  /* engines are sorted per progress, except that the one with
1124  * mpm/prefilter enabled is first */
1125  if (tx->tx_progress < engine->progress) {
1126  SCLogDebug("tx progress %d < engine progress %d",
1127  tx->tx_progress, engine->progress);
1128  break;
1129  }
1130  if (engine->mpm) {
1131  if (tx->tx_progress > engine->progress) {
1132  TRACE_SID_TXS(s->id, tx,
1133  "engine->mpm: t->tx_progress %u > engine->progress %u, so set "
1134  "mpm_before_progress",
1135  tx->tx_progress, engine->progress);
1136  mpm_before_progress = true;
1137  } else if (tx->tx_progress == engine->progress) {
1138  TRACE_SID_TXS(s->id, tx,
1139  "engine->mpm: t->tx_progress %u == engine->progress %u, so set "
1140  "mpm_in_progress",
1141  tx->tx_progress, engine->progress);
1142  mpm_in_progress = true;
1143  }
1144  }
1145 
1146  /* run callback: but bypass stream callback if we can */
1147  uint8_t match;
1148  if (unlikely(engine->stream && can->stream_stored)) {
1149  match = can->stream_result;
1150  TRACE_SID_TXS(s->id, tx, "stream skipped, stored result %d used instead", match);
1151  } else {
1152  KEYWORD_PROFILING_SET_LIST(det_ctx, engine->sm_list);
1153  DEBUG_VALIDATE_BUG_ON(engine->v2.Callback == NULL);
1154  match = engine->v2.Callback(
1155  de_ctx, det_ctx, engine, s, f, flow_flags, alstate, tx->tx_ptr, tx->tx_id);
1156  TRACE_SID_TXS(s->id, tx, "engine %p match %d", engine, match);
1157  if (engine->stream) {
1158  can->stream_stored = true;
1159  can->stream_result = match;
1160  TRACE_SID_TXS(s->id, tx, "stream ran, store result %d for next tx (if any)", match);
1161  }
1162  }
1163  if (match == DETECT_ENGINE_INSPECT_SIG_MATCH) {
1164  inspect_flags |= BIT_U32(engine->id);
1165  engine = engine->next;
1166  total_matches++;
1167  continue;
1168  } else if (match == DETECT_ENGINE_INSPECT_SIG_MATCH_MORE_FILES) {
1169  /* if the file engine matched, but indicated more
1170  * files are still in progress, we don't set inspect
1171  * flags as these would end inspection for this tx */
1172  engine = engine->next;
1173  total_matches++;
1174  continue;
1175  } else if (match == DETECT_ENGINE_INSPECT_SIG_CANT_MATCH) {
1176  inspect_flags |= DE_STATE_FLAG_SIG_CANT_MATCH;
1177  inspect_flags |= BIT_U32(engine->id);
1178  } else if (match == DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES) {
1179  inspect_flags |= DE_STATE_FLAG_SIG_CANT_MATCH;
1180  inspect_flags |= BIT_U32(engine->id);
1181  file_no_match = 1;
1182  }
1183  /* implied DETECT_ENGINE_INSPECT_SIG_NO_MATCH */
1184  if (engine->mpm && mpm_before_progress) {
1185  inspect_flags |= DE_STATE_FLAG_SIG_CANT_MATCH;
1186  inspect_flags |= BIT_U32(engine->id);
1187  }
1188  break;
1189  }
1190  engine = engine->next;
1191  } while (engine != NULL);
1192  TRACE_SID_TXS(s->id, tx, "inspect_flags %x, total_matches %u, engine %p",
1193  inspect_flags, total_matches, engine);
1194 
1195  if (engine == NULL && total_matches) {
1196  inspect_flags |= DE_STATE_FLAG_FULL_INSPECT;
1197  TRACE_SID_TXS(s->id, tx, "MATCH");
1198  retval = true;
1199  }
1200 
1201  if (stored_flags) {
1202  *stored_flags = inspect_flags;
1203  TRACE_SID_TXS(s->id, tx, "continue inspect flags %08x", inspect_flags);
1204  } else {
1205  // store... or? If tx is done we might not want to come back to this tx
1206 
1207  // also... if mpmid tracking is enabled, we won't do a sig again for this tx...
1208  TRACE_SID_TXS(s->id, tx, "start inspect flags %08x", inspect_flags);
1209  if (inspect_flags & DE_STATE_FLAG_SIG_CANT_MATCH) {
1210  if (file_no_match) {
1211  /* if we have a mismatch on a file sig, we need to keep state.
1212  * We may get another file on the same tx (for http and smtp
1213  * at least), so for a new file we need to re-eval the sig.
1214  * Thoughts / TODO:
1215  * - not for some protos that have 1 file per tx (e.g. nfs)
1216  * - maybe we only need this for file sigs that mix with
1217  * other matches? E.g. 'POST + filename', is different than
1218  * just 'filename'.
1219  */
1220  DetectRunStoreStateTx(scratch->sgh, f, tx->tx_ptr, tx->tx_id, s,
1221  inspect_flags, flow_flags, file_no_match);
1222  }
1223  } else if ((inspect_flags & DE_STATE_FLAG_FULL_INSPECT) && mpm_before_progress) {
1224  TRACE_SID_TXS(s->id, tx, "no need to store match sig, "
1225  "mpm won't trigger for it anymore");
1226 
1227  if (inspect_flags & DE_STATE_FLAG_FILE_INSPECT) {
1228  TRACE_SID_TXS(s->id, tx, "except that for new files, "
1229  "we may have to revisit anyway");
1230  DetectRunStoreStateTx(scratch->sgh, f, tx->tx_ptr, tx->tx_id, s,
1231  inspect_flags, flow_flags, file_no_match);
1232  }
1233  } else if ((inspect_flags & DE_STATE_FLAG_FULL_INSPECT) == 0 && mpm_in_progress) {
1234  TRACE_SID_TXS(s->id, tx, "no need to store no-match sig, "
1235  "mpm will revisit it");
1236  } else if (inspect_flags != 0 || file_no_match != 0) {
1237  TRACE_SID_TXS(s->id, tx, "storing state: flags %08x", inspect_flags);
1238  DetectRunStoreStateTx(scratch->sgh, f, tx->tx_ptr, tx->tx_id, s,
1239  inspect_flags, flow_flags, file_no_match);
1240  }
1241  }
1242 
1243  return retval;
1244 }
1245 
1246 #define NO_TX \
1247  { \
1248  NULL, 0, NULL, NULL, 0, 0, 0, 0, 0, \
1249  }
1250 
1251 /** \internal
1252  * \brief get a DetectTransaction object
1253  * \retval struct filled with relevant info or all nulls/0s
1254  */
1255 static DetectTransaction GetDetectTx(const uint8_t ipproto, const AppProto alproto,
1256  void *alstate, const uint64_t tx_id, void *tx_ptr, const int tx_end_state,
1257  const uint8_t flow_flags)
1258 {
1259  AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx_ptr);
1260  if (unlikely(txd == NULL)) {
1261  DetectTransaction no_tx = NO_TX;
1262  return no_tx;
1263  }
1264  uint64_t detect_flags =
1265  (flow_flags & STREAM_TOSERVER) ? txd->detect_flags_ts : txd->detect_flags_tc;
1266  if (detect_flags & APP_LAYER_TX_INSPECTED_FLAG) {
1267  SCLogDebug("%"PRIu64" tx already fully inspected for %s. Flags %016"PRIx64,
1268  tx_id, flow_flags & STREAM_TOSERVER ? "toserver" : "toclient",
1269  detect_flags);
1270  DetectTransaction no_tx = NO_TX;
1271  return no_tx;
1272  }
1273  if (detect_flags & APP_LAYER_TX_SKIP_INSPECT_FLAG) {
1274  SCLogDebug("%" PRIu64 " tx should not be inspected in direction %s. Flags %016" PRIx64,
1275  tx_id, flow_flags & STREAM_TOSERVER ? "toserver" : "toclient", detect_flags);
1276  DetectTransaction no_tx = NO_TX;
1277  return no_tx;
1278  }
1279 
1280  const int tx_progress = AppLayerParserGetStateProgress(ipproto, alproto, tx_ptr, flow_flags);
1281  const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1282  DetectEngineState *tx_de_state = txd->de_state;
1283  DetectEngineStateDirection *tx_dir_state = tx_de_state ? &tx_de_state->dir_state[dir_int] : NULL;
1284  uint64_t prefilter_flags = detect_flags & APP_LAYER_TX_PREFILTER_MASK;
1286 
1287  DetectTransaction tx = {
1288  .tx_ptr = tx_ptr,
1289  .tx_id = tx_id,
1290  .tx_data_ptr = (struct AppLayerTxData *)txd,
1291  .de_state = tx_dir_state,
1292  .detect_flags = detect_flags,
1293  .prefilter_flags = prefilter_flags,
1294  .prefilter_flags_orig = prefilter_flags,
1295  .tx_progress = tx_progress,
1296  .tx_end_state = tx_end_state,
1297  };
1298  return tx;
1299 }
1300 
1301 static inline void StoreDetectFlags(DetectTransaction *tx, const uint8_t flow_flags,
1302  const uint8_t ipproto, const AppProto alproto, const uint64_t detect_flags)
1303 {
1305  if (likely(txd != NULL)) {
1306  if (flow_flags & STREAM_TOSERVER) {
1307  txd->detect_flags_ts = detect_flags;
1308  } else {
1309  txd->detect_flags_tc = detect_flags;
1310  }
1311  }
1312 }
1313 
1314 // Merge 'state' rules from the regular prefilter
1315 // updates array_idx on the way
1316 static inline void RuleMatchCandidateMergeStateRules(
1317  DetectEngineThreadCtx *det_ctx, uint32_t *array_idx)
1318 {
1319  // Now, we will merge 2 sorted lists :
1320  // the one in det_ctx->tx_candidates
1321  // and the one in det_ctx->match_array
1322  // For match_array, we take only the relevant elements where s->app_inspect != NULL
1323 
1324  // Basically, we iterate at the same time over the 2 lists
1325  // comparing and taking an element from either.
1326 
1327  // Trick is to do so in place in det_ctx->tx_candidates,
1328  // so as to minimize the number of moves in det_ctx->tx_candidates.
1329  // For this, the algorithm traverses the lists in reverse order.
1330  // Otherwise, if the first element of match_array was to be put before
1331  // all tx_candidates, we would need to shift all tx_candidates
1332 
1333  // Retain the number of elements sorted in tx_candidates before merge
1334  uint32_t j = *array_idx;
1335  // First loop only counting the number of elements to add
1336  for (uint32_t i = 0; i < det_ctx->match_array_cnt; i++) {
1337  const Signature *s = det_ctx->match_array[i];
1338  if (s->app_inspect != NULL) {
1339  (*array_idx)++;
1340  }
1341  }
1342  // Future number of elements in tx_candidates after merge
1343  uint32_t k = *array_idx;
1344 
1345  if (k == j) {
1346  // no new element from match_array to merge in tx_candidates
1347  return;
1348  }
1349 
1350  // variable i is for all elements of match_array (even not relevant ones)
1351  // variable j is for elements of tx_candidates before merge
1352  // variable k is for elements of tx_candidates after merge
1353  for (uint32_t i = det_ctx->match_array_cnt; i > 0;) {
1354  const Signature *s = det_ctx->match_array[i - 1];
1355  if (s->app_inspect == NULL) {
1356  // no relevant element, get the next one from match_array
1357  i--;
1358  continue;
1359  }
1360  // we have one element from match_array to merge in tx_candidates
1361  k--;
1362  if (j > 0) {
1363  // j > 0 means there is still at least one element in tx_candidates to merge
1364  const RuleMatchCandidateTx *s0 = &det_ctx->tx_candidates[j - 1];
1365  if (s->num <= s0->id) {
1366  // get next element from previous tx_candidates
1367  j--;
1368  // take the element from tx_candidates before merge
1369  det_ctx->tx_candidates[k].s = det_ctx->tx_candidates[j].s;
1370  det_ctx->tx_candidates[k].id = det_ctx->tx_candidates[j].id;
1371  det_ctx->tx_candidates[k].flags = det_ctx->tx_candidates[j].flags;
1372  det_ctx->tx_candidates[k].stream_reset = det_ctx->tx_candidates[j].stream_reset;
1373  continue;
1374  }
1375  } // otherwise
1376  // get next element from match_array
1377  i--;
1378  // take the element from match_array
1379  det_ctx->tx_candidates[k].s = s;
1380  det_ctx->tx_candidates[k].id = s->num;
1381  det_ctx->tx_candidates[k].flags = NULL;
1382  det_ctx->tx_candidates[k].stream_reset = 0;
1383  }
1384  // Even if k > 0 or j > 0, the loop is over. (Note that j == k now)
1385  // The remaining elements in tx_candidates up to k were already sorted
1386  // and come before any other element later in the list
1387 }
1388 
1389 static void DetectRunTx(ThreadVars *tv,
1391  DetectEngineThreadCtx *det_ctx,
1392  Packet *p,
1393  Flow *f,
1394  DetectRunScratchpad *scratch)
1395 {
1396  const uint8_t flow_flags = scratch->flow_flags;
1397  const SigGroupHead * const sgh = scratch->sgh;
1398  void * const alstate = f->alstate;
1399  const uint8_t ipproto = f->proto;
1400  const AppProto alproto = f->alproto;
1401 
1402  const uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
1403  uint64_t tx_id_min = AppLayerParserGetTransactionInspectId(f->alparser, flow_flags);
1404  const int tx_end_state = AppLayerParserGetStateProgressCompletionStatus(alproto, flow_flags);
1405 
1406  AppLayerGetTxIteratorFunc IterFunc = AppLayerGetTxIterator(ipproto, alproto);
1407  AppLayerGetTxIterState state;
1408  memset(&state, 0, sizeof(state));
1409 
1410  while (1) {
1411  AppLayerGetTxIterTuple ires = IterFunc(ipproto, alproto, alstate, tx_id_min, total_txs, &state);
1412  if (ires.tx_ptr == NULL)
1413  break;
1414 
1415  DetectTransaction tx = GetDetectTx(ipproto, alproto,
1416  alstate, ires.tx_id, ires.tx_ptr, tx_end_state, flow_flags);
1417  if (tx.tx_ptr == NULL) {
1418  SCLogDebug("%p/%"PRIu64" no transaction to inspect",
1419  tx.tx_ptr, tx_id_min);
1420 
1421  tx_id_min++; // next (if any) run look for +1
1422  goto next;
1423  }
1424  tx_id_min = tx.tx_id + 1; // next look for cur + 1
1425 
1426  bool do_sort = false; // do we need to sort the tx candidate list?
1427  uint32_t array_idx = 0;
1428  uint32_t total_rules = det_ctx->match_array_cnt;
1429  total_rules += (tx.de_state ? tx.de_state->cnt : 0);
1430 
1431  /* run prefilter engines and merge results into a candidates array */
1432  if (sgh->tx_engines) {
1434  DetectRunPrefilterTx(det_ctx, sgh, p, ipproto, flow_flags, alproto,
1435  alstate, &tx);
1437  SCLogDebug("%p/%"PRIu64" rules added from prefilter: %u candidates",
1438  tx.tx_ptr, tx.tx_id, det_ctx->pmq.rule_id_array_cnt);
1439 
1440  total_rules += det_ctx->pmq.rule_id_array_cnt;
1441  if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
1442  RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1443  }
1444 
1445  for (uint32_t i = 0; i < det_ctx->pmq.rule_id_array_cnt; i++) {
1446  const Signature *s = de_ctx->sig_array[det_ctx->pmq.rule_id_array[i]];
1447  const SigIntId id = s->num;
1448  det_ctx->tx_candidates[array_idx].s = s;
1449  det_ctx->tx_candidates[array_idx].id = id;
1450  det_ctx->tx_candidates[array_idx].flags = NULL;
1451  det_ctx->tx_candidates[array_idx].stream_reset = 0;
1452  array_idx++;
1453  }
1454  PMQ_RESET(&det_ctx->pmq);
1455  } else {
1456  if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
1457  RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1458  }
1459  }
1460 
1461  /* merge 'state' rules from the regular prefilter */
1462 #ifdef PROFILING
1463  uint32_t x = array_idx;
1464 #endif
1465  RuleMatchCandidateMergeStateRules(det_ctx, &array_idx);
1466 
1467  /* merge stored state into results */
1468  if (tx.de_state != NULL) {
1469  const uint32_t old = array_idx;
1470 
1471  /* if tx.de_state->flags has 'new file' set and sig below has
1472  * 'file inspected' flag, reset the file part of the state */
1473  const bool have_new_file = (tx.de_state->flags & DETECT_ENGINE_STATE_FLAG_FILE_NEW);
1474  if (have_new_file) {
1475  SCLogDebug("%p/%"PRIu64" destate: need to consider new file",
1476  tx.tx_ptr, tx.tx_id);
1478  }
1479 
1480  SigIntId state_cnt = 0;
1481  DeStateStore *tx_store = tx.de_state->head;
1482  for (; tx_store != NULL; tx_store = tx_store->next) {
1483  SCLogDebug("tx_store %p", tx_store);
1484 
1485  SigIntId store_cnt = 0;
1486  for (store_cnt = 0;
1487  store_cnt < DE_STATE_CHUNK_SIZE && state_cnt < tx.de_state->cnt;
1488  store_cnt++, state_cnt++)
1489  {
1490  DeStateStoreItem *item = &tx_store->store[store_cnt];
1491  SCLogDebug("rule id %u, inspect_flags %u", item->sid, item->flags);
1492  if (have_new_file && (item->flags & DE_STATE_FLAG_FILE_INSPECT)) {
1493  /* remove part of the state. File inspect engine will now
1494  * be able to run again */
1496  SCLogDebug("rule id %u, post file reset inspect_flags %u", item->sid, item->flags);
1497  }
1498  det_ctx->tx_candidates[array_idx].s = de_ctx->sig_array[item->sid];
1499  det_ctx->tx_candidates[array_idx].id = item->sid;
1500  det_ctx->tx_candidates[array_idx].flags = &item->flags;
1501  det_ctx->tx_candidates[array_idx].stream_reset = 0;
1502  array_idx++;
1503  }
1504  }
1505  do_sort |= (old && old != array_idx); // sort if continue list adds sids
1506  SCLogDebug("%p/%" PRIu64 " rules added from 'continue' list: %u", tx.tx_ptr, tx.tx_id,
1507  array_idx - old);
1508  }
1509  if (do_sort) {
1510  qsort(det_ctx->tx_candidates, array_idx, sizeof(RuleMatchCandidateTx),
1511  DetectRunTxSortHelper);
1512  }
1513 
1514 #ifdef PROFILING
1515  if (array_idx >= de_ctx->profile_match_logging_threshold)
1516  RulesDumpTxMatchArray(det_ctx, scratch->sgh, p, tx.tx_id, array_idx, x);
1517 #endif
1518  det_ctx->tx_id = tx.tx_id;
1519  det_ctx->tx_id_set = true;
1520  det_ctx->p = p;
1521 
1522 #ifdef DEBUG
1523  for (uint32_t i = 0; i < array_idx; i++) {
1524  RuleMatchCandidateTx *can = &det_ctx->tx_candidates[i];
1525  const Signature *s = det_ctx->tx_candidates[i].s;
1526  SCLogDebug("%u: sid %u flags %p", i, s->id, can->flags);
1527  }
1528 #endif
1529  /* run rules: inspect the match candidates */
1530  for (uint32_t i = 0; i < array_idx; i++) {
1531  RuleMatchCandidateTx *can = &det_ctx->tx_candidates[i];
1532  const Signature *s = det_ctx->tx_candidates[i].s;
1533  uint32_t *inspect_flags = det_ctx->tx_candidates[i].flags;
1534 
1535  /* deduplicate: rules_array is sorted, but not deduplicated:
1536  * both mpm and stored state could give us the same sid.
1537  * As they are back to back in that case we can check for it
1538  * here. We select the stored state one as that comes first
1539  * in the array. */
1540  while ((i + 1) < array_idx &&
1541  det_ctx->tx_candidates[i].s == det_ctx->tx_candidates[i + 1].s) {
1542  SCLogDebug("%p/%" PRIu64 " inspecting SKIP NEXT: sid %u (%u), flags %08x",
1543  tx.tx_ptr, tx.tx_id, s->id, s->num, inspect_flags ? *inspect_flags : 0);
1544  i++;
1545  }
1546 
1547  SCLogDebug("%p/%"PRIu64" inspecting: sid %u (%u), flags %08x",
1548  tx.tx_ptr, tx.tx_id, s->id, s->num, inspect_flags ? *inspect_flags : 0);
1549 
1550  if (inspect_flags) {
1552  SCLogDebug("%p/%"PRIu64" inspecting: sid %u (%u), flags %08x ALREADY COMPLETE",
1553  tx.tx_ptr, tx.tx_id, s->id, s->num, *inspect_flags);
1554  continue;
1555  }
1556  }
1557 
1558  if (inspect_flags) {
1559  /* continue previous inspection */
1560  SCLogDebug("%p/%" PRIu64 " Continuing sid %u", tx.tx_ptr, tx.tx_id, s->id);
1561  } else {
1562  /* start new inspection */
1563  SCLogDebug("%p/%"PRIu64" Start sid %u", tx.tx_ptr, tx.tx_id, s->id);
1564  }
1565 
1566  /* call individual rule inspection */
1568  const int r = DetectRunTxInspectRule(tv, de_ctx, det_ctx, p, f, flow_flags,
1569  alstate, &tx, s, inspect_flags, can, scratch);
1570  if (r == 1) {
1571  /* match */
1572  DetectRunPostMatch(tv, det_ctx, p, s);
1573 
1574  const uint8_t alert_flags = (PACKET_ALERT_FLAG_STATE_MATCH | PACKET_ALERT_FLAG_TX);
1575  SCLogDebug("%p/%"PRIu64" sig %u (%u) matched", tx.tx_ptr, tx.tx_id, s->id, s->num);
1576  AlertQueueAppend(det_ctx, s, p, tx.tx_id, alert_flags);
1577  }
1578  DetectVarProcessList(det_ctx, p->flow, p);
1579  RULE_PROFILING_END(det_ctx, s, r, p);
1580  }
1581 
1582  det_ctx->tx_id = 0;
1583  det_ctx->tx_id_set = false;
1584  det_ctx->p = NULL;
1585 
1586  /* see if we have any updated state to store in the tx */
1587 
1588  uint64_t new_detect_flags = 0;
1589  /* this side of the tx is done */
1590  if (tx.tx_progress >= tx.tx_end_state) {
1591  new_detect_flags |= APP_LAYER_TX_INSPECTED_FLAG;
1592  SCLogDebug("%p/%"PRIu64" tx is done for direction %s. Flag %016"PRIx64,
1593  tx.tx_ptr, tx.tx_id,
1594  flow_flags & STREAM_TOSERVER ? "toserver" : "toclient",
1595  new_detect_flags);
1596  }
1597  if (tx.prefilter_flags != tx.prefilter_flags_orig) {
1598  new_detect_flags |= tx.prefilter_flags;
1600  SCLogDebug("%p/%"PRIu64" updated prefilter flags %016"PRIx64" "
1601  "(was: %016"PRIx64") for direction %s. Flag %016"PRIx64,
1603  flow_flags & STREAM_TOSERVER ? "toserver" : "toclient",
1604  new_detect_flags);
1605  }
1606  if (new_detect_flags != 0 &&
1607  (new_detect_flags | tx.detect_flags) != tx.detect_flags)
1608  {
1609  new_detect_flags |= tx.detect_flags;
1611  SCLogDebug("%p/%"PRIu64" Storing new flags %016"PRIx64" (was %016"PRIx64")",
1612  tx.tx_ptr, tx.tx_id, new_detect_flags, tx.detect_flags);
1613 
1614  StoreDetectFlags(&tx, flow_flags, ipproto, alproto, new_detect_flags);
1615  }
1616 next:
1617  InspectionBufferClean(det_ctx);
1618 
1619  if (!ires.has_next)
1620  break;
1621  }
1622 }
1623 
1624 static void DetectRunFrames(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
1625  Packet *p, Flow *f, DetectRunScratchpad *scratch)
1626 {
1627  const SigGroupHead *const sgh = scratch->sgh;
1628  const AppProto alproto = f->alproto;
1629 
1630  FramesContainer *frames_container = AppLayerFramesGetContainer(f);
1631  if (frames_container == NULL) {
1632  return;
1633  }
1634  Frames *frames;
1635  if (PKT_IS_TOSERVER(p)) {
1636  frames = &frames_container->toserver;
1637  } else {
1638  frames = &frames_container->toclient;
1639  }
1640 
1641  for (uint32_t idx = 0; idx < frames->cnt; idx++) {
1642  SCLogDebug("frame %u", idx);
1643  Frame *frame = FrameGetByIndex(frames, idx);
1644  if (frame == NULL) {
1645  continue;
1646  }
1647 
1648  det_ctx->frame_inspect_progress = 0;
1649  uint32_t array_idx = 0;
1650  uint32_t total_rules = det_ctx->match_array_cnt;
1651 
1652  /* run prefilter engines and merge results into a candidates array */
1653  if (sgh->frame_engines) {
1654  // PACKET_PROFILING_DETECT_START(p, PROF_DETECT_PF_TX);
1655  DetectRunPrefilterFrame(det_ctx, sgh, p, frames, frame, alproto);
1656  // PACKET_PROFILING_DETECT_END(p, PROF_DETECT_PF_TX);
1657  SCLogDebug("%p/%" PRIi64 " rules added from prefilter: %u candidates", frame, frame->id,
1658  det_ctx->pmq.rule_id_array_cnt);
1659 
1660  total_rules += det_ctx->pmq.rule_id_array_cnt;
1661 
1662  if (!(RuleMatchCandidateTxArrayHasSpace(
1663  det_ctx, total_rules))) { // TODO is it safe to overload?
1664  RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
1665  }
1666 
1667  for (uint32_t i = 0; i < det_ctx->pmq.rule_id_array_cnt; i++) {
1668  const Signature *s = de_ctx->sig_array[det_ctx->pmq.rule_id_array[i]];
1669  const SigIntId id = s->num;
1670  det_ctx->tx_candidates[array_idx].s = s;
1671  det_ctx->tx_candidates[array_idx].id = id;
1672  det_ctx->tx_candidates[array_idx].flags = NULL;
1673  det_ctx->tx_candidates[array_idx].stream_reset = 0;
1674  array_idx++;
1675  }
1676  PMQ_RESET(&det_ctx->pmq);
1677  }
1678  /* merge 'state' rules from the regular prefilter */
1679  uint32_t x = array_idx;
1680  for (uint32_t i = 0; i < det_ctx->match_array_cnt; i++) {
1681  const Signature *s = det_ctx->match_array[i];
1682  if (s->frame_inspect != NULL) {
1683  const SigIntId id = s->num;
1684  det_ctx->tx_candidates[array_idx].s = s;
1685  det_ctx->tx_candidates[array_idx].id = id;
1686  det_ctx->tx_candidates[array_idx].flags = NULL;
1687  det_ctx->tx_candidates[array_idx].stream_reset = 0;
1688  array_idx++;
1689 
1690  SCLogDebug("%p/%" PRIi64 " rule %u (%u) added from 'match' list", frame, frame->id,
1691  s->id, id);
1692  }
1693  }
1694  SCLogDebug("%p/%" PRIi64 " rules added from 'match' list: %u", frame, frame->id,
1695  array_idx - x);
1696  (void)x;
1697 
1698  /* run rules: inspect the match candidates */
1699  for (uint32_t i = 0; i < array_idx; i++) {
1700  const Signature *s = det_ctx->tx_candidates[i].s;
1701 
1702  /* deduplicate: rules_array is sorted, but not deduplicated.
1703  * As they are back to back in that case we can check for it
1704  * here. We select the stored state one as that comes first
1705  * in the array. */
1706  while ((i + 1) < array_idx &&
1707  det_ctx->tx_candidates[i].s == det_ctx->tx_candidates[i + 1].s) {
1708  i++;
1709  }
1710  SCLogDebug("%p/%" PRIi64 " inspecting: sid %u (%u)", frame, frame->id, s->id, s->num);
1711 
1712  /* start new inspection */
1713  SCLogDebug("%p/%" PRIi64 " Start sid %u", frame, frame->id, s->id);
1714 
1715  /* call individual rule inspection */
1717  bool r = DetectRunInspectRuleHeader(p, f, s, s->flags, s->proto.flags);
1718  if (r == true) {
1719  r = DetectRunFrameInspectRule(tv, det_ctx, s, f, p, frames, frame);
1720  if (r == true) {
1721  /* match */
1722  DetectRunPostMatch(tv, det_ctx, p, s);
1723 
1724  const uint8_t alert_flags =
1727  det_ctx->frame_id = frame->id;
1728  SCLogDebug(
1729  "%p/%" PRIi64 " sig %u (%u) matched", frame, frame->id, s->id, s->num);
1730  AlertQueueAppend(det_ctx, s, p, frame->tx_id, alert_flags);
1731  }
1732  }
1733  DetectVarProcessList(det_ctx, p->flow, p);
1734  RULE_PROFILING_END(det_ctx, s, r, p);
1735  }
1736 
1737  /* update Frame::inspect_progress here instead of in the code above. The reason is that a
1738  * frame might be used more than once in buffers with transforms. */
1739  if (frame->inspect_progress < det_ctx->frame_inspect_progress) {
1740  frame->inspect_progress = det_ctx->frame_inspect_progress;
1741  SCLogDebug("frame->inspect_progress: %" PRIu64 " -> updated", frame->inspect_progress);
1742  } else {
1743  SCLogDebug(
1744  "frame->inspect_progress: %" PRIu64 " -> not updated", frame->inspect_progress);
1745  }
1746 
1747  SCLogDebug("%p/%" PRIi64 " rules inspected, running cleanup", frame, frame->id);
1748  InspectionBufferClean(det_ctx);
1749  }
1750 }
1751 
1752 static DetectEngineThreadCtx *GetTenantById(HashTable *h, uint32_t id)
1753 {
1754  /* technically we need to pass a DetectEngineThreadCtx struct with the
1755  * tenant_id member. But as that member is the first in the struct, we
1756  * can use the id directly. */
1757  return HashTableLookup(h, &id, 0);
1758 }
1759 
1760 static void DetectFlow(ThreadVars *tv,
1762  Packet *p)
1763 {
1764  Flow *const f = p->flow;
1765 
1766  if (p->flags & PKT_NOPACKET_INSPECTION) {
1767  /* hack: if we are in pass the entire flow mode, we need to still
1768  * update the inspect_id forward. So test for the condition here,
1769  * and call the update code if necessary. */
1770  const int pass = ((f->flags & FLOW_NOPACKET_INSPECTION));
1771  if (pass) {
1772  uint8_t flags = STREAM_FLAGS_FOR_PACKET(p);
1774  if (f->alstate) {
1776  }
1777  }
1778  SCLogDebug("p->pcap %"PRIu64": no detection on packet, "
1779  "PKT_NOPACKET_INSPECTION is set", p->pcap_cnt);
1780  return;
1781  }
1782 
1783  /* we check the flow drop here, and not the packet drop. This is
1784  * to allow stream engine "invalid" drop packets to still be
1785  * evaluated by the stream event rules. */
1786  if (f->flags & FLOW_ACTION_DROP) {
1788  SCReturn;
1789  }
1790 
1791  /* see if the packet matches one or more of the sigs */
1792  (void)DetectRun(tv, de_ctx, det_ctx, p);
1793 }
1794 
1795 
1796 static void DetectNoFlow(ThreadVars *tv,
1798  Packet *p)
1799 {
1800  /* No need to perform any detection on this packet, if the given flag is set.*/
1802  return;
1803  }
1804 
1805  /* see if the packet matches one or more of the sigs */
1806  DetectRun(tv, de_ctx, det_ctx, p);
1807  return;
1808 }
1809 
1810 /** \brief Detection engine thread wrapper.
1811  * \param tv thread vars
1812  * \param p packet to inspect
1813  * \param data thread specific data
1814  * \param pq packet queue
1815  * \retval TM_ECODE_FAILED error
1816  * \retval TM_ECODE_OK ok
1817  */
1818 TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
1819 {
1821 
1822  DetectEngineCtx *de_ctx = NULL;
1823  DetectEngineThreadCtx *det_ctx = (DetectEngineThreadCtx *)data;
1824  if (det_ctx == NULL) {
1825  printf("ERROR: Detect has no thread ctx\n");
1826  goto error;
1827  }
1828 
1829  if (unlikely(SC_ATOMIC_GET(det_ctx->so_far_used_by_detect) == 0)) {
1830  (void)SC_ATOMIC_SET(det_ctx->so_far_used_by_detect, 1);
1831  SCLogDebug("Detect Engine using new det_ctx - %p",
1832  det_ctx);
1833  }
1834 
1835  /* if in MT mode _and_ we have tenants registered, use
1836  * MT logic. */
1837  if (det_ctx->mt_det_ctxs_cnt > 0 && det_ctx->TenantGetId != NULL)
1838  {
1839  uint32_t tenant_id = p->tenant_id;
1840  if (tenant_id == 0)
1841  tenant_id = det_ctx->TenantGetId(det_ctx, p);
1842  if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
1843  p->tenant_id = tenant_id;
1844  det_ctx = GetTenantById(det_ctx->mt_det_ctxs_hash, tenant_id);
1845  if (det_ctx == NULL)
1846  return TM_ECODE_OK;
1847  de_ctx = det_ctx->de_ctx;
1848  if (de_ctx == NULL)
1849  return TM_ECODE_OK;
1850 
1851  if (unlikely(SC_ATOMIC_GET(det_ctx->so_far_used_by_detect) == 0)) {
1852  (void)SC_ATOMIC_SET(det_ctx->so_far_used_by_detect, 1);
1853  SCLogDebug("MT de_ctx %p det_ctx %p (tenant %u)", de_ctx, det_ctx, tenant_id);
1854  }
1855  } else {
1856  /* use default if no tenants are registered for this packet */
1857  de_ctx = det_ctx->de_ctx;
1858  }
1859  } else {
1860  de_ctx = det_ctx->de_ctx;
1861  }
1862 
1863  if (p->flow) {
1864  DetectFlow(tv, de_ctx, det_ctx, p);
1865  } else {
1866  DetectNoFlow(tv, de_ctx, det_ctx, p);
1867  }
1868 
1869 #ifdef PROFILE_RULES
1870  /* aggregate statistics */
1871  struct timeval ts;
1872  gettimeofday(&ts, NULL);
1873  if (ts.tv_sec != det_ctx->rule_perf_last_sync) {
1874  SCProfilingRuleThreatAggregate(det_ctx);
1875  det_ctx->rule_perf_last_sync = ts.tv_sec;
1876  }
1877 #endif
1878 
1879  return TM_ECODE_OK;
1880 error:
1881  return TM_ECODE_FAILED;
1882 }
1883 
1884 /** \brief disable file features we don't need
1885  * Called if we have no detection engine.
1886  */
1888 {
1889  DetectPostInspectFileFlagsUpdate(f, NULL /* no sgh */, STREAM_TOSERVER);
1890  DetectPostInspectFileFlagsUpdate(f, NULL /* no sgh */, STREAM_TOCLIENT);
1891 }
1892 
1893 #ifdef UNITTESTS
1894 /**
1895  * \brief wrapper for old tests
1896  */
1899 {
1900  if (p->flow) {
1901  DetectFlow(tv, de_ctx, det_ctx, p);
1902  } else {
1903  DetectNoFlow(tv, de_ctx, det_ctx, p);
1904  }
1905 }
1906 #endif
1907 
1908 /*
1909  * TESTS
1910  */
1911 
1912 #ifdef UNITTESTS
1913 #include "tests/detect.c"
1914 #endif
1915 
PKT_IS_TOCLIENT
#define PKT_IS_TOCLIENT(p)
Definition: decode.h:253
DetectEngineAppInspectionEngine_::stream
bool stream
Definition: detect.h:432
SigGroupHead_::non_pf_syn_store_cnt
uint32_t non_pf_syn_store_cnt
Definition: detect.h:1460
PacketCheckAction
bool PacketCheckAction(const Packet *p, const uint8_t a)
Definition: packet.c:48
FLOWFILE_NO_MD5_TS
#define FLOWFILE_NO_MD5_TS
Definition: flow.h:131
DetectEngineThreadCtx_::non_pf_store_ptr
SignatureNonPrefilterStore * non_pf_store_ptr
Definition: detect.h:1200
RulesDumpTxMatchArray
void RulesDumpTxMatchArray(const DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, const Packet *p, const uint64_t tx_id, const uint32_t rule_cnt, const uint32_t pkt_prefilter_cnt)
Definition: detect-engine-profile.c:34
SIG_GROUP_HEAD_HAVEFILEMD5
#define SIG_GROUP_HEAD_HAVEFILEMD5
Definition: detect.h:1326
FLOWFILE_NO_MD5_TC
#define FLOWFILE_NO_MD5_TC
Definition: flow.h:132
SigGroupHead_::tx_engines
PrefilterEngine * tx_engines
Definition: detect.h:1467
DetectEngineAppInspectionEngine_
Definition: detect.h:427
Packet_::proto
uint8_t proto
Definition: decode.h:459
DetectTransaction_::tx_data_ptr
struct AppLayerTxData * tx_data_ptr
Definition: detect-engine-prefilter.h:34
DetectEngineAppInspectionEngine_::mpm
bool mpm
Definition: detect.h:431
DE_STATE_CHUNK_SIZE
#define DE_STATE_CHUNK_SIZE
Definition: detect-engine-state.h:52
RuleMatchCandidateTx::stream_stored
bool stream_stored
Definition: detect.h:1083
FLOWFILE_NO_SIZE_TS
#define FLOWFILE_NO_SIZE_TS
Definition: flow.h:143
Frame::inspect_progress
uint64_t inspect_progress
Definition: app-layer-frames.h:55
DetectEngineThreadCtx_::alert_queue_size
uint16_t alert_queue_size
Definition: detect.h:1184
PROF_DETECT_GETSGH
@ PROF_DETECT_GETSGH
Definition: suricata-common.h:441
ts
uint64_t ts
Definition: source-erf-file.c:55
FLOWFILE_NO_SIZE_TC
#define FLOWFILE_NO_SIZE_TC
Definition: flow.h:144
detect-engine.h
PACKET_ALERT_FLAG_STREAM_MATCH
#define PACKET_ALERT_FLAG_STREAM_MATCH
Definition: decode.h:278
detect-engine-proto.h
DetectEngineThreadCtx_::match_array_cnt
SigIntId match_array_cnt
Definition: detect.h:1195
Frame::tx_id
uint64_t tx_id
Definition: app-layer-frames.h:54
DetectEngineStateDirection_::flags
uint8_t flags
Definition: detect-engine-state.h:88
detect-dsize.h
Signature_::addr_src_match6
DetectMatchAddressIPv6 * addr_src_match6
Definition: detect.h:629
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1022
PACKET_ALERT_FLAG_TX
#define PACKET_ALERT_FLAG_TX
Definition: decode.h:280
DetectEngineCtx_::decoder_event_sgh
struct SigGroupHead_ * decoder_event_sgh
Definition: detect.h:922
FlowGetPacketDirection
int FlowGetPacketDirection(const Flow *f, const Packet *p)
determine the direction of the packet compared to the flow
Definition: flow.c:290
DetectEngineCtx_::flow_gh
DetectEngineLookupFlow flow_gh[FLOW_STATES]
Definition: detect.h:869
DE_STATE_FLAG_SIG_CANT_MATCH
#define DE_STATE_FLAG_SIG_CANT_MATCH
Definition: detect-engine-state.h:56
DetectEngineThreadCtx_::counter_match_list
uint16_t counter_match_list
Definition: detect.h:1154
DetectEngineAppInspectionEngine_::next
struct DetectEngineAppInspectionEngine_ * next
Definition: detect.h:446
DETECT_PROTO_IPV6
#define DETECT_PROTO_IPV6
Definition: detect-engine-proto.h:34
detect-engine-siggroup.h
SigGroupHead_::flags
uint16_t flags
Definition: detect.h:1449
PKT_IS_PSEUDOPKT
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
Definition: decode.h:1075
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:247
DetectEngineState_
Definition: detect-engine-state.h:92
Signature_::num
SigIntId num
Definition: detect.h:608
stream-tcp.h
Prefilter
void Prefilter(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const uint8_t flags)
Definition: detect-engine-prefilter.c:143
PrefilterRuleStore_::rule_id_array_cnt
uint32_t rule_id_array_cnt
Definition: util-prefilter.h:40
detect-engine-event.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1448
SIG_GROUP_HEAD_HAVEFILESIZE
#define SIG_GROUP_HEAD_HAVEFILESIZE
Definition: detect.h:1327
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
detect.c
SC_ATOMIC_SET
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
Definition: util-atomic.h:386
KEYWORD_PROFILING_SET_LIST
#define KEYWORD_PROFILING_SET_LIST(ctx, list)
Definition: util-profiling.h:46
DetectAddressMatchIPv4
int DetectAddressMatchIPv4(const DetectMatchAddressIPv4 *addrs, uint16_t addrs_cnt, const Address *a)
Match a packets address against a signatures addrs array.
Definition: detect-engine-address.c:1593
DetectEngineAppInspectionEngine_::Callback
InspectEngineFuncPtr Callback
Definition: detect.h:439
Signature_::alproto
AppProto alproto
Definition: detect.h:601
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
SignatureNonPrefilterStore_::id
SigIntId id
Definition: detect.h:1072
FLOW_SGH_TOCLIENT
#define FLOW_SGH_TOCLIENT
Definition: flow.h:72
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:607
AppLayerParserSetTransactionInspectId
void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *pstate, void *alstate, const uint8_t flags, bool tag_txs_as_inspected)
Definition: app-layer-parser.c:746
DetectEngineStateDirection_::cnt
SigIntId cnt
Definition: detect-engine-state.h:86
AppLayerGetTxIterator
AppLayerGetTxIteratorFunc AppLayerGetTxIterator(const uint8_t ipproto, const AppProto alproto)
Definition: app-layer-parser.c:690
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
SigMatchData_::is_last
bool is_last
Definition: detect.h:361
Flow_::proto
uint8_t proto
Definition: flow.h:373
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:81
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:290
AppLayerParserGetStateProgress
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t flags)
get the progress value for a tx/protocol
Definition: app-layer-parser.c:1086
DetectEngineThreadCtx_::tx_id
uint64_t tx_id
Definition: detect.h:1178
SigMatchData_::ctx
SigMatchCtx * ctx
Definition: detect.h:362
action-globals.h
FLOWFILE_NO_MAGIC_TS
#define FLOWFILE_NO_MAGIC_TS
Definition: flow.h:124
FramesContainer::toserver
Frames toserver
Definition: app-layer-frames.h:74
Packet_::flags
uint32_t flags
Definition: decode.h:474
ICMPV4_DEST_UNREACH_IS_VALID
#define ICMPV4_DEST_UNREACH_IS_VALID(p)
Definition: decode-icmpv4.h:267
Frame
Definition: app-layer-frames.h:45
Flow_
Flow data structure.
Definition: flow.h:351
DetectTransaction_::tx_end_state
const int tx_end_state
Definition: detect-engine-prefilter.h:41
PROF_DETECT_ALERT
@ PROF_DETECT_ALERT
Definition: suricata-common.h:452
DetectEngineThreadCtx_::pmq
PrefilterRuleStore pmq
Definition: detect.h:1204
SIG_GROUP_HEAD_HAVEFILESHA1
#define SIG_GROUP_HEAD_HAVEFILESHA1
Definition: detect.h:1328
FLOW_TC_APP_UPDATED
#define FLOW_TC_APP_UPDATED
Definition: flow.h:117
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:839
AppLayerParserGetStateProgressCompletionStatus
int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto, uint8_t direction)
Definition: app-layer-parser.c:1115
DetectRunScratchpad
struct DetectRunScratchpad DetectRunScratchpad
PROF_DETECT_PF_TX
@ PROF_DETECT_PF_TX
Definition: suricata-common.h:447
Frames::cnt
uint16_t cnt
Definition: app-layer-frames.h:61
Frame::id
int64_t id
Definition: app-layer-frames.h:53
APP_LAYER_TX_SKIP_INSPECT_FLAG
#define APP_LAYER_TX_SKIP_INSPECT_FLAG
Definition: app-layer-parser.h:79
DetectEngineThreadCtx_::p
Packet * p
Definition: detect.h:1182
DetectEngineState_::dir_state
DetectEngineStateDirection dir_state[2]
Definition: detect-engine-state.h:93
FrameGetByIndex
Frame * FrameGetByIndex(Frames *frames, const uint32_t idx)
Definition: app-layer-frames.c:106
RuleMatchCandidateTx::id
SigIntId id
Definition: detect.h:1079
PROF_DETECT_CLEANUP
@ PROF_DETECT_CLEANUP
Definition: suricata-common.h:454
SIG_FLAG_DST_ANY
#define SIG_FLAG_DST_ANY
Definition: detect.h:239
NO_TX
#define NO_TX
Definition: detect.c:1246
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:223
HashTable_
Definition: util-hash.h:35
DetectEngineThreadCtx_::flags
uint16_t flags
Definition: detect.h:1173
Frames
Definition: app-layer-frames.h:60
FramesContainer
Definition: app-layer-frames.h:73
PacketAlerts_::drop
PacketAlert drop
Definition: decode.h:296
APP_LAYER_TX_INSPECTED_FLAG
#define APP_LAYER_TX_INSPECTED_FLAG
Definition: app-layer-parser.h:81
DetectRunScratchpad
Definition: detect.c:70
SIG_GROUP_HEAD_HAVERAWSTREAM
#define SIG_GROUP_HEAD_HAVERAWSTREAM
Definition: detect.h:1322
FLOW_ACTION_DROP
#define FLOW_ACTION_DROP
Definition: flow.h:67
TcpStream_::flags
uint16_t flags
Definition: stream-tcp-private.h:107
FLOWFILE_NONE
#define FLOWFILE_NONE
Definition: flow.h:162
detect-engine-frame.h
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:1897
Signature_::sm_arrays
SigMatchData * sm_arrays[DETECT_SM_LIST_MAX]
Definition: detect.h:649
proto
uint8_t proto
Definition: decode-template.h:0
DetectPort_::sh
struct SigGroupHead_ * sh
Definition: detect.h:228
PACKET_PROFILING_DETECT_END
#define PACKET_PROFILING_DETECT_END(p, id)
Definition: util-profiling.h:222
Detect
TmEcode Detect(ThreadVars *tv, Packet *p, void *data)
Detection engine thread wrapper.
Definition: detect.c:1818
FLOW_PKT_TOCLIENT_IPONLY_SET
#define FLOW_PKT_TOCLIENT_IPONLY_SET
Definition: flow.h:227
detect-engine-payload.h
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:468
SIG_FLAG_SRC_ANY
#define SIG_FLAG_SRC_ANY
Definition: detect.h:238
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
DetectRunFrameInspectRule
bool DetectRunFrameInspectRule(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, const Frames *frames, const Frame *frame)
Definition: detect-engine-frame.c:227
Flow_::protoctx
void * protoctx
Definition: flow.h:441
SigMatchData_
Data needed for Match()
Definition: detect.h:359
DeStateStoreItem_::sid
SigIntId sid
Definition: detect-engine-state.h:74
RuleMatchCandidateTx::s
const Signature * s
Definition: detect.h:1089
KEYWORD_PROFILING_START
#define KEYWORD_PROFILING_START
Definition: util-profiling.h:50
DetectEngineThreadCtx_::counter_fnonmpm_list
uint16_t counter_fnonmpm_list
Definition: detect.h:1153
SigMatchData_::type
uint16_t type
Definition: detect.h:360
DetectEngineCtx_::version
uint32_t version
Definition: detect.h:918
DisableDetectFlowFileFlags
void DisableDetectFlowFileFlags(Flow *f)
disable file features we don't need Called if we have no detection engine.
Definition: detect.c:1887
AppLayerParserGetTransactionInspectId
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:715
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:601
DetectTransaction_::tx_progress
const int tx_progress
Definition: detect-engine-prefilter.h:40
DetectEngineThreadCtx_::counter_nonmpm_list
uint16_t counter_nonmpm_list
Definition: detect.h:1152
detect-engine-prefilter.h
DetectRunPrefilterFrame
void DetectRunPrefilterFrame(DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, Packet *p, const Frames *frames, const Frame *frame, const AppProto alproto)
Definition: detect-engine-frame.c:73
Packet_::events
PacketEngineEvents events
Definition: decode.h:611
Signature_::frame_inspect
DetectEngineFrameInspectionEngine * frame_inspect
Definition: detect.h:645
DetectTransaction_::prefilter_flags_orig
const uint64_t prefilter_flags_orig
Definition: detect-engine-prefilter.h:39
PROF_DETECT_PF_SORT2
@ PROF_DETECT_PF_SORT2
Definition: suricata-common.h:450
pad
uint16_t pad
Definition: source-erf-file.c:61
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
PacketCreateMask
void PacketCreateMask(Packet *p, SignatureMask *mask, AppProto alproto, bool app_decoder_events)
Definition: detect-engine-build.c:406
SIG_FLAG_APPLAYER
#define SIG_FLAG_APPLAYER
Definition: detect.h:245
KEYWORD_PROFILING_END
#define KEYWORD_PROFILING_END(ctx, type, m)
Definition: util-profiling.h:64
detect-flowvar.h
DetectEngineThreadCtx_::mt_det_ctxs_hash
HashTable * mt_det_ctxs_hash
Definition: detect.h:1112
PacketAlert_::action
uint8_t action
Definition: decode.h:266
TcpSession_::flags
uint32_t flags
Definition: stream-tcp-private.h:292
DetectEnginePktInspectionRun
bool DetectEnginePktInspectionRun(ThreadVars *tv, DetectEngineThreadCtx *det_ctx, const Signature *s, Flow *f, Packet *p, uint8_t *alert_flags)
Definition: detect-engine.c:1937
Flow_::sgh_toserver
const struct SigGroupHead_ * sgh_toserver
Definition: flow.h:483
PROF_DETECT_TX_UPDATE
@ PROF_DETECT_TX_UPDATE
Definition: suricata-common.h:453
DetectEngineAppInspectionEngine_::id
uint8_t id
Definition: detect.h:430
DetectEngineThreadCtx_::counter_alerts_suppressed
uint16_t counter_alerts_suppressed
Definition: detect.h:1149
DetectRunStoreStateTx
void DetectRunStoreStateTx(const SigGroupHead *sgh, Flow *f, void *tx, uint64_t tx_id, const Signature *s, uint32_t inspect_flags, uint8_t flow_flags, const uint16_t file_no_match)
Definition: detect-engine-state.c:221
DetectEngineAppInspectionEngine_::sm_list
uint16_t sm_list
Definition: detect.h:433
FLOWFILE_INIT
#define FLOWFILE_INIT
Definition: flow.h:121
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:475
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES
Definition: detect-engine-state.h:43
FLOWFILE_NO_SHA1_TC
#define FLOWFILE_NO_SHA1_TC
Definition: flow.h:136
DETECT_SM_LIST_POSTMATCH
@ DETECT_SM_LIST_POSTMATCH
Definition: detect.h:124
FramesContainer::toclient
Frames toclient
Definition: app-layer-frames.h:75
DetectEngineThreadCtx_::tx_candidates
RuleMatchCandidateTx * tx_candidates
Definition: detect.h:1197
Signature_::addr_src_match4
DetectMatchAddressIPv4 * addr_src_match4
Definition: detect.h:626
TCPHdr_::th_flags
uint8_t th_flags
Definition: decode-tcp.h:148
decode.h
DetectEngineThreadCtx_::counter_alerts_overflow
uint16_t counter_alerts_overflow
Definition: detect.h:1147
TOSERVER
#define TOSERVER
Definition: flow.h:44
DETECT_ENGINE_THREAD_CTX_FRAME_ID_SET
#define DETECT_ENGINE_THREAD_CTX_FRAME_ID_SET
Definition: detect.h:311
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:252
DetectEngineThreadCtx_
Definition: detect.h:1095
DEBUG_VALIDATE_PACKET
#define DEBUG_VALIDATE_PACKET(p)
Definition: util-validate.h:102
DeStateStoreItem_::flags
uint32_t flags
Definition: detect-engine-state.h:73
PKT_STREAM_ADD
#define PKT_STREAM_ADD
Definition: decode.h:1017
FLOWFILE_NO_STORE_TS
#define FLOWFILE_NO_STORE_TS
Definition: flow.h:128
BIT_U32
#define BIT_U32(n)
Definition: suricata-common.h:400
DetectEngineThreadCtx_::tx_candidates_size
uint32_t tx_candidates_size
Definition: detect.h:1198
FLOW_PKT_TOSERVER_IPONLY_SET
#define FLOW_PKT_TOSERVER_IPONLY_SET
Definition: flow.h:226
PKT_IS_FRAGMENT
#define PKT_IS_FRAGMENT
Definition: decode.h:1046
STREAM_FLAGS_FOR_PACKET
#define STREAM_FLAGS_FOR_PACKET(p)
Definition: stream.h:30
SCEnter
#define SCEnter(...)
Definition: util-debug.h:271
PMQ_RESET
#define PMQ_RESET(pmq)
Definition: util-prefilter.h:46
detect-engine-mpm.h
DetectEngineLookupFlow_::sgh
struct SigGroupHead_ * sgh[256]
Definition: detect.h:777
HashTableLookup
void * HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
Definition: util-hash.c:183
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DeStateStore_::next
struct DeStateStore_ * next
Definition: detect-engine-state.h:79
SignatureNonPrefilterStore_::alproto
AppProto alproto
Definition: detect.h:1074
Packet_::sp
Port sp
Definition: decode.h:444
FLOWFILE_NO_SHA256_TS
#define FLOWFILE_NO_SHA256_TS
Definition: flow.h:139
DETECT_ENGINE_INSPECT_SIG_MATCH
#define DETECT_ENGINE_INSPECT_SIG_MATCH
Definition: detect-engine-state.h:38
PKT_DETECT_HAS_STREAMDATA
#define PKT_DETECT_HAS_STREAMDATA
Definition: decode.h:1061
StreamReassembleRawHasDataReady
bool StreamReassembleRawHasDataReady(TcpSession *ssn, Packet *p)
does the stream engine have data to inspect?
Definition: stream-tcp-reassemble.c:1460
detect-engine-port.h
PktSrcToString
const char * PktSrcToString(enum PktSrcEnum pkt_src)
Definition: decode.c:820
DetectEngineThreadCtx_::non_pf_id_cnt
uint32_t non_pf_id_cnt
Definition: detect.h:1108
DetectPort_
Port structure for detection engine.
Definition: detect.h:217
PacketAlerts_::discarded
uint16_t discarded
Definition: decode.h:291
app-layer-parser.h
Signature_::app_inspect
DetectEngineAppInspectionEngine * app_inspect
Definition: detect.h:643
util-detect.h
detect-engine-profile.h
Flow_::sgh_toclient
const struct SigGroupHead_ * sgh_toclient
Definition: flow.h:480
DetectEngineThreadCtx_::base64_decoded_len
int base64_decoded_len
Definition: detect.h:1138
SIG_FLAG_REQUIRE_FLOWVAR
#define SIG_FLAG_REQUIRE_FLOWVAR
Definition: detect.h:262
RuleMatchCandidateTx::stream_result
uint8_t stream_result
Definition: detect.h:1084
util-profiling.h
DetectTransaction_::tx_id
const uint64_t tx_id
Definition: detect-engine-prefilter.h:33
DetectEngineLookupFlow_::udp
DetectPort * udp
Definition: detect.h:776
DetectEngineThreadCtx_::raw_stream_progress
uint64_t raw_stream_progress
Definition: detect.h:1121
FileUpdateFlowFileFlags
void FileUpdateFlowFileFlags(Flow *f, uint16_t set_file_flags, uint8_t direction)
set a flow's file flags
Definition: util-file.c:1121
SCReturn
#define SCReturn
Definition: util-debug.h:273
Signature_::flags
uint32_t flags
Definition: detect.h:597
AlertQueueAppend
void AlertQueueAppend(DetectEngineThreadCtx *det_ctx, const Signature *s, Packet *p, uint64_t tx_id, uint8_t alert_flags)
Append signature to local packet alert queue for later preprocessing.
Definition: detect-engine-alert.c:283
RuleMatchCandidateTxArrayFree
void RuleMatchCandidateTxArrayFree(DetectEngineThreadCtx *det_ctx)
Definition: detect.c:989
AppLayerGetTxIterState
Definition: app-layer-parser.h:144
DetectTransaction_::prefilter_flags
uint64_t prefilter_flags
Definition: detect-engine-prefilter.h:37
Packet_
Definition: decode.h:437
detect-engine-build.h
AppLayerFramesGetContainer
FramesContainer * AppLayerFramesGetContainer(Flow *f)
Definition: app-layer-parser.c:176
DetectEngineThreadCtx_::frame_id
int64_t frame_id
Definition: detect.h:1179
APP_LAYER_TX_PREFILTER_MASK
#define APP_LAYER_TX_PREFILTER_MASK
Definition: app-layer-parser.h:84
detect-engine-alert.h
conf.h
DetectRunScratchpad::pkt_mask
SignatureMask pkt_mask
Definition: detect.c:75
FlowSetIPOnlyFlag
void FlowSetIPOnlyFlag(Flow *f, int direction)
Set the IPOnly scanned flag for 'direction'.
Definition: flow.c:152
FLOW_TOSERVER_IPONLY_SET
#define FLOW_TOSERVER_IPONLY_SET
Definition: flow.h:57
DetectEngineThreadCtx_::filestore_cnt
uint16_t filestore_cnt
Definition: detect.h:1142
PROF_DETECT_IPONLY
@ PROF_DETECT_IPONLY
Definition: suricata-common.h:442
RULE_PROFILING_END
#define RULE_PROFILING_END(a, b, c, p)
Definition: util-profiling.h:431
TmEcode
TmEcode
Definition: tm-threads-common.h:83
RULE_PROFILING_START
#define RULE_PROFILING_START(p)
Definition: util-profiling.h:430
PKT_STREAM_EOF
#define PKT_STREAM_EOF
Definition: decode.h:1021
SCReturnPtr
#define SCReturnPtr(x, type)
Definition: util-debug.h:287
DetectTransaction_::de_state
DetectEngineStateDirection * de_state
Definition: detect-engine-prefilter.h:35
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
detect-filestore.h
SigTableElmt_::Match
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Definition: detect.h:1264
detect-replace.h
RulesDumpMatchArray
void RulesDumpMatchArray(const DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, const Packet *p)
Definition: detect-engine-profile.c:79
Signature_::addr_dst_match6_cnt
uint16_t addr_dst_match6_cnt
Definition: detect.h:623
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:224
SigGroupHead_::frame_engines
PrefilterEngine * frame_engines
Definition: detect.h:1468
PACKET_ALERT_NOTX
#define PACKET_ALERT_NOTX
Definition: detect.h:53
DetectEngineAppInspectionEngine_::v2
struct DetectEngineAppInspectionEngine_::@85 v2
Signature_::sp
DetectPort * sp
Definition: detect.h:637
DetectRunScratchpad::sgh
const SigGroupHead * sgh
Definition: detect.c:74
DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
#define DETECT_ENGINE_INSPECT_SIG_CANT_MATCH
Definition: detect-engine-state.h:39
DETECT_ENGINE_STATE_FLAG_FILE_NEW
#define DETECT_ENGINE_STATE_FLAG_FILE_NEW
Definition: detect-engine-state.h:70
Flow_::flowvar
GenericVar * flowvar
Definition: flow.h:486
RuleMatchCandidateTx::flags
uint32_t * flags
Definition: detect.h:1080
DetectEngineAppInspectionEngine_::alproto
AppProto alproto
Definition: detect.h:428
SCRealloc
#define SCRealloc(ptr, sz)
Definition: util-mem.h:50
detect-engine-analyzer.h
FLOWFILE_NO_SHA256_TC
#define FLOWFILE_NO_SHA256_TC
Definition: flow.h:140
DetectEngineStateDirection_::head
DeStateStore * head
Definition: detect-engine-state.h:83
DETECT_ENGINE_INSPECT_SIG_MATCH_MORE_FILES
#define DETECT_ENGINE_INSPECT_SIG_MATCH_MORE_FILES
Definition: detect-engine-state.h:49
DetectProto_::flags
uint8_t flags
Definition: detect-engine-proto.h:38
AppLayerTxData
struct AppLayerTxData AppLayerTxData
Definition: detect.h:1358
DETECT_PROTO_IPV4
#define DETECT_PROTO_IPV4
Definition: detect-engine-proto.h:33
app-layer-frames.h
DetectAddressMatchIPv6
int DetectAddressMatchIPv6(const DetectMatchAddressIPv6 *addrs, uint16_t addrs_cnt, const Address *a)
Match a packets address against a signatures addrs array.
Definition: detect-engine-address.c:1626
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:646
Packet_::flow
struct Flow_ * flow
Definition: decode.h:476
DetectEngineStateResetTxs
void DetectEngineStateResetTxs(Flow *f)
Reset de state for active tx' To be used on detect engine reload.
Definition: detect-engine-state.c:267
FLOWFILE_NO_MAGIC_TC
#define FLOWFILE_NO_MAGIC_TC
Definition: flow.h:125
TH_SYN
#define TH_SYN
Definition: decode-tcp.h:35
flags
uint8_t flags
Definition: decode-gre.h:0
Signature_::proto
DetectProto proto
Definition: detect.h:615
SigGroupHead_::non_pf_other_store_array
SignatureNonPrefilterStore * non_pf_other_store_array
Definition: detect.h:1461
FLOW_TOCLIENT_IPONLY_SET
#define FLOW_TOCLIENT_IPONLY_SET
Definition: flow.h:59
suricata-common.h
SIG_FLAG_SP_ANY
#define SIG_FLAG_SP_ANY
Definition: detect.h:240
APP_LAYER_TX_RESERVED_FLAGS
#define APP_LAYER_TX_RESERVED_FLAGS
Definition: app-layer-parser.h:69
Packet_::tcph
TCPHdr * tcph
Definition: decode.h:567
SigGroupHead_::non_pf_other_store_cnt
uint32_t non_pf_other_store_cnt
Definition: detect.h:1459
packet.h
DeStateStore_
Definition: detect-engine-state.h:77
sigmatch_table
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
Definition: detect-parse.c:127
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
DetectTransaction_
Definition: detect-engine-prefilter.h:31
Packet_::app_update_direction
uint8_t app_update_direction
Definition: decode.h:471
PROF_DETECT_SETUP
@ PROF_DETECT_SETUP
Definition: suricata-common.h:440
DetectEngineStateDirection_
Definition: detect-engine-state.h:82
DetectEngineThreadCtx_::frame_inspect_progress
uint64_t frame_inspect_progress
Definition: detect.h:1180
DetectEngineCtx_::profile_match_logging_threshold
uint32_t profile_match_logging_threshold
Definition: detect.h:960
FLOW_TS_APP_UPDATED
#define FLOW_TS_APP_UPDATED
Definition: flow.h:116
AppLayerParserGetTxData
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:1178
FatalError
#define FatalError(...)
Definition: util-debug.h:502
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:295
FLOWFILE_NO_STORE_TC
#define FLOWFILE_NO_STORE_TC
Definition: flow.h:129
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
DetectEngineThreadCtx_::non_pf_id_array
SigIntId * non_pf_id_array
Definition: detect.h:1107
DetectEngineAppInspectionEngine_::progress
int16_t progress
Definition: detect.h:435
PKT_IS_ICMPV4
#define PKT_IS_ICMPV4(p)
Definition: decode.h:250
util-validate.h
DetectTransaction_::tx_ptr
void * tx_ptr
Definition: detect-engine-prefilter.h:32
Signature_::addr_src_match6_cnt
uint16_t addr_src_match6_cnt
Definition: detect.h:624
StreamReassembleRawUpdateProgress
void StreamReassembleRawUpdateProgress(TcpSession *ssn, Packet *p, const uint64_t progress)
update stream engine after detection
Definition: stream-tcp-reassemble.c:1506
StatsAddUI64
void StatsAddUI64(ThreadVars *tv, uint16_t id, uint64_t x)
Adds a value of type uint64_t to the local counter.
Definition: counters.c:146
FLOWFILE_NO_SHA1_TS
#define FLOWFILE_NO_SHA1_TS
Definition: flow.h:135
PROF_DETECT_RULES
@ PROF_DETECT_RULES
Definition: suricata-common.h:443
DetectRunScratchpad::app_decoder_events
const bool app_decoder_events
Definition: detect.c:73
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:294
PROF_DETECT_NONMPMLIST
@ PROF_DETECT_NONMPMLIST
Definition: suricata-common.h:451
Signature_::dp
DetectPort * dp
Definition: detect.h:637
PacketAlerts_::suppressed
uint16_t suppressed
Definition: decode.h:292
PACKET_PROFILING_DETECT_START
#define PACKET_PROFILING_DETECT_START(p, id)
Definition: util-profiling.h:215
PACKET_ALERT_FLAG_FRAME
#define PACKET_ALERT_FLAG_FRAME
Definition: decode.h:284
DetectEngineThreadCtx_::non_pf_store_cnt
uint32_t non_pf_store_cnt
Definition: detect.h:1201
FLOW_SGH_TOSERVER
#define FLOW_SGH_TOSERVER
Definition: flow.h:70
DetectEngineThreadCtx_::counter_alerts
uint16_t counter_alerts
Definition: detect.h:1145
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:592
SGH_PROFILING_RECORD
#define SGH_PROFILING_RECORD(det_ctx, sgh)
Definition: util-profiling.h:253
PacketAlertFinalize
void PacketAlertFinalize(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
Check the threshold of the sigs that match, set actions, break on pass action This function iterate t...
Definition: detect-engine-alert.c:372
Signature_::addr_dst_match6
DetectMatchAddressIPv6 * addr_dst_match6
Definition: detect.h:628
Flow_::alstate
void * alstate
Definition: flow.h:476
Signature_::id
uint32_t id
Definition: detect.h:631
DeStateStore_::store
DeStateStoreItem store[DE_STATE_CHUNK_SIZE]
Definition: detect-engine-state.h:78
Flow_::flags
uint32_t flags
Definition: flow.h:421
RuleMatchCandidateTx::stream_reset
uint32_t stream_reset
Definition: detect.h:1086
detect-engine-iponly.h
Signature_
Signature container.
Definition: detect.h:596
IP_GET_IPPROTO
#define IP_GET_IPPROTO(p)
Definition: decode.h:258
InspectionBufferClean
void InspectionBufferClean(DetectEngineThreadCtx *det_ctx)
Definition: detect-engine.c:1451
SignatureMask
#define SignatureMask
Definition: detect.h:309
ALPROTO_UNKNOWN
@ ALPROTO_UNKNOWN
Definition: app-layer-protos.h:29
TRACE_SID_TXS
#define TRACE_SID_TXS(sid, txs,...)
Definition: detect.c:1052
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:225
DetectEngineThreadCtx_::tx_id_set
bool tx_id_set
Definition: detect.h:1176
STREAMTCP_FLAG_APP_LAYER_DISABLED
#define STREAMTCP_FLAG_APP_LAYER_DISABLED
Definition: stream-tcp-private.h:201
DetectRunScratchpad::flow_flags
const uint8_t flow_flags
Definition: detect.c:72
DetectEngineThreadCtx_::de_ctx
DetectEngineCtx * de_ctx
Definition: detect.h:1219
suricata.h
IPOnlyMatchPacket
void IPOnlyMatchPacket(ThreadVars *tv, const DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, const DetectEngineIPOnlyCtx *io_ctx, Packet *p)
Match a packet against the IP Only detection engine contexts.
Definition: detect-engine-iponly.c:1004
DetectEngineCtx_::sig_array
Signature ** sig_array
Definition: detect.h:856
Packet_::dst
Address dst
Definition: decode.h:442
SigGroupHead_::non_pf_syn_store_array
SignatureNonPrefilterStore * non_pf_syn_store_array
Definition: detect.h:1463
PROF_DETECT_TX
@ PROF_DETECT_TX
Definition: suricata-common.h:444
DetectEngineAppInspectionEngine_::dir
uint8_t dir
Definition: detect.h:429
PKT_NOPACKET_INSPECTION
#define PKT_NOPACKET_INSPECTION
Definition: decode.h:1006
SignatureNonPrefilterStore_::mask
SignatureMask mask
Definition: detect.h:1073
DetectRunScratchpad::alproto
const AppProto alproto
Definition: detect.c:71
DE_STATE_FLAG_FULL_INSPECT
#define DE_STATE_FLAG_FULL_INSPECT
Definition: detect-engine-state.h:55
STREAMTCP_STREAM_FLAG_DISABLE_RAW
#define STREAMTCP_STREAM_FLAG_DISABLE_RAW
Definition: stream-tcp-private.h:238
DetectEngineThreadCtx_::mt_det_ctxs_cnt
uint32_t mt_det_ctxs_cnt
Definition: detect.h:1110
AppLayerGetTxIteratorFunc
AppLayerGetTxIterTuple(* AppLayerGetTxIteratorFunc)(const uint8_t ipproto, const AppProto alproto, void *alstate, uint64_t min_tx_id, uint64_t max_tx_id, AppLayerGetTxIterState *state)
tx iterator prototype
Definition: app-layer-parser.h:153
likely
#define likely(expr)
Definition: util-optimize.h:32
IPPROTO_SCTP
#define IPPROTO_SCTP
Definition: decode.h:948
DE_STATE_FLAG_FILE_INSPECT
#define DE_STATE_FLAG_FILE_INSPECT
Definition: detect-engine-state.h:60
FLOW_NOPACKET_INSPECTION
#define FLOW_NOPACKET_INSPECTION
Definition: flow.h:62
DetectEngineCtx_::io_ctx
DetectEngineIPOnlyCtx io_ctx
Definition: detect.h:880
SC_ATOMIC_GET
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
Definition: util-atomic.h:375
Signature_::addr_dst_match4
DetectMatchAddressIPv4 * addr_dst_match4
Definition: detect.h:625
FlowGetDisruptionFlags
uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags)
get 'disruption' flags: GAP/DEPTH/PASS
Definition: flow.c:1132
TcpSession_
Definition: stream-tcp-private.h:283
flow.h
Signature_::addr_src_match4_cnt
uint16_t addr_src_match4_cnt
Definition: detect.h:622
SigIntId
#define SigIntId
Definition: suricata-common.h:315
DeStateStoreItem_
Definition: detect-engine-state.h:72
GenericVarFree
void GenericVarFree(GenericVar *gv)
Definition: util-var.c:47
Signature_::addr_dst_match4_cnt
uint16_t addr_dst_match4_cnt
Definition: detect.h:621
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:450
Packet_::dp
Port dp
Definition: decode.h:452
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SIG_GROUP_HEAD_HAVEFILESHA256
#define SIG_GROUP_HEAD_HAVEFILESHA256
Definition: detect.h:1329
SigGroupHead_::filestore_cnt
uint16_t filestore_cnt
Definition: detect.h:1454
AppLayerParserGetTxCnt
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
Definition: app-layer-parser.c:1101
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:246
PACKET_ALERT_FLAG_STATE_MATCH
#define PACKET_ALERT_FLAG_STATE_MATCH
Definition: decode.h:276
AppLayerParserHasDecoderEvents
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
Definition: app-layer-parser.c:1512
DetectEngineLookupFlow_::tcp
DetectPort * tcp
Definition: detect.h:775
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:103
DetectTransaction_::detect_flags
const uint64_t detect_flags
Definition: detect-engine-prefilter.h:36
detect-engine-address.h
Flow_::tenant_id
uint32_t tenant_id
Definition: flow.h:416
Packet_::src
Address src
Definition: decode.h:441
DetectEngineThreadCtx_::counter_mpm_list
uint16_t counter_mpm_list
Definition: detect.h:1151
SigMatchSignaturesGetSgh
const SigGroupHead * SigMatchSignaturesGetSgh(const DetectEngineCtx *de_ctx, const Packet *p)
Get the SigGroupHead for a packet.
Definition: detect.c:215
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:93
RuleMatchCandidateTxArrayInit
void RuleMatchCandidateTxArrayInit(DetectEngineThreadCtx *det_ctx, uint32_t size)
Definition: detect.c:976
SIG_FLAG_DP_ANY
#define SIG_FLAG_DP_ANY
Definition: detect.h:241
DetectPortLookupGroup
DetectPort * DetectPortLookupGroup(DetectPort *dp, uint16_t port)
Function that find the group matching port in a group head.
Definition: detect-engine-port.c:613
PKT_STREAM_EST
#define PKT_STREAM_EST
Definition: decode.h:1019
detect-engine-threshold.h
Signature_::mask
SignatureMask mask
Definition: detect.h:607
app-layer.h
RuleMatchCandidateTx
Definition: detect.h:1078
DetectEngineThreadCtx_::TenantGetId
uint32_t(* TenantGetId)(const void *, const Packet *p)
Definition: detect.h:1117
PrefilterRuleStore_::rule_id_array
SigIntId * rule_id_array
Definition: util-prefilter.h:38
PacketEngineEvents_::cnt
uint8_t cnt
Definition: decode.h:309
Flow_::de_ctx_version
uint32_t de_ctx_version
Definition: flow.h:464
DetectProtoContainsProto
int DetectProtoContainsProto(const DetectProto *dp, int proto)
see if a DetectProto contains a certain proto
Definition: detect-engine-proto.c:135
DetectEngineThreadCtx_::match_array
Signature ** match_array
Definition: detect.h:1190