diff options
author | Mobashshera Rasool <mrasool@vmware.com> | 2022-03-07 08:18:47 +0100 |
---|---|---|
committer | Mobashshera Rasool <mrasool@vmware.com> | 2022-03-08 09:54:49 +0100 |
commit | f39f349719fabd797797f29766443434c332385f (patch) | |
tree | 123ad5cd2ae3ba57a084bf8212b40532a6854219 | |
parent | pim6d: Modify apis pim_process_rp_cmd for common processing (diff) | |
download | frr-f39f349719fabd797797f29766443434c332385f.tar.xz frr-f39f349719fabd797797f29766443434c332385f.zip |
pimd: Modify "ip pim rp <> prefix-list <>" command
1. Moving the processing of the above command to an api.
2. Change DEFUN to DEPFY
3. Make the api common for pimv4 and pimv6 processing.
Signed-off-by: Mobashshera Rasool <mrasool@vmware.com>
-rw-r--r-- | pimd/pim_cmd.c | 68 | ||||
-rw-r--r-- | pimd/pim_cmd_common.c | 57 | ||||
-rw-r--r-- | pimd/pim_cmd_common.h | 4 |
3 files changed, 69 insertions, 60 deletions
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index a3bfcdc73..3b3d06e79 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -7011,34 +7011,17 @@ DEFPY (ip_pim_rp, return pim_process_rp_cmd(vty, rp_str, group_str); } -DEFUN (ip_pim_rp_prefix_list, +DEFPY (ip_pim_rp_prefix_list, ip_pim_rp_prefix_list_cmd, - "ip pim rp A.B.C.D prefix-list WORD", + "ip pim rp A.B.C.D$rp prefix-list WORD$plist", IP_STR "pim multicast routing\n" - "Rendevous Point\n" + "Rendezvous Point\n" "ip address of RP\n" "group prefix-list filter\n" "Name of a prefix-list\n") { - int idx_rp = 3, idx_plist = 5; - const char *vrfname; - char rp_plist_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(rp_plist_xpath, sizeof(rp_plist_xpath), - FRR_PIM_STATIC_RP_XPATH, - "frr-pim:pimd", "pim", vrfname, "frr-routing:ipv4", - argv[idx_rp]->arg); - strlcat(rp_plist_xpath, "/prefix-list", sizeof(rp_plist_xpath)); - - nb_cli_enqueue_change(vty, rp_plist_xpath, NB_OP_MODIFY, - argv[idx_plist]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_rp_plist_cmd(vty, rp_str, plist); } DEFPY (no_ip_pim_rp, @@ -7056,53 +7039,18 @@ DEFPY (no_ip_pim_rp, return pim_process_no_rp_cmd(vty, rp_str, group_str); } -DEFUN (no_ip_pim_rp_prefix_list, +DEFPY (no_ip_pim_rp_prefix_list, no_ip_pim_rp_prefix_list_cmd, - "no ip pim rp A.B.C.D prefix-list WORD", + "no ip pim rp A.B.C.D$rp prefix-list WORD$plist", NO_STR IP_STR "pim multicast routing\n" - "Rendevous Point\n" + "Rendezvous Point\n" "ip address of RP\n" "group prefix-list filter\n" "Name of a prefix-list\n") { - int idx_rp = 4; - int idx_plist = 6; - char rp_xpath[XPATH_MAXLEN]; - char plist_xpath[XPATH_MAXLEN]; - const char *vrfname; - const struct lyd_node *plist_dnode; - const char *plist; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(rp_xpath, sizeof(rp_xpath), FRR_PIM_STATIC_RP_XPATH, - "frr-pim:pimd", "pim", vrfname, "frr-routing:ipv4", - argv[idx_rp]->arg); - - snprintf(plist_xpath, sizeof(plist_xpath), FRR_PIM_STATIC_RP_XPATH, - "frr-pim:pimd", "pim", vrfname, "frr-routing:ipv4", - argv[idx_rp]->arg); - strlcat(plist_xpath, "/prefix-list", sizeof(plist_xpath)); - - plist_dnode = yang_dnode_get(vty->candidate_config->dnode, plist_xpath); - if (!plist_dnode) { - vty_out(vty, "%% Unable to find specified RP\n"); - return NB_OK; - } - - plist = yang_dnode_get_string(plist_dnode, plist_xpath); - if (strcmp(argv[idx_plist]->arg, plist)) { - vty_out(vty, "%% Unable to find specified RP\n"); - return NB_OK; - } - - nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_rp_plist_cmd(vty, rp_str, plist); } DEFUN (ip_pim_ssm_prefix_list, diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c index 3a3416ebb..442760fdf 100644 --- a/pimd/pim_cmd_common.c +++ b/pimd/pim_cmd_common.c @@ -597,3 +597,60 @@ int pim_process_no_rp_cmd(struct vty *vty, const char *rp_str, return nb_cli_apply_changes(vty, NULL); } + +int pim_process_rp_plist_cmd(struct vty *vty, const char *rp_str, + const char *prefix_list) +{ + const char *vrfname; + char rp_plist_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(rp_plist_xpath, sizeof(rp_plist_xpath), + FRR_PIM_STATIC_RP_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL, rp_str); + strlcat(rp_plist_xpath, "/prefix-list", sizeof(rp_plist_xpath)); + + nb_cli_enqueue_change(vty, rp_plist_xpath, NB_OP_MODIFY, prefix_list); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str, + const char *prefix_list) +{ + char rp_xpath[XPATH_MAXLEN]; + char plist_xpath[XPATH_MAXLEN]; + const char *vrfname; + const struct lyd_node *plist_dnode; + const char *plist; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(rp_xpath, sizeof(rp_xpath), FRR_PIM_STATIC_RP_XPATH, + "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL, rp_str); + + snprintf(plist_xpath, sizeof(plist_xpath), FRR_PIM_STATIC_RP_XPATH, + "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL, rp_str); + strlcat(plist_xpath, "/prefix-list", sizeof(plist_xpath)); + + plist_dnode = yang_dnode_get(vty->candidate_config->dnode, plist_xpath); + if (!plist_dnode) { + vty_out(vty, "%% Unable to find specified RP\n"); + return NB_OK; + } + + plist = yang_dnode_get_string(plist_dnode, plist_xpath); + if (strcmp(prefix_list, plist)) { + vty_out(vty, "%% Unable to find specified RP\n"); + return NB_OK; + } + + nb_cli_enqueue_change(vty, rp_xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h index 0112393cf..b7e6b6ac8 100644 --- a/pimd/pim_cmd_common.h +++ b/pimd/pim_cmd_common.h @@ -39,6 +39,10 @@ int pim_process_rp_cmd(struct vty *vty, const char *rp_str, const char *group_str); int pim_process_no_rp_cmd(struct vty *vty, const char *rp_str, const char *group_str); +int pim_process_rp_plist_cmd(struct vty *vty, const char *rp_str, + const char *prefix_list); +int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str, + const char *prefix_list); int pim_process_ip_pim_cmd(struct vty *vty); int pim_process_no_ip_pim_cmd(struct vty *vty); |