diff options
author | Ole Troan <ot@cisco.com> | 2019-08-23 22:55:18 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2019-09-03 20:04:13 +0000 |
commit | e5ff5a36dd126ee57dca4e0b03da2f7704e0a4f5 (patch) | |
tree | 2108baa60e8a697624288fe2c3050be29697bc88 /src/vnet | |
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/vnet')
-rw-r--r-- | src/vnet/interface.api | 10 | ||||
-rw-r--r-- | src/vnet/interface_api.c | 30 | ||||
-rw-r--r-- | src/vnet/ip/punt.api | 4 | ||||
-rw-r--r-- | src/vnet/session/session.api | 2 |
4 files changed, 21 insertions, 25 deletions
diff --git a/src/vnet/interface.api b/src/vnet/interface.api index 8a2d0797b5c..dff954438af 100644 --- a/src/vnet/interface.api +++ b/src/vnet/interface.api @@ -14,7 +14,7 @@ * limitations under the License. */ -option version = "3.0.0"; +option version = "3.1.0"; import "vnet/interface_types.api"; import "vnet/ethernet/ethernet_types.api"; @@ -185,8 +185,8 @@ define sw_interface_details u32 i_sid; /* Interface name */ - string interface_name; - string tag; + string interface_name[64]; + string tag[64]; }; /** \brief Request all or filtered subset of sw_interface_details @@ -204,7 +204,7 @@ define sw_interface_dump u32 context; vl_api_interface_index_t sw_if_index; bool name_filter_valid; - string name_filter; + string name_filter[]; }; /** \brief Set or delete one or all ip addresses on a specified interface @@ -307,7 +307,7 @@ autoreply define sw_interface_tag_add_del u32 context; bool is_add; vl_api_interface_index_t sw_if_index; - string tag; + string tag[64]; }; /** \brief Set an interface's MAC address 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 diff --git a/src/vnet/ip/punt.api b/src/vnet/ip/punt.api index 72efc7a9557..9890385fe5a 100644 --- a/src/vnet/ip/punt.api +++ b/src/vnet/ip/punt.api @@ -13,7 +13,7 @@ * limitations under the License. */ -option version = "2.1.0"; +option version = "2.2.0"; import "vnet/ip/ip_types.api"; /** \brief The types of packets to be punted @@ -134,7 +134,7 @@ autoreply define punt_socket_deregister { typedef punt_reason { u32 id; - string name; + string name[]; }; /** \brief Dump all or one of the excpetion punt reasons diff --git a/src/vnet/session/session.api b/src/vnet/session/session.api index 52e050d3978..6f208ff5b0e 100644 --- a/src/vnet/session/session.api +++ b/src/vnet/session/session.api @@ -320,9 +320,9 @@ autoreply define connect_sock { u8 ip[16]; u16 port; u8 proto; + u64 parent_handle; u8 hostname_len; u8 hostname[hostname_len]; - u64 parent_handle; }; /** \brief ask app to add a new cut-through registration |