From 853cfd17d08f1a9c13ad93e5ff1aae58881f9f45 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Mon, 22 May 2023 00:11:26 +0200 Subject: WIP wgSetConfig IPv4/IPv6 --- tunnel/tools/libwg-go/api-android.go | 13 +++++++++++++ tunnel/tools/libwg-go/jni.c | 13 +++++++++++++ 2 files changed, 26 insertions(+) (limited to 'tunnel/tools/libwg-go') diff --git a/tunnel/tools/libwg-go/api-android.go b/tunnel/tools/libwg-go/api-android.go index 78ee7f54..ff611e04 100644 --- a/tunnel/tools/libwg-go/api-android.go +++ b/tunnel/tools/libwg-go/api-android.go @@ -237,6 +237,19 @@ func wgVersion() *C.char { return C.CString(Version()) } +//export wgSetConfig +func wgSetConfig(tunnelHandle int32, settings string) int32 { + handle, ok := tunnelHandles[tunnelHandle] + if !ok { + return -1 + } + err := handle.device.IpcSet(settings) + if err != nil { + return -1 + } + return 0 +} + func Version() string { info, ok := debug.ReadBuildInfo() if !ok { diff --git a/tunnel/tools/libwg-go/jni.c b/tunnel/tools/libwg-go/jni.c index 20bfb332..7d6ee8a8 100644 --- a/tunnel/tools/libwg-go/jni.c +++ b/tunnel/tools/libwg-go/jni.c @@ -14,6 +14,7 @@ extern int wgGetSocketV4(int handle); extern int wgGetSocketV6(int handle); extern char *wgGetConfig(int handle); extern char *wgVersion(); +extern int wgSetConfig(int handle, struct go_string settings); extern int wgStartGrpc(); extern int wgSetFd(int handle, int tun_fd); @@ -72,6 +73,18 @@ JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgVersion return ret; } +JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgSetConfig(JNIEnv *env, jclass c, jstring handle, jstring settings) +{ + const char *settings_str = (*env)->GetStringUTFChars(env, settings, 0); + size_t settings_len = (*env)->GetStringUTFLength(env, settings); + int ret = wgSetConfig(handle, (struct go_string){ + .str = settings_str, + .n = settings_len + }); + (*env)->ReleaseStringUTFChars(env, settings, settings_str); + return ret; +} + JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgStartGrpc(JNIEnv *env, jclass c, jstring sockname) { const char *sockname_str = (*env)->GetStringUTFChars(env, sockname, 0); -- cgit v1.2.3