]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: convert table range command to NB
authorIgor Ryzhov <iryzhov@nfware.com>
Sat, 27 Jan 2024 03:00:27 +0000 (05:00 +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/table_manager.c
zebra/table_manager.h
zebra/zebra_nb.c
zebra/zebra_nb.h
zebra/zebra_nb_config.c
zebra/zebra_vty.c

index 5d539f4bd7d0d797f8d0050be9963360d0a0186a..564617103b989b40b41eaa649b2780e5104251ea 100644 (file)
@@ -2824,6 +2824,31 @@ module frr-zebra {
            Removing the leaf sets it back to the default value for the profile.";
       }
 
+      container netns {
+        description
+          "Configuration for netns VRF backend.";
+        container table-range {
+          presence "Activates table-range configuration.";
+          description
+            "The range of tables to use for this netns.";
+          leaf start {
+            type uint32;
+            mandatory true;
+            description
+              "The first table to use.";
+          }
+          leaf end {
+            type uint32;
+            mandatory true;
+            must ". >= ../start" {
+              error-message "End table must be greater than or equal to start table";
+            }
+            description
+              "The last table to use.";
+          }
+        }
+      }
+
       uses ribs;
 
       uses vrf-vni-mapping;
index 512508b79f96cf30f2940e534cd400f99c1a2791..3e540fda149e6ab545bc337ece8aae2507e445b2 100644 (file)
 #include "zebra/table_manager.h"
 #include "zebra/zebra_errors.h"
 
-/* routing table identifiers
- *
- */
-#if !defined(GNU_LINUX)
-/* BSD systems
- */
-#else
-/* Linux Systems
- */
-#define RT_TABLE_ID_LOCAL                  255
-#define RT_TABLE_ID_MAIN                   254
-#define RT_TABLE_ID_DEFAULT                253
-#define RT_TABLE_ID_COMPAT                 252
-#define RT_TABLE_ID_UNSPEC                 0
-#endif /* !def(GNU_LINUX) */
 #define RT_TABLE_ID_UNRESERVED_MIN         1
 #define RT_TABLE_ID_UNRESERVED_MAX         0xffffffff
 
@@ -279,52 +264,17 @@ void table_manager_disable(struct zebra_vrf *zvrf)
        zvrf->tbl_mgr = NULL;
 }
 
