zebra: Put nhe ifp setting inside alloc

Put the setting of the ifp on a nexthop group hash
entry into the zebra_nhg_alloc() function. It should
only be added if its not a group/recursive (it doesn't
have any depends) and its nexthop type has an ifindex.

This also provides functionality for proto-side ifp
setting.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
This commit is contained in:
Stephen Worley 2019-04-11 12:11:49 -04:00
parent bbb3940ed1
commit 7b683a96e4
2 changed files with 19 additions and 7 deletions

View File

@ -2447,12 +2447,6 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
id);
nhg_connected_head_free(&nhg_depends);
} else {
/* Add the nhe to the interface's tree
* of connected nhe's
*/
if (ifp)
zebra_nhg_set_if(nhe, ifp);
SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED);
SET_FLAG(nhe->flags, NEXTHOP_GROUP_VALID);
}

View File

@ -308,7 +308,6 @@ static void *zebra_nhg_alloc(void *arg)
nhe->refcnt = 0;
nhe->is_kernel_nh = copy->is_kernel_nh;
nhe->dplane_ref = zebra_router_get_next_sequence();
nhe->ifp = NULL;
/* Attach backpointer to anything that it depends on */
zebra_nhg_dependents_init(nhe);
@ -319,6 +318,25 @@ 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) {
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;
}
}
/* Add to id table as well */
zebra_nhg_insert_id(nhe);