]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: North-bound implementation for ospf6d rmaps
authorSarita Patra <saritap@vmware.com>
Fri, 30 Oct 2020 07:42:34 +0000 (00:42 -0700)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 30 Mar 2021 19:59:30 +0000 (22:59 +0300)
This commit introduces the implementation for the north-bound
callbacks for the ospf6d-specific route-map match and set clauses.

Signed-off-by: NaveenThanikachalam <nthanikachal@vmware.com>
Signed-off-by: Sarita Patra <saritap@vmware.com>
ospf6d/ospf6_asbr.c
ospf6d/ospf6_main.c
ospf6d/ospf6_routemap_nb.c [new file with mode: 0644]
ospf6d/ospf6_routemap_nb.h [new file with mode: 0644]
ospf6d/ospf6_routemap_nb_config.c [new file with mode: 0644]
ospf6d/subdir.am

index 9fb21d55462099904183a3bdc14208999ed4802e..ffd6dc22c373084ed152e958e76d2bea5490c01c 100644 (file)
@@ -30,6 +30,7 @@
 #include "plist.h"
 #include "thread.h"
 #include "linklist.h"
+#include "lib/northbound_cli.h"
 
 #include "ospf6_proto.h"
 #include "ospf6_lsa.h"
@@ -1924,99 +1925,83 @@ ospf6_routemap_rule_set_tag(void *rule, const struct prefix *p, void *object)
        return RMAP_OKAY;
 }
 
