]> git.ipfire.org Git - thirdparty/wireguard-go.git/log
thirdparty/wireguard-go.git
3 years agodevice: defer state machine transitions until configuration is complete
Jason A. Donenfeld [Thu, 11 Nov 2021 02:12:37 +0000 (03:12 +0100)] 
device: defer state machine transitions until configuration is complete

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agodevice: do not consume handshake messages if not running
Jason A. Donenfeld [Thu, 11 Nov 2021 02:11:29 +0000 (03:11 +0100)] 
device: do not consume handshake messages if not running

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agotun: move wintun to its own repo
Jason A. Donenfeld [Thu, 4 Nov 2021 11:53:44 +0000 (12:53 +0100)] 
tun: move wintun to its own repo

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agonamedpipe: rename from winpipe to keep in sync with CL299009
Jason A. Donenfeld [Sat, 30 Oct 2021 00:39:56 +0000 (02:39 +0200)] 
namedpipe: rename from winpipe to keep in sync with CL299009

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agodevice: timers: use pre-seeded per-thread unlocked fastrandn for jitter
Jason A. Donenfeld [Thu, 28 Oct 2021 11:47:50 +0000 (13:47 +0200)] 
device: timers: use pre-seeded per-thread unlocked fastrandn for jitter

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agodevice: timers: seed unsafe rng before use for jitter
Jason A. Donenfeld [Thu, 28 Oct 2021 11:34:21 +0000 (13:34 +0200)] 
device: timers: seed unsafe rng before use for jitter

Forgetting to seed the unsafe rng, the jitter before followed a fixed
pattern, which didn't help when a fleet of computers all boot at once.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowintun: align 64-bit argument on ARM32
Jason A. Donenfeld [Tue, 26 Oct 2021 12:51:44 +0000 (14:51 +0200)] 
wintun: align 64-bit argument on ARM32

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoREADME: raise minimum Go to 1.17
Jason A. Donenfeld [Mon, 25 Oct 2021 15:53:11 +0000 (17:53 +0200)] 
README: raise minimum Go to 1.17

Suggested-by: Adam Bliss <abliss@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agotun/netstack: update gvisor
Mikael Magnusson [Thu, 21 Oct 2021 22:04:20 +0000 (00:04 +0200)] 
tun/netstack: update gvisor

Update gvisor to v0.0.0-20211020211948-f76a604701b6, which requires some
changes to tun.go:

WriteRawPacket: Add function with not implemented error.

CreateNetTUN: Replace stack.AddAddress with stack.AddProtocolAddress, and
fix IPv6 address in error message.

Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoipc, rwcancel: compile on js/wasm
Brad Fitzpatrick [Wed, 20 Oct 2021 15:56:39 +0000 (08:56 -0700)] 
ipc, rwcancel: compile on js/wasm

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
3 years agowintun: allow retrieving DLL version
Jason A. Donenfeld [Wed, 20 Oct 2021 18:13:44 +0000 (12:13 -0600)] 
wintun: allow retrieving DLL version

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoversion: bump snapshot 0.0.20211016
Jason A. Donenfeld [Sun, 17 Oct 2021 05:27:13 +0000 (23:27 -0600)] 
version: bump snapshot

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowintun: remove memmod option for dll loading
Jason A. Donenfeld [Sun, 17 Oct 2021 04:49:38 +0000 (22:49 -0600)] 
wintun: remove memmod option for dll loading

Only wireguard-windows used this, and it's moving to wgnt exclusively.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoglobal: remove old-style build tags
Jason A. Donenfeld [Tue, 12 Oct 2021 18:02:10 +0000 (12:02 -0600)] 
global: remove old-style build tags

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoglobal: add newer-style build tags
Jason A. Donenfeld [Tue, 12 Oct 2021 17:46:53 +0000 (11:46 -0600)] 
global: add newer-style build tags

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agowintun: use new swdevice-based API for upcoming Wintun 0.14
Jason A. Donenfeld [Tue, 12 Oct 2021 06:26:46 +0000 (00:26 -0600)] 
wintun: use new swdevice-based API for upcoming Wintun 0.14

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoconn,wintun: use unsafe.Slice instead of unsafeSlice
Jason A. Donenfeld [Mon, 11 Oct 2021 20:57:53 +0000 (14:57 -0600)] 
conn,wintun: use unsafe.Slice instead of unsafeSlice

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agomemmod: import from wireguard-windows
Jason A. Donenfeld [Mon, 11 Oct 2021 20:53:36 +0000 (14:53 -0600)] 
memmod: import from wireguard-windows

