Skip to content

TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", port alone, port range, "tcp"/"udp" alone or with port range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery - #7315

Merged
RPRX merged 9 commits into
mainfrom
windows-tun-wfp-all
Nov 2, 2026

Conversation

@patterniha

@patterniha patterniha commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

autoSystemWfpBlockLeak now also takes:

  • "all": everything outside the TUN, IPv4 and IPv6, in both directions, so nothing but Xray leaves except through the TUN.
  • "allexceptlan": like "all", but traffic to and from the local network stays allowed (see below).
  • "tcp", "udp": all ports of that protocol.
  • "tcp/-", "udp/-": a range of ports, both ends within 1-65535, the left not greater than the right.
  • "" or "-" alone: TCP and UDP, e.g. "53" or "10-20". "dns" now stands for "53", "853" and "windnsclient".
  • "icmp": ICMP and ICMPv6, e.g. ping.
  • A CIDR in front of any value, to limit it to those addresses, an IPv6 one in brackets, e.g. "1.1.1.0/24:53", "[2001:db8::/32]:tcp/853", "8.8.8.8/32:all", "0.0.0.0/0:icmp" (IPv4 only) or "[::/0]:misconfigtun" (IPv6 only). It limits what the value stands for or includes as well: "0.0.0.0/0:dns" is "0.0.0.0/0:53", "0.0.0.0/0:853" and "0.0.0.0/0:windnsclient". Like autoSystemRoutingTable, it takes CIDRs only (a single address as "8.8.8.8/32") and no GeoIP; IPv4-mapped IPv6 ones are refused, as Windows checks such connections as IPv4. Without one, a value covers all addresses, as before.

"allexceptlan" keeps printers, the router's settings page, casting to a TV, etc. working: private (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7), link-local (169.254.0.0/16, fe80::/10), multicast (224.0.0.0/4, ff00::/8) and broadcast (255.255.255.255) addresses stay allowed in both directions. It includes "dns", so DNS on the local network stays blocked, as a resolver there (like the router) would forward the queries outside the TUN, and the other values still apply there, e.g. "tcp/445" blocks Windows file sharing, and "192.168.1.5/32:all" one device. "0.0.0.0/0:allexceptlan" includes "0.0.0.0/0:dns" only, so "dns" has to be added to block DNS over IPv6 as well. "all" overrides it.

Values are normalized: lower case, "tcp/1-65535" becomes "tcp", "tcp/53-53" becomes "tcp/53", CIDRs are masked ("1.1.1.1/24:53" becomes "1.1.1.0/24:53"), and repeated values are dropped.

Whatever is blocked, loopback, which cannot leave the system, and what Windows itself needs on the local link always stay allowed: DHCP, DHCPv6, and IPv6 neighbor and multicast listener discovery. Before, these were only allowed along with "misconfigtun"; otherwise "udp" or "icmp" would cut DHCP or IPv6 neighbor discovery, and "tcp" any local proxy, Xray's own inbounds included. With "dns", a local resolver on 127.0.0.1:53 now works for other programs as well (its own queries to port 53 or 853 outside the TUN stay blocked), and it can be the TUN's dns server: loopback servers no longer get the "blocked" warning, and the warning only names servers that a value actually blocks.

The filters, from the heaviest, which wins:

  1. Permit Xray, by its app ID.
  2. Permit loopback, DHCP, DHCPv6, IPv6 neighbor discovery, and everything through the TUN (one permit per layer, in both directions).
  3. Block what the values say: protocols and ports, "all", and "misconfigtun" over an IP version without routes to the TUN.
  4. Permit the DNS Client service's mDNS and LLMNR on the local network.
  5. Block the DNS Client service ("windnsclient").
  6. Permit the local network ("allexceptlan").
  7. Block everything ("all").

"allexceptlan" is the two lightest filters: 7 blocks everything, and 6 lets the local network through. Every other value is heavier, so it still applies on the local network: e.g. the "53" that "allexceptlan" brings along blocks the router's DNS, and "192.168.1.5/32:all" blocks that one device. Likewise, 4 lets mDNS and LLMNR past "windnsclient" (5), but not past another value (3) like "udp". So adding a value can only block more, never open what another value blocks.

