mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-27 12:06:31 -08:00
ipn/ipnlocal: announce a changed exit node suggestion on every path
Two paths reach suggestExitNodeLocked and then return without a broadcast: editPrefsLocked, when the edit is a no-op or the policy check rejects it, and reconcilePrefs, when the prefs are unchanged. Before the pending flag they announced a changed suggestion at once. Both now flush it before returning. TestSuggestedExitNodePendingFlushed marks a suggestion as pending and calls each entry point that can recompute it, checking that a Notify carries the suggestion and the flag is clear afterwards. Without the two flushes, the EditPrefs and reconcilePrefs cases fail. Updates #22206 Signed-off-by: Brendan Creane <[email protected]>
This commit is contained in:
2 files changed
+82
No files matched your search
@@ -2518,6 +2518,9 @@ func (b *LocalBackend) reconcilePrefs() (_ ipn.PrefsView, anyChange bool) {
|
||||
|
||||
prefs := b.pm.CurrentPrefs().AsStruct()
|
||||
if !b.reconcilePrefsLocked(prefs) {
|
||||
// Reconciling can recompute the exit node suggestion even when
|
||||
// the prefs end up unchanged.
|
||||
b.sendSuggestedExitNodeLocked()
|
||||
return prefs.View(), false
|
||||
}
|
||||
return b.setPrefsLocked(prefs), true
|
||||
@@ -5844,6 +5847,10 @@ func (b *LocalBackend) editPrefsLocked(actor ipnauth.Actor, mp *ipn.MaskedPrefs)
|
||||
syncs.RequiresMutex(&b.mu)
|
||||
p0 := b.pm.CurrentPrefs()
|
||||
|
||||
// The access check below can recompute the exit node suggestion. The
|
||||
// returns that send no prefs still announce a changed suggestion.
|
||||
defer b.sendSuggestedExitNodeLocked()
|
||||
|
||||
// Check if the changes in mp are allowed.
|
||||
if err := b.checkEditPrefsAccessLocked(actor, p0, mp); err != nil {
|
||||
b.logf("EditPrefs(%v): %v", mp.Pretty(), err)
|
||||
|
||||
@@ -1729,6 +1729,81 @@ func TestSuggestExitNodeNotifies(t *testing.T) {
|
||||
nw.check()
|
||||
}
|
||||
|
||||
// TestSuggestedExitNodePendingFlushed checks that every entry point that can
|
||||
// recompute the exit node suggestion announces a pending change before it
|
||||
// returns, including the paths that send no prefs of their own.
|
||||
func TestSuggestedExitNodePendingFlushed(t *testing.T) {
|
||||
self := makePeer(1, withName("self"), withDERP(1), withAddresses(netip.MustParsePrefix("100.64.1.1/32")))
|
||||
tests := []struct {
|
||||
name string
|
||||
run func(t *testing.T, b *LocalBackend)
|
||||
}{
|
||||
{"SetControlClientStatus without netmap", func(t *testing.T, b *LocalBackend) {
|
||||
b.SetControlClientStatus(b.cc, controlclient.Status{})
|
||||
}},
|
||||
{"UpdateNetmapDelta without mutations", func(t *testing.T, b *LocalBackend) {
|
||||
if !b.UpdateNetmapDelta(nil) {
|
||||
t.Fatal("UpdateNetmapDelta returned false")
|
||||
}
|
||||
}},
|
||||
{"EditPrefs no-op", func(t *testing.T, b *LocalBackend) {
|
||||
if _, err := b.EditPrefs(&ipn.MaskedPrefs{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}},
|
||||
{"reconcilePrefs no-op", func(t *testing.T, b *LocalBackend) {
|
||||
if _, changed := b.reconcilePrefs(); changed {
|
||||
t.Fatal("reconcilePrefs reported a change")
|
||||
}
|
||||
}},
|
||||
{"RefreshExitNode no-op", func(t *testing.T, b *LocalBackend) {
|
||||
b.RefreshExitNode()
|
||||
}},
|
||||
{"SuggestExitNode", func(t *testing.T, b *LocalBackend) {
|
||||
b.SuggestExitNode()
|
||||
}},
|
||||
{"Start", func(t *testing.T, b *LocalBackend) {
|
||||
if err := b.Start(ipn.Options{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}},
|
||||
{"WatchNotifications initial suggestion", func(t *testing.T, b *LocalBackend) {
|
||||
second := newNotificationWatcher(t, b, ipnauth.Self)
|
||||
second.watch(ipn.NotifyInitialSuggestedExitNode, nil, func(testing.TB, ipnauth.Actor, *ipn.Notify) bool { return false })
|
||||
}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := newTestLocalBackend(t)
|
||||
b.SetControlClientStatus(b.cc, controlclient.Status{NetMap: buildNetmapWithPeers(self), LoggedIn: true})
|
||||
|
||||
nw := newNotificationWatcher(t, b, ipnauth.Self)
|
||||
nw.watch(0, []wantedNotification{{
|
||||
name: "suggested exit node",
|
||||
cond: func(_ testing.TB, _ ipnauth.Actor, n *ipn.Notify) bool {
|
||||
return n.SuggestedExitNode != nil
|
||||
},
|
||||
}})
|
||||
|
||||
// Pretend a suggestion changed without being announced yet.
|
||||
b.mu.Lock()
|
||||
b.lastSuggestedExitNode = "stale"
|
||||
b.suggestedExitNodePending = true
|
||||
b.mu.Unlock()
|
||||
|
||||
tt.run(t, b)
|
||||
nw.check()
|
||||
|
||||
b.mu.Lock()
|
||||
pending := b.suggestedExitNodePending
|
||||
b.mu.Unlock()
|
||||
if pending {
|
||||
t.Error("suggestedExitNodePending still set after the call")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalAndExternalInterfaces(t *testing.T) {
|
||||
type interfacePrefix struct {
|
||||
i netmon.Interface
|
||||
|
||||
Reference in new issue
Block a user