u8 init;
u32 *client_session_index_fifo;
volatile u32 bind_session_index;
- u32 tx_event_id;
int main_cpu;
/* vpe input queue */
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)
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))
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))
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);
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);
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);
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);
int n_read = 0;
int rv;
char *fifo_str;
+ u32 poll_et;
ASSERT (buf);
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);
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
{
}
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,
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)
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;
session_fifo_event_t evt;
int rv, n_write;
char *fifo_str;
+ u32 poll_et;
ASSERT (buf);
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);
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);
/* Fabricate TX event, send to vpp */
evt.fifo = tx_fifo;
evt.event_type = FIFO_EVENT_APP_TX;
- evt.event_id = vcm->tx_event_id++;
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
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)
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;
session_t *session;
int rv = VPPCOM_OK;
u32 *flags = buffer;
- vppcom_ip46_t *vcl_addr = buffer;
+ vppcom_endpt_t *ep = buffer;
VCL_LOCK_AND_GET_SESSION (session_index, &session);
switch (op)
break;
case VPPCOM_ATTR_GET_PEER_ADDR:
- if (buffer && buflen && (*buflen >= sizeof (*vcl_addr)))
+ if (buffer && buflen && (*buflen >= sizeof (*ep)))
{
- *vcl_addr = session->peer_addr;
- *buflen = sizeof (*vcl_addr);
+ ep->vrf = session->vrf;
+ ep->is_ip4 = session->peer_addr.is_ip4;
+ ep->port = session->port;
+ if (session->peer_addr.is_ip4)
+ clib_memcpy (ep->ip, &session->peer_addr.ip46.ip4,
+ sizeof (ip4_address_t));
+ else
+ clib_memcpy (ep->ip, &session->peer_addr.ip46.ip6,
+ sizeof (ip6_address_t));
+ *buflen = sizeof (*ep);
if (VPPCOM_DEBUG > 0)
clib_warning ("VPPCOM_ATTR_GET_PEER_ADDR: is_ip4 = %u, "
- "addr = %U", vcl_addr->is_ip4, format_ip46_address,
- &vcl_addr->ip46, vcl_addr->is_ip4);
+ "addr = %U", ep->is_ip4, format_ip46_address,
+ &session->peer_addr.ip46, ep->is_ip4);
}
else
rv = VPPCOM_EINVAL;
break;
case VPPCOM_ATTR_GET_LCL_ADDR:
- if (buffer && buflen && (*buflen >= sizeof (*vcl_addr)))
+ if (buffer && buflen && (*buflen >= sizeof (*ep)))
{
- *vcl_addr = session->lcl_addr;
- *buflen = sizeof (*vcl_addr);
+ ep->vrf = session->vrf;
+ ep->is_ip4 = session->lcl_addr.is_ip4;
+ ep->port = session->port;
+ if (session->lcl_addr.is_ip4)
+ clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip4,
+ sizeof (ip4_address_t));
+ else
+ clib_memcpy (ep->ip, &session->lcl_addr.ip46.ip6,
+ sizeof (ip6_address_t));
+ *buflen = sizeof (*ep);
if (VPPCOM_DEBUG > 0)
- clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: is_ip4 = %u, "
- "addr = %U", vcl_addr->is_ip4, format_ip46_address,
- &vcl_addr->ip46, vcl_addr->is_ip4);
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("VPPCOM_ATTR_GET_LCL_ADDR: is_ip4 = %u, "
+ "addr = %U", ep->is_ip4, format_ip46_address,
+ &session->lcl_addr.ip46, ep->is_ip4);
}
else
rv = VPPCOM_EINVAL;