From 0023dedc4dc04d905c4ac6f0a0d165d265ef5280 Mon Sep 17 00:00:00 2001 From: Aaron U'Ren Date: Sun, 1 Jan 2023 16:26:59 -0600 Subject: [PATCH] fix(NRC): error when nec. host IP not found If we can't find an appropriate IP to add for nextHop to injectRoute or overlay tunnel, raise error rather than trying to continue. --- pkg/controllers/routing/network_routes_controller.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/routing/network_routes_controller.go b/pkg/controllers/routing/network_routes_controller.go index 0f6c8de4..856b24ca 100644 --- a/pkg/controllers/routing/network_routes_controller.go +++ b/pkg/controllers/routing/network_routes_controller.go @@ -649,7 +649,7 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error { switch { case link != nil: - // if we setup an overlay tunnel link, then use it for destination routing + // if we set up an overlay tunnel link, then use it for destination routing var bestIPForFamily net.IP if dst.IP.To4() != nil { bestIPForFamily = utils.FindBestIPv4NodeAddress(nrc.primaryIP, nrc.nodeIPv4Addrs) @@ -657,6 +657,10 @@ func (nrc *NetworkRoutingController) injectRoute(path *gobgpapi.Path) error { // Need to activate the ip command in IPv6 mode bestIPForFamily = utils.FindBestIPv6NodeAddress(nrc.primaryIP, nrc.nodeIPv6Addrs) } + if bestIPForFamily == nil { + return fmt.Errorf("not able to find an appropriate configured IP address on node for destination "+ + "IP family: %s", dst.String()) + } route = &netlink.Route{ LinkIndex: link.Attrs().Index, Src: bestIPForFamily, @@ -734,6 +738,10 @@ func (nrc *NetworkRoutingController) setupOverlayTunnel(tunnelName string, nextH bestIPForFamily = utils.FindBestIPv6NodeAddress(nrc.primaryIP, nrc.nodeIPv6Addrs) ipipMode = "ip6ip6" } + if nil == bestIPForFamily { + return nil, fmt.Errorf("not able to find an appropriate configured IP address on node for destination "+ + "IP family: %s", nextHop.String()) + } // an error here indicates that the tunnel didn't exist, so we need to create it, if it already exists there's // nothing to do here