Dependencies on other TUN options:

  • "all", "allexceptlan", "dns", "windnsclient", or anything covering TCP or UDP port 53, even to some addresses only ("udp", "53", "1.1.1.1/32:53", "[::/0]:all", "tcp/50-60", ...), needs dns, since Windows may then no longer reach the DNS servers of the other interfaces; the config is rejected otherwise.
  • Like the other values, the new ones need autoSystemRoutingTable.
  • The filters don't need autoOutboundsInterface, as Xray is allowed by its app ID.

README.md now recommends at least "dns" first, lists the values more briefly, and mentions FreeBSD and Linux's xray.tun.fd where they were missing.

Tested on Windows 11 with a Wintun adapter as the outside interface (250/250 checks):

  • "853", "tcp/7215", "udp/7216": TCP and UDP to 853, TCP to 7215 and UDP to 7216 are blocked outside the TUN, TCP to 7216, UDP to 7215 and port 443 are not; over IPv4 and IPv6; all of it works through the TUN.
  • "dns": TCP and UDP to 53 (IPv4 and IPv6) and to 853 are blocked outside the TUN, port 443 and UDP 5300 are not; DNS through the TUN and a local resolver on 127.0.0.1:53 work; WFP holds exactly the expected filters.
  • "tcp/7200-7210", "udp", "icmp": ports 7200, 7205 and 7210 are blocked outside the TUN, 7199 and 7211 are not; all UDP is blocked; ping is blocked outside but works through the TUN; over IPv4 and IPv6.
  • "198.18.216.0/25:all", "[2001:db8:7216::/64]:tcp", "198.18.216.128/25:5300-5301", "198.18.216.0/23:tcp/7300": each blocks only inside its CIDR (TCP, UDP and ping to the /25; TCP 5300 and UDP 5301 to .200; TCP to 2001:db8:7216::80), while the same traffic to addresses outside them still works; TCP 7300 is blocked outside the TUN but works through it, as the /23 covers the TUN's route as well; WFP holds exactly the expected filters.
  • "0.0.0.0/0:tcp/7200-7210", "[::/0]:udp", "0.0.0.0/0:icmp", "[::/0]:windnsclient": each is blocked outside the TUN over its own IP version only, while the other version still works; WFP holds exactly the expected filters, those of the DNS Client service on IPv6 only.
  • "0.0.0.0/0:allexceptlan", "[::/0]:all": the local network works over IPv4 (TCP, UDP, ping) while its DNS (UDP 53, TCP 853) is blocked, and over IPv6 everything is blocked, the local network included; everything else outside the TUN is blocked; the TUN, loopback and Xray's own traffic still work; WFP holds exactly the expected filters.
  • "allexceptlan", "10.216.2.80/32:all", "[fd00:7216:2::80/128]:all": those two devices on the local network are blocked (TCP, UDP, ping), while the rest of it works and its DNS stays blocked; WFP holds exactly the expected filters.
  • "all": TCP, UDP and ping are blocked outside the TUN, the local network included, and work through it; loopback and Xray's own traffic still work; WFP holds exactly the expected filters.
  • "allexceptlan": TCP, UDP and ping to the local network work over IPv4 and IPv6, while DNS to it (UDP/TCP 53, TCP 853) and everything else outside the TUN are blocked; the TUN, loopback and Xray's own traffic still work; WFP holds exactly the expected filters.
  • WFP accepts the filters of every kind of value, CIDRs included (TestLeakFiltersAccepted, elevated).
  • Nothing stays blocked after Xray stops.

Follow-up to #7288. Docs: XTLS/Xray-docs-next#903

🤖 Generated with Claude Code

patterniha and others added 3 commits November 2, 2026 11:13
…p" and port ranges; Always allow loopback, DHCP and IPv6 neighbor discovery

autoSystemWfpBlockLeak now also takes:

- "all": everything outside the TUN, IPv4 and IPv6, in both directions, so
  nothing but Xray leaves except through the TUN.
