From 1ad78ce6981875dc5047675f9d11f219c3c5f40b Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 19 Mar 2020 17:53:42 +1100 Subject: [PATCH] magicsock: reconnect to home DERP on key change Typically the home DERP server is found and set on startup before magicsock's SetPrivateKey can be called, so no DERP connection is established. Make sure one is by kicking the home DERP tires in SetPrivateKey. Signed-off-by: David Crawshaw --- wgengine/magicsock/magicsock.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 1c8e6eee3..e57b73376 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1024,13 +1024,13 @@ func (c *Conn) SetPrivateKey(privateKey wgcfg.PrivateKey) error { return nil } c.privateKey = newKey - if oldKey.IsZero() { - // Initial configuration on start. - return nil - } - // Key changed. Close any DERP connections. + // Key changed. Close existing DERP connections and reconnect to home. + myDerp := c.myDerp + c.myDerp = 0 + c.logf("magicsock private key set, rebooting connection to home DERP %d", myDerp) c.closeAllDerpLocked() + go c.setNearestDERP(myDerp) return nil }