tailscale/net/tstun
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>
2021-04-26 17:16:51 -07:00
..
fake.go net/tstun: rename NewFakeTUN to NewFake. 2021-03-26 22:46:47 -07:00
ifstatus_noop.go net/tstun: rename from net/tun. 2021-03-26 22:31:54 -07:00
ifstatus_windows.go net/tstun: rename from net/tun. 2021-03-26 22:31:54 -07:00
tun.go net/tstun: return the real interface name at device creation. 2021-04-05 22:53:10 -07:00
tun_notwindows.go net/tstun: return the real interface name at device creation. 2021-04-05 22:53:10 -07:00
tun_windows.go net/tstun: return the real interface name at device creation. 2021-04-05 22:53:10 -07:00
wrap.go net/tstun: split TUN events channel into up/down and MTU 2021-04-26 17:16:51 -07:00
wrap_test.go net/tstun: accept peerapi connections through the filter 2021-04-07 12:29:20 -07:00