]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
af-packet: clean up IPS config check
authorVictor Julien <vjulien@oisf.net>
Wed, 22 Nov 2023 09:41:47 +0000 (10:41 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 10 Feb 2025 19:01:34 +0000 (20:01 +0100)
Don't emmit generic error statements on things that are not errors. Instead,
for cases where (part of) the config is missing, use the defaults and log
only a more detailed explanation at the 'config' level.

Minor code cleanups.

src/runmode-af-packet.c

index d26df0f710a53df9972eca353c1abf0e4f389844..6df1b1fbafe8e4013913963ce90a9be87f619c73 100644 (file)
@@ -66,36 +66,33 @@ const char *RunModeAFPGetDefaultMode(void)
     return "workers";
 }
 
-static int AFPRunModeIsIPS(void)
+static bool AFPRunModeIsIPS(void)
 {
     int nlive = LiveGetDeviceCount();
-    int ldev;
-    ConfNode *if_root;
-    ConfNode *if_default = NULL;
-    ConfNode *af_packet_node;
-    int has_ips = 0;
-    int has_ids = 0;
+    bool has_ips = false;
+    bool has_ids = false;
 
-    /* Find initial node */
-    af_packet_node = ConfGetNode("af-packet");
+    ConfNode *af_packet_node = ConfGetNode("af-packet");
     if (af_packet_node == NULL) {
-        return 0;
+        SCLogConfig("no 'af-packet' section in the yaml, default to IDS");
+        return false;
     }
 
-    if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
+    ConfNode *if_default = ConfNodeLookupKeyValue(af_packet_node, "interface", "default");
 
-    for (ldev = 0; ldev < nlive; ldev++) {
+    for (int ldev = 0; ldev < nlive; ldev++) {
         const char *live_dev = LiveGetDeviceName(ldev);
         if (live_dev == NULL) {
-            SCLogError("Problem with config file");
-            return -1;
+            SCLogConfig("invalid livedev at index %d, default to IDS", ldev);
+            return false;
         }
-        if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
-
+        ConfNode *if_root = ConfFindDeviceConfig(af_packet_node, live_dev);
         if (if_root == NULL) {
             if (if_default == NULL) {
-                SCLogError("Problem with config file");
-                return -1;
+                SCLogConfig(
+                        "no 'af-packet' section for '%s' or 'default' in the yaml, default to IDS",
+                        live_dev);
+                return false;
             }
             if_root = if_default;
         }
@@ -105,19 +102,19 @@ static int AFPRunModeIsIPS(void)
         if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1 &&
                 ConfGetChildValue(if_root, "copy-iface", &copyifacestr) == 1) {
             if (strcmp(copymodestr, "ips") == 0) {
-                has_ips = 1;
+                has_ips = true;
             } else {
-                has_ids = 1;
+                has_ids = true;
             }
         } else {
-            has_ids = 1;
+            has_ids = true;
         }
     }
 
     if (has_ids && has_ips) {
         SCLogError("using both IPS and TAP/IDS mode is not allowed due to undefined behavior. See "
                    "ticket #5588.");
-        return -1;
+        return false;
     }
 
     return has_ips;
@@ -125,8 +122,8 @@ static int AFPRunModeIsIPS(void)
 
 static int AFPRunModeEnableIPS(void)
 {
-    int r = AFPRunModeIsIPS();
-    if (r == 1) {
+    bool r = AFPRunModeIsIPS();
+    if (r) {
         SCLogInfo("Setting IPS mode");
         EngineModeSetIPS();
     }