Skip to content

Xray-core: Add Lua script for dns and routing - #6823

Merged
RPRX merged 32 commits into
mainfrom
lua
Oct 10, 2026
Merged

RPRX merged 32 commits into
mainfrom
lua

Conversation

@Meo597

@Meo597 Meo597 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator
DNS 示例
{
  "dns": {
    "script": "dns.lua",
    "tag": "dns-proxy",
    "servers": [
      { "id": "cf", "address": "1.1.1.1" },
      { "id": "google", "address": "8.8.8.8" },
      { "id": "cn114", "address": "114.114.114.114", "tag": "dns-direct" },
      { "id": "cn223", "address": "223.5.5.5", "tag": "dns-direct" },
      { "id": "google-ecs", "address": "8.8.8.8", "clientIp": "222.85.85.85" },
      {
        "id": "google-alt-ecs",
        "address": "8.8.4.4",
        "clientIp": "222.85.85.85"
      }
    ]
  }
}
-- 场景:优先直连,未知域名用 ECS 探测,非中国一律走代理
local geodata = require("xray.geodata")
local log = require("xray.log")
local dns = require("xray.dns")
local servers = {}

-- 未配置 dns(或未配置任何 DNS server)时,dns.Servers 会自动提供 ID 为 "localhost" 的服务器。
-- 它使用系统解析器,查询本地网卡配置的 DNS,可通过下面构建的 servers["localhost"] 获取。
for _, server in ipairs(dns.Servers) do
    servers[server.ID] = server
end

local google_domains = geodata.BuildDomainMatcher("geosite:google")
local cn_domains = geodata.BuildDomainMatcher("geosite:cn")
local foreign_domains = geodata.BuildDomainMatcher("geosite:geolocation-!cn")
local cn_ips = geodata.BuildIPMatcher("geoip:cn")

log.Info("DNS script loaded")

function HandleDNSQuery(domain, ipv4, ipv6, fake)
    log.Debug("DNS query: ", domain, ", ipv4=", ipv4, ", ipv6=", ipv6, ", fake=", fake)

    local last_error

    local function ask(id, region)
        local server = assert(servers[id], "missing DNS server: " .. id)
        log.Debug("DNS upstream: ", id)

        local ips, ttl, err = server:Query(domain, ipv4, ipv6, fake)
        if err then
            log.Warning("DNS upstream ", id, " failed: ", err)
            last_error = err
            return nil
        end

        -- IP 列表可能为 nil;取长度或索引前先判 nil。
        if not ips or #ips == 0 then
            log.Debug("DNS upstream ", id, " returned no IPs")
            return nil
        end

        -- ips[i] 可取出单个 IP 用于日志等特殊处理;匹配和筛选使用整组 IP。它的开销较大应谨慎使用。
        local first_ip = ips[1]
        log.Debug("DNS answer: upstream=", id, ", first IP=", first_ip)

        if region then
            -- FilterIPs(ips) 将整组 IP 分为匹配和未匹配两组。
            local in_cn, outside_cn = cn_ips:FilterIPs(ips)
            ips = region == "cn" and in_cn or outside_cn

            local count = ips and #ips or 0
            log.Debug("DNS filter: upstream=", id, ", region=", region, ", remaining=", count)
            if count == 0 then
                return nil
            end
        end

        return ips, ttl
    end

    local ips, ttl
    if google_domains:MatchAny(domain) then
        -- Google 域名只使用公共 DNS。
        ips, ttl = ask("cf")
        if not ips then
            ips, ttl = ask("google")
        end

    elseif cn_domains:MatchAny(domain) then
        -- 中国域名先走直连 DNS,只接受中国 IP;随后回退到代理 DNS。
        ips, ttl = ask("cn114", "cn")
        if not ips then
            ips, ttl = ask("cn223", "cn")
        end
        if not ips then
            ips, ttl = ask("cf")
        end
        if not ips then
            ips, ttl = ask("google")
        end

    elseif foreign_domains:MatchAny(domain) then
        -- 非中国域名先排除中国 IP;随后尝试带 ECS 的查询。
        ips, ttl = ask("cf", "non-cn")
        if not ips then
            ips, ttl = ask("google", "non-cn")
        end
        if not ips then
            ips, ttl = ask("google-ecs")
        end
        if not ips then
            ips, ttl = ask("google-alt-ecs")
        end

    else
        -- 未知域名先寻找中国 IP;随后回退到普通公共 DNS。
        ips, ttl = ask("google-ecs", "cn")
        if not ips then
            ips, ttl = ask("google-alt-ecs", "cn")
        end
        if not ips then
            ips, ttl = ask("cf")
        end
        if not ips then
            ips, ttl = ask("google")
        end
    end

    if ips then
        log.Debug("DNS resolved: ", domain, ", ttl=", ttl)
        return ips, ttl, nil
    end

    log.Error("DNS query failed: ", domain, ", error=", last_error)
    return nil, 0, last_error
