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