CSIT-844: fix binary api rx pthread heap push/pop
[vpp.git] / src / vlibmemory / memory_vlib.c
index 2242abc..338fda4 100644 (file)
@@ -188,7 +188,6 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
   int rv = 0;
   void *oldheap;
   api_main_t *am = &api_main;
-  u8 *serialized_message_table_in_shmem;
 
   /*
    * This is tortured. Maintain a vlib-address-space private
@@ -237,7 +236,9 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
   regp->name = format (0, "%s", mp->name);
   vec_add1 (regp->name, 0);
 
-  serialized_message_table_in_shmem = vl_api_serialize_message_table (am, 0);
+  if (am->serialized_message_table_in_shmem == 0)
+    am->serialized_message_table_in_shmem =
+      vl_api_serialize_message_table (am, 0);
 
   pthread_mutex_unlock (&svm->mutex);
   svm_pop_heap (oldheap);
@@ -250,7 +251,8 @@ vl_api_memclnt_create_t_handler (vl_api_memclnt_create_t * mp)
      am->shmem_hdr->application_restarts);
   rp->context = mp->context;
   rp->response = ntohl (rv);
-  rp->message_table = pointer_to_uword (serialized_message_table_in_shmem);
+  rp->message_table =
+    pointer_to_uword (am->serialized_message_table_in_shmem);
 
   vl_msg_api_send_shmem (q, (u8 *) & rp);
 }
@@ -470,12 +472,48 @@ vl_api_memclnt_keepalive_t_handler (vl_api_memclnt_keepalive_t * mp)
   vl_msg_api_send_shmem (shmem_hdr->vl_input_queue, (u8 *) & rmp);
 }
 
+void
+vl_api_api_versions_t_handler (vl_api_api_versions_t * mp)
+{
+  api_main_t *am = &api_main;
+  vl_api_api_versions_reply_t *rmp;
+  unix_shared_memory_queue_t *q;
+  u32 nmsg = vec_len (am->api_version_list);
+  int msg_size = sizeof (*rmp) + sizeof (rmp->api_versions[0]) * nmsg;
+  int i;
+
+  q = vl_api_client_index_to_input_queue (mp->client_index);
+  if (q == 0)
+    return;
+
+  rmp = vl_msg_api_alloc (msg_size);
+  memset (rmp, 0, msg_size);
+  rmp->_vl_msg_id = ntohs (VL_API_API_VERSIONS_REPLY);
+
+  /* fill in the message */
+  rmp->context = mp->context;
+  rmp->count = htonl (nmsg);
+
+  for (i = 0; i < nmsg; ++i)
+    {
+      api_version_t *vl = &am->api_version_list[i];
+      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, 64 - 1);
+    }
+
+  vl_msg_api_send_shmem (q, (u8 *) & rmp);
+
+}
+
 #define foreach_vlib_api_msg                            \
 _(MEMCLNT_CREATE, memclnt_create)                       \
 _(MEMCLNT_DELETE, memclnt_delete)                       \
 _(GET_FIRST_MSG_ID, get_first_msg_id)                   \
 _(MEMCLNT_KEEPALIVE, memclnt_keepalive)                 \
-_(MEMCLNT_KEEPALIVE_REPLY, memclnt_keepalive_reply)
+_(MEMCLNT_KEEPALIVE_REPLY, memclnt_keepalive_reply)    \
+_(API_VERSIONS, api_versions)
 
 /*
  * vl_api_init