]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
stream: configurable stream chunk prealloc 801/head
authorVictor Julien <victor@inliniac.net>
Tue, 28 Jan 2014 16:13:05 +0000 (17:13 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 28 Jan 2014 16:13:05 +0000 (17:13 +0100)
The stream chunk pool contains preallocating stream chunks (StreamMsg).
These are used for raw reassembly, used in raw content inspection by
the detection engine. The default setting so far has been 250, which
was hardcoded. This meant that in setups that needed more, allocs and
frees would be happen constantly.

This patch introduces a yaml option to set the 'prealloc' value in the
pool. The default is still 250.

stream.reassembly.chunk-prealloc

Related to feature #1093.

src/stream-tcp-reassemble.c
src/stream.c
src/stream.h

index a1b16f83870ec1f1d1cb425fec14cf56e761e7a4..b3133c27a51a8b8faa5ce48aa628a56748ffdbbf 100644 (file)
@@ -439,6 +439,22 @@ int StreamTcpReassemblyConfig(char quiet)
     segment_pool_mutex = my_segment_lock;
     segment_pool_pktsizes = my_segment_pktsizes;
     segment_pool_num = npools;
+
+    uint32_t stream_chunk_prealloc = 250;
+    ConfNode *chunk = ConfGetNode("stream.reassembly.chunk-prealloc");
+    if (chunk) {
+        uint32_t prealloc = 0;
+        if (ByteExtractStringUint32(&prealloc, 10, strlen(chunk->val), chunk->val) == -1)
+        {
+            SCLogError(SC_ERR_INVALID_ARGUMENT, "chunk-prealloc of "
+                    "%s is invalid", chunk->val);
+            return -1;
+        }
+        stream_chunk_prealloc = prealloc;
+    }
+    if (!quiet)
+        SCLogInfo("stream.reassembly \"chunk-prealloc\": %u", stream_chunk_prealloc);
+    StreamMsgQueuesInit(stream_chunk_prealloc);
     return 0;
 }
 
@@ -449,8 +465,6 @@ int StreamTcpReassembleInit(char quiet)
 
     if (StreamTcpReassemblyConfig(quiet) < 0)
         return -1;
-    StreamMsgQueuesInit();
-
 #ifdef DEBUG
     SCMutexInit(&segment_pool_memuse_mutex, NULL);
     SCMutexInit(&segment_pool_cnt_mutex, NULL);
index d6bc3877d91e149292463774fc587002d2d87cc5..962530b0b4cc3b010f63ea48f588d9eb0dc594db 100644 (file)
@@ -161,12 +161,14 @@ void StreamMsgPoolFree(void *ptr) {
     }
 }
 
-void StreamMsgQueuesInit(void) {
+void StreamMsgQueuesInit(uint32_t prealloc) {
 #ifdef DEBUG
     SCMutexInit(&stream_pool_memuse_mutex, NULL);
 #endif
     SCMutexLock(&stream_msg_pool_mutex);
-    stream_msg_pool = PoolInit(0,250,0,StreamMsgPoolAlloc,StreamMsgInit,NULL,NULL,StreamMsgPoolFree);
+    stream_msg_pool = PoolInit(0, prealloc, 0,
+            StreamMsgPoolAlloc,StreamMsgInit,
+            NULL,NULL,StreamMsgPoolFree);
     if (stream_msg_pool == NULL)
         exit(EXIT_FAILURE); /* XXX */
     SCMutexUnlock(&stream_msg_pool_mutex);
index c8453c931cbf0f9744d6fbe8da4c866739c70511..6a5b754275430db305dff55f4685ef6b16d9e54f 100644 (file)
@@ -56,7 +56,7 @@ typedef struct StreamMsgQueue_ {
 } StreamMsgQueue;
 
 /* prototypes */
-void StreamMsgQueuesInit(void);
+void StreamMsgQueuesInit(uint32_t prealloc);
 void StreamMsgQueuesDeinit(char);
 
 StreamMsg *StreamMsgGetFromPool(void);