Blame SOURCES/0011-xtables-translate-Fix-for-iface.patch

621646
From 1e1fda9ac0a809c64fd13b4fb759becac824809e Mon Sep 17 00:00:00 2001
621646
From: Phil Sutter <phil@nwl.cc>
621646
Date: Thu, 13 Feb 2020 14:01:50 +0100
621646
Subject: [PATCH] xtables-translate: Fix for iface++
621646
621646
In legacy iptables, only the last plus sign remains special, any
621646
previous ones are taken literally. Therefore xtables-translate must not
621646
replace all of them with asterisk but just the last one.
621646
621646
Fixes: e179e87a1179e ("xtables-translate: Fix for interface name corner-cases")
621646
Signed-off-by: Phil Sutter <phil@nwl.cc>
621646
(cherry picked from commit 94488d4eb912f5af4c88d148b39b38eb8a3c1f0b)
621646
Signed-off-by: Phil Sutter <psutter@redhat.com>
621646
---
621646
 extensions/generic.txlate    | 4 ++++
621646
 iptables/xtables-translate.c | 6 +++---
621646
 2 files changed, 7 insertions(+), 3 deletions(-)
621646
621646
diff --git a/extensions/generic.txlate b/extensions/generic.txlate
621646
index c92d082abea78..0e256c3727559 100644
621646
--- a/extensions/generic.txlate
621646
+++ b/extensions/generic.txlate
621646
@@ -23,6 +23,10 @@ nft insert rule bridge filter INPUT ether type 0x800 ether daddr 01:02:03:04:00:
621646
 iptables-translate -A FORWARD -i '*' -o 'eth*foo'
621646
 nft add rule ip filter FORWARD iifname "\*" oifname "eth\*foo" counter
621646
 
621646
+# escape all asterisks but translate only the first plus character
621646
+iptables-translate -A FORWARD -i 'eth*foo*+' -o 'eth++'
621646
+nft add rule ip filter FORWARD iifname "eth\*foo\**" oifname "eth+*" counter
621646
+
621646
 # skip for always matching interface names
621646
 iptables-translate -A FORWARD -i '+'
621646
 nft add rule ip filter FORWARD counter
621646
diff --git a/iptables/xtables-translate.c b/iptables/xtables-translate.c
621646
index c4e177c0d63ba..0f95855b41aa4 100644
621646
--- a/iptables/xtables-translate.c
621646
+++ b/iptables/xtables-translate.c
621646
@@ -40,9 +40,6 @@ void xlate_ifname(struct xt_xlate *xl, const char *nftmeta, const char *ifname,
621646
 
621646
 	for (i = 0, j = 0; i < ifaclen + 1; i++, j++) {
621646
 		switch (ifname[i]) {
621646
-		case '+':
621646
-			iface[j] = '*';
621646
-			break;
621646
 		case '*':
621646
 			iface[j++] = '\\';
621646
 			/* fall through */
621646
@@ -65,6 +62,9 @@ void xlate_ifname(struct xt_xlate *xl, const char *nftmeta, const char *ifname,
621646
 		invert = false;
621646
 	}
621646
 
621646
+	if (iface[j - 2] == '+')
621646
+		iface[j - 2] = '*';
621646
+
621646
 	xt_xlate_add(xl, "%s %s\"%s\" ", nftmeta, invert ? "!= " : "", iface);
621646
 }
621646
 
621646
-- 
621646
2.24.1
621646