Does ::1/128 count as valid IPv6 address?

Hi

recently, Mikrotik exposed “lo” loopback adapter in ROS v7.14
by default, this interface have ::1/128 address which is rejected by “isValid”

function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen, $ipv6_origin, $context_name = '')
{
    global $device;

    if (! IPv6::isValid($ipv6_address, true)) {
        // ignore link-locals (coming from IPV6-MIB)
        return;
    }

::1/128 is same as 127.0.0.1/8 in v4 world
and 127.0.0.1/8 is accepted as VALID
even 127.0.0.1/32 is VALID

should LNMS accept ::1/128 as valid v6 address ?

walk from device:

ipv6AddrPfxLength[1][fe80:0:0:0:7a9a:18ff:fe4a:51a5] = 64
ipv6AddrPfxLength[11][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 64
ipv6AddrPfxLength[13][fdff:255:0:0:0:0:0:9] = 64
ipv6AddrPfxLength[13][fe80:0:0:0:c156:1169:199:2079] = 64
ipv6AddrPfxLength[14][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 64
ipv6AddrPfxLength[15][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 64
ipv6AddrPfxLength[16][fd00:9:255:0:0:0:0:1] = 64
ipv6AddrPfxLength[16][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 64
ipv6AddrPfxLength[19][fe80:0:0:0:d0d4:25bb:8d34:53c3] = 64
ipv6AddrPfxLength[25][0:0:0:0:0:0:0:1] = 128
----
ipv6AddrType[1][fe80:0:0:0:7a9a:18ff:fe4a:51a5] = 1
ipv6AddrType[11][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 1
ipv6AddrType[13][fdff:255:0:0:0:0:0:9] = 2
ipv6AddrType[13][fe80:0:0:0:c156:1169:199:2079] = 1
ipv6AddrType[14][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 1
ipv6AddrType[15][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 1
ipv6AddrType[16][fd00:9:255:0:0:0:0:1] = 2
ipv6AddrType[16][fe80:0:0:0:7a9a:18ff:fe4a:51a6] = 1
ipv6AddrType[19][fe80:0:0:0:d0d4:25bb:8d34:53c3] = 1
ipv6AddrType[25][0:0:0:0:0:0:0:1] = 2

No 127.0.0.1 is IPv4 and ::1 is IPv6 both are localhost but they are not “the same”
::1/128 is localhost with full subnet mask, so that is ::1 as address with 128 prefix len

127.0.0.1/8 is the full 127.0.0.0-127.255.255.255 range and not just the address.
Reading the comment ignoring link-local (as in fe80::/10) seems to be the goal, I would absolutely accept the premise that ::1 is not a valid global address. so should ? discover_process_ipv6 ignore link-local and localhost IPs on interfaces?

There is no way to disambiguate ::1 or 127.0.0.1 from device to device.
localhost ips do not contain any useful information, so they are rejected.

The OP asked about the localhost IPs, but the comment on isValid which according to OP return false, only mentions “link-locals” , not localhosts, so there might be some inconsistencies here.

I totally agree that they probably should be rejected, but reading OP they are not for IPv4, and the comment is not clear in the OP snippet.

OP linked the wrong bit of code. Under the context of the IPv6 module (of which they are showing code from an old version), locahost should always be rejected.

Here is a look at the isValid function:

    public static function isValid($ipv6, $exclude_reserved = false)
    {
        $filter = FILTER_FLAG_IPV6;
        if ($exclude_reserved) {
            $filter |= FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_GLOBAL_RANGE;
        }

        return filter_var($ipv6, FILTER_VALIDATE_IP, $filter) !== false;
    }

As you can see $exclude_reserved also requires it to be a global IP, which is exactly what we want for the IPv6 Addresses module.

The only issue is that the comments/option name are slightly misleading.

1 Like

Yes, that is what I tried to say, I’m sorry if it came of in any other way.

we were both just trying to clarify :wink: