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>
This commit is contained in:
parent
fc72697d82
commit
335907309c
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Reference in New Issue