From adf147ba65cf12b558314a42b4e2b03b76509294 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 ++++++++----- plugins/main/bridge/bridge.go | 2 +- 2 files changed, 9 insertions(+), 6 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) } } diff --git a/plugins/main/bridge/bridge.go b/plugins/main/bridge/bridge.go index 69ffa98f1..638b70922 100644 --- a/plugins/main/bridge/bridge.go +++ b/plugins/main/bridge/bridge.go @@ -122,7 +122,7 @@ func calcGateways(result *current.Result, n *NetConf) (*gwInfo, *gwInfo, error) // Add a default route for this family using the current // gateway address if necessary. - if n.IsDefaultGW && !gws.defaultRouteFound { + if n.IsDefaultGW { for _, route := range result.Routes { if route.GW != nil && defaultNet.String() == route.Dst.String() { gws.defaultRouteFound = true