From fa68f9d017980556c02b4d14203f2b413fc9fda9 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Thu, 23 Jun 2016 16:21:58 -0400 Subject: [PATCH] Make sure route selected is direct Signed-off-by: Clint Armstrong --- libnetwork/osl/route_linux.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libnetwork/osl/route_linux.go b/libnetwork/osl/route_linux.go index 78d1f9a14f..a9ff191b37 100644 --- a/libnetwork/osl/route_linux.go +++ b/libnetwork/osl/route_linux.go @@ -83,17 +83,29 @@ func (n *networkNamespace) programGateway(gw net.IP, isAdd bool) error { return fmt.Errorf("route for the gateway %s could not be found: %v", gw, err) } + var linkIndex int + for _, gwRoute := range gwRoutes { + if gwRoute.Gw == nil { + linkIndex = gwRoute.LinkIndex + break + } + } + + if linkIndex == 0 { + return fmt.Errorf("Direct route for the gateway %s could not be found", gw) + } + if isAdd { return n.nlHandle.RouteAdd(&netlink.Route{ Scope: netlink.SCOPE_UNIVERSE, - LinkIndex: gwRoutes[0].LinkIndex, + LinkIndex: linkIndex, Gw: gw, }) } return n.nlHandle.RouteDel(&netlink.Route{ Scope: netlink.SCOPE_UNIVERSE, - LinkIndex: gwRoutes[0].LinkIndex, + LinkIndex: linkIndex, Gw: gw, }) }