From c347755f87ece51792712ea5ca827274ef9370fe Mon Sep 17 00:00:00 2001 From: Etienne Champetier Date: Thu, 20 Apr 2023 14:37:58 -0400 Subject: [PATCH] Fix ValidateExpectedRoute with non default routes and nil GW Using ptp plugin with non default routes, we get the following error when cri-o call CheckNetworkList(): ``` Expected Route {Dst:{IP:198.18.128.0 Mask:ffff8000} GW:} not found in routing table ``` Using cniVersion 0.3.1 to bypass the check, we can see that the route is added with a gateway ``` $ ip r 198.18.0.0/17 via 198.18.0.1 dev eth0 src 198.18.3.102 198.18.0.1 dev eth0 scope link src 198.18.3.102 198.18.128.0/17 via 198.18.0.1 dev eth0 ``` If GW is nil only check if we have a route with a DST that matches, and ignore the GW. Fixes #886 Signed-off-by: Etienne Champetier --- pkg/ip/utils_linux.go | 5 ++++- plugins/main/ptp/ptp_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/ip/utils_linux.go b/pkg/ip/utils_linux.go index 567cd885..12a6175b 100644 --- a/pkg/ip/utils_linux.go +++ b/pkg/ip/utils_linux.go @@ -83,7 +83,10 @@ func ValidateExpectedRoute(resultRoutes []*types.Route) error { // Ensure that each static route in prevResults is found in the routing table for _, route := range resultRoutes { find := &netlink.Route{Dst: &route.Dst, Gw: route.GW} - routeFilter := netlink.RT_FILTER_DST | netlink.RT_FILTER_GW + routeFilter := netlink.RT_FILTER_DST + if route.GW != nil { + routeFilter |= netlink.RT_FILTER_GW + } var family int switch { diff --git a/plugins/main/ptp/ptp_test.go b/plugins/main/ptp/ptp_test.go index 1734dba8..0ede4409 100644 --- a/plugins/main/ptp/ptp_test.go +++ b/plugins/main/ptp/ptp_test.go @@ -368,7 +368,7 @@ var _ = Describe("ptp Operations", func() { doTest(conf, ver, 1, dnsConf, targetNS) }) - It(fmt.Sprintf("[%s] configures and deconfigures a dual-stack ptp link with ADD/DEL", ver), func() { + It(fmt.Sprintf("[%s] configures and deconfigures a dual-stack ptp link + routes with ADD/DEL", ver), func() { conf := fmt.Sprintf(`{ "cniVersion": "%s", "name": "mynet", @@ -381,6 +381,11 @@ var _ = Describe("ptp Operations", func() { [{ "subnet": "10.1.2.0/24"}], [{ "subnet": "2001:db8:1::0/66"}] ], + "routes": [ + { "dst": "0.0.0.0/0" }, + { "dst": "192.168.0.0/16" }, + { "dst": "1.2.3.4/32" } + ], "dataDir": "%s" } }`, ver, dataDir)