From 9b8be02c2a0674a898326b5cbf2d99fac7dd34c7 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 19 Apr 2019 09:44:54 +0200 Subject: [PATCH] Shut down when no IPv4/6 routing available Would fake-connect without VPN icon otherwise. --- .../Sources/AppExtension/TunnelKitProvider+Interaction.swift | 3 +++ TunnelKit/Sources/AppExtension/TunnelKitProvider.swift | 3 +++ TunnelKit/Sources/Core/SessionError.swift | 3 +++ TunnelKit/Sources/Core/SessionProxy.swift | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Interaction.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Interaction.swift index 496c416..71ceb3e 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider+Interaction.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider+Interaction.swift @@ -129,6 +129,9 @@ extension TunnelKitProvider { /// An error occurred at the link level. case linkError + /// Network routing information is missing or incomplete. + case routing + /// The current network changed (e.g. switched from WiFi to data connection). case networkChanged diff --git a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift index c945e99..3a6a7be 100644 --- a/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift +++ b/TunnelKit/Sources/AppExtension/TunnelKitProvider.swift @@ -696,6 +696,9 @@ extension TunnelKitProvider { case .failedLinkWrite: return .linkError + + case .noRouting: + return .routing default: return .unexpectedReply diff --git a/TunnelKit/Sources/Core/SessionError.swift b/TunnelKit/Sources/Core/SessionError.swift index 9d7ae8f..fd5e8bd 100644 --- a/TunnelKit/Sources/Core/SessionError.swift +++ b/TunnelKit/Sources/Core/SessionError.swift @@ -76,6 +76,9 @@ public enum SessionError: String, Error { /// Server uses compression. case serverCompression + + /// Missing routing information. + case noRouting } extension Error { diff --git a/TunnelKit/Sources/Core/SessionProxy.swift b/TunnelKit/Sources/Core/SessionProxy.swift index 7ab56d3..cee3cec 100644 --- a/TunnelKit/Sources/Core/SessionProxy.swift +++ b/TunnelKit/Sources/Core/SessionProxy.swift @@ -957,6 +957,11 @@ public class SessionProxy { } pushReply = reply + guard reply.options.ipv4 != nil || reply.options.ipv6 != nil else { + deferStop(.shutdown, SessionError.noRouting) + return + } + completeConnection() guard let remoteAddress = link?.remoteAddress else {