]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
WireGuardKit: Log XLAT resolution errors
authorAndrej Mihajlov <and@mullvad.net>
Thu, 3 Dec 2020 14:10:29 +0000 (15:10 +0100)
committerAndrej Mihajlov <and@mullvad.net>
Fri, 4 Dec 2020 10:50:43 +0000 (11:50 +0100)
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
Sources/WireGuardKit/WireGuardAdapter.swift

index 1dd1e6630102ff9586a51c64fb99373b7d5d0eed..f1b43d5e9271d9f6799ce5dd07510a898c15705d 100644 (file)
@@ -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 {
index ff48f1b36ea77323507341484cf4868d8cfd470a..e8f527ad1a80d85b9507d4eaa90873a989df165b 100644 (file)
@@ -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