Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 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 | * @file |
| 17 | * @brief Session and session manager |
| 18 | */ |
| 19 | |
qinyang | af9b715 | 2023-06-27 01:11:53 -0700 | [diff] [blame] | 20 | #include <vnet/plugin/plugin.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 21 | #include <vnet/session/session.h> |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 22 | #include <vnet/session/application.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 23 | #include <vnet/dpo/load_balance.h> |
| 24 | #include <vnet/fib/ip4_fib.h> |
Florin Coras | d82f471 | 2022-04-25 16:15:02 -0700 | [diff] [blame] | 25 | #include <vlib/stats/stats.h> |
Marvin Liu | 0654242 | 2022-08-16 06:49:09 +0000 | [diff] [blame] | 26 | #include <vlib/dma/dma.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 27 | |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 28 | session_main_t session_main; |
Florin Coras | 3eb5062 | 2017-07-13 01:24:57 -0400 | [diff] [blame] | 29 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 30 | static inline int |
| 31 | session_send_evt_to_thread (void *data, void *args, u32 thread_index, |
| 32 | session_evt_type_t evt_type) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 33 | { |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 34 | session_worker_t *wrk = session_main_get_worker (thread_index); |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 35 | session_event_t *evt; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 36 | svm_msg_q_msg_t msg; |
| 37 | svm_msg_q_t *mq; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 38 | |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 39 | mq = wrk->vpp_event_queue; |
Nathan Skrzypczak | b4c6775 | 2019-06-20 09:58:37 +0200 | [diff] [blame] | 40 | if (PREDICT_FALSE (svm_msg_q_lock (mq))) |
| 41 | return -1; |
Florin Coras | 80d100c | 2022-04-19 18:57:24 -0700 | [diff] [blame] | 42 | if (PREDICT_FALSE (svm_msg_q_or_ring_is_full (mq, SESSION_MQ_IO_EVT_RING))) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 43 | { |
| 44 | svm_msg_q_unlock (mq); |
| 45 | return -2; |
| 46 | } |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 47 | switch (evt_type) |
| 48 | { |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 49 | case SESSION_CTRL_EVT_RPC: |
Nathan Skrzypczak | 1afa7af | 2019-09-13 17:14:57 +0200 | [diff] [blame] | 50 | msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
| 51 | evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 52 | evt->rpc_args.fp = data; |
| 53 | evt->rpc_args.arg = args; |
| 54 | break; |
Aloys Augustin | 0c7f54d | 2019-07-03 16:59:43 +0200 | [diff] [blame] | 55 | case SESSION_IO_EVT_RX: |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 56 | case SESSION_IO_EVT_TX: |
Florin Coras | 844a36d | 2018-12-20 09:50:50 -0800 | [diff] [blame] | 57 | case SESSION_IO_EVT_TX_FLUSH: |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 58 | case SESSION_IO_EVT_BUILTIN_RX: |
Nathan Skrzypczak | 1afa7af | 2019-09-13 17:14:57 +0200 | [diff] [blame] | 59 | msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
| 60 | evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg); |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 61 | evt->session_index = *(u32 *) data; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 62 | break; |
Florin Coras | aeb7c1c | 2023-03-10 10:22:21 -0800 | [diff] [blame] | 63 | case SESSION_IO_EVT_TX_MAIN: |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 64 | case SESSION_CTRL_EVT_CLOSE: |
Florin Coras | 73cad33 | 2019-08-28 17:12:32 -0700 | [diff] [blame] | 65 | case SESSION_CTRL_EVT_RESET: |
Nathan Skrzypczak | 1afa7af | 2019-09-13 17:14:57 +0200 | [diff] [blame] | 66 | msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
| 67 | evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 68 | evt->session_handle = session_handle ((session_t *) data); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 69 | break; |
| 70 | default: |
| 71 | clib_warning ("evt unhandled!"); |
| 72 | svm_msg_q_unlock (mq); |
| 73 | return -1; |
| 74 | } |
Nathan Skrzypczak | 1afa7af | 2019-09-13 17:14:57 +0200 | [diff] [blame] | 75 | evt->event_type = evt_type; |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 76 | |
Florin Coras | 52207f1 | 2018-07-12 14:48:06 -0700 | [diff] [blame] | 77 | svm_msg_q_add_and_unlock (mq, &msg); |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 78 | |
| 79 | if (PREDICT_FALSE (wrk->state == SESSION_WRK_INTERRUPT)) |
| 80 | vlib_node_set_interrupt_pending (wrk->vm, session_queue_node.index); |
| 81 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 82 | return 0; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 85 | int |
| 86 | session_send_io_evt_to_thread (svm_fifo_t * f, session_evt_type_t evt_type) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 87 | { |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 88 | return session_send_evt_to_thread (&f->shr->master_session_index, 0, |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 89 | f->master_thread_index, evt_type); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | int |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 93 | session_send_io_evt_to_thread_custom (void *data, u32 thread_index, |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 94 | session_evt_type_t evt_type) |
| 95 | { |
Florin Coras | ef91534 | 2018-09-29 10:23:06 -0700 | [diff] [blame] | 96 | return session_send_evt_to_thread (data, 0, thread_index, evt_type); |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 100 | session_send_ctrl_evt_to_thread (session_t * s, session_evt_type_t evt_type) |
Florin Coras | 3c2fed5 | 2018-07-04 04:15:05 -0700 | [diff] [blame] | 101 | { |
liuyacan | 534468e | 2021-05-09 03:50:40 +0000 | [diff] [blame] | 102 | /* only events supported are disconnect, shutdown and reset */ |
| 103 | ASSERT (evt_type == SESSION_CTRL_EVT_CLOSE || |
| 104 | evt_type == SESSION_CTRL_EVT_HALF_CLOSE || |
| 105 | evt_type == SESSION_CTRL_EVT_RESET); |
Florin Coras | 458089b | 2019-08-21 16:20:44 -0700 | [diff] [blame] | 106 | return session_send_evt_to_thread (s, 0, s->thread_index, evt_type); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void |
Nathan Skrzypczak | 60f3e65 | 2019-03-19 13:57:31 +0100 | [diff] [blame] | 110 | session_send_rpc_evt_to_thread_force (u32 thread_index, void *fp, |
| 111 | void *rpc_args) |
| 112 | { |
| 113 | session_send_evt_to_thread (fp, rpc_args, thread_index, |
| 114 | SESSION_CTRL_EVT_RPC); |
| 115 | } |
| 116 | |
| 117 | void |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 118 | session_send_rpc_evt_to_thread (u32 thread_index, void *fp, void *rpc_args) |
| 119 | { |
| 120 | if (thread_index != vlib_get_thread_index ()) |
Nathan Skrzypczak | 60f3e65 | 2019-03-19 13:57:31 +0100 | [diff] [blame] | 121 | session_send_rpc_evt_to_thread_force (thread_index, fp, rpc_args); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 122 | else |
| 123 | { |
| 124 | void (*fnp) (void *) = fp; |
| 125 | fnp (rpc_args); |
| 126 | } |
| 127 | } |
| 128 | |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 129 | void |
| 130 | session_add_self_custom_tx_evt (transport_connection_t * tc, u8 has_prio) |
| 131 | { |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 132 | session_t *s = session_get (tc->s_index, tc->thread_index); |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 133 | |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 134 | ASSERT (s->thread_index == vlib_get_thread_index ()); |
Florin Coras | be237bf | 2019-09-27 08:16:40 -0700 | [diff] [blame] | 135 | ASSERT (s->session_state != SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 136 | |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 137 | if (!(s->flags & SESSION_F_CUSTOM_TX)) |
| 138 | { |
| 139 | s->flags |= SESSION_F_CUSTOM_TX; |
Florin Coras | 6080e0d | 2020-03-13 20:39:43 +0000 | [diff] [blame] | 140 | if (svm_fifo_set_event (s->tx_fifo) |
| 141 | || transport_connection_is_descheduled (tc)) |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 142 | { |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 143 | session_evt_elt_t *elt; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 144 | session_worker_t *wrk; |
| 145 | |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 146 | wrk = session_main_get_worker (tc->thread_index); |
| 147 | if (has_prio) |
| 148 | elt = session_evt_alloc_new (wrk); |
| 149 | else |
| 150 | elt = session_evt_alloc_old (wrk); |
| 151 | elt->evt.session_index = tc->s_index; |
| 152 | elt->evt.event_type = SESSION_IO_EVT_TX; |
Florin Coras | 6080e0d | 2020-03-13 20:39:43 +0000 | [diff] [blame] | 153 | tc->flags &= ~TRANSPORT_CONNECTION_F_DESCHED; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 154 | |
| 155 | if (PREDICT_FALSE (wrk->state == SESSION_WRK_INTERRUPT)) |
| 156 | vlib_node_set_interrupt_pending (wrk->vm, |
| 157 | session_queue_node.index); |
Florin Coras | 26dd6de | 2019-07-23 23:54:47 -0700 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 162 | void |
| 163 | sesssion_reschedule_tx (transport_connection_t * tc) |
| 164 | { |
| 165 | session_worker_t *wrk = session_main_get_worker (tc->thread_index); |
| 166 | session_evt_elt_t *elt; |
| 167 | |
| 168 | ASSERT (tc->thread_index == vlib_get_thread_index ()); |
| 169 | |
| 170 | elt = session_evt_alloc_new (wrk); |
| 171 | elt->evt.session_index = tc->s_index; |
| 172 | elt->evt.event_type = SESSION_IO_EVT_TX; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 173 | |
| 174 | if (PREDICT_FALSE (wrk->state == SESSION_WRK_INTERRUPT)) |
| 175 | vlib_node_set_interrupt_pending (wrk->vm, session_queue_node.index); |
Florin Coras | 70f879d | 2020-03-13 17:54:42 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 178 | static void |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 179 | session_program_transport_ctrl_evt (session_t * s, session_evt_type_t evt) |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 180 | { |
| 181 | u32 thread_index = vlib_get_thread_index (); |
Florin Coras | 2062ec0 | 2019-07-15 13:15:18 -0700 | [diff] [blame] | 182 | session_evt_elt_t *elt; |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 183 | session_worker_t *wrk; |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 184 | |
| 185 | /* If we are in the handler thread, or being called with the worker barrier |
| 186 | * held, just append a new event to pending disconnects vector. */ |
| 187 | if (vlib_thread_is_main_w_barrier () || thread_index == s->thread_index) |
| 188 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 189 | wrk = session_main_get_worker (s->thread_index); |
Florin Coras | b0ffbee | 2019-07-21 19:23:46 -0700 | [diff] [blame] | 190 | elt = session_evt_alloc_ctrl (wrk); |
Florin Coras | 2062ec0 | 2019-07-15 13:15:18 -0700 | [diff] [blame] | 191 | clib_memset (&elt->evt, 0, sizeof (session_event_t)); |
| 192 | elt->evt.session_handle = session_handle (s); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 193 | elt->evt.event_type = evt; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 194 | |
| 195 | if (PREDICT_FALSE (wrk->state == SESSION_WRK_INTERRUPT)) |
| 196 | vlib_node_set_interrupt_pending (wrk->vm, session_queue_node.index); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 197 | } |
| 198 | else |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 199 | session_send_ctrl_evt_to_thread (s, evt); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 202 | session_t * |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 203 | session_alloc (u32 thread_index) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 204 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 205 | session_worker_t *wrk = &session_main.wrk[thread_index]; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 206 | session_t *s; |
Damjan Marion | 66d4cb5 | 2022-03-17 18:59:46 +0100 | [diff] [blame] | 207 | |
Florin Coras | d3915dc | 2022-03-31 15:42:17 -0700 | [diff] [blame] | 208 | pool_get_aligned_safe (wrk->sessions, s, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 209 | clib_memset (s, 0, sizeof (*s)); |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 210 | s->session_index = s - wrk->sessions; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 211 | s->thread_index = thread_index; |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 212 | s->app_index = APP_INVALID_INDEX; |
Florin Coras | 6bd8d3f | 2022-03-14 21:17:25 -0700 | [diff] [blame] | 213 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 214 | return s; |
| 215 | } |
| 216 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 217 | void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 218 | session_free (session_t * s) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 219 | { |
Steven Luong | 20de85b | 2022-10-17 10:39:06 -0700 | [diff] [blame] | 220 | session_worker_t *wrk = &session_main.wrk[s->thread_index]; |
| 221 | |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 222 | SESSION_EVT (SESSION_EVT_FREE, s); |
Steven Luong | 20de85b | 2022-10-17 10:39:06 -0700 | [diff] [blame] | 223 | if (CLIB_DEBUG) |
| 224 | clib_memset (s, 0xFA, sizeof (*s)); |
| 225 | pool_put (wrk->sessions, s); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Srikanth Akula | e140d5d | 2019-11-18 11:49:58 -0800 | [diff] [blame] | 228 | u8 |
| 229 | session_is_valid (u32 si, u8 thread_index) |
| 230 | { |
| 231 | session_t *s; |
| 232 | transport_connection_t *tc; |
| 233 | |
| 234 | s = pool_elt_at_index (session_main.wrk[thread_index].sessions, si); |
| 235 | |
Srikanth Akula | e140d5d | 2019-11-18 11:49:58 -0800 | [diff] [blame] | 236 | if (s->thread_index != thread_index || s->session_index != si) |
| 237 | return 0; |
| 238 | |
| 239 | if (s->session_state == SESSION_STATE_TRANSPORT_DELETED |
| 240 | || s->session_state <= SESSION_STATE_LISTENING) |
| 241 | return 1; |
| 242 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 243 | if ((s->session_state == SESSION_STATE_CONNECTING || |
| 244 | s->session_state == SESSION_STATE_TRANSPORT_CLOSED) && |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 245 | (s->flags & SESSION_F_HALF_OPEN)) |
| 246 | return 1; |
| 247 | |
Srikanth Akula | e140d5d | 2019-11-18 11:49:58 -0800 | [diff] [blame] | 248 | tc = session_get_transport (s); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 249 | if (s->connection_index != tc->c_index || |
| 250 | s->thread_index != tc->thread_index || tc->s_index != si) |
Srikanth Akula | e140d5d | 2019-11-18 11:49:58 -0800 | [diff] [blame] | 251 | return 0; |
| 252 | |
| 253 | return 1; |
| 254 | } |
| 255 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 256 | void |
| 257 | session_cleanup (session_t *s) |
| 258 | { |
| 259 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 260 | session_free (s); |
| 261 | } |
| 262 | |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 263 | static void |
| 264 | session_cleanup_notify (session_t * s, session_cleanup_ntf_t ntf) |
| 265 | { |
| 266 | app_worker_t *app_wrk; |
| 267 | |
| 268 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 269 | if (!app_wrk) |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 270 | { |
| 271 | if (ntf == SESSION_CLEANUP_TRANSPORT) |
| 272 | return; |
| 273 | |
| 274 | session_cleanup (s); |
| 275 | return; |
| 276 | } |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 277 | app_worker_cleanup_notify (app_wrk, s, ntf); |
| 278 | } |
| 279 | |
Florin Coras | eb97e5f | 2018-10-15 21:35:42 -0700 | [diff] [blame] | 280 | void |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 281 | session_program_cleanup (session_t *s) |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 282 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 283 | ASSERT (s->session_state == SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 284 | session_cleanup_notify (s, SESSION_CLEANUP_SESSION); |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 287 | /** |
| 288 | * Cleans up session and lookup table. |
| 289 | * |
| 290 | * Transport connection must still be valid. |
| 291 | */ |
| 292 | static void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 293 | session_delete (session_t * s) |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 294 | { |
| 295 | int rv; |
| 296 | |
| 297 | /* Delete from the main lookup table. */ |
| 298 | if ((rv = session_lookup_del_session (s))) |
Florin Coras | d09236d | 2019-08-08 17:38:26 -0700 | [diff] [blame] | 299 | clib_warning ("session %u hash delete rv %d", s->session_index, rv); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 300 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 301 | session_program_cleanup (s); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 304 | void |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 305 | session_cleanup_half_open (session_handle_t ho_handle) |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 306 | { |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 307 | session_t *ho = session_get_from_handle (ho_handle); |
| 308 | |
| 309 | /* App transports can migrate their half-opens */ |
| 310 | if (ho->flags & SESSION_F_IS_MIGRATING) |
| 311 | { |
| 312 | /* Session still migrating, move to closed state to signal that the |
| 313 | * session should be removed. */ |
| 314 | if (ho->connection_index == ~0) |
| 315 | { |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 316 | session_set_state (ho, SESSION_STATE_CLOSED); |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 317 | return; |
| 318 | } |
| 319 | /* Migrated transports are no longer half-opens */ |
| 320 | transport_cleanup (session_get_transport_proto (ho), |
| 321 | ho->connection_index, ho->app_index /* overloaded */); |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 322 | } |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 323 | else if (ho->session_state != SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 324 | { |
| 325 | /* Cleanup half-open session lookup table if need be */ |
Florin Coras | 4aeba37 | 2023-06-20 16:50:51 -0700 | [diff] [blame] | 326 | if (ho->session_state != SESSION_STATE_TRANSPORT_CLOSED) |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 327 | { |
| 328 | transport_connection_t *tc; |
| 329 | tc = transport_get_half_open (session_get_transport_proto (ho), |
| 330 | ho->connection_index); |
| 331 | if (tc && !(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP)) |
| 332 | session_lookup_del_half_open (tc); |
| 333 | } |
| 334 | transport_cleanup_half_open (session_get_transport_proto (ho), |
| 335 | ho->connection_index); |
| 336 | } |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 337 | session_free (ho); |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 341 | session_half_open_free (session_t *ho) |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 342 | { |
| 343 | app_worker_t *app_wrk; |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 344 | |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 345 | ASSERT (vlib_get_thread_index () <= transport_cl_thread ()); |
| 346 | app_wrk = app_worker_get_if_valid (ho->app_wrk_index); |
| 347 | if (app_wrk) |
| 348 | app_worker_del_half_open (app_wrk, ho); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 349 | else |
| 350 | session_free (ho); |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | static void |
| 354 | session_half_open_free_rpc (void *args) |
| 355 | { |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 356 | session_t *ho = ho_session_get (pointer_to_uword (args)); |
| 357 | session_half_open_free (ho); |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | void |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 361 | session_half_open_delete_notify (transport_connection_t *tc) |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 362 | { |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 363 | session_t *ho = ho_session_get (tc->s_index); |
| 364 | |
| 365 | /* Cleanup half-open lookup table if need be */ |
Florin Coras | 4aeba37 | 2023-06-20 16:50:51 -0700 | [diff] [blame] | 366 | if (ho->session_state != SESSION_STATE_TRANSPORT_CLOSED) |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 367 | { |
| 368 | if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP)) |
| 369 | session_lookup_del_half_open (tc); |
| 370 | } |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 371 | session_set_state (ho, SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 372 | |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 373 | /* Notification from ctrl thread accepted without rpc */ |
Florin Coras | 309f7aa | 2022-03-18 08:33:08 -0700 | [diff] [blame] | 374 | if (tc->thread_index == transport_cl_thread ()) |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 375 | { |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 376 | session_half_open_free (ho); |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 377 | } |
| 378 | else |
| 379 | { |
| 380 | void *args = uword_to_pointer ((uword) tc->s_index, void *); |
Florin Coras | 309f7aa | 2022-03-18 08:33:08 -0700 | [diff] [blame] | 381 | session_send_rpc_evt_to_thread_force (transport_cl_thread (), |
| 382 | session_half_open_free_rpc, args); |
Florin Coras | 374df7a | 2021-05-13 11:37:43 -0700 | [diff] [blame] | 383 | } |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 384 | } |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 385 | |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 386 | void |
| 387 | session_half_open_migrate_notify (transport_connection_t *tc) |
| 388 | { |
| 389 | session_t *ho; |
| 390 | |
Florin Coras | c9fb987 | 2023-03-19 22:03:57 -0700 | [diff] [blame] | 391 | /* Support half-open migrations only for transports with no lookup */ |
| 392 | ASSERT (tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP); |
| 393 | |
Florin Coras | bab6c52 | 2021-05-13 08:36:56 -0700 | [diff] [blame] | 394 | ho = ho_session_get (tc->s_index); |
| 395 | ho->flags |= SESSION_F_IS_MIGRATING; |
| 396 | ho->connection_index = ~0; |
| 397 | } |
| 398 | |
| 399 | int |
| 400 | session_half_open_migrated_notify (transport_connection_t *tc) |
| 401 | { |
| 402 | session_t *ho; |
| 403 | |
| 404 | ho = ho_session_get (tc->s_index); |
| 405 | |
| 406 | /* App probably detached so the half-open must be cleaned up */ |
| 407 | if (ho->session_state == SESSION_STATE_CLOSED) |
| 408 | { |
| 409 | session_half_open_delete_notify (tc); |
| 410 | return -1; |
| 411 | } |
| 412 | ho->connection_index = tc->c_index; |
| 413 | /* Overload app index for half-open with new thread */ |
| 414 | ho->app_index = tc->thread_index; |
| 415 | return 0; |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Andreas Schultz | 1a8c437 | 2020-03-20 09:39:59 +0100 | [diff] [blame] | 418 | session_t * |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 419 | session_alloc_for_connection (transport_connection_t * tc) |
| 420 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 421 | session_t *s; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 422 | u32 thread_index = tc->thread_index; |
| 423 | |
Florin Coras | 40903ac | 2018-06-10 14:41:23 -0700 | [diff] [blame] | 424 | ASSERT (thread_index == vlib_get_thread_index () |
| 425 | || transport_protocol_is_cl (tc->proto)); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 426 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 427 | s = session_alloc (thread_index); |
| 428 | s->session_type = session_type_from_proto_and_ip (tc->proto, tc->is_ip4); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 429 | session_set_state (s, SESSION_STATE_CLOSED); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 430 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 431 | /* Attach transport to session and vice versa */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 432 | s->connection_index = tc->c_index; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 433 | tc->s_index = s->session_index; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 434 | return s; |
| 435 | } |
| 436 | |
Florin Coras | 2c876f9 | 2021-05-10 21:12:27 -0700 | [diff] [blame] | 437 | session_t * |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 438 | session_alloc_for_half_open (transport_connection_t *tc) |
| 439 | { |
| 440 | session_t *s; |
| 441 | |
| 442 | s = ho_session_alloc (); |
| 443 | s->session_type = session_type_from_proto_and_ip (tc->proto, tc->is_ip4); |
| 444 | s->connection_index = tc->c_index; |
| 445 | tc->s_index = s->session_index; |
| 446 | return s; |
| 447 | } |
| 448 | |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 449 | /** |
| 450 | * Discards bytes from buffer chain |
| 451 | * |
| 452 | * It discards n_bytes_to_drop starting at first buffer after chain_b |
| 453 | */ |
| 454 | always_inline void |
| 455 | session_enqueue_discard_chain_bytes (vlib_main_t * vm, vlib_buffer_t * b, |
| 456 | vlib_buffer_t ** chain_b, |
| 457 | u32 n_bytes_to_drop) |
| 458 | { |
| 459 | vlib_buffer_t *next = *chain_b; |
| 460 | u32 to_drop = n_bytes_to_drop; |
| 461 | ASSERT (b->flags & VLIB_BUFFER_NEXT_PRESENT); |
| 462 | while (to_drop && (next->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 463 | { |
| 464 | next = vlib_get_buffer (vm, next->next_buffer); |
| 465 | if (next->current_length > to_drop) |
| 466 | { |
| 467 | vlib_buffer_advance (next, to_drop); |
| 468 | to_drop = 0; |
| 469 | } |
| 470 | else |
| 471 | { |
| 472 | to_drop -= next->current_length; |
| 473 | next->current_length = 0; |
| 474 | } |
| 475 | } |
| 476 | *chain_b = next; |
| 477 | |
| 478 | if (to_drop == 0) |
| 479 | b->total_length_not_including_first_buffer -= n_bytes_to_drop; |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Enqueue buffer chain tail |
| 484 | */ |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 485 | always_inline int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 486 | session_enqueue_chain_tail (session_t * s, vlib_buffer_t * b, |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 487 | u32 offset, u8 is_in_order) |
| 488 | { |
| 489 | vlib_buffer_t *chain_b; |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 490 | u32 chain_bi, len, diff; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 491 | vlib_main_t *vm = vlib_get_main (); |
Florin Coras | b2215d6 | 2017-08-01 16:56:58 -0700 | [diff] [blame] | 492 | u8 *data; |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 493 | u32 written = 0; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 494 | int rv = 0; |
| 495 | |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 496 | if (is_in_order && offset) |
| 497 | { |
| 498 | diff = offset - b->current_length; |
| 499 | if (diff > b->total_length_not_including_first_buffer) |
| 500 | return 0; |
| 501 | chain_b = b; |
| 502 | session_enqueue_discard_chain_bytes (vm, b, &chain_b, diff); |
| 503 | chain_bi = vlib_get_buffer_index (vm, chain_b); |
| 504 | } |
| 505 | else |
| 506 | chain_bi = b->next_buffer; |
| 507 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 508 | do |
| 509 | { |
| 510 | chain_b = vlib_get_buffer (vm, chain_bi); |
| 511 | data = vlib_buffer_get_current (chain_b); |
| 512 | len = chain_b->current_length; |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 513 | if (!len) |
| 514 | continue; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 515 | if (is_in_order) |
| 516 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 517 | rv = svm_fifo_enqueue (s->rx_fifo, len, data); |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 518 | if (rv == len) |
| 519 | { |
| 520 | written += rv; |
| 521 | } |
| 522 | else if (rv < len) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 523 | { |
| 524 | return (rv > 0) ? (written + rv) : written; |
| 525 | } |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 526 | else if (rv > len) |
| 527 | { |
| 528 | written += rv; |
| 529 | |
| 530 | /* written more than what was left in chain */ |
| 531 | if (written > b->total_length_not_including_first_buffer) |
| 532 | return written; |
| 533 | |
| 534 | /* drop the bytes that have already been delivered */ |
| 535 | session_enqueue_discard_chain_bytes (vm, b, &chain_b, rv - len); |
| 536 | } |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 540 | rv = svm_fifo_enqueue_with_offset (s->rx_fifo, offset, len, data); |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 541 | if (rv) |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 542 | { |
| 543 | clib_warning ("failed to enqueue multi-buffer seg"); |
| 544 | return -1; |
| 545 | } |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 546 | offset += len; |
| 547 | } |
| 548 | } |
| 549 | while ((chain_bi = (chain_b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 550 | ? chain_b->next_buffer : 0)); |
| 551 | |
| 552 | if (is_in_order) |
| 553 | return written; |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 558 | void |
| 559 | session_fifo_tuning (session_t * s, svm_fifo_t * f, |
| 560 | session_ft_action_t act, u32 len) |
| 561 | { |
| 562 | if (s->flags & SESSION_F_CUSTOM_FIFO_TUNING) |
| 563 | { |
| 564 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
| 565 | app_worker_session_fifo_tuning (app_wrk, s, f, act, len); |
| 566 | if (CLIB_ASSERT_ENABLE) |
| 567 | { |
| 568 | segment_manager_t *sm; |
| 569 | sm = segment_manager_get (f->segment_manager); |
Florin Coras | c547e91 | 2020-12-08 17:50:45 -0800 | [diff] [blame] | 570 | ASSERT (f->shr->size >= 4096); |
| 571 | ASSERT (f->shr->size <= sm->max_fifo_size); |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 576 | void |
| 577 | session_wrk_program_app_wrk_evts (session_worker_t *wrk, u32 app_wrk_index) |
| 578 | { |
| 579 | u8 need_interrupt; |
| 580 | |
| 581 | ASSERT ((wrk - session_main.wrk) == vlib_get_thread_index ()); |
| 582 | need_interrupt = clib_bitmap_is_zero (wrk->app_wrks_pending_ntf); |
| 583 | wrk->app_wrks_pending_ntf = |
| 584 | clib_bitmap_set (wrk->app_wrks_pending_ntf, app_wrk_index, 1); |
| 585 | |
| 586 | if (need_interrupt) |
| 587 | vlib_node_set_interrupt_pending (wrk->vm, session_input_node.index); |
| 588 | } |
| 589 | |
| 590 | always_inline void |
| 591 | session_program_io_event (app_worker_t *app_wrk, session_t *s, |
| 592 | session_evt_type_t et, u8 is_cl) |
| 593 | { |
| 594 | if (is_cl) |
| 595 | { |
| 596 | /* Special events for connectionless sessions */ |
| 597 | et += SESSION_IO_EVT_BUILTIN_RX - SESSION_IO_EVT_RX; |
| 598 | |
Florin Coras | fa9f37c | 2023-10-10 10:21:01 -0700 | [diff] [blame] | 599 | ASSERT (s->thread_index == 0 || et == SESSION_IO_EVT_TX_MAIN); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 600 | session_event_t evt = { |
| 601 | .event_type = et, |
| 602 | .session_handle = session_handle (s), |
| 603 | }; |
| 604 | |
| 605 | app_worker_add_event_custom (app_wrk, vlib_get_thread_index (), &evt); |
| 606 | } |
| 607 | else |
| 608 | { |
| 609 | app_worker_add_event (app_wrk, s, et); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | static inline int |
| 614 | session_notify_subscribers (u32 app_index, session_t *s, svm_fifo_t *f, |
| 615 | session_evt_type_t evt_type) |
| 616 | { |
| 617 | app_worker_t *app_wrk; |
| 618 | application_t *app; |
| 619 | u8 is_cl; |
| 620 | int i; |
| 621 | |
| 622 | app = application_get (app_index); |
| 623 | if (!app) |
| 624 | return -1; |
| 625 | |
| 626 | is_cl = s->thread_index != vlib_get_thread_index (); |
| 627 | for (i = 0; i < f->shr->n_subscribers; i++) |
| 628 | { |
| 629 | app_wrk = application_get_worker (app, f->shr->subscribers[i]); |
| 630 | if (!app_wrk) |
| 631 | continue; |
| 632 | session_program_io_event (app_wrk, s, evt_type, is_cl ? 1 : 0); |
| 633 | } |
| 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | always_inline int |
| 639 | session_enqueue_notify_inline (session_t *s, u8 is_cl) |
| 640 | { |
| 641 | app_worker_t *app_wrk; |
| 642 | |
| 643 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 644 | if (PREDICT_FALSE (!app_wrk)) |
| 645 | return -1; |
| 646 | |
| 647 | session_program_io_event (app_wrk, s, SESSION_IO_EVT_RX, is_cl); |
| 648 | |
| 649 | if (PREDICT_FALSE (svm_fifo_n_subscribers (s->rx_fifo))) |
| 650 | return session_notify_subscribers (app_wrk->app_index, s, s->rx_fifo, |
| 651 | SESSION_IO_EVT_RX); |
| 652 | |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | int |
| 657 | session_enqueue_notify (session_t *s) |
| 658 | { |
| 659 | return session_enqueue_notify_inline (s, 0 /* is_cl */); |
| 660 | } |
| 661 | |
| 662 | int |
| 663 | session_enqueue_notify_cl (session_t *s) |
| 664 | { |
| 665 | return session_enqueue_notify_inline (s, 1 /* is_cl */); |
| 666 | } |
| 667 | |
| 668 | int |
| 669 | session_dequeue_notify (session_t *s) |
| 670 | { |
| 671 | app_worker_t *app_wrk; |
| 672 | u8 is_cl; |
| 673 | |
| 674 | /* Unset as soon as event is requested */ |
| 675 | svm_fifo_clear_deq_ntf (s->tx_fifo); |
| 676 | |
| 677 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 678 | if (PREDICT_FALSE (!app_wrk)) |
| 679 | return -1; |
| 680 | |
| 681 | is_cl = s->session_state == SESSION_STATE_LISTENING || |
| 682 | s->session_state == SESSION_STATE_OPENED; |
| 683 | session_program_io_event (app_wrk, s, SESSION_IO_EVT_TX, is_cl ? 1 : 0); |
| 684 | |
| 685 | if (PREDICT_FALSE (svm_fifo_n_subscribers (s->tx_fifo))) |
| 686 | return session_notify_subscribers (app_wrk->app_index, s, s->tx_fifo, |
| 687 | SESSION_IO_EVT_TX); |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * Flushes queue of sessions that are to be notified of new data |
| 694 | * enqueued events. |
| 695 | * |
| 696 | * @param transport_proto transport protocol for which queue to be flushed |
| 697 | * @param thread_index Thread index for which the flush is to be performed. |
| 698 | * @return 0 on success or a positive number indicating the number of |
| 699 | * failures due to API queue being full. |
| 700 | */ |
| 701 | void |
| 702 | session_main_flush_enqueue_events (transport_proto_t transport_proto, |
| 703 | u32 thread_index) |
| 704 | { |
| 705 | session_worker_t *wrk = session_main_get_worker (thread_index); |
| 706 | session_handle_t *handles; |
| 707 | session_t *s; |
Florin Coras | 44d9cbc | 2023-12-21 13:50:53 -0800 | [diff] [blame] | 708 | u32 i, is_cl; |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 709 | |
| 710 | handles = wrk->session_to_enqueue[transport_proto]; |
| 711 | |
| 712 | for (i = 0; i < vec_len (handles); i++) |
| 713 | { |
| 714 | s = session_get_from_handle (handles[i]); |
| 715 | session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED, |
| 716 | 0 /* TODO/not needed */); |
Florin Coras | 44d9cbc | 2023-12-21 13:50:53 -0800 | [diff] [blame] | 717 | is_cl = |
| 718 | s->thread_index != thread_index || (s->flags & SESSION_F_IS_CLESS); |
| 719 | if (!is_cl) |
| 720 | session_enqueue_notify_inline (s, 0); |
| 721 | else |
| 722 | session_enqueue_notify_inline (s, 1); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | vec_reset_length (handles); |
| 726 | wrk->session_to_enqueue[transport_proto] = handles; |
| 727 | } |
| 728 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 729 | /* |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 730 | * Enqueue data for delivery to app. If requested, it queues app notification |
| 731 | * event for later delivery. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 732 | * |
| 733 | * @param tc Transport connection which is to be enqueued data |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 734 | * @param b Buffer to be enqueued |
| 735 | * @param offset Offset at which to start enqueueing if out-of-order |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 736 | * @param queue_event Flag to indicate if peer is to be notified or if event |
| 737 | * is to be queued. The former is useful when more data is |
| 738 | * enqueued and only one event is to be generated. |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 739 | * @param is_in_order Flag to indicate if data is in order |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 740 | * @return Number of bytes enqueued or a negative value if enqueueing failed. |
| 741 | */ |
| 742 | int |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 743 | session_enqueue_stream_connection (transport_connection_t * tc, |
| 744 | vlib_buffer_t * b, u32 offset, |
| 745 | u8 queue_event, u8 is_in_order) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 746 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 747 | session_t *s; |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 748 | int enqueued = 0, rv, in_order_off; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 749 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 750 | s = session_get (tc->s_index, tc->thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 751 | |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 752 | if (is_in_order) |
| 753 | { |
Florin Coras | 87b15ce | 2019-04-28 21:16:30 -0700 | [diff] [blame] | 754 | enqueued = svm_fifo_enqueue (s->rx_fifo, |
| 755 | b->current_length, |
| 756 | vlib_buffer_get_current (b)); |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 757 | if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) |
| 758 | && enqueued >= 0)) |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 759 | { |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 760 | in_order_off = enqueued > b->current_length ? enqueued : 0; |
| 761 | rv = session_enqueue_chain_tail (s, b, in_order_off, 1); |
| 762 | if (rv > 0) |
| 763 | enqueued += rv; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | else |
| 767 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 768 | rv = svm_fifo_enqueue_with_offset (s->rx_fifo, offset, |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 769 | b->current_length, |
| 770 | vlib_buffer_get_current (b)); |
| 771 | if (PREDICT_FALSE ((b->flags & VLIB_BUFFER_NEXT_PRESENT) && !rv)) |
Florin Coras | 1f152cd | 2017-08-18 19:28:03 -0700 | [diff] [blame] | 772 | session_enqueue_chain_tail (s, b, offset + b->current_length, 0); |
| 773 | /* if something was enqueued, report even this as success for ooo |
| 774 | * segment handling */ |
| 775 | return rv; |
Florin Coras | f6d68ed | 2017-05-07 19:12:02 -0700 | [diff] [blame] | 776 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 777 | |
| 778 | if (queue_event) |
| 779 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 780 | /* Queue RX event on this fifo. Eventually these will need to be |
| 781 | * flushed by calling @ref session_main_flush_enqueue_events () */ |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 782 | if (!(s->flags & SESSION_F_RX_EVT)) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 783 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 784 | session_worker_t *wrk = session_main_get_worker (s->thread_index); |
| 785 | ASSERT (s->thread_index == vlib_get_thread_index ()); |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 786 | s->flags |= SESSION_F_RX_EVT; |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 787 | vec_add1 (wrk->session_to_enqueue[tc->proto], session_handle (s)); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 788 | } |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 789 | |
| 790 | session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED, 0); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 791 | } |
| 792 | |
Chris Luke | b2bcad6 | 2017-09-18 08:51:22 -0400 | [diff] [blame] | 793 | return enqueued; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 794 | } |
| 795 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 796 | always_inline int |
| 797 | session_enqueue_dgram_connection_inline (session_t *s, |
| 798 | session_dgram_hdr_t *hdr, |
| 799 | vlib_buffer_t *b, u8 proto, |
| 800 | u8 queue_event, u32 is_cl) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 801 | { |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 802 | int rv; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 803 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 804 | ASSERT (svm_fifo_max_enqueue_prod (s->rx_fifo) |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 805 | >= b->current_length + sizeof (*hdr)); |
| 806 | |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 807 | if (PREDICT_TRUE (!(b->flags & VLIB_BUFFER_NEXT_PRESENT))) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 808 | { |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 809 | svm_fifo_seg_t segs[2] = { |
| 810 | { (u8 *) hdr, sizeof (*hdr) }, |
| 811 | { vlib_buffer_get_current (b), b->current_length } |
| 812 | }; |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 813 | |
| 814 | rv = svm_fifo_enqueue_segments (s->rx_fifo, segs, 2, |
| 815 | 0 /* allow_partial */ ); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 816 | } |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 817 | else |
| 818 | { |
| 819 | vlib_main_t *vm = vlib_get_main (); |
| 820 | svm_fifo_seg_t *segs = 0, *seg; |
| 821 | vlib_buffer_t *it = b; |
| 822 | u32 n_segs = 1; |
| 823 | |
| 824 | vec_add2 (segs, seg, 1); |
| 825 | seg->data = (u8 *) hdr; |
| 826 | seg->len = sizeof (*hdr); |
| 827 | while (it) |
| 828 | { |
| 829 | vec_add2 (segs, seg, 1); |
| 830 | seg->data = vlib_buffer_get_current (it); |
| 831 | seg->len = it->current_length; |
| 832 | n_segs++; |
| 833 | if (!(it->flags & VLIB_BUFFER_NEXT_PRESENT)) |
| 834 | break; |
| 835 | it = vlib_get_buffer (vm, it->next_buffer); |
| 836 | } |
| 837 | rv = svm_fifo_enqueue_segments (s->rx_fifo, segs, n_segs, |
| 838 | 0 /* allow partial */ ); |
| 839 | vec_free (segs); |
| 840 | } |
| 841 | |
| 842 | if (queue_event && rv > 0) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 843 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 844 | /* Queue RX event on this fifo. Eventually these will need to be |
| 845 | * flushed by calling @ref session_main_flush_enqueue_events () */ |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 846 | if (!(s->flags & SESSION_F_RX_EVT)) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 847 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 848 | u32 thread_index = |
| 849 | is_cl ? vlib_get_thread_index () : s->thread_index; |
| 850 | session_worker_t *wrk = session_main_get_worker (thread_index); |
| 851 | ASSERT (s->thread_index == vlib_get_thread_index () || is_cl); |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 852 | s->flags |= SESSION_F_RX_EVT; |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 853 | vec_add1 (wrk->session_to_enqueue[proto], session_handle (s)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 854 | } |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 855 | |
| 856 | session_fifo_tuning (s, s->rx_fifo, SESSION_FT_ACTION_ENQUEUED, 0); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 857 | } |
Florin Coras | c95cfa2 | 2020-11-24 08:41:17 -0800 | [diff] [blame] | 858 | return rv > 0 ? rv : 0; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 859 | } |
| 860 | |
Florin Coras | 93992a9 | 2017-05-24 18:03:56 -0700 | [diff] [blame] | 861 | int |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 862 | session_enqueue_dgram_connection (session_t *s, session_dgram_hdr_t *hdr, |
| 863 | vlib_buffer_t *b, u8 proto, u8 queue_event) |
| 864 | { |
| 865 | return session_enqueue_dgram_connection_inline (s, hdr, b, proto, |
| 866 | queue_event, 0 /* is_cl */); |
| 867 | } |
| 868 | |
| 869 | int |
| 870 | session_enqueue_dgram_connection_cl (session_t *s, session_dgram_hdr_t *hdr, |
| 871 | vlib_buffer_t *b, u8 proto, |
| 872 | u8 queue_event) |
| 873 | { |
| 874 | return session_enqueue_dgram_connection_inline (s, hdr, b, proto, |
| 875 | queue_event, 1 /* is_cl */); |
| 876 | } |
| 877 | |
| 878 | int |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 879 | session_tx_fifo_peek_bytes (transport_connection_t * tc, u8 * buffer, |
| 880 | u32 offset, u32 max_bytes) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 881 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 882 | session_t *s = session_get (tc->s_index, tc->thread_index); |
| 883 | return svm_fifo_peek (s->tx_fifo, offset, max_bytes, buffer); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | u32 |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 887 | session_tx_fifo_dequeue_drop (transport_connection_t * tc, u32 max_bytes) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 888 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 889 | session_t *s = session_get (tc->s_index, tc->thread_index); |
Vladimir Kropylev | f867cf1 | 2019-06-17 21:38:00 +0300 | [diff] [blame] | 890 | u32 rv; |
| 891 | |
| 892 | rv = svm_fifo_dequeue_drop (s->tx_fifo, max_bytes); |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 893 | session_fifo_tuning (s, s->tx_fifo, SESSION_FT_ACTION_DEQUEUED, rv); |
Florin Coras | 0e573f5 | 2019-05-07 16:28:16 -0700 | [diff] [blame] | 894 | |
Florin Coras | 2d379d8 | 2019-06-28 12:45:12 -0700 | [diff] [blame] | 895 | if (svm_fifo_needs_deq_ntf (s->tx_fifo, max_bytes)) |
Florin Coras | 0e573f5 | 2019-05-07 16:28:16 -0700 | [diff] [blame] | 896 | session_dequeue_notify (s); |
| 897 | |
Vladimir Kropylev | f867cf1 | 2019-06-17 21:38:00 +0300 | [diff] [blame] | 898 | return rv; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 899 | } |
| 900 | |
Florin Coras | 4fde4ae | 2020-04-13 16:48:04 +0000 | [diff] [blame] | 901 | int |
| 902 | session_stream_connect_notify (transport_connection_t * tc, |
| 903 | session_error_t err) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 904 | { |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 905 | u32 opaque = 0, new_ti, new_si; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 906 | app_worker_t *app_wrk; |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 907 | session_t *s = 0, *ho; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 908 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 909 | /* |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 910 | * Cleanup half-open table |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 911 | */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 912 | session_lookup_del_half_open (tc); |
Florin Coras | 4eeeaaf | 2017-09-05 14:03:37 -0400 | [diff] [blame] | 913 | |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 914 | ho = ho_session_get (tc->s_index); |
Florin Coras | 4aeba37 | 2023-06-20 16:50:51 -0700 | [diff] [blame] | 915 | session_set_state (ho, SESSION_STATE_TRANSPORT_CLOSED); |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 916 | opaque = ho->opaque; |
| 917 | app_wrk = app_worker_get_if_valid (ho->app_wrk_index); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 918 | if (!app_wrk) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 919 | return -1; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 920 | |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 921 | if (err) |
| 922 | return app_worker_connect_notify (app_wrk, s, err, opaque); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 923 | |
| 924 | s = session_alloc_for_connection (tc); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 925 | session_set_state (s, SESSION_STATE_CONNECTING); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 926 | s->app_wrk_index = app_wrk->wrk_index; |
Florin Coras | 2ceb818 | 2023-08-31 17:33:47 -0700 | [diff] [blame] | 927 | s->opaque = opaque; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 928 | new_si = s->session_index; |
| 929 | new_ti = s->thread_index; |
| 930 | |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 931 | if ((err = app_worker_init_connected (app_wrk, s))) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 932 | { |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 933 | session_free (s); |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 934 | app_worker_connect_notify (app_wrk, 0, err, opaque); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 935 | return -1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 936 | } |
| 937 | |
Nathan Skrzypczak | a26349d | 2019-06-26 13:53:08 +0200 | [diff] [blame] | 938 | s = session_get (new_si, new_ti); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 939 | session_set_state (s, SESSION_STATE_READY); |
Nathan Skrzypczak | a26349d | 2019-06-26 13:53:08 +0200 | [diff] [blame] | 940 | session_lookup_add_connection (tc, session_handle (s)); |
| 941 | |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 942 | if (app_worker_connect_notify (app_wrk, s, SESSION_E_NONE, opaque)) |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 943 | { |
Florin Coras | c7fd24e | 2020-07-24 10:09:07 -0700 | [diff] [blame] | 944 | session_lookup_del_connection (tc); |
| 945 | /* Avoid notifying app about rejected session cleanup */ |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 946 | s = session_get (new_si, new_ti); |
Florin Coras | c7fd24e | 2020-07-24 10:09:07 -0700 | [diff] [blame] | 947 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 948 | session_free (s); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 949 | return -1; |
Florin Coras | 6534b7a | 2017-07-18 05:38:03 -0400 | [diff] [blame] | 950 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 951 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 952 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 953 | } |
| 954 | |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 955 | static void |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 956 | session_switch_pool_closed_rpc (void *arg) |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 957 | { |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 958 | session_handle_t sh; |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 959 | session_t *s; |
| 960 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 961 | sh = pointer_to_uword (arg); |
| 962 | s = session_get_from_handle_if_valid (sh); |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 963 | if (!s) |
| 964 | return; |
| 965 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 966 | transport_cleanup (session_get_transport_proto (s), s->connection_index, |
| 967 | s->thread_index); |
| 968 | session_cleanup (s); |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 969 | } |
| 970 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 971 | typedef struct _session_switch_pool_args |
| 972 | { |
| 973 | u32 session_index; |
| 974 | u32 thread_index; |
| 975 | u32 new_thread_index; |
| 976 | u32 new_session_index; |
| 977 | } session_switch_pool_args_t; |
| 978 | |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 979 | /** |
| 980 | * Notify old thread of the session pool switch |
| 981 | */ |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 982 | static void |
| 983 | session_switch_pool (void *cb_args) |
| 984 | { |
| 985 | session_switch_pool_args_t *args = (session_switch_pool_args_t *) cb_args; |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 986 | session_handle_t sh, new_sh; |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 987 | segment_manager_t *sm; |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 988 | app_worker_t *app_wrk; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 989 | session_t *s; |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 990 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 991 | ASSERT (args->thread_index == vlib_get_thread_index ()); |
| 992 | s = session_get (args->session_index, args->thread_index); |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 993 | |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 994 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 995 | if (!app_wrk) |
| 996 | goto app_closed; |
Aloys Augustin | b339233 | 2019-08-06 16:09:01 +0200 | [diff] [blame] | 997 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 998 | /* Cleanup fifo segment slice state for fifos */ |
| 999 | sm = app_worker_get_connect_segment_manager (app_wrk); |
| 1000 | segment_manager_detach_fifo (sm, &s->rx_fifo); |
| 1001 | segment_manager_detach_fifo (sm, &s->tx_fifo); |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 1002 | |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1003 | /* Check if session closed during migration */ |
| 1004 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING) |
| 1005 | goto app_closed; |
| 1006 | |
| 1007 | new_sh = |
| 1008 | session_make_handle (args->new_session_index, args->new_thread_index); |
| 1009 | app_worker_migrate_notify (app_wrk, s, new_sh); |
| 1010 | |
| 1011 | clib_mem_free (cb_args); |
| 1012 | return; |
| 1013 | |
| 1014 | app_closed: |
| 1015 | /* Session closed during migration. Clean everything up */ |
| 1016 | sh = session_handle (s); |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 1017 | session_send_rpc_evt_to_thread (args->new_thread_index, |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1018 | session_switch_pool_closed_rpc, |
| 1019 | uword_to_pointer (sh, void *)); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1020 | clib_mem_free (cb_args); |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Move dgram session to the right thread |
| 1025 | */ |
| 1026 | int |
| 1027 | session_dgram_connect_notify (transport_connection_t * tc, |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1028 | u32 old_thread_index, session_t ** new_session) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1029 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1030 | session_t *new_s; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1031 | session_switch_pool_args_t *rpc_args; |
Florin Coras | 0bc78d8 | 2021-01-09 14:34:01 -0800 | [diff] [blame] | 1032 | segment_manager_t *sm; |
| 1033 | app_worker_t *app_wrk; |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1034 | |
| 1035 | /* |
| 1036 | * Clone half-open session to the right thread. |
| 1037 | */ |
| 1038 | new_s = session_clone_safe (tc->s_index, old_thread_index); |
| 1039 | new_s->connection_index = tc->c_index; |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1040 | session_set_state (new_s, SESSION_STATE_READY); |
Nathan Skrzypczak | caa7acf | 2019-10-02 10:02:05 +0200 | [diff] [blame] | 1041 | new_s->flags |= SESSION_F_IS_MIGRATING; |
Florin Coras | 6d7552c | 2020-04-09 01:49:45 +0000 | [diff] [blame] | 1042 | |
Florin Coras | 0bc78d8 | 2021-01-09 14:34:01 -0800 | [diff] [blame] | 1043 | if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP)) |
| 1044 | session_lookup_add_connection (tc, session_handle (new_s)); |
| 1045 | |
| 1046 | app_wrk = app_worker_get_if_valid (new_s->app_wrk_index); |
| 1047 | if (app_wrk) |
| 1048 | { |
| 1049 | /* New set of fifos attached to the same shared memory */ |
| 1050 | sm = app_worker_get_connect_segment_manager (app_wrk); |
| 1051 | segment_manager_attach_fifo (sm, &new_s->rx_fifo, new_s); |
| 1052 | segment_manager_attach_fifo (sm, &new_s->tx_fifo, new_s); |
| 1053 | } |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* |
| 1056 | * Ask thread owning the old session to clean it up and make us the tx |
| 1057 | * fifo owner |
| 1058 | */ |
| 1059 | rpc_args = clib_mem_alloc (sizeof (*rpc_args)); |
| 1060 | rpc_args->new_session_index = new_s->session_index; |
| 1061 | rpc_args->new_thread_index = new_s->thread_index; |
| 1062 | rpc_args->session_index = tc->s_index; |
| 1063 | rpc_args->thread_index = old_thread_index; |
| 1064 | session_send_rpc_evt_to_thread (rpc_args->thread_index, session_switch_pool, |
| 1065 | rpc_args); |
| 1066 | |
| 1067 | tc->s_index = new_s->session_index; |
| 1068 | new_s->connection_index = tc->c_index; |
| 1069 | *new_session = new_s; |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1073 | /** |
| 1074 | * Notification from transport that connection is being closed. |
| 1075 | * |
| 1076 | * A disconnect is sent to application but state is not removed. Once |
| 1077 | * disconnect is acknowledged by application, session disconnect is called. |
| 1078 | * Ultimately this leads to close being called on transport (passive close). |
| 1079 | */ |
| 1080 | void |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1081 | session_transport_closing_notify (transport_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1082 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1083 | app_worker_t *app_wrk; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1084 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1085 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1086 | s = session_get (tc->s_index, tc->thread_index); |
Florin Coras | 400ded3 | 2018-10-03 01:00:57 -0700 | [diff] [blame] | 1087 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING) |
| 1088 | return; |
Florin Coras | dfd27bc | 2021-11-27 10:45:55 -0800 | [diff] [blame] | 1089 | |
| 1090 | /* Wait for reply from app before sending notification as the |
| 1091 | * accept might be rejected */ |
| 1092 | if (s->session_state == SESSION_STATE_ACCEPTING) |
| 1093 | { |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1094 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSING); |
Florin Coras | dfd27bc | 2021-11-27 10:45:55 -0800 | [diff] [blame] | 1095 | return; |
| 1096 | } |
| 1097 | |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1098 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSING); |
Florin Coras | bf7ce2c | 2019-03-06 14:44:42 -0800 | [diff] [blame] | 1099 | app_wrk = app_worker_get (s->app_wrk_index); |
| 1100 | app_worker_close_notify (app_wrk, s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1104 | * Notification from transport that connection is being deleted |
| 1105 | * |
Florin Coras | 4eeeaaf | 2017-09-05 14:03:37 -0400 | [diff] [blame] | 1106 | * This removes the session if it is still valid. It should be called only on |
| 1107 | * previously fully established sessions. For instance failed connects should |
| 1108 | * call stream_session_connect_notify and indicate that the connect has |
| 1109 | * failed. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1110 | */ |
| 1111 | void |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1112 | session_transport_delete_notify (transport_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1113 | { |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1114 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1115 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1116 | /* App might've been removed already */ |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1117 | if (!(s = session_get_if_valid (tc->s_index, tc->thread_index))) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 1118 | return; |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1119 | |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1120 | switch (s->session_state) |
| 1121 | { |
Florin Coras | 222e1f41 | 2019-02-16 20:47:32 -0800 | [diff] [blame] | 1122 | case SESSION_STATE_CREATED: |
| 1123 | /* Session was created but accept notification was not yet sent to the |
| 1124 | * app. Cleanup everything. */ |
| 1125 | session_lookup_del_session (s); |
Zeyu Zhang | cbbc4a2 | 2019-10-12 14:21:59 +0800 | [diff] [blame] | 1126 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 1127 | session_free (s); |
Florin Coras | 222e1f41 | 2019-02-16 20:47:32 -0800 | [diff] [blame] | 1128 | break; |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 1129 | case SESSION_STATE_ACCEPTING: |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1130 | case SESSION_STATE_TRANSPORT_CLOSING: |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1131 | case SESSION_STATE_CLOSING: |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1132 | case SESSION_STATE_TRANSPORT_CLOSED: |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1133 | /* If transport finishes or times out before we get a reply |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1134 | * from the app, mark transport as closed and wait for reply |
| 1135 | * before removing the session. Cleanup session table in advance |
Florin Coras | a9d5bea | 2018-12-17 08:24:19 -0800 | [diff] [blame] | 1136 | * because transport will soon be closed and closed sessions |
| 1137 | * are assumed to have been removed from the lookup table */ |
| 1138 | session_lookup_del_session (s); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1139 | session_set_state (s, SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 1140 | session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT); |
| 1141 | svm_fifo_dequeue_drop_all (s->tx_fifo); |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1142 | break; |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1143 | case SESSION_STATE_APP_CLOSED: |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1144 | /* Cleanup lookup table as transport needs to still be valid. |
| 1145 | * Program transport close to ensure that all session events |
| 1146 | * have been cleaned up. Once transport close is called, the |
| 1147 | * session is just removed because both transport and app have |
| 1148 | * confirmed the close*/ |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1149 | session_lookup_del_session (s); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1150 | session_set_state (s, SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 1151 | session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT); |
| 1152 | svm_fifo_dequeue_drop_all (s->tx_fifo); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1153 | session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_CLOSE); |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1154 | break; |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1155 | case SESSION_STATE_TRANSPORT_DELETED: |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 1156 | break; |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1157 | case SESSION_STATE_CLOSED: |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 1158 | session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT); |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1159 | session_set_state (s, SESSION_STATE_TRANSPORT_DELETED); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1160 | session_delete (s); |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1161 | break; |
Florin Coras | c01d578 | 2018-10-17 14:53:11 -0700 | [diff] [blame] | 1162 | default: |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 1163 | clib_warning ("session state %u", s->session_state); |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 1164 | session_cleanup_notify (s, SESSION_CLEANUP_TRANSPORT); |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1165 | session_delete (s); |
Florin Coras | c01d578 | 2018-10-17 14:53:11 -0700 | [diff] [blame] | 1166 | break; |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1167 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | /** |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1171 | * Notification from transport that it is closed |
Florin Coras | 54ddf43 | 2018-12-21 13:54:09 -0800 | [diff] [blame] | 1172 | * |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1173 | * Should be called by transport, prior to calling delete notify, once it |
| 1174 | * knows that no more data will be exchanged. This could serve as an |
| 1175 | * early acknowledgment of an active close especially if transport delete |
| 1176 | * can be delayed a long time, e.g., tcp time-wait. |
Florin Coras | 54ddf43 | 2018-12-21 13:54:09 -0800 | [diff] [blame] | 1177 | */ |
| 1178 | void |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1179 | session_transport_closed_notify (transport_connection_t * tc) |
Florin Coras | 54ddf43 | 2018-12-21 13:54:09 -0800 | [diff] [blame] | 1180 | { |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1181 | app_worker_t *app_wrk; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1182 | session_t *s; |
Florin Coras | 54ddf43 | 2018-12-21 13:54:09 -0800 | [diff] [blame] | 1183 | |
| 1184 | if (!(s = session_get_if_valid (tc->s_index, tc->thread_index))) |
| 1185 | return; |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 1186 | |
Florin Coras | 5afc13d | 2023-12-12 14:01:43 -0800 | [diff] [blame^] | 1187 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSED) |
| 1188 | return; |
| 1189 | |
Florin Coras | 06a2eec | 2019-05-23 22:28:16 -0700 | [diff] [blame] | 1190 | /* Transport thinks that app requested close but it actually didn't. |
liuyacan | 534468e | 2021-05-09 03:50:40 +0000 | [diff] [blame] | 1191 | * Can happen for tcp: |
| 1192 | * 1)if fin and rst are received in close succession. |
| 1193 | * 2)if app shutdown the connection. */ |
Florin Coras | 06a2eec | 2019-05-23 22:28:16 -0700 | [diff] [blame] | 1194 | if (s->session_state == SESSION_STATE_READY) |
| 1195 | { |
| 1196 | session_transport_closing_notify (tc); |
| 1197 | svm_fifo_dequeue_drop_all (s->tx_fifo); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1198 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSED); |
Florin Coras | 06a2eec | 2019-05-23 22:28:16 -0700 | [diff] [blame] | 1199 | } |
Florin Coras | b0f662f | 2018-12-27 14:51:46 -0800 | [diff] [blame] | 1200 | /* If app close has not been received or has not yet resulted in |
| 1201 | * a transport close, only mark the session transport as closed */ |
Florin Coras | 06a2eec | 2019-05-23 22:28:16 -0700 | [diff] [blame] | 1202 | else if (s->session_state <= SESSION_STATE_CLOSING) |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1203 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSED); |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1204 | /* If app also closed, switch to closed */ |
| 1205 | else if (s->session_state == SESSION_STATE_APP_CLOSED) |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1206 | session_set_state (s, SESSION_STATE_CLOSED); |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1207 | |
| 1208 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 1209 | if (app_wrk) |
| 1210 | app_worker_transport_closed_notify (app_wrk, s); |
Florin Coras | 54ddf43 | 2018-12-21 13:54:09 -0800 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1214 | * Notify application that connection has been reset. |
| 1215 | */ |
| 1216 | void |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1217 | session_transport_reset_notify (transport_connection_t * tc) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1218 | { |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1219 | app_worker_t *app_wrk; |
Florin Coras | 69b68ef | 2019-04-02 11:38:51 -0700 | [diff] [blame] | 1220 | session_t *s; |
| 1221 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1222 | s = session_get (tc->s_index, tc->thread_index); |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1223 | svm_fifo_dequeue_drop_all (s->tx_fifo); |
Florin Coras | 3c7d4f9 | 2018-12-14 11:28:43 -0800 | [diff] [blame] | 1224 | if (s->session_state >= SESSION_STATE_TRANSPORT_CLOSING) |
| 1225 | return; |
Florin Coras | dfd27bc | 2021-11-27 10:45:55 -0800 | [diff] [blame] | 1226 | if (s->session_state == SESSION_STATE_ACCEPTING) |
| 1227 | { |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1228 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSING); |
Florin Coras | dfd27bc | 2021-11-27 10:45:55 -0800 | [diff] [blame] | 1229 | return; |
| 1230 | } |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1231 | session_set_state (s, SESSION_STATE_TRANSPORT_CLOSING); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1232 | app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 69b68ef | 2019-04-02 11:38:51 -0700 | [diff] [blame] | 1233 | app_worker_reset_notify (app_wrk, s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1234 | } |
| 1235 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1236 | int |
| 1237 | session_stream_accept_notify (transport_connection_t * tc) |
| 1238 | { |
| 1239 | app_worker_t *app_wrk; |
| 1240 | session_t *s; |
| 1241 | |
| 1242 | s = session_get (tc->s_index, tc->thread_index); |
| 1243 | app_wrk = app_worker_get_if_valid (s->app_wrk_index); |
| 1244 | if (!app_wrk) |
| 1245 | return -1; |
Florin Coras | 600d7a8 | 2021-04-29 11:55:23 -0700 | [diff] [blame] | 1246 | if (s->session_state != SESSION_STATE_CREATED) |
| 1247 | return 0; |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1248 | session_set_state (s, SESSION_STATE_ACCEPTING); |
Florin Coras | 4dc10a4 | 2020-02-11 05:31:49 +0000 | [diff] [blame] | 1249 | if (app_worker_accept_notify (app_wrk, s)) |
| 1250 | { |
| 1251 | /* On transport delete, no notifications should be sent. Unless, the |
| 1252 | * accept is retried and successful. */ |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1253 | session_set_state (s, SESSION_STATE_CREATED); |
Florin Coras | 4dc10a4 | 2020-02-11 05:31:49 +0000 | [diff] [blame] | 1254 | return -1; |
| 1255 | } |
| 1256 | return 0; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1257 | } |
| 1258 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1259 | /** |
| 1260 | * Accept a stream session. Optionally ping the server by callback. |
| 1261 | */ |
| 1262 | int |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 1263 | session_stream_accept (transport_connection_t * tc, u32 listener_index, |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 1264 | u32 thread_index, u8 notify) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1265 | { |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1266 | session_t *s; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1267 | int rv; |
| 1268 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1269 | s = session_alloc_for_connection (tc); |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 1270 | s->listener_handle = ((u64) thread_index << 32) | (u64) listener_index; |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1271 | session_set_state (s, SESSION_STATE_CREATED); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1272 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1273 | if ((rv = app_worker_init_accepted (s))) |
Florin Coras | 12813d5 | 2020-04-09 20:59:20 +0000 | [diff] [blame] | 1274 | { |
| 1275 | session_free (s); |
| 1276 | return rv; |
| 1277 | } |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1278 | |
| 1279 | session_lookup_add_connection (tc, session_handle (s)); |
| 1280 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1281 | /* Shoulder-tap the server */ |
| 1282 | if (notify) |
| 1283 | { |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1284 | app_worker_t *app_wrk = app_worker_get (s->app_wrk_index); |
Florin Coras | 12813d5 | 2020-04-09 20:59:20 +0000 | [diff] [blame] | 1285 | if ((rv = app_worker_accept_notify (app_wrk, s))) |
| 1286 | { |
| 1287 | session_lookup_del_session (s); |
| 1288 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 1289 | session_free (s); |
| 1290 | return rv; |
| 1291 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | return 0; |
| 1295 | } |
| 1296 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1297 | int |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 1298 | session_dgram_accept (transport_connection_t * tc, u32 listener_index, |
| 1299 | u32 thread_index) |
| 1300 | { |
| 1301 | app_worker_t *app_wrk; |
| 1302 | session_t *s; |
| 1303 | int rv; |
| 1304 | |
| 1305 | s = session_alloc_for_connection (tc); |
| 1306 | s->listener_handle = ((u64) thread_index << 32) | (u64) listener_index; |
| 1307 | |
| 1308 | if ((rv = app_worker_init_accepted (s))) |
| 1309 | { |
| 1310 | session_free (s); |
| 1311 | return rv; |
| 1312 | } |
| 1313 | |
Florin Coras | 473556d | 2020-11-23 15:59:36 -0800 | [diff] [blame] | 1314 | session_lookup_add_connection (tc, session_handle (s)); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1315 | session_set_state (s, SESSION_STATE_ACCEPTING); |
Florin Coras | 473556d | 2020-11-23 15:59:36 -0800 | [diff] [blame] | 1316 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 1317 | app_wrk = app_worker_get (s->app_wrk_index); |
| 1318 | if ((rv = app_worker_accept_notify (app_wrk, s))) |
| 1319 | { |
Florin Coras | 473556d | 2020-11-23 15:59:36 -0800 | [diff] [blame] | 1320 | session_lookup_del_session (s); |
Florin Coras | 12813d5 | 2020-04-09 20:59:20 +0000 | [diff] [blame] | 1321 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 1322 | session_free (s); |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 1323 | return rv; |
| 1324 | } |
| 1325 | |
Florin Coras | e759bb5 | 2020-04-08 01:55:39 +0000 | [diff] [blame] | 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | int |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1330 | session_open_cl (session_endpoint_cfg_t *rmt, session_handle_t *rsh) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1331 | { |
| 1332 | transport_connection_t *tc; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1333 | transport_endpoint_cfg_t *tep; |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1334 | app_worker_t *app_wrk; |
Aloys Augustin | 20ab31e | 2019-03-25 11:29:17 +0100 | [diff] [blame] | 1335 | session_handle_t sh; |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1336 | session_t *s; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1337 | int rv; |
| 1338 | |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1339 | tep = session_endpoint_to_transport_cfg (rmt); |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1340 | rv = transport_connect (rmt->transport_proto, tep); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1341 | if (rv < 0) |
| 1342 | { |
| 1343 | SESSION_DBG ("Transport failed to open connection."); |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 1344 | return rv; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1347 | tc = transport_get_half_open (rmt->transport_proto, (u32) rv); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1348 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1349 | /* For dgram type of service, allocate session and fifos now */ |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1350 | app_wrk = app_worker_get (rmt->app_wrk_index); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1351 | s = session_alloc_for_connection (tc); |
Florin Coras | 1553197 | 2018-08-12 23:50:53 -0700 | [diff] [blame] | 1352 | s->app_wrk_index = app_wrk->wrk_index; |
Florin Coras | 2ceb818 | 2023-08-31 17:33:47 -0700 | [diff] [blame] | 1353 | s->opaque = rmt->opaque; |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1354 | session_set_state (s, SESSION_STATE_OPENED); |
Florin Coras | 44d9cbc | 2023-12-21 13:50:53 -0800 | [diff] [blame] | 1355 | if (transport_connection_is_cless (tc)) |
| 1356 | s->flags |= SESSION_F_IS_CLESS; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 1357 | if (app_worker_init_connected (app_wrk, s)) |
| 1358 | { |
| 1359 | session_free (s); |
| 1360 | return -1; |
| 1361 | } |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1362 | |
Aloys Augustin | 20ab31e | 2019-03-25 11:29:17 +0100 | [diff] [blame] | 1363 | sh = session_handle (s); |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1364 | *rsh = sh; |
| 1365 | |
Aloys Augustin | 20ab31e | 2019-03-25 11:29:17 +0100 | [diff] [blame] | 1366 | session_lookup_add_connection (tc, sh); |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1367 | return app_worker_connect_notify (app_wrk, s, SESSION_E_NONE, rmt->opaque); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | int |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1371 | session_open_vc (session_endpoint_cfg_t *rmt, session_handle_t *rsh) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1372 | { |
| 1373 | transport_connection_t *tc; |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1374 | transport_endpoint_cfg_t *tep; |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 1375 | app_worker_t *app_wrk; |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1376 | session_t *ho; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1377 | int rv; |
| 1378 | |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1379 | tep = session_endpoint_to_transport_cfg (rmt); |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1380 | rv = transport_connect (rmt->transport_proto, tep); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1381 | if (rv < 0) |
| 1382 | { |
| 1383 | SESSION_DBG ("Transport failed to open connection."); |
Florin Coras | 57660d9 | 2020-04-04 22:45:34 +0000 | [diff] [blame] | 1384 | return rv; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1385 | } |
| 1386 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1387 | tc = transport_get_half_open (rmt->transport_proto, (u32) rv); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1388 | |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1389 | app_wrk = app_worker_get (rmt->app_wrk_index); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1390 | |
Florin Coras | ea72764 | 2021-05-07 19:39:43 -0700 | [diff] [blame] | 1391 | /* If transport offers a vc service, only allocate established |
| 1392 | * session once the connection has been established. |
| 1393 | * In the meantime allocate half-open session for tracking purposes |
| 1394 | * associate half-open connection to it and add session to app-worker |
| 1395 | * half-open table. These are needed to allocate the established |
| 1396 | * session on transport notification, and to cleanup the half-open |
| 1397 | * session if the app detaches before connection establishment. |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1398 | */ |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1399 | ho = session_alloc_for_half_open (tc); |
| 1400 | ho->app_wrk_index = app_wrk->wrk_index; |
| 1401 | ho->ho_index = app_worker_add_half_open (app_wrk, session_handle (ho)); |
| 1402 | ho->opaque = rmt->opaque; |
| 1403 | *rsh = session_handle (ho); |
Florin Coras | d50ff7f | 2020-04-16 04:30:22 +0000 | [diff] [blame] | 1404 | |
Florin Coras | 2c876f9 | 2021-05-10 21:12:27 -0700 | [diff] [blame] | 1405 | if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP)) |
| 1406 | session_lookup_add_half_open (tc, tc->c_index); |
Florin Coras | 4fde4ae | 2020-04-13 16:48:04 +0000 | [diff] [blame] | 1407 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1408 | return 0; |
| 1409 | } |
| 1410 | |
| 1411 | int |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1412 | session_open_app (session_endpoint_cfg_t *rmt, session_handle_t *rsh) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1413 | { |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1414 | transport_endpoint_cfg_t *tep_cfg = session_endpoint_to_transport_cfg (rmt); |
Florin Coras | 5665ced | 2018-10-25 18:03:45 -0700 | [diff] [blame] | 1415 | |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1416 | /* Not supported for now */ |
| 1417 | *rsh = SESSION_INVALID_HANDLE; |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1418 | return transport_connect (rmt->transport_proto, tep_cfg); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1419 | } |
| 1420 | |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1421 | typedef int (*session_open_service_fn) (session_endpoint_cfg_t *, |
| 1422 | session_handle_t *); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1423 | |
| 1424 | /* *INDENT-OFF* */ |
| 1425 | static session_open_service_fn session_open_srv_fns[TRANSPORT_N_SERVICES] = { |
| 1426 | session_open_vc, |
| 1427 | session_open_cl, |
| 1428 | session_open_app, |
| 1429 | }; |
| 1430 | /* *INDENT-ON* */ |
| 1431 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1432 | /** |
| 1433 | * Ask transport to open connection to remote transport endpoint. |
| 1434 | * |
| 1435 | * Stores handle for matching request with reply since the call can be |
| 1436 | * asynchronous. For instance, for TCP the 3-way handshake must complete |
| 1437 | * before reply comes. Session is only created once connection is established. |
| 1438 | * |
| 1439 | * @param app_index Index of the application requesting the connect |
| 1440 | * @param st Session type requested. |
| 1441 | * @param tep Remote transport endpoint |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1442 | * @param opaque Opaque data (typically, api_context) the application expects |
| 1443 | * on open completion. |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1444 | */ |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1445 | int |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1446 | session_open (session_endpoint_cfg_t *rmt, session_handle_t *rsh) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1447 | { |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1448 | transport_service_type_t tst; |
| 1449 | tst = transport_protocol_service_type (rmt->transport_proto); |
Florin Coras | 89a9f61 | 2021-05-11 11:55:07 -0700 | [diff] [blame] | 1450 | return session_open_srv_fns[tst](rmt, rsh); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1453 | /** |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1454 | * Ask transport to listen on session endpoint. |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1455 | * |
| 1456 | * @param s Session for which listen will be called. Note that unlike |
| 1457 | * established sessions, listen sessions are not associated to a |
| 1458 | * thread. |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1459 | * @param sep Local endpoint to be listened on. |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1460 | */ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1461 | int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1462 | session_listen (session_t * ls, session_endpoint_cfg_t * sep) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1463 | { |
Florin Coras | 0bce71e | 2022-02-10 11:57:06 -0800 | [diff] [blame] | 1464 | transport_endpoint_cfg_t *tep; |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1465 | int tc_index; |
| 1466 | u32 s_index; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1467 | |
| 1468 | /* Transport bind/listen */ |
Florin Coras | 0bce71e | 2022-02-10 11:57:06 -0800 | [diff] [blame] | 1469 | tep = session_endpoint_to_transport_cfg (sep); |
Florin Coras | 74cac88 | 2018-09-07 09:13:15 -0700 | [diff] [blame] | 1470 | s_index = ls->session_index; |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 1471 | tc_index = transport_start_listen (session_get_transport_proto (ls), |
| 1472 | s_index, tep); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1473 | |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1474 | if (tc_index < 0) |
| 1475 | return tc_index; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1476 | |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 1477 | /* Attach transport to session. Lookup tables are populated by the app |
| 1478 | * worker because local tables (for ct sessions) are not backed by a fib */ |
Florin Coras | 74cac88 | 2018-09-07 09:13:15 -0700 | [diff] [blame] | 1479 | ls = listen_session_get (s_index); |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1480 | ls->connection_index = tc_index; |
Mohammed Hawari | 472d0da | 2022-10-17 17:55:35 +0200 | [diff] [blame] | 1481 | ls->opaque = sep->opaque; |
Florin Coras | 44d9cbc | 2023-12-21 13:50:53 -0800 | [diff] [blame] | 1482 | if (transport_connection_is_cless (session_get_transport (ls))) |
| 1483 | ls->flags |= SESSION_F_IS_CLESS; |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1484 | |
Florin Coras | ab2f6db | 2018-08-31 14:31:41 -0700 | [diff] [blame] | 1485 | return 0; |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1486 | } |
| 1487 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1488 | /** |
| 1489 | * Ask transport to stop listening on local transport endpoint. |
| 1490 | * |
| 1491 | * @param s Session to stop listening on. It must be in state LISTENING. |
| 1492 | */ |
| 1493 | int |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1494 | session_stop_listen (session_t * s) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1495 | { |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1496 | transport_proto_t tp = session_get_transport_proto (s); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1497 | transport_connection_t *tc; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1498 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1499 | if (s->session_state != SESSION_STATE_LISTENING) |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1500 | return SESSION_E_NOLISTEN; |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1501 | |
| 1502 | tc = transport_get_listener (tp, s->connection_index); |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1503 | |
| 1504 | /* If no transport, assume everything was cleaned up already */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1505 | if (!tc) |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1506 | return SESSION_E_NONE; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1507 | |
Nathan Skrzypczak | 2eed1a1 | 2019-07-04 14:26:21 +0200 | [diff] [blame] | 1508 | if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP)) |
Florin Coras | d96859f | 2023-06-24 14:43:42 -0700 | [diff] [blame] | 1509 | session_lookup_del_connection (tc); |
Florin Coras | a8c3b86 | 2020-04-07 22:31:06 +0000 | [diff] [blame] | 1510 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1511 | transport_stop_listen (tp, s->connection_index); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1512 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | /** |
liuyacan | 534468e | 2021-05-09 03:50:40 +0000 | [diff] [blame] | 1516 | * Initialize session half-closing procedure. |
| 1517 | * |
| 1518 | * Note that half-closing will not change the state of the session. |
| 1519 | */ |
| 1520 | void |
| 1521 | session_half_close (session_t *s) |
| 1522 | { |
| 1523 | if (!s) |
| 1524 | return; |
| 1525 | |
| 1526 | session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_HALF_CLOSE); |
| 1527 | } |
| 1528 | |
| 1529 | /** |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1530 | * Initialize session closing procedure. |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1531 | * |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 1532 | * Request is always sent to session node to ensure that all outstanding |
| 1533 | * requests are served before transport is notified. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1534 | */ |
| 1535 | void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1536 | session_close (session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1537 | { |
Florin Coras | 7c06b57 | 2023-02-20 15:14:04 -0800 | [diff] [blame] | 1538 | if (!s || (s->flags & SESSION_F_APP_CLOSED)) |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 1539 | return; |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1540 | |
Florin Coras | 7c06b57 | 2023-02-20 15:14:04 -0800 | [diff] [blame] | 1541 | /* Transports can close and delete their state independent of app closes |
| 1542 | * and transport initiated state transitions can hide app closes. Instead |
| 1543 | * of extending the state machine to support separate tracking of app and |
| 1544 | * transport initiated closes, use a flag. */ |
| 1545 | s->flags |= SESSION_F_APP_CLOSED; |
| 1546 | |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1547 | if (s->session_state >= SESSION_STATE_CLOSING) |
| 1548 | { |
Florin Coras | 5a2ec8f | 2018-12-27 11:53:11 -0800 | [diff] [blame] | 1549 | /* Session will only be removed once both app and transport |
| 1550 | * acknowledge the close */ |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1551 | if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED |
| 1552 | || s->session_state == SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1553 | session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_CLOSE); |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1554 | return; |
| 1555 | } |
| 1556 | |
Dongya Zhang | 7a87c71 | 2022-11-03 15:22:34 +0800 | [diff] [blame] | 1557 | /* App closed so stop propagating dequeue notifications. |
| 1558 | * App might disconnect session before connected, in this case, |
| 1559 | * tx_fifo may not be setup yet, so clear only it's inited. */ |
| 1560 | if (s->tx_fifo) |
| 1561 | svm_fifo_clear_deq_ntf (s->tx_fifo); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1562 | session_set_state (s, SESSION_STATE_CLOSING); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1563 | session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_CLOSE); |
| 1564 | } |
| 1565 | |
| 1566 | /** |
| 1567 | * Force a close without waiting for data to be flushed |
| 1568 | */ |
| 1569 | void |
| 1570 | session_reset (session_t * s) |
| 1571 | { |
| 1572 | if (s->session_state >= SESSION_STATE_CLOSING) |
| 1573 | return; |
Dongya Zhang | 7a87c71 | 2022-11-03 15:22:34 +0800 | [diff] [blame] | 1574 | /* Drop all outstanding tx data |
| 1575 | * App might disconnect session before connected, in this case, |
| 1576 | * tx_fifo may not be setup yet, so clear only it's inited. */ |
| 1577 | if (s->tx_fifo) |
| 1578 | svm_fifo_dequeue_drop_all (s->tx_fifo); |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1579 | session_set_state (s, SESSION_STATE_CLOSING); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1580 | session_program_transport_ctrl_evt (s, SESSION_CTRL_EVT_RESET); |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | /** |
liuyacan | 534468e | 2021-05-09 03:50:40 +0000 | [diff] [blame] | 1584 | * Notify transport the session can be half-disconnected. |
| 1585 | * |
| 1586 | * Must be called from the session's thread. |
| 1587 | */ |
| 1588 | void |
| 1589 | session_transport_half_close (session_t *s) |
| 1590 | { |
| 1591 | /* Only READY session can be half-closed */ |
| 1592 | if (s->session_state != SESSION_STATE_READY) |
| 1593 | { |
| 1594 | return; |
| 1595 | } |
| 1596 | |
| 1597 | transport_half_close (session_get_transport_proto (s), s->connection_index, |
| 1598 | s->thread_index); |
| 1599 | } |
| 1600 | |
| 1601 | /** |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 1602 | * Notify transport the session can be disconnected. This should eventually |
| 1603 | * result in a delete notification that allows us to cleanup session state. |
| 1604 | * Called for both active/passive disconnects. |
| 1605 | * |
| 1606 | * Must be called from the session's thread. |
| 1607 | */ |
| 1608 | void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1609 | session_transport_close (session_t * s) |
Florin Coras | 2f8d8fa | 2018-01-26 06:36:04 -0800 | [diff] [blame] | 1610 | { |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1611 | if (s->session_state >= SESSION_STATE_APP_CLOSED) |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1612 | { |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1613 | if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED) |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1614 | session_set_state (s, SESSION_STATE_CLOSED); |
Florin Coras | 5f06632 | 2019-07-22 19:03:03 -0700 | [diff] [blame] | 1615 | /* If transport is already deleted, just free the session */ |
| 1616 | else if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1617 | session_program_cleanup (s); |
Florin Coras | 568ebc7 | 2018-09-18 16:12:50 -0700 | [diff] [blame] | 1618 | return; |
| 1619 | } |
Florin Coras | 78cc4b0 | 2018-12-20 18:24:49 -0800 | [diff] [blame] | 1620 | |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 1621 | /* If the tx queue wasn't drained, the transport can continue to try |
| 1622 | * sending the outstanding data (in closed state it cannot). It MUST however |
| 1623 | * at one point, either after sending everything or after a timeout, call |
| 1624 | * delete notify. This will finally lead to the complete cleanup of the |
| 1625 | * session. |
Florin Coras | 78cc4b0 | 2018-12-20 18:24:49 -0800 | [diff] [blame] | 1626 | */ |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1627 | session_set_state (s, SESSION_STATE_APP_CLOSED); |
Florin Coras | 78cc4b0 | 2018-12-20 18:24:49 -0800 | [diff] [blame] | 1628 | |
Florin Coras | 1ee7830 | 2019-02-05 15:51:15 -0800 | [diff] [blame] | 1629 | transport_close (session_get_transport_proto (s), s->connection_index, |
| 1630 | s->thread_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | /** |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1634 | * Force transport close |
| 1635 | */ |
| 1636 | void |
| 1637 | session_transport_reset (session_t * s) |
| 1638 | { |
| 1639 | if (s->session_state >= SESSION_STATE_APP_CLOSED) |
| 1640 | { |
| 1641 | if (s->session_state == SESSION_STATE_TRANSPORT_CLOSED) |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1642 | session_set_state (s, SESSION_STATE_CLOSED); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1643 | else if (s->session_state >= SESSION_STATE_TRANSPORT_DELETED) |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 1644 | session_program_cleanup (s); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1645 | return; |
| 1646 | } |
| 1647 | |
Steven Luong | d810a6e | 2022-10-25 13:09:11 -0700 | [diff] [blame] | 1648 | session_set_state (s, SESSION_STATE_APP_CLOSED); |
Florin Coras | dfb3b87 | 2019-08-16 17:48:44 -0700 | [diff] [blame] | 1649 | transport_reset (session_get_transport_proto (s), s->connection_index, |
| 1650 | s->thread_index); |
| 1651 | } |
| 1652 | |
| 1653 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1654 | * Cleanup transport and session state. |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 1655 | * |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1656 | * Notify transport of the cleanup and free the session. This should |
| 1657 | * be called only if transport reported some error and is already |
| 1658 | * closed. |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1659 | */ |
| 1660 | void |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1661 | session_transport_cleanup (session_t * s) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1662 | { |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1663 | /* Delete from main lookup table before we axe the the transport */ |
| 1664 | session_lookup_del_session (s); |
Florin Coras | 5afea12 | 2019-10-28 08:46:37 -0700 | [diff] [blame] | 1665 | if (s->session_state != SESSION_STATE_TRANSPORT_DELETED) |
| 1666 | transport_cleanup (session_get_transport_proto (s), s->connection_index, |
| 1667 | s->thread_index); |
Florin Coras | 25579b4 | 2018-06-06 17:55:02 -0700 | [diff] [blame] | 1668 | /* Since we called cleanup, no delete notification will come. So, make |
| 1669 | * sure the session is properly freed. */ |
Florin Coras | d3955fb | 2019-11-29 09:31:47 -0800 | [diff] [blame] | 1670 | segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo); |
| 1671 | session_free (s); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1672 | } |
| 1673 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1674 | /** |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1675 | * Allocate worker mqs in share-able segment |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1676 | * |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1677 | * That can only be a newly created memfd segment, that must be mapped |
| 1678 | * by all apps/stack users unless private rx mqs are enabled. |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1679 | */ |
| 1680 | void |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1681 | session_vpp_wrk_mqs_alloc (session_main_t *smm) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1682 | { |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1683 | u32 mq_q_length = 2048, evt_size = sizeof (session_event_t); |
| 1684 | fifo_segment_t *mqs_seg = &smm->wrk_mqs_segment; |
| 1685 | svm_msg_q_cfg_t _cfg, *cfg = &_cfg; |
| 1686 | uword mqs_seg_size; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1687 | int i; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1688 | |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1689 | mq_q_length = clib_max (mq_q_length, smm->configured_wrk_mq_length); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1690 | |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1691 | svm_msg_q_ring_cfg_t rc[SESSION_MQ_N_RINGS] = { |
| 1692 | { mq_q_length, evt_size, 0 }, { mq_q_length >> 1, 256, 0 } |
| 1693 | }; |
| 1694 | cfg->consumer_pid = 0; |
| 1695 | cfg->n_rings = 2; |
| 1696 | cfg->q_nitems = mq_q_length; |
| 1697 | cfg->ring_cfgs = rc; |
Florin Coras | 6c10ab2 | 2020-11-08 16:50:39 -0800 | [diff] [blame] | 1698 | |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1699 | /* |
| 1700 | * Compute mqs segment size based on rings config and leave space |
| 1701 | * for passing extended configuration messages, i.e., data allocated |
| 1702 | * outside of the rings. If provided with a config value, accept it |
| 1703 | * if larger than minimum size. |
| 1704 | */ |
| 1705 | mqs_seg_size = svm_msg_q_size_to_alloc (cfg) * vec_len (smm->wrk); |
Florin Coras | cf5c774 | 2022-06-28 14:34:45 -0700 | [diff] [blame] | 1706 | mqs_seg_size = mqs_seg_size + (1 << 20); |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1707 | mqs_seg_size = clib_max (mqs_seg_size, smm->wrk_mqs_segment_size); |
| 1708 | |
| 1709 | mqs_seg->ssvm.ssvm_size = mqs_seg_size; |
| 1710 | mqs_seg->ssvm.my_pid = getpid (); |
| 1711 | mqs_seg->ssvm.name = format (0, "%s%c", "session: wrk-mqs-segment", 0); |
Florin Coras | 6c10ab2 | 2020-11-08 16:50:39 -0800 | [diff] [blame] | 1712 | |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1713 | if (ssvm_server_init (&mqs_seg->ssvm, SSVM_SEGMENT_MEMFD)) |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1714 | { |
Florin Coras | 6c10ab2 | 2020-11-08 16:50:39 -0800 | [diff] [blame] | 1715 | clib_warning ("failed to initialize queue segment"); |
| 1716 | return; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1717 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1718 | |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1719 | fifo_segment_init (mqs_seg); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1720 | |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 1721 | /* Special fifo segment that's filled only with mqs */ |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1722 | mqs_seg->h->n_mqs = vec_len (smm->wrk); |
Florin Coras | b462418 | 2020-12-11 13:58:12 -0800 | [diff] [blame] | 1723 | |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1724 | for (i = 0; i < vec_len (smm->wrk); i++) |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1725 | smm->wrk[i].vpp_event_queue = fifo_segment_msg_q_alloc (mqs_seg, i, cfg); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1726 | } |
| 1727 | |
Florin Coras | 04943b4 | 2020-12-25 11:45:40 -0800 | [diff] [blame] | 1728 | fifo_segment_t * |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1729 | session_main_get_wrk_mqs_segment (void) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1730 | { |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1731 | return &session_main.wrk_mqs_segment; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 1734 | u64 |
| 1735 | session_segment_handle (session_t * s) |
| 1736 | { |
| 1737 | svm_fifo_t *f; |
| 1738 | |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 1739 | if (!s->rx_fifo) |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 1740 | return SESSION_INVALID_HANDLE; |
| 1741 | |
| 1742 | f = s->rx_fifo; |
| 1743 | return segment_manager_make_segment_handle (f->segment_manager, |
| 1744 | f->segment_index); |
| 1745 | } |
| 1746 | |
qinyang | af9b715 | 2023-06-27 01:11:53 -0700 | [diff] [blame] | 1747 | void |
| 1748 | session_get_original_dst (transport_endpoint_t *i2o_src, |
| 1749 | transport_endpoint_t *i2o_dst, |
| 1750 | transport_proto_t transport_proto, u32 *original_dst, |
| 1751 | u16 *original_dst_port) |
| 1752 | { |
| 1753 | session_main_t *smm = vnet_get_session_main (); |
| 1754 | ip_protocol_t proto = |
| 1755 | (transport_proto == TRANSPORT_PROTO_TCP ? IPPROTO_TCP : IPPROTO_UDP); |
| 1756 | if (!smm->original_dst_lookup || !i2o_dst->is_ip4) |
| 1757 | return; |
| 1758 | smm->original_dst_lookup (&i2o_src->ip.ip4, i2o_src->port, &i2o_dst->ip.ip4, |
| 1759 | i2o_dst->port, proto, original_dst, |
| 1760 | original_dst_port); |
| 1761 | } |
| 1762 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1763 | /* *INDENT-OFF* */ |
| 1764 | static session_fifo_rx_fn *session_tx_fns[TRANSPORT_TX_N_FNS] = { |
| 1765 | session_tx_fifo_peek_and_snd, |
| 1766 | session_tx_fifo_dequeue_and_snd, |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 1767 | session_tx_fifo_dequeue_internal, |
| 1768 | session_tx_fifo_dequeue_and_snd |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1769 | }; |
| 1770 | /* *INDENT-ON* */ |
| 1771 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1772 | void |
| 1773 | session_register_transport (transport_proto_t transport_proto, |
| 1774 | const transport_proto_vft_t * vft, u8 is_ip4, |
| 1775 | u32 output_node) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1776 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 1777 | session_main_t *smm = &session_main; |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1778 | session_type_t session_type; |
| 1779 | u32 next_index = ~0; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1780 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1781 | session_type = session_type_from_proto_and_ip (transport_proto, is_ip4); |
| 1782 | |
| 1783 | vec_validate (smm->session_type_to_next, session_type); |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1784 | vec_validate (smm->session_tx_fns, session_type); |
| 1785 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1786 | if (output_node != ~0) |
Florin Coras | eb839cc | 2021-04-14 11:23:55 -0700 | [diff] [blame] | 1787 | next_index = vlib_node_add_next (vlib_get_main (), |
| 1788 | session_queue_node.index, output_node); |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 1789 | |
| 1790 | smm->session_type_to_next[session_type] = next_index; |
Nathan Skrzypczak | e971bc9 | 2019-06-19 13:42:37 +0200 | [diff] [blame] | 1791 | smm->session_tx_fns[session_type] = |
| 1792 | session_tx_fns[vft->transport_options.tx_type]; |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 1793 | } |
| 1794 | |
Florin Coras | 5384cca | 2022-01-20 18:10:26 -0800 | [diff] [blame] | 1795 | void |
| 1796 | session_register_update_time_fn (session_update_time_fn fn, u8 is_add) |
| 1797 | { |
| 1798 | session_main_t *smm = &session_main; |
| 1799 | session_update_time_fn *fi; |
| 1800 | u32 fi_pos = ~0; |
| 1801 | u8 found = 0; |
| 1802 | |
| 1803 | vec_foreach (fi, smm->update_time_fns) |
| 1804 | { |
| 1805 | if (*fi == fn) |
| 1806 | { |
| 1807 | fi_pos = fi - smm->update_time_fns; |
| 1808 | found = 1; |
| 1809 | break; |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | if (is_add) |
| 1814 | { |
| 1815 | if (found) |
| 1816 | { |
| 1817 | clib_warning ("update time fn %p already registered", fn); |
| 1818 | return; |
| 1819 | } |
| 1820 | vec_add1 (smm->update_time_fns, fn); |
| 1821 | } |
| 1822 | else |
| 1823 | { |
| 1824 | vec_del1 (smm->update_time_fns, fi_pos); |
| 1825 | } |
| 1826 | } |
| 1827 | |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 1828 | transport_proto_t |
| 1829 | session_add_transport_proto (void) |
| 1830 | { |
| 1831 | session_main_t *smm = &session_main; |
| 1832 | session_worker_t *wrk; |
| 1833 | u32 thread; |
| 1834 | |
| 1835 | smm->last_transport_proto_type += 1; |
| 1836 | |
| 1837 | for (thread = 0; thread < vec_len (smm->wrk); thread++) |
| 1838 | { |
| 1839 | wrk = session_main_get_worker (thread); |
| 1840 | vec_validate (wrk->session_to_enqueue, smm->last_transport_proto_type); |
| 1841 | } |
| 1842 | |
| 1843 | return smm->last_transport_proto_type; |
| 1844 | } |
| 1845 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1846 | transport_connection_t * |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1847 | session_get_transport (session_t * s) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1848 | { |
Florin Coras | ade70e4 | 2017-10-14 18:56:41 -0700 | [diff] [blame] | 1849 | if (s->session_state != SESSION_STATE_LISTENING) |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 1850 | return transport_get_connection (session_get_transport_proto (s), |
| 1851 | s->connection_index, s->thread_index); |
| 1852 | else |
| 1853 | return transport_get_listener (session_get_transport_proto (s), |
| 1854 | s->connection_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1855 | } |
| 1856 | |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 1857 | void |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 1858 | session_get_endpoint (session_t * s, transport_endpoint_t * tep, u8 is_lcl) |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 1859 | { |
| 1860 | if (s->session_state != SESSION_STATE_LISTENING) |
| 1861 | return transport_get_endpoint (session_get_transport_proto (s), |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 1862 | s->connection_index, s->thread_index, tep, |
| 1863 | is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 1864 | else |
| 1865 | return transport_get_listener_endpoint (session_get_transport_proto (s), |
Florin Coras | 09d18c2 | 2019-04-24 11:10:02 -0700 | [diff] [blame] | 1866 | s->connection_index, tep, is_lcl); |
Aloys Augustin | cdb7170 | 2019-04-08 17:54:39 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
Florin Coras | 04ae827 | 2021-04-12 19:55:37 -0700 | [diff] [blame] | 1869 | int |
| 1870 | session_transport_attribute (session_t *s, u8 is_get, |
| 1871 | transport_endpt_attr_t *attr) |
| 1872 | { |
| 1873 | if (s->session_state < SESSION_STATE_READY) |
| 1874 | return -1; |
| 1875 | |
| 1876 | return transport_connection_attribute (session_get_transport_proto (s), |
| 1877 | s->connection_index, s->thread_index, |
| 1878 | is_get, attr); |
| 1879 | } |
| 1880 | |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1881 | transport_connection_t * |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 1882 | listen_session_get_transport (session_t * s) |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1883 | { |
Florin Coras | 4edc37e | 2019-02-04 23:01:34 -0800 | [diff] [blame] | 1884 | return transport_get_listener (session_get_transport_proto (s), |
| 1885 | s->connection_index); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1886 | } |
| 1887 | |
Florin Coras | fd542f1 | 2018-05-16 19:28:24 -0700 | [diff] [blame] | 1888 | void |
Florin Coras | 5484daa | 2020-03-27 23:55:06 +0000 | [diff] [blame] | 1889 | session_queue_run_on_main_thread (vlib_main_t * vm) |
Florin Coras | fd542f1 | 2018-05-16 19:28:24 -0700 | [diff] [blame] | 1890 | { |
| 1891 | ASSERT (vlib_get_thread_index () == 0); |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 1892 | vlib_node_set_interrupt_pending (vm, session_queue_node.index); |
Florin Coras | fd542f1 | 2018-05-16 19:28:24 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
Florin Coras | d82f471 | 2022-04-25 16:15:02 -0700 | [diff] [blame] | 1895 | static void |
| 1896 | session_stats_collector_fn (vlib_stats_collector_data_t *d) |
| 1897 | { |
| 1898 | u32 i, n_workers, n_wrk_sessions, n_sessions = 0; |
| 1899 | session_main_t *smm = &session_main; |
| 1900 | session_worker_t *wrk; |
| 1901 | counter_t **counters; |
| 1902 | counter_t *cb; |
| 1903 | |
| 1904 | n_workers = vec_len (smm->wrk); |
| 1905 | vlib_stats_validate (d->entry_index, 0, n_workers - 1); |
| 1906 | counters = d->entry->data; |
| 1907 | cb = counters[0]; |
| 1908 | |
| 1909 | for (i = 0; i < vec_len (smm->wrk); i++) |
| 1910 | { |
| 1911 | wrk = session_main_get_worker (i); |
| 1912 | n_wrk_sessions = pool_elts (wrk->sessions); |
| 1913 | cb[i] = n_wrk_sessions; |
| 1914 | n_sessions += n_wrk_sessions; |
| 1915 | } |
| 1916 | |
| 1917 | vlib_stats_set_gauge (d->private_data, n_sessions); |
| 1918 | } |
| 1919 | |
| 1920 | static void |
| 1921 | session_stats_collector_init (void) |
| 1922 | { |
Florin Coras | 975e0df | 2022-04-26 19:32:11 -0700 | [diff] [blame] | 1923 | vlib_stats_collector_reg_t reg = {}; |
Florin Coras | d82f471 | 2022-04-25 16:15:02 -0700 | [diff] [blame] | 1924 | |
| 1925 | reg.entry_index = |
| 1926 | vlib_stats_add_counter_vector ("/sys/session/sessions_per_worker"); |
| 1927 | reg.private_data = vlib_stats_add_gauge ("/sys/session/sessions_total"); |
| 1928 | reg.collect_fn = session_stats_collector_fn; |
| 1929 | vlib_stats_register_collector_fn (®); |
| 1930 | vlib_stats_validate (reg.entry_index, 0, vlib_get_n_threads ()); |
| 1931 | } |
| 1932 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1933 | static clib_error_t * |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1934 | session_manager_main_enable (vlib_main_t * vm) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1935 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 1936 | session_main_t *smm = &session_main; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1937 | vlib_thread_main_t *vtm = vlib_get_thread_main (); |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1938 | u32 num_threads, preallocated_sessions_per_worker; |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 1939 | session_worker_t *wrk; |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 1940 | int i; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1941 | |
Florin Coras | e10da62 | 2020-10-25 14:00:29 -0700 | [diff] [blame] | 1942 | /* We only initialize once and do not de-initialized on disable */ |
| 1943 | if (smm->is_initialized) |
| 1944 | goto done; |
| 1945 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1946 | num_threads = 1 /* main thread */ + vtm->n_threads; |
| 1947 | |
| 1948 | if (num_threads < 1) |
| 1949 | return clib_error_return (0, "n_thread_stacks not set"); |
| 1950 | |
Florin Coras | 5f56d73 | 2018-10-30 10:21:59 -0700 | [diff] [blame] | 1951 | /* Allocate cache line aligned worker contexts */ |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1952 | vec_validate_aligned (smm->wrk, num_threads - 1, CLIB_CACHE_LINE_BYTES); |
Florin Coras | 53d8d4f | 2022-03-09 13:55:38 -0800 | [diff] [blame] | 1953 | clib_spinlock_init (&session_main.pool_realloc_lock); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1954 | |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1955 | for (i = 0; i < num_threads; i++) |
| 1956 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1957 | wrk = &smm->wrk[i]; |
Florin Coras | b0ffbee | 2019-07-21 19:23:46 -0700 | [diff] [blame] | 1958 | wrk->ctrl_head = clib_llist_make_head (wrk->event_elts, evt_list); |
Florin Coras | 2062ec0 | 2019-07-15 13:15:18 -0700 | [diff] [blame] | 1959 | wrk->new_head = clib_llist_make_head (wrk->event_elts, evt_list); |
Florin Coras | 60183db | 2019-07-20 15:53:16 -0700 | [diff] [blame] | 1960 | wrk->old_head = clib_llist_make_head (wrk->event_elts, evt_list); |
Florin Coras | af97221 | 2021-05-05 09:54:00 -0700 | [diff] [blame] | 1961 | wrk->pending_connects = clib_llist_make_head (wrk->event_elts, evt_list); |
Florin Coras | e09bd48 | 2022-03-21 10:38:01 -0700 | [diff] [blame] | 1962 | wrk->evts_pending_main = |
| 1963 | clib_llist_make_head (wrk->event_elts, evt_list); |
Damjan Marion | 6ffb7c6 | 2021-03-26 13:06:13 +0100 | [diff] [blame] | 1964 | wrk->vm = vlib_get_main_by_index (i); |
Dave Barach | 77d9838 | 2020-04-28 18:00:21 -0400 | [diff] [blame] | 1965 | wrk->last_vlib_time = vlib_time_now (vm); |
Florin Coras | a8e71c8 | 2019-10-22 19:01:39 -0700 | [diff] [blame] | 1966 | wrk->last_vlib_us_time = wrk->last_vlib_time * CLIB_US_TIME_FREQ; |
Florin Coras | a48dffe | 2021-05-16 10:58:53 -0700 | [diff] [blame] | 1967 | wrk->timerfd = -1; |
Florin Coras | 07063b8 | 2020-03-13 04:44:51 +0000 | [diff] [blame] | 1968 | vec_validate (wrk->session_to_enqueue, smm->last_transport_proto_type); |
Florin Coras | d67f112 | 2018-05-21 17:47:40 -0700 | [diff] [blame] | 1969 | |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 1970 | if (!smm->no_adaptive && smm->use_private_rx_mqs) |
| 1971 | session_wrk_enable_adaptive_mode (wrk); |
Dave Barach | acd2a6a | 2017-05-16 17:41:34 -0400 | [diff] [blame] | 1972 | } |
| 1973 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1974 | /* Allocate vpp event queues segment and queue */ |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 1975 | session_vpp_wrk_mqs_alloc (smm); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 1976 | |
Florin Coras | 9a45bd8 | 2020-12-28 16:28:07 -0800 | [diff] [blame] | 1977 | /* Initialize segment manager properties */ |
| 1978 | segment_manager_main_init (); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1979 | |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1980 | /* Preallocate sessions */ |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1981 | if (smm->preallocated_sessions) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1982 | { |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1983 | if (num_threads == 1) |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1984 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1985 | pool_init_fixed (smm->wrk[0].sessions, smm->preallocated_sessions); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1986 | } |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1987 | else |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1988 | { |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1989 | int j; |
| 1990 | preallocated_sessions_per_worker = |
| 1991 | (1.1 * (f64) smm->preallocated_sessions / |
| 1992 | (f64) (num_threads - 1)); |
| 1993 | |
| 1994 | for (j = 1; j < num_threads; j++) |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1995 | { |
Florin Coras | 5a7ca7b | 2018-10-30 12:01:48 -0700 | [diff] [blame] | 1996 | pool_init_fixed (smm->wrk[j].sessions, |
Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1997 | preallocated_sessions_per_worker); |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1998 | } |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 1999 | } |
| 2000 | } |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 2001 | |
Florin Coras | 04e5344 | 2017-07-16 17:12:15 -0700 | [diff] [blame] | 2002 | session_lookup_init (); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 2003 | app_namespaces_init (); |
Florin Coras | 3cbc04b | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 2004 | transport_init (); |
Florin Coras | d82f471 | 2022-04-25 16:15:02 -0700 | [diff] [blame] | 2005 | session_stats_collector_init (); |
Florin Coras | e10da62 | 2020-10-25 14:00:29 -0700 | [diff] [blame] | 2006 | smm->is_initialized = 1; |
| 2007 | |
| 2008 | done: |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 2009 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2010 | smm->is_enabled = 1; |
| 2011 | |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 2012 | /* Enable transports */ |
| 2013 | transport_enable_disable (vm, 1); |
Florin Coras | 1116667 | 2020-04-13 01:20:25 +0000 | [diff] [blame] | 2014 | session_debug_init (); |
Srikanth Akula | 7357043 | 2020-04-06 19:19:49 -0700 | [diff] [blame] | 2015 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 2016 | return 0; |
| 2017 | } |
| 2018 | |
Florin Coras | e10da62 | 2020-10-25 14:00:29 -0700 | [diff] [blame] | 2019 | static void |
| 2020 | session_manager_main_disable (vlib_main_t * vm) |
| 2021 | { |
| 2022 | transport_enable_disable (vm, 0 /* is_en */ ); |
| 2023 | } |
| 2024 | |
Marvin Liu | 0654242 | 2022-08-16 06:49:09 +0000 | [diff] [blame] | 2025 | /* in this new callback, cookie hint the index */ |
| 2026 | void |
| 2027 | session_dma_completion_cb (vlib_main_t *vm, struct vlib_dma_batch *batch) |
| 2028 | { |
| 2029 | session_worker_t *wrk; |
| 2030 | wrk = session_main_get_worker (vm->thread_index); |
| 2031 | session_dma_transfer *dma_transfer; |
| 2032 | |
| 2033 | dma_transfer = &wrk->dma_trans[wrk->trans_head]; |
| 2034 | vec_add (wrk->pending_tx_buffers, dma_transfer->pending_tx_buffers, |
| 2035 | vec_len (dma_transfer->pending_tx_buffers)); |
| 2036 | vec_add (wrk->pending_tx_nexts, dma_transfer->pending_tx_nexts, |
| 2037 | vec_len (dma_transfer->pending_tx_nexts)); |
| 2038 | vec_reset_length (dma_transfer->pending_tx_buffers); |
| 2039 | vec_reset_length (dma_transfer->pending_tx_nexts); |
| 2040 | wrk->trans_head++; |
| 2041 | if (wrk->trans_head == wrk->trans_size) |
| 2042 | wrk->trans_head = 0; |
| 2043 | return; |
| 2044 | } |
| 2045 | |
| 2046 | static void |
| 2047 | session_prepare_dma_args (vlib_dma_config_t *args) |
| 2048 | { |
Marvin Liu | 48d2e15 | 2023-03-14 23:56:31 +0800 | [diff] [blame] | 2049 | args->max_batches = 16; |
Marvin Liu | 0654242 | 2022-08-16 06:49:09 +0000 | [diff] [blame] | 2050 | args->max_transfers = DMA_TRANS_SIZE; |
| 2051 | args->max_transfer_size = 65536; |
| 2052 | args->features = 0; |
| 2053 | args->sw_fallback = 1; |
| 2054 | args->barrier_before_last = 1; |
| 2055 | args->callback_fn = session_dma_completion_cb; |
| 2056 | } |
| 2057 | |
| 2058 | static void |
| 2059 | session_node_enable_dma (u8 is_en, int n_vlibs) |
| 2060 | { |
| 2061 | vlib_dma_config_t args; |
| 2062 | session_prepare_dma_args (&args); |
| 2063 | session_worker_t *wrk; |
| 2064 | vlib_main_t *vm; |
| 2065 | |
| 2066 | int config_index = -1; |
| 2067 | |
| 2068 | if (is_en) |
| 2069 | { |
| 2070 | vm = vlib_get_main_by_index (0); |
| 2071 | config_index = vlib_dma_config_add (vm, &args); |
| 2072 | } |
| 2073 | else |
| 2074 | { |
| 2075 | vm = vlib_get_main_by_index (0); |
| 2076 | wrk = session_main_get_worker (0); |
| 2077 | if (wrk->config_index >= 0) |
| 2078 | vlib_dma_config_del (vm, wrk->config_index); |
| 2079 | } |
| 2080 | int i; |
| 2081 | for (i = 0; i < n_vlibs; i++) |
| 2082 | { |
| 2083 | vm = vlib_get_main_by_index (i); |
| 2084 | wrk = session_main_get_worker (vm->thread_index); |
| 2085 | wrk->config_index = config_index; |
| 2086 | if (is_en) |
| 2087 | { |
| 2088 | if (config_index >= 0) |
| 2089 | wrk->dma_enabled = true; |
| 2090 | wrk->dma_trans = (session_dma_transfer *) clib_mem_alloc ( |
| 2091 | sizeof (session_dma_transfer) * DMA_TRANS_SIZE); |
| 2092 | bzero (wrk->dma_trans, |
| 2093 | sizeof (session_dma_transfer) * DMA_TRANS_SIZE); |
| 2094 | } |
| 2095 | else |
| 2096 | { |
| 2097 | if (wrk->dma_trans) |
| 2098 | clib_mem_free (wrk->dma_trans); |
| 2099 | } |
| 2100 | wrk->trans_head = 0; |
| 2101 | wrk->trans_tail = 0; |
| 2102 | wrk->trans_size = DMA_TRANS_SIZE; |
| 2103 | } |
| 2104 | } |
| 2105 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 2106 | void |
| 2107 | session_node_enable_disable (u8 is_en) |
| 2108 | { |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2109 | u8 mstate = is_en ? VLIB_NODE_STATE_INTERRUPT : VLIB_NODE_STATE_DISABLED; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 2110 | u8 state = is_en ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED; |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2111 | session_main_t *sm = &session_main; |
| 2112 | vlib_main_t *vm; |
| 2113 | vlib_node_t *n; |
| 2114 | int n_vlibs, i; |
Florin Coras | fd542f1 | 2018-05-16 19:28:24 -0700 | [diff] [blame] | 2115 | |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2116 | n_vlibs = vlib_get_n_threads (); |
| 2117 | for (i = 0; i < n_vlibs; i++) |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2118 | { |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2119 | vm = vlib_get_main_by_index (i); |
| 2120 | /* main thread with workers and not polling */ |
| 2121 | if (i == 0 && n_vlibs > 1) |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2122 | { |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2123 | vlib_node_set_state (vm, session_queue_node.index, mstate); |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2124 | if (is_en) |
| 2125 | { |
Florin Coras | b32af35 | 2021-05-19 07:58:49 -0700 | [diff] [blame] | 2126 | session_main_get_worker (0)->state = SESSION_WRK_INTERRUPT; |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2127 | vlib_node_set_state (vm, session_queue_process_node.index, |
| 2128 | state); |
| 2129 | n = vlib_get_node (vm, session_queue_process_node.index); |
| 2130 | vlib_start_process (vm, n->runtime_index); |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2131 | } |
| 2132 | else |
| 2133 | { |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2134 | vlib_process_signal_event_mt (vm, |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2135 | session_queue_process_node.index, |
| 2136 | SESSION_Q_PROCESS_STOP, 0); |
| 2137 | } |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2138 | if (!sm->poll_main) |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2139 | continue; |
| 2140 | } |
Florin Coras | 0242d30 | 2022-12-22 15:03:44 -0800 | [diff] [blame] | 2141 | vlib_node_set_state (vm, session_input_node.index, mstate); |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2142 | vlib_node_set_state (vm, session_queue_node.index, state); |
Damjan Marion | 92ccf9b | 2021-03-26 11:38:01 +0100 | [diff] [blame] | 2143 | } |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 2144 | |
Florin Coras | 1d2e38b | 2021-03-17 21:52:49 -0700 | [diff] [blame] | 2145 | if (sm->use_private_rx_mqs) |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 2146 | application_enable_rx_mqs_nodes (is_en); |
Marvin Liu | 0654242 | 2022-08-16 06:49:09 +0000 | [diff] [blame] | 2147 | |
| 2148 | if (sm->dma_enabled) |
| 2149 | session_node_enable_dma (is_en, n_vlibs); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2152 | clib_error_t * |
| 2153 | vnet_session_enable_disable (vlib_main_t * vm, u8 is_en) |
| 2154 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 2155 | clib_error_t *error = 0; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2156 | if (is_en) |
| 2157 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 2158 | if (session_main.is_enabled) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2159 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 2160 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 2161 | error = session_manager_main_enable (vm); |
Vladimir Kropylev | a2e4451 | 2019-07-16 21:32:41 +0300 | [diff] [blame] | 2162 | session_node_enable_disable (is_en); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2163 | } |
| 2164 | else |
| 2165 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 2166 | session_main.is_enabled = 0; |
Florin Coras | e10da62 | 2020-10-25 14:00:29 -0700 | [diff] [blame] | 2167 | session_manager_main_disable (vm); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 2168 | session_node_enable_disable (is_en); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2169 | } |
| 2170 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 2171 | return error; |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2172 | } |
| 2173 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2174 | clib_error_t * |
Florin Coras | e33c002 | 2020-04-03 17:23:42 +0000 | [diff] [blame] | 2175 | session_main_init (vlib_main_t * vm) |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2176 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 2177 | session_main_t *smm = &session_main; |
Florin Coras | e33c002 | 2020-04-03 17:23:42 +0000 | [diff] [blame] | 2178 | |
| 2179 | smm->is_enabled = 0; |
| 2180 | smm->session_enable_asap = 0; |
Florin Coras | e92c946 | 2020-11-25 08:44:16 -0800 | [diff] [blame] | 2181 | smm->poll_main = 0; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 2182 | smm->use_private_rx_mqs = 0; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 2183 | smm->no_adaptive = 0; |
Florin Coras | 0b65621 | 2022-01-13 11:59:44 -0800 | [diff] [blame] | 2184 | smm->last_transport_proto_type = TRANSPORT_PROTO_HTTP; |
Nathan Skrzypczak | e111bbd | 2023-10-03 13:54:15 +0200 | [diff] [blame] | 2185 | smm->port_allocator_min_src_port = 1024; |
| 2186 | smm->port_allocator_max_src_port = 65535; |
Florin Coras | e33c002 | 2020-04-03 17:23:42 +0000 | [diff] [blame] | 2187 | |
Nathan Skrzypczak | 31bd035 | 2019-11-07 17:55:01 +0100 | [diff] [blame] | 2188 | return 0; |
| 2189 | } |
| 2190 | |
| 2191 | static clib_error_t * |
Florin Coras | e33c002 | 2020-04-03 17:23:42 +0000 | [diff] [blame] | 2192 | session_main_loop_init (vlib_main_t * vm) |
Nathan Skrzypczak | 31bd035 | 2019-11-07 17:55:01 +0100 | [diff] [blame] | 2193 | { |
| 2194 | session_main_t *smm = &session_main; |
| 2195 | if (smm->session_enable_asap) |
| 2196 | { |
| 2197 | vlib_worker_thread_barrier_sync (vm); |
| 2198 | vnet_session_enable_disable (vm, 1 /* is_en */ ); |
| 2199 | vlib_worker_thread_barrier_release (vm); |
| 2200 | } |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 2201 | return 0; |
| 2202 | } |
| 2203 | |
Florin Coras | e33c002 | 2020-04-03 17:23:42 +0000 | [diff] [blame] | 2204 | VLIB_INIT_FUNCTION (session_main_init); |
| 2205 | VLIB_MAIN_LOOP_ENTER_FUNCTION (session_main_loop_init); |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 2206 | |
| 2207 | static clib_error_t * |
| 2208 | session_config_fn (vlib_main_t * vm, unformat_input_t * input) |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2209 | { |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 2210 | session_main_t *smm = &session_main; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2211 | u32 nitems; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 2212 | uword tmp; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2213 | |
| 2214 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 2215 | { |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 2216 | if (unformat (input, "wrk-mq-length %d", &nitems)) |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2217 | { |
| 2218 | if (nitems >= 2048) |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 2219 | smm->configured_wrk_mq_length = nitems; |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2220 | else |
| 2221 | clib_warning ("event queue length %d too small, ignored", nitems); |
| 2222 | } |
Florin Coras | cf5c774 | 2022-06-28 14:34:45 -0700 | [diff] [blame] | 2223 | else if (unformat (input, "wrk-mqs-segment-size %U", |
| 2224 | unformat_memory_size, &smm->wrk_mqs_segment_size)) |
| 2225 | ; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 2226 | else if (unformat (input, "preallocated-sessions %d", |
| 2227 | &smm->preallocated_sessions)) |
Dave Barach | 2c25a62 | 2017-06-26 11:35:07 -0400 | [diff] [blame] | 2228 | ; |
Florin Coras | 66b1131 | 2017-07-31 17:18:03 -0700 | [diff] [blame] | 2229 | else if (unformat (input, "v4-session-table-buckets %d", |
| 2230 | &smm->configured_v4_session_table_buckets)) |
| 2231 | ; |
| 2232 | else if (unformat (input, "v4-halfopen-table-buckets %d", |
| 2233 | &smm->configured_v4_halfopen_table_buckets)) |
| 2234 | ; |
| 2235 | else if (unformat (input, "v6-session-table-buckets %d", |
| 2236 | &smm->configured_v6_session_table_buckets)) |
| 2237 | ; |
| 2238 | else if (unformat (input, "v6-halfopen-table-buckets %d", |
| 2239 | &smm->configured_v6_halfopen_table_buckets)) |
| 2240 | ; |
| 2241 | else if (unformat (input, "v4-session-table-memory %U", |
| 2242 | unformat_memory_size, &tmp)) |
| 2243 | { |
| 2244 | if (tmp >= 0x100000000) |
| 2245 | return clib_error_return (0, "memory size %llx (%lld) too large", |
| 2246 | tmp, tmp); |
| 2247 | smm->configured_v4_session_table_memory = tmp; |
| 2248 | } |
| 2249 | else if (unformat (input, "v4-halfopen-table-memory %U", |
| 2250 | unformat_memory_size, &tmp)) |
| 2251 | { |
| 2252 | if (tmp >= 0x100000000) |
| 2253 | return clib_error_return (0, "memory size %llx (%lld) too large", |
| 2254 | tmp, tmp); |
| 2255 | smm->configured_v4_halfopen_table_memory = tmp; |
| 2256 | } |
| 2257 | else if (unformat (input, "v6-session-table-memory %U", |
| 2258 | unformat_memory_size, &tmp)) |
| 2259 | { |
| 2260 | if (tmp >= 0x100000000) |
| 2261 | return clib_error_return (0, "memory size %llx (%lld) too large", |
| 2262 | tmp, tmp); |
| 2263 | smm->configured_v6_session_table_memory = tmp; |
| 2264 | } |
| 2265 | else if (unformat (input, "v6-halfopen-table-memory %U", |
| 2266 | unformat_memory_size, &tmp)) |
| 2267 | { |
| 2268 | if (tmp >= 0x100000000) |
| 2269 | return clib_error_return (0, "memory size %llx (%lld) too large", |
| 2270 | tmp, tmp); |
| 2271 | smm->configured_v6_halfopen_table_memory = tmp; |
| 2272 | } |
Florin Coras | 93e6580 | 2017-11-29 00:07:11 -0500 | [diff] [blame] | 2273 | else if (unformat (input, "local-endpoints-table-memory %U", |
| 2274 | unformat_memory_size, &tmp)) |
| 2275 | { |
| 2276 | if (tmp >= 0x100000000) |
| 2277 | return clib_error_return (0, "memory size %llx (%lld) too large", |
| 2278 | tmp, tmp); |
| 2279 | smm->local_endpoints_table_memory = tmp; |
| 2280 | } |
| 2281 | else if (unformat (input, "local-endpoints-table-buckets %d", |
| 2282 | &smm->local_endpoints_table_buckets)) |
| 2283 | ; |
Nathan Skrzypczak | e111bbd | 2023-10-03 13:54:15 +0200 | [diff] [blame] | 2284 | else if (unformat (input, "min-src-port %d", &tmp)) |
| 2285 | smm->port_allocator_min_src_port = tmp; |
| 2286 | else if (unformat (input, "max-src-port %d", &tmp)) |
| 2287 | smm->port_allocator_max_src_port = tmp; |
Nathan Skrzypczak | 1292d19 | 2019-09-13 15:44:54 +0200 | [diff] [blame] | 2288 | else if (unformat (input, "enable")) |
Nathan Skrzypczak | 31bd035 | 2019-11-07 17:55:01 +0100 | [diff] [blame] | 2289 | smm->session_enable_asap = 1; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 2290 | else if (unformat (input, "use-app-socket-api")) |
Nathan Skrzypczak | 7b3a3df | 2021-07-28 14:09:50 +0200 | [diff] [blame] | 2291 | (void) appns_sapi_enable_disable (1 /* is_enable */); |
Florin Coras | e92c946 | 2020-11-25 08:44:16 -0800 | [diff] [blame] | 2292 | else if (unformat (input, "poll-main")) |
| 2293 | smm->poll_main = 1; |
Florin Coras | 41d5f54 | 2021-01-15 13:49:33 -0800 | [diff] [blame] | 2294 | else if (unformat (input, "use-private-rx-mqs")) |
| 2295 | smm->use_private_rx_mqs = 1; |
Florin Coras | 7da8829 | 2021-03-18 15:04:34 -0700 | [diff] [blame] | 2296 | else if (unformat (input, "no-adaptive")) |
| 2297 | smm->no_adaptive = 1; |
Marvin Liu | 0654242 | 2022-08-16 06:49:09 +0000 | [diff] [blame] | 2298 | else if (unformat (input, "use-dma")) |
| 2299 | smm->dma_enabled = 1; |
qinyang | af9b715 | 2023-06-27 01:11:53 -0700 | [diff] [blame] | 2300 | else if (unformat (input, "nat44-original-dst-enable")) |
| 2301 | { |
| 2302 | smm->original_dst_lookup = vlib_get_plugin_symbol ( |
| 2303 | "nat_plugin.so", "nat44_original_dst_lookup"); |
| 2304 | } |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 2305 | /* |
| 2306 | * Deprecated but maintained for compatibility |
| 2307 | */ |
| 2308 | else if (unformat (input, "evt_qs_memfd_seg")) |
| 2309 | ; |
Florin Coras | ef04803 | 2021-11-17 23:57:30 -0800 | [diff] [blame] | 2310 | else if (unformat (input, "segment-baseva 0x%lx", &tmp)) |
| 2311 | ; |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 2312 | else if (unformat (input, "evt_qs_seg_size %U", unformat_memory_size, |
Florin Coras | cf5c774 | 2022-06-28 14:34:45 -0700 | [diff] [blame] | 2313 | &smm->wrk_mqs_segment_size)) |
Florin Coras | 8afe1b8 | 2021-11-17 23:38:54 -0800 | [diff] [blame] | 2314 | ; |
| 2315 | else if (unformat (input, "event-queue-length %d", &nitems)) |
| 2316 | { |
| 2317 | if (nitems >= 2048) |
| 2318 | smm->configured_wrk_mq_length = nitems; |
| 2319 | else |
| 2320 | clib_warning ("event queue length %d too small, ignored", nitems); |
| 2321 | } |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 2322 | else |
| 2323 | return clib_error_return (0, "unknown input `%U'", |
| 2324 | format_unformat_error, input); |
| 2325 | } |
| 2326 | return 0; |
| 2327 | } |
| 2328 | |
| 2329 | VLIB_CONFIG_FUNCTION (session_config_fn, "session"); |
| 2330 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 2331 | /* |
| 2332 | * fd.io coding-style-patch-verification: ON |
| 2333 | * |
| 2334 | * Local Variables: |
| 2335 | * eval: (c-set-style "gnu") |
| 2336 | * End: |
| 2337 | */ |