blob: fb74e6bbff42609b37126e3d550f3defd68349ff [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
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>
18#include <vnet/session/application.h>
Florin Coras1c710452017-10-17 00:03:13 -070019#include <vnet/session/application_interface.h>
20#include <vnet/session/session_rules_table.h>
Florin Coras6c36f532017-11-03 18:32:34 -070021#include <vnet/session/session_table.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050022
23#include <vnet/vnet_msg_enum.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050024
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
39#include <vlibapi/api_helper_macros.h>
40
41#define foreach_session_api_msg \
42_(MAP_ANOTHER_SEGMENT_REPLY, map_another_segment_reply) \
Florin Coras6cf30ad2017-04-04 23:08:23 -070043_(APPLICATION_ATTACH, application_attach) \
44_(APPLICATION_DETACH, application_detach) \
Dave Barach68b0fb02017-02-28 15:15:56 -050045_(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) \
Florin Corascea194d2017-10-02 00:18:51 -070052_(BIND_SOCK, bind_sock) \
Dave Barach68b0fb02017-02-28 15:15:56 -050053_(UNBIND_SOCK, unbind_sock) \
54_(CONNECT_SOCK, connect_sock) \
Florin Corase04c2992017-03-01 08:17:34 -080055_(SESSION_ENABLE_DISABLE, session_enable_disable) \
Florin Corascea194d2017-10-02 00:18:51 -070056_(APP_NAMESPACE_ADD_DEL, app_namespace_add_del) \
Florin Coras1c710452017-10-17 00:03:13 -070057_(SESSION_RULE_ADD_DEL, session_rule_add_del) \
Florin Coras6c36f532017-11-03 18:32:34 -070058_(SESSION_RULES_DUMP, session_rules_dump) \
Florin Corase04c2992017-03-01 08:17:34 -080059
Dave Barach68b0fb02017-02-28 15:15:56 -050060static int
61send_add_segment_callback (u32 api_client_index, const u8 * segment_name,
62 u32 segment_size)
63{
64 vl_api_map_another_segment_t *mp;
65 unix_shared_memory_queue_t *q;
66
67 q = vl_api_client_index_to_input_queue (api_client_index);
68
69 if (!q)
70 return -1;
71
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);
78
79 vl_msg_api_send_shmem (q, (u8 *) & mp);
80
81 return 0;
82}
83
84static int
Florin Coras6cf30ad2017-04-04 23:08:23 -070085send_session_accept_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -050086{
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);
Florin Coras6cf30ad2017-04-04 23:08:23 -070090 transport_connection_t *tc;
91 transport_proto_vft_t *tp_vft;
92 stream_session_t *listener;
Dave Barach68b0fb02017-02-28 15:15:56 -050093
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);
96
97 if (!q)
98 return -1;
99
100 mp = vl_msg_api_alloc (sizeof (*mp));
Florin Coras6cf30ad2017-04-04 23:08:23 -0700101 memset (mp, 0, sizeof (*mp));
102
Dave Barach68b0fb02017-02-28 15:15:56 -0500103 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
Florin Corasa5464812017-04-19 13:00:05 -0700104 mp->context = server->index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700105 listener = listen_session_get (s->session_type, s->listener_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700106 tp_vft = transport_protocol_get_vft (s->session_type);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700107 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
108 mp->listener_handle = listen_session_get_handle (listener);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700109 mp->handle = session_handle (s);
Damjan Marion7bee80c2017-04-26 15:32:12 +0200110 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);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700113 mp->port = tc->rmt_port;
114 mp->is_ip4 = tc->is_ip4;
115 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
Dave Barach68b0fb02017-02-28 15:15:56 -0500116 vl_msg_api_send_shmem (q, (u8 *) & mp);
117
118 return 0;
119}
120
121static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700122send_session_disconnect_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500123{
124 vl_api_disconnect_session_t *mp;
125 unix_shared_memory_queue_t *q;
126 application_t *app = application_get (s->app_index);
127
128 q = vl_api_client_index_to_input_queue (app->api_client_index);
129
130 if (!q)
131 return;
132
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);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700136 mp->handle = session_handle (s);
Dave Barach68b0fb02017-02-28 15:15:56 -0500137 vl_msg_api_send_shmem (q, (u8 *) & mp);
138}
139
Florin Corasd79b41e2017-03-04 05:37:52 -0800140static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700141send_session_reset_callback (stream_session_t * s)
Florin Corasd79b41e2017-03-04 05:37:52 -0800142{
143 vl_api_reset_session_t *mp;
144 unix_shared_memory_queue_t *q;
145 application_t *app = application_get (s->app_index);
146
147 q = vl_api_client_index_to_input_queue (app->api_client_index);
148
149 if (!q)
150 return;
151
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);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700155 mp->handle = session_handle (s);
Florin Corasd79b41e2017-03-04 05:37:52 -0800156 vl_msg_api_send_shmem (q, (u8 *) & mp);
157}
158
Dave Barach0194f1a2017-05-15 10:11:39 -0400159int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700160send_session_connected_callback (u32 app_index, u32 api_context,
161 stream_session_t * s, u8 is_fail)
Dave Barach68b0fb02017-02-28 15:15:56 -0500162{
Dave Wallace33e002b2017-09-06 01:20:02 -0400163 vl_api_connect_session_reply_t *mp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500164 unix_shared_memory_queue_t *q;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700165 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500166 unix_shared_memory_queue_t *vpp_queue;
Florin Corasade70e42017-10-14 18:56:41 -0700167 transport_connection_t *tc;
Dave Barach68b0fb02017-02-28 15:15:56 -0500168
Florin Coras6cf30ad2017-04-04 23:08:23 -0700169 app = application_get (app_index);
Dave Barach68b0fb02017-02-28 15:15:56 -0500170 q = vl_api_client_index_to_input_queue (app->api_client_index);
171
172 if (!q)
173 return -1;
174
175 mp = vl_msg_api_alloc (sizeof (*mp));
Dave Wallace33e002b2017-09-06 01:20:02 -0400176 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700177 mp->context = api_context;
Dave Wallace965fec92017-10-17 16:19:41 -0400178
179 if (is_fail)
180 goto done;
181
182 tc = session_get_transport (s);
183 if (!tc)
Dave Barach68b0fb02017-02-28 15:15:56 -0500184 {
Dave Wallace965fec92017-10-17 16:19:41 -0400185 is_fail = 1;
186 goto done;
Florin Corase04c2992017-03-01 08:17:34 -0800187 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500188
Dave Wallace965fec92017-10-17 16:19:41 -0400189 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;
197
198done:
199 mp->retval = is_fail ?
200 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500201 vl_msg_api_send_shmem (q, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500202 return 0;
203}
204
205/**
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
209 */
210static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700211redirect_connect_callback (u32 server_api_client_index, void *mp_arg)
Dave Barach68b0fb02017-02-28 15:15:56 -0500212{
Florin Corascea194d2017-10-02 00:18:51 -0700213 vl_api_connect_sock_t *mp = mp_arg;
Dave Barach68b0fb02017-02-28 15:15:56 -0500214 unix_shared_memory_queue_t *server_q, *client_q;
Florin Corasad0c77f2017-11-09 18:00:15 -0800215 segment_manager_properties_t *props;
Dave Barach68b0fb02017-02-28 15:15:56 -0500216 vlib_main_t *vm = vlib_get_main ();
217 f64 timeout = vlib_time_now (vm) + 0.5;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700218 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500219 int rv = 0;
220
221 server_q = vl_api_client_index_to_input_queue (server_api_client_index);
222
223 if (!server_q)
224 {
225 rv = VNET_API_ERROR_INVALID_VALUE;
226 goto out;
227 }
228
229 client_q = vl_api_client_index_to_input_queue (mp->client_index);
230 if (!client_q)
231 {
232 rv = VNET_API_ERROR_INVALID_VALUE_2;
233 goto out;
234 }
235
236 /* Tell the server the client's API queue address, so it can reply */
Damjan Marion7bee80c2017-04-26 15:32:12 +0200237 mp->client_queue_address = pointer_to_uword (client_q);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700238 app = application_lookup (mp->client_index);
Florin Coras82b13a82017-04-25 11:58:06 -0700239 if (!app)
240 {
241 clib_warning ("no client application");
242 return -1;
243 }
244
Florin Corasad0c77f2017-11-09 18:00:15 -0800245 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;
Dave Barach68b0fb02017-02-28 15:15:56 -0500248
249 /*
250 * Bounce message handlers MUST NOT block the data-plane.
251 * Spin waiting for the queue lock, but
252 */
253
254 while (vlib_time_now (vm) < timeout)
255 {
256 rv =
257 unix_shared_memory_queue_add (server_q, (u8 *) & mp, 1 /*nowait */ );
258 switch (rv)
259 {
260 /* correctly enqueued */
261 case 0:
Florin Corascea194d2017-10-02 00:18:51 -0700262 return VNET_API_ERROR_SESSION_REDIRECT;
Dave Barach68b0fb02017-02-28 15:15:56 -0500263
264 /* continue spinning, wait for pthread_mutex_trylock to work */
265 case -1:
266 continue;
267
268 /* queue stuffed, drop the msg */
269 case -2:
270 rv = VNET_API_ERROR_QUEUE_FULL;
271 goto out;
272 }
273 }
274out:
275 /* Dispose of the message */
276 vl_msg_api_free (mp);
277 return rv;
278}
279
Florin Corascea194d2017-10-02 00:18:51 -0700280static session_cb_vft_t session_cb_vft = {
Dave Barach68b0fb02017-02-28 15:15:56 -0500281 .session_accept_callback = send_session_accept_callback,
282 .session_disconnect_callback = send_session_disconnect_callback,
283 .session_connected_callback = send_session_connected_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800284 .session_reset_callback = send_session_reset_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500285 .add_segment_callback = send_add_segment_callback,
286 .redirect_connect_callback = redirect_connect_callback
287};
288
Dave Barach68b0fb02017-02-28 15:15:56 -0500289static void
Florin Corase04c2992017-03-01 08:17:34 -0800290vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
291{
292 vl_api_session_enable_disable_reply_t *rmp;
293 vlib_main_t *vm = vlib_get_main ();
294 int rv = 0;
295
296 vnet_session_enable_disable (vm, mp->is_enable);
297 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
298}
299
300static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700301vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
Dave Barach68b0fb02017-02-28 15:15:56 -0500302{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700303 vl_api_application_attach_reply_t *rmp;
304 vnet_app_attach_args_t _a, *a = &_a;
Florin Corascea194d2017-10-02 00:18:51 -0700305 clib_error_t *error = 0;
306 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500307
Florin Coras6cf30ad2017-04-04 23:08:23 -0700308 if (session_manager_is_enabled () == 0)
309 {
310 rv = VNET_API_ERROR_FEATURE_DISABLED;
311 goto done;
312 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500313
Florin Coras6cf30ad2017-04-04 23:08:23 -0700314 STATIC_ASSERT (sizeof (u64) * SESSION_OPTIONS_N_OPTIONS <=
315 sizeof (mp->options),
316 "Out of options, fix api message definition");
Dave Barach68b0fb02017-02-28 15:15:56 -0500317
318 memset (a, 0, sizeof (*a));
Dave Barach68b0fb02017-02-28 15:15:56 -0500319 a->api_client_index = mp->client_index;
320 a->options = mp->options;
Florin Corascea194d2017-10-02 00:18:51 -0700321 a->session_cb_vft = &session_cb_vft;
Dave Barach68b0fb02017-02-28 15:15:56 -0500322
Florin Corascea194d2017-10-02 00:18:51 -0700323 if (mp->namespace_id_len > 64)
324 {
325 rv = VNET_API_ERROR_INVALID_VALUE;
326 goto done;
327 }
328
329 if (mp->namespace_id_len)
330 {
Dave Wallace8af20542017-10-26 03:29:30 -0400331 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
Florin Corascea194d2017-10-02 00:18:51 -0700332 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
333 }
334
335 if ((error = vnet_application_attach (a)))
336 {
337 rv = clib_error_get_code (error);
338 clib_error_report (error);
339 }
340 vec_free (a->namespace_id);
Dave Barach68b0fb02017-02-28 15:15:56 -0500341
Florin Coras6cf30ad2017-04-04 23:08:23 -0700342done:
Florin Corasa5464812017-04-19 13:00:05 -0700343
Dave Barach68b0fb02017-02-28 15:15:56 -0500344 /* *INDENT-OFF* */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700345 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
Dave Barach68b0fb02017-02-28 15:15:56 -0500346 if (!rv)
347 {
348 rmp->segment_name_length = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700349 rmp->segment_size = a->segment_size;
350 if (a->segment_name_length)
Dave Barach68b0fb02017-02-28 15:15:56 -0500351 {
Florin Coras6cf30ad2017-04-04 23:08:23 -0700352 memcpy (rmp->segment_name, a->segment_name,
353 a->segment_name_length);
354 rmp->segment_name_length = a->segment_name_length;
Dave Barach68b0fb02017-02-28 15:15:56 -0500355 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700356 rmp->app_event_queue_address = a->app_event_queue_address;
Dave Barach68b0fb02017-02-28 15:15:56 -0500357 }
358 }));
359 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500360}
361
362static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700363vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
364{
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;
368 application_t *app;
369
370 if (session_manager_is_enabled () == 0)
371 {
372 rv = VNET_API_ERROR_FEATURE_DISABLED;
373 goto done;
374 }
375
376 app = application_lookup (mp->client_index);
377 if (app)
378 {
379 a->app_index = app->index;
380 rv = vnet_application_detach (a);
381 }
382
383done:
384 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
385}
386
387static void
388vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
389{
390 vl_api_bind_uri_reply_t *rmp;
391 vnet_bind_args_t _a, *a = &_a;
392 application_t *app;
393 int rv;
394
395 if (session_manager_is_enabled () == 0)
396 {
397 rv = VNET_API_ERROR_FEATURE_DISABLED;
398 goto done;
399 }
400
401 app = application_lookup (mp->client_index);
402 if (app)
403 {
404 memset (a, 0, sizeof (*a));
405 a->uri = (char *) mp->uri;
406 a->app_index = app->index;
407 rv = vnet_bind_uri (a);
408 }
409 else
410 {
411 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
412 }
413
414done:
415 REPLY_MACRO (VL_API_BIND_URI_REPLY);
416}
417
418static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500419vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
420{
421 vl_api_unbind_uri_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700422 application_t *app;
423 vnet_unbind_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -0500424 int rv;
425
Florin Coras6cf30ad2017-04-04 23:08:23 -0700426 if (session_manager_is_enabled () == 0)
427 {
428 rv = VNET_API_ERROR_FEATURE_DISABLED;
429 goto done;
430 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500431
Florin Coras6cf30ad2017-04-04 23:08:23 -0700432 app = application_lookup (mp->client_index);
433 if (app)
434 {
435 a->uri = (char *) mp->uri;
436 a->app_index = app->index;
437 rv = vnet_unbind_uri (a);
438 }
439 else
440 {
441 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
442 }
443
444done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500445 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
446}
447
Florin Corasf03a59a2017-06-09 21:07:32 -0700448static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500449vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
450{
Dave Wallace33e002b2017-09-06 01:20:02 -0400451 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500452 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700453 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700454 clib_error_t *error = 0;
455 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500456
Florin Coras6cf30ad2017-04-04 23:08:23 -0700457 if (session_manager_is_enabled () == 0)
458 {
459 rv = VNET_API_ERROR_FEATURE_DISABLED;
460 goto done;
461 }
Florin Corase04c2992017-03-01 08:17:34 -0800462
Florin Coras6cf30ad2017-04-04 23:08:23 -0700463 app = application_lookup (mp->client_index);
464 if (app)
465 {
466 a->uri = (char *) mp->uri;
467 a->api_context = mp->context;
468 a->app_index = app->index;
469 a->mp = mp;
Florin Corascea194d2017-10-02 00:18:51 -0700470 if ((error = vnet_connect_uri (a)))
471 {
472 rv = clib_error_get_code (error);
473 if (rv != VNET_API_ERROR_SESSION_REDIRECT)
474 clib_error_report (error);
475 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700476 }
477 else
478 {
479 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
480 }
Florin Corase04c2992017-03-01 08:17:34 -0800481
Florin Coras3cbc04b2017-10-02 00:18:51 -0700482 /*
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.
486 */
Florin Corascea194d2017-10-02 00:18:51 -0700487 if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT)
Florin Corase04c2992017-03-01 08:17:34 -0800488 return;
489
Florin Coras6cf30ad2017-04-04 23:08:23 -0700490done:
Florin Corase04c2992017-03-01 08:17:34 -0800491 /* *INDENT-OFF* */
Dave Wallace33e002b2017-09-06 01:20:02 -0400492 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corase04c2992017-03-01 08:17:34 -0800493 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500494}
495
496static void
497vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
498{
499 vl_api_disconnect_session_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700500 vnet_disconnect_args_t _a, *a = &_a;
501 application_t *app;
502 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500503
Florin Coras6cf30ad2017-04-04 23:08:23 -0700504 if (session_manager_is_enabled () == 0)
505 {
506 rv = VNET_API_ERROR_FEATURE_DISABLED;
507 goto done;
508 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500509
Florin Coras6cf30ad2017-04-04 23:08:23 -0700510 app = application_lookup (mp->client_index);
511 if (app)
512 {
513 a->handle = mp->handle;
514 a->app_index = app->index;
515 rv = vnet_disconnect_session (a);
516 }
517 else
518 {
519 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
520 }
521
522done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500523 REPLY_MACRO (VL_API_DISCONNECT_SESSION_REPLY);
524}
525
526static void
527vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
528 mp)
529{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700530 vnet_disconnect_args_t _a, *a = &_a;
531 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500532
533 /* Client objected to disconnecting the session, log and continue */
534 if (mp->retval)
535 {
536 clib_warning ("client retval %d", mp->retval);
537 return;
538 }
539
540 /* Disconnect has been confirmed. Confirm close to transport */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700541 app = application_lookup (mp->client_index);
542 if (app)
543 {
544 a->handle = mp->handle;
545 a->app_index = app->index;
546 vnet_disconnect_session (a);
547 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500548}
549
550static void
551vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
552{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700553 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500554 stream_session_t *s;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700555 u32 index, thread_index;
Dave Barach68b0fb02017-02-28 15:15:56 -0500556
Florin Coras6cf30ad2017-04-04 23:08:23 -0700557 app = application_lookup (mp->client_index);
558 if (!app)
559 return;
560
Florin Corascea194d2017-10-02 00:18:51 -0700561 session_parse_handle (mp->handle, &index, &thread_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700562 s = session_get_if_valid (index, thread_index);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700563 if (s == 0 || app->index != s->app_index)
Dave Barach68b0fb02017-02-28 15:15:56 -0500564 {
565 clib_warning ("Invalid session!");
566 return;
567 }
568
569 /* Client objected to resetting the session, log and continue */
570 if (mp->retval)
571 {
572 clib_warning ("client retval %d", mp->retval);
573 return;
574 }
575
Dave Barach68b0fb02017-02-28 15:15:56 -0500576 /* 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);
579}
580
581static void
582vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
583{
584 stream_session_t *s;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700585 u32 session_index, thread_index;
Florin Corasa5464812017-04-19 13:00:05 -0700586 vnet_disconnect_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -0500587
Florin Corasa5464812017-04-19 13:00:05 -0700588 /* Server isn't interested, kill the session */
589 if (mp->retval)
Dave Barach68b0fb02017-02-28 15:15:56 -0500590 {
Florin Corasa5464812017-04-19 13:00:05 -0700591 a->app_index = mp->context;
592 a->handle = mp->handle;
593 vnet_disconnect_session (a);
Dave Barach68b0fb02017-02-28 15:15:56 -0500594 }
Florin Corasa5464812017-04-19 13:00:05 -0700595 else
596 {
Florin Corascea194d2017-10-02 00:18:51 -0700597 session_parse_handle (mp->handle, &session_index, &thread_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700598 s = session_get_if_valid (session_index, thread_index);
Florin Corasa5464812017-04-19 13:00:05 -0700599 if (!s)
600 {
601 clib_warning ("session doesn't exist");
602 return;
603 }
604 if (s->app_index != mp->context)
605 {
606 clib_warning ("app doesn't own session");
607 return;
608 }
Florin Corasa5464812017-04-19 13:00:05 -0700609 s->session_state = SESSION_STATE_READY;
610 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500611}
612
613static void
614vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
615 * mp)
616{
617 clib_warning ("not implemented");
618}
619
620static void
621vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
622{
623 vl_api_bind_sock_reply_t *rmp;
624 vnet_bind_args_t _a, *a = &_a;
Florin Corascea194d2017-10-02 00:18:51 -0700625 int rv = 0;
626 clib_error_t *error;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700627 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500628
Florin Coras6cf30ad2017-04-04 23:08:23 -0700629 if (session_manager_is_enabled () == 0)
630 {
631 rv = VNET_API_ERROR_FEATURE_DISABLED;
632 goto done;
633 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500634
Florin Coras6cf30ad2017-04-04 23:08:23 -0700635 app = application_lookup (mp->client_index);
636 if (app)
637 {
Dave Wallace33e002b2017-09-06 01:20:02 -0400638 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700639 memset (a, 0, sizeof (*a));
Florin Corascea194d2017-10-02 00:18:51 -0700640 a->sep.is_ip4 = mp->is_ip4;
641 a->sep.ip = *ip46;
642 a->sep.port = mp->port;
643 a->sep.fib_index = mp->vrf;
644 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
Florin Coras3cbc04b2017-10-02 00:18:51 -0700645 a->sep.transport_proto = mp->proto;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700646 a->app_index = app->index;
Dave Barach68b0fb02017-02-28 15:15:56 -0500647
Florin Corascea194d2017-10-02 00:18:51 -0700648 if ((error = vnet_bind (a)))
649 {
650 rv = clib_error_get_code (error);
651 clib_error_report (error);
652 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700653 }
654done:
Florin Corascea194d2017-10-02 00:18:51 -0700655 /* *INDENT-OFF* */
656 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
657 if (!rv)
658 rmp->handle = a->handle;
659 }));
660 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500661}
662
663static void
664vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
665{
666 vl_api_unbind_sock_reply_t *rmp;
667 vnet_unbind_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700668 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700669 clib_error_t *error;
670 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500671
Florin Coras6cf30ad2017-04-04 23:08:23 -0700672 if (session_manager_is_enabled () == 0)
673 {
674 rv = VNET_API_ERROR_FEATURE_DISABLED;
675 goto done;
676 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500677
Florin Coras6cf30ad2017-04-04 23:08:23 -0700678 app = application_lookup (mp->client_index);
679 if (app)
680 {
Florin Corasef24d422017-11-09 10:05:42 -0800681 a->app_index = app->index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700682 a->handle = mp->handle;
Florin Corascea194d2017-10-02 00:18:51 -0700683 if ((error = vnet_unbind (a)))
684 {
685 rv = clib_error_get_code (error);
686 clib_error_report (error);
687 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700688 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500689
Florin Coras6cf30ad2017-04-04 23:08:23 -0700690done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500691 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
692}
693
694static void
695vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
696{
Dave Wallace33e002b2017-09-06 01:20:02 -0400697 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500698 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700699 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700700 clib_error_t *error = 0;
701 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500702
Florin Coras6cf30ad2017-04-04 23:08:23 -0700703 if (session_manager_is_enabled () == 0)
704 {
705 rv = VNET_API_ERROR_FEATURE_DISABLED;
706 goto done;
707 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500708
Florin Coras6cf30ad2017-04-04 23:08:23 -0700709 app = application_lookup (mp->client_index);
710 if (app)
711 {
Dave Wallaceb2d5ff32017-06-14 12:38:28 -0400712 unix_shared_memory_queue_t *client_q;
Dave Wallace33e002b2017-09-06 01:20:02 -0400713 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
Dave Wallaceb2d5ff32017-06-14 12:38:28 -0400714
715 client_q = vl_api_client_index_to_input_queue (mp->client_index);
716 mp->client_queue_address = pointer_to_uword (client_q);
Florin Corascea194d2017-10-02 00:18:51 -0700717 a->sep.is_ip4 = mp->is_ip4;
718 a->sep.ip = *ip46;
719 a->sep.port = mp->port;
720 a->sep.transport_proto = mp->proto;
721 a->sep.fib_index = mp->vrf;
722 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700723 a->api_context = mp->context;
724 a->app_index = app->index;
725 a->mp = mp;
Florin Corascea194d2017-10-02 00:18:51 -0700726 if ((error = vnet_connect (a)))
727 {
728 rv = clib_error_get_code (error);
729 if (rv != VNET_API_ERROR_SESSION_REDIRECT)
730 clib_error_report (error);
731 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700732 }
733 else
734 {
735 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
736 }
Florin Corase04c2992017-03-01 08:17:34 -0800737
Florin Corascea194d2017-10-02 00:18:51 -0700738 if (rv == 0 || rv == VNET_API_ERROR_SESSION_REDIRECT)
Florin Corase04c2992017-03-01 08:17:34 -0800739 return;
740
741 /* Got some error, relay it */
742
Florin Coras6cf30ad2017-04-04 23:08:23 -0700743done:
Dave Wallace33e002b2017-09-06 01:20:02 -0400744 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Dave Barach68b0fb02017-02-28 15:15:56 -0500745}
746
Florin Corascea194d2017-10-02 00:18:51 -0700747static void
748vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
749{
750 vl_api_app_namespace_add_del_reply_t *rmp;
751 u8 *ns_id = 0;
752 clib_error_t *error = 0;
753 int rv = 0;
754 if (!session_manager_is_enabled ())
755 {
756 rv = VNET_API_ERROR_FEATURE_DISABLED;
757 goto done;
758 }
759
760 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
761 {
762 rv = VNET_API_ERROR_INVALID_VALUE;
763 goto done;
764 }
765
766 vec_validate (ns_id, mp->namespace_id_len - 1);
767 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
768 vnet_app_namespace_add_del_args_t args = {
769 .ns_id = ns_id,
Florin Coras9a9adb22017-10-26 08:16:59 -0700770 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -0700771 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
772 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
773 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
774 .is_add = 1
775 };
776 error = vnet_app_namespace_add_del (&args);
777 if (error)
778 {
779 rv = clib_error_get_code (error);
780 clib_error_report (error);
781 }
782 vec_free (ns_id);
783done:
784 REPLY_MACRO (VL_API_APP_NAMESPACE_ADD_DEL_REPLY);
785}
786
Florin Coras1c710452017-10-17 00:03:13 -0700787static void
788vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
789{
790 vl_api_session_rule_add_del_reply_t *rmp;
791 session_rule_add_del_args_t args;
792 session_rule_table_add_del_args_t *table_args = &args.table_args;
793 clib_error_t *error;
794 u8 fib_proto;
795 int rv = 0;
796
Florin Corasc97a7392017-11-05 23:07:07 -0800797 memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -0700798 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
799
800 table_args->lcl.fp_len = mp->lcl_plen;
801 table_args->lcl.fp_proto = fib_proto;
802 table_args->rmt.fp_len = mp->rmt_plen;
803 table_args->rmt.fp_proto = fib_proto;
804 table_args->lcl_port = clib_net_to_host_u16 (mp->lcl_port);
805 table_args->rmt_port = clib_net_to_host_u16 (mp->rmt_port);
806 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
807 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -0800808 mp->tag[sizeof (mp->tag) - 1] = 0;
809 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700810 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
811 args.scope = mp->scope;
812
813 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
814 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
815 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
816 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
817 error = vnet_session_rule_add_del (&args);
818 if (error)
819 {
820 rv = clib_error_get_code (error);
821 clib_error_report (error);
822 }
Florin Corasc97a7392017-11-05 23:07:07 -0800823 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700824 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
825}
826
Florin Coras6c36f532017-11-03 18:32:34 -0700827static void
828send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -0800829 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c36f532017-11-03 18:32:34 -0700830 unix_shared_memory_queue_t * q, u32 context)
831{
832 vl_api_session_rules_details_t *rmp = 0;
833 session_mask_or_match_4_t *match =
834 (session_mask_or_match_4_t *) & rule->match;
835 session_mask_or_match_4_t *mask =
836 (session_mask_or_match_4_t *) & rule->mask;
837
838 rmp = vl_msg_api_alloc (sizeof (*rmp));
839 memset (rmp, 0, sizeof (*rmp));
840 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
841 rmp->context = context;
842
843 rmp->is_ip4 = 1;
844 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
845 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
846 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
847 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
848 rmp->lcl_port = clib_host_to_net_u16 (match->lcl_port);
849 rmp->rmt_port = clib_host_to_net_u16 (match->rmt_port);
850 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
851 rmp->scope =
852 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
853 rmp->transport_proto = transport_proto;
854 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800855 if (tag)
856 {
857 clib_memcpy (rmp->tag, tag, vec_len (tag));
858 rmp->tag[vec_len (tag)] = 0;
859 }
Florin Coras6c36f532017-11-03 18:32:34 -0700860
861 vl_msg_api_send_shmem (q, (u8 *) & rmp);
862}
863
864static void
Florin Corasc97a7392017-11-05 23:07:07 -0800865send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
866 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c36f532017-11-03 18:32:34 -0700867 unix_shared_memory_queue_t * q, u32 context)
868{
869 vl_api_session_rules_details_t *rmp = 0;
870 session_mask_or_match_6_t *match =
871 (session_mask_or_match_6_t *) & rule->match;
872 session_mask_or_match_6_t *mask =
873 (session_mask_or_match_6_t *) & rule->mask;
874
875 rmp = vl_msg_api_alloc (sizeof (*rmp));
876 memset (rmp, 0, sizeof (*rmp));
877 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
878 rmp->context = context;
879
880 rmp->is_ip4 = 0;
881 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
882 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
883 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
884 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
885 rmp->lcl_port = clib_host_to_net_u16 (match->lcl_port);
886 rmp->rmt_port = clib_host_to_net_u16 (match->rmt_port);
887 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800888 rmp->scope =
889 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
Florin Coras6c36f532017-11-03 18:32:34 -0700890 rmp->transport_proto = transport_proto;
891 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800892 if (tag)
893 {
894 clib_memcpy (rmp->tag, tag, vec_len (tag));
895 rmp->tag[vec_len (tag)] = 0;
896 }
Florin Coras6c36f532017-11-03 18:32:34 -0700897
898 vl_msg_api_send_shmem (q, (u8 *) & rmp);
899}
900
901static void
902send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -0800903 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c36f532017-11-03 18:32:34 -0700904 unix_shared_memory_queue_t * q, u32 context)
905{
906 mma_rule_16_t *rule16;
907 mma_rule_40_t *rule40;
908 mma_rules_table_16_t *srt16;
909 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -0800910 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -0700911
Florin Corasc97a7392017-11-05 23:07:07 -0800912 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -0700913 {
Florin Corasc97a7392017-11-05 23:07:07 -0800914 u8 *tag = 0;
915 /* *INDENT-OFF* */
916 srt16 = &srt->session_rules_tables_16;
917 pool_foreach (rule16, srt16->rules, ({
918 ri = mma_rules_table_rule_index_16 (srt16, rule16);
919 tag = session_rules_table_rule_tag (srt, ri, 1);
920 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
921 q, context);
922 }));
923 /* *INDENT-ON* */
924 }
925 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
926 {
927 u8 *tag = 0;
928 /* *INDENT-OFF* */
929 srt40 = &srt->session_rules_tables_40;
930 pool_foreach (rule40, srt40->rules, ({
931 ri = mma_rules_table_rule_index_40 (srt40, rule40);
932 tag = session_rules_table_rule_tag (srt, ri, 1);
933 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
934 q, context);
935 }));
936 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -0700937 }
938}
939
940static void
941vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
942{
943 unix_shared_memory_queue_t *q = NULL;
944 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -0800945 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -0700946
947 q = vl_api_client_index_to_input_queue (mp->client_index);
948 if (q == 0)
949 return;
950
951 /* *INDENT-OFF* */
952 session_table_foreach (st, ({
Florin Corasc97a7392017-11-05 23:07:07 -0800953 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
954 {
955 send_session_rules_table_details (&st->session_rules[tp],
956 st->active_fib_proto, tp,
957 st->is_local, st->appns_index, q,
958 mp->context);
959 }
Florin Coras6c36f532017-11-03 18:32:34 -0700960 }));
961 /* *INDENT-ON* */
962}
963
Florin Coras6cf30ad2017-04-04 23:08:23 -0700964static clib_error_t *
965application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -0500966{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700967 application_t *app = application_lookup (client_index);
968 vnet_app_detach_args_t _a, *a = &_a;
969 if (app)
970 {
971 a->app_index = app->index;
972 vnet_application_detach (a);
973 }
974 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500975}
976
Florin Coras6cf30ad2017-04-04 23:08:23 -0700977VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -0500978
979#define vl_msg_name_crc_list
980#include <vnet/vnet_all_api_h.h>
981#undef vl_msg_name_crc_list
982
983static void
984setup_message_id_table (api_main_t * am)
985{
986#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
987 foreach_vl_msg_name_crc_session;
988#undef _
989}
990
991/*
992 * session_api_hookup
993 * Add uri's API message handlers to the table.
994 * vlib has alread mapped shared memory and
995 * added the client registration handlers.
996 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
997 */
998static clib_error_t *
999session_api_hookup (vlib_main_t * vm)
1000{
1001 api_main_t *am = &api_main;
1002
1003#define _(N,n) \
1004 vl_msg_api_set_handlers(VL_API_##N, #n, \
1005 vl_api_##n##_t_handler, \
1006 vl_noop_handler, \
1007 vl_api_##n##_t_endian, \
1008 vl_api_##n##_t_print, \
1009 sizeof(vl_api_##n##_t), 1);
1010 foreach_session_api_msg;
1011#undef _
1012
1013 /*
1014 * Messages which bounce off the data-plane to
1015 * an API client. Simply tells the message handling infra not
1016 * to free the message.
1017 *
1018 * Bounced message handlers MUST NOT block the data plane
1019 */
1020 am->message_bounce[VL_API_CONNECT_URI] = 1;
1021 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1022
1023 /*
1024 * Set up the (msg_name, crc, message-id) table
1025 */
1026 setup_message_id_table (am);
1027
1028 return 0;
1029}
1030
1031VLIB_API_INIT_FUNCTION (session_api_hookup);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001032
Dave Barach68b0fb02017-02-28 15:15:56 -05001033/*
1034 * fd.io coding-style-patch-verification: ON
1035 *
1036 * Local Variables:
1037 * eval: (c-set-style "gnu")
1038 * End:
1039 */