Skip to content

Outbounds: Avoid circular dependencies with the built-in DNS - #7425

Merged
RPRX merged 7 commits into
mainfrom
freedom-circular-dependency
Nov 21, 2026
Merged

RPRX merged 7 commits into
mainfrom
freedom-circular-dependency

Conversation

@Meo597

@Meo597 Meo597 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

重写 Lua 文档的时候被迫写了下面加粗的这段,觉得十分不科学,应该把它做成和 targetStrategy 一样防环,没有大的副作用。各出站的行为也比较统一。

::: warning 循环依赖
任意查询交给内置 DNS 模块处理时,若选中 DNS 服务器的 address 不含 +local,则到该服务器的连接会交给路由。若 address 是域名,路由脚本可能再次调用内置 DNS 解析它。新的查询可能按 DNS 和路由规则顺利完成,也可能经过多个 DNS 服务器和出站,重新依赖尚未完成的解析,形成死循环。

为避免这种潜在的循环依赖,DNS 模块会将自身发起的所有连接标记为 skipDNSResolve = true。核心原生的路由模块不检查是否真的成环,而是据此标记简单粗暴地跳过 DNS 解析,直接杜绝成环可能;请求随后继续匹配其余规则并交给出站。Lua 脚本需要自行处理该标记,建议同样跳过解析,也可以按需扩展处理方式。

Freedom 出站不会检查 skipDNSResolve。若脚本将这类连接交给它,且其 sockopt.domainStrategy 非 AsIs,就会再次调用内置 DNS 解析该域名。路由脚本无法干预出站的解析,需另行规避,不再赘述;其他出站的 targetStrategy 会像路由一样检查该标记跳过解析以避免成环。

其他出站也有另一种成环路径。若代理出站的服务器地址为域名,且 sockopt.domainStrategy 非 AsIs,出站就会调用内置 DNS 解析该地址。例如,出站 A 依赖 DNS A 的解析结果,而 DNS A 的查询又被送回出站 A,就会形成死循环;也可能先送到出站 B,再因解析 B 的服务器地址而回到 DNS A,形成更长的依赖链。这些出站与 DNS 之间的循环与路由脚本无关,需另行规避,此处不再赘述。

@Meo597

Meo597 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author
  • geodata 如果没设置 outbound 则应尊重路由和出站的想法来解析,而不是打标记跳过
  • 同理 loopback 重路由的流量不应该无脑跳过解析
  • 出站切断环的时候打 info 级别日志提醒用户,路由和 dialer 那边不做因为会重复
  • 备忘 freedom 看到跳过标记会把 UDP 逐包解析也在此 session 临时绕过,无副作用因为打标的三个都不受它影响

@patterniha

patterniha commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

this PR completely break "Serverless-for-Iran" and other serverless-configs.

in "Serverless for Iran" we should use DOH-with-fragment to obtain correct DNS addresses.

but DOH-domains are blocked in DNS, so we should use DOH IPs in Hosts:

"dns": {
  "hosts": {
      "cloudflare-dns.com": ["104.16.248.249", "104.16.249.249", "2606:4700::6810:f8f9", "2606:4700::6810:f9f9"]
  },
  "servers": {
      "https://cloudflare-dns.com/dns-query"
   }
},
"outbound": [
{
  "protocol": "direct",
  "streamSettings": {
    "finalmask": "fragment..."
    "sockopt":{
      "domainStrategy": "ForceIP",
      "happyEyeballs": "..."
    }
  }
}
]

also there is no reason for normal users to use DOH in freedom, anyway programs like v2rayN automatically add a DNS-server-with-DOH-domain-with-IP-DNS to prevent this loop.

when you use DOH in v2rayN, it automatically add:

{
  "address": "223.5.5.5",
  "domains": ["full:DOH-domain"]
}

to DNS servers (other programs should do the same if they want supporting DOH in freedom).

So, this is not a core problem, we should be able to use built-in-DNS (others/hosts) for DOH-domain.

@patterniha patterniha closed this Nov 16, 2026
@patterniha

patterniha commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Also, this approach doesn't help when using Linux with TUN. Even with AsIs, AsIs-DNS request is still sent back to Xray-core. Therefore, we should still add a DNS server with the DoH domain and IP-based DNS, similar to v2rayN.

@RPRX

RPRX commented Nov 16, 2026

Copy link
Copy Markdown
Member

直接关别的 member 的 PR 不太好,如果讨论确定这个修改没意义再关吧

@RPRX RPRX reopened this Nov 16, 2026
@patterniha

Copy link
Copy Markdown
Collaborator

It's not a good idea to directly close another member's PR. Let's close it only if the discussion confirms that the change is meaningless.

I just closed it because I am sure this approach is wrong, I never close PRs unless I'm sure.

@Meo597

Meo597 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

哎。。。又来了,因为伊朗“成千上万”人都在用所以不管不顾直接 close/reopen
这个 PR 除了切断环之外,还解决了一些其它问题 #7425 (comment) 都没看完直接滥权
@LjhAUMEM 撂挑子就是你直接 reopen #7372 引起的

完全不管这些烂玩意糊进去的恶劣影响,这么喜欢乱玩为什么不在自己的 fork 里瞎弄?
其次你往核心里糊的一坨💩给我造成了很大的困扰,文档十分难写

这个 PR 目的之一是让 targetStrategy 和 domainStrategy 行为一致,归根结底还是解决你弄出来的烂玩意
而且 targetStrategy 是你声称伊朗“成千上万”人都在用的 server-less-iran 刚需,最后被证实根本没用

