Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 Cisco and/or its affiliates. |
| 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 | #include <vnet/session/application.h> |
| 17 | #include <vnet/session/application_interface.h> |
Florin Coras | 54a51fd | 2019-02-07 15:34:52 -0800 | [diff] [blame] | 18 | #include <vnet/session/session.h> |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Pool of workers associated to apps |
| 22 | */ |
| 23 | static app_worker_t *app_workers; |
| 24 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 25 | app_worker_t * |
| 26 | app_worker_alloc (application_t * app) |
| 27 | { |
| 28 | app_worker_t *app_wrk; |
| 29 | pool_get (app_workers, app_wrk); |
| 30 | clib_memset (app_wrk, 0, sizeof (*app_wrk)); |
| 31 | app_wrk->wrk_index = app_wrk - app_workers; |
| 32 | app_wrk->app_index = app->app_index; |
| 33 | app_wrk->wrk_map_index = ~0; |
| 34 | app_wrk->connects_seg_manager = APP_INVALID_SEGMENT_MANAGER_INDEX; |
| 35 | app_wrk->first_segment_manager = APP_INVALID_SEGMENT_MANAGER_INDEX; |
Nathan Skrzypczak | ba65ca4 | 2019-05-16 16:35:40 +0200 | [diff] [blame] | 36 | APP_DBG ("New app %v worker %u", app->name, app_wrk->wrk_index); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 37 | return app_wrk; |
| 38 | } |
| 39 | |
| 40 | app_worker_t * |
| 41 | app_worker_get (u32 wrk_index) |
| 42 | { |
| 43 | return pool_elt_at_index (app_workers, wrk_index); |
| 44 | } |
| 45 | |
| 46 | app_worker_t * |
| 47 | app_worker_get_if_valid (u32 wrk_index) |
| 48 | { |
| 49 | if (pool_is_free_index (app_workers, wrk_index)) |
| 50 | return 0; |
| 51 | return pool_elt_at_index (app_workers, wrk_index); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | app_worker_free (app_worker_t * app_wrk) |
| 56 | { |
| 57 | application_t *app = application_get (app_wrk->app_index); |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 58 | vnet_unlisten_args_t _a, *a = &_a; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 59 | u64 handle, *handles = 0; |
| 60 | segment_manager_t *sm; |
Florin Coras | 87d6633 | 2019-06-11 12:31:31 -0700 | [diff] [blame] | 61 | session_t *ls; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 62 | u32 sm_index; |
| 63 | int i; |
| 64 | |
| 65 | /* |
| 66 | * Listener cleanup |
| 67 | */ |
| 68 | |
| 69 | /* *INDENT-OFF* */ |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 70 | hash_foreach (handle, sm_index, app_wrk->listeners_table, ({ |
| 71 | ls = listen_session_get_from_handle (handle); |
Florin Coras | 87d6633 | 2019-06-11 12:31:31 -0700 | [diff] [blame] | 72 | vec_add1 (handles, app_listen_session_handle (ls)); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 73 | sm = segment_manager_get (sm_index); |
| 74 | sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 75 | })); |
| 76 | /* *INDENT-ON* */ |
| 77 | |
| 78 | for (i = 0; i < vec_len (handles); i++) |
| 79 | { |
| 80 | a->app_index = app->app_index; |
| 81 | a->wrk_map_index = app_wrk->wrk_map_index; |
| 82 | a->handle = handles[i]; |
| 83 | /* seg manager is removed when unbind completes */ |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 84 | (void) vnet_unlisten (a); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Connects segment manager cleanup |
| 89 | */ |
| 90 | |
| 91 | if (app_wrk->connects_seg_manager != APP_INVALID_SEGMENT_MANAGER_INDEX) |
| 92 | { |
| 93 | sm = segment_manager_get (app_wrk->connects_seg_manager); |
| 94 | sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
Florin Coras | 565115e | 2019-02-20 19:48:31 -0800 | [diff] [blame] | 95 | sm->first_is_protected = 0; |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 96 | segment_manager_init_free (sm); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* If first segment manager is used by a listener */ |
| 100 | if (app_wrk->first_segment_manager != APP_INVALID_SEGMENT_MANAGER_INDEX |
| 101 | && app_wrk->first_segment_manager != app_wrk->connects_seg_manager) |
| 102 | { |
| 103 | sm = segment_manager_get (app_wrk->first_segment_manager); |
| 104 | sm->first_is_protected = 0; |
| 105 | sm->app_wrk_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 106 | /* .. and has no fifos, e.g. it might be used for redirected sessions, |
| 107 | * remove it */ |
| 108 | if (!segment_manager_has_fifos (sm)) |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 109 | segment_manager_free (sm); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 110 | } |
| 111 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 112 | if (CLIB_DEBUG) |
| 113 | clib_memset (app_wrk, 0xfe, sizeof (*app_wrk)); |
BenoƮt Ganne | d4aeb84 | 2019-07-18 18:38:42 +0200 | [diff] [blame] | 114 | pool_put (app_workers, app_wrk); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | application_t * |
| 118 | app_worker_get_app (u32 wrk_index) |
| 119 | { |
| 120 | app_worker_t *app_wrk; |
| 121 | app_wrk = app_worker_get_if_valid (wrk_index); |
| 122 | if (!app_wrk) |
| 123 | return 0; |
| 124 | return application_get_if_valid (app_wrk->app_index); |
| 125 | } |
| 126 | |
| 127 | static segment_manager_t * |
| 128 | app_worker_alloc_segment_manager (app_worker_t * app_wrk) |
| 129 | { |
| 130 | segment_manager_t *sm = 0; |
| 131 | |
| 132 | /* If the first segment manager is not in use, don't allocate a new one */ |
| 133 | if (app_wrk->first_segment_manager != APP_INVALID_SEGMENT_MANAGER_INDEX |
| 134 | && app_wrk->first_segment_manager_in_use == 0) |
| 135 | { |
| 136 | sm = segment_manager_get (app_wrk->first_segment_manager); |
| 137 | app_wrk->first_segment_manager_in_use = 1; |
| 138 | return sm; |
| 139 | } |
| 140 | |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 141 | sm = segment_manager_alloc (); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 142 | sm->app_wrk_index = app_wrk->wrk_index; |
| 143 | |
| 144 | return sm; |
| 145 | } |
| 146 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 147 | static int |
| 148 | app_worker_alloc_session_fifos (segment_manager_t * sm, session_t * s) |
| 149 | { |
| 150 | svm_fifo_t *rx_fifo = 0, *tx_fifo = 0; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 151 | int rv; |
| 152 | |
Florin Coras | 62ddc03 | 2019-12-08 18:30:42 -0800 | [diff] [blame] | 153 | if ((rv = segment_manager_alloc_session_fifos (sm, s->thread_index, |
| 154 | &rx_fifo, &tx_fifo))) |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 155 | return rv; |
| 156 | |
| 157 | rx_fifo->master_session_index = s->session_index; |
| 158 | rx_fifo->master_thread_index = s->thread_index; |
| 159 | |
| 160 | tx_fifo->master_session_index = s->session_index; |
| 161 | tx_fifo->master_thread_index = s->thread_index; |
| 162 | |
| 163 | s->rx_fifo = rx_fifo; |
| 164 | s->tx_fifo = tx_fifo; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 165 | return 0; |
| 166 | } |
| 167 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 168 | int |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 169 | app_worker_init_listener (app_worker_t * app_wrk, session_t * ls) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 170 | { |
| 171 | segment_manager_t *sm; |
| 172 | |
| 173 | /* Allocate segment manager. All sessions derived out of a listen session |
| 174 | * have fifos allocated by the same segment manager. */ |
| 175 | if (!(sm = app_worker_alloc_segment_manager (app_wrk))) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 176 | return SESSION_E_ALLOC; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 177 | |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 178 | /* Keep track of the segment manager for the listener or this worker */ |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 179 | hash_set (app_wrk->listeners_table, listen_session_get_handle (ls), |
| 180 | segment_manager_index (sm)); |
| 181 | |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 182 | if (transport_connection_is_cless (session_get_transport (ls))) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 183 | { |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 184 | if (ls->rx_fifo) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 185 | return SESSION_E_NOSUPPORT; |
| 186 | return app_worker_alloc_session_fifos (sm, ls); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 187 | } |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | int |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 192 | app_worker_start_listen (app_worker_t * app_wrk, |
| 193 | app_listener_t * app_listener) |
| 194 | { |
| 195 | session_t *ls; |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 196 | int rv; |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 197 | |
| 198 | if (clib_bitmap_get (app_listener->workers, app_wrk->wrk_map_index)) |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 199 | return SESSION_E_ALREADY_LISTENING; |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 200 | |
| 201 | app_listener->workers = clib_bitmap_set (app_listener->workers, |
| 202 | app_wrk->wrk_map_index, 1); |
| 203 | |
| 204 | if (app_listener->session_index != SESSION_INVALID_INDEX) |
| 205 | { |
| 206 | ls = session_get (app_listener->session_index, 0); |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 207 | if ((rv = app_worker_init_listener (app_wrk, ls))) |
| 208 | return rv; |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | if (app_listener->local_index != SESSION_INVALID_INDEX) |
| 212 | { |
| 213 | ls = session_get (app_listener->local_index, 0); |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 214 | if ((rv = app_worker_init_listener (app_wrk, ls))) |
| 215 | return rv; |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | return 0; |
| 219 | } |
| 220 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 221 | static void |
| 222 | app_worker_stop_listen_session (app_worker_t * app_wrk, session_t * ls) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 223 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 224 | session_handle_t handle; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 225 | segment_manager_t *sm; |
| 226 | uword *sm_indexp; |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 227 | |
| 228 | handle = listen_session_get_handle (ls); |
| 229 | sm_indexp = hash_get (app_wrk->listeners_table, handle); |
| 230 | if (PREDICT_FALSE (!sm_indexp)) |
| 231 | return; |
| 232 | |
Florin Coras | 87b7e3d | 2020-03-27 15:06:07 +0000 | [diff] [blame] | 233 | /* Dealloc fifos first, if any, to avoid cleanup attempt lower */ |
| 234 | if (ls->rx_fifo) |
| 235 | { |
| 236 | segment_manager_dealloc_fifos (ls->rx_fifo, ls->tx_fifo); |
| 237 | ls->tx_fifo = ls->rx_fifo = 0; |
| 238 | } |
| 239 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 240 | sm = segment_manager_get (*sm_indexp); |
| 241 | if (app_wrk->first_segment_manager == *sm_indexp) |
| 242 | { |
| 243 | /* Delete sessions but don't remove segment manager */ |
| 244 | app_wrk->first_segment_manager_in_use = 0; |
| 245 | segment_manager_del_sessions (sm); |
| 246 | } |
| 247 | else |
| 248 | { |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 249 | segment_manager_init_free (sm); |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 250 | } |
| 251 | hash_unset (app_wrk->listeners_table, handle); |
| 252 | } |
| 253 | |
| 254 | int |
| 255 | app_worker_stop_listen (app_worker_t * app_wrk, app_listener_t * al) |
| 256 | { |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 257 | session_t *ls; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 258 | |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 259 | if (!clib_bitmap_get (al->workers, app_wrk->wrk_map_index)) |
| 260 | return 0; |
| 261 | |
| 262 | if (al->session_index != SESSION_INVALID_INDEX) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 263 | { |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 264 | ls = listen_session_get (al->session_index); |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 265 | app_worker_stop_listen_session (app_wrk, ls); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 266 | } |
| 267 | |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 268 | if (al->local_index != SESSION_INVALID_INDEX) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 269 | { |
Florin Coras | d4295e6 | 2019-02-22 13:11:38 -0800 | [diff] [blame] | 270 | ls = listen_session_get (al->local_index); |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 271 | app_worker_stop_listen_session (app_wrk, ls); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 272 | } |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 273 | |
| 274 | clib_bitmap_set_no_check (al->workers, app_wrk->wrk_map_index, 0); |
| 275 | if (clib_bitmap_is_zero (al->workers)) |
| 276 | app_listener_cleanup (al); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | int |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 282 | app_worker_init_accepted (session_t * s) |
| 283 | { |
| 284 | app_worker_t *app_wrk; |
| 285 | segment_manager_t *sm; |
| 286 | session_t *listener; |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 287 | application_t *app; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 288 | |
Nathan Skrzypczak | 2f0f96b | 2019-06-13 10:14:28 +0200 | [diff] [blame] | 289 | listener = listen_session_get_from_handle (s->listener_handle); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 290 | app_wrk = application_listener_select_worker (listener); |
| 291 | s->app_wrk_index = app_wrk->wrk_index; |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 292 | |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 293 | app = application_get (app_wrk->app_index); |
| 294 | if (app->cb_fns.fifo_tuning_callback) |
| 295 | s->flags |= SESSION_F_CUSTOM_FIFO_TUNING; |
| 296 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 297 | sm = app_worker_get_listen_segment_manager (app_wrk, listener); |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 298 | if (app_worker_alloc_session_fifos (sm, s)) |
| 299 | return -1; |
| 300 | |
| 301 | return 0; |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | int |
| 305 | app_worker_accept_notify (app_worker_t * app_wrk, session_t * s) |
| 306 | { |
| 307 | application_t *app = application_get (app_wrk->app_index); |
| 308 | return app->cb_fns.session_accept_callback (s); |
| 309 | } |
| 310 | |
| 311 | int |
| 312 | app_worker_init_connected (app_worker_t * app_wrk, session_t * s) |
| 313 | { |
| 314 | application_t *app = application_get (app_wrk->app_index); |
| 315 | segment_manager_t *sm; |
| 316 | |
| 317 | /* Allocate fifos for session, unless the app is a builtin proxy */ |
| 318 | if (!application_is_builtin_proxy (app)) |
| 319 | { |
| 320 | sm = app_worker_get_connect_segment_manager (app_wrk); |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 321 | return app_worker_alloc_session_fifos (sm, s); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 322 | } |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 323 | |
| 324 | if (app->cb_fns.fifo_tuning_callback) |
| 325 | s->flags |= SESSION_F_CUSTOM_FIFO_TUNING; |
| 326 | |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | int |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 331 | app_worker_connect_notify (app_worker_t * app_wrk, session_t * s, |
| 332 | session_error_t err, u32 opaque) |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 333 | { |
| 334 | application_t *app = application_get (app_wrk->app_index); |
| 335 | return app->cb_fns.session_connected_callback (app_wrk->wrk_index, opaque, |
Florin Coras | 00e01d3 | 2019-10-21 16:07:46 -0700 | [diff] [blame] | 336 | s, err); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | int |
Florin Coras | bf7ce2c | 2019-03-06 14:44:42 -0800 | [diff] [blame] | 340 | app_worker_close_notify (app_worker_t * app_wrk, session_t * s) |
| 341 | { |
| 342 | application_t *app = application_get (app_wrk->app_index); |
| 343 | app->cb_fns.session_disconnect_callback (s); |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | int |
Florin Coras | 692b949 | 2019-07-12 15:01:53 -0700 | [diff] [blame] | 348 | app_worker_transport_closed_notify (app_worker_t * app_wrk, session_t * s) |
| 349 | { |
| 350 | application_t *app = application_get (app_wrk->app_index); |
| 351 | if (app->cb_fns.session_transport_closed_callback) |
| 352 | app->cb_fns.session_transport_closed_callback (s); |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | int |
Florin Coras | 69b68ef | 2019-04-02 11:38:51 -0700 | [diff] [blame] | 357 | app_worker_reset_notify (app_worker_t * app_wrk, session_t * s) |
| 358 | { |
| 359 | application_t *app = application_get (app_wrk->app_index); |
| 360 | app->cb_fns.session_reset_callback (s); |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | int |
Florin Coras | 70f26d5 | 2019-07-08 11:47:18 -0700 | [diff] [blame] | 365 | app_worker_cleanup_notify (app_worker_t * app_wrk, session_t * s, |
| 366 | session_cleanup_ntf_t ntf) |
| 367 | { |
| 368 | application_t *app = application_get (app_wrk->app_index); |
| 369 | if (app->cb_fns.session_cleanup_callback) |
| 370 | app->cb_fns.session_cleanup_callback (s, ntf); |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | int |
Florin Coras | bf7ce2c | 2019-03-06 14:44:42 -0800 | [diff] [blame] | 375 | app_worker_builtin_rx (app_worker_t * app_wrk, session_t * s) |
| 376 | { |
| 377 | application_t *app = application_get (app_wrk->app_index); |
| 378 | app->cb_fns.builtin_app_rx_callback (s); |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | int |
Florin Coras | 0e573f5 | 2019-05-07 16:28:16 -0700 | [diff] [blame] | 383 | app_worker_builtin_tx (app_worker_t * app_wrk, session_t * s) |
| 384 | { |
| 385 | application_t *app = application_get (app_wrk->app_index); |
| 386 | |
| 387 | if (!app->cb_fns.builtin_app_tx_callback) |
| 388 | return 0; |
| 389 | |
| 390 | app->cb_fns.builtin_app_tx_callback (s); |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | int |
Florin Coras | 49568af | 2019-07-31 16:46:24 -0700 | [diff] [blame] | 395 | app_worker_migrate_notify (app_worker_t * app_wrk, session_t * s, |
| 396 | session_handle_t new_sh) |
| 397 | { |
| 398 | application_t *app = application_get (app_wrk->app_index); |
| 399 | app->cb_fns.session_migrate_callback (s, new_sh); |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | int |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 404 | app_worker_own_session (app_worker_t * app_wrk, session_t * s) |
| 405 | { |
| 406 | segment_manager_t *sm; |
| 407 | svm_fifo_t *rxf, *txf; |
| 408 | |
| 409 | if (s->session_state == SESSION_STATE_LISTENING) |
| 410 | return application_change_listener_owner (s, app_wrk); |
| 411 | |
| 412 | s->app_wrk_index = app_wrk->wrk_index; |
| 413 | |
| 414 | rxf = s->rx_fifo; |
| 415 | txf = s->tx_fifo; |
| 416 | |
| 417 | if (!rxf || !txf) |
| 418 | return 0; |
| 419 | |
| 420 | s->rx_fifo = 0; |
| 421 | s->tx_fifo = 0; |
| 422 | |
| 423 | sm = app_worker_get_or_alloc_connect_segment_manager (app_wrk); |
Florin Coras | a27a46e | 2019-02-18 13:02:28 -0800 | [diff] [blame] | 424 | if (app_worker_alloc_session_fifos (sm, s)) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 425 | return -1; |
| 426 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 427 | if (!svm_fifo_is_empty_cons (rxf)) |
| 428 | svm_fifo_clone (s->rx_fifo, rxf); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 429 | |
Sirshak Das | 28aa539 | 2019-02-05 01:33:33 -0600 | [diff] [blame] | 430 | if (!svm_fifo_is_empty_cons (txf)) |
| 431 | svm_fifo_clone (s->tx_fifo, txf); |
| 432 | |
Florin Coras | 19223e0 | 2019-03-03 14:56:05 -0800 | [diff] [blame] | 433 | segment_manager_dealloc_fifos (rxf, txf); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |
| 438 | int |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 439 | app_worker_connect_session (app_worker_t * app, session_endpoint_t * sep, |
| 440 | u32 api_context) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 441 | { |
| 442 | int rv; |
| 443 | |
| 444 | /* Make sure we have a segment manager for connects */ |
| 445 | app_worker_alloc_connects_segment_manager (app); |
| 446 | |
| 447 | if ((rv = session_open (app->wrk_index, sep, api_context))) |
| 448 | return rv; |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | int |
Ryujiro Shibuya | d8f48e2 | 2020-01-22 12:11:42 +0000 | [diff] [blame] | 454 | app_worker_session_fifo_tuning (app_worker_t * app_wrk, session_t * s, |
| 455 | svm_fifo_t * f, |
| 456 | session_ft_action_t act, u32 len) |
| 457 | { |
| 458 | application_t *app = application_get (app_wrk->app_index); |
| 459 | return app->cb_fns.fifo_tuning_callback (s, f, act, len); |
| 460 | } |
| 461 | |
| 462 | int |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 463 | app_worker_alloc_connects_segment_manager (app_worker_t * app_wrk) |
| 464 | { |
| 465 | segment_manager_t *sm; |
| 466 | |
| 467 | if (app_wrk->connects_seg_manager == APP_INVALID_SEGMENT_MANAGER_INDEX) |
| 468 | { |
| 469 | sm = app_worker_alloc_segment_manager (app_wrk); |
| 470 | if (sm == 0) |
| 471 | return -1; |
| 472 | app_wrk->connects_seg_manager = segment_manager_index (sm); |
| 473 | } |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | segment_manager_t * |
| 478 | app_worker_get_connect_segment_manager (app_worker_t * app) |
| 479 | { |
| 480 | ASSERT (app->connects_seg_manager != (u32) ~ 0); |
| 481 | return segment_manager_get (app->connects_seg_manager); |
| 482 | } |
| 483 | |
| 484 | segment_manager_t * |
| 485 | app_worker_get_or_alloc_connect_segment_manager (app_worker_t * app_wrk) |
| 486 | { |
| 487 | if (app_wrk->connects_seg_manager == (u32) ~ 0) |
| 488 | app_worker_alloc_connects_segment_manager (app_wrk); |
| 489 | return segment_manager_get (app_wrk->connects_seg_manager); |
| 490 | } |
| 491 | |
| 492 | segment_manager_t * |
| 493 | app_worker_get_listen_segment_manager (app_worker_t * app, |
| 494 | session_t * listener) |
| 495 | { |
| 496 | uword *smp; |
| 497 | smp = hash_get (app->listeners_table, listen_session_get_handle (listener)); |
Dave Barach | 47d41ad | 2020-02-17 09:13:26 -0500 | [diff] [blame] | 498 | ALWAYS_ASSERT (smp != 0); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 499 | return segment_manager_get (*smp); |
| 500 | } |
| 501 | |
| 502 | session_t * |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 503 | app_worker_first_listener (app_worker_t * app_wrk, u8 fib_proto, |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 504 | u8 transport_proto) |
| 505 | { |
| 506 | session_t *listener; |
| 507 | u64 handle; |
| 508 | u32 sm_index; |
| 509 | u8 sst; |
| 510 | |
| 511 | sst = session_type_from_proto_and_ip (transport_proto, |
| 512 | fib_proto == FIB_PROTOCOL_IP4); |
| 513 | |
| 514 | /* *INDENT-OFF* */ |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 515 | hash_foreach (handle, sm_index, app_wrk->listeners_table, ({ |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 516 | listener = listen_session_get_from_handle (handle); |
| 517 | if (listener->session_type == sst |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 518 | && !(listener->flags & SESSION_F_PROXY)) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 519 | return listener; |
| 520 | })); |
| 521 | /* *INDENT-ON* */ |
| 522 | |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | session_t * |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 527 | app_worker_proxy_listener (app_worker_t * app_wrk, u8 fib_proto, |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 528 | u8 transport_proto) |
| 529 | { |
| 530 | session_t *listener; |
| 531 | u64 handle; |
| 532 | u32 sm_index; |
| 533 | u8 sst; |
| 534 | |
| 535 | sst = session_type_from_proto_and_ip (transport_proto, |
| 536 | fib_proto == FIB_PROTOCOL_IP4); |
| 537 | |
| 538 | /* *INDENT-OFF* */ |
Florin Coras | c9940fc | 2019-02-05 20:55:11 -0800 | [diff] [blame] | 539 | hash_foreach (handle, sm_index, app_wrk->listeners_table, ({ |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 540 | listener = listen_session_get_from_handle (handle); |
Florin Coras | d5c604d | 2019-03-18 09:06:35 -0700 | [diff] [blame] | 541 | if (listener->session_type == sst && (listener->flags & SESSION_F_PROXY)) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 542 | return listener; |
| 543 | })); |
| 544 | /* *INDENT-ON* */ |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * Send an API message to the external app, to map new segment |
| 551 | */ |
| 552 | int |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 553 | app_worker_add_segment_notify (app_worker_t * app_wrk, u64 segment_handle) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 554 | { |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 555 | application_t *app = application_get (app_wrk->app_index); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 556 | |
| 557 | return app->cb_fns.add_segment_callback (app_wrk->wrk_index, |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 558 | segment_handle); |
| 559 | } |
| 560 | |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 561 | int |
| 562 | app_worker_del_segment_notify (app_worker_t * app_wrk, u64 segment_handle) |
| 563 | { |
| 564 | application_t *app = application_get (app_wrk->app_index); |
Florin Coras | c4c4cf5 | 2019-08-24 18:17:34 -0700 | [diff] [blame] | 565 | return app->cb_fns.del_segment_callback (app_wrk->wrk_index, |
Florin Coras | 2b81e3c | 2019-02-27 07:55:46 -0800 | [diff] [blame] | 566 | segment_handle); |
| 567 | } |
| 568 | |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 569 | static inline u8 |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 570 | app_worker_application_is_builtin (app_worker_t * app_wrk) |
| 571 | { |
| 572 | return app_wrk->app_is_builtin; |
| 573 | } |
| 574 | |
| 575 | static inline int |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 576 | app_send_io_evt_rx (app_worker_t * app_wrk, session_t * s) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 577 | { |
| 578 | session_event_t *evt; |
| 579 | svm_msg_q_msg_t msg; |
| 580 | svm_msg_q_t *mq; |
| 581 | |
Florin Coras | 5c29029 | 2019-09-19 08:19:44 -0700 | [diff] [blame] | 582 | if (app_worker_application_is_builtin (app_wrk)) |
| 583 | return app_worker_builtin_rx (app_wrk, s); |
| 584 | |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 585 | if (svm_fifo_has_event (s->rx_fifo)) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 586 | return 0; |
| 587 | |
| 588 | mq = app_wrk->event_queue; |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 589 | svm_msg_q_lock (mq); |
| 590 | |
| 591 | if (PREDICT_FALSE (svm_msg_q_is_full (mq))) |
| 592 | { |
| 593 | clib_warning ("evt q full"); |
| 594 | svm_msg_q_unlock (mq); |
| 595 | return -1; |
| 596 | } |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 597 | |
| 598 | if (PREDICT_FALSE (svm_msg_q_ring_is_full (mq, SESSION_MQ_IO_EVT_RING))) |
| 599 | { |
| 600 | clib_warning ("evt q rings full"); |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 601 | svm_msg_q_unlock (mq); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 602 | return -1; |
| 603 | } |
| 604 | |
| 605 | msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 606 | evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg); |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 607 | evt->session_index = s->rx_fifo->client_session_index; |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 608 | evt->event_type = SESSION_IO_EVT_RX; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 609 | |
| 610 | (void) svm_fifo_set_event (s->rx_fifo); |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 611 | svm_msg_q_add_and_unlock (mq, &msg); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 612 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static inline int |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 617 | app_send_io_evt_tx (app_worker_t * app_wrk, session_t * s) |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 618 | { |
| 619 | svm_msg_q_t *mq; |
| 620 | session_event_t *evt; |
| 621 | svm_msg_q_msg_t msg; |
| 622 | |
| 623 | if (app_worker_application_is_builtin (app_wrk)) |
Florin Coras | 0e573f5 | 2019-05-07 16:28:16 -0700 | [diff] [blame] | 624 | return app_worker_builtin_tx (app_wrk, s); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 625 | |
| 626 | mq = app_wrk->event_queue; |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 627 | svm_msg_q_lock (mq); |
| 628 | |
| 629 | if (PREDICT_FALSE (svm_msg_q_is_full (mq))) |
| 630 | { |
| 631 | clib_warning ("evt q full"); |
| 632 | svm_msg_q_unlock (mq); |
| 633 | return -1; |
| 634 | } |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 635 | |
| 636 | if (PREDICT_FALSE (svm_msg_q_ring_is_full (mq, SESSION_MQ_IO_EVT_RING))) |
| 637 | { |
| 638 | clib_warning ("evt q rings full"); |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 639 | svm_msg_q_unlock (mq); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 640 | return -1; |
| 641 | } |
| 642 | |
| 643 | msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 644 | evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg); |
Florin Coras | f6c4313 | 2019-03-01 12:41:21 -0800 | [diff] [blame] | 645 | evt->event_type = SESSION_IO_EVT_TX; |
Florin Coras | c0737e9 | 2019-03-04 14:19:39 -0800 | [diff] [blame] | 646 | evt->session_index = s->tx_fifo->client_session_index; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 647 | |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 648 | svm_msg_q_add_and_unlock (mq, &msg); |
| 649 | return 0; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /* *INDENT-OFF* */ |
| 653 | typedef int (app_send_evt_handler_fn) (app_worker_t *app, |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 654 | session_t *s); |
Florin Coras | 653e43f | 2019-03-04 10:56:23 -0800 | [diff] [blame] | 655 | static app_send_evt_handler_fn * const app_send_evt_handler_fns[2] = { |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 656 | app_send_io_evt_rx, |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 657 | app_send_io_evt_tx, |
| 658 | }; |
| 659 | /* *INDENT-ON* */ |
| 660 | |
| 661 | /** |
| 662 | * Send event to application |
| 663 | * |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 664 | * Logic from queue perspective is blocking. However, if queue is full, |
| 665 | * we return. |
| 666 | */ |
| 667 | int |
| 668 | app_worker_lock_and_send_event (app_worker_t * app, session_t * s, |
| 669 | u8 evt_type) |
| 670 | { |
Florin Coras | 2b5fed8 | 2019-07-25 14:51:09 -0700 | [diff] [blame] | 671 | return app_send_evt_handler_fns[evt_type] (app, s); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 674 | u8 * |
| 675 | format_app_worker_listener (u8 * s, va_list * args) |
| 676 | { |
| 677 | app_worker_t *app_wrk = va_arg (*args, app_worker_t *); |
| 678 | u64 handle = va_arg (*args, u64); |
| 679 | u32 sm_index = va_arg (*args, u32); |
| 680 | int verbose = va_arg (*args, int); |
| 681 | session_t *listener; |
| 682 | const u8 *app_name; |
| 683 | u8 *str; |
| 684 | |
| 685 | if (!app_wrk) |
| 686 | { |
| 687 | if (verbose) |
| 688 | s = format (s, "%-40s%-25s%=10s%-15s%-15s%-10s", "Connection", "App", |
| 689 | "Wrk", "API Client", "ListenerID", "SegManager"); |
| 690 | else |
| 691 | s = format (s, "%-40s%-25s%=10s", "Connection", "App", "Wrk"); |
| 692 | |
| 693 | return s; |
| 694 | } |
| 695 | |
| 696 | app_name = application_name_from_index (app_wrk->app_index); |
| 697 | listener = listen_session_get_from_handle (handle); |
Florin Coras | 31c9955 | 2019-03-01 13:00:58 -0800 | [diff] [blame] | 698 | str = format (0, "%U", format_session, listener, verbose); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 699 | |
| 700 | if (verbose) |
| 701 | { |
Dave Barach | 3e07a4a | 2020-04-04 10:05:48 -0400 | [diff] [blame] | 702 | u8 *buf; |
| 703 | buf = format (0, "%u(%u)", app_wrk->wrk_map_index, app_wrk->wrk_index); |
| 704 | s = format (s, "%-40s%-25s%=10v%-15u%-15u%-10u", str, app_name, |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 705 | buf, app_wrk->api_client_index, handle, sm_index); |
Dave Barach | 3e07a4a | 2020-04-04 10:05:48 -0400 | [diff] [blame] | 706 | vec_free (buf); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 707 | } |
| 708 | else |
| 709 | s = format (s, "%-40s%-25s%=10u", str, app_name, app_wrk->wrk_map_index); |
| 710 | |
| 711 | return s; |
| 712 | } |
| 713 | |
| 714 | u8 * |
| 715 | format_app_worker (u8 * s, va_list * args) |
| 716 | { |
| 717 | app_worker_t *app_wrk = va_arg (*args, app_worker_t *); |
| 718 | u32 indent = 1; |
| 719 | |
| 720 | s = format (s, "%U wrk-index %u app-index %u map-index %u " |
| 721 | "api-client-index %d\n", format_white_space, indent, |
| 722 | app_wrk->wrk_index, app_wrk->app_index, app_wrk->wrk_map_index, |
| 723 | app_wrk->api_client_index); |
| 724 | return s; |
| 725 | } |
| 726 | |
| 727 | void |
| 728 | app_worker_format_connects (app_worker_t * app_wrk, int verbose) |
| 729 | { |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 730 | segment_manager_t *sm; |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 731 | |
| 732 | /* Header */ |
| 733 | if (!app_wrk) |
| 734 | { |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 735 | segment_manager_format_sessions (0, verbose); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 736 | return; |
| 737 | } |
| 738 | |
| 739 | if (app_wrk->connects_seg_manager == (u32) ~ 0) |
| 740 | return; |
| 741 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 742 | sm = segment_manager_get (app_wrk->connects_seg_manager); |
Florin Coras | 88001c6 | 2019-04-24 14:44:46 -0700 | [diff] [blame] | 743 | segment_manager_format_sessions (sm, verbose); |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 744 | } |
| 745 | |
Florin Coras | 623eb56 | 2019-02-03 19:28:34 -0800 | [diff] [blame] | 746 | /* |
| 747 | * fd.io coding-style-patch-verification: ON |
| 748 | * |
| 749 | * Local Variables: |
| 750 | * eval: (c-set-style "gnu") |
| 751 | * End: |
| 752 | */ |