]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
utils: Drop asterisk from end of NFTA_DEVICE_PREFIX strings
authorPhil Sutter <phil@nwl.cc>
Tue, 7 Oct 2025 15:45:25 +0000 (17:45 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 15 Oct 2025 20:08:18 +0000 (22:08 +0200)
The asterisk left in place becomes part of the prefix by accident and is thus
both included when matching interface names as well as dumped back to user
space.

Fixes: f30eae26d813e ("utils: Add helpers for interface name wildcards")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/utils.c

index c4bbd4f7ed171349f524ede361f191a59c42b813..d73c5f6175802141715d4c92e9b3b3d0ef42b36b 100644 (file)
@@ -164,9 +164,16 @@ static bool is_wildcard_str(const char *str)
 
 void nftnl_attr_put_ifname(struct nlmsghdr *nlh, const char *ifname)
 {
-       uint16_t attr = is_wildcard_str(ifname) ?
-                       NFTA_DEVICE_PREFIX : NFTA_DEVICE_NAME;
+       uint16_t attr = NFTA_DEVICE_NAME;
+       char pfx[IFNAMSIZ];
 
+       if (is_wildcard_str(ifname)) {
+               snprintf(pfx, IFNAMSIZ, "%s", ifname);
+               pfx[strlen(pfx) - 1] = '\0';
+
+               attr = NFTA_DEVICE_PREFIX;
+               ifname = pfx;
+       }
        mnl_attr_put_strz(nlh, attr, ifname);
 }