]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
update runmodes to handle detect-less
authorVictor Julien <victor@inliniac.net>
Mon, 16 Dec 2013 16:35:27 +0000 (17:35 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 27 Jan 2014 12:22:47 +0000 (13:22 +0100)
In runmodes setup, consider a NULL de_ctx to mean detect is disabled.

src/runmode-erf-file.c
src/runmode-pcap-file.c
src/runmode-tile.c
src/runmodes.c
src/util-runmodes.c

index e9e15f5510681f9fe633b64365f9e7028fd847c3..dad86caaaa27859b6cd7a131d5405f1ecfe8f14e 100644 (file)
@@ -106,12 +106,14 @@ int RunModeErfFileSingle(DetectEngineCtx *de_ctx)
     }
     TmSlotSetFuncAppend(tv, tm_module, NULL);
 
-    tm_module = TmModuleGetByName("Detect");
-    if (tm_module == NULL) {
-        printf("ERROR: TmModuleGetByName Detect failed\n");
-        exit(EXIT_FAILURE);
+    if (de_ctx != NULL) {
+        tm_module = TmModuleGetByName("Detect");
+        if (tm_module == NULL) {
+            printf("ERROR: TmModuleGetByName Detect failed\n");
+            exit(EXIT_FAILURE);
+        }
+        TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
     }
-    TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
 
     SetupOutputs(tv);
 
@@ -232,12 +234,14 @@ int RunModeErfFileAutoFp(DetectEngineCtx *de_ctx)
         }
         TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            printf("ERROR: TmModuleGetByName Detect failed\n");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                printf("ERROR: TmModuleGetByName Detect failed\n");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
         }
-        TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
 
         if (threading_set_cpu_affinity) {
             TmThreadSetCPUAffinity(tv_detect_ncpu, (int)cpu);
index f6ccd41a5c81da00e965681f0178431657c0b04a..ffc3d3ea07794691e7c85b86406b88d67e040a94 100644 (file)
@@ -109,12 +109,14 @@ int RunModeFilePcapSingle(DetectEngineCtx *de_ctx)
     }
     TmSlotSetFuncAppend(tv, tm_module, NULL);
 
-    tm_module = TmModuleGetByName("Detect");
-    if (tm_module == NULL) {
-        SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-        exit(EXIT_FAILURE);
+    if (de_ctx) {
+        tm_module = TmModuleGetByName("Detect");
+        if (tm_module == NULL) {
+            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+            exit(EXIT_FAILURE);
+        }
+        TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
     }
-    TmSlotSetFuncAppend(tv, tm_module, (void *)de_ctx);
 
     SetupOutputs(tv);
 
@@ -153,6 +155,11 @@ int RunModeFilePcapAuto(DetectEngineCtx *de_ctx)
     TmModule *tm_module;
     RunModeInitialize();
 
+    if (de_ctx == NULL) {
+        SCLogError(SC_ERR_RUNMODE, "can't mix runmode 'auto' and disabled detect");
+        return -1;
+    }
+
     /* Available cpus */
     uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
 
@@ -404,13 +411,14 @@ int RunModeFilePcapAutoFp(DetectEngineCtx *de_ctx)
         }
         TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-            exit(EXIT_FAILURE);
+        if (de_ctx) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
         }
-        TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, (void *)de_ctx);
-
 
         char *thread_group_name = SCStrdup("Detect");
         if (unlikely(thread_group_name == NULL)) {
index 9e86a72ee360f0b38ca7d83ac134885fe5c342b6..46e115da8cd8ee3507feeb9eb618ead71aaa001a 100644 (file)
@@ -249,12 +249,14 @@ int RunModeTileMpipeWorkers(DetectEngineCtx *de_ctx)
         }
         TmSlotSetFuncAppend(tv_worker, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            printf("ERROR: TmModuleGetByName Detect failed\n");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                printf("ERROR: TmModuleGetByName Detect failed\n");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppend(tv_worker, tm_module, (void *)de_ctx);
         }
-        TmSlotSetFuncAppend(tv_worker, tm_module, (void *)de_ctx);
 
         tm_module = TmModuleGetByName("RespondReject");
         if (tm_module == NULL) {
index 89ae0c7a8df7348c64203b629979b4ce43dfbc56..c394ae19d22cfe740386e6108c3d443f40834b50 100644 (file)
@@ -243,6 +243,9 @@ void RunModeListRunmodes(void)
     return;
 }
 
