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