From 10caecbffd6b5188409f14cb12524319da68290a Mon Sep 17 00:00:00 2001 From: albexk Date: Mon, 18 Mar 2024 14:20:01 +0300 Subject: [PATCH] Fix wg reconnection problem after awg connection (#696) * Update Android AWG to 0.2.5 --- CMakeLists.txt | 4 ++-- client/3rd-prebuilt | 2 +- .../android/wireguard/src/main/kotlin/GoBackend.kt | 10 ---------- .../src/main/kotlin/org/amnezia/awg/GoBackend.kt | 10 ++++++++++ .../amnezia/vpn/protocol/wireguard}/Wireguard.kt | 13 +++++++------ .../vpn/protocol/wireguard}/WireguardConfig.kt | 0 6 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 client/android/wireguard/src/main/kotlin/GoBackend.kt create mode 100644 client/android/wireguard/src/main/kotlin/org/amnezia/awg/GoBackend.kt rename client/android/wireguard/src/main/kotlin/{ => org/amnezia/vpn/protocol/wireguard}/Wireguard.kt (92%) rename client/android/wireguard/src/main/kotlin/{ => org/amnezia/vpn/protocol/wireguard}/WireguardConfig.kt (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8e1391e3..58ee37c9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR) set(PROJECT AmneziaVPN) -project(${PROJECT} VERSION 4.4.1.3 +project(${PROJECT} VERSION 4.4.1.4 DESCRIPTION "AmneziaVPN" HOMEPAGE_URL "https://amnezia.org/" ) @@ -11,7 +11,7 @@ string(TIMESTAMP CURRENT_DATE "%Y-%m-%d") set(RELEASE_DATE "${CURRENT_DATE}") set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH}) -set(APP_ANDROID_VERSION_CODE 48) +set(APP_ANDROID_VERSION_CODE 49) if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(MZ_PLATFORM_NAME "linux") diff --git a/client/3rd-prebuilt b/client/3rd-prebuilt index 629fdf777..ab4e6b680 160000 --- a/client/3rd-prebuilt +++ b/client/3rd-prebuilt @@ -1 +1 @@ -Subproject commit 629fdf77735506c904bb1449a3ed73de7d1f93f6 +Subproject commit ab4e6b680dc3d3d81809886c2c25b77750659c1a diff --git a/client/android/wireguard/src/main/kotlin/GoBackend.kt b/client/android/wireguard/src/main/kotlin/GoBackend.kt deleted file mode 100644 index 28e48a758..000000000 --- a/client/android/wireguard/src/main/kotlin/GoBackend.kt +++ /dev/null @@ -1,10 +0,0 @@ -package org.amnezia.vpn.protocol.wireguard - -object GoBackend { - external fun wgGetConfig(handle: Int): String? - external fun wgGetSocketV4(handle: Int): Int - external fun wgGetSocketV6(handle: Int): Int - external fun wgTurnOff(handle: Int) - external fun wgTurnOn(ifName: String, tunFd: Int, settings: String): Int - external fun wgVersion(): String -} diff --git a/client/android/wireguard/src/main/kotlin/org/amnezia/awg/GoBackend.kt b/client/android/wireguard/src/main/kotlin/org/amnezia/awg/GoBackend.kt new file mode 100644 index 000000000..5446d8f80 --- /dev/null +++ b/client/android/wireguard/src/main/kotlin/org/amnezia/awg/GoBackend.kt @@ -0,0 +1,10 @@ +package org.amnezia.awg + +object GoBackend { + external fun awgGetConfig(handle: Int): String? + external fun awgGetSocketV4(handle: Int): Int + external fun awgGetSocketV6(handle: Int): Int + external fun awgTurnOff(handle: Int) + external fun awgTurnOn(ifName: String, tunFd: Int, settings: String): Int + external fun awgVersion(): String +} diff --git a/client/android/wireguard/src/main/kotlin/Wireguard.kt b/client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/Wireguard.kt similarity index 92% rename from client/android/wireguard/src/main/kotlin/Wireguard.kt rename to client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/Wireguard.kt index a71d79361..95ea9aca1 100644 --- a/client/android/wireguard/src/main/kotlin/Wireguard.kt +++ b/client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/Wireguard.kt @@ -4,6 +4,7 @@ import android.content.Context import android.net.VpnService.Builder import java.util.TreeMap import kotlinx.coroutines.flow.MutableStateFlow +import org.amnezia.awg.GoBackend import org.amnezia.vpn.protocol.Protocol import org.amnezia.vpn.protocol.ProtocolState import org.amnezia.vpn.protocol.ProtocolState.CONNECTED @@ -61,7 +62,7 @@ open class Wireguard : Protocol() { override val statistics: Statistics get() { if (tunnelHandle == -1) return Statistics.EMPTY_STATISTICS - val config = GoBackend.wgGetConfig(tunnelHandle) ?: return Statistics.EMPTY_STATISTICS + val config = GoBackend.awgGetConfig(tunnelHandle) ?: return Statistics.EMPTY_STATISTICS return Statistics.build { var optsCount = 0 config.splitToSequence("\n").forEach { line -> @@ -156,8 +157,8 @@ open class Wireguard : Protocol() { if (tunFd == null) { throw VpnStartException("Create VPN interface: permission not granted or revoked") } - Log.v(TAG, "Wg-go backend ${GoBackend.wgVersion()}") - tunnelHandle = GoBackend.wgTurnOn(ifName, tunFd.detachFd(), config.toWgUserspaceString()) + Log.v(TAG, "Wg-go backend ${GoBackend.awgVersion()}") + tunnelHandle = GoBackend.awgTurnOn(ifName, tunFd.detachFd(), config.toWgUserspaceString()) } if (tunnelHandle < 0) { @@ -165,8 +166,8 @@ open class Wireguard : Protocol() { throw VpnStartException("Wireguard tunnel creation error") } - if (!protect(GoBackend.wgGetSocketV4(tunnelHandle)) || !protect(GoBackend.wgGetSocketV6(tunnelHandle))) { - GoBackend.wgTurnOff(tunnelHandle) + if (!protect(GoBackend.awgGetSocketV4(tunnelHandle)) || !protect(GoBackend.awgGetSocketV6(tunnelHandle))) { + GoBackend.awgTurnOff(tunnelHandle) tunnelHandle = -1 throw VpnStartException("Protect VPN interface: permission not granted or revoked") } @@ -179,7 +180,7 @@ open class Wireguard : Protocol() { } val handleToClose = tunnelHandle tunnelHandle = -1 - GoBackend.wgTurnOff(handleToClose) + GoBackend.awgTurnOff(handleToClose) state.value = DISCONNECTED } diff --git a/client/android/wireguard/src/main/kotlin/WireguardConfig.kt b/client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/WireguardConfig.kt similarity index 100% rename from client/android/wireguard/src/main/kotlin/WireguardConfig.kt rename to client/android/wireguard/src/main/kotlin/org/amnezia/vpn/protocol/wireguard/WireguardConfig.kt