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