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);
917 if (iid == previous_id) {
923 if (
ts->app_inspect == NULL) {
940 uint32_t skipped = 0;
941 for (uint32_t x = 0; x < match_cnt; x++) {
943 if (last_sig == *
m) {
950 match_cnt -= skipped;
952 next_s = *match_array++;
953 next_sflags = next_s->
flags;
1003 break_out_of_packet_filter =
true;
1007 DetectVarProcessList(det_ctx, pflow,
p);
1008 DetectReplaceFree(det_ctx);
1012 if (break_out_of_packet_filter)
1021 if (have_fw_rules) {
1022 if (skip_fw || fw_verdict) {
1042 uint8_t flow_flags = 0;
1043 bool app_decoder_events =
false;
1069 det_ctx->pkt_stream_add_cnt++;
1078 flow_flags = STREAM_TOSERVER;
1081 flow_flags = STREAM_TOCLIENT;
1087 flow_flags |= STREAM_EOF;
1118 (
p->
proto == IPPROTO_UDP) ||
1130 SCLogDebug(
"packet doesn't have established flag set (proto %d)",
p->
proto);
1136 DetectRunScratchpad pad = { alproto, flow_flags, app_decoder_events, fw_pkt_policy, NULL };
1173 SCLogDebug(
"packet %" PRIu64
": default action as no verdict set %02x (pkt %s)",
1209 DetectByteValuesClear(det_ctx);
1211 if (pflow != NULL) {
1234 FatalError(
"failed to allocate %" PRIu64
" bytes",
1238 SCLogDebug(
"array initialized to %u elements (%"PRIu64
" bytes)",
1250 const uint32_t need)
1261 uint32_t new_size = needed;
1264 FatalError(
"failed to expand to %" PRIu64
" bytes",
1270 SCLogDebug(
"array expanded from %u to %u elements (%"PRIu64
" bytes -> %"PRIu64
" bytes)",
1283 DetectRunTxSortHelper(
const void *a,
const void *b)
1287 if (s1->
id == s0->
id) {
1294 return s0->
id > s1->
id ? 1 : -1;
1298 #define TRACE_SID_TXS(sid,txs,...) \
1300 char _trace_buf[2048]; \
1301 snprintf(_trace_buf, sizeof(_trace_buf), __VA_ARGS__); \
1302 SCLogNotice("%p/%"PRIu64"/%u: %s", txs->tx_ptr, txs->tx_id, sid, _trace_buf); \
1305 #define TRACE_SID_TXS(sid,txs,...)
1317 SCLogDebug(
"pre: tx_ptr %p flow::alproto %s engine::alproto %s", tx_ptr,
1320 switch (engine_alproto) {
1323 tx_ptr = SCDoH2GetDnsTx(tx_ptr, flow_flags);
1334 }
else if (engine_alproto != alproto && engine_alproto !=
ALPROTO_UNKNOWN) {
1361 const uint8_t in_flow_flags,
1365 const uint8_t flow_flags = in_flow_flags;
1366 const int direction = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1367 uint32_t inspect_flags = stored_flags ? *stored_flags : 0;
1368 int total_matches = 0;
1369 uint16_t file_no_match = 0;
1370 bool mpm_before_progress =
false;
1371 bool mpm_in_progress =
false;
1373 TRACE_SID_TXS(s->
id, tx,
"starting %s", direction ?
"toclient" :
"toserver");
1376 if (
likely(stored_flags == NULL)) {
1394 TRACE_SID_TXS(s->
id, tx,
"continue, inspect_flags %x", inspect_flags);
1399 TRACE_SID_TXS(s->
id, tx,
"engine %p inspect_flags %x", engine, inspect_flags);
1403 if (!(inspect_flags &
BIT_U32(engine->
id)) &&
1415 "skip because engine alproto %s sub_state %u != tx_type %u (engine "
1419 engine = engine->
next;
1423 "inspecting engine alproto %s sub_state %u == tx_type %u (engine progress %u)",
1428 if (tx_ptr == NULL) {
1434 engine = engine->
next;
1445 SCLogDebug(
"tx progress %d < engine progress %d",
1452 "engine->mpm: t->tx_progress %u > engine->progress %u, so set "
1453 "mpm_before_progress",
1455 mpm_before_progress =
true;
1458 "engine->mpm: t->tx_progress %u == engine->progress %u, so set "
1462 mpm_in_progress =
true;
1467 uint8_t engine_flags = flow_flags;
1468 if (direction != engine->
dir) {
1469 engine_flags = flow_flags ^ (STREAM_TOCLIENT | STREAM_TOSERVER);
1475 TRACE_SID_TXS(s->
id, tx,
"stream skipped, stored result %d used instead", match);
1480 mpm_before_progress =
true;
1495 de_ctx, det_ctx, engine, s,
f, engine_flags, alstate, tx_ptr, tx->
tx_id);
1500 TRACE_SID_TXS(s->
id, tx,
"stream ran, store result %d for next tx (if any)", match);
1505 engine = engine->
next;
1512 engine = engine->
next;
1524 if (engine->
mpm && mpm_before_progress) {
1530 direction != engine->
dir) {
1536 if (direction == 0 && engine->
next == NULL) {
1540 engine = engine->
next;
1544 engine = engine->
next;
1545 }
while (engine != NULL);
1546 TRACE_SID_TXS(s->
id, tx,
"inspect_flags %x, total_matches %u, engine %p",
1547 inspect_flags, total_matches, engine);
1549 bool full_match =
false;
1550 if (engine == NULL && total_matches) {
1557 *stored_flags = inspect_flags;
1558 TRACE_SID_TXS(s->
id, tx,
"continue inspect flags %08x", inspect_flags);
1565 if (file_no_match) {
1576 inspect_flags, flow_flags, file_no_match);
1580 "mpm won't trigger for it anymore");
1584 "we may have to revisit anyway");
1586 inspect_flags, flow_flags, file_no_match);
1590 "mpm will revisit it");
1592 }
else if (inspect_flags != 0 || file_no_match != 0) {
1595 inspect_flags, flow_flags, file_no_match);
1597 if (inspect_flags == 0) {
1598 TRACE_SID_TXS(s->
id, tx,
"no match: inspect_flags %08x", inspect_flags);
1616 NULL, 0, NULL, NULL, 0, 0, 0, 0, false, 0, \
1624 const uint64_t tx_id,
void *tx_ptr,
const uint8_t flow_flags)
1627 const uint8_t tx_progress =
1631 const uint8_t e_tx_end_state =
1636 if (!updated && tx_progress < e_tx_end_state && ((flow_flags & STREAM_EOF) == 0)) {
1640 const uint8_t inspected_flag =
1643 SCLogDebug(
"%" PRIu64
" tx already fully inspected for %s. Flags %02x", tx_id,
1644 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1648 const uint8_t skip_flag = (flow_flags & STREAM_TOSERVER) ? APP_LAYER_TX_SKIP_INSPECT_TS
1649 : APP_LAYER_TX_SKIP_INSPECT_TC;
1651 SCLogDebug(
"%" PRIu64
" tx should not be inspected in direction %s. Flags %02x", tx_id,
1652 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", txd->
flags);
1661 const uint8_t detect_progress =
1664 const int dir_int = (flow_flags & STREAM_TOSERVER) ? 0 : 1;
1667 tx_de_state ? &tx_de_state->
dir_state[dir_int] : NULL;
1673 .detect_progress = detect_progress,
1674 .detect_progress_orig = detect_progress,
1675 .tx_progress = (uint8_t)tx_progress,
1676 .tx_end_state = e_tx_end_state,
1683 static inline void StoreDetectProgress(
1687 if (flow_flags & STREAM_TOSERVER) {
1696 static inline void RuleMatchCandidateMergeStateRules(
1714 uint32_t j = *array_idx;
1726 uint32_t k = *array_idx;
1748 if (s->
iid <= s0->
id) {
1797 static inline void DetectFwEnsureLteCoverage(
1816 DetectFwEnsureLteCoverage(det_ctx, fw_state);
1817 for (uint32_t i = 0; i < array_idx; i++) {
1827 if (
flags == NULL) {
1828 if (!DetectRunInspectRuleHeader(
p,
f, s, s->
flags)) {
1836 if (
flags != NULL &&
1880 return covered > (counted ? 1 : 0);
1896 !DetectRunInspectRuleHeader(
p,
f, s, s->
flags)) {
1899 for (uint32_t k = 0; k < can_idx; k++) {
1904 DetectFwEnsureLteCoverage(det_ctx, fw_state);
1958 const uint8_t progress)
1960 const uint8_t dir_flags = direction & (STREAM_TOSERVER | STREAM_TOCLIENT);
1975 if (
likely(ap != NULL)) {
1981 SCLogDebug(
"dropping packet PKT_DROP_REASON_FW_DEFAULT_APP_POLICY");
1988 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p,
true, tx, ap);
1996 const bool last_hook =
progress == tx->tx_progress;
1997 bool apply_to_packet =
false;
2002 apply_to_packet =
true;
2006 apply_to_packet = tx->is_last;
2009 apply_to_packet = tx->is_last && last_hook;
2016 SCLogDebug(
"packet %" PRIu64
" hook %u default policy ACCEPT, apply_to_packet:%s",
2021 DetectRunAppendDefaultAppPolicyAlert(det_ctx,
p, apply_to_packet, tx, ap);
2022 }
else if (apply_to_packet) {
2024 DetectRunAppendDefaultAccept(det_ctx,
p);
2048 const uint8_t start_hook,
const uint8_t end_hook)
2052 const bool need_verdict =
2054 SCLogDebug(
"need_verdict:%s is_last:%s end_hook:%u tx->tx_end_state:%u tx->progress: %u",
2058 for (uint8_t hook = start_hook; hook <= end_hook; hook++) {
2059 const bool apply_to_packet =
2062 SCLogDebug(
"%" PRIu64
": %s default policy for hook %u, apply_to_packet %s",
2067 det_ctx, policies, tx,
p, alproto, direction, hook);
2068 SCLogDebug(
"fw: hook:%u policy:%02x apply_to_packet:%s", hook, policy.
action,
2088 if (apply_to_packet) {
2103 SCLogDebug(
"default accept: last tx and progress at end_hook %u", end_hook);
2104 DetectRunAppendDefaultAccept(det_ctx,
p);
2126 const Signature *s,
const uint32_t can_idx,
const bool lte_counted,
2144 SCLogDebug(
"default accept due to flow accept");
2145 DetectRunAppendDefaultAccept(det_ctx,
p);
2156 const bool accept_tx_applies_to_packet = tx->
is_last;
2157 if (accept_tx_applies_to_packet) {
2158 SCLogDebug(
"accept:tx: should be applied to the packet");
2159 DetectRunAppendDefaultAccept(det_ctx,
p);
2163 SCLogDebug(
"APP_LAYER_TX_ACCEPT, so skip rule");
2178 SCLogDebug(
"check if prior hooks are satisfied: s->app_progress_hook %u, "
2179 "tx->detect_progress_orig %u",
2182 if (DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2183 SCLogDebug(
"later LTE in-progress rule brought us here: us:%u covered:%u",
2191 SCLogDebug(
"missing fw rules at list start: sid %u, progress %u (%u:%u)", s->
id,
2231 if (can_idx + 1 < can_size) {
2237 if (DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2238 SCLogDebug(
"we have another LTE in-progress. Us:%u covered:%u",
2241 SCLogDebug(
"peek: next sid progress %u != current progress %u, so current "
2242 "is last for progress",
2247 SCLogDebug(
"peek: missing progress, so we'll drop that unless we get a "
2248 "sweeping accept first");
2254 SCLogDebug(
"peek: next sid not a fw rule, so current is last for progress");
2259 SCLogDebug(
"peek: no peek beyond last rule");
2260 if (!DetectFwOtherLteCoversHook(det_ctx, fw_state, s, lte_counted)) {
2262 SCLogDebug(
"peek: there are no rules to allow the state after this rule");
2354 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2355 "skip_before_progress:%u fw_last_for_progress:%s fw_next_progress_missing:%s",
2382 SCLogDebug(
"accept:tx applied, skip_fw_hook, skip_before_progress %u",
2387 SCLogDebug(
"sid %u: ACTION_ACCEPT with ACTION_SCOPE_FLOW", s->
id);
2408 if (rule_cnt == 0) {
2411 DetectRunAppendDefaultAccept(det_ctx,
p);
2418 DetectRunAppendDefaultAccept(det_ctx,
p);
2435 alproto, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT),
2459 const uint8_t flow_flags)
2468 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2469 if (fw_accept_to_packet) {
2471 SCLogDebug(
"accept:(tx|hook): should be applied to the packet");
2477 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2479 SCLogDebug(
"drop packet because of rule with drop action");
2482 SCLogDebug(
"drop flow because of rule with drop action");
2504 static int DetectRunTxFirewallRulePartialMatch(
2511 SCLogDebug(
"need to apply accept to packet");
2512 DetectRunAppendDefaultAccept(det_ctx,
p);
2515 SCLogDebug(
"only applying accept:flow on full match, downgrading to "
2536 const uint8_t flow_flags)
2589 Packet *
p,
const uint8_t flow_flags)
2595 const bool fw_accept_to_packet = ApplyAcceptToPacket(tx, s);
2596 DetectRunTxFirewallApplyAccept(det_ctx,
p, flow_flags, s, tx, fw_state);
2597 if (fw_accept_to_packet) {
2599 DetectRunAppendDefaultAccept(det_ctx,
p);
2621 const uint8_t flow_flags = scratch->
flow_flags;
2624 const uint8_t ipproto =
f->
proto;
2632 uint32_t tx_inspected = 0;
2636 bool last_tx_skipped =
false;
2643 if (ires.
tx_ptr == NULL) {
2644 SCLogDebug(
"%p/%" PRIu64
" no transaction to inspect", ires.
tx_ptr, tx_id_min);
2650 SCLogDebug(
"%p/%"PRIu64
" no transaction to inspect",
2657 tx_id_min = tx.
tx_id + 1;
2668 bool do_sort =
false;
2669 bool fw_lte_candidates =
false;
2670 uint32_t array_idx = 0;
2680 SCLogDebug(
"%p/%"PRIu64
" rules added from prefilter: %u candidates",
2684 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2685 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2698 fw_lte_candidates =
true;
2704 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, total_rules))) {
2705 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
2711 uint32_t x = array_idx;
2713 RuleMatchCandidateMergeStateRules(det_ctx, &array_idx, &fw_lte_candidates);
2717 const uint32_t old = array_idx;
2722 if (have_new_file) {
2723 SCLogDebug(
"%p/%"PRIu64
" destate: need to consider new file",
2730 for (; tx_store != NULL; tx_store = tx_store->
next) {
2736 store_cnt++, state_cnt++)
2755 fw_lte_candidates =
true;
2760 do_sort |= (array_idx > old);
2766 DetectRunTxSortHelper);
2775 for (uint32_t i = 0; i < array_idx; i++) {
2786 if (have_fw_rules && fw_lte_candidates) {
2787 DetectFwBuildLteCoverage(det_ctx,
p,
f, &fw_state, array_idx);
2790 SCLogDebug(
"%s: tx_progress %u tx %p have_fw_rules %s array_idx %u detect_progress_orig %u "
2791 "cur detect_progress %u",
2792 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2796 if (have_fw_rules) {
2799 const int r = DetectTxFirewallNoRulesApplyPolicies(
2800 det_ctx,
p,
f, &tx, alproto, flow_flags, array_idx);
2803 DetectRunTxClearInspected(det_ctx);
2805 }
else if (r == 2) {
2811 for (uint32_t i = 0; i < array_idx; i++) {
2817 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient", tx.
tx_progress,
2820 if (have_fw_rules) {
2822 det_ctx,
p, &tx, flow_flags & (STREAM_TOSERVER | STREAM_TOCLIENT), s, i,
2824 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2825 "skip_before_progress:%u fw_last_for_progress:%s "
2826 "fw_next_progress_missing:%s",
2845 while ((i + 1) < array_idx &&
2847 SCLogDebug(
"%p/%" PRIu64
" inspecting SKIP NEXT: sid %u (%u), flags %08x",
2853 s->
id, s->
iid, inspect_flags ? *inspect_flags : 0);
2855 if (inspect_flags) {
2858 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_FULL_INSPECT",
2863 if (have_fw_rules) {
2864 DetectRunTxFirewallRuleStatefulReApplyMatch(
2865 det_ctx, s, &tx, &fw_state,
p, flow_flags);
2871 " inspecting: sid %u (%u), flags %08x DE_STATE_FLAG_SIG_CANT_MATCH",
2883 if (have_fw_rules) {
2887 SCLogDebug(
"fw fw_skip_app_filter:%s skip_fw_hook:%s "
2888 "skip_before_progress:%u fw_last_for_progress:%s "
2889 "fw_next_progress_missing:%s",
2901 const int r = DetectRunTxInspectRule(
tv,
de_ctx, det_ctx,
p,
f, flow_flags,
2902 alstate, &tx, s, inspect_flags, can, scratch);
2906 DetectFwRetireLteRule(det_ctx, can);
2910 DetectRunPostMatch(
tv, det_ctx,
p, s);
2918 DetectRunTxFirewallRuleFullMatch(det_ctx, s, &tx, &fw_state,
f,
p, flow_flags);
2920 }
else if (r == 0) {
2922 if (DetectRunTxFirewallRulePartialMatch(det_ctx, s, &tx,
p) == 1) {
2925 }
else if (r == -1) {
2927 DetectRunTxFirewallRuleNoMatch(det_ctx, s, &tx, &fw_state,
p, flow_flags) ==
2929 DetectRunTxClearInspected(det_ctx);
2934 DetectVarProcessList(det_ctx,
p->
flow,
p);
2943 uint32_t prev_array_idx = array_idx;
2947 if (!(RuleMatchCandidateTxArrayHasSpace(det_ctx, needed))) {
2948 RuleMatchCandidateTxArrayExpand(det_ctx, needed);
2953 if (
ts->app_inspect != NULL) {
2964 if (have_fw_rules) {
2965 DetectFwCountAppendedLteRule(det_ctx,
p,
f, &fw_state,
ts, array_idx);
2969 SCLogDebug(
"%p/%" PRIu64
" rule %u (%u) added from 'post match' prefilter",
2973 SCLogDebug(
"%p/%" PRIu64
" rules added from 'post match' prefilter: %u", tx.
tx_ptr,
2974 tx.
tx_id, array_idx - prev_array_idx);
2975 if (prev_array_idx != array_idx) {
2978 DetectRunTxSortHelper);
2990 flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient");
2991 const uint8_t inspected_flag = (flow_flags & STREAM_TOSERVER)
2995 SCLogDebug(
"%p/%" PRIu64
" tx is done for direction %s. Progress %02x", tx.
tx_ptr,
2996 tx.
tx_id, flow_flags & STREAM_TOSERVER ?
"toserver" :
"toclient",
3010 DetectRunTxClearInspected(det_ctx);
3019 if (have_fw_rules) {
3020 if (tx_inspected == 0) {
3022 SCLogDebug(
"default accept: no app inspect performed");
3023 DetectRunAppendDefaultAccept(det_ctx,
p);
3024 }
else if (last_tx_skipped) {
3028 SCLogDebug(
"default accept: last tx skipped");
3029 DetectRunAppendDefaultAccept(det_ctx,
p);
3045 SCLogDebug(
"pcap_cnt %" PRIu64
": %s: skip frame inspection for TCP w/o APP UPDATE",
3050 if (frames_container == NULL) {
3055 frames = &frames_container->
toserver;
3057 frames = &frames_container->
toclient;
3060 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
3063 if (frame == NULL) {
3068 uint32_t array_idx = 0;
3076 SCLogDebug(
"%p/%" PRIi64
" rules added from prefilter: %u candidates", frame, frame->
id,
3081 if (!(RuleMatchCandidateTxArrayHasSpace(
3082 det_ctx, total_rules))) {
3083 RuleMatchCandidateTxArrayExpand(det_ctx, total_rules);
3100 uint32_t x = array_idx;
3113 SCLogDebug(
"%p/%" PRIi64
" rule %u (%u) added from 'match' list", frame, frame->
id,
3117 SCLogDebug(
"%p/%" PRIi64
" rules added from 'match' list: %u", frame, frame->
id,
3122 for (uint32_t i = 0; i < array_idx; i++) {
3129 while ((i + 1) < array_idx &&
3133 SCLogDebug(
"%p/%" PRIi64
" inspecting: sid %u (%u)", frame, frame->
id, s->
id, s->
iid);
3136 SCLogDebug(
"%p/%" PRIi64
" Start sid %u", frame, frame->
id, s->
id);
3140 bool r = DetectRunInspectRuleHeader(
p,
f, s, s->
flags);
3145 DetectRunPostMatch(
tv, det_ctx,
p, s);
3148 "%p/%" PRIi64
" sig %u (%u) matched", frame, frame->
id, s->
id, s->
iid);
3149 const uint8_t alert_flags =
3152 const uint8_t ipproto =
p->
proto;
3153 uint8_t sub_state = 0;
3166 DetectVarProcessList(det_ctx,
p->
flow,
p);
3177 "frame->inspect_progress: %" PRIu64
" -> not updated", frame->
inspect_progress);
3180 SCLogDebug(
"%p/%" PRIi64
" rules inspected, running cleanup", frame, frame->
id);
3228 SCLogDebug(
"p->pcap %" PRIu64
": no detection on packet, "
3229 "PKT_NOPACKET_INSPECTION is set",
3287 if (det_ctx == NULL) {
3288 printf(
"ERROR: Detect has no thread ctx\n");
3294 SCLogDebug(
"Detect Engine using new det_ctx - %p",
3305 if (tenant_id > 0 && tenant_id < det_ctx->mt_det_ctxs_cnt) {
3308 if (det_ctx == NULL)
3316 SCLogDebug(
"MT de_ctx %p det_ctx %p (tenant %u)",
de_ctx, det_ctx, tenant_id);
3332 #ifdef PROFILE_RULES
3335 gettimeofday(&
ts, NULL);
3336 if (
ts.tv_sec != det_ctx->rule_perf_last_sync) {
3337 SCProfilingRuleThreatAggregate(det_ctx);
3338 det_ctx->rule_perf_last_sync =
ts.tv_sec;
3352 DetectPostInspectFileFlagsUpdate(
f, NULL , STREAM_TOSERVER);
3353 DetectPostInspectFileFlagsUpdate(
f, NULL , STREAM_TOCLIENT);
3356 #if defined(UNITTESTS) || defined(FUZZ)