end
Router 示例
{
  "routing": {
    "script": "router.lua",
    "balancers": [
      {
        "tag": "proxy",
        "selector": ["proxy-"],
        "strategy": {
          "type": "random"
        }
      }
    ]
  }
}
-- 本示例用于展示 Router Lua API 的全部能力。
-- 为了把接口都用一遍,下面的路由逻辑是刻意拼出来的,没有实际配置意义。
local geodata = require("xray.geodata")
local log = require("xray.log")
local dns = require("xray.dns")
local router = require("xray.router")

local servers = {}
-- 未配置 dns(或未配置任何 DNS server)时,dns.Servers 会自动提供 ID 为 "localhost" 的服务器。
-- 它使用系统解析器,查询本地网卡配置的 DNS,可通过下面构建的 servers["localhost"] 获取。
for _, server in ipairs(dns.Servers or {}) do
    servers[server.ID] = server
end

local ads_domains = geodata.BuildDomainMatcher("geosite:category-ads-all")
local cn_domains = geodata.BuildDomainMatcher("geosite:cn")
local foreign_domains = geodata.BuildDomainMatcher("geosite:geolocation-!cn")
local private_ips = geodata.BuildIPMatcher("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "127.0.0.0/8", "::1/128",
    "fc00::/7")
local cn_ips = geodata.BuildIPMatcher("geoip:cn")

local process_lookup_supported = router.LocalOS == "linux" or router.LocalOS == "windows"

log.Info("Router script loaded: os=", router.LocalOS)

local function pick_proxy(rule)
    local outbound, err = router:PickOutbound("proxy")
    if err then
        log.Error("Router balancer failed: rule=", rule, ", error=", err)
        return nil, nil, err
    end
    return outbound, rule, nil
end

local function resolve_target(domain, server_id)
    local ips, ttl, err
    local server = server_id and servers[server_id]

    if server then
        log.Debug("Router DNS server: ", server_id, ", domain=", domain)
        ips, ttl, err = server:Query(domain, true, true, false)
        if not err and ips and #ips > 0 then
            return ips, ttl, nil
        end
        log.Warning("Router DNS server failed: ", server_id, ", error=", err or "no IPs")
    end

    log.Debug("Router DNS delegated query: ", domain)
    return dns.Query(domain, true, true, false)
end

