aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlibmemory/socket_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vlibmemory/socket_api.c')
-rw-r--r--src/vlibmemory/socket_api.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index 60ca650d92f..26be8d09522 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -35,7 +35,6 @@
#undef vl_typedefs
/* instantiate all the print functions we know about */
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_printfun
@@ -45,6 +44,10 @@
#include <vlibmemory/vl_memory_api_h.h>
#undef vl_endianfun
+#define vl_calcsizefun
+#include <vlibmemory/vl_memory_api_h.h>
+#undef vl_calcsizefun
+
socket_main_t socket_main;
#define SOCK_API_REG_HANDLE_BIT (1<<31)
@@ -84,7 +87,6 @@ vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am)
vlib_cli_output (vm, "Socket clients");
vlib_cli_output (vm, "%20s %8s", "Name", "Fildesc");
- /* *INDENT-OFF* */
pool_foreach (reg, sm->registration_pool)
{
if (reg->registration_type == REGISTRATION_TYPE_SOCKET_SERVER) {
@@ -92,7 +94,6 @@ vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am)
vlib_cli_output (vm, "%20s %8d", reg->name, f->file_descriptor);
}
}
-/* *INDENT-ON* */
}
vl_api_registration_t *
@@ -128,7 +129,7 @@ vl_socket_api_send (vl_api_registration_t * rp, u8 * elem)
cf = vl_api_registration_file (rp);
ASSERT (rp->registration_type > REGISTRATION_TYPE_SHMEM);
- if (msg_id >= vec_len (am->api_trace_cfg))
+ if (msg_id >= vec_len (am->msg_data))
{
clib_warning ("id out of range: %d", msg_id);
vl_msg_api_free ((void *) elem);
@@ -179,7 +180,8 @@ vl_socket_free_registration_index (u32 pool_index)
}
rp = pool_elt_at_index (socket_main.registration_pool, pool_index);
- vl_api_call_reaper_functions (pool_index);
+ vl_api_call_reaper_functions (
+ clib_host_to_net_u32 (sock_api_registration_handle (rp)));
ASSERT (rp->registration_type != REGISTRATION_TYPE_FREE);
for (i = 0; i < vec_len (rp->additional_fds_to_close); i++)
@@ -200,7 +202,7 @@ vl_socket_process_api_msg (vl_api_registration_t * rp, i8 * input_v)
u8 *the_msg = (u8 *) (mbp->data);
socket_main.current_rp = rp;
- vl_msg_api_socket_handler (the_msg);
+ vl_msg_api_socket_handler (the_msg, ntohl (mbp->data_len));
socket_main.current_rp = 0;
}
@@ -216,6 +218,12 @@ static void
socket_cleanup_pending_remove_registration_cb (u32 *preg_index)
{
vl_api_registration_t *rp = vl_socket_get_registration (*preg_index);
+ if (!rp)
+ {
+ /* Might already have gone */
+ return;
+ }
+
clib_file_main_t *fm = &file_main;
u32 pending_remove_file_index = vl_api_registration_file_index (rp);
@@ -278,6 +286,10 @@ vl_socket_read_ready (clib_file_t * uf)
}
rp = vl_socket_get_registration (reg_index);
+ if (!rp)
+ {
+ return 0;
+ }
/* Ignore unprocessed_input for now, n describes input_buffer for now. */
n = read (uf->file_descriptor, socket_main.input_buffer,
@@ -398,7 +410,7 @@ vl_socket_write_ready (clib_file_t * uf)
while (remaining_bytes > 0)
{
bytes_to_send = remaining_bytes > 4096 ? 4096 : remaining_bytes;
- n = write (uf->file_descriptor, p, bytes_to_send);
+ n = send (uf->file_descriptor, p, bytes_to_send, MSG_NOSIGNAL);
if (n < 0)
{
if (errno == EAGAIN)
@@ -495,7 +507,13 @@ vl_api_sockclnt_create_t_handler (vl_api_sockclnt_create_t * mp)
regp = socket_main.current_rp;
- ASSERT (regp->registration_type == REGISTRATION_TYPE_SOCKET_SERVER);
+ /* client already connected through shared memory? */
+ if (!regp || regp->registration_type != REGISTRATION_TYPE_SOCKET_SERVER)
+ {
+ clib_warning (
+ "unsupported API call: already connected though shared memory?");
+ return;
+ }
regp->name = format (0, "%s%c", mp->name, 0);
@@ -507,7 +525,6 @@ vl_api_sockclnt_create_t_handler (vl_api_sockclnt_create_t * mp)
rp->response = htonl (rv);
rp->count = htons (nmsg);
- /* *INDENT-OFF* */
hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
({
rp->message_table[i].index = htons(hp->value[0]);
@@ -517,7 +534,6 @@ vl_api_sockclnt_create_t_handler (vl_api_sockclnt_create_t * mp)
64-1 /* chars to copy, without zero byte. */);
i++;
}));
- /* *INDENT-ON* */
vl_api_send_msg (regp, (u8 *) rp);
}
@@ -686,7 +702,7 @@ vl_api_sock_init_shm_t_handler (vl_api_sock_init_shm_t * mp)
/* delete the unused heap created in ssvm_server_init_memfd and mark it
* accessible again for ASAN */
clib_mem_destroy_heap (memfd->sh->heap);
- CLIB_MEM_UNPOISON ((void *) memfd->sh->ssvm_va, memfd->ssvm_size);
+ clib_mem_unpoison ((void *) memfd->sh->ssvm_va, memfd->ssvm_size);
/* Remember to close this fd when the socket connection goes away */
vec_add1 (regp->additional_fds_to_close, memfd->fd);
@@ -765,14 +781,15 @@ reply:
vl_sock_api_send_fd_msg (cf->file_descriptor, &memfd->fd, 1);
}
-#define foreach_vlib_api_msg \
- _(SOCKCLNT_CREATE, sockclnt_create, 1) \
- _(SOCKCLNT_DELETE, sockclnt_delete, 1) \
- _(SOCK_INIT_SHM, sock_init_shm, 1)
+#define foreach_vlib_api_msg \
+ _ (SOCKCLNT_CREATE, sockclnt_create, 0) \
+ _ (SOCKCLNT_DELETE, sockclnt_delete, 0) \
+ _ (SOCK_INIT_SHM, sock_init_shm, 0)
clib_error_t *
vl_sock_api_init (vlib_main_t * vm)
{
+ api_main_t *am = vlibapi_get_main ();
clib_file_main_t *fm = &file_main;
clib_file_t template = { 0 };
vl_api_registration_t *rp;
@@ -784,13 +801,20 @@ vl_sock_api_init (vlib_main_t * vm)
if (sm->socket_name == 0)
return 0;
-#define _(N,n,t) \
- vl_msg_api_set_handlers(VL_API_##N, #n, \
- vl_api_##n##_t_handler, \
- vl_noop_handler, \
- vl_api_##n##_t_endian, \
- vl_api_##n##_t_print, \
- sizeof(vl_api_##n##_t), t);
+#define _(N, n, t) \
+ vl_msg_api_config (&(vl_msg_api_msg_config_t){ \
+ .id = VL_API_##N, \
+ .name = #n, \
+ .handler = vl_api_##n##_t_handler, \
+ .endian = vl_api_##n##_t_endian, \
+ .format_fn = vl_api_##n##_t_format, \
+ .size = sizeof (vl_api_##n##_t), \
+ .traced = t, \
+ .tojson = vl_api_##n##_t_tojson, \
+ .fromjson = vl_api_##n##_t_fromjson, \
+ .calc_size = vl_api_##n##_t_calc_size, \
+ }); \
+ am->msg_data[VL_API_##N].replay_allowed = 0;
foreach_vlib_api_msg;
#undef _
@@ -827,13 +851,11 @@ socket_exit (vlib_main_t * vm)
if (sm->registration_pool)
{
u32 index;
- /* *INDENT-OFF* */
pool_foreach (rp, sm->registration_pool) {
vl_api_registration_del_file (rp);
index = rp->vl_api_registration_pool_index;
vl_socket_free_registration_index (index);
}
-/* *INDENT-ON* */
}
return 0;