net/dns: add debug envknob to enable dual stack MagicDNS

Updates #15404

Change-Id: Ic754cc54113b1660b7071b40babb9d3c0e25b2e1
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2025-03-24 09:08:20 -07:00 committed by Brad Fitzpatrick
parent 1ec1a60c10
commit a3bc0bcb0a
2 changed files with 24 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import (
"net/netip" "net/netip"
"sort" "sort"
"tailscale.com/control/controlknobs"
"tailscale.com/envknob"
"tailscale.com/net/dns/publicdns" "tailscale.com/net/dns/publicdns"
"tailscale.com/net/dns/resolver" "tailscale.com/net/dns/resolver"
"tailscale.com/net/tsaddr" "tailscale.com/net/tsaddr"
@ -47,11 +49,28 @@ type Config struct {
OnlyIPv6 bool OnlyIPv6 bool
} }
func (c *Config) serviceIP() netip.Addr { var magicDNSDualStack = envknob.RegisterBool("TS_DEBUG_MAGIC_DNS_DUAL_STACK")
// serviceIPs returns the list of service IPs where MagicDNS is reachable.
//
// The provided knobs may be nil.
func (c *Config) serviceIPs(knobs *controlknobs.Knobs) []netip.Addr {
if c.OnlyIPv6 { if c.OnlyIPv6 {
return tsaddr.TailscaleServiceIPv6() return []netip.Addr{tsaddr.TailscaleServiceIPv6()}
} }
return tsaddr.TailscaleServiceIP()
// TODO(bradfitz,mikeodr,raggi): include IPv6 here too; tailscale/tailscale#15404
// And add a controlknobs knob to disable dual stack.
//
// For now, opt-in for testing.
if magicDNSDualStack() {
return []netip.Addr{
tsaddr.TailscaleServiceIP(),
tsaddr.TailscaleServiceIPv6(),
}
}
return []netip.Addr{tsaddr.TailscaleServiceIP()}
} }
// WriteToBufioWriter write a debug version of c for logs to w, omitting // WriteToBufioWriter write a debug version of c for logs to w, omitting

View File

@ -307,7 +307,7 @@ func (m *Manager) compileConfig(cfg Config) (rcfg resolver.Config, ocfg OSConfig
// through quad-100. // through quad-100.
rcfg.Routes = routes rcfg.Routes = routes
rcfg.Routes["."] = cfg.DefaultResolvers rcfg.Routes["."] = cfg.DefaultResolvers
ocfg.Nameservers = []netip.Addr{cfg.serviceIP()} ocfg.Nameservers = cfg.serviceIPs(m.knobs)
return rcfg, ocfg, nil return rcfg, ocfg, nil
} }
@ -345,7 +345,7 @@ func (m *Manager) compileConfig(cfg Config) (rcfg resolver.Config, ocfg OSConfig
// or routes + MagicDNS, or just MagicDNS, or on an OS that cannot // or routes + MagicDNS, or just MagicDNS, or on an OS that cannot
// split-DNS. Install a split config pointing at quad-100. // split-DNS. Install a split config pointing at quad-100.
rcfg.Routes = routes rcfg.Routes = routes
ocfg.Nameservers = []netip.Addr{cfg.serviceIP()} ocfg.Nameservers = cfg.serviceIPs(m.knobs)
var baseCfg *OSConfig // base config; non-nil if/when known var baseCfg *OSConfig // base config; non-nil if/when known