WIP: rebase for 2026-05-18 #7
+15
-20
@@ -1176,31 +1176,26 @@ func (e *userspaceEngine) Reconfig(cfg *wgcfg.Config, routerCfg *router.Config,
|
|||||||
// wireguard config as the new key was received over an existing wireguard
|
// wireguard config as the new key was received over an existing wireguard
|
||||||
// connection.
|
// connection.
|
||||||
if discoTSMP, okTSMP := e.tsmpLearnedDisco[p.PublicKey]; okTSMP {
|
if discoTSMP, okTSMP := e.tsmpLearnedDisco[p.PublicKey]; okTSMP {
|
||||||
|
// Key matches, remove entry from map.
|
||||||
|
delete(e.tsmpLearnedDisco, p.PublicKey)
|
||||||
if discoTSMP == p.DiscoKey {
|
if discoTSMP == p.DiscoKey {
|
||||||
// Key matches, remove entry from map.
|
|
||||||
e.logf("wgengine: Skipping reconfig (TSMP key): %s changed from %q to %q",
|
e.logf("wgengine: Skipping reconfig (TSMP key): %s changed from %q to %q",
|
||||||
pub.ShortString(), old, p.DiscoKey)
|
pub.ShortString(), old, p.DiscoKey)
|
||||||
delete(e.tsmpLearnedDisco, p.PublicKey)
|
// Skip session clear.
|
||||||
} else {
|
continue
|
||||||
// The new disco key does not match what we received via
|
|
||||||
// TSMP for this peer. This is unexpected, so log it.
|
|
||||||
// If it does happen, overwrite the previously-saved
|
|
||||||
// disco key with the new one for now: We expect another
|
|
||||||
// update must be pending in that case, so keep the map
|
|
||||||
// entry.
|
|
||||||
// The reason why this should never happen is that only a single
|
|
||||||
// request is coming through the netmap pipeline at a time, and there
|
|
||||||
// should realistically ever only be a single entry in the map. This
|
|
||||||
// is really a belt and suspenders solution to find usage that is
|
|
||||||
// inconsistent with our expectations.
|
|
||||||
e.logf("wgengine: [unexpected] Reconfig: using TSMP key for %s (control stale): tsmp=%q control=%q old=%q",
|
|
||||||
pub.ShortString(), discoTSMP, p.DiscoKey, old)
|
|
||||||
metricTSMPLearnedKeyMismatch.Add(1)
|
|
||||||
p.DiscoKey = discoTSMP
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip session clear no matter what.
|
// The new disco key does not match what we received via
|
||||||
continue
|
// TSMP for this peer. This is unexpected, though possible
|
||||||
|
// if processing a change in a large netmap ends up taking
|
||||||
|
// longer than the 2 second timeout in
|
||||||
|
// [controlClient.mapRoutineState.UpdateNetmapDelta], or if
|
||||||
|
// the context is cancelled mid update. Log the event, and reset
|
||||||
|
// the connection as it is possibly a stale entry in the map
|
||||||
|
// instead of a TSMP disco key update that led us here.
|
||||||
|
e.logf("wgengine: [unexpected] Reconfig: using TSMP key for %s (control stale): tsmp=%q control=%q old=%q",
|
||||||
|
pub.ShortString(), discoTSMP, p.DiscoKey, old)
|
||||||
|
metricTSMPLearnedKeyMismatch.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
discoChanged[pub] = true
|
discoChanged[pub] = true
|
||||||
|
|||||||
@@ -264,8 +264,9 @@ func TestUserspaceEngineTSMPLearnedMismatch(t *testing.T) {
|
|||||||
wrongKey bool
|
wrongKey bool
|
||||||
}{
|
}{
|
||||||
{tsmp: false, inMap: false, wrongKey: false},
|
{tsmp: false, inMap: false, wrongKey: false},
|
||||||
{tsmp: true, inMap: false, wrongKey: true},
|
{tsmp: true, inMap: false, wrongKey: false},
|
||||||
{tsmp: false, inMap: false, wrongKey: false},
|
{tsmp: true, inMap: true, wrongKey: true},
|
||||||
|
{tsmp: false, inMap: true, wrongKey: false},
|
||||||
}
|
}
|
||||||
|
|
||||||
nkHex := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
nkHex := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||||
|
|||||||
Reference in New Issue
Block a user