summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre POMES <pierre.pomes@gmail.com>2012-02-26 16:19:53 -0500
committerPierre POMES <pierre.pomes@gmail.com>2012-02-26 16:21:43 -0500
commit47335ae3d0f86c51d4629cf1ed29e52be4f7c75b (patch)
tree7fb86af611bc6e25300821612332f61043b40062
parent37459b48ef9f8519c6c49eb06d2ac1c5e1489f95 (diff)
downloadpfsense-47335ae3d0f86c51d4629cf1ed29e52be4f7c75b.zip
pfsense-47335ae3d0f86c51d4629cf1ed29e52be4f7c75b.tar.gz
Fix gen_subnetv6_max(), used to display the end of available range in dhcp server ipv6
-rw-r--r--etc/inc/util.inc51
-rw-r--r--usr/local/www/services_dhcpv6.php3
2 files changed, 9 insertions, 45 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index b370d69..70b862c 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -253,54 +253,19 @@ function gen_subnet_max($ipaddr, $bits) {
return long2ip32(ip2long($ipaddr) | ~gen_subnet_mask_long($bits));
}
-/* Generate end number for a given ipv6 subnet mask
- * no, it does not perform math */
+/* Generate end number for a given ipv6 subnet mask */
function gen_subnetv6_max($ipaddr, $bits) {
if(!is_ipaddrv6($ipaddr))
return false;
- $subnetstart = gen_subnetv6($ipaddr, $bits);
- /* we should have a expanded full ipv6 subnet starting at 0.
- * Now split those by the semicolon so we can do 16 bit math */
- $parts = explode(":", $subnetstart);
- if(count($parts) <> 8)
- return false;
+ $mask = Net_IPv6::getNetmask('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF',$bits);
- $result = array();
- /* set the itteration count properly */
- $bitsleft = $bits;
- $i = 0;
- foreach($parts as $part) {
- /* if we have more then 16 bits we just append the part to the result */
- if($bitsleft >= 16) {
- $result[$i] = $parts[$i];
- $bitsleft = $bitsleft - 16;
- $i++;
- continue;
- }
- /* if we have less then 16 bits we need to calculate the other bits */
- if(($bitsleft < 16) && ($bitsleft > 0)) {
- $result[$i] = dechex(pow(2, (16 - $bitsleft)) -1) ;
- $integer = pow(2, (16 - $bitsleft));
- $strlen = strlen($result[$i]);
- while($strlen < 4) {
- $result[$i] = 0 . $result[$i];
- $strlen++;
- }
- $bitsleft = 0;
- $i++;
- continue;
- }
- /* counter is zero, append quad F */
- if($bitsleft == 0) {
- $result[$i] = "ffff";
- $i++;
- continue;
- }
- $i++;
- }
- $subnet_end = implode(":", $result);
- return $subnet_end;
+ $inet_ip = (binary)inet_pton($ipaddr);
+ $inet_mask = (binary)inet_pton($mask);
+
+ $inet_end = $inet_ip | ~$inet_mask;
+
+ return(Net_IPv6::uncompress(inet_ntop($inet_end)));
}
/* returns a subnet mask (long given a bit count) */
diff --git a/usr/local/www/services_dhcpv6.php b/usr/local/www/services_dhcpv6.php
index 5a22676..26b6066 100644
--- a/usr/local/www/services_dhcpv6.php
+++ b/usr/local/www/services_dhcpv6.php
@@ -557,8 +557,7 @@ include("head.inc");
?>
-
<?php
- /* FIXME end of subnet calculation here */
- $range_to = gen_subnetv6_max($ifcfgip, $ifcfgsn);;
+ $range_to = gen_subnetv6_max($ifcfgip, $ifcfgsn);
echo $range_to;
?>
</td>
OpenPOWER on IntegriCloud