From 82c1d82d7767570af287b8fa8d887ba8a40015e3 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 4 Dec 2023 16:03:31 +0100 Subject: [PATCH 1/2] sharpd: fix deleting nhid when suppressing nexthop from nh group When no nexthops are in a nexthop group, two successive events are sent: NHG_DEL and NHG_ADD, but only the NHG_DEL one is necessary. Fixes this by returning in the nhg_add() function. Fixes: 82beaf6ae520 ("sharpd: fix deleting nhid when suppressing nexthop from nh group") Signed-off-by: Philippe Guibert --- sharpd/sharp_zebra.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 9ff6ba99b61e..7c7925651758 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -567,11 +567,11 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, zlog_debug("%s: nhg %u: no nexthops, deleting nexthop group", __func__, id); zclient_nhg_send(zclient, ZEBRA_NHG_DEL, &api_nhg); - } else { - zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__, - id); - is_valid = false; + return; } + zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__, + id); + is_valid = false; goto done; } From f806ec101f1d0b154c0cf0bf488d351ab397de7b Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 5 Dec 2023 09:56:41 +0100 Subject: [PATCH 2/2] sharpd: fix avoid twice sending NHG_DEL for a nexthop-group After removing the nexthop of a nexthop group, when the nexthop group is removed, a nhg removal failure happens: > ubuntu2204(config)# nexthop-group CCC > ubuntu2204(config-nh-group)# nexthop 192.0.2.211 loop1 > ubuntu2204(config-nh-group)# no nexthop 192.0.2.211 loop1 > [..] > 2023/12/05 08:59:22 SHARP: [H3QKG-WH8ZV] Removed nhg 179687505 > ubuntu2204(config-nh-group)# exi > ubuntu2204(config)# no nexthop-group CCC > [..] > 2023/12/05 08:59:27 SHARP: [N030J-V0SFN] Failed removal of nhg 179687505 The NHG_DEL message is sent twice at the nexthop deletion, and at the nexthop-group deletion. Avoid sending it twice. Fixes: 82beaf6ae520 ("sharpd: fix deleting nhid when suppressing nexthop from nh group") Signed-off-by: Philippe Guibert --- sharpd/sharp_nht.c | 3 ++- sharpd/sharp_zebra.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sharpd/sharp_nht.c b/sharpd/sharp_nht.c index 8c02f1f213e3..6d64fcfb259b 100644 --- a/sharpd/sharp_nht.c +++ b/sharpd/sharp_nht.c @@ -174,7 +174,8 @@ static void sharp_nhgroup_delete_cb(const char *name) if (!snhg) return; - nhg_del(snhg->id); + if (sharp_nhgroup_id_is_installed(snhg->id)) + nhg_del(snhg->id); sharp_nhg_rb_del(&nhg_head, snhg); XFREE(MTYPE_NHG, snhg); } diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 7c7925651758..ff4895189db6 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -934,6 +934,7 @@ static int nhg_notify_owner(ZAPI_CALLBACK_ARGS) zlog_debug("Failed install of nhg %u", id); break; case ZAPI_NHG_REMOVED: + sharp_nhgroup_id_set_installed(id, false); zlog_debug("Removed nhg %u", id); break; case ZAPI_NHG_REMOVE_FAIL: