Skip to content

Commit

Permalink
VPN now recovers from WireGuard closing utun (#3204)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1208000338328853/f

macOS: duckduckgo/macos-browser#3084
BSK: duckduckgo/BrowserServicesKit#931

## Description

If we detect an error while updating the tunnel configuration we now
cancel the tunnel so Apple recreates the virtual interface.

I believe the underlying issue is WireGuard should not "touch" the
virtual interface at all, as that responsibility is owned by Apple.
  • Loading branch information
diegoreymendez authored Aug 13, 2024
1 parent 36e3842 commit 5450a60
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
1 change: 0 additions & 1 deletion Core/Pixel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public struct PixelParameters {
// Network Protection
public static let keychainFieldName = "fieldName"
public static let keychainErrorCode = errorCode
public static let wireguardErrorCode = errorCode
public static let latency = "latency"
public static let server = "server"
public static let networkType = "network_type"
Expand Down
4 changes: 3 additions & 1 deletion Core/PixelEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ extension Pixel {
case networkProtectionWireguardErrorFailedDNSResolution
case networkProtectionWireguardErrorCannotSetNetworkSettings
case networkProtectionWireguardErrorCannotStartWireguardBackend

case networkProtectionWireguardErrorCannotSetWireguardConfig

case networkProtectionFailedToLoadFromPreferences
case networkProtectionFailedToSaveToPreferences
case networkProtectionActivationRequestFailed
Expand Down Expand Up @@ -1143,6 +1144,7 @@ extension Pixel.Event {
case .networkProtectionWireguardErrorFailedDNSResolution: return "m_netp_wireguard_error_failed_dns_resolution"
case .networkProtectionWireguardErrorCannotSetNetworkSettings: return "m_netp_wireguard_error_cannot_set_network_settings"
case .networkProtectionWireguardErrorCannotStartWireguardBackend: return "m_netp_wireguard_error_cannot_start_wireguard_backend"
case .networkProtectionWireguardErrorCannotSetWireguardConfig: return "m_netp_wireguard_error_cannot_set_wireguard_config"
case .networkProtectionFailedToLoadFromPreferences: return "m_netp_network_extension_error_failed_to_load_from_preferences"
case .networkProtectionFailedToSaveToPreferences: return "m_netp_network_extension_error_failed_to_save_to_preferences"
case .networkProtectionActivationRequestFailed: return "m_netp_network_extension_error_activation_request_failed"
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10507,7 +10507,7 @@
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 183.0.1;
version = 184.0.0;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "f0220c164618c7ca1cbf276db644d71711b0c76a",
"version" : "183.0.1"
"revision" : "c6ce430371032930d770b0388cbe44a2d40ad729",
"version" : "184.0.0"
}
},
{
Expand Down
7 changes: 6 additions & 1 deletion DuckDuckGo/EventMapping+NetworkProtectionError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ extension EventMapping where Event == NetworkProtectionError {
.wireGuardInvalidState,
.wireGuardDnsResolution,
.wireGuardSetNetworkSettings,
.startWireGuardBackend,
.failedToRetrieveAuthToken,
.failedToFetchServerStatus,
.failedToParseServerStatusResponse:
Expand All @@ -95,6 +94,12 @@ extension EventMapping where Event == NetworkProtectionError {
// Should never be sent from from the app
case .unhandledError(function: let function, line: let line, error: let error):
pixelEvent = .networkProtectionUnhandledError
case .startWireGuardBackend(let error):
pixelEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend
pixelError = error
case .setWireguardConfig(let error):
pixelEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig
pixelError = error
}

DailyPixel.fireDailyAndCount(pixel: pixelEvent, error: pixelError, withAdditionalParameters: params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,12 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
case .wireGuardSetNetworkSettings(let error):
pixelEvent = .networkProtectionWireguardErrorCannotSetNetworkSettings
pixelError = error
case .startWireGuardBackend(let code):
case .startWireGuardBackend(let error):
pixelEvent = .networkProtectionWireguardErrorCannotStartWireguardBackend
params[PixelParameters.wireguardErrorCode] = String(code)
pixelError = error
case .setWireguardConfig(let error):
pixelEvent = .networkProtectionWireguardErrorCannotSetWireguardConfig
pixelError = error
case .noAuthTokenFound:
pixelEvent = .networkProtectionNoAccessTokenFoundError
case .vpnAccessRevoked:
Expand Down

0 comments on commit 5450a60

Please sign in to comment.