tailscale/wgengine
Josh Bleecher Snyder 3c543c103a wgengine/magicsock: unify initial bind and rebind
We had two separate code paths for the initial UDP listener bind
and any subsequent rebinds.

IPv6 got left out of the rebind code.
Rather than duplicate it there, unify the two code paths.
Then improve the resulting code:

* Rebind had nested listen attempts to try the user-specified port first,
  and then fall back to :0 if that failed. Convert that into a loop.
* Initial bind tried only the user-specified port.
  Rebind tried the user-specified port and 0.
  But there are actually three ports of interest:
  The one the user specified, the most recent port in use, and 0.
  We now try all three in order, as appropriate.
* In the extremely rare case in which binding to port 0 fails,
  use a dummy net.PacketConn whose reads block until close.
  This will keep the wireguard-go receive func goroutine alive.

As a pleasant side-effect of this, if we decide that
we need to resuscitate #1796, it will now be much easier.

Fixes #1799

Co-authored-by: David Anderson <danderson@tailscale.com>
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-04-28 10:39:28 -07:00
..
bench wgengine/bench: improved rate selection. 2021-04-26 03:51:13 -04:00
filter net/packet, wgengine/{filter,tstun}: add TSMP ping 2021-03-24 09:50:01 -07:00
magicsock wgengine/magicsock: unify initial bind and rebind 2021-04-28 10:39:28 -07:00
monitor wgengine/monitor: reduce Linux log spam on down 2021-04-12 10:38:51 -07:00
netstack wgengine/netstack: log error when acceptUDP fails 2021-04-21 12:25:01 -07:00
router wgengine/router{win}: ignore broadcast routes added by Windows when removing routes. 2021-04-24 14:13:35 -07:00
wgcfg wgengine/wgcfg/nmcfg: consolidate exit node log lines 2021-04-21 11:29:30 -07:00
wglog wgengine/wglog: allow wireguard-go receive routines to log 2021-04-21 12:29:28 -07:00
winnet wgengine/winnet: don't build on non-windows 2021-02-09 21:09:24 -08:00
pendopen.go wgengine: quiet connection failure diagnostics for exit nodes 2021-04-22 08:29:20 -07:00
userspace_ext_test.go cmd/tailscaled, wgengine{,/netstack}: add netstack hybrid mode, add to Windows 2021-04-06 21:37:28 -07:00
userspace_test.go cmd/tailscaled, wgengine{,/netstack}: add netstack hybrid mode, add to Windows 2021-04-06 21:37:28 -07:00
userspace.go wgengine: periodically poll engine status for logging side effect 2021-04-27 13:55:47 -07:00
watchdog_test.go wgengine: extend TestWatchdog timeout on macOS 2021-03-27 09:27:11 -07:00
watchdog.go wgengine: take in dns.Config, split out to resolver.Config and dns.OSConfig. 2021-04-02 00:59:44 -07:00
wgengine.go tailcfg: add Endpoint, EndpointType, MapRequest.EndpointType 2021-04-13 10:12:14 -07:00