]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: convert fast log to a non-thread module
authorJason Ish <ish@unx.ca>
Thu, 26 May 2016 16:45:55 +0000 (10:45 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Sep 2016 11:47:52 +0000 (13:47 +0200)
18 files changed:
src/alert-debuglog.c
src/alert-fastlog.c
src/alert-syslog.c
src/alert-unified2-alert.c
src/log-droplog.c
src/output-json-alert.c
src/output-json-drop.c
src/output-json-ssh.c
src/output-packet.c
src/output-packet.h
src/output-tx.c
src/output-tx.h
src/output.c
src/output.h
src/runmodes.c
src/tm-modules.c
src/tm-modules.h
src/tm-threads-common.h

index e939df3ed013a2a56f564f155b445adb7e4bb202..212e90c16161dd3be9ac19da07800d85cdaa2e1a 100644 (file)
@@ -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);
 }
index cf7875bf642cbf60d026dd8056e43b7a74e90a29..59ff045e02afde8ebd87a3ea3c6f0024454ce830 100644 (file)
@@ -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_ {
index 13151dd99027d4e3d4590bb3b1ed79800fca3434..2dd541b66bb4d3f352e9f9e1320c6e4eeab4dc6f 100644 (file)
@@ -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 */
 }
index 557ec5d166b89f2daddc010ce510ba905160592e..8619f5a2a50d3c183ef41978346672dc446871ce 100644 (file)
@@ -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);
 }
 
 /**
index 724d65840ce13aa9f733b964c84fce1e6de0a2e6..0b466b6a48ed04f4f4d1df0ffa19dfc402e783a7 100644 (file)
@@ -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);
 }
index e785337e9f9f7856269aefb12dc2273aa8e1c4a8..56567ce2066c5401c54f75df9c2e6f89225a0b85 100644 (file)
@@ -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);
 }
index fd7f513ead0f47164fa9dd908d29284e2f614b83..fee5845f72b05b6e08c46919b48e463af87153bb 100644 (file)
@@ -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);
 }
index 94853c87b05550374419533f139d1f15bad6e22f..ff626666c237f6a9a730cda646fdd32a0925cb9c 100644 (file)
@@ -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,
index 7e2b550b115771fecf81a8dbf7f125495c3a03db..376b2cd51f36f5b8311095c822369a19f31c4cf6 100644 (file)
@@ -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;
index 5ae1adf8e4878c28c2ef867a1c9a9dbf45cf6400..431c441b11c733055eb2b431ea94f3ffd8e70a15 100644 (file)
@@ -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);
 
index 6250a996ffe34afd18b6baf4c4e766770080c43d..24a5cff941451d8342f755d97a447f57ce750257 100644 (file)
@@ -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
index ee2e8a77c83eacc9367a3f9f0a6b364af58e4603..53f563aca2a502b93882c3983a4c23776c4d9b08 100644 (file)
@@ -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);
index c9bc2201095ba81f5794cfc563a87c411d5906ba..b3d5c4487818df6040353a23502c5c30f83b22d7 100644 (file)
@@ -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);
index 33e92a04def6a624b64c369787d1a2441ce3deb7..232db0edcf54a7a863a34f16aa6e4d61c74563e5 100644 (file)
@@ -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);
index f761caab90b1632dbfcbdf11a19f735eb8ff0cd0..78f73aa22b32a92550fc8482c7ffa6c9d59c782b 100644 (file)
@@ -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) {
index d104afba2de369925b9e74b0112bc32873e20f9e..5879d3d44396623c08ee23d8a5d8088cd293d8b1 100644 (file)
@@ -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);
index 3486ebf04af48140d5a5afb0eab3e9ccb228a2e3..e85aa76908e2b4de4b295feef43db74b43d9b9e9 100644 (file)
 #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;
 
index 8c9c98fe8eeee7264de3021dd440c2f54a1cbe1a..d1bc75391d3dc805853a1a4f90cca5a157a1736e 100644 (file)
@@ -41,7 +41,6 @@ typedef enum {
     TMM_DECODEPCAPFILE,
     TMM_RECEIVEPFRING,
     TMM_DECODEPFRING,
-    TMM_ALERTFASTLOG,
     TMM_ALERTUNIFIED2ALERT,
     TMM_ALERTPRELUDE,
     TMM_ALERTDEBUGLOG,