Skip to content

Commit

Permalink
Add a pingableGateway address
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Oct 31, 2024
1 parent 67f669b commit 0c6409d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"location" : "https://github.com/mullvad/wireguard-apple.git",
"state" : {
"branch" : "icmp-socket-always-on",
"revision" : "5e051810193e089230529691ea7b8d2244f3a05b"
"revision" : "b7d280b42bd5899acaa3f2a5c569c50dda2c608f"
}
}
],
Expand Down
3 changes: 2 additions & 1 deletion ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private extension TunnelAdapterConfiguration {
return TunnelConfiguration(
name: nil,
interface: interfaceConfig,
peers: peers
peers: peers,
pingableGateway: pingableGateway
)
}
}
Expand Down
8 changes: 6 additions & 2 deletions ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ public struct ConfigurationBuilder {
var endpoint: MullvadEndpoint?
var allowedIPs: [IPAddressRange]
var preSharedKey: PreSharedKey?
var pingableGateway: IPv4Address

public init(
privateKey: PrivateKey,
interfaceAddresses: [IPAddressRange],
dns: SelectedDNSServers? = nil,
endpoint: MullvadEndpoint? = nil,
allowedIPs: [IPAddressRange],
preSharedKey: PreSharedKey? = nil
preSharedKey: PreSharedKey? = nil,
pingableGateway: IPv4Address
) {
self.privateKey = privateKey
self.interfaceAddresses = interfaceAddresses
self.dns = dns
self.endpoint = endpoint
self.allowedIPs = allowedIPs
self.preSharedKey = preSharedKey
self.pingableGateway = pingableGateway
}

public func makeConfiguration() throws -> TunnelAdapterConfiguration {
Expand All @@ -51,7 +54,8 @@ public struct ConfigurationBuilder {
interfaceAddresses: interfaceAddresses,
dns: dnsServers,
peer: try peer,
allowedIPs: allowedIPs
allowedIPs: allowedIPs,
pingableGateway: pingableGateway
)
}

Expand Down
17 changes: 12 additions & 5 deletions ios/PacketTunnelCore/Actor/ConnectionConfigurationBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import Foundation
import WireGuardKitTypes
import MullvadTypes
import Network

protocol Configuration {
var name: String { get }
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0c6409d

Please sign in to comment.