We'll eventually be getting rid of it here, but keep it sync'd up for
now.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agorwcancel: use unix.Poll again but bump x/sys so it uses ppoll under the hood
Jason A. Donenfeld [Mon, 27 Sep 2021 20:18:38 +0000 (14:18 -0600)] 
rwcancel: use unix.Poll again but bump x/sys so it uses ppoll under the hood

This reverts commit fcc601dbf0f6b626ec1d47a880cbe64f9c8fe385 but then
bumps go.mod.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agorwcancel: use ppoll on Linux for Android
Jason A. Donenfeld [Sun, 26 Sep 2021 23:15:58 +0000 (17:15 -0600)] 
rwcancel: use ppoll on Linux for Android

This is a temporary measure while we wait for
https://go-review.googlesource.com/c/sys/+/352310 to land.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agotun: make operateonfd.go build tags more specific
Tobias Klauser [Thu, 23 Sep 2021 10:07:19 +0000 (12:07 +0200)] 
tun: make operateonfd.go build tags more specific

(*NativeTun).operateOnFd is only used on darwin and freebsd. Adjust the
build tags accordingly.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agotun: avoid leaking sock fd in CreateTUN error cases
Tobias Klauser [Thu, 23 Sep 2021 10:05:13 +0000 (12:05 +0200)] 
tun: avoid leaking sock fd in CreateTUN error cases

At these points, the socket file descriptor is not yet wrapped in an
*os.File, so it needs to be closed explicitly on error.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
3 years agoglobal: add new go 1.17 build comments
Jason A. Donenfeld [Sun, 5 Sep 2021 14:00:43 +0000 (16:00 +0200)] 
global: add new go 1.17 build comments

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomemmod: register exception handler tables
Jason A. Donenfeld [Thu, 5 Aug 2021 12:56:48 +0000 (14:56 +0200)] 
memmod: register exception handler tables

Otherwise recent WDK binaries fail on ARM64, where an exception handler
is used for trapping an illegal instruction when ARMv8.1 atomics are
being tested for functionality.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomemmod: fix protected delayed load the right way
Jason A. Donenfeld [Wed, 28 Jul 2021 23:27:40 +0000 (01:27 +0200)] 
memmod: fix protected delayed load the right way

The reason this was failing before is that dloadsup.h's
DloadObtainSection was doing a linear search of sections to find which
header corresponds with the IMAGE_DELAYLOAD_DESCRIPTOR section, and we
were stupidly overwriting the VirtualSize field, so the linear search
wound up matching the .text section, which then it found to not be
marked writable and failed with FAST_FAIL_DLOAD_PROTECTION_FAILURE.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomemmod: disable protected delayed load for now
Jason A. Donenfeld [Wed, 28 Jul 2021 23:01:46 +0000 (01:01 +0200)] 
memmod: disable protected delayed load for now

Probably a bad idea, but we don't currently support it, and those huge
windows.NewCallback trampolines make juicer targets anyway.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoipc: allow admins but require high integrity label
Jason A. Donenfeld [Wed, 23 Jun 2021 23:19:29 +0000 (01:19 +0200)] 
ipc: allow admins but require high integrity label

Might be more reasonable.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: zero out allowedip node pointers when removing
Jason A. Donenfeld [Fri, 4 Jun 2021 14:33:28 +0000 (16:33 +0200)] 
device: zero out allowedip node pointers when removing

This should make it a bit easier for the garbage collector.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: limit allowedip fuzzer a to 4 times through
Jason A. Donenfeld [Thu, 3 Jun 2021 16:22:50 +0000 (18:22 +0200)] 
device: limit allowedip fuzzer a to 4 times through

