Skip to content

Commit

Permalink
Prevent local routes in status from being overridden by updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Jan 9, 2025
1 parent 409003b commit 1375b0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 7 additions & 6 deletions client/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 7 additions & 1 deletion client/internal/peer/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1375b0e

Please sign in to comment.