#include "plist.h"
#include "thread.h"
#include "linklist.h"
+#include "lib/northbound_cli.h"
#include "ospf6_proto.h"
#include "ospf6_lsa.h"
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)
#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"
&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,
--- /dev/null
+/*
+ * 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,
+ },
+ }
+};
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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;
+}
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 \
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 \
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