diff options
author | 2018-11-28 11:36:05 +0100 | |
---|---|---|
committer | 2018-12-13 12:11:50 +0000 | |
commit | 413f4a5b2123c1625d615315db293a080078482b (patch) | |
tree | 6cfd8376c1d84b93793b062731ec9594487dc95e /src/vpp | |
parent | 6f666ad99ae1e384aa851af5e0feed3d2a25e709 (diff) |
API: Use string type instead of u8.
The new string type is modelled after string in proto3.
It is always variable length.
Change-Id: I64884067e28a80072c8dac31b7c7c82d6e306051
Signed-off-by: Ole Troan <ot@cisco.com>
Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp')
-rw-r--r-- | src/vpp/api/api.c | 39 | ||||
-rw-r--r-- | src/vpp/api/custom_dump.c | 4 | ||||
-rw-r--r-- | src/vpp/api/types.h | 3 | ||||
-rw-r--r-- | src/vpp/api/vpe.api | 14 |
4 files changed, 38 insertions, 22 deletions
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index cf5d252e347..1f376dcc64f 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -217,16 +217,25 @@ vl_api_cli_inband_t_handler (vl_api_cli_inband_t * mp) vlib_main_t *vm = vlib_get_main (); unformat_input_t input; u8 *out_vec = 0; + u32 len = 0; - unformat_init_string (&input, (char *) mp->cmd, ntohl (mp->length)); + if (vl_msg_api_get_msg_length (mp) < vl_api_string_len (&mp->cmd)) + { + rv = -1; + goto error; + } + + unformat_init_string (&input, (char *) vl_api_from_api_string (&mp->cmd), + vl_api_string_len (&mp->cmd)); vlib_cli_input (vm, &input, inband_cli_output, (uword) & out_vec); - u32 len = vec_len (out_vec); + len = vec_len (out_vec); + +error: /* *INDENT-OFF* */ REPLY_MACRO3(VL_API_CLI_INBAND_REPLY, len, ({ - rmp->length = htonl (len); - clib_memcpy (rmp->reply, out_vec, len); + vl_api_to_api_string(len, (const char *)out_vec, &rmp->reply); })); /* *INDENT-ON* */ vec_free (out_vec); @@ -241,16 +250,22 @@ vl_api_show_version_t_handler (vl_api_show_version_t * mp) char *vpe_api_get_version (void); char *vpe_api_get_build_date (void); + u32 program_len = strnlen_s ("vpe", 32) + 1; + u32 version_len = strnlen_s (vpe_api_get_version (), 32) + 1; + u32 build_date_len = strnlen_s (vpe_api_get_build_date (), 32) + 1; + u32 build_directory_len = + strnlen_s (vpe_api_get_build_directory (), 256) + 1; + + u32 n = program_len + version_len + build_date_len + build_directory_len; + /* *INDENT-OFF* */ - REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY, + REPLY_MACRO3(VL_API_SHOW_VERSION_REPLY, n, ({ - strncpy ((char *) rmp->program, "vpe", ARRAY_LEN(rmp->program)-1); - strncpy ((char *) rmp->build_directory, vpe_api_get_build_directory(), - ARRAY_LEN(rmp->build_directory)-1); - strncpy ((char *) rmp->version, vpe_api_get_version(), - ARRAY_LEN(rmp->version)-1); - strncpy ((char *) rmp->build_date, vpe_api_get_build_date(), - ARRAY_LEN(rmp->build_date)-1); + char *p = (char *)&rmp->program; + p += vl_api_to_api_string(program_len, "vpe", (vl_api_string_t *)p); + p += vl_api_to_api_string(version_len, vpe_api_get_version(), (vl_api_string_t *)p); + p += vl_api_to_api_string(build_date_len, vpe_api_get_build_date(), (vl_api_string_t *)p); + vl_api_to_api_string(build_directory_len, vpe_api_get_build_directory(), (vl_api_string_t *)p); })); /* *INDENT-ON* */ } diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index 41a24ef5a34..78d37044955 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -2109,10 +2109,10 @@ static void *vl_api_cli_inband_t_print { u8 *s; u8 *cmd = 0; - u32 length = ntohl (mp->length); + u32 length = vl_api_string_len (&mp->cmd); vec_validate (cmd, length); - clib_memcpy (cmd, mp->cmd, length); + clib_memcpy (cmd, vl_api_from_api_string (&mp->cmd), length); s = format (0, "SCRIPT: exec %v ", cmd); diff --git a/src/vpp/api/types.h b/src/vpp/api/types.h index 252caa2d626..9a45639d030 100644 --- a/src/vpp/api/types.h +++ b/src/vpp/api/types.h @@ -16,6 +16,9 @@ #ifndef __API_TYPES_H__ #define __API_TYPES_H__ +#include <vlibapi/api_common.h> +#include <vlibapi/api_types.h> + #define vl_typedefs /* define message structures */ #include <vpp/api/vpe_all_api_h.h> #undef vl_typedefs diff --git a/src/vpp/api/vpe.api b/src/vpp/api/vpe.api index 488af1727bc..24d44bd31e7 100644 --- a/src/vpp/api/vpe.api +++ b/src/vpp/api/vpe.api @@ -93,8 +93,7 @@ define cli_inband { u32 client_index; u32 context; - u32 length; - u8 cmd[length]; + string cmd; }; /** \brief vpe parser cli string response @@ -112,8 +111,7 @@ define cli_inband_reply { u32 context; i32 retval; - u32 length; - u8 reply[length]; + string reply; }; /** \brief Get node index using name request @@ -187,10 +185,10 @@ define show_version_reply { u32 context; i32 retval; - u8 program[32]; - u8 version[32]; - u8 build_date[32]; - u8 build_directory[256]; + string program; + string version; + string build_date; + string build_directory; }; |