2021-09-07 22:18:26 +00: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.
|
|
|
|
|
|
|
|
package ipnlocal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-07-25 03:08:42 +00:00
|
|
|
"net/netip"
|
2021-09-07 22:18:26 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"tailscale.com/ipn"
|
|
|
|
"tailscale.com/net/dns"
|
|
|
|
"tailscale.com/tailcfg"
|
|
|
|
"tailscale.com/tstest"
|
|
|
|
"tailscale.com/types/dnstype"
|
|
|
|
"tailscale.com/types/netmap"
|
ipn/ipnlocal, net/dns*, util/cloudenv: specialize DNS config on Google Cloud
This does three things:
* If you're on GCP, it adds a *.internal DNS split route to the
metadata server, so we never break GCP DNS names. This lets people
have some Tailscale nodes on GCP and some not (e.g. laptops at home)
without having to add a Tailnet-wide *.internal DNS route.
If you already have such a route, though, it won't overwrite it.
* If the 100.100.100.100 DNS forwarder has nowhere to forward to,
it forwards it to the GCP metadata IP, which forwards to 8.8.8.8.
This means there are never errNoUpstreams ("upstream nameservers not set")
errors on GCP due to e.g. mangled /etc/resolv.conf (GCP default VMs
don't have systemd-resolved, so it's likely a DNS supremacy fight)
* makes the DNS fallback mechanism use the GCP metadata IP as a
fallback before our hosted HTTP-based fallbacks
I created a default GCP VM from their web wizard. It has no
systemd-resolved.
I then made its /etc/resolv.conf be empty and deleted its GCP
hostnames in /etc/hosts.
I then logged in to a tailnet with no global DNS settings.
With this, tailscaled writes /etc/resolv.conf (direct mode, as no
systemd-resolved) and sets it to 100.100.100.100, which then has
regular DNS via the metadata IP and *.internal DNS via the metadata IP
as well. If the tailnet configures explicit DNS servers, those are used
instead, except for *.internal.
This also adds a new util/cloudenv package based on version/distro
where the cloud type is only detected once. We'll likely expand it in
the future for other clouds, doing variants of this change for other
popular cloud environments.
Fixes #4911
RELNOTES=Google Cloud DNS improvements
Change-Id: I19f3c2075983669b2b2c0f29a548da8de373c7cf
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-29 20:19:34 +00:00
|
|
|
"tailscale.com/util/cloudenv"
|
2021-09-07 22:18:26 +00:00
|
|
|
"tailscale.com/util/dnsname"
|
|
|
|
)
|
|
|
|
|
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 04:14:09 +00:00
|
|
|
func ipps(ippStrs ...string) (ipps []netip.Prefix) {
|
2021-09-07 22:18:26 +00:00
|
|
|
for _, s := range ippStrs {
|
2022-07-26 03:55:44 +00:00
|
|
|
if ip, err := netip.ParseAddr(s); err == nil {
|
2022-07-25 03:08:42 +00:00
|
|
|
ipps = append(ipps, netip.PrefixFrom(ip, ip.BitLen()))
|
2021-09-07 22:18:26 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-07-26 03:55:44 +00:00
|
|
|
ipps = append(ipps, netip.MustParsePrefix(s))
|
2021-09-07 22:18:26 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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 04:14:09 +00:00
|
|
|
func ips(ss ...string) (ips []netip.Addr) {
|
2021-09-07 22:18:26 +00:00
|
|
|
for _, s := range ss {
|
2022-07-26 03:55:44 +00:00
|
|
|
ips = append(ips, netip.MustParseAddr(s))
|
2021-09-07 22:18:26 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDNSConfigForNetmap(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
nm *netmap.NetworkMap
|
2021-09-08 00:58:04 +00:00
|
|
|
os string // version.OS value; empty means linux
|
ipn/ipnlocal, net/dns*, util/cloudenv: specialize DNS config on Google Cloud
This does three things:
* If you're on GCP, it adds a *.internal DNS split route to the
metadata server, so we never break GCP DNS names. This lets people
have some Tailscale nodes on GCP and some not (e.g. laptops at home)
without having to add a Tailnet-wide *.internal DNS route.
If you already have such a route, though, it won't overwrite it.
* If the 100.100.100.100 DNS forwarder has nowhere to forward to,
it forwards it to the GCP metadata IP, which forwards to 8.8.8.8.
This means there are never errNoUpstreams ("upstream nameservers not set")
errors on GCP due to e.g. mangled /etc/resolv.conf (GCP default VMs
don't have systemd-resolved, so it's likely a DNS supremacy fight)
* makes the DNS fallback mechanism use the GCP metadata IP as a
fallback before our hosted HTTP-based fallbacks
I created a default GCP VM from their web wizard. It has no
systemd-resolved.
I then made its /etc/resolv.conf be empty and deleted its GCP
hostnames in /etc/hosts.
I then logged in to a tailnet with no global DNS settings.
With this, tailscaled writes /etc/resolv.conf (direct mode, as no
systemd-resolved) and sets it to 100.100.100.100, which then has
regular DNS via the metadata IP and *.internal DNS via the metadata IP
as well. If the tailnet configures explicit DNS servers, those are used
instead, except for *.internal.
This also adds a new util/cloudenv package based on version/distro
where the cloud type is only detected once. We'll likely expand it in
the future for other clouds, doing variants of this change for other
popular cloud environments.
Fixes #4911
RELNOTES=Google Cloud DNS improvements
Change-Id: I19f3c2075983669b2b2c0f29a548da8de373c7cf
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-29 20:19:34 +00:00
|
|
|
cloud cloudenv.Cloud
|
2021-09-07 22:18:26 +00:00
|
|
|
prefs *ipn.Prefs
|
|
|
|
want *dns.Config
|
|
|
|
wantLog string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
nm: &netmap.NetworkMap{},
|
|
|
|
prefs: &ipn.Prefs{},
|
|
|
|
want: &dns.Config{
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{},
|
2021-09-07 22:18:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "self_name_and_peers",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "myname.net",
|
|
|
|
Addresses: ipps("100.101.101.101"),
|
|
|
|
Peers: []*tailcfg.Node{
|
|
|
|
{
|
|
|
|
Name: "peera.net",
|
|
|
|
Addresses: ipps("100.102.0.1", "100.102.0.2", "fe75::1001", "fe75::1002"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "b.net",
|
|
|
|
Addresses: ipps("100.102.0.1", "100.102.0.2", "fe75::2"),
|
|
|
|
},
|
2021-09-07 22:45:28 +00:00
|
|
|
{
|
|
|
|
Name: "v6-only.net",
|
|
|
|
Addresses: ipps("fe75::3"), // no IPv4, so we don't ignore IPv6
|
|
|
|
},
|
2021-09-07 22:18:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{},
|
|
|
|
want: &dns.Config{
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{
|
2021-09-07 22:45:28 +00:00
|
|
|
"b.net.": ips("100.102.0.1", "100.102.0.2"),
|
|
|
|
"myname.net.": ips("100.101.101.101"),
|
|
|
|
"peera.net.": ips("100.102.0.1", "100.102.0.2"),
|
|
|
|
"v6-only.net.": ips("fe75::3"),
|
2021-09-07 22:18:26 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-10-04 14:54:16 +00:00
|
|
|
{
|
|
|
|
// An ephemeral node with only an IPv6 address
|
|
|
|
// should get IPv6 records for all its peers,
|
|
|
|
// even if they have IPv4.
|
|
|
|
name: "v6_only_self",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "myname.net",
|
|
|
|
Addresses: ipps("fe75::1"),
|
|
|
|
Peers: []*tailcfg.Node{
|
|
|
|
{
|
|
|
|
Name: "peera.net",
|
|
|
|
Addresses: ipps("100.102.0.1", "100.102.0.2", "fe75::1001"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "b.net",
|
|
|
|
Addresses: ipps("100.102.0.1", "100.102.0.2", "fe75::2"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "v6-only.net",
|
|
|
|
Addresses: ipps("fe75::3"), // no IPv4, so we don't ignore IPv6
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{},
|
|
|
|
want: &dns.Config{
|
2022-01-04 21:33:08 +00:00
|
|
|
OnlyIPv6: true,
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{
|
2021-10-04 14:54:16 +00:00
|
|
|
"b.net.": ips("fe75::2"),
|
|
|
|
"myname.net.": ips("fe75::1"),
|
|
|
|
"peera.net.": ips("fe75::1001"),
|
|
|
|
"v6-only.net.": ips("fe75::3"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-07 22:18:26 +00:00
|
|
|
{
|
|
|
|
name: "extra_records",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "myname.net",
|
|
|
|
Addresses: ipps("100.101.101.101"),
|
|
|
|
DNS: tailcfg.DNSConfig{
|
|
|
|
ExtraRecords: []tailcfg.DNSRecord{
|
|
|
|
{Name: "foo.com", Value: "1.2.3.4"},
|
|
|
|
{Name: "bar.com", Value: "1::6"},
|
|
|
|
{Name: "sdlfkjsdklfj", Type: "IGNORE"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{},
|
|
|
|
want: &dns.Config{
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{
|
2021-09-07 22:18:26 +00:00
|
|
|
"myname.net.": ips("100.101.101.101"),
|
|
|
|
"foo.com.": ips("1.2.3.4"),
|
|
|
|
"bar.com.": ips("1::6"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-09-08 00:58:04 +00:00
|
|
|
{
|
|
|
|
name: "corp_dns_misc",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
Name: "host.some.domain.net.",
|
|
|
|
DNS: tailcfg.DNSConfig{
|
|
|
|
Proxied: true,
|
|
|
|
Domains: []string{"foo.com", "bar.com"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{
|
|
|
|
CorpDNS: true,
|
|
|
|
},
|
|
|
|
want: &dns.Config{
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{},
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
"0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa.": nil,
|
|
|
|
"100.100.in-addr.arpa.": nil,
|
|
|
|
"101.100.in-addr.arpa.": nil,
|
|
|
|
"102.100.in-addr.arpa.": nil,
|
|
|
|
"103.100.in-addr.arpa.": nil,
|
|
|
|
"104.100.in-addr.arpa.": nil,
|
|
|
|
"105.100.in-addr.arpa.": nil,
|
|
|
|
"106.100.in-addr.arpa.": nil,
|
|
|
|
"107.100.in-addr.arpa.": nil,
|
|
|
|
"108.100.in-addr.arpa.": nil,
|
|
|
|
"109.100.in-addr.arpa.": nil,
|
|
|
|
"110.100.in-addr.arpa.": nil,
|
|
|
|
"111.100.in-addr.arpa.": nil,
|
|
|
|
"112.100.in-addr.arpa.": nil,
|
|
|
|
"113.100.in-addr.arpa.": nil,
|
|
|
|
"114.100.in-addr.arpa.": nil,
|
|
|
|
"115.100.in-addr.arpa.": nil,
|
|
|
|
"116.100.in-addr.arpa.": nil,
|
|
|
|
"117.100.in-addr.arpa.": nil,
|
|
|
|
"118.100.in-addr.arpa.": nil,
|
|
|
|
"119.100.in-addr.arpa.": nil,
|
|
|
|
"120.100.in-addr.arpa.": nil,
|
|
|
|
"121.100.in-addr.arpa.": nil,
|
|
|
|
"122.100.in-addr.arpa.": nil,
|
|
|
|
"123.100.in-addr.arpa.": nil,
|
|
|
|
"124.100.in-addr.arpa.": nil,
|
|
|
|
"125.100.in-addr.arpa.": nil,
|
|
|
|
"126.100.in-addr.arpa.": nil,
|
|
|
|
"127.100.in-addr.arpa.": nil,
|
|
|
|
"64.100.in-addr.arpa.": nil,
|
|
|
|
"65.100.in-addr.arpa.": nil,
|
|
|
|
"66.100.in-addr.arpa.": nil,
|
|
|
|
"67.100.in-addr.arpa.": nil,
|
|
|
|
"68.100.in-addr.arpa.": nil,
|
|
|
|
"69.100.in-addr.arpa.": nil,
|
|
|
|
"70.100.in-addr.arpa.": nil,
|
|
|
|
"71.100.in-addr.arpa.": nil,
|
|
|
|
"72.100.in-addr.arpa.": nil,
|
|
|
|
"73.100.in-addr.arpa.": nil,
|
|
|
|
"74.100.in-addr.arpa.": nil,
|
|
|
|
"75.100.in-addr.arpa.": nil,
|
|
|
|
"76.100.in-addr.arpa.": nil,
|
|
|
|
"77.100.in-addr.arpa.": nil,
|
|
|
|
"78.100.in-addr.arpa.": nil,
|
|
|
|
"79.100.in-addr.arpa.": nil,
|
|
|
|
"80.100.in-addr.arpa.": nil,
|
|
|
|
"81.100.in-addr.arpa.": nil,
|
|
|
|
"82.100.in-addr.arpa.": nil,
|
|
|
|
"83.100.in-addr.arpa.": nil,
|
|
|
|
"84.100.in-addr.arpa.": nil,
|
|
|
|
"85.100.in-addr.arpa.": nil,
|
|
|
|
"86.100.in-addr.arpa.": nil,
|
|
|
|
"87.100.in-addr.arpa.": nil,
|
|
|
|
"88.100.in-addr.arpa.": nil,
|
|
|
|
"89.100.in-addr.arpa.": nil,
|
|
|
|
"90.100.in-addr.arpa.": nil,
|
|
|
|
"91.100.in-addr.arpa.": nil,
|
|
|
|
"92.100.in-addr.arpa.": nil,
|
|
|
|
"93.100.in-addr.arpa.": nil,
|
|
|
|
"94.100.in-addr.arpa.": nil,
|
|
|
|
"95.100.in-addr.arpa.": nil,
|
|
|
|
"96.100.in-addr.arpa.": nil,
|
|
|
|
"97.100.in-addr.arpa.": nil,
|
|
|
|
"98.100.in-addr.arpa.": nil,
|
|
|
|
"99.100.in-addr.arpa.": nil,
|
|
|
|
"some.domain.net.": nil,
|
|
|
|
},
|
|
|
|
SearchDomains: []dnsname.FQDN{
|
|
|
|
"foo.com.",
|
|
|
|
"bar.com.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-10-09 19:17:59 +00:00
|
|
|
// Prior to fixing https://github.com/tailscale/tailscale/issues/2116,
|
|
|
|
// Android had cases where it needed FallbackResolvers. This was the
|
|
|
|
// negative test for the case where Override-local-DNS was set, so the
|
|
|
|
// fallback resolvers did not need to be used. This test is still valid
|
|
|
|
// so we keep it, but the fallback test has been removed.
|
2021-09-08 00:58:04 +00:00
|
|
|
name: "android_does_NOT_need_fallbacks",
|
|
|
|
os: "android",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
DNS: tailcfg.DNSConfig{
|
2022-05-03 21:41:58 +00:00
|
|
|
Resolvers: []*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
{Addr: "8.8.8.8"},
|
|
|
|
},
|
2022-05-03 21:41:58 +00:00
|
|
|
FallbackResolvers: []*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
{Addr: "8.8.4.4"},
|
|
|
|
},
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[string][]*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
"foo.com.": {{Addr: "1.2.3.4"}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{
|
|
|
|
CorpDNS: true,
|
|
|
|
},
|
|
|
|
want: &dns.Config{
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{},
|
2022-05-03 21:41:58 +00:00
|
|
|
DefaultResolvers: []*dnstype.Resolver{
|
2022-04-19 04:58:00 +00:00
|
|
|
{Addr: "8.8.8.8"},
|
2021-09-08 00:58:04 +00:00
|
|
|
},
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{
|
2022-04-19 04:58:00 +00:00
|
|
|
"foo.com.": {{Addr: "1.2.3.4"}},
|
2021-09-08 00:58:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "exit_nodes_need_fallbacks",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
DNS: tailcfg.DNSConfig{
|
2022-05-03 21:41:58 +00:00
|
|
|
FallbackResolvers: []*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
{Addr: "8.8.4.4"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{
|
|
|
|
CorpDNS: true,
|
|
|
|
ExitNodeID: "some-id",
|
|
|
|
},
|
|
|
|
want: &dns.Config{
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{},
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
|
|
|
DefaultResolvers: []*dnstype.Resolver{
|
2022-04-19 04:58:00 +00:00
|
|
|
{Addr: "8.8.4.4"},
|
2021-09-08 00:58:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not_exit_node_NOT_need_fallbacks",
|
|
|
|
nm: &netmap.NetworkMap{
|
|
|
|
DNS: tailcfg.DNSConfig{
|
2022-05-03 21:41:58 +00:00
|
|
|
FallbackResolvers: []*dnstype.Resolver{
|
2021-09-08 00:58:04 +00:00
|
|
|
{Addr: "8.8.4.4"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
prefs: &ipn.Prefs{
|
|
|
|
CorpDNS: true,
|
|
|
|
},
|
|
|
|
want: &dns.Config{
|
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 04:14:09 +00:00
|
|
|
Hosts: map[dnsname.FQDN][]netip.Addr{},
|
2022-05-03 21:41:58 +00:00
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
2021-09-08 00:58:04 +00:00
|
|
|
},
|
|
|
|
},
|
2021-09-07 22:18:26 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2021-09-08 00:58:04 +00:00
|
|
|
verOS := tt.os
|
|
|
|
if verOS == "" {
|
|
|
|
verOS = "linux"
|
|
|
|
}
|
2021-09-07 22:18:26 +00:00
|
|
|
var log tstest.MemLogger
|
2022-10-23 17:07:10 +00:00
|
|
|
got := dnsConfigForNetmap(tt.nm, tt.prefs.View(), log.Logf, verOS)
|
2021-09-07 22:18:26 +00:00
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
|
|
|
gotj, _ := json.MarshalIndent(got, "", "\t")
|
|
|
|
wantj, _ := json.MarshalIndent(tt.want, "", "\t")
|
|
|
|
t.Errorf("wrong\n got: %s\n\nwant: %s\n", gotj, wantj)
|
|
|
|
}
|
|
|
|
if got := log.String(); got != tt.wantLog {
|
|
|
|
t.Errorf("log output wrong\n got: %q\nwant: %q\n", got, tt.wantLog)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-11-29 22:18:09 +00:00
|
|
|
|
|
|
|
func TestAllowExitNodeDNSProxyToServeName(t *testing.T) {
|
|
|
|
b := &LocalBackend{}
|
|
|
|
if b.allowExitNodeDNSProxyToServeName("google.com") {
|
|
|
|
t.Fatal("unexpected true on backend with nil NetMap")
|
|
|
|
}
|
|
|
|
|
|
|
|
b.netMap = &netmap.NetworkMap{
|
|
|
|
DNS: tailcfg.DNSConfig{
|
|
|
|
ExitNodeFilteredSet: []string{
|
|
|
|
".ts.net",
|
|
|
|
"some.exact.bad",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
// Allow by default:
|
|
|
|
{"google.com", true},
|
|
|
|
{"GOOGLE.com", true},
|
|
|
|
|
|
|
|
// Rejected by suffix:
|
|
|
|
{"foo.TS.NET", false},
|
|
|
|
{"foo.ts.net", false},
|
|
|
|
|
|
|
|
// Suffix doesn't match
|
|
|
|
{"ts.net", true},
|
|
|
|
|
|
|
|
// Rejected by exact match:
|
|
|
|
{"some.exact.bad", false},
|
|
|
|
{"SOME.EXACT.BAD", false},
|
|
|
|
|
|
|
|
// But a prefix is okay.
|
|
|
|
{"prefix-okay.some.exact.bad", true},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
got := b.allowExitNodeDNSProxyToServeName(tt.name)
|
|
|
|
if got != tt.want {
|
|
|
|
t.Errorf("for %q = %v; want %v", tt.name, got, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|