Merge pull request #33 from libp2p/fix/filternil

Stricter filtering of degenerate routes
This commit is contained in:
Steven Allen
2023-03-06 15:36:59 -08:00
committed by GitHub
2 changed files with 18 additions and 6 deletions
+5
View File
@@ -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
View File
@@ -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)