Fix IPv6 sets nftables translation
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/1 Fix IPv6 sets nftables translation
The parser assumes the set is an IPv4 ipset because IPSET_OPT_FAMILY is not set.
# ipset-translate restore < ./ipset-mwan3_set_connected_ipv6.dump
add table inet global
add set inet global mwan3_connected_v6 { type ipv6_addr; flags interval; }
flush set inet global mwan3_connected_v6
ipset v7.15: Error in line 4: Syntax error: '64' is out of range 0-32Remove ipset_xlate_type_get(), call ipset_xlate_set_get() instead to obtain the set type and family.
--- lib/ipset.c | 24 ++++++++++-------------- tests/xlate/xlate.t | 2 ++ tests/xlate/xlate.t.nft | 2 ++ 3 files changed, 14 insertions(+), 14 deletions(-)
lib/ipset.c +10 -14
@@ -949,18 +949,6 @@ ipset_xlate_set_get(struct ipset *ipset, const char *name)return NULL ; } -static const struct ipset_type *ipset_xlate_type_get (struct ipset *ipset, -const char *name) -{ -const struct ipset_xlate_set *set; - - set =ipset_xlate_set_get (ipset, name); -if (!set) -return NULL ; - -return set->type; -} -static int ipset_parser (struct ipset *ipset,int oargc,char *oargv[]) {
@@ -1282,8 +1270,16 @@ ipset_parser(struct ipset *ipset, int oargc, char *oargv[])if (!ipset->xlate) { type =ipset_type_get (session, cmd); }else { - type =ipset_xlate_type_get (ipset, arg0); -ipset_session_data_set (session,IPSET_OPT_TYPE , type); +const struct ipset_xlate_set *xlate_set; + + xlate_set =ipset_xlate_set_get (ipset, arg0); +if (xlate_set) { +ipset_session_data_set (session,IPSET_OPT_TYPE , + xlate_set->type); +ipset_session_data_set (session,IPSET_OPT_FAMILY , + &xlate_set->family); + type = xlate_set->type; + } }if (type ==NULL )return ipset->standard_error (ipset, p);
tests/xlate/xlate.t +2 -0
@@ -53,3 +53,5 @@ create bp1 bitmap:port range 1-1024 add bp1 22 create bim1 bitmap:ip,mac range 1.1.1.0/24 add bim1 1.1.1.1,aa:bb:cc:dd:ee:ff +create hn6 hash:net family inet6 +add hn6 fe80::/64
tests/xlate/xlate.t.nft +2 -0
@@ -54,3 +54,5 @@ add set inet global bp1 { type inet_service; } add element inet global bp1 { 22 } add set inet global bim1 { type ipv4_addr . ether_addr; } add element inet global bim1 { 1.1.1.1 . aa:bb:cc:dd:ee:ff } +add set inet global hn6 { type ipv6_addr; flags interval; } +add element inet global hn6 { fe80::/64 }
Signature · 1 line
2.30.2
Thanks Pablo for the fix.
Works as expecected:
root@st-dev-07 /tmp/run/mwan3/iptables-log #
cat ipset-mwan3_set_connected_ipv6.dump && ipset-translate restore < ipset-mwan3_set_connected_ipv6.dump
-! create mwan3_connected_ipv6 hash:net family inet6
flush mwan3_connected_ipv6
-! add mwan3_connected_ipv6 fe80::/64
-! add mwan3_connected_ipv6 fe80::/64
add table inet global
add set inet global mwan3_connected_ipv6 { type ipv6_addr; flags interval; } flush set inet global mwan3_connected_ipv6
add element inet global mwan3_connected_ipv6 { fe80::/64 }
add element inet global mwan3_connected_ipv6 { fe80::/64 }
Quoted 10 lines · Pablo Neira Ayuso
The parser assumes the set is an IPv4 ipset because
IPSET_OPT_FAMILYis not set.# ipset-translate restore < ./ipset-mwan3_set_connected_ipv6.dump add table inet global add set inet global mwan3_connected_v6 { type ipv6_addr; flags interval; } flush set inet global mwan3_connected_v6 ipset v7.15: Error in line 4: Syntax error: '64' is out of range 0-32
Quoted 6 lines
Remove
ipset_xlate_type_get(), callipset_xlate_set_get()instead to obtain the set type and family.Reported-by Florian Eckert <[email protected]>Fixes 325af556cd3a ("add ipset to nftables translation infrastructure")Signed-off-by Pablo Neira Ayuso <[email protected]>
Quoted 71 lines
--- lib/ipset.c | 24 ++++++++++-------------- tests/xlate/xlate.t | 2 ++ tests/xlate/xlate.t.nft | 2 ++ 3 files changed, 14 insertions(+), 14 deletions(-)lib/ipset.c +0
-12@@ -949,18 +949,6 @@ ipset_xlate_set_get(struct ipset *ipset, const char *name)return NULL ; } -static const struct ipset_type *ipset_xlate_type_get (struct ipset *ipset, -const char *name) -{ -const struct ipset_xlate_set *set; - - set =ipset_xlate_set_get (ipset, name); -if (!set) -return NULL ; - -return set->type; -} - static int
ipset_parser(struct ipset *ipset, int oargc, char *oargv[]){lib/ipset.c +10
-2@@ -1282,8 +1270,16 @@ ipset_parser(struct ipset *ipset, int oargc, char *oargv[])if (!ipset->xlate) { type =ipset_type_get (session, cmd); }else { - type =ipset_xlate_type_get (ipset, arg0); -ipset_session_data_set (session,IPSET_OPT_TYPE , type); +const struct ipset_xlate_set *xlate_set; + + xlate_set =ipset_xlate_set_get (ipset, arg0); +if (xlate_set) { +ipset_session_data_set (session,IPSET_OPT_TYPE , + xlate_set->type); +ipset_session_data_set (session,IPSET_OPT_FAMILY , + &xlate_set->family); + type = xlate_set->type; + } }if (type ==NULL )lib/ipset.c +0
-0return ipset->standard_error (ipset, p);tests/xlate/xlate.t +2
-0@@ -53,3 +53,5 @@ create bp1 bitmap:port range 1-1024 add bp1 22 create bim1 bitmap:ip,mac range 1.1.1.0/24 add bim1 1.1.1.1,aa:bb:cc:dd:ee:ff +create hn6 hash:net family inet6 +add hn6 fe80::/64tests/xlate/xlate.t.nft +2
-0@@ -54,3 +54,5 @@ add set inet global bp1 { type inet_service; } add element inet global bp1 { 22 } add set inet global bim1 { type ipv4_addr . ether_addr; } add element inet global bim1 { 1.1.1.1 . aa:bb:cc:dd:ee:ff } +add set inet global hn6 { type ipv6_addr; flags interval; } +add element inet global hn6 { fe80::/64 }