Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance nft firewall rules; add support for IPv6 suffix matching #4219

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

jelly21fish
Copy link
Contributor

完善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可能不符合大家预期的行为。但如果作者有更多考虑,可以将其恢复,我再想其他办法解决问题~

不论如何,非常感谢开发者的辛勤付出!

Enhance the conversion of nftables firewall rules including support for IPv6 suffix matching.
@vernesong
Copy link
Owner

部分人存在大范围开端口的情况,直接饶过会影响大部分过墙流量

@jelly21fish
Copy link
Contributor Author

@vernesong 感谢大佬的回复!我已经撤销了删去return的修改(等以后我弄明白具体原理再想想怎么完善好了,目前这样确实更稳妥)。关于IPv6后缀匹配和多IP规则的修改,应该没有问题吧?另外,我觉得很多人会意识不到这个情况——有端口范围的规则和只有IP没有端口的规则没有被载入,所以在日志里加上提示会比较好?如果需要的话,我也可以修改日志描述和相应的汉化~

@vernesong vernesong merged commit 3b2567e into vernesong:dev Dec 12, 2024
@jelly21fish jelly21fish deleted the patch-1 branch December 12, 2024 16:56
@jelly21fish jelly21fish restored the patch-1 branch December 12, 2024 16:56
@jelly21fish jelly21fish deleted the patch-1 branch December 12, 2024 16:57
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