[pve-devel] [PULL stable-3 firewall 6/6] ipv6: fix ipv6 address normalization

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Mar 7 14:44:59 CET 2016


inet_ntop only takes an addres, not a CIDR notation. Since
the normalized address should just be a compressed
lower-case address, Net::IP::ip_compress_address should be
sufficient.

inet_ntop didn't succeed before, the result of which was
that ipsets weren't generated at all for ipv6 address ranges.
---
 src/PVE/Firewall.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 0d9a779..956ccc4 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -2985,8 +2985,10 @@ sub generate_ipset_chains {
 		}
 		#http://backreference.org/2013/03/01/ipv6-address-normalization/
 		if ($ver == 6) {
-		    my $ipv6 = inet_pton(AF_INET6, lc($cidr));
-		    $cidr = inet_ntop(AF_INET6, $ipv6);
+		    # ip_compress_address takes an address only, no CIDR
+		    my ($addr, $prefix_len) = ($cidr =~ m@^([^/]*)(/.*)?$@);
+		    $cidr = lc(Net::IP::ip_compress_address($addr, 6));
+		    $cidr .= $prefix_len if defined($prefix_len);
 		    $cidr =~ s|/128$||;
 		} else {
 		    $cidr =~ s|/32$||;
-- 
2.1.4





More information about the pve-devel mailing list