Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

netaddr.IP.IsLinkLocalUnicast() disagrees with net.IP #184

Closed
moreati opened this issue May 25, 2021 · 2 comments
Closed

netaddr.IP.IsLinkLocalUnicast() disagrees with net.IP #184

moreati opened this issue May 25, 2021 · 2 comments

Comments

@moreati
Copy link
Contributor

moreati commented May 25, 2021

For the IPv6 address feb0::0

netaddr.IP.IsLinkLocalUnicast() == false
net.IP.IsLinkLocalUnicast() == true

I believe netaddr.IP is in error, and net.IP may be correct. It's possible both are in error, but I don't think so.

RFC4291 section 2.4

The type of an IPv6 address is identified by the high-order bits of the address, as follows:

Address type Binary prefix IPv6 notation Section
...
Link-Local unicast 1111111010 FE80::/10 2.5.6

netaddr

netaddr.IP.IsLinkLocalUnicast() only checks the first 16 bits equal 0xfeb0, it doesn't mask.

return ip.v6u16(0) == 0xfe80

net

net.IP.IsLinkLocalUnicast() (since golang/go@91ba0ab in go 1.5beta2 ) checks the first byte equals 0xfe, and the second byte masked with 0b1100_0000 == 0b1000_0000

    return len(ip) == IPv6len && ip[0] == 0xfe && ip[1]&0xc0 == 0x80

-- https://github.com/golang/go/blob/f22ec51debeddc0903096e66bfaf641568bede3b/src/net/ip.go#L179

Analysis

Going purely from RFC4291 section 2.4 I would expect the correct test to be

    return ip.v6u16(0) & 0xffc0 == 0xfe80

where

  • 0xffc0 == 0b1111_1111_1100_0000 is the netmask
  • 0xfe80 == 0b1111_1110_1000_0000 is the prefix
@bradfitz
Copy link
Contributor

Whoops. Thanks for the report!

@moreati
Copy link
Contributor Author

moreati commented May 25, 2021

PR incoming, this was found as part of #182

moreati added a commit to moreati/netaddr that referenced this issue May 25, 2021
Signed-off-by: Alex Willmer <alex@moreati.org.uk>

fixes inetaf#184
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants