tailscale/wgengine
David Anderson 05a52746a4 wgengine/magicsock: fix destination selection logic to work with DERP.
The effect is subtle: when we're not spraying packets, and have not yet
figured out a curAddr, and we're not spraying, we end up sending to
whatever the first IP is in the iteration order. In English, that
means "when we have no idea where to send packets, and we've given
up on sending to everyone, just send to the first addr we see in
the list."

This is, in general, what we want, because the addrs are in sorted
preference order, low to high, and DERP is the least preferred
destination. So, when we have no idea where to send, send to DERP,
right?

... Except for very historical reasons, appendDests iterated through
addresses in _reverse_ order, most preferred to least preferred.
crawshaw@ believes this was part of the earliest handshaking
algorithm magicsock had, where it slowly iterated through possible
destinations and poked handshakes to them one at a time.

Anyway, because of this historical reverse iteration, in the case
described above of "we have no idea where to send", the code would
end up sending to the _most_ preferred candidate address, rather
than the _least_ preferred. So when in doubt, we'd end up firing
packets into the blackhole of some LAN address that doesn't work,
and connectivity would not work.

This case only comes up if all your non-DERP connectivity options
have failed, so we more or less failed to detect it because we
didn't have a pathological test box deployed. Worse, codependent
bug 2839854994 made DERP accidentally
work sometimes anyway by incorrectly exploiting roamAddr behavior,
albeit at the cost of making DERP traffic symmetric. In fixing
DERP to once again be asymmetric, we effectively removed the
bandaid that was concealing this bug.

Signed-Off-By: David Anderson <danderson@tailscale.com>
2020-03-06 11:10:13 -08:00
..
filter controlclinet: clone filter.MatchAllowAll 2020-02-28 22:33:06 -05:00
magicsock wgengine/magicsock: fix destination selection logic to work with DERP. 2020-03-06 11:10:13 -08:00
monitor wgengine/monitor: use RTMGRP_* consts from x/sys/unix 2020-02-17 14:15:08 -08:00
packet wgengine/packet: fix minor lint errors. 2020-02-11 00:01:14 -08:00
winnet Move Linux client & common packages into a public repo. 2020-02-09 09:32:57 -08:00
faketun.go wgengine: properly clean up freebsd routes and interfaces on close 2020-02-25 16:40:10 -05:00
ifconfig_windows.go wgengine: fix build on linux/freebsd/openbsd/windows 2020-02-19 11:58:59 -05:00
router_darwin.go wgengine: move link monitor to be owned by the engine, not the router 2020-02-17 09:53:17 -08:00
router_darwin_support.go wgengine: make SetRoutesFunc less appealing to use. 2020-02-10 21:40:00 -08:00
router_default.go wgengine: simplify, change some signatures 2020-02-17 08:04:31 -08:00
router_fake.go wgengine: move link monitor to be owned by the engine, not the router 2020-02-17 09:53:17 -08:00
router_freebsd.go wgengine: properly clean up freebsd routes and interfaces on close 2020-02-25 16:40:10 -05:00
router_linux.go wgengine: don't create duplicate iptables rules on Linux, clean up 2020-03-03 13:46:53 -08:00
router_openbsd.go wgengine: add OpenBSD router DNS update handling 2020-02-20 08:03:07 -08:00
router_windows.go wgengine: move link monitor to be owned by the engine, not the router 2020-02-17 09:53:17 -08:00
rusage.go Move "logger" package to under types, now that we have it. 2020-02-14 20:23:05 -08:00
rusage_nowindows.go wgengine: flesh out some docs 2020-02-12 13:37:45 -08:00
rusage_windows.go Move Linux client & common packages into a public repo. 2020-02-09 09:32:57 -08:00
userspace.go ipn, wgengine/magicsock: add ipn.Prefs.DisableDERP bool 2020-03-04 12:53:37 -08:00
watchdog.go ipn, wgengine/magicsock: add ipn.Prefs.DisableDERP bool 2020-03-04 12:53:37 -08:00
watchdog_test.go wgengine: simplify, change some signatures 2020-02-17 08:04:31 -08:00
wgengine.go ipn, wgengine/magicsock: add ipn.Prefs.DisableDERP bool 2020-03-04 12:53:37 -08:00