improvement: use IsLinkLocalUnicast in IsLocal

Looking at the code, this commit appears to change behavior,
because `IsLocal` will now return `true` for IPv6 link-local unicast
addresses.
This commit is contained in:
WofWca 2024-11-21 17:31:56 +04:00
parent 387096b2a1
commit f65f1d850f

View file

@ -60,15 +60,15 @@ func IsLocal(ip net.IP) bool {
if ip.IsPrivate() {
return true
}
// Dynamic Configuration as per https://tools.ietf.org/htm/rfc3927
if ip.IsLinkLocalUnicast() {
return true
}
if ip4 := ip.To4(); ip4 != nil {
// Carrier-Grade NAT as per https://tools.ietf.org/htm/rfc6598
if ip4[0] == 100 && ip4[1]&0xc0 == 64 {
return true
}
// Dynamic Configuration as per https://tools.ietf.org/htm/rfc3927
if ip4[0] == 169 && ip4[1] == 254 {
return true
}
}
return false
}