From fa3543d6299609861f6cee37d53a6441ff8d4795 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 22 Jan 2021 14:28:44 -0800 Subject: [PATCH] control/controlclient: use more direct way of getting the MagicDNS suffix Suggested by Avery earlier. Ends up fixing bug in "tailscale status" when MagicDNS if off too: https://forum.tailscale.com/t/1-3-293-is-released-a-1-4-0-pre-release/349/11?u=bradfitz --- control/controlclient/netmap.go | 28 ++++++++-------------------- ipn/ipnstate/ipnstate.go | 14 ++++++++++---- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/control/controlclient/netmap.go b/control/controlclient/netmap.go index 7e4846928..ff574a39b 100644 --- a/control/controlclient/netmap.go +++ b/control/controlclient/netmap.go @@ -18,7 +18,6 @@ import ( "tailscale.com/tailcfg" "tailscale.com/types/logger" "tailscale.com/types/wgkey" - "tailscale.com/util/dnsname" "tailscale.com/wgengine/filter" ) @@ -63,27 +62,16 @@ type NetworkMap struct { // TODO(crawshaw): Capabilities []tailcfg.Capability } -// MagicDNSSuffix returns the domain's MagicDNS suffix, or empty if none. -// If non-empty, it will neither start nor end with a period. +// MagicDNSSuffix returns the domain's MagicDNS suffix (even if +// MagicDNS isn't necessarily in use). +// +// It will neither start nor end with a period. func (nm *NetworkMap) MagicDNSSuffix() string { - searchPathUsedAsDNSSuffix := func(suffix string) bool { - if dnsname.HasSuffix(nm.Name, suffix) { - return true - } - for _, p := range nm.Peers { - if dnsname.HasSuffix(p.Name, suffix) { - return true - } - } - return false - } - - for _, d := range nm.DNS.Domains { - if searchPathUsedAsDNSSuffix(d) { - return strings.Trim(d, ".") - } + name := strings.Trim(nm.Name, ".") + if i := strings.Index(name, "."); i != -1 { + name = name[i+1:] } - return "" + return name } func (nm *NetworkMap) String() string { diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index 65454a54f..2f4ce10bd 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -25,10 +25,16 @@ import ( // Status represents the entire state of the IPN network. type Status struct { - BackendState string - TailscaleIPs []netaddr.IP // Tailscale IP(s) assigned to this node - Self *PeerStatus - MagicDNSSuffix string // e.g. "userfoo.tailscale.net" (no surrounding dots) + BackendState string + TailscaleIPs []netaddr.IP // Tailscale IP(s) assigned to this node + Self *PeerStatus + + // MagicDNSSuffix is the network's MagicDNS suffix for nodes + // in the network such as "userfoo.tailscale.net". + // There are no surrounding dots. + // MagicDNSSuffix should be populated regardless of whether a domain + // has MagicDNS enabled. + MagicDNSSuffix string Peer map[key.Public]*PeerStatus User map[tailcfg.UserID]tailcfg.UserProfile