summaryrefslogtreecommitdiffhomepage
path: root/ipn
AgeCommit message (Collapse)AuthorFilesLines
2021-05-16all: adapt to opaque netaddr typesJosh Bleecher Snyder4-39/+33
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-12ipnlocal: fix switching users while logged in + Stopped.Avery Pennarun2-72/+125
This code path is very tricky since it was originally designed for the "re-authenticate to refresh my keys" use case, which didn't want to lose the original session even if the refresh cycle failed. This is why it acts differently from the Logout(); Login(); case. Maybe that's too fancy, considering that it probably never quite worked at all, for switching between users without logging out first. But it works now. This was more invasive than I hoped, but the necessary fixes actually removed several other suspicious BUG: lines from state_test.go, so I'm pretty confident this is a significant net improvement. Fixes tailscale/corp#1756. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-05-12ipnlocal: fix deadlock in RequestEngineStatusAndWait() error path.Avery Pennarun1-0/+8
If the engine was shutting down from a previous session (e.closing=true), it would return an error code when trying to get status. In that case, ipnlocal would never unblock any callers that were waiting on the status. Not sure if this ever happened in real life, but I accidentally triggered it while writing a test. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-05-11internal/deephash: rename from deepprintBrad Fitzpatrick1-2/+2
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-10ipn{,/ipnserver}: delay JSON marshaling of ipn.NotifiesBrad Fitzpatrick3-20/+51
If nobody is connected to the IPN bus, don't burn CPU & waste allocations (causing more GC) by encoding netmaps for nobody. This will notably help hello.ipn.dev. Updates tailscale/corp#1773 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-05-07ipn/{ipnlocal,ipnstate}: add PeerStatus.ID stable ID to status --json outputBrad Fitzpatrick2-0/+8
Needed for the "up checker" to map back from exit node stable IDs (the ipn.Prefs.ExitNodeID) back to an IP address in error messages. But also previously requested so people can use it to then make API calls. The upcoming "tailscale admin" subcommand will probably need it too. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-05-05types/logger: add key grinder stats lines to rate-limiting exemption listJosh Bleecher Snyder1-6/+27
Updates #1749 Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-04ipnlocal: accept a new opts.UpdatePrefs field.Avery Pennarun3-1/+44
This is needed because the original opts.Prefs field was at some point subverted for use in frontend->backend state migration for backward compatibility on some platforms. We still need that feature, but we also need the feature of providing the full set of prefs from `tailscale up`, *not* including overwriting the prefs.Persist keys, so we can't use the original field from `tailscale up`. `tailscale up` had attempted to compensate for that by doing SetPrefs() before Start(), but that violates the ipn.Backend contract, which says you should call Start() before anything else (that's why it's called Start()). As a result, doing SetPrefs({ControlURL=..., WantRunning=true}) would cause a connection to the *previous* control server (because WantRunning=true), and then connect to the *new* control server only after running Start(). This problem may have been avoided before, but only by pure luck. It turned out to be relatively harmless since the connection to the old control server was immediately closed and replaced anyway, but it created a race condition that could have caused spurious notifications or rejected keys if the server responded quickly. As already covered by existing TODOs, a better fix would be to have Start() get out of the business of state migration altogether. But we're approaching a release so I want to make the minimum possible fix. Fixes #1840. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-05-04ipn/ipnlocal: update peerapi logging of received PUTsBrad Fitzpatrick1-1/+3
Clarify direction and add duration. (per chat with Avery) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-05-04ipn/ipnlocal: redact more errorsBrad Fitzpatrick1-7/+12
Updates tailscale/corp#1636 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-05-03ipn/ipnlocal: switch from testify to quicktestJosh Bleecher Snyder1-142/+130
Per discussion, we want to have only one test assertion library, and we want to start by exploring quicktest. This was a mostly mechanical translation. I think we could make this nicer by defining a few helper closures at the beginning of the test. Later. Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-04-30ipn/ipnlocal: remove NewLocalBackendWithClientGenBrad Fitzpatrick2-21/+35
This removes the NewLocalBackendWithClientGen constructor added in b4d04a065fd384ca7f57891a2bb87e1ff5205fb6 and instead adds LocalBackend.SetControlClientGetterForTesting, mirroring LocalBackend.SetHTTPTestClient. NewLocalBackendWithClientGen was weird in being exported but taking an unexported type. This was noted during code review: https://github.com/tailscale/tailscale/pull/1818#discussion_r623155669 which ended in: "I'll leave it for y'all to clean up if you find some way to do it elegantly." This is more idiomatic. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-30ipnlocal: don't pause the controlclient until we get at least one netmap.apenwarr/statefixAvery Pennarun2-3/+8
Without this, macOS would fail to display its menu state correctly if you started it while !WantRunning. It relies on the netmap in order to show the logged-in username. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30ipn: !WantRunning + !LoggedOut should not be idle on startup.Avery Pennarun2-21/+26
There was logic that would make a "down" tailscale backend (ie. !WantRunning) refuse to do any network activity. Unfortunately, this makes the macOS and iOS UI unable to render correctly if they start while !WantRunning. Now that we have Prefs.LoggedOut, use that instead. So `tailscale down` will still allow the controlclient to connect its authroutine, but pause the maproutine. `tailscale logout` will entirely stop all activity. This new behaviour is not obviously correct; it's a bit annoying that `tailsale down` doesn't terminate all activity like you might expect. Maybe we should redesign the UI code to render differently when disconnected, and then revert this change. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30ipnlocal: setting WantRunning with EditPrefs was special.Avery Pennarun2-31/+38
EditPrefs should be just a wrapper around the action of changing prefs, but someone had added a side effect of calling Login() sometimes. The side effect happened *after* running the state machine, which would sometimes result in us going into NeedsLogin immediately before calling cc.Login(). This manifested as the macOS app not being able to Connect if you launched it with LoggedOut=false and WantRunning=false. Trying to Connect() would sent us to the NeedsLogin state instead. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30Add prefs.LoggedOut to fix several state machine bugs.Avery Pennarun5-68/+118
Fixes: tailscale/corp#1660 Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30ipn/ipnlocal: some state_test cleanups.Avery Pennarun1-12/+38
This doesn't change the actual functionality. Just some additional comments and fine tuning. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30ipnlocal: fix deadlock when calling Shutdown() from Start().Avery Pennarun1-0/+2
Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30Revert "ipn/ipnlocal: be authoritative for the entire MagicDNS record tree."Avery Pennarun1-6/+0
Unfortunately this broke MagicDNS almost entirely. Updates: tailscale/corp#1706 This reverts commit 1d7e7b49eb8e16c31e41420deff527671a87dc0c.
2021-04-30ipn: mock controlclient.Client; big ipn.Backend state machine test.apenwarr/statetestAvery Pennarun3-41/+833
A very long unit test that verifies the way the controlclient and ipn.Backend interact. This is a giant sequential test of the state machine. The test passes, but only because it's asserting all the wrong behaviour. I marked all the behaviour I think is wrong with BUG comments, and several additional test opportunities with TODO. Note: the new test supercedes TestStartsInNeedsLoginState, which was checking for incorrect behaviour (although the new test still checks for the same incorrect behaviour) and assumed .Start() would converge before returning, which it happens to do, but only for this very specific case, for the current implementation. You're supposed to wait for the notifications. Updates: tailscale/corp#1660 Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-30controlclient: extract a Client interface and rename Client->Auto.Avery Pennarun1-6/+18
This will let us create a mock or fake Client implementation for use with ipn.Backend. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
2021-04-29ipn/ipnlocal: be authoritative for the entire MagicDNS record tree.David Anderson1-0/+6
With this change, shared node names resolve correctly on split DNS-supporting operating systems. Fixes tailscale/corp#1706 Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-29ipn/ipnlocal: make FileTargets check IPN state firstBrad Fitzpatrick2-3/+33
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-28ipn/ipnlocal: remove t.Parallel from recently added testBrad Fitzpatrick1-2/+0
The test modifies a global; it shouldn't be parallel. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-28ipn/ipnlocal: add a test for earlier lazy machine key generation changeBrad Fitzpatrick1-0/+36
Updates #1573 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-28ipn/ipnlocal: remove IPv6 records from MagicDNS.David Anderson1-0/+10
Fixes #1813. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-27ipn/ipnlocal: prevent a now-expected [unexpected] log message on WindowsBrad Fitzpatrick1-0/+6
Updates #1620 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-26ipn/ipnlocal: always write files to partial files, even in buffered modeBrad Fitzpatrick1-7/+17
The intention was always that files only get written to *.partial files and renamed at the end once fully received, but somewhere in the process that got lost in buffered mode and *.partial files were only being used in direct receive mode. This fix prevents WaitingFiles from returning files that are still being transferred. Updates tailscale/corp#1626 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-26ipn/ipnlocal: use delete marker files to work around Windows delete problemsBrad Fitzpatrick2-16/+202
If DeleteFile fails on Windows due to another process (anti-virus, probably) having our file open, instead leave a marker file that the file is logically deleted, and remove it from API calls and clean it up lazily later. Updates tailscale/corp#1626 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-23ipn/ipnlocal: add file sharing to windows shellAleksandar Pesic2-32/+28
Updates: tailscale/winmin#33 Signed-off-by: Aleksandar Pesic <peske.nis@gmail.com>
2021-04-23ipn/ipnlocal: add a LocalBackend.Start fast path if already runningBrad Fitzpatrick2-13/+53
Updates tailscale/corp#1621 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-23ipn/ipnlocal: close peer API listeners on transition away from RunningBrad Fitzpatrick1-8/+21
Updates tailscale/corp#1621 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-22ipn: define NewBackendServer nil as not affecting Backend's NotifyCallbackBrad Fitzpatrick2-1/+13
Updates tailscale/corp#1646 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-22ipn/ipnlocal: use fallback default DNS whenever exit nodes are on.David Anderson1-7/+13
Fixes #1625 Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-22ipn/ipnlocal: add peerapi goroutine fetchBrad Fitzpatrick2-1/+36
Between owners. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-22ipn/ipnlocal: put a retry loop around Windows file deletesBrad Fitzpatrick2-7/+89
oh, Windows. Updates tailscale/corp#1626 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-22ipn/ipnlocal: fix approxSize operator precedenceBrad Fitzpatrick1-1/+1
Whoops. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-22ipn/ipnlocal: log on DeleteFile errorBrad Fitzpatrick1-0/+4
Updates tailscale/corp#1626 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-21ipn/ipnlocal: fix tailscale status --json AuthURL fieldBrad Fitzpatrick1-3/+10
It was getting cleared on notify. Document that authURL is cleared on notify and add a new field that isn't, using the new field for the JSON status. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-21ipn/ipnlocal: on fresh lazy-connecting install, start in state NeedsLoginBrad Fitzpatrick2-0/+52
Fixes #1759 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20cmd/tailscaled: don't block ipnserver startup behind engine init on WindowsBrad Fitzpatrick1-41/+1
With this change, the ipnserver's safesocket.Listen (the localhost tcp.Listen) happens right away, before any synchronous TUN/DNS/Engine/etc setup work, which might be slow, especially on early boot on Windows. Because the safesocket.Listen starts up early, that means localhost TCP dials (the safesocket.Connect from the GUI) complete successfully and thus the GUI avoids the MessageBox error. (I verified that pacifies it, even without a Listener.Accept; I'd feared that Windows localhost was maybe special and avoided the normal listener backlog). Once the GUI can then connect immediately without errors, the various timeouts then matter less, because the backend is no longer trying to race against the GUI's timeout. So keep retrying on errors for a minute, or 10 minutes if the system just booted in the past 10 minutes. This should fix the problem with Windows 10 desktops auto-logging in and starting the Tailscale frontend which was then showing a MessageBox error about failing to connect to tailscaled, which was slow coming up because the Windows networking stack wasn't up yet. Fingers crossed. Fixes #1313 (previously #1187, etc) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20ipn/ipnlocal: add arpa suffixes to MagicDNS for reverse lookups.David Anderson1-1/+13
This used to not be necessary, because MagicDNS always did full proxying. But with split DNS, we need to know which names to route to our resolver, otherwise reverse lookups break. This captures the entire CGNAT range, as well as our Tailscale ULA. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-20ipn/ipnlocal: only set authoritative domains when using MagicDNS.David Anderson1-1/+1
Otherwise, the existence of authoritative domains forces full DNS proxying even when no other DNS config is present. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-20ipn: don't Logout when Windows GUI disconnectsBrad Fitzpatrick3-18/+27
Logout used to be a no-op, so the ipnserver previously synthensized a Logout on disconnect. Now that Logout actually invalidates the node key that was forcing all GUI closes to log people out. Instead, add a method to LocalBackend to specifically mean "the Windows GUI closed, please forget all the state". Fixes tailscale/corp#1591 (ignoring the notification issues, tracked elsewhere) Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20ipn/ipnlocal: plumb fallback DNS in as a workaround for split DNS issues.David Anderson1-6/+31
Cause of #1743. Signed-off-by: David Anderson <danderson@tailscale.com>
2021-04-20ipn{,/ipnlocal}: in direct file receive mode, don't rename partial fileBrad Fitzpatrick2-22/+24
Let caller (macOS) do it so Finder progress bar can be dismissed without races. Updates tailscale/corp#1575 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20ipn/ipnlocal: only fix peerapiListener on Windows when runningBrad Fitzpatrick1-1/+1
It's just logspam otherwise. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-20ipn/ipnlocal: restrict local lan access to linux machines.Maisem Ali1-10/+13
Signed-off-by: Maisem Ali <maisem@tailscale.com>
2021-04-19ipn/ipnlocal: finish/fix up filename validation & encoding on diskBrad Fitzpatrick2-5/+251
It used to just store received files URL-escaped on disk, but that was a half done lazy implementation, and pushed the burden to callers to validate and write things to disk in an unescaped way. Instead, do all the validation in the receive handler and only accept filenames that are UTF-8 and in the intersection of valid names that all platforms support. Fixes tailscale/corp#1594 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-04-19ipn/ipnlocal: add some more peerapi handlePeerPut testsBrad Fitzpatrick2-4/+80
Updates tailscale/corp#1594 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>