function HandleRoute(ctx, inboundTag, sourcePort, targetPort, localPort, targetDomain, network, protocol, user,
    vlessRoute, skipDNSResolve)
    log.Debug("Route request: inbound=", inboundTag, ", sourcePort=", sourcePort, ", targetPort=", targetPort,
        ", localPort=", localPort, ", domain=", targetDomain, ", network=", network, ", protocol=", protocol, ", user=",
        user, ", vlessRoute=", vlessRoute, ", skipDNSResolve=", skipDNSResolve)

    if network == router.NetworkUnknown then
        return nil
    end

    -- DNS server 的 tag 会作为查询连接的 inboundTag 进入路由。
    if inboundTag == "dns-direct" then
        return "direct", "dns-direct", nil
    elseif inboundTag == "dns-proxy" then
        return pick_proxy("dns-proxy")
    end

    if network == router.NetworkUNIX then
        return "direct", "unix", nil
    end

    if inboundTag == "api" then
        return "direct", "management", nil
    end

    local source_ips
    if localPort == 10085 and sourcePort > 0 then
        source_ips = ctx:GetSourceIPs()
        if private_ips:AnyMatch(source_ips) then
            return "direct", "management", nil
        end
    end

    -- attributes 是 HTTP 请求的方法、路径和 headers;非 HTTP 流量不读取。
    if string.sub(protocol, 1, 4) == "http" then
        local attributes = ctx:GetAttributes()
        local method = attributes[":method"]
        local path = attributes[":path"]
        local accept = attributes["accept"]

        if method == "GET" and path and string.find(path, "/internal/", 1, true) == 1 then
            return "direct", "http-internal", nil
        elseif accept and string.find(string.lower(accept), "text/html", 1, true) then
            return pick_proxy("http-html")
        end
    end

    if targetDomain ~= "" and ads_domains:MatchAny(targetDomain) then
        return "block", "ads", nil
    end

    if protocol == "bittorrent" then
        return "direct", "bittorrent", nil
    end

    if network == router.NetworkUDP and targetPort == 53 then
        return "direct", "dns-packet", nil
    end

    if user == "[email protected]" then
        return "direct", "trusted-user", nil
    end

    if vlessRoute ~= 0 then
        return pick_proxy("vless-route")
    end

    -- 进程查询相对昂贵,这里只为 TUN 入站启用。
    if process_lookup_supported and inboundTag == "tun" and
        (network == router.NetworkTCP or network == router.NetworkUDP) then
        local pid, name, path, err = router.FindProcess(ctx)
        if err then
            log.Warning("Router process lookup failed: ", err)
        else
            log.Debug("Router process: pid=", pid, ", name=", name, ", path=", path)

            -- 使用不带 .exe 的进程名精确匹配,与原生 ProcessNameMatcher 的规则一致。
            if name == "qbittorrent" then
                return "direct", "process-bittorrent", nil
            elseif name == "chrome" or name == "firefox" then
                return pick_proxy("process-browser")
            end
        end
    end

    if targetDomain ~= "" then
        if cn_domains:MatchAny(targetDomain) then
            return "direct", "cn-domain", nil
        elseif foreign_domains:MatchAny(targetDomain) then
            return pick_proxy("foreign-domain")
        end
    end

    -- 前面的规则未命中时,才读取目标 IP。
    -- IP 列表可能为 nil;取长度或索引前先判 nil,AnyMatch(nil) 返回 false。
    local target_ips = ctx:GetTargetIPs()
    -- AnyMatch(ips) 判断整组 IP 中是否有匹配项。
    if private_ips:AnyMatch(target_ips) then
        if not source_ips then
            source_ips = ctx:GetSourceIPs()
        end
        if private_ips:AnyMatch(source_ips) then
            local local_ips = ctx:GetLocalIPs()
            if private_ips:AnyMatch(local_ips) then
                return "direct", "private-network", nil
            end
        end
    end

    if cn_ips:AnyMatch(target_ips) then
        return "direct", "cn-ip", nil
    end

    -- 按索引取单个 IP 用于日志等特殊处理;取值前先判 nil 和长度。
    if target_ips and #target_ips > 0 then
        local first_ip = target_ips[1]
        log.Debug("Router first target IP: ", first_ip)
    end

    -- 未分类域名先查询指定 server;server 不存在或查询失败时,回退到完整委托 dns.Query。
    if targetDomain ~= "" and not skipDNSResolve then
        local ips, ttl, err = resolve_target(targetDomain, "cf")
        if err then
            log.Warning("Router DNS failed: domain=", targetDomain, ", error=", err)
        elseif not ips or #ips == 0 then
            log.Warning("Router DNS returned no IPs: domain=", targetDomain)
        else
            log.Debug("Router DNS resolved: domain=", targetDomain, ", ttl=", ttl)
            if private_ips:AnyMatch(ips) then
                return "direct", "resolved-private", nil
            elseif cn_ips:AnyMatch(ips) then
                return "direct", "resolved-cn", nil
            end
            return pick_proxy("resolved-foreign")
        end
    end

    if network == router.NetworkTCP and (targetPort == 80 or targetPort == 443) then
        return pick_proxy("web")
    elseif network == router.NetworkUDP and targetPort == 443 then
        return pick_proxy("quic")
    end

    return nil
end

感觉这玩意更适合 finalmask 这个 vibe 重灾区

设计上尽量解耦,方便以后能挂在每条连接上,想咋玩就咋玩
预期是脚本能接入 dns inbound routing outbound balancer protocol finalmask

简单测了下性能可以接受,略吃内存,有待以后进一步优化
call dns hook + dns client query 的耗时从 4714 ns 降为 1839 ns
call dns hook 的内存从 816 B, 9 allocs 降为 16 B, 1 allocs

经过多轮优化,目前是:

DNS benchmark ns/op B/op allocs/op
只调 Lua hook,固定返回 357.9 16 1
调 hook,再查一次 DNS client 1665 576 10
原生 Go 790.4 480 6
路由 benchmark ns/op B/op allocs/op
只调 Lua hook,固定返回 892.9 168 11
用 Lua 完成一次路由选择 1589 240 13
原生 Go 133.0 80 1

@RPRX

RPRX commented Sep 26, 2026

Copy link
Copy Markdown
Member

