diff options
author | Reid Linnemann <rlinnemann@netgate.com> | 2022-08-12 08:19:58 -0300 |
---|---|---|
committer | Renato Botelho <garga@FreeBSD.org> | 2022-08-12 08:23:28 -0300 |
commit | 1e7a9cbf5afa5e830a90b4285b5da0202d55f404 (patch) | |
tree | 426923cc55db71f064d5999e9e7349d9723068a1 /net/pear-Net_IPv6/files/patch-Net_IPv6.php | |
parent | devel/boost-python-libs: limit python 3.8-3.10 as py-numpy used yet (diff) |
net/pear-Net_IPv6: Add patches for handling zones
Summary:
The upstream Net/IPv6 package from PEAR has significant bugs revolving around
handling of string presentation v6 addresses which have RFC 4007 zones. Patches
are added in this commit to address them plus a handful of other errors until an
updated version of the package becomes available with these changes included.
* Add getZone() and removeZone() class methods
* Alter SplitV64() to remove any zone before attempting to split an address
into v6 and v4 parts. The zone has no meaning in this context
* Alter compress to remove and restore a zone prior to restoring a prefix
* Alter compress() to rejoin a compressed v6 part with a v4 part with a colon
if the v6 part does not already end with one
* Fix undefined variable '$address' in isCompressible()
* Ensure no zone is present at the end of an address in _ip2Bin(). The zone is
not a part of the binary address
* Change string/int arithmetic to int/int arithmetic in _ip2Bin by mapping
exploded v4 address octets to integer values
* Fix unit tests to work in modern versions of php and phpunit
* Align test case class name with source file name
* Use phpunit namespaces
* Make return type of AllTests::setUp() the expected 'void'
In addition, eight unit tests are added for basic verification of zone handling.
Sponsored by: Rubicon Communications, LLC ("Netgate")
Differential Revision: https://reviews.freebsd.org/D36151
Diffstat (limited to 'net/pear-Net_IPv6/files/patch-Net_IPv6.php')
-rw-r--r-- | net/pear-Net_IPv6/files/patch-Net_IPv6.php | 181 |
1 files changed, 179 insertions, 2 deletions
diff --git a/net/pear-Net_IPv6/files/patch-Net_IPv6.php b/net/pear-Net_IPv6/files/patch-Net_IPv6.php index 99517ee348f6..4f341704902c 100644 --- a/net/pear-Net_IPv6/files/patch-Net_IPv6.php +++ b/net/pear-Net_IPv6/files/patch-Net_IPv6.php @@ -1,6 +1,159 @@ ---- Net/IPv6.php.orig 2018-07-09 11:55:41 UTC +--- Net/IPv6.php.orig 2022-08-11 20:00:46 UTC +++ Net/IPv6.php -@@ -853,10 +853,10 @@ class Net_IPv6 +@@ -224,6 +224,27 @@ class Net_IPv6 + } + + // }}} ++ // {{{ removeZone() ++ ++ /** ++ * Removes a zone from a non-global presentation address if it exists ++ * ++ * @param String $ip a valid ipv6 link local address ++ * ++ * @return String the address without a zone ++ * @access public ++ * @static ++ * @author Reid Linnemann <rlinnemann@netgate.com> ++ */ ++ public static function removeZone($ip) ++ { ++ ++ $ip = explode('%', $ip)[0]; ++ ++ return $ip; ++ ++ } ++ // }}} + // {{{ getNetmaskSpec() + + /** +@@ -324,6 +345,33 @@ class Net_IPv6 + } + + // }}} ++ // {{{ getZone() ++ ++ /** ++ * Returns zone from a non-global presentation address if it exists ++ * ++ * @param String $ip a valid ipv6 link local address ++ * ++ * @return String a zone or empty string if none exists ++ * @access public ++ * @static ++ * @author Reid Linnemann <rlinnemann@netgate.com> ++ */ ++ public static function getZone($ip) ++ { ++ ++ $items = explode('%', $ip); ++ ++ if (count($items) > 1) { ++ ++ return array_pop($items); ++ ++ } ++ ++ return ''; ++ ++ } ++ // }}} + // {{{ isInNetmask() + + /** +@@ -549,6 +597,8 @@ class Net_IPv6 + + } + ++ $zone = Net_IPv6::getZone($ip); ++ $ip = Net_IPv6::removeZone($ip); + $netmask = Net_IPv6::getNetmaskSpec($ip); + $uip = Net_IPv6::removeNetmaskSpec($ip); + +@@ -639,6 +689,12 @@ class Net_IPv6 + $uip = implode(':', $uipT); + } + ++ if ('' != $zone) { ++ ++ $uip = $uip.'%'.$zone; ++ ++ } ++ + if ('' != $netmask) { + + $uip = $uip.'/'.$netmask; +@@ -696,6 +752,9 @@ class Net_IPv6 + + } + ++ $zone = Net_IPv6::getZone($ip); ++ $ip = Net_IPv6::removeZone($ip); ++ + $prefix = Net_IPv6::getPrefixLength($ip); + + if (false === $prefix) { +@@ -709,7 +768,7 @@ class Net_IPv6 + + } + +- $split = Net_IPv6::splitV64($ip); ++ $split = Net_IPv6::SplitV64($ip); + $ip = $split[0]; + + $netmask = Net_IPv6::getNetmaskSpec($ip); +@@ -750,9 +809,20 @@ class Net_IPv6 + } + + if ('' != $split[1]) { // add ipv4 part is available +- $cip = $cip.$split[1]; ++ if(str_ends_with($cip, ':')) { ++ $sep = ''; ++ } else { ++ $sep = ':'; ++ } ++ $cip = $cip.$sep.$split[1]; + } +- ++ ++ if ('' != $zone) { ++ ++ $cip = $cip.'%'.$zone; ++ ++ } ++ + if ('' != $netmask) { + + $cip = $cip.'/'.$netmask; +@@ -807,7 +877,7 @@ class Net_IPv6 + public static function isCompressible($ip) + { + +- return (bool)($ip != Net_IPv6::compress($address)); ++ return (bool)($ip != Net_IPv6::compress($ip)); + + } + +@@ -820,6 +890,9 @@ class Net_IPv6 + * RFC 2373 allows you to note the last two parts of an IPv6 address as + * an IPv4 compatible address + * ++ * Note that any zone will necessarily be stripped from the IPv6 part that ++ * is returned ++ * + * Example: 0:0:0:0:0:0:13.1.68.3 + * 0:0:0:0:0:FFFF:129.144.52.38 + * +@@ -837,6 +910,7 @@ class Net_IPv6 + */ + public static function SplitV64($ip, $uncompress = true) + { ++ $ip = Net_IPv6::removeZone($ip); + $ip = Net_IPv6::removeNetmaskSpec($ip); + + if ($uncompress) { +@@ -853,10 +927,10 @@ class Net_IPv6 return array("", $ip); } @@ -13,3 +166,27 @@ $ipPart[0] .= ":"; } +@@ -885,7 +959,6 @@ class Net_IPv6 + */ + public static function checkIPv6($ip) + { +- + $elements = Net_IPv6::separate($ip); + + $ip = $elements[0]; +@@ -1057,13 +1130,13 @@ class Net_IPv6 + protected static function _ip2Bin($ip) + { + $binstr = ''; +- ++ $ip = Net_IPv6::removeZone($ip); + $ip = Net_IPv6::removeNetmaskSpec($ip); + + // Correctly convert IPv4 mapped addresses (::ffff:x.x.x.x) + list(, $ipv4) = Net_IPv6::SplitV64($ip, FALSE); + if (strlen($ipv4)) { +- $ipv4map = explode('.', $ipv4, 4); ++ $ipv4map = array_map("intval", explode('.', $ipv4, 4)); + $ipv4replace = dechex($ipv4map[0] * 256 + $ipv4map[1]) . ':' . dechex($ipv4map[2] * 256 + $ipv4map[3]); + $ip = str_replace($ipv4, $ipv4replace, $ip); + } |