- "tcp", "udp": all ports of that protocol, also written "tcp/0", "udp/0".
- "tcp/<low>-<high>", "udp/<low>-<high>": a range of ports, matched with
  FWP_MATCH_RANGE, as two conditions on the same field would match when
  either does.
- "icmp": ICMP and ICMPv6, e.g. ping. It takes no port: in ICMP filters the
  local port holds the type, and "icmp/0" would read as the echo reply.

Values are normalized: "tcp/0" and "tcp/1-65535" become "tcp", and
"tcp/53-53" becomes "tcp/53".

Whatever is blocked, loopback, which cannot leave the system, and what
Windows itself needs on the local link now always stay allowed: DHCP, DHCPv6,
and IPv6 neighbor and multicast listener discovery. These used to be allowed
only along with "misconfigtun", so "udp" or "icmp" would otherwise have cut
DHCP or IPv6 neighbor discovery, and "tcp" any local proxy, Xray's own
inbounds included. Loopback being allowed means that with "dns", a local
resolver on 127.0.0.1:53 now works for other programs (its own queries to
port 53 or 853 outside the TUN stay blocked), and the DNS Client service
may use it.

"all" reuses the filters of "misconfigtun", which now also let everything
through the TUN, for both IP versions whatever the routes.

On other TUN options: keeping the system's DNS inside the TUN, with "all",
"dns", "windnsclient", or anything covering TCP or UDP port 53 ("udp",
"tcp/50-60", ...), needs dns, as Windows can no longer reach the DNS
servers of the other interfaces; the config is rejected otherwise. Like the
other values, the new ones need autoSystemRoutingTable. The filters do not
need autoOutboundsInterface, as Xray is allowed by its app ID; it still
keeps Xray's own connections out of the TUN's routes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"allexceptlan" is "all" but for the local network: traffic to and from
private (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7), link-local
(169.254.0.0/16, fe80::/10), multicast (224.0.0.0/4, ff00::/8) and broadcast
(255.255.255.255) addresses stays allowed, so that printers, the router's
settings page, or casting to a TV keep working while nothing else leaves
outside the TUN.

It includes "dns": a resolver on the local network, like the router's,
would forward the queries outside the TUN, so DNS stays blocked there. The
LAN permit sits below the other values, like the permit through the TUN, so
they still apply on the local network, e.g. "tcp/445" blocks Windows file
sharing with it. The DNS Client service keeps mDNS and LLMNR, to the local
network's addresses only. "all" overrides it.

The addresses are matched with FWP_V4_ADDR_MASK and FWP_V6_ADDR_MASK
conditions on the remote address, which match when any of them does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With autoSystemWfpBlockLeak, loopback now always stays allowed, so a DNS
server in dns like 127.0.0.1, a local resolver, stays reachable although
it lies in neither gateway nor autoSystemRoutingTable. Leave loopback
servers out of the warning that queries to them cannot go through the TUN
and are blocked, and say so in the README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

@patterniha 我又想了下 /0 这种写法还是算了,不加语法糖,/- 严格检查左右两端在 1-65535 的范围内,左侧不大于右侧

还有区分 v4/v6 的事情以后再设计吧(目前同时),以及区分本地/远程端口(目前仅远程),以及出/入流量(目前同时)

…-65535

"tcp/0" and "udp/0" no longer stand for all ports, which "tcp" and "udp"
already say: no syntactic sugar. Port 0 is rejected like any port outside
1-65535. Ranges keep being checked strictly: both ends within 1-65535, the
left one not greater than the right one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

@patterniha v4v6 的区分比较简单现在就可以做了:"tcpv4"、"udpv6"、"icmpv4",剩下两点先保持现状,契合该功能的定位

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

或者如果合适的话可以把 v4/v6 移到前面作为所有选项的可选项,不过 WFP 还能处理非 IP 流量所以,或许以后再想怎么设计

…, "udpv6", "icmpv4" and "icmpv6"

