diff options
author | 2021-07-01 13:48:18 +0200 | |
---|---|---|
committer | 2021-09-28 12:51:54 +0200 | |
commit | 07bc66e7b181fb2068d457b31c1fdd05bdd2214a (patch) | |
tree | b5db8362d0d6d5ec98ac3dfdc63f9b181a04fc3e | |
parent | UI: When saving on-demand rules, deactivate if reqd and then save (diff) | |
download | wireguard-apple-07bc66e7b181fb2068d457b31c1fdd05bdd2214a.tar.xz wireguard-apple-07bc66e7b181fb2068d457b31c1fdd05bdd2214a.zip |
Kit: handle path monitor quirks when includeAllNetworks enabled.
NEPathMonitor reports the network path as satisfied even when `utun` is
the only available interface.
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r-- | Sources/WireGuardKit/WireGuardAdapter.swift | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/Sources/WireGuardKit/WireGuardAdapter.swift b/Sources/WireGuardKit/WireGuardAdapter.swift index 4cb2e2e..4266f6e 100644 --- a/Sources/WireGuardKit/WireGuardAdapter.swift +++ b/Sources/WireGuardKit/WireGuardAdapter.swift @@ -411,6 +411,27 @@ public class WireGuardAdapter { } } + /// Tells if the network path can be used to access network, taking into account if `utun` is the only active + /// interface. + /// - Parameter path: network path + private func canPathBeSatisfied(_ path: Network.NWPath) -> Bool { + // Assume that connectivity is not available, when `utun` is the only available interface. + if let networkInterface = path.availableInterfaces.first, + path.availableInterfaces.count == 1, + networkInterface.name.starts(with: "utun") { + return false + } + + switch path.status { + case .requiresConnection, .satisfied: + return true + case .unsatisfied: + return false + @unknown default: + return true + } + } + /// Helper method used by network path monitor. /// - Parameter path: new network path private func didReceivePathUpdate(path: Network.NWPath) { @@ -423,7 +444,7 @@ public class WireGuardAdapter { #elseif os(iOS) switch self.state { case .started(let handle, let settingsGenerator): - if path.status.isSatisfiable { + if canPathBeSatisfied(path) { let (wgConfig, resolutionResults) = settingsGenerator.endpointUapiConfiguration() self.logEndpointResolutionResults(resolutionResults) @@ -438,7 +459,7 @@ public class WireGuardAdapter { } case .temporaryShutdown(let settingsGenerator): - guard path.status.isSatisfiable else { return } + guard canPathBeSatisfied(path) else { return } self.logHandler(.verbose, "Connectivity online, resuming backend.") @@ -471,17 +492,3 @@ public enum WireGuardLogLevel: Int32 { case verbose = 0 case error = 1 } - -private extension Network.NWPath.Status { - /// Returns `true` if the path is potentially satisfiable. - var isSatisfiable: Bool { - switch self { - case .requiresConnection, .satisfied: - return true - case .unsatisfied: - return false - @unknown default: - return true - } - } -} |