From 4b264116d67971cf871e9243e37385ba4f81d1a5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Feb 2024 10:10:41 -0500 Subject: [PATCH] *: Add ttable_vty_finish function Consistent pattern was this: out = ttable_dump(tt, "\n"); vty_out(vty, "%s", out); XFREE(MTYPE_TMP, out); ttable_del(tt); Let's just consolidate this pattern into ttable_vty_finish. Since no-one ever used it any other way. Signed-off-by: Donald Sharp --- bgpd/bgp_bmp.c | 12 +-- isisd/isis_spf.c | 23 ++---- isisd/isis_sr.c | 13 +--- isisd/isis_srv6.c | 11 +-- lib/hash.c | 10 +-- lib/northbound_cli.c | 38 ++++----- lib/termtable.c | 12 +++ lib/termtable.h | 10 +++ pathd/path_cli.c | 8 +- pathd/path_pcep_cli.c | 8 +- pimd/pim6_mld.c | 20 +---- pimd/pim_cmd_common.c | 175 ++++++++++-------------------------------- pimd/pim_rp.c | 11 +-- vrrpd/vrrp_vty.c | 12 +-- zebra/zebra_mpls.c | 11 +-- zebra/zebra_vty.c | 6 +- 16 files changed, 115 insertions(+), 265 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 6a55432e1497..ea12bdb22809 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -2587,7 +2587,6 @@ DEFPY(show_bmp, struct bmp *bmp; struct ttable *tt; char uptime[BGP_UPTIME_LEN]; - char *out; frr_each(bmp_bgph, &bmp_bgph, bmpbgp) { vty_out(vty, "BMP state for BGP %s:\n\n", @@ -2685,10 +2684,7 @@ DEFPY(show_bmp, uptime, &ba->addrsrc); continue; } - out = ttable_dump(tt, "\n"); - vty_out(vty, "%s", out); - XFREE(MTYPE_TMP, out); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); vty_out(vty, "\n %zu connected clients:\n", bmp_session_count(&bt->sessions)); @@ -2712,10 +2708,8 @@ DEFPY(show_bmp, bmp->cnt_mirror_overruns, total, q, kq); } - out = ttable_dump(tt, "\n"); - vty_out(vty, "%s", out); - XFREE(MTYPE_TMP, out); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); + vty_out(vty, "\n"); } } diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 7a4b45a0de17..bb6edc0020df 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -2856,17 +2856,15 @@ void isis_print_routes(struct vty *vty, struct isis_spftree *spftree, json != NULL); } - /* Dump the generated table. */ - if (json == NULL && tt->nrows > 1) { - char *table; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } else if (json) { + if (!json) { + if (tt->nrows > 1) + ttable_vty_finish(vty, &tt, "\n"); + else + ttable_del(tt); + } else { *json = ttable_json(tt, prefix_sid ? "sdssdsdd" : "sdsss"); + ttable_del(tt); } - ttable_del(tt); } static void show_isis_route_common(struct vty *vty, int levels, @@ -3152,7 +3150,6 @@ static void isis_print_frr_summary(struct vty *vty, struct isis_spftree *spftree) { struct ttable *tt; - char *table; const char *tree_id_text = NULL; uint32_t protectd[SPF_PREFIX_PRIO_MAX] = {0}; uint32_t unprotected[SPF_PREFIX_PRIO_MAX] = {0}; @@ -3234,11 +3231,7 @@ static void isis_print_frr_summary(struct vty *vty, isis_print_frr_summary_line_coverage(tt, "Protection coverage", coverage, coverage_total); - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); } 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 1d69dbbbfa41..bb52a6fc5547 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1059,15 +1059,10 @@ static void show_node(struct vty *vty, struct isis_area *area, int level, buf, cap->msd); } - /* Dump the generated table. */ - if (tt->nrows > 1) { - char *table; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } - ttable_del(tt); + if (tt->nrows > 1) + ttable_vty_finish(vty, &tt, "\n"); + else + ttable_del(tt); } DEFUN(show_sr_node, show_sr_node_cmd, diff --git a/isisd/isis_srv6.c b/isisd/isis_srv6.c index 1b0c706946a1..8ba9c55cd73d 100644 --- a/isisd/isis_srv6.c +++ b/isisd/isis_srv6.c @@ -683,15 +683,10 @@ static void show_node(struct vty *vty, struct isis_area *area, int level) cap->srv6_msd.max_end_d_msd); } - /* Dump the generated table. */ if (tt->nrows > 1) { - char *table; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); + } else + ttable_del(tt); } DEFUN(show_srv6_node, show_srv6_node_cmd, diff --git a/lib/hash.c b/lib/hash.c index df5624398533..6a47d1779dbf 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -442,13 +442,13 @@ DEFUN_NOSH(show_hash_stats, if (tt->nrows > 1) { ttable_colseps(tt, 0, RIGHT, true, '|'); - char *table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } else + + ttable_vty_finish(vty, &tt, "\n"); + } else { vty_out(vty, "No named hash tables to display.\n"); - ttable_del(tt); + ttable_del(tt); + } return CMD_SUCCESS; } diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 8809ec2ad87d..19b95b145984 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -1303,17 +1303,12 @@ static int nb_cli_show_transactions(struct vty *vty) return CMD_WARNING; } - /* Dump the generated table. */ if (tt->nrows > 1) { - char *table; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } else + ttable_vty_finish(vty, &tt, "\n"); + } else { vty_out(vty, "No configuration transactions to display.\n\n"); - - ttable_del(tt); + ttable_del(tt); + } return CMD_SUCCESS; } @@ -1584,17 +1579,14 @@ DEFPY (show_yang_module, /* Dump the generated table. */ if (tt->nrows > 1) { - char *table; - vty_out(vty, " Flags: I - Implemented, D - Deviated\n\n"); - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } else + ttable_vty_finish(vty, &tt, "\n"); + } else { vty_out(vty, "No YANG modules to display.\n\n"); - ttable_del(tt); + ttable_del(tt); + } return CMD_SUCCESS; } @@ -1694,17 +1686,13 @@ DEFPY (show_yang_module_translator, } } - /* Dump the generated table. */ - if (tt->nrows > 1) { - char *table; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } else + 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_del(tt); + } return CMD_SUCCESS; } diff --git a/lib/termtable.c b/lib/termtable.c index 9b36d5ebfa8b..d5fcae4e4cda 100644 --- a/lib/termtable.c +++ b/lib/termtable.c @@ -290,6 +290,18 @@ void ttable_rowseps(struct ttable *tt, unsigned int row, } } +void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline) +{ + char *out = ttable_dump(*tt, newline); + + vty_out(vty, "%s", out); + + XFREE(MTYPE_TMP, out); + ttable_del(*tt); + + *tt = NULL; +} + char *ttable_dump(struct ttable *tt, const char *newline) { /* clang-format off */ diff --git a/lib/termtable.h b/lib/termtable.h index 7258682bd80a..ce5d468b92b5 100644 --- a/lib/termtable.h +++ b/lib/termtable.h @@ -278,6 +278,16 @@ void ttable_rowseps(struct ttable *tt, unsigned int row, */ char *ttable_dump(struct ttable *tt, const char *newline); +/** + * Dumps the table, and frees the table + * + * @parm vty - The terminal to print to + * @param tt - double pointer to the table to dump, this pointer + * is freed. + * @param newline the desired newline sequence to use, null terminated. + */ +void ttable_vty_finish(struct vty *vty, struct ttable **tt, const char *newline); + /** * Convert a table to a JSON array of objects. * diff --git a/pathd/path_cli.c b/pathd/path_cli.c index e22931c13e1e..1f70bcc38347 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -97,7 +97,6 @@ DEFPY(show_srte_policy, { struct ttable *tt; struct srte_policy *policy; - char *table; if (RB_EMPTY(srte_policy_head, &srte_policies)) { vty_out(vty, "No SR Policies to display.\n\n"); @@ -128,12 +127,7 @@ DEFPY(show_srte_policy, : "Inactive"); } - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); return CMD_SUCCESS; } diff --git a/pathd/path_pcep_cli.c b/pathd/path_pcep_cli.c index 47a811d144f1..026d3f227dbf 100644 --- a/pathd/path_pcep_cli.c +++ b/pathd/path_pcep_cli.c @@ -503,7 +503,6 @@ static int path_pcep_cli_show_srte_pcep_counters(struct vty *vty) struct counter *counter; const char *group_name, *empty_string = ""; struct ttable *tt; - char *table; group = pcep_ctrl_get_counters(pcep_g->fpt, 1); @@ -547,12 +546,7 @@ static int path_pcep_cli_show_srte_pcep_counters(struct vty *vty) } } - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); pcep_lib_free_counters(group); diff --git a/pimd/pim6_mld.c b/pimd/pim6_mld.c index a39d182990bf..ed45d0de5beb 100644 --- a/pimd/pim6_mld.c +++ b/pimd/pim6_mld.c @@ -2479,7 +2479,6 @@ static void gm_show_if_vrf(struct vty *vty, struct vrf *vrf, const char *ifname, json_object *js_vrf = NULL; struct pim_interface *pim_ifp; struct ttable *tt = NULL; - char *table = NULL; if (js) { js_vrf = json_object_new_object(); @@ -2533,13 +2532,8 @@ static void gm_show_if_vrf(struct vty *vty, struct vrf *vrf, const char *ifname, gm_show_if_one(vty, ifp, js_if, tt); } - /* Dump the generated table. */ - if (!js && !detail) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + if (!js && !detail) + ttable_vty_finish(vty, &tt, "\n"); } static void gm_show_if(struct vty *vty, struct vrf *vrf, const char *ifname, @@ -2937,7 +2931,6 @@ static void gm_show_groups(struct vty *vty, struct vrf *vrf, bool uj) { struct interface *ifp; struct ttable *tt = NULL; - char *table; json_object *json = NULL; json_object *json_iface = NULL; json_object *json_group = NULL; @@ -3017,13 +3010,8 @@ static void gm_show_groups(struct vty *vty, struct vrf *vrf, bool uj) if (uj) vty_json(vty, json); - else { - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + else + ttable_vty_finish(vty, &tt, "\n"); } DEFPY(gm_show_mld_groups, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index ee318d45e3d4..794c82294c48 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -885,7 +885,6 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json) struct pim_upstream *up; time_t now = pim_time_monotonic_sec(); struct ttable *tt = NULL; - char *table = NULL; json_object *json_group = NULL; json_object *json_row = NULL; @@ -958,20 +957,14 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json) rpf->source_nexthop.mrib_metric_preference); } } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty) { struct interface *ifp; struct ttable *tt = NULL; - char *table = NULL; /* Prepare table. */ tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); @@ -1011,11 +1004,8 @@ void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty) &neigh->source_addr, p); } } - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + + ttable_vty_finish(vty, &tt, "\n"); } void pim_show_state(struct pim_instance *pim, struct vty *vty, @@ -1025,7 +1015,6 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, struct channel_oil *c_oil; #if PIM_IPV != 4 struct ttable *tt = NULL; - char *table = NULL; #endif char flag[50]; json_object *json_group = NULL; @@ -1266,10 +1255,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, #if PIM_IPV == 4 vty_out(vty, "\n"); #else - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); #endif } } @@ -1351,7 +1337,6 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty, { struct pim_upstream *up; struct ttable *tt = NULL; - char *table = NULL; time_t now; json_object *json_group = NULL; json_object *json_row = NULL; @@ -1497,13 +1482,9 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty, join_timer, rs_timer, ka_timer, up->ref_count); } } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } static void pim_show_join_desired_helper(struct pim_instance *pim, @@ -1552,7 +1533,6 @@ void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj) { struct pim_upstream *up; struct ttable *tt = NULL; - char *table = NULL; json_object *json = NULL; @@ -1574,20 +1554,14 @@ void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); - else { - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + else + ttable_vty_finish(vty, &tt, "\n"); } void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj) { struct pim_upstream *up; struct ttable *tt = NULL; - char *table = NULL; json_object *json = NULL; json_object *json_group = NULL; json_object *json_row = NULL; @@ -1653,13 +1627,8 @@ void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); - else { - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + else + ttable_vty_finish(vty, &tt, "\n"); } static void pim_show_join_helper(struct pim_interface *pim_ifp, @@ -1808,7 +1777,6 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, struct interface *ifp; time_t now; struct ttable *tt = NULL; - char *table = NULL; now = pim_time_monotonic_sec(); @@ -1836,12 +1804,8 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, } /* scan interface channels */ } /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } static void pim_show_jp_agg_helper(struct interface *ifp, @@ -1888,7 +1852,6 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty) struct listnode *js_node; struct pim_jp_sources *js; struct ttable *tt; - char *table; /* Prepare table. */ tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); @@ -1916,11 +1879,7 @@ void pim_show_jp_agg_list(struct pim_instance *pim, struct vty *vty) } } - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); } int pim_show_membership_cmd_helper(const char *vrf, struct vty *vty, bool uj) @@ -1971,7 +1930,6 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) json_object *json = NULL; json_object *json_tmp = NULL; struct ttable *tt = NULL; - char *table = NULL; json = json_object_new_object(); @@ -2059,11 +2017,8 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) } } json_object_free(json); - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + + ttable_vty_finish(vty, &tt, "\n"); } } @@ -2134,7 +2089,6 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj) struct interface *ifp; struct ttable *tt = NULL; json_object *json = NULL; - char *table = NULL; if (uj) json = json_object_new_object(); @@ -2163,13 +2117,8 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj) if (uj) vty_json(vty, json); - else { - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + else + ttable_vty_finish(vty, &tt, "\n"); } int pim_show_channel_cmd_helper(const char *vrf, struct vty *vty, bool uj) @@ -2254,7 +2203,6 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag, int pim_ifchannels = 0; bool uj = true; struct ttable *tt = NULL; - char *table = NULL; json_object *json_row = NULL; json_object *json_tmp; @@ -2347,12 +2295,7 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag, } json_object_free(json); - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); } } @@ -2797,7 +2740,6 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg) ifindex_t first_ifindex; struct interface *ifp = NULL; struct ttable *tt = NULL; - char *table = NULL; /* Prepare table. */ tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]); @@ -2819,11 +2761,8 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg) ifp ? ifp->name : "NULL", &nh_node->gate.ipv6); #endif } - /* Dump the generated table. */ - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + + ttable_vty_finish(vty, &tt, "\n"); return CMD_SUCCESS; } @@ -3228,7 +3167,6 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, struct pim_interface *pim_ifp; struct pim_neighbor *neigh; struct ttable *tt = NULL; - char *table = NULL; time_t now; char uptime[10]; char expire[10]; @@ -3298,13 +3236,9 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, json_ifp_rows = NULL; } } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } int gm_process_query_max_response_time_cmd(struct vty *vty, @@ -3515,7 +3449,6 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, { struct interface *ifp; struct ttable *tt = NULL; - char *table = NULL; json_object *json_row = NULL; vty_out(vty, "\n"); @@ -3594,13 +3527,9 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, (unsigned long)vreq.obytes); } } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, struct vty *vty) @@ -3657,7 +3586,6 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, struct channel_oil *c_oil; struct static_route *s_route; struct ttable *tt = NULL; - char *table = NULL; time_t now; json_object *json_group = NULL; json_object *json_source = NULL; @@ -4033,13 +3961,9 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, proto, in_ifname, "none", 0, "--:--:--"); } } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } static void show_mroute_count_per_channel_oil(struct channel_oil *c_oil, @@ -4095,7 +4019,6 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, struct channel_oil *c_oil; struct static_route *sr; struct ttable *tt = NULL; - char *table = NULL; if (!json) { vty_out(vty, "\n"); @@ -4116,13 +4039,8 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, sr)) show_mroute_count_per_channel_oil(&sr->c_oil, json, tt); - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + if (!json) + ttable_vty_finish(vty, &tt, "\n"); } void show_mroute_summary(struct pim_instance *pim, struct vty *vty, @@ -5417,16 +5335,10 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, bsm_rp->rp_holdtime, bsm_rp->hash); } } - /* Dump the generated table. */ - if (tt) { - char *table = NULL; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - tt = NULL; - } + + if (tt) + ttable_vty_finish(vty, &tt, "\n"); + if (!bsm_rpinfos_count(bsgrp->bsrp_list) && !uj) vty_out(vty, "Active List is empty.\n"); @@ -5471,15 +5383,10 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, bsm_rp->rp_holdtime, bsm_rp->hash); } } - /* Dump the generated table. */ - if (tt) { - char *table = NULL; - - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } + + if (tt) + ttable_vty_finish(vty, &tt, "\n"); + 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 d8d25712a30f..361523182a0e 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -1163,7 +1163,6 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range, struct rp_info *prev_rp_info = NULL; struct listnode *node; struct ttable *tt = NULL; - char *table = NULL; char source[7]; char grp[INET6_ADDRSTRLEN]; @@ -1268,13 +1267,9 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range, prev_rp_info = rp_info; } - /* Dump the generated table. */ - if (!json) { - table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); - } else { + if (!json) + ttable_vty_finish(vty, &tt, "\n"); + else { if (prev_rp_info && json_rp_rows) json_object_object_addf(json, json_rp_rows, "%pPA", &prev_rp_info->rp.rpf_addr); diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index fd6cbc8b6740..723353ede013 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -587,11 +587,7 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr) } } - char *table = ttable_dump(tt, "\n"); - - vty_out(vty, "\n%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); } /* @@ -692,11 +688,7 @@ DEFPY_YANG(vrrp_vrid_show_summary, : "Backup"); } - char *table = ttable_dump(tt, "\n"); - - vty_out(vty, "\n%s\n", table); - XFREE(MTYPE_TMP, table); - ttable_del(tt); + ttable_vty_finish(vty, &tt, "\n"); list_delete(&ll); diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 15e36acda8c3..bc36267646ec 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -3778,13 +3778,10 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, } } - /* Dump the generated table. */ - if (tt->nrows > 1) { - char *table = ttable_dump(tt, "\n"); - vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); - } - ttable_del(tt); + if (tt->nrows > 1) + ttable_vty_finish(vty, &tt, "\n"); + else + ttable_del(tt); } list_delete(&lsp_list); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index da6e2069ff28..bc86d291f136 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3834,7 +3834,6 @@ DEFUN (show_zebra, { struct vrf *vrf; struct ttable *table = ttable_new(&ttable_styles[TTSTYLE_BLANK]); - char *out; ttable_rowseps(table, 0, BOTTOM, true, '-'); ttable_add_row(table, "OS|%s(%s)", cmd_system_get(), cmd_release_get()); @@ -3903,11 +3902,8 @@ DEFUN (show_zebra, ttable_add_row(table, "v6 Default MC Forwarding|%s", zrouter.default_mc_forwardingv6 ? "On" : "Off"); - out = ttable_dump(table, "\n"); - vty_out(vty, "%s\n", out); - XFREE(MTYPE_TMP, out); + ttable_vty_finish(vty, &table, "\n"); - ttable_del(table); vty_out(vty, " Route Route Neighbor LSP LSP\n"); vty_out(vty,