diff options
| author | Sai Gomathi N <nsaigomathi@vmware.com> | 2022-06-09 22:43:52 -0700 |
|---|---|---|
| committer | Sai Gomathi N <nsaigomathi@vmware.com> | 2022-06-09 22:43:52 -0700 |
| commit | 94c691ba40002d336f84295c8f1ab41615b12aed (patch) | |
| tree | efc0a0936ba47998b107149ec35db70c05deb710 /pimd/pim_cmd_common.c | |
| parent | fe7eaf4065cab165d40a6010d00d5c84273a4cf0 (diff) | |
pim6d: Moving the reusable code of pim_show_join cli
Moving the common lines of pim_show_join_vrf and pim_show_join_vrf_all cli
in pim_cmd.c and pim6_cmd.c to pim_cmd_common.c file
Signed-off-by: Sai Gomathi N <nsaigomathi@vmware.com>
Diffstat (limited to 'pimd/pim_cmd_common.c')
| -rw-r--r-- | pimd/pim_cmd_common.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 54abd17d5e..f3101fd30d 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -1665,6 +1665,73 @@ static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp, } } +int pim_show_join_cmd_helper(const char *vrf, struct vty *vty, pim_addr s_or_g, + pim_addr g, const char *json) +{ + pim_sgaddr sg = {}; + struct vrf *v; + struct pim_instance *pim; + json_object *json_parent = NULL; + + v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME); + + if (!v) { + vty_out(vty, "%% Vrf specified: %s does not exist\n", vrf); + return CMD_WARNING; + } + pim = pim_get_pim_instance(v->vrf_id); + + if (!pim) { + vty_out(vty, "%% Unable to find pim instance\n"); + return CMD_WARNING; + } + + if (!pim_addr_is_any(s_or_g)) { + if (!pim_addr_is_any(g)) { + sg.src = s_or_g; + sg.grp = g; + } else + sg.grp = s_or_g; + } + + if (json) + json_parent = json_object_new_object(); + + pim_show_join(pim, vty, &sg, json_parent); + + if (json) + vty_json(vty, json_parent); + + return CMD_SUCCESS; +} + +int pim_show_join_vrf_all_cmd_helper(struct vty *vty, const char *json) +{ + pim_sgaddr sg = {0}; + struct vrf *vrf_struct; + json_object *json_parent = NULL; + json_object *json_vrf = NULL; + + if (json) + json_parent = json_object_new_object(); + + RB_FOREACH (vrf_struct, vrf_name_head, &vrfs_by_name) { + if (!json_parent) + vty_out(vty, "VRF: %s\n", vrf_struct->name); + else + json_vrf = json_object_new_object(); + pim_show_join(vrf_struct->info, vty, &sg, json_vrf); + + if (json) + json_object_object_add(json_parent, vrf_struct->name, + json_vrf); + } + if (json) + vty_json(vty, json_parent); + + return CMD_WARNING; +} + void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg, json_object *json) { |
