]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output/tx: use dynamic number of app-layer protos
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 4 Jul 2024 13:11:53 +0000 (15:11 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 1 Aug 2024 05:05:14 +0000 (07:05 +0200)
Ticket: 5053

src/output-tx.c
src/suricata.c

index 582477c16408b87df83823ded134caecaa839f55..06c8c98c735764d630b07a43865f17ae0b5def47 100644 (file)
@@ -61,7 +61,7 @@ typedef struct OutputTxLogger_ {
     void (*ThreadExitPrintStats)(ThreadVars *, void *);
 } OutputTxLogger;
 
-static OutputTxLogger *list[ALPROTO_MAX] = { NULL };
+static OutputTxLogger **list = NULL;
 
 int OutputRegisterTxLogger(LoggerId id, const char *name, AppProto alproto,
                            TxLogger LogFunc,
@@ -71,6 +71,14 @@ int OutputRegisterTxLogger(LoggerId id, const char *name, AppProto alproto,
                            ThreadDeinitFunc ThreadDeinit,
                            void (*ThreadExitPrintStats)(ThreadVars *, void *))
 {
+    if (list == NULL) {
+        list = SCCalloc(ALPROTO_MAX, sizeof(OutputTxLogger *));
+        if (unlikely(list == NULL)) {
+            SCLogError("Failed to allocate OutputTx list");
+            return -1;
+        }
+    }
+
     if (alproto != ALPROTO_UNKNOWN && !(AppLayerParserIsEnabled(alproto))) {
         SCLogDebug(
                 "%s logger not enabled: protocol %s is disabled", name, AppProtoToString(alproto));
@@ -666,12 +674,21 @@ static uint32_t OutputTxLoggerGetActiveCount(void)
 
 void OutputTxLoggerRegister (void)
 {
+    BUG_ON(list);
+    list = SCCalloc(ALPROTO_MAX, sizeof(OutputTxLogger *));
+    if (unlikely(list == NULL)) {
+        FatalError("Failed to allocate OutputTx list");
+    }
     OutputRegisterRootLogger(OutputTxLogThreadInit, OutputTxLogThreadDeinit,
         OutputTxLogExitPrintStats, OutputTxLog, OutputTxLoggerGetActiveCount);
 }
 
 void OutputTxShutdown(void)
 {
+    // called in different places because of unix socket mode, and engine-analysis mode
+    if (list == NULL) {
+        return;
+    }
     for (AppProto alproto = 0; alproto < ALPROTO_MAX; alproto++) {
         OutputTxLogger *logger = list[alproto];
         while (logger) {
@@ -681,4 +698,6 @@ void OutputTxShutdown(void)
         }
         list[alproto] = NULL;
     }
+    SCFree(list);
+    list = NULL;
 }
index 13b48fe91770a356d71a34c2eca496b862d6cbaa..a20b5f39cbcbfeafeca6ffdbb60b49da484c16a9 100644 (file)
@@ -386,6 +386,7 @@ void GlobalsDestroy(void)
     AppLayerDeSetup();
     DatasetsSave();
     DatasetsDestroy();
+    OutputTxShutdown();
     TagDestroyCtx();
 
     LiveDeviceListClean();