"v4" or "v6" after the protocol limits a value to one IP version, ports
written the same way, e.g. "tcpv4/853" or "udpv6/10-20"; "icmpv4" is ICMP
and "icmpv6" is ICMPv6. Their filters go to the ALE layers of that version
only. "tcp", "udp" and "icmp" keep covering both.

Anything covering TCP or UDP port 53 in either IP version, like
"udpv4/53", still needs dns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patterniha patterniha changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp" and port ranges; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp" (also "tcpv4", "udpv6", ...) and port ranges; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@patterniha

Copy link
Copy Markdown
Collaborator Author

@patterniha 我又想了下 /0 这种写法还是算了,不加语法糖,/- 严格检查左右两端在 1-65535 的范围内,左侧不大于右侧
@patterniha v4v6 的区分比较简单现在就可以做了:"tcpv4"、"udpv6"、"icmpv4",剩下两点先保持现状,契合该功能的定位

done, doc is also updated.

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

@patterniha 不使用 "tcpv4" 这种写法了,改为 任何选项前面 都可以加 IP 版本,: 分隔,比如 "ipv4:udp/53"、"ipv6:all"

以后要区分 remote/local、out/in 的话大概是 "ipv4+remote+out:udp/53" 这样写,还没想好,以后再说

TUN 的 README.md 和文档可以写得精简些,等发了这个版本后我来合并文档那两个 PR 吧

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

不过可以开头写一句:建议至少配置 "dns" 以阻止 DNS 泄露,至于 "misconfigtun",还不如提醒写好 autoSystemRoutingTable

综上,应当更新一下“使用提示”,另外 FreeBSD 也支持 autoSystemDnsToGateway 了,autoSystemRoutingTable 似乎也支持

你根据 TUN 的更新把 README.md 和文档缺的都补上吧,XTLS/Xray-docs-next#906 合并进 XTLS/Xray-docs-next#903

patterniha and others added 3 commits November 2, 2026 17:52
…f any value instead of "tcpv4" and the like

"ipv4:" or "ipv6:" in front of any value limits it to that IP version,
e.g. "ipv4:udp/53", "ipv6:all", "ipv4:dns" or "ipv6:misconfigtun".
"tcpv4", "udpv6", "icmpv4" and the like are gone. Values that only differ
in the IP version become one: "ipv4:udp/53" with "ipv6:udp/53" is
"udp/53".

"all" overrides "allexceptlan" per IP version, and "all" over one IP
version needs dns, as port 53 over one does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… README.md, and shorten it

README.md now recommends at least "dns" to block DNS leaks, and lists the
values of autoSystemWfpBlockLeak more briefly, "dns" first. It also lists
FreeBSD among the systems, and mentions that on Linux, as on Android, the
TUN can be a file descriptor from xray.tun.fd (XRAY_TUN_FD).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add "dns" to block DNS over IPv6 as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patterniha patterniha changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp" (also "tcpv4", "udpv6", ...) and port ranges; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp", port ranges and "ipv4:"/"ipv6:" in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@patterniha

Copy link
Copy Markdown
Collaborator Author

code and doc updated.

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

@patterniha f5cc086 这个是啥意思

我又想了下,"ipv4:" 这种写法也不要了,改成 "CIDR/single-IP:",功能更强大,另外这个方便支持 GeoIP 吗,麻烦的话就算了

至于语法糖,不支持仅写 "CIDR",毕竟有 "all",所以 IPv6 一定要加 [],但可以支持一下 "CIDR:10-20",经典写法符合直觉

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

既如此那么只写端口范围 "10-20" 或单个数字比如 "10" 也支持一下吧,TCP 和 UDP 同时,"dns" 的表述也可以简化为三个值了

@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

autoSystemRoutingTable 似乎没支持 GeoIP,那这里也算了;另外它支持 single-IP 吗?不支持的话这里也一样,反正用处不大

…instead of "ipv4:" and "ipv6:"; Ports alone for TCP and UDP

A CIDR in front of any value limits it to its addresses, an IPv6 one in
brackets, e.g. "1.1.1.0/24:53", "[2001:db8::/32]:tcp/853" or
"[::/0]:all": "0.0.0.0/0:" and "[::/0]:" take the place of "ipv4:" and
"ipv6:". Like autoSystemRoutingTable, it takes CIDRs only, a single
address as "8.8.8.8/32", and no GeoIP.