Trying this for every peer winds up being very slow and precludes it
from acceptable runtime in the CI, so reduce this to 4.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: simplify allowedips lookup signature
Jason A. Donenfeld [Thu, 3 Jun 2021 14:12:29 +0000 (16:12 +0200)] 
device: simplify allowedips lookup signature

The inliner should handle this for us.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: remove nodes by peer in O(1) instead of O(n)
Jason A. Donenfeld [Thu, 3 Jun 2021 13:40:09 +0000 (15:40 +0200)] 
device: remove nodes by peer in O(1) instead of O(n)

Now that we have parent pointers hooked up, we can simply go right to
the node and remove it in place, rather than having to recursively walk
the entire trie.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: remove recursion from insertion and connect parent pointers
Jason A. Donenfeld [Thu, 3 Jun 2021 12:50:28 +0000 (14:50 +0200)] 
device: remove recursion from insertion and connect parent pointers

This makes the insertion algorithm a bit more efficient, while also now
taking on the additional task of connecting up parent pointers. This
will be handy in the following commit.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: reduce size of trie struct
Jason A. Donenfeld [Thu, 3 Jun 2021 11:51:03 +0000 (13:51 +0200)] 
device: reduce size of trie struct

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agogo.mod: bump golang.org/x/sys again
Josh Bleecher Snyder [Sat, 3 Apr 2021 17:15:59 +0000 (10:15 -0700)] 
go.mod: bump golang.org/x/sys again

To pick up https://go-review.googlesource.com/c/sys/+/307129.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agodevice: allow reducing queue constants on iOS
Jason A. Donenfeld [Fri, 21 May 2021 22:57:42 +0000 (00:57 +0200)] 
device: allow reducing queue constants on iOS

Heavier network extensions might require the wireguard-go component to
use less ram, so let users of this reduce these as needed.

At some point we'll put this behind a configuration method of sorts, but
for now, just expose the consts as vars.

Requested-by: Josh Bleecher Snyder <josh@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: linux: account for interface removal from outside
Jason A. Donenfeld [Thu, 20 May 2021 16:26:01 +0000 (18:26 +0200)] 
tun: linux: account for interface removal from outside

On Linux we can run `ip link del wg0`, in which case the fd becomes
stale, and we should exit. Since this is an intentional action, don't
treat it as an error.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: linux: protect read fds
Jason A. Donenfeld [Thu, 20 May 2021 16:09:55 +0000 (18:09 +0200)] 
conn: linux: protect read fds

The -1 protection was removed and the wrong error was returned, causing
us to read from a bogus fd. As well, remove the useless closures that
aren't doing anything, since this is all synchronized anyway.

Fixes: 10533c3 ("all: make conn.Bind.Open return a slice of receive functions")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agorwcancel: use ordinary os.ErrClosed instead of custom error
Jason A. Donenfeld [Thu, 20 May 2021 15:56:36 +0000 (17:56 +0200)] 
rwcancel: use ordinary os.ErrClosed instead of custom error

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agorwcancel: use poll instead of select
Jason A. Donenfeld [Thu, 20 May 2021 15:42:34 +0000 (17:42 +0200)] 
rwcancel: use poll instead of select

Suggested-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: optimize Peer.String even more
Jason A. Donenfeld [Thu, 13 May 2021 23:07:55 +0000 (01:07 +0200)] 
device: optimize Peer.String even more

This reduces the allocation, branches, and amount of base64 encoding.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: optimize Peer.String
Josh Bleecher Snyder [Thu, 13 May 2021 22:30:18 +0000 (15:30 -0700)] 
device: optimize Peer.String

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
4 years agoconn: windows: set count=0 on retry
Jason A. Donenfeld [Tue, 11 May 2021 14:47:17 +0000 (16:47 +0200)] 
conn: windows: set count=0 on retry

When retrying, if count is not 0, we forget to dequeue another request,
and so the ring fills up and errors out.

