Compare commits

..

1 Commits

Author SHA1 Message Date
vkamn
d70b82246a fix: pass keepalive from config to uapi 2026-07-23 21:32:10 +08:00
17 changed files with 33 additions and 50 deletions

View File

@@ -111,7 +111,7 @@ open class Wireguard : Protocol() {
configExtensionParameters(configData)
}
configData.optStringOrNull("persistent_keep_alive")?.let { setPersistentKeepalive(it.toInt()) }
configData.optStringOrNull("persistent_keep_alive")?.toIntOrNull()?.let { setPersistentKeepalive(it) }
configData.getString("client_priv_key").let { setPrivateKeyHex(it.base64ToHex()) }
configData.getString("server_pub_key").let { setPublicKeyHex(it.base64ToHex()) }
configData.optStringOrNull("psk_key")?.let { setPreSharedKeyHex(it.base64ToHex()) }

View File

@@ -266,7 +266,7 @@ ProtocolConfig WireguardConfigurator::createConfig(const ServerCredentials &cred
clientConfig.presharedKey = connData.pskKey;
clientConfig.clientId = connData.clientPubKey;
clientConfig.allowedIps = QStringList { "0.0.0.0/0", "::/0" };
clientConfig.persistentKeepAlive = "25";
clientConfig.persistentKeepAlive = protocols::wireguard::defaultPersistentKeepAlive;
clientConfig.mtu = mtu;
clientConfig.isObfuscationEnabled = false;

View File

@@ -147,6 +147,7 @@ namespace amnezia
constexpr char defaultSubnetCidr[] = "24";
constexpr char defaultPort[] = "51820";
constexpr char defaultPersistentKeepAlive[] = "25";
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(MACOS_NE)
constexpr char defaultMtu[] = "1280";

View File

@@ -265,6 +265,8 @@ bool Daemon::parseConfig(const QJsonObject& obj, InterfaceConfig& config) {
#endif
}
config.m_persistentKeepalive = obj.value("persistentKeepalive").toString();
config.m_deviceIpv4Address = obj.value("deviceIpv4Address").toString();
config.m_deviceIpv6Address = obj.value("deviceIpv6Address").toString();
if (config.m_deviceIpv4Address.isNull() &&

View File

@@ -24,6 +24,9 @@ QJsonObject InterfaceConfig::toJson() const {
json.insert("serverIpv6AddrIn", QJsonValue(m_serverIpv6AddrIn));
json.insert("serverPort", QJsonValue((double)m_serverPort));
json.insert("deviceMTU", QJsonValue(m_deviceMTU));
if (!m_persistentKeepalive.isEmpty()) {
json.insert("persistentKeepalive", QJsonValue(m_persistentKeepalive));
}
if ((m_hopType == InterfaceConfig::MultiHopExit) ||
(m_hopType == InterfaceConfig::SingleHop)) {
json.insert("serverIpv4Gateway", QJsonValue(m_serverIpv4Gateway));
@@ -173,6 +176,9 @@ QString InterfaceConfig::toWgConf(const QMap<QString, QString>& extra) const {
ranges.append(ip.toString());
}
out << "AllowedIPs = " << ranges.join(", ") << "\n";
if (!m_persistentKeepalive.isEmpty()) {
out << "PersistentKeepalive = " << m_persistentKeepalive << "\n";
}
return content;
}

View File

@@ -36,6 +36,7 @@ class InterfaceConfig {
QString m_secondaryDnsServer;
int m_serverPort = 0;
int m_deviceMTU = 1420;
QString m_persistentKeepalive;
QList<IPAddress> m_allowedIPAddressRanges;
QStringList m_excludedAddresses;
QStringList m_vpnDisabledApps;

View File

@@ -16,8 +16,6 @@
constexpr const char* WG_INTERFACE = "amn0";
constexpr uint16_t WG_KEEPALIVE_PERIOD = 60;
class WireguardUtils : public QObject {
Q_OBJECT

View File

@@ -159,6 +159,11 @@ void LocalSocketController::activate(const QJsonObject &rawConfig) {
json.insert("serverIpv4Gateway", wgConfig.value(amnezia::configKey::hostName));
// json.insert("serverIpv6Gateway", QJsonValue(hop.m_server.ipv6Gateway()));
if (wgConfig.contains(amnezia::configKey::persistentKeepAlive)) {
json.insert("persistentKeepalive",
wgConfig.value(amnezia::configKey::persistentKeepAlive).toString());
}
json.insert("primaryDnsServer", rawConfig.value(amnezia::configKey::dns1));
// We don't use secondary DNS if primary DNS is AmneziaDNS

View File

@@ -16,7 +16,7 @@ struct WGConfig: Decodable {
let serverPublicKey: String
let presharedKey: String?
var allowedIPs: [String]
var persistentKeepAlive: String
var persistentKeepAlive: String?
let splitTunnelType: Int
let splitTunnelSites: [String]
@@ -116,7 +116,7 @@ struct WGConfig: Decodable {
\(presharedKey == nil ? "" : "PresharedKey = \(presharedKey!)")
AllowedIPs = \(allowedIPs.joined(separator: ", "))
Endpoint = \(hostName):\(port)
PersistentKeepalive = \(persistentKeepAlive)
\(persistentKeepAlive == nil ? "" : "PersistentKeepalive = \(persistentKeepAlive!)")
"""
}
@@ -133,7 +133,7 @@ struct WGConfig: Decodable {
PresharedKey = ***
AllowedIPs = \(allowedIPs.joined(separator: ", "))
Endpoint = \(hostName):\(port)
PersistentKeepalive = \(persistentKeepAlive)
\(persistentKeepAlive == nil ? "" : "PersistentKeepalive = \(persistentKeepAlive!)")
SplitTunnelType = \(splitTunnelType)
SplitTunnelSites = \(splitTunnelSites.joined(separator: ", "))

View File

@@ -591,8 +591,6 @@ bool IosController::setupWireGuard()
if (config.contains(configKey::persistentKeepAlive)) {
wgConfig.insert(configKey::persistentKeepAlive, config[configKey::persistentKeepAlive]);
} else {
wgConfig.insert(configKey::persistentKeepAlive, "25");
}
if (config.contains(configKey::isObfuscationEnabled) && config.value(configKey::isObfuscationEnabled).toBool()) {
@@ -697,8 +695,6 @@ bool IosController::setupAwg()
if (config.contains(configKey::persistentKeepAlive)) {
wgConfig.insert(configKey::persistentKeepAlive, config[configKey::persistentKeepAlive]);
} else {
wgConfig.insert(configKey::persistentKeepAlive, "25");
}
wgConfig.insert(configKey::initPacketMagicHeader, config[configKey::initPacketMagicHeader]);

View File

@@ -229,7 +229,9 @@ bool WireguardUtilsLinux::updatePeer(const InterfaceConfig& config) {
out << config.m_serverPort << "\n";
out << "replace_allowed_ips=true\n";
out << "persistent_keepalive_interval=" << WG_KEEPALIVE_PERIOD << "\n";
if (!config.m_persistentKeepalive.isEmpty()) {
out << "persistent_keepalive_interval=" << config.m_persistentKeepalive << "\n";
}
for (const IPAddress& ip : config.m_allowedIPAddressRanges) {
out << "allowed_ip=" << ip.toString() << "\n";
}

View File

@@ -229,7 +229,9 @@ bool WireguardUtilsMacos::updatePeer(const InterfaceConfig& config) {
out << config.m_serverPort << "\n";
out << "replace_allowed_ips=true\n";
out << "persistent_keepalive_interval=" << WG_KEEPALIVE_PERIOD << "\n";
if (!config.m_persistentKeepalive.isEmpty()) {
out << "persistent_keepalive_interval=" << config.m_persistentKeepalive << "\n";
}
for (const IPAddress& ip : config.m_allowedIPAddressRanges) {
out << "allowed_ip=" << ip.toString() << "\n";
}

View File

@@ -180,7 +180,9 @@ bool WireguardUtilsWindows::updatePeer(const InterfaceConfig& config) {
out << config.m_serverPort << "\n";
out << "replace_allowed_ips=true\n";
out << "persistent_keepalive_interval=" << WG_KEEPALIVE_PERIOD << "\n";
if (!config.m_persistentKeepalive.isEmpty()) {
out << "persistent_keepalive_interval=" << config.m_persistentKeepalive << "\n";
}
for (const IPAddress& ip : config.m_allowedIPAddressRanges) {
out << "allowed_ip=" << ip.toString() << "\n";
}

View File

@@ -408,11 +408,10 @@ void VpnConnection::appendSplitTunnelingConfig()
for (auto &line : nativeConfigLines) {
if (line.contains("PersistentKeepalive")) {
auto persistentKeepaliveString = line.split(" = ");
if (persistentKeepaliveString.size() < 1) {
break;
if (persistentKeepaliveString.size() > 1) {
configData.insert(configKey::persistentKeepAlive, persistentKeepaliveString.at(1));
m_vpnConfiguration.insert(protocolName + "_config_data", configData);
}
configData.insert(configKey::persistentKeepAlive, persistentKeepaliveString.at(1));
m_vpnConfiguration.insert(protocolName + "_config_data", configData);
break;
}
}

View File

@@ -1,3 +0,0 @@
patches:
"1.0.1":
- patch_file: "patches/0001-add-16kb-page-support-amnezia-libxray.patch"

View File

@@ -1,5 +1,5 @@
from conan import ConanFile
from conan.tools.files import get, copy, apply_conandata_patches, export_conandata_patches
from conan.tools.files import get, copy
from conan.tools.layout import basic_layout
from conan.errors import ConanInvalidConfiguration
from conan.tools.env import Environment
@@ -14,9 +14,6 @@ class AmneziaLibxray(ConanFile):
version = "1.0.1"
settings = "os", "arch", "compiler"
def export_sources(self):
export_conandata_patches(self)
def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
@@ -47,7 +44,6 @@ class AmneziaLibxray(ConanFile):
env.vars(self).save_script("conan_provide_androidhome")
def _patch_sources(self):
apply_conandata_patches(self)
build_path = os.path.join(self.build_folder, "build.sh")
build_stat = os.stat(build_path)
os.chmod(build_path, build_stat.st_mode | stat.S_IEXEC)

View File

@@ -1,24 +0,0 @@
From 0531cd00cd580524ec21a663442264136dbd368f Mon Sep 17 00:00:00 2001
From: NickVs2015 <nv@amnezia.org>
Date: Thu, 23 Jul 2026 11:23:07 +0300
Subject: [PATCH] fix: add 16kb page size support for android build
---
build.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build.sh b/build.sh
index 7969505..02c5b73 100755
--- a/build.sh
+++ b/build.sh
@@ -28,7 +28,7 @@ build_android() {
rm -fr assets
mkdir -p assets/geo
mv dat/* assets/geo
- gomobile bind -target android -androidapi 24 -javapkg=org.amnezia.vpn.protocol.xray -o libxray.aar -ldflags="-w -s -buildid= -checklinkname=0" -trimpath
+ gomobile bind -target android -androidapi 24 -javapkg=org.amnezia.vpn.protocol.xray -o libxray.aar -ldflags="-w -s -buildid= -checklinkname=0 -extldflags=-Wl,-z,max-page-size=16384" -trimpath
}
download_geo() {
--
2.50.1 (Apple Git-155)