]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream/segments: optimize overlap tree operations
authorVictor Julien <victor@inliniac.net>
Mon, 27 Aug 2018 10:26:11 +0000 (12:26 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 17 Sep 2018 06:27:24 +0000 (08:27 +0200)
Now that with the RBTREE we have a properly sorted Segment tree,
where with exact SEQ matches the tree is sorted by payload_len
smallest to largest, we can avoid walking backwards when checking
for overlaps. Our direct RB_PREV either overlaps or not and that
is a reliable verdict for the rest of the tree.

src/stream-tcp-list.c

index ea8c4f788a5f2c2c819cf13b68095952a6b6315c..1b6799b40a938fb1fadd3a7f672f50ed67cadf56 100644 (file)
@@ -414,8 +414,6 @@ static int DoHandleDataOverlap(TcpStream *stream, const TcpSegment *list,
     return (check_overlap_different_data && data_is_different);
 }
 
-#define MAX_IP_DATA (uint32_t)(65536 - 40) // min ip header and min tcp header
-
 /** \internal
  *  \brief walk segment tree backwards to see if there are overlaps
  *
@@ -440,7 +438,7 @@ static int DoHandleDataCheckBackwards(TcpStream *stream,
         if (SEQ_LEQ(SEG_SEQ_RIGHT_EDGE(tree_seg), stream->base_seq)) {
             // segment entirely before base_seq
             ;
-        } else if (SEQ_LEQ(tree_seg->seq + MAX_IP_DATA, seg->seq)) {
+        } else if (SEQ_LEQ(tree_seg->seq + tree_seg->payload_len, seg->seq)) {
             SCLogDebug("list segment too far to the left, no more overlap will be found");
             break;
         } else if (SEQ_GT(SEG_SEQ_RIGHT_EDGE(tree_seg), seg->seq)) {