diff options
| author | Renato Westphal <renato@opensourcerouting.org> | 2020-09-09 13:28:47 -0300 |
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2020-09-09 14:53:26 -0300 |
| commit | add39cde9d316337b2b62a7367dd34d72c15bff9 (patch) | |
| tree | f98d72b30e79465c772eadced83e696192a5efde /lib/routemap_northbound.c | |
| parent | 5ceb842f455a9b5ec738f7f52aad3a33e1ebf67c (diff) | |
lib: fix the "set metric" route-map command
The "set metric" command wasn't processing metric additions and
subtractions (using + and -) correctly. Fix those problems.
Also, remove the "+metric" and "-metric" options since they don't
work and don't make any sense (they could be interpreted as unitary
increments/decrements but that was never supported).
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/routemap_northbound.c')
| -rw-r--r-- | lib/routemap_northbound.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index 967f3fd4d4..597a6b1ecf 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -983,8 +983,19 @@ lib_route_map_entry_set_action_value_destroy(struct nb_cb_destroy_args *args) static int lib_route_map_entry_set_action_add_metric_modify(struct nb_cb_modify_args *args) { + char metric_str[16]; + + if (args->event == NB_EV_VALIDATE + && yang_dnode_get_uint32(args->dnode, NULL) == 0) { + snprintf(args->errmsg, args->errmsg_len, + "Can't add zero to metric"); + return NB_ERR_VALIDATION; + } + + snprintf(metric_str, sizeof(metric_str), "+%s", + yang_dnode_get_string(args->dnode, NULL)); return set_action_modify(args->event, args->dnode, args->resource, - "+metric"); + metric_str); } static int lib_route_map_entry_set_action_add_metric_destroy( @@ -999,8 +1010,19 @@ static int lib_route_map_entry_set_action_add_metric_destroy( static int lib_route_map_entry_set_action_subtract_metric_modify( struct nb_cb_modify_args *args) { + char metric_str[16]; + + if (args->event == NB_EV_VALIDATE + && yang_dnode_get_uint32(args->dnode, NULL) == 0) { + snprintf(args->errmsg, args->errmsg_len, + "Can't subtract zero from metric"); + return NB_ERR_VALIDATION; + } + + snprintf(metric_str, sizeof(metric_str), "-%s", + yang_dnode_get_string(args->dnode, NULL)); return set_action_modify(args->event, args->dnode, args->resource, - "-metric"); + metric_str); } static int lib_route_map_entry_set_action_subtract_metric_destroy( |
