From 779d1c7db292cdbffec4594ac9c88f0d46fcfae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 15 May 2024 22:22:08 +0800 Subject: [PATCH] Fix linux auto-route sequence --- tun_linux.go | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/tun_linux.go b/tun_linux.go index 2eccfc0..22f09aa 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -573,15 +573,16 @@ func (t *NativeTun) rules() []*netlink.Rule { } priority++ } - /*if p6 { + if p4 && !t.options.StrictRoute { it = netlink.NewRule() it.Priority = priority - it.Dst = t.options.Inet6Address.Masked() - it.Table = tunTableIndex - it.Family = unix.AF_INET6 + it.Invert = true + it.Dport = netlink.NewRulePortRange(53, 53) + it.Table = unix.RT_TABLE_MAIN + it.SuppressPrefixlen = 0 + it.Family = unix.AF_INET rules = append(rules, it) - }*/ - if p4 && !t.options.StrictRoute { + it = netlink.NewRule() it.Priority = priority it.IPProto = syscall.IPPROTO_ICMP @@ -591,6 +592,15 @@ func (t *NativeTun) rules() []*netlink.Rule { priority++ } if p6 && !t.options.StrictRoute { + it = netlink.NewRule() + it.Priority = priority6 + it.Invert = true + it.Dport = netlink.NewRulePortRange(53, 53) + it.Table = unix.RT_TABLE_MAIN + it.SuppressPrefixlen = 0 + it.Family = unix.AF_INET6 + rules = append(rules, it) + it = netlink.NewRule() it.Priority = priority6 it.IPProto = syscall.IPPROTO_ICMPV6 @@ -599,26 +609,6 @@ func (t *NativeTun) rules() []*netlink.Rule { rules = append(rules, it) priority6++ } - if p4 && !t.options.StrictRoute { - it = netlink.NewRule() - it.Priority = priority - it.Invert = true - it.Dport = netlink.NewRulePortRange(53, 53) - it.Table = unix.RT_TABLE_MAIN - it.SuppressPrefixlen = 0 - it.Family = unix.AF_INET - rules = append(rules, it) - } - if p6 && !t.options.StrictRoute { - it = netlink.NewRule() - it.Priority = priority6 - it.Invert = true - it.Dport = netlink.NewRulePortRange(53, 53) - it.Table = unix.RT_TABLE_MAIN - it.SuppressPrefixlen = 0 - it.Family = unix.AF_INET6 - rules = append(rules, it) - } } if p4 {