Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1 | /* |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 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 | 5c7cf1c | 2017-10-24 04:12:18 -0400 | [diff] [blame] | 18 | #include <vcl/vppcom.h> |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 19 | #include <vcl/vcl_debug.h> |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 20 | #include <vcl/vcl_private.h> |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 21 | #include <svm/fifo_segment.h> |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 22 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 23 | __thread uword __vcl_worker_index = ~0; |
| 24 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 25 | static int |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 26 | vcl_segment_is_not_mounted (vcl_worker_t * wrk, u64 segment_handle) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 27 | { |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 28 | u32 segment_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 29 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 30 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
Florin Coras | 5f45e01 | 2019-01-23 09:21:30 -0800 | [diff] [blame] | 31 | return 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 32 | |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 33 | segment_index = vcl_segment_table_lookup (segment_handle); |
| 34 | if (segment_index != VCL_INVALID_SEGMENT_INDEX) |
| 35 | return 0; |
| 36 | |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 37 | return 1; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 40 | static inline int |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 41 | vcl_mq_dequeue_batch (vcl_worker_t * wrk, svm_msg_q_t * mq, u32 n_max_msg) |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 42 | { |
| 43 | svm_msg_q_msg_t *msg; |
| 44 | u32 n_msgs; |
| 45 | int i; |
| 46 | |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 47 | n_msgs = clib_min (svm_msg_q_size (mq), n_max_msg); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 48 | for (i = 0; i < n_msgs; i++) |
| 49 | { |
| 50 | vec_add2 (wrk->mq_msg_vector, msg, 1); |
| 51 | svm_msg_q_sub_w_lock (mq, msg); |
| 52 | } |
| 53 | return n_msgs; |
| 54 | } |
| 55 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 56 | const char * |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 57 | vppcom_session_state_str (vcl_session_state_t state) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 58 | { |
| 59 | char *st; |
| 60 | |
| 61 | switch (state) |
| 62 | { |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 63 | case VCL_STATE_CLOSED: |
Florin Coras | 5414062 | 2020-02-04 19:04:34 +0000 | [diff] [blame] | 64 | st = "STATE_CLOSED"; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 65 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 66 | case VCL_STATE_LISTEN: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 67 | st = "STATE_LISTEN"; |
| 68 | break; |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 69 | case VCL_STATE_READY: |
| 70 | st = "STATE_READY"; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 71 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 72 | case VCL_STATE_VPP_CLOSING: |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 73 | st = "STATE_VPP_CLOSING"; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 74 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 75 | case VCL_STATE_DISCONNECT: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 76 | st = "STATE_DISCONNECT"; |
| 77 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 78 | case VCL_STATE_DETACHED: |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 79 | st = "STATE_DETACHED"; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 80 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 81 | case VCL_STATE_UPDATED: |
Florin Coras | 2d675d7 | 2019-01-28 15:54:27 -0800 | [diff] [blame] | 82 | st = "STATE_UPDATED"; |
| 83 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 84 | case VCL_STATE_LISTEN_NO_MQ: |
Florin Coras | 2d675d7 | 2019-01-28 15:54:27 -0800 | [diff] [blame] | 85 | st = "STATE_LISTEN_NO_MQ"; |
| 86 | break; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 87 | default: |
| 88 | st = "UNKNOWN_STATE"; |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | return st; |
| 93 | } |
| 94 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 95 | u8 * |
| 96 | format_ip4_address (u8 * s, va_list * args) |
| 97 | { |
| 98 | u8 *a = va_arg (*args, u8 *); |
| 99 | return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); |
| 100 | } |
| 101 | |
| 102 | u8 * |
| 103 | format_ip6_address (u8 * s, va_list * args) |
| 104 | { |
| 105 | ip6_address_t *a = va_arg (*args, ip6_address_t *); |
| 106 | u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon; |
| 107 | |
| 108 | i_max_n_zero = ARRAY_LEN (a->as_u16); |
| 109 | max_n_zeros = 0; |
| 110 | i_first_zero = i_max_n_zero; |
| 111 | n_zeros = 0; |
| 112 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 113 | { |
| 114 | u32 is_zero = a->as_u16[i] == 0; |
| 115 | if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16)) |
| 116 | { |
| 117 | i_first_zero = i; |
| 118 | n_zeros = 0; |
| 119 | } |
| 120 | n_zeros += is_zero; |
| 121 | if ((!is_zero && n_zeros > max_n_zeros) |
| 122 | || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros)) |
| 123 | { |
| 124 | i_max_n_zero = i_first_zero; |
| 125 | max_n_zeros = n_zeros; |
| 126 | i_first_zero = ARRAY_LEN (a->as_u16); |
| 127 | n_zeros = 0; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | last_double_colon = 0; |
| 132 | for (i = 0; i < ARRAY_LEN (a->as_u16); i++) |
| 133 | { |
| 134 | if (i == i_max_n_zero && max_n_zeros > 1) |
| 135 | { |
| 136 | s = format (s, "::"); |
| 137 | i += max_n_zeros - 1; |
| 138 | last_double_colon = 1; |
| 139 | } |
| 140 | else |
| 141 | { |
| 142 | s = format (s, "%s%x", |
| 143 | (last_double_colon || i == 0) ? "" : ":", |
| 144 | clib_net_to_host_u16 (a->as_u16[i])); |
| 145 | last_double_colon = 0; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return s; |
| 150 | } |
| 151 | |
| 152 | /* Format an IP46 address. */ |
| 153 | u8 * |
| 154 | format_ip46_address (u8 * s, va_list * args) |
| 155 | { |
| 156 | ip46_address_t *ip46 = va_arg (*args, ip46_address_t *); |
| 157 | ip46_type_t type = va_arg (*args, ip46_type_t); |
| 158 | int is_ip4 = 1; |
| 159 | |
| 160 | switch (type) |
| 161 | { |
| 162 | case IP46_TYPE_ANY: |
| 163 | is_ip4 = ip46_address_is_ip4 (ip46); |
| 164 | break; |
| 165 | case IP46_TYPE_IP4: |
| 166 | is_ip4 = 1; |
| 167 | break; |
| 168 | case IP46_TYPE_IP6: |
| 169 | is_ip4 = 0; |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | return is_ip4 ? |
| 174 | format (s, "%U", format_ip4_address, &ip46->ip4) : |
| 175 | format (s, "%U", format_ip6_address, &ip46->ip6); |
| 176 | } |
| 177 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 178 | /* |
| 179 | * VPPCOM Utility Functions |
| 180 | */ |
| 181 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 182 | static void |
| 183 | vcl_send_session_listen (vcl_worker_t * wrk, vcl_session_t * s) |
| 184 | { |
| 185 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 186 | session_listen_msg_t *mp; |
| 187 | svm_msg_q_t *mq; |
| 188 | |
| 189 | mq = vcl_worker_ctrl_mq (wrk); |
| 190 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_LISTEN); |
| 191 | mp = (session_listen_msg_t *) app_evt->evt->data; |
| 192 | memset (mp, 0, sizeof (*mp)); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 193 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 194 | mp->context = s->session_index; |
| 195 | mp->wrk_index = wrk->vpp_wrk_index; |
| 196 | mp->is_ip4 = s->transport.is_ip4; |
| 197 | clib_memcpy_fast (&mp->ip, &s->transport.lcl_ip, sizeof (mp->ip)); |
| 198 | mp->port = s->transport.lcl_port; |
| 199 | mp->proto = s->session_type; |
Florin Coras | 1e96617 | 2020-05-16 18:18:14 +0000 | [diff] [blame] | 200 | if (s->flags & VCL_SESSION_F_CONNECTED) |
| 201 | mp->flags = TRANSPORT_CFG_F_CONNECTED; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 202 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 203 | } |
| 204 | |
| 205 | static void |
| 206 | vcl_send_session_connect (vcl_worker_t * wrk, vcl_session_t * s) |
| 207 | { |
| 208 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 209 | session_connect_msg_t *mp; |
| 210 | svm_msg_q_t *mq; |
| 211 | |
| 212 | mq = vcl_worker_ctrl_mq (wrk); |
| 213 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_CONNECT); |
| 214 | mp = (session_connect_msg_t *) app_evt->evt->data; |
| 215 | memset (mp, 0, sizeof (*mp)); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 216 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 217 | mp->context = s->session_index; |
| 218 | mp->wrk_index = wrk->vpp_wrk_index; |
| 219 | mp->is_ip4 = s->transport.is_ip4; |
| 220 | mp->parent_handle = s->parent_handle; |
| 221 | clib_memcpy_fast (&mp->ip, &s->transport.rmt_ip, sizeof (mp->ip)); |
Florin Coras | ef7cbf6 | 2019-10-17 09:56:27 -0700 | [diff] [blame] | 222 | clib_memcpy_fast (&mp->lcl_ip, &s->transport.lcl_ip, sizeof (mp->lcl_ip)); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 223 | mp->port = s->transport.rmt_port; |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 224 | mp->lcl_port = s->transport.lcl_port; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 225 | mp->proto = s->session_type; |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 226 | if (s->flags & VCL_SESSION_F_CONNECTED) |
| 227 | mp->flags |= TRANSPORT_CFG_F_CONNECTED; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 228 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 229 | } |
| 230 | |
| 231 | void |
| 232 | vcl_send_session_unlisten (vcl_worker_t * wrk, vcl_session_t * s) |
| 233 | { |
| 234 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 235 | session_unlisten_msg_t *mp; |
| 236 | svm_msg_q_t *mq; |
| 237 | |
| 238 | mq = vcl_worker_ctrl_mq (wrk); |
| 239 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_UNLISTEN); |
| 240 | mp = (session_unlisten_msg_t *) app_evt->evt->data; |
| 241 | memset (mp, 0, sizeof (*mp)); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 242 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 243 | mp->wrk_index = wrk->vpp_wrk_index; |
| 244 | mp->handle = s->vpp_handle; |
| 245 | mp->context = wrk->wrk_index; |
| 246 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 247 | } |
| 248 | |
| 249 | static void |
| 250 | vcl_send_session_disconnect (vcl_worker_t * wrk, vcl_session_t * s) |
| 251 | { |
| 252 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 253 | session_disconnect_msg_t *mp; |
| 254 | svm_msg_q_t *mq; |
| 255 | |
| 256 | /* Send to thread that owns the session */ |
| 257 | mq = s->vpp_evt_q; |
| 258 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_DISCONNECT); |
| 259 | mp = (session_disconnect_msg_t *) app_evt->evt->data; |
| 260 | memset (mp, 0, sizeof (*mp)); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 261 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 262 | mp->handle = s->vpp_handle; |
| 263 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 264 | } |
| 265 | |
| 266 | static void |
| 267 | vcl_send_app_detach (vcl_worker_t * wrk) |
| 268 | { |
| 269 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 270 | session_app_detach_msg_t *mp; |
| 271 | svm_msg_q_t *mq; |
| 272 | |
| 273 | mq = vcl_worker_ctrl_mq (wrk); |
| 274 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_APP_DETACH); |
| 275 | mp = (session_app_detach_msg_t *) app_evt->evt->data; |
| 276 | memset (mp, 0, sizeof (*mp)); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 277 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 278 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 279 | } |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 280 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 281 | static void |
| 282 | vcl_send_session_accepted_reply (svm_msg_q_t * mq, u32 context, |
| 283 | session_handle_t handle, int retval) |
| 284 | { |
| 285 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 286 | session_accepted_reply_msg_t *rmp; |
| 287 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_ACCEPTED_REPLY); |
| 288 | rmp = (session_accepted_reply_msg_t *) app_evt->evt->data; |
| 289 | rmp->handle = handle; |
| 290 | rmp->context = context; |
| 291 | rmp->retval = retval; |
| 292 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 293 | } |
| 294 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 295 | static void |
| 296 | vcl_send_session_disconnected_reply (svm_msg_q_t * mq, u32 context, |
| 297 | session_handle_t handle, int retval) |
| 298 | { |
| 299 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 300 | session_disconnected_reply_msg_t *rmp; |
| 301 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, |
| 302 | SESSION_CTRL_EVT_DISCONNECTED_REPLY); |
| 303 | rmp = (session_disconnected_reply_msg_t *) app_evt->evt->data; |
| 304 | rmp->handle = handle; |
| 305 | rmp->context = context; |
| 306 | rmp->retval = retval; |
| 307 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 308 | } |
| 309 | |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 310 | static void |
| 311 | vcl_send_session_reset_reply (svm_msg_q_t * mq, u32 context, |
| 312 | session_handle_t handle, int retval) |
| 313 | { |
| 314 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 315 | session_reset_reply_msg_t *rmp; |
| 316 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_RESET_REPLY); |
| 317 | rmp = (session_reset_reply_msg_t *) app_evt->evt->data; |
| 318 | rmp->handle = handle; |
| 319 | rmp->context = context; |
| 320 | rmp->retval = retval; |
| 321 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 322 | } |
| 323 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 324 | void |
| 325 | vcl_send_session_worker_update (vcl_worker_t * wrk, vcl_session_t * s, |
| 326 | u32 wrk_index) |
| 327 | { |
| 328 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 329 | session_worker_update_msg_t *mp; |
| 330 | svm_msg_q_t *mq; |
| 331 | |
| 332 | mq = vcl_session_vpp_evt_q (wrk, s); |
| 333 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_WORKER_UPDATE); |
| 334 | mp = (session_worker_update_msg_t *) app_evt->evt->data; |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 335 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 336 | mp->handle = s->vpp_handle; |
| 337 | mp->req_wrk_index = wrk->vpp_wrk_index; |
| 338 | mp->wrk_index = wrk_index; |
| 339 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
| 340 | } |
| 341 | |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 342 | int |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 343 | vcl_send_worker_rpc (u32 dst_wrk_index, void *data, u32 data_len) |
| 344 | { |
| 345 | app_session_evt_t _app_evt, *app_evt = &_app_evt; |
| 346 | session_app_wrk_rpc_msg_t *mp; |
| 347 | vcl_worker_t *dst_wrk, *wrk; |
| 348 | svm_msg_q_t *mq; |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 349 | int ret = -1; |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 350 | |
| 351 | if (data_len > sizeof (mp->data)) |
| 352 | goto done; |
| 353 | |
| 354 | clib_spinlock_lock (&vcm->workers_lock); |
| 355 | |
| 356 | dst_wrk = vcl_worker_get_if_valid (dst_wrk_index); |
| 357 | if (!dst_wrk) |
| 358 | goto done; |
| 359 | |
| 360 | wrk = vcl_worker_get_current (); |
| 361 | mq = vcl_worker_ctrl_mq (wrk); |
| 362 | app_alloc_ctrl_evt_to_vpp (mq, app_evt, SESSION_CTRL_EVT_APP_WRK_RPC); |
| 363 | mp = (session_app_wrk_rpc_msg_t *) app_evt->evt->data; |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 364 | mp->client_index = wrk->api_client_handle; |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 365 | mp->wrk_index = dst_wrk->vpp_wrk_index; |
| 366 | clib_memcpy (mp->data, data, data_len); |
| 367 | app_send_ctrl_evt_to_vpp (mq, app_evt); |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 368 | ret = 0; |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 369 | |
| 370 | done: |
| 371 | clib_spinlock_unlock (&vcm->workers_lock); |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 372 | return ret; |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 375 | static u32 |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 376 | vcl_session_accepted_handler (vcl_worker_t * wrk, session_accepted_msg_t * mp, |
| 377 | u32 ls_index) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 378 | { |
| 379 | vcl_session_t *session, *listen_session; |
| 380 | svm_fifo_t *rx_fifo, *tx_fifo; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 381 | u32 vpp_wrk_index; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 382 | svm_msg_q_t *evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 383 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 384 | session = vcl_session_alloc (wrk); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 385 | |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 386 | listen_session = vcl_session_get (wrk, ls_index); |
| 387 | if (listen_session->vpp_handle != mp->listener_handle) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 388 | { |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 389 | VDBG (0, "ERROR: listener handle %lu does not match session %u", |
| 390 | mp->listener_handle, ls_index); |
| 391 | goto error; |
| 392 | } |
| 393 | |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 394 | if (vcl_segment_is_not_mounted (wrk, mp->segment_handle)) |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 395 | { |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 396 | VDBG (0, "ERROR: segment for session %u is not mounted!", |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 397 | session->session_index); |
| 398 | goto error; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 399 | } |
| 400 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 401 | rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
| 402 | tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 403 | session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address, |
| 404 | svm_msg_q_t *); |
| 405 | rx_fifo->client_session_index = session->session_index; |
| 406 | tx_fifo->client_session_index = session->session_index; |
| 407 | rx_fifo->client_thread_index = vcl_get_worker_index (); |
| 408 | tx_fifo->client_thread_index = vcl_get_worker_index (); |
| 409 | vpp_wrk_index = tx_fifo->master_thread_index; |
| 410 | vec_validate (wrk->vpp_event_queues, vpp_wrk_index); |
| 411 | wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 412 | |
| 413 | session->vpp_handle = mp->handle; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 414 | session->vpp_thread_index = rx_fifo->master_thread_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 415 | session->rx_fifo = rx_fifo; |
| 416 | session->tx_fifo = tx_fifo; |
| 417 | |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 418 | session->session_state = VCL_STATE_READY; |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 419 | session->transport.rmt_port = mp->rmt.port; |
| 420 | session->transport.is_ip4 = mp->rmt.is_ip4; |
| 421 | clib_memcpy_fast (&session->transport.rmt_ip, &mp->rmt.ip, |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 422 | sizeof (ip46_address_t)); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 423 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 424 | vcl_session_table_add_vpp_handle (wrk, mp->handle, session->session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 425 | session->transport.lcl_port = listen_session->transport.lcl_port; |
| 426 | session->transport.lcl_ip = listen_session->transport.lcl_ip; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 427 | session->session_type = listen_session->session_type; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 428 | session->is_dgram = vcl_proto_is_dgram (session->session_type); |
| 429 | session->listener_index = listen_session->session_index; |
| 430 | listen_session->n_accepted_sessions++; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 431 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 432 | VDBG (1, "session %u [0x%llx]: client accept request from %s address %U" |
| 433 | " port %d queue %p!", session->session_index, mp->handle, |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 434 | mp->rmt.is_ip4 ? "IPv4" : "IPv6", format_ip46_address, &mp->rmt.ip, |
| 435 | mp->rmt.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 436 | clib_net_to_host_u16 (mp->rmt.port), session->vpp_evt_q); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 437 | vcl_evt (VCL_EVT_ACCEPT, session, listen_session, session_index); |
| 438 | |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 439 | vcl_send_session_accepted_reply (session->vpp_evt_q, mp->context, |
| 440 | session->vpp_handle, 0); |
| 441 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 442 | return session->session_index; |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 443 | |
| 444 | error: |
| 445 | evt_q = uword_to_pointer (mp->vpp_event_queue_address, svm_msg_q_t *); |
| 446 | vcl_send_session_accepted_reply (evt_q, mp->context, mp->handle, |
| 447 | VNET_API_ERROR_INVALID_ARGUMENT); |
| 448 | vcl_session_free (wrk, session); |
| 449 | return VCL_INVALID_SESSION_INDEX; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 453 | vcl_session_connected_handler (vcl_worker_t * wrk, |
| 454 | session_connected_msg_t * mp) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 455 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 456 | u32 session_index, vpp_wrk_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 457 | svm_fifo_t *rx_fifo, *tx_fifo; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 458 | vcl_session_t *session = 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 459 | |
| 460 | session_index = mp->context; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 461 | session = vcl_session_get (wrk, session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 462 | if (!session) |
| 463 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 464 | VDBG (0, "ERROR: vpp handle 0x%llx has no session index (%u)!", |
| 465 | mp->handle, session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 466 | return VCL_INVALID_SESSION_INDEX; |
| 467 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 468 | if (mp->retval) |
| 469 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 470 | VDBG (0, "ERROR: session index %u: connect failed! %U", |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 471 | session_index, format_session_error, mp->retval); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 472 | session->session_state = VCL_STATE_DETACHED; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 473 | session->vpp_handle = mp->handle; |
| 474 | return session_index; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Florin Coras | dbc9c59 | 2019-09-25 16:37:43 -0700 | [diff] [blame] | 477 | session->vpp_handle = mp->handle; |
| 478 | session->vpp_evt_q = uword_to_pointer (mp->vpp_event_queue_address, |
| 479 | svm_msg_q_t *); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 480 | rx_fifo = uword_to_pointer (mp->server_rx_fifo, svm_fifo_t *); |
| 481 | tx_fifo = uword_to_pointer (mp->server_tx_fifo, svm_fifo_t *); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 482 | if (vcl_segment_is_not_mounted (wrk, mp->segment_handle)) |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 483 | { |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 484 | VDBG (0, "segment for session %u is not mounted!", |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 485 | session->session_index); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 486 | session->session_state = VCL_STATE_DETACHED; |
Florin Coras | dbc9c59 | 2019-09-25 16:37:43 -0700 | [diff] [blame] | 487 | vcl_send_session_disconnect (wrk, session); |
| 488 | return session_index; |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 489 | } |
| 490 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 491 | rx_fifo->client_session_index = session_index; |
| 492 | tx_fifo->client_session_index = session_index; |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 493 | rx_fifo->client_thread_index = vcl_get_worker_index (); |
| 494 | tx_fifo->client_thread_index = vcl_get_worker_index (); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 495 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 496 | vpp_wrk_index = tx_fifo->master_thread_index; |
| 497 | vec_validate (wrk->vpp_event_queues, vpp_wrk_index); |
| 498 | wrk->vpp_event_queues[vpp_wrk_index] = session->vpp_evt_q; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 499 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 500 | if (mp->ct_rx_fifo) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 501 | { |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 502 | session->ct_rx_fifo = uword_to_pointer (mp->ct_rx_fifo, svm_fifo_t *); |
| 503 | session->ct_tx_fifo = uword_to_pointer (mp->ct_tx_fifo, svm_fifo_t *); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 504 | if (vcl_segment_is_not_mounted (wrk, mp->ct_segment_handle)) |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 505 | { |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 506 | VDBG (0, "ct segment for session %u is not mounted!", |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 507 | session->session_index); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 508 | session->session_state = VCL_STATE_DETACHED; |
Florin Coras | dbc9c59 | 2019-09-25 16:37:43 -0700 | [diff] [blame] | 509 | vcl_send_session_disconnect (wrk, session); |
| 510 | return session_index; |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 511 | } |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 512 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 513 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 514 | session->rx_fifo = rx_fifo; |
| 515 | session->tx_fifo = tx_fifo; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 516 | session->vpp_thread_index = rx_fifo->master_thread_index; |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 517 | session->transport.is_ip4 = mp->lcl.is_ip4; |
| 518 | clib_memcpy_fast (&session->transport.lcl_ip, &mp->lcl.ip, |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 519 | sizeof (session->transport.lcl_ip)); |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 520 | session->transport.lcl_port = mp->lcl.port; |
Florin Coras | a5ea821 | 2020-08-24 21:23:51 -0700 | [diff] [blame] | 521 | |
| 522 | /* Application closed session before connect reply */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 523 | if (vcl_session_has_attr (session, VCL_SESS_ATTR_NONBLOCK) |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 524 | && session->session_state == VCL_STATE_CLOSED) |
Florin Coras | a5ea821 | 2020-08-24 21:23:51 -0700 | [diff] [blame] | 525 | vcl_send_session_disconnect (wrk, session); |
| 526 | else |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 527 | session->session_state = VCL_STATE_READY; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 528 | |
| 529 | /* Add it to lookup table */ |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 530 | vcl_session_table_add_vpp_handle (wrk, mp->handle, session_index); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 531 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 532 | VDBG (1, "session %u [0x%llx] connected! rx_fifo %p, refcnt %d, tx_fifo %p," |
| 533 | " refcnt %d", session_index, mp->handle, session->rx_fifo, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 534 | session->rx_fifo->refcnt, session->tx_fifo, session->tx_fifo->refcnt); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 535 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 536 | return session_index; |
| 537 | } |
| 538 | |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 539 | static int |
| 540 | vcl_flag_accepted_session (vcl_session_t * session, u64 handle, u32 flags) |
| 541 | { |
| 542 | vcl_session_msg_t *accepted_msg; |
| 543 | int i; |
| 544 | |
| 545 | for (i = 0; i < vec_len (session->accept_evts_fifo); i++) |
| 546 | { |
| 547 | accepted_msg = &session->accept_evts_fifo[i]; |
| 548 | if (accepted_msg->accepted_msg.handle == handle) |
| 549 | { |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 550 | accepted_msg->flags |= flags; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 551 | return 1; |
| 552 | } |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 557 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 558 | vcl_session_reset_handler (vcl_worker_t * wrk, |
| 559 | session_reset_msg_t * reset_msg) |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 560 | { |
| 561 | vcl_session_t *session; |
| 562 | u32 sid; |
| 563 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 564 | sid = vcl_session_index_from_vpp_handle (wrk, reset_msg->handle); |
| 565 | session = vcl_session_get (wrk, sid); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 566 | if (!session) |
| 567 | { |
| 568 | VDBG (0, "request to reset unknown handle 0x%llx", reset_msg->handle); |
| 569 | return VCL_INVALID_SESSION_INDEX; |
| 570 | } |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 571 | |
| 572 | /* Caught a reset before actually accepting the session */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 573 | if (session->session_state == VCL_STATE_LISTEN) |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 574 | { |
| 575 | |
| 576 | if (!vcl_flag_accepted_session (session, reset_msg->handle, |
| 577 | VCL_ACCEPTED_F_RESET)) |
| 578 | VDBG (0, "session was not accepted!"); |
| 579 | return VCL_INVALID_SESSION_INDEX; |
| 580 | } |
| 581 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 582 | if (session->session_state != VCL_STATE_CLOSED) |
| 583 | session->session_state = VCL_STATE_DISCONNECT; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 584 | VDBG (0, "reset session %u [0x%llx]", sid, reset_msg->handle); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 585 | return sid; |
| 586 | } |
| 587 | |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 588 | static u32 |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 589 | 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] | 590 | { |
| 591 | vcl_session_t *session; |
| 592 | u32 sid = mp->context; |
| 593 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 594 | session = vcl_session_get (wrk, sid); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 595 | if (mp->retval) |
| 596 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 597 | VERR ("session %u [0x%llx]: bind failed: %U", sid, mp->handle, |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 598 | format_session_error, mp->retval); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 599 | if (session) |
| 600 | { |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 601 | session->session_state = VCL_STATE_DETACHED; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 602 | session->vpp_handle = mp->handle; |
| 603 | return sid; |
| 604 | } |
| 605 | else |
| 606 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 607 | VDBG (0, "ERROR: session %u [0x%llx]: Invalid session index!", |
| 608 | sid, mp->handle); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 609 | return VCL_INVALID_SESSION_INDEX; |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | session->vpp_handle = mp->handle; |
| 614 | session->transport.is_ip4 = mp->lcl_is_ip4; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 615 | clib_memcpy_fast (&session->transport.lcl_ip, mp->lcl_ip, |
| 616 | sizeof (ip46_address_t)); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 617 | session->transport.lcl_port = mp->lcl_port; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 618 | vcl_session_table_add_listener (wrk, mp->handle, sid); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 619 | session->session_state = VCL_STATE_LISTEN; |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 620 | |
Florin Coras | 5f45e01 | 2019-01-23 09:21:30 -0800 | [diff] [blame] | 621 | session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); |
| 622 | vec_validate (wrk->vpp_event_queues, 0); |
| 623 | wrk->vpp_event_queues[0] = session->vpp_evt_q; |
| 624 | |
Florin Coras | 6e3c1f8 | 2020-01-15 01:30:46 +0000 | [diff] [blame] | 625 | if (vcl_session_is_cl (session)) |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 626 | { |
| 627 | svm_fifo_t *rx_fifo, *tx_fifo; |
| 628 | session->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); |
| 629 | rx_fifo = uword_to_pointer (mp->rx_fifo, svm_fifo_t *); |
| 630 | rx_fifo->client_session_index = sid; |
| 631 | tx_fifo = uword_to_pointer (mp->tx_fifo, svm_fifo_t *); |
| 632 | tx_fifo->client_session_index = sid; |
| 633 | session->rx_fifo = rx_fifo; |
| 634 | session->tx_fifo = tx_fifo; |
| 635 | } |
| 636 | |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 637 | VDBG (0, "session %u [0x%llx]: listen succeeded!", sid, mp->handle); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 638 | return sid; |
| 639 | } |
| 640 | |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 641 | static void |
| 642 | vcl_session_unlisten_reply_handler (vcl_worker_t * wrk, void *data) |
| 643 | { |
| 644 | session_unlisten_reply_msg_t *mp = (session_unlisten_reply_msg_t *) data; |
| 645 | vcl_session_t *s; |
| 646 | |
| 647 | s = vcl_session_get_w_vpp_handle (wrk, mp->handle); |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 648 | if (!s) |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 649 | { |
| 650 | VDBG (0, "Unlisten reply with wrong handle %llx", mp->handle); |
| 651 | return; |
| 652 | } |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 653 | if (s->session_state != VCL_STATE_DISCONNECT) |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 654 | { |
| 655 | /* Connected udp listener */ |
| 656 | if (s->session_type == VPPCOM_PROTO_UDP |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 657 | && s->session_state == VCL_STATE_CLOSED) |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 658 | return; |
| 659 | |
| 660 | VDBG (0, "Unlisten session in wrong state %llx", mp->handle); |
| 661 | return; |
| 662 | } |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 663 | |
| 664 | if (mp->retval) |
| 665 | VDBG (0, "ERROR: session %u [0xllx]: unlisten failed: %U", |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 666 | s->session_index, mp->handle, format_session_error, mp->retval); |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 667 | |
| 668 | if (mp->context != wrk->wrk_index) |
| 669 | VDBG (0, "wrong context"); |
| 670 | |
| 671 | vcl_session_table_del_vpp_handle (wrk, mp->handle); |
| 672 | vcl_session_free (wrk, s); |
| 673 | } |
| 674 | |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 675 | static void |
| 676 | vcl_session_migrated_handler (vcl_worker_t * wrk, void *data) |
| 677 | { |
| 678 | session_migrated_msg_t *mp = (session_migrated_msg_t *) data; |
| 679 | vcl_session_t *s; |
| 680 | |
| 681 | s = vcl_session_get_w_vpp_handle (wrk, mp->handle); |
| 682 | if (!s) |
| 683 | { |
| 684 | VDBG (0, "Migrated notification with wrong handle %llx", mp->handle); |
| 685 | return; |
| 686 | } |
| 687 | |
| 688 | s->vpp_thread_index = mp->vpp_thread_index; |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 689 | s->vpp_handle = mp->new_handle; |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 690 | s->vpp_evt_q = uword_to_pointer (mp->vpp_evt_q, svm_msg_q_t *); |
| 691 | |
| 692 | vec_validate (wrk->vpp_event_queues, s->vpp_thread_index); |
| 693 | wrk->vpp_event_queues[s->vpp_thread_index] = s->vpp_evt_q; |
| 694 | |
| 695 | vcl_session_table_del_vpp_handle (wrk, mp->handle); |
| 696 | vcl_session_table_add_vpp_handle (wrk, mp->new_handle, s->session_index); |
| 697 | |
| 698 | /* Generate new tx event if we have outstanding data */ |
| 699 | if (svm_fifo_has_event (s->tx_fifo)) |
| 700 | app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index, |
| 701 | SESSION_IO_EVT_TX, SVM_Q_WAIT); |
| 702 | |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 703 | VDBG (0, "Migrated 0x%lx to thread %u 0x%lx", mp->handle, |
| 704 | s->vpp_thread_index, mp->new_handle); |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 707 | static vcl_session_t * |
| 708 | vcl_session_accepted (vcl_worker_t * wrk, session_accepted_msg_t * msg) |
| 709 | { |
| 710 | vcl_session_msg_t *vcl_msg; |
| 711 | vcl_session_t *session; |
| 712 | |
| 713 | session = vcl_session_get_w_vpp_handle (wrk, msg->handle); |
| 714 | if (PREDICT_FALSE (session != 0)) |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 715 | VWRN ("session overlap handle %lu state %u!", msg->handle, |
| 716 | session->session_state); |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 717 | |
| 718 | session = vcl_session_table_lookup_listener (wrk, msg->listener_handle); |
| 719 | if (!session) |
| 720 | { |
| 721 | VERR ("couldn't find listen session: listener handle %llx", |
| 722 | msg->listener_handle); |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | clib_fifo_add2 (session->accept_evts_fifo, vcl_msg); |
Florin Coras | e88845e | 2020-02-13 20:04:28 +0000 | [diff] [blame] | 727 | vcl_msg->flags = 0; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 728 | vcl_msg->accepted_msg = *msg; |
| 729 | /* Session handle points to listener until fully accepted by app */ |
| 730 | vcl_session_table_add_vpp_handle (wrk, msg->handle, session->session_index); |
| 731 | |
| 732 | return session; |
| 733 | } |
| 734 | |
| 735 | static vcl_session_t * |
| 736 | vcl_session_disconnected_handler (vcl_worker_t * wrk, |
| 737 | session_disconnected_msg_t * msg) |
| 738 | { |
| 739 | vcl_session_t *session; |
| 740 | |
| 741 | session = vcl_session_get_w_vpp_handle (wrk, msg->handle); |
| 742 | if (!session) |
| 743 | { |
| 744 | VDBG (0, "request to disconnect unknown handle 0x%llx", msg->handle); |
| 745 | return 0; |
| 746 | } |
| 747 | |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 748 | /* Late disconnect notification on a session that has been closed */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 749 | if (session->session_state == VCL_STATE_CLOSED) |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 750 | return 0; |
| 751 | |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 752 | /* Caught a disconnect before actually accepting the session */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 753 | if (session->session_state == VCL_STATE_LISTEN) |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 754 | { |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 755 | if (!vcl_flag_accepted_session (session, msg->handle, |
| 756 | VCL_ACCEPTED_F_CLOSED)) |
| 757 | VDBG (0, "session was not accepted!"); |
| 758 | return 0; |
| 759 | } |
| 760 | |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 761 | /* If not already reset change state */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 762 | if (session->session_state != VCL_STATE_DISCONNECT) |
| 763 | session->session_state = VCL_STATE_VPP_CLOSING; |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 764 | |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 765 | return session; |
| 766 | } |
| 767 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 768 | static void |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 769 | vcl_session_cleanup_handler (vcl_worker_t * wrk, void *data) |
| 770 | { |
| 771 | session_cleanup_msg_t *msg; |
| 772 | vcl_session_t *session; |
| 773 | |
| 774 | msg = (session_cleanup_msg_t *) data; |
| 775 | session = vcl_session_get_w_vpp_handle (wrk, msg->handle); |
| 776 | if (!session) |
| 777 | { |
| 778 | VDBG (0, "disconnect confirmed for unknown handle 0x%llx", msg->handle); |
| 779 | return; |
| 780 | } |
| 781 | |
Florin Coras | 36d4939 | 2020-04-24 23:00:11 +0000 | [diff] [blame] | 782 | if (msg->type == SESSION_CLEANUP_TRANSPORT) |
| 783 | { |
| 784 | /* Transport was cleaned up before we confirmed close. Probably the |
| 785 | * app is still waiting for some data that cannot be delivered. |
| 786 | * Confirm close to make sure everything is cleaned up */ |
Florin Coras | 0ff7eec | 2020-08-03 18:55:40 -0700 | [diff] [blame] | 787 | if (session->session_state == VCL_STATE_VPP_CLOSING |
| 788 | || session->session_state == VCL_STATE_DISCONNECT) |
| 789 | { |
| 790 | vcl_session_cleanup (wrk, session, vcl_session_handle (session), |
| 791 | 1 /* do_disconnect */ ); |
| 792 | /* Move to undetermined state to ensure that the session is not |
| 793 | * removed before both vpp and the app cleanup. |
| 794 | * - If the app closes first, the session is moved to CLOSED state |
| 795 | * and the session cleanup notification from vpp removes the |
| 796 | * session. |
| 797 | * - If vpp cleans up the session first, the session is moved to |
| 798 | * DETACHED state lower and subsequently the close from the app |
| 799 | * frees the session |
| 800 | */ |
| 801 | session->session_state = VCL_STATE_UPDATED; |
| 802 | } |
Florin Coras | 36d4939 | 2020-04-24 23:00:11 +0000 | [diff] [blame] | 803 | return; |
| 804 | } |
| 805 | |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 806 | vcl_session_table_del_vpp_handle (wrk, msg->handle); |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 807 | /* Should not happen. App did not close the connection so don't free it. */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 808 | if (session->session_state != VCL_STATE_CLOSED) |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 809 | { |
| 810 | VDBG (0, "app did not close session %d", session->session_index); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 811 | session->session_state = VCL_STATE_DETACHED; |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 812 | session->vpp_handle = VCL_INVALID_SESSION_HANDLE; |
| 813 | return; |
| 814 | } |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 815 | vcl_session_free (wrk, session); |
| 816 | } |
| 817 | |
| 818 | static void |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 819 | vcl_session_req_worker_update_handler (vcl_worker_t * wrk, void *data) |
| 820 | { |
| 821 | session_req_worker_update_msg_t *msg; |
| 822 | vcl_session_t *s; |
| 823 | |
| 824 | msg = (session_req_worker_update_msg_t *) data; |
| 825 | s = vcl_session_get_w_vpp_handle (wrk, msg->session_handle); |
| 826 | if (!s) |
| 827 | return; |
| 828 | |
| 829 | vec_add1 (wrk->pending_session_wrk_updates, s->session_index); |
| 830 | } |
| 831 | |
| 832 | static void |
| 833 | vcl_session_worker_update_reply_handler (vcl_worker_t * wrk, void *data) |
| 834 | { |
| 835 | session_worker_update_reply_msg_t *msg; |
| 836 | vcl_session_t *s; |
| 837 | |
| 838 | msg = (session_worker_update_reply_msg_t *) data; |
| 839 | s = vcl_session_get_w_vpp_handle (wrk, msg->handle); |
| 840 | if (!s) |
| 841 | { |
| 842 | VDBG (0, "unknown handle 0x%llx", msg->handle); |
| 843 | return; |
| 844 | } |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 845 | if (vcl_segment_is_not_mounted (wrk, msg->segment_handle)) |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 846 | { |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 847 | clib_warning ("segment for session %u is not mounted!", |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 848 | s->session_index); |
| 849 | return; |
| 850 | } |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 851 | |
Florin Coras | 5f45e01 | 2019-01-23 09:21:30 -0800 | [diff] [blame] | 852 | if (s->rx_fifo) |
| 853 | { |
| 854 | s->rx_fifo = uword_to_pointer (msg->rx_fifo, svm_fifo_t *); |
| 855 | s->tx_fifo = uword_to_pointer (msg->tx_fifo, svm_fifo_t *); |
| 856 | s->rx_fifo->client_session_index = s->session_index; |
| 857 | s->tx_fifo->client_session_index = s->session_index; |
| 858 | s->rx_fifo->client_thread_index = wrk->wrk_index; |
| 859 | s->tx_fifo->client_thread_index = wrk->wrk_index; |
| 860 | } |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 861 | s->session_state = VCL_STATE_UPDATED; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 862 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 863 | VDBG (0, "session %u[0x%llx] moved to worker %u", s->session_index, |
| 864 | s->vpp_handle, wrk->wrk_index); |
| 865 | } |
| 866 | |
Florin Coras | 935ce75 | 2020-09-08 22:43:47 -0700 | [diff] [blame] | 867 | static int |
| 868 | vcl_api_recv_fd (vcl_worker_t * wrk, int *fds, int n_fds) |
| 869 | { |
| 870 | |
| 871 | if (vcm->cfg.vpp_app_socket_api) |
| 872 | return vcl_sapi_recv_fds (wrk, fds, n_fds); |
| 873 | |
| 874 | return vcl_bapi_recv_fds (wrk, fds, n_fds); |
| 875 | } |
| 876 | |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 877 | static void |
| 878 | vcl_session_app_add_segment_handler (vcl_worker_t * wrk, void *data) |
| 879 | { |
| 880 | ssvm_segment_type_t seg_type = SSVM_SEGMENT_SHM; |
| 881 | session_app_add_segment_msg_t *msg; |
| 882 | u64 segment_handle; |
| 883 | int fd = -1; |
| 884 | |
| 885 | msg = (session_app_add_segment_msg_t *) data; |
| 886 | |
| 887 | if (msg->fd_flags) |
| 888 | { |
Florin Coras | 935ce75 | 2020-09-08 22:43:47 -0700 | [diff] [blame] | 889 | vcl_api_recv_fd (wrk, &fd, 1); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 890 | seg_type = SSVM_SEGMENT_MEMFD; |
| 891 | } |
| 892 | |
| 893 | segment_handle = msg->segment_handle; |
| 894 | if (segment_handle == VCL_INVALID_SEGMENT_HANDLE) |
| 895 | { |
| 896 | clib_warning ("invalid segment handle"); |
| 897 | return; |
| 898 | } |
| 899 | |
| 900 | if (vcl_segment_attach (segment_handle, (char *) msg->segment_name, |
| 901 | seg_type, fd)) |
| 902 | { |
| 903 | VDBG (0, "vcl_segment_attach ('%s') failed", msg->segment_name); |
| 904 | return; |
| 905 | } |
| 906 | |
| 907 | VDBG (1, "mapped new segment '%s' size %d", msg->segment_name, |
| 908 | msg->segment_size); |
| 909 | } |
| 910 | |
| 911 | static void |
| 912 | vcl_session_app_del_segment_handler (vcl_worker_t * wrk, void *data) |
| 913 | { |
| 914 | session_app_del_segment_msg_t *msg = (session_app_del_segment_msg_t *) data; |
| 915 | vcl_segment_detach (msg->segment_handle); |
| 916 | VDBG (1, "Unmapped segment: %d", msg->segment_handle); |
| 917 | } |
| 918 | |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 919 | static void |
| 920 | vcl_worker_rpc_handler (vcl_worker_t * wrk, void *data) |
| 921 | { |
| 922 | if (!vcm->wrk_rpc_fn) |
| 923 | return; |
| 924 | |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 925 | (vcm->wrk_rpc_fn) (((session_app_wrk_rpc_msg_t *) data)->data); |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 926 | } |
| 927 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 928 | static int |
| 929 | vcl_handle_mq_event (vcl_worker_t * wrk, session_event_t * e) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 930 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 931 | session_disconnected_msg_t *disconnected_msg; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 932 | vcl_session_t *s; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 933 | |
| 934 | switch (e->event_type) |
| 935 | { |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 936 | case SESSION_IO_EVT_RX: |
| 937 | case SESSION_IO_EVT_TX: |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 938 | s = vcl_session_get (wrk, e->session_index); |
Florin Coras | 1bc919e | 2020-10-18 20:17:49 -0700 | [diff] [blame] | 939 | if (!s || !vcl_session_is_open (s)) |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 940 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 941 | vec_add1 (wrk->unhandled_evts_vector, *e); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 942 | break; |
| 943 | case SESSION_CTRL_EVT_ACCEPTED: |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 944 | vcl_session_accepted (wrk, (session_accepted_msg_t *) e->data); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 945 | break; |
| 946 | case SESSION_CTRL_EVT_CONNECTED: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 947 | vcl_session_connected_handler (wrk, |
| 948 | (session_connected_msg_t *) e->data); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 949 | break; |
| 950 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 951 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 952 | s = vcl_session_disconnected_handler (wrk, disconnected_msg); |
| 953 | if (!s) |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 954 | break; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 955 | VDBG (0, "disconnected session %u [0x%llx]", s->session_index, |
| 956 | s->vpp_handle); |
Florin Coras | c9fbd66 | 2018-08-24 12:59:56 -0700 | [diff] [blame] | 957 | break; |
| 958 | case SESSION_CTRL_EVT_RESET: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 959 | vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data); |
Florin Coras | 6011699 | 2018-08-27 09:52:18 -0700 | [diff] [blame] | 960 | break; |
| 961 | case SESSION_CTRL_EVT_BOUND: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 962 | vcl_session_bound_handler (wrk, (session_bound_msg_t *) e->data); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 963 | break; |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 964 | case SESSION_CTRL_EVT_UNLISTEN_REPLY: |
| 965 | vcl_session_unlisten_reply_handler (wrk, e->data); |
| 966 | break; |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 967 | case SESSION_CTRL_EVT_MIGRATED: |
| 968 | vcl_session_migrated_handler (wrk, e->data); |
| 969 | break; |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 970 | case SESSION_CTRL_EVT_CLEANUP: |
| 971 | vcl_session_cleanup_handler (wrk, e->data); |
| 972 | break; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 973 | case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: |
| 974 | vcl_session_req_worker_update_handler (wrk, e->data); |
| 975 | break; |
| 976 | case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY: |
| 977 | vcl_session_worker_update_reply_handler (wrk, e->data); |
| 978 | break; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 979 | case SESSION_CTRL_EVT_APP_ADD_SEGMENT: |
| 980 | vcl_session_app_add_segment_handler (wrk, e->data); |
| 981 | break; |
| 982 | case SESSION_CTRL_EVT_APP_DEL_SEGMENT: |
| 983 | vcl_session_app_del_segment_handler (wrk, e->data); |
| 984 | break; |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 985 | case SESSION_CTRL_EVT_APP_WRK_RPC: |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 986 | vcl_worker_rpc_handler (wrk, e->data); |
| 987 | break; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 988 | default: |
| 989 | clib_warning ("unhandled %u", e->event_type); |
| 990 | } |
| 991 | return VPPCOM_OK; |
| 992 | } |
| 993 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 994 | static int |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 995 | vppcom_wait_for_session_state_change (u32 session_index, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 996 | vcl_session_state_t state, |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 997 | f64 wait_for_time) |
| 998 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 999 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 1000 | f64 timeout = clib_time_now (&wrk->clib_time) + wait_for_time; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1001 | vcl_session_t *volatile session; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1002 | svm_msg_q_msg_t msg; |
| 1003 | session_event_t *e; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1004 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1005 | do |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1006 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1007 | session = vcl_session_get (wrk, session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1008 | if (PREDICT_FALSE (!session)) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1009 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1010 | return VPPCOM_EBADFD; |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1011 | } |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 1012 | if (session->session_state == state) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1013 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1014 | return VPPCOM_OK; |
| 1015 | } |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1016 | if (session->session_state == VCL_STATE_DETACHED) |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1017 | { |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1018 | return VPPCOM_ECONNREFUSED; |
| 1019 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1020 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1021 | if (svm_msg_q_sub (wrk->app_event_queue, &msg, SVM_Q_NOWAIT, 0)) |
Florin Coras | dc2e251 | 2018-12-03 17:47:26 -0800 | [diff] [blame] | 1022 | { |
| 1023 | usleep (100); |
| 1024 | continue; |
| 1025 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1026 | e = svm_msg_q_msg_data (wrk->app_event_queue, &msg); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 1027 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1028 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1029 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1030 | while (clib_time_now (&wrk->clib_time) < timeout); |
Florin Coras | dcf55ce | 2017-11-16 15:32:50 -0800 | [diff] [blame] | 1031 | |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 1032 | VDBG (0, "timeout waiting for state 0x%x (%s)", state, |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1033 | vppcom_session_state_str (state)); |
| 1034 | vcl_evt (VCL_EVT_SESSION_TIMEOUT, session, session_state); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1035 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1036 | return VPPCOM_ETIMEDOUT; |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1037 | } |
| 1038 | |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1039 | static void |
| 1040 | vcl_handle_pending_wrk_updates (vcl_worker_t * wrk) |
| 1041 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1042 | vcl_session_state_t state; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1043 | vcl_session_t *s; |
| 1044 | u32 *sip; |
| 1045 | |
| 1046 | if (PREDICT_TRUE (vec_len (wrk->pending_session_wrk_updates) == 0)) |
| 1047 | return; |
| 1048 | |
| 1049 | vec_foreach (sip, wrk->pending_session_wrk_updates) |
| 1050 | { |
| 1051 | s = vcl_session_get (wrk, *sip); |
| 1052 | vcl_send_session_worker_update (wrk, s, wrk->wrk_index); |
| 1053 | state = s->session_state; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1054 | vppcom_wait_for_session_state_change (s->session_index, VCL_STATE_UPDATED, |
| 1055 | 5); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1056 | s->session_state = state; |
| 1057 | } |
| 1058 | vec_reset_length (wrk->pending_session_wrk_updates); |
| 1059 | } |
| 1060 | |
Florin Coras | f9240dc | 2019-01-15 08:03:17 -0800 | [diff] [blame] | 1061 | void |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1062 | vcl_flush_mq_events (void) |
| 1063 | { |
| 1064 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 1065 | svm_msg_q_msg_t *msg; |
| 1066 | session_event_t *e; |
| 1067 | svm_msg_q_t *mq; |
| 1068 | int i; |
| 1069 | |
| 1070 | mq = wrk->app_event_queue; |
| 1071 | svm_msg_q_lock (mq); |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 1072 | vcl_mq_dequeue_batch (wrk, mq, ~0); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 1073 | svm_msg_q_unlock (mq); |
| 1074 | |
| 1075 | for (i = 0; i < vec_len (wrk->mq_msg_vector); i++) |
| 1076 | { |
| 1077 | msg = vec_elt_at_index (wrk->mq_msg_vector, i); |
| 1078 | e = svm_msg_q_msg_data (mq, msg); |
| 1079 | vcl_handle_mq_event (wrk, e); |
| 1080 | svm_msg_q_free_msg (mq, msg); |
| 1081 | } |
| 1082 | vec_reset_length (wrk->mq_msg_vector); |
| 1083 | vcl_handle_pending_wrk_updates (wrk); |
| 1084 | } |
| 1085 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1086 | static int |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1087 | vppcom_session_unbind (u32 session_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1088 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1089 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | aaff5ee | 2019-07-08 13:00:00 -0700 | [diff] [blame] | 1090 | session_accepted_msg_t *accepted_msg; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1091 | vcl_session_t *session = 0; |
Florin Coras | aaff5ee | 2019-07-08 13:00:00 -0700 | [diff] [blame] | 1092 | vcl_session_msg_t *evt; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1093 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1094 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1095 | if (!session) |
| 1096 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1097 | |
Florin Coras | aaff5ee | 2019-07-08 13:00:00 -0700 | [diff] [blame] | 1098 | /* Flush pending accept events, if any */ |
| 1099 | while (clib_fifo_elts (session->accept_evts_fifo)) |
| 1100 | { |
| 1101 | clib_fifo_sub2 (session->accept_evts_fifo, evt); |
| 1102 | accepted_msg = &evt->accepted_msg; |
| 1103 | vcl_session_table_del_vpp_handle (wrk, accepted_msg->handle); |
| 1104 | vcl_send_session_accepted_reply (session->vpp_evt_q, |
| 1105 | accepted_msg->context, |
| 1106 | session->vpp_handle, -1); |
| 1107 | } |
| 1108 | clib_fifo_free (session->accept_evts_fifo); |
| 1109 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1110 | vcl_send_session_unlisten (wrk, session); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1111 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1112 | VDBG (1, "session %u [0x%llx]: sending unbind!", session->session_index, |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1113 | session->vpp_handle); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1114 | vcl_evt (VCL_EVT_UNBIND, session); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1115 | |
| 1116 | session->vpp_handle = ~0; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1117 | session->session_state = VCL_STATE_DISCONNECT; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1118 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1119 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
Florin Coras | 697faea | 2018-06-27 17:10:49 -0700 | [diff] [blame] | 1122 | static int |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1123 | vppcom_session_disconnect (u32 session_handle) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1124 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1125 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1126 | svm_msg_q_t *vpp_evt_q; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1127 | vcl_session_t *session, *listen_session; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1128 | vcl_session_state_t state; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1129 | u64 vpp_handle; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1130 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1131 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 2179513 | 2018-09-09 09:40:51 -0700 | [diff] [blame] | 1132 | if (!session) |
| 1133 | return VPPCOM_EBADFD; |
| 1134 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1135 | vpp_handle = session->vpp_handle; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1136 | state = session->session_state; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1137 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1138 | VDBG (1, "session %u [0x%llx] state 0x%x (%s)", session->session_index, |
| 1139 | vpp_handle, state, vppcom_session_state_str (state)); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 1140 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1141 | if (PREDICT_FALSE (state == VCL_STATE_LISTEN)) |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 1142 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1143 | VDBG (0, "ERROR: Cannot disconnect a listen socket!"); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1144 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1145 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 1146 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1147 | if (state == VCL_STATE_VPP_CLOSING) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1148 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1149 | vpp_evt_q = vcl_session_vpp_evt_q (wrk, session); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 1150 | vcl_send_session_disconnected_reply (vpp_evt_q, wrk->api_client_handle, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1151 | vpp_handle, 0); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1152 | VDBG (1, "session %u [0x%llx]: sending disconnect REPLY...", |
| 1153 | session->session_index, vpp_handle); |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 1154 | } |
| 1155 | else |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 1156 | { |
Florin Coras | a5ea821 | 2020-08-24 21:23:51 -0700 | [diff] [blame] | 1157 | /* Session doesn't have an event queue yet. Probably a non-blocking |
| 1158 | * connect. Wait for the reply */ |
| 1159 | if (PREDICT_FALSE (!session->vpp_evt_q)) |
| 1160 | return VPPCOM_OK; |
| 1161 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1162 | VDBG (1, "session %u [0x%llx]: sending disconnect...", |
| 1163 | session->session_index, vpp_handle); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1164 | vcl_send_session_disconnect (wrk, session); |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 1165 | } |
Dave Wallace | 66cf6eb | 2017-10-26 02:51:07 -0400 | [diff] [blame] | 1166 | |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1167 | if (session->listener_index != VCL_INVALID_SESSION_INDEX) |
| 1168 | { |
| 1169 | listen_session = vcl_session_get (wrk, session->listener_index); |
| 1170 | listen_session->n_accepted_sessions--; |
| 1171 | } |
| 1172 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1173 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Florin Coras | 940f78f | 2018-11-30 12:11:20 -0800 | [diff] [blame] | 1176 | /** |
| 1177 | * Handle app exit |
| 1178 | * |
| 1179 | * Notify vpp of the disconnect and mark the worker as free. If we're the |
| 1180 | * last worker, do a full cleanup otherwise, since we're probably a forked |
| 1181 | * child, avoid syscalls as much as possible. We might've lost privileges. |
| 1182 | */ |
| 1183 | void |
| 1184 | vppcom_app_exit (void) |
| 1185 | { |
| 1186 | if (!pool_elts (vcm->workers)) |
| 1187 | return; |
Florin Coras | 01f3f89 | 2018-12-02 12:45:53 -0800 | [diff] [blame] | 1188 | vcl_worker_cleanup (vcl_worker_get_current (), 1 /* notify vpp */ ); |
| 1189 | vcl_set_worker_index (~0); |
Florin Coras | 940f78f | 2018-11-30 12:11:20 -0800 | [diff] [blame] | 1190 | vcl_elog_stop (vcm); |
Florin Coras | 940f78f | 2018-11-30 12:11:20 -0800 | [diff] [blame] | 1191 | } |
| 1192 | |
Florin Coras | 935ce75 | 2020-09-08 22:43:47 -0700 | [diff] [blame] | 1193 | static int |
| 1194 | vcl_api_attach (void) |
| 1195 | { |
| 1196 | if (vcm->cfg.vpp_app_socket_api) |
| 1197 | return vcl_sapi_attach (); |
| 1198 | |
| 1199 | return vcl_bapi_attach (); |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | vcl_api_detach (vcl_worker_t * wrk) |
| 1204 | { |
| 1205 | vcl_send_app_detach (wrk); |
| 1206 | |
| 1207 | if (vcm->cfg.vpp_app_socket_api) |
| 1208 | return vcl_sapi_detach (wrk); |
| 1209 | |
| 1210 | return vcl_bapi_disconnect_from_vpp (); |
| 1211 | } |
| 1212 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1213 | /* |
| 1214 | * VPPCOM Public API functions |
| 1215 | */ |
| 1216 | int |
Florin Coras | 66ec467 | 2020-06-15 07:59:40 -0700 | [diff] [blame] | 1217 | vppcom_app_create (const char *app_name) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1218 | { |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1219 | vppcom_cfg_t *vcl_cfg = &vcm->cfg; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1220 | int rv; |
| 1221 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1222 | if (vcm->is_init) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1223 | { |
Florin Coras | 955bfbb | 2018-12-04 13:43:45 -0800 | [diff] [blame] | 1224 | VDBG (1, "already initialized"); |
| 1225 | return VPPCOM_EEXIST; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1226 | } |
| 1227 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1228 | vcm->is_init = 1; |
| 1229 | vppcom_cfg (&vcm->cfg); |
| 1230 | vcl_cfg = &vcm->cfg; |
| 1231 | |
| 1232 | vcm->main_cpu = pthread_self (); |
| 1233 | vcm->main_pid = getpid (); |
| 1234 | vcm->app_name = format (0, "%s", app_name); |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 1235 | fifo_segment_main_init (&vcm->segment_main, vcl_cfg->segment_baseva, |
| 1236 | 20 /* timeout in secs */ ); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1237 | pool_alloc (vcm->workers, vcl_cfg->max_workers); |
| 1238 | clib_spinlock_init (&vcm->workers_lock); |
Florin Coras | d85de68 | 2018-11-29 17:02:29 -0800 | [diff] [blame] | 1239 | clib_rwlock_init (&vcm->segment_table_lock); |
Florin Coras | 940f78f | 2018-11-30 12:11:20 -0800 | [diff] [blame] | 1240 | atexit (vppcom_app_exit); |
Florin Coras | b88de90 | 2020-09-08 16:47:57 -0700 | [diff] [blame] | 1241 | vcl_elog_init (vcm); |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1242 | |
| 1243 | /* Allocate default worker */ |
| 1244 | vcl_worker_alloc_and_init (); |
| 1245 | |
Florin Coras | 935ce75 | 2020-09-08 22:43:47 -0700 | [diff] [blame] | 1246 | if ((rv = vcl_api_attach ())) |
Florin Coras | b88de90 | 2020-09-08 16:47:57 -0700 | [diff] [blame] | 1247 | return rv; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1248 | |
| 1249 | VDBG (0, "app_name '%s', my_client_index %d (0x%x)", app_name, |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 1250 | vcm->workers[0].api_client_handle, vcm->workers[0].api_client_handle); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1251 | |
| 1252 | return VPPCOM_OK; |
| 1253 | } |
| 1254 | |
| 1255 | void |
| 1256 | vppcom_app_destroy (void) |
| 1257 | { |
Florin Coras | dc0ded7 | 2020-04-30 02:59:55 +0000 | [diff] [blame] | 1258 | vcl_worker_t *wrk, *current_wrk; |
Damjan Marion | 4537c30 | 2020-09-28 19:03:37 +0200 | [diff] [blame] | 1259 | void *heap; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1260 | |
Florin Coras | 940f78f | 2018-11-30 12:11:20 -0800 | [diff] [blame] | 1261 | if (!pool_elts (vcm->workers)) |
| 1262 | return; |
| 1263 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1264 | vcl_evt (VCL_EVT_DETACH, vcm); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 1265 | |
Florin Coras | dc0ded7 | 2020-04-30 02:59:55 +0000 | [diff] [blame] | 1266 | current_wrk = vcl_worker_get_current (); |
Keith Burns (alagalah) | 8aa9aaf | 2018-01-05 12:16:22 -0800 | [diff] [blame] | 1267 | |
Florin Coras | ce815de | 2020-04-16 18:47:27 +0000 | [diff] [blame] | 1268 | /* *INDENT-OFF* */ |
| 1269 | pool_foreach (wrk, vcm->workers, ({ |
Florin Coras | dc0ded7 | 2020-04-30 02:59:55 +0000 | [diff] [blame] | 1270 | if (current_wrk != wrk) |
| 1271 | vcl_worker_cleanup (wrk, 0 /* notify vpp */ ); |
Florin Coras | ce815de | 2020-04-16 18:47:27 +0000 | [diff] [blame] | 1272 | })); |
| 1273 | /* *INDENT-ON* */ |
| 1274 | |
Florin Coras | 935ce75 | 2020-09-08 22:43:47 -0700 | [diff] [blame] | 1275 | vcl_api_detach (current_wrk); |
Florin Coras | dc0ded7 | 2020-04-30 02:59:55 +0000 | [diff] [blame] | 1276 | vcl_worker_cleanup (current_wrk, 0 /* notify vpp */ ); |
| 1277 | |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1278 | vcl_elog_stop (vcm); |
Florin Coras | ce815de | 2020-04-16 18:47:27 +0000 | [diff] [blame] | 1279 | |
| 1280 | /* |
| 1281 | * Free the heap and fix vcm |
| 1282 | */ |
| 1283 | heap = clib_mem_get_heap (); |
Damjan Marion | 4537c30 | 2020-09-28 19:03:37 +0200 | [diff] [blame] | 1284 | munmap (clib_mem_get_heap_base (heap), clib_mem_get_heap_size (heap)); |
Florin Coras | ce815de | 2020-04-16 18:47:27 +0000 | [diff] [blame] | 1285 | |
| 1286 | vcm = &_vppcom_main; |
Florin Coras | 69d9725 | 2020-05-11 17:19:31 +0000 | [diff] [blame] | 1287 | vcm->is_init = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | int |
Dave Wallace | c04cbf1 | 2018-02-07 18:14:02 -0500 | [diff] [blame] | 1291 | vppcom_session_create (u8 proto, u8 is_nonblocking) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1292 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1293 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1294 | vcl_session_t *session; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1295 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1296 | session = vcl_session_alloc (wrk); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1297 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1298 | session->session_type = proto; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1299 | session->session_state = VCL_STATE_CLOSED; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1300 | session->vpp_handle = ~0; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1301 | session->is_dgram = vcl_proto_is_dgram (proto); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1302 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1303 | if (is_nonblocking) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1304 | vcl_session_set_attr (session, VCL_SESS_ATTR_NONBLOCK); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1305 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1306 | vcl_evt (VCL_EVT_CREATE, session, session_type, session->session_state, |
| 1307 | is_nonblocking, session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 1308 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1309 | VDBG (0, "created session %u", session->session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 1310 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1311 | return vcl_session_handle (session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | int |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1315 | vcl_session_cleanup (vcl_worker_t * wrk, vcl_session_t * s, |
Florin Coras | f9240dc | 2019-01-15 08:03:17 -0800 | [diff] [blame] | 1316 | vcl_session_handle_t sh, u8 do_disconnect) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1317 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1318 | int rv = VPPCOM_OK; |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 1319 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1320 | VDBG (1, "session %u [0x%llx] closing", s->session_index, s->vpp_handle); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1321 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1322 | if (s->flags & VCL_SESSION_F_IS_VEP) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1323 | { |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1324 | u32 next_sh = s->vep.next_sh; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1325 | while (next_sh != ~0) |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 1326 | { |
Florin Coras | f9240dc | 2019-01-15 08:03:17 -0800 | [diff] [blame] | 1327 | rv = vppcom_epoll_ctl (sh, EPOLL_CTL_DEL, next_sh, 0); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1328 | if (PREDICT_FALSE (rv < 0)) |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1329 | VDBG (0, "vpp handle 0x%llx, sh %u: EPOLL_CTL_DEL vep_idx %u" |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1330 | " failed! rv %d (%s)", s->vpp_handle, next_sh, |
| 1331 | s->vep.vep_sh, rv, vppcom_retval_str (rv)); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1332 | next_sh = s->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1333 | } |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1334 | goto cleanup; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1335 | } |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1336 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1337 | if (s->flags & VCL_SESSION_F_IS_VEP_SESSION) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1338 | { |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1339 | rv = vppcom_epoll_ctl (s->vep.vep_sh, EPOLL_CTL_DEL, sh, 0); |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1340 | if (rv < 0) |
| 1341 | VDBG (0, "session %u [0x%llx]: EPOLL_CTL_DEL vep_idx %u " |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1342 | "failed! rv %d (%s)", s->session_index, s->vpp_handle, |
| 1343 | s->vep.vep_sh, rv, vppcom_retval_str (rv)); |
Dave Wallace | 1948161 | 2017-09-15 18:47:44 -0400 | [diff] [blame] | 1344 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1345 | |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1346 | if (!do_disconnect) |
| 1347 | { |
| 1348 | VDBG (1, "session %u [0x%llx] disconnect skipped", |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1349 | s->session_index, s->vpp_handle); |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1350 | goto cleanup; |
| 1351 | } |
| 1352 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1353 | if (s->session_state == VCL_STATE_LISTEN) |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1354 | { |
| 1355 | rv = vppcom_session_unbind (sh); |
| 1356 | if (PREDICT_FALSE (rv < 0)) |
| 1357 | VDBG (0, "session %u [0x%llx]: listener unbind failed! " |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1358 | "rv %d (%s)", s->session_index, s->vpp_handle, rv, |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1359 | vppcom_retval_str (rv)); |
| 1360 | return rv; |
| 1361 | } |
Florin Coras | 1bc919e | 2020-10-18 20:17:49 -0700 | [diff] [blame] | 1362 | else if (vcl_session_is_ready (s) |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1363 | || (vcl_session_is_connectable_listener (wrk, s))) |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1364 | { |
| 1365 | rv = vppcom_session_disconnect (sh); |
| 1366 | if (PREDICT_FALSE (rv < 0)) |
| 1367 | VDBG (0, "ERROR: session %u [0x%llx]: disconnect failed!" |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1368 | " rv %d (%s)", s->session_index, s->vpp_handle, |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1369 | rv, vppcom_retval_str (rv)); |
| 1370 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1371 | else if (s->session_state == VCL_STATE_DISCONNECT) |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1372 | { |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1373 | svm_msg_q_t *mq = vcl_session_vpp_evt_q (wrk, s); |
Florin Coras | cc7c88e | 2020-09-15 15:56:51 -0700 | [diff] [blame] | 1374 | vcl_send_session_reset_reply (mq, wrk->api_client_handle, |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1375 | s->vpp_handle, 0); |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1376 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1377 | else if (s->session_state == VCL_STATE_DETACHED) |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 1378 | { |
| 1379 | /* Should not happen. VPP cleaned up before app confirmed close */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1380 | VDBG (0, "vpp freed session %d before close", s->session_index); |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 1381 | goto free_session; |
| 1382 | } |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1383 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1384 | s->session_state = VCL_STATE_CLOSED; |
Florin Coras | 5414062 | 2020-02-04 19:04:34 +0000 | [diff] [blame] | 1385 | |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 1386 | /* Session is removed only after vpp confirms the disconnect */ |
| 1387 | return rv; |
Florin Coras | 0ef8ef2 | 2019-01-18 08:37:13 -0800 | [diff] [blame] | 1388 | |
Florin Coras | f9240dc | 2019-01-15 08:03:17 -0800 | [diff] [blame] | 1389 | cleanup: |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1390 | vcl_session_table_del_vpp_handle (wrk, s->vpp_handle); |
Florin Coras | adcfb15 | 2020-02-12 08:50:29 +0000 | [diff] [blame] | 1391 | free_session: |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1392 | vcl_session_free (wrk, s); |
| 1393 | vcl_evt (VCL_EVT_CLOSE, s, rv); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 1394 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1395 | return rv; |
| 1396 | } |
| 1397 | |
| 1398 | int |
Florin Coras | f9240dc | 2019-01-15 08:03:17 -0800 | [diff] [blame] | 1399 | vppcom_session_close (uint32_t session_handle) |
| 1400 | { |
| 1401 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 1402 | vcl_session_t *session; |
| 1403 | |
| 1404 | session = vcl_session_get_w_handle (wrk, session_handle); |
| 1405 | if (!session) |
| 1406 | return VPPCOM_EBADFD; |
| 1407 | return vcl_session_cleanup (wrk, session, session_handle, |
| 1408 | 1 /* do_disconnect */ ); |
| 1409 | } |
| 1410 | |
| 1411 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1412 | vppcom_session_bind (uint32_t session_handle, vppcom_endpt_t * ep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1413 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1414 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1415 | vcl_session_t *session = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1416 | |
| 1417 | if (!ep || !ep->ip) |
| 1418 | return VPPCOM_EINVAL; |
| 1419 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1420 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1421 | if (!session) |
| 1422 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1423 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1424 | if (session->flags & VCL_SESSION_F_IS_VEP) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1425 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1426 | VDBG (0, "ERROR: cannot bind to epoll session %u!", |
| 1427 | session->session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1428 | return VPPCOM_EBADFD; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1429 | } |
| 1430 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1431 | session->transport.is_ip4 = ep->is_ip4; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1432 | if (ep->is_ip4) |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1433 | clib_memcpy_fast (&session->transport.lcl_ip.ip4, ep->ip, |
| 1434 | sizeof (ip4_address_t)); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1435 | else |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1436 | clib_memcpy_fast (&session->transport.lcl_ip.ip6, ep->ip, |
| 1437 | sizeof (ip6_address_t)); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1438 | session->transport.lcl_port = ep->port; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 1439 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1440 | VDBG (0, "session %u handle %u: binding to local %s address %U port %u, " |
| 1441 | "proto %s", session->session_index, session_handle, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1442 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
| 1443 | format_ip46_address, &session->transport.lcl_ip, |
| 1444 | session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 1445 | clib_net_to_host_u16 (session->transport.lcl_port), |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 1446 | vppcom_proto_str (session->session_type)); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1447 | vcl_evt (VCL_EVT_BIND, session); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1448 | |
| 1449 | if (session->session_type == VPPCOM_PROTO_UDP) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1450 | vppcom_session_listen (session_handle, 10); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1451 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1452 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1456 | vppcom_session_listen (uint32_t listen_sh, uint32_t q_len) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1457 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1458 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1459 | vcl_session_t *listen_session = 0; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1460 | u64 listen_vpp_handle; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1461 | int rv; |
| 1462 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1463 | listen_session = vcl_session_get_w_handle (wrk, listen_sh); |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1464 | if (!listen_session || (listen_session->flags & VCL_SESSION_F_IS_VEP)) |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1465 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1466 | |
Keith Burns (alagalah) | aba98de | 2018-02-22 03:23:40 -0800 | [diff] [blame] | 1467 | if (q_len == 0 || q_len == ~0) |
| 1468 | q_len = vcm->cfg.listen_queue_size; |
| 1469 | |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1470 | listen_vpp_handle = listen_session->vpp_handle; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1471 | if (listen_session->session_state == VCL_STATE_LISTEN) |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 1472 | { |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 1473 | VDBG (0, "session %u [0x%llx]: already in listen state!", |
| 1474 | listen_sh, listen_vpp_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1475 | return VPPCOM_OK; |
Dave Wallace | e695cb4 | 2017-11-02 22:04:42 -0400 | [diff] [blame] | 1476 | } |
| 1477 | |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1478 | VDBG (0, "session %u: sending vpp listen request...", listen_sh); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1479 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1480 | /* |
| 1481 | * Send listen request to vpp and wait for reply |
| 1482 | */ |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1483 | vcl_send_session_listen (wrk, listen_session); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1484 | rv = vppcom_wait_for_session_state_change (listen_session->session_index, |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1485 | VCL_STATE_LISTEN, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1486 | vcm->cfg.session_timeout); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1487 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1488 | if (PREDICT_FALSE (rv)) |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1489 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1490 | listen_session = vcl_session_get_w_handle (wrk, listen_sh); |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 1491 | VDBG (0, "session %u [0x%llx]: listen failed! returning %d (%s)", |
| 1492 | listen_sh, listen_session->vpp_handle, rv, |
| 1493 | vppcom_retval_str (rv)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1494 | return rv; |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1497 | return VPPCOM_OK; |
Keith Burns (alagalah) | 0d2b0d5 | 2018-03-06 15:55:22 -0800 | [diff] [blame] | 1498 | } |
| 1499 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1500 | static int |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1501 | validate_args_session_accept_ (vcl_worker_t * wrk, vcl_session_t * ls) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1502 | { |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1503 | if (ls->flags & VCL_SESSION_F_IS_VEP) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1504 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1505 | VDBG (0, "ERROR: cannot accept on epoll session %u!", |
| 1506 | ls->session_index); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1507 | return VPPCOM_EBADFD; |
| 1508 | } |
| 1509 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1510 | if ((ls->session_state != VCL_STATE_LISTEN) |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1511 | && (!vcl_session_is_connectable_listener (wrk, ls))) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1512 | { |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1513 | VDBG (0, "ERROR: session [0x%llx]: not in listen state! state 0x%x" |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1514 | " (%s)", ls->vpp_handle, ls->session_state, |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1515 | vppcom_session_state_str (ls->session_state)); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1516 | return VPPCOM_EBADFD; |
| 1517 | } |
| 1518 | return VPPCOM_OK; |
| 1519 | } |
| 1520 | |
| 1521 | int |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1522 | vppcom_unformat_proto (uint8_t * proto, char *proto_str) |
| 1523 | { |
| 1524 | if (!strcmp (proto_str, "TCP")) |
| 1525 | *proto = VPPCOM_PROTO_TCP; |
| 1526 | else if (!strcmp (proto_str, "tcp")) |
| 1527 | *proto = VPPCOM_PROTO_TCP; |
| 1528 | else if (!strcmp (proto_str, "UDP")) |
| 1529 | *proto = VPPCOM_PROTO_UDP; |
| 1530 | else if (!strcmp (proto_str, "udp")) |
| 1531 | *proto = VPPCOM_PROTO_UDP; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1532 | else if (!strcmp (proto_str, "TLS")) |
| 1533 | *proto = VPPCOM_PROTO_TLS; |
| 1534 | else if (!strcmp (proto_str, "tls")) |
| 1535 | *proto = VPPCOM_PROTO_TLS; |
| 1536 | else if (!strcmp (proto_str, "QUIC")) |
| 1537 | *proto = VPPCOM_PROTO_QUIC; |
| 1538 | else if (!strcmp (proto_str, "quic")) |
| 1539 | *proto = VPPCOM_PROTO_QUIC; |
| 1540 | else |
| 1541 | return 1; |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1546 | vppcom_session_accept (uint32_t listen_session_handle, vppcom_endpt_t * ep, |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1547 | uint32_t flags) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1548 | { |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1549 | u32 client_session_index = ~0, listen_session_index, accept_flags = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1550 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1551 | session_accepted_msg_t accepted_msg; |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1552 | vcl_session_t *listen_session = 0; |
| 1553 | vcl_session_t *client_session = 0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1554 | vcl_session_msg_t *evt; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1555 | svm_msg_q_msg_t msg; |
| 1556 | session_event_t *e; |
| 1557 | u8 is_nonblocking; |
| 1558 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1559 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1560 | listen_session = vcl_session_get_w_handle (wrk, listen_session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1561 | if (!listen_session) |
| 1562 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1563 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1564 | listen_session_index = listen_session->session_index; |
| 1565 | if ((rv = validate_args_session_accept_ (wrk, listen_session))) |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1566 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1567 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1568 | if (clib_fifo_elts (listen_session->accept_evts_fifo)) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1569 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1570 | clib_fifo_sub2 (listen_session->accept_evts_fifo, evt); |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1571 | accept_flags = evt->flags; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1572 | accepted_msg = evt->accepted_msg; |
| 1573 | goto handle; |
| 1574 | } |
| 1575 | |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1576 | is_nonblocking = vcl_session_has_attr (listen_session, |
| 1577 | VCL_SESS_ATTR_NONBLOCK); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1578 | while (1) |
| 1579 | { |
Carl Smith | 592a909 | 2019-11-12 14:57:37 +1300 | [diff] [blame] | 1580 | if (svm_msg_q_is_empty (wrk->app_event_queue) && is_nonblocking) |
| 1581 | return VPPCOM_EAGAIN; |
| 1582 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1583 | 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] | 1584 | return VPPCOM_EAGAIN; |
| 1585 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1586 | e = svm_msg_q_msg_data (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1587 | if (e->event_type != SESSION_CTRL_EVT_ACCEPTED) |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1588 | { |
wanghanlin | 96453fd | 2019-12-16 19:14:39 +0800 | [diff] [blame] | 1589 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1590 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1591 | continue; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1592 | } |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1593 | clib_memcpy_fast (&accepted_msg, e->data, sizeof (accepted_msg)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1594 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1595 | break; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1596 | } |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1597 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1598 | handle: |
Keith Burns (alagalah) | 00f44cc | 2018-03-07 09:26:38 -0800 | [diff] [blame] | 1599 | |
Florin Coras | 00cca80 | 2019-06-06 09:38:44 -0700 | [diff] [blame] | 1600 | client_session_index = vcl_session_accepted_handler (wrk, &accepted_msg, |
| 1601 | listen_session_index); |
| 1602 | if (client_session_index == VCL_INVALID_SESSION_INDEX) |
| 1603 | return VPPCOM_ECONNABORTED; |
| 1604 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1605 | listen_session = vcl_session_get (wrk, listen_session_index); |
| 1606 | client_session = vcl_session_get (wrk, client_session_index); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1607 | |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1608 | if (flags & O_NONBLOCK) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1609 | vcl_session_set_attr (client_session, VCL_SESS_ATTR_NONBLOCK); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 1610 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1611 | VDBG (1, "listener %u [0x%llx]: Got a connect request! session %u [0x%llx]," |
| 1612 | " flags %d, is_nonblocking %u", listen_session->session_index, |
| 1613 | listen_session->vpp_handle, client_session_index, |
| 1614 | client_session->vpp_handle, flags, |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1615 | vcl_session_has_attr (client_session, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1616 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1617 | if (ep) |
| 1618 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1619 | ep->is_ip4 = client_session->transport.is_ip4; |
| 1620 | ep->port = client_session->transport.rmt_port; |
| 1621 | if (client_session->transport.is_ip4) |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1622 | clib_memcpy_fast (ep->ip, &client_session->transport.rmt_ip.ip4, |
| 1623 | sizeof (ip4_address_t)); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1624 | else |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 1625 | clib_memcpy_fast (ep->ip, &client_session->transport.rmt_ip.ip6, |
| 1626 | sizeof (ip6_address_t)); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 1627 | } |
Dave Wallace | 60caa06 | 2017-11-10 17:07:13 -0500 | [diff] [blame] | 1628 | |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 1629 | VDBG (0, "listener %u [0x%llx] accepted %u [0x%llx] peer: %U:%u " |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1630 | "local: %U:%u", listen_session_handle, listen_session->vpp_handle, |
Florin Coras | 05ecfcc | 2018-12-12 18:19:39 -0800 | [diff] [blame] | 1631 | client_session_index, client_session->vpp_handle, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1632 | format_ip46_address, &client_session->transport.rmt_ip, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1633 | client_session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1634 | clib_net_to_host_u16 (client_session->transport.rmt_port), |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1635 | format_ip46_address, &client_session->transport.lcl_ip, |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1636 | client_session->transport.is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1637 | clib_net_to_host_u16 (client_session->transport.lcl_port)); |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1638 | vcl_evt (VCL_EVT_ACCEPT, client_session, listen_session, |
| 1639 | client_session_index); |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 1640 | |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1641 | /* |
| 1642 | * Session might have been closed already |
| 1643 | */ |
| 1644 | if (accept_flags) |
| 1645 | { |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1646 | if (accept_flags & VCL_ACCEPTED_F_CLOSED) |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1647 | client_session->session_state = VCL_STATE_VPP_CLOSING; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1648 | else if (accept_flags & VCL_ACCEPTED_F_RESET) |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1649 | client_session->session_state = VCL_STATE_DISCONNECT; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1650 | } |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1651 | return vcl_session_handle (client_session); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1655 | vppcom_session_connect (uint32_t session_handle, vppcom_endpt_t * server_ep) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1656 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1657 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1658 | vcl_session_t *session = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1659 | u32 session_index; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1660 | int rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1661 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1662 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1663 | if (!session) |
| 1664 | return VPPCOM_EBADFD; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1665 | session_index = session->session_index; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1666 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1667 | if (PREDICT_FALSE (session->flags & VCL_SESSION_F_IS_VEP)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1668 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1669 | VDBG (0, "ERROR: cannot connect epoll session %u!", |
| 1670 | session->session_index); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1671 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1672 | } |
| 1673 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1674 | if (PREDICT_FALSE (vcl_session_is_ready (session))) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1675 | { |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 1676 | VDBG (0, "session handle %u [0x%llx]: session already " |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1677 | "connected to %s %U port %d proto %s, state 0x%x (%s)", |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 1678 | session_handle, session->vpp_handle, |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1679 | session->transport.is_ip4 ? "IPv4" : "IPv6", format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1680 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1681 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1682 | clib_net_to_host_u16 (session->transport.rmt_port), |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 1683 | vppcom_proto_str (session->session_type), session->session_state, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1684 | vppcom_session_state_str (session->session_state)); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1685 | return VPPCOM_OK; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1688 | /* Attempt to connect a connectionless listener */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1689 | if (PREDICT_FALSE (session->session_state == VCL_STATE_LISTEN)) |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1690 | { |
| 1691 | if (session->session_type != VPPCOM_PROTO_UDP) |
| 1692 | return VPPCOM_EINVAL; |
| 1693 | vcl_send_session_unlisten (wrk, session); |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1694 | session->session_state = VCL_STATE_CLOSED; |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1695 | } |
| 1696 | |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1697 | session->transport.is_ip4 = server_ep->is_ip4; |
Florin Coras | ef7cbf6 | 2019-10-17 09:56:27 -0700 | [diff] [blame] | 1698 | vcl_ip_copy_from_ep (&session->transport.rmt_ip, server_ep); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1699 | session->transport.rmt_port = server_ep->port; |
Nathan Skrzypczak | 8ac1d6d | 2019-07-17 11:02:20 +0200 | [diff] [blame] | 1700 | session->parent_handle = VCL_INVALID_SESSION_HANDLE; |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1701 | session->flags |= VCL_SESSION_F_CONNECTED; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1702 | |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1703 | VDBG (0, "session handle %u (%s): connecting to peer %s %U " |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1704 | "port %d proto %s", session_handle, |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 1705 | vppcom_session_state_str (session->session_state), |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1706 | session->transport.is_ip4 ? "IPv4" : "IPv6", |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1707 | format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1708 | &session->transport.rmt_ip, session->transport.is_ip4 ? |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 1709 | IP46_TYPE_IP4 : IP46_TYPE_IP6, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 1710 | clib_net_to_host_u16 (session->transport.rmt_port), |
Ping Yu | 34a3a08 | 2018-11-30 19:16:17 -0500 | [diff] [blame] | 1711 | vppcom_proto_str (session->session_type)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1712 | |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1713 | vcl_send_session_connect (wrk, session); |
Florin Coras | 57c8893 | 2019-08-29 12:03:17 -0700 | [diff] [blame] | 1714 | |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1715 | if (vcl_session_has_attr (session, VCL_SESS_ATTR_NONBLOCK)) |
Florin Coras | a5ea821 | 2020-08-24 21:23:51 -0700 | [diff] [blame] | 1716 | { |
fanyf | a49d59d | 2020-10-13 17:07:16 +0800 | [diff] [blame] | 1717 | /* State set to STATE_UPDATED to ensure the session is not assumed |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 1718 | * to be ready and to also allow the app to close it prior to vpp's |
fanyf | a49d59d | 2020-10-13 17:07:16 +0800 | [diff] [blame] | 1719 | * connected reply. */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1720 | session->session_state = VCL_STATE_UPDATED; |
Florin Coras | a5ea821 | 2020-08-24 21:23:51 -0700 | [diff] [blame] | 1721 | return VPPCOM_EINPROGRESS; |
| 1722 | } |
Florin Coras | 57c8893 | 2019-08-29 12:03:17 -0700 | [diff] [blame] | 1723 | |
| 1724 | /* |
| 1725 | * Wait for reply from vpp if blocking |
| 1726 | */ |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 1727 | rv = vppcom_wait_for_session_state_change (session_index, VCL_STATE_READY, |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1728 | vcm->cfg.session_timeout); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1729 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1730 | session = vcl_session_get (wrk, session_index); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1731 | VDBG (0, "session %u [0x%llx]: connect %s!", session->session_index, |
| 1732 | session->vpp_handle, rv ? "failed" : "succeeded"); |
Dave Wallace | ee45d41 | 2017-11-24 21:44:06 -0500 | [diff] [blame] | 1733 | |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1734 | return rv; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1737 | int |
| 1738 | vppcom_session_stream_connect (uint32_t session_handle, |
| 1739 | uint32_t parent_session_handle) |
| 1740 | { |
| 1741 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 1742 | vcl_session_t *session, *parent_session; |
| 1743 | u32 session_index, parent_session_index; |
| 1744 | int rv; |
| 1745 | |
| 1746 | session = vcl_session_get_w_handle (wrk, session_handle); |
| 1747 | if (!session) |
| 1748 | return VPPCOM_EBADFD; |
| 1749 | parent_session = vcl_session_get_w_handle (wrk, parent_session_handle); |
| 1750 | if (!parent_session) |
| 1751 | return VPPCOM_EBADFD; |
| 1752 | |
| 1753 | session_index = session->session_index; |
| 1754 | parent_session_index = parent_session->session_index; |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1755 | if (PREDICT_FALSE (session->flags & VCL_SESSION_F_IS_VEP)) |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1756 | { |
| 1757 | VDBG (0, "ERROR: cannot connect epoll session %u!", |
| 1758 | session->session_index); |
| 1759 | return VPPCOM_EBADFD; |
| 1760 | } |
| 1761 | |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 1762 | if (PREDICT_FALSE (vcl_session_is_ready (session))) |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1763 | { |
| 1764 | VDBG (0, "session handle %u [0x%llx]: session already " |
| 1765 | "connected to session %u [0x%llx] proto %s, state 0x%x (%s)", |
| 1766 | session_handle, session->vpp_handle, |
| 1767 | parent_session_handle, parent_session->vpp_handle, |
| 1768 | vppcom_proto_str (session->session_type), session->session_state, |
| 1769 | vppcom_session_state_str (session->session_state)); |
| 1770 | return VPPCOM_OK; |
| 1771 | } |
| 1772 | |
| 1773 | /* Connect to quic session specifics */ |
| 1774 | session->transport.is_ip4 = parent_session->transport.is_ip4; |
| 1775 | session->transport.rmt_ip.ip4.as_u32 = (uint32_t) 1; |
| 1776 | session->transport.rmt_port = 0; |
Nathan Skrzypczak | 8ac1d6d | 2019-07-17 11:02:20 +0200 | [diff] [blame] | 1777 | session->parent_handle = parent_session->vpp_handle; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1778 | |
| 1779 | VDBG (0, "session handle %u: connecting to session %u [0x%llx]", |
| 1780 | session_handle, parent_session_handle, parent_session->vpp_handle); |
| 1781 | |
| 1782 | /* |
| 1783 | * Send connect request and wait for reply from vpp |
| 1784 | */ |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 1785 | vcl_send_session_connect (wrk, session); |
Florin Coras | dfffdd7 | 2020-10-15 10:54:47 -0700 | [diff] [blame] | 1786 | rv = vppcom_wait_for_session_state_change (session_index, VCL_STATE_READY, |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1787 | vcm->cfg.session_timeout); |
| 1788 | |
| 1789 | session->listener_index = parent_session_index; |
| 1790 | parent_session = vcl_session_get_w_handle (wrk, parent_session_handle); |
Florin Coras | 028eaf0 | 2019-07-19 12:15:52 -0700 | [diff] [blame] | 1791 | if (parent_session) |
| 1792 | parent_session->n_accepted_sessions++; |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 1793 | |
| 1794 | session = vcl_session_get (wrk, session_index); |
| 1795 | VDBG (0, "session %u [0x%llx]: connect %s!", session->session_index, |
| 1796 | session->vpp_handle, rv ? "failed" : "succeeded"); |
| 1797 | |
| 1798 | return rv; |
| 1799 | } |
| 1800 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1801 | static u8 |
| 1802 | vcl_is_rx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct) |
| 1803 | { |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 1804 | return (e->event_type == SESSION_IO_EVT_RX && e->session_index == sid); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1807 | static inline int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1808 | vppcom_session_read_internal (uint32_t session_handle, void *buf, int n, |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1809 | u8 peek) |
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 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 4a2c794 | 2020-09-10 12:27:14 -0700 | [diff] [blame] | 1812 | int rv, n_read = 0, is_nonblocking; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1813 | vcl_session_t *s = 0; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1814 | svm_fifo_t *rx_fifo; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1815 | svm_msg_q_msg_t msg; |
| 1816 | session_event_t *e; |
| 1817 | svm_msg_q_t *mq; |
Florin Coras | 41c9e04 | 2018-09-11 00:10:41 -0700 | [diff] [blame] | 1818 | u8 is_ct; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1819 | |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1820 | if (PREDICT_FALSE (!buf)) |
| 1821 | return VPPCOM_EINVAL; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1822 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1823 | s = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1824 | if (PREDICT_FALSE (!s || (s->flags & VCL_SESSION_F_IS_VEP))) |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 1825 | return VPPCOM_EBADFD; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1826 | |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1827 | if (PREDICT_FALSE (!vcl_session_is_open (s))) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1828 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1829 | VDBG (0, "session %u[0x%llx] is not open! state 0x%x (%s)", |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1830 | s->session_index, s->vpp_handle, s->session_state, |
| 1831 | vppcom_session_state_str (s->session_state)); |
| 1832 | return vcl_session_closed_error (s); |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1833 | } |
| 1834 | |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1835 | is_nonblocking = vcl_session_has_attr (s, VCL_SESS_ATTR_NONBLOCK); |
Florin Coras | 41c9e04 | 2018-09-11 00:10:41 -0700 | [diff] [blame] | 1836 | is_ct = vcl_session_is_ct (s); |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 1837 | mq = wrk->app_event_queue; |
| 1838 | rx_fifo = is_ct ? s->ct_rx_fifo : s->rx_fifo; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1839 | s->flags &= ~VCL_SESSION_F_HAS_RX_EVT; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1840 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 1841 | if (svm_fifo_is_empty_cons (rx_fifo)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 1842 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1843 | if (is_nonblocking) |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 1844 | { |
Yu Ping | b295535 | 2019-12-04 06:49:04 +0800 | [diff] [blame] | 1845 | if (vcl_session_is_closing (s)) |
| 1846 | return vcl_session_closing_error (s); |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 1847 | svm_fifo_unset_event (s->rx_fifo); |
| 1848 | return VPPCOM_EWOULDBLOCK; |
| 1849 | } |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 1850 | while (svm_fifo_is_empty_cons (rx_fifo)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1851 | { |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1852 | if (vcl_session_is_closing (s)) |
| 1853 | return vcl_session_closing_error (s); |
| 1854 | |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 1855 | svm_fifo_unset_event (s->rx_fifo); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1856 | svm_msg_q_lock (mq); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1857 | if (svm_msg_q_is_empty (mq)) |
| 1858 | svm_msg_q_wait (mq); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1859 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1860 | svm_msg_q_sub_w_lock (mq, &msg); |
| 1861 | e = svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 1862 | svm_msg_q_unlock (mq); |
Florin Coras | 41c9e04 | 2018-09-11 00:10:41 -0700 | [diff] [blame] | 1863 | if (!vcl_is_rx_evt_for_session (e, s->session_index, is_ct)) |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 1864 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1865 | svm_msg_q_free_msg (mq, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1866 | } |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 1867 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1868 | |
Florin Coras | 4a2c794 | 2020-09-10 12:27:14 -0700 | [diff] [blame] | 1869 | read_again: |
| 1870 | |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 1871 | if (s->is_dgram) |
Florin Coras | 4a2c794 | 2020-09-10 12:27:14 -0700 | [diff] [blame] | 1872 | rv = app_recv_dgram_raw (rx_fifo, buf, n, &s->transport, 0, peek); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 1873 | else |
Florin Coras | 4a2c794 | 2020-09-10 12:27:14 -0700 | [diff] [blame] | 1874 | rv = app_recv_stream_raw (rx_fifo, buf, n, 0, peek); |
| 1875 | |
| 1876 | ASSERT (rv >= 0); |
| 1877 | n_read += rv; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1878 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 1879 | if (svm_fifo_is_empty_cons (rx_fifo)) |
Florin Coras | c34118b | 2020-08-12 18:58:25 -0700 | [diff] [blame] | 1880 | { |
| 1881 | svm_fifo_unset_event (s->rx_fifo); |
| 1882 | if (!svm_fifo_is_empty_cons (rx_fifo) |
| 1883 | && svm_fifo_set_event (s->rx_fifo) && is_nonblocking) |
| 1884 | { |
Florin Coras | c34118b | 2020-08-12 18:58:25 -0700 | [diff] [blame] | 1885 | vec_add2 (wrk->unhandled_evts_vector, e, 1); |
| 1886 | e->event_type = SESSION_IO_EVT_RX; |
| 1887 | e->session_index = s->session_index; |
| 1888 | } |
| 1889 | } |
Florin Coras | 4a2c794 | 2020-09-10 12:27:14 -0700 | [diff] [blame] | 1890 | else if (PREDICT_FALSE (rv < n)) |
| 1891 | { |
| 1892 | /* More data enqueued while reading. Try to drain it |
| 1893 | * or fill the buffer */ |
| 1894 | buf += rv; |
| 1895 | n -= rv; |
| 1896 | goto read_again; |
| 1897 | } |
Florin Coras | 41c9e04 | 2018-09-11 00:10:41 -0700 | [diff] [blame] | 1898 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 1899 | if (PREDICT_FALSE (svm_fifo_needs_deq_ntf (rx_fifo, n_read))) |
Florin Coras | 317b8e0 | 2019-04-17 09:57:46 -0700 | [diff] [blame] | 1900 | { |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 1901 | svm_fifo_clear_deq_ntf (rx_fifo); |
Florin Coras | 317b8e0 | 2019-04-17 09:57:46 -0700 | [diff] [blame] | 1902 | app_send_io_evt_to_vpp (s->vpp_evt_q, s->rx_fifo->master_session_index, |
| 1903 | SESSION_IO_EVT_RX, SVM_Q_WAIT); |
Florin Coras | 317b8e0 | 2019-04-17 09:57:46 -0700 | [diff] [blame] | 1904 | } |
| 1905 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 1906 | VDBG (2, "session %u[0x%llx]: read %d bytes from (%p)", s->session_index, |
| 1907 | s->vpp_handle, n_read, rx_fifo); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1908 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 1909 | return n_read; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 1910 | } |
| 1911 | |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1912 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1913 | vppcom_session_read (uint32_t session_handle, void *buf, size_t n) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1914 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1915 | return (vppcom_session_read_internal (session_handle, buf, n, 0)); |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1919 | vppcom_session_peek (uint32_t session_handle, void *buf, int n) |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1920 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 1921 | return (vppcom_session_read_internal (session_handle, buf, n, 1)); |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1924 | int |
| 1925 | vppcom_session_read_segments (uint32_t session_handle, |
Florin Coras | d68faf8 | 2020-09-25 15:18:13 -0700 | [diff] [blame] | 1926 | vppcom_data_segment_t * ds, uint32_t n_segments, |
| 1927 | uint32_t max_bytes) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1928 | { |
| 1929 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1930 | int n_read = 0, is_nonblocking; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1931 | vcl_session_t *s = 0; |
| 1932 | svm_fifo_t *rx_fifo; |
| 1933 | svm_msg_q_msg_t msg; |
| 1934 | session_event_t *e; |
| 1935 | svm_msg_q_t *mq; |
| 1936 | u8 is_ct; |
| 1937 | |
| 1938 | s = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 1939 | if (PREDICT_FALSE (!s || (s->flags & VCL_SESSION_F_IS_VEP))) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1940 | return VPPCOM_EBADFD; |
| 1941 | |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1942 | if (PREDICT_FALSE (!vcl_session_is_open (s))) |
| 1943 | return vcl_session_closed_error (s); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1944 | |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1945 | is_nonblocking = vcl_session_has_attr (s, VCL_SESS_ATTR_NONBLOCK); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1946 | is_ct = vcl_session_is_ct (s); |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1947 | mq = wrk->app_event_queue; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1948 | rx_fifo = s->rx_fifo; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1949 | s->flags &= ~VCL_SESSION_F_HAS_RX_EVT; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1950 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 1951 | if (is_ct) |
| 1952 | svm_fifo_unset_event (s->rx_fifo); |
| 1953 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 1954 | if (svm_fifo_is_empty_cons (rx_fifo)) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1955 | { |
| 1956 | if (is_nonblocking) |
| 1957 | { |
| 1958 | svm_fifo_unset_event (rx_fifo); |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 1959 | return VPPCOM_EWOULDBLOCK; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1960 | } |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 1961 | while (svm_fifo_is_empty_cons (rx_fifo)) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1962 | { |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 1963 | if (vcl_session_is_closing (s)) |
| 1964 | return vcl_session_closing_error (s); |
| 1965 | |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1966 | svm_fifo_unset_event (rx_fifo); |
| 1967 | svm_msg_q_lock (mq); |
| 1968 | if (svm_msg_q_is_empty (mq)) |
| 1969 | svm_msg_q_wait (mq); |
| 1970 | |
| 1971 | svm_msg_q_sub_w_lock (mq, &msg); |
| 1972 | e = svm_msg_q_msg_data (mq, &msg); |
| 1973 | svm_msg_q_unlock (mq); |
| 1974 | if (!vcl_is_rx_evt_for_session (e, s->session_index, is_ct)) |
Florin Coras | 05ce4b8 | 2018-12-15 18:30:43 -0800 | [diff] [blame] | 1975 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1976 | svm_msg_q_free_msg (mq, &msg); |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | } |
| 1979 | |
Florin Coras | d1cc38d | 2020-10-11 11:05:04 -0700 | [diff] [blame] | 1980 | n_read = svm_fifo_segments (rx_fifo, s->rx_bytes_pending, |
| 1981 | (svm_fifo_seg_t *) ds, n_segments, max_bytes); |
| 1982 | if (n_read < 0) |
| 1983 | return VPPCOM_EAGAIN; |
| 1984 | |
| 1985 | if (svm_fifo_max_dequeue_cons (rx_fifo) == n_read) |
| 1986 | { |
| 1987 | svm_fifo_unset_event (s->rx_fifo); |
| 1988 | if (svm_fifo_max_dequeue_cons (rx_fifo) != n_read |
| 1989 | && svm_fifo_set_event (s->rx_fifo) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 1990 | && vcl_session_has_attr (s, VCL_SESS_ATTR_NONBLOCK)) |
Florin Coras | d1cc38d | 2020-10-11 11:05:04 -0700 | [diff] [blame] | 1991 | { |
| 1992 | session_event_t *e; |
| 1993 | vec_add2 (wrk->unhandled_evts_vector, e, 1); |
| 1994 | e->event_type = SESSION_IO_EVT_RX; |
| 1995 | e->session_index = s->session_index; |
| 1996 | } |
| 1997 | } |
| 1998 | |
| 1999 | s->rx_bytes_pending += n_read; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 2000 | return n_read; |
| 2001 | } |
| 2002 | |
| 2003 | void |
Florin Coras | d68faf8 | 2020-09-25 15:18:13 -0700 | [diff] [blame] | 2004 | vppcom_session_free_segments (uint32_t session_handle, uint32_t n_bytes) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 2005 | { |
| 2006 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 2007 | vcl_session_t *s; |
| 2008 | |
| 2009 | s = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2010 | if (PREDICT_FALSE (!s || (s->flags & VCL_SESSION_F_IS_VEP))) |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 2011 | return; |
| 2012 | |
Florin Coras | d68faf8 | 2020-09-25 15:18:13 -0700 | [diff] [blame] | 2013 | svm_fifo_dequeue_drop (s->rx_fifo, n_bytes); |
Florin Coras | d1cc38d | 2020-10-11 11:05:04 -0700 | [diff] [blame] | 2014 | |
| 2015 | ASSERT (s->rx_bytes_pending < n_bytes); |
| 2016 | s->rx_bytes_pending -= n_bytes; |
Florin Coras | 2cba853 | 2018-09-11 16:33:36 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2019 | static u8 |
| 2020 | vcl_is_tx_evt_for_session (session_event_t * e, u32 sid, u8 is_ct) |
| 2021 | { |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2022 | return (e->event_type == SESSION_IO_EVT_TX && e->session_index == sid); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2023 | } |
| 2024 | |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2025 | always_inline u8 |
| 2026 | vcl_fifo_is_writeable (svm_fifo_t * f, u32 len, u8 is_dgram) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2027 | { |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2028 | u32 max_enq = svm_fifo_max_enqueue_prod (f); |
| 2029 | if (is_dgram) |
| 2030 | return max_enq >= (sizeof (session_dgram_hdr_t) + len); |
| 2031 | else |
| 2032 | return max_enq > 0; |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | always_inline int |
| 2036 | vppcom_session_write_inline (vcl_worker_t * wrk, vcl_session_t * s, void *buf, |
| 2037 | size_t n, u8 is_flush, u8 is_dgram) |
| 2038 | { |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2039 | int n_write, is_nonblocking; |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 2040 | session_evt_type_t et; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2041 | svm_msg_q_msg_t msg; |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2042 | svm_fifo_t *tx_fifo; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2043 | session_event_t *e; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 2044 | svm_msg_q_t *mq; |
Florin Coras | 0e88e85 | 2018-09-17 22:09:02 -0700 | [diff] [blame] | 2045 | u8 is_ct; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2046 | |
jiangxiaoming | ff31ac6 | 2019-11-21 23:34:56 +0800 | [diff] [blame] | 2047 | if (PREDICT_FALSE (!buf || n == 0)) |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2048 | return VPPCOM_EINVAL; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2049 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2050 | if (PREDICT_FALSE (s->flags & VCL_SESSION_F_IS_VEP)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2051 | { |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2052 | VDBG (0, "ERROR: session %u [0x%llx]: cannot write to an epoll" |
| 2053 | " session!", s->session_index, s->vpp_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2054 | return VPPCOM_EBADFD; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2055 | } |
| 2056 | |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2057 | if (PREDICT_FALSE (!vcl_session_is_open (s))) |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 2058 | { |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2059 | VDBG (1, "session %u [0x%llx]: is not open! state 0x%x (%s)", |
| 2060 | s->session_index, s->vpp_handle, s->session_state, |
| 2061 | vppcom_session_state_str (s->session_state)); |
| 2062 | return vcl_session_closed_error (s);; |
Dave Wallace | 9c4b5b2 | 2017-10-18 21:15:48 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Florin Coras | 0e88e85 | 2018-09-17 22:09:02 -0700 | [diff] [blame] | 2065 | is_ct = vcl_session_is_ct (s); |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2066 | tx_fifo = is_ct ? s->ct_tx_fifo : s->tx_fifo; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 2067 | is_nonblocking = vcl_session_has_attr (s, VCL_SESS_ATTR_NONBLOCK); |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 2068 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2069 | mq = wrk->app_event_queue; |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2070 | if (!vcl_fifo_is_writeable (tx_fifo, n, is_dgram)) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2071 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2072 | if (is_nonblocking) |
| 2073 | { |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2074 | return VPPCOM_EWOULDBLOCK; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2075 | } |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2076 | while (!vcl_fifo_is_writeable (tx_fifo, n, is_dgram)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2077 | { |
Florin Coras | 2d379d8 | 2019-06-28 12:45:12 -0700 | [diff] [blame] | 2078 | svm_fifo_add_want_deq_ntf (tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF); |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2079 | if (vcl_session_is_closing (s)) |
| 2080 | return vcl_session_closing_error (s); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2081 | svm_msg_q_lock (mq); |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 2082 | if (svm_msg_q_is_empty (mq)) |
| 2083 | svm_msg_q_wait (mq); |
Florin Coras | 0e88e85 | 2018-09-17 22:09:02 -0700 | [diff] [blame] | 2084 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2085 | svm_msg_q_sub_w_lock (mq, &msg); |
| 2086 | e = svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2087 | svm_msg_q_unlock (mq); |
| 2088 | |
Florin Coras | 0e88e85 | 2018-09-17 22:09:02 -0700 | [diff] [blame] | 2089 | if (!vcl_is_tx_evt_for_session (e, s->session_index, is_ct)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2090 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2091 | svm_msg_q_free_msg (mq, &msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2092 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2093 | } |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2094 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2095 | et = SESSION_IO_EVT_TX; |
| 2096 | if (is_flush && !is_ct) |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 2097 | et = SESSION_IO_EVT_TX_FLUSH; |
| 2098 | |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2099 | if (is_dgram) |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 2100 | n_write = app_send_dgram_raw (tx_fifo, &s->transport, |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2101 | s->vpp_evt_q, buf, n, et, |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2102 | 0 /* do_evt */ , SVM_Q_WAIT); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 2103 | else |
| 2104 | n_write = app_send_stream_raw (tx_fifo, s->vpp_evt_q, buf, n, et, |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2105 | 0 /* do_evt */ , SVM_Q_WAIT); |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2106 | |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2107 | if (svm_fifo_set_event (s->tx_fifo)) |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2108 | app_send_io_evt_to_vpp (s->vpp_evt_q, s->tx_fifo->master_session_index, |
| 2109 | et, SVM_Q_WAIT); |
Keith Burns (alagalah) | 410bcca | 2018-03-23 13:42:49 -0700 | [diff] [blame] | 2110 | |
Florin Coras | 5623009 | 2020-09-02 20:52:58 -0700 | [diff] [blame] | 2111 | /* The underlying fifo segment can run out of memory */ |
| 2112 | if (PREDICT_FALSE (n_write < 0)) |
| 2113 | return VPPCOM_EAGAIN; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2114 | |
Florin Coras | 6d0106e | 2019-01-29 20:11:58 -0800 | [diff] [blame] | 2115 | VDBG (2, "session %u [0x%llx]: wrote %d bytes", s->session_index, |
| 2116 | s->vpp_handle, n_write); |
Florin Coras | 0e88e85 | 2018-09-17 22:09:02 -0700 | [diff] [blame] | 2117 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2118 | return n_write; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2119 | } |
| 2120 | |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 2121 | int |
| 2122 | vppcom_session_write (uint32_t session_handle, void *buf, size_t n) |
| 2123 | { |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2124 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 2125 | vcl_session_t *s; |
| 2126 | |
| 2127 | s = vcl_session_get_w_handle (wrk, session_handle); |
| 2128 | if (PREDICT_FALSE (!s)) |
| 2129 | return VPPCOM_EBADFD; |
| 2130 | |
| 2131 | return vppcom_session_write_inline (wrk, s, buf, n, |
| 2132 | 0 /* is_flush */ , s->is_dgram ? 1 : 0); |
Florin Coras | 42ceddb | 2018-12-12 10:56:01 -0800 | [diff] [blame] | 2133 | } |
| 2134 | |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 2135 | int |
| 2136 | vppcom_session_write_msg (uint32_t session_handle, void *buf, size_t n) |
| 2137 | { |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 2138 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 2139 | vcl_session_t *s; |
| 2140 | |
| 2141 | s = vcl_session_get_w_handle (wrk, session_handle); |
| 2142 | if (PREDICT_FALSE (!s)) |
| 2143 | return VPPCOM_EBADFD; |
| 2144 | |
| 2145 | return vppcom_session_write_inline (wrk, s, buf, n, |
| 2146 | 1 /* is_flush */ , s->is_dgram ? 1 : 0); |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2149 | #define vcl_fifo_rx_evt_valid_or_break(_s) \ |
Florin Coras | bd52e46 | 2019-10-28 13:22:37 -0700 | [diff] [blame] | 2150 | if (PREDICT_FALSE (!_s->rx_fifo)) \ |
| 2151 | break; \ |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2152 | if (PREDICT_FALSE (svm_fifo_is_empty (_s->rx_fifo))) \ |
| 2153 | { \ |
| 2154 | if (!vcl_session_is_ct (_s)) \ |
| 2155 | { \ |
| 2156 | svm_fifo_unset_event (_s->rx_fifo); \ |
| 2157 | if (svm_fifo_is_empty (_s->rx_fifo)) \ |
| 2158 | break; \ |
| 2159 | } \ |
| 2160 | else if (svm_fifo_is_empty (_s->ct_rx_fifo)) \ |
| 2161 | { \ |
Florin Coras | 2f63018 | 2020-08-13 00:17:51 -0700 | [diff] [blame] | 2162 | svm_fifo_unset_event (_s->rx_fifo); /* rx evts on actual fifo*/ \ |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2163 | if (svm_fifo_is_empty (_s->ct_rx_fifo)) \ |
| 2164 | break; \ |
| 2165 | } \ |
| 2166 | } \ |
Florin Coras | 6d4bb42 | 2018-09-04 22:07:27 -0700 | [diff] [blame] | 2167 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2168 | static void |
| 2169 | vcl_select_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, |
| 2170 | unsigned long n_bits, unsigned long *read_map, |
| 2171 | unsigned long *write_map, |
| 2172 | unsigned long *except_map, u32 * bits_set) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2173 | { |
| 2174 | session_disconnected_msg_t *disconnected_msg; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2175 | session_connected_msg_t *connected_msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2176 | vcl_session_t *session; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2177 | u32 sid; |
| 2178 | |
| 2179 | switch (e->event_type) |
| 2180 | { |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2181 | case SESSION_IO_EVT_RX: |
| 2182 | sid = e->session_index; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2183 | session = vcl_session_get (wrk, sid); |
Florin Coras | f49cf47 | 2020-04-19 23:12:08 +0000 | [diff] [blame] | 2184 | if (!session || !vcl_session_is_open (session)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2185 | break; |
Florin Coras | fff68f7 | 2019-03-13 16:01:38 -0700 | [diff] [blame] | 2186 | vcl_fifo_rx_evt_valid_or_break (session); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2187 | if (sid < n_bits && read_map) |
| 2188 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2189 | clib_bitmap_set_no_check ((uword *) read_map, sid, 1); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2190 | *bits_set += 1; |
| 2191 | } |
| 2192 | break; |
Florin Coras | fe97da3 | 2019-03-06 10:09:04 -0800 | [diff] [blame] | 2193 | case SESSION_IO_EVT_TX: |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2194 | sid = e->session_index; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2195 | session = vcl_session_get (wrk, sid); |
Florin Coras | f49cf47 | 2020-04-19 23:12:08 +0000 | [diff] [blame] | 2196 | if (!session || !vcl_session_is_open (session)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2197 | break; |
| 2198 | if (sid < n_bits && write_map) |
| 2199 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2200 | clib_bitmap_set_no_check ((uword *) write_map, sid, 1); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2201 | *bits_set += 1; |
| 2202 | } |
| 2203 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2204 | case SESSION_CTRL_EVT_ACCEPTED: |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2205 | session = vcl_session_accepted (wrk, |
| 2206 | (session_accepted_msg_t *) e->data); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2207 | if (!session) |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2208 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2209 | sid = session->session_index; |
| 2210 | if (sid < n_bits && read_map) |
| 2211 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2212 | clib_bitmap_set_no_check ((uword *) read_map, sid, 1); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2213 | *bits_set += 1; |
| 2214 | } |
| 2215 | break; |
| 2216 | case SESSION_CTRL_EVT_CONNECTED: |
| 2217 | connected_msg = (session_connected_msg_t *) e->data; |
Florin Coras | 57c8893 | 2019-08-29 12:03:17 -0700 | [diff] [blame] | 2218 | sid = vcl_session_connected_handler (wrk, connected_msg); |
| 2219 | if (sid == VCL_INVALID_SESSION_INDEX) |
| 2220 | break; |
| 2221 | if (sid < n_bits && write_map) |
| 2222 | { |
| 2223 | clib_bitmap_set_no_check ((uword *) write_map, sid, 1); |
| 2224 | *bits_set += 1; |
| 2225 | } |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2226 | break; |
| 2227 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 2228 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2229 | session = vcl_session_disconnected_handler (wrk, disconnected_msg); |
| 2230 | if (!session) |
| 2231 | break; |
| 2232 | sid = session->session_index; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2233 | if (sid < n_bits && except_map) |
| 2234 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2235 | clib_bitmap_set_no_check ((uword *) except_map, sid, 1); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2236 | *bits_set += 1; |
| 2237 | } |
| 2238 | break; |
| 2239 | case SESSION_CTRL_EVT_RESET: |
| 2240 | sid = vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data); |
| 2241 | if (sid < n_bits && except_map) |
| 2242 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2243 | clib_bitmap_set_no_check ((uword *) except_map, sid, 1); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2244 | *bits_set += 1; |
| 2245 | } |
| 2246 | break; |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 2247 | case SESSION_CTRL_EVT_UNLISTEN_REPLY: |
| 2248 | vcl_session_unlisten_reply_handler (wrk, e->data); |
| 2249 | break; |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 2250 | case SESSION_CTRL_EVT_MIGRATED: |
| 2251 | vcl_session_migrated_handler (wrk, e->data); |
| 2252 | break; |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 2253 | case SESSION_CTRL_EVT_CLEANUP: |
| 2254 | vcl_session_cleanup_handler (wrk, e->data); |
| 2255 | break; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 2256 | case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY: |
| 2257 | vcl_session_worker_update_reply_handler (wrk, e->data); |
| 2258 | break; |
| 2259 | case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: |
| 2260 | vcl_session_req_worker_update_handler (wrk, e->data); |
| 2261 | break; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 2262 | case SESSION_CTRL_EVT_APP_ADD_SEGMENT: |
| 2263 | vcl_session_app_add_segment_handler (wrk, e->data); |
| 2264 | break; |
| 2265 | case SESSION_CTRL_EVT_APP_DEL_SEGMENT: |
| 2266 | vcl_session_app_del_segment_handler (wrk, e->data); |
| 2267 | break; |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 2268 | case SESSION_CTRL_EVT_APP_WRK_RPC: |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 2269 | vcl_worker_rpc_handler (wrk, e->data); |
| 2270 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2271 | default: |
| 2272 | clib_warning ("unhandled: %u", e->event_type); |
| 2273 | break; |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | static int |
| 2278 | vcl_select_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq, |
| 2279 | unsigned long n_bits, unsigned long *read_map, |
| 2280 | unsigned long *write_map, unsigned long *except_map, |
| 2281 | double time_to_wait, u32 * bits_set) |
| 2282 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2283 | svm_msg_q_msg_t *msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2284 | session_event_t *e; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2285 | u32 i; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2286 | |
| 2287 | svm_msg_q_lock (mq); |
| 2288 | if (svm_msg_q_is_empty (mq)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2289 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2290 | if (*bits_set) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2291 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2292 | svm_msg_q_unlock (mq); |
| 2293 | return 0; |
| 2294 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2295 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2296 | if (!time_to_wait) |
| 2297 | { |
| 2298 | svm_msg_q_unlock (mq); |
| 2299 | return 0; |
| 2300 | } |
| 2301 | else if (time_to_wait < 0) |
| 2302 | { |
| 2303 | svm_msg_q_wait (mq); |
| 2304 | } |
| 2305 | else |
| 2306 | { |
| 2307 | if (svm_msg_q_timedwait (mq, time_to_wait)) |
| 2308 | { |
| 2309 | svm_msg_q_unlock (mq); |
| 2310 | return 0; |
| 2311 | } |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2312 | } |
| 2313 | } |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 2314 | vcl_mq_dequeue_batch (wrk, mq, ~0); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2315 | svm_msg_q_unlock (mq); |
| 2316 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2317 | for (i = 0; i < vec_len (wrk->mq_msg_vector); i++) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2318 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2319 | msg = vec_elt_at_index (wrk->mq_msg_vector, i); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2320 | e = svm_msg_q_msg_data (mq, msg); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2321 | vcl_select_handle_mq_event (wrk, e, n_bits, read_map, write_map, |
| 2322 | except_map, bits_set); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2323 | svm_msg_q_free_msg (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2324 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2325 | vec_reset_length (wrk->mq_msg_vector); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 2326 | vcl_handle_pending_wrk_updates (wrk); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2327 | return *bits_set; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2328 | } |
| 2329 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2330 | static int |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2331 | vppcom_select_condvar (vcl_worker_t * wrk, int n_bits, |
| 2332 | vcl_si_set * read_map, vcl_si_set * write_map, |
| 2333 | vcl_si_set * except_map, double time_to_wait, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2334 | u32 * bits_set) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2335 | { |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2336 | double wait = 0, start = 0; |
| 2337 | |
| 2338 | if (!*bits_set) |
| 2339 | { |
| 2340 | wait = time_to_wait; |
| 2341 | start = clib_time_now (&wrk->clib_time); |
| 2342 | } |
| 2343 | |
| 2344 | do |
| 2345 | { |
| 2346 | vcl_select_handle_mq (wrk, wrk->app_event_queue, n_bits, read_map, |
| 2347 | write_map, except_map, wait, bits_set); |
| 2348 | if (*bits_set) |
| 2349 | return *bits_set; |
| 2350 | if (wait == -1) |
| 2351 | continue; |
| 2352 | |
| 2353 | wait = wait - (clib_time_now (&wrk->clib_time) - start); |
| 2354 | } |
| 2355 | while (wait > 0); |
| 2356 | |
| 2357 | return 0; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | static int |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2361 | vppcom_select_eventfd (vcl_worker_t * wrk, int n_bits, |
| 2362 | vcl_si_set * read_map, vcl_si_set * write_map, |
| 2363 | vcl_si_set * except_map, double time_to_wait, |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2364 | u32 * bits_set) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2365 | { |
| 2366 | vcl_mq_evt_conn_t *mqc; |
| 2367 | int __clib_unused n_read; |
| 2368 | int n_mq_evts, i; |
| 2369 | u64 buf; |
| 2370 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2371 | vec_validate (wrk->mq_events, pool_elts (wrk->mq_evt_conns)); |
| 2372 | n_mq_evts = epoll_wait (wrk->mqs_epfd, wrk->mq_events, |
| 2373 | vec_len (wrk->mq_events), time_to_wait); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2374 | for (i = 0; i < n_mq_evts; i++) |
| 2375 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2376 | 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] | 2377 | n_read = read (mqc->mq_fd, &buf, sizeof (buf)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2378 | 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] | 2379 | except_map, 0, bits_set); |
| 2380 | } |
| 2381 | |
| 2382 | return (n_mq_evts > 0 ? (int) *bits_set : 0); |
| 2383 | } |
| 2384 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2385 | int |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2386 | vppcom_select (int n_bits, vcl_si_set * read_map, vcl_si_set * write_map, |
| 2387 | vcl_si_set * except_map, double time_to_wait) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2388 | { |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2389 | u32 sid, minbits = clib_max (n_bits, BITS (uword)), bits_set = 0; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2390 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2391 | vcl_session_t *session = 0; |
Florin Coras | f49cf47 | 2020-04-19 23:12:08 +0000 | [diff] [blame] | 2392 | int i; |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2393 | |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 2394 | if (n_bits && read_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2395 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2396 | clib_bitmap_validate (wrk->rd_bitmap, minbits); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2397 | clib_memcpy_fast (wrk->rd_bitmap, read_map, |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2398 | vec_len (wrk->rd_bitmap) * sizeof (vcl_si_set)); |
| 2399 | memset (read_map, 0, vec_len (wrk->rd_bitmap) * sizeof (vcl_si_set)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2400 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 2401 | if (n_bits && write_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2402 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2403 | clib_bitmap_validate (wrk->wr_bitmap, minbits); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2404 | clib_memcpy_fast (wrk->wr_bitmap, write_map, |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2405 | vec_len (wrk->wr_bitmap) * sizeof (vcl_si_set)); |
| 2406 | memset (write_map, 0, vec_len (wrk->wr_bitmap) * sizeof (vcl_si_set)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2407 | } |
Dave Wallace | 7876d39 | 2017-10-19 03:53:57 -0400 | [diff] [blame] | 2408 | if (n_bits && except_map) |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2409 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2410 | clib_bitmap_validate (wrk->ex_bitmap, minbits); |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 2411 | clib_memcpy_fast (wrk->ex_bitmap, except_map, |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2412 | vec_len (wrk->ex_bitmap) * sizeof (vcl_si_set)); |
| 2413 | memset (except_map, 0, vec_len (wrk->ex_bitmap) * sizeof (vcl_si_set)); |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2414 | } |
| 2415 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2416 | if (!n_bits) |
| 2417 | return 0; |
| 2418 | |
| 2419 | if (!write_map) |
| 2420 | goto check_rd; |
| 2421 | |
| 2422 | /* *INDENT-OFF* */ |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2423 | clib_bitmap_foreach (sid, wrk->wr_bitmap, ({ |
| 2424 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2425 | { |
Florin Coras | 5e6222a | 2020-04-24 17:09:25 +0000 | [diff] [blame] | 2426 | clib_bitmap_set_no_check ((uword*)write_map, sid, 1); |
| 2427 | bits_set++; |
| 2428 | continue; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2429 | } |
| 2430 | |
Florin Coras | 5e6222a | 2020-04-24 17:09:25 +0000 | [diff] [blame] | 2431 | if (vcl_session_write_ready (session)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2432 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2433 | clib_bitmap_set_no_check ((uword*)write_map, sid, 1); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2434 | bits_set++; |
| 2435 | } |
Florin Coras | 294afe2 | 2019-01-07 17:49:17 -0800 | [diff] [blame] | 2436 | else |
Florin Coras | 2d379d8 | 2019-06-28 12:45:12 -0700 | [diff] [blame] | 2437 | svm_fifo_add_want_deq_ntf (session->tx_fifo, SVM_FIFO_WANT_DEQ_NOTIF); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2438 | })); |
| 2439 | |
| 2440 | check_rd: |
| 2441 | if (!read_map) |
| 2442 | goto check_mq; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2443 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2444 | clib_bitmap_foreach (sid, wrk->rd_bitmap, ({ |
| 2445 | if (!(session = vcl_session_get (wrk, sid))) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2446 | { |
Florin Coras | 5e6222a | 2020-04-24 17:09:25 +0000 | [diff] [blame] | 2447 | clib_bitmap_set_no_check ((uword*)read_map, sid, 1); |
| 2448 | bits_set++; |
| 2449 | continue; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
Florin Coras | 5e6222a | 2020-04-24 17:09:25 +0000 | [diff] [blame] | 2452 | if (vcl_session_read_ready (session)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2453 | { |
David Johnson | d9818dd | 2018-12-14 14:53:41 -0500 | [diff] [blame] | 2454 | clib_bitmap_set_no_check ((uword*)read_map, sid, 1); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2455 | bits_set++; |
| 2456 | } |
| 2457 | })); |
| 2458 | /* *INDENT-ON* */ |
| 2459 | |
| 2460 | check_mq: |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2461 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2462 | for (i = 0; i < vec_len (wrk->unhandled_evts_vector); i++) |
| 2463 | { |
| 2464 | vcl_select_handle_mq_event (wrk, &wrk->unhandled_evts_vector[i], n_bits, |
| 2465 | read_map, write_map, except_map, &bits_set); |
| 2466 | } |
| 2467 | vec_reset_length (wrk->unhandled_evts_vector); |
| 2468 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2469 | if (vcm->cfg.use_mq_eventfd) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2470 | vppcom_select_eventfd (wrk, n_bits, read_map, write_map, except_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2471 | time_to_wait, &bits_set); |
| 2472 | else |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2473 | vppcom_select_condvar (wrk, n_bits, read_map, write_map, except_map, |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2474 | time_to_wait, &bits_set); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2475 | |
Dave Wallace | 543852a | 2017-08-03 02:11:34 -0400 | [diff] [blame] | 2476 | return (bits_set); |
| 2477 | } |
| 2478 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2479 | static inline void |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2480 | vep_verify_epoll_chain (vcl_worker_t * wrk, u32 vep_handle) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2481 | { |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2482 | vppcom_epoll_t *vep; |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2483 | u32 sh = vep_handle; |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2484 | vcl_session_t *s; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2485 | |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2486 | if (VPPCOM_DEBUG <= 2) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2487 | return; |
| 2488 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2489 | s = vcl_session_get_w_handle (wrk, vep_handle); |
| 2490 | if (PREDICT_FALSE (!s)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2491 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2492 | VDBG (0, "ERROR: Invalid vep_sh (%u)!", vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2493 | goto done; |
| 2494 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2495 | if (PREDICT_FALSE (!(s->flags & VCL_SESSION_F_IS_VEP))) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2496 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2497 | VDBG (0, "ERROR: vep_sh (%u) is not a vep!", vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2498 | goto done; |
| 2499 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2500 | vep = &s->vep; |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2501 | VDBG (0, "vep_sh (%u): Dumping epoll chain\n" |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2502 | "{\n" |
| 2503 | " is_vep = %u\n" |
| 2504 | " is_vep_session = %u\n" |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2505 | " next_sh = 0x%x (%u)\n" |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2506 | "}\n", vep_handle, s->flags & VCL_SESSION_F_IS_VEP, |
| 2507 | s->flags & VCL_SESSION_F_IS_VEP_SESSION, vep->next_sh, vep->next_sh); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2508 | |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2509 | for (sh = vep->next_sh; sh != ~0; sh = vep->next_sh) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2510 | { |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2511 | s = vcl_session_get_w_handle (wrk, sh); |
| 2512 | if (PREDICT_FALSE (!s)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2513 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2514 | VDBG (0, "ERROR: Invalid sh (%u)!", sh); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2515 | goto done; |
| 2516 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2517 | if (PREDICT_FALSE (s->flags & VCL_SESSION_F_IS_VEP)) |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2518 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2519 | VDBG (0, "ERROR: sh (%u) is a vep!", vep_handle); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2520 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2521 | else if (PREDICT_FALSE (!(s->flags & VCL_SESSION_F_IS_VEP_SESSION))) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2522 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2523 | VDBG (0, "ERROR: sh (%u) is not a vep session handle!", sh); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2524 | goto done; |
| 2525 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2526 | vep = &s->vep; |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2527 | if (PREDICT_FALSE (vep->vep_sh != vep_handle)) |
| 2528 | VDBG (0, "ERROR: session (%u) vep_sh (%u) != vep_sh (%u)!", |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2529 | sh, s->vep.vep_sh, vep_handle); |
| 2530 | if (s->flags & VCL_SESSION_F_IS_VEP_SESSION) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2531 | { |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2532 | VDBG (0, "vep_sh[%u]: sh 0x%x (%u)\n" |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2533 | "{\n" |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2534 | " next_sh = 0x%x (%u)\n" |
| 2535 | " prev_sh = 0x%x (%u)\n" |
| 2536 | " vep_sh = 0x%x (%u)\n" |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2537 | " ev.events = 0x%x\n" |
| 2538 | " ev.data.u64 = 0x%llx\n" |
| 2539 | " et_mask = 0x%x\n" |
| 2540 | "}\n", |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2541 | vep_handle, sh, sh, vep->next_sh, vep->next_sh, vep->prev_sh, |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2542 | vep->prev_sh, vep->vep_sh, vep->vep_sh, vep->ev.events, |
| 2543 | vep->ev.data.u64, vep->et_mask); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2544 | } |
| 2545 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2546 | |
| 2547 | done: |
Florin Coras | 7e5e62b | 2019-07-30 14:08:23 -0700 | [diff] [blame] | 2548 | VDBG (0, "vep_sh (%u): Dump complete!\n", vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | int |
| 2552 | vppcom_epoll_create (void) |
| 2553 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2554 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2555 | vcl_session_t *vep_session; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2556 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2557 | vep_session = vcl_session_alloc (wrk); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2558 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2559 | vep_session->flags |= VCL_SESSION_F_IS_VEP; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2560 | vep_session->vep.vep_sh = ~0; |
| 2561 | vep_session->vep.next_sh = ~0; |
| 2562 | vep_session->vep.prev_sh = ~0; |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2563 | vep_session->vpp_handle = ~0; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 2564 | |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2565 | vcl_evt (VCL_EVT_EPOLL_CREATE, vep_session, vep_session->session_index); |
| 2566 | VDBG (0, "Created vep_idx %u", vep_session->session_index); |
Keith Burns (alagalah) | 09b2784 | 2018-01-05 14:39:59 -0800 | [diff] [blame] | 2567 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2568 | return vcl_session_handle (vep_session); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
| 2571 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2572 | 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] | 2573 | struct epoll_event *event) |
| 2574 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2575 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2576 | vcl_session_t *vep_session; |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2577 | int rv = VPPCOM_OK; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2578 | vcl_session_t *s; |
| 2579 | svm_fifo_t *txf; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2580 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2581 | if (vep_handle == session_handle) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2582 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2583 | VDBG (0, "vep_sh == session handle (%u)!", vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2584 | return VPPCOM_EINVAL; |
| 2585 | } |
| 2586 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2587 | vep_session = vcl_session_get_w_handle (wrk, vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2588 | if (PREDICT_FALSE (!vep_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2589 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2590 | VDBG (0, "Invalid vep_sh (%u)!", vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2591 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2592 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2593 | if (PREDICT_FALSE (!(vep_session->flags & VCL_SESSION_F_IS_VEP))) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2594 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2595 | VDBG (0, "vep_sh (%u) is not a vep!", vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2596 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2599 | ASSERT (vep_session->vep.vep_sh == ~0); |
| 2600 | ASSERT (vep_session->vep.prev_sh == ~0); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2601 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2602 | s = vcl_session_get_w_handle (wrk, session_handle); |
| 2603 | if (PREDICT_FALSE (!s)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2604 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2605 | VDBG (0, "Invalid session_handle (%u)!", session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2606 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2607 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2608 | if (PREDICT_FALSE (s->flags & VCL_SESSION_F_IS_VEP)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2609 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2610 | VDBG (0, "session_handle (%u) is a vep!", vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2611 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | switch (op) |
| 2615 | { |
| 2616 | case EPOLL_CTL_ADD: |
| 2617 | if (PREDICT_FALSE (!event)) |
| 2618 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2619 | VDBG (0, "EPOLL_CTL_ADD: NULL pointer to epoll_event structure!"); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2620 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2621 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2622 | if (vep_session->vep.next_sh != ~0) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2623 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2624 | vcl_session_t *next_session; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 2625 | next_session = vcl_session_get_w_handle (wrk, |
| 2626 | vep_session->vep.next_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2627 | if (PREDICT_FALSE (!next_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2628 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2629 | VDBG (0, "EPOLL_CTL_ADD: Invalid vep.next_sh (%u) on " |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2630 | "vep_idx (%u)!", vep_session->vep.next_sh, vep_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2631 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2632 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2633 | ASSERT (next_session->vep.prev_sh == vep_handle); |
| 2634 | next_session->vep.prev_sh = session_handle; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2635 | } |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2636 | s->vep.next_sh = vep_session->vep.next_sh; |
| 2637 | s->vep.prev_sh = vep_handle; |
| 2638 | s->vep.vep_sh = vep_handle; |
| 2639 | s->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 2640 | s->vep.ev = *event; |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2641 | s->flags &= ~VCL_SESSION_F_IS_VEP; |
| 2642 | s->flags |= VCL_SESSION_F_IS_VEP_SESSION; |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2643 | vep_session->vep.next_sh = session_handle; |
Keith Burns (alagalah) | 3cf2d64 | 2018-02-23 10:17:01 -0800 | [diff] [blame] | 2644 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2645 | txf = vcl_session_is_ct (s) ? s->ct_tx_fifo : s->tx_fifo; |
| 2646 | if (txf && (event->events & EPOLLOUT)) |
| 2647 | svm_fifo_add_want_deq_ntf (txf, SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL); |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 2648 | |
Florin Coras | 6e3c1f8 | 2020-01-15 01:30:46 +0000 | [diff] [blame] | 2649 | /* Generate EPOLLOUT if tx fifo not full */ |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2650 | if ((event->events & EPOLLOUT) && (vcl_session_write_ready (s) > 0)) |
hanlin | 475c9d7 | 2019-12-26 11:44:28 +0800 | [diff] [blame] | 2651 | { |
| 2652 | session_event_t e = { 0 }; |
| 2653 | e.event_type = SESSION_IO_EVT_TX; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2654 | e.session_index = s->session_index; |
hanlin | 475c9d7 | 2019-12-26 11:44:28 +0800 | [diff] [blame] | 2655 | vec_add1 (wrk->unhandled_evts_vector, e); |
| 2656 | } |
Florin Coras | 6e3c1f8 | 2020-01-15 01:30:46 +0000 | [diff] [blame] | 2657 | /* Generate EPOLLIN if rx fifo has data */ |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2658 | if ((event->events & EPOLLIN) && (vcl_session_read_ready (s) > 0)) |
Florin Coras | 6e3c1f8 | 2020-01-15 01:30:46 +0000 | [diff] [blame] | 2659 | { |
| 2660 | session_event_t e = { 0 }; |
| 2661 | e.event_type = SESSION_IO_EVT_RX; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2662 | e.session_index = s->session_index; |
Florin Coras | 6e3c1f8 | 2020-01-15 01:30:46 +0000 | [diff] [blame] | 2663 | vec_add1 (wrk->unhandled_evts_vector, e); |
| 2664 | } |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2665 | VDBG (1, "EPOLL_CTL_ADD: vep_sh %u, sh %u, events 0x%x, data 0x%llx!", |
| 2666 | vep_handle, session_handle, event->events, event->data.u64); |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2667 | vcl_evt (VCL_EVT_EPOLL_CTLADD, s, event->events, event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2668 | break; |
| 2669 | |
| 2670 | case EPOLL_CTL_MOD: |
| 2671 | if (PREDICT_FALSE (!event)) |
| 2672 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2673 | VDBG (0, "EPOLL_CTL_MOD: NULL pointer to epoll_event structure!"); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2674 | rv = VPPCOM_EINVAL; |
| 2675 | goto done; |
| 2676 | } |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2677 | else if (PREDICT_FALSE (!(s->flags & VCL_SESSION_F_IS_VEP_SESSION))) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2678 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2679 | VDBG (0, "sh %u EPOLL_CTL_MOD: not a vep session!", session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2680 | rv = VPPCOM_EINVAL; |
| 2681 | goto done; |
| 2682 | } |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2683 | else if (PREDICT_FALSE (s->vep.vep_sh != vep_handle)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2684 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2685 | VDBG (0, "EPOLL_CTL_MOD: sh %u vep_sh (%u) != vep_sh (%u)!", |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2686 | session_handle, s->vep.vep_sh, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2687 | rv = VPPCOM_EINVAL; |
| 2688 | goto done; |
| 2689 | } |
hanlin | 475c9d7 | 2019-12-26 11:44:28 +0800 | [diff] [blame] | 2690 | |
| 2691 | /* Generate EPOLLOUT when tx_fifo/ct_tx_fifo not full */ |
| 2692 | if ((event->events & EPOLLOUT) && |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2693 | !(s->vep.ev.events & EPOLLOUT) && (vcl_session_write_ready (s) > 0)) |
hanlin | 475c9d7 | 2019-12-26 11:44:28 +0800 | [diff] [blame] | 2694 | { |
| 2695 | session_event_t e = { 0 }; |
| 2696 | e.event_type = SESSION_IO_EVT_TX; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2697 | e.session_index = s->session_index; |
hanlin | 475c9d7 | 2019-12-26 11:44:28 +0800 | [diff] [blame] | 2698 | vec_add1 (wrk->unhandled_evts_vector, e); |
| 2699 | } |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2700 | s->vep.et_mask = VEP_DEFAULT_ET_MASK; |
| 2701 | s->vep.ev = *event; |
| 2702 | txf = vcl_session_is_ct (s) ? s->ct_tx_fifo : s->tx_fifo; |
| 2703 | if (event->events & EPOLLOUT) |
| 2704 | svm_fifo_add_want_deq_ntf (txf, SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL); |
| 2705 | else |
| 2706 | svm_fifo_del_want_deq_ntf (txf, SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL); |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2707 | VDBG (1, "EPOLL_CTL_MOD: vep_sh %u, sh %u, events 0x%x, data 0x%llx!", |
| 2708 | vep_handle, session_handle, event->events, event->data.u64); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2709 | break; |
| 2710 | |
| 2711 | case EPOLL_CTL_DEL: |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2712 | if (PREDICT_FALSE (!(s->flags & VCL_SESSION_F_IS_VEP_SESSION))) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2713 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2714 | VDBG (0, "EPOLL_CTL_DEL: %u not a vep session!", session_handle); |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2715 | rv = VPPCOM_EINVAL; |
| 2716 | goto done; |
| 2717 | } |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2718 | else if (PREDICT_FALSE (s->vep.vep_sh != vep_handle)) |
Dave Wallace | 4878cbe | 2017-11-21 03:45:09 -0500 | [diff] [blame] | 2719 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2720 | VDBG (0, "EPOLL_CTL_DEL: sh %u vep_sh (%u) != vep_sh (%u)!", |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2721 | session_handle, s->vep.vep_sh, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2722 | rv = VPPCOM_EINVAL; |
| 2723 | goto done; |
| 2724 | } |
| 2725 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2726 | if (s->vep.prev_sh == vep_handle) |
| 2727 | vep_session->vep.next_sh = s->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2728 | else |
| 2729 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2730 | vcl_session_t *prev_session; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2731 | prev_session = vcl_session_get_w_handle (wrk, s->vep.prev_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2732 | if (PREDICT_FALSE (!prev_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2733 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2734 | VDBG (0, "EPOLL_CTL_DEL: Invalid prev_sh (%u) on sh (%u)!", |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2735 | s->vep.prev_sh, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2736 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2737 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2738 | ASSERT (prev_session->vep.next_sh == session_handle); |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2739 | prev_session->vep.next_sh = s->vep.next_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2740 | } |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2741 | if (s->vep.next_sh != ~0) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2742 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 2743 | vcl_session_t *next_session; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2744 | next_session = vcl_session_get_w_handle (wrk, s->vep.next_sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2745 | if (PREDICT_FALSE (!next_session)) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2746 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2747 | VDBG (0, "EPOLL_CTL_DEL: Invalid next_sh (%u) on sh (%u)!", |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2748 | s->vep.next_sh, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 2749 | return VPPCOM_EBADFD; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2750 | } |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2751 | ASSERT (next_session->vep.prev_sh == session_handle); |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2752 | next_session->vep.prev_sh = s->vep.prev_sh; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2753 | } |
| 2754 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2755 | memset (&s->vep, 0, sizeof (s->vep)); |
| 2756 | s->vep.next_sh = ~0; |
| 2757 | s->vep.prev_sh = ~0; |
| 2758 | s->vep.vep_sh = ~0; |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 2759 | s->flags &= ~VCL_SESSION_F_IS_VEP_SESSION; |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 2760 | |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2761 | txf = vcl_session_is_ct (s) ? s->ct_tx_fifo : s->tx_fifo; |
| 2762 | if (txf) |
| 2763 | svm_fifo_del_want_deq_ntf (txf, SVM_FIFO_WANT_DEQ_NOTIF_IF_FULL); |
Florin Coras | 1bcad5c | 2019-01-09 20:04:38 -0800 | [diff] [blame] | 2764 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 2765 | VDBG (1, "EPOLL_CTL_DEL: vep_idx %u, sh %u!", vep_handle, |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2766 | session_handle); |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2767 | vcl_evt (VCL_EVT_EPOLL_CTLDEL, s, vep_sh); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2768 | break; |
| 2769 | |
| 2770 | default: |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 2771 | VDBG (0, "Invalid operation (%d)!", op); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2772 | rv = VPPCOM_EINVAL; |
| 2773 | } |
| 2774 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2775 | vep_verify_epoll_chain (wrk, vep_handle); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2776 | |
| 2777 | done: |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 2778 | return rv; |
| 2779 | } |
| 2780 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2781 | static inline void |
| 2782 | vcl_epoll_wait_handle_mq_event (vcl_worker_t * wrk, session_event_t * e, |
| 2783 | struct epoll_event *events, u32 * num_ev) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2784 | { |
| 2785 | session_disconnected_msg_t *disconnected_msg; |
| 2786 | session_connected_msg_t *connected_msg; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2787 | u32 sid = ~0, session_events; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2788 | u64 session_evt_data = ~0; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2789 | vcl_session_t *session; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2790 | u8 add_event = 0; |
| 2791 | |
| 2792 | switch (e->event_type) |
| 2793 | { |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2794 | case SESSION_IO_EVT_RX: |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2795 | sid = e->session_index; |
Florin Coras | 080aa50 | 2020-05-26 00:47:52 +0000 | [diff] [blame] | 2796 | session = vcl_session_get (wrk, sid); |
| 2797 | if (vcl_session_is_closed (session)) |
Florin Coras | fa915f8 | 2018-12-26 16:29:06 -0800 | [diff] [blame] | 2798 | break; |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2799 | vcl_fifo_rx_evt_valid_or_break (session); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2800 | session_events = session->vep.ev.events; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 2801 | if (!(EPOLLIN & session->vep.ev.events) |
| 2802 | || (session->flags & VCL_SESSION_F_HAS_RX_EVT)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2803 | break; |
| 2804 | add_event = 1; |
| 2805 | events[*num_ev].events |= EPOLLIN; |
| 2806 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 2807 | session->flags |= VCL_SESSION_F_HAS_RX_EVT; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2808 | break; |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 2809 | case SESSION_IO_EVT_TX: |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 2810 | sid = e->session_index; |
Florin Coras | 080aa50 | 2020-05-26 00:47:52 +0000 | [diff] [blame] | 2811 | session = vcl_session_get (wrk, sid); |
| 2812 | if (vcl_session_is_closed (session)) |
Florin Coras | fa915f8 | 2018-12-26 16:29:06 -0800 | [diff] [blame] | 2813 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2814 | session_events = session->vep.ev.events; |
| 2815 | if (!(EPOLLOUT & session_events)) |
| 2816 | break; |
| 2817 | add_event = 1; |
| 2818 | events[*num_ev].events |= EPOLLOUT; |
| 2819 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 17ec577 | 2020-08-12 20:46:29 -0700 | [diff] [blame] | 2820 | svm_fifo_reset_has_deq_ntf (vcl_session_is_ct (session) ? |
| 2821 | session->ct_tx_fifo : session->tx_fifo); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2822 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2823 | case SESSION_CTRL_EVT_ACCEPTED: |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2824 | session = vcl_session_accepted (wrk, |
| 2825 | (session_accepted_msg_t *) e->data); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2826 | if (!session) |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2827 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2828 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2829 | session_events = session->vep.ev.events; |
| 2830 | if (!(EPOLLIN & session_events)) |
| 2831 | break; |
| 2832 | |
| 2833 | add_event = 1; |
| 2834 | events[*num_ev].events |= EPOLLIN; |
| 2835 | session_evt_data = session->vep.ev.data.u64; |
| 2836 | break; |
| 2837 | case SESSION_CTRL_EVT_CONNECTED: |
| 2838 | connected_msg = (session_connected_msg_t *) e->data; |
Florin Coras | f1653e6 | 2019-11-06 15:41:37 -0800 | [diff] [blame] | 2839 | sid = vcl_session_connected_handler (wrk, connected_msg); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2840 | /* Generate EPOLLOUT because there's no connected event */ |
Florin Coras | 080aa50 | 2020-05-26 00:47:52 +0000 | [diff] [blame] | 2841 | session = vcl_session_get (wrk, sid); |
| 2842 | if (vcl_session_is_closed (session)) |
Florin Coras | fa915f8 | 2018-12-26 16:29:06 -0800 | [diff] [blame] | 2843 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2844 | session_events = session->vep.ev.events; |
Florin Coras | 72f7782 | 2019-01-22 19:05:52 -0800 | [diff] [blame] | 2845 | if (!(EPOLLOUT & session_events)) |
| 2846 | break; |
| 2847 | add_event = 1; |
| 2848 | events[*num_ev].events |= EPOLLOUT; |
| 2849 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 2850 | if (session->session_state == VCL_STATE_DETACHED) |
Florin Coras | dbc9c59 | 2019-09-25 16:37:43 -0700 | [diff] [blame] | 2851 | events[*num_ev].events |= EPOLLHUP; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2852 | break; |
| 2853 | case SESSION_CTRL_EVT_DISCONNECTED: |
| 2854 | disconnected_msg = (session_disconnected_msg_t *) e->data; |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 2855 | session = vcl_session_disconnected_handler (wrk, disconnected_msg); |
Florin Coras | 080aa50 | 2020-05-26 00:47:52 +0000 | [diff] [blame] | 2856 | if (vcl_session_is_closed (session)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2857 | break; |
Florin Coras | 72f7782 | 2019-01-22 19:05:52 -0800 | [diff] [blame] | 2858 | session_events = session->vep.ev.events; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2859 | add_event = 1; |
| 2860 | events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; |
| 2861 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2862 | break; |
| 2863 | case SESSION_CTRL_EVT_RESET: |
| 2864 | sid = vcl_session_reset_handler (wrk, (session_reset_msg_t *) e->data); |
Florin Coras | 080aa50 | 2020-05-26 00:47:52 +0000 | [diff] [blame] | 2865 | session = vcl_session_get (wrk, sid); |
| 2866 | if (vcl_session_is_closed (session)) |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2867 | break; |
Florin Coras | 72f7782 | 2019-01-22 19:05:52 -0800 | [diff] [blame] | 2868 | session_events = session->vep.ev.events; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2869 | add_event = 1; |
| 2870 | events[*num_ev].events |= EPOLLHUP | EPOLLRDHUP; |
| 2871 | session_evt_data = session->vep.ev.data.u64; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2872 | break; |
Florin Coras | dfae9f9 | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 2873 | case SESSION_CTRL_EVT_UNLISTEN_REPLY: |
| 2874 | vcl_session_unlisten_reply_handler (wrk, e->data); |
| 2875 | break; |
Florin Coras | 68b7e58 | 2020-01-21 18:33:23 -0800 | [diff] [blame] | 2876 | case SESSION_CTRL_EVT_MIGRATED: |
| 2877 | vcl_session_migrated_handler (wrk, e->data); |
| 2878 | break; |
Florin Coras | 9ace36d | 2019-10-28 13:14:17 -0700 | [diff] [blame] | 2879 | case SESSION_CTRL_EVT_CLEANUP: |
| 2880 | vcl_session_cleanup_handler (wrk, e->data); |
| 2881 | break; |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 2882 | case SESSION_CTRL_EVT_REQ_WORKER_UPDATE: |
| 2883 | vcl_session_req_worker_update_handler (wrk, e->data); |
| 2884 | break; |
| 2885 | case SESSION_CTRL_EVT_WORKER_UPDATE_REPLY: |
| 2886 | vcl_session_worker_update_reply_handler (wrk, e->data); |
| 2887 | break; |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 2888 | case SESSION_CTRL_EVT_APP_ADD_SEGMENT: |
| 2889 | vcl_session_app_add_segment_handler (wrk, e->data); |
| 2890 | break; |
| 2891 | case SESSION_CTRL_EVT_APP_DEL_SEGMENT: |
| 2892 | vcl_session_app_del_segment_handler (wrk, e->data); |
| 2893 | break; |
hanlin | a3a4896 | 2020-07-13 11:09:15 +0800 | [diff] [blame] | 2894 | case SESSION_CTRL_EVT_APP_WRK_RPC: |
Florin Coras | 40c07ce | 2020-07-16 20:46:17 -0700 | [diff] [blame] | 2895 | vcl_worker_rpc_handler (wrk, e->data); |
| 2896 | break; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2897 | default: |
| 2898 | VDBG (0, "unhandled: %u", e->event_type); |
| 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | if (add_event) |
| 2903 | { |
| 2904 | events[*num_ev].data.u64 = session_evt_data; |
| 2905 | if (EPOLLONESHOT & session_events) |
| 2906 | { |
| 2907 | session = vcl_session_get (wrk, sid); |
| 2908 | session->vep.ev.events = 0; |
| 2909 | } |
| 2910 | *num_ev += 1; |
| 2911 | } |
| 2912 | } |
| 2913 | |
| 2914 | static int |
| 2915 | vcl_epoll_wait_handle_mq (vcl_worker_t * wrk, svm_msg_q_t * mq, |
| 2916 | struct epoll_event *events, u32 maxevents, |
| 2917 | double wait_for_time, u32 * num_ev) |
| 2918 | { |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2919 | svm_msg_q_msg_t *msg; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2920 | session_event_t *e; |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2921 | int i; |
| 2922 | |
Florin Coras | 539663c | 2018-09-28 14:59:37 -0700 | [diff] [blame] | 2923 | if (vec_len (wrk->mq_msg_vector) && svm_msg_q_is_empty (mq)) |
| 2924 | goto handle_dequeued; |
| 2925 | |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2926 | svm_msg_q_lock (mq); |
| 2927 | if (svm_msg_q_is_empty (mq)) |
| 2928 | { |
| 2929 | if (!wait_for_time) |
| 2930 | { |
| 2931 | svm_msg_q_unlock (mq); |
| 2932 | return 0; |
| 2933 | } |
| 2934 | else if (wait_for_time < 0) |
| 2935 | { |
| 2936 | svm_msg_q_wait (mq); |
| 2937 | } |
| 2938 | else |
| 2939 | { |
Florin Coras | 60f1fc1 | 2018-08-16 14:57:31 -0700 | [diff] [blame] | 2940 | if (svm_msg_q_timedwait (mq, wait_for_time / 1e3)) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2941 | { |
| 2942 | svm_msg_q_unlock (mq); |
| 2943 | return 0; |
| 2944 | } |
| 2945 | } |
| 2946 | } |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 2947 | ASSERT (maxevents > *num_ev); |
hanlin | d0e646f | 2020-05-11 22:20:37 +0800 | [diff] [blame] | 2948 | vcl_mq_dequeue_batch (wrk, mq, ~0); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2949 | svm_msg_q_unlock (mq); |
| 2950 | |
Florin Coras | 539663c | 2018-09-28 14:59:37 -0700 | [diff] [blame] | 2951 | handle_dequeued: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2952 | for (i = 0; i < vec_len (wrk->mq_msg_vector); i++) |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2953 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2954 | msg = vec_elt_at_index (wrk->mq_msg_vector, i); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2955 | e = svm_msg_q_msg_data (mq, msg); |
hanlin | d0e646f | 2020-05-11 22:20:37 +0800 | [diff] [blame] | 2956 | if (*num_ev < maxevents) |
| 2957 | vcl_epoll_wait_handle_mq_event (wrk, e, events, num_ev); |
| 2958 | else |
| 2959 | vcl_handle_mq_event (wrk, e); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2960 | svm_msg_q_free_msg (mq, msg); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2961 | } |
Florin Coras | aa27eb9 | 2018-10-13 12:20:01 -0700 | [diff] [blame] | 2962 | vec_reset_length (wrk->mq_msg_vector); |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 2963 | vcl_handle_pending_wrk_updates (wrk); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 2964 | return *num_ev; |
| 2965 | } |
| 2966 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2967 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2968 | vppcom_epoll_wait_condvar (vcl_worker_t * wrk, struct epoll_event *events, |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2969 | int maxevents, u32 n_evts, double wait_for_time) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2970 | { |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 2971 | double wait = 0, start = 0, now; |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2972 | |
| 2973 | if (!n_evts) |
| 2974 | { |
| 2975 | wait = wait_for_time; |
| 2976 | start = clib_time_now (&wrk->clib_time); |
| 2977 | } |
| 2978 | |
| 2979 | do |
| 2980 | { |
| 2981 | vcl_epoll_wait_handle_mq (wrk, wrk->app_event_queue, events, maxevents, |
| 2982 | wait, &n_evts); |
| 2983 | if (n_evts) |
| 2984 | return n_evts; |
| 2985 | if (wait == -1) |
| 2986 | continue; |
| 2987 | |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 2988 | now = clib_time_now (&wrk->clib_time); |
Florin Coras | 0edfb1a | 2020-08-04 22:45:45 -0700 | [diff] [blame] | 2989 | wait -= (now - start) * 1e3; |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 2990 | start = now; |
Florin Coras | 14ed6df | 2019-03-06 21:13:42 -0800 | [diff] [blame] | 2991 | } |
| 2992 | while (wait > 0); |
| 2993 | |
| 2994 | return 0; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | static int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 2998 | vppcom_epoll_wait_eventfd (vcl_worker_t * wrk, struct epoll_event *events, |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 2999 | int maxevents, u32 n_evts, double wait_for_time) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3000 | { |
| 3001 | vcl_mq_evt_conn_t *mqc; |
| 3002 | int __clib_unused n_read; |
| 3003 | int n_mq_evts, i; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3004 | u64 buf; |
| 3005 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3006 | vec_validate (wrk->mq_events, pool_elts (wrk->mq_evt_conns)); |
Florin Coras | a4878ed | 2018-10-12 13:09:36 -0700 | [diff] [blame] | 3007 | again: |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3008 | n_mq_evts = epoll_wait (wrk->mqs_epfd, wrk->mq_events, |
| 3009 | vec_len (wrk->mq_events), wait_for_time); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3010 | for (i = 0; i < n_mq_evts; i++) |
| 3011 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3012 | 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] | 3013 | n_read = read (mqc->mq_fd, &buf, sizeof (buf)); |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3014 | 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] | 3015 | } |
Florin Coras | a4878ed | 2018-10-12 13:09:36 -0700 | [diff] [blame] | 3016 | if (!n_evts && n_mq_evts > 0) |
| 3017 | goto again; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3018 | |
| 3019 | return (int) n_evts; |
| 3020 | } |
| 3021 | |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3022 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3023 | vppcom_epoll_wait (uint32_t vep_handle, struct epoll_event *events, |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3024 | int maxevents, double wait_for_time) |
| 3025 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3026 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3027 | vcl_session_t *vep_session; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 3028 | u32 n_evts = 0; |
| 3029 | int i; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3030 | |
| 3031 | if (PREDICT_FALSE (maxevents <= 0)) |
| 3032 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3033 | VDBG (0, "ERROR: Invalid maxevents (%d)!", maxevents); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3034 | return VPPCOM_EINVAL; |
| 3035 | } |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3036 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3037 | vep_session = vcl_session_get_w_handle (wrk, vep_handle); |
Florin Coras | 1459877 | 2018-09-04 19:47:52 -0700 | [diff] [blame] | 3038 | if (!vep_session) |
| 3039 | return VPPCOM_EBADFD; |
| 3040 | |
Florin Coras | 6c3b218 | 2020-10-19 18:36:48 -0700 | [diff] [blame] | 3041 | if (PREDICT_FALSE (!(vep_session->flags & VCL_SESSION_F_IS_VEP))) |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3042 | { |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3043 | VDBG (0, "ERROR: vep_idx (%u) is not a vep!", vep_handle); |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 3044 | return VPPCOM_EINVAL; |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3045 | } |
Florin Coras | 54693d2 | 2018-07-17 10:46:29 -0700 | [diff] [blame] | 3046 | |
| 3047 | memset (events, 0, sizeof (*events) * maxevents); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3048 | |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 3049 | if (vec_len (wrk->unhandled_evts_vector)) |
| 3050 | { |
| 3051 | for (i = 0; i < vec_len (wrk->unhandled_evts_vector); i++) |
| 3052 | { |
| 3053 | vcl_epoll_wait_handle_mq_event (wrk, &wrk->unhandled_evts_vector[i], |
| 3054 | events, &n_evts); |
| 3055 | if (n_evts == maxevents) |
| 3056 | { |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 3057 | vec_delete (wrk->unhandled_evts_vector, i + 1, 0); |
| 3058 | return n_evts; |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 3059 | } |
| 3060 | } |
Florin Coras | e003a1b | 2019-06-05 10:47:16 -0700 | [diff] [blame] | 3061 | vec_reset_length (wrk->unhandled_evts_vector); |
Florin Coras | 86f0450 | 2018-09-12 16:08:01 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | if (vcm->cfg.use_mq_eventfd) |
| 3065 | return vppcom_epoll_wait_eventfd (wrk, events, maxevents, n_evts, |
| 3066 | wait_for_time); |
| 3067 | |
| 3068 | return vppcom_epoll_wait_condvar (wrk, events, maxevents, n_evts, |
| 3069 | wait_for_time); |
Dave Wallace | f7f809c | 2017-10-03 01:48:42 -0400 | [diff] [blame] | 3070 | } |
| 3071 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3072 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3073 | vppcom_session_attr (uint32_t session_handle, uint32_t op, |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3074 | void *buffer, uint32_t * buflen) |
| 3075 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3076 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3077 | vcl_session_t *session; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3078 | int rv = VPPCOM_OK; |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3079 | u32 *flags = buffer, tmp_flags = 0; |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 3080 | vppcom_endpt_t *ep = buffer; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3081 | |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3082 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 3083 | if (!session) |
| 3084 | return VPPCOM_EBADFD; |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 3085 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3086 | switch (op) |
| 3087 | { |
| 3088 | case VPPCOM_ATTR_GET_NREAD: |
Florin Coras | 0ef8ef2 | 2019-01-18 08:37:13 -0800 | [diff] [blame] | 3089 | rv = vcl_session_read_ready (session); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3090 | VDBG (2, "VPPCOM_ATTR_GET_NREAD: sh %u, nread = %d", session_handle, |
| 3091 | rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3092 | break; |
| 3093 | |
Dave Wallace | 227867f | 2017-11-13 21:21:53 -0500 | [diff] [blame] | 3094 | case VPPCOM_ATTR_GET_NWRITE: |
Florin Coras | 0ef8ef2 | 2019-01-18 08:37:13 -0800 | [diff] [blame] | 3095 | rv = vcl_session_write_ready (session); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3096 | VDBG (2, "VPPCOM_ATTR_GET_NWRITE: sh %u, nwrite = %d", session_handle, |
| 3097 | rv); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3098 | break; |
| 3099 | |
| 3100 | case VPPCOM_ATTR_GET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3101 | if (PREDICT_TRUE (buffer && buflen && (*buflen >= sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3102 | { |
Simon Zhang | 53ec967 | 2020-08-07 05:20:47 +0800 | [diff] [blame] | 3103 | *flags = |
| 3104 | O_RDWR | |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3105 | (vcl_session_has_attr (session, VCL_SESS_ATTR_NONBLOCK) ? |
Simon Zhang | 53ec967 | 2020-08-07 05:20:47 +0800 | [diff] [blame] | 3106 | O_NONBLOCK : 0); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3107 | *buflen = sizeof (*flags); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3108 | VDBG (2, "VPPCOM_ATTR_GET_FLAGS: sh %u, flags = 0x%08x, " |
| 3109 | "is_nonblocking = %u", session_handle, *flags, |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3110 | vcl_session_has_attr (session, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3111 | } |
| 3112 | else |
| 3113 | rv = VPPCOM_EINVAL; |
| 3114 | break; |
| 3115 | |
| 3116 | case VPPCOM_ATTR_SET_FLAGS: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3117 | if (PREDICT_TRUE (buffer && buflen && (*buflen == sizeof (*flags)))) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3118 | { |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 3119 | if (*flags & O_NONBLOCK) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3120 | vcl_session_set_attr (session, VCL_SESS_ATTR_NONBLOCK); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 3121 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3122 | vcl_session_clear_attr (session, VCL_SESS_ATTR_NONBLOCK); |
Keith Burns (alagalah) | 9b79377 | 2018-02-16 08:20:56 -0800 | [diff] [blame] | 3123 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3124 | VDBG (2, "VPPCOM_ATTR_SET_FLAGS: sh %u, flags = 0x%08x," |
| 3125 | " is_nonblocking = %u", session_handle, *flags, |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3126 | vcl_session_has_attr (session, VCL_SESS_ATTR_NONBLOCK)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3127 | } |
| 3128 | else |
| 3129 | rv = VPPCOM_EINVAL; |
| 3130 | break; |
| 3131 | |
| 3132 | case VPPCOM_ATTR_GET_PEER_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3133 | if (PREDICT_TRUE (buffer && buflen && |
| 3134 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3135 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3136 | ep->is_ip4 = session->transport.is_ip4; |
| 3137 | ep->port = session->transport.rmt_port; |
| 3138 | if (session->transport.is_ip4) |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3139 | clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip4, |
| 3140 | sizeof (ip4_address_t)); |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 3141 | else |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3142 | clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip6, |
| 3143 | sizeof (ip6_address_t)); |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 3144 | *buflen = sizeof (*ep); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3145 | VDBG (1, "VPPCOM_ATTR_GET_PEER_ADDR: sh %u, is_ip4 = %u, " |
| 3146 | "addr = %U, port %u", session_handle, ep->is_ip4, |
| 3147 | format_ip46_address, &session->transport.rmt_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 3148 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 3149 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3150 | } |
| 3151 | else |
| 3152 | rv = VPPCOM_EINVAL; |
| 3153 | break; |
| 3154 | |
| 3155 | case VPPCOM_ATTR_GET_LCL_ADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3156 | if (PREDICT_TRUE (buffer && buflen && |
| 3157 | (*buflen >= sizeof (*ep)) && ep->ip)) |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3158 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3159 | ep->is_ip4 = session->transport.is_ip4; |
| 3160 | ep->port = session->transport.lcl_port; |
| 3161 | if (session->transport.is_ip4) |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3162 | clib_memcpy_fast (ep->ip, &session->transport.lcl_ip.ip4, |
| 3163 | sizeof (ip4_address_t)); |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 3164 | else |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3165 | clib_memcpy_fast (ep->ip, &session->transport.lcl_ip.ip6, |
| 3166 | sizeof (ip6_address_t)); |
Steven | 2199aab | 2017-10-15 20:18:47 -0700 | [diff] [blame] | 3167 | *buflen = sizeof (*ep); |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3168 | VDBG (1, "VPPCOM_ATTR_GET_LCL_ADDR: sh %u, is_ip4 = %u, addr = %U" |
| 3169 | " port %d", session_handle, ep->is_ip4, format_ip46_address, |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3170 | &session->transport.lcl_ip, |
Florin Coras | 0d427d8 | 2018-06-27 03:24:07 -0700 | [diff] [blame] | 3171 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 3172 | clib_net_to_host_u16 (ep->port)); |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3173 | } |
| 3174 | else |
| 3175 | rv = VPPCOM_EINVAL; |
| 3176 | break; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 3177 | |
Florin Coras | ef7cbf6 | 2019-10-17 09:56:27 -0700 | [diff] [blame] | 3178 | case VPPCOM_ATTR_SET_LCL_ADDR: |
| 3179 | if (PREDICT_TRUE (buffer && buflen && |
| 3180 | (*buflen >= sizeof (*ep)) && ep->ip)) |
| 3181 | { |
| 3182 | session->transport.is_ip4 = ep->is_ip4; |
| 3183 | session->transport.lcl_port = ep->port; |
| 3184 | vcl_ip_copy_from_ep (&session->transport.lcl_ip, ep); |
| 3185 | *buflen = sizeof (*ep); |
| 3186 | VDBG (1, "VPPCOM_ATTR_SET_LCL_ADDR: sh %u, is_ip4 = %u, addr = %U" |
| 3187 | " port %d", session_handle, ep->is_ip4, format_ip46_address, |
| 3188 | &session->transport.lcl_ip, |
| 3189 | ep->is_ip4 ? IP46_TYPE_IP4 : IP46_TYPE_IP6, |
| 3190 | clib_net_to_host_u16 (ep->port)); |
| 3191 | } |
| 3192 | else |
| 3193 | rv = VPPCOM_EINVAL; |
| 3194 | break; |
| 3195 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3196 | case VPPCOM_ATTR_GET_LIBC_EPFD: |
| 3197 | rv = session->libc_epfd; |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3198 | VDBG (2, "VPPCOM_ATTR_GET_LIBC_EPFD: libc_epfd %d", rv); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3199 | break; |
| 3200 | |
| 3201 | case VPPCOM_ATTR_SET_LIBC_EPFD: |
| 3202 | if (PREDICT_TRUE (buffer && buflen && |
| 3203 | (*buflen == sizeof (session->libc_epfd)))) |
| 3204 | { |
| 3205 | session->libc_epfd = *(int *) buffer; |
| 3206 | *buflen = sizeof (session->libc_epfd); |
| 3207 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3208 | VDBG (2, "VPPCOM_ATTR_SET_LIBC_EPFD: libc_epfd %d, buflen %d", |
| 3209 | session->libc_epfd, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3210 | } |
| 3211 | else |
| 3212 | rv = VPPCOM_EINVAL; |
| 3213 | break; |
| 3214 | |
| 3215 | case VPPCOM_ATTR_GET_PROTOCOL: |
| 3216 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3217 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3218 | *(int *) buffer = session->session_type; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3219 | *buflen = sizeof (int); |
| 3220 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3221 | VDBG (2, "VPPCOM_ATTR_GET_PROTOCOL: %d (%s), buflen %d", |
| 3222 | *(int *) buffer, *(int *) buffer ? "UDP" : "TCP", *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3223 | } |
| 3224 | else |
| 3225 | rv = VPPCOM_EINVAL; |
| 3226 | break; |
| 3227 | |
| 3228 | case VPPCOM_ATTR_GET_LISTEN: |
| 3229 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3230 | { |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3231 | *(int *) buffer = vcl_session_has_attr (session, |
| 3232 | VCL_SESS_ATTR_LISTEN); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3233 | *buflen = sizeof (int); |
| 3234 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3235 | VDBG (2, "VPPCOM_ATTR_GET_LISTEN: %d, buflen %d", *(int *) buffer, |
| 3236 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3237 | } |
| 3238 | else |
| 3239 | rv = VPPCOM_EINVAL; |
| 3240 | break; |
| 3241 | |
| 3242 | case VPPCOM_ATTR_GET_ERROR: |
| 3243 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3244 | { |
| 3245 | *(int *) buffer = 0; |
| 3246 | *buflen = sizeof (int); |
| 3247 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3248 | VDBG (2, "VPPCOM_ATTR_GET_ERROR: %d, buflen %d, #VPP-TBD#", |
| 3249 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3250 | } |
| 3251 | else |
| 3252 | rv = VPPCOM_EINVAL; |
| 3253 | break; |
| 3254 | |
| 3255 | case VPPCOM_ATTR_GET_TX_FIFO_LEN: |
| 3256 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 3257 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3258 | |
| 3259 | /* VPP-TBD */ |
| 3260 | *(size_t *) buffer = (session->sndbuf_size ? session->sndbuf_size : |
Florin Coras | f22f4e5 | 2019-12-19 16:10:58 -0800 | [diff] [blame] | 3261 | session->tx_fifo ? |
| 3262 | svm_fifo_size (session->tx_fifo) : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3263 | vcm->cfg.tx_fifo_size); |
| 3264 | *buflen = sizeof (u32); |
| 3265 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3266 | VDBG (2, "VPPCOM_ATTR_GET_TX_FIFO_LEN: %u (0x%x), buflen %d," |
| 3267 | " #VPP-TBD#", *(size_t *) buffer, *(size_t *) buffer, |
| 3268 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3269 | } |
| 3270 | else |
| 3271 | rv = VPPCOM_EINVAL; |
| 3272 | break; |
| 3273 | |
| 3274 | case VPPCOM_ATTR_SET_TX_FIFO_LEN: |
| 3275 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 3276 | { |
| 3277 | /* VPP-TBD */ |
| 3278 | session->sndbuf_size = *(u32 *) buffer; |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3279 | VDBG (2, "VPPCOM_ATTR_SET_TX_FIFO_LEN: %u (0x%x), buflen %d," |
| 3280 | " #VPP-TBD#", session->sndbuf_size, session->sndbuf_size, |
| 3281 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3282 | } |
| 3283 | else |
| 3284 | rv = VPPCOM_EINVAL; |
| 3285 | break; |
| 3286 | |
| 3287 | case VPPCOM_ATTR_GET_RX_FIFO_LEN: |
| 3288 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 3289 | { |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3290 | |
| 3291 | /* VPP-TBD */ |
| 3292 | *(size_t *) buffer = (session->rcvbuf_size ? session->rcvbuf_size : |
Florin Coras | f22f4e5 | 2019-12-19 16:10:58 -0800 | [diff] [blame] | 3293 | session->rx_fifo ? |
| 3294 | svm_fifo_size (session->rx_fifo) : |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3295 | vcm->cfg.rx_fifo_size); |
| 3296 | *buflen = sizeof (u32); |
| 3297 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3298 | VDBG (2, "VPPCOM_ATTR_GET_RX_FIFO_LEN: %u (0x%x), buflen %d, " |
| 3299 | "#VPP-TBD#", *(size_t *) buffer, *(size_t *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3300 | } |
| 3301 | else |
| 3302 | rv = VPPCOM_EINVAL; |
| 3303 | break; |
| 3304 | |
| 3305 | case VPPCOM_ATTR_SET_RX_FIFO_LEN: |
| 3306 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 3307 | { |
| 3308 | /* VPP-TBD */ |
| 3309 | session->rcvbuf_size = *(u32 *) buffer; |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3310 | VDBG (2, "VPPCOM_ATTR_SET_RX_FIFO_LEN: %u (0x%x), buflen %d," |
| 3311 | " #VPP-TBD#", session->sndbuf_size, session->sndbuf_size, |
| 3312 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3313 | } |
| 3314 | else |
| 3315 | rv = VPPCOM_EINVAL; |
| 3316 | break; |
| 3317 | |
| 3318 | case VPPCOM_ATTR_GET_REUSEADDR: |
| 3319 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3320 | { |
| 3321 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3322 | *(int *) buffer = vcl_session_has_attr (session, |
| 3323 | VCL_SESS_ATTR_REUSEADDR); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3324 | *buflen = sizeof (int); |
| 3325 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3326 | VDBG (2, "VPPCOM_ATTR_GET_REUSEADDR: %d, buflen %d, #VPP-TBD#", |
| 3327 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3328 | } |
| 3329 | else |
| 3330 | rv = VPPCOM_EINVAL; |
| 3331 | break; |
| 3332 | |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 3333 | case VPPCOM_ATTR_SET_REUSEADDR: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3334 | if (buffer && buflen && (*buflen == sizeof (int)) && |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3335 | !vcl_session_has_attr (session, VCL_SESS_ATTR_LISTEN)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3336 | { |
| 3337 | /* VPP-TBD */ |
| 3338 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3339 | vcl_session_set_attr (session, VCL_SESS_ATTR_REUSEADDR); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3340 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3341 | vcl_session_clear_attr (session, VCL_SESS_ATTR_REUSEADDR); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3342 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3343 | VDBG (2, "VPPCOM_ATTR_SET_REUSEADDR: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3344 | vcl_session_has_attr (session, VCL_SESS_ATTR_REUSEADDR), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3345 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3346 | } |
| 3347 | else |
| 3348 | rv = VPPCOM_EINVAL; |
| 3349 | break; |
| 3350 | |
| 3351 | case VPPCOM_ATTR_GET_REUSEPORT: |
| 3352 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3353 | { |
| 3354 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3355 | *(int *) buffer = vcl_session_has_attr (session, |
| 3356 | VCL_SESS_ATTR_REUSEPORT); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3357 | *buflen = sizeof (int); |
| 3358 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3359 | VDBG (2, "VPPCOM_ATTR_GET_REUSEPORT: %d, buflen %d, #VPP-TBD#", |
| 3360 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3361 | } |
| 3362 | else |
| 3363 | rv = VPPCOM_EINVAL; |
| 3364 | break; |
| 3365 | |
| 3366 | case VPPCOM_ATTR_SET_REUSEPORT: |
| 3367 | if (buffer && buflen && (*buflen == sizeof (int)) && |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3368 | !vcl_session_has_attr (session, VCL_SESS_ATTR_LISTEN)) |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3369 | { |
| 3370 | /* VPP-TBD */ |
| 3371 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3372 | vcl_session_set_attr (session, VCL_SESS_ATTR_REUSEPORT); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3373 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3374 | vcl_session_clear_attr (session, VCL_SESS_ATTR_REUSEPORT); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3375 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3376 | VDBG (2, "VPPCOM_ATTR_SET_REUSEPORT: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3377 | vcl_session_has_attr (session, VCL_SESS_ATTR_REUSEPORT), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3378 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3379 | } |
| 3380 | else |
| 3381 | rv = VPPCOM_EINVAL; |
| 3382 | break; |
| 3383 | |
| 3384 | case VPPCOM_ATTR_GET_BROADCAST: |
| 3385 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3386 | { |
| 3387 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3388 | *(int *) buffer = vcl_session_has_attr (session, |
| 3389 | VCL_SESS_ATTR_BROADCAST); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3390 | *buflen = sizeof (int); |
| 3391 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3392 | VDBG (2, "VPPCOM_ATTR_GET_BROADCAST: %d, buflen %d, #VPP-TBD#", |
| 3393 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3394 | } |
| 3395 | else |
| 3396 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 3397 | break; |
| 3398 | |
| 3399 | case VPPCOM_ATTR_SET_BROADCAST: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3400 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3401 | { |
| 3402 | /* VPP-TBD */ |
| 3403 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3404 | vcl_session_set_attr (session, VCL_SESS_ATTR_BROADCAST); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3405 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3406 | vcl_session_clear_attr (session, VCL_SESS_ATTR_BROADCAST); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3407 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3408 | VDBG (2, "VPPCOM_ATTR_SET_BROADCAST: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3409 | vcl_session_has_attr (session, VCL_SESS_ATTR_BROADCAST), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3410 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3411 | } |
| 3412 | else |
| 3413 | rv = VPPCOM_EINVAL; |
| 3414 | break; |
| 3415 | |
| 3416 | case VPPCOM_ATTR_GET_V6ONLY: |
| 3417 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3418 | { |
| 3419 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3420 | *(int *) buffer = vcl_session_has_attr (session, |
| 3421 | VCL_SESS_ATTR_V6ONLY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3422 | *buflen = sizeof (int); |
| 3423 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3424 | VDBG (2, "VPPCOM_ATTR_GET_V6ONLY: %d, buflen %d, #VPP-TBD#", |
| 3425 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3426 | } |
| 3427 | else |
| 3428 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 3429 | break; |
| 3430 | |
| 3431 | case VPPCOM_ATTR_SET_V6ONLY: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3432 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3433 | { |
| 3434 | /* VPP-TBD */ |
| 3435 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3436 | vcl_session_set_attr (session, VCL_SESS_ATTR_V6ONLY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3437 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3438 | vcl_session_clear_attr (session, VCL_SESS_ATTR_V6ONLY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3439 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3440 | VDBG (2, "VPPCOM_ATTR_SET_V6ONLY: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3441 | vcl_session_has_attr (session, VCL_SESS_ATTR_V6ONLY), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3442 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3443 | } |
| 3444 | else |
| 3445 | rv = VPPCOM_EINVAL; |
| 3446 | break; |
| 3447 | |
| 3448 | case VPPCOM_ATTR_GET_KEEPALIVE: |
| 3449 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3450 | { |
| 3451 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3452 | *(int *) buffer = vcl_session_has_attr (session, |
| 3453 | VCL_SESS_ATTR_KEEPALIVE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3454 | *buflen = sizeof (int); |
| 3455 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3456 | VDBG (2, "VPPCOM_ATTR_GET_KEEPALIVE: %d, buflen %d, #VPP-TBD#", |
| 3457 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3458 | } |
| 3459 | else |
| 3460 | rv = VPPCOM_EINVAL; |
Steven | b5a1160 | 2017-10-11 09:59:30 -0700 | [diff] [blame] | 3461 | break; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 3462 | |
| 3463 | case VPPCOM_ATTR_SET_KEEPALIVE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3464 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3465 | { |
| 3466 | /* VPP-TBD */ |
| 3467 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3468 | vcl_session_set_attr (session, VCL_SESS_ATTR_KEEPALIVE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3469 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3470 | vcl_session_clear_attr (session, VCL_SESS_ATTR_KEEPALIVE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3471 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3472 | VDBG (2, "VPPCOM_ATTR_SET_KEEPALIVE: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3473 | vcl_session_has_attr (session, VCL_SESS_ATTR_KEEPALIVE), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3474 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3475 | } |
| 3476 | else |
| 3477 | rv = VPPCOM_EINVAL; |
| 3478 | break; |
| 3479 | |
| 3480 | case VPPCOM_ATTR_GET_TCP_NODELAY: |
| 3481 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3482 | { |
| 3483 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3484 | *(int *) buffer = vcl_session_has_attr (session, |
| 3485 | VCL_SESS_ATTR_TCP_NODELAY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3486 | *buflen = sizeof (int); |
| 3487 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3488 | VDBG (2, "VPPCOM_ATTR_GET_TCP_NODELAY: %d, buflen %d, #VPP-TBD#", |
| 3489 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3490 | } |
| 3491 | else |
| 3492 | rv = VPPCOM_EINVAL; |
| 3493 | break; |
| 3494 | |
| 3495 | case VPPCOM_ATTR_SET_TCP_NODELAY: |
| 3496 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3497 | { |
| 3498 | /* VPP-TBD */ |
| 3499 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3500 | vcl_session_set_attr (session, VCL_SESS_ATTR_TCP_NODELAY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3501 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3502 | vcl_session_clear_attr (session, VCL_SESS_ATTR_TCP_NODELAY); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3503 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3504 | VDBG (2, "VPPCOM_ATTR_SET_TCP_NODELAY: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3505 | vcl_session_has_attr (session, VCL_SESS_ATTR_TCP_NODELAY), |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3506 | *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3507 | } |
| 3508 | else |
| 3509 | rv = VPPCOM_EINVAL; |
| 3510 | break; |
| 3511 | |
| 3512 | case VPPCOM_ATTR_GET_TCP_KEEPIDLE: |
| 3513 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3514 | { |
| 3515 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3516 | *(int *) buffer = vcl_session_has_attr (session, |
| 3517 | VCL_SESS_ATTR_TCP_KEEPIDLE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3518 | *buflen = sizeof (int); |
| 3519 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3520 | VDBG (2, "VPPCOM_ATTR_GET_TCP_KEEPIDLE: %d, buflen %d, #VPP-TBD#", |
| 3521 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3522 | } |
| 3523 | else |
| 3524 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 3525 | break; |
| 3526 | |
| 3527 | case VPPCOM_ATTR_SET_TCP_KEEPIDLE: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3528 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3529 | { |
| 3530 | /* VPP-TBD */ |
| 3531 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3532 | vcl_session_set_attr (session, VCL_SESS_ATTR_TCP_KEEPIDLE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3533 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3534 | vcl_session_clear_attr (session, VCL_SESS_ATTR_TCP_KEEPIDLE); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3535 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3536 | VDBG (2, "VPPCOM_ATTR_SET_TCP_KEEPIDLE: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3537 | vcl_session_has_attr (session, |
| 3538 | VCL_SESS_ATTR_TCP_KEEPIDLE), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3539 | } |
| 3540 | else |
| 3541 | rv = VPPCOM_EINVAL; |
| 3542 | break; |
| 3543 | |
| 3544 | case VPPCOM_ATTR_GET_TCP_KEEPINTVL: |
| 3545 | if (buffer && buflen && (*buflen >= sizeof (int))) |
| 3546 | { |
| 3547 | /* VPP-TBD */ |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3548 | *(int *) buffer = vcl_session_has_attr (session, |
| 3549 | VCL_SESS_ATTR_TCP_KEEPINTVL); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3550 | *buflen = sizeof (int); |
| 3551 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3552 | VDBG (2, "VPPCOM_ATTR_GET_TCP_KEEPINTVL: %d, buflen %d, #VPP-TBD#", |
| 3553 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3554 | } |
| 3555 | else |
| 3556 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 3557 | break; |
| 3558 | |
| 3559 | case VPPCOM_ATTR_SET_TCP_KEEPINTVL: |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3560 | if (buffer && buflen && (*buflen == sizeof (int))) |
| 3561 | { |
| 3562 | /* VPP-TBD */ |
| 3563 | if (*(int *) buffer) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3564 | vcl_session_set_attr (session, VCL_SESS_ATTR_TCP_KEEPINTVL); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3565 | else |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3566 | vcl_session_clear_attr (session, VCL_SESS_ATTR_TCP_KEEPINTVL); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3567 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3568 | VDBG (2, "VPPCOM_ATTR_SET_TCP_KEEPINTVL: %d, buflen %d, #VPP-TBD#", |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3569 | vcl_session_has_attr (session, |
| 3570 | VCL_SESS_ATTR_TCP_KEEPINTVL), *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3571 | } |
| 3572 | else |
| 3573 | rv = VPPCOM_EINVAL; |
| 3574 | break; |
| 3575 | |
| 3576 | case VPPCOM_ATTR_GET_TCP_USER_MSS: |
| 3577 | if (buffer && buflen && (*buflen >= sizeof (u32))) |
| 3578 | { |
| 3579 | /* VPP-TBD */ |
| 3580 | *(u32 *) buffer = session->user_mss; |
| 3581 | *buflen = sizeof (int); |
| 3582 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3583 | VDBG (2, "VPPCOM_ATTR_GET_TCP_USER_MSS: %d, buflen %d, #VPP-TBD#", |
| 3584 | *(int *) buffer, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3585 | } |
| 3586 | else |
| 3587 | rv = VPPCOM_EINVAL; |
| 3588 | break; |
| 3589 | |
| 3590 | case VPPCOM_ATTR_SET_TCP_USER_MSS: |
| 3591 | if (buffer && buflen && (*buflen == sizeof (u32))) |
| 3592 | { |
| 3593 | /* VPP-TBD */ |
| 3594 | session->user_mss = *(u32 *) buffer; |
| 3595 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3596 | VDBG (2, "VPPCOM_ATTR_SET_TCP_USER_MSS: %u, buflen %d, #VPP-TBD#", |
| 3597 | session->user_mss, *buflen); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3598 | } |
| 3599 | else |
| 3600 | rv = VPPCOM_EINVAL; |
Steven | bccd339 | 2017-10-12 20:42:21 -0700 | [diff] [blame] | 3601 | break; |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 3602 | |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3603 | case VPPCOM_ATTR_SET_SHUT: |
| 3604 | if (*flags == SHUT_RD || *flags == SHUT_RDWR) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3605 | vcl_session_set_attr (session, VCL_SESS_ATTR_SHUT_RD); |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3606 | if (*flags == SHUT_WR || *flags == SHUT_RDWR) |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3607 | vcl_session_set_attr (session, VCL_SESS_ATTR_SHUT_WR); |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3608 | break; |
| 3609 | |
| 3610 | case VPPCOM_ATTR_GET_SHUT: |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3611 | if (vcl_session_has_attr (session, VCL_SESS_ATTR_SHUT_RD)) |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3612 | tmp_flags = 1; |
Florin Coras | ac422d6 | 2020-10-19 20:51:36 -0700 | [diff] [blame] | 3613 | if (vcl_session_has_attr (session, VCL_SESS_ATTR_SHUT_WR)) |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3614 | tmp_flags |= 2; |
| 3615 | if (tmp_flags == 1) |
| 3616 | *(int *) buffer = SHUT_RD; |
| 3617 | else if (tmp_flags == 2) |
| 3618 | *(int *) buffer = SHUT_WR; |
| 3619 | else if (tmp_flags == 3) |
| 3620 | *(int *) buffer = SHUT_RDWR; |
| 3621 | *buflen = sizeof (int); |
| 3622 | break; |
Florin Coras | 1e96617 | 2020-05-16 18:18:14 +0000 | [diff] [blame] | 3623 | |
| 3624 | case VPPCOM_ATTR_SET_CONNECTED: |
| 3625 | session->flags |= VCL_SESSION_F_CONNECTED; |
| 3626 | break; |
| 3627 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 3628 | default: |
| 3629 | rv = VPPCOM_EINVAL; |
| 3630 | break; |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3631 | } |
| 3632 | |
Dave Wallace | 35830af | 2017-10-09 01:43:42 -0400 | [diff] [blame] | 3633 | return rv; |
| 3634 | } |
| 3635 | |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3636 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3637 | vppcom_session_recvfrom (uint32_t session_handle, void *buffer, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3638 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 3639 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3640 | vcl_worker_t *wrk = vcl_worker_get_current (); |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3641 | vcl_session_t *session; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3642 | int rv = VPPCOM_OK; |
Steven | 58f464e | 2017-10-25 12:33:12 -0700 | [diff] [blame] | 3643 | |
| 3644 | if (flags == 0) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3645 | rv = vppcom_session_read (session_handle, buffer, buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3646 | else if (flags & MSG_PEEK) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3647 | rv = vppcom_session_peek (session_handle, buffer, buflen); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3648 | else |
| 3649 | { |
Florin Coras | a7a1a22 | 2018-12-30 17:11:31 -0800 | [diff] [blame] | 3650 | VDBG (0, "Unsupport flags for recvfrom %d", flags); |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 3651 | return VPPCOM_EAFNOSUPPORT; |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
Florin Coras | 0a1e183 | 2020-03-29 18:54:04 +0000 | [diff] [blame] | 3654 | if (ep && rv > 0) |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3655 | { |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3656 | session = vcl_session_get_w_handle (wrk, session_handle); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3657 | if (session->transport.is_ip4) |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3658 | clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip4, |
| 3659 | sizeof (ip4_address_t)); |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3660 | else |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 3661 | clib_memcpy_fast (ep->ip, &session->transport.rmt_ip.ip6, |
| 3662 | sizeof (ip6_address_t)); |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3663 | ep->is_ip4 = session->transport.is_ip4; |
| 3664 | ep->port = session->transport.rmt_port; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3665 | } |
Florin Coras | 460dce6 | 2018-07-27 05:45:06 -0700 | [diff] [blame] | 3666 | |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3667 | return rv; |
| 3668 | } |
| 3669 | |
| 3670 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3671 | vppcom_session_sendto (uint32_t session_handle, void *buffer, |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3672 | uint32_t buflen, int flags, vppcom_endpt_t * ep) |
| 3673 | { |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 3674 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3675 | vcl_session_t *s; |
| 3676 | |
| 3677 | s = vcl_session_get_w_handle (wrk, session_handle); |
| 3678 | if (!s) |
| 3679 | return VPPCOM_EBADFD; |
| 3680 | |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 3681 | if (!buffer) |
| 3682 | return VPPCOM_EINVAL; |
| 3683 | |
| 3684 | if (ep) |
| 3685 | { |
Florin Coras | 5824cc5 | 2020-10-20 18:44:41 -0700 | [diff] [blame] | 3686 | if (!vcl_session_is_cl (s)) |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3687 | return VPPCOM_EINVAL; |
| 3688 | |
| 3689 | /* Session not connected/bound in vpp. Create it by 'connecting' it */ |
Florin Coras | c127d5a | 2020-10-14 16:35:58 -0700 | [diff] [blame] | 3690 | if (PREDICT_FALSE (s->session_state == VCL_STATE_CLOSED)) |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3691 | { |
Florin Coras | 5824cc5 | 2020-10-20 18:44:41 -0700 | [diff] [blame] | 3692 | u32 session_index = s->session_index; |
| 3693 | f64 timeout = vcm->cfg.session_timeout; |
| 3694 | int rv; |
| 3695 | |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3696 | vcl_send_session_connect (wrk, s); |
Florin Coras | 5824cc5 | 2020-10-20 18:44:41 -0700 | [diff] [blame] | 3697 | rv = vppcom_wait_for_session_state_change (session_index, |
| 3698 | VCL_STATE_READY, |
| 3699 | timeout); |
| 3700 | if (rv < 0) |
| 3701 | return rv; |
| 3702 | s = vcl_session_get (wrk, session_index); |
Florin Coras | 5da10c4 | 2020-04-01 04:31:21 +0000 | [diff] [blame] | 3703 | } |
Florin Coras | 5824cc5 | 2020-10-20 18:44:41 -0700 | [diff] [blame] | 3704 | |
| 3705 | s->transport.is_ip4 = ep->is_ip4; |
| 3706 | s->transport.rmt_port = ep->port; |
| 3707 | vcl_ip_copy_from_ep (&s->transport.rmt_ip, ep); |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | if (flags) |
| 3711 | { |
| 3712 | // TBD check the flags and do the right thing |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3713 | VDBG (2, "handling flags 0x%u (%d) not implemented yet.", flags, flags); |
Dave Wallace | 617dffa | 2017-10-26 14:47:06 -0400 | [diff] [blame] | 3714 | } |
| 3715 | |
Florin Coras | 7a2abce | 2020-04-05 19:25:44 +0000 | [diff] [blame] | 3716 | return (vppcom_session_write_inline (wrk, s, buffer, buflen, 1, |
| 3717 | s->is_dgram ? 1 : 0)); |
Steven | ac1f96d | 2017-10-24 16:03:58 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3720 | int |
| 3721 | vppcom_poll (vcl_poll_t * vp, uint32_t n_sids, double wait_for_time) |
| 3722 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3723 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3724 | f64 timeout = clib_time_now (&wrk->clib_time) + wait_for_time; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3725 | u32 i, keep_trying = 1; |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3726 | svm_msg_q_msg_t msg; |
| 3727 | session_event_t *e; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3728 | int rv, num_ev = 0; |
| 3729 | |
Florin Coras | 5e06257 | 2019-03-14 19:07:51 -0700 | [diff] [blame] | 3730 | VDBG (3, "vp %p, nsids %u, wait_for_time %f", vp, n_sids, wait_for_time); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3731 | |
| 3732 | if (!vp) |
| 3733 | return VPPCOM_EFAULT; |
| 3734 | |
| 3735 | do |
| 3736 | { |
Florin Coras | 7e12d94 | 2018-06-27 14:32:43 -0700 | [diff] [blame] | 3737 | vcl_session_t *session; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3738 | |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3739 | /* Dequeue all events and drop all unhandled io events */ |
| 3740 | while (svm_msg_q_sub (wrk->app_event_queue, &msg, SVM_Q_NOWAIT, 0) == 0) |
| 3741 | { |
| 3742 | e = svm_msg_q_msg_data (wrk->app_event_queue, &msg); |
| 3743 | vcl_handle_mq_event (wrk, e); |
| 3744 | svm_msg_q_free_msg (wrk->app_event_queue, &msg); |
| 3745 | } |
| 3746 | vec_reset_length (wrk->unhandled_evts_vector); |
| 3747 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3748 | for (i = 0; i < n_sids; i++) |
| 3749 | { |
Florin Coras | 7baeb71 | 2019-01-04 17:05:43 -0800 | [diff] [blame] | 3750 | session = vcl_session_get (wrk, vp[i].sh); |
Florin Coras | 070453d | 2018-08-24 17:04:27 -0700 | [diff] [blame] | 3751 | if (!session) |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3752 | { |
| 3753 | vp[i].revents = POLLHUP; |
| 3754 | num_ev++; |
| 3755 | continue; |
| 3756 | } |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3757 | |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3758 | vp[i].revents = 0; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3759 | |
| 3760 | if (POLLIN & vp[i].events) |
| 3761 | { |
Florin Coras | 0ef8ef2 | 2019-01-18 08:37:13 -0800 | [diff] [blame] | 3762 | rv = vcl_session_read_ready (session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3763 | if (rv > 0) |
| 3764 | { |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3765 | vp[i].revents |= POLLIN; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3766 | num_ev++; |
| 3767 | } |
| 3768 | else if (rv < 0) |
| 3769 | { |
| 3770 | switch (rv) |
| 3771 | { |
| 3772 | case VPPCOM_ECONNRESET: |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3773 | vp[i].revents = POLLHUP; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3774 | break; |
| 3775 | |
| 3776 | default: |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3777 | vp[i].revents = POLLERR; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3778 | break; |
| 3779 | } |
| 3780 | num_ev++; |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | if (POLLOUT & vp[i].events) |
| 3785 | { |
Florin Coras | 0ef8ef2 | 2019-01-18 08:37:13 -0800 | [diff] [blame] | 3786 | rv = vcl_session_write_ready (session); |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3787 | if (rv > 0) |
| 3788 | { |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3789 | vp[i].revents |= POLLOUT; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3790 | num_ev++; |
| 3791 | } |
| 3792 | else if (rv < 0) |
| 3793 | { |
| 3794 | switch (rv) |
| 3795 | { |
| 3796 | case VPPCOM_ECONNRESET: |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3797 | vp[i].revents = POLLHUP; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3798 | break; |
| 3799 | |
| 3800 | default: |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3801 | vp[i].revents = POLLERR; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3802 | break; |
| 3803 | } |
| 3804 | num_ev++; |
| 3805 | } |
| 3806 | } |
| 3807 | |
Dave Wallace | 7e607a7 | 2018-06-18 18:41:32 -0400 | [diff] [blame] | 3808 | if (0) // Note "done:" label used by VCL_SESSION_LOCK_AND_GET() |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3809 | { |
Florin Coras | 6917b94 | 2018-11-13 22:44:54 -0800 | [diff] [blame] | 3810 | vp[i].revents = POLLNVAL; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3811 | num_ev++; |
| 3812 | } |
| 3813 | } |
| 3814 | if (wait_for_time != -1) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3815 | keep_trying = (clib_time_now (&wrk->clib_time) <= timeout) ? 1 : 0; |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3816 | } |
| 3817 | while ((num_ev == 0) && keep_trying); |
| 3818 | |
Dave Wallace | 048b1d6 | 2018-01-03 22:24:41 -0500 | [diff] [blame] | 3819 | return num_ev; |
| 3820 | } |
| 3821 | |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3822 | int |
| 3823 | vppcom_mq_epoll_fd (void) |
| 3824 | { |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3825 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3826 | return wrk->mqs_epfd; |
| 3827 | } |
| 3828 | |
| 3829 | int |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 3830 | vppcom_session_index (vcl_session_handle_t session_handle) |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3831 | { |
| 3832 | return session_handle & 0xFFFFFF; |
| 3833 | } |
| 3834 | |
| 3835 | int |
Florin Coras | 30e79c2 | 2019-01-02 19:31:22 -0800 | [diff] [blame] | 3836 | vppcom_session_worker (vcl_session_handle_t session_handle) |
| 3837 | { |
| 3838 | return session_handle >> 24; |
| 3839 | } |
| 3840 | |
| 3841 | int |
Florin Coras | 134a996 | 2018-08-28 11:32:04 -0700 | [diff] [blame] | 3842 | vppcom_worker_register (void) |
| 3843 | { |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 3844 | if (!vcl_worker_alloc_and_init ()) |
| 3845 | return VPPCOM_EEXIST; |
| 3846 | |
Florin Coras | 47c40e2 | 2018-11-26 17:01:36 -0800 | [diff] [blame] | 3847 | if (vcl_worker_register_with_vpp ()) |
| 3848 | return VPPCOM_EEXIST; |
| 3849 | |
| 3850 | return VPPCOM_OK; |
Florin Coras | 9936831 | 2018-08-02 10:45:44 -0700 | [diff] [blame] | 3851 | } |
| 3852 | |
Florin Coras | 369db83 | 2019-07-08 12:34:45 -0700 | [diff] [blame] | 3853 | void |
| 3854 | vppcom_worker_unregister (void) |
| 3855 | { |
| 3856 | vcl_worker_cleanup (vcl_worker_get_current (), 1 /* notify vpp */ ); |
| 3857 | vcl_set_worker_index (~0); |
| 3858 | } |
| 3859 | |
Pivo | 6017ff0 | 2020-05-04 17:57:33 +0200 | [diff] [blame] | 3860 | void |
| 3861 | vppcom_worker_index_set (int index) |
| 3862 | { |
| 3863 | vcl_set_worker_index (index); |
| 3864 | } |
| 3865 | |
Florin Coras | dfe4cf4 | 2018-11-28 22:13:45 -0800 | [diff] [blame] | 3866 | int |
| 3867 | vppcom_worker_index (void) |
| 3868 | { |
| 3869 | return vcl_get_worker_index (); |
| 3870 | } |
| 3871 | |
Florin Coras | e0982e5 | 2019-01-25 13:19:56 -0800 | [diff] [blame] | 3872 | int |
| 3873 | vppcom_worker_mqs_epfd (void) |
| 3874 | { |
| 3875 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3876 | if (!vcm->cfg.use_mq_eventfd) |
| 3877 | return -1; |
| 3878 | return wrk->mqs_epfd; |
| 3879 | } |
| 3880 | |
Nathan Skrzypczak | 9fd9962 | 2019-05-16 14:38:44 +0200 | [diff] [blame] | 3881 | int |
| 3882 | vppcom_session_is_connectable_listener (uint32_t session_handle) |
| 3883 | { |
| 3884 | vcl_session_t *session; |
| 3885 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3886 | session = vcl_session_get_w_handle (wrk, session_handle); |
| 3887 | if (!session) |
| 3888 | return VPPCOM_EBADFD; |
| 3889 | return vcl_session_is_connectable_listener (wrk, session); |
| 3890 | } |
| 3891 | |
| 3892 | int |
| 3893 | vppcom_session_listener (uint32_t session_handle) |
| 3894 | { |
| 3895 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3896 | vcl_session_t *listen_session, *session; |
| 3897 | session = vcl_session_get_w_handle (wrk, session_handle); |
| 3898 | if (!session) |
| 3899 | return VPPCOM_EBADFD; |
| 3900 | if (session->listener_index == VCL_INVALID_SESSION_INDEX) |
| 3901 | return VPPCOM_EBADFD; |
| 3902 | listen_session = vcl_session_get_w_handle (wrk, session->listener_index); |
| 3903 | if (!listen_session) |
| 3904 | return VPPCOM_EBADFD; |
| 3905 | return vcl_session_handle (listen_session); |
| 3906 | } |
| 3907 | |
| 3908 | int |
| 3909 | vppcom_session_n_accepted (uint32_t session_handle) |
| 3910 | { |
| 3911 | vcl_worker_t *wrk = vcl_worker_get_current (); |
| 3912 | vcl_session_t *session = vcl_session_get_w_handle (wrk, session_handle); |
| 3913 | if (!session) |
| 3914 | return VPPCOM_EBADFD; |
| 3915 | return session->n_accepted_sessions; |
| 3916 | } |
| 3917 | |
Florin Coras | 66ec467 | 2020-06-15 07:59:40 -0700 | [diff] [blame] | 3918 | const char * |
| 3919 | vppcom_proto_str (vppcom_proto_t proto) |
| 3920 | { |
| 3921 | char const *proto_str; |
| 3922 | |
| 3923 | switch (proto) |
| 3924 | { |
| 3925 | case VPPCOM_PROTO_TCP: |
| 3926 | proto_str = "TCP"; |
| 3927 | break; |
| 3928 | case VPPCOM_PROTO_UDP: |
| 3929 | proto_str = "UDP"; |
| 3930 | break; |
| 3931 | case VPPCOM_PROTO_TLS: |
| 3932 | proto_str = "TLS"; |
| 3933 | break; |
| 3934 | case VPPCOM_PROTO_QUIC: |
| 3935 | proto_str = "QUIC"; |
| 3936 | break; |
| 3937 | default: |
| 3938 | proto_str = "UNKNOWN"; |
| 3939 | break; |
| 3940 | } |
| 3941 | return proto_str; |
| 3942 | } |
| 3943 | |
| 3944 | const char * |
| 3945 | vppcom_retval_str (int retval) |
| 3946 | { |
| 3947 | char const *st; |
| 3948 | |
| 3949 | switch (retval) |
| 3950 | { |
| 3951 | case VPPCOM_OK: |
| 3952 | st = "VPPCOM_OK"; |
| 3953 | break; |
| 3954 | |
| 3955 | case VPPCOM_EAGAIN: |
| 3956 | st = "VPPCOM_EAGAIN"; |
| 3957 | break; |
| 3958 | |
| 3959 | case VPPCOM_EFAULT: |
| 3960 | st = "VPPCOM_EFAULT"; |
| 3961 | break; |
| 3962 | |
| 3963 | case VPPCOM_ENOMEM: |
| 3964 | st = "VPPCOM_ENOMEM"; |
| 3965 | break; |
| 3966 | |
| 3967 | case VPPCOM_EINVAL: |
| 3968 | st = "VPPCOM_EINVAL"; |
| 3969 | break; |
| 3970 | |
| 3971 | case VPPCOM_EBADFD: |
| 3972 | st = "VPPCOM_EBADFD"; |
| 3973 | break; |
| 3974 | |
| 3975 | case VPPCOM_EAFNOSUPPORT: |
| 3976 | st = "VPPCOM_EAFNOSUPPORT"; |
| 3977 | break; |
| 3978 | |
| 3979 | case VPPCOM_ECONNABORTED: |
| 3980 | st = "VPPCOM_ECONNABORTED"; |
| 3981 | break; |
| 3982 | |
| 3983 | case VPPCOM_ECONNRESET: |
| 3984 | st = "VPPCOM_ECONNRESET"; |
| 3985 | break; |
| 3986 | |
| 3987 | case VPPCOM_ENOTCONN: |
| 3988 | st = "VPPCOM_ENOTCONN"; |
| 3989 | break; |
| 3990 | |
| 3991 | case VPPCOM_ECONNREFUSED: |
| 3992 | st = "VPPCOM_ECONNREFUSED"; |
| 3993 | break; |
| 3994 | |
| 3995 | case VPPCOM_ETIMEDOUT: |
| 3996 | st = "VPPCOM_ETIMEDOUT"; |
| 3997 | break; |
| 3998 | |
| 3999 | default: |
| 4000 | st = "UNKNOWN_STATE"; |
| 4001 | break; |
| 4002 | } |
| 4003 | |
| 4004 | return st; |
| 4005 | } |
| 4006 | |
Dave Wallace | e22aa74 | 2017-10-20 12:30:38 -0400 | [diff] [blame] | 4007 | /* |
| 4008 | * fd.io coding-style-patch-verification: ON |
| 4009 | * |
| 4010 | * Local Variables: |
| 4011 | * eval: (c-set-style "gnu") |
| 4012 | * End: |
| 4013 | */ |