aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-02-16 19:57:31 +0530
committerRoopesh Chander <roop@roopc.net>2019-02-16 19:57:31 +0530
commitba3f0db92c141b7b6c300d0644a1679cee23b77b (patch)
treef6adb6cb090181e0e4f7b026189d1958ebb24de9
parentmacOS: Exclude private IPs (diff)
downloadwireguard-apple-ba3f0db92c141b7b6c300d0644a1679cee23b77b.tar.xz
wireguard-apple-ba3f0db92c141b7b6c300d0644a1679cee23b77b.zip
TunnelViewModel: Remove DNS from AllowedIPs when unchecking 'Exclude private IPs'
Signed-off-by: Roopesh Chander <roop@roopc.net>
-rw-r--r--WireGuard/WireGuard/UI/TunnelViewModel.swift9
1 files changed, 7 insertions, 2 deletions
diff --git a/WireGuard/WireGuard/UI/TunnelViewModel.swift b/WireGuard/WireGuard/UI/TunnelViewModel.swift
index 8f95039d..b299bea1 100644
--- a/WireGuard/WireGuard/UI/TunnelViewModel.swift
+++ b/WireGuard/WireGuard/UI/TunnelViewModel.swift
@@ -424,12 +424,17 @@ class TunnelViewModel {
shouldStronglyRecommendDNS = allowedIPStrings.contains(TunnelViewModel.PeerData.ipv4DefaultRouteString) || allowedIPStrings.isSuperset(of: TunnelViewModel.PeerData.ipv4DefaultRouteModRFC1918String)
}
+ static func normalizedIPAddressRangeStrings(_ list: [String]) -> [String] {
+ return list.compactMap { IPAddressRange(from: $0) }.map { $0.stringRepresentation }
+ }
+
static func modifiedAllowedIPs(currentAllowedIPs: [String], excludePrivateIPs: Bool, dnsServers: [String]) -> [String] {
- let ipv6Addresses = currentAllowedIPs.filter { $0.contains(":") }
+ let normalizedDNSServers = normalizedIPAddressRangeStrings(dnsServers)
+ let ipv6Addresses = normalizedIPAddressRangeStrings(currentAllowedIPs.filter { $0.contains(":") })
if excludePrivateIPs {
return ipv6Addresses + TunnelViewModel.PeerData.ipv4DefaultRouteModRFC1918String + dnsServers
} else {
- return ipv6Addresses + [TunnelViewModel.PeerData.ipv4DefaultRouteString]
+ return ipv6Addresses.filter { !normalizedDNSServers.contains($0) } + [TunnelViewModel.PeerData.ipv4DefaultRouteString]
}
}