diff options
author | Andrej Mihajlov <and@mullvad.net> | 2022-02-21 13:11:49 +0100 |
---|---|---|
committer | Andrej Mihajlov <and@mullvad.net> | 2022-02-21 13:11:49 +0100 |
commit | 399013415d16d8a6d91ff503c9f50b513d89e873 (patch) | |
tree | 6566d3e4f747649636a8ef92dc6408cc5e75eb5b | |
parent | UI: When saving on-demand rules, deactivate if reqd and then save (diff) | |
parent | Kit: Adapter: ignore error when updating tunnel settings in offline (diff) | |
download | wireguard-apple-399013415d16d8a6d91ff503c9f50b513d89e873.tar.xz wireguard-apple-399013415d16d8a6d91ff503c9f50b513d89e873.zip |
Merge branch 'am/ignore-set-network-settings-error-when-offline' into am/develop
-rw-r--r-- | Sources/WireGuardKit/WireGuardAdapter.swift | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/Sources/WireGuardKit/WireGuardAdapter.swift b/Sources/WireGuardKit/WireGuardAdapter.swift index 4cb2e2e..0f00b89 100644 --- a/Sources/WireGuardKit/WireGuardAdapter.swift +++ b/Sources/WireGuardKit/WireGuardAdapter.swift @@ -253,35 +253,58 @@ public class WireGuardAdapter { self.packetTunnelProvider?.reasserting = false } + let settingsGenerator: PacketTunnelSettingsGenerator do { - let settingsGenerator = try self.makeSettingsGenerator(with: tunnelConfiguration) - try self.setNetworkSettings(settingsGenerator.generateNetworkSettings()) + settingsGenerator = try self.makeSettingsGenerator(with: tunnelConfiguration) + } catch let error as WireGuardAdapterError { + completionHandler(error) + return + } catch { + fatalError() + } - switch self.state { - case .started(let handle, _): - let (wgConfig, resolutionResults) = settingsGenerator.uapiConfiguration() - self.logEndpointResolutionResults(resolutionResults) + switch self.state { + case .started(let handle, _): + do { + try self.setNetworkSettings(settingsGenerator.generateNetworkSettings()) + } catch let error as WireGuardAdapterError { + completionHandler(error) + return + } catch { + fatalError() + } - wgSetConfig(handle, wgConfig) - #if os(iOS) - wgDisableSomeRoamingForBrokenMobileSemantics(handle) - #endif + let (wgConfig, resolutionResults) = settingsGenerator.uapiConfiguration() + self.logEndpointResolutionResults(resolutionResults) - self.state = .started(handle, settingsGenerator) + wgSetConfig(handle, wgConfig) + #if os(iOS) + wgDisableSomeRoamingForBrokenMobileSemantics(handle) + #endif - case .temporaryShutdown: - self.state = .temporaryShutdown(settingsGenerator) + self.state = .started(handle, settingsGenerator) - case .stopped: + case .temporaryShutdown: + // On iOS 15.1 or newer, updating network settings may fail when in airplane mode. + // Network path monitor will retry updating settings later when connectivity is + // back online. + do { + try self.setNetworkSettings(settingsGenerator.generateNetworkSettings()) + } catch let error as WireGuardAdapterError { + if case .setNetworkSettings(let systemError) = error { + self.logHandler(.verbose, "Failed to set network settings while offline. Will retry when connectivity is back online. Error: \(systemError.localizedDescription)") + } + } catch { fatalError() } - completionHandler(nil) - } catch let error as WireGuardAdapterError { - completionHandler(error) - } catch { + self.state = .temporaryShutdown(settingsGenerator) + + case .stopped: fatalError() } + + completionHandler(nil) } } |