Commit Graph

371 Commits

Author SHA1 Message Date
kadmin 1f9021e287 add capability check 2021-07-08 20:15:38 +00:00
kadmin 9fd01334cf update with Josh's changes 2021-07-08 20:15:38 +00:00
kadmin c5cb642376 Add test for udp conn 2021-07-08 20:15:19 +00:00
kadmin 87fc7aa6b0 Clean up tests a bit more 2021-07-08 20:15:05 +00:00
kadmin 34c5677308 add timeout?
This adds most likely broken timeout code. I have no idea where the docs are for adding
timeouts, and there is only a very brief mention in the spec.
2021-07-08 20:14:46 +00:00
julianknodt 6d10acc6dd net/uring: add split for linux vs not for io_uring
This also adds a flag for checking whether it is active or not.

Signed-off-by: julianknodt <julianknodt@gmail.com>
2021-07-08 20:14:31 +00:00
kadmin 61e3d919ef net/uring: add go ntohs
Instead of calling out to C for ntohs, just implement it in Go for effiency.

Signed-off-by: kadmin <julianknodt@gmail.com>
2021-07-08 12:58:58 -07:00
Josh Bleecher Snyder cc5c696834 comment more 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 33c0997447 incorporate recvOut into recvReqs 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 08af39ae24 remove more dead code 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 43ccdc8879 document, cull dead code 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder e0abf1b3dd WIP: clean shutdown for UDP conn
this appears to work, most of the time.
there's lots of documentation work remaining,
thinking through the structure remaining,
testing remaining,
porting to file remaining (if appropriate).
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 7642d9fafd remove dead code 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder bf20f000fd overhaul error handling of peek/waitcompletion 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 4679379ebe refactor 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder f6b49d3e0e set sin_family (oops) 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder ae2f24ec4e remove some TODOs, make ip address extraction equally awful 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder ba49da429a simplify change point
at the cost of some very, very naughty unsafe
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 83742afabf convert manual tests into automated tests 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 5410042dcd start cleaning up code 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 75efd794a3 ipv6 support, UNTESTED, super hacky 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 36a4741bc5 comments 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 208e6eb0db fix io_uring tun device reads
Well that's an interesting one!
Apparently if you issue multiple concurrent preadv calls on
a TUN device using io_uring, the TUN device falls over.

Possibly corrupting memory along the way.
Which might be why the kernel hung on shutdown...
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder fec66b4100 make it easy to toggle uring on/off 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder a8df9fa7cc simpler init 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 78fd2b7880 stick closer to upstream tun reading code 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 001dec84de make cgo pointer rules happy
well that was a mess
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder a8a7208dbd use io_uring for sendmsg
and clean up some dead code and unify some things
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder f254f779b5 disable polling for now
we'll maybe bring it back with a token bucket or something.
and/or do multi-sqe submission.
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 3d91c5b369 they work with extra junk
thanks, dave
no thanks, kernel devs

write no work
use writev
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 2a2ed7cd17 tun writes...not working yet (but why not??) 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 55c1ce00be use polling instead of syscall 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 4013c0edbb smush together two return values from C
avoids a per-packet alloc

i will atone for my sins later

if only C let you return multiple values.
or Go let you pass in a pointer w/o it being on the heap.
2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 783d2d4327 keep 8 requests in the queue at all times 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 71f35bda1a remove all allocs 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder b83ac004f1 remove all allocations 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 59512181b5 mve sockaddr_in to Go 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 1ee40d1670 move iovec to go 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder d7a7e2d17d move msghdr to Go 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder f26c0fcbd5 use io_uring 2021-07-08 12:56:49 -07:00
Josh Bleecher Snyder 0ad92b89a6 net/tstun: fix data races
To remove some multi-case selects, we intentionally allowed
sends on closed channels (cc23049cd2).

However, we also introduced concurrent sends and closes,
which is a data race.

This commit fixes the data race. The mutexes here are uncontended,
and thus very cheap.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-07-07 16:15:29 -07:00
Josh Bleecher Snyder c35a832de6 net/tstun: add inner loop to poll
This avoids re-enqueuing to t.bufferConsumed,
which makes the code a bit clearer.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-07-02 11:02:12 -07:00
Josh Bleecher Snyder a4cc7b6d54 net/tstun: simplify code
Calculate whether the packet is injected directly,
rather than via an else branch.

Unify the exit paths. It is easier here than duplicating them.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-07-02 11:02:12 -07:00
Josh Bleecher Snyder cc23049cd2 net/tstun: remove multi-case selects from hot code
Every TUN Read went through several multi-case selects.
We know from past experience with wireguard-go that these are slow
and cause scheduler churn.

The selects served two purposes: they separated errors from data and
gracefully handled shutdown. The first is fairly easy to replace by sending
errors and data over a single channel. The second, less so.

We considered a few approaches: Intricate webs of channels,
global condition variables. They all get ugly fast.

Instead, let's embrace the ugly and handle shutdown ungracefully.
It's horrible, but the horror is simple and localized.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-07-02 11:02:12 -07:00
David Crawshaw 6b9f8208f4 net/dns: do not run wsl.exe as LocalSystem
It doesn't work. It needs to run as the user.

	https://github.com/microsoft/WSL/issues/4803

The mechanism for doing this was extracted from:

	https://web.archive.org/web/20101009012531/http://blogs.msdn.com/b/winsdk/archive/2009/07/14/launching-an-interactive-process-from-windows-service-in-windows-vista-and-later.aspx

While here, we also reclaculate WSL distro set on SetDNS.
This accounts for:

	1. potential inability to access wsl.exe on startup
	2. WSL being installed while Tailscale is running
	3. A new WSL distrobution being installed

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-06-30 10:11:33 -07:00
David Crawshaw 1147c7fd4f net/dns: set WSL /etc/resolv.conf
We also have to make a one-off change to /etc/wsl.conf to stop every
invocation of wsl.exe clobbering the /etc/resolv.conf. This appears to
be a safe change to make permanently, as even though the resolv.conf is
constantly clobbered, it is always the same stable internal IP that is
set as a nameserver. (I believe the resolv.conf clobbering predates the
MS stub resolver.)

Tested on WSL2, should work for WSL1 too.

Fixes #775

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-06-28 14:18:15 -07:00
David Crawshaw 9b063b86c3 net/dns: factor directManager out over an FS interface
This is preliminary work for using the directManager as
part of a wslManager on windows, where in addition to configuring
windows we'll use wsl.exe to edit the linux file system and modify the
system resolv.conf.

The pinholeFS is a little funky, but it's designed to work through
simple unix tools via wsl.exe without invoking bash. I would not have
thought it would stand on its own like this, but it turns out it's
useful for writing a test for the directManager.

Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-06-28 14:18:15 -07:00
Brad Fitzpatrick 15677d8a0e net/socks5/tssocks: add a SOCKS5 dialer type, method-ifying code
https://twitter.com/bradfitz/status/1409605220376580097

Prep for #1970, #2264, #2268

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-06-28 13:12:42 -07:00
Brad Fitzpatrick 3910c1edaf net/socks5/tssocks: add new package, move SOCKS5 glue out of tailscaled
Prep for #1970, #2264, #2268

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-06-28 11:34:50 -07:00
David Crawshaw d6f4b5f5cb ipn, etc: use controlplane.tailscale.com
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-06-28 09:38:23 -07:00