From 3d5fb39da41c9dd7ad95b90eeb9c73a0bb21cf1d Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Mon, 1 Dec 2025 00:02:43 +0800 Subject: [PATCH] feat: add tproxy existence check and warnings for TPROXY and NFQUEUE --- openwrt/files/luci/model/cbi/ua3f/fields.lua | 50 ++++++++++++++++++-- openwrt/po/zh_cn/ua3f.po | 7 ++- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/openwrt/files/luci/model/cbi/ua3f/fields.lua b/openwrt/files/luci/model/cbi/ua3f/fields.lua index 6d52e4d..25f38d6 100644 --- a/openwrt/files/luci/model/cbi/ua3f/fields.lua +++ b/openwrt/files/luci/model/cbi/ua3f/fields.lua @@ -17,6 +17,12 @@ function nfqueue_exists() return opkg or apk end +function tproxy_exists() + local opkg = sys.call("opkg list-installed kmod-nft-tproxy | grep -q kmod-nft-tproxy") == 0 + local apk = sys.call("apk info | grep -q kmod-nft-tproxy") == 0 + return opkg or apk +end + -- Status Section Fields function M.add_status_fields(section) -- Enabled Flag @@ -46,7 +52,27 @@ function M.add_general_fields(section) server_mode:value("TPROXY", "TPROXY") server_mode:value("REDIRECT", "REDIRECT") server_mode:value("NFQUEUE", "NFQUEUE") - server_mode.default = "SOCKS5" + server_mode.default = "TPROXY" + + if not tproxy_exists() then + local tproxy_warning = section:taboption("general", DummyValue, "_tproxy_warning", " ") + tproxy_warning.rawhtml = true + tproxy_warning:depends("server_mode", "TPROXY") + function tproxy_warning.cfgvalue(self, section) + return "" .. + translate("Recommend install kmod-nft-tproxy package for TPROXY mode") .. "" + end + end + + if not nfqueue_exists() then + local nfqueue_warning = section:taboption("general", DummyValue, "_nfqueue_warning", " ") + nfqueue_warning.rawhtml = true + nfqueue_warning:depends("server_mode", "NFQUEUE") + function nfqueue_warning.cfgvalue(self, section) + return "" .. + translate("Recommend install kmod-nft-queue package for NFQUEUE mode") .. "" + end + end -- Bind Address local bind = section:taboption("general", Value, "bind", translate("Bind Address")) @@ -213,9 +239,15 @@ function M.add_desync_fields(section) -- Enable TCP Desync local desync_enabled = section:taboption("desync", Flag, "desync_enabled", translate("Enable TCP Desync")) desync_enabled.description = translate("Enable TCP Desynchronization to evade DPI") + if not nfqueue_exists() then - desync_enabled.description = translate( - "Enable TCP Desynchronization to evade DPI. <%:Recommend install kmod-nft-queue package%>") + local nfqueue_warning = section:taboption("desync", DummyValue, "_desync_nfqueue_warning", " ") + nfqueue_warning.rawhtml = true + nfqueue_warning:depends("desync_enabled", 1) + function nfqueue_warning.cfgvalue(self, section) + return "" .. + translate("Recommend install kmod-nft-queue package for NFQUEUE mode") .. "" + end end -- CT Byte Setting @@ -250,6 +282,18 @@ function M.add_others_fields(section) -- IP ID Setting local ipid = section:taboption("others", Flag, "set_ipid", translate("Set IP ID")) ipid.description = translate("Set the IP ID to 0 for packets") + + if not nfqueue_exists() then + local nfqueue_warning = section:taboption("others", DummyValue, "_others_nfqueue_warning", " ") + nfqueue_warning.rawhtml = true + nfqueue_warning:depends("del_tcpts", 1) + nfqueue_warning:depends("set_tcp_init_window", 1) + nfqueue_warning:depends("set_ipid", 1) + function nfqueue_warning.cfgvalue(self, section) + return "" .. + translate("Recommend install kmod-nft-queue package for NFQUEUE mode") .. "" + end + end end return M diff --git a/openwrt/po/zh_cn/ua3f.po b/openwrt/po/zh_cn/ua3f.po index 5106701..7f928e3 100644 --- a/openwrt/po/zh_cn/ua3f.po +++ b/openwrt/po/zh_cn/ua3f.po @@ -296,5 +296,8 @@ msgstr "乱序发射的数据包数,谨慎设置过大" msgid "Enable TCP Desynchronization to evade DPI" msgstr "启用 TCP 分片乱序发射,可以用于规避 DPI 检测" -msgid "Enable TCP Desynchronization to evade DPI. <%:Recommend install kmod-nft-queue package%>" -msgstr "启用 TCP 分片乱序发射,可以用于规避 DPI 检测。建议安装 kmod-nft-queue 软件包以增强兼容性" \ No newline at end of file +msgid "Recommend install kmod-nft-tproxy package for TPROXY mode" +msgstr "建议安装 kmod-nft-tproxy 软件包以增强兼容性" + +msgid "Recommend install kmod-nft-queue package for NFQUEUE mode" +msgstr "建议安装 kmod-nft-queue 软件包以增强兼容性" \ No newline at end of file