From 4055b63b9b5f4662254cd4a5d926265e9ff7734f Mon Sep 17 00:00:00 2001 From: Andrea Gottardo Date: Fri, 2 Aug 2024 12:23:48 -0700 Subject: [PATCH] net/captivedetection: exclude cellular data interfaces (#13002) Updates tailscale/tailscale#1634 This PR optimizes captive portal detection on Android and iOS by excluding cellular data interfaces (`pdp*` and `rmnet`). As cellular networks do not present captive portals, frequent network switches between Wi-Fi and cellular would otherwise trigger captive detection unnecessarily, causing battery drain. Signed-off-by: Andrea Gottardo --- net/captivedetection/captivedetection.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/captivedetection/captivedetection.go b/net/captivedetection/captivedetection.go index df0030c7d..e0a4b0a25 100644 --- a/net/captivedetection/captivedetection.go +++ b/net/captivedetection/captivedetection.go @@ -106,13 +106,19 @@ func (d *Detector) detectCaptivePortalWithGOOS(ctx context.Context, netMon *netm return false } +// interfaceNameDoesNotNeedCaptiveDetection returns true if an interface does not require captive portal detection +// based on its name. This is useful to avoid making unnecessary HTTP requests on interfaces that are known to not +// require it. We also avoid making requests on the interface prefixes "pdp" and "rmnet", which are cellular data +// interfaces on iOS and Android, respectively, and would be needlessly battery-draining. func interfaceNameDoesNotNeedCaptiveDetection(ifName string, goos string) bool { ifName = strings.ToLower(ifName) excludedPrefixes := []string{"tailscale", "tun", "tap", "docker", "kube", "wg"} if goos == "windows" { excludedPrefixes = append(excludedPrefixes, "loopback", "tunnel", "ppp", "isatap", "teredo", "6to4") } else if goos == "darwin" || goos == "ios" { - excludedPrefixes = append(excludedPrefixes, "awdl", "bridge", "ap", "utun", "tap", "llw", "anpi", "lo", "stf", "gif", "xhc") + excludedPrefixes = append(excludedPrefixes, "pdp", "awdl", "bridge", "ap", "utun", "tap", "llw", "anpi", "lo", "stf", "gif", "xhc", "pktap") + } else if goos == "android" { + excludedPrefixes = append(excludedPrefixes, "rmnet", "p2p", "dummy", "sit") } for _, prefix := range excludedPrefixes { if strings.HasPrefix(ifName, prefix) {