Skip to content

Commit

Permalink
stream/reassembly: optimize GetBlock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AntsKnows authored and victorjulien committed Sep 23, 2024
1 parent 18e0d23 commit 951bcff
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/stream-tcp-reassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,22 +1033,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);
Expand Down Expand Up @@ -1084,7 +1068,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;
Expand Down

0 comments on commit 951bcff

Please sign in to comment.