+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Route map northbound implementation.
*
* Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
* Rafael Zalamena
- *
- * 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; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
*/
#include <zebra.h>
return lib_route_map_entry_set_destroy(args);
}
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/set-action/min-metric
+ */
+static int set_action_min_metric_modify(enum nb_event event,
+ const struct lyd_node *dnode,
+ union nb_resource *resource,
+ const char *value, char *errmsg,
+ size_t errmsg_len)
+{
+ struct routemap_hook_context *rhc;
+ int rv;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ /* Check for hook function. */
+ if (rmap_match_set_hook.set_min_metric == NULL)
+ return NB_OK;
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(dnode, NULL, true);
+
+ /* Set destroy information. */
+ rhc->rhc_shook = rmap_match_set_hook.no_set_min_metric;
+ rhc->rhc_rule = "min-metric";
+
+ rv = rmap_match_set_hook.set_min_metric(rhc->rhc_rmi, "min-metric",
+ value, errmsg, errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_shook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+static int
+lib_route_map_entry_set_action_min_metric_modify(struct nb_cb_modify_args *args)
+{
+ const char *min_metric = yang_dnode_get_string(args->dnode, NULL);
+
+ return set_action_min_metric_modify(args->event, args->dnode,
+ args->resource, min_metric,
+ args->errmsg, args->errmsg_len);
+}
+
+static int lib_route_map_entry_set_action_min_metric_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ return lib_route_map_entry_set_destroy(args);
+}
+
+/*
+ * XPath: /frr-route-map:lib/route-map/entry/set-action/max-metric
+ */
+static int set_action_max_metric_modify(enum nb_event event,
+ const struct lyd_node *dnode,
+ union nb_resource *resource,
+ const char *value, char *errmsg,
+ size_t errmsg_len)
+{
+ struct routemap_hook_context *rhc;
+ int rv;
+
+ if (event != NB_EV_APPLY)
+ return NB_OK;
+
+ /* Check for hook function. */
+ if (rmap_match_set_hook.set_max_metric == NULL)
+ return NB_OK;
+
+ /* Add configuration. */
+ rhc = nb_running_get_entry(dnode, NULL, true);
+
+ /* Set destroy information. */
+ rhc->rhc_shook = rmap_match_set_hook.no_set_max_metric;
+ rhc->rhc_rule = "max-metric";
+
+ rv = rmap_match_set_hook.set_max_metric(rhc->rhc_rmi, "max-metric",
+ value, errmsg, errmsg_len);
+ if (rv != CMD_SUCCESS) {
+ rhc->rhc_shook = NULL;
+ return NB_ERR_INCONSISTENCY;
+ }
+
+ return NB_OK;
+}
+
+static int
+lib_route_map_entry_set_action_max_metric_modify(struct nb_cb_modify_args *args)
+{
+ const char *max_metric = yang_dnode_get_string(args->dnode, NULL);
+
+ return set_action_max_metric_modify(args->event, args->dnode,
+ args->resource, max_metric,
+ args->errmsg, args->errmsg_len);
+}
+
+static int lib_route_map_entry_set_action_max_metric_destroy(
+ struct nb_cb_destroy_args *args)
+{
+ return lib_route_map_entry_set_destroy(args);
+}
+
/*
* XPath: /frr-route-map:lib/route-map/entry/set-action/add-metric
*/
.destroy = lib_route_map_entry_set_action_value_destroy,
}
},
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/min-metric",
+ .cbs = {
+ .modify = lib_route_map_entry_set_action_min_metric_modify,
+ .destroy = lib_route_map_entry_set_action_min_metric_destroy,
+ }
+ },
+ {
+ .xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/max-metric",
+ .cbs = {
+ .modify = lib_route_map_entry_set_action_max_metric_modify,
+ .destroy = lib_route_map_entry_set_action_max_metric_destroy,
+ }
+ },
{
.xpath = "/frr-route-map:lib/route-map/entry/set-action/rmap-set-action/add-metric",
.cbs = {