From 4676717582744e66aa67923533a1e9667ec425c5 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 1 Jan 2024 21:47:10 -0500 Subject: [PATCH] Wireguard can configure tun address local tun address is also used by Wireguard server to check against its "allowedIPs" setting --- .../kotlin/com/v2ray/ang/ui/ServerActivity.kt | 15 ++++++++ .../com/v2ray/ang/util/V2rayConfigUtil.kt | 10 +++-- .../res/layout/activity_server_wireguard.xml | 37 +++++++++++++++++++ .../app/src/main/res/values-ar/strings.xml | 2 + .../app/src/main/res/values-fa/strings.xml | 2 + .../app/src/main/res/values-ru/strings.xml | 2 + .../app/src/main/res/values-vi/strings.xml | 2 + .../src/main/res/values-zh-rCN/strings.xml | 2 + .../src/main/res/values-zh-rTW/strings.xml | 2 + V2rayNG/app/src/main/res/values/strings.xml | 2 + 10 files changed, 73 insertions(+), 3 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ServerActivity.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ServerActivity.kt index 2f38b7e2..5b7f08d1 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ServerActivity.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/ServerActivity.kt @@ -106,6 +106,9 @@ class ServerActivity : BaseActivity() { private val et_reserved1: EditText? by lazy { findViewById(R.id.et_reserved1) } private val et_reserved2: EditText? by lazy { findViewById(R.id.et_reserved2) } private val et_reserved3: EditText? by lazy { findViewById(R.id.et_reserved3) } + private val et_local_v4_address: EditText? by lazy { findViewById(R.id.et_local_v4_address) } + private val et_local_v6_address: EditText? by lazy { findViewById(R.id.et_local_v6_address) } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -210,6 +213,14 @@ class ServerActivity : BaseActivity() { et_reserved2?.text = Utils.getEditable(outbound.settings?.reserved?.get(1).toString()) et_reserved3?.text = Utils.getEditable(outbound.settings?.reserved?.get(2).toString()) } + if (outbound.settings?.address == null) { + et_local_v4_address?.text = Utils.getEditable("172.16.0.2/32") + et_local_v6_address?.text = Utils.getEditable("2606:4700:110:8f81:d551:a0:532e:a2b3/128") + } else { + val list = outbound.settings?.address as List<*> + et_local_v4_address?.text = Utils.getEditable(list.get(0).toString()) + et_local_v6_address?.text = Utils.getEditable(list.get(1).toString()) + } } val securityEncryptions = if (config.configType == EConfigType.SHADOWSOCKS) shadowsocksSecuritys else securitys val security = Utils.arrayFind(securityEncryptions, outbound.getSecurityEncryption().orEmpty()) @@ -295,6 +306,8 @@ class ServerActivity : BaseActivity() { et_reserved1?.text = Utils.getEditable("0") et_reserved2?.text = Utils.getEditable("0") et_reserved3?.text = Utils.getEditable("0") + et_local_v4_address?.text = Utils.getEditable("172.16.0.2/32") + et_local_v6_address?.text = Utils.getEditable("2606:4700:110:8f81:d551:a0:532e:a2b3/128") return true } @@ -407,6 +420,8 @@ class ServerActivity : BaseActivity() { }else { wireguard.reserved = null } + wireguard.address = listOf(et_local_v4_address?.text.toString().trim(), + et_local_v6_address?.text.toString().trim()) } private fun saveStreamSettings(streamSetting: V2rayConfig.OutboundBean.StreamSettingsBean) { diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt index 2a80162c..b29efcac 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/V2rayConfigUtil.kt @@ -427,9 +427,13 @@ object V2rayConfigUtil { } if (protocol.equals(EConfigType.WIREGUARD.name, true)) { - val localTunAddr = mutableListOf("172.16.0.2/32") - if (settingsStorage?.decodeBool(AppConfig.PREF_PREFER_IPV6) == true) { - localTunAddr.add("2606:4700:110:8f81:d551:a0:532e:a2b3/128") + var localTunAddr = if (outbound.settings?.address == null) { + listOf("172.16.0.2/32", "2606:4700:110:8f81:d551:a0:532e:a2b3/128") + } else { + outbound.settings?.address as List<*> + } + if (settingsStorage?.decodeBool(AppConfig.PREF_PREFER_IPV6) != true) { + localTunAddr = listOf(localTunAddr.first()) } outbound.settings?.address = localTunAddr } diff --git a/V2rayNG/app/src/main/res/layout/activity_server_wireguard.xml b/V2rayNG/app/src/main/res/layout/activity_server_wireguard.xml index 284a8b23..9b5bdf26 100644 --- a/V2rayNG/app/src/main/res/layout/activity_server_wireguard.xml +++ b/V2rayNG/app/src/main/res/layout/activity_server_wireguard.xml @@ -151,6 +151,43 @@ + + + + + + + + + + + + + + + ShortId SpiderX Reserved (اختياري) + العنوان المحلي IPv4(اختياري) + العنوان المحلي IPv6(اختياري, يستخدم فقط عندما تفضل IPv6) نجاح فشل لا يوجد شيء diff --git a/V2rayNG/app/src/main/res/values-fa/strings.xml b/V2rayNG/app/src/main/res/values-fa/strings.xml index 96b2cbe2..37a53b49 100644 --- a/V2rayNG/app/src/main/res/values-fa/strings.xml +++ b/V2rayNG/app/src/main/res/values-fa/strings.xml @@ -61,6 +61,8 @@ رمزگذاری جریان Reserved (اختیاری) + آدرس محلی IPv4(اختیاری) + آدرس محلی IPv6(اختیاری, فقط زمانی استفاده می شود که IPv6 را ترجیح می دهد) موفقیت شکست چیزی نیست diff --git a/V2rayNG/app/src/main/res/values-ru/strings.xml b/V2rayNG/app/src/main/res/values-ru/strings.xml index e2c4e548..59befe74 100644 --- a/V2rayNG/app/src/main/res/values-ru/strings.xml +++ b/V2rayNG/app/src/main/res/values-ru/strings.xml @@ -66,6 +66,8 @@ ShortId SpiderX Reserved (необязательно) + локальный адрес IPv4(необязательно) + локальный адрес IPv6(необязательно, используется только в том случае если предпочитаете IPv6) Успешно Ошибка Ничего нет diff --git a/V2rayNG/app/src/main/res/values-vi/strings.xml b/V2rayNG/app/src/main/res/values-vi/strings.xml index fab44ac3..f3f6ca1c 100644 --- a/V2rayNG/app/src/main/res/values-vi/strings.xml +++ b/V2rayNG/app/src/main/res/values-vi/strings.xml @@ -60,6 +60,8 @@ Mã hoá Kiểm soát lưu lượng Reserved (Bổ sung) + địa chỉ cục bộ IPv4(Bổ sung) + địa chỉ cục bộ IPv6(Bổ sung, chỉ được sử dụng khi thích IPv6) Thành công! Đã xảy ra lỗi, vui lòng thử lại! Không có gì ở đây diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 483fbe1f..e1113fc1 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -60,6 +60,8 @@ 加密方式(encryption) 流控(flow) Reserved(可选) + 本地 IPv4 地址(可选) + 本地 IPv6 地址(可选, 仅 IPv6 优先时使用) 成功 失败 没有数据 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index de2a4862..13f69607 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -60,6 +60,8 @@ 加密 (encryption) 流程 (flow) Reserved (可選) + 本機 IPv4 位址(可選) + 本機 IPv6 位址(可選, 僅偏好 IPv6 時使用) 成功 失敗 無資料 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index 532d9fc8..1e217f6e 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -67,6 +67,8 @@ SpiderX SecretKey Reserved(Optional) + local address IPv4(Optional) + local address IPv6(Optional, only used when prefer IPv6) Success Failure There is nothing