From 8763946ab271a714edb2c33b1f1e154bec7e7bab Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 24 Jan 2024 03:03:50 +0200 Subject: [PATCH] zebra: convert PTM configuration to NB Signed-off-by: Igor Ryzhov --- mgmtd/mgmt_main.c | 6 ++++ yang/frr-zebra.yang | 19 ++++++++++++ zebra/zebra_nb.c | 23 ++++++++++++++ zebra/zebra_nb.h | 6 ++++ zebra/zebra_nb_config.c | 47 ++++++++++++++++++++++++++++ zebra/zebra_ptm.c | 69 ++++++++++++++++++++++++++--------------- zebra/zebra_ptm.h | 7 +++++ 7 files changed, 152 insertions(+), 25 deletions(-) diff --git a/mgmtd/mgmt_main.c b/mgmtd/mgmt_main.c index 100f574b34..68a7489511 100644 --- a/mgmtd/mgmt_main.c +++ b/mgmtd/mgmt_main.c @@ -143,6 +143,9 @@ static struct frr_signal_t mgmt_signals[] = { extern const struct frr_yang_module_info frr_staticd_cli_info; #endif +#if HAVE_BFDD == 0 +const char *zebra_features[] = { "ptm-bfd", NULL }; +#endif /* * These are stub info structs that are used to load the modules used by backend @@ -151,6 +154,9 @@ extern const struct frr_yang_module_info frr_staticd_cli_info; */ const struct frr_yang_module_info zebra_info = { .name = "frr-zebra", +#if HAVE_BFDD == 0 + .features = zebra_features, +#endif .ignore_cfg_cbs = true, .nodes = { { .xpath = NULL } }, }; diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index 2d3523c483..689a9c2560 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -81,6 +81,11 @@ module frr-zebra { "Initial revision."; } + feature ptm-bfd { + description + "Using an external PTM daemon that implements BFD."; + } + typedef unix-timestamp { type uint32; units "seconds"; @@ -2661,6 +2666,13 @@ module frr-zebra { } } } + leaf ptm-enable { + if-feature ptm-bfd; + type boolean; + default "true"; + description + "Enable PTM on the interface."; + } container state { config false; description @@ -2830,6 +2842,13 @@ module frr-zebra { description "Limit on the number of updates queued to the dataplane subsystem."; } + leaf ptm-enable { + if-feature ptm-bfd; + type boolean; + default "false"; + description + "Enable PTM globally."; + } /* * Debug options */ diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index e4d8871406..638507c52b 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -10,9 +10,16 @@ #include "libfrr.h" #include "zebra_nb.h" +#if HAVE_BFDD == 0 +const char *features[] = { "ptm-bfd", NULL }; +#endif + /* clang-format off */ const struct frr_yang_module_info frr_zebra_info = { .name = "frr-zebra", +#if HAVE_BFDD == 0 + .features = features, +#endif .nodes = { { .xpath = "/frr-zebra:zebra/mcast-rpf-lookup", @@ -79,6 +86,14 @@ const struct frr_yang_module_info frr_zebra_info = { .modify = zebra_dplane_queue_limit_modify, } }, +#if HAVE_BFDD == 0 + { + .xpath = "/frr-zebra:zebra/ptm-enable", + .cbs = { + .modify = zebra_ptm_enable_modify, + } + }, +#endif { .xpath = "/frr-zebra:zebra/debugs/debug-events", .cbs = { @@ -705,6 +720,14 @@ const struct frr_yang_module_info frr_zebra_info = { .destroy = lib_interface_zebra_ipv6_router_advertisements_rdnss_rdnss_address_lifetime_destroy, } }, +#if HAVE_BFDD == 0 + { + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/ptm-enable", + .cbs = { + .modify = lib_interface_zebra_ptm_enable_modify, + } + }, +#endif { .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count", .cbs = { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index 5f29d0d5d7..8116e827d7 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -44,6 +44,9 @@ int zebra_import_kernel_table_route_map_destroy( int zebra_allow_external_route_update_create(struct nb_cb_create_args *args); int zebra_allow_external_route_update_destroy(struct nb_cb_destroy_args *args); int zebra_dplane_queue_limit_modify(struct nb_cb_modify_args *args); +#if HAVE_BFDD == 0 +int zebra_ptm_enable_modify(struct nb_cb_modify_args *args); +#endif int zebra_debugs_debug_events_modify(struct nb_cb_modify_args *args); int zebra_debugs_debug_events_destroy(struct nb_cb_destroy_args *args); int zebra_debugs_debug_zapi_send_modify(struct nb_cb_modify_args *args); @@ -249,6 +252,9 @@ int lib_interface_zebra_ipv6_router_advertisements_dnssl_dnssl_domain_lifetime_m struct nb_cb_modify_args *args); int lib_interface_zebra_ipv6_router_advertisements_dnssl_dnssl_domain_lifetime_destroy( struct nb_cb_destroy_args *args); +#if HAVE_BFDD == 0 +int lib_interface_zebra_ptm_enable_modify(struct nb_cb_modify_args *args); +#endif struct yang_data * lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args); struct yang_data * diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index db93e41ea2..28e48f79f9 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -24,6 +24,7 @@ #include "zebra/zebra_vxlan_private.h" #include "zebra/zebra_vxlan.h" #include "zebra/zebra_evpn_mh.h" +#include "zebra/zebra_ptm.h" /* * XPath: /frr-zebra:zebra/mcast-rpf-lookup @@ -265,6 +266,28 @@ int zebra_dplane_queue_limit_modify(struct nb_cb_modify_args *args) return NB_OK; } +#if HAVE_BFDD == 0 +/* + * XPath: /frr-zebra:zebra/ptm-enable + */ +int zebra_ptm_enable_modify(struct nb_cb_modify_args *args) +{ + bool ptm; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ptm = yang_dnode_get_bool(args->dnode, NULL); + + if (ptm) + zebra_global_ptm_enable(); + else + zebra_global_ptm_disable(); + + return NB_OK; +} +#endif + /* * XPath: /frr-zebra:zebra/debugs/debug-events */ @@ -3177,6 +3200,30 @@ int lib_interface_zebra_ipv6_router_advertisements_dnssl_dnssl_domain_lifetime_d return NB_OK; } +#if HAVE_BFDD == 0 +/* + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/ptm-enable + */ +int lib_interface_zebra_ptm_enable_modify(struct nb_cb_modify_args *args) +{ + struct interface *ifp; + bool ptm; + + if (args->event != NB_EV_APPLY) + return NB_OK; + + ifp = nb_running_get_entry(args->dnode, NULL, true); + + ptm = yang_dnode_get_bool(args->dnode, NULL); + if (ptm) + zebra_if_ptm_enable(ifp); + else + zebra_if_ptm_disable(ifp); + + return NB_OK; +} +#endif + /* * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id */ diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 40630d7890..0272315418 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -20,6 +20,7 @@ #include "vrf.h" #include "vty.h" #include "lib_errors.h" +#include "northbound_cli.h" #include "zebra/debug.h" #include "zebra/interface.h" @@ -240,10 +241,7 @@ void zebra_ptm_connect(struct event *t) } } -DEFUN (zebra_ptm_enable, - zebra_ptm_enable_cmd, - "ptm-enable", - "Enable neighbor check with specified topology\n") +void zebra_global_ptm_enable(void) { struct vrf *vrf; struct interface *ifp; @@ -266,27 +264,37 @@ DEFUN (zebra_ptm_enable, } zebra_ptm_connect(NULL); +} - return CMD_SUCCESS; +void zebra_global_ptm_disable(void) +{ + ptm_cb.ptm_enable = ZEBRA_IF_PTM_ENABLE_OFF; + zebra_ptm_reset_status(1); } -DEFUN (no_zebra_ptm_enable, +DEFUN_YANG (zebra_ptm_enable, + zebra_ptm_enable_cmd, + "ptm-enable", + "Enable neighbor check with specified topology\n") +{ + nb_cli_enqueue_change(vty, "/frr-zebra:zebra/ptm-enable", NB_OP_MODIFY, + "true"); + return nb_cli_apply_changes(vty, NULL); +} + +DEFUN_YANG (no_zebra_ptm_enable, no_zebra_ptm_enable_cmd, "no ptm-enable", NO_STR "Enable neighbor check with specified topology\n") { - ptm_cb.ptm_enable = ZEBRA_IF_PTM_ENABLE_OFF; - zebra_ptm_reset_status(1); - return CMD_SUCCESS; + nb_cli_enqueue_change(vty, "/frr-zebra:zebra/ptm-enable", NB_OP_MODIFY, + "false"); + return nb_cli_apply_changes(vty, NULL); } -DEFUN (zebra_ptm_enable_if, - zebra_ptm_enable_if_cmd, - "ptm-enable", - "Enable neighbor check with specified topology\n") +void zebra_if_ptm_enable(struct interface *ifp) { - VTY_DECLVAR_CONTEXT(interface, ifp); struct zebra_if *if_data; int old_ptm_enable; int send_linkdown = 0; @@ -295,7 +303,7 @@ DEFUN (zebra_ptm_enable_if, if_data->ptm_enable = ZEBRA_IF_PTM_ENABLE_UNSPEC; if (ifp->ifindex == IFINDEX_INTERNAL) { - return CMD_SUCCESS; + return; } old_ptm_enable = ifp->ptm_enable; @@ -312,19 +320,12 @@ DEFUN (zebra_ptm_enable_if, if_down(ifp); } } - - return CMD_SUCCESS; } -DEFUN (no_zebra_ptm_enable_if, - no_zebra_ptm_enable_if_cmd, - "no ptm-enable", - NO_STR - "Enable neighbor check with specified topology\n") +void zebra_if_ptm_disable(struct interface *ifp) { - VTY_DECLVAR_CONTEXT(interface, ifp); - int send_linkup = 0; struct zebra_if *if_data; + int send_linkup = 0; if ((ifp->ifindex != IFINDEX_INTERNAL) && (ifp->ptm_enable)) { if (!if_is_operative(ifp)) @@ -341,10 +342,28 @@ DEFUN (no_zebra_ptm_enable_if, if_data = ifp->info; if_data->ptm_enable = ZEBRA_IF_PTM_ENABLE_OFF; +} - return CMD_SUCCESS; +DEFUN_YANG (zebra_ptm_enable_if, + zebra_ptm_enable_if_cmd, + "ptm-enable", + "Enable neighbor check with specified topology\n") +{ + nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ptm-enable", NB_OP_MODIFY, + "true"); + return nb_cli_apply_changes(vty, NULL); } +DEFUN_YANG (no_zebra_ptm_enable_if, + no_zebra_ptm_enable_if_cmd, + "no ptm-enable", + NO_STR + "Enable neighbor check with specified topology\n") +{ + nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ptm-enable", NB_OP_MODIFY, + "false"); + return nb_cli_apply_changes(vty, NULL); +} void zebra_ptm_write(struct vty *vty) { diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h index 4d09474b7f..571018349c 100644 --- a/zebra/zebra_ptm.h +++ b/zebra/zebra_ptm.h @@ -61,6 +61,13 @@ void zebra_ptm_connect(struct event *t); void zebra_ptm_write(struct vty *vty); int zebra_ptm_get_enable_state(void); +#if HAVE_BFDD == 0 +void zebra_global_ptm_enable(void); +void zebra_global_ptm_disable(void); +void zebra_if_ptm_enable(struct interface *ifp); +void zebra_if_ptm_disable(struct interface *ifp); +#endif + /* ZAPI message handlers */ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS); void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS); -- 2.39.5