]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
runmodes: earlier evaluation of IPS mode
authorLukas Sismis <lsismis@oisf.net>
Wed, 3 May 2023 07:41:55 +0000 (09:41 +0200)
committerVictor Julien <vjulien@oisf.net>
Thu, 4 May 2023 13:40:57 +0000 (15:40 +0200)
Move evaluation of engine runmode to an earlier
phase so that dependend modules rely on properly
configured engine runmode.

Ticket: #5958

src/runmode-af-packet.c
src/runmode-netmap.c
src/suricata.c

index e15203b3c0660c6d8eb684759471e814adc57635..27a6bd26c2c1dabcb051c7387a291626532775bf 100644 (file)
@@ -702,7 +702,7 @@ static int AFPConfigGeThreadsCount(void *conf)
 
 int AFPRunModeIsIPS(void)
 {
-    int nlive = LiveGetDeviceCount();
+    int nlive = LiveGetDeviceNameCount();
     int ldev;
     ConfNode *if_root;
     ConfNode *if_default = NULL;
@@ -719,7 +719,7 @@ int AFPRunModeIsIPS(void)
     if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
 
     for (ldev = 0; ldev < nlive; ldev++) {
-        const char *live_dev = LiveGetDeviceName(ldev);
+        const char *live_dev = LiveGetDeviceNameName(ldev);
         if (live_dev == NULL) {
             SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
             return 0;
@@ -751,7 +751,7 @@ int AFPRunModeIsIPS(void)
                 "AF_PACKET using both IPS and TAP/IDS mode, this will not "
                 "be allowed in Suricata 8 due to undefined behavior. See ticket #5588.");
         for (ldev = 0; ldev < nlive; ldev++) {
-            const char *live_dev = LiveGetDeviceName(ldev);
+            const char *live_dev = LiveGetDeviceNameName(ldev);
             if (live_dev == NULL) {
                 SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
                 return 0;
index 794a623d66cb2777439942001b88b399653b9610..6746e77d481189d5bdaa47a25be693b711e8f3dd 100644 (file)
@@ -360,7 +360,7 @@ static int NetmapConfigGeThreadsCount(void *conf)
 
 int NetmapRunModeIsIPS(void)
 {
-    int nlive = LiveGetDeviceCount();
+    int nlive = LiveGetDeviceNameCount();
     int ldev;
     ConfNode *if_root;
     ConfNode *if_default = NULL;
@@ -377,7 +377,7 @@ int NetmapRunModeIsIPS(void)
     if_default = ConfNodeLookupKeyValue(netmap_node, "interface", "default");
 
     for (ldev = 0; ldev < nlive; ldev++) {
-        const char *live_dev = LiveGetDeviceName(ldev);
+        const char *live_dev = LiveGetDeviceNameName(ldev);
         if (live_dev == NULL) {
             SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
             return 0;
@@ -409,7 +409,7 @@ int NetmapRunModeIsIPS(void)
                 "Netmap using both IPS and TAP/IDS mode, this will not be "
                 "allowed in Suricata 8 due to undefined behavior. See ticket #5588.");
         for (ldev = 0; ldev < nlive; ldev++) {
-            const char *live_dev = LiveGetDeviceName(ldev);
+            const char *live_dev = LiveGetDeviceNameName(ldev);
             if (live_dev == NULL) {
                 SCLogError(SC_ERR_INVALID_VALUE, "Problem with config file");
                 return 0;
index e7f6f72d9e43b465238405cb1e00e73cd8ac6f36..04eb3d400f4de21295430b3e89af4b7dab42e7d8 100644 (file)
@@ -2453,10 +2453,8 @@ void PostConfLoadedDetectSetup(SCInstance *suri)
     }
 }
 
-static int PostDeviceFinalizedSetup(SCInstance *suri)
+static void RunModeEngineIsIPS(SCInstance *suri)
 {
-    SCEnter();
-
 #ifdef HAVE_AF_PACKET
     if (suri->run_mode == RUNMODE_AFP_DEV) {
         if (AFPRunModeIsIPS()) {
@@ -2599,6 +2597,9 @@ int PostConfLoadedSetup(SCInstance *suri)
 
     MacSetRegisterFlowStorage();
 
+    /* set engine mode if L2 IPS */
+    RunModeEngineIsIPS(suri);
+
     AppLayerSetup();
 
     /* Suricata will use this umask if provided. By default it will use the
@@ -2718,11 +2719,6 @@ int PostConfLoadedSetup(SCInstance *suri)
 
     LiveDeviceFinalize();
 
-    /* set engine mode if L2 IPS */
-    if (PostDeviceFinalizedSetup(suri) != TM_ECODE_OK) {
-        exit(EXIT_FAILURE);
-    }
-
     /* hostmode depends on engine mode being set */
     PostConfLoadedSetupHostMode();