summaryrefslogtreecommitdiffhomepage
path: root/internal
AgeCommit message (Collapse)AuthorFilesLines
2021-05-16all: adapt to opaque netaddr typesJosh Bleecher Snyder1-1/+1
This commit is a mishmash of automated edits using gofmt: gofmt -r 'netaddr.IPPort{IP: a, Port: b} -> netaddr.IPPortFrom(a, b)' -w . gofmt -r 'netaddr.IPPrefix{IP: a, Port: b} -> netaddr.IPPrefixFrom(a, b)' -w . gofmt -r 'a.IP.Is4 -> a.IP().Is4' -w . gofmt -r 'a.IP.As16 -> a.IP().As16' -w . gofmt -r 'a.IP.Is6 -> a.IP().Is6' -w . gofmt -r 'a.IP.As4 -> a.IP().As4' -w . gofmt -r 'a.IP.String -> a.IP().String' -w . And regexps: \w*(.*)\.Port = (.*) -> $1 = $1.WithPort($2) \w*(.*)\.IP = (.*) -> $1 = $1.WithIP($2) And lots of manual fixups. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11all: add extra information to serialized endpointsJosh Bleecher Snyder1-1/+3
magicsock.Conn.ParseEndpoint requires a peer's public key, disco key, and legacy ip/ports in order to do its job. We currently accomplish that by: * adding the public key in our wireguard-go fork * encoding the disco key as magic hostname * using a bespoke comma-separated encoding It's a bit messy. Instead, switch to something simpler: use a json-encoded struct containing exactly the information we need, in the form we use it. Our wireguard-go fork still adds the public key to the address when it passes it to ParseEndpoint, but now the code compensating for that is just a couple of simple, well-commented lines. Once this commit is in, we can remove that part of the fork and remove the compensating code. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-05-11internal/deephash: rename from deepprintBrad Fitzpatrick3-10/+5
Yes, it printed, but that was an implementation detail for hashing. And coming optimization will make it print even less. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-05-11internal/deepprint: improve benchmarkJosh Bleecher Snyder1-10/+13
This more closely matches our real usage of deepprint. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: close struct curly parensJosh Bleecher Snyder1-0/+1
Not that it matters, but we were missing a close parens. It's cheap, so add it. name old time/op new time/op delta Hash-8 6.64µs ± 0% 6.67µs ± 1% +0.42% (p=0.008 n=9+10) name old alloc/op new alloc/op delta Hash-8 1.54kB ± 0% 1.54kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta Hash-8 37.0 ± 0% 37.0 ± 0% ~ (all equal) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: stop printing struct field namesJosh Bleecher Snyder1-4/+1
The struct field names don't change within a single run, so they are irrelevant. Use the field index instead. name old time/op new time/op delta Hash-8 6.52µs ± 0% 6.64µs ± 0% +1.91% (p=0.000 n=6+9) name old alloc/op new alloc/op delta Hash-8 1.67kB ± 0% 1.54kB ± 0% -7.66% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 53.0 ± 0% 37.0 ± 0% -30.19% (p=0.000 n=10+10) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: replace Fprintf(w, const) with w.WriteStringJosh Bleecher Snyder1-8/+7
name old time/op new time/op delta Hash-8 7.77µs ± 0% 6.29µs ± 1% -19.11% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Hash-8 1.67kB ± 0% 1.67kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta Hash-8 53.0 ± 0% 53.0 ± 0% ~ (all equal) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: special-case some common typesJosh Bleecher Snyder1-0/+75
These show up a lot in our data structures. name old time/op new time/op delta Hash-8 11.5µs ± 1% 7.8µs ± 1% -32.17% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Hash-8 1.98kB ± 0% 1.67kB ± 0% -15.73% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 82.0 ± 0% 53.0 ± 0% -35.37% (p=0.000 n=10+10) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: buffer writesJosh Bleecher Snyder2-11/+10
The sha256 hash writer doesn't implement WriteString. (See https://github.com/golang/go/issues/38776.) As a consequence, we end up converting many strings to []byte. Wrapping a bufio.Writer around the hash writer lets us avoid these conversions by using WriteString. Using a bufio.Writer is, perhaps surprisingly, almost as cheap as using unsafe. The reason is that the sha256 writer does internal buffering, but doesn't do any when handed larger writers. Using a bufio.Writer merely shifts the data copying from one buffer to a different one. Using a concrete type for Print and print cuts 10% off of the execution time. name old time/op new time/op delta Hash-8 15.3µs ± 0% 11.5µs ± 0% -24.84% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Hash-8 2.82kB ± 0% 1.98kB ± 0% -29.57% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Hash-8 140 ± 0% 82 ± 0% -41.43% (p=0.000 n=10+10) Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-11internal/deepprint: add BenchmarkHashJosh Bleecher Snyder1-0/+8
deepprint currently accounts for 15% of allocs in tailscaled. This is a useful benchmark to have. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-04-05wgengine: move DNS configuration out of wgengine/router.David Anderson1-4/+3
Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-03wgengine/wgcfg: remove Config.ListenPortJosh Bleecher Snyder1-3/+2
We don't use the port that wireguard-go passes to us (via magicsock.connBind.Open). We ignore it entirely and use the port we selected. When we tell wireguard-go that we're changing the listen_port, it calls connBind.Close and then connBind.Open. And in the meantime, it stops calling the receive functions, which means that we stop receiving and processing UDP and DERP packets. And that is Very Bad. That was never a problem prior to b3ceca1dd7d7a1a6f9ddab136a4e12900e976333, because we passed the SkipBindUpdate flag to our wireguard-go fork, which told wireguard-go not to re-bind on listen_port changes. That commit eliminated the SkipBindUpdate flag. We could write a bunch of code to work around the gap. We could add background readers that process UDP and DERP packets when wireguard-go isn't. But it's simpler to never create the conditions in which wireguard-go rebinds. The other scenario in which wireguard-go re-binds is device.Down. Conveniently, we never call device.Down. We go from device.Up to device.Close, and the latter only when we're shutting down a magicsock.Conn completely. Rubber-ducked-by: Avery Pennarun <apenwarr@tailscale.com> Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-04-02net/dns: rename Config to OSConfig.David Anderson1-1/+1
Making way for a new higher level config struct. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-03-25many: gofmt.David Anderson1-1/+1
Signed-off-by: David Anderson <danderson@tailscale.com>
2021-03-25wgengine/router/dns: move to net/dns.David Anderson1-1/+1
Preparation for merging the APIs and whatnot. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-01-29all: move wgcfg from wireguard-goJosh Bleecher Snyder1-1/+1
This is mostly code movement from the wireguard-go repo. Most of the new wgcfg package corresponds to the wireguard-go wgcfg package. wgengine/wgcfg/device{_test}.go was device/config{_test}.go. There were substantive but simple changes to device_test.go to remove internal package device references. The API of device.Config (now wgcfg.DeviceConfig) grew an error return; we previously logged the error and threw it away. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-01-14all: convert from []wgcfg.Endpoint to stringJosh Bleecher Snyder1-6/+1
This eliminates a dependency on wgcfg.Endpoint, as part of the effort to eliminate our wireguard-go fork. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2020-12-28all: replace wgcfg.IP and wgcfg.CIDR with netaddr typesJosh Bleecher Snyder1-1/+1
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2020-09-09Add tooldeps package to keep depaware pinned in go.mod.Brad Fitzpatrick1-0/+9
2020-07-31all: dns refactor, add Proxied and PerDomain flags from control (#615)Dmytro Shynkevych1-1/+2
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
2020-07-28ipn: fix netmap change tracking and dns map generation (#609)Dmytro Shynkevych1-2/+12
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
2020-07-14wgengine/router: dns: unify on *BSD, multimode on Linux, Magic DNS (#536)Dmytro Shynkevych1-1/+4
Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
2020-06-29internal/deepprint: update copyright header to appease license checker scriptBrad Fitzpatrick1-1/+7
Plus mention that it's not an exact copy.
2020-06-29internal/deepprint: add missing copyright headersBrad Fitzpatrick2-0/+8
2020-06-28wgengine, internal/deepprint: replace UAPI usage as hash func; add deepprintBrad Fitzpatrick3-0/+370
The new deepprint package just walks a Go data structure and writes to an io.Writer. It's not pretty like go-spew, etc. We then use it to replace the use of UAPI (which we have a TODO to remove) to generate signatures of data structures to detect whether anything changed (without retaining the old copy). This was necessary because the UAPI conversion ends up trying to do DNS lookups which an upcoming change depends on not happening.