FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
application.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
20 #include <vnet/session/session.h>
21 
23 
24 #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 
31 static app_listener_t *
33 {
34  app_listener_t *app_listener;
35  pool_get (app->listeners, app_listener);
36  clib_memset (app_listener, 0, sizeof (*app_listener));
37  app_listener->al_index = app_listener - app->listeners;
38  app_listener->app_index = app->app_index;
39  app_listener->session_index = SESSION_INVALID_INDEX;
40  app_listener->local_index = SESSION_INVALID_INDEX;
41  app_listener->ls_handle = SESSION_INVALID_HANDLE;
42  return app_listener;
43 }
44 
46 app_listener_get (application_t * app, u32 app_listener_index)
47 {
48  return pool_elt_at_index (app->listeners, app_listener_index);
49 }
50 
51 static void
53 {
54  clib_bitmap_free (app_listener->workers);
55  pool_put (app->listeners, app_listener);
56  if (CLIB_DEBUG)
57  clib_memset (app_listener, 0xfa, sizeof (*app_listener));
58 }
59 
62 {
63  return al->ls_handle;
64 }
65 
68 {
69  application_t *app;
70 
72  if (!app)
73  return 0;
74  return app_listener_get (app, ls->al_index);
75 }
76 
79 {
80  app_listener_t *al;
82  if (!al)
83  return listen_session_get_handle (ls);
84  return al->ls_handle;
85 }
86 
89 {
90  session_t *ls;
92  if (!ls)
93  return 0;
94  return app_listener_get_w_session (ls);
95 }
96 
99 {
100  u32 table_index, fib_proto;
101  session_endpoint_t *sep;
102  session_handle_t handle;
103  session_t *ls;
104 
105  sep = (session_endpoint_t *) sep_ext;
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  {
112  ls = listen_session_get_from_handle (handle);
113  return app_listener_get_w_session (ls);
114  }
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 
129 int
133 {
134  app_listener_t *app_listener;
136  session_handle_t lh;
137  session_type_t st;
138  session_t *ls = 0;
139  u32 al_index;
140  int rv;
141 
142  app_listener = app_listener_alloc (app);
143  al_index = app_listener->al_index;
144  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  */
152  {
153  session_type_t local_st;
154  u32 table_index;
155 
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;
173  app_listener->ls_handle = lh;
174  ls->al_index = al_index;
175 
176  table_index = application_local_session_table (app);
178  (session_endpoint_t *) sep, lh);
179  }
180 
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  */
189  ls = listen_session_alloc (0, st);
190  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) */
195  lh = listen_session_get_handle (ls);
196 
197  if ((rv = session_listen (ls, sep)))
198  {
200  session_free (ls);
201  return rv;
202  }
204  app_listener = app_listener_get (app, al_index);
205  app_listener->session_index = ls->session_index;
206  app_listener->ls_handle = lh;
207  ls->al_index = al_index;
208 
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);
215  if (!(tc->flags & TRANSPORT_CONNECTION_F_NO_LOOKUP))
217  }
218 
219  if (!ls)
220  {
221  app_listener_free (app, app_listener);
222  return -1;
223  }
224 
225  *listener = app_listener;
226  return 0;
227 }
228 
229 void
231 {
233  session_t *ls;
234 
236  {
237  ls = session_get (al->session_index, 0);
238  session_stop_listen (ls);
239  listen_session_free (ls);
240  }
242  {
244  u32 table_index;
245 
246  table_index = application_local_session_table (app);
247  ls = listen_session_get (al->local_index);
248  ct_session_endpoint (ls, &sep);
249  session_lookup_del_session_endpoint (table_index, &sep);
250  session_stop_listen (ls);
251  listen_session_free (ls);
252  }
253  app_listener_free (app, al);
254 }
255 
256 static app_worker_t *
258 {
259  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 
271 session_t *
273 {
275  return 0;
276 
277  return listen_session_get (al->session_index);
278 }
279 
280 session_t *
282 {
284  return 0;
285  return listen_session_get (al->local_index);
286 }
287 
288 static app_worker_map_t *
290 {
291  app_worker_map_t *map;
292  pool_get (app->worker_maps, map);
293  clib_memset (map, 0, sizeof (*map));
294  return map;
295 }
296 
297 static u32
299 {
300  return (map - app->worker_maps);
301 }
302 
303 static void
305 {
306  pool_put (app->worker_maps, map);
307 }
308 
309 static app_worker_map_t *
311 {
312  if (pool_is_free_index (app->worker_maps, map_index))
313  return 0;
314  return pool_elt_at_index (app->worker_maps, map_index);
315 }
316 
317 static const u8 *
319 {
320  return app->name;
321 }
322 
323 u32
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 
338 u32
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 
348 /**
349  * Returns app name for app-index
350  */
351 const u8 *
353 {
354  application_t *app = application_get (app_index);
355  if (!app)
356  return 0;
357  return app_get_name (app);
358 }
359 
360 static void
361 application_api_table_add (u32 app_index, u32 api_client_index)
362 {
363  if (api_client_index != APP_INVALID_INDEX)
364  hash_set (app_main.app_by_api_client_index, api_client_index, app_index);
365 }
366 
367 static void
368 application_api_table_del (u32 api_client_index)
369 {
370  hash_unset (app_main.app_by_api_client_index, api_client_index);
371 }
372 
373 static void
375 {
376  hash_set_mem (app_main.app_by_name, app->name, app->app_index);
377 }
378 
379 static void
381 {
382  hash_unset_mem (app_main.app_by_name, app->name);
383 }
384 
386 application_lookup (u32 api_client_index)
387 {
388  uword *p;
389  p = hash_get (app_main.app_by_api_client_index, api_client_index);
390  if (p)
391  return application_get_if_valid (p[0]);
392 
393  return 0;
394 }
395 
398 {
399  uword *p;
400  p = hash_get_mem (app_main.app_by_name, name);
401  if (p)
402  return application_get (p[0]);
403 
404  return 0;
405 }
406 
407 static application_t *
409 {
410  application_t *app;
411  pool_get (app_main.app_pool, app);
412  clib_memset (app, 0, sizeof (*app));
413  app->app_index = app - app_main.app_pool;
414  return app;
415 }
416 
418 application_get (u32 app_index)
419 {
420  if (app_index == APP_INVALID_INDEX)
421  return 0;
422  return pool_elt_at_index (app_main.app_pool, app_index);
423 }
424 
427 {
428  if (pool_is_free_index (app_main.app_pool, app_index))
429  return 0;
430 
431  return pool_elt_at_index (app_main.app_pool, app_index);
432 }
433 
434 static void
436 {
437  if (cb_fns->session_accept_callback == 0)
438  clib_warning ("No accept callback function provided");
439  if (cb_fns->session_connected_callback == 0)
440  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 
447 /**
448  * Check app config for given segment type
449  *
450  * Returns 1 on success and 0 otherwise
451  */
452 static u8
454 {
455  u8 is_valid;
456  if (st == SSVM_SEGMENT_MEMFD)
457  {
458  is_valid = (session_main_get_evt_q_segment () != 0);
459  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  {
465  is_valid = (session_main_get_evt_q_segment () == 0);
466  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 
474 static int
476 {
480  application_t *app;
481  u64 *options;
482 
483  app = application_alloc ();
484  options = a->options;
485  /*
486  * Make sure we support the requested configuration
487  */
488  if (!(options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_IS_BUILTIN))
489  {
490  reg = vl_api_client_index_to_registration (a->api_client_index);
491  if (!reg)
492  return VNET_API_ERROR_APP_UNSUPPORTED_CFG;
494  seg_type = SSVM_SEGMENT_SHM;
495  }
496  else
497  {
498  seg_type = SSVM_SEGMENT_PRIVATE;
499  }
500 
501  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 
509  if (!application_verify_cfg (seg_type))
510  return VNET_API_ERROR_APP_UNSUPPORTED_CFG;
511 
512  /* Check that the obvious things are properly set up */
513  application_verify_cb_fns (a->session_cb_vft);
514 
515  app->flags = options[APP_OPTIONS_FLAGS];
516  app->cb_fns = *a->session_cb_vft;
517  app->ns_index = options[APP_OPTIONS_NAMESPACE];
519  app->name = vec_dup (a->name);
520 
521  /* If no scope enabled, default to global */
523  && !application_has_local_scope (app))
524  app->flags |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
525 
528  props->segment_size = options[APP_OPTIONS_SEGMENT_SIZE];
529  props->prealloc_fifos = options[APP_OPTIONS_PREALLOC_FIFO_PAIRS];
530  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];
539  if (options[APP_OPTIONS_EVT_QUEUE_SIZE])
540  props->evt_q_size = options[APP_OPTIONS_EVT_QUEUE_SIZE];
541  if (options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
542  props->use_mq_eventfd = 1;
543  if (options[APP_OPTIONS_TLS_ENGINE])
544  app->tls_engine = options[APP_OPTIONS_TLS_ENGINE];
545  props->segment_type = seg_type;
546 
547  /* Add app to lookup by api_client_index table */
548  if (!application_is_builtin (app))
549  application_api_table_add (app->app_index, a->api_client_index);
550  else
552 
553  a->app_index = app->app_index;
554 
555  APP_DBG ("New app name: %v api index: %u index %u", app->name,
556  a->api_client_index, app->app_index);
557 
558  return 0;
559 }
560 
561 static void
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  */
571  APP_DBG ("Delete app name %v index: %d", app->name, app->app_index);
572 
573  if (application_is_proxy (app))
575 
576  /*
577  * Free workers
578  */
579 
580  /* *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 
588  /*
589  * Cleanup remaining state
590  */
591  if (application_is_builtin (app))
593  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 
599 static void
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,
614  app->app_index, api_client_index);
615 
616  /* *INDENT-OFF* */
617  pool_foreach (wrk_map, app->worker_maps, ({
618  app_wrk = app_worker_get (wrk_map->wrk_index);
619  if (app_wrk->api_client_index == api_client_index)
620  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;
632  args->api_client_index = api_client_index;
633  vec_foreach (wrk_index, wrks)
634  {
635  app_wrk = app_worker_get (wrk_index[0]);
636  args->wrk_map_index = app_wrk->wrk_map_index;
637  args->is_add = 0;
639  }
640  vec_free (wrks);
641 }
642 
643 app_worker_t *
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 
653 app_worker_t *
655 {
656  return application_get_worker (app, 0);
657 }
658 
659 u32
661 {
662  return pool_elts (app->worker_maps);
663 }
664 
665 app_worker_t *
667 {
668  application_t *app;
669  app_listener_t *al;
670 
671  app = application_get (ls->app_index);
672  al = app_listener_get (app, ls->al_index);
673  return app_listener_select_worker (app, al);
674 }
675 
676 int
678 {
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  */
692  sm = segment_manager_alloc ();
693  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  }
701  sm->first_is_protected = 1;
702 
703  /*
704  * Setup app worker
705  */
707  app_wrk->listeners_table = hash_create (0, sizeof (u64));
709  app_wrk->app_is_builtin = application_is_builtin (app);
710 
711  *wrk = app_wrk;
712 
713  return 0;
714 }
715 
716 int
718 {
719  fifo_segment_t *fs;
720  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 
741  a->segment = &fs->ssvm;
742  a->segment_handle = segment_manager_segment_handle (sm, fs);
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 
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 
766 static int
767 app_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 
788 static u8 *
789 app_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)
794  return format (0, "%s", regp->name);
795 
796  clib_warning ("api client index %u does not have an api registration!",
797  api_client_index);
798  return format (0, "unknown");
799 }
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  */
808 int
810 {
811  fifo_segment_t *fs;
812  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;
852 
853  if (application_is_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 
861  vec_free (app_name);
862  return 0;
863 }
864 
865 /**
866  * Detach application from vpp
867  */
868 int
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 
881  application_detach_process (app, a->api_client_index);
882  return 0;
883 }
884 
885 
886 static u8
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 
901 static void
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)
912  ns_index = sep->ns_index;
913 
914  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 
946 int
948 {
949  app_listener_t *app_listener;
950  app_worker_t *app_wrk;
951  application_t *app;
952  int rv;
953 
954  app = application_get_if_valid (a->app_index);
955  if (!app)
956  return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
957 
958  app_wrk = application_get_worker (app, a->wrk_map_index);
959  if (!app_wrk)
960  return VNET_API_ERROR_INVALID_VALUE;
961 
962  a->sep_ext.app_wrk_index = app_wrk->wrk_index;
963 
964  session_endpoint_update_for_app (&a->sep_ext, app, 0 /* is_connect */ );
965  if (!session_endpoint_in_ns (&a->sep))
966  return VNET_API_ERROR_INVALID_VALUE_2;
967 
968  /*
969  * Check if we already have an app listener
970  */
971  app_listener = app_listener_lookup (app, &a->sep_ext);
972  if (app_listener)
973  {
974  if (app_listener->app_index != app->app_index)
975  return VNET_API_ERROR_ADDRESS_IN_USE;
976  if (app_worker_start_listen (app_wrk, app_listener))
977  return -1;
978  a->handle = app_listener_handle (app_listener);
979  return 0;
980  }
981 
982  /*
983  * Create new app listener
984  */
985  if ((rv = app_listener_alloc_and_init (app, &a->sep_ext, &app_listener)))
986  return rv;
987 
988  if ((rv = app_worker_start_listen (app_wrk, app_listener)))
989  {
990  app_listener_cleanup (app_listener);
991  return rv;
992  }
993 
994  a->handle = app_listener_handle (app_listener);
995  return 0;
996 }
997 
998 int
1000 {
1001  app_worker_t *client_wrk;
1002  application_t *client;
1003 
1004  if (session_endpoint_is_zero (&a->sep))
1005  return VNET_API_ERROR_INVALID_VALUE;
1006 
1007  client = application_get (a->app_index);
1008  session_endpoint_update_for_app (&a->sep_ext, client, 1 /* is_connect */ );
1009  client_wrk = application_get_worker (client, a->wrk_map_index);
1010 
1011  /*
1012  * First check the local scope for locally attached destinations.
1013  * If we have local scope, we pass *all* connects through it since we may
1014  * have special policy rules even for non-local destinations, think proxy.
1015  */
1016  if (application_has_local_scope (client))
1017  {
1018  int rv;
1019 
1020  a->sep_ext.original_tp = a->sep_ext.transport_proto;
1021  a->sep_ext.transport_proto = TRANSPORT_PROTO_NONE;
1022  rv = app_worker_connect_session (client_wrk, &a->sep, a->api_context);
1023  if (rv <= 0)
1024  return rv;
1025  }
1026  /*
1027  * Not connecting to a local server, propagate to transport
1028  */
1029  if (app_worker_connect_session (client_wrk, &a->sep, a->api_context))
1030  return VNET_API_ERROR_SESSION_CONNECT;
1031  return 0;
1032 }
1033 
1034 int
1036 {
1037  app_worker_t *app_wrk;
1038  app_listener_t *al;
1039  application_t *app;
1040 
1041  if (!(app = application_get_if_valid (a->app_index)))
1042  return VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1043 
1044  if (!(al = app_listener_get_w_handle (a->handle)))
1045  return -1;
1046 
1047  if (al->app_index != app->app_index)
1048  {
1049  clib_warning ("app doesn't own handle %llu!", a->handle);
1050  return -1;
1051  }
1052 
1053  app_wrk = application_get_worker (app, a->wrk_map_index);
1054  if (!app_wrk)
1055  {
1056  clib_warning ("no app %u worker %u", app->app_index, a->wrk_map_index);
1057  return -1;
1058  }
1059 
1060  return app_worker_stop_listen (app_wrk, al);
1061 }
1062 
1063 int
1065 {
1066  app_worker_t *app_wrk;
1067  session_t *s;
1068 
1069  s = session_get_from_handle_if_valid (a->handle);
1070  if (!s)
1071  return VNET_API_ERROR_INVALID_VALUE;
1072  app_wrk = app_worker_get (s->app_wrk_index);
1073  if (app_wrk->app_index != a->app_index)
1074  return VNET_API_ERROR_INVALID_VALUE;
1075 
1076  /* We're peeking into another's thread pool. Make sure */
1077  ASSERT (s->session_index == session_index_from_handle (a->handle));
1078 
1079  session_close (s);
1080  return 0;
1081 }
1082 
1083 int
1085 {
1086  app_worker_t *old_wrk = app_worker_get (s->app_wrk_index);
1087  app_listener_t *app_listener;
1088  application_t *app;
1089 
1090  if (!old_wrk)
1091  return -1;
1092 
1095  && s->rx_fifo)
1097 
1098  app = application_get (old_wrk->app_index);
1099  if (!app)
1100  return -1;
1101 
1102  app_listener = app_listener_get (app, s->al_index);
1103 
1104  /* Only remove from lb for now */
1105  app_listener->workers = clib_bitmap_set (app_listener->workers,
1106  old_wrk->wrk_map_index, 0);
1107 
1108  if (app_worker_start_listen (app_wrk, app_listener))
1109  return -1;
1110 
1111  s->app_wrk_index = app_wrk->wrk_index;
1112 
1113  return 0;
1114 }
1115 
1116 int
1118 {
1119  return (app->flags & APP_OPTIONS_FLAGS_IS_PROXY);
1120 }
1121 
1122 int
1124 {
1125  return (app->flags & APP_OPTIONS_FLAGS_IS_BUILTIN);
1126 }
1127 
1128 int
1130 {
1131  return (application_is_proxy (app) && application_is_builtin (app));
1132 }
1133 
1134 u8
1136 {
1137  return app->flags & APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1138 }
1139 
1140 u8
1142 {
1143  return app->flags & APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE;
1144 }
1145 
1146 static clib_error_t *
1148  u8 transport_proto, u8 is_start)
1149 {
1150  app_namespace_t *app_ns = app_namespace_get (app->ns_index);
1151  u8 is_ip4 = (fib_proto == FIB_PROTOCOL_IP4);
1154  app_worker_t *app_wrk;
1155  app_listener_t *al;
1156  session_t *s;
1157  u32 flags;
1158 
1159  /* TODO decide if we want proxy to be enabled for all workers */
1160  app_wrk = application_get_default_worker (app);
1161  if (is_start)
1162  {
1163  s = app_worker_first_listener (app_wrk, fib_proto, transport_proto);
1164  if (!s)
1165  {
1166  sep.is_ip4 = is_ip4;
1167  sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto);
1168  sep.sw_if_index = app_ns->sw_if_index;
1169  sep.transport_proto = transport_proto;
1170  sep.app_wrk_index = app_wrk->wrk_index; /* only default */
1171 
1172  /* force global scope listener */
1173  flags = app->flags;
1174  app->flags &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE;
1175  app_listener_alloc_and_init (app, &sep, &al);
1176  app->flags = flags;
1177 
1178  app_worker_start_listen (app_wrk, al);
1180  s->flags |= SESSION_F_PROXY;
1181  }
1182  }
1183  else
1184  {
1185  s = app_worker_proxy_listener (app_wrk, fib_proto, transport_proto);
1186  ASSERT (s);
1187  }
1188 
1190 
1191  if (!ip_is_zero (&tc->lcl_ip, 1))
1192  {
1193  u32 sti;
1194  sep.is_ip4 = is_ip4;
1195  sep.fib_index = app_namespace_get_fib_index (app_ns, fib_proto);
1196  sep.transport_proto = transport_proto;
1197  sep.port = 0;
1198  sti = session_lookup_get_index_for_fib (fib_proto, sep.fib_index);
1199  if (is_start)
1201  (session_endpoint_t *) & sep,
1202  s->session_index);
1203  else
1205  (session_endpoint_t *) & sep);
1206  }
1207 
1208  return 0;
1209 }
1210 
1211 static void
1213  u8 transport_proto, u8 is_start)
1214 {
1216  app_namespace_t *app_ns;
1217  app_ns = app_namespace_get (app->ns_index);
1218  sep.is_ip4 = 1;
1219  sep.transport_proto = transport_proto;
1220  sep.port = 0;
1221 
1222  if (is_start)
1223  {
1224  session_lookup_add_session_endpoint (app_ns->local_table_index, &sep,
1225  app->app_index);
1226  sep.is_ip4 = 0;
1227  session_lookup_add_session_endpoint (app_ns->local_table_index, &sep,
1228  app->app_index);
1229  }
1230  else
1231  {
1232  session_lookup_del_session_endpoint (app_ns->local_table_index, &sep);
1233  sep.is_ip4 = 0;
1234  session_lookup_del_session_endpoint (app_ns->local_table_index, &sep);
1235  }
1236 }
1237 
1238 void
1240  transport_proto_t transport_proto, u8 is_start)
1241 {
1242  if (application_has_local_scope (app))
1243  application_start_stop_proxy_local_scope (app, transport_proto, is_start);
1244 
1245  if (application_has_global_scope (app))
1246  {
1248  transport_proto, is_start);
1250  transport_proto, is_start);
1251  }
1252 }
1253 
1254 void
1256 {
1257  u16 transports = app->proxied_transports;
1258  transport_proto_t tp;
1259 
1260  ASSERT (application_is_proxy (app));
1261 
1262  /* *INDENT-OFF* */
1263  transport_proto_foreach (tp, ({
1264  if (transports & (1 << tp))
1265  application_start_stop_proxy (app, tp, 1);
1266  }));
1267  /* *INDENT-ON* */
1268 }
1269 
1270 void
1272 {
1273  u16 transports = app->proxied_transports;
1274  transport_proto_t tp;
1275 
1276  ASSERT (application_is_proxy (app));
1277 
1278  /* *INDENT-OFF* */
1279  transport_proto_foreach (tp, ({
1280  if (transports & (1 << tp))
1281  application_start_stop_proxy (app, tp, 0);
1282  }));
1283  /* *INDENT-ON* */
1284 }
1285 
1288 {
1289  return &app->sm_properties;
1290 }
1291 
1294 {
1295  application_t *app = application_get (app_index);
1296  return &app->sm_properties;
1297 }
1298 
1299 clib_error_t *
1301 {
1302  application_t *app;
1303  app = application_get (a->app_index);
1304  if (!app)
1305  return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED,
1306  0, "app %u doesn't exist", a->app_index);
1307  app->tls_cert = vec_dup (a->cert);
1308  return 0;
1309 }
1310 
1311 clib_error_t *
1313 {
1314  application_t *app;
1315  app = application_get (a->app_index);
1316  if (!app)
1317  return clib_error_return_code (0, VNET_API_ERROR_APPLICATION_NOT_ATTACHED,
1318  0, "app %u doesn't exist", a->app_index);
1319  app->tls_key = vec_dup (a->key);
1320  return 0;
1321 }
1322 
1323 static void
1325 {
1327  app_worker_map_t *wrk_map;
1328  app_worker_t *app_wrk;
1329  u32 sm_index;
1330  u64 handle;
1331 
1332  if (!app)
1333  {
1334  vlib_cli_output (vm, "%U", format_app_worker_listener, 0 /* header */ ,
1335  0, 0, verbose);
1336  return;
1337  }
1338 
1339  /* *INDENT-OFF* */
1340  pool_foreach (wrk_map, app->worker_maps, ({
1341  app_wrk = app_worker_get (wrk_map->wrk_index);
1342  if (hash_elts (app_wrk->listeners_table) == 0)
1343  continue;
1344  hash_foreach (handle, sm_index, app_wrk->listeners_table, ({
1345  vlib_cli_output (vm, "%U", format_app_worker_listener, app_wrk,
1346  handle, sm_index, verbose);
1347  }));
1348  }));
1349  /* *INDENT-ON* */
1350 }
1351 
1352 static void
1354 {
1355  app_worker_map_t *wrk_map;
1356  app_worker_t *app_wrk;
1357 
1358  if (!app)
1359  {
1360  app_worker_format_connects (0, verbose);
1361  return;
1362  }
1363 
1364  /* *INDENT-OFF* */
1365  pool_foreach (wrk_map, app->worker_maps, ({
1366  app_wrk = app_worker_get (wrk_map->wrk_index);
1367  app_worker_format_connects (app_wrk, verbose);
1368  }));
1369  /* *INDENT-ON* */
1370 }
1371 
1372 u8 *
1373 format_application (u8 * s, va_list * args)
1374 {
1375  application_t *app = va_arg (*args, application_t *);
1376  CLIB_UNUSED (int verbose) = va_arg (*args, int);
1377  segment_manager_props_t *props;
1378  const u8 *app_ns_name, *app_name;
1379  app_worker_map_t *wrk_map;
1380  app_worker_t *app_wrk;
1381 
1382  if (app == 0)
1383  {
1384  if (!verbose)
1385  s = format (s, "%-10s%-20s%-40s", "Index", "Name", "Namespace");
1386  return s;
1387  }
1388 
1389  app_name = app_get_name (app);
1390  app_ns_name = app_namespace_id_from_index (app->ns_index);
1392  if (!verbose)
1393  {
1394  s = format (s, "%-10u%-20v%-40s", app->app_index, app_name,
1395  app_ns_name);
1396  return s;
1397  }
1398 
1399  s = format (s, "app-name %v app-index %u ns-index %u seg-size %U\n",
1400  app_name, app->app_index, app->ns_index,
1401  format_memory_size, props->add_segment_size);
1402  s = format (s, "rx-fifo-size %U tx-fifo-size %U workers:\n",
1403  format_memory_size, props->rx_fifo_size,
1404  format_memory_size, props->tx_fifo_size);
1405 
1406  /* *INDENT-OFF* */
1407  pool_foreach (wrk_map, app->worker_maps, ({
1408  app_wrk = app_worker_get (wrk_map->wrk_index);
1409  s = format (s, "%U", format_app_worker, app_wrk);
1410  }));
1411  /* *INDENT-ON* */
1412 
1413  return s;
1414 }
1415 
1416 void
1418 {
1419  application_t *app;
1420 
1421  if (!pool_elts (app_main.app_pool))
1422  {
1423  vlib_cli_output (vm, "No active server bindings");
1424  return;
1425  }
1426 
1427  application_format_listeners (0, verbose);
1428 
1429  /* *INDENT-OFF* */
1430  pool_foreach (app, app_main.app_pool, ({
1431  application_format_listeners (app, verbose);
1432  }));
1433  /* *INDENT-ON* */
1434 }
1435 
1436 void
1438 {
1439  application_t *app;
1440 
1441  if (!pool_elts (app_main.app_pool))
1442  {
1443  vlib_cli_output (vm, "No active apps");
1444  return;
1445  }
1446 
1447  application_format_connects (0, verbose);
1448 
1449  /* *INDENT-OFF* */
1450  pool_foreach (app, app_main.app_pool, ({
1451  application_format_connects (app, verbose);
1452  }));
1453  /* *INDENT-ON* */
1454 }
1455 
1456 static clib_error_t *
1458  vlib_cli_command_t * cmd)
1459 {
1460  int do_server = 0, do_client = 0;
1461  application_t *app;
1462  u32 app_index = ~0;
1463  int verbose = 0;
1464 
1466 
1467  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1468  {
1469  if (unformat (input, "server"))
1470  do_server = 1;
1471  else if (unformat (input, "client"))
1472  do_client = 1;
1473  else if (unformat (input, "%u", &app_index))
1474  ;
1475  else if (unformat (input, "verbose"))
1476  verbose = 1;
1477  else
1478  return clib_error_return (0, "unknown input `%U'",
1479  format_unformat_error, input);
1480  }
1481 
1482  if (do_server)
1483  {
1484  application_format_all_listeners (vm, verbose);
1485  return 0;
1486  }
1487 
1488  if (do_client)
1489  {
1490  application_format_all_clients (vm, verbose);
1491  return 0;
1492  }
1493 
1494  if (app_index != ~0)
1495  {
1496  app = application_get_if_valid (app_index);
1497  if (!app)
1498  return clib_error_return (0, "No app with index %u", app_index);
1499 
1500  vlib_cli_output (vm, "%U", format_application, app, /* verbose */ 1);
1501  return 0;
1502  }
1503 
1504  /* Print app related info */
1505  if (!do_server && !do_client)
1506  {
1507  vlib_cli_output (vm, "%U", format_application, 0, 0);
1508  /* *INDENT-OFF* */
1509  pool_foreach (app, app_main.app_pool, ({
1510  vlib_cli_output (vm, "%U", format_application, app, 0);
1511  }));
1512  /* *INDENT-ON* */
1513  }
1514 
1515  return 0;
1516 }
1517 
1518 /* *INDENT-OFF* */
1519 VLIB_CLI_COMMAND (show_app_command, static) =
1520 {
1521  .path = "show app",
1522  .short_help = "show app [server|client] [verbose]",
1523  .function = show_app_command_fn,
1524 };
1525 /* *INDENT-ON* */
1526 
1527 /*
1528  * fd.io coding-style-patch-verification: ON
1529  *
1530  * Local Variables:
1531  * eval: (c-set-style "gnu")
1532  * End:
1533  */
u32 segment_manager_index(segment_manager_t *sm)
static void application_name_table_del(application_t *app)
Definition: application.c:380
u32 flags
Flags.
Definition: application.h:92
u32 al_index
App listener index in app&#39;s listener pool if a listener.
struct _vnet_app_worker_add_del_args vnet_app_worker_add_del_args_t
#define ENDPOINT_INVALID_INDEX
#define APP_NAMESPACE_INVALID_INDEX
session_t * app_worker_proxy_listener(app_worker_t *app, u8 fib_proto, u8 transport_proto)
u8 * name
Client name.
Definition: api_common.h:53
#define hash_set(h, key, value)
Definition: hash.h:255
void segment_manager_segment_reader_unlock(segment_manager_t *sm)
u32 flags
Definition: vhost_user.h:141
u64 segment_manager_segment_handle(segment_manager_t *sm, fifo_segment_t *segment)
#define CLIB_UNUSED(x)
Definition: clib.h:82
static void application_detach_process(application_t *app, u32 api_client_index)
Definition: application.c:600
u32 al_index
app listener index in app pool
Definition: application.h:77
#define hash_unset(h, key)
Definition: hash.h:261
a
Definition: bitmap.h:538
u64 session_lookup_endpoint_listener(u32 table_index, session_endpoint_t *sep, u8 use_rules)
Lookup listener for session endpoint in table.
svm_fifo_t * tx_fifo
u32 ns_index
Namespace the application belongs to.
Definition: application.h:107
u8 application_has_global_scope(application_t *app)
Definition: application.c:1141
struct _vnet_connect_args vnet_connect_args_t
struct _vnet_unlisten_args_t vnet_unlisten_args_t
int application_change_listener_owner(session_t *s, app_worker_t *app_wrk)
Definition: application.c:1084
u32 session_index
Index in thread pool where session was allocated.
int session_stop_listen(session_t *s)
Ask transport to stop listening on local transport endpoint.
Definition: session.c:1161
#define session_cli_return_if_not_enabled()
Definition: session.h:565
u8 ip_is_local(u32 fib_index, ip46_address_t *ip46_address, u8 is_ip4)
Checks that an ip is local to the requested fib.
Definition: ip.c:55
static clib_error_t * show_app_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: application.c:1457
unsigned long u64
Definition: types.h:89
transport_connection_t * listen_session_get_transport(session_t *s)
Definition: session.c:1421
static app_worker_t * app_listener_select_worker(application_t *app, app_listener_t *al)
Definition: application.c:257
transport_connection_t * session_get_transport(session_t *s)
Definition: session.c:1398
application_t * application_lookup_name(const u8 *name)
Definition: application.c:397
svm_fifo_t * rx_fifo
Pointers to rx/tx buffers.
u8 ip_interface_has_address(u32 sw_if_index, ip46_address_t *ip, u8 is_ip4)
Definition: ip.c:100
app_listener_t * app_listener_get_w_session(session_t *ls)
Definition: application.c:67
int app_worker_connect_session(app_worker_t *app, session_endpoint_t *tep, u32 api_context)
u32 session_lookup_get_index_for_fib(u32 fib_proto, u32 fib_index)
static session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:501
application_t * application_lookup(u32 api_client_index)
Definition: application.c:386
app_listener_t * app_listener_get(application_t *app, u32 app_listener_index)
Definition: application.c:46
app_listener_t * listeners
Pool of listeners for the app.
Definition: application.h:112
u32 wrk_map_index
Worker index in app&#39;s map pool.
Definition: application.h:40
session_handle_t app_listener_handle(app_listener_t *al)
Definition: application.c:61
static session_t * listen_session_alloc(u8 thread_index, session_type_t type)
Definition: session.h:514
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
Definition: bitmap.h:167
format_function_t format_ip46_address
Definition: format.h:61
#define hash_set_mem(h, key, value)
Definition: hash.h:275
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static u8 session_endpoint_fib_proto(session_endpoint_t *sep)
Definition: session_types.h:94
static session_t * session_get(u32 si, u32 thread_index)
Definition: session.h:258
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
int vnet_unlisten(vnet_unlisten_args_t *a)
Definition: application.c:1035
uword * listeners_table
Lookup tables for listeners.
Definition: application.h:52
struct _vnet_application_add_tls_cert_args_t vnet_app_add_tls_cert_args_t
u32 flags
Session flags.
u8 app_is_builtin
Definition: application.h:65
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
clib_error_t * vnet_app_add_tls_cert(vnet_app_add_tls_cert_args_t *a)
Definition: application.c:1300
unsigned char u8
Definition: types.h:56
app_worker_t * application_get_worker(application_t *app, u32 wrk_map_index)
Definition: application.c:644
#define SESSION_ENDPOINT_NULL
Definition: session_types.h:64
static u8 session_endpoint_in_ns(session_endpoint_t *sep)
Definition: application.c:887
int segment_manager_init(segment_manager_t *sm, u32 first_seg_size, u32 prealloc_fifo_pairs)
Initializes segment manager based on options provided.
application_t * application_get_if_valid(u32 app_index)
Definition: application.c:426
struct _vnet_bind_args_t vnet_listen_args_t
segment_manager_props_t * application_segment_manager_properties(application_t *app)
Definition: application.c:1287
static session_handle_t session_handle(session_t *s)
u8 session_type_t
static int application_alloc_and_init(app_init_args_t *a)
Definition: application.c:475
u32 app_index
owning app index
Definition: application.h:78
int application_is_proxy(application_t *app)
Definition: application.c:1117
enum ssvm_segment_type_ ssvm_segment_type_t
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
u32 first_segment_manager
First segment manager has in the the first segment the application&#39;s event fifo.
Definition: application.h:59
struct _vnet_disconnect_args_t vnet_disconnect_args_t
void segment_manager_dealloc_fifos(svm_fifo_t *rx_fifo, svm_fifo_t *tx_fifo)
u32 local_index
local listening session index
Definition: application.h:79
u32 session_index
global listening session index
Definition: application.h:80
u8 * format_memory_size(u8 *s, va_list *va)
Definition: std-formats.c:209
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
u32 app_namespace_index_from_id(const u8 *ns_id)
u16 proxied_transports
Definition: application.h:109
static int app_validate_namespace(u8 *namespace_id, u64 secret, u32 *app_ns_index)
Definition: application.c:767
#define SESSION_INVALID_HANDLE
Definition: session_types.h:23
u8 tls_engine
Preferred tls engine.
Definition: application.h:125
struct _vnet_app_attach_args_t vnet_app_attach_args_t
struct _session_endpoint_cfg session_endpoint_cfg_t
static const u8 * app_get_name(application_t *app)
Definition: application.c:318
#define pool_flush(VAR, POOL, BODY)
Remove all elements from a pool in a safe way.
Definition: pool.h:553
static app_main_t app_main
Definition: application.c:22
static void application_verify_cb_fns(session_cb_vft_t *cb_fns)
Definition: application.c:435
clib_error_t * vnet_app_add_tls_key(vnet_app_add_tls_key_args_t *a)
Definition: application.c:1312
int application_is_builtin(application_t *app)
Definition: application.c:1123
#define hash_get(h, key)
Definition: hash.h:249
u32 app_namespace_get_fib_index(app_namespace_t *app_ns, u8 fib_proto)
static session_type_t session_type_from_proto_and_ip(transport_proto_t proto, u8 is_ip4)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
#define hash_unset_mem(h, key)
Definition: hash.h:291
session_t * app_listener_get_local_session(app_listener_t *al)
Definition: application.c:281
#define VL_API_INVALID_FI
Definition: api_common.h:77
static uword clib_bitmap_first_set(uword *ai)
Return the lowest numbered set bit in a bitmap.
Definition: bitmap.h:385
static void application_api_table_del(u32 api_client_index)
Definition: application.c:368
static session_t * session_get_from_handle(session_handle_t handle)
Definition: session.h:278
session_t * app_listener_get_session(app_listener_t *al)
Definition: application.c:272
u32 app_index
Index of application that owns the listener.
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
const u8 * application_name_from_index(u32 app_index)
Returns app name for app-index.
Definition: application.c:352
static u32 app_worker_map_index(application_t *app, app_worker_map_t *map)
Definition: application.c:298
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#define APP_INVALID_INDEX
Definition: application.h:167
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:375
struct _segment_manager_props segment_manager_props_t
app_namespace_t * app_namespace_get(u32 index)
u32 wrk_index
Worker index in global worker pool.
Definition: application.h:37
u32 application_session_table(application_t *app, u8 fib_proto)
Definition: application.c:324
#define SESSION_INVALID_INDEX
Definition: session_types.h:22
app_worker_t * app_worker_alloc(application_t *app)
u8 name[64]
Definition: memclnt.api:152
session_handle_t app_listen_session_handle(session_t *ls)
Get app listener handle for listening session.
Definition: application.c:78
static u64 listen_session_get_handle(session_t *s)
Definition: session.h:493
u8 * format_app_worker_listener(u8 *s, va_list *args)
app_worker_map_t * worker_maps
Pool of mappings that keep track of workers associated to this app.
Definition: application.h:101
int vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
Definition: application.c:809
static session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:287
#define pool_free(p)
Free a pool.
Definition: pool.h:407
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
svm_msg_q_t * segment_manager_event_queue(segment_manager_t *sm)
u32 application_local_session_table(application_t *app)
Definition: application.c:339
ssvm_private_t ssvm
ssvm segment data
Definition: fifo_segment.h:52
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
uword * app_by_name
Hash table of builtin apps by name.
Definition: application.h:146
vlib_main_t * vm
Definition: buffer.c:312
segment_manager_t * segment_manager_alloc(void)
static void app_listener_free(application_t *app, app_listener_t *app_listener)
Definition: application.c:52
session_t * app_worker_first_listener(app_worker_t *app, u8 fib_proto, u8 transport_proto)
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
segment_manager_props_t sm_properties
Segment manager properties.
Definition: application.h:98
static application_t * application_alloc(void)
Definition: application.c:408
int session_lookup_del_session_endpoint(u32 table_index, session_endpoint_t *sep)
void session_free(session_t *s)
Definition: session.c:194
#define clib_warning(format, args...)
Definition: error.h:59
struct _stream_session_cb_vft session_cb_vft_t
static void session_endpoint_update_for_app(session_endpoint_cfg_t *sep, application_t *app, u8 is_connect)
Definition: application.c:902
Don&#39;t register connection in lookup Does not apply to local apps and transports using the network lay...
clib_bitmap_t * workers
workers accepting connections
Definition: application.h:75
struct _transport_connection transport_connection_t
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
const u8 * app_namespace_id_from_index(u32 index)
void application_format_all_clients(vlib_main_t *vm, int verbose)
Definition: application.c:1437
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
int session_lookup_add_session_endpoint(u32 table_index, session_endpoint_t *sep, u64 value)
static u32 vl_api_registration_file_index(vl_api_registration_t *reg)
Definition: api.h:64
static void application_name_table_add(application_t *app)
Definition: application.c:374
struct _app_namespace app_namespace_t
application_t * application_get(u32 app_index)
Definition: application.c:418
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
segment_manager_props_t * application_get_segment_manager_properties(u32 app_index)
Definition: application.c:1293
int session_listen(session_t *ls, session_endpoint_cfg_t *sep)
Ask transport to listen on session endpoint.
Definition: session.c:1133
static u32 session_index_from_handle(session_handle_t handle)
#define hash_create(elts, value_bytes)
Definition: hash.h:696
int app_listener_alloc_and_init(application_t *app, session_endpoint_cfg_t *sep, app_listener_t **listener)
Definition: application.c:130
app_listener_t * app_listener_get_w_handle(session_handle_t handle)
Get app listener for listener session handle.
Definition: application.c:88
#define ASSERT(truth)
int application_alloc_worker_and_init(application_t *app, app_worker_t **wrk)
Definition: application.c:677
segment_manager_props_t * segment_manager_props_init(segment_manager_props_t *props)
app_worker_t * application_listener_select_worker(session_t *ls)
Definition: application.c:666
static u8 * app_name_from_api_index(u32 api_client_index)
Definition: application.c:789
int vnet_listen(vnet_listen_args_t *a)
Definition: application.c:947
uword * app_by_api_client_index
Hash table of apps by api client index.
Definition: application.h:141
fifo_segment_t * segment_manager_get_segment_w_lock(segment_manager_t *sm, u32 segment_index)
Reads a segment from the segment manager&#39;s pool and acquires reader lock.
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
Definition: application.c:869
void application_remove_proxy(application_t *app)
Definition: application.c:1271
session_cb_vft_t cb_fns
Callbacks: shoulder-taps for the server/client.
Definition: application.h:95
struct _vnet_application_add_tls_key_args_t vnet_app_add_tls_key_args_t
enum _transport_proto transport_proto_t
u8 * tls_key
PEM encoded key.
Definition: application.h:122
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
u32 accept_rotor
last worker to accept a connection
Definition: application.h:76
struct _vnet_app_detach_args_t vnet_app_detach_args_t
int vnet_connect(vnet_connect_args_t *a)
Definition: application.c:999
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u8 * name
Definition: ssvm.h:87
static void listen_session_free(session_t *s)
Definition: session.h:530
u8 ip_is_zero(ip46_address_t *ip46_address, u8 is_ip4)
Definition: ip.c:20
u32 app_index
App index in app pool.
Definition: application.h:89
app_worker_t * app_worker_get(u32 wrk_index)
application_t * app_pool
Pool from which we allocate all applications.
Definition: application.h:136
u64 session_handle_t
static void application_free(application_t *app)
Definition: application.c:562
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_application(u8 *s, va_list *args)
Definition: application.c:1373
u8 * name
Name registered by builtin apps.
Definition: application.h:104
void session_close(session_t *s)
Initialize session closing procedure.
Definition: session.c:1186
u64 uword
Definition: types.h:112
session_handle_t ls_handle
session handle of the local or global listening session that also identifies the app listener ...
Definition: application.h:81
static u8 session_endpoint_is_zero(session_endpoint_t *sep)
static app_worker_map_t * app_worker_map_alloc(application_t *app)
Definition: application.c:289
ssvm_private_t * session_main_get_evt_q_segment(void)
Definition: session.c:1331
connectionless service
int vnet_disconnect_session(vnet_disconnect_args_t *a)
Definition: application.c:1064
app_worker_t * application_get_default_worker(application_t *app)
Definition: application.c:654
struct _segment_manager segment_manager_t
#define SESSION_ENDPOINT_CFG_NULL
Definition: session_types.h:74
segment_manager_t * segment_manager_get(u32 index)
u32 application_n_workers(application_t *app)
Definition: application.c:660
void app_listener_cleanup(app_listener_t *al)
Definition: application.c:230
int vnet_app_worker_add_del(vnet_app_worker_add_del_args_t *a)
Definition: application.c:717
static void application_api_table_add(u32 app_index, u32 api_client_index)
Definition: application.c:361
static void application_format_listeners(application_t *app, int verbose)
Definition: application.c:1324
int app_worker_start_listen(app_worker_t *app_wrk, app_listener_t *lstnr)
static clib_error_t * application_start_stop_proxy_fib_proto(application_t *app, u8 fib_proto, u8 transport_proto, u8 is_start)
Definition: application.c:1147
#define hash_get_mem(h, key)
Definition: hash.h:269
#define app_interface_check_thread_and_barrier(_fn, _arg)
Definition: application.c:24
u32 app_index
Index of owning app.
Definition: application.h:43
int session_lookup_add_connection(transport_connection_t *tc, u64 value)
Add transport connection to a session table.
app_listener_t * app_listener_lookup(application_t *app, session_endpoint_cfg_t *sep_ext)
Definition: application.c:98
static void application_start_stop_proxy_local_scope(application_t *app, u8 transport_proto, u8 is_start)
Definition: application.c:1212
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
int app_worker_stop_listen(app_worker_t *app_wrk, app_listener_t *al)
void app_worker_free(app_worker_t *app_wrk)
#define clib_error_return_code(e, code, flags, args...)
Definition: error.h:93
u8 * tls_cert
Certificate to be used for listen sessions.
Definition: application.h:119
#define transport_proto_foreach(VAR, BODY)
Definition: transport.h:90
static app_worker_map_t * app_worker_map_get(application_t *app, u32 map_index)
Definition: application.c:310
#define vec_foreach(var, vec)
Vector iterator.
u32 app_wrk_index
Index of the app worker that owns the session.
void application_setup_proxy(application_t *app)
Definition: application.c:1255
void app_worker_format_connects(app_worker_t *app_wrk, int verbose)
static u8 session_endpoint_is_local(session_endpoint_t *sep)
static u8 application_verify_cfg(ssvm_segment_type_t st)
Check app config for given segment type.
Definition: application.c:453
static void application_format_connects(application_t *app, int verbose)
Definition: application.c:1353
int application_is_builtin_proxy(application_t *app)
Definition: application.c:1129
u32 api_client_index
API index for the worker.
Definition: application.h:63
struct _session_endpoint session_endpoint_t
static void app_worker_map_free(application_t *app, app_worker_map_t *map)
Definition: application.c:304
void application_start_stop_proxy(application_t *app, transport_proto_t transport_proto, u8 is_start)
Definition: application.c:1239
svm_msg_q_t * event_queue
Application listens for events on this svm queue.
Definition: application.h:46
static transport_service_type_t session_transport_service_type(session_t *s)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:768
void application_format_all_listeners(vlib_main_t *vm, int verbose)
Definition: application.c:1417
#define APP_DBG(_fmt, _args...)
Definition: application.h:29
static session_t * listen_session_get(u32 ls_index)
Definition: session.h:524
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
void ct_session_endpoint(session_t *ll, session_endpoint_t *sep)
static app_listener_t * app_listener_alloc(application_t *app)
Definition: application.c:32
u8 application_has_local_scope(application_t *app)
Definition: application.c:1135
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128