aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/socket_api.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2018-10-02 18:29:25 -0700
committerDave Barach <openvpp@barachs.net>2018-10-03 16:42:38 +0000
commit2881dec8631629cf1fa415a1f63b8561590df275 (patch)
tree4a497a6c5547ec53fcee5884f298e5f8a4650fd7 /src/vlibmemory/socket_api.c
parent5bdd55831e65ffd7bb0122bf31a6c07ef8f5138a (diff)
sock api: fix registrations and client reads
- When clients connect, instead of returing registration indicies return handles. By convention socket registrations will have the MSB set to 1. This makes it easy to distinguish them from shm registrations. - Fix client reads to allow for messages larger than 4kB (needed for the creat reply wherein the message table is provided). Change-Id: I7bc0a072d066dffbf2e3ad9ba3ed50291231af9d Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vlibmemory/socket_api.c')
-rw-r--r--src/vlibmemory/socket_api.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index 4787069daa3..f3cd169d2c0 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -47,6 +47,27 @@
socket_main_t socket_main;
+#define SOCK_API_REG_HANDLE_BIT (1<<31)
+
+static u32
+sock_api_registration_handle (vl_api_registration_t * regp)
+{
+ ASSERT (regp->vl_api_registration_pool_index < SOCK_API_REG_HANDLE_BIT);
+ return regp->vl_api_registration_pool_index | SOCK_API_REG_HANDLE_BIT;
+}
+
+static u32
+socket_api_registration_handle_to_index (u32 reg_index)
+{
+ return (reg_index & ~SOCK_API_REG_HANDLE_BIT);
+}
+
+u8
+vl_socket_api_registration_handle_is_valid (u32 reg_handle)
+{
+ return ((reg_handle & SOCK_API_REG_HANDLE_BIT) != 0);
+}
+
void
vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am)
{
@@ -75,17 +96,18 @@ vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am)
}
vl_api_registration_t *
-vl_socket_api_client_index_to_registration (u32 index)
+vl_socket_api_client_handle_to_registration (u32 handle)
{
socket_main_t *sm = &socket_main;
- if (pool_is_free_index (sm->registration_pool, ntohl (index)))
+ u32 index = socket_api_registration_handle_to_index (handle);
+ if (pool_is_free_index (sm->registration_pool, index))
{
#if DEBUG > 2
- clib_warning ("Invalid index %d\n", ntohl (index));
+ clib_warning ("Invalid index %d\n", index);
#endif
return 0;
}
- return pool_elt_at_index (sm->registration_pool, ntohl (index));
+ return pool_elt_at_index (sm->registration_pool, index);
}
void
@@ -419,7 +441,7 @@ vl_api_sockclnt_create_t_handler (vl_api_sockclnt_create_t * mp)
u32 size = sizeof (*rp) + (nmsg * sizeof (vl_api_message_table_entry_t));
rp = vl_msg_api_alloc (size);
rp->_vl_msg_id = htons (VL_API_SOCKCLNT_CREATE_REPLY);
- rp->index = htonl (regp->vl_api_registration_pool_index);
+ rp->index = htonl (sock_api_registration_handle (regp));
rp->context = mp->context;
rp->response = htonl (rv);
rp->count = htons (nmsg);