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