From 004247937fb8ae0caa2400a39e0b32f4ca42fcda Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Tue, 29 Oct 2024 11:09:23 +0100 Subject: [PATCH] Add a pingableGateway address --- .../xcshareddata/swiftpm/Package.resolved | 2 +- .../WireGuardAdapter/WgAdapter.swift | 3 ++- .../Actor/ConfigurationBuilder.swift | 8 ++++++-- .../Actor/ConnectionConfigurationBuilder.swift | 17 ++++++++++++----- .../Actor/PacketTunnelActor+ErrorState.swift | 3 ++- .../Actor/Protocols/TunnelAdapterProtocol.swift | 1 + 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a6a820179091..580153fbec2c 100644 --- a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,7 +15,7 @@ "location" : "https://github.com/mullvad/wireguard-apple.git", "state" : { "branch" : "icmp-socket-always-on", - "revision" : "5e051810193e089230529691ea7b8d2244f3a05b" + "revision" : "b7d280b42bd5899acaa3f2a5c569c50dda2c608f" } } ], 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.