From 0b6945712bbfc3b4b64193849f42e97db2f751a8 Mon Sep 17 00:00:00 2001 From: Michael Cambria Date: Wed, 14 Apr 2021 12:25:57 -0400 Subject: [PATCH] Allow multiple routes to be added for the same prefix. Enables ECMP Signed-off-by: Michael Cambria --- pkg/ipam/ipam_linux.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/ipam/ipam_linux.go b/pkg/ipam/ipam_linux.go index bf16cb0ff..8c8b8e0b0 100644 --- a/pkg/ipam/ipam_linux.go +++ b/pkg/ipam/ipam_linux.go @@ -113,11 +113,14 @@ func ConfigureIface(ifName string, res *current.Result) error { gw = v6gw } } - if err = ip.AddRoute(&r.Dst, gw, link); err != nil { - // we skip over duplicate routes as we assume the first one wins - if !os.IsExist(err) { - return fmt.Errorf("failed to add route '%v via %v dev %v': %v", r.Dst, gw, ifName, err) - } + route := netlink.Route{ + Dst: &r.Dst, + LinkIndex: link.Attrs().Index, + Gw: gw, + } + + if err = netlink.RouteAddEcmp(&route); err != nil { + return fmt.Errorf("failed to add route '%v via %v dev %v': %v", r.Dst, gw, ifName, err) } }