]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
iptablesPrivateChainCreate: Switch to STRSKIP()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 26 Nov 2025 14:05:50 +0000 (15:05 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 2 Dec 2025 11:42:15 +0000 (12:42 +0100)
The body of iptablesPrivateChainCreate() uses STRPREFIX() to
match strings starting with certain prefix. Then it uses pointer
arithmetic to skip the prefix. Well, that's exactly what
STRSKIP() is meant to do. Switch the body to use the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Jaroslav Suchanek <jsuchane@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/network/network_iptables.c

index be91b273ed866488a75583dae071d6cbd5800fbd..19dcfc7c8b0979d1783db0978729af8b0e4411d6 100644 (file)
@@ -90,17 +90,21 @@ iptablesPrivateChainCreate(virFirewall *fw,
 
     line = lines;
     while (line && *line) {
-        if (STRPREFIX(*line, "-N ")) { /* eg "-N LIBVIRT_INP" */
-            if (virHashUpdateEntry(chains, *line + 3, (void *)0x1) < 0)
+        const char *tmp;
+
+        if ((tmp = STRSKIP(*line, "-N "))) { /* eg "-N LIBVIRT_INP" */
+            if (virHashUpdateEntry(chains, tmp, (void *)0x1) < 0)
                 return -1;
-        } else if (STRPREFIX(*line, "-A ")) { /* eg "-A INPUT -j LIBVIRT_INP" */
-            char *sep = strchr(*line + 3, ' ');
+        } else if ((tmp = STRSKIP(*line, "-A "))) { /* eg "-A INPUT -j LIBVIRT_INP" */
+            char *sep = strchr(tmp, ' ');
 
             if (sep) {
+                char *target;
+
                 *sep = '\0';
-                if (STRPREFIX(sep + 1, "-j ")) {
-                    if (virHashUpdateEntry(links, sep + 4,
-                                           (char *)*line + 3) < 0)
+                if ((target = STRSKIP(sep + 1, "-j "))) {
+                    if (virHashUpdateEntry(links, target,
+                                           (char *)tmp) < 0)
                         return -1;
                 }
             }