wgengine/magicsock: don't unconditionally close DERP connections on rebind

Only if the source address isn't on the currently active interface or
a ping of the DERP server fails.

Updates #3619

Change-Id: I6bf06503cff4d781f518b437c8744ac29577acc8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-12-28 18:01:50 -08:00
committed by Brad Fitzpatrick
parent 04c2c5bd80
commit 2c94e3c4ad
3 changed files with 86 additions and 9 deletions

View File

@@ -176,6 +176,16 @@ func PrefixesContainsFunc(ipp []netaddr.IPPrefix, f func(netaddr.IPPrefix) bool)
return false
}
// PrefixesContainsIP reports whether any prefix in ipp contains ip.
func PrefixesContainsIP(ipp []netaddr.IPPrefix, ip netaddr.IP) bool {
for _, r := range ipp {
if r.Contains(ip) {
return true
}
}
return false
}
// IPsContainsFunc reports whether f is true for any IP in ips.
func IPsContainsFunc(ips []netaddr.IP, f func(netaddr.IP) bool) bool {
for _, v := range ips {