diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/routemap.c | 34 | ||||
| -rw-r--r-- | lib/routemap.h | 37 | ||||
| -rw-r--r-- | lib/routemap_cli.c | 84 | ||||
| -rw-r--r-- | lib/routemap_northbound.c | 118 |
4 files changed, 273 insertions, 0 deletions
diff --git a/lib/routemap.c b/lib/routemap.c index 20dcd2a53d..39455841e3 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -394,6 +394,40 @@ void route_map_no_set_metric_hook(int (*func)(struct route_map_index *index, { rmap_match_set_hook.no_set_metric = func; } +/* set min-metric */ +void route_map_set_min_metric_hook(int (*func)(struct route_map_index *index, + const char *command, + const char *arg, char *errmsg, + size_t errmsg_len)) +{ + rmap_match_set_hook.set_min_metric = func; +} + +/* no set min-metric */ +void route_map_no_set_min_metric_hook(int (*func)(struct route_map_index *index, + const char *command, + const char *arg, char *errmsg, + size_t errmsg_len)) +{ + rmap_match_set_hook.no_set_min_metric = func; +} +/* set max-metric */ +void route_map_set_max_metric_hook(int (*func)(struct route_map_index *index, + const char *command, + const char *arg, char *errmsg, + size_t errmsg_len)) +{ + rmap_match_set_hook.set_max_metric = func; +} + +/* no set max-metric */ +void route_map_no_set_max_metric_hook(int (*func)(struct route_map_index *index, + const char *command, + const char *arg, char *errmsg, + size_t errmsg_len)) +{ + rmap_match_set_hook.no_set_max_metric = func; +} /* set tag */ void route_map_set_tag_hook(int (*func)(struct route_map_index *index, diff --git a/lib/routemap.h b/lib/routemap.h index 2197a49e76..770d705837 100644 --- a/lib/routemap.h +++ b/lib/routemap.h @@ -312,6 +312,8 @@ DECLARE_QOBJ_TYPE(route_map); (strmatch(A, "frr-route-map:ipv6-next-hop")) #define IS_SET_METRIC(A) \ (strmatch(A, "frr-route-map:set-metric")) +#define IS_SET_MIN_METRIC(A) (strmatch(A, "frr-route-map:set-min-metric")) +#define IS_SET_MAX_METRIC(A) (strmatch(A, "frr-route-map:set-max-metric")) #define IS_SET_TAG(A) (strmatch(A, "frr-route-map:set-tag")) #define IS_SET_SR_TE_COLOR(A) \ (strmatch(A, "frr-route-map:set-sr-te-color")) @@ -684,6 +686,22 @@ extern void route_map_no_set_metric_hook( int (*func)(struct route_map_index *index, const char *command, const char *arg, char *errmsg, size_t errmsg_len)); +/* set metric */ +extern void route_map_set_max_metric_hook( + int (*func)(struct route_map_index *index, const char *command, + const char *arg, char *errmsg, size_t errmsg_len)); +/* no set metric */ +extern void route_map_no_set_max_metric_hook( + int (*func)(struct route_map_index *index, const char *command, + const char *arg, char *errmsg, size_t errmsg_len)); +/* set metric */ +extern void route_map_set_min_metric_hook( + int (*func)(struct route_map_index *index, const char *command, + const char *arg, char *errmsg, size_t errmsg_len)); +/* no set metric */ +extern void route_map_no_set_min_metric_hook( + int (*func)(struct route_map_index *index, const char *command, + const char *arg, char *errmsg, size_t errmsg_len)); /* set tag */ extern void route_map_set_tag_hook(int (*func)(struct route_map_index *index, const char *command, @@ -920,6 +938,25 @@ struct route_map_match_set_hooks { int (*no_set_metric)(struct route_map_index *index, const char *command, const char *arg, char *errmsg, size_t errmsg_len); + /* set min-metric */ + int (*set_min_metric)(struct route_map_index *index, + const char *command, const char *arg, + char *errmsg, size_t errmsg_len); + + /* no set min-metric */ + int (*no_set_min_metric)(struct route_map_index *index, + const char *command, const char *arg, + char *errmsg, size_t errmsg_len); + + /* set max-metric */ + int (*set_max_metric)(struct route_map_index *index, + const char *command, const char *arg, + char *errmsg, size_t errmsg_len); + + /* no set max-metric */ + int (*no_set_max_metric)(struct route_map_index *index, + const char *command, const char *arg, + char *errmsg, size_t errmsg_len); /* set tag */ int (*set_tag)(struct route_map_index *index, diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c index 4345b74bc0..75d1175886 100644 --- a/lib/routemap_cli.c +++ b/lib/routemap_cli.c @@ -890,6 +890,76 @@ DEFPY_YANG( return nb_cli_apply_changes(vty, NULL); } +DEFPY_YANG(set_min_metric, set_min_metric_cmd, + "set min-metric <(0-4294967295)$metric>", + SET_STR + "Minimum metric value for destination routing protocol\n" + "Minimum metric value\n") +{ + const char *xpath = + "./set-action[action='frr-route-map:set-min-metric']"; + char xpath_value[XPATH_MAXLEN]; + char value[64]; + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/min-metric", xpath); + snprintf(value, sizeof(value), "%s", metric_str); + + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY_YANG(no_set_min_metric, no_set_min_metric_cmd, + "no set min-metric [(0-4294967295)]", + NO_STR SET_STR + "Minimum metric value for destination routing protocol\n" + "Minumum metric value\n") +{ + const char *xpath = + "./set-action[action='frr-route-map:set-min-metric']"; + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY_YANG(set_max_metric, set_max_metric_cmd, + "set max-metric <(0-4294967295)$metric>", + SET_STR + "Maximum metric value for destination routing protocol\n" + "Miximum metric value\n") +{ + const char *xpath = + "./set-action[action='frr-route-map:set-max-metric']"; + char xpath_value[XPATH_MAXLEN]; + char value[64]; + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + snprintf(xpath_value, sizeof(xpath_value), + "%s/rmap-set-action/max-metric", xpath); + snprintf(value, sizeof(value), "%s", metric_str); + + nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY_YANG(no_set_max_metric, no_set_max_metric_cmd, + "no set max-metric [(0-4294967295)]", + NO_STR SET_STR + "Maximum Metric value for destination routing protocol\n" + "Maximum metric value\n") +{ + const char *xpath = + "./set-action[action='frr-route-map:set-max-metric']"; + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + return nb_cli_apply_changes(vty, NULL); +} + DEFPY_YANG( set_tag, set_tag_cmd, "set tag (1-4294967295)$tag", @@ -1011,6 +1081,14 @@ void route_map_action_show(struct vty *vty, const struct lyd_node *dnode, yang_dnode_get_string( dnode, "./rmap-set-action/value")); } + } else if (IS_SET_MIN_METRIC(action)) { + vty_out(vty, " set min-metric %s\n", + yang_dnode_get_string(dnode, + "./rmap-set-action/min-metric")); + } else if (IS_SET_MAX_METRIC(action)) { + vty_out(vty, " set max-metric %s\n", + yang_dnode_get_string(dnode, + "./rmap-set-action/max-metric")); } else if (IS_SET_TAG(action)) { vty_out(vty, " set tag %s\n", yang_dnode_get_string(dnode, "./rmap-set-action/tag")); @@ -1551,6 +1629,12 @@ void route_map_cli_init(void) install_element(RMAP_NODE, &set_metric_cmd); install_element(RMAP_NODE, &no_set_metric_cmd); + install_element(RMAP_NODE, &set_min_metric_cmd); + install_element(RMAP_NODE, &no_set_min_metric_cmd); + + install_element(RMAP_NODE, &set_max_metric_cmd); + install_element(RMAP_NODE, &no_set_max_metric_cmd); + install_element(RMAP_NODE, &set_tag_cmd); install_element(RMAP_NODE, &no_set_tag_cmd); diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index ab127dd0fc..4659850994 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -1028,6 +1028,110 @@ lib_route_map_entry_set_action_value_destroy(struct nb_cb_destroy_args *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 */ static int @@ -1369,6 +1473,20 @@ const struct frr_yang_module_info frr_route_map_info = { } }, { + .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 = { .modify = lib_route_map_entry_set_action_add_metric_modify, |
