summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pimd/pim6_cmd.c61
-rw-r--r--pimd/pim_cmd.c60
-rw-r--r--pimd/pim_cmd_common.c67
-rw-r--r--pimd/pim_cmd_common.h3
4 files changed, 74 insertions, 117 deletions
diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c
index 74a9fd490a..446395272e 100644
--- a/pimd/pim6_cmd.c
+++ b/pimd/pim6_cmd.c
@@ -874,42 +874,7 @@ DEFPY (show_ipv6_pim_upstream,
"The Group\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- struct vrf *v;
- bool uj = !!json;
- 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 (uj)
- json_parent = json_object_new_object();
-
- 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;
- }
-
- pim_show_upstream(pim, vty, &sg, json_parent);
-
- if (uj)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json);
}
DEFPY (show_ipv6_pim_upstream_vrf_all,
@@ -922,29 +887,7 @@ DEFPY (show_ipv6_pim_upstream_vrf_all,
"PIM upstream information\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_upstream(vrf->info, vty, &sg, 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_upstream_vrf_all_helper(vty, !!json);
}
DEFPY (show_ipv6_pim_upstream_join_desired,
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 1bdd68bf4a..ac16fd1b7f 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -3069,41 +3069,7 @@ DEFPY (show_ip_pim_upstream,
"The Group\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- struct vrf *v;
- bool uj = !!json;
- 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 (uj)
- json_parent = json_object_new_object();
-
- 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;
- }
- pim_show_upstream(pim, vty, &sg, json_parent);
-
- if (uj)
- vty_json(vty, json_parent);
-
- return CMD_SUCCESS;
+ return pim_show_upstream_helper(vrf, vty, s_or_g, g, !!json);
}
DEFPY (show_ip_pim_upstream_vrf_all,
@@ -3116,29 +3082,7 @@ DEFPY (show_ip_pim_upstream_vrf_all,
"PIM upstream information\n"
JSON_STR)
{
- pim_sgaddr sg = {0};
- 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_upstream(vrf->info, vty, &sg, 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_upstream_vrf_all_helper(vty, !!json);
}
DEFPY (show_ip_pim_channel,
diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c
index 46f48e91a1..1159ebd3dd 100644
--- a/pimd/pim_cmd_common.c
+++ b/pimd/pim_cmd_common.c
@@ -3913,3 +3913,70 @@ int pim_show_statistics_helper(const char *vrf, struct vty *vty,
return CMD_SUCCESS;
}
+
+int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool json)
+{
+ 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 (json)
+ json_parent = json_object_new_object();
+
+ 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;
+ }
+
+ pim_show_upstream(pim, vty, &sg, json_parent);
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
+
+int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json)
+{
+ pim_sgaddr sg = {0};
+ 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_upstream(vrf->info, vty, &sg, json_vrf);
+ if (json)
+ json_object_object_add(json_parent, vrf->name,
+ json_vrf);
+ }
+
+ if (json)
+ vty_json(vty, json_parent);
+
+ return CMD_SUCCESS;
+}
diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h
index 4d5284b40b..013db79599 100644
--- a/pimd/pim_cmd_common.h
+++ b/pimd/pim_cmd_common.h
@@ -140,6 +140,9 @@ int pim_show_rp_vrf_all_helper(struct vty *vty, const char *group_str,
int pim_show_secondary_helper(const char *vrf, struct vty *vty);
int pim_show_statistics_helper(const char *vrf, struct vty *vty,
const char *word, bool uj);
+int pim_show_upstream_helper(const char *vrf, struct vty *vty, pim_addr s_or_g,
+ pim_addr g, bool json);
+int pim_show_upstream_vrf_all_helper(struct vty *vty, bool json);
/*
* Special Macro to allow us to get the correct pim_instance;