summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBug Magnet <marco.nikic@mullvad.net>2024-11-06 12:57:46 +0100
committerBug Magnet <marco.nikic@mullvad.net>2024-11-06 12:57:46 +0100
commitd27c492f5e9c48faa1ab10bd80f09d8afd2d3a96 (patch)
treec01c176e63b4258bb1d5232d8909f0d0c2ac98c8
parent82f31fb9a647e0736e3e999044126542a25654f2 (diff)
parent7f84b859a4320c80c7d589e5b9fce8b0f335de0d (diff)
downloadmullvadvpn-d27c492f5e9c48faa1ab10bd80f09d8afd2d3a96.tar.xz
mullvadvpn-d27c492f5e9c48faa1ab10bd80f09d8afd2d3a96.zip
Merge branch 'when-phone-loses-connectivity-it-fails-to-reconnect-ios-889'
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj2
-rw-r--r--ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved2
-rw-r--r--ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift3
-rw-r--r--ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift8
-rw-r--r--ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift17
-rw-r--r--ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift3
-rw-r--r--ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift1
-rw-r--r--ios/PacketTunnelCore/Pinger/PingerProtocol.swift4
-rw-r--r--ios/PacketTunnelCore/Pinger/TunnelPinger.swift10
-rw-r--r--ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift8
-rw-r--r--ios/PacketTunnelCoreTests/Mocks/PingerMock.swift4
11 files changed, 35 insertions, 27 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index dabfa71078..19a3d89d51 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 2b8fd8c64f..a592a1ad89 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 dd2d562c2e..4bfd9b8091 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 226b8b05fe..7bac95e0b8 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 54eca7b54d..f1b6f3ffa6 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 064445ff1e..540af73984 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 ac992c76c9..f99ccb0e82 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 67c64c1448..9df8ac50b0 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 47c5d8734a..d5ad6a95ac 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 e2b3dbd17b..dbd8fcbf2f 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 0dd16f6f65..463acc54b4 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
}