diff options
author | 2019-08-23 22:55:18 +0200 | |
---|---|---|
committer | 2019-09-03 20:04:13 +0000 | |
commit | e5ff5a36dd126ee57dca4e0b03da2f7704e0a4f5 (patch) | |
tree | 2108baa60e8a697624288fe2c3050be29697bc88 /src/vpp | |
parent | b6fde4a8bae474c6b73d08d223028f42e396d452 (diff) |
api: enforce vla is last and fixed string type
Enforce that variable length fields are the last element of API messages.
Add a 'fixed' version of string type, since dealing with
multiple variable length strings turned out too painful
for the C language bindings.
The string type is now:
{
string name[64]; // NUL terminated C-string. Essentially decays to u8 name[64]
string name[]; // Variable length string with embedded len field (vl_api_string_t)
};
The latter notation could be made available to other types as well.
e.g.
{
vl_api_address_t addresses[];
}
instead of
{
u32 n_addr;
vl_api_address_t addresses[n_addr];
};
Type: fix
Change-Id: I18fa17ef47227633752ab50453e8d20a652a9f9b
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp')
-rw-r--r-- | src/vpp/api/api.c | 28 | ||||
-rw-r--r-- | src/vpp/api/vpe.api | 18 |
2 files changed, 21 insertions, 25 deletions
diff --git a/src/vpp/api/api.c b/src/vpp/api/api.c index 801cf186904..989d867c06b 100644 --- a/src/vpp/api/api.c +++ b/src/vpp/api/api.c @@ -254,21 +254,16 @@ 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); - u32 version_len = strnlen_s (vpe_api_get_version (), 32); - u32 build_date_len = strnlen_s (vpe_api_get_build_date (), 32); - u32 build_directory_len = strnlen_s (vpe_api_get_build_directory (), 256); - - u32 n = program_len + version_len + build_date_len + build_directory_len; - /* *INDENT-OFF* */ - REPLY_MACRO3(VL_API_SHOW_VERSION_REPLY, n, + REPLY_MACRO2(VL_API_SHOW_VERSION_REPLY, ({ - 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); + 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); })); /* *INDENT-ON* */ } @@ -495,10 +490,11 @@ show_log_details (vl_api_registration_t * reg, u32 context, rmp->context = context; rmp->timestamp = clib_host_to_net_f64 (timestamp); rmp->level = htonl (*level); - char *p = (char *) &rmp->msg_class; - p += vl_api_vec_to_api_string (msg_class, (vl_api_string_t *) p); - p += vl_api_vec_to_api_string (message, (vl_api_string_t *) p); + strncpy ((char *) rmp->msg_class, (char *) msg_class, + ARRAY_LEN (rmp->msg_class) - 1); + strncpy ((char *) rmp->message, (char *) message, + ARRAY_LEN (rmp->message) - 1); vl_api_send_msg (reg, (u8 *) rmp); } diff --git a/src/vpp/api/vpe.api b/src/vpp/api/vpe.api index f03507ded4f..deab6a22593 100644 --- a/src/vpp/api/vpe.api +++ b/src/vpp/api/vpe.api @@ -19,7 +19,7 @@ called through a shared memory interface. */ -option version = "1.5.0"; +option version = "1.6.0"; import "vpp/api/vpe_types.api"; @@ -92,7 +92,7 @@ define cli_inband { u32 client_index; u32 context; - string cmd; + string cmd[]; }; /** \brief vpe parser cli string response @@ -110,7 +110,7 @@ define cli_inband_reply { u32 context; i32 retval; - string reply; + string reply[]; }; /** \brief Get node index using name request @@ -184,10 +184,10 @@ define show_version_reply { u32 context; i32 retval; - string program [limit = 32]; - string version [limit = 32]; - string build_date [limit = 32]; - string build_directory [limit = 256]; + string program[32]; + string version[32]; + string build_date[32]; + string build_directory[256]; }; @@ -295,8 +295,8 @@ define log_details { u32 context; vl_api_timestamp_t timestamp; vl_api_log_level_t level; - string msg_class [limit=32]; - string message [limit=256]; + string msg_class[32]; + string message[256]; }; /** \brief Show the current system timestamp. |