blob: 565938653816c9042967e9f5666c34e40e189ed1 [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 Coras371ca502018-02-21 12:07:41 -080059_(APPLICATION_TLS_CERT_ADD, application_tls_cert_add) \
60_(APPLICATION_TLS_KEY_ADD, application_tls_key_add) \
Florin Coras15531972018-08-12 23:50:53 -070061_(APP_WORKER_ADD_DEL, app_worker_add_del) \
Florin Corase04c2992017-03-01 08:17:34 -080062
Dave Barach68b0fb02017-02-28 15:15:56 -050063static int
Florin Coras99368312018-08-02 10:45:44 -070064session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
Florin Corasb384b542018-01-15 01:08:33 -080065{
66 clib_error_t *error;
67 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
68 {
69 clib_warning ("can't send memfd fd");
70 return -1;
71 }
Florin Coras99368312018-08-02 10:45:44 -070072 error = vl_api_send_fd_msg (reg, fds, n_fds);
Florin Corasb384b542018-01-15 01:08:33 -080073 if (error)
74 {
75 clib_error_report (error);
76 return -1;
77 }
78 return 0;
79}
80
81static int
82send_add_segment_callback (u32 api_client_index, const ssvm_private_t * sp)
Dave Barach68b0fb02017-02-28 15:15:56 -050083{
Florin Coras99368312018-08-02 10:45:44 -070084 int fds[SESSION_N_FD_TYPE], n_fds = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -050085 vl_api_map_another_segment_t *mp;
Florin Corasb384b542018-01-15 01:08:33 -080086 vl_api_registration_t *reg;
Florin Coras99368312018-08-02 10:45:44 -070087 u8 fd_flags = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -050088
Florin Corasb384b542018-01-15 01:08:33 -080089 reg = vl_mem_api_client_index_to_registration (api_client_index);
90 if (!reg)
91 {
92 clib_warning ("no registration: %u", api_client_index);
93 return -1;
94 }
Dave Barach68b0fb02017-02-28 15:15:56 -050095
Florin Coras99368312018-08-02 10:45:44 -070096 if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
Florin Corasb384b542018-01-15 01:08:33 -080097 {
Florin Coras99368312018-08-02 10:45:44 -070098 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
99 {
100 clib_warning ("can't send memfd fd");
101 return -1;
102 }
103
104 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
105 fds[n_fds] = sp->fd;
106 n_fds += 1;
Florin Corasb384b542018-01-15 01:08:33 -0800107 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500108
Florin Coras99368312018-08-02 10:45:44 -0700109 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Barach68b0fb02017-02-28 15:15:56 -0500110 memset (mp, 0, sizeof (*mp));
111 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_MAP_ANOTHER_SEGMENT);
Florin Corasb384b542018-01-15 01:08:33 -0800112 mp->segment_size = sp->ssvm_size;
Florin Coras99368312018-08-02 10:45:44 -0700113 mp->fd_flags = fd_flags;
Florin Corasb384b542018-01-15 01:08:33 -0800114 strncpy ((char *) mp->segment_name, (char *) sp->name,
Dave Barach68b0fb02017-02-28 15:15:56 -0500115 sizeof (mp->segment_name) - 1);
116
Florin Corasb384b542018-01-15 01:08:33 -0800117 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
118
Florin Coras99368312018-08-02 10:45:44 -0700119 if (n_fds)
120 return session_send_fds (reg, fds, n_fds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500121
122 return 0;
123}
124
125static int
Florin Corasf8f516a2018-02-08 15:10:09 -0800126send_del_segment_callback (u32 api_client_index, const ssvm_private_t * fs)
127{
128 vl_api_unmap_segment_t *mp;
129 vl_api_registration_t *reg;
130
131 reg = vl_mem_api_client_index_to_registration (api_client_index);
132 if (!reg)
133 {
134 clib_warning ("no registration: %u", api_client_index);
135 return -1;
136 }
137
Florin Coras99368312018-08-02 10:45:44 -0700138 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Corasf8f516a2018-02-08 15:10:09 -0800139 memset (mp, 0, sizeof (*mp));
140 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_UNMAP_SEGMENT);
Florin Coras15531972018-08-12 23:50:53 -0700141 strncpy ((char *) mp->segment_name, (char *) fs->name,
142 sizeof (mp->segment_name) - 1);
Florin Corasf8f516a2018-02-08 15:10:09 -0800143
144 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
145
Florin Coras99368312018-08-02 10:45:44 -0700146 return 0;
147}
148
149static int
Florin Coras134a9962018-08-28 11:32:04 -0700150send_app_cut_through_registration_add (u32 api_client_index,
151 u32 wrk_map_index, u64 mq_addr,
Florin Coras99368312018-08-02 10:45:44 -0700152 u64 peer_mq_addr)
153{
154 vl_api_app_cut_through_registration_add_t *mp;
155 vl_api_registration_t *reg;
156 svm_msg_q_t *mq, *peer_mq;
157 int fds[2];
158
159 reg = vl_mem_api_client_index_to_registration (api_client_index);
160 if (!reg)
161 {
162 clib_warning ("no registration: %u", api_client_index);
163 return -1;
164 }
165
166 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
167 memset (mp, 0, sizeof (*mp));
168 mp->_vl_msg_id =
169 clib_host_to_net_u16 (VL_API_APP_CUT_THROUGH_REGISTRATION_ADD);
170
171 mp->evt_q_address = mq_addr;
172 mp->peer_evt_q_address = peer_mq_addr;
Florin Coras134a9962018-08-28 11:32:04 -0700173 mp->wrk_index = wrk_map_index;
Florin Coras99368312018-08-02 10:45:44 -0700174
175 mq = uword_to_pointer (mq_addr, svm_msg_q_t *);
176 peer_mq = uword_to_pointer (peer_mq_addr, svm_msg_q_t *);
177
178 if (svm_msg_q_get_producer_eventfd (mq) != -1)
179 {
180 mp->fd_flags |= SESSION_FD_F_MQ_EVENTFD;
181 mp->n_fds = 2;
182 /* app will overwrite exactly the fds we pass here. So
183 * when we swap mq with peer_mq (accept vs connect) the
184 * fds will still be valid */
185 fds[0] = svm_msg_q_get_consumer_eventfd (mq);
186 fds[1] = svm_msg_q_get_producer_eventfd (peer_mq);
187 }
188
189 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
190
191 if (mp->n_fds != 0)
192 session_send_fds (reg, fds, mp->n_fds);
Florin Corasf8f516a2018-02-08 15:10:09 -0800193
194 return 0;
195}
196
197static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700198send_session_accept_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500199{
Florin Coras15531972018-08-12 23:50:53 -0700200 app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700201 transport_proto_vft_t *tp_vft;
Florin Corasb384b542018-01-15 01:08:33 -0800202 vl_api_accept_session_t *mp;
203 vl_api_registration_t *reg;
204 transport_connection_t *tc;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700205 stream_session_t *listener;
Florin Coras3c2fed52018-07-04 04:15:05 -0700206 svm_msg_q_t *vpp_queue;
Florin Coras15531972018-08-12 23:50:53 -0700207 application_t *server;
Dave Barach68b0fb02017-02-28 15:15:56 -0500208
Florin Coras15531972018-08-12 23:50:53 -0700209 server = application_get (server_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800210 reg = vl_mem_api_client_index_to_registration (server->api_client_index);
211 if (!reg)
212 {
213 clib_warning ("no registration: %u", server->api_client_index);
214 return -1;
215 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500216
Florin Corasb384b542018-01-15 01:08:33 -0800217 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Coras6cf30ad2017-04-04 23:08:23 -0700218 memset (mp, 0, sizeof (*mp));
219
Dave Barach68b0fb02017-02-28 15:15:56 -0500220 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
Florin Coras15531972018-08-12 23:50:53 -0700221 mp->context = server_wrk->wrk_index;
Damjan Marion7bee80c2017-04-26 15:32:12 +0200222 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
223 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
Florin Corasf8f516a2018-02-08 15:10:09 -0800224
225 if (session_has_transport (s))
226 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700227 listener = listen_session_get (s->listener_index);
Florin Corasf8f516a2018-02-08 15:10:09 -0800228 mp->listener_handle = listen_session_get_handle (listener);
229 if (application_is_proxy (server))
230 {
231 listener =
Florin Coras15531972018-08-12 23:50:53 -0700232 app_worker_first_listener (server_wrk, session_get_fib_proto (s),
233 session_get_transport_proto (s));
Florin Corasf8f516a2018-02-08 15:10:09 -0800234 if (listener)
235 mp->listener_handle = listen_session_get_handle (listener);
236 }
237 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
238 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
239 mp->handle = session_handle (s);
240 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
241 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
242 mp->port = tc->rmt_port;
243 mp->is_ip4 = tc->is_ip4;
244 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
245 }
246 else
247 {
248 local_session_t *ls = (local_session_t *) s;
249 local_session_t *ll;
250 if (application_local_session_listener_has_transport (ls))
251 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700252 listener = listen_session_get (ls->listener_index);
Florin Corasf8f516a2018-02-08 15:10:09 -0800253 mp->listener_handle = listen_session_get_handle (listener);
Florin Coras5fda7a32018-02-14 08:04:31 -0800254 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
Florin Corasf8f516a2018-02-08 15:10:09 -0800255 }
256 else
257 {
Florin Corasab2f6db2018-08-31 14:31:41 -0700258 ll = application_get_local_listen_session (server,
Florin Corasf8f516a2018-02-08 15:10:09 -0800259 ls->listener_index);
Florin Coras5fda7a32018-02-14 08:04:31 -0800260 if (ll->transport_listener_index != ~0)
261 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700262 listener = listen_session_get (ll->transport_listener_index);
Florin Coras5fda7a32018-02-14 08:04:31 -0800263 mp->listener_handle = listen_session_get_handle (listener);
264 }
265 else
266 {
267 mp->listener_handle = application_local_session_handle (ll);
268 }
269 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
Florin Corasf8f516a2018-02-08 15:10:09 -0800270 }
271 mp->handle = application_local_session_handle (ls);
272 mp->port = ls->port;
273 mp->vpp_event_queue_address = ls->client_evt_q;
274 mp->server_event_queue_address = ls->server_evt_q;
275 }
Florin Corasb384b542018-01-15 01:08:33 -0800276 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500277
278 return 0;
279}
280
281static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700282send_session_disconnect_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500283{
Florin Coras15531972018-08-12 23:50:53 -0700284 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Corasb384b542018-01-15 01:08:33 -0800285 vl_api_disconnect_session_t *mp;
286 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700287 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500288
Florin Coras15531972018-08-12 23:50:53 -0700289 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800290 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
291 if (!reg)
292 {
293 clib_warning ("no registration: %u", app->api_client_index);
294 return;
295 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500296
Florin Corasb384b542018-01-15 01:08:33 -0800297 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Barach68b0fb02017-02-28 15:15:56 -0500298 memset (mp, 0, sizeof (*mp));
299 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700300 mp->handle = session_handle (s);
Florin Corasf8f516a2018-02-08 15:10:09 -0800301 mp->context = app->api_client_index;
Florin Corasb384b542018-01-15 01:08:33 -0800302 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500303}
304
Florin Corasd79b41e2017-03-04 05:37:52 -0800305static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700306send_session_reset_callback (stream_session_t * s)
Florin Corasd79b41e2017-03-04 05:37:52 -0800307{
Florin Coras15531972018-08-12 23:50:53 -0700308 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Corasb384b542018-01-15 01:08:33 -0800309 vl_api_registration_t *reg;
310 vl_api_reset_session_t *mp;
Florin Coras15531972018-08-12 23:50:53 -0700311 application_t *app;
Florin Corasd79b41e2017-03-04 05:37:52 -0800312
Florin Coras15531972018-08-12 23:50:53 -0700313 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800314 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
315 if (!reg)
316 {
317 clib_warning ("no registration: %u", app->api_client_index);
318 return;
319 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800320
Florin Corasb384b542018-01-15 01:08:33 -0800321 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Corasd79b41e2017-03-04 05:37:52 -0800322 memset (mp, 0, sizeof (*mp));
323 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700324 mp->handle = session_handle (s);
Florin Corasb384b542018-01-15 01:08:33 -0800325 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Florin Corasd79b41e2017-03-04 05:37:52 -0800326}
327
Dave Barach0194f1a2017-05-15 10:11:39 -0400328int
Florin Coras15531972018-08-12 23:50:53 -0700329send_session_connected_callback (u32 app_wrk_index, u32 api_context,
Florin Coras6cf30ad2017-04-04 23:08:23 -0700330 stream_session_t * s, u8 is_fail)
Dave Barach68b0fb02017-02-28 15:15:56 -0500331{
Dave Wallace33e002b2017-09-06 01:20:02 -0400332 vl_api_connect_session_reply_t *mp;
Florin Corasade70e42017-10-14 18:56:41 -0700333 transport_connection_t *tc;
Florin Corasb384b542018-01-15 01:08:33 -0800334 vl_api_registration_t *reg;
Florin Coras3c2fed52018-07-04 04:15:05 -0700335 svm_msg_q_t *vpp_queue;
Florin Coras15531972018-08-12 23:50:53 -0700336 app_worker_t *app_wrk;
Florin Corasb384b542018-01-15 01:08:33 -0800337 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500338
Florin Coras15531972018-08-12 23:50:53 -0700339 app_wrk = app_worker_get (app_wrk_index);
340 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800341 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
342 if (!reg)
343 {
344 clib_warning ("no registration: %u", app->api_client_index);
345 return -1;
346 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500347
Florin Corasb384b542018-01-15 01:08:33 -0800348 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Wallace33e002b2017-09-06 01:20:02 -0400349 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700350 mp->context = api_context;
Dave Wallace965fec92017-10-17 16:19:41 -0400351
352 if (is_fail)
353 goto done;
354
Florin Corasf8f516a2018-02-08 15:10:09 -0800355 if (session_has_transport (s))
Dave Barach68b0fb02017-02-28 15:15:56 -0500356 {
Florin Corasf8f516a2018-02-08 15:10:09 -0800357 tc = session_get_transport (s);
358 if (!tc)
359 {
360 is_fail = 1;
361 goto done;
362 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500363
Florin Corasf8f516a2018-02-08 15:10:09 -0800364 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
365 mp->handle = session_handle (s);
366 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
367 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
368 mp->is_ip4 = tc->is_ip4;
369 mp->lcl_port = tc->lcl_port;
370 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
371 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
372 }
373 else
374 {
375 local_session_t *ls = (local_session_t *) s;
376 mp->handle = application_local_session_handle (ls);
377 mp->lcl_port = ls->port;
378 mp->vpp_event_queue_address = ls->server_evt_q;
379 mp->client_event_queue_address = ls->client_evt_q;
380 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
381 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
382 }
Dave Wallace965fec92017-10-17 16:19:41 -0400383
384done:
385 mp->retval = is_fail ?
386 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
Florin Corasb384b542018-01-15 01:08:33 -0800387 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500388 return 0;
389}
390
Florin Corascea194d2017-10-02 00:18:51 -0700391static session_cb_vft_t session_cb_vft = {
Dave Barach68b0fb02017-02-28 15:15:56 -0500392 .session_accept_callback = send_session_accept_callback,
393 .session_disconnect_callback = send_session_disconnect_callback,
394 .session_connected_callback = send_session_connected_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800395 .session_reset_callback = send_session_reset_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500396 .add_segment_callback = send_add_segment_callback,
Florin Corasf8f516a2018-02-08 15:10:09 -0800397 .del_segment_callback = send_del_segment_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500398};
399
Florin Coras52207f12018-07-12 14:48:06 -0700400static int
Florin Coras83ea6692018-10-12 16:55:14 -0700401mq_try_lock_and_alloc_msg (svm_msg_q_t * app_mq, svm_msg_q_msg_t * msg)
402{
403 int rv;
404 u8 try = 0;
405 while (try < 100)
406 {
407 rv = svm_msg_q_lock_and_alloc_msg_w_ring (app_mq,
408 SESSION_MQ_CTRL_EVT_RING,
409 SVM_Q_NOWAIT, msg);
410 if (!rv)
411 return 0;
412 try++;
413 }
414 return -1;
415}
416
417static int
Florin Coras52207f12018-07-12 14:48:06 -0700418mq_send_session_accepted_cb (stream_session_t * s)
419{
Florin Coras15531972018-08-12 23:50:53 -0700420 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700421 svm_msg_q_msg_t _msg, *msg = &_msg;
422 svm_msg_q_t *vpp_queue, *app_mq;
423 transport_proto_vft_t *tp_vft;
424 transport_connection_t *tc;
425 stream_session_t *listener;
426 session_accepted_msg_t *mp;
427 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700428 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700429
Florin Coras15531972018-08-12 23:50:53 -0700430 app = application_get (app_wrk->app_index);
431 app_mq = app_wrk->event_queue;
Florin Coras83ea6692018-10-12 16:55:14 -0700432 if (mq_try_lock_and_alloc_msg (app_mq, msg))
433 return -1;
Florin Coras52207f12018-07-12 14:48:06 -0700434
435 evt = svm_msg_q_msg_data (app_mq, msg);
436 memset (evt, 0, sizeof (*evt));
437 evt->event_type = SESSION_CTRL_EVT_ACCEPTED;
438 mp = (session_accepted_msg_t *) evt->data;
Florin Corasab2f6db2018-08-31 14:31:41 -0700439 mp->context = app->app_index;
Florin Coras52207f12018-07-12 14:48:06 -0700440 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
441 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
442
443 if (session_has_transport (s))
444 {
445 listener = listen_session_get (s->listener_index);
446 mp->listener_handle = listen_session_get_handle (listener);
447 if (application_is_proxy (app))
448 {
449 listener =
Florin Coras15531972018-08-12 23:50:53 -0700450 app_worker_first_listener (app_wrk, session_get_fib_proto (s),
451 session_get_transport_proto (s));
Florin Coras52207f12018-07-12 14:48:06 -0700452 if (listener)
453 mp->listener_handle = listen_session_get_handle (listener);
454 }
455 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
456 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
457 mp->handle = session_handle (s);
458 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
459 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
460 mp->port = tc->rmt_port;
461 mp->is_ip4 = tc->is_ip4;
462 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
463 }
464 else
465 {
466 local_session_t *ls = (local_session_t *) s;
467 local_session_t *ll;
Florin Coras99368312018-08-02 10:45:44 -0700468 u8 main_thread = vlib_num_workers ()? 1 : 0;
469
470 send_app_cut_through_registration_add (app->api_client_index,
Florin Coras134a9962018-08-28 11:32:04 -0700471 app_wrk->wrk_map_index,
Florin Coras99368312018-08-02 10:45:44 -0700472 ls->server_evt_q,
473 ls->client_evt_q);
474
Florin Coras52207f12018-07-12 14:48:06 -0700475 if (application_local_session_listener_has_transport (ls))
476 {
477 listener = listen_session_get (ls->listener_index);
478 mp->listener_handle = listen_session_get_handle (listener);
479 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
480 }
481 else
482 {
Florin Corasab2f6db2018-08-31 14:31:41 -0700483 ll = application_get_local_listen_session (app, ls->listener_index);
Florin Coras52207f12018-07-12 14:48:06 -0700484 if (ll->transport_listener_index != ~0)
485 {
486 listener = listen_session_get (ll->transport_listener_index);
487 mp->listener_handle = listen_session_get_handle (listener);
488 }
489 else
490 {
491 mp->listener_handle = application_local_session_handle (ll);
492 }
493 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
494 }
495 mp->handle = application_local_session_handle (ls);
496 mp->port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700497 vpp_queue = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700498 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
499 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700500 mp->server_event_queue_address = ls->server_evt_q;
501 }
Florin Coras537b17e2018-09-28 10:35:45 -0700502 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700503
504 return 0;
505}
506
507static void
508mq_send_session_disconnected_cb (stream_session_t * s)
509{
Florin Coras15531972018-08-12 23:50:53 -0700510 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700511 svm_msg_q_msg_t _msg, *msg = &_msg;
512 session_disconnected_msg_t *mp;
513 svm_msg_q_t *app_mq;
514 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700515 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700516
Florin Coras15531972018-08-12 23:50:53 -0700517 app = application_get (app_wrk->app_index);
518 app_mq = app_wrk->event_queue;
Florin Coras83ea6692018-10-12 16:55:14 -0700519 if (mq_try_lock_and_alloc_msg (app_mq, msg))
520 return;
Florin Coras52207f12018-07-12 14:48:06 -0700521 evt = svm_msg_q_msg_data (app_mq, msg);
522 memset (evt, 0, sizeof (*evt));
523 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
524 mp = (session_disconnected_msg_t *) evt->data;
525 mp->handle = session_handle (s);
526 mp->context = app->api_client_index;
Florin Coras537b17e2018-09-28 10:35:45 -0700527 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700528}
529
Florin Corasaa27eb92018-10-13 12:20:01 -0700530void
531mq_send_local_session_disconnected_cb (u32 app_wrk_index,
532 local_session_t * ls)
533{
534 app_worker_t *app_wrk = app_worker_get (app_wrk_index);
535 svm_msg_q_msg_t _msg, *msg = &_msg;
536 session_disconnected_msg_t *mp;
537 svm_msg_q_t *app_mq;
538 session_event_t *evt;
539 application_t *app;
540
541 app = application_get (app_wrk->app_index);
542 app_mq = app_wrk->event_queue;
543 if (mq_try_lock_and_alloc_msg (app_mq, msg))
544 return;
545 evt = svm_msg_q_msg_data (app_mq, msg);
546 memset (evt, 0, sizeof (*evt));
547 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
548 mp = (session_disconnected_msg_t *) evt->data;
549 mp->handle = application_local_session_handle (ls);
550 mp->context = app->api_client_index;
551 svm_msg_q_add_and_unlock (app_mq, msg);
552}
553
Florin Coras52207f12018-07-12 14:48:06 -0700554static void
555mq_send_session_reset_cb (stream_session_t * s)
556{
Florin Coras15531972018-08-12 23:50:53 -0700557 app_worker_t *app = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700558 svm_msg_q_msg_t _msg, *msg = &_msg;
559 session_reset_msg_t *mp;
560 svm_msg_q_t *app_mq;
561 session_event_t *evt;
562
563 app_mq = app->event_queue;
Florin Coras83ea6692018-10-12 16:55:14 -0700564 if (mq_try_lock_and_alloc_msg (app_mq, msg))
565 return;
Florin Coras52207f12018-07-12 14:48:06 -0700566 evt = svm_msg_q_msg_data (app_mq, msg);
567 memset (evt, 0, sizeof (*evt));
568 evt->event_type = SESSION_CTRL_EVT_RESET;
569 mp = (session_reset_msg_t *) evt->data;
570 mp->handle = session_handle (s);
Florin Coras537b17e2018-09-28 10:35:45 -0700571 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700572}
573
574static int
Florin Coras15531972018-08-12 23:50:53 -0700575mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
Florin Coras52207f12018-07-12 14:48:06 -0700576 stream_session_t * s, u8 is_fail)
577{
578 svm_msg_q_msg_t _msg, *msg = &_msg;
579 session_connected_msg_t *mp;
580 svm_msg_q_t *vpp_mq, *app_mq;
581 transport_connection_t *tc;
Florin Coras15531972018-08-12 23:50:53 -0700582 app_worker_t *app_wrk;
Florin Coras52207f12018-07-12 14:48:06 -0700583 session_event_t *evt;
584 application_t *app;
585
Florin Coras15531972018-08-12 23:50:53 -0700586 app_wrk = app_worker_get (app_wrk_index);
587 app = application_get (app_wrk->app_index);
588 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700589 if (!app_mq)
590 {
Florin Coras15531972018-08-12 23:50:53 -0700591 clib_warning ("app %u with api index: %u not attached", app->app_index,
Florin Coras52207f12018-07-12 14:48:06 -0700592 app->api_client_index);
593 return -1;
594 }
595
Florin Coras83ea6692018-10-12 16:55:14 -0700596 if (mq_try_lock_and_alloc_msg (app_mq, msg))
597 return -1;
Florin Coras52207f12018-07-12 14:48:06 -0700598 evt = svm_msg_q_msg_data (app_mq, msg);
599 memset (evt, 0, sizeof (*evt));
600 evt->event_type = SESSION_CTRL_EVT_CONNECTED;
601 mp = (session_connected_msg_t *) evt->data;
602 mp->context = api_context;
603
604 if (is_fail)
605 goto done;
606
607 if (session_has_transport (s))
608 {
609 tc = session_get_transport (s);
610 if (!tc)
611 {
612 is_fail = 1;
613 goto done;
614 }
615
616 vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
617 mp->handle = session_handle (s);
618 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
619 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
620 mp->is_ip4 = tc->is_ip4;
621 mp->lcl_port = tc->lcl_port;
622 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
623 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
624 }
625 else
626 {
627 local_session_t *ls = (local_session_t *) s;
Florin Coras99368312018-08-02 10:45:44 -0700628 u8 main_thread = vlib_num_workers ()? 1 : 0;
629
630 send_app_cut_through_registration_add (app->api_client_index,
Florin Coras134a9962018-08-28 11:32:04 -0700631 app_wrk->wrk_map_index,
Florin Coras99368312018-08-02 10:45:44 -0700632 ls->client_evt_q,
633 ls->server_evt_q);
634
Florin Coras52207f12018-07-12 14:48:06 -0700635 mp->handle = application_local_session_handle (ls);
636 mp->lcl_port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700637 vpp_mq = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700638 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
Florin Coras52207f12018-07-12 14:48:06 -0700639 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras54693d22018-07-17 10:46:29 -0700640 mp->server_event_queue_address = ls->server_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700641 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
642 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
643 }
644
645done:
646 mp->retval = is_fail ?
647 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
648
Florin Coras537b17e2018-09-28 10:35:45 -0700649 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700650 return 0;
651}
652
Florin Coras60116992018-08-27 09:52:18 -0700653static int
654mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
655 session_handle_t handle, int rv)
656{
657 svm_msg_q_msg_t _msg, *msg = &_msg;
658 svm_msg_q_t *app_mq, *vpp_evt_q;
659 transport_connection_t *tc;
660 stream_session_t *ls = 0;
661 session_bound_msg_t *mp;
662 app_worker_t *app_wrk;
663 session_event_t *evt;
664 application_t *app;
665
666 app_wrk = app_worker_get (app_wrk_index);
667 app = application_get (app_wrk->app_index);
668 app_mq = app_wrk->event_queue;
669 if (!app_mq)
670 {
671 clib_warning ("app %u with api index: %u not attached", app->app_index,
672 app->api_client_index);
673 return -1;
674 }
675
Florin Coras83ea6692018-10-12 16:55:14 -0700676 if (mq_try_lock_and_alloc_msg (app_mq, msg))
677 return -1;
678
Florin Coras60116992018-08-27 09:52:18 -0700679 evt = svm_msg_q_msg_data (app_mq, msg);
680 memset (evt, 0, sizeof (*evt));
681 evt->event_type = SESSION_CTRL_EVT_BOUND;
682 mp = (session_bound_msg_t *) evt->data;
683 mp->context = api_context;
684
685 if (rv)
686 goto done;
687
688 mp->handle = handle;
689 if (application_has_global_scope (app))
690 {
691 ls = listen_session_get_from_handle (handle);
692 tc = listen_session_get_transport (ls);
693 mp->lcl_port = tc->lcl_port;
694 mp->lcl_is_ip4 = tc->is_ip4;
695 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
696 }
697 else
698 {
699 local_session_t *local;
Florin Corasab2f6db2018-08-31 14:31:41 -0700700 local = application_get_local_listener_w_handle (handle);
Florin Coras60116992018-08-27 09:52:18 -0700701 mp->lcl_port = local->port;
702 mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type);
703 }
704
705 if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
706 {
707 mp->rx_fifo = pointer_to_uword (ls->server_rx_fifo);
708 mp->tx_fifo = pointer_to_uword (ls->server_tx_fifo);
709 vpp_evt_q = session_manager_get_vpp_event_queue (0);
710 mp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
711 }
712
713done:
714 mp->retval = rv;
Florin Coras537b17e2018-09-28 10:35:45 -0700715 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras60116992018-08-27 09:52:18 -0700716 return 0;
717}
718
Florin Coras52207f12018-07-12 14:48:06 -0700719static session_cb_vft_t session_mq_cb_vft = {
720 .session_accept_callback = mq_send_session_accepted_cb,
721 .session_disconnect_callback = mq_send_session_disconnected_cb,
722 .session_connected_callback = mq_send_session_connected_cb,
723 .session_reset_callback = mq_send_session_reset_cb,
724 .add_segment_callback = send_add_segment_callback,
725 .del_segment_callback = send_del_segment_callback,
726};
727
Dave Barach68b0fb02017-02-28 15:15:56 -0500728static void
Florin Corase04c2992017-03-01 08:17:34 -0800729vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
730{
731 vl_api_session_enable_disable_reply_t *rmp;
732 vlib_main_t *vm = vlib_get_main ();
733 int rv = 0;
734
735 vnet_session_enable_disable (vm, mp->is_enable);
736 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
737}
738
739static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700740vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
Dave Barach68b0fb02017-02-28 15:15:56 -0500741{
Florin Coras99368312018-08-02 10:45:44 -0700742 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700743 vl_api_application_attach_reply_t *rmp;
Florin Corasb384b542018-01-15 01:08:33 -0800744 ssvm_private_t *segp, *evt_q_segment;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700745 vnet_app_attach_args_t _a, *a = &_a;
Florin Corasb384b542018-01-15 01:08:33 -0800746 vl_api_registration_t *reg;
Florin Corascea194d2017-10-02 00:18:51 -0700747 clib_error_t *error = 0;
Florin Coras99368312018-08-02 10:45:44 -0700748 u8 fd_flags = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500749
Florin Corasfc804d92018-01-26 01:27:01 -0800750 reg = vl_api_client_index_to_registration (mp->client_index);
751 if (!reg)
752 return;
753
Florin Coras6cf30ad2017-04-04 23:08:23 -0700754 if (session_manager_is_enabled () == 0)
755 {
756 rv = VNET_API_ERROR_FEATURE_DISABLED;
757 goto done;
758 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500759
Florin Corasff6e7692017-12-11 04:59:01 -0800760 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
Florin Coras6cf30ad2017-04-04 23:08:23 -0700761 sizeof (mp->options),
762 "Out of options, fix api message definition");
Dave Barach68b0fb02017-02-28 15:15:56 -0500763
764 memset (a, 0, sizeof (*a));
Dave Barach68b0fb02017-02-28 15:15:56 -0500765 a->api_client_index = mp->client_index;
766 a->options = mp->options;
Florin Coras52207f12018-07-12 14:48:06 -0700767
768 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
769 a->session_cb_vft = &session_mq_cb_vft;
770 else
771 a->session_cb_vft = &session_cb_vft;
Dave Barach68b0fb02017-02-28 15:15:56 -0500772
Florin Corascea194d2017-10-02 00:18:51 -0700773 if (mp->namespace_id_len > 64)
774 {
775 rv = VNET_API_ERROR_INVALID_VALUE;
776 goto done;
777 }
778
779 if (mp->namespace_id_len)
780 {
Dave Wallace8af20542017-10-26 03:29:30 -0400781 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
Florin Corascea194d2017-10-02 00:18:51 -0700782 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
783 }
784
785 if ((error = vnet_application_attach (a)))
786 {
787 rv = clib_error_get_code (error);
788 clib_error_report (error);
Florin Coras99368312018-08-02 10:45:44 -0700789 vec_free (a->namespace_id);
790 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700791 }
792 vec_free (a->namespace_id);
Dave Barach68b0fb02017-02-28 15:15:56 -0500793
Florin Coras99368312018-08-02 10:45:44 -0700794 /* Send event queues segment */
795 if ((evt_q_segment = session_manager_get_evt_q_segment ()))
796 {
797 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
798 fds[n_fds] = evt_q_segment->fd;
799 n_fds += 1;
800 }
801 /* Send fifo segment fd if needed */
802 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
803 {
804 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
805 fds[n_fds] = a->segment->fd;
806 n_fds += 1;
807 }
808 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
809 {
810 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
811 fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
812 n_fds += 1;
813 }
814
Florin Coras6cf30ad2017-04-04 23:08:23 -0700815done:
Florin Corasa5464812017-04-19 13:00:05 -0700816
Dave Barach68b0fb02017-02-28 15:15:56 -0500817 /* *INDENT-OFF* */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700818 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
Dave Barach68b0fb02017-02-28 15:15:56 -0500819 if (!rv)
820 {
Florin Corasb384b542018-01-15 01:08:33 -0800821 segp = a->segment;
Dave Barach68b0fb02017-02-28 15:15:56 -0500822 rmp->segment_name_length = 0;
Florin Corasb384b542018-01-15 01:08:33 -0800823 rmp->segment_size = segp->ssvm_size;
824 if (vec_len (segp->name))
Dave Barach68b0fb02017-02-28 15:15:56 -0500825 {
Florin Corasb384b542018-01-15 01:08:33 -0800826 memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
827 rmp->segment_name_length = vec_len (segp->name);
Dave Barach68b0fb02017-02-28 15:15:56 -0500828 }
Florin Coras99368312018-08-02 10:45:44 -0700829 rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q);
830 rmp->n_fds = n_fds;
831 rmp->fd_flags = fd_flags;
Dave Barach68b0fb02017-02-28 15:15:56 -0500832 }
833 }));
834 /* *INDENT-ON* */
Florin Corasb384b542018-01-15 01:08:33 -0800835
Florin Coras99368312018-08-02 10:45:44 -0700836 if (n_fds)
837 session_send_fds (reg, fds, n_fds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500838}
839
840static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700841vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
842{
843 vl_api_application_detach_reply_t *rmp;
844 int rv = VNET_API_ERROR_INVALID_VALUE_2;
845 vnet_app_detach_args_t _a, *a = &_a;
846 application_t *app;
847
848 if (session_manager_is_enabled () == 0)
849 {
850 rv = VNET_API_ERROR_FEATURE_DISABLED;
851 goto done;
852 }
853
854 app = application_lookup (mp->client_index);
855 if (app)
856 {
Florin Coras15531972018-08-12 23:50:53 -0700857 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700858 rv = vnet_application_detach (a);
859 }
860
861done:
862 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
863}
864
865static void
866vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
867{
Florin Coras7fb0fe12018-04-09 09:24:52 -0700868 transport_connection_t *tc = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700869 vnet_bind_args_t _a, *a = &_a;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700870 vl_api_bind_uri_reply_t *rmp;
871 stream_session_t *s;
872 application_t *app = 0;
Florin Coras3c2fed52018-07-04 04:15:05 -0700873 svm_msg_q_t *vpp_evt_q;
Florin Coras60116992018-08-27 09:52:18 -0700874 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700875 int rv;
876
877 if (session_manager_is_enabled () == 0)
878 {
879 rv = VNET_API_ERROR_FEATURE_DISABLED;
880 goto done;
881 }
882
883 app = application_lookup (mp->client_index);
884 if (app)
885 {
886 memset (a, 0, sizeof (*a));
887 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700888 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700889 rv = vnet_bind_uri (a);
890 }
891 else
892 {
893 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
894 }
895
896done:
Florin Coras7fb0fe12018-04-09 09:24:52 -0700897
898 /* *INDENT-OFF* */
899 REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
900 if (!rv)
901 {
902 rmp->handle = a->handle;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700903 if (app && application_has_global_scope (app))
904 {
905 s = listen_session_get_from_handle (a->handle);
906 tc = listen_session_get_transport (s);
Florin Coras6c354942018-04-18 00:05:21 -0700907 rmp->lcl_is_ip4 = tc->is_ip4;
908 rmp->lcl_port = tc->lcl_port;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700909 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
910 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
911 {
912 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
913 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
914 vpp_evt_q = session_manager_get_vpp_event_queue (0);
915 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
916 }
917 }
918 }
919 }));
920 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -0700921
922 /* If app uses mq for control messages, send an mq message as well */
923 if (app && application_use_mq_for_ctrl (app))
924 {
925 app_wrk = application_get_worker (app, 0);
926 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
927 rv);
928 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700929}
930
931static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500932vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
933{
934 vl_api_unbind_uri_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700935 application_t *app;
936 vnet_unbind_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -0500937 int rv;
938
Florin Coras6cf30ad2017-04-04 23:08:23 -0700939 if (session_manager_is_enabled () == 0)
940 {
941 rv = VNET_API_ERROR_FEATURE_DISABLED;
942 goto done;
943 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500944
Florin Coras6cf30ad2017-04-04 23:08:23 -0700945 app = application_lookup (mp->client_index);
946 if (app)
947 {
948 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700949 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700950 rv = vnet_unbind_uri (a);
951 }
952 else
953 {
954 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
955 }
956
957done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500958 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
959}
960
Florin Corasf03a59a2017-06-09 21:07:32 -0700961static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500962vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
963{
Dave Wallace33e002b2017-09-06 01:20:02 -0400964 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500965 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700966 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700967 clib_error_t *error = 0;
968 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500969
Florin Coras6cf30ad2017-04-04 23:08:23 -0700970 if (session_manager_is_enabled () == 0)
971 {
972 rv = VNET_API_ERROR_FEATURE_DISABLED;
973 goto done;
974 }
Florin Corase04c2992017-03-01 08:17:34 -0800975
Florin Coras6cf30ad2017-04-04 23:08:23 -0700976 app = application_lookup (mp->client_index);
977 if (app)
978 {
Florin Coras41c9e042018-09-11 00:10:41 -0700979 memset (a, 0, sizeof (*a));
Florin Coras6cf30ad2017-04-04 23:08:23 -0700980 a->uri = (char *) mp->uri;
981 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -0700982 a->app_index = app->app_index;
Florin Corascea194d2017-10-02 00:18:51 -0700983 if ((error = vnet_connect_uri (a)))
984 {
985 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -0800986 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -0700987 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700988 }
989 else
990 {
991 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
992 }
Florin Corase04c2992017-03-01 08:17:34 -0800993
Florin Coras3cbc04b2017-10-02 00:18:51 -0700994 /*
995 * Don't reply to stream (tcp) connects. The reply will come once
996 * the connection is established. In case of the redirects, the reply
997 * will come from the server app.
998 */
Florin Coras8f89dd02018-03-05 16:53:07 -0800999 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -08001000 return;
1001
Florin Coras6cf30ad2017-04-04 23:08:23 -07001002done:
Florin Corase04c2992017-03-01 08:17:34 -08001003 /* *INDENT-OFF* */
Dave Wallace33e002b2017-09-06 01:20:02 -04001004 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corase04c2992017-03-01 08:17:34 -08001005 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -05001006}
1007
1008static void
1009vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
1010{
1011 vl_api_disconnect_session_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001012 vnet_disconnect_args_t _a, *a = &_a;
1013 application_t *app;
1014 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001015
Florin Coras6cf30ad2017-04-04 23:08:23 -07001016 if (session_manager_is_enabled () == 0)
1017 {
1018 rv = VNET_API_ERROR_FEATURE_DISABLED;
1019 goto done;
1020 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001021
Florin Coras6cf30ad2017-04-04 23:08:23 -07001022 app = application_lookup (mp->client_index);
1023 if (app)
1024 {
1025 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001026 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001027 rv = vnet_disconnect_session (a);
1028 }
1029 else
1030 {
1031 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1032 }
1033
1034done:
Dave Wallacede5fec92017-11-11 22:41:34 -05001035 REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
Dave Barach68b0fb02017-02-28 15:15:56 -05001036}
1037
1038static void
1039vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
1040 mp)
1041{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001042 vnet_disconnect_args_t _a, *a = &_a;
1043 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001044
1045 /* Client objected to disconnecting the session, log and continue */
1046 if (mp->retval)
1047 {
1048 clib_warning ("client retval %d", mp->retval);
1049 return;
1050 }
1051
1052 /* Disconnect has been confirmed. Confirm close to transport */
Florin Corasf8f516a2018-02-08 15:10:09 -08001053 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001054 if (app)
1055 {
1056 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001057 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001058 vnet_disconnect_session (a);
1059 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001060}
1061
1062static void
1063vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
1064{
Florin Coras15531972018-08-12 23:50:53 -07001065 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001066 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001067 stream_session_t *s;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001068 u32 index, thread_index;
Dave Barach68b0fb02017-02-28 15:15:56 -05001069
Ondrej Fabry6bd197e2018-08-15 08:46:46 +02001070 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001071 if (!app)
1072 return;
1073
Florin Corascea194d2017-10-02 00:18:51 -07001074 session_parse_handle (mp->handle, &index, &thread_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -07001075 s = session_get_if_valid (index, thread_index);
Florin Coras15531972018-08-12 23:50:53 -07001076 if (!s)
Dave Barach68b0fb02017-02-28 15:15:56 -05001077 {
1078 clib_warning ("Invalid session!");
1079 return;
1080 }
1081
Florin Coras15531972018-08-12 23:50:53 -07001082 app_wrk = app_worker_get (s->app_wrk_index);
1083 if (app_wrk->app_index != app->app_index)
1084 {
1085 clib_warning ("app %u does not own handle 0x%lx", app->app_index,
1086 mp->handle);
1087 return;
1088 }
1089
Dave Barach68b0fb02017-02-28 15:15:56 -05001090 /* Client objected to resetting the session, log and continue */
1091 if (mp->retval)
1092 {
1093 clib_warning ("client retval %d", mp->retval);
1094 return;
1095 }
1096
Dave Barach68b0fb02017-02-28 15:15:56 -05001097 /* This comes as a response to a reset, transport only waiting for
1098 * confirmation to remove connection state, no need to disconnect */
1099 stream_session_cleanup (s);
1100}
1101
1102static void
1103vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
1104{
Florin Corasf8f516a2018-02-08 15:10:09 -08001105 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
1106 local_session_t *ls;
Dave Barach68b0fb02017-02-28 15:15:56 -05001107 stream_session_t *s;
Dave Barach68b0fb02017-02-28 15:15:56 -05001108
Florin Corasa5464812017-04-19 13:00:05 -07001109 /* Server isn't interested, kill the session */
1110 if (mp->retval)
Dave Barach68b0fb02017-02-28 15:15:56 -05001111 {
Florin Corasa5464812017-04-19 13:00:05 -07001112 a->app_index = mp->context;
1113 a->handle = mp->handle;
1114 vnet_disconnect_session (a);
Florin Corasf8f516a2018-02-08 15:10:09 -08001115 return;
1116 }
1117
1118 if (session_handle_is_local (mp->handle))
1119 {
1120 ls = application_get_local_session_from_handle (mp->handle);
Florin Coras15531972018-08-12 23:50:53 -07001121 if (!ls || ls->app_wrk_index != mp->context)
Florin Corasf8f516a2018-02-08 15:10:09 -08001122 {
1123 clib_warning ("server %u doesn't own local handle %llu",
1124 mp->context, mp->handle);
1125 return;
1126 }
1127 if (application_local_session_connect_notify (ls))
1128 return;
1129 ls->session_state = SESSION_STATE_READY;
Dave Barach68b0fb02017-02-28 15:15:56 -05001130 }
Florin Corasa5464812017-04-19 13:00:05 -07001131 else
1132 {
Florin Corasf8f516a2018-02-08 15:10:09 -08001133 s = session_get_from_handle_if_valid (mp->handle);
Florin Corasa5464812017-04-19 13:00:05 -07001134 if (!s)
1135 {
1136 clib_warning ("session doesn't exist");
1137 return;
1138 }
Florin Coras15531972018-08-12 23:50:53 -07001139 if (s->app_wrk_index != mp->context)
Florin Corasa5464812017-04-19 13:00:05 -07001140 {
1141 clib_warning ("app doesn't own session");
1142 return;
1143 }
Florin Corasa5464812017-04-19 13:00:05 -07001144 s->session_state = SESSION_STATE_READY;
1145 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001146}
1147
1148static void
1149vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
1150 * mp)
1151{
1152 clib_warning ("not implemented");
1153}
1154
1155static void
1156vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
1157{
1158 vl_api_bind_sock_reply_t *rmp;
1159 vnet_bind_args_t _a, *a = &_a;
Florin Corascea194d2017-10-02 00:18:51 -07001160 int rv = 0;
1161 clib_error_t *error;
Florin Coraseb2945c2017-11-22 10:39:09 -08001162 application_t *app = 0;
Florin Coras60116992018-08-27 09:52:18 -07001163 app_worker_t *app_wrk;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001164 stream_session_t *s;
1165 transport_connection_t *tc = 0;
1166 ip46_address_t *ip46;
Florin Coras3c2fed52018-07-04 04:15:05 -07001167 svm_msg_q_t *vpp_evt_q;
Dave Barach68b0fb02017-02-28 15:15:56 -05001168
Florin Coras6cf30ad2017-04-04 23:08:23 -07001169 if (session_manager_is_enabled () == 0)
1170 {
1171 rv = VNET_API_ERROR_FEATURE_DISABLED;
1172 goto done;
1173 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001174
Florin Coras6cf30ad2017-04-04 23:08:23 -07001175 app = application_lookup (mp->client_index);
Florin Corasdcf55ce2017-11-16 15:32:50 -08001176 if (!app)
Florin Coras6cf30ad2017-04-04 23:08:23 -07001177 {
Florin Corasdcf55ce2017-11-16 15:32:50 -08001178 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1179 goto done;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001180 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001181
1182 ip46 = (ip46_address_t *) mp->ip;
1183 memset (a, 0, sizeof (*a));
1184 a->sep.is_ip4 = mp->is_ip4;
1185 a->sep.ip = *ip46;
1186 a->sep.port = mp->port;
1187 a->sep.fib_index = mp->vrf;
1188 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1189 a->sep.transport_proto = mp->proto;
Florin Coras15531972018-08-12 23:50:53 -07001190 a->app_index = app->app_index;
1191 a->wrk_map_index = mp->wrk_index;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001192
1193 if ((error = vnet_bind (a)))
1194 {
1195 rv = clib_error_get_code (error);
1196 clib_error_report (error);
1197 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001198
Florin Coras6cf30ad2017-04-04 23:08:23 -07001199done:
Florin Corascea194d2017-10-02 00:18:51 -07001200 /* *INDENT-OFF* */
1201 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
1202 if (!rv)
Florin Corasdcf55ce2017-11-16 15:32:50 -08001203 {
1204 rmp->handle = a->handle;
Florin Coraseb2945c2017-11-22 10:39:09 -08001205 rmp->lcl_port = mp->port;
Keith Burns (alagalah)60ae80f2018-03-15 10:04:20 -07001206 rmp->lcl_is_ip4 = mp->is_ip4;
Dave Wallace97b1a272017-12-18 13:51:59 -05001207 if (app && application_has_global_scope (app))
Florin Coraseb2945c2017-11-22 10:39:09 -08001208 {
1209 s = listen_session_get_from_handle (a->handle);
1210 tc = listen_session_get_transport (s);
Florin Coraseb2945c2017-11-22 10:39:09 -08001211 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
Florin Coras7fb0fe12018-04-09 09:24:52 -07001212 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
1213 {
1214 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
1215 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
1216 vpp_evt_q = session_manager_get_vpp_event_queue (0);
1217 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
1218 }
Florin Coraseb2945c2017-11-22 10:39:09 -08001219 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001220 }
Florin Corascea194d2017-10-02 00:18:51 -07001221 }));
1222 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -07001223
1224 /* If app uses mq for control messages, send an mq message as well */
1225 if (app && application_use_mq_for_ctrl (app))
1226 {
1227 app_wrk = application_get_worker (app, mp->wrk_index);
1228 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
1229 rv);
1230 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001231}
1232
1233static void
1234vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
1235{
1236 vl_api_unbind_sock_reply_t *rmp;
1237 vnet_unbind_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001238 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -07001239 clib_error_t *error;
1240 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001241
Florin Coras6cf30ad2017-04-04 23:08:23 -07001242 if (session_manager_is_enabled () == 0)
1243 {
1244 rv = VNET_API_ERROR_FEATURE_DISABLED;
1245 goto done;
1246 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001247
Florin Coras6cf30ad2017-04-04 23:08:23 -07001248 app = application_lookup (mp->client_index);
1249 if (app)
1250 {
Florin Coras15531972018-08-12 23:50:53 -07001251 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001252 a->handle = mp->handle;
Florin Corasab2f6db2018-08-31 14:31:41 -07001253 a->wrk_map_index = mp->wrk_index;
Florin Corascea194d2017-10-02 00:18:51 -07001254 if ((error = vnet_unbind (a)))
1255 {
1256 rv = clib_error_get_code (error);
1257 clib_error_report (error);
1258 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001259 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001260
Florin Coras6cf30ad2017-04-04 23:08:23 -07001261done:
Dave Barach68b0fb02017-02-28 15:15:56 -05001262 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
1263}
1264
1265static void
1266vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1267{
Dave Wallace33e002b2017-09-06 01:20:02 -04001268 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -05001269 vnet_connect_args_t _a, *a = &_a;
Florin Corasab2f6db2018-08-31 14:31:41 -07001270 application_t *app = 0;
Florin Corascea194d2017-10-02 00:18:51 -07001271 clib_error_t *error = 0;
1272 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001273
Florin Coras6cf30ad2017-04-04 23:08:23 -07001274 if (session_manager_is_enabled () == 0)
1275 {
1276 rv = VNET_API_ERROR_FEATURE_DISABLED;
1277 goto done;
1278 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001279
Florin Coras6cf30ad2017-04-04 23:08:23 -07001280 app = application_lookup (mp->client_index);
1281 if (app)
1282 {
Florin Corase86a8ed2018-01-05 03:20:25 -08001283 svm_queue_t *client_q;
Dave Wallace33e002b2017-09-06 01:20:02 -04001284 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001285
Florin Coras8f89dd02018-03-05 16:53:07 -08001286 memset (a, 0, sizeof (*a));
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001287 client_q = vl_api_client_index_to_input_queue (mp->client_index);
1288 mp->client_queue_address = pointer_to_uword (client_q);
Florin Corascea194d2017-10-02 00:18:51 -07001289 a->sep.is_ip4 = mp->is_ip4;
1290 a->sep.ip = *ip46;
1291 a->sep.port = mp->port;
1292 a->sep.transport_proto = mp->proto;
1293 a->sep.fib_index = mp->vrf;
1294 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
Florin Coras8f89dd02018-03-05 16:53:07 -08001295 if (mp->hostname_len)
1296 {
Florin Coras15531972018-08-12 23:50:53 -07001297 vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
1298 clib_memcpy (a->sep_ext.hostname, mp->hostname, mp->hostname_len);
Florin Coras8f89dd02018-03-05 16:53:07 -08001299 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001300 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -07001301 a->app_index = app->app_index;
1302 a->wrk_map_index = mp->wrk_index;
Florin Corascea194d2017-10-02 00:18:51 -07001303 if ((error = vnet_connect (a)))
1304 {
1305 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -08001306 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -07001307 }
Florin Coras15531972018-08-12 23:50:53 -07001308 vec_free (a->sep_ext.hostname);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001309 }
1310 else
1311 {
1312 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1313 }
Florin Corase04c2992017-03-01 08:17:34 -08001314
Florin Coras8f89dd02018-03-05 16:53:07 -08001315 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -08001316 return;
1317
1318 /* Got some error, relay it */
1319
Florin Coras6cf30ad2017-04-04 23:08:23 -07001320done:
Dave Wallace33e002b2017-09-06 01:20:02 -04001321 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corasab2f6db2018-08-31 14:31:41 -07001322
1323 if (app && application_use_mq_for_ctrl (app))
1324 {
1325 app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index);
1326 mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1);
1327 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001328}
1329
Florin Corascea194d2017-10-02 00:18:51 -07001330static void
Florin Coras15531972018-08-12 23:50:53 -07001331vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
1332{
1333 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1334 vl_api_app_worker_add_del_reply_t *rmp;
1335 vl_api_registration_t *reg;
1336 clib_error_t *error = 0;
1337 application_t *app;
1338 u8 fd_flags = 0;
1339
1340 if (!session_manager_is_enabled ())
1341 {
1342 rv = VNET_API_ERROR_FEATURE_DISABLED;
1343 goto done;
1344 }
1345
1346 reg = vl_api_client_index_to_registration (mp->client_index);
1347 if (!reg)
1348 return;
1349
Florin Coras6d4bb422018-09-04 22:07:27 -07001350 app = application_lookup (clib_net_to_host_u32 (mp->app_api_index));
Florin Coras15531972018-08-12 23:50:53 -07001351 if (!app)
1352 {
1353 rv = VNET_API_ERROR_INVALID_VALUE;
1354 goto done;
1355 }
1356
1357 vnet_app_worker_add_del_args_t args = {
1358 .app_index = app->app_index,
1359 .wrk_index = clib_net_to_host_u32 (mp->wrk_index),
1360 .is_add = mp->is_add
1361 };
1362 error = vnet_app_worker_add_del (&args);
1363 if (error)
1364 {
1365 rv = clib_error_get_code (error);
1366 clib_error_report (error);
1367 goto done;
1368 }
1369
Florin Coras14598772018-09-04 19:47:52 -07001370 if (!mp->is_add)
1371 goto done;
Florin Corasc3638fe2018-08-24 13:58:49 -07001372
Florin Coras15531972018-08-12 23:50:53 -07001373 /* Send fifo segment fd if needed */
1374 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1375 {
1376 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1377 fds[n_fds] = args.segment->fd;
1378 n_fds += 1;
1379 }
1380 if (application_segment_manager_properties (app)->use_mq_eventfd)
1381 {
1382 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
1383 fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q);
1384 n_fds += 1;
1385 }
1386
1387 /* *INDENT-OFF* */
1388done:
1389 REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
1390 rmp->is_add = mp->is_add;
Florin Coras3348a4c2018-09-07 17:09:35 -07001391 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_index);
Florin Coras14598772018-09-04 19:47:52 -07001392 if (!rv && mp->is_add)
Florin Coras15531972018-08-12 23:50:53 -07001393 {
Florin Coras15531972018-08-12 23:50:53 -07001394 if (vec_len (args.segment->name))
1395 {
1396 memcpy (rmp->segment_name, args.segment->name,
1397 vec_len (args.segment->name));
1398 rmp->segment_name_length = vec_len (args.segment->name);
1399 }
1400 rmp->app_event_queue_address = pointer_to_uword (args.evt_q);
1401 rmp->n_fds = n_fds;
1402 rmp->fd_flags = fd_flags;
1403 }
1404 }));
1405 /* *INDENT-ON* */
1406
1407 if (n_fds)
1408 session_send_fds (reg, fds, n_fds);
1409}
1410
1411static void
Florin Corascea194d2017-10-02 00:18:51 -07001412vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
1413{
1414 vl_api_app_namespace_add_del_reply_t *rmp;
Florin Corascea194d2017-10-02 00:18:51 -07001415 clib_error_t *error = 0;
Florin Coras6e8c6672017-11-10 09:03:54 -08001416 u32 appns_index = 0;
1417 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -07001418 int rv = 0;
1419 if (!session_manager_is_enabled ())
1420 {
1421 rv = VNET_API_ERROR_FEATURE_DISABLED;
1422 goto done;
1423 }
1424
1425 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
1426 {
1427 rv = VNET_API_ERROR_INVALID_VALUE;
1428 goto done;
1429 }
1430
1431 vec_validate (ns_id, mp->namespace_id_len - 1);
1432 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
1433 vnet_app_namespace_add_del_args_t args = {
1434 .ns_id = ns_id,
Florin Coras9a9adb22017-10-26 08:16:59 -07001435 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -07001436 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
1437 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
1438 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
1439 .is_add = 1
1440 };
1441 error = vnet_app_namespace_add_del (&args);
1442 if (error)
1443 {
1444 rv = clib_error_get_code (error);
1445 clib_error_report (error);
1446 }
Florin Coras6e8c6672017-11-10 09:03:54 -08001447 else
1448 {
1449 appns_index = app_namespace_index_from_id (ns_id);
1450 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
1451 {
1452 clib_warning ("app ns lookup failed");
1453 rv = VNET_API_ERROR_UNSPECIFIED;
1454 }
1455 }
Florin Corascea194d2017-10-02 00:18:51 -07001456 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -08001457
1458 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -07001459done:
Florin Coras6e8c6672017-11-10 09:03:54 -08001460 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
1461 if (!rv)
1462 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1463 }));
1464 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -07001465}
1466
Florin Coras1c710452017-10-17 00:03:13 -07001467static void
1468vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
1469{
1470 vl_api_session_rule_add_del_reply_t *rmp;
1471 session_rule_add_del_args_t args;
1472 session_rule_table_add_del_args_t *table_args = &args.table_args;
1473 clib_error_t *error;
1474 u8 fib_proto;
1475 int rv = 0;
1476
Florin Corasc97a7392017-11-05 23:07:07 -08001477 memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -07001478 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1479
1480 table_args->lcl.fp_len = mp->lcl_plen;
1481 table_args->lcl.fp_proto = fib_proto;
1482 table_args->rmt.fp_len = mp->rmt_plen;
1483 table_args->rmt.fp_proto = fib_proto;
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001484 table_args->lcl_port = mp->lcl_port;
1485 table_args->rmt_port = mp->rmt_port;
Florin Coras1c710452017-10-17 00:03:13 -07001486 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
1487 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -08001488 mp->tag[sizeof (mp->tag) - 1] = 0;
1489 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001490 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
1491 args.scope = mp->scope;
Florin Coras42324ad2017-11-18 18:45:20 -08001492 args.transport_proto = mp->transport_proto;
Florin Coras1c710452017-10-17 00:03:13 -07001493
1494 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
1495 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
1496 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
1497 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
1498 error = vnet_session_rule_add_del (&args);
1499 if (error)
1500 {
1501 rv = clib_error_get_code (error);
1502 clib_error_report (error);
1503 }
Florin Corasc97a7392017-11-05 23:07:07 -08001504 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001505 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
1506}
1507
Florin Coras6c36f532017-11-03 18:32:34 -07001508static void
1509send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -08001510 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001511 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001512{
1513 vl_api_session_rules_details_t *rmp = 0;
1514 session_mask_or_match_4_t *match =
1515 (session_mask_or_match_4_t *) & rule->match;
1516 session_mask_or_match_4_t *mask =
1517 (session_mask_or_match_4_t *) & rule->mask;
1518
1519 rmp = vl_msg_api_alloc (sizeof (*rmp));
1520 memset (rmp, 0, sizeof (*rmp));
1521 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1522 rmp->context = context;
1523
1524 rmp->is_ip4 = 1;
1525 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1526 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1527 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
1528 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001529 rmp->lcl_port = match->lcl_port;
1530 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001531 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1532 rmp->scope =
1533 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
1534 rmp->transport_proto = transport_proto;
1535 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001536 if (tag)
1537 {
1538 clib_memcpy (rmp->tag, tag, vec_len (tag));
1539 rmp->tag[vec_len (tag)] = 0;
1540 }
Florin Coras6c36f532017-11-03 18:32:34 -07001541
Florin Coras6c4dae22018-01-09 06:39:23 -08001542 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001543}
1544
1545static void
Florin Corasc97a7392017-11-05 23:07:07 -08001546send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
1547 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001548 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001549{
1550 vl_api_session_rules_details_t *rmp = 0;
1551 session_mask_or_match_6_t *match =
1552 (session_mask_or_match_6_t *) & rule->match;
1553 session_mask_or_match_6_t *mask =
1554 (session_mask_or_match_6_t *) & rule->mask;
1555
1556 rmp = vl_msg_api_alloc (sizeof (*rmp));
1557 memset (rmp, 0, sizeof (*rmp));
1558 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1559 rmp->context = context;
1560
1561 rmp->is_ip4 = 0;
1562 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1563 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1564 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
1565 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001566 rmp->lcl_port = match->lcl_port;
1567 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001568 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001569 rmp->scope =
1570 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
Florin Coras6c36f532017-11-03 18:32:34 -07001571 rmp->transport_proto = transport_proto;
1572 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001573 if (tag)
1574 {
1575 clib_memcpy (rmp->tag, tag, vec_len (tag));
1576 rmp->tag[vec_len (tag)] = 0;
1577 }
Florin Coras6c36f532017-11-03 18:32:34 -07001578
Florin Coras6c4dae22018-01-09 06:39:23 -08001579 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001580}
1581
1582static void
1583send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -08001584 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c4dae22018-01-09 06:39:23 -08001585 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001586{
1587 mma_rule_16_t *rule16;
1588 mma_rule_40_t *rule40;
1589 mma_rules_table_16_t *srt16;
1590 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -08001591 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -07001592
Florin Corasc97a7392017-11-05 23:07:07 -08001593 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -07001594 {
Florin Corasc97a7392017-11-05 23:07:07 -08001595 u8 *tag = 0;
1596 /* *INDENT-OFF* */
1597 srt16 = &srt->session_rules_tables_16;
1598 pool_foreach (rule16, srt16->rules, ({
1599 ri = mma_rules_table_rule_index_16 (srt16, rule16);
1600 tag = session_rules_table_rule_tag (srt, ri, 1);
1601 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001602 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001603 }));
1604 /* *INDENT-ON* */
1605 }
1606 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
1607 {
1608 u8 *tag = 0;
1609 /* *INDENT-OFF* */
1610 srt40 = &srt->session_rules_tables_40;
1611 pool_foreach (rule40, srt40->rules, ({
1612 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1613 tag = session_rules_table_rule_tag (srt, ri, 1);
1614 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001615 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001616 }));
1617 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -07001618 }
1619}
1620
1621static void
1622vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1623{
Florin Coras6c4dae22018-01-09 06:39:23 -08001624 vl_api_registration_t *reg;
Florin Coras6c36f532017-11-03 18:32:34 -07001625 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -08001626 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -07001627
Florin Coras6c4dae22018-01-09 06:39:23 -08001628 reg = vl_api_client_index_to_registration (mp->client_index);
1629 if (!reg)
Florin Coras6c36f532017-11-03 18:32:34 -07001630 return;
1631
1632 /* *INDENT-OFF* */
1633 session_table_foreach (st, ({
Florin Corasc97a7392017-11-05 23:07:07 -08001634 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
1635 {
1636 send_session_rules_table_details (&st->session_rules[tp],
1637 st->active_fib_proto, tp,
Florin Coras6c4dae22018-01-09 06:39:23 -08001638 st->is_local, st->appns_index, reg,
Florin Corasc97a7392017-11-05 23:07:07 -08001639 mp->context);
1640 }
Florin Coras6c36f532017-11-03 18:32:34 -07001641 }));
1642 /* *INDENT-ON* */
1643}
1644
Florin Coras371ca502018-02-21 12:07:41 -08001645static void
1646vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
1647 mp)
1648{
1649 vl_api_app_namespace_add_del_reply_t *rmp;
1650 vnet_app_add_tls_cert_args_t _a, *a = &_a;
1651 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001652 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001653 u32 cert_len;
1654 int rv = 0;
1655 if (!session_manager_is_enabled ())
1656 {
1657 rv = VNET_API_ERROR_FEATURE_DISABLED;
1658 goto done;
1659 }
Florin Corase3e2f072018-03-04 07:24:30 -08001660 if (!(app = application_lookup (mp->client_index)))
1661 {
1662 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1663 goto done;
1664 }
Florin Coras371ca502018-02-21 12:07:41 -08001665 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001666 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001667 cert_len = clib_net_to_host_u16 (mp->cert_len);
Florin Coras5090c572018-03-18 08:22:17 -07001668 if (cert_len > 10000)
1669 {
1670 rv = VNET_API_ERROR_INVALID_VALUE;
1671 goto done;
1672 }
Florin Coras371ca502018-02-21 12:07:41 -08001673 vec_validate (a->cert, cert_len);
1674 clib_memcpy (a->cert, mp->cert, cert_len);
1675 if ((error = vnet_app_add_tls_cert (a)))
1676 {
1677 rv = clib_error_get_code (error);
1678 clib_error_report (error);
1679 }
1680 vec_free (a->cert);
1681done:
1682 REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
1683}
1684
1685static void
1686vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
1687 mp)
1688{
1689 vl_api_app_namespace_add_del_reply_t *rmp;
1690 vnet_app_add_tls_key_args_t _a, *a = &_a;
1691 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001692 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001693 u32 key_len;
1694 int rv = 0;
1695 if (!session_manager_is_enabled ())
1696 {
1697 rv = VNET_API_ERROR_FEATURE_DISABLED;
1698 goto done;
1699 }
Florin Corase3e2f072018-03-04 07:24:30 -08001700 if (!(app = application_lookup (mp->client_index)))
1701 {
1702 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1703 goto done;
1704 }
Florin Coras371ca502018-02-21 12:07:41 -08001705 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001706 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001707 key_len = clib_net_to_host_u16 (mp->key_len);
Florin Coras5090c572018-03-18 08:22:17 -07001708 if (key_len > 10000)
1709 {
1710 rv = VNET_API_ERROR_INVALID_VALUE;
1711 goto done;
1712 }
Florin Coras371ca502018-02-21 12:07:41 -08001713 vec_validate (a->key, key_len);
1714 clib_memcpy (a->key, mp->key, key_len);
1715 if ((error = vnet_app_add_tls_key (a)))
1716 {
1717 rv = clib_error_get_code (error);
1718 clib_error_report (error);
1719 }
1720 vec_free (a->key);
1721done:
1722 REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);
1723}
1724
Florin Coras6cf30ad2017-04-04 23:08:23 -07001725static clib_error_t *
1726application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -05001727{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001728 application_t *app = application_lookup (client_index);
1729 vnet_app_detach_args_t _a, *a = &_a;
1730 if (app)
1731 {
Florin Coras15531972018-08-12 23:50:53 -07001732 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001733 vnet_application_detach (a);
1734 }
1735 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001736}
1737
Florin Coras6cf30ad2017-04-04 23:08:23 -07001738VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -05001739
1740#define vl_msg_name_crc_list
1741#include <vnet/vnet_all_api_h.h>
1742#undef vl_msg_name_crc_list
1743
1744static void
1745setup_message_id_table (api_main_t * am)
1746{
1747#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1748 foreach_vl_msg_name_crc_session;
1749#undef _
1750}
1751
1752/*
1753 * session_api_hookup
1754 * Add uri's API message handlers to the table.
1755 * vlib has alread mapped shared memory and
1756 * added the client registration handlers.
1757 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1758 */
1759static clib_error_t *
1760session_api_hookup (vlib_main_t * vm)
1761{
1762 api_main_t *am = &api_main;
1763
1764#define _(N,n) \
1765 vl_msg_api_set_handlers(VL_API_##N, #n, \
1766 vl_api_##n##_t_handler, \
1767 vl_noop_handler, \
1768 vl_api_##n##_t_endian, \
1769 vl_api_##n##_t_print, \
1770 sizeof(vl_api_##n##_t), 1);
1771 foreach_session_api_msg;
1772#undef _
1773
1774 /*
1775 * Messages which bounce off the data-plane to
1776 * an API client. Simply tells the message handling infra not
1777 * to free the message.
1778 *
1779 * Bounced message handlers MUST NOT block the data plane
1780 */
1781 am->message_bounce[VL_API_CONNECT_URI] = 1;
1782 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1783
1784 /*
1785 * Set up the (msg_name, crc, message-id) table
1786 */
1787 setup_message_id_table (am);
1788
1789 return 0;
1790}
1791
1792VLIB_API_INIT_FUNCTION (session_api_hookup);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001793
Dave Barach68b0fb02017-02-28 15:15:56 -05001794/*
1795 * fd.io coding-style-patch-verification: ON
1796 *
1797 * Local Variables:
1798 * eval: (c-set-style "gnu")
1799 * End:
1800 */