首先你应该学会尊重人
其次你 PR 的时候最起码测一下能不能用
第三你在 close/reopen PR 的时候至少应该看完上下文,看不懂还可以问 AI

@Meo597

Meo597 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

没心思折腾了,目前此 PR 暂时不切断 sockopt.domainStrategy 和 DNS 之间潜在的环,仅 log
有待以后 #6371 (comment) 实现的时候把 IP 直接做到这里,再去切

@Meo597

Meo597 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

PR 保持原样,改本机 hosts、用 freedom.redirect
又或者改几行代码检测到 finalmask 时不切环仅 log
一万种办法解决你所谓的伊朗“成千上万人”都在用 server-less

直接 close PR 神操作,你的主没教过你要尊重人吗?

@patterniha

Copy link
Copy Markdown
Collaborator

After all the effort I've put into "Serverless", someone is trying to ruin it. Do you expect me to just sit back and watch it get merged?

I don’t know why no one ever complained when @Fangliding closed dozens of my PRs, even after I became a member.

Also, this isn't just about "Serverless".
With Linux + TUN, it doesn't matter whether you use Asis or UseIP — requests in both cases are routed back to Xray.

So the right approach is to add an IP-based-DNS-server for DOH-domain, not to restrict the core's capabilities.

In freedom.redirect you can only set one fixed-IP, you can't use other DNS-server, you can't use IPv6 for dual-stack users, and you can't use happyEyeballs.

Also targetStrategy is not useless, it is now a key-feature for IP-based protocols like wireguard and masque.

@patterniha

Copy link
Copy Markdown
Collaborator

The existing DNS-avoid-loop restriction for targetStrategy has prevented us from using DoH (with domain) for wireguard/masque (If we want the DoH request itself to go through wireguard/masque, while its domain name is resolved via other-DNS/hosts).

So we should remove the restriction on targetStrategy, rather than imposing an additional restriction on freedom.

@Meo597

please add skipDNSResolve option to DNS objects, and we only set SkipDNSResolve to true in

SkipDNSResolve: true,
(or in nameserver_tcp/nameserver_quic) when it is true.

it's default can be true or false, it doesn't matter.

This way, we can reach an agreement.

@Meo597

Meo597 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Also targetStrategy is not useless, it is now a key-feature for IP-based protocols like wireguard and masque.

麻烦你搞清楚,这是我和 @RPRX @Fangliding @KobeArthurScofield 前后花了五个月时间讨论
期间我反复改了好几版,才把它理顺,使其融入 Xray 架构,不和其它选项,甚至是你自己 PR 的一些功能打架
WireGuard 使用 targetStrategy 也是 #6771 我和 @LjhAUMEM 讨论的结果
此前它一直是废功能,你自己臆想的“刚需”也没用上

你唯一“贡献”就是把它强行糊进 Xray 里,然后恶心看文档的用户,和对着它反复改了好几版文档的我和 @Fangliding

@Meo597

Meo597 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

targetStrategy 的防环检查不应被移除,因为 WG 需要它
也不应该再给 DNS 做一个 SkipDNSResolve 恶心用户
目前 sockopt.domainStrategy 暂时只打日志提示,就这样吧

@patterniha

patterniha commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

目前 sockopt.domainStrategy 暂时只打日志提示,就这样吧

If you agreed that you shouldn’t have restricted the freedom, then why did you send all these unnecessary comments?

@RPRX

RPRX commented Nov 19, 2026

Copy link
Copy Markdown
Member

讨论出共识了没

@Meo597

Meo597 commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

“友好协商”之后,就是各退一步,“成千上万”伊朗人都在用的 server-less-iran 不必变更配置
freedom's sockopt.domainStrategy 也暂不强行切断潜在的环,只是打 info 日志提醒用户
我看了下 info 本就会刷屏,因此正经人都是 warn 只有遇到问题调试的时候降等级 core 也尽了提醒的义务

@RPRX RPRX mentioned this pull request Nov 21, 2026
@RPRX
RPRX merged commit 8f0bb9f into main Nov 21, 2026
34 of 35 checks passed
@RPRX
RPRX deleted the freedom-circular-dependency branch November 21, 2026 20:37
@shagouzi233

shagouzi233 commented Nov 22, 2026 •

Copy link
Copy Markdown

dns server如果本来就是ip形式,即使不是+local是不是没环,这种情况没必要打日志吧,以及域名形式的dns server如果在dns模块中配置了hosts是不是也不应该打日志

@Meo597

Meo597 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

的确可以多判一下,但 hosts 没法做不能现在就给 dns 传 ctx
反正有 udp+local:// 并且是 info 级别本就刷屏呢
等以后重构 dns 模块时再说吧

patterniha added a commit to patterniha/Xray-core that referenced this pull request Nov 22, 2026
Brings in XTLS/Xray-core up to 74cbdf4 (4 commits). XTLS's version is
unchanged, so the fork's core/core.go stays 26.11.22. Includes: XMC
finalmask Yggdrasil third-party login and texture verification (XTLS#7416),
outbounds avoiding circular dependencies with the built-in DNS (XTLS#7425),
the HTTPUpgrade client closing the connection when the upgrade fails
(XTLS#7395) and a README update (XTLS#7446).

No conflicts. XTLS#7395 is identical to the fork's early merge of it
(cbf3dac), so transport/internet/httpupgrade/dialer.go is unchanged.
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.

4 participants