"<port>" or "<low>-<high>" alone stands for TCP and UDP, so "dns" is
"53", "853" and "windnsclient" now.

The filters follow:
- One filter per layer permits what goes through the TUN, instead of one
  for each value.
- "all" and "misconfigtun" outweigh the local network that "allexceptlan"
  leaves open, so with it, "192.168.1.5/32:all" still blocks that address.
- The DNS Client service's mDNS and LLMNR stay allowed on the local network
  only, and only while no other value blocks them.
- The warning about blocked DNS servers only names those a value blocks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@patterniha

Copy link
Copy Markdown
Collaborator Author

@patterniha What does f5cc086 mean?

~I thought about it again.~The "ipv4:" notation is no longer needed; replace it with "CIDR/single-IP:" for more powerful functionality.Also, does this feature support GeoIP? If it's too much trouble, then forget it.

As for syntactic sugar, simply writing "CIDR" is not supported, since "all" is included, so IPv6 must include it []. However, "CIDR:10-20" can be supported, as the classic syntax is intuitive.

@RPRX f5cc086: "allexceptlan" includes "dns", and with "ipv4:" in front it only included "ipv4:dns", so DNS over IPv6 stayed open unless "dns" was added too. The line said that; now it's part of the CIDR sentence ("0.0.0.0/0:allexceptlan" leaves DNS over IPv6 open).

Done in 9638715:

  • A CIDR in front of any value instead of "ipv4:"/"ipv6:", IPv6 in brackets: "1.1.1.0/24:53", "[2001:db8::/32]:tcp/853", "[::/0]:all". "0.0.0.0/0:" and "[::/0]:" are the old "ipv4:" and "ipv6:".
  • autoSystemRoutingTable takes CIDRs only (netip.ParsePrefix on every system), no single IP and no GeoIP, so the same here: one address is "8.8.8.8/32".
  • "53" or "10-20" alone is TCP and UDP, so "dns" is "53", "853", "windnsclient" now.
  • "all" with a CIDR also beats the local network that "allexceptlan" leaves open, e.g. ["allexceptlan", "192.168.1.5/32:all"] blocks only that device there.

@patterniha patterniha changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp", port ranges and "ipv4:"/"ipv6:" in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp", ports alone, port ranges and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX

RPRX commented Nov 2, 2026

Copy link
Copy Markdown
Member

本来还想支持区分 IP 子协议,不过这样的话又要 "allexcept..." 呃有点烧脑了,况且 TUN 的典型配置是将系统所有 IPv4v6 流量路由进 TUN,除了 TCP、UDP、ICMP 外其它的全没处理,貌似也没啥大问题,还是说 Windows 不会将某些 IP 子协议路由进来

如果有如此复杂的“挖洞”需求(CIDR、选项),最佳实践是再出一个 excluded 数组,以后再说吧,remote/local、out/in 也是

@RPRX RPRX changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", "tcp", "udp", "icmp", ports alone, port ranges and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port & ports range, "tcp", "udp", "icmp" and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX RPRX changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port & ports range, "tcp", "udp", "icmp" and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port & ports range, "tcp", "udp" alone & with ports range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX RPRX changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port & ports range, "tcp", "udp" alone & with ports range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port, ports range, "tcp"/"udp" alone / with ports range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX RPRX changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", single port, ports range, "tcp"/"udp" alone / with ports range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", port alone, port range, "tcp"/"udp" alone / with port range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX RPRX changed the title TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", port alone, port range, "tcp"/"udp" alone / with port range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery TUN inbound's autoSystemWfpBlockLeak: Add "all", "allexceptlan", port alone, port range, "tcp"/"udp" alone or with port range, "icmp", and a CIDR in front of any value; Always allow loopback, DHCP and IPv6 neighbor discovery Nov 2, 2026
@RPRX
RPRX merged commit 967ade1 into main Nov 2, 2026
50 of 51 checks passed
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.

2 participants