Start wire-up of logging and tunnel system.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
@@ -8,12 +8,17 @@
|
||||
|
||||
#import "WireGuardGoWrapper.h"
|
||||
|
||||
#include <os/log.h>
|
||||
#include "wireguard.h"
|
||||
|
||||
/// Trampoline function
|
||||
static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len);
|
||||
/// Trampoline function
|
||||
static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len);
|
||||
/// Trampoline function
|
||||
static void do_log(int level, const char *tag, const char *msg);
|
||||
|
||||
|
||||
|
||||
@interface WireGuardGoWrapper ()
|
||||
|
||||
@@ -26,6 +31,9 @@ static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len);
|
||||
|
||||
- (void) turnOnWithInterfaceName: (NSString *)interfaceName settingsString: (NSString *)settingsString
|
||||
{
|
||||
|
||||
wgSetLogger(do_log);
|
||||
|
||||
const char * ifName = [interfaceName UTF8String];
|
||||
const char * settings = [settingsString UTF8String];
|
||||
|
||||
@@ -38,6 +46,16 @@ static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len);
|
||||
wgTurnOff(self.handle);
|
||||
}
|
||||
|
||||
+ (os_log_t)log {
|
||||
static os_log_t subLog = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
subLog = os_log_create("com.wireguard.ios.WireGuard.WireGuardNetworkExtension", "WireGuard-Go");
|
||||
});
|
||||
|
||||
return subLog;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
|
||||
@@ -45,6 +63,7 @@ static ssize_t do_read(const void *ctx, const unsigned char *buf, size_t len)
|
||||
WireGuardGoWrapper *wrapper = (__bridge WireGuardGoWrapper *)ctx;
|
||||
printf("Reading from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
|
||||
sleep(1);
|
||||
// TODO received data from tunnel, write to Packetflow
|
||||
return wrapper.isClosed ? -1 : 0;
|
||||
}
|
||||
|
||||
@@ -54,3 +73,9 @@ static ssize_t do_write(const void *ctx, const unsigned char *buf, size_t len)
|
||||
printf("Writing from instance with ctx %p into buffer %p of length %zu\n", ctx, buf, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
static void do_log(int level, const char *tag, const char *msg)
|
||||
{
|
||||
// TODO Get some details on the log level and distribute to matching log levels.
|
||||
os_log([WireGuardGoWrapper log], "Log level %d for %s: %s", level, tag, msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user