Reported-by: Sascha Dierberg <dierberg@dresearch-fe.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomain: replace crlf on windows in fmt test
Jason A. Donenfeld [Mon, 10 May 2021 20:23:32 +0000 (22:23 +0200)] 
main: replace crlf on windows in fmt test

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomain: check that code is formatted in unit test
Jason A. Donenfeld [Fri, 7 May 2021 10:56:10 +0000 (12:56 +0200)] 
main: check that code is formatted in unit test

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: format
Jason A. Donenfeld [Fri, 7 May 2021 10:21:27 +0000 (12:21 +0200)] 
tun: format

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: add ID to repeated routines
Jason A. Donenfeld [Fri, 7 May 2021 10:21:21 +0000 (12:21 +0200)] 
device: add ID to repeated routines

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: remove unusual ... in messages
Jason A. Donenfeld [Fri, 7 May 2021 10:17:41 +0000 (12:17 +0200)] 
device: remove unusual ... in messages

We dont use ... in any other present progressive messages except these.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: avoid verbose log line during ordinary shutdown sequence
Jason A. Donenfeld [Fri, 7 May 2021 07:39:06 +0000 (09:39 +0200)] 
device: avoid verbose log line during ordinary shutdown sequence

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: windows: set event before waiting
Jason A. Donenfeld [Fri, 7 May 2021 07:26:24 +0000 (09:26 +0200)] 
tun: windows: set event before waiting

In 097af6e ("tun: windows: protect reads from closing") we made sure no
functions are running when End() is called, to avoid a UaF. But we still
need to kick that event somehow, so that Read() is allowed to exit, in
order to release the lock. So this commit calls SetEvent, while moving
the closing boolean to be atomic so it can be modified without locks,
and then moves to a WaitGroup for the RCU-like pattern.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: windows: rearrange struct to avoid alignment trap on 32bit
Jason A. Donenfeld [Fri, 7 May 2021 07:17:35 +0000 (09:17 +0200)] 
tun: windows: rearrange struct to avoid alignment trap on 32bit

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: windows: check alignment in unit test
Jason A. Donenfeld [Fri, 7 May 2021 07:10:41 +0000 (09:10 +0200)] 
tun: windows: check alignment in unit test

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: log all errors received by RoutineReceiveIncoming
Josh Bleecher Snyder [Tue, 27 Apr 2021 17:15:15 +0000 (10:15 -0700)] 
device: log all errors received by RoutineReceiveIncoming

When debugging, it's useful to know why a receive func exited.

We were already logging that, but only in the "death spiral" case.
Move the logging up, to capture it always.
Reduce the verbosity, since it is not an error case any more.
Put the receive func name in the log line.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agotun/netstack: update go mod and remove GSO argument
Jason A. Donenfeld [Thu, 6 May 2021 09:03:04 +0000 (11:03 +0200)] 
tun/netstack: update go mod and remove GSO argument

Reported-by: John Xiong <xiaoyang1258@yeah.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: windows: send MTU update when forced MTU changes
Jason A. Donenfeld [Wed, 5 May 2021 09:42:45 +0000 (11:42 +0200)] 
tun: windows: send MTU update when forced MTU changes

Otherwise the padding doesn't get updated.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: windows: protect reads from closing
Jason A. Donenfeld [Tue, 27 Apr 2021 02:22:45 +0000 (22:22 -0400)] 
tun: windows: protect reads from closing

The code previously used the old errors channel for checking, rather
than the simpler boolean, which caused issues on shutdown, since the
errors channel was meaningless. However, looking at this exposed a more
basic problem: Close() and all the other functions that check the closed
boolean can race. So protect with a basic RW lock, to ensure that
Close() waits for all pending operations to complete.

Reported-by: Joshua Sjoding <joshua.sjoding@scjalliance.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: windows: do not error out when receiving UDP jumbogram
Jason A. Donenfeld [Tue, 27 Apr 2021 02:07:03 +0000 (22:07 -0400)] 
conn: windows: do not error out when receiving UDP jumbogram

If we receive a large UDP packet, don't return an error to receive.go,
which then terminates the receive loop. Instead, simply retry.

Considering Winsock's general finickiness, we might consider other
places where an attacker on the wire can generate error conditions like
this.

