aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2020-09-25 17:30:27 -0400
committerFlorin Coras <florin.coras@gmail.com>2020-09-27 18:02:19 +0000
commit2fca85b3a171db19e0517a7a43c8029f5d24e6fa (patch)
treeccc11d693b802d39648e55d1f82ec37abf0cd438 /src
parentbaa40641e263d6462426f87d329591eef4c4e340 (diff)
cnat: fix cnat_translation_cli_add_del
Make the command scriptable, use unformat_line_input. "paths" never needed to be a pool, it's used as a vector. Pools *are* vectors so no harm but... use vec_add2(...) instead. Type: fix Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I65b42de77c3c17f532443319d8a5a15a0a930d66
Diffstat (limited to 'src')
-rw-r--r--src/plugins/cnat/cnat_translation.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/plugins/cnat/cnat_translation.c b/src/plugins/cnat/cnat_translation.c
index b128679cded..4833df9fc37 100644
--- a/src/plugins/cnat/cnat_translation.c
+++ b/src/plugins/cnat/cnat_translation.c
@@ -481,27 +481,37 @@ cnat_translation_cli_add_del (vlib_main_t * vm,
cnat_endpoint_t vip;
u8 flags = CNAT_FLAG_EXCLUSIVE;
cnat_endpoint_tuple_t tmp, *paths = NULL, *path;
+ unformat_input_t _line_input, *line_input = &_line_input;
+ clib_error_t *e = 0;
- while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+ /* Get a line of input. */
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
- if (unformat (input, "add"))
+ if (unformat (line_input, "add"))
del_index = INDEX_INVALID;
- else if (unformat (input, "del %d", &del_index))
+ else if (unformat (line_input, "del %d", &del_index))
;
- else if (unformat (input, "proto %U", unformat_ip_protocol, &proto))
+ else
+ if (unformat (line_input, "proto %U", unformat_ip_protocol, &proto))
;
- else if (unformat (input, "vip %U", unformat_cnat_ep, &vip))
+ else if (unformat (line_input, "vip %U", unformat_cnat_ep, &vip))
flags = CNAT_FLAG_EXCLUSIVE;
- else if (unformat (input, "real %U", unformat_cnat_ep, &vip))
+ else if (unformat (line_input, "real %U", unformat_cnat_ep, &vip))
flags = 0;
- else if (unformat (input, "to %U", unformat_cnat_ep_tuple, &tmp))
+ else if (unformat (line_input, "to %U", unformat_cnat_ep_tuple, &tmp))
{
- pool_get (paths, path);
+ vec_add2 (paths, path, 1);
clib_memcpy (path, &tmp, sizeof (cnat_endpoint_tuple_t));
}
else
- return (clib_error_return (0, "unknown input '%U'",
- format_unformat_error, input));
+ {
+ e = clib_error_return (0, "unknown input '%U'",
+ format_unformat_error, line_input);
+ goto done;
+ }
}
if (INDEX_INVALID == del_index)
@@ -509,8 +519,10 @@ cnat_translation_cli_add_del (vlib_main_t * vm,
else
cnat_translation_delete (del_index);
- pool_free (paths);
- return (NULL);
+done:
+ vec_free (paths);
+ unformat_free (line_input);
+ return (e);
}
/* *INDENT-OFF* */