diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index dabfa71078a4..19a3d89d51b3 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -9260,7 +9260,7 @@ repositoryURL = "https://github.com/mullvad/wireguard-apple.git"; requirement = { kind = revision; - revision = afb345188c187dddafae0f9e27c5466be11451c2; + revision = cc6d3e918691c82d13389ad0fdbe8f35b683a6fc; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2b8fd8c64f52..a592a1ad89f5 100644 --- a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,7 +14,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mullvad/wireguard-apple.git", "state" : { - "revision" : "afb345188c187dddafae0f9e27c5466be11451c2" + "revision" : "cc6d3e918691c82d13389ad0fdbe8f35b683a6fc" } } ], diff --git a/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift b/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift index dd2d562c2e57..4bfd9b809103 100644 --- a/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift +++ b/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift @@ -163,7 +163,8 @@ private extension TunnelAdapterConfiguration { return TunnelConfiguration( name: nil, interface: interfaceConfig, - peers: peers + peers: peers, + pingableGateway: pingableGateway ) } } diff --git a/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift b/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift index 226b8b05fe37..7bac95e0b809 100644 --- a/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift +++ b/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift @@ -28,6 +28,7 @@ public struct ConfigurationBuilder { var endpoint: MullvadEndpoint? var allowedIPs: [IPAddressRange] var preSharedKey: PreSharedKey? + var pingableGateway: IPv4Address public init( privateKey: PrivateKey, @@ -35,7 +36,8 @@ public struct ConfigurationBuilder { dns: SelectedDNSServers? = nil, endpoint: MullvadEndpoint? = nil, allowedIPs: [IPAddressRange], - preSharedKey: PreSharedKey? = nil + preSharedKey: PreSharedKey? = nil, + pingableGateway: IPv4Address ) { self.privateKey = privateKey self.interfaceAddresses = interfaceAddresses @@ -43,6 +45,7 @@ public struct ConfigurationBuilder { self.endpoint = endpoint self.allowedIPs = allowedIPs self.preSharedKey = preSharedKey + self.pingableGateway = pingableGateway } public func makeConfiguration() throws -> TunnelAdapterConfiguration { @@ -51,7 +54,8 @@ public struct ConfigurationBuilder { interfaceAddresses: interfaceAddresses, dns: dnsServers, peer: try peer, - allowedIPs: allowedIPs + allowedIPs: allowedIPs, + pingableGateway: pingableGateway ) } diff --git a/ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift b/ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift index 54eca7b54d74..f1b6f3ffa6dd 100644 --- a/ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift +++ b/ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift @@ -7,6 +7,8 @@ // import Foundation +import MullvadTypes +import Network import WireGuardKitTypes protocol Configuration { @@ -69,7 +71,8 @@ private struct NormalConnectionConfiguration: Configuration { endpoint: connectionData.connectedEndpoint, allowedIPs: [ IPAddressRange(from: "\(connectionData.selectedRelays.exit.endpoint.ipv4Relay.ip)/32")!, - ] + ], + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ).makeConfiguration() } else { nil @@ -84,7 +87,8 @@ private struct NormalConnectionConfiguration: Configuration { allowedIPs: [ IPAddressRange(from: "0.0.0.0/0")!, IPAddressRange(from: "::/0")!, - ] + ], + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ).makeConfiguration() return ConnectionConfiguration( @@ -112,7 +116,8 @@ private struct EphemeralConnectionConfiguration: Configuration { dns: settings.dnsServers, endpoint: connectionData.connectedEndpoint, allowedIPs: hop.configuration.allowedIPs, - preSharedKey: hop.configuration.preSharedKey + preSharedKey: hop.configuration.preSharedKey, + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ).makeConfiguration() return ConnectionConfiguration(entryConfiguration: nil, exitConfiguration: exitConfiguration) @@ -124,7 +129,8 @@ private struct EphemeralConnectionConfiguration: Configuration { dns: settings.dnsServers, endpoint: connectionData.connectedEndpoint, allowedIPs: firstHop.configuration.allowedIPs, - preSharedKey: firstHop.configuration.preSharedKey + preSharedKey: firstHop.configuration.preSharedKey, + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ).makeConfiguration() let exitConfiguration = try ConfigurationBuilder( @@ -133,7 +139,8 @@ private struct EphemeralConnectionConfiguration: Configuration { dns: settings.dnsServers, endpoint: secondHop.relay.endpoint, allowedIPs: secondHop.configuration.allowedIPs, - preSharedKey: secondHop.configuration.preSharedKey + preSharedKey: secondHop.configuration.preSharedKey, + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ).makeConfiguration() return ConnectionConfiguration(entryConfiguration: entryConfiguration, exitConfiguration: exitConfiguration) diff --git a/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift b/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift index 064445ff1ea6..540af739847e 100644 --- a/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift +++ b/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift @@ -117,7 +117,8 @@ extension PacketTunnelActor { let configurationBuilder = ConfigurationBuilder( privateKey: PrivateKey(), interfaceAddresses: [], - allowedIPs: [] + allowedIPs: [], + pingableGateway: IPv4Address(LocalNetworkIPs.gatewayAddress.rawValue)! ) var config = try configurationBuilder.makeConfiguration() config.dns = [IPv4Address.loopback] diff --git a/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift b/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift index ac992c76c99e..f99ccb0e8231 100644 --- a/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift +++ b/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift @@ -35,6 +35,7 @@ public struct TunnelAdapterConfiguration { public var dns: [IPAddress] public var peer: TunnelPeer? public var allowedIPs: [IPAddressRange] + public var pingableGateway: IPv4Address } /// Struct describing a single peer. diff --git a/ios/PacketTunnelCore/Pinger/PingerProtocol.swift b/ios/PacketTunnelCore/Pinger/PingerProtocol.swift index 67c64c14482e..9df8ac50b0ba 100644 --- a/ios/PacketTunnelCore/Pinger/PingerProtocol.swift +++ b/ios/PacketTunnelCore/Pinger/PingerProtocol.swift @@ -32,7 +32,7 @@ public struct PingerSendResult { public protocol PingerProtocol { var onReply: ((PingerReply) -> Void)? { get set } - func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws - func closeSocket() + func startPinging(destAddress: IPv4Address) throws + func stopPinging() func send() throws -> PingerSendResult } diff --git a/ios/PacketTunnelCore/Pinger/TunnelPinger.swift b/ios/PacketTunnelCore/Pinger/TunnelPinger.swift index 47c5d8734ae0..d5ad6a95ac17 100644 --- a/ios/PacketTunnelCore/Pinger/TunnelPinger.swift +++ b/ios/PacketTunnelCore/Pinger/TunnelPinger.swift @@ -31,12 +31,7 @@ public final class TunnelPinger: PingerProtocol { self.logger = Logger(label: "TunnelPinger") } - deinit { - pingProvider.closeICMP() - } - - public func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws { - try pingProvider.openICMP(address: destAddress) + public func startPinging(destAddress: IPv4Address) throws { stateLock.withLock { self.destAddress = destAddress } @@ -64,10 +59,9 @@ public final class TunnelPinger: PingerProtocol { } } - public func closeSocket() { + public func stopPinging() { stateLock.withLock { self.destAddress = nil - pingProvider.closeICMP() } } diff --git a/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift b/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift index e2b3dbd17bfc..dbd8fcbf2f05 100644 --- a/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift +++ b/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift @@ -298,12 +298,12 @@ public final class TunnelMonitor: TunnelMonitorProtocol { private func startMonitoring() { do { - guard let interfaceName = tunnelDeviceInfo.interfaceName, let probeAddress else { - logger.debug("Failed to obtain utun interface name or probe address.") + guard let probeAddress else { + logger.debug("Failed to obtain probe address.") return } - try pinger.openSocket(bindTo: interfaceName, destAddress: probeAddress) + try pinger.startPinging(destAddress: probeAddress) state.connectionState = .connecting startConnectivityCheckTimer() @@ -314,7 +314,7 @@ public final class TunnelMonitor: TunnelMonitorProtocol { private func stopMonitoring(resetRetryAttempt: Bool) { stopConnectivityCheckTimer() - pinger.closeSocket() + pinger.stopPinging() state.netStats = WgStats() state.lastSeenRx = nil diff --git a/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift b/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift index 0dd16f6f65b3..463acc54b4ba 100644 --- a/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift +++ b/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift @@ -34,14 +34,14 @@ class PingerMock: PingerProtocol { self.decideOutcome = decideOutcome } - func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws { + func startPinging(destAddress: IPv4Address) throws { stateLock.withLock { state.destAddress = destAddress state.isSocketOpen = true } } - func closeSocket() { + func stopPinging() { stateLock.withLock { state.isSocketOpen = false }