这个会不会有点重了,bin 体积会增加多少?

@Meo597

Meo597 commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

体积仅增加约 500KiB

只给 DNS 用看起来比较鸡肋,因为通过复杂的配置也可达成相同效果,且性能更佳

主要目的是接下来把其它模块都串起来,以满足一些特殊需求,比如:

  • 当 balancer 改变了出口时,修改 dns 的 ecsip
    这种东西显然不适合放在内核通过配置文件做
  • 或可缓解 finalmask 大量 vibe 情况
  • 解决总有人说 xray 没有策略组、ruleset 的问题
    其实是有的,只不过要 balancer + loopback 套娃
  • 还能干什么我想都不敢想

起因是我被隔壁的 ruleset 逻辑套娃硬控了好几个小时
与其把配置文件当代码写,不如直接写代码

@Fangliding

Copy link
Copy Markdown
Member

重爆了这 主要是就为了一个dns引这玩意

@Meo597

Meo597 commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

重爆了这

有效代码 600 行,体积增大 500KiB


主要是就为了一个dns引这玩意

画个大饼

-- balancer 改变了出口时,修改 dns 的 ecsip
function on_balancer_change(balancerId, outbound)
    dns.servers["default_proxy"].clientIp = ecs[outbound]
end
-- balancer 入站 ip 粘性,每次使用都续期;连续 5 分钟未使用才过期,出口故障则立即重新选择。
function balance(inbound_ip)
    local tag = sticky.get(inbound_ip)

    if tag and outbound.is_alive(tag) then
        sticky.touch(inbound_ip, "5m")
        return tag
    end

    tag = balancer.select()
    sticky.set(inbound_ip, tag, "5m")
    return tag
end

@Fangliding

Fangliding commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

我看到上面说的二进制大小的膨胀了 不是只有这样重 还有加这玩意的额外逻辑和维护问题
重点它不是一个纯是需要复杂逻辑而引入的图灵机 而是为了这个lua引擎 需要把各种本来go里的对象捏成lua可调用的东西 这都需要代码 完了还得维护一个文档 现在捏了个可调geodata 以后还得要个balancer change的回调 回头可能再看一眼observer里的观测数据 都需要改到这些组件里去 这一切的一切 只是为了选个DNS 而且除了你以外的人大概还看不懂

@Meo597

Meo597 commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

如果只是为了选 DNS,确实没必要引入 Lua。
DNS 是第一个接入点,Lua 主要目的是把各模块串起来,让用户实现上面那些联动场景,而不用为每种特殊需求都往内核里塞一堆东西。
比如上面提到的 balancer 粘性,我记得有人提过 PR 被 close 了。
Lua 带来无限可能。

维护成本当然存在,但没有想象中那么重。暴露一个 API 或者 hook 只需要几十行代码比如 219f758
以后还可以让脚本随连接存活,保存选择、统计和标记,贯穿整个连接生命周期,让不同模块的 hook 配合起来。
我想提供的是这种可组合的能力,而不仅是一个 DNS 功能。

@LjhAUMEM

Copy link
Copy Markdown
Contributor

如果能够做到 lua 插拔自定义 mask 真的很酷,然后 core 里就只保留一些通用性强的 mask

我个人是支持这个的,但 #6718 的 0 vibe 纯手工重构已经把我精力耗光了,需要来个 gap year,以及后续需要写点 rust 找回之前写 c 的手感 (写了这么多 go 手感全无),如果有人能来主持 finalmask 会很好

@Meo597

Meo597 commented Sep 26, 2026

Copy link
Copy Markdown
Collaborator Author

虽然我从没看过 finalmask 的代码(甚至都没用过)
但直觉 Lua 在 fm 会更有用

所以设计时也考虑了并发、内存和脚本的生命周期
重一点的初始化、建缓存只在创建时做,平时跑 hook 尽量轻
需要保存状态,也能让 local 跟着实例一直活着
脚本甚至支持热重载

比如 custom header 那个大号计算器,改用 Lua 后就能写条件分支、循环,保存连接里的变量
先读长度再读内容,看对面回了什么再决定下一步,不用继续往配置里堆东西

再往后,现在 fm 都是各干各的,想改点行为又得在 core vibe 一套
以后把收发、字节处理、随机数、定时、连接控制这些基础能力开放出来
用户就能自己写脚本组合 noise、跳跃、自定义握手,不用每搞一种玩法都往内核里塞一套实现

@RPRX

RPRX commented Sep 27, 2026

Copy link
Copy Markdown
Member

