Fix DNS in VPN when not default gateway

Awful API requires .matchDomains = [""]

Fixes #94
This commit is contained in:
Davide De Rosa 2019-04-27 23:08:39 +02:00
parent b331e3cfe6
commit ebabf02eb5
2 changed files with 11 additions and 4 deletions

View File

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Broken DNS when no servers provided. [#84](https://github.com/keeshux/tunnelkit/issues/84)
- UDP may disconnect on high-speed upload link. [#87](https://github.com/keeshux/tunnelkit/issues/87)
- Client certificate may fail when private key in .ovpn is encrypted. [#91](https://github.com/keeshux/tunnelkit/issues/91)
- DNS is unreachable when VPN is not default gateway. [#94](https://github.com/keeshux/tunnelkit/issues/94)
## 1.6.2 (2019-04-17)

View File

@ -537,6 +537,7 @@ extension TunnelKitProvider: SessionProxyDelegate {
let routingPolicies = configuration.routingPolicies ?? reply.options.routingPolicies
let isIPv4Gateway = routingPolicies?.contains(.IPv4) ?? false
let isIPv6Gateway = routingPolicies?.contains(.IPv6) ?? false
let isGateway = isIPv4Gateway || isIPv6Gateway
var ipv4Settings: NEIPv4Settings?
if let ipv4 = reply.options.ipv4 {
@ -592,7 +593,6 @@ extension TunnelKitProvider: SessionProxyDelegate {
ipv6Settings?.excludedRoutes = []
}
var dnsSettings: NEDNSSettings?
var dnsServers = cfg.sessionConfiguration.dnsServers ?? reply.options.dnsServers ?? []
// fall back
@ -601,10 +601,16 @@ extension TunnelKitProvider: SessionProxyDelegate {
dnsServers = fallbackDNSServers
}
dnsSettings = NEDNSSettings(servers: dnsServers)
let dnsSettings = NEDNSSettings(servers: dnsServers)
if !isGateway {
dnsSettings.matchDomains = [""]
}
if let searchDomain = cfg.sessionConfiguration.searchDomain ?? reply.options.searchDomain {
dnsSettings?.domainName = searchDomain
dnsSettings?.searchDomains = [searchDomain]
dnsSettings.domainName = searchDomain
dnsSettings.searchDomains = [searchDomain]
if !isGateway {
dnsSettings.matchDomains = dnsSettings.searchDomains
}
}
var proxySettings: NEProxySettings?