diff options
author | Renato Botelho <renato@netgate.com> | 2017-01-23 18:16:13 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2017-01-23 18:16:13 -0200 |
commit | c720e0ee1222b3739c40f430170901104ddd8025 (patch) | |
tree | 1bfa1e883f4b04958632dfffc202422079e194c0 /src/etc/inc/util.inc | |
parent | 02356dff6d30839c96c72884da51a02faeedf513 (diff) | |
parent | f0b1358dfe520ad3b771127127daed970ba2c0a0 (diff) | |
download | pfsense-c720e0ee1222b3739c40f430170901104ddd8025.zip pfsense-c720e0ee1222b3739c40f430170901104ddd8025.tar.gz |
Merge pull request #3414 from phil-davis/ipv6-compress
Diffstat (limited to 'src/etc/inc/util.inc')
-rw-r--r-- | src/etc/inc/util.inc | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index 38df3af..2876df9 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -266,7 +266,7 @@ function gen_subnetv4($ipaddr, $bits) { /* same as gen_subnet() but accepts IPv6 only */ function gen_subnetv6($ipaddr, $bits) { if (is_ipaddrv6($ipaddr) && is_numericint($bits) && $bits <= 128) { - return Net_IPv6::compress(Net_IPv6::getNetmask($ipaddr, $bits)); + return text_to_compressed_ip6(Net_IPv6::getNetmask($ipaddr, $bits)); } return ""; } @@ -394,7 +394,22 @@ function bin_to_ip6($bin) { * Convert IPv6 binary to compressed address */ function bin_to_compressed_ip6($bin) { - return Net_IPv6::compress(bin_to_ip6($bin)); + return text_to_compressed_ip6(bin_to_ip6($bin)); +} + +/* + * Convert textual IPv6 address string to compressed address + */ +function text_to_compressed_ip6($text) { + // Force re-compression by passing parameter 2 (force) true. + // This ensures that supposedly-compressed formats are uncompressed + // first then re-compressed into strictly correct form. + // e.g. 2001:0:0:4:0:0:0:1 + // 2001::4:0:0:0:1 is a strictly-incorrect compression, + // but maybe the user entered it like that. + // The "force" parameter will ensure it is returned as: + // 2001:0:0:4::1 + return Net_IPv6::compress($text, true); } /* Find out how many IPs are contained within a given IP range @@ -1432,14 +1447,14 @@ function get_configured_ipv6_addresses($linklocal_fallback = false) { $interfaces = get_configured_interface_list(); if (is_array($interfaces)) { foreach ($interfaces as $int) { - $ipaddrv6 = get_interface_ipv6($int, false, $linklocal_fallback); + $ipaddrv6 = text_to_compressed_ip6(get_interface_ipv6($int, false, $linklocal_fallback)); $ipv6_array[$int] = $ipaddrv6; } } $interfaces = get_configured_vip_list('inet6'); if (is_array($interfaces)) { foreach ($interfaces as $int => $ipaddrv6) { - $ipv6_array[$int] = $ipaddrv6; + $ipv6_array[$int] = text_to_compressed_ip6($ipaddrv6); } } return $ipv6_array; |