mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 10:41:19 -08:00
ipn/ipnlocal: fix cache update for peers deleted by netmap deltas (#20851)
After a netmap delta is applied, we scan the mutations for affected peers and
update the cache (if enabled) for those peers. For removals in particular, we
were relying on the node backend to resolve node IDs (provided by the delta
mutation) to stable IDs.
Prior to 65fd320a this happened to work because the node backend would hold on
to all the peers mentioned by the previous full netmap, even after applying
deltas. But that was essentially accidental, and once we fixed it not to do
that, these lookups no longer worked. We need the stable ID, since that is how
the cache is keyed, and now that they're no longer pinned, we were not properly
evicting removed peers from the cache.
To fix this, capture removed peer stable IDs while applying mutations to the
node backend, instead of trying to look them up afterward.
Updates #20796
Change-Id: I14ded78eaf9657645f0869a52460fd3cd86edba6
Signed-off-by: M. J. Fromberger <[email protected]>
This commit is contained in:
1 parent
90ed0bcf4b
commit
f3552c29c0
3 files changed
+28
-7
No files matched your search
@@ -2566,13 +2566,7 @@ func (b *LocalBackend) UpdateNetmapDelta(muts []netmap.NodeMutation) (handled bo
|
||||
peersToUpdate = append(peersToUpdate, n)
|
||||
}
|
||||
}
|
||||
var peersToRemove []tailcfg.StableNodeID
|
||||
for id := range removeIDs {
|
||||
if n, ok := cn.NodeByID(id); ok {
|
||||
peersToRemove = append(peersToRemove, n.StableID())
|
||||
}
|
||||
}
|
||||
if err := b.writePeerDeltaToDiskLocked(peersToUpdate, peersToRemove); err != nil {
|
||||
if err := b.writePeerDeltaToDiskLocked(peersToUpdate, deltaRes.RemovedPeers); err != nil {
|
||||
b.logf("update netmap cache for peer deltas: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -621,6 +621,15 @@ func TestUpdateNetMapCache(t *testing.T) {
|
||||
netip.MustParsePrefix("100.2.3.5/32"),
|
||||
},
|
||||
}).View(),
|
||||
(&tailcfg.Node{
|
||||
ID: 602,
|
||||
StableID: "n602FAKE",
|
||||
User: tailcfg.UserID(1),
|
||||
Key: makeNodeKeyFromID(602),
|
||||
Addresses: []netip.Prefix{
|
||||
netip.MustParsePrefix("100.3.4.6/32"),
|
||||
},
|
||||
}).View(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -688,6 +697,19 @@ func TestUpdateNetMapCache(t *testing.T) {
|
||||
t.Logf("Cache directory has %d entries (OK)", len(des))
|
||||
}
|
||||
|
||||
// Apply a delta update that removes a node, and verify that this gets
|
||||
// reflected in the cache.
|
||||
clb.UpdateNetmapDelta([]netmap.NodeMutation{
|
||||
netmap.MakeNodeMutationRemove(602),
|
||||
})
|
||||
if got, err := netmapcache.NewCache(netmapcache.FileStore(cacheDir)).Load(t.Context()); err != nil {
|
||||
t.Errorf("Load cached netmap: %v", err)
|
||||
} else if i := slices.IndexFunc(got.Peers, func(n tailcfg.NodeView) bool {
|
||||
return n.ID() == 602
|
||||
}); i >= 0 {
|
||||
t.Errorf("Cache did not get updated, %d (%v) still present", got.Peers[i].ID(), got.Peers[i].StableID())
|
||||
}
|
||||
|
||||
// Now disable the node attribute again, send another update, and verify
|
||||
// that the cache got cleaned up.
|
||||
testMap.AllCaps = nil
|
||||
|
||||
@@ -1078,6 +1078,10 @@ type netmapDeltaResult struct {
|
||||
// way that requires a WireGuard session reset (see
|
||||
// [nodeBackend.discoChangedLocked]).
|
||||
DiscoChanged set.Set[key.NodePublic]
|
||||
|
||||
// RemovedPeers is a slice of peer stable node IDs (if any) that were
|
||||
// removed by applying the delta.
|
||||
RemovedPeers []tailcfg.StableNodeID
|
||||
}
|
||||
|
||||
// UpdateNetmapDelta applies the given netmap mutations to the live
|
||||
@@ -1162,6 +1166,7 @@ func (nb *nodeBackend) UpdateNetmapDelta(muts []netmap.NodeMutation) (res netmap
|
||||
nb.removeNodeNameLocked(old.Name())
|
||||
delete(nb.peers, nid)
|
||||
rt.RemovePeer(nid)
|
||||
res.RemovedPeers = append(res.RemovedPeers, old.StableID())
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user