summaryrefslogtreecommitdiffhomepage
path: root/net/netmon
AgeCommit message (Collapse)AuthorFilesLines
2025-08-15net/{netns, netmon}: use LastKnownDefaultInterface if set and check for utun ↵Jonathan Nobels2-40/+88
(#16873) fixes tailscale/corp#31299 Fixes two issues: getInterfaceIndex would occasionally race with netmon's state, returning the cached default interface index after it had be changed by NWNetworkMonitor. This had the potential to cause connections to bind to the prior default. The fix here is to preferentially use the interface index provided by NWNetworkMonitor preferentially. When no interfaces are available, macOS will set the tunnel as the default interface when an exit node is enabled, potentially causing getInterfaceIndex to return utun's index. We now guard against this when taking the defaultIdx path. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
2025-08-05wgengine/router: rely on events for deleted IP rules (#16744)Claus Lensbøl2-50/+4
Adds the eventbus to the router subsystem. The event is currently only used on linux. Also includes facilities to inject events into the bus. Updates #15160 Signed-off-by: Claus Lensbøl <claus@tailscale.com>
2025-06-25net/netmon: add tests for the events over the eventbus (#16382)Claus Lensbøl1-4/+32
Updates #15160 Signed-off-by: Claus Lensbøl <claus@tailscale.com>
2025-04-16net/netmon: publish events to event busDavid Anderson8-18/+73
Updates #15160 Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-02net/netmon: disable time jump monitoring on Plan 9Brad Fitzpatrick1-1/+1
Updates #5794 Change-Id: I0f96383dea2ad017988d300df723ce906debb007 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-03-31net/netmon: always remember ifState as old state, even on minor changesBrad Fitzpatrick1-1/+1
Otherwise you can get stuck finding minor ones nonstop. Fixes #15484 Change-Id: I7f98ac338c0b32ec1b9fdc47d053207b5fc1bf23 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-03-24net/netmon: use Monitor's tsIfName if set by SetTailscaleInterfaceNameBrad Fitzpatrick3-8/+10
Currently nobody calls SetTailscaleInterfaceName yet, so this is a no-op. I checked oss, android, and the macOS/iOS client. Nobody calls this, or ever did. But I want to in the future. Updates #15408 Updates #9040 Change-Id: I05dfabe505174f9067b929e91c6e0d8bc42628d7 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-03-24net/netmon: unexport GetStateBrad Fitzpatrick3-3/+3
Baby step towards #15408. Updates #15408 Change-Id: I11fca6e677af2ad2f065d83aa0d83550143bff29 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-03-12net/netmon, wgengine/magicsock: be quieter with portmapper logsAndrew Dunham2-0/+120
This adds a new helper to the netmon package that allows us to rate-limit log messages, so that they only print once per (major) LinkChange event. We then use this when constructing the portmapper, so that we don't keep spamming logs forever on the same network. Updates #13145 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I6e7162509148abea674f96efd76be9dffb373ae4
2025-02-03net/netmon: add extra panic guard around ParseRIBJames Tucker1-1/+13
We once again have a report of a panic from ParseRIB. This panic guard should probably remain permanent. Updates #14201 This reverts commit de9d4b2f886b6bf5cf0fe9be6c17d080267acef1. Signed-off-by: James Tucker <james@tailscale.com>
2025-01-14net/netmon: trim IPv6 endpoints in already routable subnetsJames Tucker1-1/+16
We have observed some clients with extremely large lists of IPv6 endpoints, in some cases from subnets where the machine also has the zero address for a whole /48 with then arbitrary addresses additionally assigned within that /48. It is in general unnecessary for reachability to report all of these addresses, typically only one will be necessary for reachability. We report two, to cover some other common cases such as some styles of IPv6 private address rotations. Updates tailscale/corp#25850 Signed-off-by: James Tucker <james@tailscale.com>
2025-01-07net/netmon: remove extra panic guard around ParseRIBJames Tucker1-12/+1
This was an extra defense added for #14201 that is no longer required. Fixes #14201 Signed-off-by: James Tucker <james@tailscale.com>
2024-11-25net/netmon: improve panic reporting from #14202James Tucker1-2/+5
I was hoping we'd catch an example input quickly, but the reporter had rebooted their machine and it is no longer exhibiting the behavior. As such this code may be sticking around quite a bit longer and we might encounter other errors, so include the panic in the log entry. Updates #14201 Updates #14202 Updates golang/go#70528 Signed-off-by: James Tucker <james@tailscale.com>
2024-11-22net/netmon: catch ParseRIB panic to gather buffer dataJames Tucker1-1/+9
Updates #14201 Updates golang/go#70528 Signed-off-by: James Tucker <james@tailscale.com>
2024-11-05types/result, util/lineiter: add package for a result type, use itBrad Fitzpatrick4-62/+52
This adds a new generic result type (motivated by golang/go#70084) to try it out, and uses it in the new lineutil package (replacing the old lineread package), changing that package to return iterators: sometimes over []byte (when the input is all in memory), but sometimes iterators over results of []byte, if errors might happen at runtime. Updates #12912 Updates golang/go#70084 Change-Id: Iacdc1070e661b5fb163907b1e8b07ac7d51d3f83 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-08-22all: fix new lint warnings from bumping staticcheckBrad Fitzpatrick1-43/+0
In prep for updating to new staticcheck required for Go 1.23. Updates #12912 Change-Id: If77892a023b79c6fa798f936fc80428fd4ce0673 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-07-10all: add test for package comments, fix, add comments as neededBrad Fitzpatrick1-1/+0
Updates #cleanup Change-Id: Ic4304e909d2131a95a38b26911f49e7b1729aaef Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-05-01net/netmon: remove spammy log statements (#11953)Jonathan Nobels1-2/+0
Updates tailscale/corp#18960 Tests in corp called us using the wrong logging calls. Removed. This is logged downstream anyway. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
2024-05-01net/netmon: swap to swift-derived defaultRoute on macos (#11936)Jonathan Nobels2-34/+24
Updates tailscale/corp#18960 iOS uses Apple's NetworkMonitor to track the default interface and there's no reason we shouldn't also use this on macOS, for the same reasons noted in the comments for why this change was made on iOS. This eliminates the need to load and parse the routing table when querying the defaultRouter() in almost all cases. A slight modification here (on both platforms) to fallback to the default BSD logic in the unhappy-path rather than making assumptions that may not hold. If netmon is eventually parsing AF_ROUTE and able to give a consistently correct answer for the default interface index, we can fall back to that and eliminate the Swift dependency. Signed-off-by: Jonathan Nobels <jonathan@tailscale.com>
2024-04-28net/{interfaces,netmon}, all: merge net/interfaces package into net/netmonBrad Fitzpatrick17-9/+2646
In prep for most of the package funcs in net/interfaces to become methods in a long-lived netmon.Monitor that can cache things. (Many of the funcs are very heavy to call regularly, whereas the long-lived netmon.Monitor can subscribe to things from the OS and remember answers to questions it's asked regularly later) Updates tailscale/corp#10910 Updates tailscale/corp#18960 Updates #7967 Updates #3299 Change-Id: Ie4e8dedb70136af2d611b990b865a822cd1797e5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-04-28net/netmon, add: add netmon.State type alias of interfaces.StateBrad Fitzpatrick2-7/+15
... in prep for merging the net/interfaces package into net/netmon. This is a no-op change that updates a bunch of the API signatures ahead of a future change to actually move things (and remove the type alias) Updates tailscale/corp#10910 Updates tailscale/corp#18960 Updates #7967 Updates #3299 Change-Id: I477613388f09389214db0d77ccf24a65bff2199c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-04-27net/netns, net/dns/resolver, etc: make netmon required in most placesBrad Fitzpatrick1-0/+34
The goal is to move more network state accessors to netmon.Monitor where they can be cheaper/cached. But first (this change and others) we need to make sure the one netmon.Monitor is plumbed everywhere. Some notable bits: * tsdial.NewDialer is added, taking a now-required netmon * because a tsdial.Dialer always has a netmon, anything taking both a Dialer and a NetMon is now redundant; take only the Dialer and get the NetMon from that if/when needed. * netmon.NewStatic is added, primarily for tests Updates tailscale/corp#10910 Updates tailscale/corp#18960 Updates #7967 Updates #3299 Change-Id: I877f9cb87618c4eb037cee098241d18da9c01691 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-01-12net/netmon: when a new network is added, trigger netmon update (#10840)kari-ts1-0/+22
Fixes #10107
2023-12-21all: cleanup unused code, part 2 (#10670)Andrew Lytvynov2-7/+7
And enable U1000 check in staticcheck. Updates #cleanup Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
2023-12-21net/netmon: fix goroutine leak in winMon if the monitor is never startedNick Khyl2-1/+30
When the portable Monitor creates a winMon via newOSMon, we register address and route change callbacks with Windows. Once a callback is hit, it starts a goroutine that attempts to send the event into messagec and returns. The newly started goroutine then blocks until it can send to the channel. However, if the monitor is never started and winMon.Receive is never called, the goroutines remain indefinitely blocked, leading to goroutine leaks and significant memory consumption in the tailscaled service process on Windows. Unlike the tailscaled subprocess, the service process creates but never starts a Monitor. This PR adds a check within the callbacks to confirm the monitor's active status, and exits immediately if the monitor hasn't started. Updates #9864 Signed-off-by: Nick Khyl <nickk@tailscale.com>
2023-09-12net/netmon: log when the gateway/self IP changesAndrew Dunham1-1/+7
This logs that the gateway/self IP address has changed if one of the new values differs. Updates #8992 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: I0919424b68ad97fbe1204dd36317ed6f5915411f
2023-09-02net/netmon, net/tsdial: add some link change metricsBrad Fitzpatrick1-0/+16
Updates #9040 Change-Id: I2c87572d79d2118bcf1f0122eccfe712c1bea9d5 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-08-29net/{interfaces,netmon}: remove "interesting", EqualFiltered APIBrad Fitzpatrick2-3/+229
This removes a lot of API from net/interfaces (including all the filter types, EqualFiltered, active Tailscale interface func, etc) and moves the "major" change detection to net/netmon which knows more about the world and the previous/new states. Updates #9040 Change-Id: I7fe66a23039c6347ae5458745b709e7ebdcce245 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-08-23net/netmon: factor out debounce loop, simplify polling implBrad Fitzpatrick2-48/+71
This simplifies some netmon code in prep for other changes. It breaks up Monitor.debounce into a helper method so locking is easier to read and things unindent, and then it simplifies the polling netmon implementation to remove the redundant stuff that the caller (the Monitor.debounce loop) was already basically doing. Updates #9040 Change-Id: Idcfb45201d00ae64017042a7bdee6ef86ad37a9f Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-08-23net/netmon: make ChangeFunc's signature take new ChangeDelta, not boolBrad Fitzpatrick2-17/+47
Updates #9040 Change-Id: Ia43752064a1a6ecefc8802b58d6eaa0b71cf1f84 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-06-27all: adjust case of "IPv4" and "IPv6"Brad Fitzpatrick1-1/+1
Updates #docs Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2023-04-20all: move network monitoring from wgengine/monitor to net/netmonMihai Parparita10-0/+1477
We're using it in more and more places, and it's not really specific to our use of Wireguard (and does more just link/interface monitoring). Also removes the separate interface we had for it in sockstats -- it's a small enough package (we already pull in all of its dependencies via other paths) that it's not worth the extra complexity. Updates #7621 Updates #7850 Signed-off-by: Mihai Parparita <mihai@tailscale.com>