|
|
@ -22,7 +22,6 @@ import (
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/tsd"
|
|
|
|
"tailscale.com/tsd"
|
|
|
|
"tailscale.com/tstest"
|
|
|
|
"tailscale.com/tstest"
|
|
|
|
"tailscale.com/types/dnstype"
|
|
|
|
|
|
|
|
"tailscale.com/types/key"
|
|
|
|
"tailscale.com/types/key"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/logid"
|
|
|
|
"tailscale.com/types/logid"
|
|
|
@ -856,109 +855,3 @@ func TestUpdateNetmapDelta(t *testing.T) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestWireguardExitNodeDNSResolvers(t *testing.T) {
|
|
|
|
|
|
|
|
type tc struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
id tailcfg.StableNodeID
|
|
|
|
|
|
|
|
peers []*tailcfg.Node
|
|
|
|
|
|
|
|
wantOK bool
|
|
|
|
|
|
|
|
wantResolvers []*dnstype.Resolver
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests := []tc{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "no peers",
|
|
|
|
|
|
|
|
id: "1",
|
|
|
|
|
|
|
|
wantOK: false,
|
|
|
|
|
|
|
|
wantResolvers: nil,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "non wireguard peer",
|
|
|
|
|
|
|
|
id: "1",
|
|
|
|
|
|
|
|
peers: []*tailcfg.Node{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ID: 1,
|
|
|
|
|
|
|
|
StableID: "1",
|
|
|
|
|
|
|
|
IsWireGuardOnly: false,
|
|
|
|
|
|
|
|
ExitNodeDNSResolvers: []*dnstype.Resolver{{Addr: "dns.example.com"}},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantOK: false,
|
|
|
|
|
|
|
|
wantResolvers: nil,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "no matching IDs",
|
|
|
|
|
|
|
|
id: "2",
|
|
|
|
|
|
|
|
peers: []*tailcfg.Node{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ID: 1,
|
|
|
|
|
|
|
|
StableID: "1",
|
|
|
|
|
|
|
|
IsWireGuardOnly: true,
|
|
|
|
|
|
|
|
ExitNodeDNSResolvers: []*dnstype.Resolver{{Addr: "dns.example.com"}},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantOK: false,
|
|
|
|
|
|
|
|
wantResolvers: nil,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "wireguard peer",
|
|
|
|
|
|
|
|
id: "1",
|
|
|
|
|
|
|
|
peers: []*tailcfg.Node{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ID: 1,
|
|
|
|
|
|
|
|
StableID: "1",
|
|
|
|
|
|
|
|
IsWireGuardOnly: true,
|
|
|
|
|
|
|
|
ExitNodeDNSResolvers: []*dnstype.Resolver{{Addr: "dns.example.com"}},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantOK: true,
|
|
|
|
|
|
|
|
wantResolvers: []*dnstype.Resolver{{Addr: "dns.example.com"}},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
|
|
|
|
peers := peersMap(nodeViews(tc.peers))
|
|
|
|
|
|
|
|
nm := &netmap.NetworkMap{}
|
|
|
|
|
|
|
|
gotResolvers, gotOK := wireguardExitNodeDNSResolvers(nm, peers, tc.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if gotOK != tc.wantOK || !resolversEqual(gotResolvers, tc.wantResolvers) {
|
|
|
|
|
|
|
|
t.Errorf("case: %s: got %v, %v, want %v, %v", tc.name, gotOK, gotResolvers, tc.wantOK, tc.wantResolvers)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestDNSConfigForNetmapForWireguardExitNode(t *testing.T) {
|
|
|
|
|
|
|
|
resolvers := []*dnstype.Resolver{{Addr: "dns.example.com"}}
|
|
|
|
|
|
|
|
nm := &netmap.NetworkMap{}
|
|
|
|
|
|
|
|
peers := map[tailcfg.NodeID]tailcfg.NodeView{
|
|
|
|
|
|
|
|
1: (&tailcfg.Node{
|
|
|
|
|
|
|
|
ID: 1,
|
|
|
|
|
|
|
|
StableID: "1",
|
|
|
|
|
|
|
|
IsWireGuardOnly: true,
|
|
|
|
|
|
|
|
ExitNodeDNSResolvers: resolvers,
|
|
|
|
|
|
|
|
Hostinfo: (&tailcfg.Hostinfo{}).View(),
|
|
|
|
|
|
|
|
}).View(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
prefs := &ipn.Prefs{
|
|
|
|
|
|
|
|
ExitNodeID: "1",
|
|
|
|
|
|
|
|
CorpDNS: true,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
got := dnsConfigForNetmap(nm, peers, prefs.View(), t.Logf, "")
|
|
|
|
|
|
|
|
if !resolversEqual(got.DefaultResolvers, resolvers) {
|
|
|
|
|
|
|
|
t.Errorf("got %v, want %v", got.DefaultResolvers, resolvers)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func resolversEqual(a, b []*dnstype.Resolver) bool {
|
|
|
|
|
|
|
|
if len(a) != len(b) {
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range a {
|
|
|
|
|
|
|
|
if !a[i].Equal(b[i]) {
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|