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) \
61 send_add_segment_callback (u32 api_client_index, const u8 * segment_name,
64 vl_api_map_another_segment_t *mp;
65 unix_shared_memory_queue_t *q;
67 q = vl_api_client_index_to_input_queue (api_client_index);
72 mp = vl_msg_api_alloc (sizeof (*mp));
73 memset (mp, 0, sizeof (*mp));
74 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT);
75 mp->segment_size = segment_size;
76 strncpy ((char *) mp->segment_name, (char *) segment_name,
77 sizeof (mp->segment_name) - 1);
79 vl_msg_api_send_shmem (q, (u8 *) & mp);
85 send_session_accept_callback (stream_session_t * s)
87 vl_api_accept_session_t *mp;
88 unix_shared_memory_queue_t *q, *vpp_queue;
89 application_t *server = application_get (s->app_index);
90 transport_connection_t *tc;
91 transport_proto_vft_t *tp_vft;
92 stream_session_t *listener;
94 q = vl_api_client_index_to_input_queue (server->api_client_index);
95 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
100 mp = vl_msg_api_alloc (sizeof (*mp));
101 memset (mp, 0, sizeof (*mp));
103 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
104 mp->context = server->index;
105 listener = listen_session_get (s->session_type, s->listener_index);
106 tp_vft = transport_protocol_get_vft (s->session_type);
107 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
108 mp->listener_handle = listen_session_get_handle (listener);
109 mp->handle = session_handle (s);
110 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
111 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
112 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
113 mp->port = tc->rmt_port;
114 mp->is_ip4 = tc->is_ip4;
115 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
116 vl_msg_api_send_shmem (q, (u8 *) & mp);
122 send_session_disconnect_callback (stream_session_t * s)
124 vl_api_disconnect_session_t *mp;
125 unix_shared_memory_queue_t *q;
126 application_t *app = application_get (s->app_index);
128 q = vl_api_client_index_to_input_queue (app->api_client_index);
133 mp = vl_msg_api_alloc (sizeof (*mp));
134 memset (mp, 0, sizeof (*mp));
135 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
136 mp->handle = session_handle (s);
137 vl_msg_api_send_shmem (q, (u8 *) & mp);
141 send_session_reset_callback (stream_session_t * s)
143 vl_api_reset_session_t *mp;
144 unix_shared_memory_queue_t *q;
145 application_t *app = application_get (s->app_index);
147 q = vl_api_client_index_to_input_queue (app->api_client_index);
152 mp = vl_msg_api_alloc (sizeof (*mp));
153 memset (mp, 0, sizeof (*mp));
154 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
155 mp->handle = session_handle (s);
156 vl_msg_api_send_shmem (q, (u8 *) & mp);
160 send_session_connected_callback (u32 app_index, u32 api_context,
161 stream_session_t * s, u8 is_fail)
163 vl_api_connect_session_reply_t *mp;
164 unix_shared_memory_queue_t *q;
166 unix_shared_memory_queue_t *vpp_queue;
167 transport_connection_t *tc;
169 app = application_get (app_index);
170 q = vl_api_client_index_to_input_queue (app->api_client_index);
175 mp = vl_msg_api_alloc (sizeof (*mp));
176 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
177 mp->context = api_context;
182 tc = session_get_transport (s);
189 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
190 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
191 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
192 mp->handle = session_handle (s);
193 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
194 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
195 mp->is_ip4 = tc->is_ip4;
196 mp->lcl_port = tc->lcl_port;
199 mp->retval = is_fail ?
200 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
201 vl_msg_api_send_shmem (q, (u8 *) & mp);
206 * Redirect a connect_uri message to the indicated server.
207 * Only sent if the server has bound the related port with
208 * URI_OPTIONS_FLAGS_USE_FIFO
211 redirect_connect_callback (u32 server_api_client_index, void *mp_arg)
213 vl_api_connect_sock_t *mp = mp_arg;
214 unix_shared_memory_queue_t *server_q, *client_q;
215 segment_manager_properties_t *props;
216 vlib_main_t *vm = vlib_get_main ();
217 f64 timeout = vlib_time_now (vm) + 0.5;
221 server_q = vl_api_client_index_to_input_queue (server_api_client_index);
225 rv = VNET_API_ERROR_INVALID_VALUE;
229 client_q = vl_api_client_index_to_input_queue (mp->client_index);
232 rv = VNET_API_ERROR_INVALID_VALUE_2;
236 /* Tell the server the client's API queue address, so it can reply */
237 mp->client_queue_address = pointer_to_uword (client_q);
238 app = application_lookup (mp->client_index);
241 clib_warning ("no client application");
245 props = segment_manager_properties_get (app->sm_properties);
246 mp->options[SESSION_OPTIONS_RX_FIFO_SIZE] = props->rx_fifo_size;
247 mp->options[SESSION_OPTIONS_TX_FIFO_SIZE] = props->tx_fifo_size;
250 * Bounce message handlers MUST NOT block the data-plane.
251 * Spin waiting for the queue lock, but
254 while (vlib_time_now (vm) < timeout)
257 unix_shared_memory_queue_add (server_q, (u8 *) & mp, 1 /*nowait */ );
260 /* correctly enqueued */
262 return VNET_API_ERROR_SESSION_REDIRECT;
264 /* continue spinning, wait for pthread_mutex_trylock to work */
268 /* queue stuffed, drop the msg */
270 rv = VNET_API_ERROR_QUEUE_FULL;
275 /* Dispose of the message */
276 vl_msg_api_free (mp);
280 static session_cb_vft_t session_cb_vft = {
281 .session_accept_callback = send_session_accept_callback,
282 .session_disconnect_callback = send_session_disconnect_callback,
283 .session_connected_callback = send_session_connected_callback,
284 .session_reset_callback = send_session_reset_callback,
285 .add_segment_callback = send_add_segment_callback,
286 .redirect_connect_callback = redirect_connect_callback
290 vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
292 vl_api_session_enable_disable_reply_t *rmp;
293 vlib_main_t *vm = vlib_get_main ();
296 vnet_session_enable_disable (vm, mp->is_enable);
297 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
301 vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
303 vl_api_application_attach_reply_t *rmp;
304 vnet_app_attach_args_t _a, *a = &_a;
305 clib_error_t *error = 0;
308 if (session_manager_is_enabled () == 0)
310 rv = VNET_API_ERROR_FEATURE_DISABLED;
314 STATIC_ASSERT (sizeof (u64) * SESSION_OPTIONS_N_OPTIONS <=
315 sizeof (mp->options),
316 "Out of options, fix api message definition");
318 memset (a, 0, sizeof (*a));
319 a->api_client_index = mp->client_index;
320 a->options = mp->options;
321 a->session_cb_vft = &session_cb_vft;
323 if (mp->namespace_id_len > 64)
325 rv = VNET_API_ERROR_INVALID_VALUE;
329 if (mp->namespace_id_len)
331 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
332 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
335 if ((error = vnet_application_attach (a)))
337 rv = clib_error_get_code (error);
338 clib_error_report (error);
340 vec_free (a->namespace_id);
345 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
348 rmp->segment_name_length = 0;
349 rmp->segment_size = a->segment_size;
350 if (a->segment_name_length)
352 memcpy (rmp->segment_name, a->segment_name,
353 a->segment_name_length);
354 rmp->segment_name_length = a->segment_name_length;
356 rmp->app_event_queue_address = a->app_event_queue_address;
363 vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
365 vl_api_application_detach_reply_t *rmp;
366 int rv = VNET_API_ERROR_INVALID_VALUE_2;
367 vnet_app_detach_args_t _a, *a = &_a;
370 if (session_manager_is_enabled () == 0)
372 rv = VNET_API_ERROR_FEATURE_DISABLED;
376 app = application_lookup (mp->client_index);
379 a->app_index = app->index;
380 rv = vnet_application_detach (a);
384 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
388 vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
390 vl_api_bind_uri_reply_t *rmp;
391 vnet_bind_args_t _a, *a = &_a;
395 if (session_manager_is_enabled () == 0)
397 rv = VNET_API_ERROR_FEATURE_DISABLED;
401 app = application_lookup (mp->client_index);
404 memset (a, 0, sizeof (*a));
405 a->uri = (char *) mp->uri;
406 a->app_index = app->index;
407 rv = vnet_bind_uri (a);
411 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
415 REPLY_MACRO (VL_API_BIND_URI_REPLY);
419 vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
421 vl_api_unbind_uri_reply_t *rmp;
423 vnet_unbind_args_t _a, *a = &_a;
426 if (session_manager_is_enabled () == 0)
428 rv = VNET_API_ERROR_FEATURE_DISABLED;
432 app = application_lookup (mp->client_index);
435 a->uri = (char *) mp->uri;
436 a->app_index = app->index;
437 rv = vnet_unbind_uri (a);
441 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
445 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
449 vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
451 vl_api_connect_session_reply_t *rmp;
452 vnet_connect_args_t _a, *a = &_a;
454 clib_error_t *error = 0;
457 if (session_manager_is_enabled () == 0)
459 rv = VNET_API_ERROR_FEATURE_DISABLED;
463 app = application_lookup (mp->client_index);
466 a->uri = (char *) mp->uri;
467 a->api_context = mp->context;
468 a->app_index = app->index;
470 if ((error = vnet_connect_uri (a)))
472 rv = clib_error_get_code (error);
473 if (rv != VNET_API_ERROR_SESSION_REDIRECT)
474 clib_error_report (error);
479 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
483 * Don't reply to stream (tcp) connects. The reply will come once
484 * the connection is established. In case of the redirects, the reply
485 * will come from the server app.
487 if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT)
492 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
497 vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
499 vl_api_disconnect_session_reply_t *rmp;
500 vnet_disconnect_args_t _a, *a = &_a;
504 if (session_manager_is_enabled () == 0)
506 rv = VNET_API_ERROR_FEATURE_DISABLED;
510 app = application_lookup (mp->client_index);
513 a->handle = mp->handle;
514 a->app_index = app->index;
515 rv = vnet_disconnect_session (a);
519 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
523 REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
527 vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
530 vnet_disconnect_args_t _a, *a = &_a;
533 /* Client objected to disconnecting the session, log and continue */
536 clib_warning ("client retval %d", mp->retval);
540 /* Disconnect has been confirmed. Confirm close to transport */
541 app = application_lookup (mp->client_index);
544 a->handle = mp->handle;
545 a->app_index = app->index;
546 vnet_disconnect_session (a);
551 vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
555 u32 index, thread_index;
557 app = application_lookup (mp->client_index);
561 session_parse_handle (mp->handle, &index, &thread_index);
562 s = session_get_if_valid (index, thread_index);
563 if (s == 0 || app->index != s->app_index)
565 clib_warning ("Invalid session!");
569 /* Client objected to resetting the session, log and continue */
572 clib_warning ("client retval %d", mp->retval);
576 /* This comes as a response to a reset, transport only waiting for
577 * confirmation to remove connection state, no need to disconnect */
578 stream_session_cleanup (s);
582 vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
585 u32 session_index, thread_index;
586 vnet_disconnect_args_t _a, *a = &_a;
588 /* Server isn't interested, kill the session */
591 a->app_index = mp->context;
592 a->handle = mp->handle;
593 vnet_disconnect_session (a);
597 session_parse_handle (mp->handle, &session_index, &thread_index);
598 s = session_get_if_valid (session_index, thread_index);
601 clib_warning ("session doesn't exist");
604 if (s->app_index != mp->context)
606 clib_warning ("app doesn't own session");
609 s->session_state = SESSION_STATE_READY;
614 vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
617 clib_warning ("not implemented");
621 vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
623 vl_api_bind_sock_reply_t *rmp;
624 vnet_bind_args_t _a, *a = &_a;
627 application_t *app = 0;
629 transport_connection_t *tc = 0;
630 ip46_address_t *ip46;
632 if (session_manager_is_enabled () == 0)
634 rv = VNET_API_ERROR_FEATURE_DISABLED;
638 app = application_lookup (mp->client_index);
641 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
645 ip46 = (ip46_address_t *) mp->ip;
646 memset (a, 0, sizeof (*a));
647 a->sep.is_ip4 = mp->is_ip4;
649 a->sep.port = mp->port;
650 a->sep.fib_index = mp->vrf;
651 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
652 a->sep.transport_proto = mp->proto;
653 a->app_index = app->index;
655 if ((error = vnet_bind (a)))
657 rv = clib_error_get_code (error);
658 clib_error_report (error);
663 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
666 rmp->handle = a->handle;
667 rmp->lcl_port = mp->port;
668 if (application_has_global_scope (app))
670 s = listen_session_get_from_handle (a->handle);
671 tc = listen_session_get_transport (s);
672 rmp->lcl_is_ip4 = tc->is_ip4;
673 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
681 vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
683 vl_api_unbind_sock_reply_t *rmp;
684 vnet_unbind_args_t _a, *a = &_a;
689 if (session_manager_is_enabled () == 0)
691 rv = VNET_API_ERROR_FEATURE_DISABLED;
695 app = application_lookup (mp->client_index);
698 a->app_index = app->index;
699 a->handle = mp->handle;
700 if ((error = vnet_unbind (a)))
702 rv = clib_error_get_code (error);
703 clib_error_report (error);
708 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
712 vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
714 vl_api_connect_session_reply_t *rmp;
715 vnet_connect_args_t _a, *a = &_a;
717 clib_error_t *error = 0;
720 if (session_manager_is_enabled () == 0)
722 rv = VNET_API_ERROR_FEATURE_DISABLED;
726 app = application_lookup (mp->client_index);
729 unix_shared_memory_queue_t *client_q;
730 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
732 client_q = vl_api_client_index_to_input_queue (mp->client_index);
733 mp->client_queue_address = pointer_to_uword (client_q);
734 a->sep.is_ip4 = mp->is_ip4;
736 a->sep.port = mp->port;
737 a->sep.transport_proto = mp->proto;
738 a->sep.fib_index = mp->vrf;
739 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
740 a->api_context = mp->context;
741 a->app_index = app->index;
743 if ((error = vnet_connect (a)))
745 rv = clib_error_get_code (error);
746 if (rv != VNET_API_ERROR_SESSION_REDIRECT)
747 clib_error_report (error);
752 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
755 if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT)
758 /* Got some error, relay it */
761 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
765 vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
767 vl_api_app_namespace_add_del_reply_t *rmp;
768 clib_error_t *error = 0;
772 if (!session_manager_is_enabled ())
774 rv = VNET_API_ERROR_FEATURE_DISABLED;
778 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
780 rv = VNET_API_ERROR_INVALID_VALUE;
784 vec_validate (ns_id, mp->namespace_id_len - 1);
785 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
786 vnet_app_namespace_add_del_args_t args = {
788 .secret = clib_net_to_host_u64 (mp->secret),
789 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
790 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
791 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
794 error = vnet_app_namespace_add_del (&args);
797 rv = clib_error_get_code (error);
798 clib_error_report (error);
802 appns_index = app_namespace_index_from_id (ns_id);
803 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
805 clib_warning ("app ns lookup failed");
806 rv = VNET_API_ERROR_UNSPECIFIED;
813 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
815 rmp->appns_index = clib_host_to_net_u32 (appns_index);
821 vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
823 vl_api_session_rule_add_del_reply_t *rmp;
824 session_rule_add_del_args_t args;
825 session_rule_table_add_del_args_t *table_args = &args.table_args;
830 memset (&args, 0, sizeof (args));
831 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
833 table_args->lcl.fp_len = mp->lcl_plen;
834 table_args->lcl.fp_proto = fib_proto;
835 table_args->rmt.fp_len = mp->rmt_plen;
836 table_args->rmt.fp_proto = fib_proto;
837 table_args->lcl_port = mp->lcl_port;
838 table_args->rmt_port = mp->rmt_port;
839 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
840 table_args->is_add = mp->is_add;
841 mp->tag[sizeof (mp->tag) - 1] = 0;
842 table_args->tag = format (0, "%s", mp->tag);
843 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
844 args.scope = mp->scope;
845 args.transport_proto = mp->transport_proto;
847 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
848 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
849 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
850 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
851 error = vnet_session_rule_add_del (&args);
854 rv = clib_error_get_code (error);
855 clib_error_report (error);
857 vec_free (table_args->tag);
858 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
862 send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
863 u8 transport_proto, u32 appns_index, u8 * tag,
864 unix_shared_memory_queue_t * q, u32 context)
866 vl_api_session_rules_details_t *rmp = 0;
867 session_mask_or_match_4_t *match =
868 (session_mask_or_match_4_t *) & rule->match;
869 session_mask_or_match_4_t *mask =
870 (session_mask_or_match_4_t *) & rule->mask;
872 rmp = vl_msg_api_alloc (sizeof (*rmp));
873 memset (rmp, 0, sizeof (*rmp));
874 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
875 rmp->context = context;
878 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
879 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
880 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
881 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
882 rmp->lcl_port = match->lcl_port;
883 rmp->rmt_port = match->rmt_port;
884 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
886 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
887 rmp->transport_proto = transport_proto;
888 rmp->appns_index = clib_host_to_net_u32 (appns_index);
891 clib_memcpy (rmp->tag, tag, vec_len (tag));
892 rmp->tag[vec_len (tag)] = 0;
895 vl_msg_api_send_shmem (q, (u8 *) & rmp);
899 send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
900 u8 transport_proto, u32 appns_index, u8 * tag,
901 unix_shared_memory_queue_t * q, u32 context)
903 vl_api_session_rules_details_t *rmp = 0;
904 session_mask_or_match_6_t *match =
905 (session_mask_or_match_6_t *) & rule->match;
906 session_mask_or_match_6_t *mask =
907 (session_mask_or_match_6_t *) & rule->mask;
909 rmp = vl_msg_api_alloc (sizeof (*rmp));
910 memset (rmp, 0, sizeof (*rmp));
911 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
912 rmp->context = context;
915 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
916 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
917 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
918 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
919 rmp->lcl_port = match->lcl_port;
920 rmp->rmt_port = match->rmt_port;
921 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
923 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
924 rmp->transport_proto = transport_proto;
925 rmp->appns_index = clib_host_to_net_u32 (appns_index);
928 clib_memcpy (rmp->tag, tag, vec_len (tag));
929 rmp->tag[vec_len (tag)] = 0;
932 vl_msg_api_send_shmem (q, (u8 *) & rmp);
936 send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
937 u8 tp, u8 is_local, u32 appns_index,
938 unix_shared_memory_queue_t * q, u32 context)
940 mma_rule_16_t *rule16;
941 mma_rule_40_t *rule40;
942 mma_rules_table_16_t *srt16;
943 mma_rules_table_40_t *srt40;
946 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
950 srt16 = &srt->session_rules_tables_16;
951 pool_foreach (rule16, srt16->rules, ({
952 ri = mma_rules_table_rule_index_16 (srt16, rule16);
953 tag = session_rules_table_rule_tag (srt, ri, 1);
954 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
959 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
963 srt40 = &srt->session_rules_tables_40;
964 pool_foreach (rule40, srt40->rules, ({
965 ri = mma_rules_table_rule_index_40 (srt40, rule40);
966 tag = session_rules_table_rule_tag (srt, ri, 1);
967 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
975 vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
977 unix_shared_memory_queue_t *q = NULL;
981 q = vl_api_client_index_to_input_queue (mp->client_index);
986 session_table_foreach (st, ({
987 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
989 send_session_rules_table_details (&st->session_rules[tp],
990 st->active_fib_proto, tp,
991 st->is_local, st->appns_index, q,
998 static clib_error_t *
999 application_reaper_cb (u32 client_index)
1001 application_t *app = application_lookup (client_index);
1002 vnet_app_detach_args_t _a, *a = &_a;
1005 a->app_index = app->index;
1006 vnet_application_detach (a);
1011 VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
1013 #define vl_msg_name_crc_list
1014 #include <vnet/vnet_all_api_h.h>
1015 #undef vl_msg_name_crc_list
1018 setup_message_id_table (api_main_t * am)
1020 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1021 foreach_vl_msg_name_crc_session;
1026 * session_api_hookup
1027 * Add uri's API message handlers to the table.
1028 * vlib has alread mapped shared memory and
1029 * added the client registration handlers.
1030 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1032 static clib_error_t *
1033 session_api_hookup (vlib_main_t * vm)
1035 api_main_t *am = &api_main;
1038 vl_msg_api_set_handlers(VL_API_##N, #n, \
1039 vl_api_##n##_t_handler, \
1041 vl_api_##n##_t_endian, \
1042 vl_api_##n##_t_print, \
1043 sizeof(vl_api_##n##_t), 1);
1044 foreach_session_api_msg;
1048 * Messages which bounce off the data-plane to
1049 * an API client. Simply tells the message handling infra not
1050 * to free the message.
1052 * Bounced message handlers MUST NOT block the data plane
1054 am->message_bounce[VL_API_CONNECT_URI] = 1;
1055 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1058 * Set up the (msg_name, crc, message-id) table
1060 setup_message_id_table (am);
1065 VLIB_API_INIT_FUNCTION (session_api_hookup);
1068 * fd.io coding-style-patch-verification: ON
1071 * eval: (c-set-style "gnu")