]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: convert tcp data logging to non-thread module
authorJason Ish <ish@unx.ca>
Fri, 27 May 2016 19:12:06 +0000 (13:12 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 19 Sep 2016 11:47:52 +0000 (13:47 +0200)
src/log-tcp-data.c
src/output-streaming.c
src/output-streaming.h
src/output.c
src/output.h
src/runmodes.c
src/tm-modules.c
src/tm-threads-common.h

index c3dadd4416b770ece5c83db76517b99c5cf3efa4..b1ebfca3976174a6d87431cc8567dec585336f6f 100644 (file)
@@ -61,18 +61,13 @@ static void LogTcpDataLogDeInitCtx(OutputCtx *);
 int LogTcpDataLogger(ThreadVars *tv, void *thread_data, const Flow *f, const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t flags);
 
 void TmModuleLogTcpDataLogRegister (void) {
-    tmm_modules[TMM_LOGTCPDATALOG].name = MODULE_NAME;
-    tmm_modules[TMM_LOGTCPDATALOG].ThreadInit = LogTcpDataLogThreadInit;
-    tmm_modules[TMM_LOGTCPDATALOG].ThreadExitPrintStats = LogTcpDataLogExitPrintStats;
-    tmm_modules[TMM_LOGTCPDATALOG].ThreadDeinit = LogTcpDataLogThreadDeinit;
-    tmm_modules[TMM_LOGTCPDATALOG].RegisterTests = NULL;
-    tmm_modules[TMM_LOGTCPDATALOG].cap_flags = 0;
-    tmm_modules[TMM_LOGTCPDATALOG].flags = TM_FLAG_LOGAPI_TM;
-
     OutputRegisterStreamingModule(MODULE_NAME, "tcp-data", LogTcpDataLogInitCtx,
-            LogTcpDataLogger, STREAMING_TCP_DATA);
-    OutputRegisterStreamingModule(MODULE_NAME, "http-body-data", LogTcpDataLogInitCtx,
-            LogTcpDataLogger, STREAMING_HTTP_BODIES);
+        LogTcpDataLogger, STREAMING_TCP_DATA, LogTcpDataLogThreadInit,
+        LogTcpDataLogThreadDeinit, LogTcpDataLogExitPrintStats);
+    OutputRegisterStreamingModule(MODULE_NAME, "http-body-data",
+        LogTcpDataLogInitCtx, LogTcpDataLogger, STREAMING_HTTP_BODIES,
+        LogTcpDataLogThreadInit, LogTcpDataLogThreadDeinit,
+        LogTcpDataLogExitPrintStats);
 }
 
 typedef struct LogTcpDataFileCtx_ {
index 2955066203474db02e1845adfc834005766a4c5a..b72a38a44f770e0179433e8182808fafe1bc9631 100644 (file)
@@ -55,16 +55,23 @@ typedef struct OutputStreamingLogger_ {
     const char *name;
     TmmId module_id;
     enum OutputStreamingType type;
+    ThreadInitFunc ThreadInit;
+    ThreadDeinitFunc ThreadDeinit;
+    ThreadExitPrintStatsFunc ThreadExitPrintStats;
 } OutputStreamingLogger;
 
 static OutputStreamingLogger *list = NULL;
 
 int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
-        OutputCtx *output_ctx, enum OutputStreamingType type )
+    OutputCtx *output_ctx, enum OutputStreamingType type,
+    ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats)
 {
+#if 0
     int module_id = TmModuleGetIdByName(name);
     if (module_id < 0)
         return -1;
+#endif
 
     OutputStreamingLogger *op = SCMalloc(sizeof(*op));
     if (op == NULL)
@@ -74,8 +81,13 @@ int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
     op->LogFunc = LogFunc;
     op->output_ctx = output_ctx;
     op->name = name;
+#if 0
     op->module_id = (TmmId) module_id;
+#endif
     op->type = type;
+    op->ThreadInit = ThreadInit;
+    op->ThreadDeinit = ThreadDeinit;
+    op->ThreadExitPrintStats = ThreadExitPrintStats;
 
     if (list == NULL)
         list = op;
@@ -368,16 +380,9 @@ static TmEcode OutputStreamingLogThreadInit(ThreadVars *tv, void *initdata, void
 
     OutputStreamingLogger *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));
@@ -412,15 +417,8 @@ static TmEcode OutputStreamingLogThreadDeinit(ThreadVars *tv, void *thread_data)
     OutputStreamingLogger *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);
         }
 
         logger = logger->next;
@@ -436,15 +434,8 @@ static void OutputStreamingLogExitPrintStats(ThreadVars *tv, void *thread_data)
     OutputStreamingLogger *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 8b303742287522e0c279d4664166c26f199a8565..9508903a8a0356dae380271682f73b293e20dec0 100644 (file)
