vcl: fix free segments assert
[vpp.git] / src / vcl / vppcom.c
index ddd5e0b..86a0c64 100644 (file)
@@ -455,9 +455,9 @@ vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp,
       goto error;
     }
 
-  if (vcl_segment_attach_session (mp->segment_handle, mp->server_rx_fifo,
-                                 mp->server_tx_fifo,
-                                 mp->vpp_event_queue_address, 0, session))
+  if (vcl_segment_attach_session (
+       mp->segment_handle, mp->server_rx_fifo, mp->server_tx_fifo,
+       mp->vpp_event_queue_address, mp->mq_index, 0, session))
     {
       VDBG (0, "failed to attach fifos for %u", session->session_index);
       goto error;
@@ -525,9 +525,9 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
 
   session->vpp_handle = mp->handle;
 
-  if (vcl_segment_attach_session (mp->segment_handle, mp->server_rx_fifo,
-                                 mp->server_tx_fifo,
-                                 mp->vpp_event_queue_address, 0, session))
+  if (vcl_segment_attach_session (
+       mp->segment_handle, mp->server_rx_fifo, mp->server_tx_fifo,
+       mp->vpp_event_queue_address, mp->mq_index, 0, session))
     {
       VDBG (0, "failed to attach fifos for %u", session->session_index);
       session->session_state = VCL_STATE_DETACHED;
@@ -538,7 +538,8 @@ vcl_session_connected_handler (vcl_worker_t * wrk,
   if (mp->ct_rx_fifo)
     {
       if (vcl_segment_attach_session (mp->ct_segment_handle, mp->ct_rx_fifo,
-                                     mp->ct_tx_fifo, (uword) ~0, 1, session))
+                                     mp->ct_tx_fifo, (uword) ~0, ~0, 1,
+                                     session))
        {
          VDBG (0, "failed to attach ct fifos for %u", session->session_index);
          session->session_state = VCL_STATE_DETACHED;
@@ -654,7 +655,8 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp)
   if (vcl_session_is_cl (session))
     {
       if (vcl_segment_attach_session (mp->segment_handle, mp->rx_fifo,
-                                     mp->tx_fifo, mp->vpp_evt_q, 0, session))
+                                     mp->tx_fifo, mp->vpp_evt_q, mp->mq_index,
+                                     0, session))
        {
          VDBG (0, "failed to attach fifos for %u", session->session_index);
          session->session_state = VCL_STATE_DETACHED;
@@ -984,7 +986,7 @@ vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data)
   if (s->rx_fifo)
     {
       if (vcl_segment_attach_session (msg->segment_handle, msg->rx_fifo,
-                                     msg->tx_fifo, (uword) ~0, 0, s))
+                                     msg->tx_fifo, (uword) ~0, ~0, 0, s))
        {
          VDBG (0, "failed to attach fifos for %u", s->session_index);
          return;
@@ -1988,7 +1990,7 @@ vppcom_session_read_internal (uint32_t session_handle, void *buf, int n,
   u8 is_ct;
 
   if (PREDICT_FALSE (!buf))
-    return VPPCOM_EINVAL;
+    return VPPCOM_EFAULT;
 
   s = vcl_session_get_w_handle (wrk, session_handle);
   if (PREDICT_FALSE (!s || (s->flags & VCL_SESSION_F_IS_VEP)))
@@ -2194,7 +2196,7 @@ vppcom_session_free_segments (uint32_t session_handle, uint32_t n_bytes)
   is_ct = vcl_session_is_ct (s);
   svm_fifo_dequeue_drop (is_ct ? s->ct_rx_fifo : s->rx_fifo, n_bytes);
 
-  ASSERT (s->rx_bytes_pending < n_bytes);
+  ASSERT (s->rx_bytes_pending >= n_bytes);
   s->rx_bytes_pending -= n_bytes;
 }
 
@@ -3014,8 +3016,9 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e,
        break;
       vcl_fifo_rx_evt_valid_or_break (s);
       session_events = s->vep.ev.events;
-      if (!(EPOLLIN & s->vep.ev.events)
-         || (s->flags & VCL_SESSION_F_HAS_RX_EVT))
+      if (!(EPOLLIN & s->vep.ev.events) ||
+         (s->flags & VCL_SESSION_F_HAS_RX_EVT) ||
+         (s->vep.lt_next != VCL_INVALID_SESSION_INDEX))
        break;
       add_event = 1;
       events[*num_ev].events = EPOLLIN;
@@ -4058,6 +4061,10 @@ vppcom_session_sendto (uint32_t session_handle, void *buffer,
       if (!vcl_session_is_cl (s))
        return VPPCOM_EINVAL;
 
+      s->transport.is_ip4 = ep->is_ip4;
+      s->transport.rmt_port = ep->port;
+      vcl_ip_copy_from_ep (&s->transport.rmt_ip, ep);
+
       /* Session not connected/bound in vpp. Create it by 'connecting' it */
       if (PREDICT_FALSE (s->session_state == VCL_STATE_CLOSED))
        {
@@ -4073,10 +4080,6 @@ vppcom_session_sendto (uint32_t session_handle, void *buffer,
            return rv;
          s = vcl_session_get (wrk, session_index);
        }
-
-      s->transport.is_ip4 = ep->is_ip4;
-      s->transport.rmt_port = ep->port;
-      vcl_ip_copy_from_ep (&s->transport.rmt_ip, ep);
     }
 
   if (flags)
@@ -4386,22 +4389,18 @@ int
 vppcom_add_cert_key_pair (vppcom_cert_key_pair_t *ckpair)
 {
   if (vcm->cfg.vpp_app_socket_api)
-    {
-      clib_warning ("not supported");
-      return VPPCOM_EINVAL;
-    }
-  return vcl_bapi_add_cert_key_pair (ckpair);
+    return vcl_sapi_add_cert_key_pair (ckpair);
+  else
+    return vcl_bapi_add_cert_key_pair (ckpair);
 }
 
 int
 vppcom_del_cert_key_pair (uint32_t ckpair_index)
 {
   if (vcm->cfg.vpp_app_socket_api)
-    {
-      clib_warning ("not supported");
-      return VPPCOM_EINVAL;
-    }
-  return vcl_bapi_del_cert_key_pair (ckpair_index);
+    return vcl_sapi_del_cert_key_pair (ckpair_index);
+  else
+    return vcl_bapi_del_cert_key_pair (ckpair_index);
 }
 
 /*