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