From 745b8d4a68c112cbcf371d73f81b7ce7c3921b4d Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 13 Apr 2021 11:07:01 -0300 Subject: [PATCH] pimd: support BFD profiles configuration Allow users to pre configure BFD sessions with a profile. Signed-off-by: Rafael Zalamena --- pimd/pim_bfd.c | 5 +++++ pimd/pim_cmd.c | 25 ++++++++++++++++++++--- pimd/pim_iface.h | 1 + pimd/pim_nb.c | 7 +++++++ pimd/pim_nb.h | 2 ++ pimd/pim_nb_config.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 2990fcb023..bc518391a5 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -56,6 +56,10 @@ void pim_bfd_write_config(struct vty *vty, struct interface *ifp) else #endif /* ! HAVE_BFDD */ vty_out(vty, " ip pim bfd\n"); + + if (pim_ifp->bfd_config.profile) + vty_out(vty, " ip pim bfd profile %s\n", + pim_ifp->bfd_config.profile); } static void pim_neighbor_bfd_cb(struct bfd_session_params *bsp, @@ -92,6 +96,7 @@ void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp, pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx); bfd_sess_set_ipv4_addrs(neigh->bfd_session, NULL, &neigh->source_addr); bfd_sess_set_interface(neigh->bfd_session, neigh->interface->name); + bfd_sess_set_profile(neigh->bfd_session, pim_ifp->bfd_config.profile); bfd_sess_install(neigh->bfd_session); } diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index b25b755e1e..c01cfec88e 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -9676,12 +9676,14 @@ DEFUN (interface_no_pim_use_source, "frr-routing:ipv4"); } -DEFUN (ip_pim_bfd, +DEFPY (ip_pim_bfd, ip_pim_bfd_cmd, - "ip pim bfd", + "ip pim bfd [profile BFDPROF$prof]", IP_STR PIM_STR - "Enables BFD support\n") + "Enables BFD support\n" + "Use BFD profile\n" + "Use BFD profile name\n") { const struct lyd_node *igmp_enable_dnode; @@ -9698,6 +9700,22 @@ DEFUN (ip_pim_bfd, } nb_cli_enqueue_change(vty, "./bfd", NB_OP_CREATE, NULL); + if (prof) + nb_cli_enqueue_change(vty, "./bfd/profile", NB_OP_MODIFY, prof); + + return nb_cli_apply_changes(vty, "./frr-pim:pim"); +} + +DEFPY(no_ip_pim_bfd_profile, no_ip_pim_bfd_profile_cmd, + "no ip pim bfd profile [BFDPROF]", + NO_STR + IP_STR + PIM_STR + "Enables BFD support\n" + "Disable BFD profile\n" + "BFD Profile name\n") +{ + nb_cli_enqueue_change(vty, "./bfd/profile", NB_OP_DESTROY, NULL); return nb_cli_apply_changes(vty, "./frr-pim:pim"); } @@ -11694,6 +11712,7 @@ void pim_cmd_init(void) /* Install BFD command */ install_element(INTERFACE_NODE, &ip_pim_bfd_cmd); install_element(INTERFACE_NODE, &ip_pim_bfd_param_cmd); + install_element(INTERFACE_NODE, &no_ip_pim_bfd_profile_cmd); install_element(INTERFACE_NODE, &no_ip_pim_bfd_cmd); #if HAVE_BFDD == 0 install_element(INTERFACE_NODE, &no_ip_pim_bfd_param_cmd); diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index b1365cab7f..92784103fe 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -166,6 +166,7 @@ struct pim_interface { uint32_t min_rx; uint32_t min_tx; uint8_t detection_multiplier; + char *profile; } bfd_config; }; diff --git a/pimd/pim_nb.c b/pimd/pim_nb.c index 8ca0e0780b..37c539883d 100644 --- a/pimd/pim_nb.c +++ b/pimd/pim_nb.c @@ -258,6 +258,13 @@ const struct frr_yang_module_info frr_pim_info = { .modify = lib_interface_pim_bfd_detect_mult_modify, } }, + { + .xpath = "/frr-interface:lib/interface/frr-pim:pim/bfd/profile", + .cbs = { + .modify = lib_interface_pim_bfd_profile_modify, + .destroy = lib_interface_pim_bfd_profile_destroy, + } + }, { .xpath = "/frr-interface:lib/interface/frr-pim:pim/bsm", .cbs = { diff --git a/pimd/pim_nb.h b/pimd/pim_nb.h index 78eb680103..440384e45c 100644 --- a/pimd/pim_nb.h +++ b/pimd/pim_nb.h @@ -121,6 +121,8 @@ int lib_interface_pim_bfd_min_rx_interval_modify(struct nb_cb_modify_args *args) int lib_interface_pim_bfd_min_tx_interval_modify( struct nb_cb_modify_args *args); int lib_interface_pim_bfd_detect_mult_modify(struct nb_cb_modify_args *args); +int lib_interface_pim_bfd_profile_modify(struct nb_cb_modify_args *args); +int lib_interface_pim_bfd_profile_destroy(struct nb_cb_destroy_args *args); int lib_interface_pim_bsm_modify(struct nb_cb_modify_args *args); int lib_interface_pim_unicast_bsm_modify(struct nb_cb_modify_args *args); int lib_interface_pim_active_active_modify(struct nb_cb_modify_args *args); diff --git a/pimd/pim_nb_config.c b/pimd/pim_nb_config.c index ce270ea6bc..8e6f2ec42b 100644 --- a/pimd/pim_nb_config.c +++ b/pimd/pim_nb_config.c @@ -2004,6 +2004,53 @@ int lib_interface_pim_bfd_detect_mult_modify(struct nb_cb_modify_args *args) return NB_OK; } +/* + * XPath: /frr-interface:lib/interface/frr-pim:pim/bfd/profile + */ +int lib_interface_pim_bfd_profile_modify(struct nb_cb_modify_args *args) +{ + struct interface *ifp; + struct pim_interface *pim_ifp; + + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + /* NOTHING */ + break; + case NB_EV_APPLY: + ifp = nb_running_get_entry(args->dnode, NULL, true); + pim_ifp = ifp->info; + XFREE(MTYPE_TMP, pim_ifp->bfd_config.profile); + pim_ifp->bfd_config.profile = XSTRDUP( + MTYPE_TMP, yang_dnode_get_string(args->dnode, NULL)); + break; + } + + return NB_OK; +} + +int lib_interface_pim_bfd_profile_destroy(struct nb_cb_destroy_args *args) +{ + struct interface *ifp; + struct pim_interface *pim_ifp; + + switch (args->event) { + case NB_EV_VALIDATE: + case NB_EV_PREPARE: + case NB_EV_ABORT: + /* NOTHING */ + break; + case NB_EV_APPLY: + ifp = nb_running_get_entry(args->dnode, NULL, true); + pim_ifp = ifp->info; + XFREE(MTYPE_TMP, pim_ifp->bfd_config.profile); + break; + } + + return NB_OK; +} + /* * XPath: /frr-interface:lib/interface/frr-pim:pim/bsm */ -- 2.39.5