From d3f01488cdc040977e5418f0a19a45bbf109633d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 30 Aug 2024 08:52:06 -0400 Subject: [PATCH 1/2] isisd: in isis_mt.c use appropriate memory allocator Signed-off-by: Donald Sharp (cherry picked from commit a556f6e38b404ae1b90a52b23e5afacd64ab4d45) --- isisd/isis_mt.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/isisd/isis_mt.c b/isisd/isis_mt.c index d04a24dc4683..65ba395ffc81 100644 --- a/isisd/isis_mt.c +++ b/isisd/isis_mt.c @@ -226,7 +226,8 @@ struct isis_area_mt_setting **area_mt_settings(struct isis_area *area, count++; if (count > size) { - rv = XREALLOC(MTYPE_TMP, rv, count * sizeof(*rv)); + rv = XREALLOC(MTYPE_MT_AREA_SETTING, rv, + count * sizeof(*rv)); size = count; } rv[count - 1] = setting; @@ -341,7 +342,8 @@ circuit_mt_settings(struct isis_circuit *circuit, unsigned int *mt_count) count++; if (count > size) { - rv = XREALLOC(MTYPE_TMP, rv, count * sizeof(*rv)); + rv = XREALLOC(MTYPE_MT_AREA_SETTING, rv, + count * sizeof(*rv)); size = count; } rv[count - 1] = setting; @@ -376,8 +378,8 @@ bool tlvs_to_adj_mt_set(struct isis_tlvs *tlvs, bool v4_usable, bool v6_usable, old_mt_count = adj->mt_count; if (old_mt_count) { - old_mt_set = - XCALLOC(MTYPE_TMP, old_mt_count * sizeof(*old_mt_set)); + old_mt_set = XCALLOC(MTYPE_MT_AREA_SETTING, + old_mt_count * sizeof(*old_mt_set)); memcpy(old_mt_set, adj->mt_set, old_mt_count * sizeof(*old_mt_set)); } @@ -436,7 +438,7 @@ bool tlvs_to_adj_mt_set(struct isis_tlvs *tlvs, bool v4_usable, bool v6_usable, changed = true; if (old_mt_count) - XFREE(MTYPE_TMP, old_mt_set); + XFREE(MTYPE_MT_AREA_SETTING, old_mt_set); return changed; } @@ -464,7 +466,7 @@ static void mt_set_add(uint16_t **mt_set, unsigned int *size, } if (*index >= *size) { - *mt_set = XREALLOC(MTYPE_TMP, *mt_set, + *mt_set = XREALLOC(MTYPE_MT_AREA_SETTING, *mt_set, sizeof(**mt_set) * ((*index) + 1)); *size = (*index) + 1; } From 2de65d874a617d750873426bb5f79b693d1a3366 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 30 Aug 2024 09:05:11 -0400 Subject: [PATCH 2/2] *: Create termtable specific temp memory When trying to track down a MTYPE_TMP memory leak it's harder to search for it when you happen to have some usage of ttable_dump. Let's just give it it's own memory type so that we can avoid confusion in the future. Signed-off-by: Donald Sharp (cherry picked from commit d97c535c1e11904585b97da894d49b766b2d270a) # Conflicts: # isisd/isis_spf.c # zebra/dplane_fpm_nl.c --- bgpd/bgp_bmp.c | 4 +-- isisd/isis_spf.c | 16 ++++++++-- isisd/isis_sr.c | 2 +- isisd/isis_srv6.c | 2 +- lib/hash.c | 2 +- lib/memory.c | 1 + lib/memory.h | 1 + lib/northbound_cli.c | 6 ++-- lib/termtable.c | 2 +- lib/termtable.h | 2 +- pathd/path_cli.c | 2 +- pimd/pim6_mld.c | 4 +-- pimd/pim_cmd_common.c | 36 ++++++++++----------- pimd/pim_rp.c | 2 +- tests/lib/test_ttable.c | 36 ++++++++++----------- vrrpd/vrrp_vty.c | 4 +-- zebra/dplane_fpm_nl.c | 71 +++++++++++++++++++++++++++++++++++++++++ zebra/zebra_mpls.c | 2 +- zebra/zebra_vty.c | 2 +- 19 files changed, 141 insertions(+), 56 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 1de48a072a91..11ec8ff194bd 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -2687,7 +2687,7 @@ DEFPY(show_bmp, } out = ttable_dump(tt, "\n"); vty_out(vty, "%s", out); - XFREE(MTYPE_TMP, out); + XFREE(MTYPE_TMP_TTABLE, out); ttable_del(tt); vty_out(vty, "\n %zu connected clients:\n", @@ -2714,7 +2714,7 @@ DEFPY(show_bmp, } out = ttable_dump(tt, "\n"); vty_out(vty, "%s", out); - XFREE(MTYPE_TMP, out); + XFREE(MTYPE_TMP_TTABLE, out); ttable_del(tt); vty_out(vty, "\n"); } diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 9cb964b96a96..7b87ab504cc1 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -2303,6 +2303,18 @@ static void isis_print_paths(struct vty *vty, struct isis_vertex_queue *queue, } vty_out(vty, "\n"); } +<<<<<<< HEAD +======= + if (json == NULL) { + table = ttable_dump(tt, "\n"); + vty_out(vty, "%s\n", table); + XFREE(MTYPE_TMP_TTABLE, table); + } else + *json = ttable_json_with_json_text( + tt, "ssdsss", + "vertex|type|metric|nextHop|interface|parent"); + ttable_del(tt); +>>>>>>> d97c535c1e (*: Create termtable specific temp memory) } void isis_print_spftree(struct vty *vty, struct isis_spftree *spftree) @@ -2867,7 +2879,7 @@ void isis_print_routes(struct vty *vty, struct isis_spftree *spftree, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } else if (json) { *json = ttable_json(tt, prefix_sid ? "sdssdsdd" : "sdsss"); } @@ -3242,7 +3254,7 @@ static void isis_print_frr_summary(struct vty *vty, /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index 1d69dbbbfa41..0923d8fc5ffe 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1065,7 +1065,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } ttable_del(tt); } diff --git a/isisd/isis_srv6.c b/isisd/isis_srv6.c index 1b0c706946a1..76ed592e0c7f 100644 --- a/isisd/isis_srv6.c +++ b/isisd/isis_srv6.c @@ -689,7 +689,7 @@ static void show_node(struct vty *vty, struct isis_area *area, int level) table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } ttable_del(tt); } diff --git a/lib/hash.c b/lib/hash.c index df5624398533..edbfeec4645e 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -444,7 +444,7 @@ DEFUN_NOSH(show_hash_stats, ttable_colseps(tt, 0, RIGHT, true, '|'); char *table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } else vty_out(vty, "No named hash tables to display.\n"); diff --git a/lib/memory.c b/lib/memory.c index 8fbe5c409366..ac39516edd75 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -25,6 +25,7 @@ struct memgroup **mg_insert = &mg_first; DEFINE_MGROUP(LIB, "libfrr"); DEFINE_MTYPE(LIB, TMP, "Temporary memory"); +DEFINE_MTYPE(LIB, TMP_TTABLE, "Temporary memory for TTABLE"); DEFINE_MTYPE(LIB, BITFIELD, "Bitfield memory"); static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr) diff --git a/lib/memory.h b/lib/memory.h index ba437ebd0ed9..e844287c9471 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -141,6 +141,7 @@ struct memgroup { DECLARE_MGROUP(LIB); DECLARE_MTYPE(TMP); +DECLARE_MTYPE(TMP_TTABLE); extern void *qmalloc(struct memtype *mt, size_t size) diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 8809ec2ad87d..b2b1cfa77fbf 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -1309,7 +1309,7 @@ static int nb_cli_show_transactions(struct vty *vty) table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } else vty_out(vty, "No configuration transactions to display.\n\n"); @@ -1590,7 +1590,7 @@ DEFPY (show_yang_module, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } else vty_out(vty, "No YANG modules to display.\n\n"); @@ -1700,7 +1700,7 @@ DEFPY (show_yang_module_translator, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } else vty_out(vty, "No YANG module translators to display.\n\n"); diff --git a/lib/termtable.c b/lib/termtable.c index 9b36d5ebfa8b..c49254bce15b 100644 --- a/lib/termtable.c +++ b/lib/termtable.c @@ -363,7 +363,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) memcpy(&right[0], newline, nl_len); /* allocate print buffer */ - buf = XCALLOC(MTYPE_TMP, width * (nlines + 1) + 1); + buf = XCALLOC(MTYPE_TMP_TTABLE, width * (nlines + 1) + 1); pos = 0; if (tt->style.border.top_on) { diff --git a/lib/termtable.h b/lib/termtable.h index 7258682bd80a..86af8b22b8fe 100644 --- a/lib/termtable.h +++ b/lib/termtable.h @@ -270,7 +270,7 @@ void ttable_rowseps(struct ttable *tt, unsigned int row, * * Caller must free this string after use with * - * XFREE (MTYPE_TMP, str); + * XFREE (MTYPE_TMP_TTABLE, str); * * @param tt the table to dump * @param newline the desired newline sequence to use, null terminated. diff --git a/pathd/path_cli.c b/pathd/path_cli.c index e22931c13e1e..b2068487ec84 100644 --- a/pathd/path_cli.c +++ b/pathd/path_cli.c @@ -131,7 +131,7 @@ DEFPY(show_srte_policy, /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); diff --git a/pimd/pim6_mld.c b/pimd/pim6_mld.c index a39d182990bf..8ccf42d729ba 100644 --- a/pimd/pim6_mld.c +++ b/pimd/pim6_mld.c @@ -2537,7 +2537,7 @@ static void gm_show_if_vrf(struct vty *vty, struct vrf *vrf, const char *ifname, if (!js && !detail) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -3021,7 +3021,7 @@ static void gm_show_groups(struct vty *vty, struct vrf *vrf, bool uj) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 5e50a09355cf..5100425997b6 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -969,7 +969,7 @@ void pim_show_rpf(struct pim_instance *pim, struct vty *vty, json_object *json) if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -1021,7 +1021,7 @@ void pim_show_neighbors_secondary(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); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } @@ -1275,7 +1275,7 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty, #else table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); #endif } @@ -1508,7 +1508,7 @@ void pim_show_upstream(struct pim_instance *pim, struct vty *vty, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -1585,7 +1585,7 @@ void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, bool uj) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -1664,7 +1664,7 @@ void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, bool uj) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -1846,7 +1846,7 @@ void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -1926,7 +1926,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); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } @@ -2069,7 +2069,7 @@ void pim_show_membership(struct pim_instance *pim, struct vty *vty, bool uj) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -2174,7 +2174,7 @@ void pim_show_channel(struct pim_instance *pim, struct vty *vty, bool uj) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -2357,7 +2357,7 @@ void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, bool mlag, /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } @@ -2829,7 +2829,7 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg) /* Dump the generated table. */ table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); return CMD_SUCCESS; @@ -3309,7 +3309,7 @@ void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -3605,7 +3605,7 @@ void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -4044,7 +4044,7 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -4127,7 +4127,7 @@ void show_mroute_count(struct pim_instance *pim, struct vty *vty, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } } @@ -5430,7 +5430,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); tt = NULL; } @@ -5484,7 +5484,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim, table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } if (!bsm_rpinfos_count(bsgrp->partial_bsrp_list) && !uj) diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index d8d25712a30f..63262162ef1c 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -1272,7 +1272,7 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range, if (!json) { table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } else { if (prev_rp_info && json_rp_rows) diff --git a/tests/lib/test_ttable.c b/tests/lib/test_ttable.c index 562ddf9d66e3..7ac0e3516b0b 100644 --- a/tests/lib/test_ttable.c +++ b/tests/lib/test_ttable.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) assert(tt->nrows == 1); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* add new row with 1 column, assert that it is not added */ assert(ttable_add_row(tt, "%s", "Garbage") == NULL); @@ -28,7 +28,7 @@ int main(int argc, char **argv) assert(tt->nrows == 1); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* add new row, assert that it is added */ assert(ttable_add_row(tt, "%s|%s|%s", "a", "b", "c")); @@ -36,7 +36,7 @@ int main(int argc, char **argv) assert(tt->nrows == 2); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* add empty row, assert that it is added */ assert(ttable_add_row(tt, "||")); @@ -44,7 +44,7 @@ int main(int argc, char **argv) assert(tt->nrows == 3); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* delete 1st row, assert that it is removed */ ttable_del_row(tt, 0); @@ -52,7 +52,7 @@ int main(int argc, char **argv) assert(tt->nrows == 2); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* delete last row, assert that it is removed */ ttable_del_row(tt, 0); @@ -60,7 +60,7 @@ int main(int argc, char **argv) assert(tt->nrows == 1); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* delete the remaining row, check dumping an empty table */ ttable_del_row(tt, 0); @@ -68,7 +68,7 @@ int main(int argc, char **argv) assert(tt->nrows == 0); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* add new row */ ttable_add_row(tt, "%s|%s||%s|%9d", "slick", "black", "triple", 1337); @@ -76,7 +76,7 @@ int main(int argc, char **argv) assert(tt->nrows == 1); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* add bigger row */ ttable_add_row(tt, "%s|%s||%s|%s", @@ -86,7 +86,7 @@ int main(int argc, char **argv) assert(tt->nrows == 2); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* insert new row at beginning */ ttable_insert_row(tt, 0, "%s|%s||%d|%lf", "converting", "vegetarians", @@ -95,7 +95,7 @@ int main(int argc, char **argv) assert(tt->nrows == 3); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* insert new row at end */ ttable_insert_row(tt, tt->nrows - 1, "%s|%s||%d|%ld", "converting", @@ -104,7 +104,7 @@ int main(int argc, char **argv) assert(tt->nrows == 4); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* insert new row at middle */ ttable_insert_row(tt, 1, "%s|%s||%s|%ld", "she", "pioneer", "aki", 1l); @@ -112,7 +112,7 @@ int main(int argc, char **argv) assert(tt->nrows == 5); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* set alignment */ ttable_align(tt, 0, 1, 2, 2, LEFT); @@ -120,14 +120,14 @@ int main(int argc, char **argv) assert(tt->nrows == 5); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_align(tt, 0, 1, 5, 1, RIGHT); assert(tt->ncols == 5); assert(tt->nrows == 5); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* set padding */ ttable_pad(tt, 0, 1, 1, 1, RIGHT, 2); @@ -135,14 +135,14 @@ int main(int argc, char **argv) assert(tt->nrows == 5); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_pad(tt, 0, 0, 5, 4, LEFT, 2); assert(tt->ncols == 5); assert(tt->nrows == 5); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* restyle */ tt->style.cell.border.bottom_on = false; @@ -156,13 +156,13 @@ int main(int argc, char **argv) ttable_rowseps(tt, 1, TOP, true, '-'); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* column separators for leftmost column */ ttable_colseps(tt, 0, RIGHT, true, '|'); table = ttable_dump(tt, "\n"); fprintf(stdout, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); /* delete table */ ttable_del(tt); diff --git a/vrrpd/vrrp_vty.c b/vrrpd/vrrp_vty.c index fd6cbc8b6740..07d32f727bf7 100644 --- a/vrrpd/vrrp_vty.c +++ b/vrrpd/vrrp_vty.c @@ -590,7 +590,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); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); } @@ -695,7 +695,7 @@ DEFPY_YANG(vrrp_vrid_show_summary, char *table = ttable_dump(tt, "\n"); vty_out(vty, "\n%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); ttable_del(tt); list_delete(&ll); diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index 7ae1b2a0901a..8f30809926c8 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -322,6 +322,77 @@ DEFUN(fpm_reset_counters, fpm_reset_counters_cmd, return CMD_SUCCESS; } +<<<<<<< HEAD +======= +DEFPY(fpm_show_status, + fpm_show_status_cmd, + "show fpm status [json]$json", + SHOW_STR FPM_STR "FPM status\n" JSON_STR) +{ + struct json_object *j; + bool connected; + uint16_t port; + struct sockaddr_in *sin; + struct sockaddr_in6 *sin6; + char buf[BUFSIZ]; + + connected = gfnc->socket > 0 ? true : false; + + switch (gfnc->addr.ss_family) { + case AF_INET: + sin = (struct sockaddr_in *)&gfnc->addr; + snprintfrr(buf, sizeof(buf), "%pI4", &sin->sin_addr); + port = ntohs(sin->sin_port); + break; + case AF_INET6: + sin6 = (struct sockaddr_in6 *)&gfnc->addr; + snprintfrr(buf, sizeof(buf), "%pI6", &sin6->sin6_addr); + port = ntohs(sin6->sin6_port); + break; + default: + strlcpy(buf, "Unknown", sizeof(buf)); + port = FPM_DEFAULT_PORT; + break; + } + + if (json) { + j = json_object_new_object(); + + json_object_boolean_add(j, "connected", connected); + json_object_boolean_add(j, "useNHG", gfnc->use_nhg); + json_object_boolean_add(j, "useRouteReplace", + gfnc->use_route_replace); + json_object_boolean_add(j, "disabled", gfnc->disabled); + json_object_string_add(j, "address", buf); + json_object_int_add(j, "port", port); + + vty_json(vty, j); + } else { + struct ttable *table = ttable_new(&ttable_styles[TTSTYLE_BLANK]); + char *out; + + ttable_rowseps(table, 0, BOTTOM, true, '-'); + ttable_add_row(table, "Address to connect to|%s", buf); + ttable_add_row(table, "Port|%u", port); + ttable_add_row(table, "Connected|%s", connected ? "Yes" : "No"); + ttable_add_row(table, "Use Nexthop Groups|%s", + gfnc->use_nhg ? "Yes" : "No"); + ttable_add_row(table, "Use Route Replace Semantics|%s", + gfnc->use_route_replace ? "Yes" : "No"); + ttable_add_row(table, "Disabled|%s", + gfnc->disabled ? "Yes" : "No"); + + out = ttable_dump(table, "\n"); + vty_out(vty, "%s\n", out); + XFREE(MTYPE_TMP_TTABLE, out); + + ttable_del(table); + } + + return CMD_SUCCESS; +} + +>>>>>>> d97c535c1e (*: Create termtable specific temp memory) DEFUN(fpm_show_counters, fpm_show_counters_cmd, "show fpm counters", SHOW_STR diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 39fc678c23c3..a14245d84685 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -3790,7 +3790,7 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, if (tt->nrows > 1) { char *table = ttable_dump(tt, "\n"); vty_out(vty, "%s\n", table); - XFREE(MTYPE_TMP, table); + XFREE(MTYPE_TMP_TTABLE, table); } ttable_del(tt); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 9a68d5ae9db4..578a6783d34b 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3923,7 +3923,7 @@ DEFUN (show_zebra, out = ttable_dump(table, "\n"); vty_out(vty, "%s\n", out); - XFREE(MTYPE_TMP, out); + XFREE(MTYPE_TMP_TTABLE, out); ttable_del(table); vty_out(vty,