aboutsummaryrefslogtreecommitdiffstats
path: root/wireguard-go-bridge
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-01-23 22:15:01 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-01-24 01:22:04 +0100
commitab3cbee6a24a25f6391fbf5360de747eb72d18f6 (patch)
treec490c31d281d4083df5b813316a5e5aee353546d /wireguard-go-bridge
parentwireguard-go-bridge: fix standalone build (diff)
downloadwireguard-apple-ab3cbee6a24a25f6391fbf5360de747eb72d18f6.tar.xz
wireguard-apple-ab3cbee6a24a25f6391fbf5360de747eb72d18f6.zip
wireguard-go-bridge: allow querying internal settings
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'wireguard-go-bridge')
-rw-r--r--wireguard-go-bridge/src/api-ios.go26
-rw-r--r--wireguard-go-bridge/wireguard.h3
2 files changed, 22 insertions, 7 deletions
diff --git a/wireguard-go-bridge/src/api-ios.go b/wireguard-go-bridge/src/api-ios.go
index ace83d9b..de730eb7 100644
--- a/wireguard-go-bridge/src/api-ios.go
+++ b/wireguard-go-bridge/src/api-ios.go
@@ -15,10 +15,10 @@ import "C"
import (
"bufio"
+ "bytes"
"errors"
"git.zx2c4.com/wireguard-go/tun"
"golang.org/x/sys/unix"
- "io/ioutil"
"log"
"math"
"os"
@@ -94,8 +94,7 @@ func wgTurnOn(settings string, tunFd int32) int32 {
logger.Info.Println("Attaching to interface")
device := NewDevice(tun, logger)
- bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard))
- setError := ipcSetOperation(device, bufferedSettings)
+ setError := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
if setError != nil {
logger.Error.Println(setError)
return -1
@@ -133,15 +132,30 @@ func wgSetConfig(tunnelHandle int32, settings string) int64 {
if !ok {
return 0
}
- bufferedSettings := bufio.NewReadWriter(bufio.NewReader(strings.NewReader(settings)), bufio.NewWriter(ioutil.Discard))
- err := ipcSetOperation(device, bufferedSettings)
+ err := ipcSetOperation(device, bufio.NewReader(strings.NewReader(settings)))
if err != nil {
device.log.Error.Println(err)
- return err.Code
+ return err.int64
}
return 0
}
+//export wgGetConfig
+func wgGetConfig(tunnelHandle int32) *C.char {
+ device, ok := tunnelHandles[tunnelHandle]
+ if !ok {
+ return nil
+ }
+ settings := new(bytes.Buffer)
+ writer := bufio.NewWriter(settings)
+ err := ipcGetOperation(device, writer)
+ if err != nil {
+ return nil
+ }
+ writer.Flush()
+ return C.CString(settings.String())
+}
+
//export wgBindInterfaceScope
func wgBindInterfaceScope(tunnelHandle int32, ifscope int32) {
var operr error
diff --git a/wireguard-go-bridge/wireguard.h b/wireguard-go-bridge/wireguard.h
index b264a2ef..5ae9023e 100644
--- a/wireguard-go-bridge/wireguard.h
+++ b/wireguard-go-bridge/wireguard.h
@@ -17,7 +17,8 @@ extern void wgSetLogger(logger_fn_t logger_fn);
extern int wgTurnOn(gostring_t settings, int32_t tun_fd);
extern void wgTurnOff(int handle);
extern int64_t wgSetConfig(int handle, gostring_t settings);
+extern char *wgGetConfig(int handle);
extern void wgBindInterfaceScope(int handle, int32_t ifscope);
-extern char *wgVersion();
+extern const char *wgVersion();
#endif