You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
High CPU and network bandwidth usage at special gateways #5879
System version: macOS 12.6 (21G115) / M1 Max(arm64)
What happened
The tailscaled process consumes a lot of CPU and sends a lot of traffic to the derper server.
Steps to reproduce
Allow me to start with my findings:
When used with some other network proxy tools (such as Surge), if other tools set a proxy gateway (such as Surge enhanced mode will set the default gateway to 198.18.0.1), tailsaled seems to be unable to read the default gateway, which will cause tailscaled Stuck in some infinite loop.
Use the netstat -rn command to confirm that the default gateway is set to 198.18.0.1
Restart tailscaled several times with tailscale down && tailscale up command
The tailscaled process will continue to consume a lot of CPU and keep sending a lot of traffic to the derper
Log
To describe the problem more clearly, I modified the launchd configuration and generated the log(I submitted a PR #5878 incidentally to enable log files by default):
Are there any recent changes that introduced the issue?
I tried looking at the code and it seems that there is a problem in the interfaces_darwin.go code, guessing that the impactful change might start with 04c2c5bd80e86b2113d4e04e840d79ec66981fda.
Well, I don't fully understand the code; but I have it working fine with some modifications:
diff --git a/net/interfaces/interfaces_darwin.go b/net/interfaces/interfaces_darwin.go
index 60335bf8..a72c6fd5 100644
--- a/net/interfaces/interfaces_darwin.go+++ b/net/interfaces/interfaces_darwin.go@@ -59,7 +59,6 @@ func DefaultRouteInterfaceIndex() (int, error) {
if err != nil {
return 0, fmt.Errorf("route.ParseRIB: %w", err)
}
- indexSeen := map[int]int{} // index => count
for _, m := range msgs {
rm, ok := m.(*route.RouteMessage)
if !ok {
@@ -73,17 +72,9 @@ func DefaultRouteInterfaceIndex() (int, error) {
if rm.Flags&RTF_IFSCOPE != 0 {
continue
}
- indexSeen[rm.Index]+++ return rm.Index, nil
}
- if len(indexSeen) == 0 {- return 0, errors.New("no gateway index found")- }- if len(indexSeen) == 1 {- for idx := range indexSeen {- return idx, nil- }- }- return 0, fmt.Errorf("ambiguous gateway interfaces found: %v", indexSeen)+ return 0, errors.New("no gateway index found")
}
func init() {
My understanding is that the DefaultRouteInterfaceIndex method is trying to find the main route interface, but I think if multiple interfaces are found, it is better to use the first one found instead of the hardcoded index 0 interface used (my understanding may be wrong) . Finally I provide my routing table for reference:
My understanding is that the DefaultRouteInterfaceIndex method is trying to find the main route interface, but I think if multiple interfaces are found, it is better to use the first one found instead of the hardcoded index 0 interface used (my understanding may be wrong)
DefaultRouteInterfaceIndex expects to find at most one network interface that has a route configured without the RTF_IFSCOPE flag (the I in netstat -r output). Since it examines both v4 and v6 routing tables and does not actually look at the route prefix, the ambiguous gateway interfaces found error can appear when v4 and v6 routes use different interfaces, or when a machine has static routes configured on a non-default interface.
For example, on my Mac that has two active interfaces and a static route, DefaultRouteInterfaceIndex will find three different interfaces as evidenced by a simple tool that duplicates its logic:
I think a reasonable way forward would be to adjust DefaultRouteInterfaceIndex to filter by route prefix and only care about interfaces that have routes to 0.0.0.0/0 or ::/0. If default routes for IPv4 and IPv6 go via different interfaces, we could either return the first one, or add logic to prefer one over the other. @bradfitz – any thoughts?
Activity
devin-integration-bot commentedon Oct 9, 2022
The current location is caused by the receiveIPv4 method in magicsock.go
devin-integration-bot commentedon Oct 9, 2022
Well, I don't fully understand the code; but I have it working fine with some modifications:
My understanding is that the
DefaultRouteInterfaceIndexmethod is trying to find the main route interface, but I think if multiple interfaces are found, it is better to use the first one found instead of the hardcodedindex 0interface used (my understanding may be wrong) . Finally I provide my routing table for reference:knyar commentedon Oct 12, 2022
DefaultRouteInterfaceIndexexpects to find at most one network interface that has a route configured without theRTF_IFSCOPEflag (theIinnetstat -routput). Since it examines both v4 and v6 routing tables and does not actually look at the route prefix, theambiguous gateway interfaces founderror can appear when v4 and v6 routes use different interfaces, or when a machine has static routes configured on a non-default interface.For example, on my Mac that has two active interfaces and a static route,
DefaultRouteInterfaceIndexwill find three different interfaces as evidenced by a simple tool that duplicates its logic:Routing table of this machine:
I think a reasonable way forward would be to adjust
DefaultRouteInterfaceIndexto filter by route prefix and only care about interfaces that have routes to0.0.0.0/0or::/0. If default routes for IPv4 and IPv6 go via different interfaces, we could either return the first one, or add logic to prefer one over the other. @bradfitz – any thoughts?net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection
net/interfaces: improve default route detection