From: Jeff Lucovsky Date: Tue, 8 Dec 2020 13:38:18 +0000 (-0500) Subject: output/http2: Multi-threaded EVE logging support X-Git-Tag: suricata-7.0.0-beta1~1757 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=538fc58b37cb6633824fc2e167068b11d09a013a;p=thirdparty%2Fsuricata.git output/http2: Multi-threaded EVE logging support This commit adds multi-threaded EVE logging support to the HTTP/2 logging path. --- diff --git a/src/output-json-http2.c b/src/output-json-http2.c index ead4b758f5..ca9bae1df7 100644 --- a/src/output-json-http2.c +++ b/src/output-json-http2.c @@ -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)