Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/connections: allow IPv6 ULA in discovery #9048

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions lib/connections/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ func getHostPortsForAllAdapters(port int) []string {
portStr := strconv.Itoa(port)

for _, network := range nets {
// Only IPv4 addresses, as v6 link local require an interface identifiers to work correctly
// And non link local in theory are globally routable anyway.
if network.IP.To4() == nil {
continue
}
if network.IP.IsLinkLocalUnicast() || (isV4Local(network.IP) && network.IP.IsGlobalUnicast()) {
// Only accept IPv4 link-local unicast and the private ranges defined in RFC 1918 and RFC 4193
// IPv6 link-local addresses require an interface identifier to work correctly
if (network.IP.To4() != nil && network.IP.IsLinkLocalUnicast()) || network.IP.IsPrivate() {
hostPorts = append(hostPorts, net.JoinHostPort(network.IP.String(), portStr))
}
}
Expand Down Expand Up @@ -107,17 +104,6 @@ func resolve(network, hostPort string) (net.IP, int, error) {
return net.IPv4zero, 0, net.UnknownNetworkError(network)
}

func isV4Local(ip net.IP) bool {
// See https://go-review.googlesource.com/c/go/+/162998/
// We only take the V4 part of that.
if ip4 := ip.To4(); ip4 != nil {
return ip4[0] == 10 ||
(ip4[0] == 172 && ip4[1]&0xf0 == 16) ||
(ip4[0] == 192 && ip4[1] == 168)
}
return false
}

func maybeReplacePort(uri *url.URL, laddr net.Addr) *url.URL {
if laddr == nil {
return uri
Expand Down
Loading