From efa18c6c6ff84a71c70435d901421599500af5d2 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 17 Jan 2024 14:28:13 +0200 Subject: [PATCH] zebra: convert inteface multicast command to NB Introduce new "[no] multicast " 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 --- doc/user/zebra.rst | 2 +- zebra/interface.c | 69 ++++++++++++++++++----------------------- zebra/zebra_nb_config.c | 10 ++++-- 3 files changed, 40 insertions(+), 41 deletions(-) diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 8f4c9e1d45..c27819449c 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -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 or disable multicast flag for the interface. diff --git a/zebra/interface.c b/zebra/interface.c index f864b91822..541803eb9f 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -3683,6 +3683,24 @@ void if_arp(struct interface *ifp, bool enable) if_refresh(ifp); } +DEFPY_YANG (multicast_new, + multicast_new_cmd, + "[no] multicast ", + 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); diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c index 98c241b2a1..c51250e76f 100644 --- a/zebra/zebra_nb_config.c +++ b/zebra/zebra_nb_config.c @@ -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; } -- 2.39.5