]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading: let cpu set building callback return a value
authorLukas Sismis <lsismis@oisf.net>
Sat, 24 May 2025 10:16:50 +0000 (12:16 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 7 Jun 2025 08:36:43 +0000 (10:36 +0200)
src/util-affinity.c
src/util-affinity.h
src/util-ebpf.c

index 52edbffa2cfd2eaa8b3b7f843f4c8d435ff1b1f0..da0df29930835294ee95fa89bd6d1b7654b6748d 100644 (file)
@@ -222,7 +222,7 @@ static void AffinitySetupInit(void)
     }
 }
 
-void BuildCpusetWithCallback(
+int BuildCpusetWithCallback(
         const char *name, SCConfNode *node, void (*Callback)(int i, void *data), void *data)
 {
     SCConfNode *lnode;
@@ -242,15 +242,15 @@ void BuildCpusetWithCallback(
             char *sep = strchr(lnode->val, '-');
             if (StringParseUint32(&a, 10, sep - lnode->val, lnode->val) < 0) {
                 SCLogError("%s: invalid cpu range (start invalid): \"%s\"", name, lnode->val);
-                exit(EXIT_FAILURE);
+                return -1;
             }
             if (StringParseUint32(&b, 10, strlen(sep) - 1, sep + 1) < 0) {
                 SCLogError("%s: invalid cpu range (end invalid): \"%s\"", name, lnode->val);
-                exit(EXIT_FAILURE);
+                return -1;
             }
             if (a > b) {
                 SCLogError("%s: invalid cpu range (bad order): \"%s\"", name, lnode->val);
-                exit(EXIT_FAILURE);
+                return -1;
             }
             if (b > max) {
                 SCLogError("%s: upper bound (%d) of cpu set is too high, only %d cpu(s)", name, b,
@@ -259,7 +259,7 @@ void BuildCpusetWithCallback(
         } else {
             if (StringParseUint32(&a, 10, strlen(lnode->val), lnode->val) < 0) {
                 SCLogError("%s: invalid cpu range (not an integer): \"%s\"", name, lnode->val);
-                exit(EXIT_FAILURE);
+                return -1;
             }
             b = a;
         }
@@ -270,6 +270,7 @@ void BuildCpusetWithCallback(
             break;
         }
     }
+    return 0;
 }
 
 static void AffinityCallback(int i, void *data)
@@ -277,9 +278,9 @@ static void AffinityCallback(int i, void *data)
     CPU_SET(i, (cpu_set_t *)data);
 }
 
-static void BuildCpuset(const char *name, SCConfNode *node, cpu_set_t *cpu)
+static int BuildCpuset(const char *name, SCConfNode *node, cpu_set_t *cpu)
 {
-    BuildCpusetWithCallback(name, node, AffinityCallback, (void *) cpu);
+    return BuildCpusetWithCallback(name, node, AffinityCallback, (void *)cpu);
 }
 
 /**
@@ -303,7 +304,9 @@ static void SetupCpuSets(ThreadsAffinityType *taf, SCConfNode *affinity, const c
     CPU_ZERO(&taf->cpu_set);
     SCConfNode *cpu_node = SCConfNodeLookupChild(affinity, "cpu");
     if (cpu_node != NULL) {
-        BuildCpuset(setname, cpu_node, &taf->cpu_set);
+        if (BuildCpuset(setname, cpu_node, &taf->cpu_set) < 0) {
+            SCLogWarning("Failed to parse CPU set for %s", setname);
+        }
     } else {
         SCLogWarning("Unable to find 'cpu' node for set %s", setname);
     }
@@ -317,7 +320,9 @@ static void BuildPriorityCpuset(ThreadsAffinityType *taf, SCConfNode *prio_node,
 {
     SCConfNode *node = SCConfNodeLookupChild(prio_node, priority);
     if (node != NULL) {
-        BuildCpuset(setname, node, cpuset);
+        if (BuildCpuset(setname, node, cpuset) < 0) {
+            SCLogWarning("Failed to parse %s priority CPU set for %s", priority, setname);
+        }
     } else {
         SCLogDebug("Unable to find '%s' priority for set %s", priority, setname);
     }
index 202f5ba8b0c0efde82291e7e513f6df859e511df..a44f65e8a176f329e8fe16fc6a66a8dffda8e6d4 100644 (file)
@@ -112,7 +112,11 @@ uint16_t UtilAffinityCpusOverlap(ThreadsAffinityType *taf1, ThreadsAffinityType
 void UtilAffinityCpusExclude(ThreadsAffinityType *mod_taf, ThreadsAffinityType *static_taf);
 #endif /* HAVE_DPDK */
 
-void BuildCpusetWithCallback(
+int BuildCpusetWithCallback(
         const char *name, SCConfNode *node, void (*Callback)(int i, void *data), void *data);
 
+#ifdef UNITTESTS
+void ThreadingAffinityRegisterTests(void);
+#endif
+
 #endif /* SURICATA_UTIL_AFFINITY_H */
index 7b7294d993b4f1e913e088a130a1f70dfd7067ff..e6f5e7fe915b209f90b092b15974bd6e5ba66881 100644 (file)
@@ -980,9 +980,10 @@ void EBPFBuildCPUSet(SCConfNode *node, char *iface)
                         BPF_ANY);
         return;
     }
-    BuildCpusetWithCallback("xdp-cpu-redirect", node,
-            EBPFRedirectMapAddCPU,
-            iface);
+    if (BuildCpusetWithCallback("xdp-cpu-redirect", node, EBPFRedirectMapAddCPU, iface) < 0) {
+        SCLogWarning("Failed to parse XDP CPU redirect configuration");
+        return;
+    }
     bpf_map_update_elem(mapfd, &key0, &g_redirect_iface_cpu_counter,
                         BPF_ANY);
 }