From f34c67b313e475c25341c680d2ef5452828040d5 Mon Sep 17 00:00:00 2001 From: Nathan Bahr Date: Fri, 25 Oct 2024 19:58:19 +0000 Subject: [PATCH] pimd: Update show ip pim nexthop-lookup... command Allow group to be optional in the command. Only validate group if source is ANY. Documented setting source via RP if not provided. Added new output if ANY source + group lookup is performed and no RP is found for the group. Updated output to include souce and group for lookup. Signed-off-by: Nathan Bahr --- pimd/pim_cmd.c | 2 +- pimd/pim_cmd_common.c | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 397e19a7e016..6bc87f612652 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -2930,7 +2930,7 @@ DEFPY (show_ip_pim_nexthop, DEFPY (show_ip_pim_nexthop_lookup, show_ip_pim_nexthop_lookup_cmd, - "show ip pim [vrf NAME] nexthop-lookup A.B.C.D$source A.B.C.D$group", + "show ip pim [vrf NAME] nexthop-lookup A.B.C.D$source [A.B.C.D$group]", SHOW_STR IP_STR PIM_STR diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 776365e25591..c0dfbbea35e6 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -2989,31 +2989,36 @@ int pim_show_nexthop_lookup_cmd_helper(const char *vrf, struct vty *vty, #if PIM_IPV == 4 if (pim_is_group_224_4(source)) { - vty_out(vty, - "Invalid argument. Expected Valid Source Address.\n"); + vty_out(vty, "Invalid argument. Expected Valid Source Address.\n"); return CMD_WARNING; } - - if (!pim_is_group_224_4(group)) { - vty_out(vty, - "Invalid argument. Expected Valid Multicast Group Address.\n"); + /* Only require group if source is not provided */ + if (pim_addr_is_any(source) && !pim_is_group_224_4(group)) { + vty_out(vty, "Invalid argument. Expected Valid Multicast Group Address.\n"); return CMD_WARNING; } #endif - if (!pim_rp_set_upstream_addr(v->info, &vif_source, source, group)) + /* This call will set vif_source=source, if source is not ANY. Otherwise vif_source + * will be set to the RP address according to the group address. If no RP is configured + * for the group, then return 0 and set vif_source to ANY + */ + if (!pim_rp_set_upstream_addr(v->info, &vif_source, source, group)) { + vty_out(vty, "(%pPAs, %pPA) --- Nexthop Lookup failed, no RP.\n", &source, &group); return CMD_SUCCESS; + } + pim_addr_to_prefix(&grp, group); memset(&nexthop, 0, sizeof(nexthop)); if (!pim_nht_lookup_ecmp(v->info, &nexthop, vif_source, &grp, false)) { - vty_out(vty, - "Nexthop Lookup failed, no usable routes returned.\n"); + vty_out(vty, "(%pPAs, %pPA) --- Nexthop Lookup failed, no usable routes returned.\n", + &source, &group); return CMD_SUCCESS; } - vty_out(vty, "Group %pFXh --- Nexthop %pPAs Interface %s\n", &grp, + vty_out(vty, "(%pPAs, %pPA) --- Nexthop %pPAs Interface %s\n", &source, &group, &nexthop.mrib_nexthop_addr, nexthop.interface->name); return CMD_SUCCESS;