From 59b2565cd91a67ced650739f36129650830211ac Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Sun, 10 Sep 2017 15:04:27 -0400 Subject: Repair vlib API socket server - Teach vpp_api_test to send/receive API messages over sockets - Add memfd-based shared memory - Add api messages to create memfd-based shared memory segments - vpp_api_test supports both socket and shared memory segment connections - vpp_api_test pivot from socket to shared memory API messaging - add socket client support to libvlibclient.so - dead client reaper sends ping messages, container-friendly - dead client reaper falls back to kill (, 0) live checking if e.g. a python app goes silent for tens of seconds - handle ping messages in python client support code - teach show api ring about pairwise shared-memory segments - fix ip probing of already resolved destinations (VPP-998) We'll need this work to implement proper host-stack client isolation Change-Id: Ic23b65f75c854d0393d9a2e9d6b122a9551be769 Signed-off-by: Dave Barach Signed-off-by: Dave Wallace Signed-off-by: Florin Coras --- src/vpp-api/client/client.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/vpp-api/client') diff --git a/src/vpp-api/client/client.c b/src/vpp-api/client/client.c index 8bdcda01c4d..668461aad6c 100644 --- a/src/vpp-api/client/client.c +++ b/src/vpp-api/client/client.c @@ -133,8 +133,11 @@ static void * vac_rx_thread_fn (void *arg) { unix_shared_memory_queue_t *q; + vl_api_memclnt_keepalive_t *mp; + vl_api_memclnt_keepalive_reply_t *rmp; vac_main_t *pm = &vac_main; api_main_t *am = &api_main; + vl_shmem_hdr_t *shmem_hdr; uword msg; q = am->vl_input_queue; @@ -169,6 +172,17 @@ vac_rx_thread_fn (void *arg) vl_msg_api_free((void *) msg); break; + case VL_API_MEMCLNT_KEEPALIVE: + mp = (void *)msg; + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY); + rmp->context = mp->context; + shmem_hdr = am->shmem_hdr; + vl_msg_api_send_shmem(shmem_hdr->vl_input_queue, (u8 *)&rmp); + vl_msg_api_free((void *) msg); + break; + default: vac_api_handler((void *)msg); } @@ -370,8 +384,12 @@ vac_read (char **p, int *l, u16 timeout) unix_shared_memory_queue_t *q; api_main_t *am = &api_main; vac_main_t *pm = &vac_main; + vl_api_memclnt_keepalive_t *mp; + vl_api_memclnt_keepalive_reply_t *rmp; uword msg; msgbuf_t *msgbuf; + int rv; + vl_shmem_hdr_t *shmem_hdr; if (!pm->connected_to_vlib) return -1; @@ -384,7 +402,9 @@ vac_read (char **p, int *l, u16 timeout) set_timeout(timeout); q = am->vl_input_queue; - int rv = unix_shared_memory_queue_sub(q, (u8 *)&msg, 0); + + again: + rv = unix_shared_memory_queue_sub(q, (u8 *)&msg, 0); if (rv == 0) { u16 msg_id = ntohs(*((u16 *)msg)); switch (msg_id) { @@ -397,6 +417,21 @@ vac_read (char **p, int *l, u16 timeout) case VL_API_MEMCLNT_READ_TIMEOUT: printf("Received read timeout %ds\n", timeout); goto error; + case VL_API_MEMCLNT_KEEPALIVE: + /* Handle an alive-check ping from vpp. */ + mp = (void *)msg; + rmp = vl_msg_api_alloc (sizeof (*rmp)); + memset (rmp, 0, sizeof (*rmp)); + rmp->_vl_msg_id = ntohs(VL_API_MEMCLNT_KEEPALIVE_REPLY); + rmp->context = mp->context; + shmem_hdr = am->shmem_hdr; + vl_msg_api_send_shmem(shmem_hdr->vl_input_queue, (u8 *)&rmp); + vl_msg_api_free((void *) msg); + /* + * Python code is blissfully unaware of these pings, so + * act as if it never happened... + */ + goto again; default: msgbuf = (msgbuf_t *)(((u8 *)msg) - offsetof(msgbuf_t, data)); -- cgit 1.2.3-korg