VCL-LDPRELOAD: fix iperf3 socket_test.sh 89/8889/2
authorDave Wallace <dwallacelf@gmail.com>
Thu, 19 Oct 2017 01:15:48 +0000 (21:15 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 19 Oct 2017 04:35:37 +0000 (04:35 +0000)
Change-Id: Ib6b52917af717d3341429163fb9ecc903cf717fb
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
extras/vcl-ldpreload/src/libvcl-ldpreload/vcom_socket.c
src/uri/vppcom.c
src/uri/vppcom.h

index c8a9d62..96108af 100644 (file)
@@ -1256,16 +1256,6 @@ vcom_socket_bind (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
     }
 
   rv = vppcom_session_bind (vsock->sid, &ep);
-  /* TBD: remove libc_bind code snippet
-   * once vppcom implements vppcom_session_getsockname */
-  if (rv == 0)
-    {
-      rv = libc_bind (__fd, __addr, __len);
-      if (rv != 0)
-       {
-         rv = -errno;
-       }
-    }
   return rv;
 }
 
@@ -1741,12 +1731,7 @@ vppcom_getsockopt (int __sid, int __level, int __optname,
 {
   /* 1. for socket level options that are NOT socket attributes
    *    and that has corresponding vpp options get from vppcom */
-#if 0
   return 0;
-#endif
-
-  /* 2. unhandled options */
-  return -ENOPROTOOPT;
 }
 
 int
index f0bd2f8..5d1373f 100644 (file)
@@ -1840,7 +1840,7 @@ vppcom_session_create (u32 vrf, u8 proto, u8 is_nonblocking)
   session->vrf = vrf;
   session->proto = proto;
   session->state = STATE_START;
-  session->is_nonblocking = is_nonblocking;
+  session->is_nonblocking = is_nonblocking ? 1 : 0;
   clib_spinlock_unlock (&vcm->sessions_lockp);
 
   if (VPPCOM_DEBUG > 0)
@@ -1924,19 +1924,17 @@ vppcom_session_close (uint32_t session_index)
          clib_spinlock_unlock (&vcm->sessions_lockp);
        }
 
-      if (session->is_cut_thru)
+      if (session->is_cut_thru && session->is_server &&
+         (session->state == STATE_ACCEPT))
        {
-         if (session->is_server)
-           {
-             rv = vppcom_session_unbind_cut_thru (session);
-             if ((VPPCOM_DEBUG > 0) && (rv < 0))
-               clib_warning ("[%d] unbind cut-thru (session %d) failed, "
-                             "rv = %s (%d)",
-                             vcm->my_pid, session_index,
-                             vppcom_retval_str (rv), rv);
-           }
+         rv = vppcom_session_unbind_cut_thru (session);
+         if ((VPPCOM_DEBUG > 0) && (rv < 0))
+           clib_warning ("[%d] unbind cut-thru (session %d) failed, "
+                         "rv = %s (%d)",
+                         vcm->my_pid, session_index,
+                         vppcom_retval_str (rv), rv);
        }
-      else if (session->is_server)
+      else if (session->is_server && session->is_listen)
        {
          rv = vppcom_session_unbind (session_index);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
@@ -1944,7 +1942,7 @@ vppcom_session_close (uint32_t session_index)
                          vcm->my_pid, session_index,
                          vppcom_retval_str (rv), rv);
        }
-      else
+      else if (session->state == STATE_CONNECT)
        {
          rv = vppcom_session_disconnect (session_index);
          if ((VPPCOM_DEBUG > 0) && (rv < 0))
@@ -1979,6 +1977,15 @@ vppcom_session_bind (uint32_t session_index, vppcom_endpt_t * ep)
       return rv;
     }
 
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (VPPCOM_DEBUG > 0)
     clib_warning ("[%d] sid %d", vcm->my_pid, session_index);
 
@@ -2009,6 +2016,15 @@ vppcom_session_listen (uint32_t listen_session_index, uint32_t q_len)
       return rv;
     }
 
