From 8a70fd40eb9730a54d9d27c2325d30ba029f9c1a Mon Sep 17 00:00:00 2001 From: Tomas Hruby Date: Thu, 9 Sep 2021 14:02:40 -0700 Subject: [PATCH] report conflicting device when we fail to add route --- pkg/dataplane/linux/dataplane_linux.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/dataplane/linux/dataplane_linux.go b/pkg/dataplane/linux/dataplane_linux.go index 63673121e..1f8bf2d9f 100644 --- a/pkg/dataplane/linux/dataplane_linux.go +++ b/pkg/dataplane/linux/dataplane_linux.go @@ -338,8 +338,30 @@ func SetupRoutes(hostVeth netlink.Link, result *current.Result) error { return nil } } - return fmt.Errorf("route (Ifindex: %d, Dst: %s, Scope: %v) already exists for an interface other than '%s'", - route.LinkIndex, route.Dst.String(), route.Scope, hostVeth.Attrs().Name) + + // Search all routes and report the conflict, search the name of the iface + routes, err = netlink.RouteList(nil, netlink.FAMILY_ALL) + if err != nil { + return fmt.Errorf("error listing routes") + } + + var conflict string + + for _, r := range routes { + if r.Dst.IP.Equal(route.Dst.IP) { + linkName := "unknown" + if link, err := netlink.LinkByIndex(r.LinkIndex); err == nil { + linkName = link.Attrs().Name + } + + conflict = fmt.Sprintf("route (Ifindex: %d, Dst: %s, Scope: %v, Iface: %s)", + r.LinkIndex, r.Dst.String(), r.Scope, linkName) + break + } + } + + return fmt.Errorf("route (Ifindex: %d, Dst: %s, Scope: %v) already exists for an interface other than '%s': %s", + route.LinkIndex, route.Dst.String(), route.Scope, hostVeth.Attrs().Name, conflict) default: return fmt.Errorf("failed to add route (Ifindex: %d, Dst: %s, Scope: %v, Iface: %s): %v", route.LinkIndex, route.Dst.String(), route.Scope, hostVeth.Attrs().Name, err)