zebra: Fix nhg ifindex setting and checking

We were only setting and checking the ifindex if
the nexthop had an *_IFINDEX type. However, when nexthop
active checking is done, the non-*_IFINDEX types can also
obtain a nexthop with an ifindex and are thus valid too.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
This commit is contained in:
Stephen Worley 2019-04-22 15:42:10 -04:00
parent e22e80010e
commit a6e6a6d825
2 changed files with 10 additions and 17 deletions

View File

@ -1962,10 +1962,12 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx)
req.nhm.nh_family = AF_INET6;
switch (nh->type) {
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
addattr_l(&req.n, sizeof(req), NHA_GATEWAY,
&nh->gate.ipv4, IPV4_MAX_BYTELEN);
break;
case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX:
addattr_l(&req.n, sizeof(req), NHA_GATEWAY,
&nh->gate.ipv6, IPV6_MAX_BYTELEN);
@ -1978,13 +1980,13 @@ static int netlink_nexthop(int cmd, struct zebra_dplane_ctx *ctx)
case NEXTHOP_TYPE_IFINDEX:
/* Don't need anymore info for this */
break;
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV6:
}
if (!nh->ifindex) {
flog_err(
EC_ZEBRA_NHG_FIB_UPDATE,
"Context received for kernel nexthop update without an interface");
return -1;
break;
}
addattr32(&req.n, sizeof(req), NHA_OIF, nh->ifindex);

View File

@ -312,22 +312,13 @@ static void *zebra_nhg_alloc(void *arg)
}
/* Add the ifp now if its not a group or recursive and has ifindex */
if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop) {
if (zebra_nhg_depends_is_empty(nhe) && nhe->nhg->nexthop
&& nhe->nhg->nexthop->ifindex) {
struct interface *ifp = NULL;
switch (nhe->nhg->nexthop->type) {
case NEXTHOP_TYPE_IPV4_IFINDEX:
case NEXTHOP_TYPE_IPV6_IFINDEX:
case NEXTHOP_TYPE_IFINDEX:
ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex,
nhe->vrf_id);
zebra_nhg_set_if(nhe, ifp);
break;
case NEXTHOP_TYPE_BLACKHOLE:
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV6:
break;
}
ifp = if_lookup_by_index(nhe->nhg->nexthop->ifindex,
nhe->vrf_id);
zebra_nhg_set_if(nhe, ifp);
}
/* Add to id table as well */