Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/session/application_namespace.h> |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 17 | #include <vnet/session/application.h> |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 18 | #include <vnet/session/session_table.h> |
| 19 | #include <vnet/session/session.h> |
| 20 | #include <vnet/fib/fib_table.h> |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 21 | #include <vppinfra/file.h> |
| 22 | #include <vlib/unix/unix.h> |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Hash table of application namespaces by app ns ids |
| 26 | */ |
| 27 | uword *app_namespace_lookup_table; |
| 28 | |
| 29 | /** |
| 30 | * Pool of application namespaces |
| 31 | */ |
| 32 | static app_namespace_t *app_namespace_pool; |
| 33 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 34 | static u8 app_sapi_enabled; |
| 35 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 36 | app_namespace_t * |
| 37 | app_namespace_get (u32 index) |
| 38 | { |
| 39 | return pool_elt_at_index (app_namespace_pool, index); |
| 40 | } |
| 41 | |
| 42 | app_namespace_t * |
| 43 | app_namespace_get_from_id (const u8 * ns_id) |
| 44 | { |
| 45 | u32 index = app_namespace_index_from_id (ns_id); |
| 46 | if (index == APP_NAMESPACE_INVALID_INDEX) |
| 47 | return 0; |
| 48 | return app_namespace_get (index); |
| 49 | } |
| 50 | |
| 51 | u32 |
| 52 | app_namespace_index (app_namespace_t * app_ns) |
| 53 | { |
| 54 | return (app_ns - app_namespace_pool); |
| 55 | } |
| 56 | |
| 57 | app_namespace_t * |
| 58 | app_namespace_alloc (u8 * ns_id) |
| 59 | { |
| 60 | app_namespace_t *app_ns; |
| 61 | pool_get (app_namespace_pool, app_ns); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 62 | clib_memset (app_ns, 0, sizeof (*app_ns)); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 63 | app_ns->ns_id = vec_dup (ns_id); |
| 64 | hash_set_mem (app_namespace_lookup_table, app_ns->ns_id, |
| 65 | app_ns - app_namespace_pool); |
| 66 | return app_ns; |
| 67 | } |
| 68 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 69 | int |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 70 | vnet_app_namespace_add_del (vnet_app_namespace_add_del_args_t * a) |
| 71 | { |
| 72 | app_namespace_t *app_ns; |
| 73 | session_table_t *st; |
| 74 | |
| 75 | if (a->is_add) |
| 76 | { |
| 77 | if (a->sw_if_index != APP_NAMESPACE_INVALID_INDEX |
Dave Barach | 3940de3 | 2019-07-23 16:28:36 -0400 | [diff] [blame] | 78 | && !vnet_get_sw_interface_or_null (vnet_get_main (), |
| 79 | a->sw_if_index)) |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 80 | return VNET_API_ERROR_INVALID_SW_IF_INDEX; |
| 81 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 82 | |
| 83 | if (a->sw_if_index != APP_NAMESPACE_INVALID_INDEX) |
| 84 | { |
| 85 | a->ip4_fib_id = |
| 86 | fib_table_get_table_id_for_sw_if_index (FIB_PROTOCOL_IP4, |
| 87 | a->sw_if_index); |
| 88 | a->ip6_fib_id = |
Florin Coras | 56b39f6 | 2018-03-27 17:29:32 -0700 | [diff] [blame] | 89 | fib_table_get_table_id_for_sw_if_index (FIB_PROTOCOL_IP6, |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 90 | a->sw_if_index); |
| 91 | } |
| 92 | if (a->sw_if_index == APP_NAMESPACE_INVALID_INDEX |
| 93 | && a->ip4_fib_id == APP_NAMESPACE_INVALID_INDEX) |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 94 | return VNET_API_ERROR_INVALID_VALUE; |
| 95 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 96 | app_ns = app_namespace_get_from_id (a->ns_id); |
| 97 | if (!app_ns) |
Florin Coras | fc1c612 | 2017-10-26 14:25:12 -0700 | [diff] [blame] | 98 | { |
| 99 | app_ns = app_namespace_alloc (a->ns_id); |
| 100 | st = session_table_alloc (); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 101 | session_table_init (st, FIB_PROTOCOL_MAX); |
| 102 | st->is_local = 1; |
| 103 | st->appns_index = app_namespace_index (app_ns); |
Florin Coras | fc1c612 | 2017-10-26 14:25:12 -0700 | [diff] [blame] | 104 | app_ns->local_table_index = session_table_index (st); |
| 105 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 106 | app_ns->ns_secret = a->secret; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 107 | app_ns->netns = a->netns ? vec_dup (a->netns) : 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 108 | app_ns->sw_if_index = a->sw_if_index; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 109 | app_ns->ip4_fib_index = |
| 110 | fib_table_find (FIB_PROTOCOL_IP4, a->ip4_fib_id); |
| 111 | app_ns->ip6_fib_index = |
| 112 | fib_table_find (FIB_PROTOCOL_IP6, a->ip6_fib_id); |
Florin Coras | 6c36f53 | 2017-11-03 18:32:34 -0700 | [diff] [blame] | 113 | session_lookup_set_tables_appns (app_ns); |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 114 | |
| 115 | /* Add socket for namespace */ |
| 116 | if (app_sapi_enabled) |
| 117 | appns_sapi_add_ns_socket (app_ns); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 118 | } |
| 119 | else |
| 120 | { |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 121 | return VNET_API_ERROR_UNIMPLEMENTED; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 122 | } |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | const u8 * |
| 127 | app_namespace_id (app_namespace_t * app_ns) |
| 128 | { |
| 129 | return app_ns->ns_id; |
| 130 | } |
| 131 | |
| 132 | u32 |
| 133 | app_namespace_index_from_id (const u8 * ns_id) |
| 134 | { |
| 135 | uword *indexp; |
| 136 | indexp = hash_get_mem (app_namespace_lookup_table, ns_id); |
| 137 | if (!indexp) |
| 138 | return APP_NAMESPACE_INVALID_INDEX; |
| 139 | return *indexp; |
| 140 | } |
| 141 | |
| 142 | const u8 * |
| 143 | app_namespace_id_from_index (u32 index) |
| 144 | { |
| 145 | app_namespace_t *app_ns; |
| 146 | |
| 147 | app_ns = app_namespace_get (index); |
| 148 | return app_namespace_id (app_ns); |
| 149 | } |
| 150 | |
Florin Coras | 1c71045 | 2017-10-17 00:03:13 -0700 | [diff] [blame] | 151 | u32 |
| 152 | app_namespace_get_fib_index (app_namespace_t * app_ns, u8 fib_proto) |
| 153 | { |
| 154 | return fib_proto == FIB_PROTOCOL_IP4 ? |
| 155 | app_ns->ip4_fib_index : app_ns->ip6_fib_index; |
| 156 | } |
| 157 | |
| 158 | session_table_t * |
| 159 | app_namespace_get_local_table (app_namespace_t * app_ns) |
| 160 | { |
| 161 | return session_table_get (app_ns->local_table_index); |
| 162 | } |
| 163 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 164 | void |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 165 | appns_sapi_enable (void) |
| 166 | { |
| 167 | app_sapi_enabled = 1; |
| 168 | } |
| 169 | |
| 170 | u8 |
| 171 | appns_sapi_enabled (void) |
| 172 | { |
| 173 | return app_sapi_enabled; |
| 174 | } |
| 175 | |
| 176 | void |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 177 | app_namespaces_init (void) |
| 178 | { |
| 179 | u8 *ns_id = format (0, "default"); |
Florin Coras | fc1c612 | 2017-10-26 14:25:12 -0700 | [diff] [blame] | 180 | |
| 181 | if (!app_namespace_lookup_table) |
| 182 | app_namespace_lookup_table = |
| 183 | hash_create_vec (0, sizeof (u8), sizeof (uword)); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * Allocate default namespace |
| 187 | */ |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 188 | |
| 189 | /* clang-format off */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 190 | vnet_app_namespace_add_del_args_t a = { |
| 191 | .ns_id = ns_id, |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 192 | .netns = 0, |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 193 | .secret = 0, |
| 194 | .sw_if_index = APP_NAMESPACE_INVALID_INDEX, |
| 195 | .is_add = 1 |
| 196 | }; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 197 | /* clang-format on */ |
| 198 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 199 | vnet_app_namespace_add_del (&a); |
| 200 | vec_free (ns_id); |
| 201 | } |
| 202 | |
| 203 | static clib_error_t * |
| 204 | app_ns_fn (vlib_main_t * vm, unformat_input_t * input, |
| 205 | vlib_cli_command_t * cmd) |
| 206 | { |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 207 | u8 is_add = 0, *ns_id = 0, secret_set = 0, sw_if_index_set = 0, *netns = 0; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 208 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 209 | u32 sw_if_index, fib_id = APP_NAMESPACE_INVALID_INDEX; |
| 210 | u64 secret; |
| 211 | clib_error_t *error = 0; |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 212 | int rv; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 213 | |
| 214 | session_cli_return_if_not_enabled (); |
| 215 | |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 216 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 217 | return 0; |
| 218 | |
| 219 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 220 | { |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 221 | if (unformat (line_input, "add")) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 222 | is_add = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 223 | else if (unformat (line_input, "id %_%v%_", &ns_id)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 224 | ; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 225 | else if (unformat (line_input, "secret %lu", &secret)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 226 | secret_set = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 227 | else if (unformat (line_input, "sw_if_index %u", &sw_if_index)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 228 | sw_if_index_set = 1; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 229 | else if (unformat (line_input, "fib_id", &fib_id)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 230 | ; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 231 | else if (unformat (line_input, "netns %_%v%_", &netns)) |
| 232 | ; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 233 | else |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 234 | { |
| 235 | error = clib_error_return (0, "unknown input `%U'", |
| 236 | format_unformat_error, line_input); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 237 | goto done; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 238 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | if (!ns_id || !secret_set || !sw_if_index_set) |
| 242 | { |
| 243 | vlib_cli_output (vm, "namespace-id, secret and sw_if_index must be " |
| 244 | "provided"); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 245 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | if (is_add) |
| 249 | { |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 250 | /* clang-format off */ |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 251 | vnet_app_namespace_add_del_args_t args = { |
| 252 | .ns_id = ns_id, |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 253 | .netns = netns, |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 254 | .secret = secret, |
| 255 | .sw_if_index = sw_if_index, |
| 256 | .ip4_fib_id = fib_id, |
| 257 | .is_add = 1 |
| 258 | }; |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 259 | /* clang-format on */ |
| 260 | |
Florin Coras | c1a4265 | 2019-02-08 18:27:29 -0800 | [diff] [blame] | 261 | if ((rv = vnet_app_namespace_add_del (&args))) |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 262 | error = clib_error_return (0, "app namespace add del returned %d", rv); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 265 | done: |
| 266 | |
| 267 | vec_free (ns_id); |
| 268 | vec_free (netns); |
| 269 | unformat_free (line_input); |
| 270 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 271 | return error; |
| 272 | } |
| 273 | |
| 274 | /* *INDENT-OFF* */ |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 275 | VLIB_CLI_COMMAND (app_ns_command, static) = { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 276 | .path = "app ns", |
| 277 | .short_help = "app ns [add] id <namespace-id> secret <secret> " |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 278 | "sw_if_index <sw_if_index> [netns <ns>]", |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 279 | .function = app_ns_fn, |
| 280 | }; |
| 281 | /* *INDENT-ON* */ |
| 282 | |
| 283 | u8 * |
| 284 | format_app_namespace (u8 * s, va_list * args) |
| 285 | { |
| 286 | app_namespace_t *app_ns = va_arg (*args, app_namespace_t *); |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 287 | |
| 288 | s = |
| 289 | format (s, "%-10u%-10lu%-15d%-15v%-15v%-40v", app_namespace_index (app_ns), |
| 290 | app_ns->ns_secret, app_ns->sw_if_index, app_ns->ns_id, |
| 291 | app_ns->netns, app_ns->sock_name); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 292 | return s; |
| 293 | } |
| 294 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 295 | static void |
| 296 | app_namespace_show_api (vlib_main_t * vm, app_namespace_t * app_ns) |
| 297 | { |
| 298 | app_ns_api_handle_t *handle; |
| 299 | app_worker_t *app_wrk; |
| 300 | clib_socket_t *cs; |
| 301 | clib_file_t *cf; |
| 302 | |
| 303 | if (!app_sapi_enabled) |
| 304 | { |
| 305 | vlib_cli_output (vm, "app socket api not enabled!"); |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | vlib_cli_output (vm, "socket: %v\n", app_ns->sock_name); |
| 310 | |
| 311 | if (!pool_elts (app_ns->app_sockets)) |
| 312 | return; |
| 313 | |
| 314 | vlib_cli_output (vm, "%12s%12s%5s", "app index", "wrk index", "fd"); |
| 315 | |
| 316 | |
| 317 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 318 | pool_foreach (cs, app_ns->app_sockets) { |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 319 | handle = (app_ns_api_handle_t *) &cs->private_data; |
| 320 | cf = clib_file_get (&file_main, handle->aah_file_index); |
| 321 | if (handle->aah_app_wrk_index == APP_INVALID_INDEX) |
| 322 | { |
| 323 | vlib_cli_output (vm, "%12d%12d%5u", -1, -1, cf->file_descriptor); |
| 324 | continue; |
| 325 | } |
| 326 | app_wrk = app_worker_get (handle->aah_app_wrk_index); |
| 327 | vlib_cli_output (vm, "%12d%12d%5u", app_wrk->app_index, |
| 328 | app_wrk->wrk_map_index, cf->file_descriptor); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 329 | } |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 330 | /* *INDENT-ON* */ |
| 331 | } |
| 332 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 333 | static clib_error_t * |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 334 | show_app_ns_fn (vlib_main_t * vm, unformat_input_t * main_input, |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 335 | vlib_cli_command_t * cmd) |
| 336 | { |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 337 | unformat_input_t _line_input, *line_input = &_line_input; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 338 | u8 *ns_id, do_table = 0, had_input = 1, do_api = 0; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 339 | app_namespace_t *app_ns; |
| 340 | session_table_t *st; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 341 | |
| 342 | session_cli_return_if_not_enabled (); |
| 343 | |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 344 | if (!unformat_user (main_input, unformat_line_input, line_input)) |
Florin Coras | 2640808 | 2017-11-09 02:06:07 -0800 | [diff] [blame] | 345 | { |
| 346 | had_input = 0; |
| 347 | goto do_ns_list; |
| 348 | } |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 349 | |
| 350 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 351 | { |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 352 | if (unformat (line_input, "table %_%v%_", &ns_id)) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 353 | do_table = 1; |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 354 | else if (unformat (line_input, "api-clients")) |
| 355 | do_api = 1; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 356 | else |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 357 | { |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 358 | vlib_cli_output (vm, "unknown input [%U]", format_unformat_error, |
| 359 | line_input); |
| 360 | goto done; |
Dave Wallace | 8af2054 | 2017-10-26 03:29:30 -0400 | [diff] [blame] | 361 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 364 | if (do_api) |
| 365 | { |
| 366 | if (!do_table) |
| 367 | { |
| 368 | vlib_cli_output (vm, "must specify a table for api"); |
| 369 | goto done; |
| 370 | } |
| 371 | app_ns = app_namespace_get_from_id (ns_id); |
| 372 | app_namespace_show_api (vm, app_ns); |
| 373 | goto done; |
| 374 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 375 | if (do_table) |
| 376 | { |
| 377 | app_ns = app_namespace_get_from_id (ns_id); |
| 378 | if (!app_ns) |
| 379 | { |
| 380 | vlib_cli_output (vm, "ns %v not found", ns_id); |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 381 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 382 | } |
| 383 | st = session_table_get (app_ns->local_table_index); |
| 384 | if (!st) |
| 385 | { |
| 386 | vlib_cli_output (vm, "table for ns %v could not be found", ns_id); |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 387 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 388 | } |
| 389 | session_lookup_show_table_entries (vm, st, 0, 1); |
| 390 | vec_free (ns_id); |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 391 | goto done; |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Florin Coras | 2640808 | 2017-11-09 02:06:07 -0800 | [diff] [blame] | 394 | do_ns_list: |
Florin Coras | 7cb471a | 2021-07-23 08:39:26 -0700 | [diff] [blame] | 395 | vlib_cli_output (vm, "%-10s%-10s%-15s%-15s%-15s%-40s", "Index", "Secret", |
| 396 | "sw_if_index", "Id", "netns", "Socket"); |
Florin Coras | dff48db | 2017-11-19 18:06:58 -0800 | [diff] [blame] | 397 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 398 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 399 | pool_foreach (app_ns, app_namespace_pool) { |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 400 | vlib_cli_output (vm, "%U", format_app_namespace, app_ns); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 401 | } |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 402 | /* *INDENT-ON* */ |
| 403 | |
Florin Coras | dcdff6e | 2017-11-07 22:36:02 -0800 | [diff] [blame] | 404 | done: |
Florin Coras | 2640808 | 2017-11-09 02:06:07 -0800 | [diff] [blame] | 405 | if (had_input) |
| 406 | unformat_free (line_input); |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | /* *INDENT-OFF* */ |
| 411 | VLIB_CLI_COMMAND (show_app_ns_command, static) = |
| 412 | { |
| 413 | .path = "show app ns", |
Florin Coras | 61ae056 | 2020-09-02 19:10:28 -0700 | [diff] [blame] | 414 | .short_help = "show app ns [table <id> [api-clients]]", |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 415 | .function = show_app_ns_fn, |
| 416 | }; |
| 417 | /* *INDENT-ON* */ |
| 418 | |
| 419 | /* |
| 420 | * fd.io coding-style-patch-verification: ON |
| 421 | * |
| 422 | * Local Variables: |
| 423 | * eval: (c-set-style "gnu") |
| 424 | * End: |
| 425 | */ |