Reported-by: Sascha Dierberg <sascha.dierberg@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump snapshot 0.0.20210424
Jason A. Donenfeld [Sat, 24 Apr 2021 17:07:27 +0000 (13:07 -0400)] 
version: bump snapshot

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: avoid OOB writes
Jason A. Donenfeld [Mon, 19 Apr 2021 21:10:23 +0000 (15:10 -0600)] 
tun: freebsd: avoid OOB writes

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: become controlling process when reopening tun FD
Jason A. Donenfeld [Mon, 19 Apr 2021 21:01:36 +0000 (15:01 -0600)] 
tun: freebsd: become controlling process when reopening tun FD

When we pass the TUN FD to the child, we have to call TUNSIFPID;
otherwise when we close the device, we get a splat in dmesg.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: restructure and cleanup
Jason A. Donenfeld [Mon, 19 Apr 2021 20:54:59 +0000 (14:54 -0600)] 
tun: freebsd: restructure and cleanup

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: remove horrific hack for getting tunnel name
Jason A. Donenfeld [Mon, 19 Apr 2021 02:26:32 +0000 (20:26 -0600)] 
tun: freebsd: remove horrific hack for getting tunnel name

As of FreeBSD 12.1, there's TUNGIFNAME.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: set IFF_MULTICAST for routing daemons
Jason A. Donenfeld [Mon, 19 Apr 2021 02:09:04 +0000 (20:09 -0600)] 
tun: freebsd: set IFF_MULTICAST for routing daemons

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomain: print kernel warning on OpenBSD and FreeBSD too
Jason A. Donenfeld [Fri, 16 Apr 2021 05:32:44 +0000 (23:32 -0600)] 
main: print kernel warning on OpenBSD and FreeBSD too

More kernels!

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: don't defer unlocking from loop
Jason A. Donenfeld [Mon, 12 Apr 2021 22:19:35 +0000 (16:19 -0600)] 
device: don't defer unlocking from loop

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: reconstruct v4 vs v6 receive function based on symtab
Jason A. Donenfeld [Fri, 9 Apr 2021 23:21:35 +0000 (17:21 -0600)] 
conn: reconstruct v4 vs v6 receive function based on symtab

This is kind of gross but it's better than the alternatives.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: allocate new buffer in receive death spiral
Kristupas Antanavičius [Mon, 12 Apr 2021 11:50:58 +0000 (14:50 +0300)] 
device: allocate new buffer in receive death spiral

Note: this bug is "hidden" by avoiding "death spiral" code path by
6228659 ("device: handle broader range of errors in RoutineReceiveIncoming").

If the code reached "death spiral" mechanism, there would be multiple
double frees happening. This results in a deadlock on iOS, because the
pools are fixed size and goroutine might stop until somebody makes
space in the pool.

This was almost 100% repro on the new ARM Macbooks:

- Build with 'ios' tag for Mac. This will enable bounded pools.
- Somehow call device.IpcSet at least couple of times (update config)
- device.BindUpdate() would be triggered
- RoutineReceiveIncoming would enter "death spiral".
- RoutineReceiveIncoming would stall on double free (pool is already
  full)
- The stuck routine would deadlock 'device.closeBindLocked()' function
  on line 'netc.stopping.Wait()'

Signed-off-by: Kristupas Antanavičius <kristupas.antanavicius@nordsec.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: windows: reset ring to starting position after free
Jason A. Donenfeld [Sat, 10 Apr 2021 00:08:48 +0000 (18:08 -0600)] 
conn: windows: reset ring to starting position after free

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: windows: compare head and tail properly
Jason A. Donenfeld [Fri, 9 Apr 2021 00:17:59 +0000 (18:17 -0600)] 
conn: windows: compare head and tail properly

By not comparing these with the modulo, the ring became nearly never
full, resulting in completion queue buffers filling up prematurely.

Reported-by: Joshua Sjoding <joshua.sjoding@scjalliance.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowinrio: test that IOCP-based RIO is supported
Jason A. Donenfeld [Tue, 6 Apr 2021 17:45:10 +0000 (11:45 -0600)] 
winrio: test that IOCP-based RIO is supported

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoall: make conn.Bind.Open return a slice of receive functions
Josh Bleecher Snyder [Wed, 31 Mar 2021 20:55:18 +0000 (13:55 -0700)] 
all: make conn.Bind.Open return a slice of receive functions

