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.
This commit is contained in:
Aaron U'Ren 2023-01-01 16:26:59 -06:00 committed by Aaron U'Ren
parent 4f284be53e
commit 0023dedc4d

View File

@ -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