From 93f3e1b14b6f2b70b535b547a2c4fd308f98b209 Mon Sep 17 00:00:00 2001 From: Viktor Liu <17948409+lixmal@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:02:05 +0100 Subject: [PATCH] [client] Prevent local routes in status from being overridden by updates (#3166) --- client/internal/engine.go | 13 +++++++------ client/internal/peer/status.go | 8 +++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 7b6f269df..b50532b7d 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -763,12 +763,13 @@ func (e *Engine) updateConfig(conf *mgmProto.PeerConfig) error { } } - e.statusRecorder.UpdateLocalPeerState(peer.LocalPeerState{ - IP: e.config.WgAddr, - PubKey: e.config.WgPrivateKey.PublicKey().String(), - KernelInterface: device.WireGuardModuleIsLoaded(), - FQDN: conf.GetFqdn(), - }) + state := e.statusRecorder.GetLocalPeerState() + state.IP = e.config.WgAddr + state.PubKey = e.config.WgPrivateKey.PublicKey().String() + state.KernelInterface = device.WireGuardModuleIsLoaded() + state.FQDN = conf.GetFqdn() + + e.statusRecorder.UpdateLocalPeerState(state) return nil } diff --git a/client/internal/peer/status.go b/client/internal/peer/status.go index dc461257a..0df2a2e81 100644 --- a/client/internal/peer/status.go +++ b/client/internal/peer/status.go @@ -84,6 +84,12 @@ type LocalPeerState struct { Routes map[string]struct{} } +// Clone returns a copy of the LocalPeerState +func (l LocalPeerState) Clone() LocalPeerState { + l.Routes = maps.Clone(l.Routes) + return l +} + // SignalState contains the latest state of a signal connection type SignalState struct { URL string @@ -501,7 +507,7 @@ func (d *Status) GetPeerStateChangeNotifier(peer string) <-chan struct{} { func (d *Status) GetLocalPeerState() LocalPeerState { d.mux.Lock() defer d.mux.Unlock() - return d.localPeer + return d.localPeer.Clone() } // UpdateLocalPeerState updates local peer status