mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-27 11:32:24 +00:00
net/interfaces: cache "home" router lookup on big Linux routers
This is a continuation of the earlier 2a67beaacf but more aggressive; this now remembers that we failed to find the "home" router IP so we don't try again later on the next call. Updates #7621 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
c5150eae67
commit
162488a775
@ -98,7 +98,22 @@ func likelyHomeRouterIPLinux() (ret netip.Addr, ok bool) {
|
|||||||
}
|
}
|
||||||
log.Printf("interfaces: failed to read /proc/net/route: %v", err)
|
log.Printf("interfaces: failed to read /proc/net/route: %v", err)
|
||||||
}
|
}
|
||||||
return ret, ret.IsValid()
|
if ret.IsValid() {
|
||||||
|
return ret, true
|
||||||
|
}
|
||||||
|
if lineNum >= maxProcNetRouteRead {
|
||||||
|
// If we went over our line limit without finding an answer, assume
|
||||||
|
// we're a big fancy Linux router (or at least not a home system)
|
||||||
|
// and set the error bit so we stop trying this in the future (and wasting CPU).
|
||||||
|
// See https://github.com/tailscale/tailscale/issues/7621.
|
||||||
|
//
|
||||||
|
// Remember that "likelyHomeRouterIP" exists purely to find the port
|
||||||
|
// mapping service (UPnP, PMP, PCP) often present on a home router. If we hit
|
||||||
|
// the route (line) limit without finding an answer, we're unlikely to ever
|
||||||
|
// find one in the future.
|
||||||
|
procNetRouteErr.Store(true)
|
||||||
|
}
|
||||||
|
return netip.Addr{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Android apps don't have permission to read /proc/net/route, at
|
// Android apps don't have permission to read /proc/net/route, at
|
||||||
|
Loading…
x
Reference in New Issue
Block a user