Brad Fitzpatrick
93ffc565e5
derp: remove protocol version 1 support
...
It hasn't existed for a long time and there are no current users.
Fixes #199
2020-08-17 16:17:56 -07:00
Josh Bleecher Snyder
062bd67d3b
derp: use rand instead of crypto/rand to generate jitter
...
We don't need crypto/rand. Let the OS keep its entropy bits.
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-08-13 14:06:50 -07:00
David Anderson
37c19970b3
derp: add a debug option to verbosely log drops to a destination.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-08-12 15:27:01 -07:00
Josh Bleecher Snyder
909c165382
derp: remove two key.Public allocations
...
Reading and writing a [32]byte key to a bufio.Reader/bufio.Writer
can easily by done without allocating. Do so.
It is slower; on my machine, it adds about 100ns per read/write.
However, the overall request takes a minimum of several µs,
and it cuts allocations meaningfully, so it is probably worth it.
name old time/op new time/op delta
SendRecv/msgsize=10-8 9.21µs ± 9% 9.08µs ± 8% ~ (p=0.250 n=15+15)
SendRecv/msgsize=100-8 6.51µs ± 9% 6.60µs ± 7% ~ (p=0.259 n=15+13)
SendRecv/msgsize=1000-8 7.24µs ±13% 7.61µs ±36% ~ (p=1.000 n=11+15)
SendRecv/msgsize=10000-8 19.5µs ±15% 19.9µs ±25% ~ (p=0.890 n=14+15)
name old speed new speed delta
SendRecv/msgsize=10-8 1.09MB/s ± 8% 1.10MB/s ± 8% ~ (p=0.286 n=15+15)
SendRecv/msgsize=100-8 15.4MB/s ± 8% 15.1MB/s ± 6% ~ (p=0.129 n=15+12)
SendRecv/msgsize=1000-8 139MB/s ±15% 135MB/s ±28% ~ (p=1.000 n=11+15)
SendRecv/msgsize=10000-8 516MB/s ±17% 506MB/s ±21% ~ (p=0.880 n=14+15)
name old alloc/op new alloc/op delta
SendRecv/msgsize=10-8 170B ± 1% 108B ± 1% -36.63% (p=0.000 n=15+15)
SendRecv/msgsize=100-8 265B ± 1% 203B ± 1% -23.34% (p=0.000 n=15+15)
SendRecv/msgsize=1000-8 1.18kB ± 1% 1.12kB ± 0% -5.31% (p=0.000 n=14+14)
SendRecv/msgsize=10000-8 18.8kB ± 2% 18.8kB ± 2% ~ (p=0.443 n=12+12)
name old allocs/op new allocs/op delta
SendRecv/msgsize=10-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=15+15)
SendRecv/msgsize=100-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=15+15)
SendRecv/msgsize=1000-8 4.00 ± 0% 2.00 ± 0% -50.00% (p=0.000 n=15+15)
SendRecv/msgsize=10000-8 5.00 ± 0% 3.00 ± 0% -40.00% (p=0.000 n=13+14)
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-08-12 15:15:58 -07:00
Brad Fitzpatrick
75225368a4
derp: fix 32-bit struct field alignment
2020-08-11 13:50:16 -07:00
David Anderson
15949ad77d
derp: export the new expvar.
2020-08-11 19:59:08 +00:00
David Anderson
13661e195a
derp: rename "wireguard" packet type to "other".
...
Strictly speaking, we don't know that it's a wireguard packet, just that
it doesn't look like a disco packet.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-08-11 19:30:39 +00:00
David Anderson
1b5b59231b
derp: break down received packets by kind (disco vs. wireguard).
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-08-11 19:16:28 +00:00
Josh Bleecher Snyder
b23f2263c1
derp: add server version to /debug, expvars
...
This will make it easier for a human to tell what
version is deployed, for (say) correlating line numbers
in profiles or panics to corresponding source code.
It'll also let us observe version changes in prometheus.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2020-08-07 12:46:02 -07:00
David Anderson
c3994fd77c
derp: remove OnlyDisco option.
...
Active discovery lets us introspect the state of the network stack precisely
enough that it's unnecessary, and dropping the initial DERP packets greatly
slows down tests. Additionally, it's unrealistic since our production network
will never deliver _only_ discovery packets, it'll be all or nothing.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-27 14:09:54 -07:00
Brad Fitzpatrick
52969bdfb0
derp: fix atomic padding on 32-bit again
...
Broken by earlier OnlyDisco addition.
2020-07-16 13:38:21 -07:00
Brad Fitzpatrick
a6559a8924
wgengine/magicsock: run test DERP in mode where only disco packets allowed
...
So we don't accidentally pass a NAT traversal test by having DERP pick up our slack
when we really just wanted DERP as an OOB messaging channel.
2020-07-16 12:58:35 -07:00
Brad Fitzpatrick
c1cabe75dc
derp: fix server struct fielfd alignment on 32-bit
...
Mostly so the GitHub CI will pass on 32-bit.
2020-07-07 09:08:15 -07:00
Brad Fitzpatrick
4732722b87
derp: add frameClosePeer to move around clients within a region
...
For various reasons (mostly during rollouts or config changes on our
side), nodes may end up connecting to a fallback DERP node in a
region, rather than the primary one we tell them about in the DERP
map.
Connecting to the "wrong" node is fine, but it's in our best interest
for all nodes in a domain to connect to the same node, to reduce
intra-region packet forwarding.
This adds a privileged frame type used by the control system that can
kick off a client connection when they're connected to the wrong node
in a region. Then they hopefully reconnect immediately to the correct
location. (If not, we can leave them alone and stop closing them.)
Updates tailscale/corp#372
2020-06-25 09:33:10 -07:00
Brad Fitzpatrick
dd43d9bc5f
derp: fix varz typo
...
Updates tailscale/corp#391
2020-06-25 08:43:28 -07:00
Brad Fitzpatrick
b87396b5d9
cmd/derper, derp: add some more varz and consistency check handler
...
I'm trying to hunt down a slow drift in numbers not agreeing.
2020-06-23 14:01:51 -07:00
Brad Fitzpatrick
6fbd1abcd3
derp: update peerGone code to work with regional DERP mesh clusters too
...
Updates #150
Updates #388
2020-06-22 10:06:42 -07:00
Brad Fitzpatrick
07ca0c1c29
derp: fix tracking problem if conn starts local, then also joins mesh peer
2020-06-05 12:53:43 -07:00
Brad Fitzpatrick
1cb7dab881
cmd/derper: support forwarding packets amongst set of peer DERP servers
...
Updates #388
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-06-05 10:14:33 -07:00
Brad Fitzpatrick
4d599d194f
derp, derp/derphttp: add key accessors, add Client.RecvDetail
...
Client.RecvDetail returns a connection generation so interested clients
can detect when a reconnect happened. (Will be needed for #388 )
2020-06-04 11:35:53 -07:00
Brad Fitzpatrick
b33c86b542
derp: add an unexported key.Public zero value variable to be less verbose
2020-06-04 11:28:00 -07:00
Brad Fitzpatrick
b663ab4685
cmd/derper: treat self-connection connection watch as no-op
...
Updates #388
2020-06-04 08:26:05 -07:00
Brad Fitzpatrick
484b7fc9a3
derp, cmd/derper: add frameWatchConns, framePeerPresent for inter-DERP routing
...
This lets a trusted DERP client that knows a pre-shared key subscribe
to the connection list. Upon subscribing, they get the current set
of connected public keys, and then all changes over time.
This lets a set of DERP server peers within a region all stay connected to
each other and know which clients are connected to which nodes.
Updates #388
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-06-03 08:03:29 -07:00
Dmitry Adamushko
f2c2d0de68
derp/derp_server: unregisterClient() for replaced client connections.
...
When unregistering a replaced client connection, move the
still-connected peers to the current client connecition. Inform
the peers that we've gone only when unregistering the active
client connection.
Signed-off-by: Dmitry Adamushko <da@stablebits.net>
2020-04-10 08:52:30 -07:00
Dmitry Adamushko
44434fdc82
derp/derp_server: fixed unbalanced {register,unregister}Client() calls.
...
Signed-off-by: Dmitry Adamushko <da@stablebits.net>
2020-04-06 15:13:47 -07:00
Brad Fitzpatrick
1ab5b31c4b
derp, magicsock: send new "peer gone" frames when previous sender disconnects
...
Updates #150 (not yet enabled by default in magicsock)
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-22 21:00:47 -07:00
Brad Fitzpatrick
8c4cef60f8
derp: wait for send goroutine to finish before returning from run
...
I saw a test flake due to the sender goroutine logging (ultimately to
t.Logf) after the server was closed.
This makes sure the all goroutines are cleaned up before Server.Close
returns.
2020-03-22 13:10:07 -07:00
Brad Fitzpatrick
521ad7b0fc
derp: only flush writes to clients when we're out of things to write
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-22 08:01:25 -07:00
Brad Fitzpatrick
0a25abcdaa
derp: remove TODO comment
...
It was done in bf704a5218
2020-03-22 07:54:50 -07:00
Brad Fitzpatrick
8519a1b29f
derp: revert rename of pkt to sendMsg
...
New plan, sorry.
Most reverts 77921a31b1
, except some doc changes.
2020-03-21 22:17:22 -07:00
Brad Fitzpatrick
c34b350efa
derp: remove the mutex around and closing of send channel
...
Makes it less complicated.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-21 22:00:04 -07:00
Brad Fitzpatrick
77921a31b1
derp: rename pkt to sendMsg, in prep for other types of writes
...
Updates #150
2020-03-21 20:34:49 -07:00
Brad Fitzpatrick
1453aecb44
derp: add sclient.done channel, simplify some context passing
...
This is mostly prep for a few future CLs, making sure we always have a
close-on-dead done channel available to select on when doing other
channel operations.
2020-03-21 18:28:34 -07:00
David Anderson
ea90780066
derp: specify type of the by-reason drop varz.
...
Signed-off-by: David Anderson <dave@natulte.net>
2020-03-20 15:53:04 -07:00
Brad Fitzpatrick
fd824df1fa
derp: export metric for server's initial MemStats.Sys reading
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-20 15:37:36 -07:00
David Anderson
64b5248929
derp: sprinkle comments and docstrings.
...
Signed-off-by: David Anderson <dave@natulte.net>
2020-03-20 15:14:01 -07:00
David Anderson
58b8ebd290
derp: add per-reason packet drop counter.
...
In parallel with the summed counter for now, for dashboard migration.
Signed-off-by: David Anderson <dave@natulte.net>
2020-03-20 15:14:01 -07:00
David Anderson
1e031001db
derp: move write timeout to package constant.
...
Signed-off-by: David Anderson <dave@natulte.net>
2020-03-20 15:14:01 -07:00
David Anderson
dbfc916273
derp: add short queues between reader and writer, drop on overload.
...
This avoids the server blocking on misbehaving or heavily contended
clients. We attempt to drop from the head of the queue to keep
overall queueing time lower.
Also:
- fixes server->client keepalives, which weren't happening.
- removes read rate-limiter, deferring instead to kernel-level
global limiter/fair queuer.
Signed-off-by: David Anderson <dave@natulte.net>
2020-03-20 15:14:01 -07:00
David Crawshaw
e838b3fb59
derp: use a write timeout when sending to clients
...
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2020-03-12 14:42:48 -04:00
David Crawshaw
3df1b97ea8
derp: do not treat failure to relay as the fault of the sender
...
If Alice attempts to send a packet to Bob and the DERP server
encounters an error on the socket to Bob, we should not disconnect
Alice for that.
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2020-03-12 14:42:48 -04:00
David Crawshaw
43aa8595dd
derp: introduce Conn interface
...
This lets us test with something other than a net.Conn.
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2020-03-12 14:42:48 -04:00
Brad Fitzpatrick
4fd29349b9
derp: add clients_replaced counter
...
Updates #109
2020-03-11 11:55:43 -07:00
Brad Fitzpatrick
5d8001d0ad
derp: add varz for home moves
...
Updates #162
Updates #163 (maybe)
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-09 11:09:27 -07:00
Brad Fitzpatrick
dd456f04c5
derp: actually record client's preferred bit
2020-03-05 19:02:54 -08:00
Brad Fitzpatrick
6978b93bdd
derp, magicsock: track home (preferred) vs visiting connections for stats
2020-03-05 15:00:56 -08:00
Brad Fitzpatrick
bf704a5218
derp: protocol negotiation, add v2: send src pub keys to clients in packets
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-04 09:55:13 -08:00
Brad Fitzpatrick
e371520cc5
tsweb, derp: add expvar http.Handler for Prometheus's format
...
And add some opinions.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-03 13:59:16 -08:00
Brad Fitzpatrick
d59d0576af
derp: don't log on all dropped packets; super spammy
...
Signed-off-by: Brad Fitzpatrick <brad@danga.com>
2020-02-28 13:33:47 -08:00
Brad Fitzpatrick
752146a70f
derp: clean up derphttp client code, use contexts
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-02-28 13:18:59 -08:00