aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbt90 <btom1990@googlemail.com>2023-08-23 12:28:48 +0200
committerGitHub <noreply@github.com>2023-08-23 12:28:48 +0200
commit467522d04d9e0f941c618dc7bd25e674b6638f9a (patch)
treea9282ff1fbb2c6292e562e789c7e2d7490e81d2c
parent3147285c60ffe899e27495b8b6f5632f7b25e69b (diff)
downloadsyncthing-467522d04d9e0f941c618dc7bd25e674b6638f9a.tar.gz
syncthing-467522d04d9e0f941c618dc7bd25e674b6638f9a.zip
lib/connections: Allow IPv6 ULA in discovery announcements (fixes #7456) (#9048)v1.24.0-rc.1v1.24.0
The allowed IPv4 ranges are the same as before. But we now also accept IPv6 addresses in the ULA range FC00::/7. These addresses don't require an interface identifier and are roughly equivalent to the IPv4 private ranges. Typical usecases: VPN interface IPs: Wireguard, OpenVPN, Tailscale, ... fixed IPv6 LAN addressing while the provider assigns a dynamic prefix. e.g used by pihole https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/net/ip.go;l=146
-rw-r--r--lib/connections/util.go20
1 files changed, 3 insertions, 17 deletions
diff --git a/lib/connections/util.go b/lib/connections/util.go
index 3dd5dc92c..7f6c3fd60 100644
--- a/lib/connections/util.go
+++ b/lib/connections/util.go
@@ -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))
}
}
@@ -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