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