+  if (listen_session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, listen_session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (VPPCOM_DEBUG > 0)
     clib_warning ("[%d] sid %d", vcm->my_pid, listen_session_index);
 
@@ -2067,6 +2083,15 @@ vppcom_session_accept (uint32_t listen_session_index, vppcom_endpt_t * ep,
       return rv;
     }
 
+  if (listen_session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, listen_session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (listen_session->state != STATE_LISTEN)
     {
       clib_spinlock_unlock (&vcm->sessions_lockp);
@@ -2145,6 +2170,15 @@ vppcom_session_connect (uint32_t session_index, vppcom_endpt_t * server_ep)
       return rv;
     }
 
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (session->state == STATE_CONNECT)
     {
       clib_spinlock_unlock (&vcm->sessions_lockp);
@@ -2193,6 +2227,7 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
   int n_read = 0;
   int rv;
   char *fifo_str;
+  u32 poll_et;
 
   ASSERT (buf);
 
@@ -2207,6 +2242,15 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
       return rv;
     }
 
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (session->state == STATE_DISCONNECT)
     {
       clib_spinlock_unlock (&vcm->sessions_lockp);
@@ -2220,6 +2264,8 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
             session->server_rx_fifo : session->server_tx_fifo);
   fifo_str = ((!session->is_cut_thru || session->is_server) ?
              "server_rx_fifo" : "server_tx_fifo");
+  poll_et = EPOLLET & session->vep.ev.events;
+  clib_spinlock_unlock (&vcm->sessions_lockp);
 
   do
     {
@@ -2227,10 +2273,12 @@ vppcom_session_read (uint32_t session_index, void *buf, int n)
     }
   while (!session->is_nonblocking && (n_read <= 0));
 
-  if (n_read <= 0)
-    session->vep.et_mask |= EPOLLIN;
-
-  clib_spinlock_unlock (&vcm->sessions_lockp);
+  if (poll_et && (n_read <= 0))
+    {
+      clib_spinlock_lock (&vcm->sessions_lockp);
+      session->vep.et_mask |= EPOLLIN;
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+    }
 
   if ((VPPCOM_DEBUG > 2) && (n_read > 0))
     clib_warning ("[%d] sid %d, read %d bytes from %s (%p)", vcm->my_pid,
@@ -2247,6 +2295,15 @@ vppcom_session_read_ready (session_t * session, u32 session_index)
   int ready = 0;
 
   /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (session->state == STATE_DISCONNECT)
     {
       if (VPPCOM_DEBUG > 0)
@@ -2270,7 +2327,7 @@ vppcom_session_read_ready (session_t * session, u32 session_index)
                  session_index,
                  session->is_server ? "server_rx_fifo" : "server_tx_fifo",
                  rx_fifo, ready);
-  if (ready == 0)
+  if ((session->vep.ev.events & EPOLLET) && (ready == 0))
     session->vep.et_mask |= EPOLLIN;
 
   return ready;
@@ -2286,6 +2343,7 @@ vppcom_session_write (uint32_t session_index, void *buf, int n)
   session_fifo_event_t evt;
   int rv, n_write;
   char *fifo_str;
+  u32 poll_et;
 
   ASSERT (buf);
 
@@ -2300,6 +2358,15 @@ vppcom_session_write (uint32_t session_index, void *buf, int n)
       return rv;
     }
 
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (session->state == STATE_DISCONNECT)
     {
       clib_spinlock_unlock (&vcm->sessions_lockp);
@@ -2313,6 +2380,10 @@ vppcom_session_write (uint32_t session_index, void *buf, int n)
             session->server_tx_fifo : session->server_rx_fifo);
   fifo_str = ((!session->is_cut_thru || session->is_server) ?
              "server_tx_fifo" : "server_rx_fifo");
+  q = session->vpp_event_queue;
+  poll_et = EPOLLET & session->vep.ev.events;
+  clib_spinlock_unlock (&vcm->sessions_lockp);
+
   do
     {
       n_write = svm_fifo_enqueue_nowait (tx_fifo, n, buf);
@@ -2331,27 +2402,33 @@ vppcom_session_write (uint32_t session_index, void *buf, int n)
       rval = vppcom_session_at_index (session_index, &session);
       if (PREDICT_FALSE (rval))
        {
-         clib_spinlock_unlock (&vcm->sessions_lockp);
          if (VPPCOM_DEBUG > 1)
            clib_warning ("[%d] invalid session, sid (%u) has been closed!",
                          vcm->my_pid, session_index);
          return rval;
        }
-      q = session->vpp_event_queue;
       ASSERT (q);
       unix_shared_memory_queue_add (q, (u8 *) & evt,
                                    0 /* do wait for mutex */ );
     }
 
-  if (n_write <= 0)
-    session->vep.et_mask |= EPOLLOUT;
-
-  clib_spinlock_unlock (&vcm->sessions_lockp);
+  if (poll_et && (n_write <= 0))
+    {
+      clib_spinlock_lock (&vcm->sessions_lockp);
+      session->vep.et_mask |= EPOLLOUT;
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+    }
 
   if (VPPCOM_DEBUG > 2)
-    clib_warning ("[%d] sid %d, wrote %d bytes to %s (%p)", vcm->my_pid,
-                 session_index, n_write, fifo_str, tx_fifo);
-  return n_write;
+    {
+      if (n_write == -2)
+       clib_warning ("[%d] sid %d, FIFO-FULL %s (%p)", vcm->my_pid,
+                     session_index, fifo_str, tx_fifo);
+      else
+       clib_warning ("[%d] sid %d, wrote %d bytes to %s (%p)", vcm->my_pid,
+                     session_index, n_write, fifo_str, tx_fifo);
+    }
+  return (n_write < 0) ? VPPCOM_EAGAIN : n_write;
 }
 
 static inline int
@@ -2363,6 +2440,15 @@ vppcom_session_write_ready (session_t * session, u32 session_index)
   int ready;
 
   /* Assumes caller has acquired spinlock: vcm->sessions_lockp */
+  if (session->is_vep)
+    {
+      clib_spinlock_unlock (&vcm->sessions_lockp);
+      if (VPPCOM_DEBUG > 0)
+       clib_warning ("[%d] invalid session, sid (%u) is an epoll session!",
+                     vcm->my_pid, session_index);
+      return VPPCOM_EBADFD;
+    }
+
   if (session->state == STATE_DISCONNECT)
     {
       if (VPPCOM_DEBUG > 0)
@@ -2381,7 +2467,7 @@ vppcom_session_write_ready (session_t * session, u32 session_index)
   if (VPPCOM_DEBUG > 3)
     clib_warning ("[%d] sid %d, peek %s (%p), ready = %d", vcm->my_pid,
                  session_index, fifo_str, tx_fifo, ready);
-  if (ready == 0)
+  if ((session->vep.ev.events & EPOLLET) && (ready == 0))
     session->vep.et_mask |= EPOLLOUT;
 
   return ready;
index 0b2a2dc..dd72986 100644 (file)
@@ -127,13 +127,6 @@ vppcom_retval_str (int retval)
   return st;
 }
 
-static inline int
-is_vcom_fd (int fd)
-{
-#define VPPCOM_FD_OFFSET (1 << 30)
-  return (fd >= VPPCOM_FD_OFFSET);
-}
-
 /* TBD: make these constructor/destructor function */
 extern int vppcom_app_create (char *app_name);
 extern void vppcom_app_destroy (void);