From ac259f2d111515c8cd85c407f3464f783e78c163 Mon Sep 17 00:00:00 2001 From: Tianhe Y <10704839+nftbty@users.noreply.github.com> Date: Thu, 6 Apr 2023 14:34:35 +0800 Subject: [PATCH] luci: wireguard add reserved option when xray>=1.8.0 (#2462) * luci: wireguard add reserved option when xray>=1.8.0 * luci: 4.63 --- luci-app-passwall/Makefile | 4 ++-- .../luasrc/model/cbi/passwall/client/node_config.lua | 5 +++++ luci-app-passwall/luasrc/passwall/api.lua | 2 +- luci-app-passwall/luasrc/passwall/util_xray.lua | 11 ++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/luci-app-passwall/Makefile b/luci-app-passwall/Makefile index 54ba46035..453c54b97 100644 --- a/luci-app-passwall/Makefile +++ b/luci-app-passwall/Makefile @@ -6,8 +6,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-passwall -PKG_VERSION:=4.62 -PKG_RELEASE:=7 +PKG_VERSION:=4.63 +PKG_RELEASE:=1 PKG_CONFIG_DEPENDS:= \ CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \ diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua index 2fa98d0b9..804547b43 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua @@ -748,6 +748,11 @@ wireguard_mtu = s:option(Value, "wireguard_mtu", translate("MTU")) wireguard_mtu.default = "1420" wireguard_mtu:depends({ type = "Xray", protocol = "wireguard" }) +if api.compare_versions(api.get_app_version("xray"), ">=", "1.8.0") then + wireguard_reserved = s:option(Value, "wireguard_reserved", translate("Reserved")) + wireguard_reserved:depends({ type = "Xray", protocol = "wireguard" }) +end + wireguard_keepAlive = s:option(Value, "wireguard_keepAlive", translate("Keep Alive")) wireguard_keepAlive.default = "0" wireguard_keepAlive:depends({ type = "Xray", protocol = "wireguard" }) diff --git a/luci-app-passwall/luasrc/passwall/api.lua b/luci-app-passwall/luasrc/passwall/api.lua index 8b5706cac..0922336d2 100644 --- a/luci-app-passwall/luasrc/passwall/api.lua +++ b/luci-app-passwall/luasrc/passwall/api.lua @@ -536,7 +536,7 @@ local function exec(cmd, args, writer, timeout) end end -local function compare_versions(ver1, comp, ver2) +function compare_versions(ver1, comp, ver2) local table = table if not ver1 then ver1 = "" end diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index 71e165946..2fc03c657 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -100,6 +100,14 @@ function gen_outbound(flag, node, tag, proxy_table) end end + if node.protocol == "wireguard" and node.wireguard_reserved then + local bytes = {} + node.wireguard_reserved:gsub("[^,]+", function(b) + bytes[#bytes+1] = tonumber(b) + end) + node.wireguard_reserved = #bytes > 0 and bytes or nil + end + result = { _flag_tag = node_id, _flag_proxy = proxy, @@ -223,7 +231,8 @@ function gen_outbound(flag, node, tag, proxy_table) keepAlive = node.wireguard_keepAlive and tonumber(node.wireguard_keepAlive) or nil } } or nil, - mtu = (node.protocol == "wireguard" and node.wireguard_mtu) and tonumber(node.wireguard_mtu) or nil + mtu = (node.protocol == "wireguard" and node.wireguard_mtu) and tonumber(node.wireguard_mtu) or nil, + reserved = (node.protocol == "wireguard" and node.wireguard_reserved) and node.wireguard_reserved or nil } } local alpn = {}