diff --git a/src/output-flow.c b/src/output-flow.c index 20d5d7d423..6113631d9f 100644 --- a/src/output-flow.c +++ b/src/output-flow.c @@ -47,17 +47,18 @@ typedef struct OutputFlowLogger_ { OutputCtx *output_ctx; struct OutputFlowLogger_ *next; const char *name; - TmmId module_id; + TmEcode (*ThreadInit)(ThreadVars *, void *, void **); + TmEcode (*ThreadDeinit)(ThreadVars *, void *); + void (*ThreadExitPrintStats)(ThreadVars *, void *); } OutputFlowLogger; static OutputFlowLogger *list = NULL; -int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, OutputCtx *output_ctx) +int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, + OutputCtx *output_ctx, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { - int module_id = TmModuleGetIdByName(name); - if (module_id < 0) - return -1; - OutputFlowLogger *op = SCMalloc(sizeof(*op)); if (op == NULL) return -1; @@ -66,7 +67,9 @@ int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, OutputCtx *ou op->LogFunc = LogFunc; op->output_ctx = output_ctx; op->name = name; - op->module_id = (TmmId) module_id; + op->ThreadInit = ThreadInit; + op->ThreadDeinit = ThreadDeinit; + op->ThreadExitPrintStats = ThreadExitPrintStats; if (list == NULL) list = op; @@ -106,9 +109,9 @@ TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f) BUG_ON(logger->LogFunc == NULL); SCLogDebug("logger %p", logger); - //PACKET_PROFILING_TMM_START(p, logger->module_id); + //PACKET_PROFILING_LOGGER_START(p, logger->module_id); logger->LogFunc(tv, store->thread_data, f); - //PACKET_PROFILING_TMM_END(p, logger->module_id); + //PACKET_PROFILING_LOGGER_END(p, logger->module_id); logger = logger->next; store = store->next; @@ -136,16 +139,9 @@ TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void *initdata, void **data) OutputFlowLogger *logger = list; while (logger) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadInit) { + if (logger->ThreadInit) { void *retptr = NULL; - if (tm_module->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { + if (logger->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) { OutputLoggerThreadStore *ts = SCMalloc(sizeof(*ts)); /* todo */ BUG_ON(ts == NULL); memset(ts, 0x00, sizeof(*ts)); @@ -179,15 +175,8 @@ TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data) OutputFlowLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadDeinit) { - tm_module->ThreadDeinit(tv, store->thread_data); + if (logger->ThreadDeinit) { + logger->ThreadDeinit(tv, store->thread_data); } OutputLoggerThreadStore *next_store = store->next; @@ -207,15 +196,8 @@ void OutputFlowLogExitPrintStats(ThreadVars *tv, void *thread_data) OutputFlowLogger *logger = list; while (logger && store) { - TmModule *tm_module = TmModuleGetByName((char *)logger->name); - if (tm_module == NULL) { - SCLogError(SC_ERR_INVALID_ARGUMENT, - "TmModuleGetByName for %s failed", logger->name); - exit(EXIT_FAILURE); - } - - if (tm_module->ThreadExitPrintStats) { - tm_module->ThreadExitPrintStats(tv, store->thread_data); + if (logger->ThreadExitPrintStats) { + logger->ThreadExitPrintStats(tv, store->thread_data); } logger = logger->next; diff --git a/src/output-flow.h b/src/output-flow.h index af093e3eb0..26bfc32450 100644 --- a/src/output-flow.h +++ b/src/output-flow.h @@ -36,7 +36,9 @@ typedef int (*FlowLogger)(ThreadVars *, void *thread_data, Flow *f); */ //typedef int (*TxLogCondition)(ThreadVars *, const Packet *); -int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, OutputCtx *); +int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, + OutputCtx *, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputFlowShutdown(void); diff --git a/src/output-json-flow.c b/src/output-json-flow.c index 1ce4b6f2f7..a55faa3115 100644 --- a/src/output-json-flow.c +++ b/src/output-json-flow.c @@ -450,34 +450,22 @@ static TmEcode JsonFlowLogThreadDeinit(ThreadVars *t, void *data) void TmModuleJsonFlowLogRegister (void) { - tmm_modules[TMM_JSONFLOWLOG].name = "JsonFlowLog"; - tmm_modules[TMM_JSONFLOWLOG].ThreadInit = JsonFlowLogThreadInit; - tmm_modules[TMM_JSONFLOWLOG].ThreadDeinit = JsonFlowLogThreadDeinit; - tmm_modules[TMM_JSONFLOWLOG].RegisterTests = NULL; - tmm_modules[TMM_JSONFLOWLOG].cap_flags = 0; - tmm_modules[TMM_JSONFLOWLOG].flags = TM_FLAG_LOGAPI_TM; - /* register as separate module */ OutputRegisterFlowModule("JsonFlowLog", "flow-json-log", - OutputFlowLogInit, JsonFlowLogger); + OutputFlowLogInit, JsonFlowLogger, JsonFlowLogThreadInit, + JsonFlowLogThreadDeinit, NULL); /* also register as child of eve-log */ OutputRegisterFlowSubModule("eve-log", "JsonFlowLog", "eve-log.flow", - OutputFlowLogInitSub, JsonFlowLogger); + OutputFlowLogInitSub, JsonFlowLogger, JsonFlowLogThreadInit, + JsonFlowLogThreadDeinit, NULL); } #else -static TmEcode OutputJsonThreadInit(ThreadVars *t, void *initdata, void **data) -{ - SCLogInfo("Can't init JSON output - JSON support was disabled during build."); - return TM_ECODE_FAILED; -} - void TmModuleJsonFlowLogRegister (void) { - tmm_modules[TMM_JSONFLOWLOG].name = "JsonFlowLog"; - tmm_modules[TMM_JSONFLOWLOG].ThreadInit = OutputJsonThreadInit; + SCLogInfo("Can't register JSON output - JSON support was disabled during build."); } #endif diff --git a/src/output-json-netflow.c b/src/output-json-netflow.c index 52ff013cad..e131588bb6 100644 --- a/src/output-json-netflow.c +++ b/src/output-json-netflow.c @@ -441,11 +441,11 @@ void TmModuleJsonNetFlowLogRegister (void) /* register as separate module */ OutputRegisterFlowModule("JsonNetFlowLog", "netflow-json-log", - OutputNetFlowLogInit, JsonNetFlowLogger); + OutputNetFlowLogInit, JsonNetFlowLogger, NULL, NULL, NULL); /* also register as child of eve-log */ OutputRegisterFlowSubModule("eve-log", "JsonNetFlowLog", "eve-log.netflow", - OutputNetFlowLogInitSub, JsonNetFlowLogger); + OutputNetFlowLogInitSub, JsonNetFlowLogger, NULL, NULL, NULL); } #else diff --git a/src/output.c b/src/output.c index f981fbdeb3..5d121b3294 100644 --- a/src/output.c +++ b/src/output.c @@ -484,7 +484,9 @@ error: */ void OutputRegisterFlowModule(const char *name, const char *conf_name, - OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc) + OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(FlowLogFunc == NULL)) { goto error; @@ -499,6 +501,9 @@ OutputRegisterFlowModule(const char *name, const char *conf_name, module->conf_name = conf_name; module->InitFunc = InitFunc; module->FlowLogFunc = FlowLogFunc; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Flow logger \"%s\" registered.", name); @@ -519,7 +524,9 @@ error: void OutputRegisterFlowSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - FlowLogger FlowLogFunc) + FlowLogger FlowLogFunc, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(FlowLogFunc == NULL)) { goto error; @@ -535,6 +542,9 @@ OutputRegisterFlowSubModule(const char *parent_name, const char *name, module->parent_name = parent_name; module->InitSubFunc = InitFunc; module->FlowLogFunc = FlowLogFunc; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Flow logger \"%s\" registered.", name); diff --git a/src/output.h b/src/output.h index d7311c13de..9a6296ffc2 100644 --- a/src/output.h +++ b/src/output.h @@ -129,10 +129,15 @@ void OutputRegisterFiledataSubModule(const char *parent_name, const char *name, FiledataLogger FiledataLogFunc); void OutputRegisterFlowModule(const char *name, const char *conf_name, - OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc); + OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc, + ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterFlowSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), - FlowLogger FlowLogFunc); + FlowLogger FlowLogFunc, ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats); void OutputRegisterStreamingModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc, diff --git a/src/runmodes.c b/src/runmodes.c index 78f73aa22b..6c0d9918c8 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -585,7 +585,9 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu { /* flow logger doesn't run in the packet path */ if (module->FlowLogFunc) { - OutputRegisterFlowLogger(module->name, module->FlowLogFunc, output_ctx); + OutputRegisterFlowLogger(module->name, module->FlowLogFunc, + output_ctx, module->ThreadInit, module->ThreadDeinit, + module->ThreadExitPrintStats); return; } /* stats logger doesn't run in the packet path */ diff --git a/src/tm-modules.c b/src/tm-modules.c index 5099a74b82..67a97767ac 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -244,7 +244,6 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_STREAMINGLOGGER); CASE_CODE (TMM_JSONDROPLOG); CASE_CODE (TMM_JSONFILELOG); - CASE_CODE (TMM_JSONFLOWLOG); CASE_CODE (TMM_JSONNETFLOWLOG); CASE_CODE (TMM_JSONSMTPLOG); CASE_CODE (TMM_JSONSSHLOG); diff --git a/src/tm-threads-common.h b/src/tm-threads-common.h index 7e76782692..9a980ed736 100644 --- a/src/tm-threads-common.h +++ b/src/tm-threads-common.h @@ -82,7 +82,6 @@ typedef enum { TMM_JSONFILELOG, TMM_RECEIVENFLOG, TMM_DECODENFLOG, - TMM_JSONFLOWLOG, TMM_JSONNETFLOWLOG, TMM_LOGSTATSLOG, TMM_JSONTEMPLATELOG,