]> git.puffer.fish Git - mirror/frr.git/commitdiff
pim6d: Moving resuable code to common api for "show pim rpf" command
authorAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 05:49:16 +0000 (22:49 -0700)
committerAbhishek N R <abnr@vmware.com>
Thu, 9 Jun 2022 05:49:16 +0000 (22:49 -0700)
Signed-off-by: Abhishek N R <abnr@vmware.com>
pimd/pim6_cmd.c
pimd/pim_cmd.c
pimd/pim_cmd_common.c
pimd/pim_cmd_common.h

index 77844988eab18969e017f26e87e8c2720bd152f8..f86f3375d5b750e8090591615756a967b73b8d50 100644 (file)
@@ -879,31 +879,7 @@ DEFPY (show_ipv6_pim_rpf,
        "PIM cached source rpf information\n"
        JSON_STR)
 {
-       struct pim_instance *pim;
-       struct vrf *v;
-       json_object *json_parent = NULL;
-
-       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
-
-       if (!v)
-               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 (json)
-               json_parent = json_object_new_object();
-
-       pim_show_rpf(pim, vty, json_parent);
-
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_rpf_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ipv6_pim_rpf_vrf_all,
@@ -916,27 +892,7 @@ DEFPY (show_ipv6_pim_rpf_vrf_all,
        "PIM cached source rpf information\n"
        JSON_STR)
 {
-       struct vrf *vrf;
-       json_object *json_parent = NULL;
-       json_object *json_vrf = NULL;
-
-       if (json)
-               json_parent = json_object_new_object();
-
-       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
-               if (!json)
-                       vty_out(vty, "VRF: %s\n", vrf->name);
-               else
-                       json_vrf = json_object_new_object();
-               pim_show_rpf(vrf->info, vty, json_vrf);
-               if (json)
-                       json_object_object_add(json_parent, vrf->name,
-                                              json_vrf);
-       }
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_rpf_vrf_all_helper(vty, !!json);
 }
 
 DEFPY (show_ipv6_pim_secondary,
index 2d6ce24381af2f9703148bf9c61488fb3fd6ebcb..53ea54e906e0f2ffbc024b969b9e5de2ec03ad14 100644 (file)
@@ -3343,31 +3343,7 @@ DEFPY (show_ip_pim_rpf,
        "PIM cached source rpf information\n"
        JSON_STR)
 {
-       struct pim_instance *pim;
-       struct vrf *v;
-       json_object *json_parent = NULL;
-
-       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
-
-       if (!v)
-               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 (json)
-               json_parent = json_object_new_object();
-
-       pim_show_rpf(pim, vty, json_parent);
-
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_rpf_helper(vrf, vty, !!json);
 }
 
 DEFPY (show_ip_pim_rpf_vrf_all,
@@ -3380,27 +3356,7 @@ DEFPY (show_ip_pim_rpf_vrf_all,
        "PIM cached source rpf information\n"
        JSON_STR)
 {
-       struct vrf *vrf;
-       json_object *json_parent = NULL;
-       json_object *json_vrf = NULL;
-
-       if (json)
-               json_parent = json_object_new_object();
-
-       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
-               if (!json)
-                       vty_out(vty, "VRF: %s\n", vrf->name);
-               else
-                       json_vrf = json_object_new_object();
-               pim_show_rpf(vrf->info, vty, json_vrf);
-               if (json)
-                       json_object_object_add(json_parent, vrf->name,
-                                              json_vrf);
-       }
-       if (json)
-               vty_json(vty, json_parent);
-
-       return CMD_SUCCESS;
+       return pim_show_rpf_vrf_all_helper(vty, !!json);
 }
 
 DEFPY (show_ip_pim_nexthop,
index 668853e988bd700639b3613dc1012c746253f813..28077621759b761c0fcf18d55e16cfe77d035b2e 100644 (file)
@@ -3737,3 +3737,57 @@ int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins,
 
        return CMD_SUCCESS;
 }
+
+int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json)
+{
+       struct pim_instance *pim;
+       struct vrf *v;
+       json_object *json_parent = NULL;
+
+       v = vrf_lookup_by_name(vrf ? vrf : VRF_DEFAULT_NAME);
+
+       if (!v)
+               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 (json)
+               json_parent = json_object_new_object();
+
+       pim_show_rpf(pim, vty, json_parent);
+
+       if (json)
+               vty_json(vty, json_parent);
+
+       return CMD_SUCCESS;
+}
+
+int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json)
+{
+       struct vrf *vrf;
+       json_object *json_parent = NULL;
+       json_object *json_vrf = NULL;
+
+       if (json)
+               json_parent = json_object_new_object();
+
+       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+               if (!json)
+                       vty_out(vty, "VRF: %s\n", vrf->name);
+               else
+                       json_vrf = json_object_new_object();
+               pim_show_rpf(vrf->info, vty, json_vrf);
+               if (json)
+                       json_object_object_add(json_parent, vrf->name,
+                                              json_vrf);
+       }
+       if (json)
+               vty_json(vty, json_parent);
+
+       return CMD_SUCCESS;
+}
index 9644f84e0c57476096f2f55fb68b42f0437ac1ae..ce81473eb45dbc8f70a46a968463973857cc4fdd 100644 (file)
@@ -131,6 +131,8 @@ int pim_debug_pim_packets_cmd(const char *hello, const char *joins,
                              const char *registers, struct vty *vty);
 int pim_no_debug_pim_packets_cmd(const char *hello, const char *joins,
                                 const char *registers, struct vty *vty);
+int pim_show_rpf_helper(const char *vrf, struct vty *vty, bool json);
+int pim_show_rpf_vrf_all_helper(struct vty *vty, bool json);
 
 /*
  * Special Macro to allow us to get the correct pim_instance;