You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/net
Josh Bleecher Snyder 99705aa6b7 net/tstun: split TUN events channel into up/down and MTU
We had a long-standing bug in which our TUN events channel
was being received from simultaneously in two places.

The first is wireguard-go.

At wgengine/userspace.go:366, we pass e.tundev to wireguard-go,
which starts a goroutine (RoutineTUNEventReader)
that receives from that channel and uses events to adjust the MTU
and bring the device up/down.

At wgengine/userspace.go:374, we launch a goroutine that
receives from e.tundev, logs MTU changes, and triggers
state updates when up/down changes occur.

Events were getting delivered haphazardly between the two of them.

We don't really want wireguard-go to receive the up/down events;
we control the state of the device explicitly by calling device.Up.
And the userspace.go loop MTU logging duplicates logging that
wireguard-go does when it received MTU updates.

So this change splits the single TUN events channel into up/down
and other (aka MTU), and sends them to the parties that ought
to receive them.

I'm actually a bit surprised that this hasn't caused more visible trouble.
If a down event went to wireguard-go but the subsequent up event
went to userspace.go, we could end up with the wireguard-go device disappearing.

I believe that this may also (somewhat accidentally) be a fix for #1790.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
3 years ago
..
dns net/dns: work around WSL DNS implementation flaws. 3 years ago
dnscache control/controlclient, net/{dnscache,dnsfallback}: add DNS fallback mechanism 3 years ago
dnsfallback net/dnsfallback: fix infinite loop and limit number of candidates 3 years ago
flowtrack net/packet, wgengine/filter: support SCTP 3 years ago
interfaces net/interfaces: work around race fetching routing table 3 years ago
netcheck net/netcheck: add a few more STUN retries for prior DERP home 3 years ago
netns net/{interfaces,netns}: add some new tests, missed from prior commit 3 years ago
netstat net/netstat: remove a bit more unsafe 4 years ago
nettest net/nettest: make nettest.NewConn pass x/net/nettest.TestConn. 3 years ago
packet net/{packet,tstun}: send peerapi port in TSMP pongs 3 years ago
portmapper net/portmapper: silently handle PCP NOT_AUTHORIZED responses. 3 years ago
socks5 cmd/tailscaled, wgengine: remove --fake, replace with netstack 3 years ago
stun stun fuzzer: Small fix 3 years ago
tlsdial net/tlsdial, derp/derphttp: finish DERPNode.CertName validation 4 years ago
tsaddr net/tsaddr: expand ephemeral nodes range to /64 3 years ago
tshttpproxy net/tshttpproxy: call winhttp calls from a fixed OS thread 3 years ago
tstun net/tstun: split TUN events channel into up/down and MTU 3 years ago