From 7382616e8b34d3c04f9dbd6ae69b5b92ff5b426d Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Thu, 25 Apr 2019 14:09:27 +0200 Subject: [PATCH] Parse routing policies for TunnelKitProvider --- .../TunnelKitProvider+Configuration.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift index 96e61e7..b977ffc 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Configuration.swift @@ -176,6 +176,14 @@ extension TunnelKitProvider { sessionConfigurationBuilder.httpsProxy = proxy } sessionConfigurationBuilder.proxyBypassDomains = providerConfiguration[S.proxyBypassDomains] as? [String] + if let routingPoliciesStrings = providerConfiguration[S.routingPolicies] as? [String], !routingPoliciesStrings.isEmpty { + sessionConfigurationBuilder.routingPolicies = try routingPoliciesStrings.map { + guard let policy = SessionProxy.RoutingPolicy(rawValue: $0) else { + throw ProviderConfigurationError.parameter(name: "protocolConfiguration.providerConfiguration[\(S.routingPolicies)] has a badly formed element") + } + return policy + } + } sessionConfiguration = sessionConfigurationBuilder.build() shouldDebug = providerConfiguration[S.debug] as? Bool ?? ConfigurationBuilder.defaults.shouldDebug @@ -259,6 +267,8 @@ extension TunnelKitProvider { static let proxyBypassDomains = "ProxyBypassDomains" + static let routingPolicies = "RoutingPolicies" + // MARK: Debugging static let debug = "Debug" @@ -471,6 +481,9 @@ extension TunnelKitProvider { if let proxyBypassDomains = sessionConfiguration.proxyBypassDomains { dict[S.proxyBypassDomains] = proxyBypassDomains } + if let routingPolicies = sessionConfiguration.routingPolicies { + dict[S.routingPolicies] = routingPolicies.map { $0.rawValue } + } // if let resolvedAddresses = resolvedAddresses { dict[S.resolvedAddresses] = resolvedAddresses @@ -559,6 +572,12 @@ extension TunnelKitProvider { if sessionConfiguration.randomizeEndpoint ?? false { log.info("\tRandomize endpoint: true") } + // FIXME: refine logging of other routing policies + if let routingPolicies = sessionConfiguration.routingPolicies { + log.info("\tDefault gateway: \(routingPolicies.map { $0.rawValue })") + } else { + log.info("\tDefault gateway: no") + } if let dnsServers = sessionConfiguration.dnsServers { log.info("\tDNS servers: \(dnsServers.maskedDescription)") }