+/**
+ *  \param de_ctx Detection engine ctx. Can be NULL is detect is disabled.
+ */
 void RunModeDispatch(int runmode, const char *custom_mode, DetectEngineCtx *de_ctx)
 {
     char *local_custom_mode = NULL;
index c6a4cbf83fbb045d3b728ef7e0d568178781b97b..3c5387e463da4721fc58872bfc646aa5cfd2f302 100644 (file)
@@ -61,6 +61,11 @@ int RunModeSetLiveCaptureAuto(DetectEngineCtx *de_ctx,
     char tname[TM_THREAD_NAME_MAX];
     int thread;
 
+    if (de_ctx == NULL) {
+        SCLogError(SC_ERR_RUNMODE, "can't use runmode 'auto' when detection is disabled");
+        return -1;
+    }
+
     if ((nlive <= 1) && (live_dev != NULL)) {
         void *aconf;
         SCLogDebug("live_dev %s", live_dev);
@@ -317,6 +322,9 @@ char *RunmodeAutoFpCreatePickupQueuesString(int n) {
     return queues;
 }
 
+/**
+ *  \param de_ctx detection engine, can be NULL
+ */
 int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx,
                               ConfigIfaceParserFunc ConfigParser,
                               ConfigIfaceThreadsCountFunc ModThreadsCount,
@@ -491,13 +499,15 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx,
         }
         TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppendDelayed(tv_detect_ncpu, tm_module,
+                    (void *)de_ctx, de_ctx->delayed_detect);
         }
-        TmSlotSetFuncAppendDelayed(tv_detect_ncpu, tm_module,
-                                   (void *)de_ctx, de_ctx->delayed_detect);
 
         TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
 
@@ -528,6 +538,9 @@ int RunModeSetLiveCaptureAutoFp(DetectEngineCtx *de_ctx,
     return 0;
 }
 
+/**
+ *  \param de_ctx detection engine, can be NULL
+ */
 static int RunModeSetLiveCaptureWorkersForDevice(DetectEngineCtx *de_ctx,
                               ConfigIfaceThreadsCountFunc ModThreadsCount,
                               char *recv_mod_name,
@@ -593,13 +606,15 @@ static int RunModeSetLiveCaptureWorkersForDevice(DetectEngineCtx *de_ctx,
         }
         TmSlotSetFuncAppend(tv, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppendDelayed(tv, tm_module,
+                    (void *)de_ctx, de_ctx->delayed_detect);
         }
-        TmSlotSetFuncAppendDelayed(tv, tm_module,
-                                   (void *)de_ctx, de_ctx->delayed_detect);
 
         tm_module = TmModuleGetByName("RespondReject");
         if (tm_module == NULL) {
@@ -708,6 +723,11 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
     uint16_t ncpus = UtilCpuGetNumProcessorsOnline();
     int nqueue = LiveGetDeviceCount();
 
+    if (de_ctx == NULL) {
+        SCLogError(SC_ERR_RUNMODE, "can't use runmode 'auto' when detection is disabled");
+        return -1;
+    }
+
     for (int i = 0; i < nqueue; i++) {
         /* create the threads */
         cur_queue = LiveGetDeviceName(i);
@@ -894,6 +914,9 @@ int RunModeSetIPSAuto(DetectEngineCtx *de_ctx,
 
 }
 
+/**
+ *  \param de_ctx detection engine, can be NULL
+ */
 int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
                         ConfigIPSParserFunc ConfigParser,
                         char *recv_mod_name,
@@ -997,13 +1020,15 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
         }
         TmSlotSetFuncAppend(tv_detect_ncpu, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppendDelayed(tv_detect_ncpu, tm_module,
+                    (void *)de_ctx, de_ctx->delayed_detect);
         }
-        TmSlotSetFuncAppendDelayed(tv_detect_ncpu, tm_module,
-                                   (void *)de_ctx, de_ctx->delayed_detect);
 
         TmThreadSetCPU(tv_detect_ncpu, DETECT_CPU_SET);
 
@@ -1067,6 +1092,9 @@ int RunModeSetIPSAutoFp(DetectEngineCtx *de_ctx,
     return 0;
 }
 
+/**
+ *  \param de_ctx detection engine, can be NULL
+ */
 int RunModeSetIPSWorker(DetectEngineCtx *de_ctx,
         ConfigIPSParserFunc ConfigParser,
         char *recv_mod_name,
@@ -1125,13 +1153,15 @@ int RunModeSetIPSWorker(DetectEngineCtx *de_ctx,
         }
         TmSlotSetFuncAppend(tv, tm_module, NULL);
 
-        tm_module = TmModuleGetByName("Detect");
-        if (tm_module == NULL) {
-            SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
-            exit(EXIT_FAILURE);
+        if (de_ctx != NULL) {
+            tm_module = TmModuleGetByName("Detect");
+            if (tm_module == NULL) {
+                SCLogError(SC_ERR_RUNMODE, "TmModuleGetByName Detect failed");
+                exit(EXIT_FAILURE);
+            }
+            TmSlotSetFuncAppendDelayed(tv, tm_module,
+                    (void *)de_ctx, de_ctx->delayed_detect);
         }
-        TmSlotSetFuncAppendDelayed(tv, tm_module,
-                                   (void *)de_ctx, de_ctx->delayed_detect);
 
         tm_module = TmModuleGetByName(verdict_mod_name);
         if (tm_module == NULL) {