From e3af7f6c1616425eab2ee474ead73d7b321436b5 Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Mon, 12 Feb 2024 14:57:59 +0100 Subject: [PATCH] Resurface the list of allowedIPs to make it configurable --- ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift | 5 +---- ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift | 4 +++- .../Actor/PacketTunnelActor+ErrorState.swift | 3 ++- ios/PacketTunnelCore/Actor/PacketTunnelActor.swift | 6 +++++- .../Actor/Protocols/TunnelAdapterProtocol.swift | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift b/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift index c907d3d981b5..7ad9b6be9a76 100644 --- a/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift +++ b/ios/PacketTunnel/WireGuardAdapter/WgAdapter.swift @@ -112,10 +112,7 @@ private extension TunnelAdapterConfiguration { if let peer { var peerConfig = PeerConfiguration(publicKey: peer.publicKey) peerConfig.endpoint = peer.endpoint.wgEndpoint - peerConfig.allowedIPs = [ - IPAddressRange(from: "0.0.0.0/0")!, - IPAddressRange(from: "::/0")!, - ] + peerConfig.allowedIPs = allowedIPs peers.append(peerConfig) } diff --git a/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift b/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift index 1b06f39366bf..06b970a223b7 100644 --- a/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift +++ b/ios/PacketTunnelCore/Actor/ConfigurationBuilder.swift @@ -26,13 +26,15 @@ struct ConfigurationBuilder { var interfaceAddresses: [IPAddressRange] var dns: SelectedDNSServers? var endpoint: MullvadEndpoint? + var allowedIPs: [IPAddressRange] func makeConfiguration() throws -> TunnelAdapterConfiguration { return TunnelAdapterConfiguration( privateKey: privateKey, interfaceAddresses: interfaceAddresses, dns: dnsServers, - peer: try peer + peer: try peer, + allowedIPs: allowedIPs ) } diff --git a/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift b/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift index 077bfdbb25f4..94888c81157b 100644 --- a/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift +++ b/ios/PacketTunnelCore/Actor/PacketTunnelActor+ErrorState.swift @@ -114,7 +114,8 @@ extension PacketTunnelActor { do { let configurationBuilder = ConfigurationBuilder( privateKey: PrivateKey(), - interfaceAddresses: [] + interfaceAddresses: [], + allowedIPs: [] ) var config = try configurationBuilder.makeConfiguration() config.dns = [IPv4Address.loopback] diff --git a/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift b/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift index 8d3372c6beb9..4d40fdf1e632 100644 --- a/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift +++ b/ios/PacketTunnelCore/Actor/PacketTunnelActor.swift @@ -250,7 +250,11 @@ extension PacketTunnelActor { privateKey: activeKey, interfaceAddresses: settings.interfaceAddresses, dns: settings.dnsServers, - endpoint: connectionState.connectedEndpoint + endpoint: connectionState.connectedEndpoint, + allowedIPs: [ + IPAddressRange(from: "0.0.0.0/0")!, + IPAddressRange(from: "::/0")!, + ] ) /* diff --git a/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift b/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift index b50ab4a7ada0..0bbbbbf8a5b9 100644 --- a/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift +++ b/ios/PacketTunnelCore/Actor/Protocols/TunnelAdapterProtocol.swift @@ -27,6 +27,7 @@ public struct TunnelAdapterConfiguration { public var interfaceAddresses: [IPAddressRange] public var dns: [IPAddress] public var peer: TunnelPeer? + public var allowedIPs: [IPAddressRange] } /// Struct describing a single peer.