Skip to content

Commit 660222a

Browse files
committed
Fix Linux IPv6 auto route rules
1 parent fee2614 commit 660222a

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

tun_linux.go

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -572,36 +572,31 @@ func (t *NativeTun) rules() []*netlink.Rule {
572572
priority++
573573
}
574574
if p6 {
575-
// FIXME: this match connections from public address
576-
it = netlink.NewRule()
577-
it.Priority = priority6
578-
it.Table = t.options.TableIndex
579-
it.Family = unix.AF_INET6
580-
rules = append(rules, it)
575+
if !t.options.StrictRoute {
576+
it = netlink.NewRule()
577+
it.Priority = priority6
578+
it.IifName = "lo"
579+
it.Src = netip.PrefixFrom(netip.IPv6Unspecified(), 1)
580+
it.Goto = nopPriority
581+
it.Family = unix.AF_INET6
582+
rules = append(rules, it)
581583

582-
/*it = netlink.NewRule()
583-
it.Priority = priority
584-
it.Invert = true
585-
it.IifName = "lo"
586-
it.Table = tunTableIndex
587-
it.Family = unix.AF_INET6
588-
rules = append(rules, it)
584+
it = netlink.NewRule()
585+
it.Priority = priority6
586+
it.IifName = "lo"
587+
it.Src = netip.PrefixFrom(netip.AddrFrom16([16]byte{0: 128}), 1)
588+
it.Goto = nopPriority
589+
it.Family = unix.AF_INET6
590+
rules = append(rules, it)
589591

590-
it = netlink.NewRule()
591-
it.Priority = priority
592-
it.IifName = "lo"
593-
it.Src = netip.PrefixFrom(netip.IPv6Unspecified(), 128) // not working
594-
it.Table = tunTableIndex
595-
it.Family = unix.AF_INET6
596-
rules = append(rules, it)
592+
priority6++
593+
}
597594

598595
it = netlink.NewRule()
599-
it.Priority = priority
600-
it.IifName = "lo"
601-
it.Src = t.options.Inet6Address.Masked()
602-
it.Table = tunTableIndex
596+
it.Priority = priority6
597+
it.Table = t.options.TableIndex
603598
it.Family = unix.AF_INET6
604-
rules = append(rules, it)*/
599+
rules = append(rules, it)
605600
priority6++
606601
}
607602
if p4 {

0 commit comments

Comments
 (0)