mirror of
https://github.com/nextcloud/server.git
synced 2026-05-22 01:55:56 -04:00
fix: handle NAT64 addresses in isLocalAddress
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
887dfeb886
commit
a472a189bb
2 changed files with 11 additions and 1 deletions
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OC\Net;
|
||||
|
||||
use IPLib\Address\IPv4;
|
||||
use IPLib\Address\IPv6;
|
||||
use IPLib\Factory;
|
||||
use IPLib\ParseStringFlag;
|
||||
|
|
@ -42,7 +43,15 @@ class IpAddressClassifier {
|
|||
}
|
||||
/* Replace by normalized form */
|
||||
if ($parsedIp instanceof IPv6) {
|
||||
$ip = (string)($parsedIp->toIPv4() ?? $parsedIp);
|
||||
$ipv4 = $parsedIp->toIPv4();
|
||||
$ipv6Bytes = $parsedIp->getBytes();
|
||||
if ($ipv4) {
|
||||
$ip = (string)$ipv4;
|
||||
} elseif (array_slice($ipv6Bytes, 0, 4) === [0x00, 0x64, 0xFF, 0x9B]) {
|
||||
$ip = (string)IPv4::fromBytes(array_slice($ipv6Bytes, -4, 4));
|
||||
} else {
|
||||
$ip = (string)$parsedIp;
|
||||
}
|
||||
} else {
|
||||
$ip = (string)$parsedIp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class IpAddressClassifierTest extends TestCase {
|
|||
['::1'],
|
||||
['100.100.100.200'],
|
||||
['192.0.0.1'],
|
||||
['64:ff9b::a9fe:a9fe'], // NAT64 of 169.254.169.254
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue