mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-27 03:55:36 +00:00
d9aeb30281
Updates #8022 Updates #6075 On iOS, we currently rely on delegated interface information to figure out the default route interface. The NetworkExtension framework in iOS seems to set the delegate interface only once, upon the *creation* of the VPN tunnel. If a network transition (e.g. from Wi-Fi to Cellular) happens while the tunnel is connected, it will be ignored and we will still try to set Wi-Fi as the default route because the delegated interface is not getting updated as connectivity transitions. Here we work around this on the Swift side with a NWPathMonitor instance that observes the interface name of the first currently satisfied network path. Our Swift code will call into `UpdateLastKnownDefaultRouteInterface`, so we can rely on that when it is set. If for any reason the Swift machinery didn't work and we don't get any updates, here we also have some fallback logic: we try finding a hardcoded Wi-Fi interface called en0. If en0 is down, we fall back to cellular (pdp_ip0) as a last resort. This doesn't handle all edge cases like USB-Ethernet adapters or multiple Ethernet interfaces, but it is good enough to ensure connectivity isn't broken. I tested this on iPhones and iPads running iOS 17.1 and it appears to work. Switching between different cellular plans on a dual SIM configuration also works (the interface name remains pdp_ip0). Signed-off-by: Andrea Gottardo <andrea@tailscale.com>
27 lines
610 B
Go
27 lines
610 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Common code for FreeBSD and Darwin. This might also work on other
|
|
// BSD systems (e.g. OpenBSD) but has not been tested.
|
|
// Not used on iOS. See defaultroute_ios.go.
|
|
|
|
//go:build !ios && (darwin || freebsd)
|
|
|
|
package interfaces
|
|
|
|
import "net"
|
|
|
|
func defaultRoute() (d DefaultRouteDetails, err error) {
|
|
idx, err := DefaultRouteInterfaceIndex()
|
|
if err != nil {
|
|
return d, err
|
|
}
|
|
iface, err := net.InterfaceByIndex(idx)
|
|
if err != nil {
|
|
return d, err
|
|
}
|
|
d.InterfaceName = iface.Name
|
|
d.InterfaceIndex = idx
|
|
return d, nil
|
|
}
|