Fix network environment collecting all routes of the default interface

This commit is contained in:
世界
2026-11-25 23:44:43 +08:00
parent becfb0d6ad
commit 43a6cf39f5
+1 -7
View File
@@ -9,7 +9,7 @@ import (
)
func systemGateways(interfaceIndex int) []netip.Addr {
routes, err := netlink.RouteListFiltered(netlink.FAMILY_ALL, &netlink.Route{LinkIndex: interfaceIndex}, netlink.RT_FILTER_OIF)
routes, err := netlink.RouteListFiltered(netlink.FAMILY_ALL, &netlink.Route{LinkIndex: interfaceIndex}, netlink.RT_FILTER_OIF|netlink.RT_FILTER_DST)
if err != nil {
return nil
}
@@ -18,12 +18,6 @@ func systemGateways(interfaceIndex int) []netip.Addr {
if currentRoute.Gw == nil {
continue
}
if currentRoute.Dst != nil {
ones, _ := currentRoute.Dst.Mask.Size()
if ones != 0 {
continue
}
}
gateway, valid := netip.AddrFromSlice(currentRoute.Gw)
if valid {
gateways = append(gateways, gateway.Unmap())