-int table_manager_range(struct vty *vty, bool add, struct zebra_vrf *zvrf,
-                       const char *start_table_str, const char *end_table_str)
+void table_manager_range(bool add, struct zebra_vrf *zvrf, uint32_t start,
+                        uint32_t end)
 {
-       uint32_t start;
-       uint32_t end;
-
        if (add) {
-               if (!start_table_str || !end_table_str) {
-                       vty_out(vty, "%% Labels not specified\n");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-               start = atoi(start_table_str);
-               end = atoi(end_table_str);
-               if (end < start) {
-                       vty_out(vty, "%% End table is less than Start table\n");
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
+               if (zvrf->tbl_mgr &&
+                   ((zvrf->tbl_mgr->start && zvrf->tbl_mgr->start != start) ||
+                    (zvrf->tbl_mgr->end && zvrf->tbl_mgr->end != end)))
+                       zlog_info(
+                               "%% New range will be taken into account at restart");
 
-#if !defined(GNU_LINUX)
-/* BSD systems
- */
-#else
-               /* Linux Systems
-                */
-               if ((start >= RT_TABLE_ID_COMPAT && start <= RT_TABLE_ID_LOCAL)
-                   || (end >= RT_TABLE_ID_COMPAT
-                       && end <= RT_TABLE_ID_LOCAL)) {
-                       vty_out(vty, "%% Values forbidden in range [%u;%u]\n",
-                               RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-               if (start < RT_TABLE_ID_COMPAT && end > RT_TABLE_ID_LOCAL) {
-                       vty_out(vty,
-                               "%% Range overlaps range [%u;%u] forbidden\n",
-                               RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
-                       return CMD_WARNING_CONFIG_FAILED;
-               }
-#endif
-               if (zvrf->tbl_mgr
-                   && ((zvrf->tbl_mgr->start && zvrf->tbl_mgr->start != start)
-                       || (zvrf->tbl_mgr->end && zvrf->tbl_mgr->end != end))) {
-                       vty_out(vty,
-                               "%% New range will be taken into account at restart\n");
-               }
                table_range_add(zvrf, start, end);
        } else
                table_range_add(zvrf, 0, 0);
-       return CMD_SUCCESS;
 }
index f8e99a357dbac43e8d18ff6609dfb9f865251c7e..21691994cba62274cf4241e3a3c2f510e23181a2 100644 (file)
 extern "C" {
 #endif
 
+/* routing table identifiers
+ *
+ */
+#if !defined(GNU_LINUX)
+/* BSD systems
+ */
+#else
+/* Linux Systems
+ */
+#define RT_TABLE_ID_LOCAL   255
+#define RT_TABLE_ID_MAIN    254
+#define RT_TABLE_ID_DEFAULT 253
+#define RT_TABLE_ID_COMPAT  252
+#define RT_TABLE_ID_UNSPEC  0
+#endif /* !def(GNU_LINUX) */
+
 /*
  * Table chunk struct
  * Client daemon which the chunk belongs to can be identified by either
@@ -56,8 +72,8 @@ int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start,
                        uint32_t end, struct zebra_vrf *zvrf);
 int release_daemon_table_chunks(struct zserv *client);
 void table_manager_disable(struct zebra_vrf *zvrf);
-int table_manager_range(struct vty *vty, bool add, struct zebra_vrf *zvrf,
-                       const char *min, const char *max);
+void table_manager_range(bool add, struct zebra_vrf *zvrf, uint32_t start,
+                        uint32_t end);
 
 #ifdef __cplusplus
 }
index d3c8d9badfcedb3d4c2c949025bd779e83a95af8..c90720b749dfa7f44ab80797fa8c465ca8265891 100644 (file)
@@ -893,6 +893,25 @@ const struct frr_yang_module_info frr_zebra_info = {
                                .destroy = lib_vrf_zebra_ipv6_resolve_via_default_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range",
+                       .cbs = {
+                               .create = lib_vrf_zebra_netns_table_range_create,
+                               .destroy = lib_vrf_zebra_netns_table_range_destroy,
+                       }
+               },
+               {
+                       .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/start",
+                       .cbs = {
+                               .modify = lib_vrf_zebra_netns_table_range_start_modify,
+                       }
+               },
+               {
+                       .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/end",
+                       .cbs = {
+                               .modify = lib_vrf_zebra_netns_table_range_end_modify,
+                       }
+               },
                {
                        .xpath = "/frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib",
                        .cbs = {
index 1861236121828995cd5b79da8e36940c6587bfc0..f60340fe9358046079f77b6eeb9675064f07077c 100644 (file)
@@ -433,6 +433,10 @@ int lib_vrf_zebra_resolve_via_default_destroy(struct nb_cb_destroy_args *args);
 int lib_vrf_zebra_ipv6_resolve_via_default_modify(struct nb_cb_modify_args *args);
 int lib_vrf_zebra_ipv6_resolve_via_default_destroy(
        struct nb_cb_destroy_args *args);
+int lib_vrf_zebra_netns_table_range_create(struct nb_cb_create_args *args);
+int lib_vrf_zebra_netns_table_range_destroy(struct nb_cb_destroy_args *args);
+int lib_vrf_zebra_netns_table_range_start_modify(struct nb_cb_modify_args *args);
+int lib_vrf_zebra_netns_table_range_end_modify(struct nb_cb_modify_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 50c116d156b304844176e1761e0770a70362a770..b026f994cdf40dff39ab0a4199a173c18a21d121 100644 (file)
@@ -28,6 +28,7 @@
 #include "zebra/router-id.h"
 #include "zebra/zebra_routemap.h"
 #include "zebra/zebra_rnh.h"
+#include "zebra/table_manager.h"
 
 /*
  * XPath: /frr-zebra:zebra/mcast-rpf-lookup
@@ -3630,6 +3631,125 @@ int lib_vrf_zebra_ipv6_resolve_via_default_destroy(struct nb_cb_destroy_args *ar
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range
+ */
+static int table_range_validate(uint32_t start, uint32_t end, char *errmsg,
+                               size_t errmsg_len)
+{
+#if defined(GNU_LINUX)
+       if ((start >= RT_TABLE_ID_COMPAT && start <= RT_TABLE_ID_LOCAL) ||
+           (end >= RT_TABLE_ID_COMPAT && end <= RT_TABLE_ID_LOCAL)) {
+               snprintfrr(errmsg, errmsg_len,
+                          "Values forbidden in range [%u;%u]",
+                          RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
+               return NB_ERR_VALIDATION;
+       }
+       if (start < RT_TABLE_ID_COMPAT && end > RT_TABLE_ID_LOCAL) {
+               snprintfrr(errmsg, errmsg_len,
+                          "Range overlaps range [%u;%u] forbidden",
+                          RT_TABLE_ID_COMPAT, RT_TABLE_ID_LOCAL);
+               return NB_ERR_VALIDATION;
+       }
+#endif
+       return NB_OK;
+}
+
+int lib_vrf_zebra_netns_table_range_create(struct nb_cb_create_args *args)
+{
+       struct vrf *vrf;
+       uint32_t start, end;
+       const char *vrf_name;
+
+       start = yang_dnode_get_uint32(args->dnode, "start");
+       end = yang_dnode_get_uint32(args->dnode, "end");
+
+       if (args->event == NB_EV_VALIDATE) {
+               vrf_name = yang_dnode_get_string(args->dnode, "../../../name");
+               if (!vrf_is_backend_netns() &&
+                   strcmp(vrf_name, VRF_DEFAULT_NAME)) {
+                       snprintfrr(args->errmsg, args->errmsg_len,
+                                  "Configuration is not available in non-default VRFs when using VRF-lite backend.");
+                       return NB_ERR_VALIDATION;
+               }
+               return table_range_validate(start, end, args->errmsg,
+                                           args->errmsg_len);
+       }
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       table_manager_range(true, vrf->info, start, end);
+
+       return NB_OK;
+}
+
+int lib_vrf_zebra_netns_table_range_destroy(struct nb_cb_destroy_args *args)
+{
+       struct vrf *vrf;
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       table_manager_range(false, vrf->info, 0, 0);
+
+       return NB_OK;
+}
+
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/start
+ */
+int lib_vrf_zebra_netns_table_range_start_modify(struct nb_cb_modify_args *args)
+{
+       struct vrf *vrf;
+       uint32_t start, end;
+
+       start = yang_dnode_get_uint32(args->dnode, NULL);
+       end = yang_dnode_get_uint32(args->dnode, "../end");
+
+       if (args->event == NB_EV_VALIDATE)
+               return table_range_validate(start, end, args->errmsg,
+                                           args->errmsg_len);
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       table_manager_range(true, vrf->info, start, end);
+
+       return NB_OK;
+}
+
+/*
+ * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/netns/table-range/end
+ */
+int lib_vrf_zebra_netns_table_range_end_modify(struct nb_cb_modify_args *args)
+{
+       struct vrf *vrf;
+       uint32_t start, end;
+
+       start = yang_dnode_get_uint32(args->dnode, "../start");
+       end = yang_dnode_get_uint32(args->dnode, NULL);
+
+       if (args->event == NB_EV_VALIDATE)
+               return table_range_validate(start, end, args->errmsg,
+                                           args->errmsg_len);
+
+       if (args->event != NB_EV_APPLY)
+               return NB_OK;
+
+       vrf = nb_running_get_entry(args->dnode, NULL, true);
+
+       table_manager_range(true, vrf->info, start, end);
+
+       return NB_OK;
+}
+
 /*
  * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/l3vni-id
  */
index bb14e85e7d5323cb3ae98d63b3312aac9d8d36f5..352e51afaeeba3b614e406afceaf6600e2fc0ce9 100644 (file)
@@ -4394,29 +4394,33 @@ DEFPY (no_zebra_protodown_bit,
 
 #endif /* HAVE_NETLINK */
 
-DEFUN(ip_table_range, ip_table_range_cmd,
-      "[no] ip table range (1-4294967295) (1-4294967295)",
+DEFPY_YANG (ip_table_range, ip_table_range_cmd,
+      "[no] ip table range ![(1-4294967295)$start (1-4294967295)$end]",
       NO_STR IP_STR
       "table configuration\n"
       "Configure table range\n"
       "Start Routing Table\n"
       "End Routing Table\n")
 {
-       ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
-
-       if (!zvrf)
-               return CMD_WARNING;
-
-       if (zvrf_id(zvrf) != VRF_DEFAULT && !vrf_is_backend_netns()) {
-               vty_out(vty,
-                       "VRF subcommand does not make any sense in l3mdev based vrf's\n");
-               return CMD_WARNING;
+       if (!no) {
+               nb_cli_enqueue_change(vty, "./frr-zebra:zebra/netns/table-range",
+                                     NB_OP_CREATE, NULL);
+               nb_cli_enqueue_change(vty,
+                                     "./frr-zebra:zebra/netns/table-range/start",
+                                     NB_OP_MODIFY, start_str);
+               nb_cli_enqueue_change(vty,
+                                     "./frr-zebra:zebra/netns/table-range/end",
+                                     NB_OP_MODIFY, end_str);
+       } else {
+               nb_cli_enqueue_change(vty, "./frr-zebra:zebra/netns/table-range",
+                                     NB_OP_DESTROY, NULL);
        }
 
-       if (strmatch(argv[0]->text, "no"))
-               return table_manager_range(vty, false, zvrf, NULL, NULL);
+       if (vty->node == CONFIG_NODE)
+               return nb_cli_apply_changes(vty, "/frr-vrf:lib/vrf[name='%s']",
+                                           VRF_DEFAULT_NAME);
 
-       return table_manager_range(vty, true, zvrf, argv[3]->arg, argv[4]->arg);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 #ifdef HAVE_SCRIPTING