diff options
author | Simon Cornelius P. Umacob <simoncpu@gmail.com> | 2009-01-20 15:52:39 +0800 |
---|---|---|
committer | Simon Cornelius P. Umacob <simoncpu@gmail.com> | 2009-01-20 15:52:39 +0800 |
commit | f193cf92b2c925a2f3f71a713d766efd1e4d81e0 (patch) | |
tree | c02f02076434ddf76d0892a06a66ad0969cbe70e /etc/inc | |
parent | 1f9f2a95b7b42cf33e730535092e56e214fdb848 (diff) | |
download | pfsense-f193cf92b2c925a2f3f71a713d766efd1e4d81e0.zip pfsense-f193cf92b2c925a2f3f71a713d766efd1e4d81e0.tar.gz |
Merge IPv6 changes
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/util.inc | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 3ef01fc..7b8ebe8 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -27,6 +27,8 @@ POSSIBILITY OF SUCH DAMAGE. */ +require_once 'IPv6.inc'; + /* kill a process by pid file */ function killbypid($pidfile) { sigkillbypid($pidfile, "TERM"); @@ -120,9 +122,8 @@ function is_ipaddr($ipaddr) { return false; } -/* returns true if $ipaddr is a valid dotted IPv4 address or an alias thereof */ +/* returns true if $ipaddr is a valid IPv4/IPv6 address or an alias thereof */ function is_ipaddroralias($ipaddr) { - global $aliastable, $config; if(is_array($config['aliases']['alias'])) { @@ -132,22 +133,22 @@ function is_ipaddroralias($ipaddr) { } } - if (isset($aliastable[$ipaddr]) && is_ipaddr($aliastable[$ipaddr])) + if (isset($aliastable[$ipaddr]) && (is_ipaddr($aliastable[$ipaddr]) || Net_IPv6::checkIPv6($aliastable[$ipaddr]))) { return true; - else - return is_ipaddr($ipaddr); - + } else { + return (is_ipaddr($ipaddr) || Net_IPv6::checkIPv6($ipaddr)); + } } /* returns true if $ipaddr is a valid dotted IPv4 address or any alias */ function is_ipaddroranyalias($ipaddr) { - global $aliastable; - if (isset($aliastable[$ipaddr])) + if (isset($aliastable[$ipaddr])) { return true; - else - return is_ipaddr($ipaddr); + } else { + return (is_ipaddr($ipaddr) || Net_IPv6::checkIPv6($ipaddr)); + } } /* returns true if $subnet is a valid subnet in CIDR format */ @@ -166,6 +167,26 @@ function is_subnet($subnet) { return true; } +/* returns true if $subnet is a valid IPv6 network address */ +function is_subnet_ipv6($subnet, $max = 64) { + if (!is_string($subnet)) { + return false; + } + + list ($hp, $np) = explode('/', $subnet); + + if (!Net_IPv6::checkIPv6($hp)) { + return false; + } + + if (!is_numeric($np) || ($np < 1) || ($np > $max)) { + return false; + } + + return true; +} + + /* returns true if $subnet is a valid subnet in CIDR format or an alias thereof */ function is_subnetoralias($subnet) { @@ -503,15 +524,15 @@ function alias_expand_value($name) { /* expand a host or network alias, if necessary */ function alias_expand($name) { - global $aliastable; - if (isset($aliastable[$name])) + if (isset($aliastable[$name])) { return "\${$name}"; - else if (is_ipaddr($name) || is_subnet($name)) + } else if (is_ipaddr($name) || is_subnet($name) || Net_IPv6::checkIPv6($name) || is_subnet_ipv6($name)) { return "{$name}"; - else + } else { return null; + } } /* expand a host alias, if necessary */ @@ -521,14 +542,16 @@ function alias_expand_host($name) { if (isset($aliastable[$name])) { $ip_arr = explode(" ", $aliastable[$name]); foreach($ip_arr as $ip) { - if (!is_ipaddr($ip)) + if (!is_ipaddr($ip) || Net_IPv6::checkIPv6($ip)) { return null; + } } return $aliastable[$name]; - } else if (is_ipaddr($name)) + } else if (is_ipaddr($name) || Net_IPv6::checkIPv6($name)) { return $name; - else + } else { return null; + } } /* expand a network alias, if necessary */ @@ -612,8 +635,8 @@ function arp_get_mac_by_ip($ip) { /* return a fieldname that is safe for xml usage */ function xml_safe_fieldname($fieldname) { - $replace = array('/', '-', ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', - '_', '+', '=', '{', '}', '[', ']', '|', '/', '<', '>', '?', + $replace = array('/', ' ', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', + '+', '=', '{', '}', '[', ']', '|', '/', '<', '>', '?', ':', ',', '.', '\'', '\\' ); return strtolower(str_replace($replace, "", $fieldname)); @@ -647,8 +670,9 @@ function mac_format($clientmac) { function resolve_retry($hostname, $retries = 5) { - if (is_ipaddr($hostname)) + if (is_ipaddr($hostname) || Net_IPv6::checkIPv6($hostname)) { return $hostname; + } for ($i = 0; $i < $retries; $i++) { $ip = gethostbyname($hostname); |