From 00e65e3cfac53cc018d4a89c2377bd379bd0f192 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 27 Aug 2018 12:26:11 +0200 Subject: [PATCH] stream/segments: optimize overlap tree operations 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/stream-tcp-list.c b/src/stream-tcp-list.c index ea8c4f788a..1b6799b40a 100644 --- a/src/stream-tcp-list.c +++ b/src/stream-tcp-list.c @@ -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)) { -- 2.47.2