ipn/ipnlocal,wgengine: move disco-key change detection to nodeBackend
Engine.Reconfig previously diffed cfg.Peers disco keys against the previous config to find restarted peers and flush their WireGuard sessions, with a TSMP-learned-key map to suppress resets for key changes that arrived over a working session. That was the last per-peer state computed from wgcfg.Config.Peers inside the engine, and it only ran on full reconfigs, so incremental netmap deltas never got session resets at all. Move the detection into nodeBackend, which sees every peer change: full netmaps in SetNetMap and incremental upserts in UpdateNetmapDelta both now report which peers changed disco keys, with the same TSMP suppression and mismatch accounting as before. LocalBackend acts on the result via a new Engine.ResetDevicePeer method, which just removes the peer from the WireGuard device and lets the peer lookup func lazily re-create it with fresh state. LocalBackend.PatchDiscoKey now records TSMP-learned keys in nodeBackend instead of forwarding to the engine, so the engine's PatchDiscoKey method and tsmpLearnedDisco map are gone. The controlclient patchDiscoKeyer interface becomes the exported DiscoKeyUpdater so LocalBackend can compile-time assert that it implements it, alongside its NetmapDeltaUpdater friends, replacing the test that asserted the same of the engine. This is one of the last steps toward removing Peers from wgcfg.Config. Updates #12542 Change-Id: I6b42e460f42924816beae89ca43731cb91b66054 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
911c5e58ed
commit
aff605d163
@@ -575,13 +575,13 @@ func (mrs mapRoutineState) UpdateUserProfiles(profiles map[tailcfg.UserID]tailcf
|
||||
}
|
||||
}
|
||||
|
||||
var _ patchDiscoKeyer = mapRoutineState{}
|
||||
var _ DiscoKeyUpdater = mapRoutineState{}
|
||||
|
||||
func (mrs mapRoutineState) PatchDiscoKey(pub key.NodePublic, disco key.DiscoPublic) {
|
||||
c := mrs.c
|
||||
c.mu.Lock()
|
||||
goodState := c.loggedIn && c.inMapPoll
|
||||
dun, ok := c.observer.(patchDiscoKeyer)
|
||||
dun, ok := c.observer.(DiscoKeyUpdater)
|
||||
mapCtx := c.mapCtx
|
||||
c.mu.Unlock()
|
||||
|
||||
|
||||
@@ -286,10 +286,10 @@ type UserProfileUpdater interface {
|
||||
UpdateUserProfiles(profiles map[tailcfg.UserID]tailcfg.UserProfileView) bool
|
||||
}
|
||||
|
||||
// patchDiscoKeyer is an optional interface that can be implemented by an [Observer] to be
|
||||
// DiscoKeyUpdater is an optional interface that can be implemented by an [Observer] to be
|
||||
// notified about node disco keys received out-of-band from control, via
|
||||
// existing connection state.
|
||||
type patchDiscoKeyer interface {
|
||||
type DiscoKeyUpdater interface {
|
||||
// PatchDiscoKey reports to the receiver that the specified disco key
|
||||
// for node was obtained out-of-band from control.
|
||||
PatchDiscoKey(key.NodePublic, key.DiscoPublic)
|
||||
|
||||
@@ -362,7 +362,7 @@ func (ms *mapSession) handleNonKeepAliveMapResponse(ctx context.Context, resp *t
|
||||
}
|
||||
|
||||
func (ms *mapSession) tryMarkDiscoAsLearnedFromTSMP(res *tailcfg.MapResponse) {
|
||||
dun, ok := ms.netmapUpdater.(patchDiscoKeyer)
|
||||
dun, ok := ms.netmapUpdater.(DiscoKeyUpdater)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -34,9 +34,7 @@ import (
|
||||
"tailscale.com/util/eventbus/eventbustest"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/must"
|
||||
"tailscale.com/util/usermetric"
|
||||
"tailscale.com/util/zstdframe"
|
||||
"tailscale.com/wgengine"
|
||||
)
|
||||
|
||||
func eps(s ...string) []netip.AddrPort {
|
||||
@@ -1949,20 +1947,6 @@ func TestLearnZstdOfKeepAlive(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathDiscokeyerImplementations(t *testing.T) {
|
||||
bus := eventbustest.NewBus(t)
|
||||
ht := health.NewTracker(bus)
|
||||
reg := new(usermetric.Registry)
|
||||
e, err := wgengine.NewFakeUserspaceEngine(t.Logf, 0, ht, reg, bus)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(e.Close)
|
||||
if _, ok := e.(patchDiscoKeyer); !ok {
|
||||
t.Error("wgengine.userspaceEngine must implement patchDiscoKeyer")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPeerIDAndKeyByTailscaleIP(t *testing.T) {
|
||||
peerKey1 := key.NewNode().Public()
|
||||
peerKey2 := key.NewNode().Public()
|
||||
|
||||
Reference in New Issue
Block a user