aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-12-03 15:10:29 +0100
committerAndrej Mihajlov <and@mullvad.net>2020-12-04 11:50:43 +0100
commitd440a91b0e0e47745991625ef20fde4bfb8d16b3 (patch)
tree8aa47bfd191d48b210a3712371ba6788f663798a
parentWireGuardApp: Disable SWIFT_PRECOMPILE_BRIDGING_HEADER (diff)
downloadwireguard-apple-d440a91b0e0e47745991625ef20fde4bfb8d16b3.tar.xz
wireguard-apple-d440a91b0e0e47745991625ef20fde4bfb8d16b3.zip
WireGuardKit: Log XLAT resolution errors
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r--Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift19
-rw-r--r--Sources/WireGuardKit/WireGuardAdapter.swift6
2 files changed, 20 insertions, 5 deletions
diff --git a/Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift b/Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
index 1dd1e66..f1b43d5 100644
--- a/Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
+++ b/Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
@@ -18,17 +18,28 @@ class PacketTunnelSettingsGenerator {
self.resolvedEndpoints = resolvedEndpoints
}
- func endpointUapiConfiguration() -> String {
+ func endpointUapiConfiguration() -> (String, [DNSResolutionError]) {
+ var resolutionErrors = [DNSResolutionError]()
var wgSettings = ""
for (index, peer) in tunnelConfiguration.peers.enumerated() {
wgSettings.append("public_key=\(peer.publicKey.hexKey)\n")
- // TODO: log the error returned by `withReresolvedIP`
- if let endpoint = try? resolvedEndpoints[index]?.withReresolvedIP() {
+ let result = Result { try resolvedEndpoints[index]?.withReresolvedIP() }
+ .mapError { error -> DNSResolutionError in
+ // swiftlint:disable:next force_cast
+ return error as! DNSResolutionError
+ }
+
+ switch result {
+ case .success(.some(let endpoint)):
if case .name(_, _) = endpoint.host { assert(false, "Endpoint is not resolved") }
wgSettings.append("endpoint=\(endpoint.stringRepresentation)\n")
+ case .success(.none):
+ break
+ case .failure(let error):
+ resolutionErrors.append(error)
}
}
- return wgSettings
+ return (wgSettings, resolutionErrors)
}
func uapiConfiguration() -> String {
diff --git a/Sources/WireGuardKit/WireGuardAdapter.swift b/Sources/WireGuardKit/WireGuardAdapter.swift
index ff48f1b..e8f527a 100644
--- a/Sources/WireGuardKit/WireGuardAdapter.swift
+++ b/Sources/WireGuardKit/WireGuardAdapter.swift
@@ -336,7 +336,11 @@ public class WireGuardAdapter {
#if os(iOS)
if let settingsGenerator = self.settingsGenerator {
- wgSetConfig(handle, settingsGenerator.endpointUapiConfiguration())
+ let (wgSettings, resolutionErrors) = settingsGenerator.endpointUapiConfiguration()
+ for error in resolutionErrors {
+ self.logHandler(.error, "Failed to re-resolve \(error.address): \(error.errorDescription ?? "(nil)")")
+ }
+ wgSetConfig(handle, wgSettings)
}
#endif