Skip to content

Commit

Permalink
*: Add ttable_vty_finish function
Browse files Browse the repository at this point in the history
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 <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Feb 16, 2024
1 parent 9aec0d5 commit 4b26411
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 265 deletions.
12 changes: 3 additions & 9 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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));
Expand All @@ -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");
}
}
Expand Down
23 changes: 8 additions & 15 deletions isisd/isis_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 4 additions & 9 deletions isisd/isis_sr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 3 additions & 8 deletions isisd/isis_srv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions lib/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
38 changes: 13 additions & 25 deletions lib/northbound_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
12 changes: 12 additions & 0 deletions lib/termtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions lib/termtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 1 addition & 7 deletions pathd/path_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 1 addition & 7 deletions pathd/path_pcep_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
20 changes: 4 additions & 16 deletions pimd/pim6_mld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 4b26411

Please sign in to comment.