]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output/http2: Multi-threaded EVE logging support
authorJeff Lucovsky <jeff@lucovsky.org>
Tue, 8 Dec 2020 13:38:18 +0000 (08:38 -0500)
committerVictor Julien <victor@inliniac.net>
Sat, 27 Feb 2021 17:46:02 +0000 (18:46 +0100)
This commit adds multi-threaded EVE logging support to the HTTP/2
logging path.

(cherry picked from commit 538fc58b37cb6633824fc2e167068b11d09a013a)

src/output-json-http2.c

index ead4b758f559401a7fc73e6a2f618d3fd935ac6f..ca9bae1df774da3791dc653ccc234bc8bf16431a 100644 (file)
@@ -61,6 +61,7 @@ typedef struct OutputHttp2Ctx_ {
 
 typedef struct JsonHttp2LogThread_ {
     OutputHttp2Ctx *http2log_ctx;
+    LogFileCtx *file_ctx;
     MemBuffer *buffer;
 } JsonHttp2LogThread;
 
@@ -101,7 +102,7 @@ static int JsonHttp2Logger(ThreadVars *tv, void *thread_data, const Packet *p,
         goto end;
     }
     jb_close(js);
-    OutputJsonBuilderBuffer(js, http2_ctx->file_ctx, &aft->buffer);
+    OutputJsonBuilderBuffer(js, aft->file_ctx, &aft->buffer);
 end:
     jb_free(js);
     return 0;
@@ -109,29 +110,37 @@ end:
 
 static TmEcode JsonHttp2LogThreadInit(ThreadVars *t, const void *initdata, void **data)
 {
-    JsonHttp2LogThread *aft = SCMalloc(sizeof(JsonHttp2LogThread));
+    JsonHttp2LogThread *aft = SCCalloc(1, sizeof(JsonHttp2LogThread));
     if (unlikely(aft == NULL))
         return TM_ECODE_FAILED;
-    memset(aft, 0, sizeof(JsonHttp2LogThread));
 
     if(initdata == NULL)
     {
         SCLogDebug("Error getting context for EveLogHTTP2.  \"initdata\" argument NULL");
-        SCFree(aft);
-        return TM_ECODE_FAILED;
+        goto error_exit;
     }
 
-    /* Use the Ouptut Context (file pointer and mutex) */
+    /* Use the Output Context (file pointer and mutex) */
     aft->http2log_ctx = ((OutputCtx *)initdata)->data;
+    aft->file_ctx = LogFileEnsureExists(aft->http2log_ctx->file_ctx, t->id);
+    if (!aft->file_ctx) {
+        goto error_exit;
+    }
 
     aft->buffer = MemBufferCreateNew(JSON_OUTPUT_BUFFER_SIZE);
     if (aft->buffer == NULL) {
-        SCFree(aft);
-        return TM_ECODE_FAILED;
+        goto error_exit;
     }
 
     *data = (void *)aft;
     return TM_ECODE_OK;
+
+error_exit:
+    if (aft->buffer != NULL) {
+        MemBufferFree(aft->buffer);
+    }
+    SCFree(aft);
+    return TM_ECODE_FAILED;
 }
 
 static TmEcode JsonHttp2LogThreadDeinit(ThreadVars *t, void *data)