FD.io VPP  v18.11-rc0-18-g2a3fb1a
Vector Packet Processing
session_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016 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 
16 #include <vnet/vnet.h>
17 #include <vlibmemory/api.h>
22 
23 #include <vnet/vnet_msg_enum.h>
24 
25 #define vl_typedefs /* define message structures */
26 #include <vnet/vnet_all_api_h.h>
27 #undef vl_typedefs
28 
29 #define vl_endianfun /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_endianfun
32 
33 /* instantiate all the print functions we know about */
34 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
35 #define vl_printfun
36 #include <vnet/vnet_all_api_h.h>
37 #undef vl_printfun
38 
40 
41 #define foreach_session_api_msg \
42 _(MAP_ANOTHER_SEGMENT_REPLY, map_another_segment_reply) \
43 _(APPLICATION_ATTACH, application_attach) \
44 _(APPLICATION_DETACH, application_detach) \
45 _(BIND_URI, bind_uri) \
46 _(UNBIND_URI, unbind_uri) \
47 _(CONNECT_URI, connect_uri) \
48 _(DISCONNECT_SESSION, disconnect_session) \
49 _(DISCONNECT_SESSION_REPLY, disconnect_session_reply) \
50 _(ACCEPT_SESSION_REPLY, accept_session_reply) \
51 _(RESET_SESSION_REPLY, reset_session_reply) \
52 _(BIND_SOCK, bind_sock) \
53 _(UNBIND_SOCK, unbind_sock) \
54 _(CONNECT_SOCK, connect_sock) \
55 _(SESSION_ENABLE_DISABLE, session_enable_disable) \
56 _(APP_NAMESPACE_ADD_DEL, app_namespace_add_del) \
57 _(SESSION_RULE_ADD_DEL, session_rule_add_del) \
58 _(SESSION_RULES_DUMP, session_rules_dump) \
59 _(APPLICATION_TLS_CERT_ADD, application_tls_cert_add) \
60 _(APPLICATION_TLS_KEY_ADD, application_tls_key_add) \
61 
62 static int
64 {
65  clib_error_t *error;
67  {
68  clib_warning ("can't send memfd fd");
69  return -1;
70  }
71  error = vl_api_send_fd_msg (reg, sp->fd);
72  if (error)
73  {
74  clib_error_report (error);
75  return -1;
76  }
77  return 0;
78 }
79 
80 static int
81 send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
82 {
85 
86  reg = vl_mem_api_client_index_to_registration (api_client_index);
87  if (!reg)
88  {
89  clib_warning ("no registration: %u", api_client_index);
90  return -1;
91  }
92 
93  if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD
95  {
96  clib_warning ("can't send memfd fd");
97  return -1;
98  }
99 
100  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
101  memset (mp, 0, sizeof (*mp));
102  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT);
103  mp->segment_size = sp->ssvm_size;
104  strncpy ((char *) mp->segment_name, (char *) sp->name,
105  sizeof (mp->segment_name) - 1);
106 
107  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
108 
109  if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
110  return session_send_memfd_fd (reg, sp);
111 
112  return 0;
113 }
114 
115 static int
116 send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs)
117 {
120 
121  reg = vl_mem_api_client_index_to_registration (api_client_index);
122  if (!reg)
123  {
124  clib_warning ("no registration: %u", api_client_index);
125  return -1;
126  }
127 
128  if (ssvm_type (fs) == SSVM_SEGMENT_MEMFD
130  {
131  clib_warning ("can't send memfd fd");
132  return -1;
133  }
134 
135  mp = vl_msg_api_alloc_as_if_client (sizeof (*mp));
136  memset (mp, 0, sizeof (*mp));
137  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT);
138  strncpy ((char *) mp->segment_name, (char *) fs->name,
139  sizeof (mp->segment_name) - 1);
140 
141  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
142 
143  if (ssvm_type (fs) == SSVM_SEGMENT_MEMFD)
144  return session_send_memfd_fd (reg, fs);
145 
146  return 0;
147 }
148 
149 static int
151 {
152  application_t *server = application_get (s->app_index);
153  transport_proto_vft_t *tp_vft;
157  stream_session_t *listener;
158  svm_msg_q_t *vpp_queue;
159 
160  reg = vl_mem_api_client_index_to_registration (server->api_client_index);
161  if (!reg)
162  {
163  clib_warning ("no registration: %u", server->api_client_index);
164  return -1;
165  }
166 
167  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
168  memset (mp, 0, sizeof (*mp));
169 
170  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
171  mp->context = server->index;
172  mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
173  mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
174 
175  if (session_has_transport (s))
176  {
177  listener = listen_session_get (s->listener_index);
179  if (application_is_proxy (server))
180  {
181  listener =
184  if (listener)
186  }
187  vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
188  mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
189  mp->handle = session_handle (s);
191  tc = tp_vft->get_connection (s->connection_index, s->thread_index);
192  mp->port = tc->rmt_port;
193  mp->is_ip4 = tc->is_ip4;
194  clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
195  }
196  else
197  {
198  local_session_t *ls = (local_session_t *) s;
199  local_session_t *ll;
201  {
202  listener = listen_session_get (ls->listener_index);
204  mp->is_ip4 = session_type_is_ip4 (listener->session_type);
205  }
206  else
207  {
209  ls->listener_index);
210  if (ll->transport_listener_index != ~0)
211  {
214  }
215  else
216  {
218  }
220  }
222  mp->port = ls->port;
225  }
226  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
227 
228  return 0;
229 }
230 
231 void
233 {
234  application_t *app = application_get (app_index);
237 
238  reg = vl_mem_api_client_index_to_registration (app->api_client_index);
239  if (!reg)
240  {
241  clib_warning ("no registration: %u", app->api_client_index);
242  return;
243  }
244 
245  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
246  memset (mp, 0, sizeof (*mp));
247  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
249  mp->context = app->api_client_index;
250  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
251 }
252 
253 static void
255 {
256  application_t *app = application_get (s->app_index);
259 
260  reg = vl_mem_api_client_index_to_registration (app->api_client_index);
261  if (!reg)
262  {
263  clib_warning ("no registration: %u", app->api_client_index);
264  return;
265  }
266 
267  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
268  memset (mp, 0, sizeof (*mp));
269  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
270  mp->handle = session_handle (s);
271  mp->context = app->api_client_index;
272  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
273 }
274 
275 static void
277 {
278  application_t *app = application_get (s->app_index);
281 
282  reg = vl_mem_api_client_index_to_registration (app->api_client_index);
283  if (!reg)
284  {
285  clib_warning ("no registration: %u", app->api_client_index);
286  return;
287  }
288 
289  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
290  memset (mp, 0, sizeof (*mp));
291  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
292  mp->handle = session_handle (s);
293  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
294 }
295 
296 int
297 send_session_connected_callback (u32 app_index, u32 api_context,
298  stream_session_t * s, u8 is_fail)
299 {
303  svm_msg_q_t *vpp_queue;
304  application_t *app;
305 
306  app = application_get (app_index);
307  reg = vl_mem_api_client_index_to_registration (app->api_client_index);
308  if (!reg)
309  {
310  clib_warning ("no registration: %u", app->api_client_index);
311  return -1;
312  }
313 
314  mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
315  mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
316  mp->context = api_context;
317 
318  if (is_fail)
319  goto done;
320 
321  if (session_has_transport (s))
322  {
323  tc = session_get_transport (s);
324  if (!tc)
325  {
326  is_fail = 1;
327  goto done;
328  }
329 
330  vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
331  mp->handle = session_handle (s);
332  mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
333  clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
334  mp->is_ip4 = tc->is_ip4;
335  mp->lcl_port = tc->lcl_port;
336  mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
337  mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
338  }
339  else
340  {
341  local_session_t *ls = (local_session_t *) s;
343  mp->lcl_port = ls->port;
346  mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
347  mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
348  }
349 
350 done:
351  mp->retval = is_fail ?
352  clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
353  vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
354  return 0;
355 }
356 
358  .session_accept_callback = send_session_accept_callback,
359  .session_disconnect_callback = send_session_disconnect_callback,
360  .session_connected_callback = send_session_connected_callback,
361  .session_reset_callback = send_session_reset_callback,
362  .add_segment_callback = send_add_segment_callback,
363  .del_segment_callback = send_del_segment_callback,
364 };
365 
366 static int
368 {
369  application_t *app = application_get (s->app_index);
370  svm_msg_q_msg_t _msg, *msg = &_msg;
371  svm_msg_q_t *vpp_queue, *app_mq;
372  transport_proto_vft_t *tp_vft;
374  stream_session_t *listener;
376  session_event_t *evt;
377 
378  app_mq = app->event_queue;
380  SVM_Q_WAIT, msg);
381  svm_msg_q_unlock (app_mq);
382 
383  evt = svm_msg_q_msg_data (app_mq, msg);
384  memset (evt, 0, sizeof (*evt));
385  evt->event_type = SESSION_CTRL_EVT_ACCEPTED;
386  mp = (session_accepted_msg_t *) evt->data;
387  mp->context = app->index;
388  mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
389  mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
390 
391  if (session_has_transport (s))
392  {
393  listener = listen_session_get (s->listener_index);
395  if (application_is_proxy (app))
396  {
397  listener =
400  if (listener)
402  }
403  vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
404  mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
405  mp->handle = session_handle (s);
407  tc = tp_vft->get_connection (s->connection_index, s->thread_index);
408  mp->port = tc->rmt_port;
409  mp->is_ip4 = tc->is_ip4;
410  clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
411  }
412  else
413  {
414  local_session_t *ls = (local_session_t *) s;
415  local_session_t *ll;
417  {
418  listener = listen_session_get (ls->listener_index);
420  mp->is_ip4 = session_type_is_ip4 (listener->session_type);
421  }
422  else
423  {
425  if (ll->transport_listener_index != ~0)
426  {
429  }
430  else
431  {
433  }
435  }
437  mp->port = ls->port;
440  }
441  svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
442 
443  return 0;
444 }
445 
446 static void
448 {
449  application_t *app = application_get (s->app_index);
450  svm_msg_q_msg_t _msg, *msg = &_msg;
452  svm_msg_q_t *app_mq;
453  session_event_t *evt;
454 
455  app_mq = app->event_queue;
457  SVM_Q_WAIT, msg);
458  svm_msg_q_unlock (app_mq);
459  evt = svm_msg_q_msg_data (app_mq, msg);
460  memset (evt, 0, sizeof (*evt));
461  evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
462  mp = (session_disconnected_msg_t *) evt->data;
463  mp->handle = session_handle (s);
464  mp->context = app->api_client_index;
465  svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
466 }
467 
468 static void
470 {
471  application_t *app = application_get (s->app_index);
472  svm_msg_q_msg_t _msg, *msg = &_msg;
474  svm_msg_q_t *app_mq;
475  session_event_t *evt;
476 
477  app_mq = app->event_queue;
479  SVM_Q_WAIT, msg);
480  svm_msg_q_unlock (app_mq);
481  evt = svm_msg_q_msg_data (app_mq, msg);
482  memset (evt, 0, sizeof (*evt));
483  evt->event_type = SESSION_CTRL_EVT_RESET;
484  mp = (session_reset_msg_t *) evt->data;
485  mp->handle = session_handle (s);
486  svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
487 }
488 
489 static int
490 mq_send_session_connected_cb (u32 app_index, u32 api_context,
491  stream_session_t * s, u8 is_fail)
492 {
493  svm_msg_q_msg_t _msg, *msg = &_msg;
495  svm_msg_q_t *vpp_mq, *app_mq;
497  session_event_t *evt;
498  application_t *app;
499 
500  app = application_get (app_index);
501  app_mq = app->event_queue;
502  if (!app_mq)
503  {
504  clib_warning ("app %u with api index: %u not attached", app->index,
505  app->api_client_index);
506  return -1;
507  }
508 
510  SVM_Q_WAIT, msg);
511  svm_msg_q_unlock (app_mq);
512  evt = svm_msg_q_msg_data (app_mq, msg);
513  memset (evt, 0, sizeof (*evt));
514  evt->event_type = SESSION_CTRL_EVT_CONNECTED;
515  mp = (session_connected_msg_t *) evt->data;
516  mp->context = api_context;
517 
518  if (is_fail)
519  goto done;
520 
521  if (session_has_transport (s))
522  {
523  tc = session_get_transport (s);
524  if (!tc)
525  {
526  is_fail = 1;
527  goto done;
528  }
529 
530  vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
531  mp->handle = session_handle (s);
533  clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
534  mp->is_ip4 = tc->is_ip4;
535  mp->lcl_port = tc->lcl_port;
536  mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
537  mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
538  }
539  else
540  {
541  local_session_t *ls = (local_session_t *) s;
543  mp->lcl_port = ls->port;
546  mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
547  mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
548  }
549 
550 done:
551  mp->retval = is_fail ?
552  clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
553 
554  svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
555  return 0;
556 }
557 
559  .session_accept_callback = mq_send_session_accepted_cb,
560  .session_disconnect_callback = mq_send_session_disconnected_cb,
561  .session_connected_callback = mq_send_session_connected_cb,
562  .session_reset_callback = mq_send_session_reset_cb,
563  .add_segment_callback = send_add_segment_callback,
564  .del_segment_callback = send_del_segment_callback,
565 };
566 
567 static void
569 {
570  vl_api_session_enable_disable_reply_t *rmp;
572  int rv = 0;
573 
575  REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
576 }
577 
578 static void
580 {
582  ssvm_private_t *segp, *evt_q_segment;
583  vnet_app_attach_args_t _a, *a = &_a;
585  clib_error_t *error = 0;
586  int rv = 0;
587 
589  if (!reg)
590  return;
591 
592  if (session_manager_is_enabled () == 0)
593  {
594  rv = VNET_API_ERROR_FEATURE_DISABLED;
595  goto done;
596  }
597 
599  sizeof (mp->options),
600  "Out of options, fix api message definition");
601 
602  memset (a, 0, sizeof (*a));
603  a->api_client_index = mp->client_index;
604  a->options = mp->options;
605 
606  if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
607  a->session_cb_vft = &session_mq_cb_vft;
608  else
609  a->session_cb_vft = &session_cb_vft;
610 
611  if (mp->namespace_id_len > 64)
612  {
613  rv = VNET_API_ERROR_INVALID_VALUE;
614  goto done;
615  }
616 
617  if (mp->namespace_id_len)
618  {
619  vec_validate (a->namespace_id, mp->namespace_id_len - 1);
620  clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
621  }
622 
623  if ((error = vnet_application_attach (a)))
624  {
625  rv = clib_error_get_code (error);
626  clib_error_report (error);
627  }
628  vec_free (a->namespace_id);
629 
630 done:
631 
632  /* *INDENT-OFF* */
633  REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
634  if (!rv)
635  {
636  segp = a->segment;
637  rmp->segment_name_length = 0;
638  rmp->segment_size = segp->ssvm_size;
639  if (vec_len (segp->name))
640  {
641  memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
642  rmp->segment_name_length = vec_len (segp->name);
643  }
644  rmp->app_event_queue_address = a->app_event_queue_address;
645  }
646  }));
647  /* *INDENT-ON* */
648 
649  if (rv)
650  return;
651 
652  /* Send fifo segment fd if needed */
653  if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
654  session_send_memfd_fd (reg, a->segment);
655  /* Send event queues segment */
656  if ((evt_q_segment = session_manager_get_evt_q_segment ()))
657  session_send_memfd_fd (reg, evt_q_segment);
658 }
659 
660 static void
662 {
663  vl_api_application_detach_reply_t *rmp;
664  int rv = VNET_API_ERROR_INVALID_VALUE_2;
665  vnet_app_detach_args_t _a, *a = &_a;
666  application_t *app;
667 
668  if (session_manager_is_enabled () == 0)
669  {
670  rv = VNET_API_ERROR_FEATURE_DISABLED;
671  goto done;
672  }
673 
674  app = application_lookup (mp->client_index);
675  if (app)
676  {
677  a->app_index = app->index;
678  rv = vnet_application_detach (a);
679  }
680 
681 done:
682  REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
683 }
684 
685 static void
687 {
688  transport_connection_t *tc = 0;
689  vnet_bind_args_t _a, *a = &_a;
691  stream_session_t *s;
692  application_t *app = 0;
693  svm_msg_q_t *vpp_evt_q;
694  int rv;
695 
696  if (session_manager_is_enabled () == 0)
697  {
698  rv = VNET_API_ERROR_FEATURE_DISABLED;
699  goto done;
700  }
701 
702  app = application_lookup (mp->client_index);
703  if (app)
704  {
705  memset (a, 0, sizeof (*a));
706  a->uri = (char *) mp->uri;
707  a->app_index = app->index;
708  rv = vnet_bind_uri (a);
709  }
710  else
711  {
712  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
713  }
714 
715 done:
716 
717  /* *INDENT-OFF* */
718  REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
719  if (!rv)
720  {
721  rmp->handle = a->handle;
722  if (app && application_has_global_scope (app))
723  {
724  s = listen_session_get_from_handle (a->handle);
726  rmp->lcl_is_ip4 = tc->is_ip4;
727  rmp->lcl_port = tc->lcl_port;
728  clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
730  {
731  rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
732  rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
733  vpp_evt_q = session_manager_get_vpp_event_queue (0);
734  rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
735  }
736  }
737  }
738  }));
739  /* *INDENT-ON* */
740 }
741 
742 static void
744 {
745  vl_api_unbind_uri_reply_t *rmp;
746  application_t *app;
747  vnet_unbind_args_t _a, *a = &_a;
748  int rv;
749 
750  if (session_manager_is_enabled () == 0)
751  {
752  rv = VNET_API_ERROR_FEATURE_DISABLED;
753  goto done;
754  }
755 
756  app = application_lookup (mp->client_index);
757  if (app)
758  {
759  a->uri = (char *) mp->uri;
760  a->app_index = app->index;
761  rv = vnet_unbind_uri (a);
762  }
763  else
764  {
765  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
766  }
767 
768 done:
769  REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
770 }
771 
772 static void
774 {
776  vnet_connect_args_t _a, *a = &_a;
777  application_t *app;
778  clib_error_t *error = 0;
779  int rv = 0;
780 
781  if (session_manager_is_enabled () == 0)
782  {
783  rv = VNET_API_ERROR_FEATURE_DISABLED;
784  goto done;
785  }
786 
787  app = application_lookup (mp->client_index);
788  if (app)
789  {
790  a->uri = (char *) mp->uri;
791  a->api_context = mp->context;
792  a->app_index = app->index;
793  if ((error = vnet_connect_uri (a)))
794  {
795  rv = clib_error_get_code (error);
796  clib_error_report (error);
797  }
798  }
799  else
800  {
801  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
802  }
803 
804  /*
805  * Don't reply to stream (tcp) connects. The reply will come once
806  * the connection is established. In case of the redirects, the reply
807  * will come from the server app.
808  */
809  if (rv == 0)
810  return;
811 
812 done:
813  /* *INDENT-OFF* */
814  REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
815  /* *INDENT-ON* */
816 }
817 
818 static void
820 {
822  vnet_disconnect_args_t _a, *a = &_a;
823  application_t *app;
824  int rv = 0;
825 
826  if (session_manager_is_enabled () == 0)
827  {
828  rv = VNET_API_ERROR_FEATURE_DISABLED;
829  goto done;
830  }
831 
832  app = application_lookup (mp->client_index);
833  if (app)
834  {
835  a->handle = mp->handle;
836  a->app_index = app->index;
837  rv = vnet_disconnect_session (a);
838  }
839  else
840  {
841  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
842  }
843 
844 done:
845  REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
846 }
847 
848 static void
850  mp)
851 {
852  vnet_disconnect_args_t _a, *a = &_a;
853  application_t *app;
854 
855  /* Client objected to disconnecting the session, log and continue */
856  if (mp->retval)
857  {
858  clib_warning ("client retval %d", mp->retval);
859  return;
860  }
861 
862  /* Disconnect has been confirmed. Confirm close to transport */
863  app = application_lookup (mp->context);
864  if (app)
865  {
866  a->handle = mp->handle;
867  a->app_index = app->index;
869  }
870 }
871 
872 static void
874 {
875  application_t *app;
876  stream_session_t *s;
877  u32 index, thread_index;
878 
879  app = application_lookup (mp->client_index);
880  if (!app)
881  return;
882 
883  session_parse_handle (mp->handle, &index, &thread_index);
884  s = session_get_if_valid (index, thread_index);
885  if (s == 0 || app->index != s->app_index)
886  {
887  clib_warning ("Invalid session!");
888  return;
889  }
890 
891  /* Client objected to resetting the session, log and continue */
892  if (mp->retval)
893  {
894  clib_warning ("client retval %d", mp->retval);
895  return;
896  }
897 
898  /* This comes as a response to a reset, transport only waiting for
899  * confirmation to remove connection state, no need to disconnect */
901 }
902 
903 static void
905 {
906  vnet_disconnect_args_t _a = { 0 }, *a = &_a;
907  local_session_t *ls;
908  stream_session_t *s;
909 
910  /* Server isn't interested, kill the session */
911  if (mp->retval)
912  {
913  a->app_index = mp->context;
914  a->handle = mp->handle;
916  return;
917  }
918 
920  {
922  if (!ls || ls->app_index != mp->context)
923  {
924  clib_warning ("server %u doesn't own local handle %llu",
925  mp->context, mp->handle);
926  return;
927  }
929  return;
931  }
932  else
933  {
935  if (!s)
936  {
937  clib_warning ("session doesn't exist");
938  return;
939  }
940  if (s->app_index != mp->context)
941  {
942  clib_warning ("app doesn't own session");
943  return;
944  }
945  s->session_state = SESSION_STATE_READY;
946  }
947 }
948 
949 static void
950 vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
951  * mp)
952 {
953  clib_warning ("not implemented");
954 }
955 
956 static void
958 {
960  vnet_bind_args_t _a, *a = &_a;
961  int rv = 0;
962  clib_error_t *error;
963  application_t *app = 0;
964  stream_session_t *s;
965  transport_connection_t *tc = 0;
966  ip46_address_t *ip46;
967  svm_msg_q_t *vpp_evt_q;
968 
969  if (session_manager_is_enabled () == 0)
970  {
971  rv = VNET_API_ERROR_FEATURE_DISABLED;
972  goto done;
973  }
974 
975  app = application_lookup (mp->client_index);
976  if (!app)
977  {
978  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
979  goto done;
980  }
981 
982  ip46 = (ip46_address_t *) mp->ip;
983  memset (a, 0, sizeof (*a));
984  a->sep.is_ip4 = mp->is_ip4;
985  a->sep.ip = *ip46;
986  a->sep.port = mp->port;
987  a->sep.fib_index = mp->vrf;
988  a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
989  a->sep.transport_proto = mp->proto;
990  a->app_index = app->index;
991 
992  if ((error = vnet_bind (a)))
993  {
994  rv = clib_error_get_code (error);
995  clib_error_report (error);
996  }
997 
998 done:
999  /* *INDENT-OFF* */
1000  REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
1001  if (!rv)
1002  {
1003  rmp->handle = a->handle;
1004  rmp->lcl_port = mp->port;
1005  rmp->lcl_is_ip4 = mp->is_ip4;
1006  if (app && application_has_global_scope (app))
1007  {
1008  s = listen_session_get_from_handle (a->handle);
1010  clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
1012  {
1013  rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
1014  rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
1015  vpp_evt_q = session_manager_get_vpp_event_queue (0);
1016  rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
1017  }
1018  }
1019  }
1020  }));
1021  /* *INDENT-ON* */
1022 }
1023 
1024 static void
1026 {
1027  vl_api_unbind_sock_reply_t *rmp;
1028  vnet_unbind_args_t _a, *a = &_a;
1029  application_t *app;
1030  clib_error_t *error;
1031  int rv = 0;
1032 
1033  if (session_manager_is_enabled () == 0)
1034  {
1035  rv = VNET_API_ERROR_FEATURE_DISABLED;
1036  goto done;
1037  }
1038 
1039  app = application_lookup (mp->client_index);
1040  if (app)
1041  {
1042  a->app_index = app->index;
1043  a->handle = mp->handle;
1044  if ((error = vnet_unbind (a)))
1045  {
1046  rv = clib_error_get_code (error);
1047  clib_error_report (error);
1048  }
1049  }
1050 
1051 done:
1052  REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
1053 }
1054 
1055 static void
1057 {
1059  vnet_connect_args_t _a, *a = &_a;
1060  application_t *app;
1061  clib_error_t *error = 0;
1062  int rv = 0;
1063 
1064  if (session_manager_is_enabled () == 0)
1065  {
1066  rv = VNET_API_ERROR_FEATURE_DISABLED;
1067  goto done;
1068  }
1069 
1070  app = application_lookup (mp->client_index);
1071  if (app)
1072  {
1073  svm_queue_t *client_q;
1074  ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
1075 
1076  memset (a, 0, sizeof (*a));
1078  mp->client_queue_address = pointer_to_uword (client_q);
1079  a->sep.is_ip4 = mp->is_ip4;
1080  a->sep.ip = *ip46;
1081  a->sep.port = mp->port;
1082  a->sep.transport_proto = mp->proto;
1083  a->sep.fib_index = mp->vrf;
1084  a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1085  if (mp->hostname_len)
1086  {
1087  vec_validate (a->sep.hostname, mp->hostname_len - 1);
1088  clib_memcpy (a->sep.hostname, mp->hostname, mp->hostname_len);
1089  }
1090  a->api_context = mp->context;
1091  a->app_index = app->index;
1092  if ((error = vnet_connect (a)))
1093  {
1094  rv = clib_error_get_code (error);
1095  clib_error_report (error);
1096  }
1097  vec_free (a->sep.hostname);
1098  }
1099  else
1100  {
1101  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1102  }
1103 
1104  if (rv == 0)
1105  return;
1106 
1107  /* Got some error, relay it */
1108 
1109 done:
1110  REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
1111 }
1112 
1113 static void
1115 {
1117  clib_error_t *error = 0;
1118  u32 appns_index = 0;
1119  u8 *ns_id = 0;
1120  int rv = 0;
1122  {
1123  rv = VNET_API_ERROR_FEATURE_DISABLED;
1124  goto done;
1125  }
1126 
1127  if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
1128  {
1129  rv = VNET_API_ERROR_INVALID_VALUE;
1130  goto done;
1131  }
1132 
1133  vec_validate (ns_id, mp->namespace_id_len - 1);
1134  clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
1136  .ns_id = ns_id,
1137  .secret = clib_net_to_host_u64 (mp->secret),
1138  .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
1139  .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
1140  .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
1141  .is_add = 1
1142  };
1143  error = vnet_app_namespace_add_del (&args);
1144  if (error)
1145  {
1146  rv = clib_error_get_code (error);
1147  clib_error_report (error);
1148  }
1149  else
1150  {
1151  appns_index = app_namespace_index_from_id (ns_id);
1152  if (appns_index == APP_NAMESPACE_INVALID_INDEX)
1153  {
1154  clib_warning ("app ns lookup failed");
1155  rv = VNET_API_ERROR_UNSPECIFIED;
1156  }
1157  }
1158  vec_free (ns_id);
1159 
1160  /* *INDENT-OFF* */
1161 done:
1162  REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
1163  if (!rv)
1164  rmp->appns_index = clib_host_to_net_u32 (appns_index);
1165  }));
1166  /* *INDENT-ON* */
1167 }
1168 
1169 static void
1171 {
1172  vl_api_session_rule_add_del_reply_t *rmp;
1174  session_rule_table_add_del_args_t *table_args = &args.table_args;
1175  clib_error_t *error;
1176  u8 fib_proto;
1177  int rv = 0;
1178 
1179  memset (&args, 0, sizeof (args));
1180  fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1181 
1182  table_args->lcl.fp_len = mp->lcl_plen;
1183  table_args->lcl.fp_proto = fib_proto;
1184  table_args->rmt.fp_len = mp->rmt_plen;
1185  table_args->rmt.fp_proto = fib_proto;
1186  table_args->lcl_port = mp->lcl_port;
1187  table_args->rmt_port = mp->rmt_port;
1188  table_args->action_index = clib_net_to_host_u32 (mp->action_index);
1189  table_args->is_add = mp->is_add;
1190  mp->tag[sizeof (mp->tag) - 1] = 0;
1191  table_args->tag = format (0, "%s", mp->tag);
1192  args.appns_index = clib_net_to_host_u32 (mp->appns_index);
1193  args.scope = mp->scope;
1194  args.transport_proto = mp->transport_proto;
1195 
1196  memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
1197  memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
1198  ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
1199  ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
1200  error = vnet_session_rule_add_del (&args);
1201  if (error)
1202  {
1203  rv = clib_error_get_code (error);
1204  clib_error_report (error);
1205  }
1206  vec_free (table_args->tag);
1207  REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
1208 }
1209 
1210 static void
1211 send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
1212  u8 transport_proto, u32 appns_index, u8 * tag,
1213  vl_api_registration_t * reg, u32 context)
1214 {
1216  session_mask_or_match_4_t *match =
1217  (session_mask_or_match_4_t *) & rule->match;
1218  session_mask_or_match_4_t *mask =
1219  (session_mask_or_match_4_t *) & rule->mask;
1220 
1221  rmp = vl_msg_api_alloc (sizeof (*rmp));
1222  memset (rmp, 0, sizeof (*rmp));
1223  rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1224  rmp->context = context;
1225 
1226  rmp->is_ip4 = 1;
1227  clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1228  clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1229  rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
1230  rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
1231  rmp->lcl_port = match->lcl_port;
1232  rmp->rmt_port = match->rmt_port;
1233  rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1234  rmp->scope =
1236  rmp->transport_proto = transport_proto;
1237  rmp->appns_index = clib_host_to_net_u32 (appns_index);
1238  if (tag)
1239  {
1240  clib_memcpy (rmp->tag, tag, vec_len (tag));
1241  rmp->tag[vec_len (tag)] = 0;
1242  }
1243 
1244  vl_api_send_msg (reg, (u8 *) rmp);
1245 }
1246 
1247 static void
1248 send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
1249  u8 transport_proto, u32 appns_index, u8 * tag,
1250  vl_api_registration_t * reg, u32 context)
1251 {
1253  session_mask_or_match_6_t *match =
1254  (session_mask_or_match_6_t *) & rule->match;
1255  session_mask_or_match_6_t *mask =
1256  (session_mask_or_match_6_t *) & rule->mask;
1257 
1258  rmp = vl_msg_api_alloc (sizeof (*rmp));
1259  memset (rmp, 0, sizeof (*rmp));
1260  rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1261  rmp->context = context;
1262 
1263  rmp->is_ip4 = 0;
1264  clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1265  clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1266  rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
1267  rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
1268  rmp->lcl_port = match->lcl_port;
1269  rmp->rmt_port = match->rmt_port;
1270  rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1271  rmp->scope =
1273  rmp->transport_proto = transport_proto;
1274  rmp->appns_index = clib_host_to_net_u32 (appns_index);
1275  if (tag)
1276  {
1277  clib_memcpy (rmp->tag, tag, vec_len (tag));
1278  rmp->tag[vec_len (tag)] = 0;
1279  }
1280 
1281  vl_api_send_msg (reg, (u8 *) rmp);
1282 }
1283 
1284 static void
1286  u8 tp, u8 is_local, u32 appns_index,
1287  vl_api_registration_t * reg, u32 context)
1288 {
1289  mma_rule_16_t *rule16;
1290  mma_rule_40_t *rule40;
1291  mma_rules_table_16_t *srt16;
1292  mma_rules_table_40_t *srt40;
1293  u32 ri;
1294 
1295  if (is_local || fib_proto == FIB_PROTOCOL_IP4)
1296  {
1297  u8 *tag = 0;
1298  /* *INDENT-OFF* */
1299  srt16 = &srt->session_rules_tables_16;
1300  pool_foreach (rule16, srt16->rules, ({
1301  ri = mma_rules_table_rule_index_16 (srt16, rule16);
1302  tag = session_rules_table_rule_tag (srt, ri, 1);
1303  send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
1304  reg, context);
1305  }));
1306  /* *INDENT-ON* */
1307  }
1308  if (is_local || fib_proto == FIB_PROTOCOL_IP6)
1309  {
1310  u8 *tag = 0;
1311  /* *INDENT-OFF* */
1312  srt40 = &srt->session_rules_tables_40;
1313  pool_foreach (rule40, srt40->rules, ({
1314  ri = mma_rules_table_rule_index_40 (srt40, rule40);
1315  tag = session_rules_table_rule_tag (srt, ri, 1);
1316  send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
1317  reg, context);
1318  }));
1319  /* *INDENT-ON* */
1320  }
1321 }
1322 
1323 static void
1325 {
1326  vl_api_registration_t *reg;
1327  session_table_t *st;
1328  u8 tp;
1329 
1331  if (!reg)
1332  return;
1333 
1334  /* *INDENT-OFF* */
1335  session_table_foreach (st, ({
1336  for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
1337  {
1338  send_session_rules_table_details (&st->session_rules[tp],
1339  st->active_fib_proto, tp,
1340  st->is_local, st->appns_index, reg,
1341  mp->context);
1342  }
1343  }));
1344  /* *INDENT-ON* */
1345 }
1346 
1347 static void
1349  mp)
1350 {
1352  vnet_app_add_tls_cert_args_t _a, *a = &_a;
1353  clib_error_t *error;
1354  application_t *app;
1355  u32 cert_len;
1356  int rv = 0;
1358  {
1359  rv = VNET_API_ERROR_FEATURE_DISABLED;
1360  goto done;
1361  }
1362  if (!(app = application_lookup (mp->client_index)))
1363  {
1364  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1365  goto done;
1366  }
1367  memset (a, 0, sizeof (*a));
1368  a->app_index = app->index;
1369  cert_len = clib_net_to_host_u16 (mp->cert_len);
1370  if (cert_len > 10000)
1371  {
1372  rv = VNET_API_ERROR_INVALID_VALUE;
1373  goto done;
1374  }
1375  vec_validate (a->cert, cert_len);
1376  clib_memcpy (a->cert, mp->cert, cert_len);
1377  if ((error = vnet_app_add_tls_cert (a)))
1378  {
1379  rv = clib_error_get_code (error);
1380  clib_error_report (error);
1381  }
1382  vec_free (a->cert);
1383 done:
1384  REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
1385 }
1386 
1387 static void
1389  mp)
1390 {
1392  vnet_app_add_tls_key_args_t _a, *a = &_a;
1393  clib_error_t *error;
1394  application_t *app;
1395  u32 key_len;
1396  int rv = 0;
1398  {
1399  rv = VNET_API_ERROR_FEATURE_DISABLED;
1400  goto done;
1401  }
1402  if (!(app = application_lookup (mp->client_index)))
1403  {
1404  rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1405  goto done;
1406  }
1407  memset (a, 0, sizeof (*a));
1408  a->app_index = app->index;
1409  key_len = clib_net_to_host_u16 (mp->key_len);
1410  if (key_len > 10000)
1411  {
1412  rv = VNET_API_ERROR_INVALID_VALUE;
1413  goto done;
1414  }
1415  vec_validate (a->key, key_len);
1416  clib_memcpy (a->key, mp->key, key_len);
1417  if ((error = vnet_app_add_tls_key (a)))
1418  {
1419  rv = clib_error_get_code (error);
1420  clib_error_report (error);
1421  }
1422  vec_free (a->key);
1423 done:
1424  REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);
1425 }
1426 
1427 static clib_error_t *
1429 {
1430  application_t *app = application_lookup (client_index);
1431  vnet_app_detach_args_t _a, *a = &_a;
1432  if (app)
1433  {
1434  a->app_index = app->index;
1436  }
1437  return 0;
1438 }
1439 
1441 
1442 #define vl_msg_name_crc_list
1443 #include <vnet/vnet_all_api_h.h>
1444 #undef vl_msg_name_crc_list
1445 
1446 static void
1448 {
1449 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1450  foreach_vl_msg_name_crc_session;
1451 #undef _
1452 }
1453 
1454 /*
1455  * session_api_hookup
1456  * Add uri's API message handlers to the table.
1457  * vlib has alread mapped shared memory and
1458  * added the client registration handlers.
1459  * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1460  */
1461 static clib_error_t *
1463 {
1464  api_main_t *am = &api_main;
1465 
1466 #define _(N,n) \
1467  vl_msg_api_set_handlers(VL_API_##N, #n, \
1468  vl_api_##n##_t_handler, \
1469  vl_noop_handler, \
1470  vl_api_##n##_t_endian, \
1471  vl_api_##n##_t_print, \
1472  sizeof(vl_api_##n##_t), 1);
1474 #undef _
1475 
1476  /*
1477  * Messages which bounce off the data-plane to
1478  * an API client. Simply tells the message handling infra not
1479  * to free the message.
1480  *
1481  * Bounced message handlers MUST NOT block the data plane
1482  */
1483  am->message_bounce[VL_API_CONNECT_URI] = 1;
1484  am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1485 
1486  /*
1487  * Set up the (msg_name, crc, message-id) table
1488  */
1490 
1491  return 0;
1492 }
1493 
1495 
1496 /*
1497  * fd.io coding-style-patch-verification: ON
1498  *
1499  * Local Variables:
1500  * eval: (c-set-style "gnu")
1501  * End:
1502  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
static void vl_api_disconnect_session_reply_t_handler(vl_api_disconnect_session_reply_t *mp)
Definition: session_api.c:849
u64 ssvm_size
Definition: ssvm.h:84
session_type_t listener_session_type
Has transport embedded when listener not purely local.
#define APP_NAMESPACE_INVALID_INDEX
static clib_error_t * session_api_hookup(vlib_main_t *vm)
Definition: session_api.c:1462
static void mq_send_session_reset_cb(stream_session_t *s)
Definition: session_api.c:469
void * svm_msg_q_msg_data(svm_msg_q_t *mq, svm_msg_q_msg_t *msg)
Get data for message in queue.
clib_error_t * vnet_app_namespace_add_del(vnet_app_namespace_add_del_args_t *a)
static clib_error_t * vl_api_send_fd_msg(vl_api_registration_t *reg, int fd_to_send)
Definition: api.h:85
static session_handle_t application_local_session_handle(local_session_t *ls)
Definition: application.h:240
vpp->client reset session API
Definition: session.api:244
a
Definition: bitmap.h:538
VL_MSG_API_REAPER_FUNCTION(application_reaper_cb)
struct _session_rules_table_t session_rules_table_t
u8 application_has_global_scope(application_t *app)
Definition: application.c:613
struct _transport_connection transport_connection_t
struct _vnet_connect_args vnet_connect_args_t
Application add TLS key.
Definition: session.api:74
static int send_del_segment_callback(u32 api_client_index, const ssvm_private_t *fs)
Definition: session_api.c:116
int vnet_bind_uri(vnet_bind_args_t *a)
static void vl_api_app_namespace_add_del_t_handler(vl_api_app_namespace_add_del_t *mp)
Definition: session_api.c:1114
unsigned long u64
Definition: types.h:89
void ip_set(ip46_address_t *dst, void *src, u8 is_ip4)
Definition: ip.c:90
clib_error_t * vnet_unbind(vnet_unbind_args_t *a)
#define REPLY_MACRO2(t, body)
add/del session rule
Definition: session.api:464
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
u8 * message_bounce
Don&#39;t automatically free message buffer vetor.
Definition: api_common.h:221
Session rules details.
Definition: session.api:510
static void vl_api_map_another_segment_reply_t_handler(vl_api_map_another_segment_reply_t *mp)
Definition: session_api.c:950
struct _transport_proto_vft transport_proto_vft_t
local_session_t * application_get_local_session_from_handle(session_handle_t handle)
Definition: application.c:972
Bind to an ip:port pair for a given transport protocol.
Definition: session.api:274
struct _vnet_app_namespace_add_del_args vnet_app_namespace_add_del_args_t
client->vpp, reply to an accept message
Definition: session.api:207
application_t * application_lookup(u32 api_client_index)
Definition: application.c:136
Request for map server summary status.
Definition: one.api:885
static void vl_api_unbind_sock_t_handler(vl_api_unbind_sock_t *mp)
Definition: session_api.c:1025
static void session_parse_handle(session_handle_t handle, u32 *index, u32 *thread_index)
Definition: session.h:347
transport_connection_t * session_get_transport(stream_session_t *s)
Definition: session.c:1309
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define foreach_session_api_msg
Definition: session_api.c:41
struct _vnet_application_add_tls_cert_args_t vnet_app_add_tls_cert_args_t
static u8 session_manager_is_enabled()
Definition: session.h:634
void * vl_msg_api_alloc(int nbytes)
clib_error_t * vnet_app_add_tls_cert(vnet_app_add_tls_cert_args_t *a)
Definition: application.c:1368
unsigned char u8
Definition: types.h:56
static stream_session_t * listen_session_get_from_handle(session_handle_t handle)
Definition: session.h:591
int svm_msg_q_lock_and_alloc_msg_w_ring(svm_msg_q_t *mq, u32 ring_index, u8 noblock, svm_msg_q_msg_t *msg)
Lock message queue and allocate message buffer on ring.
Definition: message_queue.c:99
connectionless service
int application_is_proxy(application_t *app)
Definition: application.c:579
clib_error_t * vnet_session_rule_add_del(session_rule_add_del_args_t *args)
static void vl_api_connect_uri_t_handler(vl_api_connect_uri_t *mp)
Definition: session_api.c:773
int vnet_unbind_uri(vnet_unbind_args_t *a)
static svm_msg_q_t * session_manager_get_vpp_event_queue(u32 thread_index)
Definition: session.h:575
static void vl_api_session_enable_disable_t_handler(vl_api_session_enable_disable_t *mp)
Definition: session_api.c:568
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:443
struct _vnet_disconnect_args_t vnet_disconnect_args_t
static void send_session_reset_callback(stream_session_t *s)
Definition: session_api.c:276
int application_local_session_connect_notify(local_session_t *ls)
Definition: application.c:1183
u32 transport_listener_index
struct _stream_session_cb_vft session_cb_vft_t
vl_api_registration_t * vl_mem_api_client_index_to_registration(u32 handle)
Definition: memory_api.c:725
struct _vnet_unbind_args_t vnet_unbind_args_t
vpp/server->client, connect reply – used for all connect_* messages
Definition: session.api:378
static stream_session_t * listen_session_get(u32 index)
Definition: session.h:614
add/del application namespace
Definition: session.api:420
static void vl_api_application_tls_cert_add_t_handler(vl_api_application_tls_cert_add_t *mp)
Definition: session_api.c:1348
void stream_session_cleanup(stream_session_t *s)
Cleanup transport and session state.
Definition: session.c:1150
unsigned int u32
Definition: types.h:88
static local_session_t * application_get_local_listen_session(application_t *app, u32 session_index)
Definition: application.h:247
static void send_session_rule_details4(mma_rule_16_t *rule, u8 is_local, u8 transport_proto, u32 appns_index, u8 *tag, vl_api_registration_t *reg, u32 context)
Definition: session_api.c:1211
u32 app_namespace_index_from_id(const u8 *ns_id)
struct _stream_session_t stream_session_t
struct _vnet_app_attach_args_t vnet_app_attach_args_t
transport_proto_vft_t * transport_protocol_get_vft(transport_proto_t transport_proto)
Get transport virtual function table.
Definition: transport.c:191
vpp->client unmap shared memory segment
Definition: session.api:108
static transport_proto_t session_get_transport_proto(stream_session_t *s)
Definition: session.h:392
static void vl_api_session_rules_dump_t_handler(vl_api_one_map_server_dump_t *mp)
Definition: session_api.c:1324
clib_error_t * vnet_app_add_tls_key(vnet_app_add_tls_key_args_t *a)
Definition: application.c:1380
static session_cb_vft_t session_cb_vft
Definition: session_api.c:357
#define VL_API_INVALID_FI
Definition: api_common.h:75
static void vl_api_accept_session_reply_t_handler(vl_api_accept_session_reply_t *mp)
Definition: session_api.c:904
svm_queue_t * vl_input_queue
shared memory only: pointer to client input queue
Definition: api_common.h:59
struct _session_rule_add_del_args session_rule_add_del_args_t
client->vpp, attach application to session layer
Definition: session.api:27
u8 hostname[hostname_len]
Definition: session.api:322
static u8 session_handle_is_local(session_handle_t handle)
Definition: session.h:372
static void vl_api_disconnect_session_t_handler(vl_api_disconnect_session_t *mp)
Definition: session_api.c:819
static session_handle_t session_handle(stream_session_t *s)
Definition: session.h:329
stream_session_t * application_first_listener(application_t *app, u8 fib_proto, u8 transport_proto)
Definition: application.c:625
#define REPLY_MACRO(t)
static u8 application_local_session_listener_has_transport(local_session_t *ls)
Definition: application.h:263
static clib_error_t * application_reaper_cb(u32 client_index)
Definition: session_api.c:1428
static int send_add_segment_callback(u32 api_client_index, const ssvm_private_t *sp)
Definition: session_api.c:81
clib_error_t * vnet_connect(vnet_connect_args_t *a)
Unbind a given URI.
Definition: session.api:148
static stream_session_t * session_get_if_valid(u64 si, u32 thread_index)
Definition: session.h:316
static int session_send_memfd_fd(vl_api_registration_t *reg, const ssvm_private_t *sp)
Definition: session_api.c:63
clib_error_t * vnet_session_enable_disable(vlib_main_t *vm, u8 is_en)
Definition: session.c:1481
volatile u8 session_state
State.
vpp->client, accept this session
Definition: session.api:186
u32 ip6_mask_to_preflen(ip6_address_t *mask)
Definition: ip.c:266
int send_session_connected_callback(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
Definition: session_api.c:297
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:201
An API client registration, only in vpp/vlib.
Definition: api_common.h:44
static int send_session_accept_callback(stream_session_t *s)
Definition: session_api.c:150
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
vlib_main_t * vm
Definition: buffer.c:294
static void svm_msg_q_unlock(svm_msg_q_t *mq)
Unlock message queue.
svm_queue_t * vl_api_client_index_to_input_queue(u32 index)
Definition: memory_api.c:754
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define ENDPOINT_INVALID_INDEX
Definition: transport.h:116
transport_service_type_t session_transport_service_type(stream_session_t *s)
Definition: session.c:1166
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:75
int svm_msg_q_add(svm_msg_q_t *mq, svm_msg_q_msg_t *msg, int nowait)
Producer enqueue one message to queue.
u16 port
Port for connection.
u32 ip4_mask_to_preflen(ip4_address_t *mask)
Definition: ip.c:205
struct _application application_t
int vnet_disconnect_session(vnet_disconnect_args_t *a)
static void send_session_rules_table_details(session_rules_table_t *srt, u8 fib_proto, u8 tp, u8 is_local, u32 appns_index, vl_api_registration_t *reg, u32 context)
Definition: session_api.c:1285
#define ARRAY_LEN(x)
Definition: clib.h:59
blocking call
Definition: queue.h:44
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
Application attach reply.
Definition: session.api:45
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:411
static int mq_send_session_connected_cb(u32 app_index, u32 api_context, stream_session_t *s, u8 is_fail)
Definition: session_api.c:490
static void send_session_rule_details6(mma_rule_40_t *rule, u8 is_local, u8 transport_proto, u32 appns_index, u8 *tag, vl_api_registration_t *reg, u32 context)
Definition: session_api.c:1248
static stream_session_t * session_get_from_handle_if_valid(session_handle_t handle)
Definition: session.h:364
int fd
memfd segments
Definition: ssvm.h:92
ssvm_private_t * session_manager_get_evt_q_segment(void)
Definition: session.c:1256
enable/disable session layer
Definition: session.api:400
static void vl_api_connect_sock_t_handler(vl_api_connect_sock_t *mp)
Definition: session_api.c:1056
clib_error_t * vnet_bind(vnet_bind_args_t *a)
Reply for app namespace add/del.
Definition: session.api:436
client->vpp, attach application to session layer
Definition: session.api:86
static int mq_send_session_accepted_cb(stream_session_t *s)
Definition: session_api.c:367
struct _vnet_application_add_tls_key_args_t vnet_app_add_tls_key_args_t
static void vl_api_bind_sock_t_handler(vl_api_bind_sock_t *mp)
Definition: session_api.c:957
vpp->client, please map an additional shared memory segment
Definition: session.api:96
#define clib_error_report(e)
Definition: error.h:113
struct _vnet_app_detach_args_t vnet_app_detach_args_t
static uword pointer_to_uword(const void *p)
Definition: types.h:131
Connect to a remote peer.
Definition: session.api:311
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u8 * name
Definition: ssvm.h:86
static void vl_api_application_attach_t_handler(vl_api_application_attach_t *mp)
Definition: session_api.c:579
static void setup_message_id_table(api_main_t *am)
Definition: session_api.c:1447
bidirectional disconnect API
Definition: session.api:219
static session_cb_vft_t session_mq_cb_vft
Definition: session_api.c:558
static void mq_send_session_disconnected_cb(stream_session_t *s)
Definition: session_api.c:447
clib_error_t * vnet_connect_uri(vnet_connect_args_t *a)
transport_connection_t * listen_session_get_transport(stream_session_t *s)
Definition: session.c:1322
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Bind to a given URI.
Definition: session.api:122
clib_error_t * vnet_application_attach(vnet_app_attach_args_t *a)
Attach application to vpp.
#define STATIC_ASSERT(truth,...)
application_t * application_get(u32 index)
Definition: application.c:386
static void vl_api_application_tls_key_add_t_handler(vl_api_application_tls_key_add_t *mp)
Definition: session_api.c:1388
#define clib_error_get_code(err)
Definition: error.h:77
VLIB_API_INIT_FUNCTION(session_api_hookup)
struct _session_lookup_table session_table_t
struct _svm_queue svm_queue_t
void * vl_mem_api_alloc_as_if_client_w_reg(vl_api_registration_t *reg, int nbytes)
static void send_session_disconnect_callback(stream_session_t *s)
Definition: session_api.c:254
static void vl_api_application_detach_t_handler(vl_api_application_detach_t *mp)
Definition: session_api.c:661
struct _session_rules_table_add_del_args session_rule_table_add_del_args_t
#define session_table_foreach(VAR, BODY)
Definition: session_table.h:77
Application add TLS certificate.
Definition: session.api:60
client->vpp reset session reply
Definition: session.api:257
Connect to a given URI.
Definition: session.api:164
static void vl_api_session_rule_add_del_t_handler(vl_api_session_rule_add_del_t *mp)
Definition: session_api.c:1170
void * vl_msg_api_alloc_as_if_client(int nbytes)
void send_local_session_disconnect_callback(u32 app_index, local_session_t *ls)
Definition: session_api.c:232
bidirectional disconnect reply API
Definition: session.api:232
static fib_protocol_t session_get_fib_proto(stream_session_t *s)
Definition: session.h:398
api_main_t api_main
Definition: api_shared.c:35
int vnet_application_detach(vnet_app_detach_args_t *a)
Detach application from vpp.
struct _vnet_bind_args_t vnet_bind_args_t
static u8 session_type_is_ip4(session_type_t st)
Definition: session.h:386
static u64 listen_session_get_handle(stream_session_t *s)
Definition: session.h:584
static void vl_api_bind_uri_t_handler(vl_api_bind_uri_t *mp)
Definition: session_api.c:686
static void vl_api_reset_session_reply_t_handler(vl_api_reset_session_reply_t *mp)
Definition: session_api.c:873
static void vl_api_unbind_uri_t_handler(vl_api_unbind_uri_t *mp)
Definition: session_api.c:743
u32 app_index
Server index.
ssvm_segment_type_t ssvm_type(const ssvm_private_t *ssvm)
Definition: ssvm.c:398