]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: convert router-id commands to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Fri, 26 Jan 2024 22:16:17 +0000 (00:16 +0200)
committerIgor Ryzhov <iryzhov@nfware.com>
Sun, 28 Jan 2024 21:28:40 +0000 (23:28 +0200)
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
yang/frr-zebra.yang
zebra/router-id.c
zebra/router-id.h
zebra/subdir.am
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c

index 72193664d4e6d9c3d24b4d9c372f19f5b8596af5..06ba547d0b35a4f47d19bb8cfc168827e5cf0443 100644 (file)
@@ -2743,6 +2743,21 @@ module frr-zebra {
     container zebra {
       description
         "Zebra's vrf specific configuration and operational model.";
+
+      leaf router-id {
+        type yang:dotted-quad;
+        description
+          "A 32-bit number in the form of a dotted quad that is used by
+           some routing protocols identifying a router.";
+      }
+
+      leaf ipv6-router-id {
+        type inet:ipv6-address-no-zone;
+        description
+          "A 128-bit number in the form of an IPv6 address that is used by
+           some routing protocols identifying a router.";
+      }
+
       uses ribs;
 
       uses vrf-vni-mapping;
index ef87d924fe54eb58ae7f971516ff77f1a65630f2..92b005081a1bf353c4f31681e87254103f7e791a 100644 (file)
@@ -23,6 +23,7 @@
 #include "table.h"
 #include "rib.h"
 #include "vrf.h"
+#include "northbound_cli.h"
 
 #include "zebra/zebra_router.h"
 #include "zebra/zapi_msg.h"
@@ -30,6 +31,8 @@
 #include "zebra/router-id.h"
 #include "zebra/redistribute.h"
 
+#include "router-id_clippy.c"
+
 static struct connected *router_id_find_node(struct list *l,
                                             struct connected *ifc)
 {
@@ -109,7 +112,7 @@ int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
        assert(!"Reached end of function we should never hit");
 }
 
-static int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
+int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
 {
        struct prefix after, before;
        struct listnode *node;
@@ -256,194 +259,121 @@ void router_id_write(struct vty *vty, struct zebra_vrf *zvrf)
        }
        if (!router_id_v6_is_any(&zvrf->rid6_user_assigned)) {
                vty_out(vty, "%sipv6 router-id %pI6\n", space,
-                       &zvrf->rid_user_assigned.u.prefix6);
+                       &zvrf->rid6_user_assigned.u.prefix6);
        }
 }
 
