]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: wait for protocol detection to complete
authorVictor Julien <victor@inliniac.net>
Tue, 24 Sep 2013 17:36:51 +0000 (19:36 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 2 Dec 2013 14:50:04 +0000 (15:50 +0100)
Wait for protocol detection to complete before removing segments
from the list.

src/stream-tcp-reassemble.c

index 9c97161e5c14a4cd6b9d05079a1e3f5f908354ea..0ee90070e82d72bfe6b4326798a56c888f959fcb 100644 (file)
@@ -3052,26 +3052,31 @@ static int StreamTcpReassembleRaw (TcpReassemblyThreadCtx *ra_ctx,
                 seg, seg->seq, seg->payload_len,
                 (uint32_t)(seg->seq + seg->payload_len));
 
-        /* Remove the segments which are either completely before the
-           ra_base_seq or if they are beyond ra_base_seq, but the segment offset
-           from which we need to copy in to smsg is beyond the stream->last_ack.
-           As we are copying until the stream->last_ack only */
-        if (SEQ_LEQ((seg->seq + seg->payload_len), ra_base_seq+1))
+        if ((p->flow->flags & FLOW_NO_APPLAYER_INSPECTION) ||
+            (stream->flags & STREAMTCP_STREAM_FLAG_APPPROTO_DETECTION_COMPLETED) ||
+            (stream->flags & STREAMTCP_STREAM_FLAG_GAP))
         {
-            if (StreamTcpReturnSegmentCheck(ssn, stream, seg) == 0) {
-                seg = seg->next;
-                continue;
-            }
+            /* Remove the segments which are either completely before the
+               ra_base_seq or if they are beyond ra_base_seq, but the segment offset
+               from which we need to copy in to smsg is beyond the stream->last_ack.
+               As we are copying until the stream->last_ack only */
+            if (SEQ_LEQ((seg->seq + seg->payload_len), ra_base_seq+1))
+            {
+                if (StreamTcpReturnSegmentCheck(ssn, stream, seg) == 0) {
+                    seg = seg->next;
+                    continue;
+                }
 
-            SCLogDebug("removing pre ra_base_seq %"PRIu32" seg %p seq %"PRIu32""
+                SCLogDebug("removing pre ra_base_seq %"PRIu32" seg %p seq %"PRIu32""
                         " len %"PRIu16"", ra_base_seq, seg, seg->seq,
                         seg->payload_len);
 
-            TcpSegment *next_seg = seg->next;
-            StreamTcpRemoveSegmentFromStream(stream, seg);
-            StreamTcpSegmentReturntoPool(seg);
-            seg = next_seg;
-            continue;
+                TcpSegment *next_seg = seg->next;
+                StreamTcpRemoveSegmentFromStream(stream, seg);
+                StreamTcpSegmentReturntoPool(seg);
+                seg = next_seg;
+                continue;
+            }
         }
 
         /* if app layer protocol has been detected, then remove all the segments