mirror of
https://github.com/netbirdio/go-netroute.git
synced 2026-05-22 17:11:07 -07:00
Merge pull request #33 from libp2p/fix/filternil
Stricter filtering of degenerate routes
This commit is contained in:
@@ -46,6 +46,11 @@ func (rt rtInfo) IsMoreSpecThan(mostSpecificRt *rtInfo) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// if all else is equal, prefer a route with a gateway.
|
||||
if mostSpecificRt.Priority == rt.Priority && rt.Gateway == nil && mostSpecificRt.Gateway != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Windows and MacOS hasn't metric/priority on rule entry,
|
||||
// But the interface device has the priority property.
|
||||
//
|
||||
|
||||
+13
-6
@@ -60,12 +60,7 @@ loop:
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch rt.Family {
|
||||
case syscall.AF_INET:
|
||||
rtr.v4 = append(rtr.v4, &routeInfo)
|
||||
case syscall.AF_INET6:
|
||||
rtr.v6 = append(rtr.v6, &routeInfo)
|
||||
default:
|
||||
if rt.Family != syscall.AF_INET && rt.Family != syscall.AF_INET6 {
|
||||
continue loop
|
||||
}
|
||||
for _, attr := range attrs {
|
||||
@@ -92,6 +87,18 @@ loop:
|
||||
routeInfo.Priority = *(*uint32)(unsafe.Pointer(&attr.Value[0]))
|
||||
}
|
||||
}
|
||||
if routeInfo.Dst == nil && routeInfo.Src == nil && routeInfo.Gateway == nil {
|
||||
continue loop
|
||||
}
|
||||
switch rt.Family {
|
||||
case syscall.AF_INET:
|
||||
rtr.v4 = append(rtr.v4, &routeInfo)
|
||||
case syscall.AF_INET6:
|
||||
rtr.v6 = append(rtr.v6, &routeInfo)
|
||||
default:
|
||||
// should not happen.
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
}
|
||||
sort.Sort(rtr.v4)
|
||||
|
||||
Reference in New Issue
Block a user