Provide the new sequence number in responses. New message Local Discovery to be sent instead of Announcement via IPv4 Broadcast and IPv6 Multicast.

Detecting IPv6 link-local addresses as local ones. Fixes.
This commit is contained in:
Kleissner
2021-04-18 21:50:30 +02:00
parent 703e40c947
commit 00db57aed8
7 changed files with 50 additions and 15 deletions

View File

@@ -249,13 +249,16 @@ func networkChangeIPRemove(iface net.Interface, address net.Addr) {
}
}
// IsIPLocal reports whether ip is a private (local) address. [forked function]
// IsIPLocal reports whether ip is a private (local) address.
// The identification of private, or local, unicast addresses uses address type
// indentification as defined in RFC 1918 for ip4 and RFC 4193 for ip6 with the exception of ip4 directed broadcast addresses.
// indentification as defined in RFC 1918 for ip4 and RFC 4193 (fc00::/7) for ip6 with the exception of ip4 directed broadcast addresses.
// Unassigned, reserved, multicast and limited-broadcast addresses are not handled and will return false.
// IPv6 link-local addresses (fe80::/10) are included in this check.
func IsIPLocal(ip net.IP) bool {
if ip4 := ip.To4(); ip4 != nil {
return ip4[0] == 10 || (ip4[0] == 172 && ip4[1]&0xf0 == 16) || (ip4[0] == 192 && ip4[1] == 168)
}
return len(ip) == net.IPv6len && ip[0]&0xfe == 0xfc
return len(ip) == net.IPv6len &&
(ip[0]&0xfe == 0xfc || // fc00::/7
(ip[0] == 0xfe && ip[1]&0xC0 == 0x80)) // fe80::/10
}