Skip to content

fix(firewall): prerouting 链内用 drop 替代 reject,修复 fw4 整份规则集加载失败 - #677

Closed
LYOI wants to merge 1 commit into
immortalwrt:masterfrom
LYOI:fix/nft-reject-in-prerouting
Closed

LYOI wants to merge 1 commit into
immortalwrt:masterfrom
LYOI:fix/nft-reject-in-prerouting

Conversation

@LYOI

@LYOI LYOI commented Nov 14, 2026

Copy link
Copy Markdown

现象

ImmortalWrt 24.10(kernel 5.4.302 / nftables 1.1.6)上启用 homeproxy 后,/etc/init.d/firewall restart 直接失败:

/var/run/homeproxy/fw4_post.nft:9853:2-73: Error: Could not process rule: Not supported
	meta nfproto { ipv4, ipv6 } meta l4proto udp jump homeproxy_mangle_lanac
	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The rendered ruleset contains errors, not doing firewall restart.

fw4 的语义是「整份规则集要么全装、要么全不装」,因此一条规则被内核拒绝,等于所有规则都没装。表现为:

  • dstnat 里的 TCP 重定向没有生效
  • homeproxy_redirect* 链全部为空(nft list ruleset | grep homeproxy 为 0 条)
  • 客户端流量完全绕过代理:面板里节点状态正常、测速正常,但浏览器打不开 Google / YouTube

排查时很容易误判成节点故障或 DNS 问题,因为代理进程本身是健康的。

根因

报错行只是定位点,真正被内核拒绝的是同一张链里的这条规则:

udp dport { 80, 443 } counter reject comment "!<cfgname>: Fuck you QUIC"

reject 在 prerouting 钩子里不被内核支持——发 ICMP / TCP RST 需要路由结果,此时还没有,内核返回 EOPNOTSUPP,nftables 记为 Not supported。

最小复现:

table inet t {
  chain c { udp dport 443 counter reject }
  chain h {
    type filter hook prerouting priority mangle; policy accept;
    meta l4proto udp jump c
  }
}

nft -c -f 报 Could not process rule: Not supported;把 reject 换成 drop,校验立刻通过。

改动

root/etc/homeproxy/scripts/firewall_post.ut,共 4 处(tproxy 与 tun 两个分支各 2 处):

- udp dport { 80, 443 } counter reject comment "!{{ cfgname }}: Fuck you QUIC"
+ udp dport { 80, 443 } counter drop comment "!{{ cfgname }}: block quic"

语义不变:这条规则的目的就是阻断 QUIC,让浏览器回落到 TCP。drop 与 reject 对客户端的效果一致(UDP 80/443 都不通),而 drop 在 prerouting 中合法。顺带把注释里的脏话换成中性描述。

验证

设备:ARM64 / ImmortalWrt 24.10 / kernel 5.4.302 / nftables 1.1.6

步骤 结果
渲染后的规则集 nft -c -f 通过
/etc/init.d/firewall restart 无报错,规则全部装上
nft list chain inet fw4 homeproxy_redirect_lanac 有规则,counter 正常增长
客户端访问 YouTube / Google / GitHub 200 / 302 / 200
客户端访问 baidu 200,国内直连未受影响

建议

后续在 prerouting 里做阻断动作统一用 drop;reject 只适用于 input / forward / output 钩子。

…ting

reject is not supported inside a prerouting hook: the kernel needs a routing
decision to emit ICMP/RST and returns EOPNOTSUPP, so nftables aborts with

  Error: Could not process rule: Not supported

fw4 loads the rule set as a whole, so a single rejected rule makes it keep the
previous (empty) rule set:

  The rendered ruleset contains errors, not doing firewall restart.

The result is that homeproxy_redirect* stay empty and client traffic bypasses
the proxy completely - the panel shows healthy nodes and working latency tests,
yet browsers cannot open Google/YouTube.

Blocking QUIC on udp 80,443 only needs the packets to be dropped so browsers
fall back to TCP, which drop does as well as reject and is valid in prerouting.
Also replaces the profanity in the comment with a neutral description.

Verified on ImmortalWrt 24.10 / kernel 5.4.302 / nftables 1.1.6: nft -c passes,
firewall restart succeeds, redirect chains get rules and counters, clients reach
YouTube/Google/GitHub while domestic sites stay direct.
@LYOI LYOI closed this Nov 14, 2026
@LYOI
LYOI deleted the fix/nft-reject-in-prerouting branch November 14, 2026 12:25
@1715173329 1715173329 added invalid This doesn't seem right AI-generated This issue/PR is AI-generated. labels Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-generated This issue/PR is AI-generated. invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants