summaryrefslogtreecommitdiffhomepage
path: root/portlist
AgeCommit message (Collapse)AuthorFilesLines
2026-01-23all: remove AUTHORS file and references to itWill Norris12-12/+12
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
2025-12-10portlist: skip tests on Linux 6.14.x with /proc/net/tcp bug (#18185)Simon Law1-0/+1
PR #18033 skipped tests for the versions of Linux 6.6 and 6.12 that had a regression in /proc/net/tcp that causes seek operations to fail with “illegal seek”. This PR skips tests for Linux 6.14.0, which is the default Ubuntu kernel, that also contains this regression. Updates #16966 Signed-off-by: Simon Law <sfllaw@tailscale.com>
2025-11-21portlist,tstest: skip tests on kernels with /proc/net/tcp regressionAndrew Dunham1-0/+15
Linux kernel versions 6.6.102-104 and 6.12.42-45 have a regression in /proc/net/tcp that causes seek operations to fail with "illegal seek". This breaks portlist tests on these kernels. Add kernel version detection for Linux systems and a SkipOnKernelVersions helper to tstest. Use it to skip affected portlist tests on the broken kernel versions. Thanks to philiptaron for the list of kernels with the issue and fix. Updates #16966 Signed-off-by: Andrew Dunham <andrew@tailscale.com>
2025-04-02portlist: add Plan 9 supportBrad Fitzpatrick1-0/+122
Updates #5794 Change-Id: I77df1eb9bea9f079a25337cb7bbd498cf8a19135 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-04-16all: use Go 1.22 range-over-intBrad Fitzpatrick2-4/+4
Updates #11058 Change-Id: I35e7ef9b90e83cac04ca93fd964ad00ed5b48430 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-12-21all: cleanup unused code, part 2 (#10670)Andrew Lytvynov1-2/+0
And enable U1000 check in staticcheck. Updates #cleanup Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
2023-12-05all: fix nilness issuesMatt Layher1-1/+1
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2023-10-04portlist: populate Pid field on LinuxBrad Fitzpatrick2-2/+4
The Port.Pid was always more of an implementation detail on some platforms and isn't necessary on Linux so it was never populated. (Nothing outside the portlist package ever used it) But might as well populate it for consistency since we have it in memory and its absence confused people. Updates #cleanup Change-Id: I869768a75c9fedeff242a5452206e2b2947a17cb Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-08-17all: use Go 1.21 slices, maps instead of x/exp/{slices,maps}Brad Fitzpatrick1-1/+1
Updates #8419 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-06-07portlist: remove async functionalityMarwan Sulaiman2-194/+20
This PR removes all async functionality from the portlist package which may be a breaking change for non-tailscale importers. The only importer within this codebase (LocalBackend) is already using the synchronous API so no further action needed. Fixes #8171 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
2023-06-05portlist: add a synchronous Poll methodMarwan Sulaiman2-25/+87
This is a follow up on PR #8172 that adds a synchronous Poll method which allows for the Poller to be used as a zero value without needing the constructor. The local backend is also changed to use the new API. A follow up PR will remove the async functionality from the portlist package. Updates #8171 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
2023-05-24portlist: add Poller.IncludeLocalhost optionMarwan Sulaiman9-64/+88
This PR parameterizes receiving loopback updates from the portlist package. Callers can now include services bound to localhost if they want. Note that this option is off by default still. Fixes #8171 Signed-off-by: Marwan Sulaiman <marwan@tailscale.com>
2023-04-17various: add golangci-lint, fix issues (#7905)Andrew Dunham1-3/+3
This adds an initial and intentionally minimal configuration for golang-ci, fixes the issues reported, and adds a GitHub Action to check new pull requests against this linter configuration. Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I8f38fbc315836a19a094d0d3e986758b9313f163
2023-01-27all: update copyright and license headersWill Norris11-33/+22
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
2022-12-19netstat, portlist: update Windows implementation to disambiguate svchost ↵Aaron Klotz1-29/+10
processes We change our invocations of GetExtendedTcpTable to request additional information about the "module" responsible for the port. In addition to pid, this output also includes sufficient metadata to enable Windows to resolve process names and disambiguate svchost processes. We store the OS-specific output in an OSMetadata field in netstat.Entry, which portlist may then use as necessary to actually resolve the process/module name. Signed-off-by: Aaron Klotz <aaron@tailscale.com>
2022-11-18portlist: wait for lsof cmd to exitMaisem Ali1-0/+9
We were leaking processes otherwise. Co-authored-by: Mihai Parparita <mihai@tailscale.com> Signed-off-by: Maisem Ali <maisem@tailscale.com>
2022-11-14portlist: fix data raceBrad Fitzpatrick2-10/+85
Maisem spotted the bug. The initial getList call in NewPoller wasn't making a clone (only the Run loop's getList calls). Fixes #6314 Change-Id: I8ab8799fcccea8e799140340d0ff88a825bb6ff0 Co-authored-by: Maisem Ali <maisem@tailscale.com> Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-11-05util/dirwalk, metrics, portlist: add new package for fast directory walkingBrad Fitzpatrick2-78/+71
This is similar to the golang.org/x/tools/internal/fastwalk I'd previously written but not recursive and using mem.RO. The metrics package already had some Linux-specific directory reading code in it. Move that out to a new general package that can be reused by portlist too, which helps its scanning of all /proc files: name old time/op new time/op delta FindProcessNames-8 2.79ms ± 6% 2.45ms ± 7% -12.11% (p=0.000 n=10+10) name old alloc/op new alloc/op delta FindProcessNames-8 62.9kB ± 0% 33.5kB ± 0% -46.76% (p=0.000 n=9+10) name old allocs/op new allocs/op delta FindProcessNames-8 2.25k ± 0% 0.38k ± 0% -82.98% (p=0.000 n=9+10) Change-Id: I75db393032c328f12d95c39f71c9742c375f207a Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-11-04portlist: add macOS osImpl, finish migration to new styleBrad Fitzpatrick10-290/+239
Previously: * 036f70b7b4 for linux * 35bee36549 for windows This does macOS. And removes all the compat code for the old style. (e.g. iOS, js are no longer mentioned; all platforms without implementations just default to not doing anything) One possible regression is that platforms without explicit implementations previously tried to do the "netstat -na" style to get open ports (but not process names). Maybe that worked on FreeBSD and OpenBSD previously, but nobody ever really tested it. And it was kinda useless without associated process names. So better off removing those for now until they get a good implementation. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-11-04all: remove old +build tagsBrad Fitzpatrick6-8/+0
The //go:build syntax was introduced in Go 1.17: https://go.dev/doc/go1.17#build-lines gofmt has kept the +build and go:build lines in sync since then, but enough time has passed. Time to remove them. Done with: perl -i -npe 's,^// \+build.*\n,,' $(git grep -l -F '+build') Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-25portlist: use win32 calls instead of running netstat process [windows]Brad Fitzpatrick2-28/+101
Turns out using win32 instead of shelling out to child processes is a bit faster: name old time/op new time/op delta GetListIncremental-4 278ms ± 2% 0ms ± 7% -99.93% (p=0.000 n=8+10) name old alloc/op new alloc/op delta GetListIncremental-4 238kB ± 0% 9kB ± 0% -96.12% (p=0.000 n=10+8) name old allocs/op new allocs/op delta GetListIncremental-4 1.19k ± 0% 0.02k ± 0% -98.49% (p=0.000 n=10+10) Fixes #3876 (sadly) Change-Id: I1195ac5de21a8a8b3cdace5871d263e81aa27e91 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-23portlist: add a test that verifies changes are picked up over timeBrad Fitzpatrick1-0/+50
To avoid annoying firewall dialogs on macOS and Windows, only run it on Linux by default without the flag. Change-Id: If8486c31d4243ade54b0131f673237c6c9184c08 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-23portlist: refactor, introduce OS-specific typesBrad Fitzpatrick6-244/+278
Add an osImpl interface that can be stateful and thus more efficient between calls. It will later be implemented by all OSes but for now this change only adds a Linux implementation. Remove Port.inode. It was only used by Linux and moves into its osImpl. Don't reopen /proc/net/* files on each run. Turns out you can just keep then open and seek to the beginning and reread and the contents are fresh. name old time/op new time/op delta GetListIncremental-8 7.29ms ± 2% 6.53ms ± 1% -10.50% (p=0.000 n=9+9) name old alloc/op new alloc/op delta GetListIncremental-8 1.30kB ±13% 0.70kB ± 5% -46.38% (p=0.000 n=9+10) name old allocs/op new allocs/op delta GetListIncremental-8 33.2 ±11% 18.0 ± 0% -45.82% (p=0.000 n=9+10) Updates #5958 Change-Id: I4be83463cbd23c2e2fa5d0bdf38560004f53401b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-22portlist: add package doc, file comments, move a method to the right fileBrad Fitzpatrick2-25/+35
And respect envknob earlier. NewPoller has one caller and ignores errors; they just signal ipnlocal to log a warning and not use the portlist poller. Change-Id: I4a33af936fe780cca8c7197d4d74ac31a1dc01e3 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-22portlist: add BenchmarkGetListIncrementalBrad Fitzpatrick1-1/+12
In contrast to BenchmarkGetList, this new BenchmarkGetListIncremental acts like what happens in practice, remembering the previous run and avoiding work that's already been done previously. Currently: BenchmarkGetList BenchmarkGetList-8 100 11011100 ns/op 68411 B/op 2211 allocs/op BenchmarkGetList-8 100 11443410 ns/op 69073 B/op 2223 allocs/op BenchmarkGetList-8 100 11217311 ns/op 68421 B/op 2197 allocs/op BenchmarkGetList-8 100 11035559 ns/op 68801 B/op 2220 allocs/op BenchmarkGetList-8 100 10921596 ns/op 69226 B/op 2225 allocs/op BenchmarkGetListIncremental BenchmarkGetListIncremental-8 168 7187217 ns/op 1192 B/op 28 allocs/op BenchmarkGetListIncremental-8 172 7004525 ns/op 1194 B/op 28 allocs/op BenchmarkGetListIncremental-8 162 7235889 ns/op 1221 B/op 29 allocs/op BenchmarkGetListIncremental-8 164 7035671 ns/op 1219 B/op 29 allocs/op BenchmarkGetListIncremental-8 174 7095448 ns/op 1114 B/op 27 allocs/op Updates #5958 Change-Id: I1bd5a4b206df4173e2cb8e8a780429d9daa6ef1d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-22portlist: remove unix.Readlink allocs on LinuxBrad Fitzpatrick1-2/+25
name old time/op new time/op delta GetList-8 11.2ms ± 5% 11.1ms ± 3% ~ (p=0.661 n=10+9) name old alloc/op new alloc/op delta GetList-8 83.3kB ± 1% 67.4kB ± 1% -19.05% (p=0.000 n=10+10) name old allocs/op new allocs/op delta GetList-8 2.89k ± 2% 2.19k ± 1% -24.24% (p=0.000 n=10+10) (real issue is we're calling this code as much as we are, but easy enough to make it efficient because it'll still need to be called sometimes in any case) Updates #5958 Change-Id: I90c20278d73e80315a840aed1397d24faa308d93 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-22portlist: further reduce allocations on LinuxBrad Fitzpatrick3-14/+47
Make Linux parsePorts also an append-style API and attach it to caller's provided append base memory. And add a little string intern pool in front of the []byte to string for inode names. name old time/op new time/op delta GetList-8 11.1ms ± 4% 9.8ms ± 6% -11.68% (p=0.000 n=9+10) name old alloc/op new alloc/op delta GetList-8 92.8kB ± 2% 79.7kB ± 0% -14.11% (p=0.000 n=10+9) name old allocs/op new allocs/op delta GetList-8 2.94k ± 1% 2.76k ± 0% -6.16% (p=0.000 n=10+10) More coming. (the bulk of the allocations are in addProcesses and filesystem operations, most of which we should usually be able to skip) Updates #5958 Change-Id: I3f0c03646d314a16fef7f8346aefa7d5c96701e7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-22portlist: unexport all Poller fields, removing unused one, rework channelsBrad Fitzpatrick1-30/+41
Poller.C and Poller.c were duplicated for one caller. Add an accessor returning the receive-only version instead. It'll inline. Poller.Err was unused. Remove. Then Poller is opaque. The channel usage and shutdown was a bit sketchy. Clean it up. And document some things. Change-Id: I5669e54f51a6a13492cf5485c83133bda7ea3ce9 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-21portlist: update some internals to use append-style APIsBrad Fitzpatrick13-36/+53
In prep for reducing garbage, being able to reuse memory. So far this doesn't actually reuse much. This is just changing signatures around. But some improvement in any case: bradfitz@tsdev:~/src/tailscale.com$ ~/go/bin/benchstat before after name old time/op new time/op delta GetList-8 11.8ms ± 9% 9.9ms ± 3% -15.98% (p=0.000 n=10+10) name old alloc/op new alloc/op delta GetList-8 99.5kB ± 2% 91.9kB ± 0% -7.62% (p=0.000 n=9+9) name old allocs/op new allocs/op delta GetList-8 3.05k ± 1% 2.93k ± 0% -3.83% (p=0.000 n=8+9) More later, once parsers can reuse strings from previous parses. Updates #5958 Change-Id: I76cd5048246dd24d11c4e263d8bb8041747fb2b0 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-10-21portlist: unexport GetListBrad Fitzpatrick3-6/+6
It's an internal implementation detail, and I plan to refactor it for performance (garbage) reasons anyway, so start by hiding it. Updates #5958 Change-Id: I2c0d1f743d3495c5f798d1d8afc364692cd9d290 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-09-15refactor: move from io/ioutil to io and os packagesEng Zer Jun1-2/+1
The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit replaces the existing io/ioutil functions with their new definitions in io and os packages. Reference: https://golang.org/doc/go1.16#ioutil Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-09-15envknob: support changing envknobs post-initBrad Fitzpatrick1-2/+2
Updates #5114 Change-Id: Ia423fc7486e1b3f3180a26308278be0086fae49b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-09-15portlist: normalise space delimited process names (#5634)Kristoffer Dalby2-0/+19
2022-08-04syncs, all: move to using Go's new atomic types instead of oursBrad Fitzpatrick1-5/+5
Fixes #5185 Change-Id: I850dd532559af78c3895e2924f8237ccc328449d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-06-06wasm: exclude code that's not used on iOS for Wasm tooMihai Parparita2-3/+4
It has similar size constraints. Saves ~1.9MB from the Wasm build. Updates #3157 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
2022-01-24envknob: add new package for all the strconv.ParseBool(os.Getenv(..))Brad Fitzpatrick1-3/+3
A new package can also later record/report which knobs are checked and set. It also makes the code cleaner & easier to grep for env knobs. Change-Id: Id8a123ab7539f1fadbd27e0cbeac79c2e4f09751 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-12-15all: gofmt -w -s (simplify) testsBrad Fitzpatrick1-7/+7
And it updates the build tag style on a couple files. Change-Id: I84478d822c8de3f84b56fa1176c99d2ea5083237 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-10-20all: fix some js/wasm compilation issuesBrad Fitzpatrick2-2/+19
Change-Id: I05a3a4835e225a1e413ec3540a7c7e4a2d477084 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-09-16portlist: add debug knob to disable portlist collectionBrad Fitzpatrick1-0/+7
For big servers. Per discussion with @crawshaw. Updates tailscale/corp#2566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-09-14portlist: stop logging stray UDP portsJosh Bleecher Snyder1-4/+1
These "weird" port lines show up in logs frequently. They're the result of uninteresting races, and they're not actionable. Remove the noise. Remove the isLoopbackAddr case to placate staticcheck. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-09-13portlist: cache field index position between runs, cut two more allocs (Linux)Brad Fitzpatrick1-4/+33
name old time/op new time/op delta ParsePorts-6 6.41ms ± 7% 3.15ms ± 2% -50.84% (p=0.000 n=9+9) name old alloc/op new alloc/op delta ParsePorts-6 408B ± 0% 216B ± 0% -47.06% (p=0.002 n=8+10) name old allocs/op new allocs/op delta ParsePorts-6 7.00 ± 0% 4.00 ± 0% -42.86% (p=0.000 n=10+10) Updates tailscale/corp#2566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-09-13portlist: reuse bufio.Reader between filesBrad Fitzpatrick2-8/+21
name old time/op new time/op delta ListPorts-6 1.18ms ± 5% 1.16ms ± 5% ~ (p=0.075 n=10+10) name old alloc/op new alloc/op delta ListPorts-6 27.2kB ± 0% 14.9kB ± 0% -45.14% (p=0.001 n=8+9) name old allocs/op new allocs/op delta ListPorts-6 90.0 ± 0% 84.0 ± 0% -6.67% (p=0.000 n=10+10) Updates tailscale/corp#2566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-09-13portlist: reduce CPU parsing portlistBrad Fitzpatrick2-15/+79
Avoid splitting fields in the common case. Field splitting was 84% of the overall CPU. name old time/op new time/op delta ParsePorts-6 33.3ms ± 2% 6.3ms ± 4% -80.97% (p=0.000 n=9+10) name old alloc/op new alloc/op delta ParsePorts-6 520B ±79% 408B ± 0% -21.49% (p=0.046 n=10+8) name old allocs/op new allocs/op delta ParsePorts-6 7.00 ± 0% 7.00 ± 0% ~ (all equal) Updates tailscale/corp#2566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-09-12portlist: reduce allocs on LinuxBrad Fitzpatrick2-13/+54
Notably, it no longer allocates proportional to the number of open sockets on the machine. Any alloc reduction numbers are a little contrived with such a reduction but e.g. on a machine with 50,000 connections open: name old time/op new time/op delta ParsePorts-6 57.7ms ± 6% 32.8ms ± 3% -43.04% (p=0.000 n=9+10) name old alloc/op new alloc/op delta ParsePorts-6 24.0MB ± 0% 0.0MB ± 0% -100.00% (p=0.000 n=10+9) name old allocs/op new allocs/op delta ParsePorts-6 100k ± 0% 0k ± 0% -99.99% (p=0.000 n=10+10) Updates tailscale/corp#2566 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-08-18portlist: fix build tag to build only on macOS, not macOS+iOS.David Anderson1-2/+2
2021-08-17all: simplify build tags involving iOSJosh Bleecher Snyder4-9/+8
Prior to Go 1.16, iOS used GOOS=darwin, so we had to distinguish macOS from iOS during GOARCH. We now require Go 1.16 in our go.mod, so we can simplify. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-08-05all: gofmt with Go 1.17Josh Bleecher Snyder5-0/+5
This adds "//go:build" lines and tidies up existing "// +build" lines. Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-06-18staticcheck.conf: turn off noisy lint errorsDavid Crawshaw1-1/+1
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-05-04portlist: suppress staticcheck errorJosh Bleecher Snyder1-1/+1
Signed-off-by: Josh Bleecher Snyder <josharian@gmail.com>
2021-04-13portlist: de-dup services on same (proto, port) on both IPv4/IPv6Brad Fitzpatrick2-6/+21
Fixes #1703 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>