From 3ff8a55fa709a6239869e31ea78e2c1bd41ddef0 Mon Sep 17 00:00:00 2001 From: Matt Layher Date: Wed, 28 Jul 2021 14:23:43 -0400 Subject: [PATCH] net/tsaddr: remove IsULA, replace with netaddr.IP.IsPrivate Signed-off-by: Matt Layher --- net/interfaces/interfaces.go | 4 ++-- net/tsaddr/tsaddr.go | 5 ----- net/tsaddr/tsaddr_test.go | 22 ---------------------- 3 files changed, 2 insertions(+), 29 deletions(-) diff --git a/net/interfaces/interfaces.go b/net/interfaces/interfaces.go index ce385f57c..e2ce140f0 100644 --- a/net/interfaces/interfaces.go +++ b/net/interfaces/interfaces.go @@ -134,7 +134,7 @@ func LocalAddresses() (regular, loopback []netaddr.IP, err error) { // but their OS supports IPv6 so they have an fe80:: // address. We don't want to report all of those // IPv6 LL to Control. - } else if ip.Is6() && tsaddr.IsULA(ip) { + } else if ip.Is6() && ip.IsPrivate() { // Google Cloud Run uses NAT with IPv6 Unique // Local Addresses to provide IPv6 connectivity. ula6 = append(ula6, ip) @@ -548,7 +548,7 @@ func isUsableV4(ip netaddr.IP) bool { // (fc00::/7) are in some environments used with address translation. func isUsableV6(ip netaddr.IP) bool { return v6Global1.Contains(ip) || - (tsaddr.IsULA(ip) && !tsaddr.TailscaleULARange().Contains(ip)) + (ip.IsPrivate() && !tsaddr.TailscaleULARange().Contains(ip)) } var ( diff --git a/net/tsaddr/tsaddr.go b/net/tsaddr/tsaddr.go index 78543f13d..fc4ef26f9 100644 --- a/net/tsaddr/tsaddr.go +++ b/net/tsaddr/tsaddr.go @@ -105,11 +105,6 @@ func Tailscale4To6(ipv4 netaddr.IP) netaddr.IP { return netaddr.IPFrom16(ret) } -func IsULA(ip netaddr.IP) bool { - ulaRange.Do(func() { mustPrefix(&ulaRange.v, "fc00::/7") }) - return ulaRange.v.Contains(ip) -} - func mustPrefix(v *netaddr.IPPrefix, prefix string) { var err error *v, err = netaddr.ParseIPPrefix(prefix) diff --git a/net/tsaddr/tsaddr_test.go b/net/tsaddr/tsaddr_test.go index 2d27d0265..cfea446c6 100644 --- a/net/tsaddr/tsaddr_test.go +++ b/net/tsaddr/tsaddr_test.go @@ -43,28 +43,6 @@ func TestCGNATRange(t *testing.T) { } } -func TestIsUla(t *testing.T) { - tests := []struct { - name string - ip string - want bool - }{ - {"first ULA", "fc00::1", true}, - {"not ULA", "fb00::1", false}, - {"Tailscale", "fd7a:115c:a1e0::1", true}, - {"Cloud Run", "fddf:3978:feb1:d745::1", true}, - {"zeros", "0000:0000:0000:0000:0000:0000:0000:0000", false}, - {"Link Local", "fe80::1", false}, - {"Global", "2602::1", false}, - } - - for _, test := range tests { - if got := IsULA(netaddr.MustParseIP(test.ip)); got != test.want { - t.Errorf("IsULA(%s) = %v, want %v", test.name, got, test.want) - } - } -} - func TestNewContainsIPFunc(t *testing.T) { f := NewContainsIPFunc([]netaddr.IPPrefix{netaddr.MustParseIPPrefix("10.0.0.0/8")}) if f(netaddr.MustParseIP("8.8.8.8")) {