ipn/ipnlocal: use updated prefs in tkaSyncIfNeeded

Signed-off-by: Maisem Ali <maisem@tailscale.com>
pull/6283/head
Maisem Ali 2 years ago committed by Maisem Ali
parent 329a0a8406
commit 6cc0036b40

@ -844,7 +844,7 @@ func (b *LocalBackend) setClientStatus(st controlclient.Status) {
// Prefs will be written out; this is not safe unless locked or cloned. // Prefs will be written out; this is not safe unless locked or cloned.
if st.NetMap != nil { if st.NetMap != nil {
b.mu.Unlock() // respect locking rules for tkaSyncIfNeeded b.mu.Unlock() // respect locking rules for tkaSyncIfNeeded
if err := b.tkaSyncIfNeeded(st.NetMap); err != nil { if err := b.tkaSyncIfNeeded(st.NetMap, prefs.View()); err != nil {
b.logf("[v1] TKA sync error: %v", err) b.logf("[v1] TKA sync error: %v", err)
} }
b.mu.Lock() b.mu.Lock()

@ -17,6 +17,7 @@ import (
"time" "time"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/ipn"
"tailscale.com/ipn/ipnstate" "tailscale.com/ipn/ipnstate"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/tka" "tailscale.com/tka"
@ -96,7 +97,7 @@ func (b *LocalBackend) tkaFilterNetmapLocked(nm *netmap.NetworkMap) {
// //
// tkaSyncIfNeeded immediately takes b.takeSyncLock which is held throughout, // tkaSyncIfNeeded immediately takes b.takeSyncLock which is held throughout,
// and may take b.mu as required. // and may take b.mu as required.
func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap) error { func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap, prefs ipn.PrefsView) error {
if !envknob.UseWIPCode() { if !envknob.UseWIPCode() {
// If the feature flag is not enabled, pretend we don't exist. // If the feature flag is not enabled, pretend we don't exist.
return nil return nil
@ -109,7 +110,7 @@ func (b *LocalBackend) tkaSyncIfNeeded(nm *netmap.NetworkMap) error {
b.mu.Lock() // take mu to protect access to synchronized fields. b.mu.Lock() // take mu to protect access to synchronized fields.
defer b.mu.Unlock() defer b.mu.Unlock()
ourNodeKey := b.pm.CurrentPrefs().Persist().PublicNodeKey() ourNodeKey := prefs.Persist().PublicNodeKey()
isEnabled := b.tka != nil isEnabled := b.tka != nil
wantEnabled := nm.TKAEnabled wantEnabled := nm.TKAEnabled

@ -135,7 +135,7 @@ func TestTKAEnablementFlow(t *testing.T) {
err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ err = b.tkaSyncIfNeeded(&netmap.NetworkMap{
TKAEnabled: true, TKAEnabled: true,
TKAHead: a1.Head(), TKAHead: a1.Head(),
}) }, pm.CurrentPrefs())
if err != nil { if err != nil {
t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) t.Errorf("tkaSyncIfNeededLocked() failed: %v", err)
} }
@ -237,7 +237,7 @@ func TestTKADisablementFlow(t *testing.T) {
err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ err = b.tkaSyncIfNeeded(&netmap.NetworkMap{
TKAEnabled: false, TKAEnabled: false,
TKAHead: authority.Head(), TKAHead: authority.Head(),
}) }, pm.CurrentPrefs())
if err != nil { if err != nil {
t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) t.Errorf("tkaSyncIfNeededLocked() failed: %v", err)
} }
@ -250,7 +250,7 @@ func TestTKADisablementFlow(t *testing.T) {
err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ err = b.tkaSyncIfNeeded(&netmap.NetworkMap{
TKAEnabled: false, TKAEnabled: false,
TKAHead: authority.Head(), TKAHead: authority.Head(),
}) }, pm.CurrentPrefs())
if err != nil { if err != nil {
t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) t.Errorf("tkaSyncIfNeededLocked() failed: %v", err)
} }
@ -485,7 +485,7 @@ func TestTKASync(t *testing.T) {
err = b.tkaSyncIfNeeded(&netmap.NetworkMap{ err = b.tkaSyncIfNeeded(&netmap.NetworkMap{
TKAEnabled: true, TKAEnabled: true,
TKAHead: controlAuthority.Head(), TKAHead: controlAuthority.Head(),
}) }, pm.CurrentPrefs())
if err != nil { if err != nil {
t.Errorf("tkaSyncIfNeededLocked() failed: %v", err) t.Errorf("tkaSyncIfNeededLocked() failed: %v", err)
} }

Loading…
Cancel
Save