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