[PATCH] Wireguard-Apple: Restore iOS-like NWPath handling on MacOS app
Kajetan Staszkiewicz <[email protected]>
| Newsgroups | com.zx2c4.lists.wireguard |
|---|---|
| Message-ID | <[email protected]> |
I've sent this already when the mailing list was down, maybe it went unnoticed: Sometimes after a network path change, especially when only "unsatisfied" network path is available, for example when a laptop loses all LAN and WiFi networks, further network path changes are ignored. When "satisfied" networks disappear the cloned route for the bound socket is removed by the system and WireGuard packets are routed through the tunnel. This will result in an non-operational tunnel. The iOS code does not manifest this behaviour, as it properly disables the tunnel when no "satisfied" networks are available. Remove the special MacOS case, use the iOS code on MacOS app. -- | pozdrawiam / regards | Powered by Debian and FreeBSD | | Kajetan Staszkiewicz | www: http://tuxpowered.net | | | matrix: @vegeta:tuxpowered.net | `----------------------^--------------------------------'
0001-Restore-iOS-like-NWPath-handling-on-MacOS-app.patch
(text/plain, 2.9 KB)
From 0dc1630f54201dac005125b065265b7b3394bc29 Mon Sep 17 00:00:00 2001 From: Kajetan Staszkiewicz <[email protected]> Date: Mon, 27 Jan 2025 12:48:36 +0100 Subject: [PATCH] Restore iOS-like NWPath handling on MacOS app Sometimes after a network path change, especially when only "unsatisfied" network path is available, for example when a laptop loses all LAN and WiFi networks, further network path changes are ignored. When "satisfied" networks disappear the cloned route for the bound socket is removed by the system and WireGuard packets are routed through the tunnel. This will result in an non-operational tunnel. The iOS code does not manifest this behaviour, as it properly disables the tunnel when no "satisfied" networks are available. Remove the special MacOS case, use the iOS code on MacOS app. --- Sources/WireGuardKit/WireGuardAdapter.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Sources/WireGuardKit/WireGuardAdapter.swift b/Sources/WireGuardKit/WireGuardAdapter.swift index f7be19b..f5bf115 100644 --- a/Sources/WireGuardKit/WireGuardAdapter.swift +++ b/Sources/WireGuardKit/WireGuardAdapter.swift @@ -409,25 +409,20 @@ public class WireGuardAdapter { self.logHandler(.error, "Failed to resolve endpoint \(resolutionError.address): \(resolutionError.errorDescription ?? "(nil)")") } } } /// Helper method used by network path monitor. /// - Parameter path: new network path private func didReceivePathUpdate(path: Network.NWPath) { self.logHandler(.verbose, "Network change detected with \(path.status) route and interface order \(path.availableInterfaces)") - #if os(macOS) - if case .started(let handle, _) = self.state { - wgBumpSockets(handle) - } - #elseif os(iOS) switch self.state { case .started(let handle, let settingsGenerator): if path.status.isSatisfiable { let (wgConfig, resolutionResults) = settingsGenerator.endpointUapiConfiguration() self.logEndpointResolutionResults(resolutionResults) wgSetConfig(handle, wgConfig) wgDisableSomeRoamingForBrokenMobileSemantics(handle) wgBumpSockets(handle) } else { @@ -453,23 +448,20 @@ public class WireGuardAdapter { settingsGenerator ) } catch { self.logHandler(.error, "Failed to restart backend: \(error.localizedDescription)") } case .stopped: // no-op break } - #else - #error("Unsupported") - #endif } } /// A enum describing WireGuard log levels defined in `api-apple.go`. public enum WireGuardLogLevel: Int32 { case verbose = 0 case error = 1 } private extension Network.NWPath.Status { -- 2.47.0
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEfSEIcxY9kDeZvSZsgKrXf6bzAFMFAmhTI9MFAwAAAAAACgkQgKrXf6bzAFMM 2BAAoV3mugoknb5TBcQOhb+N1zUBfAPbKMNoqK0zG6s0nng2HwCPjdEIeVeIKAlSv9yBtHHQN5M4 4A/hVSUI20gGHJNHUi2ZvsTenK1rFdxgXSzu2p6ogQGDeCuYIxKg7mIiYaFqXm/FUx2EmYKslMAG gTqaZ79iEY5AFTaIxzHR11Pw6PoqKaC7dipKQtwM34yO7dRO4AjyQ2IDuc9f9ZrU2HgLU41P3nul kh36Re7PK1WN8KnFzQMRtBA2PthYOV1yPtX5+pgW9aJs10pkOw37RYHG+cdWIdDeKsoEmZP5PUcV ifipUqjqbHTWRNSbW0IrMSWXJCLRteXxkfhZiU9nE3In6wg3QJgA2oC8HGf9aK7OtQ1L/AOGReIJ wmELaISJEp9GbDdotdx/0ka7zwOOSQxMTb3so/4MTO37PUCBhzWjeweKmjZM9+x2aqZRaeLuTUj7 O+ATYrXygHzKAg8j+vKF3ktQnvVDTeq3z0qmG2ETica7swp1pDOyynKRHOwFPZnqVpSLLlIw0OJ8 0dwF4SH1ofmwuOUFvndrLk39gYujHnxTOC1sOnZX7d/wragSOYFLcVNWbm16+KXQfI1a8o/isg5a 3Oo+4FneWqO+Onr97vNCB5MNa+/WLSqlz8I5TRzKXt2sM7oUziECDB4GQiULMLxzl9fNejoY5zjc ibw= =WKmv -----END PGP SIGNATURE-----