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(
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",
726 SCLogDebug(
"packet %" PRIu64
": accept scope hook upgraded to packet",
756 const uint8_t alert_flags_in)
772 uint8_t alert_flags = alert_flags_in;
773 if (
f->
proto != IPPROTO_UDP) {
785 static inline uint8_t DetectRulePacketRules(
ThreadVars *
const tv,
790 bool fw_verdict =
false;
810 bool skip_fw = SkipFwRules(
p);
811 uint32_t sflags, next_sflags = 0;
813 next_s = *match_array++;
814 next_sflags = next_s->
flags;
816 while (match_cnt--) {
818 bool break_out_of_packet_filter =
false;
819 uint8_t alert_flags = 0;
824 sflags = next_sflags;
826 next_s = *match_array++;
827 next_sflags = next_s->
flags;
839 }
else if (have_fw_rules) {
846 break_out_of_packet_filter =
true;
869 if (SigDsizePrefilter(
p, s, sflags))
880 if (DetectRunInspectRuleHeader(
p, pflow, s, sflags) ==
false) {
891 DetectRunPostMatch(
tv, det_ctx,
p, s);
893 DetectRulePacketAppendAlert(
de_ctx, det_ctx, s,
p, pflow, alert_flags);
902 SCLogDebug(
"sig_array_len %u det_ctx->pmq.rule_id_array_cnt %u",
905 for (uint32_t x = 0; x < match_cnt; x++) {
906 *r++ = match_array[x];
907 SCLogDebug(
"appended %u", match_array[x]->
id);
914 if (
ts->app_inspect == NULL) {
926 uint32_t skipped = 0;
927 for (uint32_t x = 0; x < match_cnt; x++) {
929 if (last_sig == *
m) {
936 match_cnt -= skipped;
938 next_s = *match_array++;
939 next_sflags = next_s->
flags;
986 break_out_of_packet_filter =
true;
990 DetectVarProcessList(det_ctx, pflow,
p);
991 DetectReplaceFree(det_ctx);
995 if (break_out_of_packet_filter)
1004 if (have_fw_rules) {
1005 if (skip_fw || fw_verdict) {
1025 uint8_t flow_flags = 0;
1026 bool app_decoder_events =
false;
1049 det_ctx->pkt_stream_add_cnt++;
1058 flow_flags = STREAM_TOSERVER;
1061 flow_flags = STREAM_TOCLIENT;
1067 flow_flags |= STREAM_EOF;
1098 (
p->
proto == IPPROTO_UDP) ||
1110 SCLogDebug(
"packet doesn't have established flag set (proto %d)",
p->
proto);
1116 DetectRunScratchpad pad = { alproto, flow_flags, app_decoder_events, fw_pkt_policy, NULL };
1153 SCLogDebug(
"packet %" PRIu64
": default action as no verdict set %02x (pkt %s)",
1166 if (pflow != NULL) {
1189 FatalError(
"failed to allocate %" PRIu64
" bytes",
1193 SCLogDebug(
"array initialized to %u elements (%"PRIu64
" bytes)",
1205 const uint32_t need)
1216 uint32_t new_size = needed;
1219 FatalError(
"failed to expand to %" PRIu64
" bytes",
1225 SCLogDebug(
"array expanded from %u to %u elements (%"PRIu64
" bytes -> %"PRIu64
" bytes)",
1238 DetectRunTxSortHelper(
const void *a,
const void *b)
1242 if (s1->
id == s0->
id) {
1249 return s0->
id > s1->
id ? 1 : -1;
1253 #define TRACE_SID_TXS(sid,txs,...) \
1255 char _trace_buf[2048]; \
1256 snprintf(_trace_buf, sizeof(_trace_buf), __VA_ARGS__); \
1257 SCLogNotice("%p/%"PRIu64"/%u: %s", txs->tx_ptr, txs->tx_id, sid, _trace_buf); \
1260 #define TRACE_SID_TXS(sid,txs,...)
1272 SCLogDebug(
"pre: tx_ptr %p flow::alproto %s engine::alproto %s", tx_ptr,
1275 switch (engine_alproto) {
1278 tx_ptr = SCDoH2GetDnsTx(tx_ptr, flow_flags);
1289 }
else if (engine_alproto != alproto && engine_alproto !=
ALPROTO_UNKNOWN) {
1316 const uint8_t in_flow_flags,
1320 const uint8_t flow_flags = in_flow_flags;
1321 const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1322 uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
1323 int total_matches = 0;
1324 uint16_t file_no_match = 0;
1325 bool mpm_before_progress =
false;
1326 bool mpm_in_progress =
false;
1328 TRACE_SID_TXS(s->
id, tx,
"starting %s", direction ?
"toclient" :
"toserver");
1331 if (
likely(stored_flags == NULL)) {
1349 TRACE_SID_TXS(s->
id, tx,
"continue, inspect_flags %x", inspect_flags);
1354 TRACE_SID_TXS(s->
id, tx,
"engine %p inspect_flags %x", engine, inspect_flags);
1358 if (!(inspect_flags &
BIT_U32(engine->
id)) &&
1370 "skip because engine alproto %s sub_state %u != tx_type %u (engine "
1374 engine = engine->
next;
1378 "inspecting engine alproto %s sub_state %u == tx_type %u (engine progress %u)",
1383 if (tx_ptr == NULL) {
1389 engine = engine->
next;
1400 SCLogDebug(
"tx progress %d < engine progress %d",
1407 "engine->mpm: t->tx_progress %u > engine->progress %u, so set "
1408 "mpm_before_progress",
1410 mpm_before_progress =
true;
1413 "engine->mpm: t->tx_progress %u == engine->progress %u, so set "
1417 mpm_in_progress =
true;
1422 uint8_t engine_flags = flow_flags;
1423 if (direction != engine->
dir) {
1424 engine_flags = flow_flags ^ (STREAM_TOCLIENT | STREAM_TOSERVER);
1430 TRACE_SID_TXS(s->
id, tx,
"stream skipped, stored result %d used instead", match);
1435 mpm_before_progress =
true;
1450 de_ctx, det_ctx, engine, s,
f, engine_flags, alstate, tx_ptr, tx->
tx_id);
1455 TRACE_SID_TXS(s->
id, tx,
"stream ran, store result %d for next tx (if any)", match);
1460 engine = engine->
next;
1467 engine = engine->
next;
1479 if (engine->
mpm && mpm_before_progress) {
1485 direction != engine->
dir) {
1491 if (direction == 0 && engine->
next == NULL) {
1495 engine = engine->
next;
1499 engine = engine->
next;
1500 }
while (engine != NULL);
1501 TRACE_SID_TXS(s->
id, tx,
"inspect_flags %x, total_matches %u, engine %p",
1502 inspect_flags, total_matches, engine);
1504 bool full_match =
false;
1505 if (engine == NULL && total_matches) {
1512 *stored_flags = inspect_flags;
1513 TRACE_SID_TXS(s->
id, tx,
"continue inspect flags %08x", inspect_flags);
1520 if (file_no_match) {
1531 inspect_flags, flow_flags, file_no_match);
1535 "mpm won't trigger for it anymore");
1539 "we may have to revisit anyway");
1541 inspect_flags, flow_flags, file_no_match);
1545 "mpm will revisit it");
1547 }
else if (inspect_flags != 0 || file_no_match != 0) {
1550 inspect_flags, flow_flags, file_no_match);
1552 if (inspect_flags == 0) {
1553 TRACE_SID_TXS(s->
id, tx,
"no match: inspect_flags %08x", inspect_flags);
1571 NULL, 0, NULL, NULL, 0, 0, 0, 0, false, 0, \
1579 const uint64_t tx_id,
void *tx_ptr,
const uint8_t flow_flags)
1582 const uint8_t tx_progress =
1586 const uint8_t e_tx_end_state =
1591 if (!updated && tx_progress < e_tx_end_state && ((flow_flags & STREAM_EOF) == 0)) {
1595 const uint8_t inspected_flag =
1598 SCLogDebug(
"%" PRIu64
" tx already fully inspected for %s. Flags %02x", tx_id,
1599 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1603 const uint8_t skip_flag = (flow_flags & STREAM_TOSERVER) ? APP_LAYER_TX_SKIP_INSPECT_TS
1604 : APP_LAYER_TX_SKIP_INSPECT_TC;
1606 SCLogDebug(
"%" PRIu64
" tx should not be inspected in direction %s. Flags %02x", tx_id,
1607 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1616 const uint8_t detect_progress =
1619 const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1622 tx_de_state ? &tx_de_state->
dir_state[dir_int] : NULL;
1628 .detect_progress = detect_progress,
1629 .detect_progress_orig = detect_progress,
1630 .tx_progress = (uint8_t)tx_progress,
1631 .tx_end_state = e_tx_end_state,
1638 static inline void StoreDetectProgress(
1642 if (flow_flags & STREAM_TOSERVER) {
1651 static inline void RuleMatchCandidateMergeStateRules(
1669 uint32_t j = *array_idx;
1681 uint32_t k = *array_idx;
1703 if (s->
iid <= s0->
id) {
1752 static inline void DetectFwEnsureLteCoverage(
1771 DetectFwEnsureLteCoverage(det_ctx, fw_state);
1772 for (uint32_t i = 0; i < array_idx; i++) {
1782 if (
flags == NULL) {
1783 if (!DetectRunInspectRuleHeader(
p,
f, s, s->
flags)) {
1791 if (
flags != NULL &&
1835 return covered > (counted ? 1 : 0);
1851 !DetectRunInspectRuleHeader(
p,
f, s, s->
flags)) {
1854 for (uint32_t k = 0; k < can_idx; k++) {
1859 DetectFwEnsureLteCoverage(det_ctx, fw_state);
1913 const uint8_t progress)
1915 const uint8_t dir_flags = direction & (STREAM_TOSERVER | STREAM_TOCLIENT);
1930 if (
likely(ap != NULL)) {
1936 SCLogDebug(
"dropping packet PKT_DROP_REASON_FW_DEFAULT_APP_POLICY");
1943 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p,
true, tx, ap);
1951 const bool last_hook =
progress == tx->tx_progress;
1952 bool apply_to_packet =
false;
1957 apply_to_packet =
true;
1961 apply_to_packet = tx->is_last;
1964 apply_to_packet = tx->is_last && last_hook;
1971 SCLogDebug(
"packet %" PRIu64
" hook %u default policy ACCEPT, apply_to_packet:%s",
1976 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p, apply_to_packet, tx, ap);
1977 }
else if (apply_to_packet) {
1979 DetectRunAppendDefaultAccept(det_ctx,
p);
2003 const uint8_t start_hook,
const uint8_t end_hook)
2007 const bool need_verdict =
2009 SCLogDebug(
"need_verdict:%s is_last:%s end_hook:%u tx->tx_end_state:%u tx->progress: %u",
2013 for (uint8_t hook = start_hook; hook <= end_hook; hook++) {
2014 const bool apply_to_packet =
2017 SCLogDebug(
"%" PRIu64
": %s default policy for hook %u, apply_to_packet %s",
2022 det_ctx, policies, tx,
p, alproto, direction, hook);
2023 SCLogDebug(
"fw: hook:%u policy:%02x apply_to_packet:%s", hook, policy.
action,
2043 if (apply_to_packet) {
2058 SCLogDebug(
"default accept: last tx and progress at end_hook %u", end_hook);
2059 DetectRunAppendDefaultAccept(det_ctx,
p);
2081 const Signature *s,
const uint32_t can_idx,
const bool lte_counted,
2099 SCLogDebug(
"default accept due to flow accept");
2100 DetectRunAppendDefaultAccept(det_ctx,
p);
2111 const bool accept_tx_applies_to_packet = tx->
is_last;
2112 if (accept_tx_applies_to_packet) {
2113 SCLogDebug(
"accept:tx: should be applied to the packet");
2114 DetectRunAppendDefaultAccept(det_ctx,
p);
2118 SCLogDebug(
"APP_LAYER_TX_ACCEPT, so skip rule");
2133 SCLogDebug(
"check if prior hooks are satisfied: s->app_progress_hook %u, "
2134 "tx->detect_progress_orig %u",
2137 if (DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2138 SCLogDebug(
"later LTE in-progress rule brought us here: us:%u covered:%u",
2146 SCLogDebug(
"missing fw rules at list start: sid %u, progress %u (%u:%u)", s->
id,
2186 if (can_idx + 1 < can_size) {
2192 if (DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2193 SCLogDebug(
"we have another LTE in-progress. Us:%u covered:%u",
2196 SCLogDebug(
"peek: next sid progress %u != current progress %u, so current "
2197 "is last for progress",
2202 SCLogDebug(
"peek: missing progress, so we'll drop that unless we get a "
2203 "sweeping accept first");
2209 SCLogDebug(
"peek: next sid not a fw rule, so current is last for progress");
2214 SCLogDebug(
"peek: no peek beyond last rule");
2215 if (!DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2217 SCLogDebug(
"peek: there are no rules to allow the state after this rule");
2309 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2310 "skip_before_progress:%u fw_last_for_progress:%s fw_next_progress_missing:%s",
2337 SCLogDebug(
"accept:tx applied, skip_fw_hook, skip_before_progress %u",
2342 SCLogDebug(
"sid %u: ACTION_ACCEPT with ACTION_SCOPE_FLOW", s->
id);
2363 if (rule_cnt == 0) {
2366 DetectRunAppendDefaultAccept(det_ctx,
p);
2373 DetectRunAppendDefaultAccept(det_ctx,
p);
2390 alproto, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT),
2414 const uint8_t flow_flags)
2423 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2424 if (fw_accept_to_packet) {
2426 SCLogDebug(
"accept:(tx|hook): should be applied to the packet");
2432 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2434 SCLogDebug(
"drop packet because of rule with drop action");
2437 SCLogDebug(
"drop flow because of rule with drop action");
2459 static int DetectRunTxFirewallRulePartialMatch(
2466 SCLogDebug(
"need to apply accept to packet");
2467 DetectRunAppendDefaultAccept(det_ctx,
p);
2470 SCLogDebug(
"only applying accept:flow on full match, downgrading to "
2491 const uint8_t flow_flags)
2544 Packet *
p,
const uint8_t flow_flags)
2550 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2551 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2552 if (fw_accept_to_packet) {
2554 DetectRunAppendDefaultAccept(det_ctx,
p);
2566 const uint8_t flow_flags = scratch->
flow_flags;
2569 const uint8_t ipproto =
f->
proto;
2577 uint32_t tx_inspected = 0;
2581 bool last_tx_skipped =
false;
2588 if (ires.
tx_ptr == NULL) {
2589 SCLogDebug(
"%p/%" PRIu64
" no transaction to inspect", ires.
tx_ptr, tx_id_min);
2595 SCLogDebug(
"%p/%"PRIu64
" no transaction to inspect",
2602 tx_id_min = tx.
tx_id + 1;
2612 bool do_sort =
false;
2613 bool fw_lte_candidates =
false;
2614 uint32_t array_idx = 0;
2624 SCLogDebug(
"%p/%"PRIu64
" rules added from prefilter: %u candidates",
2628 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2629 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2642 fw_lte_candidates =
true;
2648 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2649 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2655 uint32_t x = array_idx;
2657 RuleMatchCandidateMergeStateRules(det_ctx, &array_idx, &fw_lte_candidates);
2661 const uint32_t old = array_idx;
2666 if (have_new_file) {
2667 SCLogDebug(
"%p/%"PRIu64
" destate: need to consider new file",
2674 for (; tx_store != NULL; tx_store = tx_store->
next) {
2680 store_cnt++, state_cnt++)
2699 fw_lte_candidates =
true;
2704 do_sort |= (array_idx > old);
2710 DetectRunTxSortHelper);
2719 for (uint32_t i = 0; i < array_idx; i++) {
2730 if (have_fw_rules && fw_lte_candidates) {
2731 DetectFwBuildLteCoverage(det_ctx,
p,
f, &fw_state, array_idx);
2734 SCLogDebug(
"%s: tx_progress %u tx %p have_fw_rules %s array_idx %u detect_progress_orig %u "
2735 "cur detect_progress %u",
2736 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2740 if (have_fw_rules) {
2743 const int r = DetectTxFirewallNoRulesApplyPolicies(
2744 det_ctx,
p,
f, &tx, alproto, flow_flags, array_idx);
2748 }
else if (r == 2) {
2754 for (uint32_t i = 0; i < array_idx; i++) {
2760 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2763 if (have_fw_rules) {
2765 det_ctx,
p, &tx, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT), s, i,
2767 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2768 "skip_before_progress:%u fw_last_for_progress:%s "
2769 "fw_next_progress_missing:%s",
2788 while ((i + 1) < array_idx &&
2790 SCLogDebug(
"%p/%" PRIu64
" inspecting SKIP NEXT: sid %u (%u), flags %08x",
2796 s->
id, s->
iid, inspect_flags ? *inspect_flags : 0);
2798 if (inspect_flags) {
2801 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_FULL_INSPECT",
2806 if (have_fw_rules) {
2807 DetectRunTxFirewallRuleStatefulReApplyMatch(
2808 det_ctx, s, &tx, &fw_state,
p, flow_flags);
2814 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_SIG_CANT_MATCH",
2826 if (have_fw_rules) {
2830 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2831 "skip_before_progress:%u fw_last_for_progress:%s "
2832 "fw_next_progress_missing:%s",
2844 const int r = DetectRunTxInspectRule(
tv,
de_ctx, det_ctx,
p,
f, flow_flags,
2845 alstate, &tx, s, inspect_flags, can, scratch);
2849 DetectFwRetireLteRule(det_ctx, can);
2853 DetectRunPostMatch(
tv, det_ctx,
p, s);
2861 DetectRunTxFirewallRuleFullMatch(det_ctx, s, &tx, &fw_state,
f,
p, flow_flags);
2863 }
else if (r == 0) {
2865 if (DetectRunTxFirewallRulePartialMatch(det_ctx, s, &tx,
p) == 1) {
2868 }
else if (r == -1) {
2870 DetectRunTxFirewallRuleNoMatch(det_ctx, s, &tx, &fw_state,
p, flow_flags) ==
2876 DetectVarProcessList(det_ctx,
p->
flow,
p);
2885 uint32_t prev_array_idx = array_idx;
2889 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, needed))) {
2890 RuleMatchCandidateTxArrayExpand(det_ctx, needed);
2895 if (
ts->app_inspect != NULL) {
2906 if (have_fw_rules) {
2907 DetectFwCountAppendedLteRule(det_ctx,
p,
f, &fw_state,
ts, array_idx);
2911 SCLogDebug(
"%p/%" PRIu64
" rule %u (%u) added from 'post match' prefilter",
2915 SCLogDebug(
"%p/%" PRIu64
" rules added from 'post match' prefilter: %u", tx.
tx_ptr,
2916 tx.
tx_id, array_idx - prev_array_idx);
2917 if (prev_array_idx != array_idx) {
2920 DetectRunTxSortHelper);
2936 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient");
2937 const uint8_t inspected_flag = (flow_flags & STREAM_TOSERVER)
2941 SCLogDebug(
"%p/%" PRIu64
" tx is done for direction %s. Progress %02x", tx.
tx_ptr,
2942 tx.
tx_id, flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
2964 if (have_fw_rules) {
2965 if (tx_inspected == 0) {
2967 SCLogDebug(
"default accept: no app inspect performed");
2968 DetectRunAppendDefaultAccept(det_ctx,
p);
2969 }
else if (last_tx_skipped) {
2973 SCLogDebug(
"default accept: last tx skipped");
2974 DetectRunAppendDefaultAccept(det_ctx,
p);
2990 SCLogDebug(
"pcap_cnt %" PRIu64
": %s: skip frame inspection for TCP w/o APP UPDATE",
2995 if (frames_container == NULL) {
3000 frames = &frames_container->
toserver;
3002 frames = &frames_container->
toclient;
3005 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
3008 if (frame == NULL) {
3013 uint32_t array_idx = 0;
3021 SCLogDebug(
"%p/%" PRIi64
" rules added from prefilter: %u candidates", frame, frame->
id,
3026 if (!(RuleMatchCandidateTxArrayHasSpace(
3027 det_ctx, total_rules))) {
3028 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
3045 uint32_t x = array_idx;
3058 SCLogDebug(
"%p/%" PRIi64
" rule %u (%u) added from 'match' list", frame, frame->
id,
3062 SCLogDebug(
"%p/%" PRIi64
" rules added from 'match' list: %u", frame, frame->
id,
3067 for (uint32_t i = 0; i < array_idx; i++) {
3074 while ((i + 1) < array_idx &&
3078 SCLogDebug(
"%p/%" PRIi64
" inspecting: sid %u (%u)", frame, frame->
id, s->
id, s->
iid);
3081 SCLogDebug(
"%p/%" PRIi64
" Start sid %u", frame, frame->
id, s->
id);
3085 bool r = DetectRunInspectRuleHeader(
p,
f, s, s->
flags);
3090 DetectRunPostMatch(
tv, det_ctx,
p, s);
3093 "%p/%" PRIi64
" sig %u (%u) matched", frame, frame->
id, s->
id, s->
iid);
3094 const uint8_t alert_flags =
3097 const uint8_t ipproto =
p->
proto;
3098 uint8_t sub_state = 0;
3111 DetectVarProcessList(det_ctx,
p->
flow,
p);
3122 "frame->inspect_progress: %" PRIu64
" -> not updated", frame->
inspect_progress);
3125 SCLogDebug(
"%p/%" PRIi64
" rules inspected, running cleanup", frame, frame->
id);
3173 SCLogDebug(
"p->pcap %" PRIu64
": no detection on packet, "
3174 "PKT_NOPACKET_INSPECTION is set",
3232 if (det_ctx == NULL) {
3233 printf(
"ERROR: Detect has no thread ctx\n");
3239 SCLogDebug(
"Detect Engine using new det_ctx - %p",
3250 if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
3253 if (det_ctx == NULL)
3261 SCLogDebug(
"MT de_ctx %p det_ctx %p (tenant %u)",
de_ctx, det_ctx, tenant_id);
3277 #ifdef PROFILE_RULES
3280 gettimeofday(&
ts, NULL);
3281 if (
ts.tv_sec != det_ctx->rule_perf_last_sync) {
3282 SCProfilingRuleThreatAggregate(det_ctx);
3283 det_ctx->rule_perf_last_sync =
ts.tv_sec;
3297 DetectPostInspectFileFlagsUpdate(
f, NULL , STREAM_TOSERVER);
3298 DetectPostInspectFileFlagsUpdate(
f, NULL , STREAM_TOCLIENT);
3301 #if defined(UNITTESTS) || defined(FUZZ)