xray-core: add Mihomo TUIC v4/v5 support and LuCI integration

Signed-off-by: coolsnowwolf <coolsnowwolf@gmail.com>
This commit is contained in:
coolsnowwolf committed 2026-10-21 10:07:57 +08:00
1 parent ac70ddcf30
commit 2a70c30fd8
8 files changed
+2387 -11

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ LUCI_TITLE:=luci-app-ssr-plus
LUCI_PKGARCH:=all
PKG_NAME:=luci-app-ssr-plus
PKG_VERSION:=196
PKG_RELEASE:=21
PKG_RELEASE:=22
PKG_CONFIG_DEPENDS:= \
CONFIG_PACKAGE_$(PKG_NAME)_Iptables_Transparent_Proxy \
@@ -474,6 +474,7 @@ if is_finded("xray") then
o:value("wireguard", translate("WireGuard"))
o:value("naive", "NaiveProxy (Xray / Cronet)")
o:value("shadowsocksr", "ShadowsocksR (Xray)")
o:value("tuic", "TUIC (Xray)")
end
if is_finded("xray") then
o:value("hysteria2", translate("Hysteria2"))
@@ -926,6 +927,17 @@ end
o.rmempty = true
o.default="auto"
o = s:option(ListValue, "xray_tuic_version", "TUIC Version")
o:value("5", "v5 (UUID / Password)")
o:value("4", "v4 (Token)")
o.default = "5"
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o = s:option(Value, "xray_tuic_token", "TUIC Token")
o.password = true
o:depends({type = "v2ray", v2ray_protocol = "tuic", xray_tuic_version = "4"})
o = s:option(Value, "xray_tuic_ca", translate("Certificate File Path"))
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
-- [[ TUIC ]]
-- TuicNameId
o = s:option(Value, "tuic_uuid", translate("TUIC User UUID"))
@@ -933,6 +945,7 @@ o.password = true
o.rmempty = true
o.default = uuid
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic", xray_tuic_version = "5"})
--Tuic IP
o = s:option(Value, "tuic_ip", translate("TUIC Server IP Address"))
@@ -947,9 +960,11 @@ o.password = true
o.rmempty = true
o.default = ""
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic", xray_tuic_version = "5"})
o = s:option(ListValue, "udp_relay_mode", translate("UDP relay mode"))
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o:value("native", translate("native UDP characteristics"))
o:value("quic", translate("lossless UDP relay using QUIC streams"))
o.default = "native"
@@ -957,6 +972,7 @@ o.rmempty = true
o = s:option(ListValue, "congestion_control", translate("Congestion control algorithm"))
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o:value("bbr", translate("BBR"))
o:value("cubic", translate("CUBIC"))
o:value("new_reno", translate("New Reno"))
@@ -965,12 +981,14 @@ o.rmempty = true
o = s:option(Value, "heartbeat", translate("Heartbeat interval(second)"))
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o.datatype = "uinteger"
o.default = "3"
o.rmempty = true
o = s:option(Value, "timeout", translate("Timeout for establishing a connection to server(second)"))
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o.datatype = "uinteger"
o.default = "8"
o.rmempty = true
@@ -1006,6 +1024,7 @@ o.rmempty = true
o = s:option(Flag, "zero_rtt_handshake", translate("Enable 0-RTT QUIC handshake"))
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o.default = "0"
o.rmempty = true
@@ -1437,7 +1456,7 @@ if protocols and type(protocols) == "table" and #protocols > 0 then
if not proto:find("^_") then
if proto == "hysteria2" then
o:depends({type = "v2ray", v2ray_protocol = "hysteria2", hysteria2_realms = false})
elseif proto ~= "socks" and proto ~= "http" and proto ~= "shadowsocksr" then
elseif proto ~= "socks" and proto ~= "http" and proto ~= "shadowsocksr" and proto ~= "tuic" then
o:depends({type = "v2ray", v2ray_protocol = proto})
end
end
@@ -1602,6 +1621,7 @@ o:depends("tls", true)
o:depends("xtls", true)
o:depends("reality", true)
o.rmempty = true
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
o:depends({type = "v2ray", v2ray_protocol = "naive"})
@@ -1631,6 +1651,7 @@ o:value("h3,h2,http/1.1")
o:value("spdy/3.1")
o:value("h3,spdy/3.1")
o:depends("type", "tuic")
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
-- IP STACK PREFERENCE
o = s:option(ListValue, "ipstack_prefer", translate("IP Stack Preference"))
@@ -1648,6 +1669,7 @@ o:depends("type", "trojan")
o:depends("type", "tuic")
o.description = translate("If true, allowss insecure connection at TLS client, e.g., TLS server uses unverifiable certificates.")
o:depends("tls", true)
o:depends({type = "v2ray", v2ray_protocol = "tuic"})
if xray_version_val >= 260131 then
-- Xray 版本大于等于 26.1.31
@@ -74,6 +74,7 @@ then
end
if nixio.fs.access("/usr/bin/xray") or nixio.fs.access("/usr/libexec/xray") then
o:value("naive", "NaiveProxy (Xray)")
o:value("tuic", "TUIC (Xray)")
end
o.default = "socks5"
@@ -235,6 +236,7 @@ o = s:option(Value, "tls_certificateFile", translate("Certificate File Path"))
o.description = translate("e.g.: /etc/ssl/fullchain.pem")
o.rmempty = true
o:depends("tls", "1")
o:depends("type", "tuic")
o:depends("type", "naive")
@@ -242,6 +244,7 @@ o = s:option(Value, "tls_keyFile", translate("Private Key File Path"))
o.description = translate("e.g.: /etc/ssl/private.key")
o.rmempty = true
o:depends("tls", "1")
o:depends("type", "tuic")
-- ========== 传输层设置 (Transport) ==========
o:depends("type", "naive")
@@ -411,4 +414,11 @@ o:value("h2,h3", "HTTP/2 + HTTP/3")
o.default = "h2"
o:depends("type", "naive")
return m
-- TUIC credentials are independent of the legacy server settings.
for _, field in ipairs({{"tuic_uuid", "TUIC UUID"}, {"tuic_password", "TUIC Password"}, {"tuic_token", "TUIC v4 Token"}}) do
o = s:option(Value, field[1], field[2])
o.password = field[1] ~= "tuic_uuid"
o:depends("type", "tuic")
end
return m
+13 -3
View File
@@ -993,7 +993,7 @@ use_mihomo_for_ss_rust_server() {
start_v2ray_with_mihomo() {
# These nodes use Xray-specific settings.
case "$(uci_get_by_name "$1" v2ray_protocol)" in naive|shadowsocksr) return 1 ;; esac
case "$(uci_get_by_name "$1" v2ray_protocol)" in naive|shadowsocksr|tuic) return 1 ;; esac
local sid="$1"
local local_port="$2"
local socks_port="$3"
@@ -1798,7 +1798,7 @@ start_udp() {
;;
v2ray)
enable_mihomo=$(uci_get_by_type server_subscribe enable_mihomo "")
if [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "naive" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "shadowsocksr" ] && [ "$enable_mihomo" = "1" ] && has_mihomo_binary; then
if [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "naive" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "shadowsocksr" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "tuic" ] && [ "$enable_mihomo" = "1" ] && has_mihomo_binary; then
redir_udp=0
ARG_UDP=""
echolog "UDP TPROXY Relay:V2Ray/Xray 单节点由主 Mihomo 实例处理。"
@@ -1811,7 +1811,7 @@ start_udp() {
echolog "UDP TPROXY Relay:$($(first_type xray) version | head -1) Started!"
else
# Xray 不存在但 Mihomo 存在,回退到 Mihomo(当 enable_mihomo=0 时)
if [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "naive" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "shadowsocksr" ] && has_mihomo_binary; then
if [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "naive" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "shadowsocksr" ] && [ "$(uci_get_by_name "$UDP_RELAY_SERVER" v2ray_protocol)" != "tuic" ] && has_mihomo_binary; then
redir_udp=0
ARG_UDP=""
echolog "UDP TPROXY Relay:Xray 内核不存在,已回退到 Mihomo 内核启动。"
@@ -2752,6 +2752,16 @@ start_server() {
echolog "Server: Xray NaiveProxy Server$server_count Started!"
;;
tuic)
xray_bin="$(first_type xray)"
[ -x "$xray_bin" ] || return 1
config_file="$TMP_PATH/xray-server-$server_count.json"
lua /usr/share/shadowsocksr/gen_tuic_server.lua "$1" > "$config_file" || return 1
"$xray_bin" run -test -c "$config_file" >> /var/ssrplus.log 2>&1 || return 1
ln_start_bin "$xray_bin" xray-server-$server_count run -c "$config_file"
echolog "Server: Xray TUIC Server$server_count Started!"
;;
vmess|vless|trojan|shadowsocks)
# Xray 服务端支持
port=$(uci_get_by_name "$1" server_port)
@@ -363,6 +363,26 @@ function outbound:handleIndex(index)
trojan = function()
trojan_shadowsocks()
end,
tuic = function()
local version = tonumber(server.xray_tuic_version) or 5
local alpn = {}
for value in (server.tuic_alpn or ""):gmatch("[^,]+") do alpn[#alpn + 1] = value end
if #alpn == 0 then alpn = {"h3"} end
outbound_settings = {
address = server.server, port = tonumber(server.server_port), version = version,
token = version == 4 and server.xray_tuic_token or nil,
uuid = version == 5 and server.tuic_uuid or nil,
password = version == 5 and server.tuic_passwd or nil,
serverName = server.tls_host, certificateFile = server.xray_tuic_ca,
allowInsecure = server.insecure == "1",
alpn = alpn,
congestionControl = server.congestion_control or "cubic",
udpRelayMode = server.udp_relay_mode or "native",
heartbeatInterval = (tonumber(server.heartbeat) or 10) * 1000,
requestTimeout = (tonumber(server.timeout) or 8) * 1000,
reduceRtt = server.zero_rtt_handshake == "1"
}
end,
shadowsocksr = function()
outbound_settings = {
address = server.server, port = tonumber(server.server_port),
@@ -899,9 +919,9 @@ Xray.outbounds = {
}
}
-- Naive owns TLS/multiplexing; SSR owns obfuscation and uses native UDP.
-- Preserve Xray socket marks and dialer chains for both.
if server.v2ray_protocol == "naive" or server.v2ray_protocol == "shadowsocksr" then
-- Naive and TUIC own TLS/multiplexing; SSR owns obfuscation and native UDP.
-- Preserve Xray socket marks and dialer chains.
if server.v2ray_protocol == "naive" or server.v2ray_protocol == "shadowsocksr" or server.v2ray_protocol == "tuic" then
local ob = Xray.outbounds[1]
ob.streamSettings = { network = "raw", sockopt = ob.streamSettings.sockopt }
ob.mux = nil
@@ -0,0 +1,19 @@
#!/usr/bin/lua
local uci = require("luci.model.uci").cursor()
local json = require "luci.jsonc"
local s = assert(uci:get_all("shadowsocksr", arg[1]), "missing server section")
local users, tokens = {}, {}
if s.tuic_uuid and s.tuic_uuid ~= "" then
users[s.tuic_uuid] = assert(s.tuic_password, "TUIC password required")
end
if s.tuic_token and s.tuic_token ~= "" then tokens[1] = s.tuic_token end
assert(next(users) or #tokens > 0, "TUIC credentials required")
print(json.stringify({
log = {loglevel = "warning"},
inbounds = {{listen = "::", port = assert(tonumber(s.server_port)), protocol = "tuic",
settings = {users = next(users) and users or nil, tokens = #tokens > 0 and tokens or nil,
certificateFile = assert(s.tls_certificateFile), keyFile = assert(s.tls_keyFile)},
streamSettings = {network = "tuic"}
}},
outbounds = {{protocol = "freedom", settings = {}}}
}, 1))
+2 -2
View File
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=xray-core
PKG_VERSION:=26.10.17
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://codeload.github.com/XTLS/Xray-core/tar.gz/v$(PKG_VERSION)?
@@ -10,7 +10,7 @@ PKG_HASH:=62fb186017bc29c3d10950d7a1a61fd40aff0cb92ba2b77363e9004455f6bf89
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
PKG_LICENSE:=MPL-2.0 GPL-3.0-or-later
PKG_LICENSE_FILES:=LICENSE proxy/anytls/LICENSE.sing-anytls proxy/naive/LICENSE.sing-box proxy/shadowsocksr/LICENSE
PKG_LICENSE_FILES:=LICENSE proxy/anytls/LICENSE.sing-anytls proxy/naive/LICENSE.sing-box proxy/shadowsocksr/LICENSE proxy/tuic/LICENSE.mihomo
PKG_BUILD_DIR:=$(BUILD_DIR)/Xray-core-$(PKG_VERSION)
PKG_BUILD_DEPENDS:=golang/host upx/host
File diff suppressed because it is too large. Load diff