aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-23 17:56:39 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-24 18:39:29 +0200
commitb637570caa3fcf658ba26c37e7eb9590f4cd620d (patch)
treeb1d7322a1e60bf7079d3078d1f690977d6b2750d
parentVersion bump (diff)
downloadwireguard-android-b637570caa3fcf658ba26c37e7eb9590f4cd620d.tar.xz
wireguard-android-b637570caa3fcf658ba26c37e7eb9590f4cd620d.zip
libwg-go: reenable sticky sockets, just slightly less sticky
-rw-r--r--app/src/main/java/com/wireguard/android/backend/GoBackend.java6
-rw-r--r--app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go57
-rw-r--r--app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c12
m---------app/tools/wireguard-go0
4 files changed, 53 insertions, 22 deletions
diff --git a/app/src/main/java/com/wireguard/android/backend/GoBackend.java b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
index d11802f..f9dca4c 100644
--- a/app/src/main/java/com/wireguard/android/backend/GoBackend.java
+++ b/app/src/main/java/com/wireguard/android/backend/GoBackend.java
@@ -51,6 +51,10 @@ public final class GoBackend implements Backend {
private static native int wgGetSocketV6(int handle);
+ private static native void wgPutSocketV4(int handle);
+
+ private static native void wgPutSocketV6(int handle);
+
private static native void wgTurnOff(int handle);
private static native int wgTurnOn(String ifName, int tunFd, String settings);
@@ -186,7 +190,9 @@ public final class GoBackend implements Backend {
currentTunnel = tunnel;
service.protect(wgGetSocketV4(currentTunnelHandle));
+ wgPutSocketV4(currentTunnelHandle);
service.protect(wgGetSocketV6(currentTunnelHandle));
+ wgPutSocketV6(currentTunnelHandle);
} else {
Log.i(TAG, "Bringing tunnel down");
diff --git a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go
index 24a0eae..74a0c97 100644
--- a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go
+++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/api-android.go
@@ -85,6 +85,7 @@ func wgTurnOn(ifnameRef string, tun_fd int32, settings string) int32 {
}
device.Up()
+ device.net.bind.(*NativeBind).clearSourceOnAllRouteChanges = true
logger.Info.Println("Device started")
var i int32
@@ -121,18 +122,7 @@ func wgGetSocketV4(tunnelHandle int32) int32 {
if !ok {
return -1
}
- fd := int32(-1)
- conn, err := native.ipv4.SyscallConn()
- if err != nil {
- return -1
- }
- err = conn.Control(func(f uintptr) {
- fd = int32(f)
- })
- if err != nil {
- return -1
- }
- return fd
+ return int32(native.sock4)
}
//export wgGetSocketV6
@@ -145,18 +135,41 @@ func wgGetSocketV6(tunnelHandle int32) int32 {
if !ok {
return -1
}
- fd := int32(-1)
- conn, err := native.ipv6.SyscallConn()
- if err != nil {
- return -1
+ return int32(native.sock6)
+}
+
+//export wgPutSocketV4
+func wgPutSocketV4(tunnelHandle int32) {
+ device, ok := tunnelHandles[tunnelHandle]
+ if !ok {
+ return
}
- err = conn.Control(func(f uintptr) {
- fd = int32(f)
- })
- if err != nil {
- return -1
+ native, ok := device.net.bind.(*NativeBind)
+ if !ok {
+ return
+ }
+ fwmark, err := unix.GetsockoptInt(native.sock6, unix.SOL_SOCKET, unix.SO_MARK)
+ if err == nil {
+ native.lastMark = uint32(fwmark)
+ device.net.fwmark = uint32(fwmark)
+ }
+}
+
+//export wgPutSocketV6
+func wgPutSocketV6(tunnelHandle int32) {
+ device, ok := tunnelHandles[tunnelHandle]
+ if !ok {
+ return
+ }
+ native, ok := device.net.bind.(*NativeBind)
+ if !ok {
+ return
+ }
+ fwmark, err := unix.GetsockoptInt(native.sock6, unix.SOL_SOCKET, unix.SO_MARK)
+ if err == nil {
+ native.lastMark = uint32(fwmark)
+ device.net.fwmark = uint32(fwmark)
}
- return fd
}
func main() {}
diff --git a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c
index a0f3d0b..ae6422a 100644
--- a/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c
+++ b/app/tools/libwg-go/src/git.zx2c4.com/wireguard-go/jni.c
@@ -10,6 +10,8 @@ extern int wgTurnOn(struct go_string ifname, int tun_fd, struct go_string settin
extern void wgTurnOff(int handle);
extern int wgGetSocketV4(int handle);
extern int wgGetSocketV6(int handle);
+extern void wgPutSocketV4(int handle);
+extern void wgPutSocketV6(int handle);
JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOn(JNIEnv *env, jclass c, jstring ifname, jint tun_fd, jstring settings)
{
@@ -43,3 +45,13 @@ JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV
{
return wgGetSocketV6(handle);
}
+
+JNIEXPORT void JNICALL Java_com_wireguard_android_backend_GoBackend_wgPutSocketV4(JNIEnv *env, jclass c, jint handle)
+{
+ wgPutSocketV4(handle);
+}
+
+JNIEXPORT void JNICALL Java_com_wireguard_android_backend_GoBackend_wgPutSocketV6(JNIEnv *env, jclass c, jint handle)
+{
+ wgPutSocketV6(handle);
+}
diff --git a/app/tools/wireguard-go b/app/tools/wireguard-go
-Subproject 0b647d1ca7e079f3bb2fe95c3ca7c05898315a6
+Subproject 4365b4583fa32b1b77d33f5074da9c165a28f82