mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-07 08:07:42 +00:00
wgengine/magicsock: reconnect to DERP home after network comes back up
Updates #1310
This commit is contained in:
parent
d2c1ae7ed4
commit
cc2ec141fe
@ -961,6 +961,13 @@ func (c *Conn) setNearestDERP(derpNum int) (wantDERP bool) {
|
||||
return true
|
||||
}
|
||||
|
||||
// startDerpHomeConnectLocked starts connecting to our DERP home, if any.
|
||||
//
|
||||
// c.mu must be held.
|
||||
func (c *Conn) startDerpHomeConnectLocked() {
|
||||
c.goDerpConnect(c.myDerp)
|
||||
}
|
||||
|
||||
// goDerpConnect starts a goroutine to start connecting to the given
|
||||
// DERP node.
|
||||
//
|
||||
@ -2123,7 +2130,9 @@ func (c *Conn) SetNetworkUp(up bool) {
|
||||
c.logf("magicsock: SetNetworkUp(%v)", up)
|
||||
c.networkUp.Set(up)
|
||||
|
||||
if !up {
|
||||
if up {
|
||||
c.startDerpHomeConnectLocked()
|
||||
} else {
|
||||
c.closeAllDerpLocked("network-down")
|
||||
}
|
||||
}
|
||||
@ -2165,7 +2174,7 @@ func (c *Conn) SetPrivateKey(privateKey wgkey.Private) error {
|
||||
// Key changed. Close existing DERP connections and reconnect to home.
|
||||
if c.myDerp != 0 && !newKey.IsZero() {
|
||||
c.logf("magicsock: private key changed, reconnecting to home derp-%d", c.myDerp)
|
||||
c.goDerpConnect(c.myDerp)
|
||||
c.startDerpHomeConnectLocked()
|
||||
}
|
||||
|
||||
if newKey.IsZero() {
|
||||
@ -2628,12 +2637,11 @@ func (c *Conn) Rebind() {
|
||||
|
||||
c.mu.Lock()
|
||||
c.closeAllDerpLocked("rebind")
|
||||
haveKey := !c.privateKey.IsZero()
|
||||
if !c.privateKey.IsZero() {
|
||||
c.startDerpHomeConnectLocked()
|
||||
}
|
||||
c.mu.Unlock()
|
||||
|
||||
if haveKey {
|
||||
c.goDerpConnect(c.myDerp)
|
||||
}
|
||||
c.resetEndpointStates()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user