Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | /* |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 18 | #include <svm/svm_fifo_segment.h> |
Dave Wallace | 5c7cf1c | 2017-10-24 04:12:18 -0400 | [diff] [blame] | 19 | #include <vcl/vppcom.h> |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 20 | #include <vcl/vcl_event.h> |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 21 | #include <vcl/vcl_debug.h> |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 22 | #include <vcl/vcl_private.h> |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 23 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 24 | __thread uword __vcl_worker_index = ~0; |
| 25 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 26 | static u8 not_ready; |
| 27 | |
| 28 | void |
| 29 | sigsegv_signal (int signum) |
| 30 | { |
| 31 | not_ready = 1; |
| 32 | } |
| 33 | |
| 34 | static void |
| 35 | vcl_wait_for_memory (void *mem) |
| 36 | { |
| 37 | u8 __clib_unused test; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 38 | if (vcm->mounting_segment) |
| 39 | { |
| 40 | while (vcm->mounting_segment) |
| 41 | ; |
| 42 | return; |
| 43 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 44 | if (1 || vcm->debug) |
| 45 | { |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 46 | usleep (1e5); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | if (signal (SIGSEGV, sigsegv_signal)) |
| 50 | { |
| 51 | perror ("signal()"); |
| 52 | return; |
| 53 | } |
| 54 | not_ready = 0; |
| 55 | |
| 56 | again: |
| 57 | test = *(u8 *) mem; |
| 58 | if (not_ready) |
| 59 | { |
| 60 | not_ready = 0; |
| 61 | usleep (1); |
| 62 | goto again; |
| 63 | } |
| 64 | |
| 65 | signal (SIGSEGV, SIG_DFL); |
| 66 | } |
| 67 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 68 | const char * |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 69 | vppcom_session_state_str (session_state_t state) |
| 70 | { |
| 71 | char *st; |
| 72 | |
| 73 | switch (state) |
| 74 | { |
| 75 | case STATE_START: |
| 76 | st = "STATE_START"; |
| 77 | break; |
| 78 | |
| 79 | case STATE_CONNECT: |
| 80 | st = "STATE_CONNECT"; |
| 81 | break; |
| 82 | |
| 83 | case STATE_LISTEN: |
| 84 | st = "STATE_LISTEN"; |
| 85 | break; |
| 86 | |
| 87 | case STATE_ACCEPT: |
| 88 | st = "STATE_ACCEPT"; |
| 89 | break; |
| 90 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 91 | case STATE_CLOSE_ON_EMPTY: |
| 92 | st = "STATE_CLOSE_ON_EMPTY"; |
| 93 | break; |
| 94 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 95 | case STATE_DISCONNECT: |
| 96 | st = "STATE_DISCONNECT"; |
| 97 | break; |
| 98 | |
| 99 | case STATE_FAILED: |
| 100 | st = "STATE_FAILED"; |
| 101 | break; |
| 102 | |
| 103 | default: |
| 104 | st = "UNKNOWN_STATE"; |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | return st; |
| 109 | } |
| 110 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 111 | u8 * |
| 112 | format_ip4_address (u8 * s, va_list * args) |
| 113 | { |
| 114 | u8 *a = va_arg (*args, u8 *); |
| 115 | return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); |
| 116 | } |
| 117 | |
| 118 | u8 * |
| 119 | format_ip6_address (u8 * s, va_list * args) |
| 120 | { |
| 121 | ip6_address_t *a = va_arg (*args, ip6_address_t *); |
| 122 | u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon; |
| 123 | |
| 124 | i_max_n_zero = ARRAY_LEN (a->as_u16); |
| 125 | max_n_zeros = 0; |
| 126 | i_first_zero = i_max_n_zero; |
| 127 | n_zeros = 0; |
| 128 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 129 | { |
| 130 | u32 is_zero = a->as_u16[i] == 0; |
| 131 | if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16)) |
| 132 | { |
| 133 | i_first_zero = i; |
| 134 | n_zeros = 0; |
| 135 | } |
| 136 | n_zeros += is_zero; |
| 137 | if ((!is_zero && n_zeros > max_n_zeros) |
| 138 | || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros)) |
| 139 | { |
| 140 | i_max_n_zero = i_first_zero; |
| 141 | max_n_zeros = n_zeros; |
| 142 | i_first_zero = ARRAY_LEN (a->as_u16); |
| 143 | n_zeros = 0; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | last_double_colon = 0; |
| 148 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 149 | { |
| 150 | if (i == i_max_n_zero && max_n_zeros > 1) |
| 151 | { |
| 152 | s = format (s, "::"); |
| 153 | i += max_n_zeros - 1; |
| 154 | last_double_colon = 1; |
| 155 | } |
| 156 | else |
| 157 | { |
| 158 | s = format (s, "%s%x", |
| 159 | (last_double_colon || i == 0) ? "" : ":", |
| 160 | clib_net_to_host_u16 (a->as_u16[i])); |
| 161 | last_double_colon = 0; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return s; |
| 166 | } |
| 167 | |
| 168 | /* Format an IP46 address. */ |
| 169 | u8 * |
| 170 | format_ip46_address (u8 * s, va_list * args) |
| 171 | { |
| 172 | ip46_address_t *ip46 = va_arg (*args, ip46_address_t *); |
| 173 | ip46_type_t type = va_arg (*args, ip46_type_t); |
| 174 | int is_ip4 = 1; |
| 175 | |
| 176 | switch (type) |
| 177 | { |
| 178 | case IP46_TYPE_ANY: |
| 179 | is_ip4 = ip46_address_is_ip4 (ip46); |
| 180 | break; |
| 181 | case IP46_TYPE_IP4: |
| 182 | is_ip4 = 1; |
| 183 | break; |
| 184 | case IP46_TYPE_IP6: |
| 185 | is_ip4 = 0; |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | return is_ip4 ? |
| 190 | format (s, "%U", format_ip4_address, &ip46->ip4) : |
| 191 | format (s, "%U", format_ip6_address, &ip46->ip6); |
| 192 | } |
| 193 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 194 | /* |
| 195 | * VPPCOM Utility Functions |
| 196 | */ |
| 197 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 198 | |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 199 | static svm_msg_q_t * |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 200 | vcl_session_vpp_evt_q (vcl_worker_t * wrk, vcl_session_t * s) |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 201 | { |
| 202 | if (vcl_session_is_ct (s)) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 203 | return wrk->vpp_event_queues[0]; |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 204 | else |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 205 | return wrk->vpp_event_queues[s->tx_fifo->master_thread_index]; |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 208 | static void |
| 209 | vcl_send_session_accepted_reply (svm_msg_q_t * mq, u32 context, |
| 210 | session_handle_t handle, int retval) |
| 211 | { |
| 212 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 213 | session_accepted_reply_msg_t *rmp; |
| 214 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_ACCEPTED_REPLY); |
| 215 | rmp = (session_accepted_reply_msg_t *) app_evt->evt->data; |
| 216 | rmp->handle = handle; |
| 217 | rmp->context = context; |
| 218 | rmp->retval = retval; |
| 219 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 220 | } |
| 221 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 222 | static void |
| 223 | vcl_send_session_disconnected_reply (svm_msg_q_t * mq, u32 context, |
| 224 | session_handle_t handle, int retval) |
| 225 | { |
| 226 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 227 | session_disconnected_reply_msg_t *rmp; |
| 228 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, |
| 229 | SESSION_CTRL_EVT_DISCONNECTED_REPLY); |
| 230 | rmp = (session_disconnected_reply_msg_t *) app_evt->evt->data; |
| 231 | rmp->handle = handle; |
| 232 | rmp->context = context; |
| 233 | rmp->retval = retval; |
| 234 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 235 | } |
| 236 | |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 237 | static void |
| 238 | vcl_send_session_reset_reply (svm_msg_q_t * mq, u32 context, |
| 239 | session_handle_t handle, int retval) |
| 240 | { |
| 241 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 242 | session_reset_reply_msg_t *rmp; |
| 243 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_RESET_REPLY); |
| 244 | rmp = (session_reset_reply_msg_t *) app_evt->evt->data; |
| 245 | rmp->handle = handle; |
| 246 | rmp->context = context; |
| 247 | rmp->retval = retval; |
| 248 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 249 | } |
| 250 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 251 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 252 | vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 253 | { |
| 254 | vcl_session_t *session, *listen_session; |
| 255 | svm_fifo_t *rx_fifo, *tx_fifo; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 256 | u32 vpp_wrk_index; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 257 | svm_msg_q_t *evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 258 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 259 | session = vcl_session_alloc (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 260 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 261 | listen_session = vcl_session_table_lookup_listener (wrk, |
| 262 | mp->listener_handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 263 | if (!listen_session) |
| 264 | { |
| 265 | svm_msg_q_t *evt_q; |
| 266 | evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *); |
| 267 | clib_warning ("VCL<%d>: ERROR: couldn't find listen session: " |
| 268 | "unknown vpp listener handle %llx", |
| 269 | getpid (), mp->listener_handle); |
| 270 | vcl_send_session_accepted_reply (evt_q, mp->context, mp->handle, |
| 271 | VNET_API_ERROR_INVALID_ARGUMENT); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 272 | vcl_session_free (wrk, session); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 273 | return VCL_INVALID_SESSION_INDEX; |
| 274 | } |
| 275 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 276 | rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
| 277 | tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
| 278 | |
| 279 | if (mp->server_event_queue_address) |
| 280 | { |
| 281 | session->vpp_evt_q = uword_to_pointer (mp->client_event_queue_address, |
| 282 | svm_msg_q_t *); |
| 283 | session->our_evt_q = uword_to_pointer (mp->server_event_queue_address, |
| 284 | svm_msg_q_t *); |
| 285 | vcl_wait_for_memory (session->vpp_evt_q); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 286 | rx_fifo->master_session_index = session->session_index; |
| 287 | tx_fifo->master_session_index = session->session_index; |
| 288 | vec_validate (wrk->vpp_event_queues, 0); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 289 | evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 290 | wrk->vpp_event_queues[0] = evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 291 | } |
| 292 | else |
| 293 | { |
| 294 | session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address, |
| 295 | svm_msg_q_t *); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 296 | rx_fifo->client_session_index = session->session_index; |
| 297 | tx_fifo->client_session_index = session->session_index; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 298 | |
| 299 | vpp_wrk_index = tx_fifo->master_thread_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 300 | vec_validate (wrk->vpp_event_queues, vpp_wrk_index); |
| 301 | wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | session->vpp_handle = mp->handle; |
| 305 | session->client_context = mp->context; |
| 306 | session->rx_fifo = rx_fifo; |
| 307 | session->tx_fifo = tx_fifo; |
| 308 | |
| 309 | session->session_state = STATE_ACCEPT; |
| 310 | session->transport.rmt_port = mp->port; |
| 311 | session->transport.is_ip4 = mp->is_ip4; |
| 312 | clib_memcpy (&session->transport.rmt_ip, mp->ip, sizeof (ip46_address_t)); |
| 313 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 314 | vcl_session_table_add_vpp_handle (wrk, mp->handle, session->session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 315 | session->transport.lcl_port = listen_session->transport.lcl_port; |
| 316 | session->transport.lcl_ip = listen_session->transport.lcl_ip; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 317 | session->session_type = listen_session->session_type; |
| 318 | session->is_dgram = session->session_type == VPPCOM_PROTO_UDP; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 319 | |
| 320 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: client accept request from %s" |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 321 | " address %U port %d queue %p!", getpid (), mp->handle, |
| 322 | session->session_index, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 323 | mp->is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &mp->ip, |
| 324 | mp->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 325 | clib_net_to_host_u16 (mp->port), session->vpp_evt_q); |
| 326 | vcl_evt (VCL_EVT_ACCEPT, session, listen_session, session_index); |
| 327 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 328 | return session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 332 | vcl_session_connected_handler (vcl_worker_t * wrk, |
| 333 | session_connected_msg_t * mp) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 334 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 335 | u32 session_index, vpp_wrk_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 336 | svm_fifo_t *rx_fifo, *tx_fifo; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 337 | vcl_session_t *session = 0; |
| 338 | svm_msg_q_t *evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 339 | |
| 340 | session_index = mp->context; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 341 | session = vcl_session_get (wrk, session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 342 | if (!session) |
| 343 | { |
| 344 | clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: " |
| 345 | "Invalid session index (%u)!", |
| 346 | getpid (), mp->handle, session_index); |
| 347 | return VCL_INVALID_SESSION_INDEX; |
| 348 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 349 | if (mp->retval) |
| 350 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 351 | clib_warning ("VCL<%d>: ERROR: sid %u: connect failed! %U", getpid (), |
| 352 | mp->handle, session_index, format_api_error, |
| 353 | ntohl (mp->retval)); |
| 354 | session->session_state = STATE_FAILED; |
| 355 | session->vpp_handle = mp->handle; |
| 356 | return session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 359 | rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
| 360 | tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
| 361 | vcl_wait_for_memory (rx_fifo); |
| 362 | rx_fifo->client_session_index = session_index; |
| 363 | tx_fifo->client_session_index = session_index; |
| 364 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 365 | if (mp->client_event_queue_address) |
| 366 | { |
| 367 | session->vpp_evt_q = uword_to_pointer (mp->server_event_queue_address, |
| 368 | svm_msg_q_t *); |
| 369 | session->our_evt_q = uword_to_pointer (mp->client_event_queue_address, |
| 370 | svm_msg_q_t *); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 371 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 372 | vec_validate (wrk->vpp_event_queues, 0); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 373 | evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 374 | wrk->vpp_event_queues[0] = evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 375 | } |
| 376 | else |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 377 | { |
| 378 | session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address, |
| 379 | svm_msg_q_t *); |
| 380 | vpp_wrk_index = tx_fifo->master_thread_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 381 | vec_validate (wrk->vpp_event_queues, vpp_wrk_index); |
| 382 | wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 383 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 384 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 385 | session->rx_fifo = rx_fifo; |
| 386 | session->tx_fifo = tx_fifo; |
| 387 | session->vpp_handle = mp->handle; |
| 388 | session->transport.is_ip4 = mp->is_ip4; |
| 389 | clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip, |
| 390 | sizeof (session->transport.lcl_ip)); |
| 391 | session->transport.lcl_port = mp->lcl_port; |
| 392 | session->session_state = STATE_CONNECT; |
| 393 | |
| 394 | /* Add it to lookup table */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 395 | hash_set (wrk->session_index_by_vpp_handles, mp->handle, session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 396 | |
| 397 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: connect succeeded! " |
| 398 | "session_rx_fifo %p, refcnt %d, session_tx_fifo %p, refcnt %d", |
| 399 | getpid (), mp->handle, session_index, session->rx_fifo, |
| 400 | session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 401 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 402 | return session_index; |
| 403 | } |
| 404 | |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 405 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 406 | vcl_session_reset_handler (vcl_worker_t * wrk, |
| 407 | session_reset_msg_t * reset_msg) |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 408 | { |
| 409 | vcl_session_t *session; |
| 410 | u32 sid; |
| 411 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 412 | sid = vcl_session_index_from_vpp_handle (wrk, reset_msg->handle); |
| 413 | session = vcl_session_get (wrk, sid); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 414 | if (!session) |
| 415 | { |
| 416 | VDBG (0, "request to reset unknown handle 0x%llx", reset_msg->handle); |
| 417 | return VCL_INVALID_SESSION_INDEX; |
| 418 | } |
| 419 | session->session_state = STATE_CLOSE_ON_EMPTY; |
| 420 | VDBG (0, "reset handle 0x%llx, sid %u ", reset_msg->handle, sid); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 421 | vcl_send_session_reset_reply (vcl_session_vpp_evt_q (wrk, session), |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 422 | vcm->my_client_index, reset_msg->handle, 0); |
| 423 | return sid; |
| 424 | } |
| 425 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 426 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 427 | vcl_session_bound_handler (vcl_worker_t * wrk, session_bound_msg_t * mp) |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 428 | { |
| 429 | vcl_session_t *session; |
| 430 | u32 sid = mp->context; |
| 431 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 432 | session = vcl_session_get (wrk, sid); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 433 | if (mp->retval) |
| 434 | { |
| 435 | VDBG (0, "VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: bind failed: %U", |
| 436 | getpid (), mp->handle, sid, format_api_error, ntohl (mp->retval)); |
| 437 | if (session) |
| 438 | { |
| 439 | session->session_state = STATE_FAILED; |
| 440 | session->vpp_handle = mp->handle; |
| 441 | return sid; |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | clib_warning ("[%s] ERROR: vpp handle 0x%llx, sid %u: " |
| 446 | "Invalid session index (%u)!", |
| 447 | getpid (), mp->handle, sid); |
| 448 | return VCL_INVALID_SESSION_INDEX; |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | session->vpp_handle = mp->handle; |
| 453 | session->transport.is_ip4 = mp->lcl_is_ip4; |
| 454 | clib_memcpy (&session->transport.lcl_ip, mp->lcl_ip, |
| 455 | sizeof (ip46_address_t)); |
| 456 | session->transport.lcl_port = mp->lcl_port; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 457 | vcl_session_table_add_listener (wrk, mp->handle, sid); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 458 | session->session_state = STATE_LISTEN; |
| 459 | |
| 460 | if (session->is_dgram) |
| 461 | { |
| 462 | svm_fifo_t *rx_fifo, *tx_fifo; |
| 463 | session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); |
| 464 | rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *); |
| 465 | rx_fifo->client_session_index = sid; |
| 466 | tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *); |
| 467 | tx_fifo->client_session_index = sid; |
| 468 | session->rx_fifo = rx_fifo; |
| 469 | session->tx_fifo = tx_fifo; |
| 470 | } |
| 471 | |
| 472 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: bind succeeded!", |
| 473 | getpid (), mp->handle, sid); |
| 474 | return sid; |
| 475 | } |
| 476 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 477 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 478 | vcl_handle_mq_ctrl_event (vcl_worker_t * wrk, session_event_t * e) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 479 | { |
| 480 | session_accepted_msg_t *accepted_msg; |
| 481 | session_disconnected_msg_t *disconnected_msg; |
| 482 | vcl_session_msg_t *vcl_msg; |
| 483 | vcl_session_t *session; |
| 484 | u64 handle; |
| 485 | u32 sid; |
| 486 | |
| 487 | switch (e->event_type) |
| 488 | { |
| 489 | case FIFO_EVENT_APP_RX: |
| 490 | clib_warning ("unhandled rx: sid %u (0x%x)", |
| 491 | e->fifo->client_session_index, |
| 492 | e->fifo->client_session_index); |
| 493 | break; |
| 494 | case SESSION_CTRL_EVT_ACCEPTED: |
| 495 | accepted_msg = (session_accepted_msg_t *) e->data; |
| 496 | handle = accepted_msg->listener_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 497 | session = vcl_session_table_lookup_listener (wrk, handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 498 | if (!session) |
| 499 | { |
| 500 | clib_warning ("VCL<%d>: ERROR: couldn't find listen session:" |
| 501 | "listener handle %llx", getpid (), handle); |
| 502 | break; |
| 503 | } |
| 504 | |
| 505 | clib_fifo_add2 (session->accept_evts_fifo, vcl_msg); |
| 506 | vcl_msg->accepted_msg = *accepted_msg; |
| 507 | break; |
| 508 | case SESSION_CTRL_EVT_CONNECTED: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 509 | vcl_session_connected_handler (wrk, |
| 510 | (session_connected_msg_t *) e->data); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 511 | break; |
| 512 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 513 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 514 | sid = vcl_session_index_from_vpp_handle (wrk, disconnected_msg->handle); |
| 515 | session = vcl_session_get (wrk, sid); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 516 | if (!session) |
| 517 | { |
| 518 | VDBG (0, "request to disconnect unknown handle 0x%llx", |
| 519 | disconnected_msg->handle); |
| 520 | break; |
| 521 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 522 | session->session_state = STATE_DISCONNECT; |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 523 | VDBG (0, "disconnected handle 0xllx, sid %u", disconnected_msg->handle, |
| 524 | sid); |
| 525 | break; |
| 526 | case SESSION_CTRL_EVT_RESET: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 527 | vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 528 | break; |
| 529 | case SESSION_CTRL_EVT_BOUND: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 530 | vcl_session_bound_handler (wrk, (session_bound_msg_t *) e->data); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 531 | break; |
| 532 | default: |
| 533 | clib_warning ("unhandled %u", e->event_type); |
| 534 | } |
| 535 | return VPPCOM_OK; |
| 536 | } |
| 537 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 538 | static inline int |
| 539 | vppcom_wait_for_session_state_change (u32 session_index, |
| 540 | session_state_t state, |
| 541 | f64 wait_for_time) |
| 542 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 543 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 544 | f64 timeout = clib_time_now (&wrk->clib_time) + wait_for_time; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 545 | vcl_session_t *volatile session; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 546 | svm_msg_q_msg_t msg; |
| 547 | session_event_t *e; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 548 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 549 | do |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 550 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 551 | session = vcl_session_get (wrk, session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 552 | if (PREDICT_FALSE (!session)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 553 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 554 | return VPPCOM_EBADFD; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 555 | } |
| 556 | if (session->session_state & state) |
| 557 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 558 | return VPPCOM_OK; |
| 559 | } |
| 560 | if (session->session_state & STATE_FAILED) |
| 561 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 562 | return VPPCOM_ECONNREFUSED; |
| 563 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 564 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 565 | if (svm_msg_q_sub (wrk->app_event_queue, &msg, SVM_Q_NOWAIT, 0)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 566 | continue; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 567 | e = svm_msg_q_msg_data (wrk->app_event_queue, &msg); |
| 568 | vcl_handle_mq_ctrl_event (wrk, e); |
| 569 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 570 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 571 | while (clib_time_now (&wrk->clib_time) < timeout); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 572 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 573 | VDBG (0, "VCL<%d>: timeout waiting for state 0x%x (%s)", getpid (), state, |
| 574 | vppcom_session_state_str (state)); |
| 575 | vcl_evt (VCL_EVT_SESSION_TIMEOUT, session, session_state); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 576 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 577 | return VPPCOM_ETIMEDOUT; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 578 | } |
| 579 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 580 | static int |
| 581 | vppcom_app_session_enable (void) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 582 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 583 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 584 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 585 | if (vcm->app_state != STATE_APP_ENABLED) |
| 586 | { |
| 587 | vppcom_send_session_enable_disable (1 /* is_enabled == TRUE */ ); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 588 | rv = vcl_wait_for_app_state_change (STATE_APP_ENABLED); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 589 | if (PREDICT_FALSE (rv)) |
| 590 | { |
| 591 | VDBG (0, "VCL<%d>: application session enable timed out! " |
| 592 | "returning %d (%s)", getpid (), rv, vppcom_retval_str (rv)); |
| 593 | return rv; |
| 594 | } |
| 595 | } |
| 596 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 597 | } |
| 598 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 599 | static int |
| 600 | vppcom_app_attach (void) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 601 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 602 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 603 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 604 | vppcom_app_send_attach (); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 605 | rv = vcl_wait_for_app_state_change (STATE_APP_ATTACHED); |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 606 | if (PREDICT_FALSE (rv)) |
| 607 | { |
| 608 | VDBG (0, "VCL<%d>: application attach timed out! returning %d (%s)", |
| 609 | getpid (), rv, vppcom_retval_str (rv)); |
| 610 | return rv; |
| 611 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 612 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 613 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static int |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 617 | vppcom_session_unbind (u32 session_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 618 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 619 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 620 | vcl_session_t *session = 0; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 621 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 622 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 623 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 624 | if (!session) |
| 625 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 626 | |
| 627 | vpp_handle = session->vpp_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 628 | vcl_session_table_del_listener (wrk, vpp_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 629 | session->vpp_handle = ~0; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 630 | session->session_state = STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 631 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 632 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending unbind msg! new state" |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 633 | " 0x%x (%s)", getpid (), vpp_handle, session_handle, STATE_DISCONNECT, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 634 | vppcom_session_state_str (STATE_DISCONNECT)); |
| 635 | vcl_evt (VCL_EVT_UNBIND, session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 636 | vppcom_send_unbind_sock (vpp_handle); |
| 637 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 638 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 639 | } |
| 640 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 641 | static int |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 642 | vppcom_session_disconnect (u32 session_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 643 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 644 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 645 | svm_msg_q_t *vpp_evt_q; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 646 | vcl_session_t *session; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 647 | session_state_t state; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 648 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 649 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 650 | session = vcl_session_get_w_handle (wrk, session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 651 | vpp_handle = session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 652 | state = session->session_state; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 653 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 654 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u state 0x%x (%s)", getpid (), |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 655 | vpp_handle, session_handle, state, vppcom_session_state_str (state)); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 656 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 657 | if (PREDICT_FALSE (state & STATE_LISTEN)) |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 658 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 659 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 660 | "Cannot disconnect a listen socket!", |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 661 | getpid (), vpp_handle, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 662 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 663 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 664 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 665 | if (state & STATE_CLOSE_ON_EMPTY) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 666 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 667 | vpp_evt_q = vcl_session_vpp_evt_q (wrk, session); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 668 | vcl_send_session_disconnected_reply (vpp_evt_q, vcm->my_client_index, |
| 669 | vpp_handle, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 670 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect " |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 671 | "REPLY...", getpid (), vpp_handle, session_handle); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 672 | } |
| 673 | else |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 674 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 675 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: sending disconnect...", |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 676 | getpid (), vpp_handle, session_handle); |
| 677 | vppcom_send_disconnect_session (vpp_handle); |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 678 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 679 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 680 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 683 | /* |
| 684 | * VPPCOM Public API functions |
| 685 | */ |
| 686 | int |
| 687 | vppcom_app_create (char *app_name) |
| 688 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 689 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 690 | int rv; |
| 691 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 692 | if (!vcm->is_init) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 693 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 694 | vcm->is_init = 1; |
Dave Barach | 6a5adc3 | 2018-07-04 10:56:23 -0400 | [diff] [blame] | 695 | vppcom_cfg (&vcm->cfg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 696 | vcl_cfg = &vcm->cfg; |
| 697 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 698 | vcm->main_cpu = pthread_self (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 699 | vppcom_init_error_string_table (); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 700 | svm_fifo_segment_main_init (vcl_cfg->segment_baseva, |
| 701 | 20 /* timeout in secs */ ); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 702 | pool_init_fixed (vcm->workers, vcl_cfg->max_workers); |
| 703 | vcl_worker_alloc_and_init (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | if (vcm->my_client_index == ~0) |
| 707 | { |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 708 | /* API hookup and connect to VPP */ |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 709 | vppcom_api_hookup (); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 710 | vcl_elog_init (vcm); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 711 | vcm->app_state = STATE_APP_START; |
| 712 | rv = vppcom_connect_to_vpp (app_name); |
| 713 | if (rv) |
| 714 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 715 | clib_warning ("VCL<%d>: ERROR: couldn't connect to VPP!", |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 716 | getpid ()); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 717 | return rv; |
| 718 | } |
| 719 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 720 | VDBG (0, "VCL<%d>: sending session enable", getpid ()); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 721 | rv = vppcom_app_session_enable (); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 722 | if (rv) |
| 723 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 724 | clib_warning ("VCL<%d>: ERROR: vppcom_app_session_enable() " |
| 725 | "failed!", getpid ()); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 726 | return rv; |
| 727 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 728 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 729 | VDBG (0, "VCL<%d>: sending app attach", getpid ()); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 730 | rv = vppcom_app_attach (); |
| 731 | if (rv) |
| 732 | { |
| 733 | clib_warning ("VCL<%d>: ERROR: vppcom_app_attach() failed!", |
| 734 | getpid ()); |
| 735 | return rv; |
| 736 | } |
| 737 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 738 | VDBG (0, "VCL<%d>: app_name '%s', my_client_index %d (0x%x)", |
| 739 | getpid (), app_name, vcm->my_client_index, vcm->my_client_index); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 740 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 741 | |
| 742 | return VPPCOM_OK; |
| 743 | } |
| 744 | |
| 745 | void |
| 746 | vppcom_app_destroy (void) |
| 747 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 748 | int rv; |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 749 | f64 orig_app_timeout; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 750 | |
| 751 | if (vcm->my_client_index == ~0) |
| 752 | return; |
| 753 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 754 | VDBG (0, "VCL<%d>: detaching from VPP, my_client_index %d (0x%x)", |
| 755 | getpid (), vcm->my_client_index, vcm->my_client_index); |
| 756 | vcl_evt (VCL_EVT_DETACH, vcm); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 757 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 758 | vppcom_app_send_detach (); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 759 | orig_app_timeout = vcm->cfg.app_timeout; |
| 760 | vcm->cfg.app_timeout = 2.0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 761 | rv = vcl_wait_for_app_state_change (STATE_APP_ENABLED); |
Dave Wallace | de91006 | 2018-03-20 09:22:13 -0400 | [diff] [blame] | 762 | vcm->cfg.app_timeout = orig_app_timeout; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 763 | if (PREDICT_FALSE (rv)) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 764 | VDBG (0, "VCL<%d>: application detach timed out! returning %d (%s)", |
| 765 | getpid (), rv, vppcom_retval_str (rv)); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 766 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 767 | vcl_elog_stop (vcm); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 768 | vl_client_disconnect_from_vlib (); |
| 769 | vcm->my_client_index = ~0; |
| 770 | vcm->app_state = STATE_APP_START; |
| 771 | } |
| 772 | |
| 773 | int |
Dave Wallace | c04cbf1 | 2018-02-07 18:14:02 -0500 | [diff] [blame] | 774 | vppcom_session_create (u8 proto, u8 is_nonblocking) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 775 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 776 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 777 | vcl_session_t *session; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 778 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 779 | session = vcl_session_alloc (wrk); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 780 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 781 | session->session_type = proto; |
| 782 | session->session_state = STATE_START; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 783 | session->vpp_handle = ~0; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 784 | session->is_dgram = proto == VPPCOM_PROTO_UDP; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 785 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 786 | if (is_nonblocking) |
| 787 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_NONBLOCK); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 788 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 789 | vcl_evt (VCL_EVT_CREATE, session, session_type, session->session_state, |
| 790 | is_nonblocking, session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 791 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 792 | VDBG (0, "VCL<%d>: sid %u", getpid (), session->session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 793 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 794 | return vcl_session_handle (session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 798 | vppcom_session_close (uint32_t session_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 799 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 800 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 801 | vcl_session_t *session = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 802 | u8 is_vep, is_vep_session; |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 803 | session_state_t state; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 804 | u32 next_sh, vep_sh; |
| 805 | int rv = VPPCOM_OK; |
| 806 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 807 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 808 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 809 | if (!session) |
| 810 | return VPPCOM_EBADFD; |
| 811 | |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 812 | is_vep = session->is_vep; |
| 813 | is_vep_session = session->is_vep_session; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 814 | next_sh = session->vep.next_sh; |
| 815 | vep_sh = session->vep.vep_sh; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 816 | state = session->session_state; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 817 | vpp_handle = session->vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 818 | |
| 819 | if (VPPCOM_DEBUG > 0) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 820 | { |
| 821 | if (is_vep) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 822 | clib_warning ("VCL<%d>: vep_idx %u / sid %u: " |
| 823 | "closing epoll session...", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 824 | getpid (), session_handle, session_handle); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 825 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 826 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %d: " |
| 827 | "closing session...", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 828 | getpid (), vpp_handle, session_handle); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 829 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 830 | |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 831 | if (is_vep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 832 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 833 | while (next_sh != ~0) |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 834 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 835 | rv = vppcom_epoll_ctl (session_handle, EPOLL_CTL_DEL, next_sh, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 836 | if (PREDICT_FALSE (rv < 0)) |
| 837 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: EPOLL_CTL_DEL " |
| 838 | "vep_idx %u failed! rv %d (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 839 | getpid (), vpp_handle, next_sh, vep_sh, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 840 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 841 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 842 | next_sh = session->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | else |
| 846 | { |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 847 | if (is_vep_session) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 848 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 849 | rv = vppcom_epoll_ctl (vep_sh, EPOLL_CTL_DEL, session_handle, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 850 | if (rv < 0) |
| 851 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: EPOLL_CTL_DEL " |
| 852 | "vep_idx %u failed! rv %d (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 853 | getpid (), vpp_handle, session_handle, |
| 854 | vep_sh, rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 855 | } |
| 856 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 857 | if (state & STATE_LISTEN) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 858 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 859 | rv = vppcom_session_unbind (session_handle); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 860 | if (PREDICT_FALSE (rv < 0)) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 861 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: listener unbind " |
| 862 | "failed! rv %d (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 863 | getpid (), vpp_handle, session_handle, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 864 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 865 | } |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 866 | else if (state & STATE_OPEN) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 867 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 868 | rv = vppcom_session_disconnect (session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 869 | if (PREDICT_FALSE (rv < 0)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 870 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 871 | "session disconnect failed! rv %d (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 872 | getpid (), vpp_handle, session_handle, |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 873 | rv, vppcom_retval_str (rv)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 874 | } |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 875 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 876 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 877 | if (vcl_session_is_ct (session)) |
| 878 | { |
| 879 | vcl_cut_through_registration_t *ctr; |
| 880 | uword mq_addr; |
| 881 | |
| 882 | mq_addr = pointer_to_uword (session->our_evt_q); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 883 | ctr = vcl_ct_registration_lock_and_lookup (wrk, mq_addr); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 884 | ASSERT (ctr); |
| 885 | if (ctr->epoll_evt_conn_index != ~0) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 886 | vcl_mq_epoll_del_evfd (wrk, ctr->epoll_evt_conn_index); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 887 | VDBG (0, "Removing ct registration %u", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 888 | vcl_ct_registration_index (wrk, ctr)); |
| 889 | vcl_ct_registration_del (wrk, ctr); |
| 890 | vcl_ct_registration_lookup_del (wrk, mq_addr); |
| 891 | vcl_ct_registration_unlock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 892 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 893 | |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 894 | if (vpp_handle != ~0) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 895 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 896 | vcl_session_table_del_vpp_handle (wrk, vpp_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 897 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 898 | vcl_session_free (wrk, session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 899 | |
| 900 | if (VPPCOM_DEBUG > 0) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 901 | { |
| 902 | if (is_vep) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 903 | clib_warning ("VCL<%d>: vep_idx %u / sid %u: epoll session removed.", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 904 | getpid (), session_handle, session_handle); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 905 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 906 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: session removed.", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 907 | getpid (), vpp_handle, session_handle); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 908 | } |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 909 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 910 | vcl_evt (VCL_EVT_CLOSE, session, rv); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 911 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 912 | return rv; |
| 913 | } |
| 914 | |
| 915 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 916 | vppcom_session_bind (uint32_t session_handle, vppcom_endpt_t * ep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 917 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 918 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 919 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 920 | |
| 921 | if (!ep || !ep->ip) |
| 922 | return VPPCOM_EINVAL; |
| 923 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 924 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 925 | if (!session) |
| 926 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 927 | |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 928 | if (session->is_vep) |
| 929 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 930 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 931 | "bind to an epoll session!", getpid (), session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 932 | return VPPCOM_EBADFD; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 933 | } |
| 934 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 935 | session->transport.is_ip4 = ep->is_ip4; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 936 | if (ep->is_ip4) |
| 937 | clib_memcpy (&session->transport.lcl_ip.ip4, ep->ip, |
| 938 | sizeof (ip4_address_t)); |
| 939 | else |
| 940 | clib_memcpy (&session->transport.lcl_ip.ip6, ep->ip, |
| 941 | sizeof (ip6_address_t)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 942 | session->transport.lcl_port = ep->port; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 943 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 944 | VDBG (0, "VCL<%d>: sid %u: binding to local %s address %U port %u, " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 945 | "proto %s", getpid (), session_handle, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 946 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 947 | format_ip46_address, &session->transport.lcl_ip, |
| 948 | session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 949 | clib_net_to_host_u16 (session->transport.lcl_port), |
| 950 | session->session_type ? "UDP" : "TCP"); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 951 | vcl_evt (VCL_EVT_BIND, session); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 952 | |
| 953 | if (session->session_type == VPPCOM_PROTO_UDP) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 954 | vppcom_session_listen (session_handle, 10); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 955 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 956 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 960 | vppcom_session_listen (uint32_t listen_sh, uint32_t q_len) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 961 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 962 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 963 | vcl_session_t *listen_session = 0; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 964 | u64 listen_vpp_handle; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 965 | int rv; |
| 966 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 967 | listen_session = vcl_session_get_w_handle (wrk, listen_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 968 | if (!listen_session) |
| 969 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 970 | |
Keith Burns (alagalah) | aba98de | 2018-02-22 03:23:40 -0800 | [diff] [blame] | 971 | if (q_len == 0 || q_len == ~0) |
| 972 | q_len = vcm->cfg.listen_queue_size; |
| 973 | |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 974 | if (listen_session->is_vep) |
| 975 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 976 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot listen on an " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 977 | "epoll session!", getpid (), listen_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 978 | return VPPCOM_EBADFD; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 979 | } |
| 980 | |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 981 | listen_vpp_handle = listen_session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 982 | if (listen_session->session_state & STATE_LISTEN) |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 983 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 984 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: already in listen state!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 985 | getpid (), listen_vpp_handle, listen_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 986 | return VPPCOM_OK; |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 989 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: sending VPP bind+listen " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 990 | "request...", getpid (), listen_vpp_handle, listen_sh); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 991 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 992 | /* |
| 993 | * Send listen request to vpp and wait for reply |
| 994 | */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 995 | vppcom_send_bind_sock (listen_session); |
| 996 | rv = vppcom_wait_for_session_state_change (listen_session->session_index, |
| 997 | STATE_LISTEN, |
| 998 | vcm->cfg.session_timeout); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 999 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1000 | if (PREDICT_FALSE (rv)) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1001 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1002 | listen_session = vcl_session_get_w_handle (wrk, listen_sh); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1003 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: bind+listen failed! " |
| 1004 | "returning %d (%s)", getpid (), listen_session->vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1005 | listen_sh, rv, vppcom_retval_str (rv)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1006 | return rv; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1007 | } |
| 1008 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1009 | return VPPCOM_OK; |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1012 | static int |
| 1013 | validate_args_session_accept_ (vcl_worker_t * wrk, |
| 1014 | vcl_session_t * listen_session) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1015 | { |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1016 | /* Input validation - expects spinlock on sessions_lockp */ |
| 1017 | if (listen_session->is_vep) |
| 1018 | { |
| 1019 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot accept on an " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1020 | "epoll session!", getpid (), |
| 1021 | listen_session->session_index); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1022 | return VPPCOM_EBADFD; |
| 1023 | } |
| 1024 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1025 | if (listen_session->session_state != STATE_LISTEN) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1026 | { |
| 1027 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
| 1028 | "not in listen state! state 0x%x (%s)", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1029 | listen_session->vpp_handle, listen_session->session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1030 | listen_session->session_state, |
| 1031 | vppcom_session_state_str (listen_session->session_state)); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1032 | return VPPCOM_EBADFD; |
| 1033 | } |
| 1034 | return VPPCOM_OK; |
| 1035 | } |
| 1036 | |
| 1037 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1038 | vppcom_session_accept (uint32_t listen_session_handle, vppcom_endpt_t * ep, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1039 | uint32_t flags) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1040 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1041 | u32 client_session_index = ~0, listen_session_index; |
| 1042 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1043 | session_accepted_msg_t accepted_msg; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1044 | vcl_session_t *listen_session = 0; |
| 1045 | vcl_session_t *client_session = 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1046 | svm_msg_q_t *vpp_evt_q; |
| 1047 | vcl_session_msg_t *evt; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1048 | u64 listen_vpp_handle; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1049 | svm_msg_q_msg_t msg; |
| 1050 | session_event_t *e; |
| 1051 | u8 is_nonblocking; |
| 1052 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1053 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1054 | listen_session = vcl_session_get_w_handle (wrk, listen_session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1055 | if (!listen_session) |
| 1056 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1057 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1058 | listen_session_index = listen_session->session_index; |
| 1059 | if ((rv = validate_args_session_accept_ (wrk, listen_session))) |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1060 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1061 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1062 | if (clib_fifo_elts (listen_session->accept_evts_fifo)) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1063 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1064 | clib_fifo_sub2 (listen_session->accept_evts_fifo, evt); |
| 1065 | accepted_msg = evt->accepted_msg; |
| 1066 | goto handle; |
| 1067 | } |
| 1068 | |
| 1069 | is_nonblocking = VCL_SESS_ATTR_TEST (listen_session->attr, |
| 1070 | VCL_SESS_ATTR_NONBLOCK); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1071 | if (svm_msg_q_is_empty (wrk->app_event_queue) && is_nonblocking) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1072 | return VPPCOM_EAGAIN; |
| 1073 | |
| 1074 | while (1) |
| 1075 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1076 | if (svm_msg_q_sub (wrk->app_event_queue, &msg, SVM_Q_WAIT, 0)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1077 | return VPPCOM_EAGAIN; |
| 1078 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1079 | e = svm_msg_q_msg_data (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1080 | if (e->event_type != SESSION_CTRL_EVT_ACCEPTED) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1081 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1082 | clib_warning ("discarded event: %u", e->event_type); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1083 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1084 | continue; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1085 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1086 | clib_memcpy (&accepted_msg, e->data, sizeof (accepted_msg)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1087 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1088 | break; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1089 | } |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1090 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1091 | handle: |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 1092 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1093 | client_session_index = vcl_session_accepted_handler (wrk, &accepted_msg); |
| 1094 | listen_session = vcl_session_get (wrk, listen_session_index); |
| 1095 | client_session = vcl_session_get (wrk, client_session_index); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1096 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1097 | if (flags & O_NONBLOCK) |
| 1098 | VCL_SESS_ATTR_SET (client_session->attr, VCL_SESS_ATTR_NONBLOCK); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1099 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1100 | listen_vpp_handle = listen_session->vpp_handle; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1101 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: Got a client request! " |
| 1102 | "vpp handle 0x%llx, sid %u, flags %d, is_nonblocking %u", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1103 | getpid (), listen_vpp_handle, listen_session_handle, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1104 | client_session->vpp_handle, client_session_index, |
| 1105 | flags, VCL_SESS_ATTR_TEST (client_session->attr, |
| 1106 | VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1107 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1108 | if (ep) |
| 1109 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1110 | ep->is_ip4 = client_session->transport.is_ip4; |
| 1111 | ep->port = client_session->transport.rmt_port; |
| 1112 | if (client_session->transport.is_ip4) |
| 1113 | clib_memcpy (ep->ip, &client_session->transport.rmt_ip.ip4, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1114 | sizeof (ip4_address_t)); |
| 1115 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1116 | clib_memcpy (ep->ip, &client_session->transport.rmt_ip.ip6, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1117 | sizeof (ip6_address_t)); |
| 1118 | } |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1119 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1120 | if (accepted_msg.server_event_queue_address) |
| 1121 | vpp_evt_q = uword_to_pointer (accepted_msg.vpp_event_queue_address, |
| 1122 | svm_msg_q_t *); |
| 1123 | else |
| 1124 | vpp_evt_q = client_session->vpp_evt_q; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1125 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1126 | vcl_send_session_accepted_reply (vpp_evt_q, client_session->client_context, |
| 1127 | client_session->vpp_handle, 0); |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1128 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1129 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: accepted vpp handle 0x%llx, " |
| 1130 | "sid %u connection from peer %s address %U port %u to local %s " |
| 1131 | "address %U port %u", getpid (), listen_vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1132 | listen_session_handle, client_session->vpp_handle, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1133 | client_session_index, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1134 | client_session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 1135 | format_ip46_address, &client_session->transport.rmt_ip, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1136 | client_session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1137 | clib_net_to_host_u16 (client_session->transport.rmt_port), |
| 1138 | client_session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 1139 | format_ip46_address, &client_session->transport.lcl_ip, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1140 | client_session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1141 | clib_net_to_host_u16 (client_session->transport.lcl_port)); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1142 | vcl_evt (VCL_EVT_ACCEPT, client_session, listen_session, |
| 1143 | client_session_index); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1144 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1145 | return vcl_session_handle (client_session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1149 | vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1150 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1151 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1152 | vcl_session_t *session = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1153 | u32 session_index; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1154 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1155 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1156 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1157 | if (!session) |
| 1158 | return VPPCOM_EBADFD; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1159 | session_index = session->session_index; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1160 | |
| 1161 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1162 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1163 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1164 | "connect on an epoll session!", getpid (), |
| 1165 | session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1166 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1169 | if (PREDICT_FALSE (session->session_state & CLIENT_STATE_OPEN)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1170 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1171 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: session already " |
| 1172 | "connected to %s %U port %d proto %s, state 0x%x (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1173 | getpid (), session->vpp_handle, session_handle, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1174 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1175 | format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1176 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1177 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1178 | clib_net_to_host_u16 (session->transport.rmt_port), |
| 1179 | session->session_type ? "UDP" : "TCP", session->session_state, |
| 1180 | vppcom_session_state_str (session->session_state)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1181 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1182 | } |
| 1183 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1184 | session->transport.is_ip4 = server_ep->is_ip4; |
| 1185 | if (session->transport.is_ip4) |
| 1186 | clib_memcpy (&session->transport.rmt_ip.ip4, server_ep->ip, |
Dave Wallace | d239f8d | 2018-06-19 13:37:30 -0400 | [diff] [blame] | 1187 | sizeof (ip4_address_t)); |
| 1188 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1189 | clib_memcpy (&session->transport.rmt_ip.ip6, server_ep->ip, |
Dave Wallace | d239f8d | 2018-06-19 13:37:30 -0400 | [diff] [blame] | 1190 | sizeof (ip6_address_t)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1191 | session->transport.rmt_port = server_ep->port; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1192 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1193 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: connecting to server %s %U " |
| 1194 | "port %d proto %s", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1195 | getpid (), session->vpp_handle, session_handle, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1196 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1197 | format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1198 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1199 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1200 | clib_net_to_host_u16 (session->transport.rmt_port), |
| 1201 | session->session_type ? "UDP" : "TCP"); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1202 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1203 | /* |
| 1204 | * Send connect request and wait for reply from vpp |
| 1205 | */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1206 | vppcom_send_connect_sock (session); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1207 | rv = vppcom_wait_for_session_state_change (session_index, STATE_CONNECT, |
| 1208 | vcm->cfg.session_timeout); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1209 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1210 | session = vcl_session_get (wrk, session_index); |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1211 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1212 | if (PREDICT_FALSE (rv)) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1213 | { |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1214 | if (VPPCOM_DEBUG > 0) |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1215 | { |
| 1216 | if (session) |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1217 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: connect " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1218 | "failed! returning %d (%s)", getpid (), |
| 1219 | session->vpp_handle, session_handle, rv, |
| 1220 | vppcom_retval_str (rv)); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1221 | else |
| 1222 | clib_warning ("VCL<%d>: no session for sid %u: connect failed! " |
| 1223 | "returning %d (%s)", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1224 | session_handle, rv, vppcom_retval_str (rv)); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1225 | } |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1226 | } |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1227 | else |
| 1228 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: connected!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1229 | getpid (), session->vpp_handle, session_handle); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1230 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1231 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1234 | static u8 |
| 1235 | vcl_is_rx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct) |
| 1236 | { |
| 1237 | if (!is_ct) |
| 1238 | return (e->event_type == FIFO_EVENT_APP_RX |
| 1239 | && e->fifo->client_session_index == sid); |
| 1240 | else |
| 1241 | return (e->event_type == SESSION_IO_EVT_CT_TX); |
| 1242 | } |
| 1243 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1244 | static inline u8 |
| 1245 | vcl_session_is_readable (vcl_session_t * s) |
| 1246 | { |
| 1247 | return ((s->session_state & STATE_OPEN) |
| 1248 | || (s->session_state == STATE_LISTEN |
| 1249 | && s->session_type == VPPCOM_PROTO_UDP)); |
| 1250 | } |
| 1251 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1252 | static inline int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1253 | vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1254 | u8 peek) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1255 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1256 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1257 | int n_read = 0, rv, is_nonblocking; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1258 | vcl_session_t *s = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1259 | svm_fifo_t *rx_fifo; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1260 | svm_msg_q_msg_t msg; |
| 1261 | session_event_t *e; |
| 1262 | svm_msg_q_t *mq; |
| 1263 | u8 is_full; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1264 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1265 | if (PREDICT_FALSE (!buf)) |
| 1266 | return VPPCOM_EINVAL; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1267 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1268 | s = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1269 | if (PREDICT_FALSE (!s)) |
| 1270 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1271 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1272 | if (PREDICT_FALSE (s->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1273 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1274 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1275 | "read from an epoll session!", getpid (), session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1276 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1277 | } |
| 1278 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1279 | is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK); |
| 1280 | rx_fifo = s->rx_fifo; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1281 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1282 | if (PREDICT_FALSE (!vcl_session_is_readable (s))) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1283 | { |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1284 | session_state_t state = s->session_state; |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1285 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1286 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1287 | VDBG (0, "VCL<%d>: vpp handle 0x%llx, sid %u: %s session is not open! " |
| 1288 | "state 0x%x (%s), returning %d (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1289 | getpid (), s->vpp_handle, session_handle, state, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1290 | vppcom_session_state_str (state), rv, vppcom_retval_str (rv)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1291 | return rv; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1292 | } |
| 1293 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1294 | mq = vcl_session_is_ct (s) ? s->our_evt_q : wrk->app_event_queue; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1295 | svm_fifo_unset_event (rx_fifo); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1296 | is_full = svm_fifo_is_full (rx_fifo); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1297 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1298 | if (svm_fifo_is_empty (rx_fifo)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1299 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1300 | if (is_nonblocking) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1301 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1302 | return VPPCOM_OK; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1303 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1304 | while (1) |
| 1305 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1306 | svm_msg_q_lock (mq); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1307 | if (svm_msg_q_is_empty (mq)) |
| 1308 | svm_msg_q_wait (mq); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1309 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1310 | svm_msg_q_sub_w_lock (mq, &msg); |
| 1311 | e = svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1312 | svm_msg_q_unlock (mq); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1313 | if (!vcl_is_rx_evt_for_session (e, s->session_index, |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1314 | s->our_evt_q != 0)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1315 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1316 | vcl_handle_mq_ctrl_event (wrk, e); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1317 | svm_msg_q_free_msg (mq, &msg); |
| 1318 | continue; |
| 1319 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1320 | svm_fifo_unset_event (rx_fifo); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1321 | svm_msg_q_free_msg (mq, &msg); |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 1322 | if (PREDICT_FALSE (s->session_state == STATE_CLOSE_ON_EMPTY)) |
| 1323 | return 0; |
| 1324 | if (svm_fifo_is_empty (rx_fifo)) |
| 1325 | continue; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1326 | break; |
| 1327 | } |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1328 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1329 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1330 | if (s->is_dgram) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1331 | n_read = app_recv_dgram_raw (rx_fifo, buf, n, &s->transport, 0, peek); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1332 | else |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1333 | n_read = app_recv_stream_raw (rx_fifo, buf, n, 0, peek); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1334 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1335 | if (vcl_session_is_ct (s) && is_full) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1336 | { |
| 1337 | /* If the peer is not polling send notification */ |
| 1338 | if (!svm_fifo_has_event (s->rx_fifo)) |
| 1339 | app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo, |
| 1340 | SESSION_IO_EVT_CT_RX, SVM_Q_WAIT); |
| 1341 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1342 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1343 | if (VPPCOM_DEBUG > 2) |
| 1344 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1345 | if (n_read > 0) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1346 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: read %d bytes " |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1347 | "from (%p)", getpid (), s->vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1348 | session_handle, n_read, rx_fifo); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1349 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1350 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: nothing read! " |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1351 | "returning %d (%s)", getpid (), s->vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1352 | session_handle, n_read, vppcom_retval_str (n_read)); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1353 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1354 | return n_read; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1357 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1358 | vppcom_session_read (uint32_t session_handle, void *buf, size_t n) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1359 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1360 | return (vppcom_session_read_internal (session_handle, buf, n, 0)); |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1364 | vppcom_session_peek (uint32_t session_handle, void *buf, int n) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1365 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1366 | return (vppcom_session_read_internal (session_handle, buf, n, 1)); |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1369 | static inline int |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1370 | vppcom_session_read_ready (vcl_session_t * session) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1371 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1372 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1373 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1374 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1375 | clib_warning ("VCL<%d>: ERROR: sid %u: cannot read from an " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1376 | "epoll session!", getpid (), session->session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1377 | return VPPCOM_EBADFD; |
| 1378 | } |
| 1379 | |
| 1380 | if (PREDICT_FALSE (!(session->session_state & (STATE_OPEN | STATE_LISTEN)))) |
| 1381 | { |
| 1382 | session_state_t state = session->session_state; |
| 1383 | int rv; |
| 1384 | |
| 1385 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
| 1386 | |
| 1387 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open!" |
| 1388 | " state 0x%x (%s), returning %d (%s)", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1389 | session->vpp_handle, session->session_index, state, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1390 | vppcom_session_state_str (state), rv, vppcom_retval_str (rv)); |
| 1391 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1392 | } |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1393 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1394 | if (session->session_state & STATE_LISTEN) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1395 | return clib_fifo_elts (session->accept_evts_fifo); |
| 1396 | |
| 1397 | return svm_fifo_max_dequeue (session->rx_fifo); |
| 1398 | } |
| 1399 | |
| 1400 | static u8 |
| 1401 | vcl_is_tx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct) |
| 1402 | { |
| 1403 | if (!is_ct) |
| 1404 | return (e->event_type == FIFO_EVENT_APP_TX |
| 1405 | && e->fifo->client_session_index == sid); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1406 | else |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1407 | return (e->event_type == SESSION_IO_EVT_CT_RX); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1408 | } |
| 1409 | |
| 1410 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1411 | vppcom_session_write (uint32_t session_handle, void *buf, size_t n) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1412 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1413 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1414 | int rv, n_write, is_nonblocking; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1415 | vcl_session_t *s = 0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1416 | svm_fifo_t *tx_fifo = 0; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1417 | session_evt_type_t et; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1418 | svm_msg_q_msg_t msg; |
| 1419 | session_event_t *e; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 1420 | svm_msg_q_t *mq; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1421 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1422 | if (PREDICT_FALSE (!buf)) |
| 1423 | return VPPCOM_EINVAL; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1424 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1425 | s = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1426 | if (PREDICT_FALSE (!s)) |
| 1427 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1428 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1429 | tx_fifo = s->tx_fifo; |
| 1430 | is_nonblocking = VCL_SESS_ATTR_TEST (s->attr, VCL_SESS_ATTR_NONBLOCK); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1431 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1432 | if (PREDICT_FALSE (s->is_vep)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1433 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1434 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1435 | "cannot write to an epoll session!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1436 | getpid (), s->vpp_handle, session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1437 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1438 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1441 | if (!(s->session_state & STATE_OPEN)) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1442 | { |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1443 | session_state_t state = s->session_state; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1444 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1445 | VDBG (1, "VCL<%d>: vpp handle 0x%llx, sid %u: session is not open! " |
| 1446 | "state 0x%x (%s)", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1447 | getpid (), s->vpp_handle, session_handle, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1448 | state, vppcom_session_state_str (state)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1449 | return rv; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1450 | } |
| 1451 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1452 | mq = vcl_session_is_ct (s) ? s->our_evt_q : wrk->app_event_queue; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1453 | if (svm_fifo_is_full (tx_fifo)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1454 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1455 | if (is_nonblocking) |
| 1456 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1457 | return VPPCOM_EWOULDBLOCK; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1458 | } |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 1459 | while (svm_fifo_is_full (tx_fifo)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1460 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1461 | svm_msg_q_lock (mq); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1462 | while (svm_msg_q_is_empty (mq) && svm_msg_q_timedwait (mq, 10e-6)) |
| 1463 | ; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1464 | svm_msg_q_sub_w_lock (mq, &msg); |
| 1465 | e = svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1466 | svm_msg_q_unlock (mq); |
| 1467 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1468 | if (!vcl_is_tx_evt_for_session (e, s->session_index, |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1469 | s->our_evt_q != 0)) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1470 | vcl_handle_mq_ctrl_event (wrk, e); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1471 | svm_msg_q_free_msg (mq, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1472 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1473 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1474 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1475 | ASSERT (FIFO_EVENT_APP_TX + 1 == SESSION_IO_EVT_CT_TX); |
| 1476 | et = FIFO_EVENT_APP_TX + vcl_session_is_ct (s); |
| 1477 | if (s->is_dgram) |
| 1478 | n_write = app_send_dgram_raw (tx_fifo, &s->transport, |
| 1479 | s->vpp_evt_q, buf, n, et, SVM_Q_WAIT); |
| 1480 | else |
| 1481 | n_write = app_send_stream_raw (tx_fifo, s->vpp_evt_q, buf, n, et, |
| 1482 | SVM_Q_WAIT); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 1483 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1484 | ASSERT (n_write > 0); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1485 | |
| 1486 | if (VPPCOM_DEBUG > 2) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1487 | { |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1488 | if (n_write <= 0) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1489 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: " |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1490 | "FIFO-FULL (%p)", getpid (), s->vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1491 | session_handle, tx_fifo); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1492 | else |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1493 | clib_warning ("VCL<%d>: vpp handle 0x%llx, sid %u: " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1494 | "wrote %d bytes tx-fifo: (%p)", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1495 | s->vpp_handle, session_handle, n_write, tx_fifo); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1496 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1497 | return n_write; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1498 | } |
| 1499 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1500 | static vcl_session_t * |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1501 | vcl_ct_session_get_from_fifo (vcl_worker_t * wrk, svm_fifo_t * f, u8 type) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1502 | { |
| 1503 | vcl_session_t *s; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1504 | s = vcl_session_get (wrk, f->client_session_index); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1505 | if (s) |
| 1506 | { |
| 1507 | /* rx fifo */ |
| 1508 | if (type == 0 && s->rx_fifo == f) |
| 1509 | return s; |
| 1510 | /* tx fifo */ |
| 1511 | if (type == 1 && s->tx_fifo == f) |
| 1512 | return s; |
| 1513 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1514 | s = vcl_session_get (wrk, f->master_session_index); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1515 | if (s) |
| 1516 | { |
| 1517 | if (type == 0 && s->rx_fifo == f) |
| 1518 | return s; |
| 1519 | if (type == 1 && s->tx_fifo == f) |
| 1520 | return s; |
| 1521 | } |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1525 | static inline int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1526 | vppcom_session_write_ready (vcl_session_t * session) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1527 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1528 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1529 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1530 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1531 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1532 | "cannot write to an epoll session!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1533 | getpid (), session->vpp_handle, session->session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1534 | return VPPCOM_EBADFD; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1537 | if (PREDICT_FALSE (session->session_state & STATE_LISTEN)) |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1538 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1539 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1540 | "cannot write to a listen session!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1541 | getpid (), session->vpp_handle, session->session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1542 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1543 | } |
| 1544 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1545 | if (PREDICT_FALSE (!(session->session_state & STATE_OPEN))) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1546 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1547 | session_state_t state = session->session_state; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1548 | int rv; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1549 | |
Keith Burns (alagalah) | 56a0d06 | 2018-02-15 07:52:50 -0800 | [diff] [blame] | 1550 | rv = ((state & STATE_DISCONNECT) ? VPPCOM_ECONNRESET : VPPCOM_ENOTCONN); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1551 | clib_warning ("VCL<%d>: ERROR: vpp handle 0x%llx, sid %u: " |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1552 | "session is not open! state 0x%x (%s), " |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1553 | "returning %d (%s)", getpid (), session->vpp_handle, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1554 | session->session_index, |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1555 | state, vppcom_session_state_str (state), |
| 1556 | rv, vppcom_retval_str (rv)); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1557 | return rv; |
Dave Wallace | 33e002b | 2017-09-06 01:20:02 -0400 | [diff] [blame] | 1558 | } |
| 1559 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1560 | VDBG (3, "VCL<%d>: vpp handle 0x%llx, sid %u: peek %s (%p), ready = %d", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1561 | getpid (), session->vpp_handle, session->session_index, |
| 1562 | session->tx_fifo, svm_fifo_max_enqueue (session->tx_fifo)); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1563 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1564 | return svm_fifo_max_enqueue (session->tx_fifo); |
| 1565 | } |
| 1566 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1567 | static inline int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1568 | vcl_mq_dequeue_batch (vcl_worker_t * wrk, svm_msg_q_t * mq) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1569 | { |
| 1570 | svm_msg_q_msg_t *msg; |
| 1571 | u32 n_msgs; |
| 1572 | int i; |
| 1573 | |
| 1574 | n_msgs = svm_msg_q_size (mq); |
| 1575 | for (i = 0; i < n_msgs; i++) |
| 1576 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1577 | vec_add2 (wrk->mq_msg_vector, msg, 1); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1578 | svm_msg_q_sub_w_lock (mq, msg); |
| 1579 | } |
| 1580 | return n_msgs; |
| 1581 | } |
| 1582 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1583 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1584 | vcl_select_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq, |
| 1585 | unsigned long n_bits, unsigned long *read_map, |
| 1586 | unsigned long *write_map, unsigned long *except_map, |
| 1587 | double time_to_wait, u32 * bits_set) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1588 | { |
| 1589 | session_disconnected_msg_t *disconnected_msg; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1590 | session_connected_msg_t *connected_msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1591 | session_accepted_msg_t *accepted_msg; |
| 1592 | vcl_session_msg_t *vcl_msg; |
| 1593 | vcl_session_t *session; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1594 | svm_msg_q_msg_t *msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1595 | session_event_t *e; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1596 | u32 i, sid; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1597 | u64 handle; |
| 1598 | |
| 1599 | svm_msg_q_lock (mq); |
| 1600 | if (svm_msg_q_is_empty (mq)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1601 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1602 | if (*bits_set) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1603 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1604 | svm_msg_q_unlock (mq); |
| 1605 | return 0; |
| 1606 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1607 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1608 | if (!time_to_wait) |
| 1609 | { |
| 1610 | svm_msg_q_unlock (mq); |
| 1611 | return 0; |
| 1612 | } |
| 1613 | else if (time_to_wait < 0) |
| 1614 | { |
| 1615 | svm_msg_q_wait (mq); |
| 1616 | } |
| 1617 | else |
| 1618 | { |
| 1619 | if (svm_msg_q_timedwait (mq, time_to_wait)) |
| 1620 | { |
| 1621 | svm_msg_q_unlock (mq); |
| 1622 | return 0; |
| 1623 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1624 | } |
| 1625 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1626 | vcl_mq_dequeue_batch (wrk, mq); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1627 | svm_msg_q_unlock (mq); |
| 1628 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1629 | for (i = 0; i < vec_len (wrk->mq_msg_vector); i++) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1630 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1631 | msg = vec_elt_at_index (wrk->mq_msg_vector, i); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1632 | e = svm_msg_q_msg_data (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1633 | switch (e->event_type) |
| 1634 | { |
| 1635 | case FIFO_EVENT_APP_RX: |
| 1636 | sid = e->fifo->client_session_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1637 | session = vcl_session_get (wrk, sid); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1638 | if (!session) |
| 1639 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1640 | if (sid < n_bits && read_map) |
| 1641 | { |
| 1642 | clib_bitmap_set_no_check (read_map, sid, 1); |
| 1643 | *bits_set += 1; |
| 1644 | } |
| 1645 | break; |
| 1646 | case FIFO_EVENT_APP_TX: |
| 1647 | sid = e->fifo->client_session_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1648 | session = vcl_session_get (wrk, sid); |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 1649 | if (!session) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1650 | break; |
| 1651 | if (sid < n_bits && write_map) |
| 1652 | { |
| 1653 | clib_bitmap_set_no_check (write_map, sid, 1); |
| 1654 | *bits_set += 1; |
| 1655 | } |
| 1656 | break; |
| 1657 | case SESSION_IO_EVT_CT_TX: |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1658 | if (svm_fifo_is_empty (e->fifo)) |
| 1659 | { |
| 1660 | svm_fifo_unset_event (e->fifo); |
| 1661 | if (svm_fifo_is_empty (e->fifo)) |
| 1662 | break; |
| 1663 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1664 | session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1665 | if (!session) |
| 1666 | break; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1667 | sid = session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1668 | if (sid < n_bits && read_map) |
| 1669 | { |
| 1670 | clib_bitmap_set_no_check (read_map, sid, 1); |
| 1671 | *bits_set += 1; |
| 1672 | } |
| 1673 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1674 | case SESSION_IO_EVT_CT_RX: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1675 | session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 1); |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 1676 | if (!session) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1677 | break; |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 1678 | sid = session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1679 | if (sid < n_bits && write_map) |
| 1680 | { |
| 1681 | clib_bitmap_set_no_check (write_map, sid, 1); |
| 1682 | *bits_set += 1; |
| 1683 | } |
| 1684 | break; |
| 1685 | case SESSION_CTRL_EVT_ACCEPTED: |
| 1686 | accepted_msg = (session_accepted_msg_t *) e->data; |
| 1687 | handle = accepted_msg->listener_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1688 | session = vcl_session_table_lookup_listener (wrk, handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1689 | if (!session) |
| 1690 | { |
| 1691 | clib_warning ("VCL<%d>: ERROR: couldn't find listen session:" |
| 1692 | "listener handle %llx", getpid (), handle); |
| 1693 | break; |
| 1694 | } |
| 1695 | |
| 1696 | clib_fifo_add2 (session->accept_evts_fifo, vcl_msg); |
| 1697 | vcl_msg->accepted_msg = *accepted_msg; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1698 | sid = session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1699 | if (sid < n_bits && read_map) |
| 1700 | { |
| 1701 | clib_bitmap_set_no_check (read_map, sid, 1); |
| 1702 | *bits_set += 1; |
| 1703 | } |
| 1704 | break; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1705 | case SESSION_CTRL_EVT_CONNECTED: |
| 1706 | connected_msg = (session_connected_msg_t *) e->data; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1707 | vcl_session_connected_handler (wrk, connected_msg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1708 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1709 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 1710 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1711 | sid = vcl_session_index_from_vpp_handle (wrk, |
| 1712 | disconnected_msg->handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1713 | if (sid < n_bits && except_map) |
| 1714 | { |
| 1715 | clib_bitmap_set_no_check (except_map, sid, 1); |
| 1716 | *bits_set += 1; |
| 1717 | } |
| 1718 | break; |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 1719 | case SESSION_CTRL_EVT_RESET: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1720 | sid = vcl_session_reset_handler (wrk, |
| 1721 | (session_reset_msg_t *) e->data); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 1722 | if (sid < n_bits && except_map) |
| 1723 | { |
| 1724 | clib_bitmap_set_no_check (except_map, sid, 1); |
| 1725 | *bits_set += 1; |
| 1726 | } |
| 1727 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1728 | default: |
| 1729 | clib_warning ("unhandled: %u", e->event_type); |
| 1730 | break; |
| 1731 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1732 | svm_msg_q_free_msg (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1735 | vec_reset_length (wrk->mq_msg_vector); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1736 | return *bits_set; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1737 | } |
| 1738 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1739 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1740 | vppcom_select_condvar (vcl_worker_t * wrk, unsigned long n_bits, |
| 1741 | unsigned long *read_map, unsigned long *write_map, |
| 1742 | unsigned long *except_map, double time_to_wait, |
| 1743 | u32 * bits_set) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1744 | { |
| 1745 | double total_wait = 0, wait_slice; |
| 1746 | vcl_cut_through_registration_t *cr; |
| 1747 | |
| 1748 | time_to_wait = (time_to_wait == -1) ? 10e9 : time_to_wait; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1749 | wait_slice = wrk->cut_through_registrations ? 10e-6 : time_to_wait; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1750 | do |
| 1751 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1752 | vcl_ct_registration_lock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1753 | /* *INDENT-OFF* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1754 | pool_foreach (cr, wrk->cut_through_registrations, ({ |
| 1755 | vcl_select_handle_mq (wrk, cr->mq, n_bits, read_map, write_map, except_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1756 | 0, bits_set); |
| 1757 | })); |
| 1758 | /* *INDENT-ON* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1759 | vcl_ct_registration_unlock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1760 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1761 | vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map, |
| 1762 | write_map, except_map, time_to_wait, bits_set); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1763 | total_wait += wait_slice; |
| 1764 | if (*bits_set) |
| 1765 | return *bits_set; |
| 1766 | } |
| 1767 | while (total_wait < time_to_wait); |
| 1768 | |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1773 | vppcom_select_eventfd (vcl_worker_t * wrk, unsigned long n_bits, |
| 1774 | unsigned long *read_map, unsigned long *write_map, |
| 1775 | unsigned long *except_map, double time_to_wait, |
| 1776 | u32 * bits_set) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1777 | { |
| 1778 | vcl_mq_evt_conn_t *mqc; |
| 1779 | int __clib_unused n_read; |
| 1780 | int n_mq_evts, i; |
| 1781 | u64 buf; |
| 1782 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1783 | vec_validate (wrk->mq_events, pool_elts (wrk->mq_evt_conns)); |
| 1784 | n_mq_evts = epoll_wait (wrk->mqs_epfd, wrk->mq_events, |
| 1785 | vec_len (wrk->mq_events), time_to_wait); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1786 | for (i = 0; i < n_mq_evts; i++) |
| 1787 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1788 | mqc = vcl_mq_evt_conn_get (wrk, wrk->mq_events[i].data.u32); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1789 | n_read = read (mqc->mq_fd, &buf, sizeof (buf)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1790 | vcl_select_handle_mq (wrk, mqc->mq, n_bits, read_map, write_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1791 | except_map, 0, bits_set); |
| 1792 | } |
| 1793 | |
| 1794 | return (n_mq_evts > 0 ? (int) *bits_set : 0); |
| 1795 | } |
| 1796 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1797 | int |
| 1798 | vppcom_select (unsigned long n_bits, unsigned long *read_map, |
| 1799 | unsigned long *write_map, unsigned long *except_map, |
| 1800 | double time_to_wait) |
| 1801 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1802 | u32 sid, minbits = clib_max (n_bits, BITS (uword)), bits_set = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1803 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1804 | vcl_session_t *session = 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1805 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1806 | |
| 1807 | ASSERT (sizeof (clib_bitmap_t) == sizeof (long int)); |
| 1808 | |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1809 | if (n_bits && read_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1810 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1811 | clib_bitmap_validate (wrk->rd_bitmap, minbits); |
| 1812 | clib_memcpy (wrk->rd_bitmap, read_map, |
| 1813 | vec_len (wrk->rd_bitmap) * sizeof (clib_bitmap_t)); |
| 1814 | memset (read_map, 0, vec_len (wrk->rd_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1815 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1816 | if (n_bits && write_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1817 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1818 | clib_bitmap_validate (wrk->wr_bitmap, minbits); |
| 1819 | clib_memcpy (wrk->wr_bitmap, write_map, |
| 1820 | vec_len (wrk->wr_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1821 | memset (write_map, 0, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1822 | vec_len (wrk->wr_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1823 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 1824 | if (n_bits && except_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1825 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1826 | clib_bitmap_validate (wrk->ex_bitmap, minbits); |
| 1827 | clib_memcpy (wrk->ex_bitmap, except_map, |
| 1828 | vec_len (wrk->ex_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1829 | memset (except_map, 0, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1830 | vec_len (wrk->ex_bitmap) * sizeof (clib_bitmap_t)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1831 | } |
| 1832 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1833 | if (!n_bits) |
| 1834 | return 0; |
| 1835 | |
| 1836 | if (!write_map) |
| 1837 | goto check_rd; |
| 1838 | |
| 1839 | /* *INDENT-OFF* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1840 | clib_bitmap_foreach (sid, wrk->wr_bitmap, ({ |
| 1841 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1842 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1843 | VDBG (0, "VCL<%d>: session %d specified in write_map is closed.", |
| 1844 | getpid (), sid); |
| 1845 | return VPPCOM_EBADFD; |
| 1846 | } |
| 1847 | |
| 1848 | rv = svm_fifo_is_full (session->tx_fifo); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1849 | if (!rv) |
| 1850 | { |
| 1851 | clib_bitmap_set_no_check (write_map, sid, 1); |
| 1852 | bits_set++; |
| 1853 | } |
| 1854 | })); |
| 1855 | |
| 1856 | check_rd: |
| 1857 | if (!read_map) |
| 1858 | goto check_mq; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1859 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1860 | clib_bitmap_foreach (sid, wrk->rd_bitmap, ({ |
| 1861 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1862 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1863 | VDBG (0, "VCL<%d>: session %d specified in write_map is closed.", |
| 1864 | getpid (), sid); |
| 1865 | return VPPCOM_EBADFD; |
| 1866 | } |
| 1867 | |
| 1868 | rv = vppcom_session_read_ready (session); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1869 | if (rv) |
| 1870 | { |
| 1871 | clib_bitmap_set_no_check (read_map, sid, 1); |
| 1872 | bits_set++; |
| 1873 | } |
| 1874 | })); |
| 1875 | /* *INDENT-ON* */ |
| 1876 | |
| 1877 | check_mq: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1878 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1879 | if (vcm->cfg.use_mq_eventfd) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1880 | vppcom_select_eventfd (wrk, n_bits, read_map, write_map, except_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1881 | time_to_wait, &bits_set); |
| 1882 | else |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1883 | vppcom_select_condvar (wrk, n_bits, read_map, write_map, except_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1884 | time_to_wait, &bits_set); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1885 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1886 | return (bits_set); |
| 1887 | } |
| 1888 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1889 | static inline void |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1890 | vep_verify_epoll_chain (vcl_worker_t * wrk, u32 vep_idx) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1891 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1892 | vcl_session_t *session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1893 | vppcom_epoll_t *vep; |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1894 | u32 sid = vep_idx; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1895 | |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1896 | if (VPPCOM_DEBUG <= 1) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1897 | return; |
| 1898 | |
| 1899 | /* Assumes caller has acquired spinlock: vcm->sessions_lockp */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1900 | session = vcl_session_get (wrk, vep_idx); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1901 | if (PREDICT_FALSE (!session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1902 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1903 | clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!", |
| 1904 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1905 | goto done; |
| 1906 | } |
| 1907 | if (PREDICT_FALSE (!session->is_vep)) |
| 1908 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1909 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
| 1910 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1911 | goto done; |
| 1912 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1913 | vep = &session->vep; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1914 | clib_warning ("VCL<%d>: vep_idx (%u): Dumping epoll chain\n" |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1915 | "{\n" |
| 1916 | " is_vep = %u\n" |
| 1917 | " is_vep_session = %u\n" |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1918 | " next_sid = 0x%x (%u)\n" |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1919 | " wait_cont_idx = 0x%x (%u)\n" |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1920 | "}\n", getpid (), vep_idx, |
| 1921 | session->is_vep, session->is_vep_session, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1922 | vep->next_sh, vep->next_sh, |
Dave Wallace | 498b3a5 | 2017-11-09 13:00:34 -0500 | [diff] [blame] | 1923 | session->wait_cont_idx, session->wait_cont_idx); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1924 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1925 | for (sid = vep->next_sh; sid != ~0; sid = vep->next_sh) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1926 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1927 | session = vcl_session_get (wrk, sid); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1928 | if (PREDICT_FALSE (!session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1929 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1930 | clib_warning ("VCL<%d>: ERROR: Invalid sid (%u)!", getpid (), sid); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1931 | goto done; |
| 1932 | } |
| 1933 | if (PREDICT_FALSE (session->is_vep)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1934 | clib_warning ("VCL<%d>: ERROR: sid (%u) is a vep!", |
| 1935 | getpid (), vep_idx); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1936 | else if (PREDICT_FALSE (!session->is_vep_session)) |
| 1937 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1938 | clib_warning ("VCL<%d>: ERROR: session (%u) " |
| 1939 | "is not a vep session!", getpid (), sid); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1940 | goto done; |
| 1941 | } |
| 1942 | vep = &session->vep; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1943 | if (PREDICT_FALSE (vep->vep_sh != vep_idx)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1944 | clib_warning ("VCL<%d>: ERROR: session (%u) vep_idx (%u) != " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1945 | "vep_idx (%u)!", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1946 | sid, session->vep.vep_sh, vep_idx); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1947 | if (session->is_vep_session) |
| 1948 | { |
| 1949 | clib_warning ("vep_idx[%u]: sid 0x%x (%u)\n" |
| 1950 | "{\n" |
| 1951 | " next_sid = 0x%x (%u)\n" |
| 1952 | " prev_sid = 0x%x (%u)\n" |
| 1953 | " vep_idx = 0x%x (%u)\n" |
| 1954 | " ev.events = 0x%x\n" |
| 1955 | " ev.data.u64 = 0x%llx\n" |
| 1956 | " et_mask = 0x%x\n" |
| 1957 | "}\n", |
| 1958 | vep_idx, sid, sid, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1959 | vep->next_sh, vep->next_sh, |
| 1960 | vep->prev_sh, vep->prev_sh, |
| 1961 | vep->vep_sh, vep->vep_sh, |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1962 | vep->ev.events, vep->ev.data.u64, vep->et_mask); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1963 | } |
| 1964 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1965 | |
| 1966 | done: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1967 | clib_warning ("VCL<%d>: vep_idx (%u): Dump complete!\n", |
| 1968 | getpid (), vep_idx); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | int |
| 1972 | vppcom_epoll_create (void) |
| 1973 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1974 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1975 | vcl_session_t *vep_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1976 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1977 | vep_session = vcl_session_alloc (wrk); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1978 | |
| 1979 | vep_session->is_vep = 1; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1980 | vep_session->vep.vep_sh = ~0; |
| 1981 | vep_session->vep.next_sh = ~0; |
| 1982 | vep_session->vep.prev_sh = ~0; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1983 | vep_session->wait_cont_idx = ~0; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1984 | vep_session->vpp_handle = ~0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1985 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1986 | vcl_evt (VCL_EVT_EPOLL_CREATE, vep_session, vep_sh); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1987 | VDBG (0, "VCL<%d>: Created vep_idx %u / sid %u!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1988 | getpid (), vep_session->session_index, vep_session->session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 1989 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1990 | return vcl_session_handle (vep_session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1994 | vppcom_epoll_ctl (uint32_t vep_handle, int op, uint32_t session_handle, |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1995 | struct epoll_event *event) |
| 1996 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1997 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1998 | vcl_session_t *vep_session; |
| 1999 | vcl_session_t *session; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2000 | int rv = VPPCOM_OK; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2001 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2002 | if (vep_handle == session_handle) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2003 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2004 | clib_warning ("VCL<%d>: ERROR: vep_idx == session_index (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2005 | getpid (), vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2006 | return VPPCOM_EINVAL; |
| 2007 | } |
| 2008 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2009 | vep_session = vcl_session_get_w_handle (wrk, vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2010 | if (PREDICT_FALSE (!vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2011 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2012 | clib_warning ("VCL<%d>: ERROR: Invalid vep_idx (%u)!", vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2013 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2014 | } |
| 2015 | if (PREDICT_FALSE (!vep_session->is_vep)) |
| 2016 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2017 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2018 | getpid (), vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2019 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2020 | } |
| 2021 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2022 | ASSERT (vep_session->vep.vep_sh == ~0); |
| 2023 | ASSERT (vep_session->vep.prev_sh == ~0); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2024 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2025 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2026 | if (PREDICT_FALSE (!session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2027 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2028 | VDBG (0, "VCL<%d>: ERROR: Invalid session_handle (%u)!", |
| 2029 | getpid (), session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2030 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2031 | } |
| 2032 | if (PREDICT_FALSE (session->is_vep)) |
| 2033 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2034 | clib_warning ("ERROR: session_handle (%u) is a vep!", vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2035 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | switch (op) |
| 2039 | { |
| 2040 | case EPOLL_CTL_ADD: |
| 2041 | if (PREDICT_FALSE (!event)) |
| 2042 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2043 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: NULL pointer to " |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 2044 | "epoll_event structure!", getpid ()); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2045 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2046 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2047 | if (vep_session->vep.next_sh != ~0) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2048 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2049 | vcl_session_t *next_session; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2050 | next_session = vcl_session_get_w_handle (wrk, |
| 2051 | vep_session->vep.next_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2052 | if (PREDICT_FALSE (!next_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2053 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2054 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_ADD: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2055 | "vep.next_sid (%u) on vep_idx (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2056 | getpid (), vep_session->vep.next_sh, vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2057 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2058 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2059 | ASSERT (next_session->vep.prev_sh == vep_handle); |
| 2060 | next_session->vep.prev_sh = session_handle; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2061 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2062 | session->vep.next_sh = vep_session->vep.next_sh; |
| 2063 | session->vep.prev_sh = vep_handle; |
| 2064 | session->vep.vep_sh = vep_handle; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2065 | session->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 2066 | session->vep.ev = *event; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2067 | session->is_vep = 0; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2068 | session->is_vep_session = 1; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2069 | vep_session->vep.next_sh = session_handle; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 2070 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2071 | VDBG (1, "VCL<%d>: EPOLL_CTL_ADD: vep_idx %u, sid %u, events 0x%x, " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2072 | "data 0x%llx!", getpid (), vep_handle, session_handle, |
| 2073 | event->events, event->data.u64); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2074 | vcl_evt (VCL_EVT_EPOLL_CTLADD, session, event->events, event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2075 | break; |
| 2076 | |
| 2077 | case EPOLL_CTL_MOD: |
| 2078 | if (PREDICT_FALSE (!event)) |
| 2079 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2080 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_MOD: NULL pointer to " |
Dave Wallace | 2e005bb | 2017-11-07 01:21:39 -0500 | [diff] [blame] | 2081 | "epoll_event structure!", getpid ()); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2082 | rv = VPPCOM_EINVAL; |
| 2083 | goto done; |
| 2084 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2085 | else if (PREDICT_FALSE (!session->is_vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2086 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2087 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2088 | "not a vep session!", getpid (), session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2089 | rv = VPPCOM_EINVAL; |
| 2090 | goto done; |
| 2091 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2092 | else if (PREDICT_FALSE (session->vep.vep_sh != vep_handle)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2093 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2094 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_MOD: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2095 | "vep_idx (%u) != vep_idx (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2096 | getpid (), session_handle, |
| 2097 | session->vep.vep_sh, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2098 | rv = VPPCOM_EINVAL; |
| 2099 | goto done; |
| 2100 | } |
| 2101 | session->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 2102 | session->vep.ev = *event; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2103 | VDBG (1, "VCL<%d>: EPOLL_CTL_MOD: vep_idx %u, sid %u, events 0x%x," |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2104 | " data 0x%llx!", getpid (), vep_handle, session_handle, |
| 2105 | event->events, event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2106 | break; |
| 2107 | |
| 2108 | case EPOLL_CTL_DEL: |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2109 | if (PREDICT_FALSE (!session->is_vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2110 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2111 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: " |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2112 | "not a vep session!", getpid (), session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2113 | rv = VPPCOM_EINVAL; |
| 2114 | goto done; |
| 2115 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2116 | else if (PREDICT_FALSE (session->vep.vep_sh != vep_handle)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2117 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2118 | clib_warning ("VCL<%d>: ERROR: sid %u EPOLL_CTL_DEL: " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2119 | "vep_idx (%u) != vep_idx (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2120 | getpid (), session_handle, |
| 2121 | session->vep.vep_sh, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2122 | rv = VPPCOM_EINVAL; |
| 2123 | goto done; |
| 2124 | } |
| 2125 | |
| 2126 | vep_session->wait_cont_idx = |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2127 | (vep_session->wait_cont_idx == session_handle) ? |
| 2128 | session->vep.next_sh : vep_session->wait_cont_idx; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2129 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2130 | if (session->vep.prev_sh == vep_handle) |
| 2131 | vep_session->vep.next_sh = session->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2132 | else |
| 2133 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2134 | vcl_session_t *prev_session; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2135 | prev_session = vcl_session_get_w_handle (wrk, session->vep.prev_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2136 | if (PREDICT_FALSE (!prev_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2137 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2138 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2139 | "vep.prev_sid (%u) on sid (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2140 | getpid (), session->vep.prev_sh, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2141 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2142 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2143 | ASSERT (prev_session->vep.next_sh == session_handle); |
| 2144 | prev_session->vep.next_sh = session->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2145 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2146 | if (session->vep.next_sh != ~0) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2147 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2148 | vcl_session_t *next_session; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2149 | next_session = vcl_session_get_w_handle (wrk, session->vep.next_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2150 | if (PREDICT_FALSE (!next_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2151 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2152 | clib_warning ("VCL<%d>: ERROR: EPOLL_CTL_DEL: Invalid " |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2153 | "vep.next_sid (%u) on sid (%u)!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2154 | getpid (), session->vep.next_sh, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2155 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2156 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2157 | ASSERT (next_session->vep.prev_sh == session_handle); |
| 2158 | next_session->vep.prev_sh = session->vep.prev_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | memset (&session->vep, 0, sizeof (session->vep)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2162 | session->vep.next_sh = ~0; |
| 2163 | session->vep.prev_sh = ~0; |
| 2164 | session->vep.vep_sh = ~0; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2165 | session->is_vep_session = 0; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2166 | VDBG (1, "VCL<%d>: EPOLL_CTL_DEL: vep_idx %u, sid %u!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2167 | getpid (), vep_handle, session_handle); |
| 2168 | vcl_evt (VCL_EVT_EPOLL_CTLDEL, session, vep_sh); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2169 | break; |
| 2170 | |
| 2171 | default: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2172 | clib_warning ("VCL<%d>: ERROR: Invalid operation (%d)!", getpid (), op); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2173 | rv = VPPCOM_EINVAL; |
| 2174 | } |
| 2175 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2176 | vep_verify_epoll_chain (wrk, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2177 | |
| 2178 | done: |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2179 | return rv; |
| 2180 | } |
| 2181 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2182 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2183 | vcl_epoll_wait_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq, |
| 2184 | struct epoll_event *events, u32 maxevents, |
| 2185 | double wait_for_time, u32 * num_ev) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2186 | { |
| 2187 | session_disconnected_msg_t *disconnected_msg; |
| 2188 | session_connected_msg_t *connected_msg; |
| 2189 | session_accepted_msg_t *accepted_msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2190 | u64 session_evt_data = ~0, handle; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2191 | u32 sid = ~0, session_events; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2192 | vcl_session_msg_t *vcl_msg; |
| 2193 | vcl_session_t *session; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2194 | svm_msg_q_msg_t *msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2195 | session_event_t *e; |
| 2196 | u8 add_event; |
| 2197 | int i; |
| 2198 | |
| 2199 | svm_msg_q_lock (mq); |
| 2200 | if (svm_msg_q_is_empty (mq)) |
| 2201 | { |
| 2202 | if (!wait_for_time) |
| 2203 | { |
| 2204 | svm_msg_q_unlock (mq); |
| 2205 | return 0; |
| 2206 | } |
| 2207 | else if (wait_for_time < 0) |
| 2208 | { |
| 2209 | svm_msg_q_wait (mq); |
| 2210 | } |
| 2211 | else |
| 2212 | { |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2213 | if (svm_msg_q_timedwait (mq, wait_for_time / 1e3)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2214 | { |
| 2215 | svm_msg_q_unlock (mq); |
| 2216 | return 0; |
| 2217 | } |
| 2218 | } |
| 2219 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2220 | vcl_mq_dequeue_batch (wrk, mq); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2221 | svm_msg_q_unlock (mq); |
| 2222 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2223 | for (i = 0; i < vec_len (wrk->mq_msg_vector); i++) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2224 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2225 | msg = vec_elt_at_index (wrk->mq_msg_vector, i); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2226 | e = svm_msg_q_msg_data (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2227 | add_event = 0; |
| 2228 | switch (e->event_type) |
| 2229 | { |
| 2230 | case FIFO_EVENT_APP_RX: |
| 2231 | sid = e->fifo->client_session_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2232 | session = vcl_session_get (wrk, sid); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2233 | session_events = session->vep.ev.events; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2234 | if (!(EPOLLIN & session->vep.ev.events)) |
| 2235 | break; |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2236 | add_event = 1; |
| 2237 | events[*num_ev].events |= EPOLLIN; |
| 2238 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2239 | break; |
| 2240 | case FIFO_EVENT_APP_TX: |
| 2241 | sid = e->fifo->client_session_index; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2242 | session = vcl_session_get (wrk, sid); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2243 | session_events = session->vep.ev.events; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2244 | if (!(EPOLLOUT & session_events)) |
| 2245 | break; |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2246 | add_event = 1; |
| 2247 | events[*num_ev].events |= EPOLLOUT; |
| 2248 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2249 | break; |
| 2250 | case SESSION_IO_EVT_CT_TX: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2251 | session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 0); |
| 2252 | sid = session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2253 | session_events = session->vep.ev.events; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2254 | if (!(EPOLLIN & session->vep.ev.events)) |
| 2255 | break; |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2256 | add_event = 1; |
| 2257 | events[*num_ev].events |= EPOLLIN; |
| 2258 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2259 | break; |
| 2260 | case SESSION_IO_EVT_CT_RX: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2261 | session = vcl_ct_session_get_from_fifo (wrk, e->fifo, 1); |
| 2262 | sid = session->session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2263 | session_events = session->vep.ev.events; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2264 | if (!(EPOLLOUT & session_events)) |
| 2265 | break; |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2266 | add_event = 1; |
| 2267 | events[*num_ev].events |= EPOLLOUT; |
| 2268 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2269 | break; |
| 2270 | case SESSION_CTRL_EVT_ACCEPTED: |
| 2271 | accepted_msg = (session_accepted_msg_t *) e->data; |
| 2272 | handle = accepted_msg->listener_handle; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2273 | session = vcl_session_table_lookup_listener (wrk, handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2274 | if (!session) |
| 2275 | { |
| 2276 | clib_warning ("VCL<%d>: ERROR: couldn't find listen session:" |
| 2277 | "listener handle %llx", getpid (), handle); |
| 2278 | break; |
| 2279 | } |
| 2280 | |
| 2281 | clib_fifo_add2 (session->accept_evts_fifo, vcl_msg); |
| 2282 | vcl_msg->accepted_msg = *accepted_msg; |
| 2283 | session_events = session->vep.ev.events; |
| 2284 | if (!(EPOLLIN & session_events)) |
| 2285 | break; |
| 2286 | |
| 2287 | add_event = 1; |
| 2288 | events[*num_ev].events |= EPOLLIN; |
| 2289 | session_evt_data = session->vep.ev.data.u64; |
| 2290 | break; |
| 2291 | case SESSION_CTRL_EVT_CONNECTED: |
| 2292 | connected_msg = (session_connected_msg_t *) e->data; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2293 | vcl_session_connected_handler (wrk, connected_msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2294 | /* Generate EPOLLOUT because there's no connected event */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2295 | sid = vcl_session_index_from_vpp_handle (wrk, |
| 2296 | connected_msg->handle); |
| 2297 | session = vcl_session_get (wrk, sid); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2298 | session_events = session->vep.ev.events; |
| 2299 | if (EPOLLOUT & session_events) |
| 2300 | { |
| 2301 | add_event = 1; |
| 2302 | events[*num_ev].events |= EPOLLOUT; |
| 2303 | session_evt_data = session->vep.ev.data.u64; |
| 2304 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2305 | break; |
| 2306 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 2307 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2308 | sid = vcl_session_index_from_vpp_handle (wrk, |
| 2309 | disconnected_msg->handle); |
| 2310 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 2311 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2312 | add_event = 1; |
| 2313 | events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; |
| 2314 | session_evt_data = session->vep.ev.data.u64; |
| 2315 | session_events = session->vep.ev.events; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2316 | break; |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 2317 | case SESSION_CTRL_EVT_RESET: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2318 | sid = vcl_session_reset_handler (wrk, |
| 2319 | (session_reset_msg_t *) e->data); |
| 2320 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 2321 | break; |
| 2322 | add_event = 1; |
| 2323 | events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; |
| 2324 | session_evt_data = session->vep.ev.data.u64; |
| 2325 | session_events = session->vep.ev.events; |
| 2326 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2327 | default: |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2328 | VDBG (0, "unhandled: %u", e->event_type); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2329 | svm_msg_q_free_msg (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2330 | continue; |
| 2331 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2332 | svm_msg_q_free_msg (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2333 | |
| 2334 | if (add_event) |
| 2335 | { |
| 2336 | events[*num_ev].data.u64 = session_evt_data; |
| 2337 | if (EPOLLONESHOT & session_events) |
| 2338 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2339 | session = vcl_session_get (wrk, sid); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2340 | session->vep.ev.events = 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2341 | } |
| 2342 | *num_ev += 1; |
| 2343 | if (*num_ev == maxevents) |
| 2344 | break; |
| 2345 | } |
| 2346 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2347 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2348 | vec_reset_length (wrk->mq_msg_vector); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2349 | return *num_ev; |
| 2350 | } |
| 2351 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2352 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2353 | vppcom_epoll_wait_condvar (vcl_worker_t * wrk, struct epoll_event *events, |
| 2354 | int maxevents, double wait_for_time) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2355 | { |
| 2356 | vcl_cut_through_registration_t *cr; |
| 2357 | double total_wait = 0, wait_slice; |
| 2358 | u32 num_ev = 0; |
| 2359 | int rv; |
| 2360 | |
| 2361 | wait_for_time = (wait_for_time == -1) ? (double) 10e9 : wait_for_time; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2362 | wait_slice = wrk->cut_through_registrations ? 10e-6 : wait_for_time; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2363 | |
| 2364 | do |
| 2365 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2366 | vcl_ct_registration_lock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2367 | /* *INDENT-OFF* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2368 | pool_foreach (cr, wrk->cut_through_registrations, ({ |
| 2369 | vcl_epoll_wait_handle_mq (wrk, cr->mq, events, maxevents, 0, &num_ev); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2370 | })); |
| 2371 | /* *INDENT-ON* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2372 | vcl_ct_registration_unlock (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2373 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2374 | rv = vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events, |
| 2375 | maxevents, num_ev ? 0 : wait_slice, |
| 2376 | &num_ev); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2377 | if (rv) |
| 2378 | total_wait += wait_slice; |
| 2379 | if (num_ev) |
| 2380 | return num_ev; |
| 2381 | } |
| 2382 | while (total_wait < wait_for_time); |
| 2383 | return (int) num_ev; |
| 2384 | } |
| 2385 | |
| 2386 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2387 | vppcom_epoll_wait_eventfd (vcl_worker_t * wrk, struct epoll_event *events, |
| 2388 | int maxevents, double wait_for_time) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2389 | { |
| 2390 | vcl_mq_evt_conn_t *mqc; |
| 2391 | int __clib_unused n_read; |
| 2392 | int n_mq_evts, i; |
| 2393 | u32 n_evts = 0; |
| 2394 | u64 buf; |
| 2395 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2396 | vec_validate (wrk->mq_events, pool_elts (wrk->mq_evt_conns)); |
| 2397 | n_mq_evts = epoll_wait (wrk->mqs_epfd, wrk->mq_events, |
| 2398 | vec_len (wrk->mq_events), wait_for_time); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2399 | for (i = 0; i < n_mq_evts; i++) |
| 2400 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2401 | mqc = vcl_mq_evt_conn_get (wrk, wrk->mq_events[i].data.u32); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2402 | n_read = read (mqc->mq_fd, &buf, sizeof (buf)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2403 | vcl_epoll_wait_handle_mq (wrk, mqc->mq, events, maxevents, 0, &n_evts); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2404 | } |
| 2405 | |
| 2406 | return (int) n_evts; |
| 2407 | } |
| 2408 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2409 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2410 | vppcom_epoll_wait (uint32_t vep_handle, struct epoll_event *events, |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2411 | int maxevents, double wait_for_time) |
| 2412 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2413 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2414 | vcl_session_t *vep_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2415 | |
| 2416 | if (PREDICT_FALSE (maxevents <= 0)) |
| 2417 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2418 | clib_warning ("VCL<%d>: ERROR: Invalid maxevents (%d)!", |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2419 | getpid (), maxevents); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2420 | return VPPCOM_EINVAL; |
| 2421 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2422 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2423 | vep_session = vcl_session_get_w_handle (wrk, vep_handle); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 2424 | if (!vep_session) |
| 2425 | return VPPCOM_EBADFD; |
| 2426 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2427 | if (PREDICT_FALSE (!vep_session->is_vep)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2428 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2429 | clib_warning ("VCL<%d>: ERROR: vep_idx (%u) is not a vep!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2430 | getpid (), vep_handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2431 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2432 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2433 | |
| 2434 | memset (events, 0, sizeof (*events) * maxevents); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2435 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2436 | if (vcm->cfg.use_mq_eventfd) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2437 | return vppcom_epoll_wait_eventfd (wrk, events, maxevents, wait_for_time); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2438 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2439 | return vppcom_epoll_wait_condvar (wrk, events, maxevents, wait_for_time); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2440 | } |
| 2441 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2442 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2443 | vppcom_session_attr (uint32_t session_handle, uint32_t op, |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2444 | void *buffer, uint32_t * buflen) |
| 2445 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2446 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2447 | vcl_session_t *session; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2448 | int rv = VPPCOM_OK; |
| 2449 | u32 *flags = buffer; |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2450 | vppcom_endpt_t *ep = buffer; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2451 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2452 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2453 | if (!session) |
| 2454 | return VPPCOM_EBADFD; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2455 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2456 | switch (op) |
| 2457 | { |
| 2458 | case VPPCOM_ATTR_GET_NREAD: |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2459 | rv = vppcom_session_read_ready (session); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2460 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NREAD: sid %u, nread = %d", |
| 2461 | getpid (), rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2462 | break; |
| 2463 | |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 2464 | case VPPCOM_ATTR_GET_NWRITE: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2465 | rv = vppcom_session_write_ready (session); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2466 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_NWRITE: sid %u, nwrite = %d", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2467 | getpid (), session_handle, rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2468 | break; |
| 2469 | |
| 2470 | case VPPCOM_ATTR_GET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2471 | if (PREDICT_TRUE (buffer && buflen && (*buflen >= sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2472 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2473 | *flags = O_RDWR | (VCL_SESS_ATTR_TEST (session->attr, |
| 2474 | VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2475 | *buflen = sizeof (*flags); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2476 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_FLAGS: sid %u, flags = 0x%08x, " |
| 2477 | "is_nonblocking = %u", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2478 | session_handle, *flags, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2479 | VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2480 | } |
| 2481 | else |
| 2482 | rv = VPPCOM_EINVAL; |
| 2483 | break; |
| 2484 | |
| 2485 | case VPPCOM_ATTR_SET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2486 | if (PREDICT_TRUE (buffer && buflen && (*buflen == sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2487 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2488 | if (*flags & O_NONBLOCK) |
| 2489 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 2490 | else |
| 2491 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_NONBLOCK); |
| 2492 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2493 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_FLAGS: sid %u, flags = 0x%08x," |
| 2494 | " is_nonblocking = %u", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2495 | getpid (), session_handle, *flags, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2496 | VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2497 | } |
| 2498 | else |
| 2499 | rv = VPPCOM_EINVAL; |
| 2500 | break; |
| 2501 | |
| 2502 | case VPPCOM_ATTR_GET_PEER_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2503 | if (PREDICT_TRUE (buffer && buflen && |
| 2504 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2505 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2506 | ep->is_ip4 = session->transport.is_ip4; |
| 2507 | ep->port = session->transport.rmt_port; |
| 2508 | if (session->transport.is_ip4) |
| 2509 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip4, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2510 | sizeof (ip4_address_t)); |
| 2511 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2512 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip6, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2513 | sizeof (ip6_address_t)); |
| 2514 | *buflen = sizeof (*ep); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2515 | VDBG (1, "VCL<%d>: VPPCOM_ATTR_GET_PEER_ADDR: sid %u, is_ip4 = %u, " |
| 2516 | "addr = %U, port %u", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2517 | session_handle, ep->is_ip4, format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2518 | &session->transport.rmt_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2519 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 2520 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2521 | } |
| 2522 | else |
| 2523 | rv = VPPCOM_EINVAL; |
| 2524 | break; |
| 2525 | |
| 2526 | case VPPCOM_ATTR_GET_LCL_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2527 | if (PREDICT_TRUE (buffer && buflen && |
| 2528 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2529 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2530 | ep->is_ip4 = session->transport.is_ip4; |
| 2531 | ep->port = session->transport.lcl_port; |
| 2532 | if (session->transport.is_ip4) |
| 2533 | clib_memcpy (ep->ip, &session->transport.lcl_ip.ip4, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2534 | sizeof (ip4_address_t)); |
| 2535 | else |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2536 | clib_memcpy (ep->ip, &session->transport.lcl_ip.ip6, |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 2537 | sizeof (ip6_address_t)); |
| 2538 | *buflen = sizeof (*ep); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2539 | VDBG (1, "VCL<%d>: VPPCOM_ATTR_GET_LCL_ADDR: sid %u, is_ip4 = %u," |
| 2540 | " addr = %U port %d", getpid (), |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2541 | session_handle, ep->is_ip4, format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2542 | &session->transport.lcl_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2543 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 2544 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2545 | } |
| 2546 | else |
| 2547 | rv = VPPCOM_EINVAL; |
| 2548 | break; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2549 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2550 | case VPPCOM_ATTR_GET_LIBC_EPFD: |
| 2551 | rv = session->libc_epfd; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2552 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_LIBC_EPFD: libc_epfd %d", |
| 2553 | getpid (), rv); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2554 | break; |
| 2555 | |
| 2556 | case VPPCOM_ATTR_SET_LIBC_EPFD: |
| 2557 | if (PREDICT_TRUE (buffer && buflen && |
| 2558 | (*buflen == sizeof (session->libc_epfd)))) |
| 2559 | { |
| 2560 | session->libc_epfd = *(int *) buffer; |
| 2561 | *buflen = sizeof (session->libc_epfd); |
| 2562 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2563 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_LIBC_EPFD: libc_epfd %d, " |
| 2564 | "buflen %d", getpid (), session->libc_epfd, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2565 | } |
| 2566 | else |
| 2567 | rv = VPPCOM_EINVAL; |
| 2568 | break; |
| 2569 | |
| 2570 | case VPPCOM_ATTR_GET_PROTOCOL: |
| 2571 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2572 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2573 | *(int *) buffer = session->session_type; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2574 | *buflen = sizeof (int); |
| 2575 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2576 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_PROTOCOL: %d (%s), buflen %d", |
| 2577 | getpid (), *(int *) buffer, *(int *) buffer ? "UDP" : "TCP", |
| 2578 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2579 | } |
| 2580 | else |
| 2581 | rv = VPPCOM_EINVAL; |
| 2582 | break; |
| 2583 | |
| 2584 | case VPPCOM_ATTR_GET_LISTEN: |
| 2585 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2586 | { |
| 2587 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2588 | VCL_SESS_ATTR_LISTEN); |
| 2589 | *buflen = sizeof (int); |
| 2590 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2591 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_LISTEN: %d, buflen %d", |
| 2592 | getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2593 | } |
| 2594 | else |
| 2595 | rv = VPPCOM_EINVAL; |
| 2596 | break; |
| 2597 | |
| 2598 | case VPPCOM_ATTR_GET_ERROR: |
| 2599 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2600 | { |
| 2601 | *(int *) buffer = 0; |
| 2602 | *buflen = sizeof (int); |
| 2603 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2604 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_ERROR: %d, buflen %d, #VPP-TBD#", |
| 2605 | getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2606 | } |
| 2607 | else |
| 2608 | rv = VPPCOM_EINVAL; |
| 2609 | break; |
| 2610 | |
| 2611 | case VPPCOM_ATTR_GET_TX_FIFO_LEN: |
| 2612 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2613 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2614 | |
| 2615 | /* VPP-TBD */ |
| 2616 | *(size_t *) buffer = (session->sndbuf_size ? session->sndbuf_size : |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2617 | session->tx_fifo ? session->tx_fifo->nitems : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2618 | vcm->cfg.tx_fifo_size); |
| 2619 | *buflen = sizeof (u32); |
| 2620 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2621 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TX_FIFO_LEN: %u (0x%x), " |
| 2622 | "buflen %d, #VPP-TBD#", getpid (), |
| 2623 | *(size_t *) buffer, *(size_t *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2624 | } |
| 2625 | else |
| 2626 | rv = VPPCOM_EINVAL; |
| 2627 | break; |
| 2628 | |
| 2629 | case VPPCOM_ATTR_SET_TX_FIFO_LEN: |
| 2630 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2631 | { |
| 2632 | /* VPP-TBD */ |
| 2633 | session->sndbuf_size = *(u32 *) buffer; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2634 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TX_FIFO_LEN: %u (0x%x), " |
| 2635 | "buflen %d, #VPP-TBD#", getpid (), |
| 2636 | session->sndbuf_size, session->sndbuf_size, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2637 | } |
| 2638 | else |
| 2639 | rv = VPPCOM_EINVAL; |
| 2640 | break; |
| 2641 | |
| 2642 | case VPPCOM_ATTR_GET_RX_FIFO_LEN: |
| 2643 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2644 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2645 | |
| 2646 | /* VPP-TBD */ |
| 2647 | *(size_t *) buffer = (session->rcvbuf_size ? session->rcvbuf_size : |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2648 | session->rx_fifo ? session->rx_fifo->nitems : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2649 | vcm->cfg.rx_fifo_size); |
| 2650 | *buflen = sizeof (u32); |
| 2651 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2652 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_RX_FIFO_LEN: %u (0x%x), " |
| 2653 | "buflen %d, #VPP-TBD#", getpid (), |
| 2654 | *(size_t *) buffer, *(size_t *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2655 | } |
| 2656 | else |
| 2657 | rv = VPPCOM_EINVAL; |
| 2658 | break; |
| 2659 | |
| 2660 | case VPPCOM_ATTR_SET_RX_FIFO_LEN: |
| 2661 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2662 | { |
| 2663 | /* VPP-TBD */ |
| 2664 | session->rcvbuf_size = *(u32 *) buffer; |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2665 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_RX_FIFO_LEN: %u (0x%x), " |
| 2666 | "buflen %d, #VPP-TBD#", getpid (), |
| 2667 | session->sndbuf_size, session->sndbuf_size, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2668 | } |
| 2669 | else |
| 2670 | rv = VPPCOM_EINVAL; |
| 2671 | break; |
| 2672 | |
| 2673 | case VPPCOM_ATTR_GET_REUSEADDR: |
| 2674 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2675 | { |
| 2676 | /* VPP-TBD */ |
| 2677 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2678 | VCL_SESS_ATTR_REUSEADDR); |
| 2679 | *buflen = sizeof (int); |
| 2680 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2681 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_REUSEADDR: %d, " |
| 2682 | "buflen %d, #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2683 | } |
| 2684 | else |
| 2685 | rv = VPPCOM_EINVAL; |
| 2686 | break; |
| 2687 | |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2688 | case VPPCOM_ATTR_SET_REUSEADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2689 | if (buffer && buflen && (*buflen == sizeof (int)) && |
| 2690 | !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN)) |
| 2691 | { |
| 2692 | /* VPP-TBD */ |
| 2693 | if (*(int *) buffer) |
| 2694 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEADDR); |
| 2695 | else |
| 2696 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEADDR); |
| 2697 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2698 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_REUSEADDR: %d, buflen %d," |
| 2699 | " #VPP-TBD#", getpid (), |
| 2700 | VCL_SESS_ATTR_TEST (session->attr, |
| 2701 | VCL_SESS_ATTR_REUSEADDR), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2702 | } |
| 2703 | else |
| 2704 | rv = VPPCOM_EINVAL; |
| 2705 | break; |
| 2706 | |
| 2707 | case VPPCOM_ATTR_GET_REUSEPORT: |
| 2708 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2709 | { |
| 2710 | /* VPP-TBD */ |
| 2711 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2712 | VCL_SESS_ATTR_REUSEPORT); |
| 2713 | *buflen = sizeof (int); |
| 2714 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2715 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_REUSEPORT: %d, buflen %d," |
| 2716 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2717 | } |
| 2718 | else |
| 2719 | rv = VPPCOM_EINVAL; |
| 2720 | break; |
| 2721 | |
| 2722 | case VPPCOM_ATTR_SET_REUSEPORT: |
| 2723 | if (buffer && buflen && (*buflen == sizeof (int)) && |
| 2724 | !VCL_SESS_ATTR_TEST (session->attr, VCL_SESS_ATTR_LISTEN)) |
| 2725 | { |
| 2726 | /* VPP-TBD */ |
| 2727 | if (*(int *) buffer) |
| 2728 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_REUSEPORT); |
| 2729 | else |
| 2730 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_REUSEPORT); |
| 2731 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2732 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_REUSEPORT: %d, buflen %d," |
| 2733 | " #VPP-TBD#", getpid (), |
| 2734 | VCL_SESS_ATTR_TEST (session->attr, |
| 2735 | VCL_SESS_ATTR_REUSEPORT), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2736 | } |
| 2737 | else |
| 2738 | rv = VPPCOM_EINVAL; |
| 2739 | break; |
| 2740 | |
| 2741 | case VPPCOM_ATTR_GET_BROADCAST: |
| 2742 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2743 | { |
| 2744 | /* VPP-TBD */ |
| 2745 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2746 | VCL_SESS_ATTR_BROADCAST); |
| 2747 | *buflen = sizeof (int); |
| 2748 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2749 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_BROADCAST: %d, buflen %d," |
| 2750 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2751 | } |
| 2752 | else |
| 2753 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2754 | break; |
| 2755 | |
| 2756 | case VPPCOM_ATTR_SET_BROADCAST: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2757 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2758 | { |
| 2759 | /* VPP-TBD */ |
| 2760 | if (*(int *) buffer) |
| 2761 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_BROADCAST); |
| 2762 | else |
| 2763 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_BROADCAST); |
| 2764 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2765 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_BROADCAST: %d, buflen %d, " |
| 2766 | "#VPP-TBD#", getpid (), |
| 2767 | VCL_SESS_ATTR_TEST (session->attr, |
| 2768 | VCL_SESS_ATTR_BROADCAST), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2769 | } |
| 2770 | else |
| 2771 | rv = VPPCOM_EINVAL; |
| 2772 | break; |
| 2773 | |
| 2774 | case VPPCOM_ATTR_GET_V6ONLY: |
| 2775 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2776 | { |
| 2777 | /* VPP-TBD */ |
| 2778 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2779 | VCL_SESS_ATTR_V6ONLY); |
| 2780 | *buflen = sizeof (int); |
| 2781 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2782 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_V6ONLY: %d, buflen %d, " |
| 2783 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2784 | } |
| 2785 | else |
| 2786 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2787 | break; |
| 2788 | |
| 2789 | case VPPCOM_ATTR_SET_V6ONLY: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2790 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2791 | { |
| 2792 | /* VPP-TBD */ |
| 2793 | if (*(int *) buffer) |
| 2794 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_V6ONLY); |
| 2795 | else |
| 2796 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_V6ONLY); |
| 2797 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2798 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_V6ONLY: %d, buflen %d, " |
| 2799 | "#VPP-TBD#", getpid (), |
| 2800 | VCL_SESS_ATTR_TEST (session->attr, |
| 2801 | VCL_SESS_ATTR_V6ONLY), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2802 | } |
| 2803 | else |
| 2804 | rv = VPPCOM_EINVAL; |
| 2805 | break; |
| 2806 | |
| 2807 | case VPPCOM_ATTR_GET_KEEPALIVE: |
| 2808 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2809 | { |
| 2810 | /* VPP-TBD */ |
| 2811 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2812 | VCL_SESS_ATTR_KEEPALIVE); |
| 2813 | *buflen = sizeof (int); |
| 2814 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2815 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_KEEPALIVE: %d, buflen %d, " |
| 2816 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2817 | } |
| 2818 | else |
| 2819 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 2820 | break; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2821 | |
| 2822 | case VPPCOM_ATTR_SET_KEEPALIVE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2823 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2824 | { |
| 2825 | /* VPP-TBD */ |
| 2826 | if (*(int *) buffer) |
| 2827 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_KEEPALIVE); |
| 2828 | else |
| 2829 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_KEEPALIVE); |
| 2830 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2831 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_KEEPALIVE: %d, buflen %d, " |
| 2832 | "#VPP-TBD#", getpid (), |
| 2833 | VCL_SESS_ATTR_TEST (session->attr, |
| 2834 | VCL_SESS_ATTR_KEEPALIVE), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2835 | } |
| 2836 | else |
| 2837 | rv = VPPCOM_EINVAL; |
| 2838 | break; |
| 2839 | |
| 2840 | case VPPCOM_ATTR_GET_TCP_NODELAY: |
| 2841 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2842 | { |
| 2843 | /* VPP-TBD */ |
| 2844 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2845 | VCL_SESS_ATTR_TCP_NODELAY); |
| 2846 | *buflen = sizeof (int); |
| 2847 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2848 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_NODELAY: %d, buflen %d, " |
| 2849 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2850 | } |
| 2851 | else |
| 2852 | rv = VPPCOM_EINVAL; |
| 2853 | break; |
| 2854 | |
| 2855 | case VPPCOM_ATTR_SET_TCP_NODELAY: |
| 2856 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2857 | { |
| 2858 | /* VPP-TBD */ |
| 2859 | if (*(int *) buffer) |
| 2860 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_NODELAY); |
| 2861 | else |
| 2862 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_NODELAY); |
| 2863 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2864 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_NODELAY: %d, buflen %d, " |
| 2865 | "#VPP-TBD#", getpid (), |
| 2866 | VCL_SESS_ATTR_TEST (session->attr, |
| 2867 | VCL_SESS_ATTR_TCP_NODELAY), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2868 | } |
| 2869 | else |
| 2870 | rv = VPPCOM_EINVAL; |
| 2871 | break; |
| 2872 | |
| 2873 | case VPPCOM_ATTR_GET_TCP_KEEPIDLE: |
| 2874 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2875 | { |
| 2876 | /* VPP-TBD */ |
| 2877 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2878 | VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2879 | *buflen = sizeof (int); |
| 2880 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2881 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d, buflen %d, " |
| 2882 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2883 | } |
| 2884 | else |
| 2885 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2886 | break; |
| 2887 | |
| 2888 | case VPPCOM_ATTR_SET_TCP_KEEPIDLE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2889 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2890 | { |
| 2891 | /* VPP-TBD */ |
| 2892 | if (*(int *) buffer) |
| 2893 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2894 | else |
| 2895 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPIDLE); |
| 2896 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2897 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPIDLE: %d, buflen %d, " |
| 2898 | "#VPP-TBD#", getpid (), |
| 2899 | VCL_SESS_ATTR_TEST (session->attr, |
| 2900 | VCL_SESS_ATTR_TCP_KEEPIDLE), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2901 | } |
| 2902 | else |
| 2903 | rv = VPPCOM_EINVAL; |
| 2904 | break; |
| 2905 | |
| 2906 | case VPPCOM_ATTR_GET_TCP_KEEPINTVL: |
| 2907 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 2908 | { |
| 2909 | /* VPP-TBD */ |
| 2910 | *(int *) buffer = VCL_SESS_ATTR_TEST (session->attr, |
| 2911 | VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2912 | *buflen = sizeof (int); |
| 2913 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2914 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_KEEPINTVL: %d, buflen %d, " |
| 2915 | "#VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2916 | } |
| 2917 | else |
| 2918 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2919 | break; |
| 2920 | |
| 2921 | case VPPCOM_ATTR_SET_TCP_KEEPINTVL: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2922 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 2923 | { |
| 2924 | /* VPP-TBD */ |
| 2925 | if (*(int *) buffer) |
| 2926 | VCL_SESS_ATTR_SET (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2927 | else |
| 2928 | VCL_SESS_ATTR_CLR (session->attr, VCL_SESS_ATTR_TCP_KEEPINTVL); |
| 2929 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2930 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_KEEPINTVL: %d, buflen %d, " |
| 2931 | "#VPP-TBD#", getpid (), |
| 2932 | VCL_SESS_ATTR_TEST (session->attr, |
| 2933 | VCL_SESS_ATTR_TCP_KEEPINTVL), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2934 | } |
| 2935 | else |
| 2936 | rv = VPPCOM_EINVAL; |
| 2937 | break; |
| 2938 | |
| 2939 | case VPPCOM_ATTR_GET_TCP_USER_MSS: |
| 2940 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 2941 | { |
| 2942 | /* VPP-TBD */ |
| 2943 | *(u32 *) buffer = session->user_mss; |
| 2944 | *buflen = sizeof (int); |
| 2945 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2946 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_GET_TCP_USER_MSS: %d, buflen %d," |
| 2947 | " #VPP-TBD#", getpid (), *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2948 | } |
| 2949 | else |
| 2950 | rv = VPPCOM_EINVAL; |
| 2951 | break; |
| 2952 | |
| 2953 | case VPPCOM_ATTR_SET_TCP_USER_MSS: |
| 2954 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 2955 | { |
| 2956 | /* VPP-TBD */ |
| 2957 | session->user_mss = *(u32 *) buffer; |
| 2958 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2959 | VDBG (2, "VCL<%d>: VPPCOM_ATTR_SET_TCP_USER_MSS: %u, buflen %d, " |
| 2960 | "#VPP-TBD#", getpid (), session->user_mss, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 2961 | } |
| 2962 | else |
| 2963 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 2964 | break; |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 2965 | |
| 2966 | default: |
| 2967 | rv = VPPCOM_EINVAL; |
| 2968 | break; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2969 | } |
| 2970 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 2971 | return rv; |
| 2972 | } |
| 2973 | |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2974 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2975 | vppcom_session_recvfrom (uint32_t session_handle, void *buffer, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2976 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 2977 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2978 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2979 | int rv = VPPCOM_OK; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2980 | vcl_session_t *session = 0; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2981 | |
| 2982 | if (ep) |
| 2983 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2984 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2985 | if (PREDICT_FALSE (!session)) |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2986 | { |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 2987 | VDBG (0, "VCL<%d>: invalid session, sid (%u) has been closed!", |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2988 | getpid (), session_handle); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 2989 | return VPPCOM_EBADFD; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2990 | } |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2991 | ep->is_ip4 = session->transport.is_ip4; |
| 2992 | ep->port = session->transport.rmt_port; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2993 | } |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 2994 | |
| 2995 | if (flags == 0) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2996 | rv = vppcom_session_read (session_handle, buffer, buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2997 | else if (flags & MSG_PEEK) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2998 | rv = vppcom_session_peek (session_handle, buffer, buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 2999 | else |
| 3000 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3001 | clib_warning ("VCL<%d>: Unsupport flags for recvfrom %d", |
| 3002 | getpid (), flags); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 3003 | return VPPCOM_EAFNOSUPPORT; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3004 | } |
| 3005 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3006 | if (ep) |
| 3007 | { |
| 3008 | if (session->transport.is_ip4) |
| 3009 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip4, |
| 3010 | sizeof (ip4_address_t)); |
| 3011 | else |
| 3012 | clib_memcpy (ep->ip, &session->transport.rmt_ip.ip6, |
| 3013 | sizeof (ip6_address_t)); |
| 3014 | } |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 3015 | |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3016 | return rv; |
| 3017 | } |
| 3018 | |
| 3019 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3020 | vppcom_session_sendto (uint32_t session_handle, void *buffer, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3021 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 3022 | { |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 3023 | if (!buffer) |
| 3024 | return VPPCOM_EINVAL; |
| 3025 | |
| 3026 | if (ep) |
| 3027 | { |
| 3028 | // TBD |
| 3029 | return VPPCOM_EINVAL; |
| 3030 | } |
| 3031 | |
| 3032 | if (flags) |
| 3033 | { |
| 3034 | // TBD check the flags and do the right thing |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 3035 | VDBG (2, "VCL<%d>: handling flags 0x%u (%d) not implemented yet.", |
| 3036 | getpid (), flags, flags); |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 3037 | } |
| 3038 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3039 | return (vppcom_session_write (session_handle, buffer, buflen)); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3042 | int |
| 3043 | vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time) |
| 3044 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3045 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3046 | f64 timeout = clib_time_now (&wrk->clib_time) + wait_for_time; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3047 | u32 i, keep_trying = 1; |
| 3048 | int rv, num_ev = 0; |
| 3049 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 3050 | VDBG (3, "VCL<%d>: vp %p, nsids %u, wait_for_time %f", |
| 3051 | getpid (), vp, n_sids, wait_for_time); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3052 | |
| 3053 | if (!vp) |
| 3054 | return VPPCOM_EFAULT; |
| 3055 | |
| 3056 | do |
| 3057 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3058 | vcl_session_t *session; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3059 | |
| 3060 | for (i = 0; i < n_sids; i++) |
| 3061 | { |
| 3062 | ASSERT (vp[i].revents); |
| 3063 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3064 | session = vcl_session_get (wrk, vp[i].sid); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 3065 | if (!session) |
| 3066 | continue; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3067 | |
| 3068 | if (*vp[i].revents) |
| 3069 | *vp[i].revents = 0; |
| 3070 | |
| 3071 | if (POLLIN & vp[i].events) |
| 3072 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 3073 | rv = vppcom_session_read_ready (session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3074 | if (rv > 0) |
| 3075 | { |
| 3076 | *vp[i].revents |= POLLIN; |
| 3077 | num_ev++; |
| 3078 | } |
| 3079 | else if (rv < 0) |
| 3080 | { |
| 3081 | switch (rv) |
| 3082 | { |
| 3083 | case VPPCOM_ECONNRESET: |
| 3084 | *vp[i].revents = POLLHUP; |
| 3085 | break; |
| 3086 | |
| 3087 | default: |
| 3088 | *vp[i].revents = POLLERR; |
| 3089 | break; |
| 3090 | } |
| 3091 | num_ev++; |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | if (POLLOUT & vp[i].events) |
| 3096 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3097 | rv = vppcom_session_write_ready (session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3098 | if (rv > 0) |
| 3099 | { |
| 3100 | *vp[i].revents |= POLLOUT; |
| 3101 | num_ev++; |
| 3102 | } |
| 3103 | else if (rv < 0) |
| 3104 | { |
| 3105 | switch (rv) |
| 3106 | { |
| 3107 | case VPPCOM_ECONNRESET: |
| 3108 | *vp[i].revents = POLLHUP; |
| 3109 | break; |
| 3110 | |
| 3111 | default: |
| 3112 | *vp[i].revents = POLLERR; |
| 3113 | break; |
| 3114 | } |
| 3115 | num_ev++; |
| 3116 | } |
| 3117 | } |
| 3118 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 3119 | if (0) // Note "done:" label used by VCL_SESSION_LOCK_AND_GET() |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3120 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3121 | *vp[i].revents = POLLNVAL; |
| 3122 | num_ev++; |
| 3123 | } |
| 3124 | } |
| 3125 | if (wait_for_time != -1) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3126 | keep_trying = (clib_time_now (&wrk->clib_time) <= timeout) ? 1 : 0; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3127 | } |
| 3128 | while ((num_ev == 0) && keep_trying); |
| 3129 | |
| 3130 | if (VPPCOM_DEBUG > 3) |
| 3131 | { |
| 3132 | clib_warning ("VCL<%d>: returning %d", getpid (), num_ev); |
| 3133 | for (i = 0; i < n_sids; i++) |
| 3134 | { |
| 3135 | clib_warning ("VCL<%d>: vp[%d].sid %d (0x%x), .events 0x%x, " |
| 3136 | ".revents 0x%x", getpid (), i, vp[i].sid, vp[i].sid, |
| 3137 | vp[i].events, *vp[i].revents); |
| 3138 | } |
| 3139 | } |
| 3140 | return num_ev; |
| 3141 | } |
| 3142 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3143 | int |
| 3144 | vppcom_mq_epoll_fd (void) |
| 3145 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3146 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3147 | return wrk->mqs_epfd; |
| 3148 | } |
| 3149 | |
| 3150 | int |
| 3151 | vppcom_session_index (uint32_t session_handle) |
| 3152 | { |
| 3153 | return session_handle & 0xFFFFFF; |
| 3154 | } |
| 3155 | |
| 3156 | int |
| 3157 | vppcom_worker_register (void) |
| 3158 | { |
| 3159 | if (!vcl_worker_alloc_and_init ()) |
| 3160 | return VPPCOM_OK; |
| 3161 | return VPPCOM_EEXIST; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3162 | } |
| 3163 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 3164 | /* |
| 3165 | * fd.io coding-style-patch-verification: ON |
| 3166 | * |
| 3167 | * Local Variables: |
| 3168 | * eval: (c-set-style "gnu") |
| 3169 | * End: |
| 3170 | */ |