引入一个脚本引擎是可以接受的,不如就用这个来搞 NEXT 架构吧

@Meo597

Meo597 commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator Author

我设想把脚本分成三种生命周期:

  • 池化:用于 DNS、FinalMask、Router 等并发 Hook。一个脚本可创建多个实例,数量随负载动态调整。每个 Hook 点只绑定一个脚本。
  • 全局:每个脚本常驻一个实例,与 Xray 同生命周期。可以同时运行多个全局脚本,处理其它所有 Hook。每个 Hook 点多个脚本,链式或做注册时冲突检查。
  • 连接:每条连接创建一个实例,状态贯穿连接生命周期。内存成本较高,暂时没想好具体场景,可能根本没有需求。

三种脚本拥有相同的 Event 订阅和操作 Xray 的能力,区别只在于实例生命周期和适用的 Hook 点。

这样侵入的很小,就像现在这个 DNS 一样。

不知道这样符不符合 NEXT 架构的预期

@RPRX

RPRX commented Sep 28, 2026

Copy link
Copy Markdown
Member

NEXT 架构大概是组件可任意串联,尤其是哪里都能塞路由/DNS,以及增强匹配/行为语法(比如这个 lua),最好还能判断/修改一些内部变量,以及配置文件和 API 改为一行行加载脚本的形式而不是现在这种固定 JSON 加 gRPC API,貌似应当全用 lua

@Meo597

Meo597 commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Lua 能干更多事情之后,迫切需要重构 DNS 做成全功能的了,暂时没有那么多精力
路由我在这个 PR 还是分开做

@HPPC114514

Copy link
Copy Markdown

我觉得这个功能可以剥离xray-core,只需要在xray-core里面留一个扩展接口/api,通过接口连接外置一个lua runtime二进制然后就能为所欲为了
但是这样的话性能表现估计会很难看。。。

@RPRX

RPRX commented Sep 29, 2026

Copy link
Copy Markdown
Member

就 500k 还是别剥离出去了吧,还指望靠它完全重构 Xray 的配置和 API 呢,之前频道说的“完全可编程协议”似乎也能用这个做

之前想的是引入一个 Go 解释器,lua 似乎更合适些?@Meo597

@Meo597

Meo597 commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator Author

剥离出去代码反而会变重,基本没法写
看目前此 PR 状态就知道,对 core 几乎无侵入,没什么维护成本


我先后试过 tengo yaegi wazero goja gopherlua

考虑接口暴露便利程度、并发安全、跨语言调用性能、内存开销、脚本自身执行性能、修改方便程度

lua 几乎是唯一解

@Meo597

Meo597 commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

之前频道说的“完全可编程协议”似乎也能用这个做

跟 finalmask 难点一样,想要把 payload 完全读到脚本 vm 去做会有性能问题
yaegi 比 lua 还要慢

最快的是 wazero 但它太太太重了
和 core 交互需要拷贝内存,不适合大量 hook event call 的场景
之前想的是 go 暴露出来一些常用 fn,实在不行单就 fm、protocol 再上 wazero

目前此 pr 已经是 ready 状态
提供 log geodata dns 能力,提供 dns router 的 hook

Meo597 added 2 commits October 1, 2026 18:25
Expose localdns.Client in xray.dns.Servers with the ID "localhost",
so Lua scripts can use the same server API for both clients.
@RPRX

RPRX commented Oct 10, 2026

Copy link
Copy Markdown
Member

@Meo597 再次 ready 了吗,文档先写一下

@Meo597

Meo597 commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

再次 ready 了
目前相当于大号的 dns/router rule
解决了没有 ruleset logic 的问题

因为是热路径不能用反射,所以花了许多功夫优化,写的比较啰嗦

下个 PR 是一些 event 和对 xray 的一些操控,全局型的脚本
顶上有示例,文档正在写

@RPRX RPRX changed the title feat(dns): add Lua scripting for DNS queries Xray-core: Add Lua script for dns and routing Oct 10, 2026
@RPRX
RPRX merged commit 8855145 into main Oct 10, 2026
@Meo597
Meo597 deleted the lua branch October 10, 2026 09:17
Jolymmiles added a commit to Jolymmiles/Xray-core that referenced this pull request Oct 10, 2026
Upstream's Lua scripts (XTLS#6823) have two problems that keep them out of
this fork for now:

