]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: improve needs reassembly code
authorVictor Julien <victor@inliniac.net>
Tue, 28 Feb 2017 11:44:02 +0000 (12:44 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 20 Apr 2017 15:41:11 +0000 (17:41 +0200)
src/flow-timeout.c
src/stream-tcp-reassemble.c
src/stream-tcp.h

index d7ccf8cf829f6e695456abc8eb89e999a4038bca..eb277295f4874a54291030be935ba1b5bbdcfb82 100644 (file)
@@ -304,8 +304,8 @@ int FlowForceReassemblyNeedReassembly(Flow *f, int *server, int *client)
         SCReturnInt(0);
     }
 
-    *client = StreamNeedsReassembly(ssn, 0);
-    *server = StreamNeedsReassembly(ssn, 1);
+    *client = StreamNeedsReassembly(ssn, STREAM_TOSERVER);
+    *server = StreamNeedsReassembly(ssn, STREAM_TOCLIENT);
 
     /* if state is not fully closed we assume that we haven't fully
      * inspected the app layer state yet */
index df208658adf77c953c502fc9c6764cd6744882b1..0366789f5bf24674a66892e786f69cc98ce3117f 100644 (file)
@@ -762,14 +762,13 @@ static int StreamTcpReassembleRawCheckLimit(const TcpSession *ssn,
 /**
  *  \brief see what if any work the TCP session still needs
  */
-int StreamNeedsReassembly(TcpSession *ssn, int direction)
+int StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction)
 {
-    TcpStream *stream = NULL;
+    const TcpStream *stream = NULL;
 #ifdef DEBUG
     char *dirstr = NULL;
 #endif
-    /* TODO use STREAM_TOCLIENT/STREAM_TOSERVER */
-    if (direction == 0) {
+    if (direction == STREAM_TOSERVER) {
         stream = &ssn->client;
 #ifdef DEBUG
         dirstr = "client";
@@ -796,31 +795,25 @@ int StreamNeedsReassembly(TcpSession *ssn, int direction)
         use_raw = 0;
     }
 
-    if (stream->seg_list_tail != NULL) {
-        uint64_t right_edge = TCP_SEG_OFFSET(stream->seg_list_tail) +
-                              TCP_SEG_LEN(stream->seg_list_tail);
+    uint64_t right_edge = STREAM_BASE_OFFSET(stream) + stream->sb.buf_offset;
 
-        SCLogDebug("%s: list %p app %"PRIu64" (use: %s), raw %"PRIu64" (use: %s). Stream right edge: %"PRIu64,
-                dirstr,
-                stream->seg_list,
-                STREAM_APP_PROGRESS(stream), use_app ? "yes" : "no",
-                STREAM_RAW_PROGRESS(stream), use_raw ? "yes" : "no",
-                right_edge);
-
-        if (use_raw) {
-            if (right_edge > STREAM_RAW_PROGRESS(stream)) {
-                SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr);
-                return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
-            }
+    SCLogDebug("%s: list %p app %"PRIu64" (use: %s), raw %"PRIu64" (use: %s). Stream right edge: %"PRIu64,
+            dirstr,
+            stream->seg_list,
+            STREAM_APP_PROGRESS(stream), use_app ? "yes" : "no",
+            STREAM_RAW_PROGRESS(stream), use_raw ? "yes" : "no",
+            right_edge);
+    if (use_raw) {
+        if (right_edge > STREAM_RAW_PROGRESS(stream)) {
+            SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr);
+            return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
         }
-        if (use_app) {
-            if (right_edge > STREAM_APP_PROGRESS(stream)) {
-                SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr);
-                return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
-            }
+    }
+    if (use_app) {
+        if (right_edge > STREAM_APP_PROGRESS(stream)) {
+            SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION", dirstr);
+            return STREAM_HAS_UNPROCESSED_SEGMENTS_NEED_ONLY_DETECTION;
         }
-    } else {
-        SCLogDebug("%s: no list", dirstr);
     }
 
     SCLogDebug("%s: STREAM_HAS_UNPROCESSED_SEGMENTS_NONE", dirstr);
index 11db4a0c827738b2008fbd59ad2720db8113e01d..86646fbed97e56b1293a1756a3e1b1dd566e61db 100644 (file)
@@ -187,7 +187,7 @@ enum {
 };
 
 TmEcode StreamTcp (ThreadVars *, Packet *, void *, PacketQueue *, PacketQueue *);
-int StreamNeedsReassembly(TcpSession *ssn, int direction);
+int StreamNeedsReassembly(const TcpSession *ssn, uint8_t direction);
 TmEcode StreamTcpThreadInit(ThreadVars *, void *, void **);
 TmEcode StreamTcpThreadDeinit(ThreadVars *tv, void *data);
 void StreamTcpRegisterTests (void);