From add39cde9d316337b2b62a7367dd34d72c15bff9 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 9 Sep 2020 13:28:47 -0300 Subject: 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 --- lib/routemap_cli.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'lib/routemap_cli.c') diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c index 836be38113..920f6c7195 100644 --- a/lib/routemap_cli.c +++ b/lib/routemap_cli.c @@ -719,15 +719,13 @@ DEFPY_YANG( DEFPY_YANG( set_metric, set_metric_cmd, - "set metric <(0-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt|+metric$ametric|-metric$smetric>", + "set metric <(-4294967295-4294967295)$metric|rtt$rtt|+rtt$artt|-rtt$srtt>", SET_STR "Metric value for destination routing protocol\n" - "Metric value\n" + "Metric value (use +/- for additions or subtractions)\n" "Assign round trip time\n" "Add round trip time\n" - "Subtract round trip time\n" - "Add metric\n" - "Subtract metric\n") + "Subtract round trip time\n") { const char *xpath = "./set-action[action='metric']"; char xpath_value[XPATH_MAXLEN]; @@ -746,17 +744,17 @@ DEFPY_YANG( snprintf(xpath_value, sizeof(xpath_value), "%s/subtract-round-trip-time", xpath); snprintf(value, sizeof(value), "true"); - } else if (ametric) { + } else if (metric_str && metric_str[0] == '+') { snprintf(xpath_value, sizeof(xpath_value), "%s/add-metric", xpath); - snprintf(value, sizeof(value), "true"); - } else if (smetric) { + snprintf(value, sizeof(value), "%s", ++metric_str); + } else if (metric_str && metric_str[0] == '-') { snprintf(xpath_value, sizeof(xpath_value), "%s/subtract-metric", xpath); - snprintf(value, sizeof(value), "true"); + snprintf(value, sizeof(value), "%s", ++metric_str); } else { snprintf(xpath_value, sizeof(xpath_value), "%s/value", xpath); - snprintf(value, sizeof(value), "%lu", metric); + snprintf(value, sizeof(value), "%s", metric_str); } nb_cli_enqueue_change(vty, xpath_value, NB_OP_MODIFY, value); @@ -831,9 +829,12 @@ void route_map_action_show(struct vty *vty, struct lyd_node *dnode, } else if (yang_dnode_get(dnode, "./subtract-round-trip-time")) { vty_out(vty, " set metric -rtt\n"); } else if (yang_dnode_get(dnode, "./add-metric")) { - vty_out(vty, " set metric +metric\n"); + vty_out(vty, " set metric +%s\n", + yang_dnode_get_string(dnode, "./add-metric")); } else if (yang_dnode_get(dnode, "./subtract-metric")) { - vty_out(vty, " set metric -metric\n"); + vty_out(vty, " set metric -%s\n", + yang_dnode_get_string(dnode, + "./subtract-metric")); } else { vty_out(vty, " set metric %s\n", yang_dnode_get_string(dnode, "./value")); -- cgit v1.2.3 From 12488d7c8dfef8a6f6386fe2ef356c7a95a9230e Mon Sep 17 00:00:00 2001 From: David Schweizer Date: Thu, 10 Sep 2020 09:14:58 +0200 Subject: lib: fix negating set metric route-map command Changed negating set metric route-map command to be usable in conjunction with the affirming command. Signed-off-by: David Schweizer --- lib/routemap_cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/routemap_cli.c') diff --git a/lib/routemap_cli.c b/lib/routemap_cli.c index 920f6c7195..339d025124 100644 --- a/lib/routemap_cli.c +++ b/lib/routemap_cli.c @@ -763,7 +763,7 @@ DEFPY_YANG( DEFPY_YANG( no_set_metric, no_set_metric_cmd, - "no set metric [(0-4294967295)]", + "no set metric [OPTVAL]", NO_STR SET_STR "Metric value for destination routing protocol\n" -- cgit v1.2.3