ipn/ipnlocal: add tags and a few other details to self status

This makes tags, creation time, exit node option and primary routes
for the current node exposed via `tailscale status --json`

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
pull/6126/head
Anton Tolchanov 2 years ago committed by Anton Tolchanov
parent 120bfc97ce
commit 193afe19cb

@ -584,11 +584,12 @@ func (b *LocalBackend) updateStatus(sb *ipnstate.StatusBuilder, extraLocked func
sb.MutateSelfStatus(func(ss *ipnstate.PeerStatus) { sb.MutateSelfStatus(func(ss *ipnstate.PeerStatus) {
ss.Online = health.GetInPollNetMap() ss.Online = health.GetInPollNetMap()
if b.netMap != nil { if b.netMap != nil {
ss.InNetworkMap = true
ss.HostName = b.netMap.Hostinfo.Hostname ss.HostName = b.netMap.Hostinfo.Hostname
ss.DNSName = b.netMap.Name ss.DNSName = b.netMap.Name
ss.UserID = b.netMap.User ss.UserID = b.netMap.User
if sn := b.netMap.SelfNode; sn != nil { if sn := b.netMap.SelfNode; sn != nil {
ss.ID = sn.StableID peerStatusFromNode(ss, sn)
if c := sn.Capabilities; len(c) > 0 { if c := sn.Capabilities; len(c) > 0 {
ss.Capabilities = append([]string(nil), c...) ss.Capabilities = append([]string(nil), c...)
} }
@ -626,38 +627,38 @@ func (b *LocalBackend) populatePeerStatusLocked(sb *ipnstate.StatusBuilder) {
tailscaleIPs = append(tailscaleIPs, addr.Addr()) tailscaleIPs = append(tailscaleIPs, addr.Addr())
} }
} }
exitNodeOption := tsaddr.PrefixesContainsFunc(p.AllowedIPs, func(r netip.Prefix) bool { ps := &ipnstate.PeerStatus{
return r.Bits() == 0 InNetworkMap: true,
}) UserID: p.User,
var tags *views.Slice[string] TailscaleIPs: tailscaleIPs,
var primaryRoutes *views.IPPrefixSlice HostName: p.Hostinfo.Hostname(),
if p.Tags != nil { DNSName: p.Name,
v := views.SliceOf(p.Tags) OS: p.Hostinfo.OS(),
tags = &v KeepAlive: p.KeepAlive,
} LastSeen: lastSeen,
if p.PrimaryRoutes != nil { Online: p.Online != nil && *p.Online,
v := views.IPPrefixSliceOf(p.PrimaryRoutes) ShareeNode: p.Hostinfo.ShareeNode(),
primaryRoutes = &v ExitNode: p.StableID != "" && p.StableID == b.prefs.ExitNodeID(),
} SSH_HostKeys: p.Hostinfo.SSH_HostKeys().AsSlice(),
sb.AddPeer(p.Key, &ipnstate.PeerStatus{ }
InNetworkMap: true, peerStatusFromNode(ps, p)
ID: p.StableID, sb.AddPeer(p.Key, ps)
UserID: p.User, }
TailscaleIPs: tailscaleIPs, }
Tags: tags,
PrimaryRoutes: primaryRoutes, // peerStatusFromNode copies fields that exist in the Node struct for
HostName: p.Hostinfo.Hostname(), // current node and peers into the provided PeerStatus.
DNSName: p.Name, func peerStatusFromNode(ps *ipnstate.PeerStatus, n *tailcfg.Node) {
OS: p.Hostinfo.OS(), ps.ID = n.StableID
KeepAlive: p.KeepAlive, ps.Created = n.Created
Created: p.Created, ps.ExitNodeOption = tsaddr.ContainsExitRoutes(n.AllowedIPs)
LastSeen: lastSeen, if n.Tags != nil {
Online: p.Online != nil && *p.Online, v := views.SliceOf(n.Tags)
ShareeNode: p.Hostinfo.ShareeNode(), ps.Tags = &v
ExitNode: p.StableID != "" && p.StableID == b.prefs.ExitNodeID(), }
ExitNodeOption: exitNodeOption, if n.PrimaryRoutes != nil {
SSH_HostKeys: p.Hostinfo.SSH_HostKeys().AsSlice(), v := views.IPPrefixSliceOf(n.PrimaryRoutes)
}) ps.PrimaryRoutes = &v
} }
} }

Loading…
Cancel
Save