logging: convert json flow output to non-thread module

pull/2245/head
Jason Ish 9 years ago committed by Victor Julien
parent ad15ac8297
commit 983a619ff0

@ -47,17 +47,18 @@ typedef struct OutputFlowLogger_ {
OutputCtx *output_ctx; OutputCtx *output_ctx;
struct OutputFlowLogger_ *next; struct OutputFlowLogger_ *next;
const char *name; const char *name;
TmmId module_id; TmEcode (*ThreadInit)(ThreadVars *, void *, void **);
TmEcode (*ThreadDeinit)(ThreadVars *, void *);
void (*ThreadExitPrintStats)(ThreadVars *, void *);
} OutputFlowLogger; } OutputFlowLogger;
static OutputFlowLogger *list = NULL; 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)); OutputFlowLogger *op = SCMalloc(sizeof(*op));
if (op == NULL) if (op == NULL)
return -1; return -1;
@ -66,7 +67,9 @@ int OutputRegisterFlowLogger(const char *name, FlowLogger LogFunc, OutputCtx *ou
op->LogFunc = LogFunc; op->LogFunc = LogFunc;
op->output_ctx = output_ctx; op->output_ctx = output_ctx;
op->name = name; op->name = name;
op->module_id = (TmmId) module_id; op->ThreadInit = ThreadInit;
op->ThreadDeinit = ThreadDeinit;
op->ThreadExitPrintStats = ThreadExitPrintStats;
if (list == NULL) if (list == NULL)
list = op; list = op;
@ -106,9 +109,9 @@ TmEcode OutputFlowLog(ThreadVars *tv, void *thread_data, Flow *f)
BUG_ON(logger->LogFunc == NULL); BUG_ON(logger->LogFunc == NULL);
SCLogDebug("logger %p", logger); 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); 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; logger = logger->next;
store = store->next; store = store->next;
@ -136,16 +139,9 @@ TmEcode OutputFlowLogThreadInit(ThreadVars *tv, void *initdata, void **data)
OutputFlowLogger *logger = list; OutputFlowLogger *logger = list;
while (logger) { while (logger) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name); if (logger->ThreadInit) {
if (tm_module == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"TmModuleGetByName for %s failed", logger->name);
exit(EXIT_FAILURE);
}
if (tm_module->ThreadInit) {
void *retptr = NULL; 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)); OutputLoggerThreadStore *ts = SCMalloc(sizeof(*ts));
/* todo */ BUG_ON(ts == NULL); /* todo */ BUG_ON(ts == NULL);
memset(ts, 0x00, sizeof(*ts)); memset(ts, 0x00, sizeof(*ts));
@ -179,15 +175,8 @@ TmEcode OutputFlowLogThreadDeinit(ThreadVars *tv, void *thread_data)
OutputFlowLogger *logger = list; OutputFlowLogger *logger = list;
while (logger && store) { while (logger && store) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name); if (logger->ThreadDeinit) {
if (tm_module == NULL) { logger->ThreadDeinit(tv, store->thread_data);
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);
} }
OutputLoggerThreadStore *next_store = store->next; OutputLoggerThreadStore *next_store = store->next;
@ -207,15 +196,8 @@ void OutputFlowLogExitPrintStats(ThreadVars *tv, void *thread_data)
OutputFlowLogger *logger = list; OutputFlowLogger *logger = list;
while (logger && store) { while (logger && store) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name); if (logger->ThreadExitPrintStats) {
if (tm_module == NULL) { logger->ThreadExitPrintStats(tv, store->thread_data);
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);
} }
logger = logger->next; logger = logger->next;

@ -36,7 +36,9 @@ typedef int (*FlowLogger)(ThreadVars *, void *thread_data, Flow *f);
*/ */
//typedef int (*TxLogCondition)(ThreadVars *, const Packet *); //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); void OutputFlowShutdown(void);

@ -450,34 +450,22 @@ static TmEcode JsonFlowLogThreadDeinit(ThreadVars *t, void *data)
void TmModuleJsonFlowLogRegister (void) 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 */ /* register as separate module */
OutputRegisterFlowModule("JsonFlowLog", "flow-json-log", OutputRegisterFlowModule("JsonFlowLog", "flow-json-log",
OutputFlowLogInit, JsonFlowLogger); OutputFlowLogInit, JsonFlowLogger, JsonFlowLogThreadInit,
JsonFlowLogThreadDeinit, NULL);
/* also register as child of eve-log */ /* also register as child of eve-log */
OutputRegisterFlowSubModule("eve-log", "JsonFlowLog", "eve-log.flow", OutputRegisterFlowSubModule("eve-log", "JsonFlowLog", "eve-log.flow",
OutputFlowLogInitSub, JsonFlowLogger); OutputFlowLogInitSub, JsonFlowLogger, JsonFlowLogThreadInit,
JsonFlowLogThreadDeinit, NULL);
} }
#else #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) void TmModuleJsonFlowLogRegister (void)
{ {
tmm_modules[TMM_JSONFLOWLOG].name = "JsonFlowLog"; SCLogInfo("Can't register JSON output - JSON support was disabled during build.");
tmm_modules[TMM_JSONFLOWLOG].ThreadInit = OutputJsonThreadInit;
} }
#endif #endif