@@ -45,8 +45,10 @@ typedef int (*StreamingLogger)(ThreadVars *, void *thread_data,
         const Flow *f, const uint8_t *data, uint32_t data_len,
         uint64_t tx_id, uint8_t flags);
 
-int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, OutputCtx *,
-        enum OutputStreamingType);
+int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
+    OutputCtx *, enum OutputStreamingType, ThreadInitFunc ThreadInit,
+    ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats);
 
 void TmModuleStreamingLoggerRegister (void);
 
index 85840cb18e1bb26f84bf01eab5bfe6d8a71bab27..351cd294aec89db71930e94fa5c82ac0a51e1ccd 100644 (file)
@@ -587,7 +587,9 @@ error:
 void
 OutputRegisterStreamingModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc,
-    enum OutputStreamingType stream_type)
+    enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit,
+    ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats)
 {
     if (unlikely(StreamingLogFunc == NULL)) {
         goto error;
@@ -603,6 +605,9 @@ OutputRegisterStreamingModule(const char *name, const char *conf_name,
     module->InitFunc = InitFunc;
     module->StreamingLogFunc = StreamingLogFunc;
     module->stream_type = stream_type;
+    module->ThreadInit = ThreadInit;
+    module->ThreadDeinit = ThreadDeinit;
+    module->ThreadExitPrintStats = ThreadExitPrintStats;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
 
     SCLogDebug("Streaming logger \"%s\" registered.", name);
@@ -623,7 +628,9 @@ error:
 void
 OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
     const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
-    StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type)
+    StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
+    ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats)
 {
     if (unlikely(StreamingLogFunc == NULL)) {
         goto error;
@@ -640,6 +647,9 @@ OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
     module->InitSubFunc = InitFunc;
     module->StreamingLogFunc = StreamingLogFunc;
     module->stream_type = stream_type;
+    module->ThreadInit = ThreadInit;
+    module->ThreadDeinit = ThreadDeinit;
+    module->ThreadExitPrintStats = ThreadExitPrintStats;
     TAILQ_INSERT_TAIL(&output_modules, module, entries);
 
     SCLogDebug("Streaming logger \"%s\" registered.", name);
index 073f810cad220c85ce80351dd9d697c5663cbe3a..e34d34379d747c2fd89a56f4bb3096882f0da4e8 100644 (file)
@@ -153,10 +153,14 @@ void OutputRegisterFlowSubModule(const char *parent_name, const char *name,
 
 void OutputRegisterStreamingModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc,
-    enum OutputStreamingType stream_type);
+    enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit,
+    ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats);
 void OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
     const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
-    StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type);
+    StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
+    ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
+    ThreadExitPrintStatsFunc ThreadExitPrintStats);
 
 void OutputRegisterStatsModule(const char *name, const char *conf_name,
     OutputCtx *(*InitFunc)(ConfNode *), StatsLogger StatsLogFunc,
index 903f9a99a3118ac2c0ea6c9c1551b7434c632493..3f043b9409f6427daaf8c769c1c8044b3122b9e8 100644 (file)
@@ -711,7 +711,8 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
     } else if (module->StreamingLogFunc) {
         SCLogDebug("%s is a streaming logger", module->name);
         OutputRegisterStreamingLogger(module->name, module->StreamingLogFunc,
-                output_ctx, module->stream_type);
+            output_ctx, module->stream_type, module->ThreadInit,
+            module->ThreadDeinit, module->ThreadExitPrintStats);
 
         /* need one instance of the streaming logger module */
         if (streaming_logger_module == NULL) {
index 49d519e66f709519135622491b632dc6652aebb5..cab153838463fd79a65daebf19aa51821284c023 100644 (file)
@@ -214,7 +214,6 @@ const char * TmModuleTmmIdToString(TmmId id)
         CASE_CODE (TMM_ALERTDEBUGLOG);
         CASE_CODE (TMM_RESPONDREJECT);
         CASE_CODE (TMM_LOGTLSLOG);
-        CASE_CODE (TMM_LOGTCPDATALOG);
         CASE_CODE (TMM_PCAPLOG);
         CASE_CODE (TMM_DECODEIPFW);
         CASE_CODE (TMM_VERDICTIPFW);
index dfebc45429a852f6728c025557f9f90fec49ee5c..b528053b1e67d1f7e1bff82c15cd00f6afd7e430 100644 (file)
@@ -44,7 +44,6 @@ typedef enum {
     TMM_ALERTDEBUGLOG,
     TMM_RESPONDREJECT,
     TMM_LOGTLSLOG,
-    TMM_LOGTCPDATALOG,
     TMM_OUTPUTJSON,
     TMM_PCAPLOG,
     TMM_DECODEIPFW,