2021-06-28 23:16:37 +01:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-11-30 23:53:34 +00:00
|
|
|
package tsdial
|
2021-06-28 23:16:37 +01:00
|
|
|
|
|
|
|
import (
|
2022-07-26 04:55:44 +01:00
|
|
|
"net/netip"
|
2021-06-28 23:16:37 +01:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/types/netmap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDNSMapFromNetworkMap(t *testing.T) {
|
2022-07-26 04:55:44 +01:00
|
|
|
pfx := netip.MustParsePrefix
|
|
|
|
ip := netip.MustParseAddr
|
2021-06-28 23:16:37 +01:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
nm *netmap.NetworkMap
|
2021-12-02 19:10:35 +00:00
|
|
|
want dnsMap
|
2021-06-28 23:16:37 +01:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "self",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "foo.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100.102.103.104/32"),
|
|
|
|
pfx("100::123/128"),
|
|
|
|
},
|
|
|
|
},
|
2021-12-02 19:10:35 +00:00
|
|
|
want: dnsMap{
|
2021-06-28 23:16:37 +01:00
|
|
|
"foo": ip("100.102.103.104"),
|
|
|
|
"foo.tailnet": ip("100.102.103.104"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "self_and_peers",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "foo.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100.102.103.104/32"),
|
|
|
|
pfx("100::123/128"),
|
|
|
|
},
|
|
|
|
Peers: []*tailcfg.Node{
|
|
|
|
{
|
|
|
|
Name: "a.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100.0.0.201/32"),
|
|
|
|
pfx("100::201/128"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "b.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100::202/128"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-02 19:10:35 +00:00
|
|
|
want: dnsMap{
|
2021-06-28 23:16:37 +01:00
|
|
|
"foo": ip("100.102.103.104"),
|
|
|
|
"foo.tailnet": ip("100.102.103.104"),
|
|
|
|
"a": ip("100.0.0.201"),
|
|
|
|
"a.tailnet": ip("100.0.0.201"),
|
|
|
|
"b": ip("100::202"),
|
|
|
|
"b.tailnet": ip("100::202"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "self_has_v6_only",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "foo.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100::123/128"),
|
|
|
|
},
|
|
|
|
Peers: []*tailcfg.Node{
|
|
|
|
{
|
|
|
|
Name: "a.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100.0.0.201/32"),
|
|
|
|
pfx("100::201/128"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "b.tailnet",
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 05:14:09 +01:00
|
|
|
Addresses: []netip.Prefix{
|
2021-06-28 23:16:37 +01:00
|
|
|
pfx("100::202/128"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-02 19:10:35 +00:00
|
|
|
want: dnsMap{
|
2021-06-28 23:16:37 +01:00
|
|
|
"foo": ip("100::123"),
|
|
|
|
"foo.tailnet": ip("100::123"),
|
|
|
|
"a": ip("100::201"),
|
|
|
|
"a.tailnet": ip("100::201"),
|
|
|
|
"b": ip("100::202"),
|
|
|
|
"b.tailnet": ip("100::202"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-12-02 19:10:35 +00:00
|
|
|
got := dnsMapFromNetworkMap(tt.nm)
|
2021-06-28 23:16:37 +01:00
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("mismatch:\n got %v\nwant %v\n", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|