-static const struct route_map_rule_cmd
-               ospf6_routemap_rule_set_tag_cmd = {
+static const struct route_map_rule_cmd ospf6_routemap_rule_set_tag_cmd = {
        "tag",
        ospf6_routemap_rule_set_tag,
        route_map_rule_tag_compile,
        route_map_rule_tag_free,
 };
 
-static int route_map_command_status(struct vty *vty, enum rmap_compile_rets ret)
-{
-       switch (ret) {
-       case RMAP_RULE_MISSING:
-               vty_out(vty, "OSPF6 Can't find rule.\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       case RMAP_COMPILE_ERROR:
-               vty_out(vty, "OSPF6 Argument is malformed.\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       case RMAP_COMPILE_SUCCESS:
-               break;
-       }
-
-       return CMD_SUCCESS;
-}
-
 /* add "set metric-type" */
-DEFUN (ospf6_routemap_set_metric_type,
-       ospf6_routemap_set_metric_type_cmd,
-       "set metric-type <type-1|type-2>",
-       "Set value\n"
-       "Type of metric\n"
-       "OSPF6 external type 1 metric\n"
-       "OSPF6 external type 2 metric\n")
+DEFUN_YANG (ospf6_routemap_set_metric_type, ospf6_routemap_set_metric_type_cmd,
+      "set metric-type <type-1|type-2>",
+      "Set value\n"
+      "Type of metric\n"
+      "OSPF6 external type 1 metric\n"
+      "OSPF6 external type 2 metric\n")
 {
-       VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
-       int idx_external = 2;
-       enum rmap_compile_rets ret = route_map_add_set(route_map_index,
-                                                      "metric-type",
-                                                      argv[idx_external]->arg);
+       char *ext = argv[2]->text;
 
-       return route_map_command_status(vty, ret);
+       const char *xpath =
+               "./set-action[action='frr-ospf-route-map:metric-type']";
+       char xpath_value[XPATH_MAXLEN];
+
+       nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+       snprintf(xpath_value, sizeof(xpath_value),
+                "%s/rmap-set-action/frr-ospf-route-map:metric-type", xpath);
+       nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, ext);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 /* delete "set metric-type" */
-DEFUN (ospf6_routemap_no_set_metric_type,
-       ospf6_routemap_no_set_metric_type_cmd,
-       "no set metric-type [<type-1|type-2>]",
-       NO_STR
-       "Set value\n"
-       "Type of metric\n"
-       "OSPF6 external type 1 metric\n"
-       "OSPF6 external type 2 metric\n")
+DEFUN_YANG (ospf6_routemap_no_set_metric_type, ospf6_routemap_no_set_metric_type_cmd,
+      "no set metric-type [<type-1|type-2>]",
+      NO_STR
+      "Set value\n"
+      "Type of metric\n"
+      "OSPF6 external type 1 metric\n"
+      "OSPF6 external type 2 metric\n")
 {
-       VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
-       char *ext = (argc == 4) ? argv[3]->text : NULL;
-       enum rmap_compile_rets ret = route_map_delete_set(route_map_index,
-                                                         "metric-type", ext);
+       const char *xpath =
+               "./set-action[action='frr-ospf-route-map:metric-type']";
 
-       return route_map_command_status(vty, ret);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 /* add "set forwarding-address" */
-DEFUN (ospf6_routemap_set_forwarding,
-       ospf6_routemap_set_forwarding_cmd,
-       "set forwarding-address X:X::X:X",
-       "Set value\n"
-       "Forwarding Address\n"
-       "IPv6 Address\n")
-{
-       VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
+DEFUN_YANG (ospf6_routemap_set_forwarding, ospf6_routemap_set_forwarding_cmd,
+      "set forwarding-address X:X::X:X",
+      "Set value\n"
+      "Forwarding Address\n"
+      "IPv6 Address\n")
+{
        int idx_ipv6 = 2;
-       enum rmap_compile_rets ret = route_map_add_set(route_map_index,
-                                                      "forwarding-address",
-                                                      argv[idx_ipv6]->arg);
+       const char *xpath =
+               "./set-action[action='frr-ospf6-route-map:forwarding-address']";
+       char xpath_value[XPATH_MAXLEN];
 
-       return route_map_command_status(vty, ret);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+       snprintf(xpath_value, sizeof(xpath_value),
+                "%s/rmap-set-action/frr-ospf6-route-map:ipv6-address", xpath);
+       nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY,
+                             argv[idx_ipv6]->arg);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 /* delete "set forwarding-address" */
-DEFUN (ospf6_routemap_no_set_forwarding,
-       ospf6_routemap_no_set_forwarding_cmd,
-       "no set forwarding-address X:X::X:X",
-       NO_STR
-       "Set value\n"
-       "Forwarding Address\n"
-       "IPv6 Address\n")
-{
-       VTY_DECLVAR_CONTEXT(route_map_index, route_map_index);
-       int idx_ipv6 = 3;
-       enum rmap_compile_rets ret = route_map_delete_set(route_map_index,
-                                                         "forwarding-address",
-                                                         argv[idx_ipv6]->arg);
-
-       return route_map_command_status(vty, ret);
+DEFUN_YANG (ospf6_routemap_no_set_forwarding, ospf6_routemap_no_set_forwarding_cmd,
+      "no set forwarding-address [X:X::X:X]",
+      NO_STR
+      "Set value\n"
+      "Forwarding Address\n"
+      "IPv6 Address\n")
+{
+       const char *xpath =
+               "./set-action[action='frr-ospf6-route-map:forwarding-address']";
+
+       nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 static void ospf6_routemap_init(void)
index c601693a7e4167c7697247e44fbcc87bfee2865f..cf61ca7a62dd16c20e5052292534505e046813b4 100644 (file)
@@ -47,6 +47,7 @@
 #include "ospf6_lsa.h"
 #include "ospf6_interface.h"
 #include "ospf6_zebra.h"
+#include "ospf6_routemap_nb.h"
 
 /* Default configuration file name for ospf6d. */
 #define OSPF6_DEFAULT_CONFIG       "ospf6d.conf"
@@ -172,6 +173,8 @@ static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
        &frr_interface_info,
        &frr_route_map_info,
        &frr_vrf_info,
+       &frr_ospf_route_map_info,
+       &frr_ospf6_route_map_info,
 };
 
 FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
diff --git a/ospf6d/ospf6_routemap_nb.c b/ospf6d/ospf6_routemap_nb.c
new file mode 100644 (file)
index 0000000..b710fef
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2020        Vmware
+ *                           Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "lib/northbound.h"
+#include "lib/routemap.h"
+#include "ospf6_routemap_nb.h"
+
+/* clang-format off */
+const struct frr_yang_module_info frr_ospf_route_map_info = {
+       .name = "frr-ospf-route-map",
+       .nodes = {
+               {
+                       .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type",
+                       .cbs = {
+                               .modify = lib_route_map_entry_set_action_rmap_set_action_metric_type_modify,
+                               .destroy = lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy,
+                       }
+               },
+               {
+                       .xpath = NULL,
+               },
+       }
+};
+
+const struct frr_yang_module_info frr_ospf6_route_map_info = {
+       .name = "frr-ospf6-route-map",
+       .nodes = {
+               {
+                       .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf6-route-map:ipv6-address",
+                       .cbs = {
+                               .modify = lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify,
+                               .destroy = lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy,
+                       }
+               },
+               {
+                       .xpath = NULL,
+               },
+       }
+};
diff --git a/ospf6d/ospf6_routemap_nb.h b/ospf6d/ospf6_routemap_nb.h
new file mode 100644 (file)
index 0000000..181e71a
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020        Vmware
+ *                           Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _FRR_OSPF6_ROUTEMAP_NB_H_
+#define _FRR_OSPF6_ROUTEMAP_NB_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern const struct frr_yang_module_info frr_ospf_route_map_info;
+extern const struct frr_yang_module_info frr_ospf6_route_map_info;
+
+/* prototypes */
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy(struct nb_cb_destroy_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(struct nb_cb_modify_args *args);
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(struct nb_cb_destroy_args *args);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ospf6d/ospf6_routemap_nb_config.c b/ospf6d/ospf6_routemap_nb_config.c
new file mode 100644 (file)
index 0000000..3c7741e
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2020        Vmware
+ *                           Sarita Patra
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "lib/command.h"
+#include "lib/log.h"
+#include "lib/northbound.h"
+#include "lib/routemap.h"
+#include "ospf6_routemap_nb.h"
+
+/*
+ * XPath:
+ * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf-route-map:metric-type
+ */
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct routemap_hook_context *rhc;
+       const char *type;
+       int rv;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               /* Add configuration. */
+               rhc = nb_running_get_entry(args->dnode, NULL, true);
+               type = yang_dnode_get_string(args->dnode, NULL);
+
+               /* Set destroy information. */
+               rhc->rhc_shook = generic_set_delete;
+               rhc->rhc_rule = "metric-type";
+               rhc->rhc_event = RMAP_EVENT_SET_DELETED;
+
+               rv = generic_set_add(rhc->rhc_rmi, "metric-type", type,
+                                    args->errmsg, args->errmsg_len);
+               if (rv != CMD_SUCCESS) {
+                       rhc->rhc_mhook = NULL;
+                       return NB_ERR_INCONSISTENCY;
+               }
+       }
+
+       return NB_OK;
+}
+
+int lib_route_map_entry_set_action_rmap_set_action_metric_type_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               return lib_route_map_entry_set_destroy(args);
+       }
+
+       return NB_OK;
+}
+
+/*
+ * XPath:
+ * /frr-route-map:lib/route-map/entry/set-action/rmap-set-action/frr-ospf6-route-map:ipv6-address
+ */
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct routemap_hook_context *rhc;
+       const char *ipv6_addr;
+       int rv;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               /* Add configuration. */
+               rhc = nb_running_get_entry(args->dnode, NULL, true);
+               ipv6_addr = yang_dnode_get_string(args->dnode, NULL);
+
+               /* Set destroy information. */
+               rhc->rhc_shook = generic_set_delete;
+               rhc->rhc_rule = "forwarding-address";
+               rhc->rhc_event = RMAP_EVENT_SET_DELETED;
+
+               rv = generic_set_add(rhc->rhc_rmi, "forwarding-address",
+                                    ipv6_addr,
+                                    args->errmsg, args->errmsg_len);
+               if (rv != CMD_SUCCESS) {
+                       rhc->rhc_mhook = NULL;
+                       return NB_ERR_INCONSISTENCY;
+               }
+       }
+
+       return NB_OK;
+}
+
+int lib_route_map_entry_set_action_rmap_set_action_ipv6_address_destroy(
+       struct nb_cb_destroy_args *args)
+{
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               return lib_route_map_entry_set_destroy(args);
+       }
+
+       return NB_OK;
+}
index dc173da9dc03dca1148cac7b7337a9145ff77841..788b532a9015c57dc061eb7f371d51b2b01f55c6 100644 (file)
@@ -34,6 +34,8 @@ ospf6d_libospf6_a_SOURCES = \
        ospf6d/ospf6_abr.c \
        ospf6d/ospf6_area.c \
        ospf6d/ospf6_asbr.c \
+       ospf6d/ospf6_routemap_nb.c \
+       ospf6d/ospf6_routemap_nb_config.c \
        ospf6d/ospf6_bfd.c \
        ospf6d/ospf6_flood.c \
        ospf6d/ospf6_interface.c \
@@ -66,6 +68,7 @@ noinst_HEADERS += \
        ospf6d/ospf6_network.h \
        ospf6d/ospf6_proto.h \
        ospf6d/ospf6_route.h \
+       ospf6d/ospf6_routemap_nb.h \
        ospf6d/ospf6_spf.h \
        ospf6d/ospf6_top.h \
        ospf6d/ospf6_zebra.h \
@@ -85,3 +88,8 @@ ospf6d_ospf6d_snmp_la_LIBADD = lib/libfrrsnmp.la
 clippy_scan += \
        ospf6d/ospf6_asbr.c \
        # end
+
+nodist_ospf6d_ospf6d_SOURCES = \
+       yang/frr-ospf-route-map.yang.c \
+       yang/frr-ospf6-route-map.yang.c \
+       # end