aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-14 02:24:53 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-14 02:24:53 +0530
commit48552d2663128b39a394127c0f564acd380179ea (patch)
tree8ec83ff378edcaa12a1d1c0147a1abee59b5e1db /WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
parentTunnelsManager: startActivation() need not take a tunnelConfiguration (diff)
downloadwireguard-apple-48552d2663128b39a394127c0f564acd380179ea.tar.xz
wireguard-apple-48552d2663128b39a394127c0f564acd380179ea.zip
NE: Communicate last error to app through a shared file
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift20
1 files changed, 12 insertions, 8 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index f2fa2691..559c7c26 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -28,21 +28,23 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
networkMonitor?.cancel()
}
- /// Begin the process of establishing the tunnel.
override func startTunnel(options: [String: NSObject]?, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
+ let activationAttemptId = options?["activationAttemptId"] as? String
+ let errorNotifier = ErrorNotifier(activationAttemptId: activationAttemptId, tunnelProvider: self)
+
guard let tunnelProviderProtocol = self.protocolConfiguration as? NETunnelProviderProtocol,
let tunnelConfiguration = tunnelProviderProtocol.tunnelConfiguration() else {
- ErrorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid, from: self)
+ errorNotifier.notify(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
startTunnelCompletionHandler(PacketTunnelProviderError.savedProtocolConfigurationIsInvalid)
return
}
- startTunnel(with: tunnelConfiguration, completionHandler: startTunnelCompletionHandler)
+ startTunnel(with: tunnelConfiguration, errorNotifier: errorNotifier, completionHandler: startTunnelCompletionHandler)
}
//swiftlint:disable:next function_body_length
- func startTunnel(with tunnelConfiguration: TunnelConfiguration, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
+ func startTunnel(with tunnelConfiguration: TunnelConfiguration, errorNotifier: ErrorNotifier, completionHandler startTunnelCompletionHandler: @escaping (Error?) -> Void) {
configureLogger()
@@ -55,7 +57,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
} catch DNSResolverError.dnsResolutionFailed(let hostnames) {
wg_log(.error, staticMessage: "Starting tunnel failed: DNS resolution failure")
wg_log(.error, message: "Hostnames for which DNS resolution failed: \(hostnames.joined(separator: ", "))")
- ErrorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames), from: self)
+ errorNotifier.notify(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
startTunnelCompletionHandler(PacketTunnelProviderError.dnsResolutionFailure(hostnames: hostnames))
return
} catch {
@@ -73,7 +75,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
let fileDescriptor = packetFlow.value(forKeyPath: "socket.fileDescriptor") as! Int32 //swiftlint:disable:this force_cast
if fileDescriptor < 0 {
wg_log(.error, staticMessage: "Starting tunnel failed: Could not determine file descriptor")
- ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
+ errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard)
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
return
}
@@ -101,7 +103,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
if handle < 0 {
wg_log(.error, staticMessage: "Starting tunnel failed: Could not start WireGuard")
- ErrorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard, from: self)
+ errorNotifier.notify(PacketTunnelProviderError.couldNotStartWireGuard)
startTunnelCompletionHandler(PacketTunnelProviderError.couldNotStartWireGuard)
return
}
@@ -115,7 +117,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
if let error = error {
wg_log(.error, staticMessage: "Starting tunnel failed: Error setting network settings.")
wg_log(.error, message: "Error from setTunnelNetworkSettings: \(error.localizedDescription)")
- ErrorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings, from: self)
+ errorNotifier.notify(PacketTunnelProviderError.coultNotSetNetworkSettings)
startTunnelCompletionHandler(PacketTunnelProviderError.coultNotSetNetworkSettings)
} else {
startTunnelCompletionHandler(nil /* No errors */)
@@ -128,6 +130,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
networkMonitor?.cancel()
networkMonitor = nil
+ ErrorNotifier.removeLastErrorFile()
+
wg_log(.info, staticMessage: "Stopping tunnel")
if let handle = wgHandle {
wgTurnOff(handle)