Enhance nft firewall rules; add support for IPv6 suffix matching #4219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
完善nftables防火墙规则的导入,包括添加对IPv6后缀匹配的支持。
1)由于有设备需要开放端口,且公网IPv6的前缀时常变动,我在OpenWrt上添加了匹配IPv6后缀的规则。但OpenClash并没有成功导入这一规则,因为nft规则有特定的格式要求,需要进行转换。以往,有需要的朋友会通过自定义脚本来解决 #3929 #3088 (comment) ,而完善代码后,包含端口的这类规则将可以自动读取。
PS. 目前的代码还不支持导入只有IP没有端口的防火墙规则。这是为什么呢?看起来这意味着openclash_mangle_output(_v6)链要return来自所有端口的流量,这应该会带来问题,但我不太理解为什么要这样。如果能通过其他办法规避问题,我可以试着修改,比如在此情况下只添加openclash_mangle链的规则。
2)如果nft规则中出现多个IP,OpenClash会无法导入该规则,将IP之间的空格改为逗号即可解决。
3)如果nft规则中出现端口范围,OpenClash会无法导入该规则。脚本中提示称这可能影响正常流量经过核心,并将其return,但后续在iptables的相关部分,又存在将端口范围的”-“改成”:“的代码,这还有意义吗?如果根据提示,在”黑白名单“中添加绕过的端口,这将无法区分来源的IP。我觉得有提示已经足够了,直接return可能不符合大家预期的行为。但如果作者有更多考虑,可以将其恢复,我再想其他办法解决问题~
不论如何,非常感谢开发者的辛勤付出!