88 static inline uint8_t DetectRulePacketRules(
ThreadVars *
const tv,
123 DetectRunInspectIPOnly(
th_v,
de_ctx, det_ctx, pflow,
p);
126 DetectRunGetRuleGroup(
de_ctx,
p, pflow, &scratch);
129 if (scratch.
sgh == NULL) {
131 SCLogDebug(
"no sgh for this packet, nothing to match against");
135 "packet %" PRIu64
": no sgh, need to apply default policies",
PcapPacketCntGet(
p));
138 DetectRunPrefilterPkt(
th_v,
de_ctx, det_ctx,
p, &scratch);
142 const uint8_t pkt_policy = DetectRulePacketRules(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
160 if (
p->
proto == IPPROTO_TCP) {
164 SCLogDebug(
"default accept: no PKT_STREAM_EST");
165 DetectRunAppendDefaultAccept(det_ctx,
p);
178 DetectRunFrames(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
188 DetectRunAppendDefaultAccept(det_ctx,
p);
192 }
else if (
p->
proto == IPPROTO_UDP) {
193 DetectRunFrames(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
197 DetectRunTx(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
208 DetectRunAppendDefaultAccept(det_ctx,
p);
213 DetectRunPostRules(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
215 DetectRunCleanup(det_ctx,
p, pflow);
240 if (scratch.
sgh == NULL) {
241 SCLogDebug(
"no sgh for this packet, nothing to match against");
246 DetectRunPrefilterPkt(
th_v,
de_ctx, det_ctx,
p, &scratch);
250 const uint8_t pkt_policy = DetectRulePacketRules(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
257 DetectRunPostRules(
th_v,
de_ctx, det_ctx,
p, pflow, &scratch);
259 DetectRunCleanup(det_ctx,
p, pflow);
272 SCLogDebug(
"running match functions, sm %p", smd);
309 }
else if (
p->
proto == 0) {
310 if (!(PacketIsIPv4(
p) || PacketIsIPv6(
p))) {
319 int proto = PacketGetIPProto(
p);
320 if (
proto == IPPROTO_TCP) {
324 const uint16_t port = dir ?
p->
dp :
p->
sp;
329 SCLogDebug(
"TCP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
330 dir ?
"toserver" :
"toclient", sghport, sgh);
331 }
else if (
proto == IPPROTO_UDP) {
333 uint16_t port = dir ?
p->
dp :
p->
sp;
337 SCLogDebug(
"UDP list %p, port %u, direction %s, sghport %p, sgh %p", list, port,
338 dir ?
"toserver" :
"toclient", sghport, sgh);
346 static inline void DetectPrefilterCopyDeDup(
354 while (final_cnt-- > 0) {
359 if (
likely(
id != previous_id)) {
376 DetectPostInspectFileFlagsUpdate(
Flow *f,
const SigGroupHead *sgh, uint8_t direction)
381 SCLogDebug(
"requesting disabling all file features for flow");
385 SCLogDebug(
"requesting disabling filestore for flow");
386 flow_file_flags |= (FLOWFILE_NO_STORE_TS|FLOWFILE_NO_STORE_TC);
389 if (!(sgh->
flags & SIG_GROUP_HEAD_HAVEFILEMAGIC)) {
390 SCLogDebug(
"requesting disabling magic for flow");
395 SCLogDebug(
"requesting disabling md5 for flow");
399 SCLogDebug(
"requesting disabling sha1 for flow");
403 SCLogDebug(
"requesting disabling sha256 for flow");
407 if (flow_file_flags != 0) {
423 SCLogDebug(
"STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.client");
428 DetectPostInspectFileFlagsUpdate(pflow,
438 SCLogDebug(
"STREAMTCP_STREAM_FLAG_DISABLE_RAW ssn.server");
443 DetectPostInspectFileFlagsUpdate(pflow,
448 static inline void DetectRunGetRuleGroup(
456 bool use_flow_sgh =
false;
459 if (PacketGetIPProto(
p) == pflow->
proto) {
463 SCLogDebug(
"sgh = pflow->sgh_toserver; => %p", sgh);
467 SCLogDebug(
"sgh = pflow->sgh_toclient; => %p", sgh);
473 if (!(use_flow_sgh)) {
486 DetectRunPostGetFirstRuleGroup(
p, pflow, sgh);
506 SCLogDebug(
"testing against \"ip-only\" signatures");
525 static inline bool DetectRunInspectRuleHeader(
535 const bool fv = f->
flowvar != NULL;
537 SCLogDebug(
"skipping sig as the flow has no flowvars and sig "
538 "has SIG_FLAG_REQUIRE_FLOWVAR flag set.");
543 if (!(s->
proto == NULL)) {
544 const uint8_t s_proto_flags = s->
proto->
flags;
556 if (PacketIsEthernet(
p) &&
590 SCLogDebug(
"port-less protocol and sig needs ports");
596 if (PacketIsIPv4(
p)) {
599 }
else if (PacketIsIPv6(
p)) {
606 if (PacketIsIPv4(
p)) {
609 }
else if (PacketIsIPv6(
p)) {
637 DetectPrefilterCopyDeDup(
de_ctx, det_ctx);
652 static bool IsOnlyTxInDirection(
Flow *f, uint64_t txid, uint8_t dir)
655 if (tx_cnt == txid + 1) {
659 if (tx_cnt == txid + 2) {
665 if ((dir == STREAM_TOSERVER && (txd->
flags & APP_LAYER_TX_SKIP_INSPECT_TS)) ||
666 (dir == STREAM_TOCLIENT && (txd->
flags & APP_LAYER_TX_SKIP_INSPECT_TC))) {
674 static int SortHelper(
const void *a,
const void *b)
680 return sa->
iid > sb->
iid ? 1 : -1;
683 static inline bool SkipFwRules(
const Packet *
p)
685 if (
p->
flow != NULL) {
710 SCLogDebug(
"packet %" PRIu64
": drop PKT_DROP_REASON_FW_DEFAULT_PACKET_POLICY",
722 SCLogDebug(
"packet %" PRIu64
": accept scope hook upgraded to packet",
752 const uint8_t alert_flags_in)
768 uint8_t alert_flags = alert_flags_in;
769 if (f->
proto != IPPROTO_UDP) {
781 static inline uint8_t DetectRulePacketRules(
ThreadVars *
const tv,
786 bool fw_verdict =
false;
806 bool skip_fw = SkipFwRules(
p);
807 uint32_t sflags, next_sflags = 0;
809 next_s = *match_array++;
810 next_sflags = next_s->
flags;
812 while (match_cnt--) {
814 bool break_out_of_packet_filter =
false;
815 uint8_t alert_flags = 0;
820 sflags = next_sflags;
822 next_s = *match_array++;
823 next_sflags = next_s->
flags;
835 }
else if (have_fw_rules) {
842 break_out_of_packet_filter =
true;
865 if (SigDsizePrefilter(
p, s, sflags))
876 if (DetectRunInspectRuleHeader(
p, pflow, s, sflags) ==
false) {
887 DetectRunPostMatch(
tv, det_ctx,
p, s);
889 DetectRulePacketAppendAlert(
de_ctx, det_ctx, s,
p, pflow, alert_flags);
898 SCLogDebug(
"sig_array_len %u det_ctx->pmq.rule_id_array_cnt %u",
901 for (uint32_t x = 0; x < match_cnt; x++) {
902 *r++ = match_array[x];
903 SCLogDebug(
"appended %u", match_array[x]->
id);
910 if (
ts->app_inspect == NULL) {
922 uint32_t skipped = 0;
923 for (uint32_t x = 0; x < match_cnt; x++) {
925 if (last_sig == *
m) {
932 match_cnt -= skipped;
934 next_s = *match_array++;
935 next_sflags = next_s->
flags;
982 break_out_of_packet_filter =
true;
986 DetectVarProcessList(det_ctx, pflow,
p);
987 DetectReplaceFree(det_ctx);
991 if (break_out_of_packet_filter)
1000 if (have_fw_rules) {
1001 if (skip_fw || fw_verdict) {
1021 uint8_t flow_flags = 0;
1022 bool app_decoder_events =
false;
1045 det_ctx->pkt_stream_add_cnt++;
1054 flow_flags = STREAM_TOSERVER;
1057 flow_flags = STREAM_TOCLIENT;
1063 flow_flags |= STREAM_EOF;
1094 (
p->
proto == IPPROTO_UDP) ||
1106 SCLogDebug(
"packet doesn't have established flag set (proto %d)",
p->
proto);
1149 SCLogDebug(
"packet %" PRIu64
": default action as no verdict set %02x (pkt %s)",
1162 if (pflow != NULL) {
1185 FatalError(
"failed to allocate %" PRIu64
" bytes",
1189 SCLogDebug(
"array initialized to %u elements (%"PRIu64
" bytes)",
1201 const uint32_t need)
1212 uint32_t new_size = needed;
1215 FatalError(
"failed to expand to %" PRIu64
" bytes",
1221 SCLogDebug(
"array expanded from %u to %u elements (%"PRIu64
" bytes -> %"PRIu64
" bytes)",
1234 DetectRunTxSortHelper(
const void *a,
const void *b)
1238 if (s1->
id == s0->
id) {
1245 return s0->
id > s1->
id ? 1 : -1;
1249 #define TRACE_SID_TXS(sid,txs,...) \
1251 char _trace_buf[2048]; \
1252 snprintf(_trace_buf, sizeof(_trace_buf), __VA_ARGS__); \
1253 SCLogNotice("%p/%"PRIu64"/%u: %s", txs->tx_ptr, txs->tx_id, sid, _trace_buf); \
1256 #define TRACE_SID_TXS(sid,txs,...)
1268 SCLogDebug(
"pre: tx_ptr %p flow::alproto %s engine::alproto %s", tx_ptr,
1271 switch (engine_alproto) {
1274 tx_ptr = SCDoH2GetDnsTx(tx_ptr, flow_flags);
1285 }
else if (engine_alproto != alproto && engine_alproto !=
ALPROTO_UNKNOWN) {
1308 const uint8_t in_flow_flags,
1312 const uint8_t flow_flags = in_flow_flags;
1313 const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1314 uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
1315 int total_matches = 0;
1316 uint16_t file_no_match = 0;
1317 bool mpm_before_progress =
false;
1318 bool mpm_in_progress =
false;
1320 TRACE_SID_TXS(s->
id, tx,
"starting %s", direction ?
"toclient" :
"toserver");
1323 if (
likely(stored_flags == NULL)) {
1325 if (DetectRunInspectRuleHeader(
p, f, s, s->
flags) ==
false) {
1339 TRACE_SID_TXS(s->
id, tx,
"continue, inspect_flags %x", inspect_flags);
1344 TRACE_SID_TXS(s->
id, tx,
"engine %p inspect_flags %x", engine, inspect_flags);
1348 if (!(inspect_flags &
BIT_U32(engine->
id)) &&
1360 "skip because engine alproto %s sub_state %u != tx_type %u (engine "
1364 engine = engine->
next;
1368 "inspecting engine alproto %s sub_state %u == tx_type %u (engine progress %u)",
1373 if (tx_ptr == NULL) {
1379 engine = engine->
next;
1390 SCLogDebug(
"tx progress %d < engine progress %d",
1397 "engine->mpm: t->tx_progress %u > engine->progress %u, so set "
1398 "mpm_before_progress",
1400 mpm_before_progress =
true;
1403 "engine->mpm: t->tx_progress %u == engine->progress %u, so set "
1407 mpm_in_progress =
true;
1412 uint8_t engine_flags = flow_flags;
1413 if (direction != engine->
dir) {
1414 engine_flags = flow_flags ^ (STREAM_TOCLIENT | STREAM_TOSERVER);
1420 TRACE_SID_TXS(s->
id, tx,
"stream skipped, stored result %d used instead", match);
1425 mpm_before_progress =
true;
1440 de_ctx, det_ctx, engine, s, f, engine_flags, alstate, tx_ptr, tx->
tx_id);
1445 TRACE_SID_TXS(s->
id, tx,
"stream ran, store result %d for next tx (if any)", match);
1450 engine = engine->
next;
1457 engine = engine->
next;
1469 if (engine->
mpm && mpm_before_progress) {
1475 direction != engine->
dir) {
1481 if (direction == 0 && engine->
next == NULL) {
1485 engine = engine->
next;
1489 engine = engine->
next;
1490 }
while (engine != NULL);
1491 TRACE_SID_TXS(s->
id, tx,
"inspect_flags %x, total_matches %u, engine %p",
1492 inspect_flags, total_matches, engine);
1494 bool full_match =
false;
1495 if (engine == NULL && total_matches) {
1502 *stored_flags = inspect_flags;
1503 TRACE_SID_TXS(s->
id, tx,
"continue inspect flags %08x", inspect_flags);
1510 if (file_no_match) {
1521 inspect_flags, flow_flags, file_no_match);
1525 "mpm won't trigger for it anymore");
1529 "we may have to revisit anyway");
1531 inspect_flags, flow_flags, file_no_match);
1535 "mpm will revisit it");
1537 }
else if (inspect_flags != 0 || file_no_match != 0) {
1540 inspect_flags, flow_flags, file_no_match);
1542 if (inspect_flags == 0) {
1543 TRACE_SID_TXS(s->
id, tx,
"no match: inspect_flags %08x", inspect_flags);
1561 NULL, 0, NULL, NULL, 0, 0, 0, 0, false, 0, \
1569 const uint64_t tx_id,
void *tx_ptr,
const int tx_end_state,
const uint8_t flow_flags)
1574 const uint8_t tx_progress =
1578 const uint8_t e_tx_end_state = txd->
tx_type == 0 ? (uint8_t)tx_end_state
1583 if (!updated && tx_progress < e_tx_end_state && ((flow_flags & STREAM_EOF) == 0)) {
1587 const uint8_t inspected_flag =
1590 SCLogDebug(
"%" PRIu64
" tx already fully inspected for %s. Flags %02x", tx_id,
1591 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1595 const uint8_t skip_flag = (flow_flags & STREAM_TOSERVER) ? APP_LAYER_TX_SKIP_INSPECT_TS
1596 : APP_LAYER_TX_SKIP_INSPECT_TC;
1598 SCLogDebug(
"%" PRIu64
" tx should not be inspected in direction %s. Flags %02x", tx_id,
1599 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1608 const uint8_t detect_progress =
1611 const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1614 tx_de_state ? &tx_de_state->
dir_state[dir_int] : NULL;
1620 .detect_progress = detect_progress,
1621 .detect_progress_orig = detect_progress,
1622 .tx_progress = (uint8_t)tx_progress,
1623 .tx_end_state = e_tx_end_state,
1630 static inline void StoreDetectProgress(
1634 if (flow_flags & STREAM_TOSERVER) {
1643 static inline void RuleMatchCandidateMergeStateRules(
1661 uint32_t j = *array_idx;
1670 uint32_t k = *array_idx;
1692 if (s->
iid <= s0->
id) {
1749 const uint8_t progress)
1751 const uint8_t dir_flags = direction & (STREAM_TOSERVER | STREAM_TOCLIENT);
1766 if (
likely(ap != NULL)) {
1772 SCLogDebug(
"dropping packet PKT_DROP_REASON_FW_DEFAULT_APP_POLICY");
1780 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p,
true, tx, ap);
1788 const bool last_hook =
progress == tx->tx_progress;
1789 bool apply_to_packet =
false;
1794 apply_to_packet =
true;
1798 apply_to_packet = tx->is_last;
1801 apply_to_packet = tx->is_last && last_hook;
1808 SCLogDebug(
"packet %" PRIu64
" hook %u default policy ACCEPT, apply_to_packet:%s",
1813 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p, apply_to_packet, tx, ap);
1814 }
else if (apply_to_packet) {
1816 DetectRunAppendDefaultAccept(det_ctx,
p);
1840 const uint8_t start_hook,
const uint8_t end_hook)
1844 const bool need_verdict =
1846 SCLogDebug(
"need_verdict:%s is_last:%s end_hook:%u tx->tx_end_state:%u tx->progress: %u",
1850 for (uint8_t hook = start_hook; hook <= end_hook; hook++) {
1851 const bool apply_to_packet =
1854 SCLogDebug(
"%" PRIu64
": %s default policy for hook %u, apply_to_packet %s",
1859 det_ctx, policies, tx,
p, alproto, direction, hook);
1860 SCLogDebug(
"fw: hook:%u policy:%02x apply_to_packet:%s", hook, policy.
action,
1880 if (apply_to_packet) {
1895 SCLogDebug(
"default accept: last tx and progress at end_hook %u", end_hook);
1896 DetectRunAppendDefaultAccept(det_ctx,
p);
1935 SCLogDebug(
"default accept due to flow accept");
1936 DetectRunAppendDefaultAccept(det_ctx,
p);
1947 const bool accept_tx_applies_to_packet = tx->
is_last;
1948 if (accept_tx_applies_to_packet) {
1949 SCLogDebug(
"accept:tx: should be applied to the packet");
1950 DetectRunAppendDefaultAccept(det_ctx,
p);
1954 SCLogDebug(
"APP_LAYER_TX_ACCEPT, so skip rule");
1970 SCLogDebug(
"missing fw rules at list start: sid %u, progress %u (%u:%u)", s->
id,
2009 if (can_idx + 1 < can_size) {
2015 SCLogDebug(
"peek: next sid progress %u != current progress %u, so current "
2016 "is last for progress",
2021 SCLogDebug(
"peek: missing progress, so we'll drop that unless we get a "
2022 "sweeping accept first");
2027 SCLogDebug(
"peek: next sid not a fw rule, so current is last for progress");
2032 SCLogDebug(
"peek: no peek beyond last rule");
2034 SCLogDebug(
"peek: there are no rules to allow the state after this rule");
2125 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2126 "skip_before_progress:%u fw_last_for_progress:%s fw_next_progress_missing:%s",
2148 SCLogDebug(
"accept:tx applied, skip_fw_hook, skip_before_progress %u",
2153 SCLogDebug(
"sid %u: ACTION_ACCEPT with ACTION_SCOPE_FLOW", s->
id);
2174 if (rule_cnt == 0) {
2177 DetectRunAppendDefaultAccept(det_ctx,
p);
2184 DetectRunAppendDefaultAccept(det_ctx,
p);
2201 alproto, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT),
2225 const uint8_t flow_flags)
2234 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2235 if (fw_accept_to_packet) {
2237 SCLogDebug(
"accept:(tx|hook): should be applied to the packet");
2243 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2245 SCLogDebug(
"drop packet because of rule with drop action");
2248 SCLogDebug(
"drop flow because of rule with drop action");
2271 static int DetectRunTxFirewallRulePartialMatch(
2278 SCLogDebug(
"need to apply accept to packet");
2279 DetectRunAppendDefaultAccept(det_ctx,
p);
2282 SCLogDebug(
"only applying accept:flow on full match, downgrading to "
2303 const uint8_t flow_flags)
2330 Packet *
p,
const uint8_t flow_flags)
2336 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2337 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2338 if (fw_accept_to_packet) {
2340 DetectRunAppendDefaultAccept(det_ctx,
p);
2352 const uint8_t flow_flags = scratch->
flow_flags;
2354 void *
const alstate = f->
alstate;
2355 const uint8_t ipproto = f->
proto;
2365 uint32_t tx_inspected = 0;
2369 bool last_tx_skipped =
false;
2376 if (ires.
tx_ptr == NULL) {
2377 SCLogDebug(
"%p/%" PRIu64
" no transaction to inspect", ires.
tx_ptr, tx_id_min);
2382 GetDetectTx(ipproto, alproto, ires.
tx_id, ires.
tx_ptr, tx_end_state, flow_flags);
2384 SCLogDebug(
"%p/%"PRIu64
" no transaction to inspect",
2391 tx_id_min = tx.
tx_id + 1;
2401 bool do_sort =
false;
2402 uint32_t array_idx = 0;
2412 SCLogDebug(
"%p/%"PRIu64
" rules added from prefilter: %u candidates",
2416 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2417 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2431 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2432 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2438 uint32_t x = array_idx;
2440 RuleMatchCandidateMergeStateRules(det_ctx, &array_idx);
2444 const uint32_t old = array_idx;
2449 if (have_new_file) {
2450 SCLogDebug(
"%p/%"PRIu64
" destate: need to consider new file",
2457 for (; tx_store != NULL; tx_store = tx_store->
next) {
2463 store_cnt++, state_cnt++)
2480 do_sort |= (old && old != array_idx);
2486 DetectRunTxSortHelper);
2495 for (uint32_t i = 0; i < array_idx; i++) {
2511 SCLogDebug(
"%s: tx_progress %u tx %p have_fw_rules %s array_idx %u detect_progress_orig %u "
2512 "cur detect_progress %u",
2513 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2517 if (have_fw_rules) {
2520 const int r = DetectTxFirewallNoRulesApplyPolicies(
2521 det_ctx,
p, f, &tx, alproto, flow_flags, array_idx);
2525 }
else if (r == 2) {
2531 for (uint32_t i = 0; i < array_idx; i++) {
2537 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2540 if (have_fw_rules) {
2542 DetectRunTxPreCheckFirewallPolicy(det_ctx,
p, &tx,
2543 flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT), s, i, &fw_state);
2544 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2545 "skip_before_progress:%u fw_last_for_progress:%s "
2546 "fw_next_progress_missing:%s",
2565 while ((i + 1) < array_idx &&
2567 SCLogDebug(
"%p/%" PRIu64
" inspecting SKIP NEXT: sid %u (%u), flags %08x",
2573 s->
id, s->
iid, inspect_flags ? *inspect_flags : 0);
2575 if (inspect_flags) {
2578 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_FULL_INSPECT",
2583 if (have_fw_rules) {
2584 DetectRunTxFirewallRuleStatefulReApplyMatch(
2585 det_ctx, s, &tx, &fw_state,
p, flow_flags);
2591 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_SIG_CANT_MATCH",
2603 if (have_fw_rules) {
2606 DetectRunTxCheckRuleState(det_ctx,
p, f, &tx, s, i, array_idx, &fw_state);
2607 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2608 "skip_before_progress:%u fw_last_for_progress:%s "
2609 "fw_next_progress_missing:%s",
2621 const int r = DetectRunTxInspectRule(
tv,
de_ctx, det_ctx,
p, f, flow_flags,
2622 alstate, &tx, s, inspect_flags, can, scratch);
2626 DetectRunPostMatch(
tv, det_ctx,
p, s);
2634 DetectRunTxFirewallRuleFullMatch(det_ctx, s, &tx, &fw_state, f,
p, flow_flags);
2636 }
else if (r == 0) {
2638 if (DetectRunTxFirewallRulePartialMatch(det_ctx, s, &tx,
p) == 1) {
2642 if (DetectRunTxFirewallRuleNoMatch(det_ctx, s, &tx, &fw_state,
p, flow_flags) ==
2647 DetectVarProcessList(det_ctx,
p->
flow,
p);
2656 uint32_t prev_array_idx = array_idx;
2659 if (
ts->app_inspect != NULL) {
2667 SCLogDebug(
"%p/%" PRIu64
" rule %u (%u) added from 'post match' prefilter",
2671 SCLogDebug(
"%p/%" PRIu64
" rules added from 'post match' prefilter: %u", tx.
tx_ptr,
2672 tx.
tx_id, array_idx - prev_array_idx);
2673 if (prev_array_idx != array_idx) {
2676 DetectRunTxSortHelper);
2692 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient");
2693 const uint8_t inspected_flag = (flow_flags & STREAM_TOSERVER)
2697 SCLogDebug(
"%p/%" PRIu64
" tx is done for direction %s. Progress %02x", tx.
tx_ptr,
2698 tx.
tx_id, flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
2720 if (have_fw_rules) {
2721 if (tx_inspected == 0) {
2723 SCLogDebug(
"default accept: no app inspect performed");
2724 DetectRunAppendDefaultAccept(det_ctx,
p);
2725 }
else if (last_tx_skipped) {
2729 SCLogDebug(
"default accept: last tx skipped");
2730 DetectRunAppendDefaultAccept(det_ctx,
p);
2746 SCLogDebug(
"pcap_cnt %" PRIu64
": %s: skip frame inspection for TCP w/o APP UPDATE",
2751 if (frames_container == NULL) {
2756 frames = &frames_container->
toserver;
2758 frames = &frames_container->
toclient;
2761 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
2764 if (frame == NULL) {
2769 uint32_t array_idx = 0;
2777 SCLogDebug(
"%p/%" PRIi64
" rules added from prefilter: %u candidates", frame, frame->
id,
2782 if (!(RuleMatchCandidateTxArrayHasSpace(
2783 det_ctx, total_rules))) {
2784 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2799 uint32_t x = array_idx;
2810 SCLogDebug(
"%p/%" PRIi64
" rule %u (%u) added from 'match' list", frame, frame->
id,
2814 SCLogDebug(
"%p/%" PRIi64
" rules added from 'match' list: %u", frame, frame->
id,
2819 for (uint32_t i = 0; i < array_idx; i++) {
2826 while ((i + 1) < array_idx &&
2830 SCLogDebug(
"%p/%" PRIi64
" inspecting: sid %u (%u)", frame, frame->
id, s->
id, s->
iid);
2833 SCLogDebug(
"%p/%" PRIi64
" Start sid %u", frame, frame->
id, s->
id);
2837 bool r = DetectRunInspectRuleHeader(
p, f, s, s->
flags);
2842 DetectRunPostMatch(
tv, det_ctx,
p, s);
2845 "%p/%" PRIi64
" sig %u (%u) matched", frame, frame->
id, s->
id, s->
iid);
2846 const uint8_t alert_flags =
2849 const uint8_t ipproto =
p->
proto;
2850 uint8_t sub_state = 0;
2863 DetectVarProcessList(det_ctx,
p->
flow,
p);
2874 "frame->inspect_progress: %" PRIu64
" -> not updated", frame->
inspect_progress);
2877 SCLogDebug(
"%p/%" PRIi64
" rules inspected, running cleanup", frame, frame->
id);
2925 SCLogDebug(
"p->pcap %" PRIu64
": no detection on packet, "
2926 "PKT_NOPACKET_INSPECTION is set",
2984 if (det_ctx == NULL) {
2985 printf(
"ERROR: Detect has no thread ctx\n");
2991 SCLogDebug(
"Detect Engine using new det_ctx - %p",
3002 if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
3005 if (det_ctx == NULL)
3013 SCLogDebug(
"MT de_ctx %p det_ctx %p (tenant %u)",
de_ctx, det_ctx, tenant_id);
3029 #ifdef PROFILE_RULES
3032 gettimeofday(&
ts, NULL);
3033 if (
ts.tv_sec != det_ctx->rule_perf_last_sync) {
3034 SCProfilingRuleThreatAggregate(det_ctx);
3035 det_ctx->rule_perf_last_sync =
ts.tv_sec;
3049 DetectPostInspectFileFlagsUpdate(f, NULL , STREAM_TOSERVER);
3050 DetectPostInspectFileFlagsUpdate(f, NULL , STREAM_TOCLIENT);
3053 #if defined(UNITTESTS) || defined(FUZZ)