blob: 7de77ddfd34f0775cf12bac8cf4de6f6b99080b9 [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;
Florin Corascea194d2017-10-02 00:18:51 -0700751 clib_error_t *error = 0;
Florin Coras6e8c6672017-11-10 09:03:54 -0800752 u32 appns_index = 0;
753 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -0700754 int rv = 0;
755 if (!session_manager_is_enabled ())
756 {
757 rv = VNET_API_ERROR_FEATURE_DISABLED;
758 goto done;
759 }
760
761 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
762 {
763 rv = VNET_API_ERROR_INVALID_VALUE;
764 goto done;
765 }
766
767 vec_validate (ns_id, mp->namespace_id_len - 1);
768 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
769 vnet_app_namespace_add_del_args_t args = {
770 .ns_id = ns_id,
Florin Coras9a9adb22017-10-26 08:16:59 -0700771 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -0700772 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
773 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
774 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
775 .is_add = 1
776 };
777 error = vnet_app_namespace_add_del (&args);
778 if (error)
779 {
780 rv = clib_error_get_code (error);
781 clib_error_report (error);
782 }
Florin Coras6e8c6672017-11-10 09:03:54 -0800783 else
784 {
785 appns_index = app_namespace_index_from_id (ns_id);
786 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
787 {
788 clib_warning ("app ns lookup failed");
789 rv = VNET_API_ERROR_UNSPECIFIED;
790 }
791 }
Florin Corascea194d2017-10-02 00:18:51 -0700792 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -0800793
794 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -0700795done:
Florin Coras6e8c6672017-11-10 09:03:54 -0800796 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
797 if (!rv)
798 rmp->appns_index = clib_host_to_net_u32 (appns_index);
799 }));
800 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -0700801}
802
Florin Coras1c710452017-10-17 00:03:13 -0700803static void
804vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
805{
806 vl_api_session_rule_add_del_reply_t *rmp;
807 session_rule_add_del_args_t args;
808 session_rule_table_add_del_args_t *table_args = &args.table_args;
809 clib_error_t *error;
810 u8 fib_proto;
811 int rv = 0;
812
Florin Corasc97a7392017-11-05 23:07:07 -0800813 memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -0700814 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
815
816 table_args->lcl.fp_len = mp->lcl_plen;
817 table_args->lcl.fp_proto = fib_proto;
818 table_args->rmt.fp_len = mp->rmt_plen;
819 table_args->rmt.fp_proto = fib_proto;
820 table_args->lcl_port = clib_net_to_host_u16 (mp->lcl_port);
821 table_args->rmt_port = clib_net_to_host_u16 (mp->rmt_port);
822 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
823 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -0800824 mp->tag[sizeof (mp->tag) - 1] = 0;
825 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700826 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
827 args.scope = mp->scope;
828
829 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
830 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
831 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
832 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
833 error = vnet_session_rule_add_del (&args);
834 if (error)
835 {
836 rv = clib_error_get_code (error);
837 clib_error_report (error);
838 }
Florin Corasc97a7392017-11-05 23:07:07 -0800839 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700840 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
841}
842
Florin Coras6c36f532017-11-03 18:32:34 -0700843static void
844send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -0800845 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c36f532017-11-03 18:32:34 -0700846 unix_shared_memory_queue_t * q, u32 context)
847{
848 vl_api_session_rules_details_t *rmp = 0;
849 session_mask_or_match_4_t *match =
850 (session_mask_or_match_4_t *) & rule->match;
851 session_mask_or_match_4_t *mask =
852 (session_mask_or_match_4_t *) & rule->mask;
853
854 rmp = vl_msg_api_alloc (sizeof (*rmp));
855 memset (rmp, 0, sizeof (*rmp));
856 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
857 rmp->context = context;
858
859 rmp->is_ip4 = 1;
860 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
861 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
862 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
863 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
864 rmp->lcl_port = clib_host_to_net_u16 (match->lcl_port);
865 rmp->rmt_port = clib_host_to_net_u16 (match->rmt_port);
866 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
867 rmp->scope =
868 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
869 rmp->transport_proto = transport_proto;
870 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800871 if (tag)
872 {
873 clib_memcpy (rmp->tag, tag, vec_len (tag));
874 rmp->tag[vec_len (tag)] = 0;
875 }
Florin Coras6c36f532017-11-03 18:32:34 -0700876
877 vl_msg_api_send_shmem (q, (u8 *) & rmp);
878}
879
880static void
Florin Corasc97a7392017-11-05 23:07:07 -0800881send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
882 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c36f532017-11-03 18:32:34 -0700883 unix_shared_memory_queue_t * q, u32 context)
884{
885 vl_api_session_rules_details_t *rmp = 0;
886 session_mask_or_match_6_t *match =
887 (session_mask_or_match_6_t *) & rule->match;
888 session_mask_or_match_6_t *mask =
889 (session_mask_or_match_6_t *) & rule->mask;
890
891 rmp = vl_msg_api_alloc (sizeof (*rmp));
892 memset (rmp, 0, sizeof (*rmp));
893 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
894 rmp->context = context;
895
896 rmp->is_ip4 = 0;
897 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
898 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
899 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
900 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
901 rmp->lcl_port = clib_host_to_net_u16 (match->lcl_port);
902 rmp->rmt_port = clib_host_to_net_u16 (match->rmt_port);
903 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800904 rmp->scope =
905 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
Florin Coras6c36f532017-11-03 18:32:34 -0700906 rmp->transport_proto = transport_proto;
907 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800908 if (tag)
909 {
910 clib_memcpy (rmp->tag, tag, vec_len (tag));
911 rmp->tag[vec_len (tag)] = 0;
912 }
Florin Coras6c36f532017-11-03 18:32:34 -0700913
914 vl_msg_api_send_shmem (q, (u8 *) & rmp);
915}
916
917static void
918send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -0800919 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c36f532017-11-03 18:32:34 -0700920 unix_shared_memory_queue_t * q, u32 context)
921{
922 mma_rule_16_t *rule16;
923 mma_rule_40_t *rule40;
924 mma_rules_table_16_t *srt16;
925 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -0800926 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -0700927
Florin Corasc97a7392017-11-05 23:07:07 -0800928 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -0700929 {
Florin Corasc97a7392017-11-05 23:07:07 -0800930 u8 *tag = 0;
931 /* *INDENT-OFF* */
932 srt16 = &srt->session_rules_tables_16;
933 pool_foreach (rule16, srt16->rules, ({
934 ri = mma_rules_table_rule_index_16 (srt16, rule16);
935 tag = session_rules_table_rule_tag (srt, ri, 1);
936 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
937 q, context);
938 }));
939 /* *INDENT-ON* */
940 }
941 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
942 {
943 u8 *tag = 0;
944 /* *INDENT-OFF* */
945 srt40 = &srt->session_rules_tables_40;
946 pool_foreach (rule40, srt40->rules, ({
947 ri = mma_rules_table_rule_index_40 (srt40, rule40);
948 tag = session_rules_table_rule_tag (srt, ri, 1);
949 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
950 q, context);
951 }));
952 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -0700953 }
954}
955
956static void
957vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
958{
959 unix_shared_memory_queue_t *q = NULL;
960 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -0800961 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -0700962
963 q = vl_api_client_index_to_input_queue (mp->client_index);
964 if (q == 0)
965 return;
966
967 /* *INDENT-OFF* */
968 session_table_foreach (st, ({
Florin Corasc97a7392017-11-05 23:07:07 -0800969 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
970 {
971 send_session_rules_table_details (&st->session_rules[tp],
972 st->active_fib_proto, tp,
973 st->is_local, st->appns_index, q,
974 mp->context);
975 }
Florin Coras6c36f532017-11-03 18:32:34 -0700976 }));
977 /* *INDENT-ON* */
978}
979
Florin Coras6cf30ad2017-04-04 23:08:23 -0700980static clib_error_t *
981application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -0500982{
Florin Coras6cf30ad2017-04-04 23:08:23 -0700983 application_t *app = application_lookup (client_index);
984 vnet_app_detach_args_t _a, *a = &_a;
985 if (app)
986 {
987 a->app_index = app->index;
988 vnet_application_detach (a);
989 }
990 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500991}
992
Florin Coras6cf30ad2017-04-04 23:08:23 -0700993VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -0500994
995#define vl_msg_name_crc_list
996#include <vnet/vnet_all_api_h.h>
997#undef vl_msg_name_crc_list
998
999static void
1000setup_message_id_table (api_main_t * am)
1001{
1002#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1003 foreach_vl_msg_name_crc_session;
1004#undef _
1005}
1006
1007/*
1008 * session_api_hookup
1009 * Add uri's API message handlers to the table.
1010 * vlib has alread mapped shared memory and
1011 * added the client registration handlers.
1012 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1013 */
1014static clib_error_t *
1015session_api_hookup (vlib_main_t * vm)
1016{
1017 api_main_t *am = &api_main;
1018
1019#define _(N,n) \
1020 vl_msg_api_set_handlers(VL_API_##N, #n, \
1021 vl_api_##n##_t_handler, \
1022 vl_noop_handler, \
1023 vl_api_##n##_t_endian, \
1024 vl_api_##n##_t_print, \
1025 sizeof(vl_api_##n##_t), 1);
1026 foreach_session_api_msg;
1027#undef _
1028
1029 /*
1030 * Messages which bounce off the data-plane to
1031 * an API client. Simply tells the message handling infra not
1032 * to free the message.
1033 *
1034 * Bounced message handlers MUST NOT block the data plane
1035 */
1036 am->message_bounce[VL_API_CONNECT_URI] = 1;
1037 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1038
1039 /*
1040 * Set up the (msg_name, crc, message-id) table
1041 */
1042 setup_message_id_table (am);
1043
1044 return 0;
1045}
1046
1047VLIB_API_INIT_FUNCTION (session_api_hookup);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001048
Dave Barach68b0fb02017-02-28 15:15:56 -05001049/*
1050 * fd.io coding-style-patch-verification: ON
1051 *
1052 * Local Variables:
1053 * eval: (c-set-style "gnu")
1054 * End:
1055 */