From 82beaf6ae520f1c969755ae0ee82d2af2f150927 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 23 Nov 2023 14:19:04 +0100 Subject: [PATCH] sharpd: fix deleting nhid when suppressing nexthop from nh group When removing the last nexthop from a nexthop-group, the nexthop group remains in the zebra contexts: > ubuntu2204(config)# nexthop-group gdgd > 2023/11/23 14:06:36 SHARP: [Q5NBA-GN1BG] NHG ID assigned: 179687502 > ubuntu2204(config-nh-group)# nexthop 192.0.2.7 loop1 > ubuntu2204(config-nh-group)# 2023/11/23 14:06:38 ZEBRA: [VNMVB-91G3G] _netlink_nexthop_build_group: ID (179687502): group 338 > 2023/11/23 14:06:38 ZEBRA: [R43C6-KYHWT] netlink_nexthop_msg_encode: RTM_NEWNEXTHOP, id=179687502 > 2023/11/23 14:06:38 ZEBRA: [HYEHE-CQZ9G] nl_batch_send: netlink-dp (NS 0), batch size=44, msg cnt=1 > 2023/11/23 14:06:38 SHARP: [JWRCN-N9K90] Installed nhg 179687502 > > ubuntu2204(config-nh-group)# no nexthop 192.0.2.7 loop1 > 2023/11/23 14:06:47 SHARP: [Y2G2F-ZTW6M] nhg_add: nhg 179687502 not sent: no valid nexthops > ubuntu2204(config-nh-group)# do show nexthop-group rib 179687502 > ID: 179687502 (sharp) > RefCnt: 1 > Uptime: 00:00:23 > VRF: default > Valid, Installed > Depends: (338) > via 192.0.2.7, loop1 (vrf default), weight 1 Fix this by sending an NHG_DEL message when no nexthops are attached, and when the id was already installed. Fixes: 5a9c0931aa95 ("sharpd: don't send invalid nexthop-groups to zebra") Signed-off-by: Philippe Guibert --- sharpd/sharp_zebra.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index aa720bacf2..9ff6ba99b6 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -563,9 +563,15 @@ void nhg_add(uint32_t id, const struct nexthop_group *nhg, } if (api_nhg.nexthop_num == 0) { - zlog_debug("%s: nhg %u not sent: no valid nexthops", __func__, - id); - is_valid = false; + if (sharp_nhgroup_id_is_installed(id)) { + 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; + } goto done; }