blob: 03e41fdb22dd9bc6df33adc213893528df7ba56c [file] [log] [blame]
Florin Corascea194d2017-10-02 00:18:51 -07001/*
Florin Coras288eaab2019-02-03 15:26:14 -08002 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
Florin Corascea194d2017-10-02 00:18:51 -07003 * 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_namespace.h>
Florin Coras61ae0562020-09-02 19:10:28 -070017#include <vnet/session/application.h>
Florin Corascea194d2017-10-02 00:18:51 -070018#include <vnet/session/session_table.h>
19#include <vnet/session/session.h>
20#include <vnet/fib/fib_table.h>
Florin Coras61ae0562020-09-02 19:10:28 -070021#include <vppinfra/file.h>
Nathan Skrzypczak3d5e7412021-09-17 11:53:25 +020022#include <vppinfra/format_table.h>
Florin Coras61ae0562020-09-02 19:10:28 -070023#include <vlib/unix/unix.h>
Florin Corascea194d2017-10-02 00:18:51 -070024
25/**
26 * Hash table of application namespaces by app ns ids
27 */
28uword *app_namespace_lookup_table;
29
30/**
31 * Pool of application namespaces
32 */
33static app_namespace_t *app_namespace_pool;
34
Florin Coras61ae0562020-09-02 19:10:28 -070035static u8 app_sapi_enabled;
36
Florin Corascea194d2017-10-02 00:18:51 -070037app_namespace_t *
38app_namespace_get (u32 index)
39{
40 return pool_elt_at_index (app_namespace_pool, index);
41}
42
43app_namespace_t *
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +020044app_namespace_get_from_id (const u8 *ns_id)
Florin Corascea194d2017-10-02 00:18:51 -070045{
46 u32 index = app_namespace_index_from_id (ns_id);
47 if (index == APP_NAMESPACE_INVALID_INDEX)
48 return 0;
49 return app_namespace_get (index);
50}
51
52u32
53app_namespace_index (app_namespace_t * app_ns)
54{
55 return (app_ns - app_namespace_pool);
56}
57
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +020058void
59app_namespace_free (app_namespace_t *app_ns)
60{
61 hash_unset_mem (app_namespace_lookup_table, app_ns->ns_id);
62 vec_free (app_ns->ns_id);
63
64 pool_put (app_namespace_pool, app_ns);
65}
66
Florin Corascea194d2017-10-02 00:18:51 -070067app_namespace_t *
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +020068app_namespace_alloc (const u8 *ns_id)
Florin Corascea194d2017-10-02 00:18:51 -070069{
70 app_namespace_t *app_ns;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +020071
Florin Corascea194d2017-10-02 00:18:51 -070072 pool_get (app_namespace_pool, app_ns);
Dave Barachb7b92992018-10-17 10:38:51 -040073 clib_memset (app_ns, 0, sizeof (*app_ns));
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +020074
75 app_ns->ns_id = vec_dup ((u8 *) ns_id);
76 vec_terminate_c_string (app_ns->ns_id);
77
Florin Corascea194d2017-10-02 00:18:51 -070078 hash_set_mem (app_namespace_lookup_table, app_ns->ns_id,
79 app_ns - app_namespace_pool);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +020080
Florin Corascea194d2017-10-02 00:18:51 -070081 return app_ns;
82}
83
Filip Tehlar0028e6f2023-06-28 10:47:32 +020084session_error_t
85vnet_app_namespace_add_del (vnet_app_namespace_add_del_args_t *a)
Florin Corascea194d2017-10-02 00:18:51 -070086{
87 app_namespace_t *app_ns;
88 session_table_t *st;
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +020089 u32 ns_index;
Filip Tehlar0028e6f2023-06-28 10:47:32 +020090 session_error_t rv;
Florin Corascea194d2017-10-02 00:18:51 -070091
92 if (a->is_add)
93 {
94 if (a->sw_if_index != APP_NAMESPACE_INVALID_INDEX
Dave Barach3940de32019-07-23 16:28:36 -040095 && !vnet_get_sw_interface_or_null (vnet_get_main (),
96 a->sw_if_index))
Filip Tehlar0028e6f2023-06-28 10:47:32 +020097 return SESSION_E_INVALID;
Florin Corascea194d2017-10-02 00:18:51 -070098
99 if (a->sw_if_index != APP_NAMESPACE_INVALID_INDEX)
100 {
101 a->ip4_fib_id =
102 fib_table_get_table_id_for_sw_if_index (FIB_PROTOCOL_IP4,
103 a->sw_if_index);
104 a->ip6_fib_id =
Florin Coras56b39f62018-03-27 17:29:32 -0700105 fib_table_get_table_id_for_sw_if_index (FIB_PROTOCOL_IP6,
Florin Corascea194d2017-10-02 00:18:51 -0700106 a->sw_if_index);
107 }
108 if (a->sw_if_index == APP_NAMESPACE_INVALID_INDEX
109 && a->ip4_fib_id == APP_NAMESPACE_INVALID_INDEX)
Filip Tehlar0028e6f2023-06-28 10:47:32 +0200110 return SESSION_E_INVALID;
Florin Corasc1a42652019-02-08 18:27:29 -0800111
Florin Corascea194d2017-10-02 00:18:51 -0700112 app_ns = app_namespace_get_from_id (a->ns_id);
113 if (!app_ns)
Florin Corasfc1c6122017-10-26 14:25:12 -0700114 {
115 app_ns = app_namespace_alloc (a->ns_id);
116 st = session_table_alloc ();
Florin Coras6c36f532017-11-03 18:32:34 -0700117 session_table_init (st, FIB_PROTOCOL_MAX);
118 st->is_local = 1;
119 st->appns_index = app_namespace_index (app_ns);
Florin Corasfc1c6122017-10-26 14:25:12 -0700120 app_ns->local_table_index = session_table_index (st);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200121 if (a->sock_name)
122 {
123 app_ns->sock_name = vec_dup (a->sock_name);
124 vec_terminate_c_string (app_ns->sock_name);
125 }
126
127 /* Add socket for namespace,
128 * only at creation time */
129 if (app_sapi_enabled)
130 {
131 rv = appns_sapi_add_ns_socket (app_ns);
132 if (rv)
133 return rv;
134 }
Florin Corasfc1c6122017-10-26 14:25:12 -0700135 }
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200136
Florin Corascea194d2017-10-02 00:18:51 -0700137 app_ns->ns_secret = a->secret;
138 app_ns->sw_if_index = a->sw_if_index;
Florin Corascea194d2017-10-02 00:18:51 -0700139 app_ns->ip4_fib_index =
140 fib_table_find (FIB_PROTOCOL_IP4, a->ip4_fib_id);
141 app_ns->ip6_fib_index =
142 fib_table_find (FIB_PROTOCOL_IP6, a->ip6_fib_id);
Florin Coras6c36f532017-11-03 18:32:34 -0700143 session_lookup_set_tables_appns (app_ns);
Florin Coras61ae0562020-09-02 19:10:28 -0700144
Florin Corascea194d2017-10-02 00:18:51 -0700145 }
146 else
147 {
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200148 ns_index = app_namespace_index_from_id (a->ns_id);
149 if (ns_index == APP_NAMESPACE_INVALID_INDEX)
Filip Tehlar0028e6f2023-06-28 10:47:32 +0200150 return SESSION_E_INVALID;
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200151
152 app_ns = app_namespace_get (ns_index);
153 if (!app_ns)
Filip Tehlar0028e6f2023-06-28 10:47:32 +0200154 return SESSION_E_INVALID;
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200155
156 application_namespace_cleanup (app_ns);
157
158 if (app_sapi_enabled)
159 appns_sapi_del_ns_socket (app_ns);
160
161 st = session_table_get (app_ns->local_table_index);
162
163 session_table_free (st, FIB_PROTOCOL_MAX);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200164 if (app_ns->sock_name)
165 vec_free (app_ns->sock_name);
166
167 app_namespace_free (app_ns);
Florin Corascea194d2017-10-02 00:18:51 -0700168 }
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200169
Florin Corascea194d2017-10-02 00:18:51 -0700170 return 0;
171}
172
173const u8 *
174app_namespace_id (app_namespace_t * app_ns)
175{
176 return app_ns->ns_id;
177}
178
179u32
180app_namespace_index_from_id (const u8 * ns_id)
181{
182 uword *indexp;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200183 u8 *key;
184
185 key = vec_dup ((u8 *) ns_id);
186 vec_terminate_c_string (key);
187
188 indexp = hash_get_mem (app_namespace_lookup_table, key);
189 vec_free (key);
Florin Corascea194d2017-10-02 00:18:51 -0700190 if (!indexp)
191 return APP_NAMESPACE_INVALID_INDEX;
192 return *indexp;
193}
194
195const u8 *
196app_namespace_id_from_index (u32 index)
197{
198 app_namespace_t *app_ns;
199
200 app_ns = app_namespace_get (index);
201 return app_namespace_id (app_ns);
202}
203
Florin Coras1c710452017-10-17 00:03:13 -0700204u32
205app_namespace_get_fib_index (app_namespace_t * app_ns, u8 fib_proto)
206{
207 return fib_proto == FIB_PROTOCOL_IP4 ?
208 app_ns->ip4_fib_index : app_ns->ip6_fib_index;
209}
210
211session_table_t *
212app_namespace_get_local_table (app_namespace_t * app_ns)
213{
214 return session_table_get (app_ns->local_table_index);
215}
216
Nathan Skrzypczak7b3a3df2021-07-28 14:09:50 +0200217int
218appns_sapi_enable_disable (int is_enable)
Florin Coras61ae0562020-09-02 19:10:28 -0700219{
Nathan Skrzypczak7b3a3df2021-07-28 14:09:50 +0200220 /* This cannot be called with active sockets */
221 if (pool_elts (app_namespace_pool))
222 return -1;
223
224 app_sapi_enabled = is_enable;
225 return 0;
Florin Coras61ae0562020-09-02 19:10:28 -0700226}
227
228u8
229appns_sapi_enabled (void)
230{
231 return app_sapi_enabled;
232}
233
234void
Florin Corascea194d2017-10-02 00:18:51 -0700235app_namespaces_init (void)
236{
237 u8 *ns_id = format (0, "default");
Florin Corasfc1c6122017-10-26 14:25:12 -0700238
239 if (!app_namespace_lookup_table)
240 app_namespace_lookup_table =
241 hash_create_vec (0, sizeof (u8), sizeof (uword));
Florin Corascea194d2017-10-02 00:18:51 -0700242
243 /*
244 * Allocate default namespace
245 */
Florin Coras7cb471a2021-07-23 08:39:26 -0700246
247 /* clang-format off */
Florin Corascea194d2017-10-02 00:18:51 -0700248 vnet_app_namespace_add_del_args_t a = {
249 .ns_id = ns_id,
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200250 .sock_name = 0,
Florin Corascea194d2017-10-02 00:18:51 -0700251 .secret = 0,
252 .sw_if_index = APP_NAMESPACE_INVALID_INDEX,
253 .is_add = 1
254 };
Florin Coras7cb471a2021-07-23 08:39:26 -0700255 /* clang-format on */
256
Florin Corascea194d2017-10-02 00:18:51 -0700257 vnet_app_namespace_add_del (&a);
258 vec_free (ns_id);
259}
260
261static clib_error_t *
262app_ns_fn (vlib_main_t * vm, unformat_input_t * input,
263 vlib_cli_command_t * cmd)
264{
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200265 u8 is_add = 0, *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +0200266 u8 *sock_name = 0;
Dave Wallace8af20542017-10-26 03:29:30 -0400267 unformat_input_t _line_input, *line_input = &_line_input;
Florin Corascea194d2017-10-02 00:18:51 -0700268 u32 sw_if_index, fib_id = APP_NAMESPACE_INVALID_INDEX;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200269 vnet_main_t *vnm = vnet_get_main ();
Florin Corascea194d2017-10-02 00:18:51 -0700270 u64 secret;
271 clib_error_t *error = 0;
Florin Corasc1a42652019-02-08 18:27:29 -0800272 int rv;
Florin Corascea194d2017-10-02 00:18:51 -0700273
274 session_cli_return_if_not_enabled ();
275
Dave Wallace8af20542017-10-26 03:29:30 -0400276 if (!unformat_user (input, unformat_line_input, line_input))
277 return 0;
278
279 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Florin Corascea194d2017-10-02 00:18:51 -0700280 {
Dave Wallace8af20542017-10-26 03:29:30 -0400281 if (unformat (line_input, "add"))
Florin Corascea194d2017-10-02 00:18:51 -0700282 is_add = 1;
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200283 else if (unformat (line_input, "del"))
284 is_add = 0;
Dave Wallace8af20542017-10-26 03:29:30 -0400285 else if (unformat (line_input, "id %_%v%_", &ns_id))
Florin Corascea194d2017-10-02 00:18:51 -0700286 ;
Dave Wallace8af20542017-10-26 03:29:30 -0400287 else if (unformat (line_input, "secret %lu", &secret))
Florin Corascea194d2017-10-02 00:18:51 -0700288 secret_set = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400289 else if (unformat (line_input, "sw_if_index %u", &sw_if_index))
Florin Corascea194d2017-10-02 00:18:51 -0700290 sw_if_index_set = 1;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200291 else if (unformat (line_input, "if %U", unformat_vnet_sw_interface, vnm,
292 &sw_if_index))
293 sw_if_index_set = 1;
Dave Wallace8af20542017-10-26 03:29:30 -0400294 else if (unformat (line_input, "fib_id", &fib_id))
Florin Corascea194d2017-10-02 00:18:51 -0700295 ;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200296 else if (unformat (line_input, "sock-name %_%v%_", &sock_name))
297 ;
Florin Corascea194d2017-10-02 00:18:51 -0700298 else
Dave Wallace8af20542017-10-26 03:29:30 -0400299 {
300 error = clib_error_return (0, "unknown input `%U'",
301 format_unformat_error, line_input);
Florin Coras7cb471a2021-07-23 08:39:26 -0700302 goto done;
Dave Wallace8af20542017-10-26 03:29:30 -0400303 }
Florin Corascea194d2017-10-02 00:18:51 -0700304 }
305
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200306 if (!ns_id)
Florin Corascea194d2017-10-02 00:18:51 -0700307 {
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200308 vlib_cli_output (vm, "namespace-id must be provided");
Florin Coras7cb471a2021-07-23 08:39:26 -0700309 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700310 }
311
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200312 if (is_add && (!secret_set || !sw_if_index_set))
Florin Corascea194d2017-10-02 00:18:51 -0700313 {
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200314 vlib_cli_output (vm, "secret and interface must be provided");
315 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700316 }
317
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200318 /* clang-format off */
319 vnet_app_namespace_add_del_args_t args = {
320 .ns_id = ns_id,
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200321 .secret = secret,
322 .sw_if_index = sw_if_index,
323 .sock_name = sock_name,
324 .ip4_fib_id = fib_id,
325 .is_add = is_add,
326 };
327 /* clang-format on */
328
329 if ((rv = vnet_app_namespace_add_del (&args)))
330 error = clib_error_return (0, "app namespace add del returned %d", rv);
331
Florin Coras7cb471a2021-07-23 08:39:26 -0700332done:
333
334 vec_free (ns_id);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200335 vec_free (sock_name);
Florin Coras7cb471a2021-07-23 08:39:26 -0700336 unformat_free (line_input);
337
Florin Corascea194d2017-10-02 00:18:51 -0700338 return error;
339}
340
341/* *INDENT-OFF* */
Florin Coras7cb471a2021-07-23 08:39:26 -0700342VLIB_CLI_COMMAND (app_ns_command, static) = {
Florin Corascea194d2017-10-02 00:18:51 -0700343 .path = "app ns",
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200344 .short_help = "app ns [add|del] id <namespace-id> secret <secret> "
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +0200345 "sw_if_index <sw_if_index> if <interface>",
Florin Corascea194d2017-10-02 00:18:51 -0700346 .function = app_ns_fn,
347};
348/* *INDENT-ON* */
349
350u8 *
351format_app_namespace (u8 * s, va_list * args)
352{
353 app_namespace_t *app_ns = va_arg (*args, app_namespace_t *);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200354 vnet_main_t *vnm = vnet_get_main ();
Florin Coras7cb471a2021-07-23 08:39:26 -0700355
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200356 s = format (s, "Application namespace [%u]\nid: %s\nsecret: %lu",
357 app_namespace_index (app_ns), app_ns->ns_id, app_ns->ns_secret);
358 if (app_ns->sw_if_index != (u32) ~0)
359 s = format (s, "\nInterface: %U", format_vnet_sw_if_index_name, vnm,
360 app_ns->sw_if_index);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200361 if (app_ns->sock_name)
362 s = format (s, "\nSocket: %s", app_ns->sock_name);
363
Florin Corascea194d2017-10-02 00:18:51 -0700364 return s;
365}
366
Florin Coras61ae0562020-09-02 19:10:28 -0700367static void
368app_namespace_show_api (vlib_main_t * vm, app_namespace_t * app_ns)
369{
370 app_ns_api_handle_t *handle;
371 app_worker_t *app_wrk;
372 clib_socket_t *cs;
373 clib_file_t *cf;
374
375 if (!app_sapi_enabled)
376 {
377 vlib_cli_output (vm, "app socket api not enabled!");
378 return;
379 }
380
381 vlib_cli_output (vm, "socket: %v\n", app_ns->sock_name);
382
383 if (!pool_elts (app_ns->app_sockets))
384 return;
385
386 vlib_cli_output (vm, "%12s%12s%5s", "app index", "wrk index", "fd");
387
388
389 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100390 pool_foreach (cs, app_ns->app_sockets) {
Florin Coras61ae0562020-09-02 19:10:28 -0700391 handle = (app_ns_api_handle_t *) &cs->private_data;
392 cf = clib_file_get (&file_main, handle->aah_file_index);
393 if (handle->aah_app_wrk_index == APP_INVALID_INDEX)
394 {
395 vlib_cli_output (vm, "%12d%12d%5u", -1, -1, cf->file_descriptor);
396 continue;
397 }
398 app_wrk = app_worker_get (handle->aah_app_wrk_index);
399 vlib_cli_output (vm, "%12d%12d%5u", app_wrk->app_index,
400 app_wrk->wrk_map_index, cf->file_descriptor);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100401 }
Florin Coras61ae0562020-09-02 19:10:28 -0700402 /* *INDENT-ON* */
403}
404
Florin Corascea194d2017-10-02 00:18:51 -0700405static clib_error_t *
Florin Corasdcdff6e2017-11-07 22:36:02 -0800406show_app_ns_fn (vlib_main_t * vm, unformat_input_t * main_input,
Florin Corascea194d2017-10-02 00:18:51 -0700407 vlib_cli_command_t * cmd)
408{
Florin Corasdcdff6e2017-11-07 22:36:02 -0800409 unformat_input_t _line_input, *line_input = &_line_input;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200410 u8 *ns_id = 0, do_table = 0, had_input = 1, do_api = 0;
Florin Corascea194d2017-10-02 00:18:51 -0700411 app_namespace_t *app_ns;
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200412 vnet_main_t *vnm = vnet_get_main ();
Florin Corascea194d2017-10-02 00:18:51 -0700413 session_table_t *st;
Nathan Skrzypczak3d5e7412021-09-17 11:53:25 +0200414 table_t table = {}, *t = &table;
Florin Corascea194d2017-10-02 00:18:51 -0700415
416 session_cli_return_if_not_enabled ();
417
Florin Corasdcdff6e2017-11-07 22:36:02 -0800418 if (!unformat_user (main_input, unformat_line_input, line_input))
Florin Coras26408082017-11-09 02:06:07 -0800419 {
420 had_input = 0;
421 goto do_ns_list;
422 }
Florin Corasdcdff6e2017-11-07 22:36:02 -0800423
424 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Florin Corascea194d2017-10-02 00:18:51 -0700425 {
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200426 if (unformat (line_input, "id %_%v%_", &ns_id))
Florin Corascea194d2017-10-02 00:18:51 -0700427 do_table = 1;
Florin Coras61ae0562020-09-02 19:10:28 -0700428 else if (unformat (line_input, "api-clients"))
429 do_api = 1;
Florin Corascea194d2017-10-02 00:18:51 -0700430 else
Dave Wallace8af20542017-10-26 03:29:30 -0400431 {
Florin Corasdcdff6e2017-11-07 22:36:02 -0800432 vlib_cli_output (vm, "unknown input [%U]", format_unformat_error,
433 line_input);
434 goto done;
Dave Wallace8af20542017-10-26 03:29:30 -0400435 }
Florin Corascea194d2017-10-02 00:18:51 -0700436 }
437
Florin Coras61ae0562020-09-02 19:10:28 -0700438 if (do_api)
439 {
440 if (!do_table)
441 {
442 vlib_cli_output (vm, "must specify a table for api");
443 goto done;
444 }
445 app_ns = app_namespace_get_from_id (ns_id);
446 app_namespace_show_api (vm, app_ns);
447 goto done;
448 }
Florin Corascea194d2017-10-02 00:18:51 -0700449 if (do_table)
450 {
451 app_ns = app_namespace_get_from_id (ns_id);
452 if (!app_ns)
453 {
454 vlib_cli_output (vm, "ns %v not found", ns_id);
Florin Corasdcdff6e2017-11-07 22:36:02 -0800455 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700456 }
457 st = session_table_get (app_ns->local_table_index);
458 if (!st)
459 {
460 vlib_cli_output (vm, "table for ns %v could not be found", ns_id);
Florin Corasdcdff6e2017-11-07 22:36:02 -0800461 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700462 }
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200463 vlib_cli_output (vm, "%U", format_app_namespace, app_ns);
Florin Corascea194d2017-10-02 00:18:51 -0700464 session_lookup_show_table_entries (vm, st, 0, 1);
465 vec_free (ns_id);
Florin Corasdcdff6e2017-11-07 22:36:02 -0800466 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700467 }
468
Florin Coras26408082017-11-09 02:06:07 -0800469do_ns_list:
Nathan Skrzypczak51f1b262023-04-27 12:43:46 +0200470 table_add_header_col (t, 5, "Index", "Secret", "Interface", "Id", "Socket");
Nathan Skrzypczak3d5e7412021-09-17 11:53:25 +0200471 int i = 0;
472 pool_foreach (app_ns, app_namespace_pool)
473 {
474 int j = 0;
475 table_format_cell (t, i, j++, "%u", app_namespace_index (app_ns));
476 table_format_cell (t, i, j++, "%lu", app_ns->ns_secret);
477 table_format_cell (t, i, j++, "%U", format_vnet_sw_if_index_name, vnm,
478 app_ns->sw_if_index);
479 table_format_cell (t, i, j++, "%s", app_ns->ns_id);
Nathan Skrzypczak3d5e7412021-09-17 11:53:25 +0200480 table_format_cell (t, i++, j++, "%s", app_ns->sock_name);
481 }
Florin Corasdff48db2017-11-19 18:06:58 -0800482
Nathan Skrzypczak3d5e7412021-09-17 11:53:25 +0200483 t->default_body.align = TTAA_LEFT;
484 t->default_header_col.align = TTAA_LEFT;
485 t->default_header_col.fg_color = TTAC_YELLOW;
486 t->default_header_col.flags = TTAF_FG_COLOR_SET;
487 vlib_cli_output (vm, "%U", format_table, t);
488 table_free (t);
Florin Corascea194d2017-10-02 00:18:51 -0700489
Florin Corasdcdff6e2017-11-07 22:36:02 -0800490done:
Florin Coras26408082017-11-09 02:06:07 -0800491 if (had_input)
492 unformat_free (line_input);
Florin Corascea194d2017-10-02 00:18:51 -0700493 return 0;
494}
495
496/* *INDENT-OFF* */
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200497VLIB_CLI_COMMAND (show_app_ns_command, static) = {
Florin Corascea194d2017-10-02 00:18:51 -0700498 .path = "show app ns",
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200499 .short_help = "show app ns [id <id> [api-clients]]",
Florin Corascea194d2017-10-02 00:18:51 -0700500 .function = show_app_ns_fn,
501};
502/* *INDENT-ON* */
503
504/*
505 * fd.io coding-style-patch-verification: ON
506 *
507 * Local Variables:
508 * eval: (c-set-style "gnu")
509 * End:
510 */