Instead of hard-coding exactly two sources from which
to receive packets (an IPv4 source and an IPv6 source),
allow the conn.Bind to specify a set of sources.

Beneficial consequences:

* If there's no IPv6 support on a system,
  conn.Bind.Open can choose not to return a receive function for it,
  which is simpler than tracking that state in the bind.
  This simplification removes existing data races from both
  conn.StdNetBind and bindtest.ChannelBind.
* If there are more than two sources on a system,
  the conn.Bind no longer needs to add a separate muxing layer.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agoconn: winrio: pass key parameter into struct
Jason A. Donenfeld [Fri, 2 Apr 2021 16:36:41 +0000 (10:36 -0600)] 
conn: winrio: pass key parameter into struct

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: handle broader range of errors in RoutineReceiveIncoming
Josh Bleecher Snyder [Tue, 30 Mar 2021 19:36:59 +0000 (12:36 -0700)] 
device: handle broader range of errors in RoutineReceiveIncoming

RoutineReceiveIncoming exits immediately on net.ErrClosed,
but not on other errors. However, for errors that are known
to be permanent, such as syscall.EAFNOSUPPORT,
we may as well exit immediately instead of retrying.

This considerably speeds up the package device tests right now,
because the Bind sometimes (incorrectly) returns syscall.EAFNOSUPPORT
instead of net.ErrClosed.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agoconn: document retry loop in StdNetBind.Open
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:27:21 +0000 (13:27 -0700)] 
conn: document retry loop in StdNetBind.Open

It's not obvious on a first read what the loop is doing.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agoconn: use local ipvN vars in StdNetBind.Open
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:21:06 +0000 (13:21 -0700)] 
conn: use local ipvN vars in StdNetBind.Open

This makes it clearer that they are fresh on each attempt,
and avoids the bookkeeping required to clearing them on failure.

Also, remove an unnecessary err != nil.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agoconn: unify code in StdNetBind.Send
Josh Bleecher Snyder [Mon, 29 Mar 2021 20:11:11 +0000 (13:11 -0700)] 
conn: unify code in StdNetBind.Send

The sending code is identical for ipv4 and ipv6;
select the conn, then use it.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agodevice: rename unsafeCloseBind to closeBindLocked
Josh Bleecher Snyder [Mon, 29 Mar 2021 19:36:09 +0000 (12:36 -0700)] 
device: rename unsafeCloseBind to closeBindLocked

And document a bit.
This name is more idiomatic.

Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
4 years agoversion: bump snapshot 0.0.20210323
Jason A. Donenfeld [Tue, 23 Mar 2021 19:07:19 +0000 (13:07 -0600)] 
version: bump snapshot

4 years agotun: freebsd: use broadcast mode instead of PPP mode
Jason A. Donenfeld [Tue, 23 Mar 2021 18:41:34 +0000 (12:41 -0600)] 
tun: freebsd: use broadcast mode instead of PPP mode

It makes the routing configuration simpler.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: signal to close device in separate routine
Jason A. Donenfeld [Thu, 11 Mar 2021 16:29:10 +0000 (09:29 -0700)] 
device: signal to close device in separate routine

Otherwise we wind up deadlocking.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: linux: do not spam events every second from hack listener
Jason A. Donenfeld [Thu, 11 Mar 2021 16:23:11 +0000 (09:23 -0700)] 
tun: linux: do not spam events every second from hack listener

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: freebsd: allow empty names
Kay Diam [Sun, 7 Mar 2021 16:21:31 +0000 (17:21 +0100)] 
tun: freebsd: allow empty names

This change allows omitting the tun interface name setting. When the
name is not set, the kernel automatically picks up the tun name and
index.

Signed-off-by: Kay Diam <kay.diam@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agowinpipe: move syscalls into x/sys
Jason A. Donenfeld [Wed, 3 Mar 2021 11:26:59 +0000 (12:26 +0100)] 
winpipe: move syscalls into x/sys

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomemmod: use resource functions from x/sys
Jason A. Donenfeld [Wed, 3 Mar 2021 14:05:19 +0000 (15:05 +0100)] 
memmod: use resource functions from x/sys

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomemmod: do not use IsBadReadPtr
Jason A. Donenfeld [Wed, 3 Mar 2021 13:38:26 +0000 (14:38 +0100)] 
memmod: do not use IsBadReadPtr

