Blame SOURCES/0007-Fix-IPv6-sets-nftables-translation.patch

74da1b
From 343650906603dff56f766d1fbcef1de64a98e14a Mon Sep 17 00:00:00 2001
74da1b
From: Pablo Neira Ayuso <pablo@netfilter.org>
74da1b
Date: Mon, 28 Feb 2022 19:52:57 +0100
74da1b
Subject: [PATCH] Fix IPv6 sets nftables translation
74da1b
74da1b
The parser assumes the set is an IPv4 ipset because IPSET_OPT_FAMILY is
74da1b
not set.
74da1b
74da1b
 # ipset-translate restore < ./ipset-mwan3_set_connected_ipv6.dump
74da1b
 add table inet global
74da1b
 add set inet global mwan3_connected_v6 { type ipv6_addr; flags interval; }
74da1b
 flush set inet global mwan3_connected_v6
74da1b
 ipset v7.15: Error in line 4: Syntax error: '64' is out of range 0-32
74da1b
74da1b
Remove ipset_xlate_type_get(), call ipset_xlate_set_get() instead to
74da1b
obtain the set type and family.
74da1b
74da1b
Reported-by: Florian Eckert <fe@dev.tdt.de>
74da1b
Fixes: 325af556cd3a ("add ipset to nftables translation infrastructure")
74da1b
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
74da1b
(cherry picked from commit be7f6099feb7b5d34715b06f9308877cdcdc404a)
74da1b
---
74da1b
 lib/ipset.c             | 24 ++++++++++--------------
74da1b
 tests/xlate/xlate.t     |  2 ++
74da1b
 tests/xlate/xlate.t.nft |  2 ++
74da1b
 3 files changed, 14 insertions(+), 14 deletions(-)
74da1b
74da1b
diff --git a/lib/ipset.c b/lib/ipset.c
74da1b
index 73e67db88e0d1..50f86aee045bc 100644
74da1b
--- a/lib/ipset.c
74da1b
+++ b/lib/ipset.c
74da1b
@@ -949,18 +949,6 @@ ipset_xlate_set_get(struct ipset *ipset, const char *name)
74da1b
 	return NULL;
74da1b
 }
74da1b
 
74da1b
-static const struct ipset_type *ipset_xlate_type_get(struct ipset *ipset,
74da1b
-						     const char *name)
74da1b
-{
74da1b
-	const struct ipset_xlate_set *set;
74da1b
-
74da1b
-	set = ipset_xlate_set_get(ipset, name);
74da1b
-	if (!set)
74da1b
-		return NULL;
74da1b
-
74da1b
-	return set->type;
74da1b
-}
74da1b
-
74da1b
 static int
74da1b
 ipset_parser(struct ipset *ipset, int oargc, char *oargv[])
74da1b
 {
74da1b
@@ -1282,8 +1270,16 @@ ipset_parser(struct ipset *ipset, int oargc, char *oargv[])
74da1b
 		if (!ipset->xlate) {
74da1b
 			type = ipset_type_get(session, cmd);
74da1b
 		} else {
74da1b
-			type = ipset_xlate_type_get(ipset, arg0);
74da1b
-			ipset_session_data_set(session, IPSET_OPT_TYPE, type);
74da1b
+			const struct ipset_xlate_set *xlate_set;
74da1b
+
74da1b
+			xlate_set = ipset_xlate_set_get(ipset, arg0);
74da1b
+			if (xlate_set) {
74da1b
+				ipset_session_data_set(session, IPSET_OPT_TYPE,
74da1b
+						       xlate_set->type);
74da1b
+				ipset_session_data_set(session, IPSET_OPT_FAMILY,
74da1b
+						       &xlate_set->family);
74da1b
+				type = xlate_set->type;
74da1b
+			}
74da1b
 		}
74da1b
 		if (type == NULL)
74da1b
 			return ipset->standard_error(ipset, p);
74da1b
diff --git a/tests/xlate/xlate.t b/tests/xlate/xlate.t
74da1b
index b1e7d288e2a98..f09cb202bb6c0 100644
74da1b
--- a/tests/xlate/xlate.t
74da1b
+++ b/tests/xlate/xlate.t
74da1b
@@ -53,3 +53,5 @@ create bp1 bitmap:port range 1-1024
74da1b
 add bp1 22
74da1b
 create bim1 bitmap:ip,mac range 1.1.1.0/24
74da1b
 add bim1 1.1.1.1,aa:bb:cc:dd:ee:ff
74da1b
+create hn6 hash:net family inet6
74da1b
+add hn6 fe80::/64
74da1b
diff --git a/tests/xlate/xlate.t.nft b/tests/xlate/xlate.t.nft
74da1b
index 96eba3b0175ea..0152a30811258 100644
74da1b
--- a/tests/xlate/xlate.t.nft
74da1b
+++ b/tests/xlate/xlate.t.nft
74da1b
@@ -54,3 +54,5 @@ add set inet global bp1 { type inet_service; }
74da1b
 add element inet global bp1 { 22 }
74da1b
 add set inet global bim1 { type ipv4_addr . ether_addr; }
74da1b
 add element inet global bim1 { 1.1.1.1 . aa:bb:cc:dd:ee:ff }
74da1b
+add set inet global hn6 { type ipv6_addr; flags interval; }
74da1b
+add element inet global hn6 { fe80::/64 }
74da1b
-- 
74da1b
2.38.0
74da1b