diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-05-22 00:11:26 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-05-22 00:11:26 +0200 |
commit | 853cfd17d08f1a9c13ad93e5ff1aae58881f9f45 (patch) | |
tree | 4a891c1dddf82266fd608237b9fae0b07dc40af4 | |
parent | 276128328fd8aea4ff9fb7af3f3f933d591e1261 (diff) |
WIP wgSetConfig IPv4/IPv6
-rw-r--r-- | tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java | 12 | ||||
-rw-r--r-- | tunnel/tools/libwg-go/api-android.go | 13 | ||||
-rw-r--r-- | tunnel/tools/libwg-go/jni.c | 13 |
3 files changed, 34 insertions, 4 deletions
diff --git a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java index 24f1adc8..481ef8ae 100644 --- a/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java +++ b/tunnel/src/main/java/com/wireguard/android/backend/GoBackend.java @@ -149,6 +149,8 @@ public final class GoBackend implements Backend { private static native int wgGetSocketV6(int handle); + private static native int wgSetConfig(int handle, String settings); + private static native void wgSetFd(int handle, int tunFd); private static native void wgTurnOff(int handle); @@ -322,8 +324,9 @@ public final class GoBackend implements Backend { LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel); TunnelHandle handle = TunnelHandle.newBuilder().setHandle(currentTunnelHandle).build(); - IpcSetRequest request = IpcSetRequest.newBuilder().setTunnel(handle).setConfig(goConfig).build(); - IpcSetResponse resp = stub.ipcSet(request); + // IpcSetRequest request = IpcSetRequest.newBuilder().setTunnel(handle).setConfig(goConfig).build(); + // IpcSetResponse resp = stub.ipcSet(request); + wgSetConfig(handle, request); } private static String downloadPacFile(Network network, Uri pacFileUrl) { @@ -875,8 +878,9 @@ public final class GoBackend implements Backend { LibwgGrpc.LibwgBlockingStub stub = LibwgGrpc.newBlockingStub(channel); TunnelHandle tunnel = TunnelHandle.newBuilder().setHandle(currentTunnelHandle).build(); - IpcSetRequest request = IpcSetRequest.newBuilder().setTunnel(tunnel).setConfig(goConfig).build(); - IpcSetResponse resp = stub.ipcSet(request); + // IpcSetRequest request = IpcSetRequest.newBuilder().setTunnel(tunnel).setConfig(goConfig).build(); + // IpcSetResponse resp = stub.ipcSet(request); + wgSetConfig(handle, request); } } } 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); |