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