]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: convert inteface multicast command to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 17 Jan 2024 12:28:13 +0000 (14:28 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 28 Jan 2024 21:28:39 +0000 (23:28 +0200)
Introduce new "[no] multicast <enable|disable>" command to be able to
remove the configuration. Current "[no] multicast" command cannot be
removed. Current command is hidden but still works for backwards
compatibility.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
doc/user/zebra.rst
zebra/interface.c
zebra/zebra_nb_config.c

index 8f4c9e1d45af2a671a00e7278976937abbe7592c..c27819449cc3de051c5b69f72f05b5ea63495785 100644 (file)
@@ -178,7 +178,7 @@ Standard Commands
    work on non-linux systems at all. 'enable' and 'disable' will respectively turn
    on and off mpls on the given interface.
 
-.. clicmd:: multicast
+.. clicmd:: multicast <enable|disable>
 
 
    Enable or disable multicast flag for the interface.
index f864b91822534fb7dd84e7a1d450d17c55d1e305..541803eb9f5edcafc057b53db9975fd5a0a787dd 100644 (file)
@@ -3683,6 +3683,24 @@ void if_arp(struct interface *ifp, bool enable)
        if_refresh(ifp);
 }
 
+DEFPY_YANG (multicast_new,
+       multicast_new_cmd,
+       "[no] multicast <enable$on|disable$off>",
+       NO_STR
+       "Control multicast flag on interface\n"
+       "Set multicast flag on interface\n"
+       "Unset multicast flag on interface\n")
+{
+       if (!no)
+               nb_cli_enqueue_change(vty, "./frr-zebra:zebra/multicast",
+                                     NB_OP_CREATE, on ? "true" : "false");
+       else
+               nb_cli_enqueue_change(vty, "./frr-zebra:zebra/multicast",
+                                     NB_OP_DESTROY, NULL);
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
 int if_multicast_set(struct interface *ifp)
 {
        struct zebra_if *if_data;
@@ -3701,27 +3719,15 @@ int if_multicast_set(struct interface *ifp)
        return 0;
 }
 
-DEFUN (multicast,
+DEFUN_HIDDEN (multicast,
        multicast_cmd,
        "multicast",
        "Set multicast flag to interface\n")
 {
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       int ret;
-       struct zebra_if *if_data;
-
-       if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
-               ret = if_set_flags(ifp, IFF_MULTICAST);
-               if (ret < 0) {
-                       vty_out(vty, "Can't set multicast flag\n");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-               if_refresh(ifp);
-       }
-       if_data = ifp->info;
-       if_data->multicast = IF_ZEBRA_DATA_ON;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/multicast",
+                             NB_OP_CREATE, "true");
 
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFPY (mpls,
@@ -3760,28 +3766,16 @@ int if_multicast_unset(struct interface *ifp)
        return 0;
 }
 
-DEFUN (no_multicast,
+DEFUN_HIDDEN (no_multicast,
        no_multicast_cmd,
        "no multicast",
        NO_STR
        "Unset multicast flag to interface\n")
 {
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       int ret;
-       struct zebra_if *if_data;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/multicast",
+                             NB_OP_CREATE, "false");
 
-       if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
-               ret = if_unset_flags(ifp, IFF_MULTICAST);
-               if (ret < 0) {
-                       vty_out(vty, "Can't unset multicast flag\n");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-               if_refresh(ifp);
-       }
-       if_data = ifp->info;
-       if_data->multicast = IF_ZEBRA_DATA_OFF;
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 int if_linkdetect(struct interface *ifp, bool detect)
@@ -5531,12 +5525,10 @@ static int if_config_write(struct vty *vty)
                        }
 
                        if (if_data) {
-                               if (if_data->multicast != IF_ZEBRA_DATA_UNSPEC)
-                                       vty_out(vty, " %smulticast\n",
-                                               if_data->multicast ==
-                                                               IF_ZEBRA_DATA_ON
-                                                       ? ""
-                                                       : "no ");
+                               if (if_data->multicast == IF_ZEBRA_DATA_ON)
+                                       vty_out(vty, " multicast enable\n");
+                               else if (if_data->multicast == IF_ZEBRA_DATA_OFF)
+                                       vty_out(vty, " multicast disable\n");
 
                                if (if_data->mpls_config == IF_ZEBRA_DATA_ON)
                                        vty_out(vty, " mpls enable\n");
@@ -5572,6 +5564,7 @@ void zebra_if_init(void)
 
        install_element(ENABLE_NODE, &show_interface_desc_cmd);
        install_element(ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
+       install_element(INTERFACE_NODE, &multicast_new_cmd);
        install_element(INTERFACE_NODE, &multicast_cmd);
        install_element(INTERFACE_NODE, &no_multicast_cmd);
        install_element(INTERFACE_NODE, &mpls_cmd);
index 98c241b2a1a584fab5f2095d757c1df3dece81e4..c51250e76fb22292798cb8b492b8d85df23ce662 100644 (file)
@@ -999,10 +999,14 @@ int lib_interface_zebra_multicast_modify(struct nb_cb_modify_args *args)
                return NB_OK;
 
        struct interface *ifp;
+       bool multicast = yang_dnode_get_bool(args->dnode, NULL);
 
        ifp = nb_running_get_entry(args->dnode, NULL, true);
 
-       if_multicast_set(ifp);
+       if (multicast)
+               if_multicast_set(ifp);
+       else
+               if_multicast_unset(ifp);
 
        return NB_OK;
 }
@@ -1013,10 +1017,12 @@ int lib_interface_zebra_multicast_destroy(struct nb_cb_destroy_args *args)
                return NB_OK;
 
        struct interface *ifp;
+       struct zebra_if *zif;
 
        ifp = nb_running_get_entry(args->dnode, NULL, true);
+       zif = ifp->info;
 
-       if_multicast_unset(ifp);
+       zif->multicast = IF_ZEBRA_DATA_UNSPEC;
 
        return NB_OK;
 }