X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvppcom.c;h=6b690e5d1d0de3fa9cc1e81a374ebd1e392f0c46;hb=6017ff0dd7a27c062d0ad4687bfc70a69747ac55;hp=15313fd286ca3c83b266173b89b300e6855b0cd2;hpb=68b7e5888cbfc1fafd38971c725ce10268ad3841;p=vpp.git diff --git a/src/vcl/vppcom.c b/src/vcl/vppcom.c index 15313fd286c..6b690e5d1d0 100644 --- a/src/vcl/vppcom.c +++ b/src/vcl/vppcom.c @@ -60,8 +60,8 @@ vppcom_session_state_str (vcl_session_state_t state) switch (state) { - case STATE_START: - st = "STATE_START"; + case STATE_CLOSED: + st = "STATE_CLOSED"; break; case STATE_CONNECT: @@ -84,8 +84,8 @@ vppcom_session_state_str (vcl_session_state_t state) st = "STATE_DISCONNECT"; break; - case STATE_FAILED: - st = "STATE_FAILED"; + case STATE_DETACHED: + st = "STATE_DETACHED"; break; case STATE_UPDATED: @@ -231,7 +231,10 @@ vcl_send_session_connect (vcl_worker_t * wrk, vcl_session_t * s) clib_memcpy_fast (&mp->ip, &s->transport.rmt_ip, sizeof (mp->ip)); clib_memcpy_fast (&mp->lcl_ip, &s->transport.lcl_ip, sizeof (mp->lcl_ip)); mp->port = s->transport.rmt_port; + mp->lcl_port = s->transport.lcl_port; mp->proto = s->session_type; + if (s->flags & VCL_SESSION_F_CONNECTED) + mp->flags |= TRANSPORT_CFG_F_CONNECTED; app_send_ctrl_evt_to_vpp (mq, app_evt); } @@ -442,8 +445,8 @@ vcl_session_connected_handler (vcl_worker_t * wrk, if (mp->retval) { VDBG (0, "ERROR: session index %u: connect failed! %U", - session_index, format_api_error, ntohl (mp->retval)); - session->session_state = STATE_FAILED | STATE_DISCONNECT; + session_index, format_session_error, mp->retval); + session->session_state = STATE_DETACHED | STATE_DISCONNECT; session->vpp_handle = mp->handle; return session_index; } @@ -457,7 +460,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk, { VDBG (0, "segment for session %u is not mounted!", session->session_index); - session->session_state = STATE_FAILED | STATE_DISCONNECT; + session->session_state = STATE_DETACHED | STATE_DISCONNECT; vcl_send_session_disconnect (wrk, session); return session_index; } @@ -479,7 +482,7 @@ vcl_session_connected_handler (vcl_worker_t * wrk, { VDBG (0, "ct segment for session %u is not mounted!", session->session_index); - session->session_state = STATE_FAILED | STATE_DISCONNECT; + session->session_state = STATE_DETACHED | STATE_DISCONNECT; vcl_send_session_disconnect (wrk, session); return session_index; } @@ -562,10 +565,10 @@ vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp) if (mp->retval) { VERR ("session %u [0x%llx]: bind failed: %U", sid, mp->handle, - format_api_error, mp->retval); + format_session_error, mp->retval); if (session) { - session->session_state = STATE_FAILED; + session->session_state = STATE_DETACHED; session->vpp_handle = mp->handle; return sid; } @@ -612,15 +615,25 @@ vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data) vcl_session_t *s; s = vcl_session_get_w_vpp_handle (wrk, mp->handle); - if (!s || s->session_state != STATE_DISCONNECT) + if (!s) { VDBG (0, "Unlisten reply with wrong handle %llx", mp->handle); return; } + if (s->session_state != STATE_DISCONNECT) + { + /* Connected udp listener */ + if (s->session_type == VPPCOM_PROTO_UDP + && s->session_state == STATE_CLOSED) + return; + + VDBG (0, "Unlisten session in wrong state %llx", mp->handle); + return; + } if (mp->retval) VDBG (0, "ERROR: session %u [0xllx]: unlisten failed: %U", - s->session_index, mp->handle, format_api_error, ntohl (mp->retval)); + s->session_index, mp->handle, format_session_error, mp->retval); if (mp->context != wrk->wrk_index) VDBG (0, "wrong context"); @@ -643,6 +656,7 @@ vcl_session_migrated_handler (vcl_worker_t * wrk, void *data) } s->vpp_thread_index = mp->vpp_thread_index; + s->vpp_handle = mp->new_handle; s->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); vec_validate (wrk->vpp_event_queues, s->vpp_thread_index); @@ -656,7 +670,8 @@ vcl_session_migrated_handler (vcl_worker_t * wrk, void *data) app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index, SESSION_IO_EVT_TX, SVM_Q_WAIT); - VDBG (0, "Migrated 0x%x to thread %u", mp->handle, s->vpp_thread_index); + VDBG (0, "Migrated 0x%lx to thread %u 0x%lx", mp->handle, + s->vpp_thread_index, mp->new_handle); } static vcl_session_t * @@ -679,6 +694,7 @@ vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg) } clib_fifo_add2 (session->accept_evts_fifo, vcl_msg); + vcl_msg->flags = 0; vcl_msg->accepted_msg = *msg; /* Session handle points to listener until fully accepted by app */ vcl_session_table_add_vpp_handle (wrk, msg->handle, session->session_index); @@ -699,6 +715,10 @@ vcl_session_disconnected_handler (vcl_worker_t * wrk, return 0; } + /* Late disconnect notification on a session that has been closed */ + if (session->session_state == STATE_CLOSED) + return 0; + /* Caught a disconnect before actually accepting the session */ if (session->session_state == STATE_LISTEN) { @@ -708,10 +728,50 @@ vcl_session_disconnected_handler (vcl_worker_t * wrk, return 0; } - session->session_state = STATE_VPP_CLOSING; + /* If not already reset change state */ + if (session->session_state != STATE_DISCONNECT) + session->session_state = STATE_VPP_CLOSING; + return session; } +static void +vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data) +{ + session_cleanup_msg_t *msg; + vcl_session_t *session; + + msg = (session_cleanup_msg_t *) data; + session = vcl_session_get_w_vpp_handle (wrk, msg->handle); + if (!session) + { + VDBG (0, "disconnect confirmed for unknown handle 0x%llx", msg->handle); + return; + } + + if (msg->type == SESSION_CLEANUP_TRANSPORT) + { + /* Transport was cleaned up before we confirmed close. Probably the + * app is still waiting for some data that cannot be delivered. + * Confirm close to make sure everything is cleaned up */ + if (session->session_state == STATE_VPP_CLOSING) + vcl_session_cleanup (wrk, session, vcl_session_handle (session), + 1 /* do_disconnect */ ); + return; + } + + vcl_session_table_del_vpp_handle (wrk, msg->handle); + /* Should not happen. App did not close the connection so don't free it. */ + if (session->session_state != STATE_CLOSED) + { + VDBG (0, "app did not close session %d", session->session_index); + session->session_state = STATE_DETACHED; + session->vpp_handle = VCL_INVALID_SESSION_HANDLE; + return; + } + vcl_session_free (wrk, session); +} + static void vcl_session_req_worker_update_handler (vcl_worker_t * wrk, void *data) { @@ -845,6 +905,9 @@ vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e) case SESSION_CTRL_EVT_MIGRATED: vcl_session_migrated_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: vcl_session_req_worker_update_handler (wrk, e->data); break; @@ -885,7 +948,7 @@ vppcom_wait_for_session_state_change (u32 session_index, { return VPPCOM_OK; } - if (session->session_state & STATE_FAILED) + if (session->session_state & STATE_DETACHED) { return VPPCOM_ECONNREFUSED; } @@ -1159,35 +1222,38 @@ vppcom_app_create (char *app_name) void vppcom_app_destroy (void) { - int rv; - f64 orig_app_timeout; + vcl_worker_t *wrk, *current_wrk; + struct dlmallinfo mi; + mspace heap; if (!pool_elts (vcm->workers)) return; vcl_evt (VCL_EVT_DETACH, vcm); - if (pool_elts (vcm->workers) == 1) - { - vcl_send_app_detach (vcl_worker_get_current ()); - orig_app_timeout = vcm->cfg.app_timeout; - vcm->cfg.app_timeout = 2.0; - rv = vcl_wait_for_app_state_change (STATE_APP_ENABLED); - vcm->cfg.app_timeout = orig_app_timeout; - if (PREDICT_FALSE (rv)) - VDBG (0, "application detach timed out! returning %d (%s)", rv, - vppcom_retval_str (rv)); - vec_free (vcm->app_name); - vcl_worker_cleanup (vcl_worker_get_current (), 0 /* notify vpp */ ); - } - else - { - vcl_worker_cleanup (vcl_worker_get_current (), 1 /* notify vpp */ ); - } + current_wrk = vcl_worker_get_current (); + + /* *INDENT-OFF* */ + pool_foreach (wrk, vcm->workers, ({ + if (current_wrk != wrk) + vcl_worker_cleanup (wrk, 0 /* notify vpp */ ); + })); + /* *INDENT-ON* */ + + vcl_send_app_detach (current_wrk); + vppcom_disconnect_from_vpp (); + vcl_worker_cleanup (current_wrk, 0 /* notify vpp */ ); - vcl_set_worker_index (~0); vcl_elog_stop (vcm); - vl_client_disconnect_from_vlib (); + + /* + * Free the heap and fix vcm + */ + heap = clib_mem_get_heap (); + mi = mspace_mallinfo (heap); + munmap (mspace_least_addr (heap), mi.arena); + + vcm = &_vppcom_main; } int @@ -1199,7 +1265,7 @@ vppcom_session_create (u8 proto, u8 is_nonblocking) session = vcl_session_alloc (wrk); session->session_type = proto; - session->session_state = STATE_START; + session->session_state = STATE_CLOSED; session->vpp_handle = ~0; session->is_dgram = vcl_proto_is_dgram (proto); @@ -1244,55 +1310,64 @@ vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * session, next_sh = session->vep.next_sh; } + goto cleanup; } - else + + if (session->is_vep_session) { - if (session->is_vep_session) - { - rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, sh, 0); - if (rv < 0) - VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u " - "failed! rv %d (%s)", session->session_index, vpp_handle, - vep_sh, rv, vppcom_retval_str (rv)); - } + rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, sh, 0); + if (rv < 0) + VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u " + "failed! rv %d (%s)", session->session_index, vpp_handle, + vep_sh, rv, vppcom_retval_str (rv)); + } - if (!do_disconnect) - { - VDBG (1, "session %u [0x%llx] disconnect skipped", - session->session_index, vpp_handle); - goto cleanup; - } + if (!do_disconnect) + { + VDBG (1, "session %u [0x%llx] disconnect skipped", + session->session_index, vpp_handle); + goto cleanup; + } - if (state & STATE_LISTEN) - { - rv = vppcom_session_unbind (sh); - if (PREDICT_FALSE (rv < 0)) - VDBG (0, "session %u [0x%llx]: listener unbind failed! " - "rv %d (%s)", session->session_index, vpp_handle, rv, - vppcom_retval_str (rv)); - return rv; - } - else if ((state & STATE_OPEN) - || (vcl_session_is_connectable_listener (wrk, session))) - { - rv = vppcom_session_disconnect (sh); - if (PREDICT_FALSE (rv < 0)) - VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!" - " rv %d (%s)", session->session_index, vpp_handle, - rv, vppcom_retval_str (rv)); - } - else if (state == STATE_DISCONNECT) - { - svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session); - vcl_send_session_reset_reply (mq, wrk->my_client_index, - session->vpp_handle, 0); - } + if (state & STATE_LISTEN) + { + rv = vppcom_session_unbind (sh); + if (PREDICT_FALSE (rv < 0)) + VDBG (0, "session %u [0x%llx]: listener unbind failed! " + "rv %d (%s)", session->session_index, vpp_handle, rv, + vppcom_retval_str (rv)); + return rv; } + else if ((state & STATE_OPEN) + || (vcl_session_is_connectable_listener (wrk, session))) + { + rv = vppcom_session_disconnect (sh); + if (PREDICT_FALSE (rv < 0)) + VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!" + " rv %d (%s)", session->session_index, vpp_handle, + rv, vppcom_retval_str (rv)); + } + else if (state == STATE_DISCONNECT) + { + svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, session); + vcl_send_session_reset_reply (mq, wrk->my_client_index, + session->vpp_handle, 0); + } + else if (state == STATE_DETACHED) + { + /* Should not happen. VPP cleaned up before app confirmed close */ + VDBG (0, "vpp freed session %d before close", session->session_index); + goto free_session; + } + + session->session_state = STATE_CLOSED; - VDBG (0, "session %u [0x%llx] removed", session->session_index, vpp_handle); + /* Session is removed only after vpp confirms the disconnect */ + return rv; cleanup: vcl_session_table_del_vpp_handle (wrk, vpp_handle); +free_session: vcl_session_free (wrk, session); vcl_evt (VCL_EVT_CLOSE, session, rv); @@ -1484,10 +1559,6 @@ vppcom_unformat_proto (uint8_t * proto, char *proto_str) *proto = VPPCOM_PROTO_UDPC; else if (!strcmp (proto_str, "udpc")) *proto = VPPCOM_PROTO_UDPC; - else if (!strcmp (proto_str, "SCTP")) - *proto = VPPCOM_PROTO_SCTP; - else if (!strcmp (proto_str, "sctp")) - *proto = VPPCOM_PROTO_SCTP; else if (!strcmp (proto_str, "TLS")) *proto = VPPCOM_PROTO_TLS; else if (!strcmp (proto_str, "tls")) @@ -1610,25 +1681,6 @@ handle: return vcl_session_handle (client_session); } -static void -vcl_ip_copy_from_ep (ip46_address_t * ip, vppcom_endpt_t * ep) -{ - if (ep->is_ip4) - clib_memcpy_fast (&ip->ip4, ep->ip, sizeof (ip4_address_t)); - else - clib_memcpy_fast (&ip->ip6, ep->ip, sizeof (ip6_address_t)); -} - -void -vcl_ip_copy_to_ep (ip46_address_t * ip, vppcom_endpt_t * ep, u8 is_ip4) -{ - ep->is_ip4 = is_ip4; - if (is_ip4) - clib_memcpy_fast (ep->ip, &ip->ip4, sizeof (ip4_address_t)); - else - clib_memcpy_fast (ep->ip, &ip->ip6, sizeof (ip6_address_t)); -} - int vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep) { @@ -1663,13 +1715,24 @@ vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep) return VPPCOM_OK; } + /* Attempt to connect a connectionless listener */ + if (PREDICT_FALSE (session->session_state & STATE_LISTEN)) + { + if (session->session_type != VPPCOM_PROTO_UDP) + return VPPCOM_EINVAL; + vcl_send_session_unlisten (wrk, session); + session->session_state = STATE_CLOSED; + } + session->transport.is_ip4 = server_ep->is_ip4; vcl_ip_copy_from_ep (&session->transport.rmt_ip, server_ep); session->transport.rmt_port = server_ep->port; session->parent_handle = VCL_INVALID_SESSION_HANDLE; + session->flags |= VCL_SESSION_F_CONNECTED; - VDBG (0, "session handle %u: connecting to server %s %U " + VDBG (0, "session handle %u (%s): connecting to peer %s %U " "port %d proto %s", session_handle, + vppcom_session_state_str (session->session_state), session->transport.is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &session->transport.rmt_ip, session->transport.is_ip4 ? @@ -1955,13 +2018,21 @@ vcl_is_tx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct) return (e->event_type == SESSION_IO_EVT_TX && e->session_index == sid); } -static inline int -vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n, - u8 is_flush) +always_inline u8 +vcl_fifo_is_writeable (svm_fifo_t * f, u32 len, u8 is_dgram) +{ + u32 max_enq = svm_fifo_max_enqueue_prod (f); + if (is_dgram) + return max_enq >= (sizeof (session_dgram_hdr_t) + len); + else + return max_enq > 0; +} + +always_inline int +vppcom_session_write_inline (vcl_worker_t * wrk, vcl_session_t * s, void *buf, + size_t n, u8 is_flush, u8 is_dgram) { - vcl_worker_t *wrk = vcl_worker_get_current (); int n_write, is_nonblocking; - vcl_session_t *s = 0; session_evt_type_t et; svm_msg_q_msg_t msg; svm_fifo_t *tx_fifo; @@ -1972,10 +2043,6 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n, if (PREDICT_FALSE (!buf || n == 0)) return VPPCOM_EINVAL; - s = vcl_session_get_w_handle (wrk, session_handle); - if (PREDICT_FALSE (!s)) - return VPPCOM_EBADFD; - if (PREDICT_FALSE (s->is_vep)) { VDBG (0, "ERROR: session %u [0x%llx]: cannot write to an epoll" @@ -1996,13 +2063,13 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n, is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK); mq = wrk->app_event_queue; - if (svm_fifo_is_full_prod (tx_fifo)) + if (!vcl_fifo_is_writeable (tx_fifo, n, is_dgram)) { if (is_nonblocking) { return VPPCOM_EWOULDBLOCK; } - while (svm_fifo_is_full_prod (tx_fifo)) + while (!vcl_fifo_is_writeable (tx_fifo, n, is_dgram)) { svm_fifo_add_want_deq_ntf (tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF); if (vcl_session_is_closing (s)) @@ -2025,7 +2092,7 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n, if (is_flush && !is_ct) et = SESSION_IO_EVT_TX_FLUSH; - if (s->is_dgram) + if (is_dgram) n_write = app_send_dgram_raw (tx_fifo, &s->transport, s->vpp_evt_q, buf, n, et, 0 /* do_evt */ , SVM_Q_WAIT); @@ -2048,15 +2115,29 @@ vppcom_session_write_inline (uint32_t session_handle, void *buf, size_t n, int vppcom_session_write (uint32_t session_handle, void *buf, size_t n) { - return vppcom_session_write_inline (session_handle, buf, n, - 0 /* is_flush */ ); + vcl_worker_t *wrk = vcl_worker_get_current (); + vcl_session_t *s; + + s = vcl_session_get_w_handle (wrk, session_handle); + if (PREDICT_FALSE (!s)) + return VPPCOM_EBADFD; + + return vppcom_session_write_inline (wrk, s, buf, n, + 0 /* is_flush */ , s->is_dgram ? 1 : 0); } int vppcom_session_write_msg (uint32_t session_handle, void *buf, size_t n) { - return vppcom_session_write_inline (session_handle, buf, n, - 1 /* is_flush */ ); + vcl_worker_t *wrk = vcl_worker_get_current (); + vcl_session_t *s; + + s = vcl_session_get_w_handle (wrk, session_handle); + if (PREDICT_FALSE (!s)) + return VPPCOM_EBADFD; + + return vppcom_session_write_inline (wrk, s, buf, n, + 1 /* is_flush */ , s->is_dgram ? 1 : 0); } #define vcl_fifo_rx_evt_valid_or_break(_s) \ @@ -2094,7 +2175,7 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_IO_EVT_RX: sid = e->session_index; session = vcl_session_get (wrk, sid); - if (!session) + if (!session || !vcl_session_is_open (session)) break; vcl_fifo_rx_evt_valid_or_break (session); if (sid < n_bits && read_map) @@ -2106,7 +2187,7 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_IO_EVT_TX: sid = e->session_index; session = vcl_session_get (wrk, sid); - if (!session) + if (!session || !vcl_session_is_open (session)) break; if (sid < n_bits && write_map) { @@ -2163,6 +2244,9 @@ vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_CTRL_EVT_MIGRATED: vcl_session_migrated_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY: vcl_session_worker_update_reply_handler (wrk, e->data); break; @@ -2296,7 +2380,7 @@ vppcom_select (int n_bits, vcl_si_set * read_map, vcl_si_set * write_map, u32 sid, minbits = clib_max (n_bits, BITS (uword)), bits_set = 0; vcl_worker_t *wrk = vcl_worker_get_current (); vcl_session_t *session = 0; - int rv, i; + int i; if (n_bits && read_map) { @@ -2330,13 +2414,12 @@ vppcom_select (int n_bits, vcl_si_set * read_map, vcl_si_set * write_map, clib_bitmap_foreach (sid, wrk->wr_bitmap, ({ if (!(session = vcl_session_get (wrk, sid))) { - if (except_map && sid < minbits) - clib_bitmap_set_no_check (except_map, sid, 1); - continue; + clib_bitmap_set_no_check ((uword*)write_map, sid, 1); + bits_set++; + continue; } - rv = svm_fifo_is_full_prod (session->tx_fifo); - if (!rv) + if (vcl_session_write_ready (session)) { clib_bitmap_set_no_check ((uword*)write_map, sid, 1); bits_set++; @@ -2352,13 +2435,12 @@ check_rd: clib_bitmap_foreach (sid, wrk->rd_bitmap, ({ if (!(session = vcl_session_get (wrk, sid))) { - if (except_map && sid < minbits) - clib_bitmap_set_no_check (except_map, sid, 1); - continue; + clib_bitmap_set_no_check ((uword*)read_map, sid, 1); + bits_set++; + continue; } - rv = vcl_session_read_ready (session); - if (rv) + if (vcl_session_read_ready (session)) { clib_bitmap_set_no_check ((uword*)read_map, sid, 1); bits_set++; @@ -2746,7 +2828,7 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, add_event = 1; events[*num_ev].events |= EPOLLOUT; session_evt_data = session->vep.ev.data.u64; - if (session->session_state & STATE_FAILED) + if (session->session_state & STATE_DETACHED) events[*num_ev].events |= EPOLLHUP; break; case SESSION_CTRL_EVT_DISCONNECTED: @@ -2755,8 +2837,6 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, if (!session) break; session_events = session->vep.ev.events; - if (!((EPOLLHUP | EPOLLRDHUP) & session_events)) - break; add_event = 1; events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; session_evt_data = session->vep.ev.data.u64; @@ -2766,8 +2846,6 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, if (!(session = vcl_session_get (wrk, sid))) break; session_events = session->vep.ev.events; - if (!((EPOLLHUP | EPOLLRDHUP) & session_events)) - break; add_event = 1; events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; session_evt_data = session->vep.ev.data.u64; @@ -2778,6 +2856,9 @@ vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, case SESSION_CTRL_EVT_MIGRATED: vcl_session_migrated_handler (wrk, e->data); break; + case SESSION_CTRL_EVT_CLEANUP: + vcl_session_cleanup_handler (wrk, e->data); + break; case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: vcl_session_req_worker_update_handler (wrk, e->data); break; @@ -3149,7 +3230,8 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op, /* VPP-TBD */ *(size_t *) buffer = (session->sndbuf_size ? session->sndbuf_size : - session->tx_fifo ? session->tx_fifo->nitems : + session->tx_fifo ? + svm_fifo_size (session->tx_fifo) : vcm->cfg.tx_fifo_size); *buflen = sizeof (u32); @@ -3180,7 +3262,8 @@ vppcom_session_attr (uint32_t session_handle, uint32_t op, /* VPP-TBD */ *(size_t *) buffer = (session->rcvbuf_size ? session->rcvbuf_size : - session->rx_fifo ? session->rx_fifo->nitems : + session->rx_fifo ? + svm_fifo_size (session->rx_fifo) : vcm->cfg.rx_fifo_size); *buflen = sizeof (u32); @@ -3522,20 +3605,8 @@ vppcom_session_recvfrom (uint32_t session_handle, void *buffer, uint32_t buflen, int flags, vppcom_endpt_t * ep) { vcl_worker_t *wrk = vcl_worker_get_current (); + vcl_session_t *session; int rv = VPPCOM_OK; - vcl_session_t *session = 0; - - if (ep) - { - session = vcl_session_get_w_handle (wrk, session_handle); - if (PREDICT_FALSE (!session)) - { - VDBG (0, "sh 0x%llx is closed!", session_handle); - return VPPCOM_EBADFD; - } - ep->is_ip4 = session->transport.is_ip4; - ep->port = session->transport.rmt_port; - } if (flags == 0) rv = vppcom_session_read (session_handle, buffer, buflen); @@ -3547,14 +3618,17 @@ vppcom_session_recvfrom (uint32_t session_handle, void *buffer, return VPPCOM_EAFNOSUPPORT; } - if (ep) + if (ep && rv > 0) { + session = vcl_session_get_w_handle (wrk, session_handle); if (session->transport.is_ip4) clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip4, sizeof (ip4_address_t)); else clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip6, sizeof (ip6_address_t)); + ep->is_ip4 = session->transport.is_ip4; + ep->port = session->transport.rmt_port; } return rv; @@ -3564,13 +3638,33 @@ int vppcom_session_sendto (uint32_t session_handle, void *buffer, uint32_t buflen, int flags, vppcom_endpt_t * ep) { + vcl_worker_t *wrk = vcl_worker_get_current (); + vcl_session_t *s; + + s = vcl_session_get_w_handle (wrk, session_handle); + if (!s) + return VPPCOM_EBADFD; + if (!buffer) return VPPCOM_EINVAL; if (ep) { - // TBD - return VPPCOM_EINVAL; + if (s->session_type != VPPCOM_PROTO_UDP + || (s->flags & VCL_SESSION_F_CONNECTED)) + return VPPCOM_EINVAL; + + /* Session not connected/bound in vpp. Create it by 'connecting' it */ + if (PREDICT_FALSE (s->session_state == STATE_CLOSED)) + { + vcl_send_session_connect (wrk, s); + } + else + { + 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) @@ -3579,7 +3673,8 @@ vppcom_session_sendto (uint32_t session_handle, void *buffer, VDBG (2, "handling flags 0x%u (%d) not implemented yet.", flags, flags); } - return (vppcom_session_write_inline (session_handle, buffer, buflen, 1)); + return (vppcom_session_write_inline (wrk, s, buffer, buflen, 1, + s->is_dgram ? 1 : 0)); } int @@ -3735,6 +3830,12 @@ vppcom_worker_unregister (void) vcl_set_worker_index (~0); } +void +vppcom_worker_index_set (int index) +{ + vcl_set_worker_index (index); +} + int vppcom_worker_index (void) {