diff options
author | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-14 21:40:20 +0200 |
---|---|---|
committer | Jeroen Leenarts <jeroen.leenarts@gmail.com> | 2018-08-14 21:40:20 +0200 |
commit | 335907309c8209b4a4d49167a40d4a22c6013f3a (patch) | |
tree | bb02f4bfe223c427bc134a45c8f5b0a2022a9b3e /WireGuardNetworkExtension | |
parent | Use config key for DNS config setting. (diff) | |
download | wireguard-apple-335907309c8209b4a4d49167a40d4a22c6013f3a.tar.xz wireguard-apple-335907309c8209b4a4d49167a40d4a22c6013f3a.zip |
Make sure the reference is not nil to packet flow. Thanks go out to "The Eskimo".
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'WireGuardNetworkExtension')
-rw-r--r-- | WireGuardNetworkExtension/PacketTunnelProvider.swift | 6 | ||||
-rw-r--r-- | WireGuardNetworkExtension/WireGuardGoWrapper.h | 2 | ||||
-rw-r--r-- | WireGuardNetworkExtension/WireGuardGoWrapper.m | 6 |
3 files changed, 11 insertions, 3 deletions
diff --git a/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuardNetworkExtension/PacketTunnelProvider.swift index a86bad2..a885a41 100644 --- a/WireGuardNetworkExtension/PacketTunnelProvider.swift +++ b/WireGuardNetworkExtension/PacketTunnelProvider.swift @@ -41,7 +41,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { //TODO: Hardcoded values for addresses let ipv4Settings = NEIPv4Settings(addresses: ["10.50.10.171"], subnetMasks: ["255.255.224.0"]) //TODO: Hardcoded values for allowed ips - ipv4Settings.includedRoutes = [NEIPv4Route(destinationAddress: "0.0.0.0", subnetMask: "0.0.0.0")] + ipv4Settings.includedRoutes = [NEIPv4Route.default()] ipv4Settings.excludedRoutes = endpoints.split(separator: ",").compactMap { $0.split(separator: ":").first}.map {NEIPv4Route(destinationAddress: String($0), subnetMask: "255.255.255.255")} //TODO IPv6 settings @@ -58,12 +58,14 @@ class PacketTunnelProvider: NEPacketTunnelProvider { } setTunnelNetworkSettings(newSettings) { [weak self](error) in - completionHandler(error) + self?.wireGuardWrapper.packetFlow = self?.packetFlow self?.wireGuardWrapper.configured = true self?.wireGuardWrapper.startReadingPackets() + completionHandler(error) } } else { + self.wireGuardWrapper.packetFlow = self.packetFlow completionHandler(PacketTunnelProviderError.tunnelSetupFailed) wireGuardWrapper.configured = false } diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.h b/WireGuardNetworkExtension/WireGuardGoWrapper.h index 21ee8b4..09c7193 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.h +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.h @@ -11,7 +11,7 @@ @interface WireGuardGoWrapper : NSObject -@property (nonatomic, weak) NEPacketTunnelFlow *packetFlow; +@property (nonatomic, strong) NEPacketTunnelFlow *packetFlow; @property (nonatomic, assign) BOOL configured; - (BOOL) turnOnWithInterfaceName: (NSString *)interfaceName settingsString: (NSString *)settingsString; diff --git a/WireGuardNetworkExtension/WireGuardGoWrapper.m b/WireGuardNetworkExtension/WireGuardGoWrapper.m index 7afe255..c4235b8 100644 --- a/WireGuardNetworkExtension/WireGuardGoWrapper.m +++ b/WireGuardNetworkExtension/WireGuardGoWrapper.m @@ -83,12 +83,14 @@ static void do_log(int level, const char *tag, const char *msg); os_log_debug([WireGuardGoWrapper log], "readPackets - read call - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); [self.packetFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) { + [self.condition lock]; @synchronized(self.packets) { [self.packets addObjectsFromArray:packets]; [self.protocols addObjectsFromArray:protocols]; } os_log_debug([WireGuardGoWrapper log], "readPackets - signal - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); [self.condition signal]; + [self.condition unlock]; [self readPackets]; }]; }); @@ -126,6 +128,7 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) NSData * __block packet = nil; // NSNumber *protocol = nil; dispatch_sync(wrapper.dispatchQueue, ^{ + [wrapper.condition lock]; @synchronized(wrapper.packets) { if (wrapper.packets.count == 0) { os_log_debug([WireGuardGoWrapper log], "do_read - no packet - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); @@ -143,7 +146,10 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len) if (packet == nil) { os_log_debug([WireGuardGoWrapper log], "do_read - wait - on thread \"%{public}@\" - %d", NSThread.currentThread.name, (int)NSThread.currentThread); [wrapper.condition wait]; + [wrapper.condition unlock]; return 0; + } else { + [wrapper.condition unlock]; } NSUInteger packetLength = [packet length]; |