Skip to content

Commit b370274

Browse files
committed
ipn/ipnlocal: pull CapabilityPreviewWebClient into webClientAtomicBool
Now uses webClientAtomicBool as the source of truth for whether the web client should be running in tailscaled, with it updated when either the RunWebClient pref or CapabilityPreviewWebClient node capability changes. This avoids requiring holding the LocalBackend lock on each call to ShouldRunWebClient to check for the CapabilityPreviewWebClient value. Updates tailscale/corp#14335 Signed-off-by: Sonia Appasamy <sonia@tailscale.com>
1 parent c6a4612 commit b370274

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

ipn/ipnlocal/local.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ type LocalBackend struct {
170170
logFlushFunc func() // or nil if SetLogFlusher wasn't called
171171
em *expiryManager // non-nil
172172
sshAtomicBool atomic.Bool
173-
webclientAtomicBool atomic.Bool
173+
webClientAtomicBool atomic.Bool
174174
shutdownCalled bool // if Shutdown has been called
175175
debugSink *capture.Sink
176176
sockstatLogger *sockstatlog.Logger
@@ -1113,6 +1113,7 @@ func (b *LocalBackend) SetControlClientStatus(c controlclient.Client, st control
11131113
// Perform all reconfiguration based on the netmap here.
11141114
if st.NetMap != nil {
11151115
b.capTailnetLock = hasCapability(st.NetMap, tailcfg.CapabilityTailnetLock)
1116+
b.setWebClientAtomicBoolLocked(st.NetMap, prefs.View())
11161117

11171118
b.mu.Unlock() // respect locking rules for tkaSyncIfNeeded
11181119
if err := b.tkaSyncIfNeeded(st.NetMap, prefs.View()); err != nil {
@@ -2504,7 +2505,7 @@ func (b *LocalBackend) setTCPPortsIntercepted(ports []uint16) {
25042505
// and shouldInterceptTCPPortAtomic from the prefs p, which may be !Valid().
25052506
func (b *LocalBackend) setAtomicValuesFromPrefsLocked(p ipn.PrefsView) {
25062507
b.sshAtomicBool.Store(p.Valid() && p.RunSSH() && envknob.CanSSHD())
2507-
b.webclientAtomicBool.Store(p.Valid() && p.RunWebClient())
2508+
b.setWebClientAtomicBoolLocked(b.netMap, p)
25082509

25092510
if !p.Valid() {
25102511
b.containsViaIPFuncAtomic.Store(tsaddr.FalseContainsIPFunc())
@@ -3018,9 +3019,6 @@ func (b *LocalBackend) setPrefsLockedOnEntry(caller string, newp *ipn.Prefs) ipn
30183019
b.sshServer = nil
30193020
}
30203021
}
3021-
if oldp.ShouldWebClientBeRunning() && !newp.ShouldWebClientBeRunning() {
3022-
go b.WebClientShutdown()
3023-
}
30243022
if netMap != nil {
30253023
newProfile := netMap.UserProfiles[netMap.User()]
30263024
if newLoginName := newProfile.LoginName; newLoginName != "" {
@@ -4212,8 +4210,14 @@ func (b *LocalBackend) ResetForClientDisconnect() {
42124210

42134211
func (b *LocalBackend) ShouldRunSSH() bool { return b.sshAtomicBool.Load() && envknob.CanSSHD() }
42144212

4215-
func (b *LocalBackend) ShouldRunWebClient() bool {
4216-
return b.webclientAtomicBool.Load() && hasCapability(b.netMap, tailcfg.CapabilityPreviewWebClient)
4213+
func (b *LocalBackend) ShouldRunWebClient() bool { return b.webClientAtomicBool.Load() }
4214+
4215+
func (b *LocalBackend) setWebClientAtomicBoolLocked(nm *netmap.NetworkMap, prefs ipn.PrefsView) {
4216+
shouldRun := prefs.Valid() && prefs.RunWebClient() && hasCapability(nm, tailcfg.CapabilityPreviewWebClient)
4217+
wasRunning := b.webClientAtomicBool.Swap(shouldRun)
4218+
if wasRunning && !shouldRun {
4219+
go b.WebClientShutdown() // stop web client
4220+
}
42174221
}
42184222

42194223
// ShouldHandleViaIP reports whether ip is an IPv6 address in the

ipn/ipnlocal/web_client.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"tailscale.com/client/tailscale"
1515
"tailscale.com/client/web"
1616
"tailscale.com/net/netutil"
17-
"tailscale.com/tailcfg"
1817
)
1918

2019
// webClient holds state for the web interface for managing
@@ -41,7 +40,7 @@ func (b *LocalBackend) SetWebLocalClient(lc *tailscale.LocalClient) {
4140
// tailscaled instance.
4241
// If the web interface is already running, WebClientInit is a no-op.
4342
func (b *LocalBackend) WebClientInit() (err error) {
44-
if !hasCapability(b.netMap, tailcfg.CapabilityPreviewWebClient) {
43+
if !b.ShouldRunWebClient() {
4544
return errors.New("web client not enabled for this device")
4645
}
4746

0 commit comments

Comments
 (0)