@ -441,11 +441,11 @@ void TmModuleJsonNetFlowLogRegister (void)
/* register as separate module */ /* register as separate module */
OutputRegisterFlowModule("JsonNetFlowLog", "netflow-json-log", OutputRegisterFlowModule("JsonNetFlowLog", "netflow-json-log",
OutputNetFlowLogInit, JsonNetFlowLogger); OutputNetFlowLogInit, JsonNetFlowLogger, NULL, NULL, NULL);
/* also register as child of eve-log */ /* also register as child of eve-log */
OutputRegisterFlowSubModule("eve-log", "JsonNetFlowLog", "eve-log.netflow", OutputRegisterFlowSubModule("eve-log", "JsonNetFlowLog", "eve-log.netflow",
OutputNetFlowLogInitSub, JsonNetFlowLogger); OutputNetFlowLogInitSub, JsonNetFlowLogger, NULL, NULL, NULL);
} }
#else #else

@ -484,7 +484,9 @@ error:
*/ */
void void
OutputRegisterFlowModule(const char *name, const char *conf_name, 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)) { if (unlikely(FlowLogFunc == NULL)) {
goto error; goto error;
@ -499,6 +501,9 @@ OutputRegisterFlowModule(const char *name, const char *conf_name,
module->conf_name = conf_name; module->conf_name = conf_name;
module->InitFunc = InitFunc; module->InitFunc = InitFunc;
module->FlowLogFunc = FlowLogFunc; module->FlowLogFunc = FlowLogFunc;
module->ThreadInit = ThreadInit;
module->ThreadDeinit = ThreadDeinit;
module->ThreadExitPrintStats = ThreadExitPrintStats;
TAILQ_INSERT_TAIL(&output_modules, module, entries); TAILQ_INSERT_TAIL(&output_modules, module, entries);
SCLogDebug("Flow logger \"%s\" registered.", name); SCLogDebug("Flow logger \"%s\" registered.", name);
@ -519,7 +524,9 @@ error:
void void
OutputRegisterFlowSubModule(const char *parent_name, const char *name, OutputRegisterFlowSubModule(const char *parent_name, const char *name,
const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
FlowLogger FlowLogFunc) FlowLogger FlowLogFunc, ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats)
{ {
if (unlikely(FlowLogFunc == NULL)) { if (unlikely(FlowLogFunc == NULL)) {
goto error; goto error;
@ -535,6 +542,9 @@ OutputRegisterFlowSubModule(const char *parent_name, const char *name,
module->parent_name = parent_name; module->parent_name = parent_name;
module->InitSubFunc = InitFunc; module->InitSubFunc = InitFunc;
module->FlowLogFunc = FlowLogFunc; module->FlowLogFunc = FlowLogFunc;
module->ThreadInit = ThreadInit;
module->ThreadDeinit = ThreadDeinit;
module->ThreadExitPrintStats = ThreadExitPrintStats;
TAILQ_INSERT_TAIL(&output_modules, module, entries); TAILQ_INSERT_TAIL(&output_modules, module, entries);
SCLogDebug("Flow logger \"%s\" registered.", name); SCLogDebug("Flow logger \"%s\" registered.", name);

@ -129,10 +129,15 @@ void OutputRegisterFiledataSubModule(const char *parent_name, const char *name,
FiledataLogger FiledataLogFunc); FiledataLogger FiledataLogFunc);
void OutputRegisterFlowModule(const char *name, const char *conf_name, 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, void OutputRegisterFlowSubModule(const char *parent_name, const char *name,
const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), 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, void OutputRegisterStreamingModule(const char *name, const char *conf_name,
OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc, OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc,

@ -585,7 +585,9 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
{ {
/* flow logger doesn't run in the packet path */ /* flow logger doesn't run in the packet path */
if (module->FlowLogFunc) { if (module->FlowLogFunc) {
OutputRegisterFlowLogger(module->name, module->FlowLogFunc, output_ctx); OutputRegisterFlowLogger(module->name, module->FlowLogFunc,
output_ctx, module->ThreadInit, module->ThreadDeinit,
module->ThreadExitPrintStats);
return; return;
} }
/* stats logger doesn't run in the packet path */ /* stats logger doesn't run in the packet path */

@ -244,7 +244,6 @@ const char * TmModuleTmmIdToString(TmmId id)
CASE_CODE (TMM_STREAMINGLOGGER); CASE_CODE (TMM_STREAMINGLOGGER);
CASE_CODE (TMM_JSONDROPLOG); CASE_CODE (TMM_JSONDROPLOG);
CASE_CODE (TMM_JSONFILELOG); CASE_CODE (TMM_JSONFILELOG);
CASE_CODE (TMM_JSONFLOWLOG);
CASE_CODE (TMM_JSONNETFLOWLOG); CASE_CODE (TMM_JSONNETFLOWLOG);
CASE_CODE (TMM_JSONSMTPLOG); CASE_CODE (TMM_JSONSMTPLOG);
CASE_CODE (TMM_JSONSSHLOG); CASE_CODE (TMM_JSONSSHLOG);

@ -82,7 +82,6 @@ typedef enum {
TMM_JSONFILELOG, TMM_JSONFILELOG,
TMM_RECEIVENFLOG, TMM_RECEIVENFLOG,
TMM_DECODENFLOG, TMM_DECODENFLOG,
TMM_JSONFLOWLOG,
TMM_JSONNETFLOWLOG, TMM_JSONNETFLOWLOG,
TMM_LOGSTATSLOG, TMM_LOGSTATSLOG,
TMM_JSONTEMPLATELOG, TMM_JSONTEMPLATELOG,

Loading…
Cancel
Save