fix RouteList can't list routes properly when unspecifying link

Signed-off-by: chengzhycn <chengzhycn@gmail.com>
This commit is contained in:
chengzhycn 2022-10-26 19:19:33 +08:00 committed by Alessandro Boch
parent 8715fe718d
commit 337a587de1
2 changed files with 11 additions and 1 deletions

View File

@ -1004,8 +1004,10 @@ func (h *Handle) RouteList(link Link, family int) ([]Route, error) {
routeFilter := &Route{}
if link != nil {
routeFilter.LinkIndex = link.Attrs().Index
return h.RouteListFiltered(family, routeFilter, RT_FILTER_OIF)
}
return h.RouteListFiltered(family, routeFilter, RT_FILTER_OIF)
return h.RouteListFiltered(family, routeFilter, 0)
}
// RouteListFiltered gets a list of routes in the system filtered with specified rules.

View File

@ -49,6 +49,14 @@ func TestRouteAddDel(t *testing.T) {
t.Fatal("Route not added properly")
}
routes, err = RouteList(nil, FAMILY_V4)
if err != nil {
t.Fatal(err)
}
if len(routes) != 1 {
t.Fatal("Route not listed properly")
}
dstIP := net.IPv4(192, 168, 0, 42)
routeToDstIP, err := RouteGet(dstIP)
if err != nil {