aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2020-02-07 12:31:42 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-02-07 22:35:57 +0100
commit3276339af69b7a7a1f5784715f81f2b0537a9c4d (patch)
tree703938da0b130ceaffe13e7a89be64920066aa7e
parentVersion bump (diff)
downloadwireguard-apple-master.tar.xz
wireguard-apple-master.zip
wireguard-go-bridge: use C string instead of gostring_tHEADmaster
Signed-off-by: Andrej Mihajlov <and@mullvad.net>
-rw-r--r--WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift15
-rw-r--r--wireguard-go-bridge/api-ios.go8
-rw-r--r--wireguard-go-bridge/wireguard.h5
3 files changed, 10 insertions, 18 deletions
diff --git a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
index f8d87d7..fc93630 100644
--- a/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
+++ b/WireGuard/WireGuardNetworkExtension/PacketTunnelProvider.swift
@@ -70,7 +70,8 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
}
ifnamePtr.deallocate()
wg_log(.info, message: "Tunnel interface is \(self.ifname ?? "unknown")")
- let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration().withGoString { return wgTurnOn($0, fileDescriptor) }
+ let handle = self.packetTunnelSettingsGenerator!.uapiConfiguration()
+ .withCString { return wgTurnOn($0, fileDescriptor) }
if handle < 0 {
wg_log(.error, message: "Starting tunnel failed with wgTurnOn returning \(handle)")
errorNotifier.notify(PacketTunnelProviderError.couldNotStartBackend)
@@ -146,18 +147,10 @@ class PacketTunnelProvider: NEPacketTunnelProvider {
#if os(iOS)
if let packetTunnelSettingsGenerator = packetTunnelSettingsGenerator {
- _ = packetTunnelSettingsGenerator.endpointUapiConfiguration().withGoString { return wgSetConfig(handle, $0) }
+ _ = packetTunnelSettingsGenerator.endpointUapiConfiguration()
+ .withCString { return wgSetConfig(handle, $0) }
}
#endif
wgBumpSockets(handle)
}
}
-
-extension String {
- func withGoString<R>(_ call: (gostring_t) -> R) -> R {
- func helper(_ pointer: UnsafePointer<Int8>?, _ call: (gostring_t) -> R) -> R {
- return call(gostring_t(p: pointer, n: utf8.count))
- }
- return helper(self, call)
- }
-}
diff --git a/wireguard-go-bridge/api-ios.go b/wireguard-go-bridge/api-ios.go
index 55e1b0d..93dd323 100644
--- a/wireguard-go-bridge/api-ios.go
+++ b/wireguard-go-bridge/api-ios.go
@@ -84,7 +84,7 @@ func wgSetLogger(loggerFn uintptr) {
}
//export wgTurnOn
-func wgTurnOn(settings string, tunFd int32) int32 {
+func wgTurnOn(settings *C.char, tunFd int32) int32 {
logger := &device.Logger{
Debug: log.New(&CLogger{level: 0}, "", 0),
Info: log.New(&CLogger{level: 1}, "", 0),
@@ -104,7 +104,7 @@ func wgTurnOn(settings string, tunFd int32) int32 {
logger.Info.Println("Attaching to interface")
device := device.NewDevice(tun, logger)
- setError := device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
+ setError := device.IpcSetOperation(bufio.NewReader(strings.NewReader(C.GoString(settings))))
if setError != nil {
logger.Error.Println(setError)
return -1
@@ -137,12 +137,12 @@ func wgTurnOff(tunnelHandle int32) {
}
//export wgSetConfig
-func wgSetConfig(tunnelHandle int32, settings string) int64 {
+func wgSetConfig(tunnelHandle int32, settings *C.char) int64 {
device, ok := tunnelHandles[tunnelHandle]
if !ok {
return 0
}
- err := device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
+ err := device.IpcSetOperation(bufio.NewReader(strings.NewReader(C.GoString(settings))))
if err != nil {
device.Error.Println(err)
return err.ErrorCode()
diff --git a/wireguard-go-bridge/wireguard.h b/wireguard-go-bridge/wireguard.h
index e8e451b..5c30ee9 100644
--- a/wireguard-go-bridge/wireguard.h
+++ b/wireguard-go-bridge/wireguard.h
@@ -10,13 +10,12 @@
#include <stdint.h>
#include <stdbool.h>
-typedef struct { const char *p; size_t n; } gostring_t;
typedef void(*logger_fn_t)(int level, const char *msg);
extern void wgEnableRoaming(bool enabled);
extern void wgSetLogger(logger_fn_t logger_fn);
-extern int wgTurnOn(gostring_t settings, int32_t tun_fd);
+extern int wgTurnOn(const char *settings, int32_t tun_fd);
extern void wgTurnOff(int handle);
-extern int64_t wgSetConfig(int handle, gostring_t settings);
+extern int64_t wgSetConfig(int handle, const char *settings);
extern char *wgGetConfig(int handle);
extern void wgBumpSockets(int handle);
extern const char *wgVersion();