From: Noah Liu Date: Mon, 23 Sep 2024 03:07:47 +0000 (+0800) Subject: stream/reassembly: optimize GetBlock X-Git-Tag: suricata-7.0.8~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ede115fbc1b9f3969a681eff37b40fa44bdb3657;p=thirdparty%2Fsuricata.git stream/reassembly: optimize GetBlock Current GetBlock degrees the sbb search from rb tree to line, which costs much cpu time, and could be replaced by SBB_RB_FIND_INCLUSIVE. It reduces time complexity from O(nlogn) to O(logn). Ticket: 7208. (cherry picked from commit 951bcff9702f1f39c00293d68d286fd77008b037) --- diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index a1f8b8ea68..d6d05410fe 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -1037,22 +1037,6 @@ static void GetSessionSize(TcpSession *ssn, Packet *p) } #endif -static StreamingBufferBlock *GetBlock(const StreamingBuffer *sb, const uint64_t offset) -{ - StreamingBufferBlock *blk = sb->head; - if (blk == NULL) - return NULL; - - for ( ; blk != NULL; blk = SBB_RB_NEXT(blk)) { - if (blk->offset >= offset) - return blk; - else if ((blk->offset + blk->len) > offset) { - return blk; - } - } - return NULL; -} - static inline bool GapAhead(const TcpStream *stream, StreamingBufferBlock *cur_blk) { StreamingBufferBlock *nblk = SBB_RB_NEXT(cur_blk); @@ -1088,7 +1072,8 @@ static bool GetAppBuffer(const TcpStream *stream, const uint8_t **data, uint32_t *data_len = mydata_len; } else { SCLogDebug("block mode"); - StreamingBufferBlock *blk = GetBlock(&stream->sb, offset); + StreamingBufferBlock key = { .offset = offset, .len = 0 }; + StreamingBufferBlock *blk = SBB_RB_FIND_INCLUSIVE((struct SBB *)&stream->sb.sbb_tree, &key); if (blk == NULL) { *data = NULL; *data_len = 0;