Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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> |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 17 | #include <vnet/session/application_interface.h> |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 18 | #include <vnet/session/application_namespace.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 19 | #include <vnet/session/session.h> |
| 20 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 21 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 22 | * Pool from which we allocate all applications |
| 23 | */ |
| 24 | static application_t *app_pool; |
| 25 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 26 | /** |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 27 | * Hash table of apps by api client index |
| 28 | */ |
| 29 | static uword *app_by_api_client_index; |
| 30 | |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Hash table of builtin apps by name |
| 33 | */ |
| 34 | static uword *app_by_name; |
| 35 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 36 | static u8 * |
| 37 | app_get_name_from_reg_index (application_t * app) |
| 38 | { |
| 39 | u8 *app_name; |
| 40 | |
| 41 | vl_api_registration_t *regp; |
| 42 | regp = vl_api_client_index_to_registration (app->api_client_index); |
| 43 | if (!regp) |
| 44 | app_name = format (0, "builtin-%d%c", app->index, 0); |
| 45 | else |
| 46 | app_name = format (0, "%s%c", regp->name, 0); |
| 47 | |
| 48 | return app_name; |
| 49 | } |
| 50 | |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 51 | static u8 * |
| 52 | app_get_name (application_t * app) |
| 53 | { |
| 54 | if (!app->name) |
| 55 | return app_get_name_from_reg_index (app); |
| 56 | return app->name; |
| 57 | } |
| 58 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 59 | u32 |
| 60 | application_session_table (application_t * app, u8 fib_proto) |
| 61 | { |
| 62 | app_namespace_t *app_ns; |
| 63 | app_ns = app_namespace_get (app->ns_index); |
| 64 | if (!application_has_global_scope (app)) |
| 65 | return APP_INVALID_INDEX; |
| 66 | if (fib_proto == FIB_PROTOCOL_IP4) |
| 67 | return session_lookup_get_index_for_fib (fib_proto, |
| 68 | app_ns->ip4_fib_index); |
| 69 | else |
| 70 | return session_lookup_get_index_for_fib (fib_proto, |
| 71 | app_ns->ip6_fib_index); |
| 72 | } |
| 73 | |
| 74 | u32 |
| 75 | application_local_session_table (application_t * app) |
| 76 | { |
| 77 | app_namespace_t *app_ns; |
| 78 | if (!application_has_local_scope (app)) |
| 79 | return APP_INVALID_INDEX; |
| 80 | app_ns = app_namespace_get (app->ns_index); |
| 81 | return app_ns->local_table_index; |
| 82 | } |
| 83 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 84 | int |
| 85 | application_api_queue_is_full (application_t * app) |
| 86 | { |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 87 | svm_queue_t *q; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 88 | |
| 89 | /* builtin servers are always OK */ |
| 90 | if (app->api_client_index == ~0) |
| 91 | return 0; |
| 92 | |
| 93 | q = vl_api_client_index_to_input_queue (app->api_client_index); |
| 94 | if (!q) |
| 95 | return 1; |
| 96 | |
| 97 | if (q->cursize == q->maxsize) |
| 98 | return 1; |
| 99 | return 0; |
| 100 | } |
| 101 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Returns app name |
| 104 | * |
| 105 | * Since the name is not stored per app, we generate it on the fly. It is |
| 106 | * the caller's responsibility to free the vector |
| 107 | */ |
| 108 | u8 * |
| 109 | application_name_from_index (u32 app_index) |
| 110 | { |
| 111 | application_t *app = application_get (app_index); |
| 112 | if (!app) |
| 113 | return 0; |
| 114 | return app_get_name_from_reg_index (app); |
| 115 | } |
| 116 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 117 | static void |
| 118 | application_table_add (application_t * app) |
| 119 | { |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 120 | if (app->api_client_index != APP_INVALID_INDEX) |
| 121 | hash_set (app_by_api_client_index, app->api_client_index, app->index); |
| 122 | else if (app->name) |
| 123 | hash_set_mem (app_by_name, app->name, app->index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void |
| 127 | application_table_del (application_t * app) |
| 128 | { |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 129 | if (app->api_client_index != APP_INVALID_INDEX) |
| 130 | hash_unset (app_by_api_client_index, app->api_client_index); |
| 131 | else if (app->name) |
| 132 | hash_unset_mem (app_by_name, app->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | application_t * |
| 136 | application_lookup (u32 api_client_index) |
| 137 | { |
| 138 | uword *p; |
| 139 | p = hash_get (app_by_api_client_index, api_client_index); |
| 140 | if (p) |
| 141 | return application_get (p[0]); |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 146 | application_t * |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 147 | application_lookup_name (const u8 * name) |
| 148 | { |
| 149 | uword *p; |
| 150 | p = hash_get_mem (app_by_name, name); |
| 151 | if (p) |
| 152 | return application_get (p[0]); |
| 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | application_t * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 158 | application_new () |
| 159 | { |
| 160 | application_t *app; |
| 161 | pool_get (app_pool, app); |
| 162 | memset (app, 0, sizeof (*app)); |
| 163 | app->index = application_get_index (app); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 164 | app->connects_seg_manager = APP_INVALID_SEGMENT_MANAGER_INDEX; |
| 165 | app->first_segment_manager = APP_INVALID_SEGMENT_MANAGER_INDEX; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 166 | app->local_segment_manager = APP_INVALID_SEGMENT_MANAGER_INDEX; |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 167 | if (CLIB_DEBUG > 1) |
| 168 | clib_warning ("[%d] New app (%d)", getpid (), app->index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 169 | return app; |
| 170 | } |
| 171 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 172 | void |
| 173 | application_del (application_t * app) |
| 174 | { |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 175 | vnet_unbind_args_t _a, *a = &_a; |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 176 | u64 handle, *handles = 0; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 177 | segment_manager_t *sm; |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 178 | u32 index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 179 | int i; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 180 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 181 | /* |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 182 | * The app event queue allocated in first segment is cleared with |
| 183 | * the segment manager. No need to explicitly free it. |
| 184 | */ |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 185 | if (CLIB_DEBUG > 1) |
| 186 | clib_warning ("[%d] Delete app (%d)", getpid (), app->index); |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 187 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 188 | if (application_is_proxy (app)) |
| 189 | application_remove_proxy (app); |
| 190 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 191 | /* |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 192 | * Listener cleanup |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 193 | */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 194 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 195 | /* *INDENT-OFF* */ |
| 196 | hash_foreach (handle, index, app->listeners_table, |
| 197 | ({ |
| 198 | vec_add1 (handles, handle); |
Florin Coras | 9d06304 | 2017-09-14 03:08:00 -0400 | [diff] [blame] | 199 | sm = segment_manager_get (index); |
| 200 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 201 | })); |
| 202 | /* *INDENT-ON* */ |
| 203 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 204 | for (i = 0; i < vec_len (handles); i++) |
| 205 | { |
Florin Coras | f03a59a | 2017-06-09 21:07:32 -0700 | [diff] [blame] | 206 | a->app_index = app->index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 207 | a->handle = handles[i]; |
| 208 | /* seg manager is removed when unbind completes */ |
| 209 | vnet_unbind (a); |
| 210 | } |
| 211 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 212 | /* |
| 213 | * Connects segment manager cleanup |
| 214 | */ |
| 215 | |
| 216 | if (app->connects_seg_manager != APP_INVALID_SEGMENT_MANAGER_INDEX) |
| 217 | { |
| 218 | sm = segment_manager_get (app->connects_seg_manager); |
| 219 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 220 | segment_manager_init_del (sm); |
| 221 | } |
| 222 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 223 | /* If first segment manager is used by a listener */ |
| 224 | if (app->first_segment_manager != APP_INVALID_SEGMENT_MANAGER_INDEX |
| 225 | && app->first_segment_manager != app->connects_seg_manager) |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 226 | { |
| 227 | sm = segment_manager_get (app->first_segment_manager); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 228 | /* .. and has no fifos, e.g. it might be used for redirected sessions, |
| 229 | * remove it */ |
| 230 | if (!segment_manager_has_fifos (sm)) |
| 231 | { |
| 232 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 233 | segment_manager_del (sm); |
| 234 | } |
Dave Wallace | 7b749fe | 2017-07-05 14:30:46 -0400 | [diff] [blame] | 235 | } |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 236 | |
| 237 | /* |
| 238 | * Local connections cleanup |
| 239 | */ |
| 240 | application_local_sessions_del (app); |
| 241 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 242 | vec_free (app->tls_cert); |
| 243 | vec_free (app->tls_key); |
| 244 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 245 | application_table_del (app); |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 246 | vec_free (app->name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 247 | pool_put (app_pool, app); |
| 248 | } |
| 249 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 250 | static void |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 251 | application_verify_cb_fns (session_cb_vft_t * cb_fns) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 252 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 253 | if (cb_fns->session_accept_callback == 0) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 254 | clib_warning ("No accept callback function provided"); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 255 | if (cb_fns->session_connected_callback == 0) |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 256 | clib_warning ("No session connected callback function provided"); |
| 257 | if (cb_fns->session_disconnect_callback == 0) |
| 258 | clib_warning ("No session disconnect callback function provided"); |
| 259 | if (cb_fns->session_reset_callback == 0) |
| 260 | clib_warning ("No session reset callback function provided"); |
| 261 | } |
| 262 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 263 | /** |
| 264 | * Check app config for given segment type |
| 265 | * |
| 266 | * Returns 1 on success and 0 otherwise |
| 267 | */ |
| 268 | static u8 |
| 269 | application_verify_cfg (ssvm_segment_type_t st) |
| 270 | { |
| 271 | u8 is_valid; |
| 272 | if (st == SSVM_SEGMENT_MEMFD) |
| 273 | { |
| 274 | is_valid = (session_manager_get_evt_q_segment () != 0); |
| 275 | if (!is_valid) |
| 276 | clib_warning ("memfd seg: vpp's event qs IN binary api svm region"); |
| 277 | return is_valid; |
| 278 | } |
| 279 | else if (st == SSVM_SEGMENT_SHM) |
| 280 | { |
| 281 | is_valid = (session_manager_get_evt_q_segment () == 0); |
| 282 | if (!is_valid) |
| 283 | clib_warning ("shm seg: vpp's event qs NOT IN binary api svm region"); |
| 284 | return is_valid; |
| 285 | } |
| 286 | else |
| 287 | return 1; |
| 288 | } |
| 289 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 290 | int |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 291 | application_init (application_t * app, u32 api_client_index, u8 * app_name, |
| 292 | u64 * options, session_cb_vft_t * cb_fns) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 293 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 294 | ssvm_segment_type_t seg_type = SSVM_SEGMENT_MEMFD; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 295 | u32 first_seg_size, prealloc_fifo_pairs; |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 296 | segment_manager_properties_t *props; |
| 297 | vl_api_registration_t *reg; |
| 298 | segment_manager_t *sm; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 299 | int rv; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 300 | |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 301 | /* |
| 302 | * Make sure we support the requested configuration |
| 303 | */ |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 304 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 305 | if (!(options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_IS_BUILTIN)) |
| 306 | { |
| 307 | reg = vl_api_client_index_to_registration (api_client_index); |
| 308 | if (!reg) |
| 309 | return VNET_API_ERROR_APP_UNSUPPORTED_CFG; |
| 310 | if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) |
| 311 | seg_type = SSVM_SEGMENT_SHM; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | seg_type = SSVM_SEGMENT_PRIVATE; |
| 316 | } |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 317 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 318 | if (!application_verify_cfg (seg_type)) |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 319 | return VNET_API_ERROR_APP_UNSUPPORTED_CFG; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 320 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 321 | /* |
| 322 | * Setup segment manager |
| 323 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 324 | sm = segment_manager_new (); |
| 325 | sm->app_index = app->index; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 326 | props = application_segment_manager_properties (app); |
| 327 | segment_manager_properties_init (props); |
Florin Coras | b384b54 | 2018-01-15 01:08:33 -0800 | [diff] [blame] | 328 | if (options[APP_OPTIONS_ADD_SEGMENT_SIZE]) |
| 329 | { |
| 330 | props->add_segment_size = options[APP_OPTIONS_ADD_SEGMENT_SIZE]; |
| 331 | props->add_segment = 1; |
| 332 | } |
| 333 | if (options[APP_OPTIONS_RX_FIFO_SIZE]) |
| 334 | props->rx_fifo_size = options[APP_OPTIONS_RX_FIFO_SIZE]; |
| 335 | if (options[APP_OPTIONS_TX_FIFO_SIZE]) |
| 336 | props->tx_fifo_size = options[APP_OPTIONS_TX_FIFO_SIZE]; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 337 | if (options[APP_OPTIONS_EVT_QUEUE_SIZE]) |
| 338 | props->evt_q_size = options[APP_OPTIONS_EVT_QUEUE_SIZE]; |
Florin Coras | 58d36f0 | 2018-03-09 13:05:53 -0800 | [diff] [blame] | 339 | if (options[APP_OPTIONS_TLS_ENGINE]) |
| 340 | app->tls_engine = options[APP_OPTIONS_TLS_ENGINE]; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 341 | props->segment_type = seg_type; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 342 | |
Florin Coras | ff6e769 | 2017-12-11 04:59:01 -0800 | [diff] [blame] | 343 | first_seg_size = options[APP_OPTIONS_SEGMENT_SIZE]; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 344 | prealloc_fifo_pairs = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS]; |
| 345 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 346 | if ((rv = segment_manager_init (sm, first_seg_size, prealloc_fifo_pairs))) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 347 | return rv; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 348 | sm->first_is_protected = 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 349 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 350 | /* |
| 351 | * Setup application |
| 352 | */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 353 | app->first_segment_manager = segment_manager_index (sm); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 354 | app->api_client_index = api_client_index; |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 355 | app->flags = options[APP_OPTIONS_FLAGS]; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 356 | app->cb_fns = *cb_fns; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 357 | app->ns_index = options[APP_OPTIONS_NAMESPACE]; |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 358 | app->listeners_table = hash_create (0, sizeof (u64)); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 359 | app->local_connects = hash_create (0, sizeof (u64)); |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 360 | app->proxied_transports = options[APP_OPTIONS_PROXY_TRANSPORT]; |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 361 | app->event_queue = segment_manager_event_queue (sm); |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 362 | app->name = vec_dup (app_name); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 363 | |
| 364 | /* If no scope enabled, default to global */ |
| 365 | if (!application_has_global_scope (app) |
| 366 | && !application_has_local_scope (app)) |
| 367 | app->flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 368 | |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 369 | /* Check that the obvious things are properly set up */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 370 | application_verify_cb_fns (cb_fns); |
Florin Coras | d79b41e | 2017-03-04 05:37:52 -0800 | [diff] [blame] | 371 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 372 | /* Add app to lookup by api_client_index table */ |
| 373 | application_table_add (app); |
| 374 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 375 | /* |
| 376 | * Segment manager for local sessions |
| 377 | */ |
| 378 | sm = segment_manager_new (); |
| 379 | sm->app_index = app->index; |
| 380 | app->local_segment_manager = segment_manager_index (sm); |
| 381 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 382 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | application_t * |
| 386 | application_get (u32 index) |
| 387 | { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 388 | if (index == APP_INVALID_INDEX) |
| 389 | return 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 390 | return pool_elt_at_index (app_pool, index); |
| 391 | } |
| 392 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 393 | application_t * |
| 394 | application_get_if_valid (u32 index) |
| 395 | { |
| 396 | if (pool_is_free_index (app_pool, index)) |
| 397 | return 0; |
| 398 | |
| 399 | return pool_elt_at_index (app_pool, index); |
| 400 | } |
| 401 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 402 | u32 |
| 403 | application_get_index (application_t * app) |
| 404 | { |
| 405 | return app - app_pool; |
| 406 | } |
| 407 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 408 | static segment_manager_t * |
| 409 | application_alloc_segment_manager (application_t * app) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 410 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 411 | segment_manager_t *sm = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 412 | |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 413 | /* If the first segment manager is not in use, don't allocate a new one */ |
| 414 | if (app->first_segment_manager != APP_INVALID_SEGMENT_MANAGER_INDEX |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 415 | && app->first_segment_manager_in_use == 0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 416 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 417 | sm = segment_manager_get (app->first_segment_manager); |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 418 | app->first_segment_manager_in_use = 1; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 419 | return sm; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 420 | } |
| 421 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 422 | sm = segment_manager_new (); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 423 | sm->app_index = app->index; |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 424 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 425 | return sm; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Start listening local transport endpoint for requested transport. |
| 430 | * |
| 431 | * Creates a 'dummy' stream session with state LISTENING to be used in session |
| 432 | * lookups, prior to establishing connection. Requests transport to build |
| 433 | * it's own specific listening connection. |
| 434 | */ |
| 435 | int |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 436 | application_start_listen (application_t * srv, session_endpoint_t * sep, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 437 | session_handle_t * res) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 438 | { |
| 439 | segment_manager_t *sm; |
| 440 | stream_session_t *s; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 441 | session_handle_t handle; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 442 | session_type_t sst; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 443 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 444 | sst = session_type_from_proto_and_ip (sep->transport_proto, sep->is_ip4); |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 445 | s = listen_session_new (0, sst); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 446 | s->app_index = srv->index; |
| 447 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 448 | /* Allocate segment manager. All sessions derived out of a listen session |
| 449 | * have fifos allocated by the same segment manager. */ |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 450 | if (!(sm = application_alloc_segment_manager (srv))) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 451 | goto err; |
| 452 | |
| 453 | /* Add to app's listener table. Useful to find all child listeners |
| 454 | * when app goes down, although, just for unbinding this is not needed */ |
| 455 | handle = listen_session_get_handle (s); |
| 456 | hash_set (srv->listeners_table, handle, segment_manager_index (sm)); |
| 457 | |
Florin Coras | 7fb0fe1 | 2018-04-09 09:24:52 -0700 | [diff] [blame] | 458 | if (stream_session_listen (s, sep)) |
| 459 | { |
| 460 | segment_manager_del (sm); |
| 461 | hash_unset (srv->listeners_table, handle); |
| 462 | goto err; |
| 463 | } |
| 464 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 465 | *res = handle; |
| 466 | return 0; |
| 467 | |
| 468 | err: |
| 469 | listen_session_del (s); |
| 470 | return -1; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * Stop listening on session associated to handle |
| 475 | */ |
| 476 | int |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 477 | application_stop_listen (application_t * srv, session_handle_t handle) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 478 | { |
| 479 | stream_session_t *listener; |
| 480 | uword *indexp; |
| 481 | segment_manager_t *sm; |
| 482 | |
| 483 | if (srv && hash_get (srv->listeners_table, handle) == 0) |
| 484 | { |
| 485 | clib_warning ("app doesn't own handle %llu!", handle); |
| 486 | return -1; |
| 487 | } |
| 488 | |
| 489 | listener = listen_session_get_from_handle (handle); |
| 490 | stream_session_stop_listen (listener); |
| 491 | |
| 492 | indexp = hash_get (srv->listeners_table, handle); |
| 493 | ASSERT (indexp); |
| 494 | |
| 495 | sm = segment_manager_get (*indexp); |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 496 | if (srv->first_segment_manager == *indexp) |
| 497 | { |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 498 | /* Delete sessions but don't remove segment manager */ |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 499 | srv->first_segment_manager_in_use = 0; |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 500 | segment_manager_del_sessions (sm); |
| 501 | } |
| 502 | else |
| 503 | { |
| 504 | segment_manager_init_del (sm); |
Florin Coras | 0e9c33b | 2017-08-14 22:33:41 -0700 | [diff] [blame] | 505 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 506 | hash_unset (srv->listeners_table, handle); |
| 507 | listen_session_del (listener); |
| 508 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 509 | return 0; |
| 510 | } |
| 511 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 512 | int |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 513 | application_open_session (application_t * app, session_endpoint_t * sep, |
| 514 | u32 api_context) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 515 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 516 | int rv; |
| 517 | |
| 518 | /* Make sure we have a segment manager for connects */ |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 519 | application_alloc_connects_segment_manager (app); |
| 520 | |
| 521 | if ((rv = session_open (app->index, sep, api_context))) |
| 522 | return rv; |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | int |
| 528 | application_alloc_connects_segment_manager (application_t * app) |
| 529 | { |
| 530 | segment_manager_t *sm; |
| 531 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 532 | if (app->connects_seg_manager == APP_INVALID_SEGMENT_MANAGER_INDEX) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 533 | { |
| 534 | sm = application_alloc_segment_manager (app); |
| 535 | if (sm == 0) |
| 536 | return -1; |
| 537 | app->connects_seg_manager = segment_manager_index (sm); |
| 538 | } |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | segment_manager_t * |
| 543 | application_get_connect_segment_manager (application_t * app) |
| 544 | { |
| 545 | ASSERT (app->connects_seg_manager != (u32) ~ 0); |
| 546 | return segment_manager_get (app->connects_seg_manager); |
| 547 | } |
| 548 | |
| 549 | segment_manager_t * |
| 550 | application_get_listen_segment_manager (application_t * app, |
| 551 | stream_session_t * s) |
| 552 | { |
| 553 | uword *smp; |
| 554 | smp = hash_get (app->listeners_table, listen_session_get_handle (s)); |
| 555 | ASSERT (smp != 0); |
| 556 | return segment_manager_get (*smp); |
| 557 | } |
| 558 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 559 | segment_manager_t * |
| 560 | application_get_local_segment_manager (application_t * app) |
| 561 | { |
| 562 | return segment_manager_get (app->local_segment_manager); |
| 563 | } |
| 564 | |
| 565 | segment_manager_t * |
| 566 | application_get_local_segment_manager_w_session (application_t * app, |
| 567 | local_session_t * ls) |
| 568 | { |
| 569 | stream_session_t *listener; |
| 570 | if (application_local_session_listener_has_transport (ls)) |
| 571 | { |
Florin Coras | 5c9083d | 2018-04-13 06:39:07 -0700 | [diff] [blame] | 572 | listener = listen_session_get (ls->listener_index); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 573 | return application_get_listen_segment_manager (app, listener); |
| 574 | } |
| 575 | return segment_manager_get (app->local_segment_manager); |
| 576 | } |
| 577 | |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 578 | int |
| 579 | application_is_proxy (application_t * app) |
| 580 | { |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 581 | return (app->flags & APP_OPTIONS_FLAGS_IS_PROXY); |
| 582 | } |
| 583 | |
| 584 | int |
| 585 | application_is_builtin (application_t * app) |
| 586 | { |
| 587 | return (app->flags & APP_OPTIONS_FLAGS_IS_BUILTIN); |
| 588 | } |
| 589 | |
| 590 | int |
| 591 | application_is_builtin_proxy (application_t * app) |
| 592 | { |
| 593 | return (application_is_proxy (app) && application_is_builtin (app)); |
Dave Barach | 52851e6 | 2017-08-07 09:35:25 -0400 | [diff] [blame] | 594 | } |
| 595 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 596 | /** |
| 597 | * Send an API message to the external app, to map new segment |
| 598 | */ |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 599 | int |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 600 | application_add_segment_notify (u32 app_index, ssvm_private_t * fs) |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 601 | { |
| 602 | application_t *app = application_get (app_index); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 603 | return app->cb_fns.add_segment_callback (app->api_client_index, fs); |
Florin Coras | c87c91d | 2017-08-16 19:55:49 -0700 | [diff] [blame] | 604 | } |
| 605 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 606 | u8 |
| 607 | application_has_local_scope (application_t * app) |
| 608 | { |
| 609 | return app->flags & APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; |
| 610 | } |
| 611 | |
| 612 | u8 |
| 613 | application_has_global_scope (application_t * app) |
| 614 | { |
| 615 | return app->flags & APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; |
| 616 | } |
| 617 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 618 | u32 |
| 619 | application_n_listeners (application_t * app) |
| 620 | { |
| 621 | return hash_elts (app->listeners_table); |
| 622 | } |
| 623 | |
| 624 | stream_session_t * |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 625 | application_first_listener (application_t * app, u8 fib_proto, |
| 626 | u8 transport_proto) |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 627 | { |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 628 | stream_session_t *listener; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 629 | u64 handle; |
| 630 | u32 sm_index; |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 631 | u8 sst; |
| 632 | |
| 633 | sst = session_type_from_proto_and_ip (transport_proto, |
| 634 | fib_proto == FIB_PROTOCOL_IP4); |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 635 | |
| 636 | /* *INDENT-OFF* */ |
| 637 | hash_foreach (handle, sm_index, app->listeners_table, ({ |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 638 | listener = listen_session_get_from_handle (handle); |
Florin Coras | c3ddea8 | 2017-11-27 03:12:00 -0800 | [diff] [blame] | 639 | if (listener->session_type == sst |
| 640 | && listener->listener_index != SESSION_PROXY_LISTENER_INDEX) |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 641 | return listener; |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 642 | })); |
| 643 | /* *INDENT-ON* */ |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 648 | stream_session_t * |
| 649 | application_proxy_listener (application_t * app, u8 fib_proto, |
| 650 | u8 transport_proto) |
| 651 | { |
| 652 | stream_session_t *listener; |
| 653 | u64 handle; |
| 654 | u32 sm_index; |
| 655 | u8 sst; |
| 656 | |
| 657 | sst = session_type_from_proto_and_ip (transport_proto, |
| 658 | fib_proto == FIB_PROTOCOL_IP4); |
| 659 | |
| 660 | /* *INDENT-OFF* */ |
| 661 | hash_foreach (handle, sm_index, app->listeners_table, ({ |
| 662 | listener = listen_session_get_from_handle (handle); |
| 663 | if (listener->session_type == sst |
| 664 | && listener->listener_index == SESSION_PROXY_LISTENER_INDEX) |
| 665 | return listener; |
| 666 | })); |
| 667 | /* *INDENT-ON* */ |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 672 | static clib_error_t * |
| 673 | application_start_stop_proxy_fib_proto (application_t * app, u8 fib_proto, |
| 674 | u8 transport_proto, u8 is_start) |
| 675 | { |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 676 | app_namespace_t *app_ns = app_namespace_get (app->ns_index); |
| 677 | u8 is_ip4 = (fib_proto == FIB_PROTOCOL_IP4); |
| 678 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
| 679 | transport_connection_t *tc; |
| 680 | stream_session_t *s; |
| 681 | u64 handle; |
| 682 | |
| 683 | if (is_start) |
| 684 | { |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 685 | s = application_first_listener (app, fib_proto, transport_proto); |
| 686 | if (!s) |
| 687 | { |
| 688 | sep.is_ip4 = is_ip4; |
| 689 | sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto); |
| 690 | sep.sw_if_index = app_ns->sw_if_index; |
| 691 | sep.transport_proto = transport_proto; |
| 692 | application_start_listen (app, &sep, &handle); |
| 693 | s = listen_session_get_from_handle (handle); |
| 694 | s->listener_index = SESSION_PROXY_LISTENER_INDEX; |
| 695 | } |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 696 | } |
| 697 | else |
| 698 | { |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 699 | s = application_proxy_listener (app, fib_proto, transport_proto); |
| 700 | ASSERT (s); |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 701 | } |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 702 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 703 | tc = listen_session_get_transport (s); |
| 704 | |
| 705 | if (!ip_is_zero (&tc->lcl_ip, 1)) |
| 706 | { |
Florin Coras | dbd4456 | 2017-11-09 19:30:17 -0800 | [diff] [blame] | 707 | u32 sti; |
| 708 | sep.is_ip4 = is_ip4; |
| 709 | sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto); |
| 710 | sep.transport_proto = transport_proto; |
| 711 | sep.port = 0; |
| 712 | sti = session_lookup_get_index_for_fib (fib_proto, sep.fib_index); |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 713 | if (is_start) |
| 714 | session_lookup_add_session_endpoint (sti, &sep, s->session_index); |
| 715 | else |
| 716 | session_lookup_del_session_endpoint (sti, &sep); |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 717 | } |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 718 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 719 | return 0; |
| 720 | } |
| 721 | |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 722 | static void |
| 723 | application_start_stop_proxy_local_scope (application_t * app, |
| 724 | u8 transport_proto, u8 is_start) |
| 725 | { |
| 726 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
| 727 | app_namespace_t *app_ns; |
| 728 | app_ns = app_namespace_get (app->ns_index); |
| 729 | sep.is_ip4 = 1; |
| 730 | sep.transport_proto = transport_proto; |
| 731 | sep.port = 0; |
| 732 | |
| 733 | if (is_start) |
| 734 | { |
| 735 | session_lookup_add_session_endpoint (app_ns->local_table_index, &sep, |
| 736 | app->index); |
| 737 | sep.is_ip4 = 0; |
| 738 | session_lookup_add_session_endpoint (app_ns->local_table_index, &sep, |
| 739 | app->index); |
| 740 | } |
| 741 | else |
| 742 | { |
| 743 | session_lookup_del_session_endpoint (app_ns->local_table_index, &sep); |
| 744 | sep.is_ip4 = 0; |
| 745 | session_lookup_del_session_endpoint (app_ns->local_table_index, &sep); |
| 746 | } |
| 747 | } |
| 748 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 749 | void |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 750 | application_start_stop_proxy (application_t * app, |
| 751 | transport_proto_t transport_proto, u8 is_start) |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 752 | { |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 753 | if (application_has_local_scope (app)) |
Florin Coras | 19b1f6a | 2017-12-11 03:37:03 -0800 | [diff] [blame] | 754 | application_start_stop_proxy_local_scope (app, transport_proto, is_start); |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 755 | |
| 756 | if (application_has_global_scope (app)) |
| 757 | { |
| 758 | application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP4, |
| 759 | transport_proto, is_start); |
| 760 | application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP6, |
| 761 | transport_proto, is_start); |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | void |
| 766 | application_setup_proxy (application_t * app) |
| 767 | { |
| 768 | u16 transports = app->proxied_transports; |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 769 | transport_proto_t tp; |
| 770 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 771 | ASSERT (application_is_proxy (app)); |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 772 | |
| 773 | /* *INDENT-OFF* */ |
| 774 | transport_proto_foreach (tp, ({ |
| 775 | if (transports & (1 << tp)) |
| 776 | application_start_stop_proxy (app, tp, 1); |
| 777 | })); |
| 778 | /* *INDENT-ON* */ |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void |
| 782 | application_remove_proxy (application_t * app) |
| 783 | { |
| 784 | u16 transports = app->proxied_transports; |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 785 | transport_proto_t tp; |
| 786 | |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 787 | ASSERT (application_is_proxy (app)); |
Florin Coras | 561af9b | 2017-12-09 10:19:43 -0800 | [diff] [blame] | 788 | |
| 789 | /* *INDENT-OFF* */ |
| 790 | transport_proto_foreach (tp, ({ |
| 791 | if (transports & (1 << tp)) |
| 792 | application_start_stop_proxy (app, tp, 0); |
| 793 | })); |
| 794 | /* *INDENT-ON* */ |
Florin Coras | 7999e83 | 2017-10-31 01:51:04 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 797 | segment_manager_properties_t * |
| 798 | application_segment_manager_properties (application_t * app) |
| 799 | { |
| 800 | return &app->sm_properties; |
| 801 | } |
| 802 | |
| 803 | segment_manager_properties_t * |
| 804 | application_get_segment_manager_properties (u32 app_index) |
| 805 | { |
| 806 | application_t *app = application_get (app_index); |
| 807 | return &app->sm_properties; |
| 808 | } |
| 809 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 810 | local_session_t * |
| 811 | application_alloc_local_session (application_t * app) |
| 812 | { |
| 813 | local_session_t *s; |
| 814 | pool_get (app->local_sessions, s); |
| 815 | memset (s, 0, sizeof (*s)); |
| 816 | s->app_index = app->index; |
| 817 | s->session_index = s - app->local_sessions; |
| 818 | s->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE, 0); |
| 819 | return s; |
| 820 | } |
| 821 | |
| 822 | void |
| 823 | application_free_local_session (application_t * app, local_session_t * s) |
| 824 | { |
| 825 | pool_put (app->local_sessions, s); |
| 826 | if (CLIB_DEBUG) |
| 827 | memset (s, 0xfc, sizeof (*s)); |
| 828 | } |
| 829 | |
| 830 | local_session_t * |
| 831 | application_get_local_session (application_t * app, u32 session_index) |
| 832 | { |
| 833 | return pool_elt_at_index (app->local_sessions, session_index); |
| 834 | } |
| 835 | |
| 836 | local_session_t * |
| 837 | application_get_local_session_from_handle (session_handle_t handle) |
| 838 | { |
| 839 | application_t *server; |
| 840 | u32 session_index, server_index; |
| 841 | local_session_parse_handle (handle, &server_index, &session_index); |
| 842 | server = application_get (server_index); |
| 843 | return application_get_local_session (server, session_index); |
| 844 | } |
| 845 | |
| 846 | always_inline void |
| 847 | application_local_listener_session_endpoint (local_session_t * ll, |
| 848 | session_endpoint_t * sep) |
| 849 | { |
| 850 | sep->transport_proto = |
| 851 | session_type_transport_proto (ll->listener_session_type); |
| 852 | sep->port = ll->port; |
| 853 | sep->is_ip4 = ll->listener_session_type & 1; |
| 854 | } |
| 855 | |
| 856 | int |
| 857 | application_start_local_listen (application_t * server, |
| 858 | session_endpoint_t * sep, |
| 859 | session_handle_t * handle) |
| 860 | { |
| 861 | session_handle_t lh; |
| 862 | local_session_t *ll; |
| 863 | u32 table_index; |
| 864 | |
| 865 | table_index = application_local_session_table (server); |
| 866 | |
| 867 | /* An exact sep match, as opposed to session_lookup_local_listener */ |
| 868 | lh = session_lookup_endpoint_listener (table_index, sep, 1); |
| 869 | if (lh != SESSION_INVALID_HANDLE) |
| 870 | return VNET_API_ERROR_ADDRESS_IN_USE; |
| 871 | |
| 872 | pool_get (server->local_listen_sessions, ll); |
| 873 | memset (ll, 0, sizeof (*ll)); |
| 874 | ll->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE, 0); |
| 875 | ll->app_index = server->index; |
| 876 | ll->session_index = ll - server->local_listen_sessions; |
| 877 | ll->port = sep->port; |
| 878 | /* Store the original session type for the unbind */ |
| 879 | ll->listener_session_type = |
| 880 | session_type_from_proto_and_ip (sep->transport_proto, sep->is_ip4); |
Florin Coras | 5fda7a3 | 2018-02-14 08:04:31 -0800 | [diff] [blame] | 881 | ll->transport_listener_index = ~0; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 882 | |
| 883 | *handle = application_local_session_handle (ll); |
| 884 | session_lookup_add_session_endpoint (table_index, sep, *handle); |
| 885 | |
| 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | /** |
| 890 | * Clean up local session table. If we have a listener session use it to |
| 891 | * find the port and proto. If not, the handle must be a local table handle |
| 892 | * so parse it. |
| 893 | */ |
| 894 | int |
| 895 | application_stop_local_listen (application_t * server, session_handle_t lh) |
| 896 | { |
| 897 | session_endpoint_t sep = SESSION_ENDPOINT_NULL; |
| 898 | u32 table_index, ll_index, server_index; |
| 899 | stream_session_t *sl = 0; |
| 900 | local_session_t *ll, *ls; |
| 901 | |
| 902 | table_index = application_local_session_table (server); |
| 903 | |
| 904 | /* We have both local and global table binds. Figure from global what |
| 905 | * the sep we should be cleaning up is. |
| 906 | */ |
| 907 | if (!session_handle_is_local (lh)) |
| 908 | { |
| 909 | sl = listen_session_get_from_handle (lh); |
| 910 | if (!sl || listen_session_get_local_session_endpoint (sl, &sep)) |
| 911 | { |
| 912 | clib_warning ("broken listener"); |
| 913 | return -1; |
| 914 | } |
| 915 | lh = session_lookup_endpoint_listener (table_index, &sep, 0); |
| 916 | if (lh == SESSION_INVALID_HANDLE) |
| 917 | return -1; |
| 918 | } |
| 919 | |
| 920 | local_session_parse_handle (lh, &server_index, &ll_index); |
| 921 | ASSERT (server->index == server_index); |
| 922 | if (!(ll = application_get_local_listen_session (server, ll_index))) |
| 923 | { |
| 924 | clib_warning ("no local listener"); |
| 925 | return -1; |
| 926 | } |
| 927 | application_local_listener_session_endpoint (ll, &sep); |
| 928 | session_lookup_del_session_endpoint (table_index, &sep); |
| 929 | |
| 930 | /* *INDENT-OFF* */ |
| 931 | pool_foreach (ls, server->local_sessions, ({ |
| 932 | if (ls->listener_index == ll->session_index) |
| 933 | application_local_session_disconnect (server->index, ls); |
| 934 | })); |
| 935 | /* *INDENT-ON* */ |
| 936 | pool_put_index (server->local_listen_sessions, ll->session_index); |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | int |
| 942 | application_local_session_connect (u32 table_index, application_t * client, |
| 943 | application_t * server, |
| 944 | local_session_t * ll, u32 opaque) |
| 945 | { |
| 946 | u32 seg_size, evt_q_sz, evt_q_elts, margin = 16 << 10; |
| 947 | segment_manager_properties_t *props, *cprops; |
| 948 | int rv, has_transport, seg_index; |
| 949 | svm_fifo_segment_private_t *seg; |
| 950 | segment_manager_t *sm; |
| 951 | local_session_t *ls; |
| 952 | svm_queue_t *sq, *cq; |
| 953 | |
| 954 | ls = application_alloc_local_session (server); |
| 955 | |
| 956 | props = application_segment_manager_properties (server); |
| 957 | cprops = application_segment_manager_properties (client); |
| 958 | evt_q_elts = props->evt_q_size + cprops->evt_q_size; |
| 959 | evt_q_sz = evt_q_elts * sizeof (session_fifo_event_t); |
| 960 | seg_size = props->rx_fifo_size + props->tx_fifo_size + evt_q_sz + margin; |
| 961 | |
| 962 | has_transport = session_has_transport ((stream_session_t *) ll); |
| 963 | if (!has_transport) |
| 964 | { |
| 965 | /* Local sessions don't have backing transport */ |
| 966 | ls->port = ll->port; |
| 967 | sm = application_get_local_segment_manager (server); |
| 968 | } |
| 969 | else |
| 970 | { |
| 971 | stream_session_t *sl = (stream_session_t *) ll; |
| 972 | transport_connection_t *tc; |
| 973 | tc = listen_session_get_transport (sl); |
| 974 | ls->port = tc->lcl_port; |
| 975 | sm = application_get_listen_segment_manager (server, sl); |
| 976 | } |
| 977 | |
| 978 | seg_index = segment_manager_add_segment (sm, seg_size); |
| 979 | if (seg_index < 0) |
| 980 | { |
| 981 | clib_warning ("failed to add new cut-through segment"); |
| 982 | return seg_index; |
| 983 | } |
| 984 | seg = segment_manager_get_segment_w_lock (sm, seg_index); |
| 985 | sq = segment_manager_alloc_queue (seg, props->evt_q_size); |
| 986 | cq = segment_manager_alloc_queue (seg, cprops->evt_q_size); |
| 987 | ls->server_evt_q = pointer_to_uword (sq); |
| 988 | ls->client_evt_q = pointer_to_uword (cq); |
| 989 | rv = segment_manager_try_alloc_fifos (seg, props->rx_fifo_size, |
| 990 | props->tx_fifo_size, |
| 991 | &ls->server_rx_fifo, |
| 992 | &ls->server_tx_fifo); |
| 993 | if (rv) |
| 994 | { |
| 995 | clib_warning ("failed to add fifos in cut-through segment"); |
| 996 | segment_manager_segment_reader_unlock (sm); |
| 997 | goto failed; |
| 998 | } |
| 999 | ls->server_rx_fifo->master_session_index = ls->session_index; |
| 1000 | ls->server_tx_fifo->master_session_index = ls->session_index; |
| 1001 | ls->server_rx_fifo->master_thread_index = ~0; |
| 1002 | ls->server_tx_fifo->master_thread_index = ~0; |
| 1003 | ls->svm_segment_index = seg_index; |
| 1004 | ls->listener_index = ll->session_index; |
| 1005 | ls->client_index = client->index; |
| 1006 | ls->client_opaque = opaque; |
| 1007 | ls->listener_session_type = ll->session_type; |
| 1008 | |
| 1009 | if ((rv = server->cb_fns.add_segment_callback (server->api_client_index, |
| 1010 | &seg->ssvm))) |
| 1011 | { |
| 1012 | clib_warning ("failed to notify server of new segment"); |
| 1013 | segment_manager_segment_reader_unlock (sm); |
| 1014 | goto failed; |
| 1015 | } |
| 1016 | segment_manager_segment_reader_unlock (sm); |
| 1017 | if ((rv = server->cb_fns.session_accept_callback ((stream_session_t *) ls))) |
| 1018 | { |
| 1019 | clib_warning ("failed to send accept cut-through notify to server"); |
| 1020 | goto failed; |
| 1021 | } |
| 1022 | if (server->flags & APP_OPTIONS_FLAGS_IS_BUILTIN) |
| 1023 | application_local_session_connect_notify (ls); |
| 1024 | |
| 1025 | return 0; |
| 1026 | |
| 1027 | failed: |
| 1028 | if (!has_transport) |
| 1029 | segment_manager_del_segment (sm, seg); |
| 1030 | return rv; |
| 1031 | } |
| 1032 | |
| 1033 | static uword |
| 1034 | application_client_local_connect_key (local_session_t * ls) |
| 1035 | { |
| 1036 | return ((uword) ls->app_index << 32 | (uword) ls->session_index); |
| 1037 | } |
| 1038 | |
| 1039 | static void |
| 1040 | application_client_local_connect_key_parse (uword key, u32 * app_index, |
| 1041 | u32 * session_index) |
| 1042 | { |
| 1043 | *app_index = key >> 32; |
| 1044 | *session_index = key & 0xFFFFFFFF; |
| 1045 | } |
| 1046 | |
| 1047 | int |
| 1048 | application_local_session_connect_notify (local_session_t * ls) |
| 1049 | { |
| 1050 | svm_fifo_segment_private_t *seg; |
| 1051 | application_t *client, *server; |
| 1052 | segment_manager_t *sm; |
| 1053 | int rv, is_fail = 0; |
| 1054 | uword client_key; |
| 1055 | |
| 1056 | client = application_get (ls->client_index); |
| 1057 | server = application_get (ls->app_index); |
| 1058 | sm = application_get_local_segment_manager_w_session (server, ls); |
| 1059 | seg = segment_manager_get_segment_w_lock (sm, ls->svm_segment_index); |
| 1060 | if ((rv = client->cb_fns.add_segment_callback (client->api_client_index, |
| 1061 | &seg->ssvm))) |
| 1062 | { |
| 1063 | clib_warning ("failed to notify client %u of new segment", |
| 1064 | ls->client_index); |
| 1065 | segment_manager_segment_reader_unlock (sm); |
| 1066 | application_local_session_disconnect (ls->client_index, ls); |
| 1067 | is_fail = 1; |
| 1068 | } |
| 1069 | else |
| 1070 | { |
| 1071 | segment_manager_segment_reader_unlock (sm); |
| 1072 | } |
| 1073 | |
| 1074 | client->cb_fns.session_connected_callback (client->index, ls->client_opaque, |
| 1075 | (stream_session_t *) ls, |
| 1076 | is_fail); |
| 1077 | |
| 1078 | client_key = application_client_local_connect_key (ls); |
| 1079 | hash_set (client->local_connects, client_key, client_key); |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | int |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1084 | application_local_session_cleanup (application_t * client, |
| 1085 | application_t * server, |
| 1086 | local_session_t * ls) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1087 | { |
| 1088 | svm_fifo_segment_private_t *seg; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1089 | segment_manager_t *sm; |
| 1090 | uword client_key; |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1091 | u8 has_transport; |
| 1092 | |
| 1093 | has_transport = session_has_transport ((stream_session_t *) ls); |
| 1094 | client_key = application_client_local_connect_key (ls); |
| 1095 | if (!has_transport) |
| 1096 | sm = application_get_local_segment_manager_w_session (server, ls); |
| 1097 | else |
| 1098 | sm = application_get_listen_segment_manager (server, |
| 1099 | (stream_session_t *) ls); |
| 1100 | |
| 1101 | seg = segment_manager_get_segment (sm, ls->svm_segment_index); |
| 1102 | if (client) |
| 1103 | hash_unset (client->local_connects, client_key); |
| 1104 | |
| 1105 | if (!has_transport) |
| 1106 | { |
| 1107 | server->cb_fns.del_segment_callback (server->api_client_index, |
| 1108 | &seg->ssvm); |
| 1109 | if (client) |
| 1110 | client->cb_fns.del_segment_callback (client->api_client_index, |
| 1111 | &seg->ssvm); |
| 1112 | segment_manager_del_segment (sm, seg); |
| 1113 | } |
| 1114 | |
| 1115 | application_free_local_session (server, ls); |
| 1116 | |
| 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | int |
| 1121 | application_local_session_disconnect (u32 app_index, local_session_t * ls) |
| 1122 | { |
| 1123 | application_t *client, *server; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1124 | |
| 1125 | client = application_get_if_valid (ls->client_index); |
| 1126 | server = application_get (ls->app_index); |
| 1127 | |
| 1128 | if (ls->session_state == SESSION_STATE_CLOSED) |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1129 | return application_local_session_cleanup (client, server, ls); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1130 | |
| 1131 | if (app_index == ls->client_index) |
| 1132 | { |
| 1133 | send_local_session_disconnect_callback (ls->app_index, ls); |
| 1134 | } |
| 1135 | else |
| 1136 | { |
| 1137 | if (!client) |
| 1138 | { |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1139 | return application_local_session_cleanup (client, server, ls); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1140 | } |
| 1141 | else if (ls->session_state < SESSION_STATE_READY) |
| 1142 | { |
| 1143 | client->cb_fns.session_connected_callback (client->index, |
| 1144 | ls->client_opaque, |
| 1145 | (stream_session_t *) ls, |
| 1146 | 1 /* is_fail */ ); |
| 1147 | ls->session_state = SESSION_STATE_CLOSED; |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1148 | return application_local_session_cleanup (client, server, ls); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1149 | } |
| 1150 | else |
| 1151 | { |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1152 | send_local_session_disconnect_callback (client->index, ls); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | ls->session_state = SESSION_STATE_CLOSED; |
| 1157 | |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
Florin Coras | f6647e0 | 2018-03-23 22:56:43 -0700 | [diff] [blame] | 1161 | int |
| 1162 | application_local_session_disconnect_w_index (u32 app_index, u32 ls_index) |
| 1163 | { |
| 1164 | application_t *app; |
| 1165 | local_session_t *ls; |
| 1166 | app = application_get (app_index); |
| 1167 | ls = application_get_local_session (app, ls_index); |
| 1168 | return application_local_session_disconnect (app_index, ls); |
| 1169 | } |
| 1170 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1171 | void |
| 1172 | application_local_sessions_del (application_t * app) |
| 1173 | { |
| 1174 | u32 index, server_index, session_index, table_index; |
| 1175 | segment_manager_t *sm; |
| 1176 | u64 handle, *handles = 0; |
| 1177 | local_session_t *ls, *ll; |
| 1178 | application_t *server; |
| 1179 | session_endpoint_t sep; |
| 1180 | int i; |
| 1181 | |
| 1182 | /* |
| 1183 | * Local listens. Don't bother with local sessions, we clean them lower |
| 1184 | */ |
| 1185 | table_index = application_local_session_table (app); |
| 1186 | /* *INDENT-OFF* */ |
| 1187 | pool_foreach (ll, app->local_listen_sessions, ({ |
| 1188 | application_local_listener_session_endpoint (ll, &sep); |
| 1189 | session_lookup_del_session_endpoint (table_index, &sep); |
| 1190 | })); |
| 1191 | /* *INDENT-ON* */ |
| 1192 | |
| 1193 | /* |
| 1194 | * Local sessions |
| 1195 | */ |
| 1196 | if (app->local_sessions) |
| 1197 | { |
| 1198 | /* *INDENT-OFF* */ |
| 1199 | pool_foreach (ls, app->local_sessions, ({ |
| 1200 | application_local_session_disconnect (app->index, ls); |
| 1201 | })); |
| 1202 | /* *INDENT-ON* */ |
| 1203 | } |
| 1204 | |
| 1205 | /* |
| 1206 | * Local connects |
| 1207 | */ |
| 1208 | vec_reset_length (handles); |
| 1209 | /* *INDENT-OFF* */ |
| 1210 | hash_foreach (handle, index, app->local_connects, ({ |
| 1211 | vec_add1 (handles, handle); |
| 1212 | })); |
| 1213 | /* *INDENT-ON* */ |
| 1214 | |
| 1215 | for (i = 0; i < vec_len (handles); i++) |
| 1216 | { |
| 1217 | application_client_local_connect_key_parse (handles[i], &server_index, |
| 1218 | &session_index); |
| 1219 | server = application_get_if_valid (server_index); |
| 1220 | if (server) |
| 1221 | { |
| 1222 | ls = application_get_local_session (server, session_index); |
| 1223 | application_local_session_disconnect (app->index, ls); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | sm = segment_manager_get (app->local_segment_manager); |
| 1228 | sm->app_index = SEGMENT_MANAGER_INVALID_APP_INDEX; |
| 1229 | segment_manager_del (sm); |
| 1230 | } |
| 1231 | |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 1232 | clib_error_t * |
| 1233 | vnet_app_add_tls_cert (vnet_app_add_tls_cert_args_t * a) |
| 1234 | { |
| 1235 | application_t *app; |
| 1236 | app = application_get (a->app_index); |
| 1237 | if (!app) |
| 1238 | return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED, |
| 1239 | 0, "app %u doesn't exist", a->app_index); |
| 1240 | app->tls_cert = vec_dup (a->cert); |
| 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | clib_error_t * |
| 1245 | vnet_app_add_tls_key (vnet_app_add_tls_key_args_t * a) |
| 1246 | { |
| 1247 | application_t *app; |
| 1248 | app = application_get (a->app_index); |
| 1249 | if (!app) |
| 1250 | return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED, |
| 1251 | 0, "app %u doesn't exist", a->app_index); |
| 1252 | app->tls_key = vec_dup (a->key); |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1256 | u8 * |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1257 | format_application_listener (u8 * s, va_list * args) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1258 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1259 | application_t *app = va_arg (*args, application_t *); |
| 1260 | u64 handle = va_arg (*args, u64); |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1261 | u32 sm_index = va_arg (*args, u32); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1262 | int verbose = va_arg (*args, int); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1263 | stream_session_t *listener; |
| 1264 | u8 *app_name, *str; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1265 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1266 | if (app == 0) |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1267 | { |
| 1268 | if (verbose) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1269 | s = format (s, "%-40s%-20s%-15s%-15s%-10s", "Connection", "App", |
| 1270 | "API Client", "ListenerID", "SegManager"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1271 | else |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1272 | s = format (s, "%-40s%-20s", "Connection", "App"); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1273 | |
| 1274 | return s; |
| 1275 | } |
| 1276 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1277 | app_name = app_get_name_from_reg_index (app); |
| 1278 | listener = listen_session_get_from_handle (handle); |
| 1279 | str = format (0, "%U", format_stream_session, listener, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1280 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1281 | if (verbose) |
| 1282 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1283 | s = format (s, "%-40s%-20s%-15u%-15u%-10u", str, app_name, |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1284 | app->api_client_index, handle, sm_index); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1285 | } |
| 1286 | else |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1287 | s = format (s, "%-40s%-20s", str, app_name); |
| 1288 | |
| 1289 | vec_free (app_name); |
| 1290 | return s; |
| 1291 | } |
| 1292 | |
| 1293 | void |
| 1294 | application_format_connects (application_t * app, int verbose) |
| 1295 | { |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 1296 | svm_fifo_segment_private_t *fifo_segment; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1297 | vlib_main_t *vm = vlib_get_main (); |
| 1298 | segment_manager_t *sm; |
| 1299 | u8 *app_name, *s = 0; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1300 | |
| 1301 | /* Header */ |
| 1302 | if (app == 0) |
| 1303 | { |
| 1304 | if (verbose) |
| 1305 | vlib_cli_output (vm, "%-40s%-20s%-15s%-10s", "Connection", "App", |
| 1306 | "API Client", "SegManager"); |
| 1307 | else |
| 1308 | vlib_cli_output (vm, "%-40s%-20s", "Connection", "App"); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
| 1312 | /* make sure */ |
| 1313 | if (app->connects_seg_manager == (u32) ~ 0) |
| 1314 | return; |
| 1315 | |
| 1316 | app_name = app_get_name_from_reg_index (app); |
| 1317 | |
| 1318 | /* Across all fifo segments */ |
| 1319 | sm = segment_manager_get (app->connects_seg_manager); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1320 | |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 1321 | /* *INDENT-OFF* */ |
| 1322 | segment_manager_foreach_segment_w_lock (fifo_segment, sm, ({ |
| 1323 | svm_fifo_t *fifo; |
| 1324 | u8 *str; |
| 1325 | |
| 1326 | fifo = svm_fifo_segment_get_fifo_list (fifo_segment); |
| 1327 | while (fifo) |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1328 | { |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1329 | u32 session_index, thread_index; |
| 1330 | stream_session_t *session; |
| 1331 | |
Florin Coras | a546481 | 2017-04-19 13:00:05 -0700 | [diff] [blame] | 1332 | session_index = fifo->master_session_index; |
| 1333 | thread_index = fifo->master_thread_index; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1334 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1335 | session = session_get (session_index, thread_index); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1336 | str = format (0, "%U", format_stream_session, session, verbose); |
| 1337 | |
| 1338 | if (verbose) |
| 1339 | s = format (s, "%-40s%-20s%-15u%-10u", str, app_name, |
| 1340 | app->api_client_index, app->connects_seg_manager); |
| 1341 | else |
| 1342 | s = format (s, "%-40s%-20s", str, app_name); |
| 1343 | |
| 1344 | vlib_cli_output (vm, "%v", s); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1345 | vec_reset_length (s); |
| 1346 | vec_free (str); |
Dave Barach | 10d8cc6 | 2017-05-30 09:30:07 -0400 | [diff] [blame] | 1347 | |
| 1348 | fifo = fifo->next; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1349 | } |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 1350 | vec_free (s); |
| 1351 | })); |
| 1352 | /* *INDENT-ON* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1353 | |
| 1354 | vec_free (app_name); |
| 1355 | } |
| 1356 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1357 | void |
| 1358 | application_format_local_sessions (application_t * app, int verbose) |
| 1359 | { |
| 1360 | vlib_main_t *vm = vlib_get_main (); |
| 1361 | local_session_t *ls; |
| 1362 | transport_proto_t tp; |
| 1363 | u8 *conn = 0; |
| 1364 | |
| 1365 | /* Header */ |
| 1366 | if (app == 0) |
| 1367 | { |
| 1368 | vlib_cli_output (vm, "%-40s%-15s%-20s", "Connection", "ServerApp", |
| 1369 | "ClientApp"); |
| 1370 | return; |
| 1371 | } |
| 1372 | |
| 1373 | /* *INDENT-OFF* */ |
| 1374 | pool_foreach (ls, app->local_listen_sessions, ({ |
| 1375 | tp = session_type_transport_proto(ls->listener_session_type); |
| 1376 | conn = format (0, "[L][%U] *:%u", format_transport_proto_short, tp, |
| 1377 | ls->port); |
| 1378 | vlib_cli_output (vm, "%-40v%-15u%-20s", conn, ls->app_index, "*"); |
| 1379 | vec_reset_length (conn); |
| 1380 | })); |
| 1381 | pool_foreach (ls, app->local_sessions, ({ |
| 1382 | tp = session_type_transport_proto(ls->listener_session_type); |
| 1383 | conn = format (0, "[L][%U] *:%u", format_transport_proto_short, tp, |
| 1384 | ls->port); |
| 1385 | vlib_cli_output (vm, "%-40v%-15u%-20u", conn, ls->app_index, |
| 1386 | ls->client_index); |
| 1387 | vec_reset_length (conn); |
| 1388 | })); |
| 1389 | /* *INDENT-ON* */ |
| 1390 | |
| 1391 | vec_free (conn); |
| 1392 | } |
| 1393 | |
| 1394 | void |
| 1395 | application_format_local_connects (application_t * app, int verbose) |
| 1396 | { |
| 1397 | vlib_main_t *vm = vlib_get_main (); |
| 1398 | u32 app_index, session_index; |
| 1399 | application_t *server; |
| 1400 | local_session_t *ls; |
| 1401 | uword client_key; |
| 1402 | u64 value; |
| 1403 | |
| 1404 | /* Header */ |
| 1405 | if (app == 0) |
| 1406 | { |
| 1407 | if (verbose) |
| 1408 | vlib_cli_output (vm, "%-40s%-15s%-20s%-10s", "Connection", "App", |
| 1409 | "Peer App", "SegManager"); |
| 1410 | else |
| 1411 | vlib_cli_output (vm, "%-40s%-15s%-20s", "Connection", "App", |
| 1412 | "Peer App"); |
| 1413 | return; |
| 1414 | } |
| 1415 | |
| 1416 | /* *INDENT-OFF* */ |
| 1417 | hash_foreach (client_key, value, app->local_connects, ({ |
| 1418 | application_client_local_connect_key_parse (client_key, &app_index, |
| 1419 | &session_index); |
| 1420 | server = application_get (app_index); |
| 1421 | ls = application_get_local_session (server, session_index); |
| 1422 | vlib_cli_output (vm, "%-40s%-15s%-20s", "TODO", ls->app_index, ls->client_index); |
| 1423 | })); |
| 1424 | /* *INDENT-ON* */ |
| 1425 | } |
| 1426 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1427 | u8 * |
| 1428 | format_application (u8 * s, va_list * args) |
| 1429 | { |
| 1430 | application_t *app = va_arg (*args, application_t *); |
| 1431 | CLIB_UNUSED (int verbose) = va_arg (*args, int); |
Florin Coras | ad0c77f | 2017-11-09 18:00:15 -0800 | [diff] [blame] | 1432 | segment_manager_properties_t *props; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1433 | const u8 *app_ns_name; |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1434 | u8 *app_name; |
| 1435 | |
| 1436 | if (app == 0) |
| 1437 | { |
| 1438 | if (verbose) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1439 | s = format (s, "%-10s%-20s%-15s%-15s%-15s%-15s%-15s", "Index", "Name", |
Florin Coras | 078371e | 2018-05-11 09:20:12 -0700 | [diff] [blame] | 1440 | "API Client", "Namespace", "Add seg size", "Rx-f size", |
| 1441 | "Tx-f size"); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1442 | else |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 1443 | s = format (s, "%-10s%-20s%-15s%-40s", "Index", "Name", "API Client", |
| 1444 | "Namespace"); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1445 | return s; |
| 1446 | } |
| 1447 | |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 1448 | app_name = app_get_name (app); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1449 | app_ns_name = app_namespace_id_from_index (app->ns_index); |
Florin Coras | a332c46 | 2018-01-31 06:52:17 -0800 | [diff] [blame] | 1450 | props = application_segment_manager_properties (app); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1451 | if (verbose) |
Florin Coras | 078371e | 2018-05-11 09:20:12 -0700 | [diff] [blame] | 1452 | s = format (s, "%-10u%-20s%-15d%-15u%-15U%-15U%-15U", app->index, |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 1453 | app_name, app->api_client_index, app->ns_index, |
Florin Coras | 078371e | 2018-05-11 09:20:12 -0700 | [diff] [blame] | 1454 | format_memory_size, props->add_segment_size, |
| 1455 | format_memory_size, props->rx_fifo_size, format_memory_size, |
Florin Coras | 0bee9ce | 2018-03-22 21:24:31 -0700 | [diff] [blame] | 1456 | props->tx_fifo_size); |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1457 | else |
Florin Coras | 078371e | 2018-05-11 09:20:12 -0700 | [diff] [blame] | 1458 | s = format (s, "%-10u%-20s%-15d%-40s", app->index, app_name, |
Florin Coras | 8f107b3 | 2017-11-21 22:13:03 -0800 | [diff] [blame] | 1459 | app->api_client_index, app_ns_name); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1460 | return s; |
| 1461 | } |
| 1462 | |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1463 | |
| 1464 | void |
| 1465 | application_format_all_listeners (vlib_main_t * vm, int do_local, int verbose) |
| 1466 | { |
| 1467 | application_t *app; |
| 1468 | u32 sm_index; |
| 1469 | u64 handle; |
| 1470 | |
| 1471 | if (!pool_elts (app_pool)) |
| 1472 | { |
| 1473 | vlib_cli_output (vm, "No active server bindings"); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
| 1477 | if (do_local) |
| 1478 | { |
| 1479 | application_format_local_sessions (0, verbose); |
| 1480 | /* *INDENT-OFF* */ |
| 1481 | pool_foreach (app, app_pool, ({ |
| 1482 | if (!pool_elts (app->local_sessions) |
| 1483 | && !pool_elts(app->local_connects)) |
| 1484 | continue; |
| 1485 | application_format_local_sessions (app, verbose); |
| 1486 | })); |
| 1487 | /* *INDENT-ON* */ |
| 1488 | } |
| 1489 | else |
| 1490 | { |
| 1491 | vlib_cli_output (vm, "%U", format_application_listener, 0 /* header */ , |
| 1492 | 0, 0, verbose); |
| 1493 | |
| 1494 | /* *INDENT-OFF* */ |
| 1495 | pool_foreach (app, app_pool, ({ |
| 1496 | if (hash_elts (app->listeners_table) == 0) |
| 1497 | continue; |
| 1498 | hash_foreach (handle, sm_index, app->listeners_table, ({ |
| 1499 | vlib_cli_output (vm, "%U", format_application_listener, app, |
| 1500 | handle, sm_index, verbose); |
| 1501 | })); |
| 1502 | })); |
| 1503 | /* *INDENT-ON* */ |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | void |
| 1508 | application_format_all_clients (vlib_main_t * vm, int do_local, int verbose) |
| 1509 | { |
| 1510 | application_t *app; |
| 1511 | |
| 1512 | if (!pool_elts (app_pool)) |
| 1513 | { |
| 1514 | vlib_cli_output (vm, "No active apps"); |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | if (do_local) |
| 1519 | { |
| 1520 | application_format_local_connects (0, verbose); |
| 1521 | |
| 1522 | /* *INDENT-OFF* */ |
| 1523 | pool_foreach (app, app_pool, ({ |
| 1524 | if (app->local_connects) |
| 1525 | application_format_local_connects (app, verbose); |
| 1526 | })); |
| 1527 | /* *INDENT-ON* */ |
| 1528 | } |
| 1529 | else |
| 1530 | { |
| 1531 | application_format_connects (0, verbose); |
| 1532 | |
| 1533 | /* *INDENT-OFF* */ |
| 1534 | pool_foreach (app, app_pool, ({ |
| 1535 | if (app->connects_seg_manager == (u32)~0) |
| 1536 | continue; |
| 1537 | application_format_connects (app, verbose); |
| 1538 | })); |
| 1539 | /* *INDENT-ON* */ |
| 1540 | } |
| 1541 | } |
| 1542 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1543 | static clib_error_t * |
| 1544 | show_app_command_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1545 | vlib_cli_command_t * cmd) |
| 1546 | { |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1547 | int do_server = 0, do_client = 0, do_local = 0; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1548 | application_t *app; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1549 | int verbose = 0; |
| 1550 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1551 | session_cli_return_if_not_enabled (); |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1552 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1553 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 1554 | { |
| 1555 | if (unformat (input, "server")) |
| 1556 | do_server = 1; |
| 1557 | else if (unformat (input, "client")) |
| 1558 | do_client = 1; |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1559 | else if (unformat (input, "local")) |
| 1560 | do_local = 1; |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1561 | else if (unformat (input, "verbose")) |
| 1562 | verbose = 1; |
| 1563 | else |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | if (do_server) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1568 | application_format_all_listeners (vm, do_local, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1569 | |
| 1570 | if (do_client) |
Florin Coras | f8f516a | 2018-02-08 15:10:09 -0800 | [diff] [blame] | 1571 | application_format_all_clients (vm, do_local, verbose); |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1572 | |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1573 | /* Print app related info */ |
| 1574 | if (!do_server && !do_client) |
| 1575 | { |
| 1576 | vlib_cli_output (vm, "%U", format_application, 0, verbose); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1577 | /* *INDENT-OFF* */ |
| 1578 | pool_foreach (app, app_pool, ({ |
| 1579 | vlib_cli_output (vm, "%U", format_application, app, verbose); |
| 1580 | })); |
| 1581 | /* *INDENT-ON* */ |
Florin Coras | 6cf30ad | 2017-04-04 23:08:23 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1584 | return 0; |
| 1585 | } |
| 1586 | |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1587 | /* *INDENT-OFF* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1588 | VLIB_CLI_COMMAND (show_app_command, static) = |
| 1589 | { |
Florin Coras | e04c299 | 2017-03-01 08:17:34 -0800 | [diff] [blame] | 1590 | .path = "show app", |
| 1591 | .short_help = "show app [server|client] [verbose]", |
| 1592 | .function = show_app_command_fn, |
| 1593 | }; |
| 1594 | /* *INDENT-ON* */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 1595 | |
| 1596 | /* |
| 1597 | * fd.io coding-style-patch-verification: ON |
| 1598 | * |
| 1599 | * Local Variables: |
| 1600 | * eval: (c-set-style "gnu") |
| 1601 | * End: |
| 1602 | */ |