From 2fca85b3a171db19e0517a7a43c8029f5d24e6fa Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Fri, 25 Sep 2020 17:30:27 -0400 Subject: 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 Change-Id: I65b42de77c3c17f532443319d8a5a15a0a930d66 --- src/plugins/cnat/cnat_translation.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/plugins/cnat/cnat_translation.c') 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* */ -- cgit 1.2.3-korg