Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/detect-engine-build.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,8 @@ int SigPrepareStage1(DetectEngineCtx *de_ctx)
{
uint32_t cnt_iponly = 0;
uint32_t cnt_payload = 0;
uint32_t cnt_packet = 0;
uint32_t cnt_packet_stream = 0;
uint32_t cnt_applayer = 0;
uint32_t cnt_deonly = 0;

Expand Down Expand Up @@ -1752,6 +1754,12 @@ int SigPrepareStage1(DetectEngineCtx *de_ctx)
} else if (SignatureIsInspectingPayload(de_ctx, s) == 1) {
SCLogDebug("Signature %"PRIu32" is considered \"Payload inspecting\"", s->id);
cnt_payload++;
} else if (s->type == SIG_TYPE_PKT) {
SCLogDebug("Signature %" PRIu32 " is considered \"Packet inspecting\"", s->id);
cnt_packet++;
} else if (s->type == SIG_TYPE_PKT_STREAM) {
SCLogDebug("Signature %" PRIu32 " is considered \"Packet-stream inspecting\"", s->id);
cnt_packet_stream++;
} else if (s->type == SIG_TYPE_DEONLY) {
SCLogDebug("Signature %"PRIu32" is considered \"Decoder Event only\"", s->id);
cnt_deonly++;
Expand Down Expand Up @@ -1812,14 +1820,19 @@ int SigPrepareStage1(DetectEngineCtx *de_ctx)
if (strlen(de_ctx->config_prefix) > 0)
SCLogInfo("tenant id %d: %" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
"rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
" inspect application layer, %" PRIu32 " are decoder event only",
" inspect application layer, %" PRIu32 " are decoder event only, %" PRIu32
" are packet inspecting,"
" %" PRIu32 " are packet-stream inspecting",
de_ctx->tenant_id, de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer,
cnt_deonly);
cnt_deonly, cnt_packet, cnt_packet_stream);
else
SCLogInfo("%" PRIu32 " signatures processed. %" PRIu32 " are IP-only "
"rules, %" PRIu32 " are inspecting packet payload, %" PRIu32
" inspect application layer, %" PRIu32 " are decoder event only",
de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer, cnt_deonly);
" inspect application layer, %" PRIu32 " are decoder event only %" PRIu32
" are packet inspecting,"
" %" PRIu32 " are packet-stream inspecting",
de_ctx->sig_cnt, cnt_iponly, cnt_payload, cnt_applayer, cnt_deonly, cnt_packet,
cnt_packet_stream);

SCLogConfig("building signature grouping structure, stage 1: "
"preprocessing rules... complete");
Expand Down
2 changes: 1 addition & 1 deletion src/detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ static void DetectFlow(ThreadVars *tv,
skip = (p->flags & PKT_NOPACKET_INSPECTION || f->flags & (FLOW_ACTION_PASS));
}
if (skip) {
/* enfore prior accept:flow */
/* enforce prior accept:flow */
if (f->flags & FLOW_ACTION_ACCEPT) {
p->action |= ACTION_ACCEPT;
}
Expand Down
3 changes: 3 additions & 0 deletions src/stream-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,9 @@ static int StreamTcpPacketStateNone(
StreamTcpPacketSetState(p, ssn, TCP_ESTABLISHED);
SCLogDebug("ssn %p: =~ midstream picked ssn state is now "
"TCP_ESTABLISHED", ssn);
/* Since we're picking this session mid-stream, update the packet flag, so that detection
* will inspect it */
p->flags |= PKT_STREAM_EST;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense.

Wonder if we could do it in more generic way, like:

diff --git a/src/stream-tcp.c b/src/stream-tcp.c
index f7171fff2b..e2e257c4cc 100644
--- a/src/stream-tcp.c
+++ b/src/stream-tcp.c
@@ -5804,10 +5804,9 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
 
     skip:
         StreamTcpPacketCheckPostRst(ssn, p);
-
-        if (ssn->state >= TCP_ESTABLISHED) {
-            p->flags |= PKT_STREAM_EST;
-        }
+    }
+    if (ssn && ssn->state >= TCP_ESTABLISHED) {
+        p->flags |= PKT_STREAM_EST;
     }
 
     if (ssn != NULL) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This impacts the tests, must understand why and looks like the most correct results.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should mention I didn't test this :)

Copy link
Contributor Author

@jufajardini jufajardini Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If my understanding is correct -- that we would have this instead of what the PR suggests --, it doesn't to work, because, again, if I understood correctly, this is in an else that's called after checking for the session's existence. As we will call StreamTcpPacketStateNone after the first check, this means that we don't set PKT_STREAM_FLAG for the first packet, and thus still skip the first packet seen for the flow, in midstream session, with this approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/src/stream-tcp.c b/src/stream-tcp.c
index f7171fff2b..d218a14535 100644
--- a/src/stream-tcp.c
+++ b/src/stream-tcp.c
@@ -5731,6 +5731,7 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
         if (StreamTcpPacketStateNone(tv, p, stt, ssn) == -1) {
             goto error;
         }
+        ssn = (TcpSession *)p->flow->protoctx;
 
         if (ssn != NULL)
             SCLogDebug("ssn->alproto %"PRIu16"", p->flow->alproto);
@@ -5805,10 +5806,10 @@ int StreamTcpPacket (ThreadVars *tv, Packet *p, StreamTcpThread *stt,
     skip:
         StreamTcpPacketCheckPostRst(ssn, p);
 
-        if (ssn->state >= TCP_ESTABLISHED) {
+    }
+        if (ssn != NULL && ssn->state >= TCP_ESTABLISHED) {
             p->flags |= PKT_STREAM_EST;
         }
-    }
 
     if (ssn != NULL) {
         /* recalc the csum on the packet if it was modified */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, this isn't working locally for me. I'll review, probably did something wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's... the same situation, still, because we'll skip the packet flag setting for the first packet, again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? The ssn->state should now be set to established, right?


ssn->flags = STREAMTCP_FLAG_MIDSTREAM;
ssn->flags |= STREAMTCP_FLAG_MIDSTREAM_ESTABLISHED;
Expand Down
Loading