summaryrefslogtreecommitdiffhomepage
path: root/tunnel/tools/libwg-go/api-android.go
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-04-13 20:37:03 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2020-03-17 22:27:45 +0100
commitab4e2b29e61e913ce63a4494a3b3cfe069a3bb12 (patch)
treef05fa201e151b272de6dd2356e0ff5da47c746ed /tunnel/tools/libwg-go/api-android.go
parent553ec49d11eb7ad727b0409982a2285e86f4917d (diff)
Implement get and set tunnel config actions
Add three tunnel actions: com.wireguard.android.action.GET_TUNNEL_CONFIG com.wireguard.android.action.SET_TUNNEL_CONFIG com.wireguard.android.action.SET_TUNNEL_USERSPACE_CONFIG
Diffstat (limited to 'tunnel/tools/libwg-go/api-android.go')
-rw-r--r--tunnel/tools/libwg-go/api-android.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go
index 7a393cae..9ccd913f 100644
--- a/tunnel/tools/libwg-go/api-android.go
+++ b/tunnel/tools/libwg-go/api-android.go
@@ -11,6 +11,7 @@ import "C"
import (
"bufio"
+ "bytes"
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
@@ -143,6 +144,40 @@ func wgTurnOff(tunnelHandle int32) {
handle.device.Close()
}
+//export wgGetOperation
+func wgGetOperation(tunnelHandle int32) *C.char {
+ handle, ok := tunnelHandles[tunnelHandle]
+ if !ok {
+ return C.CString("(bad handle)")
+ }
+
+ var buf bytes.Buffer
+ writer := bufio.NewWriter(&buf)
+
+ getError := handle.device.IpcGetOperation(writer)
+ if getError != nil {
+ return C.CString(getError.Error())
+ }
+
+ writer.Flush()
+ return C.CString(buf.String())
+}
+
+//export wgSetOperation
+func wgSetOperation(tunnelHandle int32, settings string) int32 {
+ handle, ok := tunnelHandles[tunnelHandle]
+ if !ok {
+ return -1
+ }
+
+ setError := handle.device.IpcSetOperation(bufio.NewReader(strings.NewReader(settings)))
+ if setError != nil {
+ return -1
+ }
+
+ return 0
+}
+
//export wgGetSocketV4
func wgGetSocketV4(tunnelHandle int32) int32 {
handle, ok := tunnelHandles[tunnelHandle]