Skip to contentSkip to conversation

mnl: Drop asterisk from end of NFTA_DEVICE_PREFIX strings

PATCH In review Phil Sutter 2 participants 3 messages Oct 7, 2025 – Oct 8, 2025 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 mnl: 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 c31e887504a90 ("mnl: Support simple wildcards in netdev hooks")

---
This is covered by existing tests already. Looks like this late conversion to NFTA_DEVICE_PREFIX went entirely untested by accident.

---
 src/mnl.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
src/mnl.c +9 -2
index bba34b73a708f..ab4a7dbc8d252 100644
@@ -815,9 +815,16 @@ static bool is_wildcard_str(const char *str)
 
 static void mnl_nft_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);
 }
 
Signature · 1 line
2.51.0
author reviewer
#2 lore raw
Quoted 9 lines · Pablo Neira Ayuso
Quoted 6 lines · Phil Sutter

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 c31e887504a90 ("mnl: Support simple wildcards in netdev hooks")

Patch applied, thanks!