wgengine/magicsock: reconnect to DERP when its definition changes

Change-Id: I7c560feb9e4a6e155a35ec764a68354f19f694e4
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2022-01-04 14:59:11 -08:00 committed by Brad Fitzpatrick
parent 506c727e30
commit a201b89e4a

View File

@ -2252,12 +2252,31 @@ func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap) {
return return
} }
old := c.derpMap
c.derpMap = dm c.derpMap = dm
if dm == nil { if dm == nil {
c.closeAllDerpLocked("derp-disabled") c.closeAllDerpLocked("derp-disabled")
return return
} }
// Reconnect any DERP region that changed definitions.
if old != nil {
changes := false
for rid, oldDef := range old.Regions {
if reflect.DeepEqual(oldDef, dm.Regions[rid]) {
continue
}
changes = true
if rid == c.myDerp {
c.myDerp = 0
}
c.closeDerpLocked(rid, "derp-region-redefined")
}
if changes {
c.logActiveDerpLocked()
}
}
go c.ReSTUN("derp-map-update") go c.ReSTUN("derp-map-update")
} }