diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2020-09-19 08:06:36 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-19 08:06:36 -0400 |
| commit | 0b8125588ae674a146bcd58e893a60111ceef59e (patch) | |
| tree | b2b14071ad8c97a2fa20ec28d58ae898cf37d5c6 /lib/routemap_northbound.c | |
| parent | dfc51e66bf365b435caece197f11a0f24e997587 (diff) | |
| parent | f6bcffb6232a8e055f2cc4012ffe762e5d18c457 (diff) | |
Merge pull request #7069 from opensourcerouting/fix-set-metric
lib: fix the "set metric" route-map command
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( |
