summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Mos <seth.mos@dds.nl>2010-10-26 11:44:25 +0200
committerSeth Mos <seth.mos@dds.nl>2010-10-26 11:44:25 +0200
commit22b5abac48ce99350c7e3d750bfeb0748663bd26 (patch)
tree499057c26cc349e6073434bc12602eb27132abee
parentb2c63fa3f2df5fea9ad05710dd8aac577ed5149f (diff)
downloadpfsense-22b5abac48ce99350c7e3d750bfeb0748663bd26.zip
pfsense-22b5abac48ce99350c7e3d750bfeb0748663bd26.tar.gz
Switch over the IPv6 functions from IPv6.inc, these are from the PHP PEAR library
-rw-r--r--etc/inc/config.inc4
-rw-r--r--etc/inc/filter.inc2
-rw-r--r--etc/inc/util.inc50
3 files changed, 17 insertions, 39 deletions
diff --git a/etc/inc/config.inc b/etc/inc/config.inc
index 724615a..a00f910 100644
--- a/etc/inc/config.inc
+++ b/etc/inc/config.inc
@@ -60,6 +60,8 @@ require_once('config.lib.inc');
if($g['booting']) echo ".";
require_once("util.inc");
if($g['booting']) echo ".";
+require_once("IPv6.inc");
+if($g['booting']) echo ".";
if(file_exists("/cf/conf/use_xmlreader"))
require_once("xmlreader.inc");
else
@@ -211,4 +213,4 @@ if($config_parsed == true) {
}
}
-?> \ No newline at end of file
+?>
diff --git a/etc/inc/filter.inc b/etc/inc/filter.inc
index 6905e61..170de90 100644
--- a/etc/inc/filter.inc
+++ b/etc/inc/filter.inc
@@ -732,7 +732,7 @@ function filter_generate_optcfg_array() {
$oic['mss'] = empty($oc['mss']) ? '' : $oc['mss'];
$oic['descr'] = $ifdetail;
$oic['sa'] = gen_subnet($oic['ip'], $oic['sn']);
- $oic['sav6'] = "{$oic['ipv6']}";
+ $oic['sav6'] = gen_subnetv6($oic['ipv6'], $oic['snv6']);
$oic['nonat'] = $oc['nonat'];
$oic['alias-address'] = $oc['alias-address'];
$oic['alias-subnet'] = $oc['alias-subnet'];
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index e28192a..af88d2c 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -218,13 +218,16 @@ function is_module_loaded($module_name) {
/* return the subnet address given a host address and a subnet bit count */
function gen_subnet($ipaddr, $bits) {
- if(is_ipaddrv6($ipaddr)) {
- return "{$ipaddr}/{$bits}";
- } else {
- if (!is_ipaddr($ipaddr) || !is_numeric($bits))
- return "";
- return long2ip(ip2long($ipaddr) & gen_subnet_mask_long($bits));
- }
+ if (!is_ipaddr($ipaddr) || !is_numeric($bits))
+ return "";
+ return long2ip(ip2long($ipaddr) & gen_subnet_mask_long($bits));
+}
+
+/* return the subnet address given a host address and a subnet bit count */
+function gen_subnetv6($ipaddr, $bits) {
+ if (!is_ipaddrv6($ipaddr) || !is_numeric($bits))
+ return "";
+ return Net_IPv6::getNetmask($ipaddr, $bits);
}
/* return the highest (broadcast) address in the subnet given a host address and a subnet bit count */
@@ -397,37 +400,10 @@ function is_ipaddr($ipaddr) {
return false;
}
+/* returns true if $ipaddr is a valid IPv6 address */
function is_ipaddrv6($ipaddr) {
- /* Not using filter_var here. It misses some test cases */
- /* http://crisp.tweakblogs.net/blog/2031 */
- // fast exit for localhost
- if (strlen($ipaddr) < 3)
- return $ipaddr == '::';
-
- // Check if part is in IPv4 format
- if (strpos($ipaddr, '.')) {
- $lastcolon = strrpos($ipaddr, ':');
- if (!($lastcolon && validateIPv4(substr(ipaddr, $lastcolon + 1))))
- return false;
-
- // replace IPv4 part with dummy
- $ipaddr = substr($ipaddr, 0, $lastcolon) . ':0:0';
- }
-
- // check uncompressed
- if (strpos($ipaddr, '::') === false) {
- return preg_match('/^(?:[a-f0-9]{1,4}:){7}[a-f0-9]{1,4}$/i', $ipaddr);
- }
-
- // check colon-count for compressed format
- if (substr_count($ipaddr, ':') < 8) {
- return preg_match('/^(?::|(?:[a-f0-9]{1,4}:)+):(?:(?:[a-f0-9]{1,4}:)*[a-f0-9]{1,4})?$/i', $ipaddr);
- }
- return false;
-}
-
-function validateIPv4($ipaddr) {
- return $ipaddr == long2ip(ip2long($ipaddr));
+ $result = Net_IPv6::checkIPv6($ipaddr);
+ return $result;
}
/* returns true if $ipaddr is a valid dotted IPv4 address */
OpenPOWER on IntegriCloud