aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-11-05 06:23:26 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-11-05 06:23:26 +0100
commit8860abc89eb0cde8918e7cbc9b1883ae577555a5 (patch)
tree2258fabef35b69f7165431dcdebc4f671ddfe5e9 /WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift
parentwireguard-go-bridge: work around DWARF generation issue (diff)
downloadwireguard-apple-8860abc89eb0cde8918e7cbc9b1883ae577555a5.tar.xz
wireguard-apple-8860abc89eb0cde8918e7cbc9b1883ae577555a5.zip
TunnelsManager: account for no or many endpoints
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift')
-rw-r--r--WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift18
1 files changed, 11 insertions, 7 deletions
diff --git a/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift b/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift
index 35d4bb7c..3eabde71 100644
--- a/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift
+++ b/WireGuard/WireGuard/VPN/PacketTunnelOptionsGenerator.swift
@@ -48,19 +48,23 @@ class PacketTunnelOptionsGenerator {
// Remote address
- let remoteAddress: String
- if let firstEndpoint = resolvedEndpoints.compactMap({ $0 }).first {
- switch (firstEndpoint.host) {
+ /* iOS requires a tunnel endpoint, whereas in WireGuard it's valid for
+ * a tunnel to have no endpoint, or for there to be many endpoints, in
+ * which case, displaying a single one in settings doesn't really
+ * make sense. So, we fill it in with this placeholder, which is not
+ * a valid IP address that will actually route over the Internet.
+ */
+ var remoteAddress: String = "0.0.0.0"
+ let endpointsCompact = resolvedEndpoints.compactMap({ $0 })
+ if endpointsCompact.count == 1 {
+ switch (endpointsCompact.first!.host) {
case .ipv4(let address):
remoteAddress = "\(address)"
case .ipv6(let address):
remoteAddress = "\(address)"
default:
- fatalError("Endpoint must be resolved")
+ break
}
- } else {
- // We don't have any peer with an endpoint
- remoteAddress = ""
}
options[.remoteAddress] = remoteAddress as NSObject