From edd3c63170023abc211a52dce049bf4c3522b319 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 17 Jan 2024 15:58:17 +0200 Subject: [PATCH] zebra: convert interface shutdown command to NB Replace "shutdown" leaf with "enabled" leaf in frr-zebra YANG module to make it in line with standard YANG models. Signed-off-by: Igor Ryzhov --- yang/frr-zebra.yang | 2 +- zebra/interface.c | 59 +++++------------------------------------ zebra/zebra_nb.c | 6 ++--- zebra/zebra_nb.h | 4 +-- zebra/zebra_nb_config.c | 17 ++++++++---- 5 files changed, 25 insertions(+), 63 deletions(-) diff --git a/yang/frr-zebra.yang b/yang/frr-zebra.yang index c948664336..d74e9e84d2 100644 --- a/yang/frr-zebra.yang +++ b/yang/frr-zebra.yang @@ -1977,7 +1977,7 @@ module frr-zebra { "Link-detection for the interface."; } - leaf shutdown { + leaf enabled { type boolean; description "Interface admin status."; diff --git a/zebra/interface.c b/zebra/interface.c index 219dff083b..82f681c848 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -136,7 +136,7 @@ static int if_zebra_new_hook(struct interface *ifp) zebra_if->multicast = IF_ZEBRA_DATA_UNSPEC; zebra_if->mpls_config = IF_ZEBRA_DATA_UNSPEC; - zebra_if->shutdown = IF_ZEBRA_DATA_OFF; + zebra_if->shutdown = IF_ZEBRA_DATA_UNSPEC; zebra_if->link_nsid = NS_UNKNOWN; @@ -3832,29 +3832,16 @@ int if_shutdown(struct interface *ifp) return 0; } -DEFUN (shutdown_if, +DEFPY_YANG (shutdown_if, shutdown_if_cmd, - "shutdown", + "[no] shutdown", + NO_STR "Shutdown the selected interface\n") { - VTY_DECLVAR_CONTEXT(interface, ifp); - int ret; - struct zebra_if *if_data; + nb_cli_enqueue_change(vty, "./frr-zebra:zebra/enabled", + NB_OP_CREATE, no ? "true" : "false"); - if (ifp->ifindex != IFINDEX_INTERNAL) { - /* send RA lifetime of 0 before stopping. rfc4861/6.2.5 */ - rtadv_stop_ra(ifp); - ret = if_unset_flags(ifp, IFF_UP); - if (ret < 0) { - vty_out(vty, "Can't shutdown interface\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if_refresh(ifp); - } - if_data = ifp->info; - if_data->shutdown = IF_ZEBRA_DATA_ON; - - return CMD_SUCCESS; + return nb_cli_apply_changes(vty, NULL); } int if_no_shutdown(struct interface *ifp) @@ -3881,37 +3868,6 @@ int if_no_shutdown(struct interface *ifp) return 0; } -DEFUN (no_shutdown_if, - no_shutdown_if_cmd, - "no shutdown", - NO_STR - "Shutdown the selected interface\n") -{ - VTY_DECLVAR_CONTEXT(interface, ifp); - int ret; - struct zebra_if *if_data; - - if (ifp->ifindex != IFINDEX_INTERNAL) { - ret = if_set_flags(ifp, IFF_UP | IFF_RUNNING); - if (ret < 0) { - vty_out(vty, "Can't up interface\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if_refresh(ifp); - - /* Some addresses (in particular, IPv6 addresses on Linux) get - * removed when the interface goes down. They need to be - * readded. - */ - if_addr_wakeup(ifp); - } - - if_data = ifp->info; - if_data->shutdown = IF_ZEBRA_DATA_OFF; - - return CMD_SUCCESS; -} - DEFUN (bandwidth_if, bandwidth_if_cmd, "bandwidth (1-100000)", @@ -5558,7 +5514,6 @@ void zebra_if_init(void) install_element(INTERFACE_NODE, &mpls_cmd); install_element(INTERFACE_NODE, &linkdetect_cmd); install_element(INTERFACE_NODE, &shutdown_if_cmd); - install_element(INTERFACE_NODE, &no_shutdown_if_cmd); install_element(INTERFACE_NODE, &bandwidth_if_cmd); install_element(INTERFACE_NODE, &no_bandwidth_if_cmd); install_element(INTERFACE_NODE, &ip_address_cmd); diff --git a/zebra/zebra_nb.c b/zebra/zebra_nb.c index de94480d1b..89bbd66bc0 100644 --- a/zebra/zebra_nb.c +++ b/zebra/zebra_nb.c @@ -324,10 +324,10 @@ const struct frr_yang_module_info frr_zebra_info = { } }, { - .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/shutdown", + .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/enabled", .cbs = { - .modify = lib_interface_zebra_shutdown_modify, - .destroy = lib_interface_zebra_shutdown_destroy, + .modify = lib_interface_zebra_enabled_modify, + .destroy = lib_interface_zebra_enabled_destroy, } }, { diff --git a/zebra/zebra_nb.h b/zebra/zebra_nb.h index c781675287..92cabe3042 100644 --- a/zebra/zebra_nb.h +++ b/zebra/zebra_nb.h @@ -91,8 +91,8 @@ int lib_interface_zebra_ip_addrs_ip4_peer_destroy( int lib_interface_zebra_multicast_modify(struct nb_cb_modify_args *args); int lib_interface_zebra_multicast_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_link_detect_modify(struct nb_cb_modify_args *args); -int lib_interface_zebra_shutdown_modify(struct nb_cb_modify_args *args); -int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args); +int lib_interface_zebra_enabled_modify(struct nb_cb_modify_args *args); +int lib_interface_zebra_enabled_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_bandwidth_modify(struct nb_cb_modify_args *args); int lib_interface_zebra_bandwidth_destroy(struct nb_cb_destroy_args *args); int lib_interface_zebra_mpls_modify(struct nb_cb_modify_args *args); diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index b148363032..247082f7be 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -1047,32 +1047,39 @@ int lib_interface_zebra_link_detect_modify(struct nb_cb_modify_args *args) } /* - * XPath: /frr-interface:lib/interface/frr-zebra:zebra/shutdown + * XPath: /frr-interface:lib/interface/frr-zebra:zebra/enabled */ -int lib_interface_zebra_shutdown_modify(struct nb_cb_modify_args *args) +int lib_interface_zebra_enabled_modify(struct nb_cb_modify_args *args) { if (args->event != NB_EV_APPLY) return NB_OK; struct interface *ifp; + bool enabled; ifp = nb_running_get_entry(args->dnode, NULL, true); + enabled = yang_dnode_get_bool(args->dnode, NULL); - if_shutdown(ifp); + if (enabled) + if_no_shutdown(ifp); + else + if_shutdown(ifp); return NB_OK; } -int lib_interface_zebra_shutdown_destroy(struct nb_cb_destroy_args *args) +int lib_interface_zebra_enabled_destroy(struct nb_cb_destroy_args *args) { if (args->event != NB_EV_APPLY) return NB_OK; struct interface *ifp; + struct zebra_if *zif; ifp = nb_running_get_entry(args->dnode, NULL, true); + zif = ifp->info; - if_no_shutdown(ifp); + zif->shutdown = IF_ZEBRA_DATA_UNSPEC; return NB_OK; } -- 2.39.5