From aaac9cb0a24d57e214a7ba0bde189a035d326854 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 30 Nov 2020 18:05:51 -0800 Subject: [PATCH] tailcfg, cmd/tailscale: add Hostinfo.ShareeNode, hide in "tailscale status" (cherry picked from commit c0af7deb867a0c2fa95be4a37b941643e1d5f962) --- cmd/tailscale/cli/status.go | 3 +++ ipn/ipnstate/ipnstate.go | 9 +++++++++ ipn/local.go | 1 + tailcfg/tailcfg.go | 1 + tailcfg/tailcfg_clone.go | 1 + tailcfg/tailcfg_test.go | 14 +++++++++++--- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index 54476f1b0..782c4d8ef 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -169,6 +169,9 @@ func runStatus(ctx context.Context, args []string) error { } for _, peer := range st.Peers() { ps := st.Peer[peer] + if ps.ShareeNode { + continue + } active := peerActive(ps) if statusArgs.active && !active { continue diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index 703dca26c..06559ce44 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -64,6 +64,12 @@ type PeerStatus struct { LastHandshake time.Time // with local wireguard KeepAlive bool + // ShareeNode indicates this node exists in the netmap because + // it's owned by a shared-to user and that node might connect + // to us. These nodes should be hidden by "tailscale status" + // etc by default. + ShareeNode bool `json:",omitempty"` + // InNetworkMap means that this peer was seen in our latest network map. // In theory, all of InNetworkMap and InMagicSock and InEngine should all be true. InNetworkMap bool @@ -218,6 +224,9 @@ func (sb *StatusBuilder) AddPeer(peer key.Public, st *PeerStatus) { if st.KeepAlive { e.KeepAlive = true } + if st.ShareeNode { + e.ShareeNode = true + } } type StatusUpdater interface { diff --git a/ipn/local.go b/ipn/local.go index 16934eb8e..d0ee2e06e 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -221,6 +221,7 @@ func (b *LocalBackend) UpdateStatus(sb *ipnstate.StatusBuilder) { KeepAlive: p.KeepAlive, Created: p.Created, LastSeen: lastSeen, + ShareeNode: p.Hostinfo.ShareeNode, }) } } diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 741f090c4..bc154e97b 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -281,6 +281,7 @@ type Hostinfo struct { OSVersion string `json:",omitempty"` // operating system version, with optional distro prefix ("Debian 10.4", "Windows 10 Pro 10.0.19041") DeviceModel string `json:",omitempty"` // mobile phone model ("Pixel 3a", "iPhone 11 Pro") Hostname string // name of the host the client runs on + ShareeNode bool `json:",omitempty"` // indicates this node exists in netmap because it's owned by a shared-to user GoArch string `json:",omitempty"` // the host's GOARCH value (of the running binary) RoutableIPs []wgcfg.CIDR `json:",omitempty"` // set of IP ranges this client can route RequestTags []string `json:",omitempty"` // set of ACL tags this node wants to claim diff --git a/tailcfg/tailcfg_clone.go b/tailcfg/tailcfg_clone.go index 8389cab45..94c47e714 100644 --- a/tailcfg/tailcfg_clone.go +++ b/tailcfg/tailcfg_clone.go @@ -105,6 +105,7 @@ var _HostinfoNeedsRegeneration = Hostinfo(struct { OSVersion string DeviceModel string Hostname string + ShareeNode bool GoArch string RoutableIPs []wgcfg.CIDR RequestTags []string diff --git a/tailcfg/tailcfg_test.go b/tailcfg/tailcfg_test.go index b0d96c9f8..60d559ba7 100644 --- a/tailcfg/tailcfg_test.go +++ b/tailcfg/tailcfg_test.go @@ -23,9 +23,12 @@ func fieldsOf(t reflect.Type) (fields []string) { func TestHostinfoEqual(t *testing.T) { hiHandles := []string{ - "IPNVersion", "FrontendLogID", "BackendLogID", "OS", "OSVersion", - "DeviceModel", "Hostname", "GoArch", "RoutableIPs", "RequestTags", "Services", - "NetInfo", + "IPNVersion", "FrontendLogID", "BackendLogID", + "OS", "OSVersion", "DeviceModel", "Hostname", + "ShareeNode", + "GoArch", + "RoutableIPs", "RequestTags", + "Services", "NetInfo", } if have := fieldsOf(reflect.TypeOf(Hostinfo{})); !reflect.DeepEqual(have, hiHandles) { t.Errorf("Hostinfo.Equal check might be out of sync\nfields: %q\nhandled: %q\n", @@ -169,6 +172,11 @@ func TestHostinfoEqual(t *testing.T) { &Hostinfo{Services: []Service{Service{Proto: TCP, Port: 1234, Description: "foo"}}}, true, }, + { + &Hostinfo{ShareeNode: true}, + &Hostinfo{}, + false, + }, } for i, tt := range tests { got := tt.a.Equal(tt.b)