memif: fix max number of rings
[vpp.git] / extras / libmemif / src / socket.c
index 8f18d89..3982c96 100644 (file)
@@ -107,12 +107,12 @@ memif_msg_send_hello (int fd)
   msg.type = MEMIF_MSG_TYPE_HELLO;
   h->min_version = MEMIF_VERSION;
   h->max_version = MEMIF_VERSION;
-  h->max_s2m_ring = MEMIF_MAX_M2S_RING;
+  h->max_s2m_ring = MEMIF_MAX_S2M_RING;
   h->max_m2s_ring = MEMIF_MAX_M2S_RING;
   h->max_region = MEMIF_MAX_REGION;
   h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
 
-  strncpy ((char *) h->name, lm->app_name, strlen (lm->app_name));
+  strncpy ((char *) h->name, (char *) lm->app_name, strlen ((char *) lm->app_name));
 
   /* msg hello is not enqueued but sent directly,
      because it is the first msg to be sent */
@@ -141,7 +141,7 @@ memif_msg_enq_init (memif_connection_t * c)
 
   strncpy ((char *) i->name, (char *) lm->app_name,
           strlen ((char *) lm->app_name));
-  if (c->args.secret)
+  if (strlen((char *) c->args.secret) > 0)
     strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
 
   e->next = NULL;
@@ -227,6 +227,7 @@ memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
   ar->region = mq->region;
   ar->log2_ring_size = mq->log2_ring_size;
   ar->flags = (dir == MEMIF_RING_S2M) ? MEMIF_MSG_ADD_RING_FLAG_S2M : 0;
+  ar->private_hdr_size = 0;
 
   e->next = NULL;
   if (c->msg_queue == NULL)
@@ -423,10 +424,10 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
   strncpy ((char *) c->remote_name, (char *) i->name,
           strlen ((char *) i->name));
 
-  if (c->args.secret)
+  if (strlen((char *) c->args.secret) > 0)
     {
       int r;
-      if (i->secret)
+      if (strlen((char *) i->secret) > 0)
        {
          if (strlen ((char *) c->args.secret) != strlen ((char *) i->secret))
            {
@@ -516,6 +517,9 @@ memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
   if (fd < 0)
     return MEMIF_ERR_NO_INTFD;
 
+  if (ar->private_hdr_size != 0)
+    return MEMIF_ERR_PRIVHDR;
+
   if (ar->flags & MEMIF_MSG_ADD_RING_FLAG_S2M)
     {
       if (ar->index > MEMIF_MAX_S2M_RING)
@@ -526,7 +530,7 @@ memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
       mq =
        (memif_queue_t *) realloc (c->rx_queues,
                                   sizeof (memif_queue_t) * (ar->index + 1));
-      memset (mq, 0, sizeof (memif_queue_t) * (ar->index + 1));
+      memset (mq + ar->index, 0, sizeof (memif_queue_t));
       if (mq == NULL)
        return memif_syscall_error_handler (errno);
       c->rx_queues = mq;
@@ -546,7 +550,7 @@ memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
       mq =
        (memif_queue_t *) realloc (c->tx_queues,
                                   sizeof (memif_queue_t) * (ar->index + 1));
-      memset (mq, 0, sizeof (memif_queue_t) * (ar->index + 1));
+      memset (mq + ar->index, 0, sizeof (memif_queue_t));
       if (mq == NULL)
        return memif_syscall_error_handler (errno);
       c->tx_queues = mq;
@@ -586,9 +590,6 @@ memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
          add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
 
          lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
-
-         /* refill ring buffers */
-         memif_refill_queue ((void *) c, i, -1);
        }
 
     }
@@ -619,9 +620,6 @@ memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
       for (i = 0; i < c->run_args.num_s2m_rings; i++)
        {
          lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
-
-         /* refill ring buffers */
-         memif_refill_queue ((void *) c, i, -1);
        }
     }