wgengine/magicsock: check all 3 fast paths independently.

The previous code would skip the DERP short-circuit if roamAddr
was set, which is not what we wanted. More generally, hitting
any of the fast path conditions is a direct return, so we can
just have 3 standalone branches rather than 'else if' stuff.

Signed-Off-By: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2020-03-06 10:36:33 -08:00 committed by Dave Anderson
parent 05a52746a4
commit ef31dd7bb5
1 changed files with 14 additions and 7 deletions

View File

@ -1124,16 +1124,23 @@ func (a *AddrSet) SrcToString() string { return "" }
func (a *AddrSet) ClearSrc() {} func (a *AddrSet) ClearSrc() {}
func (a *AddrSet) UpdateDst(new *net.UDPAddr) error { func (a *AddrSet) UpdateDst(new *net.UDPAddr) error {
if new.IP.Equal(derpMagicIP) {
// Never consider DERP addresses as a viable candidate for
// either curAddr or roamAddr. It's only ever a last resort
// choice, never a preferred choice.
// This is a hot path for established connections.
return nil
}
a.mu.Lock() a.mu.Lock()
defer a.mu.Unlock() defer a.mu.Unlock()
if a.roamAddr != nil { if a.roamAddr != nil && equalUDPAddr(new, a.roamAddr) {
if equalUDPAddr(a.roamAddr, new) { // Packet from the current roaming address, no logging.
// Packet from the current roaming address, no logging. // This is a hot path for established connections.
// This is a hot path for established connections. return nil
return nil }
} if a.curAddr >= 0 && equalUDPAddr(new, &a.addrs[a.curAddr]) {
} else if a.curAddr >= 0 && equalUDPAddr(new, &a.addrs[a.curAddr]) {
// Packet from current-priority address, no logging. // Packet from current-priority address, no logging.
// This is a hot path for established connections. // This is a hot path for established connections.
return nil return nil