- common/lua.Pool creates one state (about 177 KiB plus the script's
  data) per concurrent call and only bounds idle states. With a script
  on an inbound that accepts unauthenticated connections, nothing caps
  the states or the factory runs. A plain semaphore is not a fix: a
  routing script whose DNS lookup re-enters routing holds one state
  while it waits for another, and a failed acquisition sends the
  connection to the default outbound, past the script.
- Scripts load in Start, after the inbound manager starts, so the
  connections accepted first and the TUN DNS takeover probe see only
  the JSON rules.

core.New now rejects a config that names a routing or DNS script while
common/lua.ScriptsEnabled is false, which it always is outside tests.
The check sits where each config is registered: an error from a
deferred RequireFeatures callback can be lost, and this one must stop
the instance. The upstream code stays compiled and tested, so later
syncs merge without conflicts, and lifting the gate needs no revert.

TestCoreRejects{Routing,DNS}ScriptWhileScriptsDisabled failed before
this change: core.New accepted both configs.

Review findings R1-1 and R1-3 on PR #33.
Jolymmiles added a commit to Jolymmiles/Xray-core that referenced this pull request Oct 10, 2026
Maintainer decision on PR #33: the Lua scripts (XTLS#6823) ship as upstream
ships them. This reverts 8d9977b, 6a6625a and 6562b8c, which made
core.New refuse routing.script and dns.script.

docs/FORK.md records the two risks accepted with this decision, review
findings R1-1 and R1-3: the state pool has no bound on concurrent
states, and scripts load after the inbound manager starts. The routing
script still decides on the dispatcher's PickRouteTag path.
Meo597 added a commit to XTLS/Xray-docs-next that referenced this pull request Oct 11, 2026
@Meo597

Meo597 commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

文档补了,即便有 AI 加持还是写的我人都麻了

@Meo597

Meo597 commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

备忘

写路由脚本的时候发现很多注入的参数其实用不到
之前设计的时候为了避免 go 和 lua 来回调用全都给拉平了
这导致不必要的开销

以后有人觉得这里是瓶颈,可以改为初始化的时候脚本自己声明需要哪些参数

TaiLerV pushed a commit to TaiLerV/Xray-core-up that referenced this pull request Oct 13, 2026
Sync the fork with upstream 7da5dae..v26.10.10 (13 commits).

Conflict resolutions:
- Routing and DNS Lua scripts (XTLS#6823): take them. The dispatcher picks
  routes through the fork's PickRouteTag, which bypassed the script hook
  upstream placed in PickRoute; PickRouteTag now runs the script too, and
  NeedsSniffingAttributes reports true while a script is loaded because a
  script can read attributes. Covered by script_fastpath_test.go and by
  upstream's TestRouterScriptDNSDispatcherReentry, which failed without it.
- Logging: the Lua log module calls the fork's ShouldLog instead of
  upstream's GetSeverity; its tests save and restore the fork's handler
  snapshot and filter through Enabled.
- Dispatcher: keep the ShouldLog guard and add upstream's error log for a
  failed route pick.
- XDNS (XTLS#7095): take upstream's synchronous upload and its fragment
  manager without the per-client size counter. The fork's full-queue test
  becomes a test that every written packet reaches a resolver; the
  fragment-manager test checks entries only.
- Hysteria (XTLS#7107): keep the fork's pool cleaner (docs/FORK.md); take only
  OmitMaxDatagramFrameSize: true, which the old date check already gave.
- TLS client: keep session resumption in copyConfig and add upstream's
  GetClientCertificate bridge for MASQUE WARP.
- go.mod: add gopher-lua (MIT), gopher-luar (MPL-2.0) and
  x509roots/fallback; keep golang.org/x/text v0.43.0.
- Version stamp stays 26.10.6-2241 until the next fork release.
onesyue added a commit to onesyue/Xray-core that referenced this pull request Oct 17, 2026
Upstream 8855145 (XTLS#6823, Lua `script` for dns and routing) binds app/dns
into every routing script, and app/dns links the DoQ name server and with
it github.com/apernet/quic-go. yue-node's check-profile-deps.sh forbids
both in the VLESS role graph, so the rebased fork failed the consumer's
profile boundary.

The dns.RegisterLua call moves behind the profile tag: unchanged by default,
and under yue_profile_vless a configured routing script is refused instead
of running with a silently missing `dns` global. yue-node never configures a
routing script. script_dns_vless_test.go asserts the refusal and that the
VLESS app/router graph has neither app/dns nor quic-go; re-importing app/dns
in the VLESS file turns it red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Plugin System based on WASM (wazero) for Hot-Patching Protocols & Logic on Mobile [idea] Dynamic strategies

5 participants