summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2025-10-07 17:45:25 +0200
committerPhil Sutter <phil@nwl.cc>2025-10-15 22:08:18 +0200
commit6f24a13a19b8690444564f50e1866fae5abf7687 (patch)
tree2008319984230cd32bcf15858234b7a89d1fb75b /src
parentdd25d612811ed093b6941ca95240eb1aa7704046 (diff)
utils: Drop asterisk from end of NFTA_DEVICE_PREFIX strings
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>
Diffstat (limited to 'src')
-rw-r--r--src/utils.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/utils.c b/src/utils.c
index c4bbd4f..d73c5f6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -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);
}