]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: convert interface ipv6 nd suppress-ra command to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 23 Jan 2024 12:20:49 +0000 (14:20 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 28 Jan 2024 21:28:39 +0000 (23:28 +0200)
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
yang/frr-zebra.yang
zebra/rtadv.c
zebra/rtadv.h
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c

index 95e4fc6db15ff15f25e9587196862304e6b0e026..fd263406f34a40f88c203f8c664e61d5cdf4ec2b 100644 (file)
@@ -2264,6 +2264,21 @@ module frr-zebra {
             "Uplink to the VxLAN core.";
         }
       }
+      container ipv6-router-advertisements {
+        description
+          "Support for IPv6 Router Advertisements.";
+        leaf send-advertisements {
+          type boolean;
+          default "false";
+          description
+            "A flag indicating whether or not the router sends
+            periodic Router Advertisements and responds to
+            Router Solicitations.";
+          reference
+            "RFC 4861: Neighbor Discovery for IP version 6 (IPv6)
+                       - AdvSendAdvertisements";
+        }
+      }
       container state {
         config false;
         description
index 00f018d19232abed8c905ba00cd1fe9dc07ef4b5..f6d3ec40d0cca32cd8ef3671de6cbeb5b8580e87 100644 (file)
@@ -21,6 +21,7 @@
 #include "vrf.h"
 #include "ns.h"
 #include "lib_errors.h"
+#include "northbound_cli.h"
 
 #include "zebra/interface.h"
 #include "zebra/rtadv.h"
@@ -1248,8 +1249,8 @@ static void rtadv_start_interface_events(struct zebra_vrf *zvrf,
                rtadv_event(zvrf, RTADV_START, 0);
 }
 
-static void ipv6_nd_suppress_ra_set(struct interface *ifp,
-                                   enum ipv6_nd_suppress_ra_status status)
+void ipv6_nd_suppress_ra_set(struct interface *ifp,
+                            enum ipv6_nd_suppress_ra_status status)
 {
        struct zebra_if *zif;
        struct zebra_vrf *zvrf;
@@ -1632,49 +1633,23 @@ DEFPY (no_ipv6_nd_ra_retrans_interval,
        return CMD_SUCCESS;
 }
 
-DEFUN (ipv6_nd_suppress_ra,
+DEFPY_YANG (ipv6_nd_suppress_ra,
        ipv6_nd_suppress_ra_cmd,
-       "ipv6 nd suppress-ra",
-       "Interface IPv6 config commands\n"
-       "Neighbor discovery\n"
-       "Suppress Router Advertisement\n")
-{
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       struct zebra_if *zif = ifp->info;
-
-       if (if_is_loopback(ifp)) {
-               vty_out(vty,
-                       "Cannot configure IPv6 Router Advertisements on this  interface\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       if (!CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED))
-               ipv6_nd_suppress_ra_set(ifp, RA_SUPPRESS);
-
-       UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
-       return CMD_SUCCESS;
-}
-
-DEFUN (no_ipv6_nd_suppress_ra,
-       no_ipv6_nd_suppress_ra_cmd,
-       "no ipv6 nd suppress-ra",
+       "[no] ipv6 nd suppress-ra",
        NO_STR
        "Interface IPv6 config commands\n"
        "Neighbor discovery\n"
        "Suppress Router Advertisement\n")
 {
-       VTY_DECLVAR_CONTEXT(interface, ifp);
-       struct zebra_if *zif = ifp->info;
-
-       if (if_is_loopback(ifp)) {
-               vty_out(vty,
-                       "Cannot configure IPv6 Router Advertisements on this interface\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
-       ipv6_nd_suppress_ra_set(ifp, RA_ENABLE);
-       SET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
-       return CMD_SUCCESS;
+       if (no)
+               nb_cli_enqueue_change(vty,
+                                     "./frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
+                                     NB_OP_MODIFY, "true");
+       else
+               nb_cli_enqueue_change(vty,
+                                     "./frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
+                                     NB_OP_DESTROY, NULL);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFUN (ipv6_nd_ra_interval_msec,
@@ -2928,7 +2903,6 @@ void rtadv_cmd_init(void)
        install_element(INTERFACE_NODE, &ipv6_nd_ra_hop_limit_cmd);
        install_element(INTERFACE_NODE, &no_ipv6_nd_ra_hop_limit_cmd);
        install_element(INTERFACE_NODE, &ipv6_nd_suppress_ra_cmd);
-       install_element(INTERFACE_NODE, &no_ipv6_nd_suppress_ra_cmd);
        install_element(INTERFACE_NODE, &ipv6_nd_ra_interval_cmd);
        install_element(INTERFACE_NODE, &ipv6_nd_ra_interval_msec_cmd);
        install_element(INTERFACE_NODE, &no_ipv6_nd_ra_interval_cmd);
index 9d358d4b0d84934cac184a128a2c8b812455cf3d..79abe5f7e0750103cd3e6909d0d6148dcb1894a8 100644 (file)
@@ -385,6 +385,9 @@ extern void rtadv_if_fini(struct zebra_if *zif);
 extern void rtadv_add_prefix(struct zebra_if *zif, const struct prefix_ipv6 *p);
 extern void rtadv_delete_prefix(struct zebra_if *zif, const struct prefix *p);
 
+void ipv6_nd_suppress_ra_set(struct interface *ifp,
+                            enum ipv6_nd_suppress_ra_status status);
+
 #else /* !HAVE_RTADV */
 struct rtadv {
        /* empty structs aren't valid ISO C */
index 15cb9c08585a6f124d092a6e7961f754b5ed3e61..87cfab5469474f304d03b9bd01c13e870a2fcaf8 100644 (file)
@@ -546,6 +546,12 @@ const struct frr_yang_module_info frr_zebra_info = {
                                .modify = lib_interface_zebra_evpn_mh_uplink_modify,
                        }
                },
+               {
+                       .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/ipv6-router-advertisements/send-advertisements",
+                       .cbs = {
+                               .modify = lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify,
+                       }
+               },
                {
                        .xpath = "/frr-interface:lib/interface/frr-zebra:zebra/state/up-count",
                        .cbs = {
index 1ddc985ffdbb8aeb32a0deb29a30245082b94c1c..f45270f7b4fab94b71a308ce85f7ab12b458192d 100644 (file)
@@ -181,6 +181,8 @@ int lib_interface_zebra_evpn_mh_df_preference_modify(
        struct nb_cb_modify_args *args);
 int lib_interface_zebra_evpn_mh_bypass_modify(struct nb_cb_modify_args *args);
 int lib_interface_zebra_evpn_mh_uplink_modify(struct nb_cb_modify_args *args);
+int lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify(
+       struct nb_cb_modify_args *args);
 struct yang_data *
 lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args);
 struct yang_data *
index eb3d5eec2c2d5857e1b555aef63a7b0961a96204..d13a75866f54d5a80d44056b0e62b438c8032f14 100644 (file)
@@ -2455,6 +2455,36 @@ int lib_interface_zebra_evpn_mh_uplink_modify(struct nb_cb_modify_args *args)
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-interface:lib/interface/frr-zebra:zebra/ipv6-router-advertisements/send-advertisements
+ */
+int lib_interface_zebra_ipv6_router_advertisements_send_advertisements_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct interface *ifp;
+       struct zebra_if *zif;
+       bool send_adv;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       ifp = nb_running_get_entry(args->dnode, NULL, true);
+       zif = ifp->info;
+
+       send_adv = yang_dnode_get_bool(args->dnode, NULL);
+
+       if (send_adv) {
+               ipv6_nd_suppress_ra_set(ifp, RA_ENABLE);
+               SET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
+       } else {
+               if (!CHECK_FLAG(zif->rtadv.ra_configured, BGP_RA_CONFIGURED))
+                       ipv6_nd_suppress_ra_set(ifp, RA_SUPPRESS);
+               UNSET_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED);
+       }
+
+       return NB_OK;
+}
+
 /*
  * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
  */