]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: fix modules ordering during logging
authorEric Leblond <eric@regit.org>
Wed, 27 May 2015 20:05:19 +0000 (22:05 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 30 May 2015 09:02:59 +0000 (11:02 +0200)
With the previous code the order of the logging modules in the
YAML were determining which module was run first. This was not
wished and a consequences was that the EVE fileinfo module was
not correctly displaying the key 'stored' because it was
depending on a flag set alter by the filestore module.

This patch adds a priority file to the TmModule structure. The
higher the priority is set, the sooner the module is run in the
logging process. The RunModeOutput structure has also been
updated to contain the name of the original TmModule. Thus allowing
to define a priority for a RunModeOutput.

Currently only the filestore has a priority set. The rest of them is
set to the default value of zero.

src/log-filestore.c
src/runmodes.c
src/tm-modules.h

index 51ad673b9e05e2a636d1a2156ac0c956a5c18543..3caee3b7ff45fd6020aebac490165b92472d6812 100644 (file)
@@ -485,6 +485,7 @@ void TmModuleLogFilestoreRegister (void)
     tmm_modules[TMM_FILESTORE].RegisterTests = NULL;
     tmm_modules[TMM_FILESTORE].cap_flags = 0;
     tmm_modules[TMM_FILESTORE].flags = TM_FLAG_LOGAPI_TM;
+    tmm_modules[TMM_FILESTORE].priority = 10;
 
     OutputRegisterFiledataModule(MODULE_NAME, "file", LogFilestoreLogInitCtx,
             LogFilestoreLogger);
index a769b9b6ee7deccd9e67a2410acebf09301732bd..5f9b201d51784dd67da362c1aae7301999f3c396 100644 (file)
@@ -72,6 +72,7 @@ typedef struct RunModes_ {
  * A list of output modules that will be active for the run mode.
  */
 typedef struct RunModeOutput_ {
+    const char *name;
     TmModule *tm_module;
     OutputCtx *output_ctx;
 
@@ -506,6 +507,32 @@ static void AddOutputToFreeList(OutputModule *module, OutputCtx *output_ctx)
     TAILQ_INSERT_TAIL(&output_free_list, fl_output, entries);
 }
 
+
+static int GetRunModeOutputPriority(RunModeOutput *module)
+{
+    TmModule *tm = TmModuleGetByName(module->name);
+    if (tm == NULL)
+        return 0;
+
+    return tm->priority;
+}
+
+static void InsertInRunModeOutputs(RunModeOutput *runmode_output)
+{
+    RunModeOutput *r_output = NULL;
+    int output_priority = GetRunModeOutputPriority(runmode_output);
+
+    TAILQ_FOREACH(r_output, &RunModeOutputs, entries) {
+        if (GetRunModeOutputPriority(r_output) < output_priority)
+            break;
+    }
+    if (r_output) {
+        TAILQ_INSERT_BEFORE(r_output, runmode_output, entries);
+    } else {
+        TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+    }
+}
+
 /** \brief Turn output into thread module */
 static void SetupOutput(const char *name, OutputModule *module, OutputCtx *output_ctx)
 {
@@ -546,9 +573,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
             RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
             if (unlikely(runmode_output == NULL))
                 return;
+            runmode_output->name = module->name;
             runmode_output->tm_module = pkt_logger_module;
             runmode_output->output_ctx = NULL;
-            TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+            InsertInRunModeOutputs(runmode_output);
             SCLogDebug("__packet_logger__ added");
         }
     } else if (module->TxLogFunc) {
@@ -568,9 +596,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
             RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
             if (unlikely(runmode_output == NULL))
                 return;
+            runmode_output->name = module->name;
             runmode_output->tm_module = tx_logger_module;
             runmode_output->output_ctx = NULL;
-            TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+            InsertInRunModeOutputs(runmode_output);
             SCLogDebug("__tx_logger__ added");
         }
     } else if (module->FiledataLogFunc) {
@@ -589,9 +618,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
             RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
             if (unlikely(runmode_output == NULL))
                 return;
+            runmode_output->name = module->name;
             runmode_output->tm_module = filedata_logger_module;
             runmode_output->output_ctx = NULL;
-            TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+            InsertInRunModeOutputs(runmode_output);
             SCLogDebug("__filedata_logger__ added");
         }
     } else if (module->FileLogFunc) {
@@ -610,9 +640,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
             RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
             if (unlikely(runmode_output == NULL))
                 return;
+            runmode_output->name = module->name;
             runmode_output->tm_module = file_logger_module;
             runmode_output->output_ctx = NULL;
-            TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+            InsertInRunModeOutputs(runmode_output);
             SCLogDebug("__file_logger__ added");
         }
     } else if (module->StreamingLogFunc) {
@@ -632,9 +663,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
             RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
             if (unlikely(runmode_output == NULL))
                 return;
+            runmode_output->name = module->name;
             runmode_output->tm_module = streaming_logger_module;
             runmode_output->output_ctx = NULL;
-            TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+            InsertInRunModeOutputs(runmode_output);
             SCLogDebug("__streaming_logger__ added");
         }
     } else {
@@ -643,9 +675,10 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
         RunModeOutput *runmode_output = SCCalloc(1, sizeof(RunModeOutput));
         if (unlikely(runmode_output == NULL))
             return;
+        runmode_output->name = module->name;
         runmode_output->tm_module = tm_module;
         runmode_output->output_ctx = output_ctx;
-        TAILQ_INSERT_TAIL(&RunModeOutputs, runmode_output, entries);
+        InsertInRunModeOutputs(runmode_output);
     }
 }
 
index 6502b21c1080683185840930bba4d2121ed42b17..c9d4e1f56e3fd99e6cbfbf77ef0ca05af1d3b455 100644 (file)
@@ -61,6 +61,8 @@ typedef struct TmModule_ {
                              the given TmModule */
     /* Other flags used by the module */
     uint8_t flags;
+    /* priority in the logging order, higher priority is runned first */
+    uint8_t priority;
 } TmModule;
 
 TmModule tmm_modules[TMM_SIZE];