mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 11:35:35 +00:00
adc5997592
This starts to refactor tsdial.Dialer's name resolution to have different stages: in-memory MagicDNS vs system resolution. A future change will plug in ExitDNS resolution. This also plumbs a Dialer into netstack and unexports the dnsMap internals. And it removes some of the async AddNetworkMapCallback usage and replaces it with synchronous updates of the Dialer's netmap from LocalBackend, since the LocalBackend has the Dialer too. Updates #3475 Change-Id: Idcb7b1169878c74f0522f5151031ccbc49fe4cb4 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
113 lines
2.4 KiB
Go
113 lines
2.4 KiB
Go
// 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.
|
|
|
|
package tsdial
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"inet.af/netaddr"
|
|
"tailscale.com/tailcfg"
|
|
"tailscale.com/types/netmap"
|
|
)
|
|
|
|
func TestDNSMapFromNetworkMap(t *testing.T) {
|
|
pfx := netaddr.MustParseIPPrefix
|
|
ip := netaddr.MustParseIP
|
|
tests := []struct {
|
|
name string
|
|
nm *netmap.NetworkMap
|
|
want dnsMap
|
|
}{
|
|
{
|
|
name: "self",
|
|
nm: &netmap.NetworkMap{
|
|
Name: "foo.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100.102.103.104/32"),
|
|
pfx("100::123/128"),
|
|
},
|
|
},
|
|
want: dnsMap{
|
|
"foo": ip("100.102.103.104"),
|
|
"foo.tailnet": ip("100.102.103.104"),
|
|
},
|
|
},
|
|
{
|
|
name: "self_and_peers",
|
|
nm: &netmap.NetworkMap{
|
|
Name: "foo.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100.102.103.104/32"),
|
|
pfx("100::123/128"),
|
|
},
|
|
Peers: []*tailcfg.Node{
|
|
{
|
|
Name: "a.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100.0.0.201/32"),
|
|
pfx("100::201/128"),
|
|
},
|
|
},
|
|
{
|
|
Name: "b.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100::202/128"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
want: dnsMap{
|
|
"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",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100::123/128"),
|
|
},
|
|
Peers: []*tailcfg.Node{
|
|
{
|
|
Name: "a.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100.0.0.201/32"),
|
|
pfx("100::201/128"),
|
|
},
|
|
},
|
|
{
|
|
Name: "b.tailnet",
|
|
Addresses: []netaddr.IPPrefix{
|
|
pfx("100::202/128"),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
want: dnsMap{
|
|
"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) {
|
|
got := dnsMapFromNetworkMap(tt.nm)
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("mismatch:\n got %v\nwant %v\n", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|