diff --git a/tun_linux.go b/tun_linux.go index a1b5560..f35921e 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -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)