From: Victor Julien Date: Mon, 9 Jan 2023 17:31:01 +0000 (+0100) Subject: streaming: make minimum region gap size configurable X-Git-Tag: suricata-7.0.0-rc1~144 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2cfbefb6c6c6ed1ee680967e40140c9a9c182ac3;p=thirdparty%2Fsuricata.git streaming: make minimum region gap size configurable --- diff --git a/src/app-layer-htp-body.c b/src/app-layer-htp-body.c index 8d3065bda1..5516514c38 100644 --- a/src/app-layer-htp-body.c +++ b/src/app-layer-htp-body.c @@ -33,7 +33,8 @@ #include "util-streaming-buffer.h" #include "util-print.h" -static StreamingBufferConfig default_cfg = { 0, 3072, 1, HTPCalloc, HTPRealloc, HTPFree }; +static StreamingBufferConfig default_cfg = { 0, 3072, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, + HTPCalloc, HTPRealloc, HTPFree }; /** * \brief Append a chunk of body to the HtpBody struct diff --git a/src/stream-tcp-reassemble.c b/src/stream-tcp-reassemble.c index 8cde25e23f..e647aaa6ec 100644 --- a/src/stream-tcp-reassemble.c +++ b/src/stream-tcp-reassemble.c @@ -500,6 +500,7 @@ static int StreamTcpReassemblyConfig(bool quiet) stream_config.prealloc_segments = segment_prealloc; stream_config.sbcnf.buf_size = 2048; stream_config.sbcnf.max_regions = max_regions; + stream_config.sbcnf.region_gap = STREAMING_BUFFER_REGION_GAP_DEFAULT; stream_config.sbcnf.Calloc = ReassembleCalloc; stream_config.sbcnf.Realloc = StreamTcpReassembleRealloc; stream_config.sbcnf.Free = ReassembleFree; diff --git a/src/util-streaming-buffer.c b/src/util-streaming-buffer.c index bd4610d71e..06d4150ac7 100644 --- a/src/util-streaming-buffer.c +++ b/src/util-streaming-buffer.c @@ -23,7 +23,6 @@ #include "util-debug.h" static void ListRegions(StreamingBuffer *sb); -#define REGION_MAX_GAP 250000 #define DUMP_REGIONS 0 // set to 1 to dump a visual representation of the regions list and sbb tree. @@ -1071,8 +1070,8 @@ static inline bool RegionsIntersect(const StreamingBuffer *sb, const StreamingBu /* create the data range for the region, adding the max gap */ const uint64_t reg_o = - r->stream_offset > REGION_MAX_GAP ? (r->stream_offset - REGION_MAX_GAP) : 0; - const uint64_t reg_re = r->stream_offset + r->buf_size + REGION_MAX_GAP; + r->stream_offset > sb->cfg->region_gap ? (r->stream_offset - sb->cfg->region_gap) : 0; + const uint64_t reg_re = r->stream_offset + r->buf_size + sb->cfg->region_gap; SCLogDebug("r %p: %" PRIu64 "/%" PRIu64 " - adjusted %" PRIu64 "/%" PRIu64, r, r->stream_offset, r->stream_offset + r->buf_size, reg_o, reg_re); /* check if data range intersects with region range */ @@ -1707,7 +1706,7 @@ static void DumpSegment(StreamingBuffer *sb, StreamingBufferSegment *seg) static int StreamingBufferTest02(void) { - StreamingBufferConfig cfg = { 8, 24, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 24, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -1763,7 +1762,7 @@ static int StreamingBufferTest02(void) static int StreamingBufferTest03(void) { - StreamingBufferConfig cfg = { 8, 24, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 24, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -1818,7 +1817,7 @@ static int StreamingBufferTest03(void) static int StreamingBufferTest04(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -1909,7 +1908,7 @@ static int StreamingBufferTest04(void) /** \test lots of gaps in block list */ static int StreamingBufferTest06(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -1967,7 +1966,7 @@ static int StreamingBufferTest06(void) /** \test lots of gaps in block list */ static int StreamingBufferTest07(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -2025,7 +2024,7 @@ static int StreamingBufferTest07(void) /** \test lots of gaps in block list */ static int StreamingBufferTest08(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -2083,7 +2082,7 @@ static int StreamingBufferTest08(void) /** \test lots of gaps in block list */ static int StreamingBufferTest09(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); @@ -2141,7 +2140,7 @@ static int StreamingBufferTest09(void) /** \test lots of gaps in block list */ static int StreamingBufferTest10(void) { - StreamingBufferConfig cfg = { 8, 16, 1, NULL, NULL, NULL }; + StreamingBufferConfig cfg = { 8, 16, 1, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL }; StreamingBuffer *sb = StreamingBufferInit(&cfg); FAIL_IF(sb == NULL); diff --git a/src/util-streaming-buffer.h b/src/util-streaming-buffer.h index 0463b8028e..c7805ff8b2 100644 --- a/src/util-streaming-buffer.h +++ b/src/util-streaming-buffer.h @@ -61,10 +61,13 @@ #include "tree.h" +#define STREAMING_BUFFER_REGION_GAP_DEFAULT 262144 + typedef struct StreamingBufferConfig_ { uint32_t buf_slide; uint32_t buf_size; uint16_t max_regions; /**< max concurrent memory regions. 0 means no limit. */ + uint32_t region_gap; /**< max gap size before a new region will be created. */ void *(*Calloc)(size_t n, size_t size); void *(*Realloc)(void *ptr, size_t orig_size, size_t size); void (*Free)(void *ptr, size_t size); @@ -72,7 +75,7 @@ typedef struct StreamingBufferConfig_ { #define STREAMING_BUFFER_CONFIG_INITIALIZER \ { \ - 0, 0, 0, NULL, NULL, NULL, \ + 0, 0, 0, STREAMING_BUFFER_REGION_GAP_DEFAULT, NULL, NULL, NULL, \ } #define STREAMING_BUFFER_REGION_INIT \