Use localOptions to clarify context

localOptions = cfg.configuration
This commit is contained in:
Davide De Rosa 2022-09-25 16:48:47 +02:00
parent 6018c30cc4
commit 5c84c15416
1 changed files with 13 additions and 13 deletions

View File

@ -640,13 +640,13 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
} }
var dnsSettings: NEDNSSettings? var dnsSettings: NEDNSSettings?
if cfg.configuration.isDNSEnabled ?? true { if localOptions.isDNSEnabled ?? true {
var dnsServers: [String] = [] var dnsServers: [String] = []
if #available(iOS 14, macOS 11, *) { if #available(iOS 14, macOS 11, *) {
switch cfg.configuration.dnsProtocol { switch localOptions.dnsProtocol {
case .https: case .https:
dnsServers = cfg.configuration.dnsServers ?? [] dnsServers = localOptions.dnsServers ?? []
guard let serverURL = cfg.configuration.dnsHTTPSURL else { guard let serverURL = localOptions.dnsHTTPSURL else {
break break
} }
let specific = NEDNSOverHTTPSSettings(servers: dnsServers) let specific = NEDNSOverHTTPSSettings(servers: dnsServers)
@ -656,8 +656,8 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
log.info("\tHTTPS URL: \(serverURL.maskedDescription)") log.info("\tHTTPS URL: \(serverURL.maskedDescription)")
case .tls: case .tls:
dnsServers = cfg.configuration.dnsServers ?? [] dnsServers = localOptions.dnsServers ?? []
guard let serverName = cfg.configuration.dnsTLSServerName else { guard let serverName = localOptions.dnsTLSServerName else {
break break
} }
let specific = NEDNSOverTLSSettings(servers: dnsServers) let specific = NEDNSOverTLSSettings(servers: dnsServers)
@ -674,7 +674,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
// fall back // fall back
if dnsSettings == nil { if dnsSettings == nil {
dnsServers = [] dnsServers = []
if let servers = cfg.configuration.dnsServers, if let servers = localOptions.dnsServers,
!servers.isEmpty { !servers.isEmpty {
dnsServers = servers dnsServers = servers
} else if let servers = options.dnsServers { } else if let servers = options.dnsServers {
@ -695,7 +695,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
dnsSettings?.matchDomains = [""] dnsSettings?.matchDomains = [""]
} }
if let searchDomains = cfg.configuration.searchDomains ?? options.searchDomains { if let searchDomains = localOptions.searchDomains ?? options.searchDomains {
log.info("DNS: Using search domains \(searchDomains.maskedDescription)") log.info("DNS: Using search domains \(searchDomains.maskedDescription)")
dnsSettings?.domainName = searchDomains.first dnsSettings?.domainName = searchDomains.first
dnsSettings?.searchDomains = searchDomains dnsSettings?.searchDomains = searchDomains
@ -717,14 +717,14 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
} }
var proxySettings: NEProxySettings? var proxySettings: NEProxySettings?
if cfg.configuration.isProxyEnabled ?? true { if localOptions.isProxyEnabled ?? true {
if let httpsProxy = cfg.configuration.httpsProxy ?? options.httpsProxy { if let httpsProxy = cfg.configuration.httpsProxy ?? options.httpsProxy {
proxySettings = NEProxySettings() proxySettings = NEProxySettings()
proxySettings?.httpsServer = httpsProxy.neProxy() proxySettings?.httpsServer = httpsProxy.neProxy()
proxySettings?.httpsEnabled = true proxySettings?.httpsEnabled = true
log.info("Routing: Setting HTTPS proxy \(httpsProxy.address.maskedDescription):\(httpsProxy.port)") log.info("Routing: Setting HTTPS proxy \(httpsProxy.address.maskedDescription):\(httpsProxy.port)")
} }
if let httpProxy = cfg.configuration.httpProxy ?? options.httpProxy { if let httpProxy = localOptions.httpProxy ?? options.httpProxy {
if proxySettings == nil { if proxySettings == nil {
proxySettings = NEProxySettings() proxySettings = NEProxySettings()
} }
@ -732,7 +732,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
proxySettings?.httpEnabled = true proxySettings?.httpEnabled = true
log.info("Routing: Setting HTTP proxy \(httpProxy.address.maskedDescription):\(httpProxy.port)") log.info("Routing: Setting HTTP proxy \(httpProxy.address.maskedDescription):\(httpProxy.port)")
} }
if let pacURL = cfg.configuration.proxyAutoConfigurationURL ?? options.proxyAutoConfigurationURL { if let pacURL = localOptions.proxyAutoConfigurationURL ?? options.proxyAutoConfigurationURL {
if proxySettings == nil { if proxySettings == nil {
proxySettings = NEProxySettings() proxySettings = NEProxySettings()
} }
@ -742,7 +742,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
} }
// only set if there is a proxy (proxySettings set to non-nil above) // only set if there is a proxy (proxySettings set to non-nil above)
if let bypass = cfg.configuration.proxyBypassDomains ?? options.proxyBypassDomains { if let bypass = localOptions.proxyBypassDomains ?? options.proxyBypassDomains {
proxySettings?.exceptionList = bypass proxySettings?.exceptionList = bypass
log.info("Routing: Setting proxy by-pass list: \(bypass.maskedDescription)") log.info("Routing: Setting proxy by-pass list: \(bypass.maskedDescription)")
} }
@ -790,7 +790,7 @@ extension OpenVPNTunnelProvider: OpenVPNSessionDelegate {
newSettings.ipv6Settings = ipv6Settings newSettings.ipv6Settings = ipv6Settings
newSettings.dnsSettings = dnsSettings newSettings.dnsSettings = dnsSettings
newSettings.proxySettings = proxySettings newSettings.proxySettings = proxySettings
if let mtu = cfg.configuration.mtu, mtu > 0 { if let mtu = localOptions.mtu, mtu > 0 {
newSettings.mtu = NSNumber(value: mtu) newSettings.mtu = NSNumber(value: mtu)
} }