tailscale/net/interfaces
Andrea Gottardo d9aeb30281
net/interfaces: handle iOS network transitions (#10680)
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>
2024-01-04 09:40:18 -08:00
..
defaultroute_bsd.go net/interfaces: handle iOS network transitions (#10680) 2024-01-04 09:40:18 -08:00
defaultroute_ios.go net/interfaces: handle iOS network transitions (#10680) 2024-01-04 09:40:18 -08:00
interfaces.go net/interfaces: better handle multiple interfaces in LikelyHomeRouterIP 2023-12-20 15:33:58 -05:00
interfaces_bsd.go net/interfaces: handle iOS network transitions (#10680) 2024-01-04 09:40:18 -08:00
interfaces_darwin.go ipn/ipnlocal: add delegated interface information to /interfaces PeerAPI handler 2023-02-27 09:39:49 -08:00
interfaces_darwin_test.go net/interfaces: better handle multiple interfaces in LikelyHomeRouterIP 2023-12-20 15:33:58 -05:00
interfaces_default_route_test.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_defaultrouteif_todo.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00
interfaces_freebsd.go net/interfaces: redo how we get the default interface on macOS and iOS 2023-02-10 16:23:37 -08:00
interfaces_linux.go net/interfaces: better handle multiple interfaces in LikelyHomeRouterIP 2023-12-20 15:33:58 -05:00
interfaces_linux_test.go all: use tstest.Replace more 2023-03-04 12:24:55 -08:00
interfaces_test.go net/interfaces: better handle multiple interfaces in LikelyHomeRouterIP 2023-12-20 15:33:58 -05:00
interfaces_windows.go net/interfaces: better handle multiple interfaces in LikelyHomeRouterIP 2023-12-20 15:33:58 -05:00
interfaces_windows_test.go all: update copyright and license headers 2023-01-27 15:36:29 -08:00