From 6d02a48d8d6e3d11db4c3d467c85bc36386058a3 Mon Sep 17 00:00:00 2001 From: Ross Zurowski Date: Tue, 15 Feb 2022 12:36:01 -0500 Subject: [PATCH] ipn: add `TailnetStatus` field to `tailscale status --json` (#3865) We need to capture some tailnet-related information for some Docker features we're building. This exposes the tailnet name and MagicDNS information via `tailscale status --json`. Fixes tailscale/corp#3670 Signed-off-by: Ross Zurowski --- ipn/ipnlocal/local.go | 9 +++++++-- ipn/ipnstate/ipnstate.go | 34 +++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 2125447a0..15f7f5698 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -383,9 +383,14 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func } } if b.netMap != nil { - s.MagicDNSSuffix = b.netMap.MagicDNSSuffix() s.CertDomains = append([]string(nil), b.netMap.DNS.CertDomains...) - s.TailnetName = b.netMap.Domain + s.MagicDNSSuffix = b.netMap.MagicDNSSuffix() + if s.CurrentTailnet == nil { + s.CurrentTailnet = &ipnstate.TailnetStatus{} + } + s.CurrentTailnet.MagicDNSSuffix = b.netMap.MagicDNSSuffix() + s.CurrentTailnet.MagicDNSEnabled = b.netMap.DNS.Proxied + s.CurrentTailnet.Name = b.netMap.Domain } }) sb.MutateSelfStatus(func(ss *ipnstate.PeerStatus) { diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index fd77875cb..9941d7931 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -33,10 +33,6 @@ type Status struct { // "Starting", "Running". BackendState string - // TailnetName is the name of the network that's currently in - // use. - TailnetName string - AuthURL string // current URL provided by control to authorize client TailscaleIPs []netaddr.IP // Tailscale IP(s) assigned to this node Self *PeerStatus @@ -46,13 +42,15 @@ type Status struct { // problems are detected) Health []string - // 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. + // This field is the legacy name of CurrentTailnet.MagicDNSSuffix. + // + // Deprecated: use CurrentTailnet.MagicDNSSuffix instead. MagicDNSSuffix string + // CurrentTailnet is information about the tailnet that the node + // is currently connected to. When not connected, this field is nil. + CurrentTailnet *TailnetStatus + // CertDomains are the set of DNS names for which the control // plane server will assist with provisioning TLS // certificates. See SetDNSRequest for dns-01 ACME challenges @@ -64,6 +62,24 @@ type Status struct { User map[tailcfg.UserID]tailcfg.UserProfile } +// TailnetStatus is information about a Tailscale network ("tailnet"). +type TailnetStatus struct { + // Name is the name of the network that's currently in use. + Name string + + // 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 + + // MagicDNSEnabled is whether or not the network has MagicDNS enabled. + // Note that the current device may still not support MagicDNS if + // `--accept-dns=false` was used. + MagicDNSEnabled bool +} + func (s *Status) Peers() []key.NodePublic { kk := make([]key.NodePublic, 0, len(s.Peer)) for k := range s.Peer {