summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMihai Parparita <mihai@tailscale.com>2023-04-18 09:44:59 -0700
committerMihai Parparita <mihai.parparita@gmail.com>2023-04-18 09:57:15 -0700
commitc7cea825aea39a00aca71ea02bab7266afc03e7c (patch)
tree7d89200d3f8719e74a37fcce2f749094e1b8b0de
parent280255acae604796a1113861f5a84e6fa2dc6121 (diff)
downloadtailscale-c7cea825aea39a00aca71ea02bab7266afc03e7c.tar.xz
tailscale-c7cea825aea39a00aca71ea02bab7266afc03e7c.zip
net/netns: don't log errors when we can't get the default route on Darwin
It's somewhat common (e.g. when a phone has no reception), and leads to lots of logspam. Updates #7850 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
-rw-r--r--net/interfaces/interfaces_bsd.go6
-rw-r--r--net/netns/netns_darwin.go7
2 files changed, 11 insertions, 2 deletions
diff --git a/net/interfaces/interfaces_bsd.go b/net/interfaces/interfaces_bsd.go
index 99c82e166..2b63908d9 100644
--- a/net/interfaces/interfaces_bsd.go
+++ b/net/interfaces/interfaces_bsd.go
@@ -35,6 +35,10 @@ func defaultRoute() (d DefaultRouteDetails, err error) {
return d, nil
}
+// ErrNoGatewayIndexFound is returned by DefaultRouteInterfaceIndex when no
+// default route is found.
+var ErrNoGatewayIndexFound = errors.New("no gateway index found")
+
// DefaultRouteInterfaceIndex returns the index of the network interface that
// owns the default route. It returns the first IPv4 or IPv6 default route it
// finds (it does not prefer one or the other).
@@ -75,7 +79,7 @@ func DefaultRouteInterfaceIndex() (int, error) {
return rm.Index, nil
}
}
- return 0, errors.New("no gateway index found")
+ return 0, ErrNoGatewayIndexFound
}
func init() {
diff --git a/net/netns/netns_darwin.go b/net/netns/netns_darwin.go
index 50d7fcaad..c24c51102 100644
--- a/net/netns/netns_darwin.go
+++ b/net/netns/netns_darwin.go
@@ -61,7 +61,12 @@ func getInterfaceIndex(logf logger.Logf, address string) (int, error) {
defaultIdx := func() (int, error) {
idx, err := interfaces.DefaultRouteInterfaceIndex()
if err != nil {
- logf("[unexpected] netns: DefaultRouteInterfaceIndex: %v", err)
+ // It's somewhat common for there to be no default gateway route
+ // (e.g. on a phone with no connectivity), don't log those errors
+ // since they are expected.
+ if !errors.Is(err, interfaces.ErrNoGatewayIndexFound) {
+ logf("[unexpected] netns: DefaultRouteInterfaceIndex: %v", err)
+ }
return -1, err
}
return idx, nil