summaryrefslogtreecommitdiffhomepage
path: root/wgengine/monitor
AgeCommit message (Collapse)AuthorFilesLines
2021-05-16all: adapt to opaque netaddr typesJosh Bleecher Snyder1-3/+3
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-04-12wgengine/monitor: reduce Linux log spam on downBrad Fitzpatrick1-1/+1
Fixes #1689 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-06monitor/polling: reduce Cloud Run polling interval.Denton Gentry1-2/+22
Cloud Run's routes never change at runtime. Don't poll it for route changes very often. Signed-off-by: Denton Gentry <dgentry@tailscale.com>
2021-04-01wgengine/monitor: Linux fall back to pollingDenton Gentry3-55/+73
Google Cloud Run does not implement NETLINK_ROUTE RTMGRP. If initialization of the netlink socket or group membership fails, fall back to a polling implementation. Signed-off-by: Denton Gentry <dgentry@tailscale.com>
2021-03-28wgengine/monitor: on wall time jump, synthesize network change eventBrad Fitzpatrick1-28/+107
... to force rebinds of TCP connections Fixes #1555 Updates tailscale/felicity#4 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-26wgengine/monitor: fix OpenBSD buildBrad Fitzpatrick1-1/+2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-26net/interfaces: remove mutating methods, add EqualFiltered insteadBrad Fitzpatrick1-7/+2
Now callers (wgengine/monitor) don't need to mutate the state to remove boring interfaces before calling State.Equal. Instead, the methods to remove boring interfaces from the State are removed, as is the reflect-using Equal method itself, and in their place is a new EqualFiltered method that takes a func predicate to match interfaces to compare. And then the FilterInteresting predicate is added for use with EqualFiltered to do the job that that wgengine/monitor previously wanted. Now wgengine/monitor can keep the full interface state around, including the "boring" interfaces, which we'll need for peerapi on macOS/iOS to bind to the interface index of the utunN device. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-16wgengine/monitor: skip more route messages on darwinBrad Fitzpatrick1-10/+64
Should help iOS battery life on NEProvider.wake/skip events with useless route updates that shouldn't cause re-STUNs. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-15net/portmapper, wgengine/monitor: cache gateway IP info until link changesBrad Fitzpatrick1-3/+26
Cuts down allocs & CPU in steady state (on regular STUN probes) when network is unchanging. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-08net/interfaces, wgengine/monitor: fix false positives link changesBrad Fitzpatrick1-0/+1
interfaces.State.String tries to print a concise summary of the network state, removing any interfaces that don't have any or any interesting IP addresses. On macOS and iOS, for instance, there are a ton of misc things. But the link monitor based its are-there-changes decision on interfaces.State.Equal, which just used reflect.DeepEqual, including comparing all the boring interfaces. On macOS, when turning wifi on or off, there are a ton of misc boring interface changes, resulting in hitting an earlier check I'd added on suspicion this was happening: [unexpected] network state changed, but stringification didn't This fixes that by instead adding a new interfaces.State.RemoveUninterestingInterfacesAndAddresses method that does, uh, that. Then use that in the monitor. So then when Equal is used later, it's DeepEqualing the already-cleaned version with only interesting interfaces. This makes cmd/tailscaled debug --monitor much less noisy. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-08wgengine/monitor: simplify the Windows monitor to make it more reliableAleksandar Pesic1-224/+75
Updates tailscale/tailscale#1414 Signed-off-by: Aleksandar Pesic <peske.nis@gmail.com>
2021-03-05wgengine/monitor: log warning if state changes but stringification doesn'tBrad Fitzpatrick1-1/+16
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-03wgengine{,/monitor}: restore Engine.LinkChange, add Mon.InjectEventBrad Fitzpatrick2-7/+39
The Engine.LinkChange method was recently removed in e3df29d488f5ce50ee396b1f05a92e9cf1abb006 while misremembering how Android's link state mechanism worked. Rather than do some last minute rearchitecting of link state on Android before Tailscale 1.6, restore the old Engine.LinkChange hook for now so the Android client doesn't need any changes. But change how it's implemented to instead inject an event into the link monitor. Fixes #1427 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02wgengine/monitor: on unsupported platforms, use a polling implementationBrad Fitzpatrick7-20/+86
Not great, but lets people working on new ports get going more quickly without having to do everything up front. As the link monitor is getting used more, I felt bad having a useless implementation. Updates #815 Updates #1427 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02wgengine/monitor: skip some macOS route updates, fix debounce regressionBrad Fitzpatrick3-18/+89
Debound was broken way back in 5c1e443d348d32 and we never noticed. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02wgengine/monitor: add skipped failing test for Darwin route message bugBrad Fitzpatrick1-0/+28
Updates #1416 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-02wgengine/monitor: don't return nil, nil in darwin monitorBrad Fitzpatrick1-1/+1
We used to allow that, but now it just crashes. Separately I need to figure out why it got into this path at all, which is #1416. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-01wgengine/monitor: make Darwin monitor shut down cleanly, add testBrad Fitzpatrick2-7/+42
Don't use os.NewFile or (*os.File).Close on the AF_ROUTE socket. It apparently does weird things to the fd and at least doesn't seem to close it. Just use the unix package. The test doesn't actually fail reliably before the fix, though. It was an attempt. But this fixes the integration tests. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-01wgengine{,/monitor}: move interface state fetching/comparing to monitorBrad Fitzpatrick1-12/+35
Gets it out of wgengine so the Engine isn't responsible for being a callback registration hub for it. This also removes the Engine.LinkChange method, as it's no longer necessary. The monitor tells us about changes; it doesn't seem to need any help. (Currently it was only used by Swift, but as of 14dc79013754fe we just do the same from Go) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-01wgengine/monitor: start moving interface state accessor into monitorBrad Fitzpatrick1-0/+11
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-28wgengine/monitor: make the darwin link monitor work in the sandbox tooBrad Fitzpatrick3-73/+132
Previously tailscaled on macOS was running "/sbin/route monitor" as a child process, but child processes aren't allowed in the Network Extension / App Store sandbox. Instead, just do what "/sbin/route monitor" itself does: unix.Socket(unix.AF_ROUTE, unix.SOCK_RAW, 0) and read that. We also parse it now, but don't do anything with the parsed results yet. We will over time, as we have with Linux netlink messages over time. Currently any message is considered a signal to poll and see what changed. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-27wgengine/monitor: change API to permit multiple independent callbakcksBrad Fitzpatrick1-6/+30
Currently it assumes exactly 1 registered callback. This changes it to support 0, 1, or more than 1. This is a step towards plumbing wgengine/monitor into more places (and moving some of wgengine's interface state fetching into monitor in a later step) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-02-22wgengine/monitor: don't log any single-IP routes added to the tailscale table.David Anderson1-1/+1
Signed-off-by: David Anderson <danderson@tailscale.com>
2021-02-22wgengine/monitor: on linux, also monitor for IPv6 changes.David Anderson1-6/+5
Signed-off-by: David Anderson <danderson@tailscale.com>
2021-02-15wgengine/monitor: prevent shutdown hang in darwin link monitorBrad Fitzpatrick1-3/+10
2021-02-13wgengine/monitor: add a darwin implementation for tailscaled modeBrad Fitzpatrick2-1/+66
Tangentially related to #987, #177, #594, #925, #505 Motivated by rebooting a launchd-controlled tailscaled and it going into SetNetworkUp(false) mode immediately because there really is no network up at system boot, but then it got stuck in that paused state forever, without a monitor implementation.
2021-01-07wgengine/monitor: close closeHandleAlex Brainman1-13/+22
eccc167 introduced closeHandle which opened the handle, but never closed it. Windows handles should be closed. Updates #921 Signed-off-by: Alex Brainman <alex.brainman@gmail.com>
2020-12-23go.mod: bump github.com/mdlayher/netlink to v1.2.0Matt Layher1-4/+1
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2020-11-18wgengine/monitor: fix memory corruption in Windows implementationBrad Fitzpatrick1-57/+115
I used the Windows APIs wrong previously, but it had worked just enough. Updates #921 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-10-09wgengine/monitor: fix copy/paste-o to actually monitor route changesBrad Fitzpatrick1-1/+1
Due to a copy/paste-o, we were monitoring address changes twice, and not monitoring route changes at all. Verified with 'tailscale debug --monitor' that this actually works now (while running 'route add 10.3.0.0 mask 255.255.0.0 10.0.0.1' and 'route delete (same)' back and forth in cmd.exe) In practice route changes are accompanied by address changes and this doesn't fix any known issues. I just noticed this while reading this code again. But at least the code does what it was trying to do now.
2020-08-24wgengine/monitor: add a poller to the Windows link change monitorBrad Fitzpatrick2-16/+97
The poller is slow by default, but speeds up for a bit after a network change, in case WPAD/PAC files are still loading.
2020-08-21wgengine/monitor_freebsd.go: remove duplicated errcheckDisconnect3d1-3/+0
Signed-off-by: disconnect3d <dominik.b.czarnota@gmail.com>
2020-08-13wgengine/monitor: add Windows linkchange monitorBrad Fitzpatrick2-1/+132
Updates tailscale/corp#553 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-08-12wgengine/monitor: add, clean up netlink logging on route changesBrad Fitzpatrick1-18/+51
Updates #643
2020-08-05wgengine/monitor: log RTM_DELROUTE details, fix format stringsBrad Fitzpatrick1-2/+12
Updates #643
2020-07-14wgengine: fix macos staticcheck errors (#557)Wendi Yu3-7/+14
Signed-off-by: Wendi <wendi.yu@yahoo.ca>
2020-07-07wgengine/monitor: fix other potential crashes on LinuxBrad Fitzpatrick1-11/+16
Never return "nil, nil" anymore. The caller expected a usable interface now. I missed some of these earlier. Also, handle address deletion now. Updates #532
2020-07-07wgengine/monitor: fix crash on Linux on type 21 messagesBrad Fitzpatrick3-7/+9
Fixes #532
2020-07-06wgengine/monitor: parse Linux netlink messages, ignore our own eventsBrad Fitzpatrick4-22/+105
Fixes tailscale/corp#412 ("flood of link change events at start-up") Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-04-24wgengine/monitor: disable monitor on AndroidElias Naur2-1/+3
Netlink is not supported on Android. Signed-off-by: Elias Naur <mail@eliasnaur.com>
2020-03-10Move linkstate boring change filtering to magicsockBrad Fitzpatrick1-28/+0
So we can at least re-STUN on boring updates. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-03-10wgengine/monitor: don't call LinkChange when interfaces look unchangedBrad Fitzpatrick1-1/+29
Basically, don't trust the OS-level link monitor to only tell you interesting things. Sanity check it. Also, move the interfaces package into the net directory now that we have it.
2020-02-17wgengine/monitor: use RTMGRP_* consts from x/sys/unixTobias Klauser1-10/+1
Bump golang.org/x/sys/unix to get the RTMGRP_* consts and use them. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2020-02-17wgengine/monitor: make Close not block forever on LinuxBrad Fitzpatrick1-0/+2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-02-17wgengine: move link monitor to be owned by the engine, not the routerBrad Fitzpatrick4-27/+71
And make the monitor package portable with no-op implementations on unsupported operating systems. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-02-17wgengine: simplify, change some signaturesBrad Fitzpatrick1-0/+2
* make RouterGen return an error, not take both tunname and tundev * also remove RouteGen taking a wireguard/device.Device; currently unused * remove derp parameter (it'll work differently) * unexport NewUserspaceRouter in per-OS impls, add documented wrapper Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-02-14Move "logger" package to under types, now that we have it.Brad Fitzpatrick1-1/+1
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2020-02-13monitor: refactor for architecture-specific connection implementationswardn3-0/+213
Signed-off-by: wardn <wardn@users.noreply.github.com>