From 28fd80f4e09e60401685b0d587236b9331ef5cbd Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 17 Apr 2019 00:42:07 +0200 Subject: [PATCH 1/3] Treat empty DNS servers as nil Empty local DNS array was pretty much hiding server-pushed DNS. --- TunnelKit/Sources/AppExtension/TunnelKitProvider.swift | 5 ++++- TunnelKit/Sources/Core/ConfigurationParser.swift | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index 83e3fef..6152ac8 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -560,7 +560,10 @@ extension TunnelKitProvider: SessionProxyDelegate { ipv6Settings?.excludedRoutes = [] } - let dnsServers = cfg.sessionConfiguration.dnsServers ?? reply.options.dnsServers + var dnsServers = cfg.sessionConfiguration.dnsServers + if dnsServers?.isEmpty ?? true { + dnsServers = reply.options.dnsServers + } let searchDomain = cfg.sessionConfiguration.searchDomain ?? reply.options.searchDomain let dnsSettings = NEDNSSettings(servers: dnsServers ?? []) dnsSettings.domainName = searchDomain diff --git a/TunnelKit/Sources/Core/ConfigurationParser.swift b/TunnelKit/Sources/Core/ConfigurationParser.swift index 390ac20..fbfe683 100644 --- a/TunnelKit/Sources/Core/ConfigurationParser.swift +++ b/TunnelKit/Sources/Core/ConfigurationParser.swift @@ -199,7 +199,7 @@ public class ConfigurationParser { var optGateway4Arguments: [String]? var optRoutes4: [(String, String, String?)] = [] // address, netmask, gateway var optRoutes6: [(String, UInt8, String?)] = [] // destination, prefix, gateway - var optDNSServers: [String] = [] + var optDNSServers: [String]? var optSearchDomain: String? var optHTTPProxy: Proxy? var optHTTPSProxy: Proxy? @@ -482,7 +482,10 @@ public class ConfigurationParser { guard $0.count == 2 else { return } - optDNSServers.append($0[1]) + if optDNSServers == nil { + optDNSServers = [] + } + optDNSServers?.append($0[1]) } Regex.domain.enumerateArguments(in: line) { guard $0.count == 2 else { From b199064b94c994a0c80b178863b2e3c17f668184 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 17 Apr 2019 00:45:08 +0200 Subject: [PATCH 2/3] Only override domain if non-nil --- TunnelKit/Sources/AppExtension/TunnelKitProvider.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index 6152ac8..c9b8142 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -564,10 +564,9 @@ extension TunnelKitProvider: SessionProxyDelegate { if dnsServers?.isEmpty ?? true { dnsServers = reply.options.dnsServers } - let searchDomain = cfg.sessionConfiguration.searchDomain ?? reply.options.searchDomain let dnsSettings = NEDNSSettings(servers: dnsServers ?? []) - dnsSettings.domainName = searchDomain - if let searchDomain = searchDomain { + if let searchDomain = cfg.sessionConfiguration.searchDomain ?? reply.options.searchDomain { + dnsSettings.domainName = searchDomain dnsSettings.searchDomains = [searchDomain] } From 233aa02169ba59a72edac18310838bd1049dcb63 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Wed, 17 Apr 2019 00:46:34 +0200 Subject: [PATCH 3/3] Add FIXME for default DNS from network interface --- TunnelKit/Sources/AppExtension/TunnelKitProvider.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index c9b8142..5f2ae7e 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -564,6 +564,7 @@ extension TunnelKitProvider: SessionProxyDelegate { if dnsServers?.isEmpty ?? true { dnsServers = reply.options.dnsServers } + // FIXME: default to DNS servers from current network instead let dnsSettings = NEDNSSettings(servers: dnsServers ?? []) if let searchDomain = cfg.sessionConfiguration.searchDomain ?? reply.options.searchDomain { dnsSettings.domainName = searchDomain