streaming: make minimum region gap size configurable

pull/8406/head
Victor Julien 3 years ago
parent 8e9dac99f3
commit 2cfbefb6c6

@ -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

@ -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;

@ -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);

@ -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 \

Loading…
Cancel
Save