]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: convert interface shutdown command to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 17 Jan 2024 13:58:17 +0000 (15:58 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 28 Jan 2024 21:28:39 +0000 (23:28 +0200)
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 <iryzhov@nfware.com>
yang/frr-zebra.yang
zebra/interface.c
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c

index c9486643367f1f18f9511f11dd08d0b4c25019ef..d74e9e84d2cf20a75f580df81d8c7b85644f9e79 100644 (file)
@@ -1977,7 +1977,7 @@ module frr-zebra {
           "Link-detection for the interface.";
       }
 
-      leaf shutdown {
+      leaf enabled {
         type boolean;
         description
           "Interface admin status.";
index 219dff083bafa4d9c9cf26e40c462f47b4cc7236..82f681c8483d3ab7fe1c0708810f5e4d1109d8c7 100644 (file)
@@ -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);
index de94480d1b71511d9dda35da47d954bd0df98089..89bbd66bc0e288d4efa461478f92f7875bfbcbb3 100644 (file)
@@ -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,
                        }
                },
                {
index c781675287db4b6f7bae914a34f3eaf9ca2cda24..92cabe30425b1e60d7e10addc5b6c88e5795ce10 100644 (file)
@@ -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);
index b148363032b07312213e81bc0293de7c7be6c925..247082f7bebecc2583e572be31fa05c2993845c7 100644 (file)
@@ -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;
 }