vcl: attr api to set endpt ext config
[vpp.git] / src / vcl / vppcom.c
index a0f4338..96a207b 100644 (file)
@@ -3001,56 +3001,50 @@ handle_dequeued:
 }
 
 static int
-vppcom_epoll_wait_condvar (vcl_worker_t * wrk, struct epoll_event *events,
-                          int maxevents, u32 n_evts, double wait_for_time)
+vppcom_epoll_wait_condvar (vcl_worker_t *wrk, struct epoll_event *events,
+                          int maxevents, u32 n_evts, double timeout_ms)
 {
-  double wait = 0, start = 0, now;
+  double end = -1;
 
   if (!n_evts)
     {
-      wait = wait_for_time;
-      start = clib_time_now (&wrk->clib_time);
+      if (timeout_ms > 0)
+       end = clib_time_now (&wrk->clib_time) + (timeout_ms / 1e3);
     }
 
   do
     {
       vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events, maxevents,
-                               wait, &n_evts);
-      if (n_evts)
+                               timeout_ms, &n_evts);
+      if (n_evts || !timeout_ms)
        return n_evts;
-      if (wait == -1)
-       continue;
-
-      now = clib_time_now (&wrk->clib_time);
-      wait -= (now - start) * 1e3;
-      start = now;
     }
-  while (wait > 0);
+  while (end == -1 || clib_time_now (&wrk->clib_time) < end);
 
   return 0;
 }
 
 static int
-vppcom_epoll_wait_eventfd (vcl_worker_t * wrk, struct epoll_event *events,
-                          int maxevents, u32 n_evts, double wait_for_time)
+vppcom_epoll_wait_eventfd (vcl_worker_t *wrk, struct epoll_event *events,
+                          int maxevents, u32 n_evts, double timeout_ms)
 {
-  double wait = 0, start = 0, now;
   int __clib_unused n_read;
   vcl_mq_evt_conn_t *mqc;
   int n_mq_evts, i;
+  double end = -1;
   u64 buf;
 
   vec_validate (wrk->mq_events, pool_elts (wrk->mq_evt_conns));
   if (!n_evts)
     {
-      wait = wait_for_time;
-      start = clib_time_now (&wrk->clib_time);
+      if (timeout_ms > 0)
+       end = clib_time_now (&wrk->clib_time) + (timeout_ms / 1e3);
     }
 
   do
     {
       n_mq_evts = epoll_wait (wrk->mqs_epfd, wrk->mq_events,
-                             vec_len (wrk->mq_events), wait);
+                             vec_len (wrk->mq_events), timeout_ms);
       if (n_mq_evts < 0)
        {
          VDBG (0, "epoll_wait error %u", errno);
@@ -3065,16 +3059,10 @@ vppcom_epoll_wait_eventfd (vcl_worker_t * wrk, struct epoll_event *events,
                                    &n_evts);
        }
 
-      if (n_evts)
+      if (n_evts || !timeout_ms)
        return n_evts;
-      if (wait == -1)
-       continue;
-
-      now = clib_time_now (&wrk->clib_time);
-      wait -= (now - start) * 1e3;
-      start = now;
     }
-  while (wait > 0);
+  while (end == -1 || clib_time_now (&wrk->clib_time) < end);
 
   return 0;
 }
@@ -3709,7 +3697,8 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
        }
       if (!session->ext_config)
        {
-         vcl_session_alloc_ext_cfg (session, TRANSPORT_ENDPT_EXT_CFG_CRYPTO);
+         vcl_session_alloc_ext_cfg (session, TRANSPORT_ENDPT_EXT_CFG_CRYPTO,
+                                    sizeof (transport_endpt_ext_cfg_t));
        }
       else if (session->ext_config->type != TRANSPORT_ENDPT_EXT_CFG_CRYPTO)
        {
@@ -3756,6 +3745,23 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op,
            *buflen);
       break;
 
+    case VPPCOM_ATTR_SET_ENDPT_EXT_CFG:
+      if (!(buffer && buflen && (*buflen > 0)))
+       {
+         rv = VPPCOM_EINVAL;
+         break;
+       }
+      if (session->ext_config)
+       {
+         rv = VPPCOM_EINVAL;
+         break;
+       }
+      vcl_session_alloc_ext_cfg (session, TRANSPORT_ENDPT_EXT_CFG_NONE,
+                                *buflen + sizeof (u32));
+      clib_memcpy (session->ext_config->data, buffer, *buflen);
+      session->ext_config->len = *buflen;
+      break;
+
     default:
       rv = VPPCOM_EINVAL;
       break;