aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-08-22 09:02:59 +0200
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-08-27 07:51:55 +0000
commit2959d42feb576c0e00c28c4e27658b25f6c783e9 (patch)
tree9b1e3474eb835b4fac2e3edfbcbda9a02a8cc730 /src/vlibmemory
parent3f1964d2d2847c5307694fe8daea0a7eef1e2733 (diff)
api: use string type for strings in memclnt.api
Explicitly using string type in API allows for autogenerating tools to print strings instead of hex-dumping byte strings. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I573962d6b34d5d10aab9dc6a5fdf101c9b12a6a6 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vlibmemory')
-rw-r--r--src/vlibmemory/memclnt.api10
-rw-r--r--src/vlibmemory/memory_api.c2
-rw-r--r--src/vlibmemory/memory_client.c9
-rw-r--r--src/vlibmemory/socket_api.c3
-rw-r--r--src/vlibmemory/socket_client.c4
-rw-r--r--src/vlibmemory/vlib_api.c35
6 files changed, 35 insertions, 28 deletions
diff --git a/src/vlibmemory/memclnt.api b/src/vlibmemory/memclnt.api
index 2f1e2daa4b6..5a7ef4f48ef 100644
--- a/src/vlibmemory/memclnt.api
+++ b/src/vlibmemory/memclnt.api
@@ -34,7 +34,7 @@ define memclnt_create {
u32 context; /* opaque value to be returned in the reply */
i32 ctx_quota; /* requested punt context quota */
u64 input_queue; /* client's queue */
- u8 name[64]; /* for show, find by name, whatever */
+ string name [limit=64]; /* for show, find by name, whatever */
u32 api_versions[8]; /* client-server pairs use as desired */
};
@@ -102,7 +102,7 @@ autoreply define rpc_call {
define get_first_msg_id {
u32 client_index;
u32 context;
- u8 name[64];
+ string name [limit=64];
};
define get_first_msg_id_reply {
@@ -118,7 +118,7 @@ typedef module_version {
u32 major;
u32 minor;
u32 patch;
- u8 name[64];
+ string name [limit=64];
};
define api_versions {
u32 client_index;
@@ -141,7 +141,7 @@ manual_print define trace_plugin_msg_ids
{
u32 client_index;
u32 context;
- u8 plugin_name[128];
+ string plugin_name [limit=128];
u16 first_msg_id;
u16 last_msg_id;
};
@@ -157,7 +157,7 @@ typedef message_table_entry
*/
define sockclnt_create {
u32 context; /* opaque value to be returned in the reply */
- u8 name[64]; /* for show, find by name, whatever */
+ string name [limit=64]; /* for show, find by name, whatever */
};
define sockclnt_create_reply {
diff --git a/src/vlibmemory/memory_api.c b/src/vlibmemory/memory_api.c
index b87aa76b2d0..0dcf0b001af 100644
--- a/src/vlibmemory/memory_api.c
+++ b/src/vlibmemory/memory_api.c
@@ -211,7 +211,7 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
q = regp->vl_input_queue = (svm_queue_t *) (uword) mp->input_queue;
- regp->name = format (0, "%s", mp->name);
+ regp->name = vl_api_from_api_to_vec (&mp->name);
vec_add1 (regp->name, 0);
if (am->serialized_message_table_in_shmem == 0)
diff --git a/src/vlibmemory/memory_client.c b/src/vlibmemory/memory_client.c
index f032ae77d19..3e1bdff777c 100644
--- a/src/vlibmemory/memory_client.c
+++ b/src/vlibmemory/memory_client.c
@@ -195,7 +195,7 @@ vl_client_connect (const char *name, int ctx_quota, int input_queue_size)
mp->_vl_msg_id = ntohs (VL_API_MEMCLNT_CREATE);
mp->ctx_quota = ctx_quota;
mp->input_queue = (uword) vl_input_queue;
- strncpy ((char *) mp->name, name, sizeof (mp->name) - 1);
+ vl_api_to_api_string (strnlen_s (name, 64), name, &mp->name);
vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & mp);
@@ -517,7 +517,8 @@ vl_client_get_first_plugin_msg_id (const char *plugin_name)
clib_time_t clib_time;
u16 rv = ~0;
- if (strlen (plugin_name) + 1 > sizeof (mp->name))
+ size_t plugin_name_len = strnlen_s (plugin_name, 128);
+ if (plugin_name_len == 128)
return (rv);
clib_memset (&clib_time, 0, sizeof (clib_time));
@@ -538,7 +539,7 @@ vl_client_get_first_plugin_msg_id (const char *plugin_name)
clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
mp->client_index = am->my_client_index;
- strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);
+ vl_api_to_api_string (plugin_name_len, plugin_name, &mp->name);
if (vl_socket_client_write () <= 0)
goto sock_err;
@@ -563,7 +564,7 @@ vl_client_get_first_plugin_msg_id (const char *plugin_name)
clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID);
mp->client_index = am->my_client_index;
- strncpy ((char *) mp->name, plugin_name, sizeof (mp->name) - 1);
+ vl_api_to_api_string (plugin_name_len, plugin_name, &mp->name);
vl_msg_api_send_shmem (am->shmem_hdr->vl_input_queue, (u8 *) & mp);
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index 868298ccc85..f9dd53364e4 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -436,7 +436,8 @@ vl_api_sockclnt_create_t_handler (vl_api_sockclnt_create_t * mp)
ASSERT (regp->registration_type == REGISTRATION_TYPE_SOCKET_SERVER);
- regp->name = format (0, "%s%c", mp->name, 0);
+ regp->name = vl_api_from_api_to_vec (&mp->name);
+ vec_add1 (regp->name, 0);
u32 size = sizeof (*rp) + (nmsg * sizeof (vl_api_message_table_entry_t));
rp = vl_msg_api_alloc_zero (size);
diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c
index 96330ce481a..fcd31992fa5 100644
--- a/src/vlibmemory/socket_client.c
+++ b/src/vlibmemory/socket_client.c
@@ -395,8 +395,8 @@ vl_socket_client_connect (char *socket_path, char *client_name,
mp = vl_socket_client_msg_alloc (sizeof (*mp));
mp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE);
- strncpy ((char *) mp->name, client_name, sizeof (mp->name) - 1);
- mp->name[sizeof (mp->name) - 1] = 0;
+
+ vl_api_to_api_string (strnlen_s (client_name, 64), client_name, &mp->name);
mp->context = 0xfeedface;
clib_time_init (&scm->clib_time);
diff --git a/src/vlibmemory/vlib_api.c b/src/vlibmemory/vlib_api.c
index e1a6bd18d55..7d7ed3e68aa 100644
--- a/src/vlibmemory/vlib_api.c
+++ b/src/vlibmemory/vlib_api.c
@@ -56,10 +56,12 @@ static inline void *
vl_api_trace_plugin_msg_ids_t_print (vl_api_trace_plugin_msg_ids_t * a,
void *handle)
{
- vl_print (handle, "vl_api_trace_plugin_msg_ids: %s first %u last %u\n",
- a->plugin_name,
+ u8 *plugin_name = vl_api_from_api_to_vec (&a->plugin_name);
+ vl_print (handle, "vl_api_trace_plugin_msg_ids: %v first %u last %u\n",
+ plugin_name,
clib_host_to_net_u16 (a->first_msg_id),
clib_host_to_net_u16 (a->last_msg_id));
+ vec_free (plugin_name);
return handle;
}
@@ -76,7 +78,6 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
uword *p;
api_main_t *am = &api_main;
vl_api_msg_range_t *rp;
- u8 name[64];
u16 first_msg_id = ~0;
int rv = -7; /* VNET_API_ERROR_INVALID_VALUE */
@@ -84,10 +85,11 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
if (!regp)
return;
+ u8 *name = vl_api_from_api_to_vec (&mp->name);
+
if (am->msg_range_by_name == 0)
goto out;
- strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name));
- name[ARRAY_LEN (name) - 1] = '\0';
+
p = hash_get_mem (am->msg_range_by_name, name);
if (p == 0)
goto out;
@@ -97,6 +99,7 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp)
rv = 0;
out:
+ vec_free (name);
rmp = vl_msg_api_alloc (sizeof (*rmp));
rmp->_vl_msg_id = ntohs (VL_API_GET_FIRST_MSG_ID_REPLY);
rmp->context = mp->context;
@@ -133,10 +136,8 @@ vl_api_api_versions_t_handler (vl_api_api_versions_t * mp)
rmp->api_versions[i].major = htonl (vl->major);
rmp->api_versions[i].minor = htonl (vl->minor);
rmp->api_versions[i].patch = htonl (vl->patch);
- strncpy ((char *) rmp->api_versions[i].name, vl->name,
- ARRAY_LEN (rmp->api_versions[i].name));
- rmp->api_versions[i].name[ARRAY_LEN (rmp->api_versions[i].name) - 1] =
- '\0';
+ vl_api_to_api_string (strnlen (vl->name, 64), vl->name,
+ &rmp->api_versions[i].name);
}
vl_api_send_msg (reg, (u8 *) rmp);
@@ -193,8 +194,8 @@ send_one_plugin_msg_ids_msg (u8 * name, u16 first_msg_id, u16 last_msg_id)
clib_memset (mp, 0, sizeof (*mp));
mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_TRACE_PLUGIN_MSG_IDS);
- strncpy ((char *) mp->plugin_name, (char *) name,
- sizeof (mp->plugin_name) - 1);
+ vl_api_to_api_string (strnlen_s ((char *) name, 64), (char *) name,
+ &mp->plugin_name);
mp->first_msg_id = clib_host_to_net_u16 (first_msg_id);
mp->last_msg_id = clib_host_to_net_u16 (last_msg_id);
@@ -625,11 +626,14 @@ vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
if (am->replay_in_progress == 0)
return;
- p = hash_get_mem (am->msg_range_by_name, mp->plugin_name);
+ u8 *plugin_name = vl_api_from_api_to_vec (&mp->plugin_name);
+ vec_add1 (plugin_name, 0);
+
+ p = hash_get_mem (am->msg_range_by_name, plugin_name);
if (p == 0)
{
clib_warning ("WARNING: traced plugin '%s' not in current image",
- mp->plugin_name);
+ plugin_name);
return;
}
@@ -637,16 +641,17 @@ vl_api_trace_plugin_msg_ids_t_handler (vl_api_trace_plugin_msg_ids_t * mp)
if (rp->first_msg_id != clib_net_to_host_u16 (mp->first_msg_id))
{
clib_warning ("WARNING: traced plugin '%s' first message id %d not %d",
- mp->plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
+ plugin_name, clib_net_to_host_u16 (mp->first_msg_id),
rp->first_msg_id);
}
if (rp->last_msg_id != clib_net_to_host_u16 (mp->last_msg_id))
{
clib_warning ("WARNING: traced plugin '%s' last message id %d not %d",
- mp->plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
+ plugin_name, clib_net_to_host_u16 (mp->last_msg_id),
rp->last_msg_id);
}
+ vec_free (plugin_name);
}
#define foreach_rpc_api_msg \