VCL-LDPRELOAD: Fix Coverity Warning CID 178776
[vpp.git] / src / vcl / vppcom.c
index 092c219..2e3af1b 100644 (file)
@@ -132,6 +132,7 @@ typedef struct
 typedef struct vppcom_cfg_t_
 {
   u64 heapsize;
+  u32 vpp_api_q_length;
   u64 segment_baseva;
   u32 segment_size;
   u32 add_segment_size;
@@ -361,7 +362,8 @@ vppcom_connect_to_vpp (char *app_name)
 
   if (VPPCOM_DEBUG > 0)
     printf ("\nConnecting to VPP api...");
-  if (vl_client_connect_to_vlib ("/vpe-api", app_name, 32) < 0)
+  if (vl_client_connect_to_vlib ("/vpe-api", app_name,
+                                vcm->cfg.vpp_api_q_length) < 0)
     {
       clib_warning ("[%d] connect to vpp (%s) failed!", getpid (), app_name);
       return VPPCOM_ECONNREFUSED;
@@ -551,10 +553,13 @@ vppcom_app_send_attach (void)
   bmp->options[APP_OPTIONS_PROXY_TRANSPORT] =
     (vcm->cfg.app_proxy_transport_tcp ? 1 << TRANSPORT_PROTO_TCP : 0) |
     (vcm->cfg.app_proxy_transport_udp ? 1 << TRANSPORT_PROTO_UDP : 0);
-  bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
-  bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
-  bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
-  bmp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
+  bmp->options[APP_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
+  bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
+  bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
+  bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = vcm->cfg.tx_fifo_size;
+  bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] =
+    vcm->cfg.preallocated_fifo_pairs;
+  bmp->options[APP_OPTIONS_EVT_QUEUE_SIZE] = vcm->cfg.event_queue_size;
   if (nsid_len)
     {
       bmp->namespace_id_len = nsid_len;
@@ -1063,7 +1068,7 @@ format_ip46_address (u8 * s, va_list * args)
 }
 
 static inline void
-vppcom_send_accept_session_reply (u32 handle, u32 context, int retval)
+vppcom_send_accept_session_reply (u64 handle, u32 context, int retval)
 {
   vl_api_accept_session_reply_t *rmp;
 
@@ -1138,10 +1143,10 @@ vl_api_accept_session_t_handler (vl_api_accept_session_t * mp)
 
   if (VPPCOM_DEBUG > 1)
     clib_warning ("[%d] vpp handle 0x%llx, sid %u: client accept "
-                 "request from %s address %U port %d!", getpid (),
+                 "request from %s address %U port %d queue %p!", getpid (),
                  mp->handle, session_index, mp->is_ip4 ? "IPv4" : "IPv6",
                  format_ip46_address, &mp->ip, mp->is_ip4,
-                 clib_net_to_host_u16 (mp->port));
+                 clib_net_to_host_u16 (mp->port), session->vpp_event_queue);
 }
 
 static void
@@ -1449,6 +1454,7 @@ vppcom_cfg_init (vppcom_cfg_t * vcl_cfg)
   ASSERT (vcl_cfg);
 
   vcl_cfg->heapsize = (256ULL << 20);
+  vcl_cfg->vpp_api_q_length = 1024;
   vcl_cfg->segment_baseva = 0x200000000ULL;
   vcl_cfg->segment_size = (256 << 20);
   vcl_cfg->add_segment_size = (128 << 20);
@@ -1611,7 +1617,7 @@ vppcom_cfg_read (char *conf_fname)
   u8 vc_cfg_input = 0;
   u8 *chroot_path;
   struct stat s;
-  u32 uid, gid;
+  u32 uid, gid, q_len;
 
   fd = open (conf_fname, O_RDONLY);
   if (fd < 0)
@@ -1670,6 +1676,23 @@ vppcom_cfg_read (char *conf_fname)
                              getpid (), chroot_path);
              chroot_path = 0;  /* Don't vec_free() it! */
            }
+         else if (unformat (line_input, "vpp-api-q-length %d", &q_len))
+           {
+             if (q_len < vcl_cfg->vpp_api_q_length)
+               {
+                 clib_warning ("[%d] ERROR: configured vpp-api-q-length "
+                               "(%u) is too small! Using default: %u ",
+                               getpid (), q_len, vcl_cfg->vpp_api_q_length);
+               }
+             else
+               {
+                 vcl_cfg->vpp_api_q_length = q_len;
+
+                 if (VPPCOM_DEBUG > 0)
+                   clib_warning ("[%d] configured vpp-api-q-length %u",
+                                 getpid (), vcl_cfg->vpp_api_q_length);
+               }
+           }
          else if (unformat (line_input, "uid %d", &uid))
            {
              vl_set_memory_uid (uid);
@@ -2850,6 +2873,19 @@ vppcom_session_read_ready (session_t * session, u32 session_index)
        }
     }
   rv = ready;
+
+  if (vcm->app_event_queue->cursize &&
+      !pthread_mutex_trylock (&vcm->app_event_queue->mutex))
+    {
+      u32 i, n_to_dequeue = vcm->app_event_queue->cursize;
+      session_fifo_event_t e;
+
+      for (i = 0; i < n_to_dequeue; i++)
+       unix_shared_memory_queue_sub_raw (vcm->app_event_queue, (u8 *) & e);
+
+      pthread_mutex_unlock (&vcm->app_event_queue->mutex);
+    }
+
 done:
   return rv;
 }
@@ -3761,7 +3797,7 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
       break;
 
     case VPPCOM_ATTR_GET_PEER_ADDR:
-      if (buffer && buflen && (*buflen >= sizeof (*ep)))
+      if (buffer && buflen && (*buflen >= sizeof (*ep)) && ep->ip)
        {
          ep->vrf = session->vrf;
          ep->is_ip4 = session->peer_addr.is_ip4;
@@ -3785,7 +3821,7 @@ vppcom_session_attr (uint32_t session_index, uint32_t op,
       break;
 
     case VPPCOM_ATTR_GET_LCL_ADDR:
-      if (buffer && buflen && (*buflen >= sizeof (*ep)))
+      if (buffer && buflen && (*buflen >= sizeof (*ep)) && ep->ip)
        {
          ep->vrf = session->vrf;
          ep->is_ip4 = session->lcl_addr.is_ip4;