blob: d4f3d61ab613e4b718e747095d1adffd5971eba5 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
Florin Coras288eaab2019-02-03 15:26:14 -08002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Dave Barach68b0fb02017-02-28 15:15:56 -05003 * 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 Coras6cf30ad2017-04-04 23:08:23 -070017#include <vnet/session/application_interface.h>
Florin Corascea194d2017-10-02 00:18:51 -070018#include <vnet/session/application_namespace.h>
Florin Corasba7d8f52019-02-22 13:11:38 -080019#include <vnet/session/application_local.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050020#include <vnet/session/session.h>
21
Florin Coras15531972018-08-12 23:50:53 -070022static app_main_t app_main;
Dave Barach68b0fb02017-02-28 15:15:56 -050023
Florin Corasc1a42652019-02-08 18:27:29 -080024#define app_interface_check_thread_and_barrier(_fn, _arg) \
25 if (PREDICT_FALSE (!vlib_thread_is_main_w_barrier ())) \
26 { \
27 vlib_rpc_call_main_thread (_fn, (u8 *) _arg, sizeof(*_arg)); \
28 return 0; \
29 }
30
Florin Corasab2f6db2018-08-31 14:31:41 -070031static app_listener_t *
32app_listener_alloc (application_t * app)
33{
34 app_listener_t *app_listener;
35 pool_get (app->listeners, app_listener);
Dave Barachb7b92992018-10-17 10:38:51 -040036 clib_memset (app_listener, 0, sizeof (*app_listener));
Florin Corasab2f6db2018-08-31 14:31:41 -070037 app_listener->al_index = app_listener - app->listeners;
Florin Corasc9940fc2019-02-05 20:55:11 -080038 app_listener->app_index = app->app_index;
39 app_listener->session_index = SESSION_INVALID_INDEX;
40 app_listener->local_index = SESSION_INVALID_INDEX;
Florin Coras87d66332019-06-11 12:31:31 -070041 app_listener->ls_handle = SESSION_INVALID_HANDLE;
Florin Corasab2f6db2018-08-31 14:31:41 -070042 return app_listener;
43}
44
Florin Corasc9940fc2019-02-05 20:55:11 -080045app_listener_t *
Florin Corasab2f6db2018-08-31 14:31:41 -070046app_listener_get (application_t * app, u32 app_listener_index)
47{
48 return pool_elt_at_index (app->listeners, app_listener_index);
49}
50
51static void
52app_listener_free (application_t * app, app_listener_t * app_listener)
53{
54 clib_bitmap_free (app_listener->workers);
55 pool_put (app->listeners, app_listener);
56 if (CLIB_DEBUG)
Dave Barachb7b92992018-10-17 10:38:51 -040057 clib_memset (app_listener, 0xfa, sizeof (*app_listener));
Florin Corasab2f6db2018-08-31 14:31:41 -070058}
59
Florin Corasc9940fc2019-02-05 20:55:11 -080060session_handle_t
61app_listener_handle (app_listener_t * al)
62{
Florin Coras87d66332019-06-11 12:31:31 -070063 return al->ls_handle;
Florin Corasc9940fc2019-02-05 20:55:11 -080064}
65
66app_listener_t *
67app_listener_get_w_session (session_t * ls)
68{
69 application_t *app;
70
71 app = application_get_if_valid (ls->app_index);
72 if (!app)
73 return 0;
74 return app_listener_get (app, ls->al_index);
75}
76
Florin Coras87d66332019-06-11 12:31:31 -070077session_handle_t
78app_listen_session_handle (session_t * ls)
79{
80 app_listener_t *al;
81 al = app_listener_get_w_session (ls);
82 if (!al)
83 return listen_session_get_handle (ls);
84 return al->ls_handle;
85}
86
Florin Corasc9940fc2019-02-05 20:55:11 -080087app_listener_t *
88app_listener_get_w_handle (session_handle_t handle)
89{
Florin Coras87d66332019-06-11 12:31:31 -070090 session_t *ls;
91 ls = session_get_from_handle_if_valid (handle);
92 if (!ls)
Florin Corasc9940fc2019-02-05 20:55:11 -080093 return 0;
Florin Coras87d66332019-06-11 12:31:31 -070094 return app_listener_get_w_session (ls);
Florin Corasc9940fc2019-02-05 20:55:11 -080095}
96
97app_listener_t *
98app_listener_lookup (application_t * app, session_endpoint_cfg_t * sep_ext)
99{
100 u32 table_index, fib_proto;
101 session_endpoint_t *sep;
102 session_handle_t handle;
Florin Corasc9940fc2019-02-05 20:55:11 -0800103 session_t *ls;
104
105 sep = (session_endpoint_t *) sep_ext;
106 if (application_has_local_scope (app) && session_endpoint_is_local (sep))
107 {
108 table_index = application_local_session_table (app);
109 handle = session_lookup_endpoint_listener (table_index, sep, 1);
110 if (handle != SESSION_INVALID_HANDLE)
111 {
Florin Corasd4295e62019-02-22 13:11:38 -0800112 ls = listen_session_get_from_handle (handle);
113 return app_listener_get_w_session (ls);
Florin Corasc9940fc2019-02-05 20:55:11 -0800114 }
115 }
116
117 fib_proto = session_endpoint_fib_proto (sep);
118 table_index = application_session_table (app, fib_proto);
119 handle = session_lookup_endpoint_listener (table_index, sep, 1);
120 if (handle != SESSION_INVALID_HANDLE)
121 {
122 ls = listen_session_get_from_handle (handle);
123 return app_listener_get_w_session ((session_t *) ls);
124 }
125
126 return 0;
127}
128
129int
130app_listener_alloc_and_init (application_t * app,
131 session_endpoint_cfg_t * sep,
132 app_listener_t ** listener)
133{
134 app_listener_t *app_listener;
Florin Corasd4295e62019-02-22 13:11:38 -0800135 transport_connection_t *tc;
Florin Corasc9940fc2019-02-05 20:55:11 -0800136 session_handle_t lh;
137 session_type_t st;
138 session_t *ls = 0;
Florin Corasa27a46e2019-02-18 13:02:28 -0800139 u32 al_index;
Florin Corasc9940fc2019-02-05 20:55:11 -0800140 int rv;
141
142 app_listener = app_listener_alloc (app);
Florin Corasa27a46e2019-02-18 13:02:28 -0800143 al_index = app_listener->al_index;
Florin Corasc9940fc2019-02-05 20:55:11 -0800144 st = session_type_from_proto_and_ip (sep->transport_proto, sep->is_ip4);
145
146 /*
147 * Add session endpoint to local session table. Only binds to "inaddr_any"
148 * (i.e., zero address) are added to local scope table.
149 */
150 if (application_has_local_scope (app)
151 && session_endpoint_is_local ((session_endpoint_t *) sep))
152 {
Florin Corasd4295e62019-02-22 13:11:38 -0800153 session_type_t local_st;
Florin Corasc9940fc2019-02-05 20:55:11 -0800154 u32 table_index;
155
Florin Corasd4295e62019-02-22 13:11:38 -0800156 local_st = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE,
157 sep->is_ip4);
158 ls = listen_session_alloc (0, local_st);
159 ls->app_index = app->app_index;
160 ls->app_wrk_index = sep->app_wrk_index;
161 lh = session_handle (ls);
162
163 if ((rv = session_listen (ls, sep)))
164 {
165 ls = session_get_from_handle (lh);
166 session_free (ls);
167 return rv;
168 }
169
170 ls = session_get_from_handle (lh);
171 app_listener = app_listener_get (app, al_index);
172 app_listener->local_index = ls->session_index;
Florin Coras87d66332019-06-11 12:31:31 -0700173 app_listener->ls_handle = lh;
Florin Corasd4295e62019-02-22 13:11:38 -0800174 ls->al_index = al_index;
175
Florin Corasc9940fc2019-02-05 20:55:11 -0800176 table_index = application_local_session_table (app);
Florin Corasc9940fc2019-02-05 20:55:11 -0800177 session_lookup_add_session_endpoint (table_index,
178 (session_endpoint_t *) sep, lh);
Florin Corasc9940fc2019-02-05 20:55:11 -0800179 }
180
181 if (application_has_global_scope (app))
182 {
183 /*
184 * Start listening on local endpoint for requested transport and scope.
185 * Creates a stream session with state LISTENING to be used in session
186 * lookups, prior to establishing connection. Requests transport to
187 * build it's own specific listening connection.
188 */
Florin Corasba7d8f52019-02-22 13:11:38 -0800189 ls = listen_session_alloc (0, st);
Florin Corasc9940fc2019-02-05 20:55:11 -0800190 ls->app_index = app->app_index;
191 ls->app_wrk_index = sep->app_wrk_index;
192
193 /* Listen pool can be reallocated if the transport is
194 * recursive (tls) */
Florin Corasd4295e62019-02-22 13:11:38 -0800195 lh = listen_session_get_handle (ls);
Florin Corasc9940fc2019-02-05 20:55:11 -0800196
197 if ((rv = session_listen (ls, sep)))
198 {
Florin Corasd4295e62019-02-22 13:11:38 -0800199 ls = listen_session_get_from_handle (lh);
Florin Corasc9940fc2019-02-05 20:55:11 -0800200 session_free (ls);
201 return rv;
202 }
Florin Corasd4295e62019-02-22 13:11:38 -0800203 ls = listen_session_get_from_handle (lh);
Florin Corasa27a46e2019-02-18 13:02:28 -0800204 app_listener = app_listener_get (app, al_index);
Florin Corasc9940fc2019-02-05 20:55:11 -0800205 app_listener->session_index = ls->session_index;
Florin Coras87d66332019-06-11 12:31:31 -0700206 app_listener->ls_handle = lh;
Florin Corasa27a46e2019-02-18 13:02:28 -0800207 ls->al_index = al_index;
Florin Corasd4295e62019-02-22 13:11:38 -0800208
209 /* Add to the global lookup table after transport was initialized.
210 * Lookup table needs to be populated only now because sessions
211 * with cut-through transport are are added to app local tables that
212 * are not related to network fibs, i.e., cannot be added as
213 * connections */
214 tc = session_get_transport (ls);
Nathan Skrzypczak2eed1a12019-07-04 14:26:21 +0200215 if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
216 session_lookup_add_connection (tc, lh);
Florin Corasc9940fc2019-02-05 20:55:11 -0800217 }
218
Florin Coras2b81e3c2019-02-27 07:55:46 -0800219 if (!ls)
Florin Corasc9940fc2019-02-05 20:55:11 -0800220 {
221 app_listener_free (app, app_listener);
222 return -1;
223 }
224
225 *listener = app_listener;
226 return 0;
227}
228
229void
230app_listener_cleanup (app_listener_t * al)
231{
232 application_t *app = application_get (al->app_index);
Florin Corasd4295e62019-02-22 13:11:38 -0800233 session_t *ls;
Florin Corasc9940fc2019-02-05 20:55:11 -0800234
235 if (al->session_index != SESSION_INVALID_INDEX)
236 {
Florin Corasd4295e62019-02-22 13:11:38 -0800237 ls = session_get (al->session_index, 0);
Florin Corasc9940fc2019-02-05 20:55:11 -0800238 session_stop_listen (ls);
Florin Corasba7d8f52019-02-22 13:11:38 -0800239 listen_session_free (ls);
Florin Corasc9940fc2019-02-05 20:55:11 -0800240 }
241 if (al->local_index != SESSION_INVALID_INDEX)
242 {
243 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
Florin Corasc9940fc2019-02-05 20:55:11 -0800244 u32 table_index;
245
246 table_index = application_local_session_table (app);
Florin Corasd4295e62019-02-22 13:11:38 -0800247 ls = listen_session_get (al->local_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800248 ct_session_endpoint (ls, &sep);
Florin Corasc9940fc2019-02-05 20:55:11 -0800249 session_lookup_del_session_endpoint (table_index, &sep);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800250 session_stop_listen (ls);
Florin Corasd4295e62019-02-22 13:11:38 -0800251 listen_session_free (ls);
Florin Corasc9940fc2019-02-05 20:55:11 -0800252 }
253 app_listener_free (app, al);
254}
255
Florin Coras11e2cf52019-03-06 12:04:24 -0800256static app_worker_t *
257app_listener_select_worker (application_t * app, app_listener_t * al)
Florin Corasc9940fc2019-02-05 20:55:11 -0800258{
Florin Corasc9940fc2019-02-05 20:55:11 -0800259 u32 wrk_index;
260
261 app = application_get (al->app_index);
262 wrk_index = clib_bitmap_next_set (al->workers, al->accept_rotor + 1);
263 if (wrk_index == ~0)
264 wrk_index = clib_bitmap_first_set (al->workers);
265
266 ASSERT (wrk_index != ~0);
267 al->accept_rotor = wrk_index;
268 return application_get_worker (app, wrk_index);
269}
270
271session_t *
272app_listener_get_session (app_listener_t * al)
273{
274 if (al->session_index == SESSION_INVALID_INDEX)
275 return 0;
276
277 return listen_session_get (al->session_index);
Florin Corasab2f6db2018-08-31 14:31:41 -0700278}
279
Florin Corasd4295e62019-02-22 13:11:38 -0800280session_t *
281app_listener_get_local_session (app_listener_t * al)
282{
283 if (al->local_index == SESSION_INVALID_INDEX)
284 return 0;
285 return listen_session_get (al->local_index);
286}
287
Florin Coras15531972018-08-12 23:50:53 -0700288static app_worker_map_t *
289app_worker_map_alloc (application_t * app)
290{
291 app_worker_map_t *map;
292 pool_get (app->worker_maps, map);
Dave Barachb7b92992018-10-17 10:38:51 -0400293 clib_memset (map, 0, sizeof (*map));
Florin Coras15531972018-08-12 23:50:53 -0700294 return map;
295}
Dave Barach68b0fb02017-02-28 15:15:56 -0500296
Florin Coras15531972018-08-12 23:50:53 -0700297static u32
298app_worker_map_index (application_t * app, app_worker_map_t * map)
299{
300 return (map - app->worker_maps);
301}
302
303static void
304app_worker_map_free (application_t * app, app_worker_map_t * map)
305{
306 pool_put (app->worker_maps, map);
307}
308
309static app_worker_map_t *
310app_worker_map_get (application_t * app, u32 map_index)
311{
Florin Coras01f3f892018-12-02 12:45:53 -0800312 if (pool_is_free_index (app->worker_maps, map_index))
313 return 0;
Florin Coras15531972018-08-12 23:50:53 -0700314 return pool_elt_at_index (app->worker_maps, map_index);
315}
Florin Coras0bee9ce2018-03-22 21:24:31 -0700316
Florin Coras053a0e42018-11-13 15:52:38 -0800317static const u8 *
Florin Coras0bee9ce2018-03-22 21:24:31 -0700318app_get_name (application_t * app)
319{
Florin Coras0bee9ce2018-03-22 21:24:31 -0700320 return app->name;
321}
322
Florin Corascea194d2017-10-02 00:18:51 -0700323u32
324application_session_table (application_t * app, u8 fib_proto)
325{
326 app_namespace_t *app_ns;
327 app_ns = app_namespace_get (app->ns_index);
328 if (!application_has_global_scope (app))
329 return APP_INVALID_INDEX;
330 if (fib_proto == FIB_PROTOCOL_IP4)
331 return session_lookup_get_index_for_fib (fib_proto,
332 app_ns->ip4_fib_index);
333 else
334 return session_lookup_get_index_for_fib (fib_proto,
335 app_ns->ip6_fib_index);
336}
337
338u32
339application_local_session_table (application_t * app)
340{
341 app_namespace_t *app_ns;
342 if (!application_has_local_scope (app))
343 return APP_INVALID_INDEX;
344 app_ns = app_namespace_get (app->ns_index);
345 return app_ns->local_table_index;
346}
347
Florin Corascea194d2017-10-02 00:18:51 -0700348/**
Florin Coras053a0e42018-11-13 15:52:38 -0800349 * Returns app name for app-index
Florin Corascea194d2017-10-02 00:18:51 -0700350 */
Florin Coras053a0e42018-11-13 15:52:38 -0800351const u8 *
Florin Corascea194d2017-10-02 00:18:51 -0700352application_name_from_index (u32 app_index)
353{
354 application_t *app = application_get (app_index);
355 if (!app)
356 return 0;
Florin Coras053a0e42018-11-13 15:52:38 -0800357 return app_get_name (app);
358}
359
360static void
361application_api_table_add (u32 app_index, u32 api_client_index)
362{
Florin Corasc1f5a432018-11-20 11:31:26 -0800363 if (api_client_index != APP_INVALID_INDEX)
364 hash_set (app_main.app_by_api_client_index, api_client_index, app_index);
Florin Coras053a0e42018-11-13 15:52:38 -0800365}
366
367static void
368application_api_table_del (u32 api_client_index)
369{
370 hash_unset (app_main.app_by_api_client_index, api_client_index);
Florin Corascea194d2017-10-02 00:18:51 -0700371}
372
Dave Barach68b0fb02017-02-28 15:15:56 -0500373static void
Florin Corasc1f5a432018-11-20 11:31:26 -0800374application_name_table_add (application_t * app)
Dave Barach68b0fb02017-02-28 15:15:56 -0500375{
Florin Corasc1f5a432018-11-20 11:31:26 -0800376 hash_set_mem (app_main.app_by_name, app->name, app->app_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500377}
378
379static void
Florin Corasc1f5a432018-11-20 11:31:26 -0800380application_name_table_del (application_t * app)
Dave Barach68b0fb02017-02-28 15:15:56 -0500381{
Florin Corasc1f5a432018-11-20 11:31:26 -0800382 hash_unset_mem (app_main.app_by_name, app->name);
Dave Barach68b0fb02017-02-28 15:15:56 -0500383}
384
385application_t *
386application_lookup (u32 api_client_index)
387{
388 uword *p;
Florin Coras15531972018-08-12 23:50:53 -0700389 p = hash_get (app_main.app_by_api_client_index, api_client_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500390 if (p)
Florin Coras053a0e42018-11-13 15:52:38 -0800391 return application_get_if_valid (p[0]);
Dave Barach68b0fb02017-02-28 15:15:56 -0500392
393 return 0;
394}
395
Florin Coras6cf30ad2017-04-04 23:08:23 -0700396application_t *
Florin Coras0bee9ce2018-03-22 21:24:31 -0700397application_lookup_name (const u8 * name)
398{
399 uword *p;
Florin Coras15531972018-08-12 23:50:53 -0700400 p = hash_get_mem (app_main.app_by_name, name);
Florin Coras0bee9ce2018-03-22 21:24:31 -0700401 if (p)
402 return application_get (p[0]);
403
404 return 0;
405}
406
Florin Corasc1a42652019-02-08 18:27:29 -0800407static application_t *
Florin Coras15531972018-08-12 23:50:53 -0700408application_alloc (void)
Florin Coras6cf30ad2017-04-04 23:08:23 -0700409{
410 application_t *app;
Florin Coras15531972018-08-12 23:50:53 -0700411 pool_get (app_main.app_pool, app);
Dave Barachb7b92992018-10-17 10:38:51 -0400412 clib_memset (app, 0, sizeof (*app));
Florin Coras15531972018-08-12 23:50:53 -0700413 app->app_index = app - app_main.app_pool;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700414 return app;
415}
416
Florin Coras15531972018-08-12 23:50:53 -0700417application_t *
418application_get (u32 app_index)
Dave Barach68b0fb02017-02-28 15:15:56 -0500419{
Florin Coras15531972018-08-12 23:50:53 -0700420 if (app_index == APP_INVALID_INDEX)
421 return 0;
422 return pool_elt_at_index (app_main.app_pool, app_index);
423}
Dave Barach68b0fb02017-02-28 15:15:56 -0500424
Florin Coras15531972018-08-12 23:50:53 -0700425application_t *
426application_get_if_valid (u32 app_index)
427{
428 if (pool_is_free_index (app_main.app_pool, app_index))
429 return 0;
Florin Corasa5464812017-04-19 13:00:05 -0700430
Florin Coras15531972018-08-12 23:50:53 -0700431 return pool_elt_at_index (app_main.app_pool, app_index);
432}
Florin Coras7999e832017-10-31 01:51:04 -0700433
Florin Corasd79b41e2017-03-04 05:37:52 -0800434static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700435application_verify_cb_fns (session_cb_vft_t * cb_fns)
Florin Corasd79b41e2017-03-04 05:37:52 -0800436{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700437 if (cb_fns->session_accept_callback == 0)
Florin Corasd79b41e2017-03-04 05:37:52 -0800438 clib_warning ("No accept callback function provided");
Florin Coras6cf30ad2017-04-04 23:08:23 -0700439 if (cb_fns->session_connected_callback == 0)
Florin Corasd79b41e2017-03-04 05:37:52 -0800440 clib_warning ("No session connected callback function provided");
441 if (cb_fns->session_disconnect_callback == 0)
442 clib_warning ("No session disconnect callback function provided");
443 if (cb_fns->session_reset_callback == 0)
444 clib_warning ("No session reset callback function provided");
445}
446
Florin Corasb384b542018-01-15 01:08:33 -0800447/**
448 * Check app config for given segment type
449 *
450 * Returns 1 on success and 0 otherwise
451 */
452static u8
453application_verify_cfg (ssvm_segment_type_t st)
454{
455 u8 is_valid;
456 if (st == SSVM_SEGMENT_MEMFD)
457 {
Florin Coras31c99552019-03-01 13:00:58 -0800458 is_valid = (session_main_get_evt_q_segment () != 0);
Florin Corasb384b542018-01-15 01:08:33 -0800459 if (!is_valid)
460 clib_warning ("memfd seg: vpp's event qs IN binary api svm region");
461 return is_valid;
462 }
463 else if (st == SSVM_SEGMENT_SHM)
464 {
Florin Coras31c99552019-03-01 13:00:58 -0800465 is_valid = (session_main_get_evt_q_segment () == 0);
Florin Corasb384b542018-01-15 01:08:33 -0800466 if (!is_valid)
467 clib_warning ("shm seg: vpp's event qs NOT IN binary api svm region");
468 return is_valid;
469 }
470 else
471 return 1;
472}
473
Florin Corasc1a42652019-02-08 18:27:29 -0800474static int
Florin Coras15531972018-08-12 23:50:53 -0700475application_alloc_and_init (app_init_args_t * a)
Dave Barach68b0fb02017-02-28 15:15:56 -0500476{
Florin Corasa332c462018-01-31 06:52:17 -0800477 ssvm_segment_type_t seg_type = SSVM_SEGMENT_MEMFD;
Florin Coras88001c62019-04-24 14:44:46 -0700478 segment_manager_props_t *props;
Florin Corasb384b542018-01-15 01:08:33 -0800479 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700480 application_t *app;
481 u64 *options;
Dave Barach68b0fb02017-02-28 15:15:56 -0500482
Florin Coras15531972018-08-12 23:50:53 -0700483 app = application_alloc ();
484 options = a->options;
Florin Corasb384b542018-01-15 01:08:33 -0800485 /*
486 * Make sure we support the requested configuration
487 */
Florin Corasa332c462018-01-31 06:52:17 -0800488 if (!(options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_IS_BUILTIN))
489 {
Florin Coras15531972018-08-12 23:50:53 -0700490 reg = vl_api_client_index_to_registration (a->api_client_index);
Florin Corasa332c462018-01-31 06:52:17 -0800491 if (!reg)
492 return VNET_API_ERROR_APP_UNSUPPORTED_CFG;
493 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
494 seg_type = SSVM_SEGMENT_SHM;
495 }
496 else
497 {
498 seg_type = SSVM_SEGMENT_PRIVATE;
499 }
Florin Corasb384b542018-01-15 01:08:33 -0800500
Florin Corasd8402ae2019-03-03 16:46:52 -0800501 if ((options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
502 && seg_type != SSVM_SEGMENT_MEMFD)
503 {
504 clib_warning ("mq eventfds can only be used if socket transport is "
505 "used for binary api");
506 return VNET_API_ERROR_APP_UNSUPPORTED_CFG;
507 }
508
Florin Corasa332c462018-01-31 06:52:17 -0800509 if (!application_verify_cfg (seg_type))
Florin Corasb384b542018-01-15 01:08:33 -0800510 return VNET_API_ERROR_APP_UNSUPPORTED_CFG;
Dave Barach68b0fb02017-02-28 15:15:56 -0500511
Florin Coras15531972018-08-12 23:50:53 -0700512 /* Check that the obvious things are properly set up */
513 application_verify_cb_fns (a->session_cb_vft);
514
Florin Coras15531972018-08-12 23:50:53 -0700515 app->flags = options[APP_OPTIONS_FLAGS];
516 app->cb_fns = *a->session_cb_vft;
517 app->ns_index = options[APP_OPTIONS_NAMESPACE];
518 app->proxied_transports = options[APP_OPTIONS_PROXY_TRANSPORT];
519 app->name = vec_dup (a->name);
520
521 /* If no scope enabled, default to global */
522 if (!application_has_global_scope (app)
523 && !application_has_local_scope (app))
524 app->flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
525
Florin Corasa332c462018-01-31 06:52:17 -0800526 props = application_segment_manager_properties (app);
Florin Coras88001c62019-04-24 14:44:46 -0700527 segment_manager_props_init (props);
Florin Coras404b8a32019-05-09 12:08:06 -0700528 props->segment_size = options[APP_OPTIONS_SEGMENT_SIZE];
Florin Coras15531972018-08-12 23:50:53 -0700529 props->prealloc_fifos = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS];
Florin Corasb384b542018-01-15 01:08:33 -0800530 if (options[APP_OPTIONS_ADD_SEGMENT_SIZE])
531 {
532 props->add_segment_size = options[APP_OPTIONS_ADD_SEGMENT_SIZE];
533 props->add_segment = 1;
534 }
535 if (options[APP_OPTIONS_RX_FIFO_SIZE])
536 props->rx_fifo_size = options[APP_OPTIONS_RX_FIFO_SIZE];
537 if (options[APP_OPTIONS_TX_FIFO_SIZE])
538 props->tx_fifo_size = options[APP_OPTIONS_TX_FIFO_SIZE];
Florin Corasf8f516a2018-02-08 15:10:09 -0800539 if (options[APP_OPTIONS_EVT_QUEUE_SIZE])
540 props->evt_q_size = options[APP_OPTIONS_EVT_QUEUE_SIZE];
Florin Coras99368312018-08-02 10:45:44 -0700541 if (options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
542 props->use_mq_eventfd = 1;
Florin Coras58d36f02018-03-09 13:05:53 -0800543 if (options[APP_OPTIONS_TLS_ENGINE])
544 app->tls_engine = options[APP_OPTIONS_TLS_ENGINE];
Florin Corasa332c462018-01-31 06:52:17 -0800545 props->segment_type = seg_type;
Dave Barach68b0fb02017-02-28 15:15:56 -0500546
Florin Coras15531972018-08-12 23:50:53 -0700547 /* Add app to lookup by api_client_index table */
Florin Corasc1f5a432018-11-20 11:31:26 -0800548 if (!application_is_builtin (app))
549 application_api_table_add (app->app_index, a->api_client_index);
550 else
551 application_name_table_add (app);
552
553 a->app_index = app->app_index;
Florin Corasa332c462018-01-31 06:52:17 -0800554
Florin Coras15531972018-08-12 23:50:53 -0700555 APP_DBG ("New app name: %v api index: %u index %u", app->name,
Nathan Skrzypczakba65ca42019-05-16 16:35:40 +0200556 a->api_client_index, app->app_index);
Florin Coras15531972018-08-12 23:50:53 -0700557
558 return 0;
559}
560
Florin Corasc1a42652019-02-08 18:27:29 -0800561static void
Florin Coras15531972018-08-12 23:50:53 -0700562application_free (application_t * app)
563{
564 app_worker_map_t *wrk_map;
565 app_worker_t *app_wrk;
566
567 /*
568 * The app event queue allocated in first segment is cleared with
569 * the segment manager. No need to explicitly free it.
570 */
Nathan Skrzypczakba65ca42019-05-16 16:35:40 +0200571 APP_DBG ("Delete app name %v index: %d", app->name, app->app_index);
Florin Coras15531972018-08-12 23:50:53 -0700572
573 if (application_is_proxy (app))
574 application_remove_proxy (app);
575
Florin Corasab2f6db2018-08-31 14:31:41 -0700576 /*
577 * Free workers
578 */
579
Florin Coras15531972018-08-12 23:50:53 -0700580 /* *INDENT-OFF* */
581 pool_flush (wrk_map, app->worker_maps, ({
582 app_wrk = app_worker_get (wrk_map->wrk_index);
583 app_worker_free (app_wrk);
584 }));
585 /* *INDENT-ON* */
586 pool_free (app->worker_maps);
587
Florin Corasab2f6db2018-08-31 14:31:41 -0700588 /*
Florin Corasab2f6db2018-08-31 14:31:41 -0700589 * Cleanup remaining state
590 */
Florin Corasc1f5a432018-11-20 11:31:26 -0800591 if (application_is_builtin (app))
592 application_name_table_del (app);
Florin Coras15531972018-08-12 23:50:53 -0700593 vec_free (app->name);
594 vec_free (app->tls_cert);
595 vec_free (app->tls_key);
596 pool_put (app_main.app_pool, app);
597}
598
Florin Corasc1a42652019-02-08 18:27:29 -0800599static void
Florin Coras053a0e42018-11-13 15:52:38 -0800600application_detach_process (application_t * app, u32 api_client_index)
601{
602 vnet_app_worker_add_del_args_t _args = { 0 }, *args = &_args;
603 app_worker_map_t *wrk_map;
604 u32 *wrks = 0, *wrk_index;
605 app_worker_t *app_wrk;
606
607 if (api_client_index == ~0)
608 {
609 application_free (app);
610 return;
611 }
612
613 APP_DBG ("Detaching for app %v index %u api client index %u", app->name,
Nathan Skrzypczakba65ca42019-05-16 16:35:40 +0200614 app->app_index, api_client_index);
Florin Coras053a0e42018-11-13 15:52:38 -0800615
616 /* *INDENT-OFF* */
617 pool_foreach (wrk_map, app->worker_maps, ({
618 app_wrk = app_worker_get (wrk_map->wrk_index);
Florin Corasc1f5a432018-11-20 11:31:26 -0800619 if (app_wrk->api_client_index == api_client_index)
Florin Coras053a0e42018-11-13 15:52:38 -0800620 vec_add1 (wrks, app_wrk->wrk_index);
621 }));
622 /* *INDENT-ON* */
623
624 if (!vec_len (wrks))
625 {
626 clib_warning ("no workers for app %u api_index %u", app->app_index,
627 api_client_index);
628 return;
629 }
630
631 args->app_index = app->app_index;
Florin Corasc1f5a432018-11-20 11:31:26 -0800632 args->api_client_index = api_client_index;
Florin Coras053a0e42018-11-13 15:52:38 -0800633 vec_foreach (wrk_index, wrks)
634 {
635 app_wrk = app_worker_get (wrk_index[0]);
Florin Coras349f8ca2018-11-20 16:52:49 -0800636 args->wrk_map_index = app_wrk->wrk_map_index;
Florin Coras053a0e42018-11-13 15:52:38 -0800637 args->is_add = 0;
638 vnet_app_worker_add_del (args);
639 }
640 vec_free (wrks);
641}
642
Florin Coras15531972018-08-12 23:50:53 -0700643app_worker_t *
644application_get_worker (application_t * app, u32 wrk_map_index)
645{
646 app_worker_map_t *map;
647 map = app_worker_map_get (app, wrk_map_index);
648 if (!map)
649 return 0;
650 return app_worker_get (map->wrk_index);
651}
652
653app_worker_t *
654application_get_default_worker (application_t * app)
655{
656 return application_get_worker (app, 0);
657}
658
Florin Coras053a0e42018-11-13 15:52:38 -0800659u32
660application_n_workers (application_t * app)
661{
662 return pool_elts (app->worker_maps);
663}
664
Florin Coras15531972018-08-12 23:50:53 -0700665app_worker_t *
Florin Corasc9940fc2019-02-05 20:55:11 -0800666application_listener_select_worker (session_t * ls)
Florin Corasab2f6db2018-08-31 14:31:41 -0700667{
Florin Coras11e2cf52019-03-06 12:04:24 -0800668 application_t *app;
Florin Corasc9940fc2019-02-05 20:55:11 -0800669 app_listener_t *al;
Florin Corasab2f6db2018-08-31 14:31:41 -0700670
Florin Coras11e2cf52019-03-06 12:04:24 -0800671 app = application_get (ls->app_index);
672 al = app_listener_get (app, ls->al_index);
673 return app_listener_select_worker (app, al);
Florin Corasab2f6db2018-08-31 14:31:41 -0700674}
675
Florin Coras15531972018-08-12 23:50:53 -0700676int
Florin Coras623eb562019-02-03 19:28:34 -0800677application_alloc_worker_and_init (application_t * app, app_worker_t ** wrk)
Florin Coras15531972018-08-12 23:50:53 -0700678{
679 app_worker_map_t *wrk_map;
680 app_worker_t *app_wrk;
681 segment_manager_t *sm;
682 int rv;
683
684 app_wrk = app_worker_alloc (app);
685 wrk_map = app_worker_map_alloc (app);
686 wrk_map->wrk_index = app_wrk->wrk_index;
687 app_wrk->wrk_map_index = app_worker_map_index (app, wrk_map);
688
689 /*
690 * Setup first segment manager
691 */
Florin Coras88001c62019-04-24 14:44:46 -0700692 sm = segment_manager_alloc ();
Florin Coras15531972018-08-12 23:50:53 -0700693 sm->app_wrk_index = app_wrk->wrk_index;
694
695 if ((rv = segment_manager_init (sm, app->sm_properties.segment_size,
696 app->sm_properties.prealloc_fifos)))
697 {
698 app_worker_free (app_wrk);
699 return rv;
700 }
Florin Corasc87c91d2017-08-16 19:55:49 -0700701 sm->first_is_protected = 1;
Dave Barach68b0fb02017-02-28 15:15:56 -0500702
Florin Corascea194d2017-10-02 00:18:51 -0700703 /*
Florin Coras15531972018-08-12 23:50:53 -0700704 * Setup app worker
Florin Corascea194d2017-10-02 00:18:51 -0700705 */
Florin Coras15531972018-08-12 23:50:53 -0700706 app_wrk->first_segment_manager = segment_manager_index (sm);
707 app_wrk->listeners_table = hash_create (0, sizeof (u64));
708 app_wrk->event_queue = segment_manager_event_queue (sm);
709 app_wrk->app_is_builtin = application_is_builtin (app);
Dave Barach68b0fb02017-02-28 15:15:56 -0500710
Florin Coras15531972018-08-12 23:50:53 -0700711 *wrk = app_wrk;
Florin Corasf8f516a2018-02-08 15:10:09 -0800712
Florin Coras6cf30ad2017-04-04 23:08:23 -0700713 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500714}
715
Florin Coras623eb562019-02-03 19:28:34 -0800716int
Florin Corasc1a42652019-02-08 18:27:29 -0800717vnet_app_worker_add_del (vnet_app_worker_add_del_args_t * a)
718{
Florin Coras88001c62019-04-24 14:44:46 -0700719 fifo_segment_t *fs;
Florin Corasc1a42652019-02-08 18:27:29 -0800720 app_worker_map_t *wrk_map;
721 app_worker_t *app_wrk;
722 segment_manager_t *sm;
723 application_t *app;
724 int rv;
725
726 app = application_get (a->app_index);
727 if (!app)
728 return VNET_API_ERROR_INVALID_VALUE;
729
730 if (a->is_add)
731 {
732 if ((rv = application_alloc_worker_and_init (app, &app_wrk)))
733 return rv;
734
735 /* Map worker api index to the app */
736 app_wrk->api_client_index = a->api_client_index;
737 application_api_table_add (app->app_index, a->api_client_index);
738
739 sm = segment_manager_get (app_wrk->first_segment_manager);
740 fs = segment_manager_get_segment_w_lock (sm, 0);
741 a->segment = &fs->ssvm;
742 a->segment_handle = segment_manager_segment_handle (sm, fs);
743 segment_manager_segment_reader_unlock (sm);
744 a->evt_q = app_wrk->event_queue;
745 a->wrk_map_index = app_wrk->wrk_map_index;
746 }
747 else
748 {
749 wrk_map = app_worker_map_get (app, a->wrk_map_index);
750 if (!wrk_map)
751 return VNET_API_ERROR_INVALID_VALUE;
752
753 app_wrk = app_worker_get (wrk_map->wrk_index);
754 if (!app_wrk)
755 return VNET_API_ERROR_INVALID_VALUE;
756
757 application_api_table_del (app_wrk->api_client_index);
758 app_worker_free (app_wrk);
759 app_worker_map_free (app, wrk_map);
760 if (application_n_workers (app) == 0)
761 application_free (app);
762 }
763 return 0;
764}
765
766static int
767app_validate_namespace (u8 * namespace_id, u64 secret, u32 * app_ns_index)
768{
769 app_namespace_t *app_ns;
770 if (vec_len (namespace_id) == 0)
771 {
772 /* Use default namespace */
773 *app_ns_index = 0;
774 return 0;
775 }
776
777 *app_ns_index = app_namespace_index_from_id (namespace_id);
778 if (*app_ns_index == APP_NAMESPACE_INVALID_INDEX)
779 return VNET_API_ERROR_APP_INVALID_NS;
780 app_ns = app_namespace_get (*app_ns_index);
781 if (!app_ns)
782 return VNET_API_ERROR_APP_INVALID_NS;
783 if (app_ns->ns_secret != secret)
784 return VNET_API_ERROR_APP_WRONG_NS_SECRET;
785 return 0;
786}
787
788static u8 *
789app_name_from_api_index (u32 api_client_index)
790{
791 vl_api_registration_t *regp;
792 regp = vl_api_client_index_to_registration (api_client_index);
793 if (regp)
Florin Corasbee97682019-04-09 16:13:18 -0700794 return format (0, "%s", regp->name);
Florin Corasc1a42652019-02-08 18:27:29 -0800795
796 clib_warning ("api client index %u does not have an api registration!",
797 api_client_index);
Florin Corasbee97682019-04-09 16:13:18 -0700798 return format (0, "unknown");
Florin Corasc1a42652019-02-08 18:27:29 -0800799}
800
801/**
802 * Attach application to vpp
803 *
804 * Allocates a vpp app, i.e., a structure that keeps back pointers
805 * to external app and a segment manager for shared memory fifo based
806 * communication with the external app.
807 */
808int
809vnet_application_attach (vnet_app_attach_args_t * a)
810{
Florin Coras88001c62019-04-24 14:44:46 -0700811 fifo_segment_t *fs;
Florin Corasc1a42652019-02-08 18:27:29 -0800812 application_t *app = 0;
813 app_worker_t *app_wrk;
814 segment_manager_t *sm;
815 u32 app_ns_index = 0;
816 u8 *app_name = 0;
817 u64 secret;
818 int rv;
819
820 if (a->api_client_index != APP_INVALID_INDEX)
821 app = application_lookup (a->api_client_index);
822 else if (a->name)
823 app = application_lookup_name (a->name);
824 else
825 return VNET_API_ERROR_INVALID_VALUE;
826
827 if (app)
828 return VNET_API_ERROR_APP_ALREADY_ATTACHED;
829
830 if (a->api_client_index != APP_INVALID_INDEX)
831 {
832 app_name = app_name_from_api_index (a->api_client_index);
833 a->name = app_name;
834 }
835
836 secret = a->options[APP_OPTIONS_NAMESPACE_SECRET];
837 if ((rv = app_validate_namespace (a->namespace_id, secret, &app_ns_index)))
838 return rv;
839 a->options[APP_OPTIONS_NAMESPACE] = app_ns_index;
840
841 if ((rv = application_alloc_and_init ((app_init_args_t *) a)))
842 return rv;
843
844 app = application_get (a->app_index);
845 if ((rv = application_alloc_worker_and_init (app, &app_wrk)))
846 return rv;
847
848 a->app_evt_q = app_wrk->event_queue;
849 app_wrk->api_client_index = a->api_client_index;
850 sm = segment_manager_get (app_wrk->first_segment_manager);
851 fs = segment_manager_get_segment_w_lock (sm, 0);
852
853 if (application_is_proxy (app))
854 application_setup_proxy (app);
855
856 ASSERT (vec_len (fs->ssvm.name) <= 128);
857 a->segment = &fs->ssvm;
858 a->segment_handle = segment_manager_segment_handle (sm, fs);
859
860 segment_manager_segment_reader_unlock (sm);
861 vec_free (app_name);
862 return 0;
863}
864
865/**
866 * Detach application from vpp
867 */
868int
869vnet_application_detach (vnet_app_detach_args_t * a)
870{
871 application_t *app;
872
873 app = application_get_if_valid (a->app_index);
874 if (!app)
875 {
876 clib_warning ("app not attached");
877 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
878 }
879
880 app_interface_check_thread_and_barrier (vnet_application_detach, a);
881 application_detach_process (app, a->api_client_index);
882 return 0;
883}
884
885
886static u8
887session_endpoint_in_ns (session_endpoint_t * sep)
888{
889 u8 is_lep = session_endpoint_is_local (sep);
890 if (!is_lep && sep->sw_if_index != ENDPOINT_INVALID_INDEX
891 && !ip_interface_has_address (sep->sw_if_index, &sep->ip, sep->is_ip4))
892 {
893 clib_warning ("sw_if_index %u not configured with ip %U",
894 sep->sw_if_index, format_ip46_address, &sep->ip,
895 sep->is_ip4);
896 return 0;
897 }
898 return (is_lep || ip_is_local (sep->fib_index, &sep->ip, sep->is_ip4));
899}
900
901static void
902session_endpoint_update_for_app (session_endpoint_cfg_t * sep,
903 application_t * app, u8 is_connect)
904{
905 app_namespace_t *app_ns;
906 u32 ns_index, fib_index;
907
908 ns_index = app->ns_index;
909
910 /* App is a transport proto, so fetch the calling app's ns */
911 if (app->flags & APP_OPTIONS_FLAGS_IS_TRANSPORT_APP)
Florin Coras8a140612019-02-18 22:39:39 -0800912 ns_index = sep->ns_index;
Florin Corasc1a42652019-02-08 18:27:29 -0800913
Florin Corasc1a42652019-02-08 18:27:29 -0800914 app_ns = app_namespace_get (ns_index);
915 if (!app_ns)
916 return;
917
918 /* Ask transport and network to bind to/connect using local interface
919 * that "supports" app's namespace. This will fix our local connection
920 * endpoint.
921 */
922
923 /* If in default namespace and user requested a fib index use it */
924 if (ns_index == 0 && sep->fib_index != ENDPOINT_INVALID_INDEX)
925 fib_index = sep->fib_index;
926 else
927 fib_index = sep->is_ip4 ? app_ns->ip4_fib_index : app_ns->ip6_fib_index;
928 sep->peer.fib_index = fib_index;
929 sep->fib_index = fib_index;
930
931 if (!is_connect)
932 {
933 sep->sw_if_index = app_ns->sw_if_index;
934 }
935 else
936 {
937 if (app_ns->sw_if_index != APP_NAMESPACE_INVALID_INDEX
938 && sep->peer.sw_if_index != ENDPOINT_INVALID_INDEX
939 && sep->peer.sw_if_index != app_ns->sw_if_index)
940 clib_warning ("Local sw_if_index different from app ns sw_if_index");
941
942 sep->peer.sw_if_index = app_ns->sw_if_index;
943 }
944}
945
946int
947vnet_listen (vnet_listen_args_t * a)
948{
949 app_listener_t *app_listener;
950 app_worker_t *app_wrk;
951 application_t *app;
952 int rv;
953
Florin Coras458089b2019-08-21 16:20:44 -0700954 ASSERT (vlib_thread_is_main_w_barrier ());
955
Florin Corasc1a42652019-02-08 18:27:29 -0800956 app = application_get_if_valid (a->app_index);
957 if (!app)
958 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
959
960 app_wrk = application_get_worker (app, a->wrk_map_index);
961 if (!app_wrk)
962 return VNET_API_ERROR_INVALID_VALUE;
963
964 a->sep_ext.app_wrk_index = app_wrk->wrk_index;
965
966 session_endpoint_update_for_app (&a->sep_ext, app, 0 /* is_connect */ );
967 if (!session_endpoint_in_ns (&a->sep))
968 return VNET_API_ERROR_INVALID_VALUE_2;
969
970 /*
971 * Check if we already have an app listener
972 */
973 app_listener = app_listener_lookup (app, &a->sep_ext);
974 if (app_listener)
975 {
976 if (app_listener->app_index != app->app_index)
977 return VNET_API_ERROR_ADDRESS_IN_USE;
978 if (app_worker_start_listen (app_wrk, app_listener))
979 return -1;
980 a->handle = app_listener_handle (app_listener);
981 return 0;
982 }
983
984 /*
985 * Create new app listener
986 */
987 if ((rv = app_listener_alloc_and_init (app, &a->sep_ext, &app_listener)))
988 return rv;
989
990 if ((rv = app_worker_start_listen (app_wrk, app_listener)))
991 {
992 app_listener_cleanup (app_listener);
993 return rv;
994 }
995
996 a->handle = app_listener_handle (app_listener);
997 return 0;
998}
999
1000int
1001vnet_connect (vnet_connect_args_t * a)
1002{
Florin Coras2b81e3c2019-02-27 07:55:46 -08001003 app_worker_t *client_wrk;
Florin Corasc1a42652019-02-08 18:27:29 -08001004 application_t *client;
Florin Corasc1a42652019-02-08 18:27:29 -08001005
Florin Coras458089b2019-08-21 16:20:44 -07001006 ASSERT (vlib_thread_is_main_w_barrier ());
1007
Florin Corasc1a42652019-02-08 18:27:29 -08001008 if (session_endpoint_is_zero (&a->sep))
1009 return VNET_API_ERROR_INVALID_VALUE;
1010
1011 client = application_get (a->app_index);
1012 session_endpoint_update_for_app (&a->sep_ext, client, 1 /* is_connect */ );
1013 client_wrk = application_get_worker (client, a->wrk_map_index);
1014
1015 /*
1016 * First check the local scope for locally attached destinations.
1017 * If we have local scope, we pass *all* connects through it since we may
1018 * have special policy rules even for non-local destinations, think proxy.
1019 */
1020 if (application_has_local_scope (client))
1021 {
Florin Coras2b81e3c2019-02-27 07:55:46 -08001022 int rv;
Florin Corasc1a42652019-02-08 18:27:29 -08001023
Florin Coras2b81e3c2019-02-27 07:55:46 -08001024 a->sep_ext.original_tp = a->sep_ext.transport_proto;
1025 a->sep_ext.transport_proto = TRANSPORT_PROTO_NONE;
1026 rv = app_worker_connect_session (client_wrk, &a->sep, a->api_context);
1027 if (rv <= 0)
1028 return rv;
Florin Corasc1a42652019-02-08 18:27:29 -08001029 }
Florin Corasc1a42652019-02-08 18:27:29 -08001030 /*
1031 * Not connecting to a local server, propagate to transport
1032 */
1033 if (app_worker_connect_session (client_wrk, &a->sep, a->api_context))
1034 return VNET_API_ERROR_SESSION_CONNECT;
1035 return 0;
1036}
1037
1038int
1039vnet_unlisten (vnet_unlisten_args_t * a)
1040{
1041 app_worker_t *app_wrk;
1042 app_listener_t *al;
1043 application_t *app;
1044
Florin Coras458089b2019-08-21 16:20:44 -07001045 ASSERT (vlib_thread_is_main_w_barrier ());
1046
Florin Corasc1a42652019-02-08 18:27:29 -08001047 if (!(app = application_get_if_valid (a->app_index)))
1048 return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1049
Florin Coras92311f62019-03-01 19:26:31 -08001050 if (!(al = app_listener_get_w_handle (a->handle)))
1051 return -1;
1052
Florin Corasc1a42652019-02-08 18:27:29 -08001053 if (al->app_index != app->app_index)
1054 {
1055 clib_warning ("app doesn't own handle %llu!", a->handle);
1056 return -1;
1057 }
1058
1059 app_wrk = application_get_worker (app, a->wrk_map_index);
1060 if (!app_wrk)
1061 {
1062 clib_warning ("no app %u worker %u", app->app_index, a->wrk_map_index);
1063 return -1;
1064 }
1065
1066 return app_worker_stop_listen (app_wrk, al);
1067}
1068
1069int
1070vnet_disconnect_session (vnet_disconnect_args_t * a)
1071{
Florin Coras2b81e3c2019-02-27 07:55:46 -08001072 app_worker_t *app_wrk;
1073 session_t *s;
Florin Corasc1a42652019-02-08 18:27:29 -08001074
Florin Coras2b81e3c2019-02-27 07:55:46 -08001075 s = session_get_from_handle_if_valid (a->handle);
1076 if (!s)
1077 return VNET_API_ERROR_INVALID_VALUE;
1078 app_wrk = app_worker_get (s->app_wrk_index);
1079 if (app_wrk->app_index != a->app_index)
1080 return VNET_API_ERROR_INVALID_VALUE;
Florin Corasc1a42652019-02-08 18:27:29 -08001081
Florin Coras2b81e3c2019-02-27 07:55:46 -08001082 /* We're peeking into another's thread pool. Make sure */
1083 ASSERT (s->session_index == session_index_from_handle (a->handle));
Florin Corasc1a42652019-02-08 18:27:29 -08001084
Florin Coras2b81e3c2019-02-27 07:55:46 -08001085 session_close (s);
Florin Corasc1a42652019-02-08 18:27:29 -08001086 return 0;
1087}
1088
1089int
Florin Coras623eb562019-02-03 19:28:34 -08001090application_change_listener_owner (session_t * s, app_worker_t * app_wrk)
1091{
1092 app_worker_t *old_wrk = app_worker_get (s->app_wrk_index);
1093 app_listener_t *app_listener;
1094 application_t *app;
1095
1096 if (!old_wrk)
1097 return -1;
1098
1099 hash_unset (old_wrk->listeners_table, listen_session_get_handle (s));
1100 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL
1101 && s->rx_fifo)
Florin Coras19223e02019-03-03 14:56:05 -08001102 segment_manager_dealloc_fifos (s->rx_fifo, s->tx_fifo);
Florin Coras623eb562019-02-03 19:28:34 -08001103
Florin Coras623eb562019-02-03 19:28:34 -08001104 app = application_get (old_wrk->app_index);
1105 if (!app)
1106 return -1;
1107
Florin Corasc9940fc2019-02-05 20:55:11 -08001108 app_listener = app_listener_get (app, s->al_index);
1109
1110 /* Only remove from lb for now */
Florin Coras623eb562019-02-03 19:28:34 -08001111 app_listener->workers = clib_bitmap_set (app_listener->workers,
1112 old_wrk->wrk_map_index, 0);
Florin Coras623eb562019-02-03 19:28:34 -08001113
Florin Corasc9940fc2019-02-05 20:55:11 -08001114 if (app_worker_start_listen (app_wrk, app_listener))
1115 return -1;
Florin Corasab2f6db2018-08-31 14:31:41 -07001116
Florin Corasc9940fc2019-02-05 20:55:11 -08001117 s->app_wrk_index = app_wrk->wrk_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001118
Dave Barach68b0fb02017-02-28 15:15:56 -05001119 return 0;
1120}
1121
Dave Barach52851e62017-08-07 09:35:25 -04001122int
1123application_is_proxy (application_t * app)
1124{
Florin Coras7999e832017-10-31 01:51:04 -07001125 return (app->flags & APP_OPTIONS_FLAGS_IS_PROXY);
1126}
1127
1128int
1129application_is_builtin (application_t * app)
1130{
1131 return (app->flags & APP_OPTIONS_FLAGS_IS_BUILTIN);
1132}
1133
1134int
1135application_is_builtin_proxy (application_t * app)
1136{
1137 return (application_is_proxy (app) && application_is_builtin (app));
Dave Barach52851e62017-08-07 09:35:25 -04001138}
1139
Florin Corascea194d2017-10-02 00:18:51 -07001140u8
1141application_has_local_scope (application_t * app)
1142{
1143 return app->flags & APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1144}
1145
1146u8
1147application_has_global_scope (application_t * app)
1148{
1149 return app->flags & APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
1150}
1151
Florin Coras7999e832017-10-31 01:51:04 -07001152static clib_error_t *
1153application_start_stop_proxy_fib_proto (application_t * app, u8 fib_proto,
1154 u8 transport_proto, u8 is_start)
1155{
Florin Coras7999e832017-10-31 01:51:04 -07001156 app_namespace_t *app_ns = app_namespace_get (app->ns_index);
1157 u8 is_ip4 = (fib_proto == FIB_PROTOCOL_IP4);
Florin Coras5665ced2018-10-25 18:03:45 -07001158 session_endpoint_cfg_t sep = SESSION_ENDPOINT_CFG_NULL;
Florin Coras7999e832017-10-31 01:51:04 -07001159 transport_connection_t *tc;
Florin Coras15531972018-08-12 23:50:53 -07001160 app_worker_t *app_wrk;
Florin Corasc9940fc2019-02-05 20:55:11 -08001161 app_listener_t *al;
Florin Coras288eaab2019-02-03 15:26:14 -08001162 session_t *s;
Florin Corasc9940fc2019-02-05 20:55:11 -08001163 u32 flags;
Florin Coras7999e832017-10-31 01:51:04 -07001164
Florin Coras15531972018-08-12 23:50:53 -07001165 /* TODO decide if we want proxy to be enabled for all workers */
1166 app_wrk = application_get_default_worker (app);
Florin Coras7999e832017-10-31 01:51:04 -07001167 if (is_start)
1168 {
Florin Coras15531972018-08-12 23:50:53 -07001169 s = app_worker_first_listener (app_wrk, fib_proto, transport_proto);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001170 if (!s)
1171 {
1172 sep.is_ip4 = is_ip4;
1173 sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto);
1174 sep.sw_if_index = app_ns->sw_if_index;
1175 sep.transport_proto = transport_proto;
Florin Corasab2f6db2018-08-31 14:31:41 -07001176 sep.app_wrk_index = app_wrk->wrk_index; /* only default */
Florin Corasc9940fc2019-02-05 20:55:11 -08001177
1178 /* force global scope listener */
1179 flags = app->flags;
1180 app->flags &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1181 app_listener_alloc_and_init (app, &sep, &al);
1182 app->flags = flags;
1183
1184 app_worker_start_listen (app_wrk, al);
1185 s = listen_session_get (al->session_index);
Florin Corasd5c604d2019-03-18 09:06:35 -07001186 s->flags |= SESSION_F_PROXY;
Florin Coras19b1f6a2017-12-11 03:37:03 -08001187 }
Florin Coras7999e832017-10-31 01:51:04 -07001188 }
1189 else
1190 {
Florin Coras623eb562019-02-03 19:28:34 -08001191 s = app_worker_proxy_listener (app_wrk, fib_proto, transport_proto);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001192 ASSERT (s);
Florin Coras7999e832017-10-31 01:51:04 -07001193 }
Florin Coras19b1f6a2017-12-11 03:37:03 -08001194
Florin Coras7999e832017-10-31 01:51:04 -07001195 tc = listen_session_get_transport (s);
1196
1197 if (!ip_is_zero (&tc->lcl_ip, 1))
1198 {
Florin Corasdbd44562017-11-09 19:30:17 -08001199 u32 sti;
1200 sep.is_ip4 = is_ip4;
1201 sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto);
1202 sep.transport_proto = transport_proto;
1203 sep.port = 0;
1204 sti = session_lookup_get_index_for_fib (fib_proto, sep.fib_index);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001205 if (is_start)
Florin Corasab2f6db2018-08-31 14:31:41 -07001206 session_lookup_add_session_endpoint (sti,
1207 (session_endpoint_t *) & sep,
1208 s->session_index);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001209 else
Florin Corasab2f6db2018-08-31 14:31:41 -07001210 session_lookup_del_session_endpoint (sti,
1211 (session_endpoint_t *) & sep);
Florin Coras7999e832017-10-31 01:51:04 -07001212 }
Florin Coras19b1f6a2017-12-11 03:37:03 -08001213
Florin Coras7999e832017-10-31 01:51:04 -07001214 return 0;
1215}
1216
Florin Coras19b1f6a2017-12-11 03:37:03 -08001217static void
1218application_start_stop_proxy_local_scope (application_t * app,
1219 u8 transport_proto, u8 is_start)
1220{
1221 session_endpoint_t sep = SESSION_ENDPOINT_NULL;
1222 app_namespace_t *app_ns;
1223 app_ns = app_namespace_get (app->ns_index);
1224 sep.is_ip4 = 1;
1225 sep.transport_proto = transport_proto;
1226 sep.port = 0;
1227
1228 if (is_start)
1229 {
1230 session_lookup_add_session_endpoint (app_ns->local_table_index, &sep,
Florin Coras15531972018-08-12 23:50:53 -07001231 app->app_index);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001232 sep.is_ip4 = 0;
1233 session_lookup_add_session_endpoint (app_ns->local_table_index, &sep,
Florin Coras15531972018-08-12 23:50:53 -07001234 app->app_index);
Florin Coras19b1f6a2017-12-11 03:37:03 -08001235 }
1236 else
1237 {
1238 session_lookup_del_session_endpoint (app_ns->local_table_index, &sep);
1239 sep.is_ip4 = 0;
1240 session_lookup_del_session_endpoint (app_ns->local_table_index, &sep);
1241 }
1242}
1243
Florin Coras7999e832017-10-31 01:51:04 -07001244void
Florin Coras561af9b2017-12-09 10:19:43 -08001245application_start_stop_proxy (application_t * app,
1246 transport_proto_t transport_proto, u8 is_start)
Florin Coras7999e832017-10-31 01:51:04 -07001247{
Florin Coras7999e832017-10-31 01:51:04 -07001248 if (application_has_local_scope (app))
Florin Coras19b1f6a2017-12-11 03:37:03 -08001249 application_start_stop_proxy_local_scope (app, transport_proto, is_start);
Florin Coras7999e832017-10-31 01:51:04 -07001250
1251 if (application_has_global_scope (app))
1252 {
1253 application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP4,
1254 transport_proto, is_start);
1255 application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP6,
1256 transport_proto, is_start);
1257 }
1258}
1259
1260void
1261application_setup_proxy (application_t * app)
1262{
1263 u16 transports = app->proxied_transports;
Florin Coras561af9b2017-12-09 10:19:43 -08001264 transport_proto_t tp;
1265
Florin Coras7999e832017-10-31 01:51:04 -07001266 ASSERT (application_is_proxy (app));
Florin Coras561af9b2017-12-09 10:19:43 -08001267
1268 /* *INDENT-OFF* */
1269 transport_proto_foreach (tp, ({
1270 if (transports & (1 << tp))
1271 application_start_stop_proxy (app, tp, 1);
1272 }));
1273 /* *INDENT-ON* */
Florin Coras7999e832017-10-31 01:51:04 -07001274}
1275
1276void
1277application_remove_proxy (application_t * app)
1278{
1279 u16 transports = app->proxied_transports;
Florin Coras561af9b2017-12-09 10:19:43 -08001280 transport_proto_t tp;
1281
Florin Coras7999e832017-10-31 01:51:04 -07001282 ASSERT (application_is_proxy (app));
Florin Coras561af9b2017-12-09 10:19:43 -08001283
1284 /* *INDENT-OFF* */
1285 transport_proto_foreach (tp, ({
1286 if (transports & (1 << tp))
1287 application_start_stop_proxy (app, tp, 0);
1288 }));
1289 /* *INDENT-ON* */
Florin Coras7999e832017-10-31 01:51:04 -07001290}
1291
Florin Coras88001c62019-04-24 14:44:46 -07001292segment_manager_props_t *
Florin Corasa332c462018-01-31 06:52:17 -08001293application_segment_manager_properties (application_t * app)
1294{
1295 return &app->sm_properties;
1296}
1297
Florin Coras88001c62019-04-24 14:44:46 -07001298segment_manager_props_t *
Florin Corasa332c462018-01-31 06:52:17 -08001299application_get_segment_manager_properties (u32 app_index)
1300{
1301 application_t *app = application_get (app_index);
1302 return &app->sm_properties;
1303}
1304
Florin Coras371ca502018-02-21 12:07:41 -08001305clib_error_t *
1306vnet_app_add_tls_cert (vnet_app_add_tls_cert_args_t * a)
1307{
1308 application_t *app;
1309 app = application_get (a->app_index);
1310 if (!app)
1311 return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED,
1312 0, "app %u doesn't exist", a->app_index);
1313 app->tls_cert = vec_dup (a->cert);
1314 return 0;
1315}
1316
1317clib_error_t *
1318vnet_app_add_tls_key (vnet_app_add_tls_key_args_t * a)
1319{
1320 application_t *app;
1321 app = application_get (a->app_index);
1322 if (!app)
1323 return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED,
1324 0, "app %u doesn't exist", a->app_index);
1325 app->tls_key = vec_dup (a->key);
1326 return 0;
1327}
1328
Florin Coras15531972018-08-12 23:50:53 -07001329static void
1330application_format_listeners (application_t * app, int verbose)
1331{
1332 vlib_main_t *vm = vlib_get_main ();
1333 app_worker_map_t *wrk_map;
1334 app_worker_t *app_wrk;
1335 u32 sm_index;
1336 u64 handle;
1337
1338 if (!app)
1339 {
1340 vlib_cli_output (vm, "%U", format_app_worker_listener, 0 /* header */ ,
1341 0, 0, verbose);
1342 return;
1343 }
1344
1345 /* *INDENT-OFF* */
1346 pool_foreach (wrk_map, app->worker_maps, ({
1347 app_wrk = app_worker_get (wrk_map->wrk_index);
1348 if (hash_elts (app_wrk->listeners_table) == 0)
1349 continue;
1350 hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
1351 vlib_cli_output (vm, "%U", format_app_worker_listener, app_wrk,
1352 handle, sm_index, verbose);
1353 }));
1354 }));
1355 /* *INDENT-ON* */
1356}
1357
1358static void
Florin Coras15531972018-08-12 23:50:53 -07001359application_format_connects (application_t * app, int verbose)
1360{
1361 app_worker_map_t *wrk_map;
1362 app_worker_t *app_wrk;
1363
1364 if (!app)
1365 {
1366 app_worker_format_connects (0, verbose);
1367 return;
1368 }
1369
1370 /* *INDENT-OFF* */
1371 pool_foreach (wrk_map, app->worker_maps, ({
1372 app_wrk = app_worker_get (wrk_map->wrk_index);
1373 app_worker_format_connects (app_wrk, verbose);
1374 }));
1375 /* *INDENT-ON* */
1376}
1377
Florin Coras6cf30ad2017-04-04 23:08:23 -07001378u8 *
1379format_application (u8 * s, va_list * args)
1380{
1381 application_t *app = va_arg (*args, application_t *);
1382 CLIB_UNUSED (int verbose) = va_arg (*args, int);
Florin Coras88001c62019-04-24 14:44:46 -07001383 segment_manager_props_t *props;
Florin Coras053a0e42018-11-13 15:52:38 -08001384 const u8 *app_ns_name, *app_name;
Florin Coras349f8ca2018-11-20 16:52:49 -08001385 app_worker_map_t *wrk_map;
1386 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001387
1388 if (app == 0)
1389 {
Florin Coras349f8ca2018-11-20 16:52:49 -08001390 if (!verbose)
Florin Corasc1f5a432018-11-20 11:31:26 -08001391 s = format (s, "%-10s%-20s%-40s", "Index", "Name", "Namespace");
Florin Coras6cf30ad2017-04-04 23:08:23 -07001392 return s;
1393 }
1394
Florin Coras0bee9ce2018-03-22 21:24:31 -07001395 app_name = app_get_name (app);
Florin Corascea194d2017-10-02 00:18:51 -07001396 app_ns_name = app_namespace_id_from_index (app->ns_index);
Florin Corasa332c462018-01-31 06:52:17 -08001397 props = application_segment_manager_properties (app);
Florin Coras349f8ca2018-11-20 16:52:49 -08001398 if (!verbose)
1399 {
Florin Corasfa7512e2019-04-04 22:31:50 -07001400 s = format (s, "%-10u%-20v%-40s", app->app_index, app_name,
Florin Coras349f8ca2018-11-20 16:52:49 -08001401 app_ns_name);
1402 return s;
1403 }
1404
Florin Corasfa7512e2019-04-04 22:31:50 -07001405 s = format (s, "app-name %v app-index %u ns-index %u seg-size %U\n",
Florin Coras349f8ca2018-11-20 16:52:49 -08001406 app_name, app->app_index, app->ns_index,
1407 format_memory_size, props->add_segment_size);
1408 s = format (s, "rx-fifo-size %U tx-fifo-size %U workers:\n",
1409 format_memory_size, props->rx_fifo_size,
1410 format_memory_size, props->tx_fifo_size);
1411
1412 /* *INDENT-OFF* */
1413 pool_foreach (wrk_map, app->worker_maps, ({
1414 app_wrk = app_worker_get (wrk_map->wrk_index);
Florin Coras623eb562019-02-03 19:28:34 -08001415 s = format (s, "%U", format_app_worker, app_wrk);
Florin Coras349f8ca2018-11-20 16:52:49 -08001416 }));
1417 /* *INDENT-ON* */
1418
Dave Barach68b0fb02017-02-28 15:15:56 -05001419 return s;
1420}
1421
Florin Corasf8f516a2018-02-08 15:10:09 -08001422void
Florin Coras2b81e3c2019-02-27 07:55:46 -08001423application_format_all_listeners (vlib_main_t * vm, int verbose)
Florin Corasf8f516a2018-02-08 15:10:09 -08001424{
1425 application_t *app;
Florin Corasf8f516a2018-02-08 15:10:09 -08001426
Florin Coras15531972018-08-12 23:50:53 -07001427 if (!pool_elts (app_main.app_pool))
Florin Corasf8f516a2018-02-08 15:10:09 -08001428 {
1429 vlib_cli_output (vm, "No active server bindings");
1430 return;
1431 }
1432
Florin Coras2b81e3c2019-02-27 07:55:46 -08001433 application_format_listeners (0, verbose);
Florin Corasf8f516a2018-02-08 15:10:09 -08001434
Florin Coras2b81e3c2019-02-27 07:55:46 -08001435 /* *INDENT-OFF* */
1436 pool_foreach (app, app_main.app_pool, ({
1437 application_format_listeners (app, verbose);
1438 }));
1439 /* *INDENT-ON* */
Florin Corasf8f516a2018-02-08 15:10:09 -08001440}
1441
1442void
Florin Coras2b81e3c2019-02-27 07:55:46 -08001443application_format_all_clients (vlib_main_t * vm, int verbose)
Florin Corasf8f516a2018-02-08 15:10:09 -08001444{
1445 application_t *app;
1446
Florin Coras15531972018-08-12 23:50:53 -07001447 if (!pool_elts (app_main.app_pool))
Florin Corasf8f516a2018-02-08 15:10:09 -08001448 {
1449 vlib_cli_output (vm, "No active apps");
1450 return;
1451 }
1452
Florin Coras2b81e3c2019-02-27 07:55:46 -08001453 application_format_connects (0, verbose);
Florin Corasf8f516a2018-02-08 15:10:09 -08001454
Florin Coras2b81e3c2019-02-27 07:55:46 -08001455 /* *INDENT-OFF* */
1456 pool_foreach (app, app_main.app_pool, ({
1457 application_format_connects (app, verbose);
1458 }));
1459 /* *INDENT-ON* */
Florin Corasf8f516a2018-02-08 15:10:09 -08001460}
1461
Dave Barach68b0fb02017-02-28 15:15:56 -05001462static clib_error_t *
1463show_app_command_fn (vlib_main_t * vm, unformat_input_t * input,
1464 vlib_cli_command_t * cmd)
1465{
Florin Coras2b81e3c2019-02-27 07:55:46 -08001466 int do_server = 0, do_client = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001467 application_t *app;
Florin Coras349f8ca2018-11-20 16:52:49 -08001468 u32 app_index = ~0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001469 int verbose = 0;
1470
Florin Corascea194d2017-10-02 00:18:51 -07001471 session_cli_return_if_not_enabled ();
Florin Corase04c2992017-03-01 08:17:34 -08001472
Dave Barach68b0fb02017-02-28 15:15:56 -05001473 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1474 {
1475 if (unformat (input, "server"))
1476 do_server = 1;
1477 else if (unformat (input, "client"))
1478 do_client = 1;
Florin Coras349f8ca2018-11-20 16:52:49 -08001479 else if (unformat (input, "%u", &app_index))
1480 ;
Dave Barach68b0fb02017-02-28 15:15:56 -05001481 else if (unformat (input, "verbose"))
1482 verbose = 1;
1483 else
Florin Coras349f8ca2018-11-20 16:52:49 -08001484 return clib_error_return (0, "unknown input `%U'",
1485 format_unformat_error, input);
Dave Barach68b0fb02017-02-28 15:15:56 -05001486 }
1487
1488 if (do_server)
Florin Coras349f8ca2018-11-20 16:52:49 -08001489 {
Florin Coras2b81e3c2019-02-27 07:55:46 -08001490 application_format_all_listeners (vm, verbose);
Florin Coras349f8ca2018-11-20 16:52:49 -08001491 return 0;
1492 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001493
1494 if (do_client)
Florin Coras349f8ca2018-11-20 16:52:49 -08001495 {
Florin Coras2b81e3c2019-02-27 07:55:46 -08001496 application_format_all_clients (vm, verbose);
Florin Coras349f8ca2018-11-20 16:52:49 -08001497 return 0;
1498 }
1499
1500 if (app_index != ~0)
1501 {
Florin Coras47c40e22018-11-26 17:01:36 -08001502 app = application_get_if_valid (app_index);
Florin Coras349f8ca2018-11-20 16:52:49 -08001503 if (!app)
1504 return clib_error_return (0, "No app with index %u", app_index);
1505
1506 vlib_cli_output (vm, "%U", format_application, app, /* verbose */ 1);
1507 return 0;
1508 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001509
Florin Coras6cf30ad2017-04-04 23:08:23 -07001510 /* Print app related info */
1511 if (!do_server && !do_client)
1512 {
Florin Coras349f8ca2018-11-20 16:52:49 -08001513 vlib_cli_output (vm, "%U", format_application, 0, 0);
Florin Corascea194d2017-10-02 00:18:51 -07001514 /* *INDENT-OFF* */
Florin Coras15531972018-08-12 23:50:53 -07001515 pool_foreach (app, app_main.app_pool, ({
Florin Coras349f8ca2018-11-20 16:52:49 -08001516 vlib_cli_output (vm, "%U", format_application, app, 0);
Florin Corascea194d2017-10-02 00:18:51 -07001517 }));
1518 /* *INDENT-ON* */
Florin Coras6cf30ad2017-04-04 23:08:23 -07001519 }
1520
Dave Barach68b0fb02017-02-28 15:15:56 -05001521 return 0;
1522}
1523
Florin Corase04c2992017-03-01 08:17:34 -08001524/* *INDENT-OFF* */
Dave Barach68b0fb02017-02-28 15:15:56 -05001525VLIB_CLI_COMMAND (show_app_command, static) =
1526{
Florin Corase04c2992017-03-01 08:17:34 -08001527 .path = "show app",
1528 .short_help = "show app [server|client] [verbose]",
1529 .function = show_app_command_fn,
1530};
1531/* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -05001532
1533/*
1534 * fd.io coding-style-patch-verification: ON
1535 *
1536 * Local Variables:
1537 * eval: (c-set-style "gnu")
1538 * End:
1539 */