net/tsaddr: IsUla() for IPv6 Unique Local Address

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry
2021-03-29 18:28:57 -07:00
committed by Denton Gentry
parent 36a85e1760
commit ecf310be3c
2 changed files with 30 additions and 2 deletions

View File

@@ -42,3 +42,25 @@ func TestCGNATRange(t *testing.T) {
t.Errorf("got %q; want %q", got, want)
}
}
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)
}
}
}