u32 et_mask;
} vppcom_epoll_t;
+typedef struct
+{
+ u8 is_ip4;
+ ip46_address_t ip46;
+} vppcom_ip46_t;
+
typedef struct
{
volatile session_state_t state;
u32 wait_cont_idx;
vppcom_epoll_t vep;
u32 vrf;
- u8 is_ip4;
- u8 ip[16];
+ vppcom_ip46_t lcl_addr;
+ vppcom_ip46_t peer_addr;
u16 port;
u8 proto;
u64 client_queue_address;
u8 init;
u32 *client_session_index_fifo;
volatile u32 bind_session_index;
- u32 tx_event_id;
int main_cpu;
/* vpe input queue */
bmp->client_index = vcm->my_client_index;
bmp->context = htonl (0xfeedface);
bmp->options[APP_OPTIONS_FLAGS] =
- APP_OPTIONS_FLAGS_USE_FIFO | APP_OPTIONS_FLAGS_ADD_SEGMENT;
+ APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT |
+ APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE | APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
bmp->options[SESSION_OPTIONS_SEGMENT_SIZE] = vcm->cfg.segment_size;
bmp->options[SESSION_OPTIONS_ADD_SEGMENT_SIZE] = vcm->cfg.add_segment_size;
bmp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = vcm->cfg.rx_fifo_size;
vcm->my_pid, session_index, session_index);
cmp->vrf = session->vrf;
- cmp->is_ip4 = session->is_ip4;
- clib_memcpy (cmp->ip, session->ip, sizeof (cmp->ip));
+ cmp->is_ip4 = session->peer_addr.is_ip4;
+ clib_memcpy (cmp->ip, &session->peer_addr.ip46, sizeof (cmp->ip));
cmp->port = session->port;
cmp->proto = session->proto;
clib_memcpy (cmp->options, session->options, sizeof (cmp->options));
session->state = STATE_ACCEPT;
session->is_cut_thru = 0;
session->is_server = 1;
- session->port = ntohs (mp->port);
- session->is_ip4 = mp->is_ip4;
- clib_memcpy (session->ip, mp->ip, sizeof (session->ip));
+ session->port = mp->port;
+ session->peer_addr.is_ip4 = mp->is_ip4;
+ clib_memcpy (&session->peer_addr.ip46, mp->ip,
+ sizeof (session->peer_addr.ip46));
/* Add it to lookup table */
hash_set (vcm->session_index_by_vpp_handles, mp->handle, session_index);
session->client_queue_address = mp->client_queue_address;
session->is_cut_thru = 1;
session->is_server = 1;
- session->is_ip4 = mp->is_ip4;
session->port = mp->port;
+ session->peer_addr.is_ip4 = mp->is_ip4;
+ clib_memcpy (&session->peer_addr.ip46, mp->ip,
+ sizeof (session->peer_addr.ip46));
{
void *oldheap;
ssvm_shared_header_t *sh = seg->ssvm.sh;
ssvm_pop_heap (oldheap);
ssvm_unlock_non_recursive (sh);
}
- clib_memcpy (session->ip, mp->ip, sizeof (session->ip));
session->state = STATE_ACCEPT;
if (VPPCOM_DEBUG > 1)
bmp->client_index = vcm->my_client_index;
bmp->context = htonl (0xfeedface);
bmp->vrf = session->vrf;
- bmp->is_ip4 = session->is_ip4;
- clib_memcpy (bmp->ip, session->ip, sizeof (bmp->ip));
+ bmp->is_ip4 = session->lcl_addr.is_ip4;
+ clib_memcpy (bmp->ip, &session->lcl_addr.ip46, sizeof (bmp->ip));
bmp->port = session->port;
bmp->proto = session->proto;
clib_memcpy (bmp->options, session->options, sizeof (bmp->options));
rv = vppcom_connect_to_vpp (app_name);
if (rv)
{
- clib_warning ("[%s] couldn't connect to VPP.", vcm->my_pid);
+ clib_warning ("[%d] couldn't connect to VPP.", vcm->my_pid);
return rv;
}
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))
vppcom_main_t *vcm = &vppcom_main;
session_t *session = 0;
int rv;
- ip46_address_t *ip46;
if (!ep || !ep->ip)
return VPPCOM_EINVAL;
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);
session->vrf = ep->vrf;
- session->is_ip4 = ep->is_ip4;
- memset (session->ip, 0, sizeof (session->ip));
- ip46 = (ip46_address_t *) session->ip;
- *ip46 = to_ip46 (!ep->is_ip4, ep->ip);
+ session->lcl_addr.is_ip4 = ep->is_ip4;
+ session->lcl_addr.ip46 = to_ip46 (!ep->is_ip4, ep->ip);
session->port = ep->port;
clib_spinlock_unlock (&vcm->sessions_lockp);
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);
clib_fifo_sub1 (vcm->client_session_index_fifo, client_session_index);
rv = vppcom_session_at_index (client_session_index, &client_session);
ASSERT (rv == VPPCOM_OK);
- ASSERT (client_session->is_ip4 == listen_session->is_ip4);
+ ASSERT (client_session->peer_addr.is_ip4 ==
+ listen_session->lcl_addr.is_ip4);
if (VPPCOM_DEBUG > 0)
clib_warning ("[%d] Got a request: client sid %d", vcm->my_pid,
ep->vrf = client_session->vrf;
ep->is_cut_thru = client_session->is_cut_thru;
- ep->is_ip4 = client_session->is_ip4;
+ ep->is_ip4 = client_session->peer_addr.is_ip4;
ep->port = client_session->port;
- if (client_session->is_ip4)
- clib_memcpy (ep->ip, client_session->ip, sizeof (ip4_address_t));
+ if (client_session->peer_addr.is_ip4)
+ clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip4,
+ sizeof (ip4_address_t));
else
- clib_memcpy (ep->ip, client_session->ip, sizeof (ip6_address_t));
+ clib_memcpy (ep->ip, &client_session->peer_addr.ip46.ip6,
+ sizeof (ip6_address_t));
clib_spinlock_unlock (&vcm->sessions_lockp);
return (int) client_session_index;
}
vppcom_main_t *vcm = &vppcom_main;
session_t *session = 0;
int rv;
- ip46_address_t *ip46;
clib_spinlock_lock (&vcm->sessions_lockp);
rv = vppcom_session_at_index (session_index, &session);
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);
}
session->vrf = server_ep->vrf;
- session->is_ip4 = server_ep->is_ip4;
- memset (session->ip, 0, sizeof (session->ip));
- ip46 = (ip46_address_t *) session->ip;
- *ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
+ session->peer_addr.is_ip4 = server_ep->is_ip4;
+ session->peer_addr.ip46 = to_ip46 (!server_ep->is_ip4, server_ep->ip);
session->port = server_ep->port;
if (VPPCOM_DEBUG > 0)
{
u8 *ip_str = format (0, "%U", format_ip46_address,
- &session->ip, session->is_ip4);
- clib_warning ("[%d] connect sid %d to %s server port %d",
+ &session->peer_addr.ip46,
+ session->peer_addr.is_ip4);
+ clib_warning ("[%d] connect sid %d to %s server port %d proto %s",
vcm->my_pid, session_index, ip_str,
- clib_net_to_host_u16 (session->port));
+ clib_net_to_host_u16 (session->port),
+ session->proto ? "UDP" : "TCP");
vec_free (ip_str);
}
vcm->my_pid, vppcom_retval_str (rv), rv);
return rv;
}
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] sid %d connected!", vcm->my_pid, session_index);
+
return VPPCOM_OK;
}
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;
ASSERT (sizeof (clib_bitmap_t) == sizeof (long int));
- if (read_map)
+ if (n_bits && read_map)
{
clib_bitmap_validate (vcm->rd_bitmap, minbits);
clib_memcpy (vcm->rd_bitmap, read_map, vec_len (vcm->rd_bitmap));
memset (read_map, 0, vec_len (vcm->rd_bitmap));
}
- if (write_map)
+ if (n_bits && write_map)
{
clib_bitmap_validate (vcm->wr_bitmap, minbits);
clib_memcpy (vcm->wr_bitmap, write_map, vec_len (vcm->wr_bitmap));
memset (write_map, 0, vec_len (vcm->wr_bitmap));
}
- if (except_map)
+ if (n_bits && except_map)
{
clib_bitmap_validate (vcm->ex_bitmap, minbits);
clib_memcpy (vcm->ex_bitmap, except_map, vec_len (vcm->ex_bitmap));
do
{
/* *INDENT-OFF* */
- clib_bitmap_foreach (session_index, vcm->rd_bitmap,
- ({
- clib_spinlock_lock (&vcm->sessions_lockp);
- rv = vppcom_session_at_index (session_index, &session);
- if (rv < 0)
+ if (n_bits)
+ {
+ if (read_map)
{
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (VPPCOM_DEBUG > 1)
- clib_warning ("[%d] session %d specified in "
- "read_map is closed.", vcm->my_pid,
- session_index);
- bits_set = VPPCOM_EBADFD;
- goto select_done;
+ clib_bitmap_foreach (session_index, vcm->rd_bitmap,
+ ({
+ clib_spinlock_lock (&vcm->sessions_lockp);
+ rv = vppcom_session_at_index (session_index, &session);
+ if (rv < 0)
+ {
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (VPPCOM_DEBUG > 1)
+ clib_warning ("[%d] session %d specified in "
+ "read_map is closed.", vcm->my_pid,
+ session_index);
+ bits_set = VPPCOM_EBADFD;
+ goto select_done;
+ }
+
+ rv = vppcom_session_read_ready (session, session_index);
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (except_map && vcm->ex_bitmap &&
+ clib_bitmap_get (vcm->ex_bitmap, session_index) &&
+ (rv < 0))
+ {
+ // TBD: clib_warning
+ clib_bitmap_set_no_check (except_map, session_index, 1);
+ bits_set++;
+ }
+ else if (rv > 0)
+ {
+ // TBD: clib_warning
+ clib_bitmap_set_no_check (read_map, session_index, 1);
+ bits_set++;
+ }
+ }));
}
- rv = vppcom_session_read_ready (session, session_index);
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (vcm->ex_bitmap &&
- clib_bitmap_get (vcm->ex_bitmap, session_index) && (rv < 0))
- {
- // TBD: clib_warning
- /* coverity[FORWARD_NULL] */
- clib_bitmap_set_no_check (except_map, session_index, 1);
- bits_set++;
- }
- else if (rv > 0)
+ if (write_map)
{
- // TBD: clib_warning
- /* coverity[FORWARD_NULL] */
- clib_bitmap_set_no_check (read_map, session_index, 1);
- bits_set++;
+ clib_bitmap_foreach (session_index, vcm->wr_bitmap,
+ ({
+ clib_spinlock_lock (&vcm->sessions_lockp);
+ rv = vppcom_session_at_index (session_index, &session);
+ if (rv < 0)
+ {
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("[%d] session %d specified in "
+ "write_map is closed.", vcm->my_pid,
+ session_index);
+ bits_set = VPPCOM_EBADFD;
+ goto select_done;
+ }
+
+ rv = vppcom_session_write_ready (session, session_index);
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (write_map && (rv > 0))
+ {
+ // TBD: clib_warning
+ clib_bitmap_set_no_check (write_map, session_index, 1);
+ bits_set++;
+ }
+ }));
}
- }));
- clib_bitmap_foreach (session_index, vcm->wr_bitmap,
- ({
- clib_spinlock_lock (&vcm->sessions_lockp);
- rv = vppcom_session_at_index (session_index, &session);
- if (rv < 0)
+ if (except_map)
{
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (VPPCOM_DEBUG > 0)
- clib_warning ("[%d] session %d specified in "
- "write_map is closed.", vcm->my_pid,
- session_index);
- bits_set = VPPCOM_EBADFD;
- goto select_done;
+ clib_bitmap_foreach (session_index, vcm->ex_bitmap,
+ ({
+ clib_spinlock_lock (&vcm->sessions_lockp);
+ rv = vppcom_session_at_index (session_index, &session);
+ if (rv < 0)
+ {
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (VPPCOM_DEBUG > 1)
+ clib_warning ("[%d] session %d specified in "
+ "except_map is closed.", vcm->my_pid,
+ session_index);
+ bits_set = VPPCOM_EBADFD;
+ goto select_done;
+ }
+
+ rv = vppcom_session_read_ready (session, session_index);
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ if (rv < 0)
+ {
+ // TBD: clib_warning
+ clib_bitmap_set_no_check (except_map, session_index, 1);
+ bits_set++;
+ }
+ }));
}
-
- rv = vppcom_session_write_ready (session, session_index);
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (rv > 0 )
- {
- // TBD: clib_warning
- /* coverity[FORWARD_NULL] */
- clib_bitmap_set_no_check (write_map, session_index, 1);
- bits_set++;
- }
- }));
-
- clib_bitmap_foreach (session_index, vcm->ex_bitmap,
- ({
- clib_spinlock_lock (&vcm->sessions_lockp);
- rv = vppcom_session_at_index (session_index, &session);
- if (rv < 0)
- {
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (VPPCOM_DEBUG > 1)
- clib_warning ("[%d] session %d specified in "
- "except_map is closed.", vcm->my_pid,
- session_index);
- bits_set = VPPCOM_EBADFD;
- goto select_done;
- }
-
- rv = vppcom_session_read_ready (session, session_index);
- clib_spinlock_unlock (&vcm->sessions_lockp);
- if (rv < 0)
- {
- // TBD: clib_warning
- /* coverity[FORWARD_NULL] */
- clib_bitmap_set_no_check (except_map, session_index, 1);
- bits_set++;
- }
- }));
+ }
/* *INDENT-ON* */
}
while (clib_time_now (&vcm->clib_time) < timeout);
do
{
vep = &session->vep;
+ sid = vep->next_sid;
if (session->is_vep_session)
{
if (VPPCOM_DEBUG > 1)
vep->vep_idx, vep->vep_idx,
vep->ev.events, vep->ev.data.u64, vep->et_mask);
}
- sid = vep->next_sid;
if (sid != ~0)
{
rv = vppcom_session_at_index (sid, &session);
return (rv != VPPCOM_OK) ? rv : num_ev;
}
- /*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
+int
+vppcom_session_attr (uint32_t session_index, uint32_t op,
+ void *buffer, uint32_t * buflen)
+{
+ vppcom_main_t *vcm = &vppcom_main;
+ session_t *session;
+ int rv = VPPCOM_OK;
+ u32 *flags = buffer;
+ vppcom_endpt_t *ep = buffer;
+
+ VCL_LOCK_AND_GET_SESSION (session_index, &session);
+ switch (op)
+ {
+ case VPPCOM_ATTR_GET_NREAD:
+ rv = vppcom_session_read_ready (session, session_index);
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("VPPCOM_ATTR_GET_NREAD: nread = %d", rv);
+
+ break;
+
+ case VPPCOM_ATTR_PEEK_NREAD:
+ /* TBD */
+ break;
+
+ case VPPCOM_ATTR_GET_FLAGS:
+ if (buffer && buflen && (*buflen >= sizeof (*flags)))
+ {
+ *flags = O_RDWR | ((session->is_nonblocking) ? O_NONBLOCK : 0);
+ *buflen = sizeof (*flags);
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("VPPCOM_ATTR_GET_FLAGS: flags = 0x%08x, "
+ "is_nonblocking = %u", *flags,
+ session->is_nonblocking);
+ }
+ else
+ rv = VPPCOM_EINVAL;
+ break;
+
+ case VPPCOM_ATTR_SET_FLAGS:
+ if (buffer && buflen && (*buflen >= sizeof (*flags)))
+ {
+ session->is_nonblocking = (*flags & O_NONBLOCK) ? 1 : 0;
+ if (VPPCOM_DEBUG > 0)
+ clib_warning ("VPPCOM_ATTR_SET_FLAGS: flags = 0x%08x, "
+ "is_nonblocking = %u", *flags,
+ session->is_nonblocking);
+ }
+ else
+ rv = VPPCOM_EINVAL;
+ break;
+
+ case VPPCOM_ATTR_GET_PEER_ADDR:
+ if (buffer && buflen && (*buflen >= sizeof (*ep)))
+ {
+ 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", 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 (*ep)))
+ {
+ 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)
+ 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;
+ break;
+
+ case VPPCOM_ATTR_SET_REUSEADDR:
+ break;
+
+ case VPPCOM_ATTR_SET_BROADCAST:
+ break;
+
+ case VPPCOM_ATTR_SET_V6ONLY:
+ break;
+
+ case VPPCOM_ATTR_SET_KEEPALIVE:
+ break;
+
+ case VPPCOM_ATTR_SET_TCP_KEEPIDLE:
+ break;
+
+ case VPPCOM_ATTR_SET_TCP_KEEPINTVL:
+ break;
+
+ default:
+ rv = VPPCOM_EINVAL;
+ break;
+ }
+
+done:
+ clib_spinlock_unlock (&vcm->sessions_lockp);
+ return rv;
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */