]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
streaming: make minimum region gap size configurable
authorVictor Julien <vjulien@oisf.net>
Mon, 9 Jan 2023 17:31:01 +0000 (18:31 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 18 Jan 2023 14:28:19 +0000 (15:28 +0100)
src/app-layer-htp-body.c
src/stream-tcp-reassemble.c
src/util-streaming-buffer.c
src/util-streaming-buffer.h

index 8d3065bda1cdf03180e62c870003a66f5ad474c9..5516514c38766f0bc7b85613b63f632660ee21ce 100644 (file)
@@ -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
index 8cde25e23f26db10070840523ac4bc60b98190e3..e647aaa6ecda6664e1a85de9d402f6b3817ea87a 100644 (file)
@@ -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;
index bd4610d71ebe061e5410efa0713ff39ec78b8698..06d4150ac7060e9d00e7b4204d507503f7feda30 100644 (file)
@@ -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);
 
index 0463b8028e1c33ea455c5b7262f579775f340f00..c7805ff8b2b240c1321b7092b8dadbf6112a5605 100644 (file)
 
 #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                                                               \