fix: handle NAT64 addresses in isLocalAddress

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2026-04-15 18:59:18 +02:00
parent 887dfeb886
commit a472a189bb
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
2 changed files with 11 additions and 1 deletions

View file

@ -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;
}

View file

@ -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
];
}