]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: flag ACKs that ack segments after next_seq
authorVictor Julien <vjulien@oisf.net>
Wed, 22 Feb 2023 20:14:23 +0000 (21:14 +0100)
committerVictor Julien <vjulien@oisf.net>
Fri, 24 Feb 2023 09:45:38 +0000 (10:45 +0100)
Avoid this for async streams.

src/stream-tcp-private.h
src/stream-tcp.c

index 25f10b353dd7233ec9c80282e156e82cd68e3c29..e006596ac1971aa345a9f9274eb5a2e94059edea 100644 (file)
@@ -308,6 +308,7 @@ typedef struct TcpSession_ {
 #define STREAM_PKT_FLAG_EVENTSET                BIT_U16(6)
 #define STREAM_PKT_FLAG_DUP_ACK                 BIT_U16(7)
 #define STREAM_PKT_FLAG_DSACK                   BIT_U16(8)
+#define STREAM_PKT_FLAG_ACK_UNSEEN_DATA         BIT_U16(9)
 
 #define STREAM_PKT_FLAG_SET(p, f) (p)->tcpvars.stream_pkt_flags |= (f)
 
index f6789ae23f1454b05841270ecca65fd1a75d6967..c694007000544ca09fa6025f8d90e44740ce6fb2 100644 (file)
@@ -2626,8 +2626,14 @@ static int HandleEstablishedPacketToServer(
                     ssn->server.window);
 
         /* Check if the ACK value is sane and inside the window limit */
-        if (p->tcph->th_flags & TH_ACK)
+        if (p->tcph->th_flags & TH_ACK) {
             StreamTcpUpdateLastAck(ssn, &ssn->server, TCP_GET_ACK(p));
+            if ((ssn->flags & STREAMTCP_FLAG_ASYNC) == 0 &&
+                    SEQ_GT(ssn->server.last_ack, ssn->server.next_seq)) {
+                STREAM_PKT_FLAG_SET(p, STREAM_PKT_FLAG_ACK_UNSEEN_DATA);
+            }
+        }
+
         SCLogDebug("ack %u last_ack %u next_seq %u", TCP_GET_ACK(p), ssn->server.last_ack, ssn->server.next_seq);
 
         if (ssn->flags & STREAMTCP_FLAG_TIMESTAMP) {
@@ -2756,8 +2762,13 @@ static int HandleEstablishedPacketToClient(
         SCLogDebug("ssn %p: ssn->client.window %"PRIu32"", ssn,
                     ssn->client.window);
 
-        if (p->tcph->th_flags & TH_ACK)
+        if (p->tcph->th_flags & TH_ACK) {
             StreamTcpUpdateLastAck(ssn, &ssn->client, TCP_GET_ACK(p));
+            if ((ssn->flags & STREAMTCP_FLAG_ASYNC) == 0 &&
+                    SEQ_GT(ssn->client.last_ack, ssn->client.next_seq)) {
+                STREAM_PKT_FLAG_SET(p, STREAM_PKT_FLAG_ACK_UNSEEN_DATA);
+            }
+        }
 
         if (ssn->flags & STREAMTCP_FLAG_TIMESTAMP) {
             StreamTcpHandleTimestamp(ssn, p);