Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TunnelVision using enforceRoutes #3460

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {

enum DebugFeatureRows: Int, CaseIterable {
case toggleAlwaysOn
case enforceRoutes
}

enum SimulateFailureRows: Int, CaseIterable {
Expand Down Expand Up @@ -324,6 +325,14 @@ final class NetworkProtectionDebugViewController: UITableViewController {
} else {
cell.accessoryType = .checkmark
}
case .enforceRoutes:
cell.textLabel?.text = "Enforce Routes"

if !AppDependencyProvider.shared.vpnSettings.enforceRoutes {
cell.accessoryType = .none
} else {
cell.accessoryType = .checkmark
}
default:
break
}
Expand All @@ -334,6 +343,9 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case .toggleAlwaysOn:
debugFeatures.alwaysOnDisabled.toggle()
tableView.reloadRows(at: [indexPath], with: .none)
case .enforceRoutes:
AppDependencyProvider.shared.vpnSettings.enforceRoutes.toggle()
tableView.reloadRows(at: [indexPath], with: .none)
default:
break
}
Expand Down
57 changes: 57 additions & 0 deletions DuckDuckGo/NetworkProtectionTunnelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
return tunnelManager
}

@MainActor
private func setupAndSave(_ tunnelManager: NETunnelProviderManager) async throws {
setup(tunnelManager)

Expand All @@ -319,6 +320,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr

/// Setups the tunnel manager if it's not set up already.
///
@MainActor
private func setup(_ tunnelManager: NETunnelProviderManager) {
tunnelManager.localizedDescription = "DuckDuckGo VPN"
tunnelManager.isEnabled = true
Expand All @@ -327,16 +329,71 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
let protocolConfiguration = NETunnelProviderProtocol()
protocolConfiguration.serverAddress = "127.0.0.1" // Dummy address... the NetP service will take care of grabbing a real server

protocolConfiguration.providerConfiguration = [
NetworkProtectionOptionKey.includedRoutes: includedRoutes().map(\.stringRepresentation) as NSArray
]

// always-on
protocolConfiguration.disconnectOnSleep = false

// kill switch
protocolConfiguration.enforceRoutes = AppDependencyProvider.shared.vpnSettings.enforceRoutes

#if DEBUG
if #available(iOS 17.4, *) {
protocolConfiguration.excludeDeviceCommunication = true
}
#endif

return protocolConfiguration
}()

// reconnect on reboot
tunnelManager.onDemandRules = [NEOnDemandRuleConnect()]
}

/// extra Included Routes appended to 0.0.0.0, ::/0 (peers) and interface.addresses
@MainActor
private func includedRoutes() -> [NetworkProtection.IPAddressRange] {
[
IPAddressRange(stringLiteral: "0.0.0.0/0"),
IPAddressRange(stringLiteral: "1.0.0.0/8"),
IPAddressRange(stringLiteral: "2.0.0.0/8"),
IPAddressRange(stringLiteral: "3.0.0.0/8"),
IPAddressRange(stringLiteral: "4.0.0.0/6"),
IPAddressRange(stringLiteral: "8.0.0.0/7"),
IPAddressRange(stringLiteral: "10.11.12.1"),
IPAddressRange(stringLiteral: "11.0.0.0/8"),
IPAddressRange(stringLiteral: "12.0.0.0/6"),
IPAddressRange(stringLiteral: "16.0.0.0/4"),
IPAddressRange(stringLiteral: "32.0.0.0/3"),
IPAddressRange(stringLiteral: "64.0.0.0/2"),
IPAddressRange(stringLiteral: "128.0.0.0/3"),
IPAddressRange(stringLiteral: "160.0.0.0/5"),
IPAddressRange(stringLiteral: "168.0.0.0/6"),
IPAddressRange(stringLiteral: "172.0.0.0/12"),
IPAddressRange(stringLiteral: "172.32.0.0/11"),
IPAddressRange(stringLiteral: "172.64.0.0/10"),
IPAddressRange(stringLiteral: "172.128.0.0/9"),
IPAddressRange(stringLiteral: "173.0.0.0/8"),
IPAddressRange(stringLiteral: "174.0.0.0/7"),
IPAddressRange(stringLiteral: "176.0.0.0/4"),
IPAddressRange(stringLiteral: "192.0.0.0/9"),
IPAddressRange(stringLiteral: "192.128.0.0/11"),
IPAddressRange(stringLiteral: "192.160.0.0/13"),
IPAddressRange(stringLiteral: "192.169.0.0/16"),
IPAddressRange(stringLiteral: "192.170.0.0/15"),
IPAddressRange(stringLiteral: "192.172.0.0/14"),
IPAddressRange(stringLiteral: "192.176.0.0/12"),
IPAddressRange(stringLiteral: "192.192.0.0/10"),
IPAddressRange(stringLiteral: "193.0.0.0/8"),
IPAddressRange(stringLiteral: "194.0.0.0/7"),
IPAddressRange(stringLiteral: "196.0.0.0/6"),
IPAddressRange(stringLiteral: "200.0.0.0/5"),
IPAddressRange(stringLiteral: "208.0.0.0/4")
]
}

// MARK: - Observing Configuration Changes

private func subscribeToConfigurationChanges() {
Expand Down
Loading