]> git.proxmox.com Git - mirror_frr.git/commitdiff
pim6d: Moving the reusable code of pim_show_join cli
authorSai Gomathi N <nsaigomathi@vmware.com>
Fri, 10 Jun 2022 05:43:52 +0000 (22:43 -0700)
committerSai Gomathi N <nsaigomathi@vmware.com>
Fri, 10 Jun 2022 05:43:52 +0000 (22:43 -0700)
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>
pimd/pim6_cmd.c
pimd/pim_cmd.c
pimd/pim_cmd_common.c
pimd/pim_cmd_common.h

index 2b13d70f516d30714bf6bd3d5cb17bef39a00df3..5adeb51c19390363e11545e7b30bc091d4bbbe2a 100644 (file)
@@ -1282,41 +1282,7 @@ DEFPY (show_ipv6_pim_join,
        "The Group\n"
        JSON_STR)
 {
-       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;
+       return pim_show_join_cmd_helper(vrf, vty, s_or_g, g, json);
 }
 
 DEFPY (show_ipv6_pim_join_vrf_all,
@@ -1329,29 +1295,7 @@ DEFPY (show_ipv6_pim_join_vrf_all,
        "PIM interface join information\n"
        JSON_STR)
 {
-       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;
+       return pim_show_join_vrf_all_cmd_helper(vty, json);
 }
 
 DEFPY (show_ipv6_pim_jp_agg,
index ccd3a64bedc6368d7111dccd8e9ddcd4d8358e4b..3b2ef9aaf1ac7b2bd67433f0aae05ddc034de7c4 100644 (file)
@@ -2460,41 +2460,7 @@ DEFPY (show_ip_pim_join,
        "The Group\n"
        JSON_STR)
 {
-       pim_sgaddr sg = {0};
-       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 (s_or_g.s_addr != INADDR_ANY) {
-               if (g.s_addr != INADDR_ANY) {
-                       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;
+       return pim_show_join_cmd_helper(vrf, vty, s_or_g, g, json);
 }
 
 DEFPY (show_ip_pim_join_vrf_all,
@@ -2507,28 +2473,7 @@ DEFPY (show_ip_pim_join_vrf_all,
        "PIM interface join information\n"
        JSON_STR)
 {
-       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)
-                       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;
+       return pim_show_join_vrf_all_cmd_helper(vty, json);
 }
 
 DEFPY (show_ip_pim_jp_agg,
index 54abd17d5e661cb6f3163ef6c4e81a505fd2094c..f3101fd30d2c4581597e9af118c66108411a6337 100644 (file)
@@ -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)
 {
index bb07a7da0f2f3c5a75b214b22c06022259c9a24d..e3d1a68652faa32709df186cdbf86704704c6eb5 100644 (file)
@@ -83,6 +83,9 @@ bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match);
 void json_object_pim_ifp_add(struct json_object *json, struct interface *ifp);
 void pim_print_ifp_flags(struct vty *vty, struct interface *ifp);
 void json_object_pim_upstream_add(json_object *json, struct pim_upstream *up);
+int pim_show_join_cmd_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+                            pim_addr g, const char *json);
+int pim_show_join_vrf_all_cmd_helper(struct vty *vty, const char *json);
 void pim_show_join(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
                   json_object *json);
 int pim_show_jp_agg_list_cmd_helper(const char *vrf, struct vty *vty);