Add back random iproute2 table index

This commit is contained in:
世界 2026-02-02 14:10:06 +08:00
parent 2e21cd99ef
commit 635920688d
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -3,6 +3,7 @@ package tun
import (
"errors"
"fmt"
"math/rand"
"net"
"net/netip"
"os"
@ -283,6 +284,16 @@ func (t *NativeTun) Start() error {
return nil
}
if t.options.IPRoute2TableIndex == 0 {
for {
t.options.IPRoute2TableIndex = int(rand.Uint32())
routeList, fErr := netlink.RouteListFiltered(netlink.FAMILY_ALL, &netlink.Route{Table: t.options.IPRoute2TableIndex}, netlink.RT_FILTER_TABLE)
if len(routeList) == 0 || fErr != nil {
break
}
}
}
err = t.setRoute(tunLink)
if err != nil {
_ = t.unsetRoute0(tunLink)