|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* Copyright (C) 2020 Open Information Security Foundation
|
|
|
|
|
/* Copyright (C) 2020-2021 Open Information Security Foundation
|
|
|
|
|
*
|
|
|
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
|
|
|
* the GNU General Public License version 2 as published by the Free
|
|
|
|
@ -54,8 +54,7 @@
|
|
|
|
|
#define MODULE_NAME "LogHttp2Log"
|
|
|
|
|
|
|
|
|
|
typedef struct OutputHttp2Ctx_ {
|
|
|
|
|
LogFileCtx *file_ctx;
|
|
|
|
|
OutputJsonCommonSettings cfg;
|
|
|
|
|
OutputJsonCtx *eve_ctx;
|
|
|
|
|
} OutputHttp2Ctx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -82,18 +81,16 @@ static int JsonHttp2Logger(ThreadVars *tv, void *thread_data, const Packet *p,
|
|
|
|
|
Flow *f, void *state, void *txptr, uint64_t tx_id)
|
|
|
|
|
{
|
|
|
|
|
JsonHttp2LogThread *aft = (JsonHttp2LogThread *)thread_data;
|
|
|
|
|
OutputHttp2Ctx *http2_ctx = aft->http2log_ctx;
|
|
|
|
|
|
|
|
|
|
if (unlikely(state == NULL)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JsonBuilder *js = CreateEveHeaderWithTxId(p, LOG_DIR_FLOW, "http", NULL, tx_id);
|
|
|
|
|
JsonBuilder *js = CreateEveHeaderWithTxId(
|
|
|
|
|
p, LOG_DIR_FLOW, "http", NULL, tx_id, aft->http2log_ctx->eve_ctx);
|
|
|
|
|
if (unlikely(js == NULL))
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
EveAddCommonOptions(&http2_ctx->cfg, p, f, js);
|
|
|
|
|
|
|
|
|
|
/* reset */
|
|
|
|
|
MemBufferReset(aft->buffer);
|
|
|
|
|
|
|
|
|
@ -122,7 +119,7 @@ static TmEcode JsonHttp2LogThreadInit(ThreadVars *t, const void *initdata, void
|
|
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
aft->file_ctx = LogFileEnsureExists(aft->http2log_ctx->eve_ctx->file_ctx, t->id);
|
|
|
|
|
if (!aft->file_ctx) {
|
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
|
|
|
@ -158,55 +155,6 @@ static TmEcode JsonHttp2LogThreadDeinit(ThreadVars *t, void *data)
|
|
|
|
|
return TM_ECODE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OutputHttp2LogDeinit(OutputCtx *output_ctx)
|
|
|
|
|
{
|
|
|
|
|
OutputHttp2Ctx *http2_ctx = output_ctx->data;
|
|
|
|
|
LogFileCtx *logfile_ctx = http2_ctx->file_ctx;
|
|
|
|
|
LogFileFreeCtx(logfile_ctx);
|
|
|
|
|
SCFree(http2_ctx);
|
|
|
|
|
SCFree(output_ctx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_LOG_FILENAME "http2.json"
|
|
|
|
|
static OutputInitResult OutputHttp2LogInit(ConfNode *conf)
|
|
|
|
|
{
|
|
|
|
|
OutputInitResult result = { NULL, false };
|
|
|
|
|
LogFileCtx *file_ctx = LogFileNewCtx();
|
|
|
|
|
if(file_ctx == NULL) {
|
|
|
|
|
SCLogError(SC_ERR_HTTP2_LOG_GENERIC, "couldn't create new file_ctx");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
|
|
|
|
|
LogFileFreeCtx(file_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputHttp2Ctx *http2_ctx = SCMalloc(sizeof(OutputHttp2Ctx));
|
|
|
|
|
if (unlikely(http2_ctx == NULL)) {
|
|
|
|
|
LogFileFreeCtx(file_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
|
|
|
|
|
if (unlikely(output_ctx == NULL)) {
|
|
|
|
|
LogFileFreeCtx(file_ctx);
|
|
|
|
|
SCFree(http2_ctx);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http2_ctx->file_ctx = file_ctx;
|
|
|
|
|
|
|
|
|
|
output_ctx->data = http2_ctx;
|
|
|
|
|
output_ctx->DeInit = OutputHttp2LogDeinit;
|
|
|
|
|
|
|
|
|
|
AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP2);
|
|
|
|
|
|
|
|
|
|
result.ctx = output_ctx;
|
|
|
|
|
result.ok = true;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OutputHttp2LogDeinitSub(OutputCtx *output_ctx)
|
|
|
|
|
{
|
|
|
|
|
OutputHttp2Ctx *http2_ctx = output_ctx->data;
|
|
|
|
@ -229,8 +177,7 @@ static OutputInitResult OutputHttp2LogInitSub(ConfNode *conf, OutputCtx *parent_
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http2_ctx->file_ctx = ojc->file_ctx;
|
|
|
|
|
http2_ctx->cfg = ojc->cfg;
|
|
|
|
|
http2_ctx->eve_ctx = ojc;
|
|
|
|
|
|
|
|
|
|
output_ctx->data = http2_ctx;
|
|
|
|
|
output_ctx->DeInit = OutputHttp2LogDeinitSub;
|
|
|
|
@ -244,13 +191,6 @@ static OutputInitResult OutputHttp2LogInitSub(ConfNode *conf, OutputCtx *parent_
|
|
|
|
|
|
|
|
|
|
void JsonHttp2LogRegister (void)
|
|
|
|
|
{
|
|
|
|
|
/* register as separate module */
|
|
|
|
|
OutputRegisterTxModuleWithProgress(LOGGER_JSON_HTTP2,
|
|
|
|
|
MODULE_NAME, "http2-json-log",
|
|
|
|
|
OutputHttp2LogInit, ALPROTO_HTTP2, JsonHttp2Logger,
|
|
|
|
|
HTTP2StateClosed, HTTP2StateClosed,
|
|
|
|
|
JsonHttp2LogThreadInit, JsonHttp2LogThreadDeinit, NULL);
|
|
|
|
|
|
|
|
|
|
/* also register as child of eve-log */
|
|
|
|
|
OutputRegisterTxSubModuleWithProgress(LOGGER_JSON_HTTP2,
|
|
|
|
|
"eve-log", MODULE_NAME, "eve-log.http2",
|
|
|
|
|