Skip to content

Commit 337a587

Browse files
chengzhycnaboch
authored andcommitted
fix RouteList can't list routes properly when unspecifying link
Signed-off-by: chengzhycn <[email protected]>
1 parent 8715fe7 commit 337a587

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

route_linux.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,10 @@ func (h *Handle) RouteList(link Link, family int) ([]Route, error) {
10041004
routeFilter := &Route{}
10051005
if link != nil {
10061006
routeFilter.LinkIndex = link.Attrs().Index
1007+
1008+
return h.RouteListFiltered(family, routeFilter, RT_FILTER_OIF)
10071009
}
1008-
return h.RouteListFiltered(family, routeFilter, RT_FILTER_OIF)
1010+
return h.RouteListFiltered(family, routeFilter, 0)
10091011
}
10101012

10111013
// RouteListFiltered gets a list of routes in the system filtered with specified rules.

route_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ func TestRouteAddDel(t *testing.T) {
4949
t.Fatal("Route not added properly")
5050
}
5151

52+
routes, err = RouteList(nil, FAMILY_V4)
53+
if err != nil {
54+
t.Fatal(err)
55+
}
56+
if len(routes) != 1 {
57+
t.Fatal("Route not listed properly")
58+
}
59+
5260
dstIP := net.IPv4(192, 168, 0, 42)
5361
routeToDstIP, err := RouteGet(dstIP)
5462
if err != nil {

0 commit comments

Comments
 (0)