aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp/api/api_main.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-09-10 15:04:27 -0400
committerDamjan Marion <dmarion.lists@gmail.com>2017-10-03 11:03:47 +0000
commit59b2565cd91a67ced650739f36129650830211ac (patch)
tree1ae3b8d69d7952500b07186169fb31e0f72ae04e /src/vpp/api/api_main.c
parent35ffa3e8f6b032f6e324234d495f769049d8feea (diff)
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 (<pid>, 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 <dave@barachs.net> Signed-off-by: Dave Wallace <dwallacelf@gmail.com> Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vpp/api/api_main.c')
-rw-r--r--src/vpp/api/api_main.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/vpp/api/api_main.c b/src/vpp/api/api_main.c
index c355a5fdff0..129334830d7 100644
--- a/src/vpp/api/api_main.c
+++ b/src/vpp/api/api_main.c
@@ -49,10 +49,13 @@ api_main_init (vlib_main_t * vm)
vam->my_client_index = (u32) ~ 0;
/* Ensure that vam->inbuf is never NULL */
vec_validate (vam->inbuf, 0);
+ vec_validate (vam->cmd_reply, 0);
+ vec_reset_length (vam->cmd_reply);
init_error_string_table (vam);
rv = vat_plugin_init (vam);
if (rv)
clib_warning ("vat_plugin_init returned %d", rv);
+
return 0;
}
@@ -68,6 +71,47 @@ vat_plugin_hash_create (void)
vam->help_by_name = hash_create_string (0, sizeof (uword));
}
+static void
+maybe_register_api_client (vat_main_t * vam)
+{
+ vl_api_registration_t **regpp;
+ vl_api_registration_t *regp;
+ svm_region_t *svm;
+ void *oldheap;
+ api_main_t *am = &api_main;
+
+ if (vam->my_client_index != ~0)
+ return;
+
+ pool_get (am->vl_clients, regpp);
+
+ svm = am->vlib_rp;
+
+ pthread_mutex_lock (&svm->mutex);
+ oldheap = svm_push_data_heap (svm);
+ *regpp = clib_mem_alloc (sizeof (vl_api_registration_t));
+
+ regp = *regpp;
+ memset (regp, 0, sizeof (*regp));
+ regp->registration_type = REGISTRATION_TYPE_SHMEM;
+ regp->vl_api_registration_pool_index = regpp - am->vl_clients;
+ regp->vlib_rp = svm;
+ regp->shmem_hdr = am->shmem_hdr;
+
+ /* Loopback connection */
+ regp->vl_input_queue = am->shmem_hdr->vl_input_queue;
+
+ regp->name = format (0, "%s", "vpp-internal");
+ vec_add1 (regp->name, 0);
+
+ pthread_mutex_unlock (&svm->mutex);
+ svm_pop_heap (oldheap);
+
+ vam->my_client_index = vl_msg_api_handle_from_index_and_epoch
+ (regp->vl_api_registration_pool_index,
+ am->shmem_hdr->application_restarts);
+}
+
static clib_error_t *
api_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -82,6 +126,8 @@ api_command_fn (vlib_main_t * vm,
int (*fp) (vat_main_t *);
api_main_t *am = &api_main;
+ maybe_register_api_client (vam);
+
vam->vl_input_queue = am->shmem_hdr->vl_input_queue;
/* vec_validated in the init routine */