From 2614bf87643e1f019fb337fab5fe45c3be5752be Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 14 May 2019 13:46:05 -0700 Subject: [PATCH] zebra: Add ifp to zebra-side rib_add Add an interface pointer for an nexthop group hash entry when we are getting a rib_add for a new route. Also, add the interface index to the `show nexthop-group` command. Signed-off-by: Stephen Worley --- zebra/interface.c | 1 - zebra/interface.h | 3 --- zebra/rt_netlink.c | 13 +++++++------ zebra/zebra_nhg.c | 1 + zebra/zebra_nhg.h | 8 ++++++++ zebra/zebra_rib.c | 1 + zebra/zebra_vty.c | 3 +++ 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/zebra/interface.c b/zebra/interface.c index 6b77f3c871..3eb0e68537 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -947,7 +947,6 @@ struct nhe_connected *nhe_connected_add(struct interface *ifp, struct zebra_if *zif = (struct zebra_if *)ifp->info; if_nhec = nhe_connected_new(); - if_nhec->ifp = ifp; /* Attach the nhe */ if_nhec->nhe = nhe; diff --git a/zebra/interface.h b/zebra/interface.h index 270cc868c0..7dccaeaccb 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -266,9 +266,6 @@ struct irdp_interface; /* Nexthop hash entry connected structure */ struct nhe_connected { - /* Attached interface */ - struct interface *ifp; - /* Connected nexthop hash entry */ struct nhg_hash_entry *nhe; }; diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 73260ee18b..b2712d52f1 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -2313,16 +2313,17 @@ int netlink_nexthop_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) nhe = zebra_nhg_find(&nhg, nh.vrf_id, id); if (nhe) { nhe->is_kernel_nh = true; - if (ifp) { - /* Add the nhe to the interface's list - * of connected nhe's - */ - nhe_connected_add(ifp, nhe); - } } else { return -1; } } + if (ifp) { + /* Add the nhe to the interface's list + * of connected nhe's + */ + // TODO: Don't add dupes + nhe_connected_add(ifp, nhe); + } SET_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED); } else if (h->nlmsg_type == RTM_DELNEXTHOP) { diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index ece1e1ccd5..5704cf0e23 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -108,6 +108,7 @@ static void *zebra_nhg_alloc(void *arg) nhe->refcnt = 0; nhe->is_kernel_nh = false; nhe->dplane_ref = zebra_router_get_next_sequence(); + nhe->ifp = NULL; nhe->nhg.nexthop = NULL; nexthop_group_copy(&nhe->nhg, ©->nhg); diff --git a/zebra/zebra_nhg.h b/zebra/zebra_nhg.h index a7a97f5529..8b3f6502a1 100644 --- a/zebra/zebra_nhg.h +++ b/zebra/zebra_nhg.h @@ -35,6 +35,14 @@ struct nhg_hash_entry { struct nexthop_group nhg; + /* If this is not a group, it + * will be a single nexthop + * and must have an interface + * associated with it. + * Otherwise, this will be null. + */ + struct interface *ifp; + uint32_t refcnt; uint32_t dplane_ref; diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index df1f3df091..8decb2210d 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2666,6 +2666,7 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, } if (nhe) { + // TODO: Add interface pointer nhe->refcnt++; /* Freeing the nexthop structs we were using diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index cf728a649d..067b7a12a8 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -1120,6 +1120,9 @@ static void show_nexthop_group_cmd_helper(struct vty *vty, vty_out(vty, "\tValid: %d, Installed %d\n", nhe->flags & NEXTHOP_GROUP_VALID, nhe->flags & NEXTHOP_GROUP_INSTALLED); + if (nhe->ifp) + vty_out(vty, "\tInterface Index: %d\n", + nhe->ifp->ifindex); for (ALL_NEXTHOPS(nhe->nhg, nhop)) { vty_out(vty, "\t"); nexthop_group_write_nexthop(vty, nhop); -- 2.39.5