It should be enough to check for the trailing zero name.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: linux: unexport mutex
Jason A. Donenfeld [Sat, 6 Mar 2021 16:20:46 +0000 (09:20 -0700)] 
conn: linux: unexport mutex

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomod: bump x/sys
Jason A. Donenfeld [Fri, 5 Mar 2021 22:06:08 +0000 (15:06 -0700)] 
mod: bump x/sys

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agomod: rename COPYING to LICENSE
Jason A. Donenfeld [Sat, 6 Mar 2021 16:03:28 +0000 (09:03 -0700)] 
mod: rename COPYING to LICENSE

Otherwise the netstack module doesn't show up on the package site.

https://github.com/golang/go/issues/43817#issuecomment-764987580

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun/netstack: bump deps and api
Jason A. Donenfeld [Sat, 6 Mar 2021 15:21:18 +0000 (08:21 -0700)] 
tun/netstack: bump deps and api

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: get rid of peers.empty boolean in timersActive
Jason A. Donenfeld [Thu, 25 Feb 2021 11:28:53 +0000 (12:28 +0100)] 
device: get rid of peers.empty boolean in timersActive

There's no way for len(peers)==0 when a current peer has
isRunning==false.

This requires some struct reshuffling so that the uint64 pointer is
aligned.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: implement RIO for fast Windows UDP sockets
Jason A. Donenfeld [Mon, 22 Feb 2021 17:47:41 +0000 (18:47 +0100)] 
conn: implement RIO for fast Windows UDP sockets

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoglobal: remove TODO name graffiti
Jason A. Donenfeld [Mon, 22 Feb 2021 14:43:08 +0000 (15:43 +0100)] 
global: remove TODO name graffiti

Googlers have a habit of graffiting their name in TODO items that then
are never addressed, and other people won't go near those because
they're marked territory of another animal. I've been gradually cleaning
these up as I see them, but this commit just goes all the way and
removes the remaining stragglers.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: test up/down using virtual conn
Jason A. Donenfeld [Mon, 22 Feb 2021 03:30:31 +0000 (04:30 +0100)] 
device: test up/down using virtual conn

This prevents port clashing bugs.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: cleanup unused test components
Jason A. Donenfeld [Mon, 22 Feb 2021 01:57:41 +0000 (02:57 +0100)] 
device: cleanup unused test components

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: make binds replacable
Jason A. Donenfeld [Mon, 22 Feb 2021 01:01:50 +0000 (02:01 +0100)] 
conn: make binds replacable

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agodevice: disable waitpool tests
Jason A. Donenfeld [Mon, 22 Feb 2021 14:12:03 +0000 (15:12 +0100)] 
device: disable waitpool tests

This code is stable, and the test is finicky, especially on high core
count systems, so just disable it.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agotun: make NativeTun.Close well behaved, not crash on double close
Brad Fitzpatrick [Thu, 18 Feb 2021 22:53:22 +0000 (14:53 -0800)] 
tun: make NativeTun.Close well behaved, not crash on double close

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
4 years agoREADME: bump document Go requirement to 1.16
Brad Fitzpatrick [Thu, 18 Feb 2021 22:42:04 +0000 (14:42 -0800)] 
README: bump document Go requirement to 1.16

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
4 years agoglobal: stop using ioutil
Jason A. Donenfeld [Wed, 17 Feb 2021 21:19:27 +0000 (22:19 +0100)] 
global: stop using ioutil

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoconn: bump to 1.16 and get rid of NetErrClosed hack
Jason A. Donenfeld [Tue, 16 Feb 2021 20:05:25 +0000 (21:05 +0100)] 
conn: bump to 1.16 and get rid of NetErrClosed hack

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
4 years agoversion: bump snapshot 0.0.20210212
Jason A. Donenfeld [Fri, 12 Feb 2021 17:00:59 +0000 (18:00 +0100)] 
version: bump snapshot

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>