From f799f47c256027130e348095b15fca10c8d2387b Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 28 Apr 2019 15:43:23 +0200 Subject: [PATCH] Add direct routes to DNS servers If VPN is not default gateway. Further fix of #94 --- .../Sources/AppExtension/TunnelKitProvider.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index 9325bb4..27e7d22 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -618,6 +618,17 @@ extension TunnelKitProvider: SessionProxyDelegate { } } + // add direct routes to DNS servers + if !isGateway { + for server in dnsServers { + if server.contains(":") { + ipv6Settings?.includedRoutes?.insert(NEIPv6Route(destinationAddress: server, networkPrefixLength: 128), at: 0) + } else { + ipv4Settings?.includedRoutes?.insert(NEIPv4Route(destinationAddress: server, subnetMask: "255.255.255.255"), at: 0) + } + } + } + var proxySettings: NEProxySettings? if let httpsProxy = cfg.sessionConfiguration.httpsProxy ?? reply.options.httpsProxy { proxySettings = NEProxySettings() @@ -633,7 +644,7 @@ extension TunnelKitProvider: SessionProxyDelegate { } // only set if there is a proxy (proxySettings set to non-nil above) proxySettings?.exceptionList = cfg.sessionConfiguration.proxyBypassDomains ?? reply.options.proxyBypassDomains - + let newSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: remoteAddress) newSettings.ipv4Settings = ipv4Settings newSettings.ipv6Settings = ipv6Settings