From b1200dba54053cf9faccf080ff2f3e759acc9cc1 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Thu, 26 May 2016 10:45:55 -0600 Subject: [PATCH] logging: convert fast log to a non-thread module --- src/alert-debuglog.c | 2 +- src/alert-fastlog.c | 14 ++++------- src/alert-syslog.c | 2 +- src/alert-unified2-alert.c | 2 +- src/log-droplog.c | 2 +- src/output-json-alert.c | 2 +- src/output-json-drop.c | 2 +- src/output-json-ssh.c | 2 +- src/output-packet.c | 48 ++++++++++++++++---------------------- src/output-packet.h | 3 ++- src/output-tx.c | 4 ++-- src/output-tx.h | 3 +-- src/output.c | 7 +++++- src/output.h | 3 ++- src/runmodes.c | 5 ++-- src/tm-modules.c | 1 - src/tm-modules.h | 4 ++++ src/tm-threads-common.h | 1 - 18 files changed, 51 insertions(+), 56 deletions(-) diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index e939df3ed0..212e90c161 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -522,5 +522,5 @@ void TmModuleAlertDebugLogRegister (void) tmm_modules[TMM_ALERTDEBUGLOG].flags = TM_FLAG_LOGAPI_TM; OutputRegisterPacketModule(MODULE_NAME, "alert-debug", - AlertDebugLogInitCtx, AlertDebugLogLogger, AlertDebugLogCondition); + AlertDebugLogInitCtx, AlertDebugLogLogger, AlertDebugLogCondition, NULL, NULL, NULL); } diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index cf7875bf64..59ff045e02 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -78,16 +78,10 @@ int AlertFastLogger(ThreadVars *tv, void *data, const Packet *p); void TmModuleAlertFastLogRegister (void) { - tmm_modules[TMM_ALERTFASTLOG].name = MODULE_NAME; - tmm_modules[TMM_ALERTFASTLOG].ThreadInit = AlertFastLogThreadInit; - tmm_modules[TMM_ALERTFASTLOG].ThreadExitPrintStats = AlertFastLogExitPrintStats; - tmm_modules[TMM_ALERTFASTLOG].ThreadDeinit = AlertFastLogThreadDeinit; - tmm_modules[TMM_ALERTFASTLOG].RegisterTests = AlertFastLogRegisterTests; - tmm_modules[TMM_ALERTFASTLOG].cap_flags = 0; - tmm_modules[TMM_ALERTFASTLOG].flags = TM_FLAG_LOGAPI_TM; - - OutputRegisterPacketModule(MODULE_NAME, "fast", - AlertFastLogInitCtx, AlertFastLogger, AlertFastLogCondition); + OutputRegisterPacketModule(MODULE_NAME, "fast", AlertFastLogInitCtx, + AlertFastLogger, AlertFastLogCondition, AlertFastLogThreadInit, + AlertFastLogThreadDeinit, AlertFastLogExitPrintStats); + AlertFastLogRegisterTests(); } typedef struct AlertFastLogThread_ { diff --git a/src/alert-syslog.c b/src/alert-syslog.c index 13151dd990..2dd541b66b 100644 --- a/src/alert-syslog.c +++ b/src/alert-syslog.c @@ -421,7 +421,7 @@ void TmModuleAlertSyslogRegister (void) tmm_modules[TMM_ALERTSYSLOG].flags = TM_FLAG_LOGAPI_TM; OutputRegisterPacketModule(MODULE_NAME, "syslog", - AlertSyslogInitCtx, AlertSyslogLogger, AlertSyslogCondition); + AlertSyslogInitCtx, AlertSyslogLogger, AlertSyslogCondition, NULL, NULL, NULL); #endif /* !OS_WIN32 */ } diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 557ec5d166..8619f5a2a5 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -245,7 +245,7 @@ void TmModuleUnified2AlertRegister(void) //OutputRegisterModule(MODULE_NAME, "unified2-alert", Unified2AlertInitCtx); OutputRegisterPacketModule(MODULE_NAME, "unified2-alert", - Unified2AlertInitCtx, Unified2Logger, Unified2Condition); + Unified2AlertInitCtx, Unified2Logger, Unified2Condition, NULL, NULL, NULL); } /** diff --git a/src/log-droplog.c b/src/log-droplog.c index 724d65840c..0b466b6a48 100644 --- a/src/log-droplog.c +++ b/src/log-droplog.c @@ -506,5 +506,5 @@ void TmModuleLogDropLogRegister (void) tmm_modules[TMM_LOGDROPLOG].flags = TM_FLAG_LOGAPI_TM; OutputRegisterPacketModule(MODULE_NAME, "drop", LogDropLogInitCtx, - LogDropLogger, LogDropCondition); + LogDropLogger, LogDropCondition, NULL, NULL, NULL); } diff --git a/src/output-json-alert.c b/src/output-json-alert.c index e785337e9f..56567ce206 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -748,7 +748,7 @@ void TmModuleJsonAlertLogRegister (void) tmm_modules[TMM_JSONALERTLOG].flags = TM_FLAG_LOGAPI_TM; OutputRegisterPacketModule(MODULE_NAME, "alert-json-log", - JsonAlertLogInitCtx, JsonAlertLogger, JsonAlertLogCondition); + JsonAlertLogInitCtx, JsonAlertLogger, JsonAlertLogCondition, NULL, NULL, NULL); OutputRegisterPacketSubModule("eve-log", MODULE_NAME, "eve-log.alert", JsonAlertLogInitCtxSub, JsonAlertLogger, JsonAlertLogCondition); } diff --git a/src/output-json-drop.c b/src/output-json-drop.c index fd7f513ead..fee5845f72 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -436,7 +436,7 @@ void TmModuleJsonDropLogRegister (void) tmm_modules[TMM_JSONDROPLOG].flags = TM_FLAG_LOGAPI_TM; OutputRegisterPacketModule(MODULE_NAME, "drop-json-log", - JsonDropLogInitCtx, JsonDropLogger, JsonDropLogCondition); + JsonDropLogInitCtx, JsonDropLogger, JsonDropLogCondition, NULL, NULL, NULL); OutputRegisterPacketSubModule("eve-log", MODULE_NAME, "eve-log.drop", JsonDropLogInitCtxSub, JsonDropLogger, JsonDropLogCondition); } diff --git a/src/output-json-ssh.c b/src/output-json-ssh.c index 94853c87b0..ff626666c2 100644 --- a/src/output-json-ssh.c +++ b/src/output-json-ssh.c @@ -325,7 +325,7 @@ void TmModuleJsonSshLogRegister (void) /* register as separate module */ OutputRegisterPacketModule("JsonSshLog", "ssh-json-log", OutputSshLogInit, - JsonSshLogger, JsonSshCondition); + JsonSshLogger, JsonSshCondition, NULL, NULL, NULL); /* also register as child of eve-log */ OutputRegisterPacketSubModule("eve-log", "JsonSshLog", "eve-log.ssh", OutputSshLogInitSub, diff --git a/src/output-packet.c b/src/output-packet.c index 7e2b550b11..376b2cd51f 100644 --- a/src/output-packet.c +++ b/src/output-packet.c @@ -49,15 +49,23 @@ typedef struct OutputPacketLogger_ { struct OutputPacketLogger_ *next; const char *name; TmmId module_id; + ThreadInitFunc ThreadInit; + ThreadDeinitFunc ThreadDeinit; + ThreadExitPrintStatsFunc ThreadExitPrintStats; } OutputPacketLogger; static OutputPacketLogger *list = NULL; -int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, PacketLogCondition ConditionFunc, OutputCtx *output_ctx) +int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, + PacketLogCondition ConditionFunc, OutputCtx *output_ctx, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { +#if 0 int module_id = TmModuleGetIdByName(name); if (module_id < 0) return -1; +#endif OutputPacketLogger *op = SCMalloc(sizeof(*op)); if (op == NULL) @@ -68,7 +76,12 @@ int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, PacketLog op->ConditionFunc = ConditionFunc; op->output_ctx = output_ctx; op->name = name; + op->ThreadInit = ThreadInit; + op->ThreadDeinit = ThreadDeinit; + op->ThreadExitPrintStats = ThreadExitPrintStats; +#if 0 op->module_id = (TmmId) module_id; +#endif if (list == NULL) list = op; @@ -131,16 +144,9 @@ static TmEcode OutputPacketLogThreadInit(ThreadVars *tv, void *initdata, void ** OutputPacketLogger *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)); @@ -174,15 +180,8 @@ static TmEcode OutputPacketLogThreadDeinit(ThreadVars *tv, void *thread_data) OutputPacketLogger *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; @@ -203,15 +202,8 @@ static void OutputPacketLogExitPrintStats(ThreadVars *tv, void *thread_data) OutputPacketLogger *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-packet.h b/src/output-packet.h index 5ae1adf8e4..431c441b11 100644 --- a/src/output-packet.h +++ b/src/output-packet.h @@ -37,7 +37,8 @@ typedef int (*PacketLogger)(ThreadVars *, void *thread_data, const Packet *); typedef int (*PacketLogCondition)(ThreadVars *, const Packet *); int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, - PacketLogCondition ConditionFunc, OutputCtx *); + PacketLogCondition ConditionFunc, OutputCtx *, ThreadInitFunc, + ThreadDeinitFunc, ThreadExitPrintStatsFunc); void TmModulePacketLoggerRegister (void); diff --git a/src/output-tx.c b/src/output-tx.c index 6250a996ff..24a5cff941 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -65,8 +65,8 @@ static OutputTxLogger *list = NULL; int OutputRegisterTxLogger(const char *name, AppProto alproto, TxLogger LogFunc, OutputCtx *output_ctx, int tc_log_progress, int ts_log_progress, TxLoggerCondition LogCondition, - TmEcode (*ThreadInit)(ThreadVars *, void *, void **), - TmEcode (*ThreadDeinit)(ThreadVars *, void *), + ThreadInitFunc ThreadInit, + ThreadDeinitFunc ThreadDeinit, void (*ThreadExitPrintStats)(ThreadVars *, void *)) { #if 0 diff --git a/src/output-tx.h b/src/output-tx.h index ee2e8a77c8..53f563aca2 100644 --- a/src/output-tx.h +++ b/src/output-tx.h @@ -39,8 +39,7 @@ typedef int (*TxLoggerCondition)(ThreadVars *, const Packet *, void *state, void int OutputRegisterTxLogger(const char *name, AppProto alproto, TxLogger LogFunc, OutputCtx *, int tc_log_progress, int ts_log_progress, TxLoggerCondition LogCondition, - TmEcode (*ThreadInit)(ThreadVars *, void *, void **), - TmEcode (*ThreadDeinit)(ThreadVars *, void *), + ThreadInitFunc, ThreadDeinitFunc, void (*ThreadExitPrintStats)(ThreadVars *, void *)); void TmModuleTxLoggerRegister (void); diff --git a/src/output.c b/src/output.c index c9bc220109..b3d5c44878 100644 --- a/src/output.c +++ b/src/output.c @@ -86,7 +86,9 @@ error: void OutputRegisterPacketModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), - PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc) + PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc, + ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, + ThreadExitPrintStatsFunc ThreadExitPrintStats) { if (unlikely(PacketLogFunc == NULL || PacketConditionFunc == NULL)) { goto error; @@ -102,6 +104,9 @@ OutputRegisterPacketModule(const char *name, const char *conf_name, module->InitFunc = InitFunc; module->PacketLogFunc = PacketLogFunc; module->PacketConditionFunc = PacketConditionFunc; + module->ThreadInit = ThreadInit; + module->ThreadDeinit = ThreadDeinit; + module->ThreadExitPrintStats = ThreadExitPrintStats; TAILQ_INSERT_TAIL(&output_modules, module, entries); SCLogDebug("Packet logger \"%s\" registered.", name); diff --git a/src/output.h b/src/output.h index 33e92a04de..232db0edcf 100644 --- a/src/output.h +++ b/src/output.h @@ -73,7 +73,8 @@ void OutputRegisterModule(const char *, const char *, OutputCtx *(*)(ConfNode *) void OutputRegisterPacketModule(const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *), - PacketLogger LogFunc, PacketLogCondition ConditionFunc); + PacketLogger LogFunc, PacketLogCondition ConditionFunc, + ThreadInitFunc, ThreadDeinitFunc, ThreadExitPrintStatsFunc); void OutputRegisterPacketSubModule(const char *parent_name, const char *name, const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *), PacketLogger LogFunc, PacketLogCondition ConditionFunc); diff --git a/src/runmodes.c b/src/runmodes.c index f761caab90..78f73aa22b 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -607,9 +607,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu #endif if (module->PacketLogFunc) { - SCLogDebug("%s is a packet logger", module->name); + SCLogNotice("%s is a packet logger", module->name); OutputRegisterPacketLogger(module->name, module->PacketLogFunc, - module->PacketConditionFunc, output_ctx); + module->PacketConditionFunc, output_ctx, module->ThreadInit, + module->ThreadDeinit, module->ThreadExitPrintStats); /* need one instance of the packet logger module */ if (pkt_logger_module == NULL) { diff --git a/src/tm-modules.c b/src/tm-modules.c index d104afba2d..5879d3d443 100644 --- a/src/tm-modules.c +++ b/src/tm-modules.c @@ -211,7 +211,6 @@ const char * TmModuleTmmIdToString(TmmId id) CASE_CODE (TMM_DECODEPCAPFILE); CASE_CODE (TMM_RECEIVEPFRING); CASE_CODE (TMM_DECODEPFRING); - CASE_CODE (TMM_ALERTFASTLOG); CASE_CODE (TMM_ALERTUNIFIED2ALERT); CASE_CODE (TMM_ALERTPRELUDE); CASE_CODE (TMM_ALERTDEBUGLOG); diff --git a/src/tm-modules.h b/src/tm-modules.h index 3486ebf04a..e85aa76908 100644 --- a/src/tm-modules.h +++ b/src/tm-modules.h @@ -36,6 +36,10 @@ #define TM_FLAG_MANAGEMENT_TM 0x20 #define TM_FLAG_COMMAND_TM 0x40 +typedef TmEcode (*ThreadInitFunc)(ThreadVars *, void *, void **); +typedef TmEcode (*ThreadDeinitFunc)(ThreadVars *, void *); +typedef void (*ThreadExitPrintStatsFunc)(ThreadVars *, void *); + typedef struct TmModule_ { char *name; diff --git a/src/tm-threads-common.h b/src/tm-threads-common.h index 8c9c98fe8e..d1bc75391d 100644 --- a/src/tm-threads-common.h +++ b/src/tm-threads-common.h @@ -41,7 +41,6 @@ typedef enum { TMM_DECODEPCAPFILE, TMM_RECEIVEPFRING, TMM_DECODEPFRING, - TMM_ALERTFASTLOG, TMM_ALERTUNIFIED2ALERT, TMM_ALERTPRELUDE, TMM_ALERTDEBUGLOG, -- 2.47.2