diff options
author | bcyrill <cyrill@bannwart.info> | 2013-02-06 12:06:02 +0100 |
---|---|---|
committer | bcyrill <cyrill@bannwart.info> | 2013-02-06 12:06:02 +0100 |
commit | dbea91b3570111695644e76e89d02a0d32dcc0ab (patch) | |
tree | 427b64aac936e67fba485734baa9d0ab8b871fd6 /etc | |
parent | 6b207f739b20246d9b981a8a180ba7c746916cb6 (diff) | |
download | pfsense-dbea91b3570111695644e76e89d02a0d32dcc0ab.zip pfsense-dbea91b3570111695644e76e89d02a0d32dcc0ab.tar.gz |
Add check_subnetsv6_overlap()
Diffstat (limited to 'etc')
-rw-r--r-- | etc/inc/interfaces.inc | 3 | ||||
-rw-r--r-- | etc/inc/util.inc | 16 |
2 files changed, 15 insertions, 4 deletions
diff --git a/etc/inc/interfaces.inc b/etc/inc/interfaces.inc index 9424bda..7698979 100644 --- a/etc/inc/interfaces.inc +++ b/etc/inc/interfaces.inc @@ -3889,7 +3889,8 @@ function find_virtual_ip_alias($ip, $bits = null) { } } else { - if (check_subnets_overlap($ip, $bits, $vip['subnet'], $vip['subnet_bits'])) { + if (($isv6ip && check_subnetsv6_overlap($ip, $bits, $vip['subnet'], $vip['subnet_bits'])) + || (!$isv6ip && check_subnets_overlap($ip, $bits, $vip['subnet'], $vip['subnet_bits']))) { return $vip; } } diff --git a/etc/inc/util.inc b/etc/inc/util.inc index edbc4ff..d7019de 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -1154,7 +1154,7 @@ function alias_expand_urltable($name) { return null; } -function subnet_size ($subnet) { +function subnet_size($subnet) { if (is_subnetv4($subnet)) { list ($ip, $bits) = explode("/", $subnet); return round(exp(log(2) * (32 - $bits))); @@ -1168,7 +1168,7 @@ function subnet_size ($subnet) { } } -function subnet_expand ($subnet) { +function subnet_expand($subnet) { if (is_subnetv4($subnet)) { return subnetv4_expand($subnet); } else if (is_subnetv6($subnet)) { @@ -1178,7 +1178,7 @@ function subnet_expand ($subnet) { } } -function subnetv4_expand ($subnet) { +function subnetv4_expand($subnet) { $result = array(); list ($ip, $bits) = explode("/", $subnet); $net = ip2long($ip); @@ -1210,6 +1210,16 @@ function check_subnets_overlap($subnet1, $bits1, $subnet2, $bits2) { return ($sn1 == $sn2); } +/* find out whether two IPv6 subnets overlap */ +function check_subnetsv6_overlap($subnet1, $bits1, $subnet2, $bits2) { + $sub1_min = gen_subnetv6($subnet1, $bits1); + $sub1_max = gen_subnetv6_max($subnet1, $bits1); + $sub2_min = gen_subnetv6($subnet2, $bits2); + $sub2_max = gen_subnetv6_max($subnet2, $bits2); + + return (is_inrange_v6($sub1_min, $sub2_min, $sub2_max) || is_inrange_v6($sub1_max, $sub2_min, $sub2_max)); +} + /* compare two IP addresses */ function ipcmp($a, $b) { if (ip_less_than($a, $b)) |