-DEFUN (ip_router_id,
+DEFPY_YANG (ip_router_id,
        ip_router_id_cmd,
-       "ip router-id A.B.C.D vrf NAME",
+       "ip router-id A.B.C.D$id vrf NAME",
        IP_STR
        "Manually set the router-id\n"
        "IP address to use for router-id\n"
        VRF_CMD_HELP_STR)
 {
-       int idx = 0;
-       struct prefix rid;
-       vrf_id_t vrf_id;
-       struct zebra_vrf *zvrf;
-
-       argv_find(argv, argc, "A.B.C.D", &idx);
-
-       if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
-               return CMD_WARNING_CONFIG_FAILED;
-
-       rid.prefixlen = IPV4_MAX_BITLEN;
-       rid.family = AF_INET;
-
-       argv_find(argv, argc, "NAME", &idx);
-       VRF_GET_ID(vrf_id, argv[idx]->arg, false);
-
-       zvrf = zebra_vrf_lookup_by_id(vrf_id);
-       router_id_set(AFI_IP, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/router-id", NB_OP_MODIFY,
+                             id_str);
+       return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']", vrf);
 }
 
-ALIAS (ip_router_id,
+ALIAS_YANG (ip_router_id,
        router_id_cmd,
-       "router-id A.B.C.D vrf NAME",
+       "router-id A.B.C.D$id vrf NAME",
        "Manually set the router-id\n"
        "IP address to use for router-id\n"
        VRF_CMD_HELP_STR);
 
-DEFUN (ipv6_router_id,
+DEFPY_YANG (ipv6_router_id,
        ipv6_router_id_cmd,
-       "ipv6 router-id X:X::X:X vrf NAME",
+       "ipv6 router-id X:X::X:X$id vrf NAME",
        IPV6_STR
        "Manually set the router-id\n"
        "IPv6 address to use for router-id\n"
        VRF_CMD_HELP_STR)
 {
-       int idx = 0;
-       struct prefix rid;
-       vrf_id_t vrf_id;
-       struct zebra_vrf *zvrf;
-
-       argv_find(argv, argc, "X:X::X:X", &idx);
-
-       if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
-               return CMD_WARNING_CONFIG_FAILED;
-
-       rid.prefixlen = IPV6_MAX_BITLEN;
-       rid.family = AF_INET6;
-
-       argv_find(argv, argc, "NAME", &idx);
-       VRF_GET_ID(vrf_id, argv[idx]->arg, false);
-
-       zvrf = zebra_vrf_lookup_by_id(vrf_id);
-       router_id_set(AFI_IP6, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ipv6-router-id",
+                             NB_OP_MODIFY, id_str);
+       return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']", vrf);
 }
 
 
-DEFUN (ip_router_id_in_vrf,
+DEFPY_YANG (ip_router_id_in_vrf,
        ip_router_id_in_vrf_cmd,
-       "ip router-id A.B.C.D",
+       "ip router-id A.B.C.D$id",
        IP_STR
        "Manually set the router-id\n"
        "IP address to use for router-id\n")
 {
-       ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
-       int idx = 0;
-       struct prefix rid;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/router-id", NB_OP_MODIFY,
+                             id_str);
 
-       argv_find(argv, argc, "A.B.C.D", &idx);
+       if (vty->node == CONFIG_NODE)
+               return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
+                                           VRF_DEFAULT_NAME);
 
-       if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
-               return CMD_WARNING_CONFIG_FAILED;
-
-       rid.prefixlen = IPV4_MAX_BITLEN;
-       rid.family = AF_INET;
-
-       router_id_set(AFI_IP, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
-ALIAS (ip_router_id_in_vrf,
+ALIAS_YANG (ip_router_id_in_vrf,
        router_id_in_vrf_cmd,
-       "router-id A.B.C.D",
+       "router-id A.B.C.D$id",
        "Manually set the router-id\n"
        "IP address to use for router-id\n");
 
-DEFUN (ipv6_router_id_in_vrf,
+DEFPY_YANG (ipv6_router_id_in_vrf,
        ipv6_router_id_in_vrf_cmd,
-       "ipv6 router-id X:X::X:X",
+       "ipv6 router-id X:X::X:X$id",
        IP6_STR
        "Manually set the IPv6 router-id\n"
        "IPV6 address to use for router-id\n")
 {
-       ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
-       int idx = 0;
-       struct prefix rid;
-
-       argv_find(argv, argc, "X:X::X:X", &idx);
-
-       if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
-               return CMD_WARNING_CONFIG_FAILED;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ipv6-router-id",
+                             NB_OP_MODIFY, id_str);
 
-       rid.prefixlen = IPV6_MAX_BITLEN;
-       rid.family = AF_INET6;
+       if (vty->node == CONFIG_NODE)
+               return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
+                                           VRF_DEFAULT_NAME);
 
-       router_id_set(AFI_IP6, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
-DEFUN (no_ip_router_id,
+DEFPY_YANG (no_ip_router_id,
        no_ip_router_id_cmd,
-       "no ip router-id [A.B.C.D vrf NAME]",
+       "no ip router-id A.B.C.D vrf NAME",
        NO_STR
        IP_STR
        "Remove the manually configured router-id\n"
        "IP address to use for router-id\n"
        VRF_CMD_HELP_STR)
 {
-       int idx = 0;
-       struct prefix rid;
-       vrf_id_t vrf_id = VRF_DEFAULT;
-       struct zebra_vrf *zvrf;
-
-       rid.u.prefix4.s_addr = 0;
-       rid.prefixlen = 0;
-       rid.family = AF_INET;
-
-       if (argv_find(argv, argc, "NAME", &idx))
-               VRF_GET_ID(vrf_id, argv[idx]->arg, false);
-
-       zvrf = zebra_vrf_lookup_by_id(vrf_id);
-       router_id_set(AFI_IP, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/router-id", NB_OP_DESTROY,
+                             NULL);
+       return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']", vrf);
 }
 
-ALIAS (no_ip_router_id,
+ALIAS_YANG (no_ip_router_id,
        no_router_id_cmd,
-       "no router-id [A.B.C.D vrf NAME]",
+       "no router-id A.B.C.D vrf NAME",
        NO_STR
        "Remove the manually configured router-id\n"
        "IP address to use for router-id\n"
        VRF_CMD_HELP_STR);
 
-DEFUN (no_ipv6_router_id,
+DEFPY_YANG (no_ipv6_router_id,
        no_ipv6_router_id_cmd,
-       "no ipv6 router-id [X:X::X:X vrf NAME]",
+       "no ipv6 router-id X:X::X:X vrf NAME",
        NO_STR
        IPV6_STR
        "Remove the manually configured IPv6 router-id\n"
        "IPv6 address to use for router-id\n"
        VRF_CMD_HELP_STR)
 {
-       int idx = 0;
-       struct prefix rid;
-       vrf_id_t vrf_id = VRF_DEFAULT;
-       struct zebra_vrf *zvrf;
-
-       memset(&rid, 0, sizeof(rid));
-       rid.family = AF_INET;
-
-       if (argv_find(argv, argc, "NAME", &idx))
-               VRF_GET_ID(vrf_id, argv[idx]->arg, false);
-
-       zvrf = zebra_vrf_lookup_by_id(vrf_id);
-       router_id_set(AFI_IP6, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ipv6-router-id",
+                             NB_OP_DESTROY, NULL);
+       return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']", vrf);
 }
 
-DEFUN (no_ip_router_id_in_vrf,
+DEFPY_YANG (no_ip_router_id_in_vrf,
        no_ip_router_id_in_vrf_cmd,
        "no ip router-id [A.B.C.D]",
        NO_STR
@@ -451,27 +381,24 @@ DEFUN (no_ip_router_id_in_vrf,
        "Remove the manually configured router-id\n"
        "IP address to use for router-id\n")
 {
-       ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
-
-       struct prefix rid;
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/router-id", NB_OP_DESTROY,
+                             NULL);
 
-       rid.u.prefix4.s_addr = 0;
-       rid.prefixlen = 0;
-       rid.family = AF_INET;
+       if (vty->node == CONFIG_NODE)
+               return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
+                                           VRF_DEFAULT_NAME);
 
-       router_id_set(AFI_IP, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
-ALIAS (no_ip_router_id_in_vrf,
+ALIAS_YANG (no_ip_router_id_in_vrf,
        no_router_id_in_vrf_cmd,
        "no router-id [A.B.C.D]",
        NO_STR
        "Remove the manually configured router-id\n"
        "IP address to use for router-id\n");
 
-DEFUN (no_ipv6_router_id_in_vrf,
+DEFPY_YANG (no_ipv6_router_id_in_vrf,
        no_ipv6_router_id_in_vrf_cmd,
        "no ipv6 router-id [X:X::X:X]",
        NO_STR
@@ -479,16 +406,14 @@ DEFUN (no_ipv6_router_id_in_vrf,
        "Remove the manually configured IPv6 router-id\n"
        "IPv6 address to use for router-id\n")
 {
-       ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
+       nb_cli_enqueue_change(vty, "./frr-zebra:zebra/ipv6-router-id",
+                             NB_OP_DESTROY, NULL);
 
-       struct prefix rid;
+       if (vty->node == CONFIG_NODE)
+               return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
+                                           VRF_DEFAULT_NAME);
 
-       memset(&rid, 0, sizeof(rid));
-       rid.family = AF_INET;
-
-       router_id_set(AFI_IP6, &rid, zvrf);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFUN (show_ip_router_id,
index 45860d8b7b805e59f8d3a998086a5ebaf918da1b..4753a1840e4ccd4d1d5c7162b7005ddf55399046 100644 (file)
@@ -27,6 +27,7 @@ extern void router_id_init(struct zebra_vrf *zvrf);
 extern void router_id_cmd_init(void);
 extern void router_id_write(struct vty *vty, struct zebra_vrf *zvrf);
 extern int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf);
+extern int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf);
 
 #ifdef __cplusplus
 }
index 6d499e97e87d07aad6a127c77cd2ccfb5536c2bc..ad1bcee69544a530560d79c012fb830014a23722 100644 (file)
@@ -126,6 +126,7 @@ clippy_scan += \
        zebra/zebra_vrf.c \
        zebra/dpdk/zebra_dplane_dpdk_vty.c \
        zebra/label_manager.c \
+       zebra/router-id.c \
        # end
 
 noinst_HEADERS += \
index b261325f19b938186b4eef28b4027d10370c1908..cbf5bfb59adbf769b74f7eaf1596a3925dba4f64 100644 (file)
@@ -833,6 +833,20 @@ const struct frr_yang_module_info frr_zebra_info = {
                                .get_elem = lib_interface_zebra_state_mcast_group_get_elem,
                        }
                },
+               {
+                       .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/router-id",
+                       .cbs = {
+                               .modify = lib_vrf_zebra_router_id_modify,
+                               .destroy = lib_vrf_zebra_router_id_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ipv6-router-id",
+                       .cbs = {
+                               .modify = lib_vrf_zebra_ipv6_router_id_modify,
+                               .destroy = lib_vrf_zebra_ipv6_router_id_destroy,
+                       }
+               },
                {
                        .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib",
                        .cbs = {
index 5343cb0e9b7f9db898d01e170d63df06c39f7308..9cde562060af0f2dfd08ec3691e367c6ae97988b 100644 (file)
@@ -416,6 +416,10 @@ struct yang_data *lib_interface_zebra_state_remote_vtep_get_elem(
        struct nb_cb_get_elem_args *args);
 struct yang_data *lib_interface_zebra_state_mcast_group_get_elem(
        struct nb_cb_get_elem_args *args);
+int lib_vrf_zebra_router_id_modify(struct nb_cb_modify_args *args);
+int lib_vrf_zebra_router_id_destroy(struct nb_cb_destroy_args *args);
+int lib_vrf_zebra_ipv6_router_id_modify(struct nb_cb_modify_args *args);
+int lib_vrf_zebra_ipv6_router_id_destroy(struct nb_cb_destroy_args *args);
 const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args);
 int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args);
 const void *
index 41f82f5ebe63cc3e36f5d8dd252cced7ad744133..c828d087330e7aadeadaed9781c0cb795487faac 100644 (file)
@@ -25,6 +25,7 @@
 #include "zebra/zebra_vxlan.h"
 #include "zebra/zebra_evpn_mh.h"
 #include "zebra/zebra_ptm.h"
+#include "zebra/router-id.h"
 
 /*
  * XPath: /frr-zebra:zebra/mcast-rpf-lookup
@@ -3226,6 +3227,82 @@ int lib_interface_zebra_ptm_enable_modify(struct nb_cb_modify_args *args)
 }
 #endif
 
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/router-id
+ */
+int lib_vrf_zebra_router_id_modify(struct nb_cb_modify_args *args)
+{
+       struct vrf *vrf;
+       struct prefix p;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       yang_dnode_get_ipv4p(&p, args->dnode, NULL);
+
+       router_id_set(AFI_IP, &p, vrf->info);
+
+       return NB_OK;
+}
+
+int lib_vrf_zebra_router_id_destroy(struct nb_cb_destroy_args *args)
+{
+       struct vrf *vrf;
+       struct prefix p;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       memset(&p, 0, sizeof(p));
+       p.family = AF_INET;
+
+       router_id_set(AFI_IP, &p, vrf->info);
+
+       return NB_OK;
+}
+
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ipv6-router-id
+ */
+int lib_vrf_zebra_ipv6_router_id_modify(struct nb_cb_modify_args *args)
+{
+       struct vrf *vrf;
+       struct prefix p;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       yang_dnode_get_ipv6p(&p, args->dnode, NULL);
+
+       router_id_set(AFI_IP6, &p, vrf->info);
+
+       return NB_OK;
+}
+
+int lib_vrf_zebra_ipv6_router_id_destroy(struct nb_cb_destroy_args *args)
+{
+       struct vrf *vrf;
+       struct prefix p;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       memset(&p, 0, sizeof(p));
+       p.family = AF_INET6;
+
+       router_id_set(AFI_IP6, &p, vrf->info);
+
+       return NB_OK;
+}
+
 /*
  * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
  */