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