Merge branch 'multiple-search-domains'

This commit is contained in:
Davide De Rosa 2019-10-25 19:11:37 +02:00
commit 0ab913fb24
5 changed files with 39 additions and 22 deletions

View File

@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow keep-alive timeout to be configured by the server or client (Robert Patchett). [#122](https://github.com/passepartoutvpn/tunnelkit/pull/122) - Allow keep-alive timeout to be configured by the server or client (Robert Patchett). [#122](https://github.com/passepartoutvpn/tunnelkit/pull/122)
- Support for proxy autoconfiguration URL (ThinkChaos). [#125](https://github.com/passepartoutvpn/tunnelkit/pull/125) - Support for proxy autoconfiguration URL (ThinkChaos). [#125](https://github.com/passepartoutvpn/tunnelkit/pull/125)
- Support multiple DNS search domains. [#127](https://github.com/passepartoutvpn/tunnelkit/issues/127)
### Fixed ### Fixed

View File

@ -177,7 +177,7 @@ extension OpenVPNTunnelProvider {
static let dnsServers = "DNSServers" static let dnsServers = "DNSServers"
static let searchDomain = "SearchDomain" static let searchDomains = "SearchDomains"
static let httpProxy = "HTTPProxy" static let httpProxy = "HTTPProxy"
@ -519,8 +519,8 @@ private extension OpenVPN.Configuration {
if let dnsServers = providerConfiguration[S.dnsServers] as? [String] { if let dnsServers = providerConfiguration[S.dnsServers] as? [String] {
builder.dnsServers = dnsServers builder.dnsServers = dnsServers
} }
if let searchDomain = providerConfiguration[S.searchDomain] as? String { if let searchDomains = providerConfiguration[S.searchDomains] as? [String] {
builder.searchDomain = searchDomain builder.searchDomains = searchDomains
} }
if let proxyString = providerConfiguration[S.httpProxy] as? String { if let proxyString = providerConfiguration[S.httpProxy] as? String {
guard let proxy = Proxy(rawValue: proxyString) else { guard let proxy = Proxy(rawValue: proxyString) else {
@ -599,8 +599,8 @@ private extension OpenVPN.Configuration {
if let dnsServers = dnsServers { if let dnsServers = dnsServers {
dict[S.dnsServers] = dnsServers dict[S.dnsServers] = dnsServers
} }
if let searchDomain = searchDomain { if let searchDomains = searchDomains {
dict[S.searchDomain] = searchDomain dict[S.searchDomains] = searchDomains
} }
if let httpProxy = httpProxy { if let httpProxy = httpProxy {
dict[S.httpProxy] = httpProxy.rawValue dict[S.httpProxy] = httpProxy.rawValue
@ -680,8 +680,8 @@ private extension OpenVPN.Configuration {
} else { } else {
log.info("\tDNS: not configured") log.info("\tDNS: not configured")
} }
if let searchDomain = searchDomain, !searchDomain.isEmpty { if let searchDomains = searchDomains, !searchDomains.isEmpty {
log.info("\tSearch domain: \(searchDomain.maskedDescription)") log.info("\tSearch domains: \(searchDomains.maskedDescription)")
} }
if let httpProxy = httpProxy { if let httpProxy = httpProxy {
log.info("\tHTTP proxy: \(httpProxy.maskedDescription)") log.info("\tHTTP proxy: \(httpProxy.maskedDescription)")

View File

@ -506,10 +506,10 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
} else { } else {
log.info("\tDNS: not configured") log.info("\tDNS: not configured")
} }
if let searchDomain = options.searchDomain, !searchDomain.isEmpty { if let searchDomains = options.searchDomains, !searchDomains.isEmpty {
log.info("\tDomain: \(searchDomain.maskedDescription)") log.info("\tSearch domains: \(searchDomains.maskedDescription)")
} else { } else {
log.info("\tDomain: not configured") log.info("\tSearch domains: not configured")
} }
if options.httpProxy != nil || options.httpsProxy != nil || options.proxyAutoConfigurationURL != nil { if options.httpProxy != nil || options.httpsProxy != nil || options.proxyAutoConfigurationURL != nil {
@ -652,9 +652,10 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
if !isGateway { if !isGateway {
dnsSettings.matchDomains = [""] dnsSettings.matchDomains = [""]
} }
if let searchDomain = cfg.sessionConfiguration.searchDomain ?? options.searchDomain { if let searchDomains = cfg.sessionConfiguration.searchDomains ?? options.searchDomains {
dnsSettings.domainName = searchDomain log.info("DNS: Using search domains \(searchDomains.maskedDescription)")
dnsSettings.searchDomains = [searchDomain] dnsSettings.domainName = searchDomains.first
dnsSettings.searchDomains = searchDomains
if !isGateway { if !isGateway {
dnsSettings.matchDomains = dnsSettings.searchDomains dnsSettings.matchDomains = dnsSettings.searchDomains
} }

View File

@ -245,7 +245,19 @@ extension OpenVPN {
public var dnsServers: [String]? public var dnsServers: [String]?
/// The search domain. /// The search domain.
public var searchDomain: String? @available(*, deprecated, message: "Use searchDomains instead")
public var searchDomain: String? {
didSet {
guard let searchDomain = searchDomain else {
searchDomains = nil
return
}
searchDomains = [searchDomain]
}
}
/// The search domains. The first one is interpreted as the main domain name.
public var searchDomains: [String]?
/// The Proxy Auto-Configuration (PAC) url. /// The Proxy Auto-Configuration (PAC) url.
public var proxyAutoConfigurationURL: URL? public var proxyAutoConfigurationURL: URL?
@ -295,7 +307,7 @@ extension OpenVPN {
ipv4: ipv4, ipv4: ipv4,
ipv6: ipv6, ipv6: ipv6,
dnsServers: dnsServers, dnsServers: dnsServers,
searchDomain: searchDomain, searchDomains: searchDomains,
httpProxy: httpProxy, httpProxy: httpProxy,
httpsProxy: httpsProxy, httpsProxy: httpsProxy,
proxyAutoConfigurationURL: proxyAutoConfigurationURL, proxyAutoConfigurationURL: proxyAutoConfigurationURL,
@ -391,8 +403,8 @@ extension OpenVPN {
/// - Seealso: `ConfigurationBuilder.dnsServers` /// - Seealso: `ConfigurationBuilder.dnsServers`
public let dnsServers: [String]? public let dnsServers: [String]?
/// - Seealso: `ConfigurationBuilder.searchDomain` /// - Seealso: `ConfigurationBuilder.searchDomains`
public let searchDomain: String? public let searchDomains: [String]?
/// - Seealso: `ConfigurationBuilder.httpProxy` /// - Seealso: `ConfigurationBuilder.httpProxy`
public let httpProxy: Proxy? public let httpProxy: Proxy?
@ -461,7 +473,7 @@ extension OpenVPN.Configuration {
builder.ipv4 = ipv4 builder.ipv4 = ipv4
builder.ipv6 = ipv6 builder.ipv6 = ipv6
builder.dnsServers = dnsServers builder.dnsServers = dnsServers
builder.searchDomain = searchDomain builder.searchDomains = searchDomains
builder.httpProxy = httpProxy builder.httpProxy = httpProxy
builder.httpsProxy = httpsProxy builder.httpsProxy = httpsProxy
builder.proxyAutoConfigurationURL = proxyAutoConfigurationURL builder.proxyAutoConfigurationURL = proxyAutoConfigurationURL

View File

@ -225,7 +225,7 @@ extension OpenVPN {
var optRoutes4: [(String, String, String?)] = [] // address, netmask, gateway var optRoutes4: [(String, String, String?)] = [] // address, netmask, gateway
var optRoutes6: [(String, UInt8, String?)] = [] // destination, prefix, gateway var optRoutes6: [(String, UInt8, String?)] = [] // destination, prefix, gateway
var optDNSServers: [String]? var optDNSServers: [String]?
var optSearchDomain: String? var optSearchDomains: [String]?
var optHTTPProxy: Proxy? var optHTTPProxy: Proxy?
var optHTTPSProxy: Proxy? var optHTTPSProxy: Proxy?
var optProxyAutoConfigurationURL: URL? var optProxyAutoConfigurationURL: URL?
@ -531,7 +531,10 @@ extension OpenVPN {
guard $0.count == 2 else { guard $0.count == 2 else {
return return
} }
optSearchDomain = $0[1] if optSearchDomains == nil {
optSearchDomains = []
}
optSearchDomains?.append($0[1])
} }
Regex.proxy.enumerateArguments(in: line) { Regex.proxy.enumerateArguments(in: line) {
if $0.count == 2 { if $0.count == 2 {
@ -738,7 +741,7 @@ extension OpenVPN {
} }
sessionBuilder.dnsServers = optDNSServers sessionBuilder.dnsServers = optDNSServers
sessionBuilder.searchDomain = optSearchDomain sessionBuilder.searchDomains = optSearchDomains
sessionBuilder.httpProxy = optHTTPProxy sessionBuilder.httpProxy = optHTTPProxy
sessionBuilder.httpsProxy = optHTTPSProxy sessionBuilder.httpsProxy = optHTTPSProxy
sessionBuilder.proxyAutoConfigurationURL = optProxyAutoConfigurationURL sessionBuilder.proxyAutoConfigurationURL = optProxyAutoConfigurationURL