From 7b683a96e4227956cfe6236628885b1421b62781 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Thu, 11 Apr 2019 12:11:49 -0400 Subject: [PATCH] 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 --- zebra/rt_netlink.c | 6 ------ zebra/zebra_nhg.c | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index db8e28cea0..4407167521 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -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); } diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 376d07535d..cacbce1785 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -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);