From a3ea8493a8f173f96b84cc928c1ea25b1197ee52 Mon Sep 17 00:00:00 2001 From: Stephen Worley Date: Tue, 15 Feb 2022 17:46:05 -0500 Subject: [PATCH] zebra: simplify reason code printing in show Simplify the code for printing the reason codes via show command. Just remove the trailing comma last before printing. Signed-off-by: Stephen Worley --- zebra/interface.c | 52 ++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/zebra/interface.c b/zebra/interface.c index 708e7b5485..97741bd404 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1852,49 +1852,31 @@ static void ifs_dump_brief_vty_json(json_object *json, struct vrf *vrf) const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf, uint32_t pd_buf_len) { - bool first = true; - pd_buf[0] = '\0'; + size_t len; strlcat(pd_buf, "(", pd_buf_len); - if (protodown_rc & ZEBRA_PROTODOWN_EXTERNAL) { - if (first) - first = false; - else - strlcat(pd_buf, ",", pd_buf_len); - strlcat(pd_buf, "external", pd_buf_len); - } + if (protodown_rc & ZEBRA_PROTODOWN_EXTERNAL) + strlcat(pd_buf, "external,", pd_buf_len); - if (protodown_rc & ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY) { - if (first) - first = false; - else - strlcat(pd_buf, ",", pd_buf_len); - strlcat(pd_buf, "startup-delay", pd_buf_len); - } + if (protodown_rc & ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY) + strlcat(pd_buf, "startup-delay,", pd_buf_len); - if (protodown_rc & ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN) { - if (first) - first = false; - else - strlcat(pd_buf, ",", pd_buf_len); - strlcat(pd_buf, "uplinks-down", pd_buf_len); - } + if (protodown_rc & ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN) + strlcat(pd_buf, "uplinks-down,", pd_buf_len); - if (protodown_rc & ZEBRA_PROTODOWN_VRRP) { - if (first) - first = false; - else - strlcat(pd_buf, ",", pd_buf_len); - strlcat(pd_buf, "vrrp", pd_buf_len); - } + if (protodown_rc & ZEBRA_PROTODOWN_VRRP) + strlcat(pd_buf, "vrrp,", pd_buf_len); - if (protodown_rc & ZEBRA_PROTODOWN_SHARP) { - if (!first) - strlcat(pd_buf, ",", pd_buf_len); - strlcat(pd_buf, "sharp", pd_buf_len); - } + if (protodown_rc & ZEBRA_PROTODOWN_SHARP) + strlcat(pd_buf, "sharp,", pd_buf_len); + + len = strnlen(pd_buf, pd_buf_len); + + /* Remove trailing comma */ + if (pd_buf[len - 1] == ',') + pd_buf[len - 1] = '\0'; strlcat(pd_buf, ")", pd_buf_len);