Add options to exclude APNs route

This commit is contained in:
世界
2024-03-11 17:40:25 +08:00
parent 4109942f31
commit 95e9bc5fb2
3 changed files with 26 additions and 0 deletions
@@ -28,6 +28,7 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
}
let autoRouteUseSubRangesByDefault = await SharedPreferences.autoRouteUseSubRangesByDefault.get()
let excludeAPNs = await SharedPreferences.excludeAPNsRoute.get()
let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
if options.getAutoRoute() {
@@ -84,6 +85,13 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
ipv4ExcludeRoutes.append(NEIPv4Route(destinationAddress: "0.0.0.0", subnetMask: "255.255.255.254"))
}
}
if excludeAPNs, !ipv4Routes.isEmpty {
if !ipv4ExcludeRoutes.contains(where: { it in
it.destinationAddress == "17.0.0.0" && it.destinationSubnetMask == "255.0.0.0"
}) {
ipv4ExcludeRoutes.append(NEIPv4Route(destinationAddress: "17.0.0.0", subnetMask: "255.0.0.0"))
}
}
ipv4Settings.includedRoutes = ipv4Routes
ipv4Settings.excludedRoutes = ipv4ExcludeRoutes
@@ -140,6 +148,9 @@ public class ExtensionPlatformInterface: NSObject, LibboxPlatformInterfaceProtoc
proxySettings.httpEnabled = true
proxySettings.httpsEnabled = true
}
if excludeAPNs {
proxySettings.exceptionList = ["push.apple.com"]
}
settings.proxySettings = proxySettings
}