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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vlibmemory/api.h>
18 #include <vnet/session/application.h>
19 #include <vnet/session/application_interface.h>
20 #include <vnet/session/session_rules_table.h>
21 #include <vnet/session/session_table.h>
23 #include <vnet/vnet_msg_enum.h>
25 #define vl_typedefs /* define message structures */
26 #include <vnet/vnet_all_api_h.h>
29 #define vl_endianfun /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
33 /* instantiate all the print functions we know about */
34 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
36 #include <vnet/vnet_all_api_h.h>
39 #include <vlibapi/api_helper_macros.h>
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 _(APP_WORKER_ADD_DEL, app_worker_add_del) \
64 session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
67 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
69 clib_warning ("can't send memfd fd");
72 error = vl_api_send_fd_msg (reg, fds, n_fds);
75 clib_error_report (error);
82 send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
84 int fds[SESSION_N_FD_TYPE], n_fds = 0;
85 vl_api_map_another_segment_t *mp;
86 vl_api_registration_t *reg;
89 reg = vl_mem_api_client_index_to_registration (api_client_index);
92 clib_warning ("no registration: %u", api_client_index);
96 if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
98 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
100 clib_warning ("can't send memfd fd");
104 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
109 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
110 memset (mp, 0, sizeof (*mp));
111 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT);
112 mp->segment_size = sp->ssvm_size;
113 mp->fd_flags = fd_flags;
114 strncpy ((char *) mp->segment_name, (char *) sp->name,
115 sizeof (mp->segment_name) - 1);
117 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
120 return session_send_fds (reg, fds, n_fds);
126 send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs)
128 vl_api_unmap_segment_t *mp;
129 vl_api_registration_t *reg;
131 reg = vl_mem_api_client_index_to_registration (api_client_index);
134 clib_warning ("no registration: %u", api_client_index);
138 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
139 memset (mp, 0, sizeof (*mp));
140 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT);
141 strncpy ((char *) mp->segment_name, (char *) fs->name,
142 sizeof (mp->segment_name) - 1);
144 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
150 send_app_cut_through_registration_add (u32 api_client_index,
151 u32 wrk_map_index, u64 mq_addr,
154 vl_api_app_cut_through_registration_add_t *mp;
155 vl_api_registration_t *reg;
156 svm_msg_q_t *mq, *peer_mq;
159 reg = vl_mem_api_client_index_to_registration (api_client_index);
162 clib_warning ("no registration: %u", api_client_index);
166 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
167 memset (mp, 0, sizeof (*mp));
169 clib_host_to_net_u16 (VL_API_APP_CUT_THROUGH_REGISTRATION_ADD);
171 mp->evt_q_address = mq_addr;
172 mp->peer_evt_q_address = peer_mq_addr;
173 mp->wrk_index = wrk_map_index;
175 mq = uword_to_pointer (mq_addr, svm_msg_q_t *);
176 peer_mq = uword_to_pointer (peer_mq_addr, svm_msg_q_t *);
178 if (svm_msg_q_get_producer_eventfd (mq) != -1)
180 mp->fd_flags |= SESSION_FD_F_MQ_EVENTFD;
182 /* app will overwrite exactly the fds we pass here. So
183 * when we swap mq with peer_mq (accept vs connect) the
184 * fds will still be valid */
185 fds[0] = svm_msg_q_get_consumer_eventfd (mq);
186 fds[1] = svm_msg_q_get_producer_eventfd (peer_mq);
189 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
192 session_send_fds (reg, fds, mp->n_fds);
198 send_session_accept_callback (stream_session_t * s)
200 app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
201 transport_proto_vft_t *tp_vft;
202 vl_api_accept_session_t *mp;
203 vl_api_registration_t *reg;
204 transport_connection_t *tc;
205 stream_session_t *listener;
206 svm_msg_q_t *vpp_queue;
207 application_t *server;
209 server = application_get (server_wrk->app_index);
210 reg = vl_mem_api_client_index_to_registration (server->api_client_index);
213 clib_warning ("no registration: %u", server->api_client_index);
217 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
218 memset (mp, 0, sizeof (*mp));
220 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
221 mp->context = server_wrk->wrk_index;
222 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
223 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
225 if (session_has_transport (s))
227 listener = listen_session_get (s->listener_index);
228 mp->listener_handle = listen_session_get_handle (listener);
229 if (application_is_proxy (server))
232 app_worker_first_listener (server_wrk, session_get_fib_proto (s),
233 session_get_transport_proto (s));
235 mp->listener_handle = listen_session_get_handle (listener);
237 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
238 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
239 mp->handle = session_handle (s);
240 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
241 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
242 mp->port = tc->rmt_port;
243 mp->is_ip4 = tc->is_ip4;
244 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
248 local_session_t *ls = (local_session_t *) s;
250 if (application_local_session_listener_has_transport (ls))
252 listener = listen_session_get (ls->listener_index);
253 mp->listener_handle = listen_session_get_handle (listener);
254 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
258 ll = application_get_local_listen_session (server,
260 if (ll->transport_listener_index != ~0)
262 listener = listen_session_get (ll->transport_listener_index);
263 mp->listener_handle = listen_session_get_handle (listener);
267 mp->listener_handle = application_local_session_handle (ll);
269 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
271 mp->handle = application_local_session_handle (ls);
273 mp->vpp_event_queue_address = ls->client_evt_q;
274 mp->server_event_queue_address = ls->server_evt_q;
276 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
282 send_session_disconnect_callback (stream_session_t * s)
284 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
285 vl_api_disconnect_session_t *mp;
286 vl_api_registration_t *reg;
289 app = application_get (app_wrk->app_index);
290 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
293 clib_warning ("no registration: %u", app->api_client_index);
297 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
298 memset (mp, 0, sizeof (*mp));
299 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
300 mp->handle = session_handle (s);
301 mp->context = app->api_client_index;
302 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
306 send_session_reset_callback (stream_session_t * s)
308 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
309 vl_api_registration_t *reg;
310 vl_api_reset_session_t *mp;
313 app = application_get (app_wrk->app_index);
314 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
317 clib_warning ("no registration: %u", app->api_client_index);
321 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
322 memset (mp, 0, sizeof (*mp));
323 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
324 mp->handle = session_handle (s);
325 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
329 send_session_connected_callback (u32 app_wrk_index, u32 api_context,
330 stream_session_t * s, u8 is_fail)
332 vl_api_connect_session_reply_t *mp;
333 transport_connection_t *tc;
334 vl_api_registration_t *reg;
335 svm_msg_q_t *vpp_queue;
336 app_worker_t *app_wrk;
339 app_wrk = app_worker_get (app_wrk_index);
340 app = application_get (app_wrk->app_index);
341 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
344 clib_warning ("no registration: %u", app->api_client_index);
348 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
349 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
350 mp->context = api_context;
355 if (session_has_transport (s))
357 tc = session_get_transport (s);
364 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
365 mp->handle = session_handle (s);
366 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
367 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
368 mp->is_ip4 = tc->is_ip4;
369 mp->lcl_port = tc->lcl_port;
370 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
371 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
375 local_session_t *ls = (local_session_t *) s;
376 mp->handle = application_local_session_handle (ls);
377 mp->lcl_port = ls->port;
378 mp->vpp_event_queue_address = ls->server_evt_q;
379 mp->client_event_queue_address = ls->client_evt_q;
380 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
381 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
385 mp->retval = is_fail ?
386 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
387 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
391 static session_cb_vft_t session_cb_vft = {
392 .session_accept_callback = send_session_accept_callback,
393 .session_disconnect_callback = send_session_disconnect_callback,
394 .session_connected_callback = send_session_connected_callback,
395 .session_reset_callback = send_session_reset_callback,
396 .add_segment_callback = send_add_segment_callback,
397 .del_segment_callback = send_del_segment_callback,
401 mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg)
407 rv = svm_msg_q_lock_and_alloc_msg_w_ring (app_mq,
408 SESSION_MQ_CTRL_EVT_RING,
418 mq_send_session_accepted_cb (stream_session_t * s)
420 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
421 svm_msg_q_msg_t _msg, *msg = &_msg;
422 svm_msg_q_t *vpp_queue, *app_mq;
423 transport_proto_vft_t *tp_vft;
424 transport_connection_t *tc;
425 stream_session_t *listener;
426 session_accepted_msg_t *mp;
427 session_event_t *evt;
430 app = application_get (app_wrk->app_index);
431 app_mq = app_wrk->event_queue;
432 if (mq_try_lock_and_alloc_msg (app_mq, msg))
435 evt = svm_msg_q_msg_data (app_mq, msg);
436 memset (evt, 0, sizeof (*evt));
437 evt->event_type = SESSION_CTRL_EVT_ACCEPTED;
438 mp = (session_accepted_msg_t *) evt->data;
439 mp->context = app->app_index;
440 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
441 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
443 if (session_has_transport (s))
445 listener = listen_session_get (s->listener_index);
446 mp->listener_handle = listen_session_get_handle (listener);
447 if (application_is_proxy (app))
450 app_worker_first_listener (app_wrk, session_get_fib_proto (s),
451 session_get_transport_proto (s));
453 mp->listener_handle = listen_session_get_handle (listener);
455 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
456 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
457 mp->handle = session_handle (s);
458 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
459 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
460 mp->port = tc->rmt_port;
461 mp->is_ip4 = tc->is_ip4;
462 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
466 local_session_t *ls = (local_session_t *) s;
468 u8 main_thread = vlib_num_workers ()? 1 : 0;
470 send_app_cut_through_registration_add (app->api_client_index,
471 app_wrk->wrk_map_index,
475 if (application_local_session_listener_has_transport (ls))
477 listener = listen_session_get (ls->listener_index);
478 mp->listener_handle = listen_session_get_handle (listener);
479 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
483 ll = application_get_local_listen_session (app, ls->listener_index);
484 if (ll->transport_listener_index != ~0)
486 listener = listen_session_get (ll->transport_listener_index);
487 mp->listener_handle = listen_session_get_handle (listener);
491 mp->listener_handle = application_local_session_handle (ll);
493 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
495 mp->handle = application_local_session_handle (ls);
497 vpp_queue = session_manager_get_vpp_event_queue (main_thread);
498 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
499 mp->client_event_queue_address = ls->client_evt_q;
500 mp->server_event_queue_address = ls->server_evt_q;
502 svm_msg_q_add_and_unlock (app_mq, msg);
508 mq_send_session_disconnected_cb (stream_session_t * s)
510 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
511 svm_msg_q_msg_t _msg, *msg = &_msg;
512 session_disconnected_msg_t *mp;
514 session_event_t *evt;
517 app = application_get (app_wrk->app_index);
518 app_mq = app_wrk->event_queue;
519 if (mq_try_lock_and_alloc_msg (app_mq, msg))
521 evt = svm_msg_q_msg_data (app_mq, msg);
522 memset (evt, 0, sizeof (*evt));
523 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
524 mp = (session_disconnected_msg_t *) evt->data;
525 mp->handle = session_handle (s);
526 mp->context = app->api_client_index;
527 svm_msg_q_add_and_unlock (app_mq, msg);
531 mq_send_local_session_disconnected_cb (u32 app_wrk_index,
532 local_session_t * ls)
534 app_worker_t *app_wrk = app_worker_get (app_wrk_index);
535 svm_msg_q_msg_t _msg, *msg = &_msg;
536 session_disconnected_msg_t *mp;
538 session_event_t *evt;
541 app = application_get (app_wrk->app_index);
542 app_mq = app_wrk->event_queue;
543 if (mq_try_lock_and_alloc_msg (app_mq, msg))
545 evt = svm_msg_q_msg_data (app_mq, msg);
546 memset (evt, 0, sizeof (*evt));
547 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
548 mp = (session_disconnected_msg_t *) evt->data;
549 mp->handle = application_local_session_handle (ls);
550 mp->context = app->api_client_index;
551 svm_msg_q_add_and_unlock (app_mq, msg);
555 mq_send_session_reset_cb (stream_session_t * s)
557 app_worker_t *app = app_worker_get (s->app_wrk_index);
558 svm_msg_q_msg_t _msg, *msg = &_msg;
559 session_reset_msg_t *mp;
561 session_event_t *evt;
563 app_mq = app->event_queue;
564 if (mq_try_lock_and_alloc_msg (app_mq, msg))
566 evt = svm_msg_q_msg_data (app_mq, msg);
567 memset (evt, 0, sizeof (*evt));
568 evt->event_type = SESSION_CTRL_EVT_RESET;
569 mp = (session_reset_msg_t *) evt->data;
570 mp->handle = session_handle (s);
571 svm_msg_q_add_and_unlock (app_mq, msg);
575 mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
576 stream_session_t * s, u8 is_fail)
578 svm_msg_q_msg_t _msg, *msg = &_msg;
579 session_connected_msg_t *mp;
580 svm_msg_q_t *vpp_mq, *app_mq;
581 transport_connection_t *tc;
582 app_worker_t *app_wrk;
583 session_event_t *evt;
586 app_wrk = app_worker_get (app_wrk_index);
587 app = application_get (app_wrk->app_index);
588 app_mq = app_wrk->event_queue;
591 clib_warning ("app %u with api index: %u not attached", app->app_index,
592 app->api_client_index);
596 if (mq_try_lock_and_alloc_msg (app_mq, msg))
598 evt = svm_msg_q_msg_data (app_mq, msg);
599 memset (evt, 0, sizeof (*evt));
600 evt->event_type = SESSION_CTRL_EVT_CONNECTED;
601 mp = (session_connected_msg_t *) evt->data;
602 mp->context = api_context;
607 if (session_has_transport (s))
609 tc = session_get_transport (s);
616 vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
617 mp->handle = session_handle (s);
618 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
619 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
620 mp->is_ip4 = tc->is_ip4;
621 mp->lcl_port = tc->lcl_port;
622 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
623 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
627 local_session_t *ls = (local_session_t *) s;
628 u8 main_thread = vlib_num_workers ()? 1 : 0;
630 send_app_cut_through_registration_add (app->api_client_index,
631 app_wrk->wrk_map_index,
635 mp->handle = application_local_session_handle (ls);
636 mp->lcl_port = ls->port;
637 vpp_mq = session_manager_get_vpp_event_queue (main_thread);
638 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
639 mp->client_event_queue_address = ls->client_evt_q;
640 mp->server_event_queue_address = ls->server_evt_q;
641 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
642 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
646 mp->retval = is_fail ?
647 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
649 svm_msg_q_add_and_unlock (app_mq, msg);
654 mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
655 session_handle_t handle, int rv)
657 svm_msg_q_msg_t _msg, *msg = &_msg;
658 svm_msg_q_t *app_mq, *vpp_evt_q;
659 transport_connection_t *tc;
660 stream_session_t *ls = 0;
661 session_bound_msg_t *mp;
662 app_worker_t *app_wrk;
663 session_event_t *evt;
666 app_wrk = app_worker_get (app_wrk_index);
667 app = application_get (app_wrk->app_index);
668 app_mq = app_wrk->event_queue;
671 clib_warning ("app %u with api index: %u not attached", app->app_index,
672 app->api_client_index);
676 if (mq_try_lock_and_alloc_msg (app_mq, msg))
679 evt = svm_msg_q_msg_data (app_mq, msg);
680 memset (evt, 0, sizeof (*evt));
681 evt->event_type = SESSION_CTRL_EVT_BOUND;
682 mp = (session_bound_msg_t *) evt->data;
683 mp->context = api_context;
689 if (application_has_global_scope (app))
691 ls = listen_session_get_from_handle (handle);
692 tc = listen_session_get_transport (ls);
693 mp->lcl_port = tc->lcl_port;
694 mp->lcl_is_ip4 = tc->is_ip4;
695 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
699 local_session_t *local;
700 local = application_get_local_listener_w_handle (handle);
701 mp->lcl_port = local->port;
702 mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type);
705 if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
707 mp->rx_fifo = pointer_to_uword (ls->server_rx_fifo);
708 mp->tx_fifo = pointer_to_uword (ls->server_tx_fifo);
709 vpp_evt_q = session_manager_get_vpp_event_queue (0);
710 mp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
715 svm_msg_q_add_and_unlock (app_mq, msg);
719 static session_cb_vft_t session_mq_cb_vft = {
720 .session_accept_callback = mq_send_session_accepted_cb,
721 .session_disconnect_callback = mq_send_session_disconnected_cb,
722 .session_connected_callback = mq_send_session_connected_cb,
723 .session_reset_callback = mq_send_session_reset_cb,
724 .add_segment_callback = send_add_segment_callback,
725 .del_segment_callback = send_del_segment_callback,
729 vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
731 vl_api_session_enable_disable_reply_t *rmp;
732 vlib_main_t *vm = vlib_get_main ();
735 vnet_session_enable_disable (vm, mp->is_enable);
736 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
740 vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
742 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
743 vl_api_application_attach_reply_t *rmp;
744 ssvm_private_t *segp, *evt_q_segment;
745 vnet_app_attach_args_t _a, *a = &_a;
746 vl_api_registration_t *reg;
747 clib_error_t *error = 0;
750 reg = vl_api_client_index_to_registration (mp->client_index);
754 if (session_manager_is_enabled () == 0)
756 rv = VNET_API_ERROR_FEATURE_DISABLED;
760 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
761 sizeof (mp->options),
762 "Out of options, fix api message definition");
764 memset (a, 0, sizeof (*a));
765 a->api_client_index = mp->client_index;
766 a->options = mp->options;
768 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
769 a->session_cb_vft = &session_mq_cb_vft;
771 a->session_cb_vft = &session_cb_vft;
773 if (mp->namespace_id_len > 64)
775 rv = VNET_API_ERROR_INVALID_VALUE;
779 if (mp->namespace_id_len)
781 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
782 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
785 if ((error = vnet_application_attach (a)))
787 rv = clib_error_get_code (error);
788 clib_error_report (error);
789 vec_free (a->namespace_id);
792 vec_free (a->namespace_id);
794 /* Send event queues segment */
795 if ((evt_q_segment = session_manager_get_evt_q_segment ()))
797 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
798 fds[n_fds] = evt_q_segment->fd;
801 /* Send fifo segment fd if needed */
802 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
804 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
805 fds[n_fds] = a->segment->fd;
808 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
810 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
811 fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
818 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
822 rmp->segment_name_length = 0;
823 rmp->segment_size = segp->ssvm_size;
824 if (vec_len (segp->name))
826 memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
827 rmp->segment_name_length = vec_len (segp->name);
829 rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q);
831 rmp->fd_flags = fd_flags;
837 session_send_fds (reg, fds, n_fds);
841 vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
843 vl_api_application_detach_reply_t *rmp;
844 int rv = VNET_API_ERROR_INVALID_VALUE_2;
845 vnet_app_detach_args_t _a, *a = &_a;
848 if (session_manager_is_enabled () == 0)
850 rv = VNET_API_ERROR_FEATURE_DISABLED;
854 app = application_lookup (mp->client_index);
857 a->app_index = app->app_index;
858 rv = vnet_application_detach (a);
862 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
866 vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
868 transport_connection_t *tc = 0;
869 vnet_bind_args_t _a, *a = &_a;
870 vl_api_bind_uri_reply_t *rmp;
872 application_t *app = 0;
873 svm_msg_q_t *vpp_evt_q;
874 app_worker_t *app_wrk;
877 if (session_manager_is_enabled () == 0)
879 rv = VNET_API_ERROR_FEATURE_DISABLED;
883 app = application_lookup (mp->client_index);
886 memset (a, 0, sizeof (*a));
887 a->uri = (char *) mp->uri;
888 a->app_index = app->app_index;
889 rv = vnet_bind_uri (a);
893 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
899 REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
902 rmp->handle = a->handle;
903 if (app && application_has_global_scope (app))
905 s = listen_session_get_from_handle (a->handle);
906 tc = listen_session_get_transport (s);
907 rmp->lcl_is_ip4 = tc->is_ip4;
908 rmp->lcl_port = tc->lcl_port;
909 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
910 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
912 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
913 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
914 vpp_evt_q = session_manager_get_vpp_event_queue (0);
915 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
922 /* If app uses mq for control messages, send an mq message as well */
923 if (app && application_use_mq_for_ctrl (app))
925 app_wrk = application_get_worker (app, 0);
926 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
932 vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
934 vl_api_unbind_uri_reply_t *rmp;
936 vnet_unbind_args_t _a, *a = &_a;
939 if (session_manager_is_enabled () == 0)
941 rv = VNET_API_ERROR_FEATURE_DISABLED;
945 app = application_lookup (mp->client_index);
948 a->uri = (char *) mp->uri;
949 a->app_index = app->app_index;
950 rv = vnet_unbind_uri (a);
954 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
958 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
962 vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
964 vl_api_connect_session_reply_t *rmp;
965 vnet_connect_args_t _a, *a = &_a;
967 clib_error_t *error = 0;
970 if (session_manager_is_enabled () == 0)
972 rv = VNET_API_ERROR_FEATURE_DISABLED;
976 app = application_lookup (mp->client_index);
979 memset (a, 0, sizeof (*a));
980 a->uri = (char *) mp->uri;
981 a->api_context = mp->context;
982 a->app_index = app->app_index;
983 if ((error = vnet_connect_uri (a)))
985 rv = clib_error_get_code (error);
986 clib_error_report (error);
991 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
995 * Don't reply to stream (tcp) connects. The reply will come once
996 * the connection is established. In case of the redirects, the reply
997 * will come from the server app.
1004 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
1009 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
1011 vl_api_disconnect_session_reply_t *rmp;
1012 vnet_disconnect_args_t _a, *a = &_a;
1016 if (session_manager_is_enabled () == 0)
1018 rv = VNET_API_ERROR_FEATURE_DISABLED;
1022 app = application_lookup (mp->client_index);
1025 a->handle = mp->handle;
1026 a->app_index = app->app_index;
1027 rv = vnet_disconnect_session (a);
1031 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1035 REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
1039 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
1042 vnet_disconnect_args_t _a, *a = &_a;
1045 /* Client objected to disconnecting the session, log and continue */
1048 clib_warning ("client retval %d", mp->retval);
1052 /* Disconnect has been confirmed. Confirm close to transport */
1053 app = application_lookup (mp->context);
1056 a->handle = mp->handle;
1057 a->app_index = app->app_index;
1058 vnet_disconnect_session (a);
1063 vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
1065 app_worker_t *app_wrk;
1067 stream_session_t *s;
1068 u32 index, thread_index;
1070 app = application_lookup (mp->context);
1074 session_parse_handle (mp->handle, &index, &thread_index);
1075 s = session_get_if_valid (index, thread_index);
1078 clib_warning ("Invalid session!");
1082 app_wrk = app_worker_get (s->app_wrk_index);
1083 if (app_wrk->app_index != app->app_index)
1085 clib_warning ("app %u does not own handle 0x%lx", app->app_index,
1090 /* Client objected to resetting the session, log and continue */
1093 clib_warning ("client retval %d", mp->retval);
1097 /* This comes as a response to a reset, transport only waiting for
1098 * confirmation to remove connection state, no need to disconnect */
1099 stream_session_cleanup (s);
1103 vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
1105 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
1106 local_session_t *ls;
1107 stream_session_t *s;
1109 /* Server isn't interested, kill the session */
1112 a->app_index = mp->context;
1113 a->handle = mp->handle;
1114 vnet_disconnect_session (a);
1118 if (session_handle_is_local (mp->handle))
1120 ls = application_get_local_session_from_handle (mp->handle);
1121 if (!ls || ls->app_wrk_index != mp->context)
1123 clib_warning ("server %u doesn't own local handle %llu",
1124 mp->context, mp->handle);
1127 if (application_local_session_connect_notify (ls))
1129 ls->session_state = SESSION_STATE_READY;
1133 s = session_get_from_handle_if_valid (mp->handle);
1136 clib_warning ("session doesn't exist");
1139 if (s->app_wrk_index != mp->context)
1141 clib_warning ("app doesn't own session");
1144 s->session_state = SESSION_STATE_READY;
1149 vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
1152 clib_warning ("not implemented");
1156 vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
1158 vl_api_bind_sock_reply_t *rmp;
1159 vnet_bind_args_t _a, *a = &_a;
1161 clib_error_t *error;
1162 application_t *app = 0;
1163 app_worker_t *app_wrk;
1164 stream_session_t *s;
1165 transport_connection_t *tc = 0;
1166 ip46_address_t *ip46;
1167 svm_msg_q_t *vpp_evt_q;
1169 if (session_manager_is_enabled () == 0)
1171 rv = VNET_API_ERROR_FEATURE_DISABLED;
1175 app = application_lookup (mp->client_index);
1178 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1182 ip46 = (ip46_address_t *) mp->ip;
1183 memset (a, 0, sizeof (*a));
1184 a->sep.is_ip4 = mp->is_ip4;
1186 a->sep.port = mp->port;
1187 a->sep.fib_index = mp->vrf;
1188 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1189 a->sep.transport_proto = mp->proto;
1190 a->app_index = app->app_index;
1191 a->wrk_map_index = mp->wrk_index;
1193 if ((error = vnet_bind (a)))
1195 rv = clib_error_get_code (error);
1196 clib_error_report (error);
1201 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
1204 rmp->handle = a->handle;
1205 rmp->lcl_port = mp->port;
1206 rmp->lcl_is_ip4 = mp->is_ip4;
1207 if (app && application_has_global_scope (app))
1209 s = listen_session_get_from_handle (a->handle);
1210 tc = listen_session_get_transport (s);
1211 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
1212 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
1214 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
1215 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
1216 vpp_evt_q = session_manager_get_vpp_event_queue (0);
1217 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
1224 /* If app uses mq for control messages, send an mq message as well */
1225 if (app && application_use_mq_for_ctrl (app))
1227 app_wrk = application_get_worker (app, mp->wrk_index);
1228 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
1234 vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
1236 vl_api_unbind_sock_reply_t *rmp;
1237 vnet_unbind_args_t _a, *a = &_a;
1239 clib_error_t *error;
1242 if (session_manager_is_enabled () == 0)
1244 rv = VNET_API_ERROR_FEATURE_DISABLED;
1248 app = application_lookup (mp->client_index);
1251 a->app_index = app->app_index;
1252 a->handle = mp->handle;
1253 a->wrk_map_index = mp->wrk_index;
1254 if ((error = vnet_unbind (a)))
1256 rv = clib_error_get_code (error);
1257 clib_error_report (error);
1262 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
1266 vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1268 vl_api_connect_session_reply_t *rmp;
1269 vnet_connect_args_t _a, *a = &_a;
1270 application_t *app = 0;
1271 clib_error_t *error = 0;
1274 if (session_manager_is_enabled () == 0)
1276 rv = VNET_API_ERROR_FEATURE_DISABLED;
1280 app = application_lookup (mp->client_index);
1283 svm_queue_t *client_q;
1284 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
1286 memset (a, 0, sizeof (*a));
1287 client_q = vl_api_client_index_to_input_queue (mp->client_index);
1288 mp->client_queue_address = pointer_to_uword (client_q);
1289 a->sep.is_ip4 = mp->is_ip4;
1291 a->sep.port = mp->port;
1292 a->sep.transport_proto = mp->proto;
1293 a->sep.fib_index = mp->vrf;
1294 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1295 if (mp->hostname_len)
1297 vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
1298 clib_memcpy (a->sep_ext.hostname, mp->hostname, mp->hostname_len);
1300 a->api_context = mp->context;
1301 a->app_index = app->app_index;
1302 a->wrk_map_index = mp->wrk_index;
1303 if ((error = vnet_connect (a)))
1305 rv = clib_error_get_code (error);
1306 clib_error_report (error);
1308 vec_free (a->sep_ext.hostname);
1312 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1318 /* Got some error, relay it */
1321 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
1323 if (app && application_use_mq_for_ctrl (app))
1325 app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index);
1326 mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1);
1331 vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
1333 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1334 vl_api_app_worker_add_del_reply_t *rmp;
1335 vl_api_registration_t *reg;
1336 clib_error_t *error = 0;
1340 if (!session_manager_is_enabled ())
1342 rv = VNET_API_ERROR_FEATURE_DISABLED;
1346 reg = vl_api_client_index_to_registration (mp->client_index);
1350 app = application_lookup (clib_net_to_host_u32 (mp->app_api_index));
1353 rv = VNET_API_ERROR_INVALID_VALUE;
1357 vnet_app_worker_add_del_args_t args = {
1358 .app_index = app->app_index,
1359 .wrk_index = clib_net_to_host_u32 (mp->wrk_index),
1360 .is_add = mp->is_add
1362 error = vnet_app_worker_add_del (&args);
1365 rv = clib_error_get_code (error);
1366 clib_error_report (error);
1373 /* Send fifo segment fd if needed */
1374 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1376 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1377 fds[n_fds] = args.segment->fd;
1380 if (application_segment_manager_properties (app)->use_mq_eventfd)
1382 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
1383 fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q);
1389 REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
1390 rmp->is_add = mp->is_add;
1391 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_index);
1392 if (!rv && mp->is_add)
1394 if (vec_len (args.segment->name))
1396 memcpy (rmp->segment_name, args.segment->name,
1397 vec_len (args.segment->name));
1398 rmp->segment_name_length = vec_len (args.segment->name);
1400 rmp->app_event_queue_address = pointer_to_uword (args.evt_q);
1402 rmp->fd_flags = fd_flags;
1408 session_send_fds (reg, fds, n_fds);
1412 vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
1414 vl_api_app_namespace_add_del_reply_t *rmp;
1415 clib_error_t *error = 0;
1416 u32 appns_index = 0;
1419 if (!session_manager_is_enabled ())
1421 rv = VNET_API_ERROR_FEATURE_DISABLED;
1425 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
1427 rv = VNET_API_ERROR_INVALID_VALUE;
1431 vec_validate (ns_id, mp->namespace_id_len - 1);
1432 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
1433 vnet_app_namespace_add_del_args_t args = {
1435 .secret = clib_net_to_host_u64 (mp->secret),
1436 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
1437 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
1438 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
1441 error = vnet_app_namespace_add_del (&args);
1444 rv = clib_error_get_code (error);
1445 clib_error_report (error);
1449 appns_index = app_namespace_index_from_id (ns_id);
1450 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
1452 clib_warning ("app ns lookup failed");
1453 rv = VNET_API_ERROR_UNSPECIFIED;
1460 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
1462 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1468 vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
1470 vl_api_session_rule_add_del_reply_t *rmp;
1471 session_rule_add_del_args_t args;
1472 session_rule_table_add_del_args_t *table_args = &args.table_args;
1473 clib_error_t *error;
1477 memset (&args, 0, sizeof (args));
1478 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1480 table_args->lcl.fp_len = mp->lcl_plen;
1481 table_args->lcl.fp_proto = fib_proto;
1482 table_args->rmt.fp_len = mp->rmt_plen;
1483 table_args->rmt.fp_proto = fib_proto;
1484 table_args->lcl_port = mp->lcl_port;
1485 table_args->rmt_port = mp->rmt_port;
1486 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
1487 table_args->is_add = mp->is_add;
1488 mp->tag[sizeof (mp->tag) - 1] = 0;
1489 table_args->tag = format (0, "%s", mp->tag);
1490 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
1491 args.scope = mp->scope;
1492 args.transport_proto = mp->transport_proto;
1494 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
1495 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
1496 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
1497 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
1498 error = vnet_session_rule_add_del (&args);
1501 rv = clib_error_get_code (error);
1502 clib_error_report (error);
1504 vec_free (table_args->tag);
1505 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
1509 send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
1510 u8 transport_proto, u32 appns_index, u8 * tag,
1511 vl_api_registration_t * reg, u32 context)
1513 vl_api_session_rules_details_t *rmp = 0;
1514 session_mask_or_match_4_t *match =
1515 (session_mask_or_match_4_t *) & rule->match;
1516 session_mask_or_match_4_t *mask =
1517 (session_mask_or_match_4_t *) & rule->mask;
1519 rmp = vl_msg_api_alloc (sizeof (*rmp));
1520 memset (rmp, 0, sizeof (*rmp));
1521 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1522 rmp->context = context;
1525 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1526 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1527 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
1528 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
1529 rmp->lcl_port = match->lcl_port;
1530 rmp->rmt_port = match->rmt_port;
1531 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1533 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
1534 rmp->transport_proto = transport_proto;
1535 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1538 clib_memcpy (rmp->tag, tag, vec_len (tag));
1539 rmp->tag[vec_len (tag)] = 0;
1542 vl_api_send_msg (reg, (u8 *) rmp);
1546 send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
1547 u8 transport_proto, u32 appns_index, u8 * tag,
1548 vl_api_registration_t * reg, u32 context)
1550 vl_api_session_rules_details_t *rmp = 0;
1551 session_mask_or_match_6_t *match =
1552 (session_mask_or_match_6_t *) & rule->match;
1553 session_mask_or_match_6_t *mask =
1554 (session_mask_or_match_6_t *) & rule->mask;
1556 rmp = vl_msg_api_alloc (sizeof (*rmp));
1557 memset (rmp, 0, sizeof (*rmp));
1558 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1559 rmp->context = context;
1562 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1563 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1564 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
1565 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
1566 rmp->lcl_port = match->lcl_port;
1567 rmp->rmt_port = match->rmt_port;
1568 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1570 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
1571 rmp->transport_proto = transport_proto;
1572 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1575 clib_memcpy (rmp->tag, tag, vec_len (tag));
1576 rmp->tag[vec_len (tag)] = 0;
1579 vl_api_send_msg (reg, (u8 *) rmp);
1583 send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
1584 u8 tp, u8 is_local, u32 appns_index,
1585 vl_api_registration_t * reg, u32 context)
1587 mma_rule_16_t *rule16;
1588 mma_rule_40_t *rule40;
1589 mma_rules_table_16_t *srt16;
1590 mma_rules_table_40_t *srt40;
1593 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
1597 srt16 = &srt->session_rules_tables_16;
1598 pool_foreach (rule16, srt16->rules, ({
1599 ri = mma_rules_table_rule_index_16 (srt16, rule16);
1600 tag = session_rules_table_rule_tag (srt, ri, 1);
1601 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
1606 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
1610 srt40 = &srt->session_rules_tables_40;
1611 pool_foreach (rule40, srt40->rules, ({
1612 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1613 tag = session_rules_table_rule_tag (srt, ri, 1);
1614 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
1622 vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1624 vl_api_registration_t *reg;
1625 session_table_t *st;
1628 reg = vl_api_client_index_to_registration (mp->client_index);
1633 session_table_foreach (st, ({
1634 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
1636 send_session_rules_table_details (&st->session_rules[tp],
1637 st->active_fib_proto, tp,
1638 st->is_local, st->appns_index, reg,
1646 vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
1649 vl_api_app_namespace_add_del_reply_t *rmp;
1650 vnet_app_add_tls_cert_args_t _a, *a = &_a;
1651 clib_error_t *error;
1655 if (!session_manager_is_enabled ())
1657 rv = VNET_API_ERROR_FEATURE_DISABLED;
1660 if (!(app = application_lookup (mp->client_index)))
1662 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1665 memset (a, 0, sizeof (*a));
1666 a->app_index = app->app_index;
1667 cert_len = clib_net_to_host_u16 (mp->cert_len);
1668 if (cert_len > 10000)
1670 rv = VNET_API_ERROR_INVALID_VALUE;
1673 vec_validate (a->cert, cert_len);
1674 clib_memcpy (a->cert, mp->cert, cert_len);
1675 if ((error = vnet_app_add_tls_cert (a)))
1677 rv = clib_error_get_code (error);
1678 clib_error_report (error);
1682 REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
1686 vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
1689 vl_api_app_namespace_add_del_reply_t *rmp;
1690 vnet_app_add_tls_key_args_t _a, *a = &_a;
1691 clib_error_t *error;
1695 if (!session_manager_is_enabled ())
1697 rv = VNET_API_ERROR_FEATURE_DISABLED;
1700 if (!(app = application_lookup (mp->client_index)))
1702 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1705 memset (a, 0, sizeof (*a));
1706 a->app_index = app->app_index;
1707 key_len = clib_net_to_host_u16 (mp->key_len);
1708 if (key_len > 10000)
1710 rv = VNET_API_ERROR_INVALID_VALUE;
1713 vec_validate (a->key, key_len);
1714 clib_memcpy (a->key, mp->key, key_len);
1715 if ((error = vnet_app_add_tls_key (a)))
1717 rv = clib_error_get_code (error);
1718 clib_error_report (error);
1722 REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);
1725 static clib_error_t *
1726 application_reaper_cb (u32 client_index)
1728 application_t *app = application_lookup (client_index);
1729 vnet_app_detach_args_t _a, *a = &_a;
1732 a->app_index = app->app_index;
1733 vnet_application_detach (a);
1738 VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
1740 #define vl_msg_name_crc_list
1741 #include <vnet/vnet_all_api_h.h>
1742 #undef vl_msg_name_crc_list
1745 setup_message_id_table (api_main_t * am)
1747 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1748 foreach_vl_msg_name_crc_session;
1753 * session_api_hookup
1754 * Add uri's API message handlers to the table.
1755 * vlib has alread mapped shared memory and
1756 * added the client registration handlers.
1757 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1759 static clib_error_t *
1760 session_api_hookup (vlib_main_t * vm)
1762 api_main_t *am = &api_main;
1765 vl_msg_api_set_handlers(VL_API_##N, #n, \
1766 vl_api_##n##_t_handler, \
1768 vl_api_##n##_t_endian, \
1769 vl_api_##n##_t_print, \
1770 sizeof(vl_api_##n##_t), 1);
1771 foreach_session_api_msg;
1775 * Messages which bounce off the data-plane to
1776 * an API client. Simply tells the message handling infra not
1777 * to free the message.
1779 * Bounced message handlers MUST NOT block the data plane
1781 am->message_bounce[VL_API_CONNECT_URI] = 1;
1782 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1785 * Set up the (msg_name, crc, message-id) table
1787 setup_message_id_table (am);
1792 VLIB_API_INIT_FUNCTION (session_api_hookup);
1795 * fd.io coding-style-patch-verification: ON
1798 * eval: (c-set-style "gnu")