aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuardNetworkExtension/WireGuardGoWrapper.m
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-12 21:39:39 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-08-12 21:39:39 +0200
commita27328ed72187d3956b2339afc02d5881af730a6 (patch)
treef5a6d04d2a297cf0c64205305020b6cd3b7fcc6d /WireGuardNetworkExtension/WireGuardGoWrapper.m
parentAdd back addresses. (diff)
downloadwireguard-apple-a27328ed72187d3956b2339afc02d5881af730a6.tar.xz
wireguard-apple-a27328ed72187d3956b2339afc02d5881af730a6.zip
Do not read from packetFlow when tunnel is not yet fully initialized and configured.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--WireGuardNetworkExtension/WireGuardGoWrapper.m10
1 files changed, 10 insertions, 0 deletions
diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m
index cda62b4..2d6056d 100644
--- a/WireGuardNetworkExtension/WireGuardGoWrapper.m
+++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m
@@ -37,6 +37,8 @@ static void do_log(int level, const char *tag, const char *msg);
{
self = [super init];
if (self) {
+ self.handle = -1;
+ self.configured = false;
self.condition = [NSCondition new];
}
return self;
@@ -59,7 +61,9 @@ static void do_log(int level, const char *tag, const char *msg);
- (void) turnOff
{
self.isClosed = YES;
+ self.configured = NO;
wgTurnOff(self.handle);
+ self.handle = -1;
}
+ (NSString *)versionWireGuardGo {
@@ -83,6 +87,12 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx;
if (wrapper.isClosed) return -1;
+ if (wrapper.handle < 0 || !wrapper.configured ) {
+// os_log_debug([WireGuardGoWrapper log], "do_read - early - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread);
+
+ return 0;
+ }
+
if (wrapper.packets.count == 0) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{