]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: add util function to get 'usable' data
authorVictor Julien <vjulien@oisf.net>
Sat, 18 Dec 2021 18:11:40 +0000 (19:11 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 17 Jan 2022 18:32:29 +0000 (19:32 +0100)
src/stream-tcp-reassemble.c
src/stream-tcp.h

index f8c177ba4e73b644ffc4621c5bcb4b152927ec25..ad2e30310d28e1873d11e59ab454a6cb81b20d00 100644 (file)
@@ -331,6 +331,20 @@ static inline uint64_t GetAbsLastAck(const TcpStream *stream)
     }
 }
 
+uint64_t StreamTcpGetAcked(const TcpStream *stream)
+{
+    return GetAbsLastAck(stream);
+}
+
+uint64_t StreamTcpGetUsable(const TcpStream *stream, const bool eof)
+{
+    uint64_t right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
+    if (!eof && StreamTcpInlineMode() == FALSE) {
+        right_edge = MIN(GetAbsLastAck(stream), right_edge);
+    }
+    return right_edge;
+}
+
 #ifdef UNITTESTS
 /** \internal
  *  \brief check if segments falls before stream 'offset' */
index 04e3b78edc608a85d397e62c3425985d5e61a6a3..3b4f4fc8a4054d6a30a3b3379778ca12ec287a9b 100644 (file)
@@ -198,5 +198,8 @@ int TcpSessionPacketSsnReuse(const Packet *p, const Flow *f, const void *tcp_ssn
 void StreamTcpUpdateAppLayerProgress(TcpSession *ssn, char direction,
         const uint32_t progress);
 
+uint64_t StreamTcpGetAcked(const TcpStream *stream);
+uint64_t StreamTcpGetUsable(const TcpStream *stream, const bool eof);
+
 #endif /* __STREAM_TCP_H__ */