Use OpenVPN trick to retain default gateway

Override default gateway with 2 split routes.

- IPv4: 0.0.0.0/1, 128.0.0.0/1
- IPv6: 2000::/4, 3000::/4
This commit is contained in:
Davide De Rosa 2019-04-27 13:31:26 +02:00
parent a047d2bdd5
commit 7d26323d3f
1 changed files with 16 additions and 6 deletions

View File

@ -538,9 +538,14 @@ extension TunnelKitProvider: SessionProxyDelegate {
// route all traffic to VPN?
if routingPolicies?.contains(.IPv4) ?? false {
let defaultRoute = NEIPv4Route.default()
defaultRoute.gatewayAddress = ipv4.defaultGateway
routes.append(defaultRoute)
// let defaultRoute = NEIPv4Route.default()
// defaultRoute.gatewayAddress = ipv4.defaultGateway
// routes.append(defaultRoute)
for network in ["0.0.0.0", "128.0.0.0"] {
let route = NEIPv4Route(destinationAddress: network, subnetMask: "128.0.0.0")
route.gatewayAddress = ipv4.defaultGateway
routes.append(route)
}
}
for r in ipv4.routes {
@ -560,9 +565,14 @@ extension TunnelKitProvider: SessionProxyDelegate {
// route all traffic to VPN?
if routingPolicies?.contains(.IPv6) ?? false {
let defaultRoute = NEIPv6Route.default()
defaultRoute.gatewayAddress = ipv6.defaultGateway
routes.append(defaultRoute)
// let defaultRoute = NEIPv6Route.default()
// defaultRoute.gatewayAddress = ipv6.defaultGateway
// routes.append(defaultRoute)
for network in ["2000::", "3000::"] {
let route = NEIPv6Route(destinationAddress: network, networkPrefixLength: 4)
route.gatewayAddress = ipv6.defaultGateway
routes.append(route)
}
}
for r in ipv6.routes {