L2-fwd trace show the lookup result
[vpp.git] / extras / libmemif / src / socket.c
index a471e0b..b25b026 100644 (file)
@@ -107,12 +107,13 @@ 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 +142,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;
@@ -166,7 +167,6 @@ static_fn int
 memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
 {
   libmemif_main_t *lm = &libmemif_main;
-  /* maybe check if region is valid? */
   memif_region_t *mr = &c->regions[region_index];
 
   memif_msg_queue_elt_t *e =
@@ -424,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))
            {
@@ -484,6 +484,8 @@ static_fn int
 memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
                              int fd)
 {
+  libmemif_main_t *lm = &libmemif_main;
+
   memif_msg_add_region_t *ar = &msg->add_region;
   memif_region_t *mr;
   if (fd < 0)
@@ -493,14 +495,20 @@ memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
     return MEMIF_ERR_MAXREG;
 
   mr =
-    (memif_region_t *) realloc (c->regions,
-                               sizeof (memif_region_t) * (ar->index + 1));
+    (memif_region_t *) lm->realloc (c->regions,
+                                   sizeof (memif_region_t) *
+                                   (++c->regions_num));
   if (mr == NULL)
     return memif_syscall_error_handler (errno);
+  memset (mr + ar->index, 0, sizeof (memif_region_t));
   c->regions = mr;
   c->regions[ar->index].fd = fd;
   c->regions[ar->index].region_size = ar->size;
-  c->regions[ar->index].shm = NULL;
+  c->regions[ar->index].addr = NULL;
+
+  /* region 0 is never external */
+  if (lm->get_external_region_addr && (ar->index != 0))
+    c->regions[ar->index].is_external = 1;
 
   return MEMIF_ERR_SUCCESS;    /* 0 */
 }
@@ -510,6 +518,8 @@ memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
 static_fn int
 memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
 {
+  libmemif_main_t *lm = &libmemif_main;
+
   memif_msg_add_ring_t *ar = &msg->add_ring;
 
   memif_queue_t *mq;
@@ -528,9 +538,10 @@ memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
        return MEMIF_ERR_MAXRING;
 
       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));
+       (memif_queue_t *) lm->realloc (c->rx_queues,
+                                      sizeof (memif_queue_t) *
+                                      (++c->rx_queues_num));
+      memset (mq + ar->index, 0, sizeof (memif_queue_t));
       if (mq == NULL)
        return memif_syscall_error_handler (errno);
       c->rx_queues = mq;
@@ -548,9 +559,10 @@ memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
        return MEMIF_ERR_MAXRING;
 
       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));
+       (memif_queue_t *) lm->realloc (c->tx_queues,
+                                      sizeof (memif_queue_t) *
+                                      (++c->tx_queues_num));
+      memset (mq + ar->index, 0, sizeof (memif_queue_t));
       if (mq == NULL)
        return memif_syscall_error_handler (errno);
       c->tx_queues = mq;
@@ -590,9 +602,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);
        }
 
     }
@@ -623,9 +632,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);
        }
     }
 
@@ -724,8 +730,11 @@ memif_msg_receive (int ifd)
        return err;
       if ((err = memif_msg_enq_init (c)) != MEMIF_ERR_SUCCESS)
        return err;
-      if ((err = memif_msg_enq_add_region (c, 0)) != MEMIF_ERR_SUCCESS)
-       return err;
+      for (i = 0; i < c->regions_num; i++)
+       {
+         if ((err = memif_msg_enq_add_region (c, i)) != MEMIF_ERR_SUCCESS)
+           return err;
+       }
       for (i = 0; i < c->run_args.num_s2m_rings; i++)
        {
          if ((err =