diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index ea12bdb22809..08b677b322f5 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -2684,7 +2684,7 @@ DEFPY(show_bmp, uptime, &ba->addrsrc); continue; } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); vty_out(vty, "\n %zu connected clients:\n", bmp_session_count(&bt->sessions)); @@ -2708,7 +2708,7 @@ DEFPY(show_bmp, bmp->cnt_mirror_overruns, total, q, kq); } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); vty_out(vty, "\n"); } diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index bb6edc0020df..49759b6de240 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -2856,12 +2856,9 @@ void isis_print_routes(struct vty *vty, struct isis_spftree *spftree, json != NULL); } - if (!json) { - if (tt->nrows > 1) - ttable_vty_finish(vty, &tt, "\n"); - else - ttable_del(tt); - } else { + if (!json) + ttable_vty_finish(vty, &tt, "\n", NULL); + else { *json = ttable_json(tt, prefix_sid ? "sdssdsdd" : "sdsss"); ttable_del(tt); } @@ -3231,7 +3228,7 @@ static void isis_print_frr_summary(struct vty *vty, isis_print_frr_summary_line_coverage(tt, "Protection coverage", coverage, coverage_total); - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void show_isis_frr_summary_common(struct vty *vty, int levels, diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index bb52a6fc5547..852a8062db31 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1059,10 +1059,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level, buf, cap->msd); } - if (tt->nrows > 1) - ttable_vty_finish(vty, &tt, "\n"); - else - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n", NULL); } DEFUN(show_sr_node, show_sr_node_cmd, diff --git a/isisd/isis_srv6.c b/isisd/isis_srv6.c index 8ba9c55cd73d..82b89af85602 100644 --- a/isisd/isis_srv6.c +++ b/isisd/isis_srv6.c @@ -683,10 +683,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level) cap->srv6_msd.max_end_d_msd); } - if (tt->nrows > 1) { - ttable_vty_finish(vty, &tt, "\n"); - } else - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n", NULL); } DEFUN(show_srv6_node, show_srv6_node_cmd, diff --git a/lib/hash.c b/lib/hash.c index 6a47d1779dbf..ebd36bcc2081 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -440,15 +440,9 @@ DEFUN_NOSH(show_hash_stats, vty_out(vty, "# allocated: %d\n", _hashes->count); vty_out(vty, "# named: %d\n\n", tt->nrows - 1); - if (tt->nrows > 1) { - ttable_colseps(tt, 0, RIGHT, true, '|'); + ttable_colseps(tt, 0, RIGHT, true, '|'); - ttable_vty_finish(vty, &tt, "\n"); - } else { - vty_out(vty, "No named hash tables to display.\n"); - - ttable_del(tt); - } + ttable_vty_finish(vty, &tt, "\n", "No named hash tables to display.\n"); return CMD_SUCCESS; } diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 19b95b145984..d0380bd83776 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -1303,12 +1303,8 @@ static int nb_cli_show_transactions(struct vty *vty) return CMD_WARNING; } - if (tt->nrows > 1) { - ttable_vty_finish(vty, &tt, "\n"); - } else { - vty_out(vty, "No configuration transactions to display.\n\n"); - ttable_del(tt); - } + ttable_vty_finish(vty, &tt, "\n", + "No configuration transactions to display.\n\n"); return CMD_SUCCESS; } @@ -1577,16 +1573,10 @@ DEFPY (show_yang_module, module->ns); } - /* Dump the generated table. */ - if (tt->nrows > 1) { + if (tt->nrows > 1) vty_out(vty, " Flags: I - Implemented, D - Deviated\n\n"); - ttable_vty_finish(vty, &tt, "\n"); - } else { - vty_out(vty, "No YANG modules to display.\n\n"); - - ttable_del(tt); - } + ttable_vty_finish(vty, &tt, "\n", "No YANG modules to display.\n\n"); return CMD_SUCCESS; } @@ -1686,13 +1676,8 @@ DEFPY (show_yang_module_translator, } } - if (tt->nrows > 1) - ttable_vty_finish(vty, &tt, "\n"); - else { - vty_out(vty, "No YANG module translators to display.\n\n"); - - ttable_del(tt); - } + ttable_vty_finish(vty, &tt, "\n", + "No YANG module translators to display.\n\n"); return CMD_SUCCESS; } diff --git a/lib/termtable.c b/lib/termtable.c index d5fcae4e4cda..5eb1c523860a 100644 --- a/lib/termtable.c +++ b/lib/termtable.c @@ -290,13 +290,18 @@ void ttable_rowseps(struct ttable *tt, unsigned int row, } } -void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline) +void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline, + const char *display_if_no_rows) { - char *out = ttable_dump(*tt, newline); + if ((*tt)->nrows > 1) { + char *out = ttable_dump(*tt, newline); - vty_out(vty, "%s", out); + vty_out(vty, "%s", out); + + XFREE(MTYPE_TMP, out); + } else if (display_if_no_rows) + vty_out(vty, "%s", display_if_no_rows); - XFREE(MTYPE_TMP, out); ttable_del(*tt); *tt = NULL; diff --git a/lib/termtable.h b/lib/termtable.h index ce5d468b92b5..9c79c9afaacc 100644 --- a/lib/termtable.h +++ b/lib/termtable.h @@ -285,8 +285,10 @@ char *ttable_dump(struct ttable *tt, const char *newline); * @param tt - double pointer to the table to dump, this pointer * is freed. * @param newline the desired newline sequence to use, null terminated. + * @param display_if_no_rows The string to display if nrows is 0 */ -void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline); +void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline, + const char *display_if_no_rows); /** * Convert a table to a JSON array of objects. diff --git a/pathd/path_cli.c b/pathd/path_cli.c index 1f70bcc38347..a9f0f7d21b85 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -127,7 +127,7 @@ DEFPY(show_srte_policy, : "Inactive"); } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); return CMD_SUCCESS; } diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index 026d3f227dbf..95cef786c8ba 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -546,7 +546,7 @@ static int path_pcep_cli_show_srte_pcep_counters(struct vty *vty) } } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); pcep_lib_free_counters(group); diff --git a/pimd/pim6_mld.c b/pimd/pim6_mld.c index ed45d0de5beb..c44496873044 100644 --- a/pimd/pim6_mld.c +++ b/pimd/pim6_mld.c @@ -2533,7 +2533,7 @@ static void gm_show_if_vrf(struct vty *vty, struct vrf *vrf, const char *ifname, } if (!js && !detail) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void gm_show_if(struct vty *vty, struct vrf *vrf, const char *ifname, @@ -3011,7 +3011,7 @@ static void gm_show_groups(struct vty *vty, struct vrf *vrf, bool uj) if (uj) vty_json(vty, json); else - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } DEFPY(gm_show_mld_groups, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 794c82294c48..b7cefd6edfcd 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -958,7 +958,7 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json) } } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty) @@ -1005,7 +1005,7 @@ void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty) } } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } void pim_show_state(struct pim_instance *pim, struct vty *vty, @@ -1255,7 +1255,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, #if PIM_IPV == 4 vty_out(vty, "\n"); #else - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); #endif } } @@ -1484,7 +1484,7 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty, } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void pim_show_join_desired_helper(struct pim_instance *pim, @@ -1555,7 +1555,7 @@ void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); else - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj) @@ -1628,7 +1628,7 @@ void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); else - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void pim_show_join_helper(struct pim_interface *pim_ifp, @@ -1805,7 +1805,7 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } /* Dump the generated table. */ if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void pim_show_jp_agg_helper(struct interface *ifp, @@ -1879,7 +1879,7 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty) } } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj) @@ -2018,7 +2018,7 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) } json_object_free(json); - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } } @@ -2118,7 +2118,7 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); else - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj) @@ -2295,7 +2295,7 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag, } json_object_free(json); - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } } @@ -2762,7 +2762,7 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg) #endif } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); return CMD_SUCCESS; } @@ -3238,7 +3238,7 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } int gm_process_query_max_response_time_cmd(struct vty *vty, @@ -3529,7 +3529,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty) @@ -3963,7 +3963,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, @@ -4040,7 +4040,7 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, show_mroute_count_per_channel_oil(&sr->c_oil, json, tt); if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } void show_mroute_summary(struct pim_instance *pim, struct vty *vty, @@ -5337,7 +5337,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, } if (tt) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); if (!bsm_rpinfos_count(bsgrp->bsrp_list) && !uj) vty_out(vty, "Active List is empty.\n"); @@ -5385,7 +5385,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, } if (tt) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); if (!bsm_rpinfos_count(bsgrp->partial_bsrp_list) && !uj) vty_out(vty, "Partial List is empty\n"); diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 361523182a0e..4e4c968b9abd 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -1268,7 +1268,7 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range, } if (!json) - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); else { if (prev_rp_info && json_rp_rows) json_object_object_addf(json, json_rp_rows, "%pPA", diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index 723353ede013..0eafd4fd2dc0 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -587,7 +587,7 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr) } } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); } /* @@ -688,7 +688,7 @@ DEFPY_YANG(vrrp_vrid_show_summary, : "Backup"); } - ttable_vty_finish(vty, &tt, "\n"); + ttable_vty_finish(vty, &tt, "\n", NULL); list_delete(&ll); diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index bc36267646ec..2543305878e8 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -3778,10 +3778,7 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, } } - if (tt->nrows > 1) - ttable_vty_finish(vty, &tt, "\n"); - else - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n", NULL); } list_delete(&lsp_list); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index bc86d291f136..7cbf0da9c447 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3902,7 +3902,7 @@ DEFUN (show_zebra, ttable_add_row(table, "v6 Default MC Forwarding|%s", zrouter.default_mc_forwardingv6 ? "On" : "Off"); - ttable_vty_finish(vty, &table, "\n"); + ttable_vty_finish(vty, &table, "\n", NULL); vty_out(vty, " Route Route Neighbor LSP LSP\n");