From c7ebfd1b68f839ab6ec79a832587433f747ebe0d Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 1 May 2014 17:30:32 +0200 Subject: [PATCH] flow: flow log threading setup Set up threading for the flow logger. --- src/output.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/output.h | 8 ++++++ src/runmodes.c | 6 +++++ 3 files changed, 84 insertions(+) diff --git a/src/output.c b/src/output.c index 980369ddea..ebf2dda6ef 100644 --- a/src/output.c +++ b/src/output.c @@ -354,6 +354,76 @@ error: exit(EXIT_FAILURE); } +/** + * \brief Register a flow output module. + * + * This function will register an output module so it can be + * configured with the configuration file. + * + * \retval Returns 0 on success, -1 on failure. + */ +void +OutputRegisterFlowModule(const char *name, const char *conf_name, + OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc) +{ + if (unlikely(FlowLogFunc == NULL)) { + goto error; + } + + OutputModule *module = SCCalloc(1, sizeof(*module)); + if (unlikely(module == NULL)) { + goto error; + } + + module->name = name; + module->conf_name = conf_name; + module->InitFunc = InitFunc; + module->FlowLogFunc = FlowLogFunc; + TAILQ_INSERT_TAIL(&output_modules, module, entries); + + SCLogDebug("Flow logger \"%s\" registered.", name); + return; +error: + SCLogError(SC_ERR_FATAL, "Fatal error encountered. Exiting..."); + exit(EXIT_FAILURE); +} + +/** + * \brief Register a flow output sub-module. + * + * This function will register an output module so it can be + * configured with the configuration file. + * + * \retval Returns 0 on success, -1 on failure. + */ +void +OutputRegisterFlowSubModule(const char *parent_name, const char *name, + const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), + FlowLogger FlowLogFunc) +{ + if (unlikely(FlowLogFunc == NULL)) { + goto error; + } + + OutputModule *module = SCCalloc(1, sizeof(*module)); + if (unlikely(module == NULL)) { + goto error; + } + + module->name = name; + module->conf_name = conf_name; + module->parent_name = parent_name; + module->InitSubFunc = InitFunc; + module->FlowLogFunc = FlowLogFunc; + TAILQ_INSERT_TAIL(&output_modules, module, entries); + + SCLogDebug("Flow logger \"%s\" registered.", name); + return; +error: + SCLogError(SC_ERR_FATAL, "Fatal error encountered. Exiting..."); + exit(EXIT_FAILURE); +} + /** * \brief Get an output module by name. * diff --git a/src/output.h b/src/output.h index 72837ce20c..a097cbc99c 100644 --- a/src/output.h +++ b/src/output.h @@ -34,6 +34,7 @@ #include "output-tx.h" #include "output-file.h" #include "output-filedata.h" +#include "output-flow.h" typedef struct OutputModule_ { const char *name; @@ -47,6 +48,7 @@ typedef struct OutputModule_ { TxLogger TxLogFunc; FileLogger FileLogFunc; FiledataLogger FiledataLogFunc; + FlowLogger FlowLogFunc; AppProto alproto; TAILQ_ENTRY(OutputModule_) entries; @@ -80,6 +82,12 @@ void OutputRegisterFiledataSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), FiledataLogger FiledataLogFunc); +void OutputRegisterFlowModule(const char *name, const char *conf_name, + OutputCtx *(*InitFunc)(ConfNode *), FlowLogger FlowLogFunc); +void OutputRegisterFlowSubModule(const char *parent_name, const char *name, + const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), + FlowLogger FlowLogFunc); + OutputModule *OutputGetModuleByConfName(const char *name); void OutputDeregisterAll(void); diff --git a/src/runmodes.c b/src/runmodes.c index 7a316163d5..c84165873f 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -484,6 +484,12 @@ static void AddOutputToFreeList(OutputModule *module, OutputCtx *output_ctx) /** \brief Turn output into thread module */ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *output_ctx) { + /* flow logger doesn't run in the packet path */ + if (module->FlowLogFunc) { + OutputRegisterFlowLogger(module->name, module->FlowLogFunc, output_ctx); + return; + } + TmModule *tm_module = TmModuleGetByName(module->name); if (tm_module == NULL) { SCLogError(SC_ERR_INVALID_ARGUMENT,