From 2a95ee46806605e458080939b4d4a116a393e79f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 30 Nov 2021 11:46:12 -0800 Subject: [PATCH] cmd/tailscale, ipn/ipnstate: note which nodes are exit nodes in status Fixes #3446 Change-Id: Ib41d588e7fa434c02d134fa449f85b0e15083683 Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/status.go | 4 ++++ ipn/ipnlocal/local.go | 4 ++++ ipn/ipnstate/ipnstate.go | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index e5e230590..142fb9242 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -148,6 +148,8 @@ func runStatus(ctx context.Context, args []string) error { if !ps.Active { if ps.ExitNode { f("idle; exit node") + } else if ps.ExitNodeOption { + f("idle; offers exit node") } else if anyTraffic { f("idle") } else { @@ -157,6 +159,8 @@ func runStatus(ctx context.Context, args []string) error { f("active; ") if ps.ExitNode { f("exit node; ") + } else if ps.ExitNodeOption { + f("offers exit node; ") } if relay != "" && ps.CurAddr == "" { f("relay %q", relay) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index f35e10977..605b9f58c 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -402,6 +402,9 @@ func (b *LocalBackend) populatePeerStatusLocked(sb *ipnstate.StatusBuilder) { tailscaleIPs = append(tailscaleIPs, addr.IP()) } } + exitNodeOption := tsaddr.PrefixesContainsFunc(p.AllowedIPs, func(r netaddr.IPPrefix) bool { + return r.Bits() == 0 + }) sb.AddPeer(p.Key, &ipnstate.PeerStatus{ InNetworkMap: true, ID: p.StableID, @@ -416,6 +419,7 @@ func (b *LocalBackend) populatePeerStatusLocked(sb *ipnstate.StatusBuilder) { LastSeen: lastSeen, ShareeNode: p.Hostinfo.ShareeNode, ExitNode: p.StableID != "" && p.StableID == b.prefs.ExitNodeID, + ExitNodeOption: exitNodeOption, }) } } diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index be6bf433f..2347b86ca 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -96,14 +96,15 @@ type PeerStatus struct { CurAddr string // one of Addrs, or unique if roaming Relay string // DERP region - RxBytes int64 - TxBytes int64 - Created time.Time // time registered with tailcontrol - LastWrite time.Time // time last packet sent - LastSeen time.Time // last seen to tailcontrol - LastHandshake time.Time // with local wireguard - KeepAlive bool - ExitNode bool // true if this is the currently selected exit node. + RxBytes int64 + TxBytes int64 + Created time.Time // time registered with tailcontrol + LastWrite time.Time // time last packet sent + LastSeen time.Time // last seen to tailcontrol + LastHandshake time.Time // with local wireguard + KeepAlive bool + ExitNode bool // true if this is the currently selected exit node. + ExitNodeOption bool // true if this node can be an exit node (offered && approved) // Active is whether the node was recently active. The // definition is somewhat undefined but has historically and @@ -290,6 +291,9 @@ func (sb *StatusBuilder) AddPeer(peer key.NodePublic, st *PeerStatus) { if st.ExitNode { e.ExitNode = true } + if st.ExitNodeOption { + e.ExitNodeOption = true + } if st.ShareeNode { e.ShareeNode = true }