From d89ab3f20716768026de28640b669d51767eae06 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Wed, 9 Apr 2025 13:35:20 +0800 Subject: [PATCH] Fix IncludeInterface/ExcludeInterface priority --- tun_linux.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tun_linux.go b/tun_linux.go index 72aac6a..6a3549d 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -668,7 +668,7 @@ func (t *NativeTun) rules() []*netlink.Rule { } } if len(t.options.IncludeInterface) > 0 { - matchPriority := priority + 2*len(t.options.IncludeInterface) + 1 + matchPriority := priority + 2 for _, includeInterface := range t.options.IncludeInterface { if p4 { it = netlink.NewRule() @@ -677,7 +677,6 @@ func (t *NativeTun) rules() []*netlink.Rule { it.Goto = matchPriority it.Family = unix.AF_INET rules = append(rules, it) - priority++ } if p6 { it = netlink.NewRule() @@ -686,9 +685,14 @@ func (t *NativeTun) rules() []*netlink.Rule { it.Goto = matchPriority it.Family = unix.AF_INET6 rules = append(rules, it) - priority6++ } } + if p4 { + priority++ + } + if p6 { + priority6++ + } if p4 { it = netlink.NewRule() it.Priority = priority @@ -726,7 +730,6 @@ func (t *NativeTun) rules() []*netlink.Rule { it.Goto = nopPriority it.Family = unix.AF_INET rules = append(rules, it) - priority++ } if p6 { it = netlink.NewRule() @@ -735,9 +738,15 @@ func (t *NativeTun) rules() []*netlink.Rule { it.Goto = nopPriority it.Family = unix.AF_INET6 rules = append(rules, it) - priority6++ } } + + if p4 { + priority++ + } + if p6 { + priority6++ + } } if runtime.GOOS == "android" && t.options.InterfaceMonitor.AndroidVPNEnabled() {