aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/interface_api.c
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-08-23 22:55:18 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-09-03 20:04:13 +0000
commite5ff5a36dd126ee57dca4e0b03da2f7704e0a4f5 (patch)
tree2108baa60e8a697624288fe2c3050be29697bc88 /src/vnet/interface_api.c
parentb6fde4a8bae474c6b73d08d223028f42e396d452 (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/vnet/interface_api.c')
-rw-r--r--src/vnet/interface_api.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c
index 9a695ed5bdd..3448c6037b7 100644
--- a/src/vnet/interface_api.c
+++ b/src/vnet/interface_api.c
@@ -200,14 +200,8 @@ send_sw_interface_details (vpe_api_main_t * am,
vnet_hw_interface_t *hi =
vnet_get_sup_hw_interface (am->vnet_main, swif->sw_if_index);
- uint32_t if_name_len = strlen ((char *) interface_name);
- u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index);
- uint32_t tag_len = 0;
- if (tag != NULL)
- tag_len = strlen ((char *) tag);
- vl_api_sw_interface_details_t *mp =
- vl_msg_api_alloc (sizeof (*mp) + if_name_len + tag_len);
- clib_memset (mp, 0, sizeof (*mp) + if_name_len + tag_len);
+ vl_api_sw_interface_details_t *mp = vl_msg_api_alloc (sizeof (*mp));
+ clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_SW_INTERFACE_DETAILS);
mp->sw_if_index = ntohl (swif->sw_if_index);
mp->sup_sw_if_index = ntohl (swif->sup_sw_if_index);
@@ -245,6 +239,9 @@ send_sw_interface_details (vpe_api_main_t * am,
mp->context = context;
+ strncpy ((char *) mp->interface_name,
+ (char *) interface_name, ARRAY_LEN (mp->interface_name) - 1);
+
/* Send the L2 address for ethernet physical intfcs */
if (swif->sup_sw_if_index == swif->sw_if_index
&& hi->hw_class_index == ethernet_hw_interface_class.index)
@@ -306,12 +303,9 @@ send_sw_interface_details (vpe_api_main_t * am,
mp->i_sid = i_sid;
}
- char *p = (char *) &mp->interface_name;
- p +=
- vl_api_to_api_string (if_name_len, (char *) interface_name,
- (vl_api_string_t *) p);
- if (tag != NULL)
- vl_api_to_api_string (tag_len, (char *) tag, (vl_api_string_t *) p);
+ u8 *tag = vnet_get_sw_interface_tag (vnet_get_main (), swif->sw_if_index);
+ if (tag)
+ strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
vl_api_send_msg (rp, (u8 *) mp);
}
@@ -356,7 +350,8 @@ vl_api_sw_interface_dump_t_handler (vl_api_sw_interface_dump_t * mp)
if (mp->name_filter_valid)
{
filter =
- format (0, "%s%c", vl_api_from_api_string (&mp->name_filter), 0);
+ format (0, ".*%s", vl_api_string_len (&mp->name_filter),
+ vl_api_from_api_string (&mp->name_filter), 0);
}
char *strcasestr (char *, char *); /* lnx hdr file botch */
@@ -884,13 +879,14 @@ static void vl_api_sw_interface_tag_add_del_t_handler
if (mp->is_add)
{
- if (vl_api_from_api_string (&mp->tag)[0] == 0)
+ if (mp->tag[0] == 0)
{
rv = VNET_API_ERROR_INVALID_VALUE;
goto out;
}
- tag = format (0, "%s%c", vl_api_from_api_string (&mp->tag), 0);
+ mp->tag[ARRAY_LEN (mp->tag) - 1] = 0;
+ tag = format (0, "%s%c", mp->tag, 0);
vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
}
else