From: Philippe Antoine Date: Fri, 2 Feb 2024 10:11:10 +0000 (+0100) Subject: detect: do not run tx detection on non established packets X-Git-Tag: suricata-8.0.0-beta1~1713 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=497394eec69fec1ff82c864de05127687bc1eb33;p=thirdparty%2Fsuricata.git detect: do not run tx detection on non established packets Follows commit 2fb5059 Ticket: 6775 --- diff --git a/src/detect.c b/src/detect.c index 72e40eaff3..6eb8698cf4 100644 --- a/src/detect.c +++ b/src/detect.c @@ -146,6 +146,9 @@ static void DetectRun(ThreadVars *th_v, /* run tx/state inspection. Don't call for ICMP error msgs. */ if (pflow && pflow->alstate && likely(pflow->proto == p->proto)) { if (p->proto == IPPROTO_TCP) { + if ((p->flags & PKT_STREAM_EST) == 0) { + goto end; + } const TcpSession *ssn = p->flow->protoctx; if (ssn && (ssn->flags & STREAMTCP_FLAG_APP_LAYER_DISABLED) == 0) { // PACKET_PROFILING_DETECT_START(p, PROF_DETECT_TX); diff --git a/src/flow-worker.c b/src/flow-worker.c index 6980570d3c..77fe2b87fe 100644 --- a/src/flow-worker.c +++ b/src/flow-worker.c @@ -619,7 +619,7 @@ static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data) if (p->proto == IPPROTO_TCP) { StreamTcpSessionCleanup(p->flow->protoctx); } - } else if (p->proto == IPPROTO_TCP && p->flow->protoctx) { + } else if (p->proto == IPPROTO_TCP && p->flow->protoctx && p->flags & PKT_STREAM_EST) { FramesPrune(p->flow, p); FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_TCPPRUNE); StreamTcpPruneSession(p->flow, p->flowflags & FLOW_PKT_TOSERVER ? @@ -631,18 +631,19 @@ static TmEcode FlowWorker(ThreadVars *tv, Packet *p, void *data) if ((PKT_IS_PSEUDOPKT(p)) || (p->flow->flags & (FLOW_TS_APP_UPDATED | FLOW_TC_APP_UPDATED))) { - if (PKT_IS_TOSERVER(p)) { - if (PKT_IS_PSEUDOPKT(p) || (p->flow->flags & (FLOW_TS_APP_UPDATED))) { - AppLayerParserTransactionsCleanup(p->flow, STREAM_TOSERVER); - p->flow->flags &= ~FLOW_TS_APP_UPDATED; - } - } else { - if (PKT_IS_PSEUDOPKT(p) || (p->flow->flags & (FLOW_TC_APP_UPDATED))) { - AppLayerParserTransactionsCleanup(p->flow, STREAM_TOCLIENT); - p->flow->flags &= ~FLOW_TC_APP_UPDATED; + if ((p->flags & PKT_STREAM_EST) || p->proto != IPPROTO_TCP) { + if (PKT_IS_TOSERVER(p)) { + if (PKT_IS_PSEUDOPKT(p) || (p->flow->flags & (FLOW_TS_APP_UPDATED))) { + AppLayerParserTransactionsCleanup(p->flow, STREAM_TOSERVER); + p->flow->flags &= ~FLOW_TS_APP_UPDATED; + } + } else { + if (PKT_IS_PSEUDOPKT(p) || (p->flow->flags & (FLOW_TC_APP_UPDATED))) { + AppLayerParserTransactionsCleanup(p->flow, STREAM_TOCLIENT); + p->flow->flags &= ~FLOW_TC_APP_UPDATED; + } } } - } else { SCLogDebug("not pseudo, no app update: skip"); } diff --git a/src/output-tx.c b/src/output-tx.c index cf9a1bd11d..751d538982 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -341,6 +341,9 @@ static TmEcode OutputTxLog(ThreadVars *tv, Packet *p, void *thread_data) SCLogDebug("not pseudo, no app update: skip"); return TM_ECODE_OK; } + if ((p->flags & PKT_STREAM_EST) == 0 && p->proto == IPPROTO_TCP) { + return TM_ECODE_OK; + } SCLogDebug("pseudo, or app update: run output"); OutputTxLoggerThreadData *op_thread_data = (OutputTxLoggerThreadData *)thread_data;