]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: add support for enabling IPS support in DPDK mode
authorLukas Sismis <lsismis@oisf.net>
Wed, 19 Oct 2022 21:18:59 +0000 (23:18 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 24 Jan 2023 09:44:49 +0000 (10:44 +0100)
src/runmode-dpdk.c

index 1d0a1839e1dbc50a54da55147d122dbcdf88e4db..55cac70a5f5df98dfa21272fb2409aeb55d17de7 100644 (file)
@@ -45,6 +45,8 @@
 #include "util-dpdk-ice.h"
 #include "util-dpdk-ixgbe.h"
 #include "util-time.h"
+#include "util-conf.h"
+#include "suricata.h"
 
 #ifdef HAVE_DPDK
 
@@ -1362,6 +1364,62 @@ static int DPDKConfigGetThreadsCount(void *conf)
 
 #endif /* HAVE_DPDK */
 
+static int DPDKRunModeIsIPS(void)
+{
+    /* Find initial node */
+    const char dpdk_node_query[] = "dpdk.interfaces";
+    ConfNode *dpdk_node = ConfGetNode(dpdk_node_query);
+    if (dpdk_node == NULL) {
+        FatalError("Unable to get %s configuration node", dpdk_node_query);
+    }
+
+    const char default_iface[] = "default";
+    ConfNode *if_default = ConfNodeLookupKeyValue(dpdk_node, "interface", default_iface);
+    int nlive = LiveGetDeviceCount();
+    bool has_ips = false;
+    bool has_ids = false;
+    for (int ldev = 0; ldev < nlive; ldev++) {
+        const char *live_dev = LiveGetDeviceName(ldev);
+        if (live_dev == NULL)
+            FatalError("Unable to get device id %d from LiveDevice list", ldev);
+
+        ConfNode *if_root = ConfFindDeviceConfig(dpdk_node, live_dev);
+        if (if_root == NULL) {
+            if (if_default == NULL)
+                FatalError("Unable to get %s or %s  interface", live_dev, default_iface);
+
+            if_root = if_default;
+        }
+
+        const char *copymodestr = NULL;
+        if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1) {
+            if (strcmp(copymodestr, "ips") == 0) {
+                has_ips = true;
+            } else {
+                has_ids = true;
+            }
+        } else {
+            has_ids = true;
+        }
+
+        if (has_ids && has_ips) {
+            FatalError("Copy-mode of interface %s mixes with the previously set copy-modes "
+                       "(only IDS/TAP and IPS copy-mode combinations are allowed in DPDK",
+                    live_dev);
+        }
+    }
+
+    return has_ips;
+}
+
+static void DPDKRunModeEnableIPS(void)
+{
+    if (DPDKRunModeIsIPS()) {
+        SCLogInfo("Setting IPS mode");
+        EngineModeSetIPS();
+    }
+}
+
 const char *RunModeDpdkGetDefaultMode(void)
 {
     return "workers";
@@ -1372,7 +1430,7 @@ void RunModeDpdkRegister(void)
     RunModeRegisterNewRunMode(RUNMODE_DPDK, "workers",
             "Workers DPDK mode, each thread does all"
             " tasks from acquisition to logging",
-            RunModeIdsDpdkWorkers, NULL);
+            RunModeIdsDpdkWorkers, DPDKRunModeEnableIPS);
 }
 
 /**