blob: fc63428277eeaa0cabfc9eeec0992d7a135e2496 [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
Florin Corasf8f516a2018-02-08 15:10:09 -0800281void
Florin Coras15531972018-08-12 23:50:53 -0700282mq_send_local_session_disconnected_cb (u32 app_wrk_index,
283 local_session_t * ls)
Florin Corasf8f516a2018-02-08 15:10:09 -0800284{
Florin Coras15531972018-08-12 23:50:53 -0700285 app_worker_t *app_wrk = app_worker_get (app_wrk_index);
Florin Coras99368312018-08-02 10:45:44 -0700286 svm_msg_q_msg_t _msg, *msg = &_msg;
287 session_disconnected_msg_t *mp;
288 svm_msg_q_t *app_mq;
289 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700290 application_t *app;
Florin Corasf8f516a2018-02-08 15:10:09 -0800291
Florin Coras15531972018-08-12 23:50:53 -0700292 app = application_get (app_wrk->app_index);
293 app_mq = app_wrk->event_queue;
Florin Coras99368312018-08-02 10:45:44 -0700294 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
295 SVM_Q_WAIT, msg);
Florin Coras99368312018-08-02 10:45:44 -0700296 evt = svm_msg_q_msg_data (app_mq, msg);
297 memset (evt, 0, sizeof (*evt));
298 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
299 mp = (session_disconnected_msg_t *) evt->data;
Florin Corasf8f516a2018-02-08 15:10:09 -0800300 mp->handle = application_local_session_handle (ls);
301 mp->context = app->api_client_index;
Florin Coras537b17e2018-09-28 10:35:45 -0700302 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Corasf8f516a2018-02-08 15:10:09 -0800303}
304
Dave Barach68b0fb02017-02-28 15:15:56 -0500305static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700306send_session_disconnect_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500307{
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_disconnect_session_t *mp;
310 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700311 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500312
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 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500320
Florin Corasb384b542018-01-15 01:08:33 -0800321 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Barach68b0fb02017-02-28 15:15:56 -0500322 memset (mp, 0, sizeof (*mp));
323 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700324 mp->handle = session_handle (s);
Florin Corasf8f516a2018-02-08 15:10:09 -0800325 mp->context = app->api_client_index;
Florin Corasb384b542018-01-15 01:08:33 -0800326 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500327}
328
Florin Corasd79b41e2017-03-04 05:37:52 -0800329static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700330send_session_reset_callback (stream_session_t * s)
Florin Corasd79b41e2017-03-04 05:37:52 -0800331{
Florin Coras15531972018-08-12 23:50:53 -0700332 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Corasb384b542018-01-15 01:08:33 -0800333 vl_api_registration_t *reg;
334 vl_api_reset_session_t *mp;
Florin Coras15531972018-08-12 23:50:53 -0700335 application_t *app;
Florin Corasd79b41e2017-03-04 05:37:52 -0800336
Florin Coras15531972018-08-12 23:50:53 -0700337 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800338 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
339 if (!reg)
340 {
341 clib_warning ("no registration: %u", app->api_client_index);
342 return;
343 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800344
Florin Corasb384b542018-01-15 01:08:33 -0800345 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Corasd79b41e2017-03-04 05:37:52 -0800346 memset (mp, 0, sizeof (*mp));
347 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700348 mp->handle = session_handle (s);
Florin Corasb384b542018-01-15 01:08:33 -0800349 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Florin Corasd79b41e2017-03-04 05:37:52 -0800350}
351
Dave Barach0194f1a2017-05-15 10:11:39 -0400352int
Florin Coras15531972018-08-12 23:50:53 -0700353send_session_connected_callback (u32 app_wrk_index, u32 api_context,
Florin Coras6cf30ad2017-04-04 23:08:23 -0700354 stream_session_t * s, u8 is_fail)
Dave Barach68b0fb02017-02-28 15:15:56 -0500355{
Dave Wallace33e002b2017-09-06 01:20:02 -0400356 vl_api_connect_session_reply_t *mp;
Florin Corasade70e42017-10-14 18:56:41 -0700357 transport_connection_t *tc;
Florin Corasb384b542018-01-15 01:08:33 -0800358 vl_api_registration_t *reg;
Florin Coras3c2fed52018-07-04 04:15:05 -0700359 svm_msg_q_t *vpp_queue;
Florin Coras15531972018-08-12 23:50:53 -0700360 app_worker_t *app_wrk;
Florin Corasb384b542018-01-15 01:08:33 -0800361 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500362
Florin Coras15531972018-08-12 23:50:53 -0700363 app_wrk = app_worker_get (app_wrk_index);
364 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800365 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
366 if (!reg)
367 {
368 clib_warning ("no registration: %u", app->api_client_index);
369 return -1;
370 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500371
Florin Corasb384b542018-01-15 01:08:33 -0800372 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Wallace33e002b2017-09-06 01:20:02 -0400373 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700374 mp->context = api_context;
Dave Wallace965fec92017-10-17 16:19:41 -0400375
376 if (is_fail)
377 goto done;
378
Florin Corasf8f516a2018-02-08 15:10:09 -0800379 if (session_has_transport (s))
Dave Barach68b0fb02017-02-28 15:15:56 -0500380 {
Florin Corasf8f516a2018-02-08 15:10:09 -0800381 tc = session_get_transport (s);
382 if (!tc)
383 {
384 is_fail = 1;
385 goto done;
386 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500387
Florin Corasf8f516a2018-02-08 15:10:09 -0800388 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
389 mp->handle = session_handle (s);
390 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
391 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
392 mp->is_ip4 = tc->is_ip4;
393 mp->lcl_port = tc->lcl_port;
394 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
395 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
396 }
397 else
398 {
399 local_session_t *ls = (local_session_t *) s;
400 mp->handle = application_local_session_handle (ls);
401 mp->lcl_port = ls->port;
402 mp->vpp_event_queue_address = ls->server_evt_q;
403 mp->client_event_queue_address = ls->client_evt_q;
404 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
405 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
406 }
Dave Wallace965fec92017-10-17 16:19:41 -0400407
408done:
409 mp->retval = is_fail ?
410 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
Florin Corasb384b542018-01-15 01:08:33 -0800411 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500412 return 0;
413}
414
Florin Corascea194d2017-10-02 00:18:51 -0700415static session_cb_vft_t session_cb_vft = {
Dave Barach68b0fb02017-02-28 15:15:56 -0500416 .session_accept_callback = send_session_accept_callback,
417 .session_disconnect_callback = send_session_disconnect_callback,
418 .session_connected_callback = send_session_connected_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800419 .session_reset_callback = send_session_reset_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500420 .add_segment_callback = send_add_segment_callback,
Florin Corasf8f516a2018-02-08 15:10:09 -0800421 .del_segment_callback = send_del_segment_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500422};
423
Florin Coras52207f12018-07-12 14:48:06 -0700424static int
425mq_send_session_accepted_cb (stream_session_t * s)
426{
Florin Coras15531972018-08-12 23:50:53 -0700427 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700428 svm_msg_q_msg_t _msg, *msg = &_msg;
429 svm_msg_q_t *vpp_queue, *app_mq;
430 transport_proto_vft_t *tp_vft;
431 transport_connection_t *tc;
432 stream_session_t *listener;
433 session_accepted_msg_t *mp;
434 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700435 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700436
Florin Coras15531972018-08-12 23:50:53 -0700437 app = application_get (app_wrk->app_index);
438 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700439 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
440 SVM_Q_WAIT, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700441
442 evt = svm_msg_q_msg_data (app_mq, msg);
443 memset (evt, 0, sizeof (*evt));
444 evt->event_type = SESSION_CTRL_EVT_ACCEPTED;
445 mp = (session_accepted_msg_t *) evt->data;
Florin Corasab2f6db2018-08-31 14:31:41 -0700446 mp->context = app->app_index;
Florin Coras52207f12018-07-12 14:48:06 -0700447 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
448 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
449
450 if (session_has_transport (s))
451 {
452 listener = listen_session_get (s->listener_index);
453 mp->listener_handle = listen_session_get_handle (listener);
454 if (application_is_proxy (app))
455 {
456 listener =
Florin Coras15531972018-08-12 23:50:53 -0700457 app_worker_first_listener (app_wrk, session_get_fib_proto (s),
458 session_get_transport_proto (s));
Florin Coras52207f12018-07-12 14:48:06 -0700459 if (listener)
460 mp->listener_handle = listen_session_get_handle (listener);
461 }
462 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
463 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
464 mp->handle = session_handle (s);
465 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
466 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
467 mp->port = tc->rmt_port;
468 mp->is_ip4 = tc->is_ip4;
469 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
470 }
471 else
472 {
473 local_session_t *ls = (local_session_t *) s;
474 local_session_t *ll;
Florin Coras99368312018-08-02 10:45:44 -0700475 u8 main_thread = vlib_num_workers ()? 1 : 0;
476
477 send_app_cut_through_registration_add (app->api_client_index,
Florin Coras134a9962018-08-28 11:32:04 -0700478 app_wrk->wrk_map_index,
Florin Coras99368312018-08-02 10:45:44 -0700479 ls->server_evt_q,
480 ls->client_evt_q);
481
Florin Coras52207f12018-07-12 14:48:06 -0700482 if (application_local_session_listener_has_transport (ls))
483 {
484 listener = listen_session_get (ls->listener_index);
485 mp->listener_handle = listen_session_get_handle (listener);
486 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
487 }
488 else
489 {
Florin Corasab2f6db2018-08-31 14:31:41 -0700490 ll = application_get_local_listen_session (app, ls->listener_index);
Florin Coras52207f12018-07-12 14:48:06 -0700491 if (ll->transport_listener_index != ~0)
492 {
493 listener = listen_session_get (ll->transport_listener_index);
494 mp->listener_handle = listen_session_get_handle (listener);
495 }
496 else
497 {
498 mp->listener_handle = application_local_session_handle (ll);
499 }
500 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
501 }
502 mp->handle = application_local_session_handle (ls);
503 mp->port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700504 vpp_queue = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700505 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
506 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700507 mp->server_event_queue_address = ls->server_evt_q;
508 }
Florin Coras537b17e2018-09-28 10:35:45 -0700509 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700510
511 return 0;
512}
513
514static void
515mq_send_session_disconnected_cb (stream_session_t * s)
516{
Florin Coras15531972018-08-12 23:50:53 -0700517 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700518 svm_msg_q_msg_t _msg, *msg = &_msg;
519 session_disconnected_msg_t *mp;
520 svm_msg_q_t *app_mq;
521 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700522 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700523
Florin Coras15531972018-08-12 23:50:53 -0700524 app = application_get (app_wrk->app_index);
525 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700526 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
527 SVM_Q_WAIT, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700528 evt = svm_msg_q_msg_data (app_mq, msg);
529 memset (evt, 0, sizeof (*evt));
530 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
531 mp = (session_disconnected_msg_t *) evt->data;
532 mp->handle = session_handle (s);
533 mp->context = app->api_client_index;
Florin Coras537b17e2018-09-28 10:35:45 -0700534 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700535}
536
537static void
538mq_send_session_reset_cb (stream_session_t * s)
539{
Florin Coras15531972018-08-12 23:50:53 -0700540 app_worker_t *app = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700541 svm_msg_q_msg_t _msg, *msg = &_msg;
542 session_reset_msg_t *mp;
543 svm_msg_q_t *app_mq;
544 session_event_t *evt;
545
546 app_mq = app->event_queue;
547 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
548 SVM_Q_WAIT, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700549 evt = svm_msg_q_msg_data (app_mq, msg);
550 memset (evt, 0, sizeof (*evt));
551 evt->event_type = SESSION_CTRL_EVT_RESET;
552 mp = (session_reset_msg_t *) evt->data;
553 mp->handle = session_handle (s);
Florin Coras537b17e2018-09-28 10:35:45 -0700554 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700555}
556
557static int
Florin Coras15531972018-08-12 23:50:53 -0700558mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
Florin Coras52207f12018-07-12 14:48:06 -0700559 stream_session_t * s, u8 is_fail)
560{
561 svm_msg_q_msg_t _msg, *msg = &_msg;
562 session_connected_msg_t *mp;
563 svm_msg_q_t *vpp_mq, *app_mq;
564 transport_connection_t *tc;
Florin Coras15531972018-08-12 23:50:53 -0700565 app_worker_t *app_wrk;
Florin Coras52207f12018-07-12 14:48:06 -0700566 session_event_t *evt;
567 application_t *app;
568
Florin Coras15531972018-08-12 23:50:53 -0700569 app_wrk = app_worker_get (app_wrk_index);
570 app = application_get (app_wrk->app_index);
571 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700572 if (!app_mq)
573 {
Florin Coras15531972018-08-12 23:50:53 -0700574 clib_warning ("app %u with api index: %u not attached", app->app_index,
Florin Coras52207f12018-07-12 14:48:06 -0700575 app->api_client_index);
576 return -1;
577 }
578
579 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
580 SVM_Q_WAIT, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700581 evt = svm_msg_q_msg_data (app_mq, msg);
582 memset (evt, 0, sizeof (*evt));
583 evt->event_type = SESSION_CTRL_EVT_CONNECTED;
584 mp = (session_connected_msg_t *) evt->data;
585 mp->context = api_context;
586
587 if (is_fail)
588 goto done;
589
590 if (session_has_transport (s))
591 {
592 tc = session_get_transport (s);
593 if (!tc)
594 {
595 is_fail = 1;
596 goto done;
597 }
598
599 vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
600 mp->handle = session_handle (s);
601 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
602 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
603 mp->is_ip4 = tc->is_ip4;
604 mp->lcl_port = tc->lcl_port;
605 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
606 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
607 }
608 else
609 {
610 local_session_t *ls = (local_session_t *) s;
Florin Coras99368312018-08-02 10:45:44 -0700611 u8 main_thread = vlib_num_workers ()? 1 : 0;
612
613 send_app_cut_through_registration_add (app->api_client_index,
Florin Coras134a9962018-08-28 11:32:04 -0700614 app_wrk->wrk_map_index,
Florin Coras99368312018-08-02 10:45:44 -0700615 ls->client_evt_q,
616 ls->server_evt_q);
617
Florin Coras52207f12018-07-12 14:48:06 -0700618 mp->handle = application_local_session_handle (ls);
619 mp->lcl_port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700620 vpp_mq = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700621 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
Florin Coras52207f12018-07-12 14:48:06 -0700622 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras54693d22018-07-17 10:46:29 -0700623 mp->server_event_queue_address = ls->server_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700624 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
625 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
626 }
627
628done:
629 mp->retval = is_fail ?
630 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
631
Florin Coras537b17e2018-09-28 10:35:45 -0700632 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras52207f12018-07-12 14:48:06 -0700633 return 0;
634}
635
Florin Coras60116992018-08-27 09:52:18 -0700636static int
637mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
638 session_handle_t handle, int rv)
639{
640 svm_msg_q_msg_t _msg, *msg = &_msg;
641 svm_msg_q_t *app_mq, *vpp_evt_q;
642 transport_connection_t *tc;
643 stream_session_t *ls = 0;
644 session_bound_msg_t *mp;
645 app_worker_t *app_wrk;
646 session_event_t *evt;
647 application_t *app;
648
649 app_wrk = app_worker_get (app_wrk_index);
650 app = application_get (app_wrk->app_index);
651 app_mq = app_wrk->event_queue;
652 if (!app_mq)
653 {
654 clib_warning ("app %u with api index: %u not attached", app->app_index,
655 app->api_client_index);
656 return -1;
657 }
658
659 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
660 SVM_Q_WAIT, msg);
Florin Coras60116992018-08-27 09:52:18 -0700661 evt = svm_msg_q_msg_data (app_mq, msg);
662 memset (evt, 0, sizeof (*evt));
663 evt->event_type = SESSION_CTRL_EVT_BOUND;
664 mp = (session_bound_msg_t *) evt->data;
665 mp->context = api_context;
666
667 if (rv)
668 goto done;
669
670 mp->handle = handle;
671 if (application_has_global_scope (app))
672 {
673 ls = listen_session_get_from_handle (handle);
674 tc = listen_session_get_transport (ls);
675 mp->lcl_port = tc->lcl_port;
676 mp->lcl_is_ip4 = tc->is_ip4;
677 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
678 }
679 else
680 {
681 local_session_t *local;
Florin Corasab2f6db2018-08-31 14:31:41 -0700682 local = application_get_local_listener_w_handle (handle);
Florin Coras60116992018-08-27 09:52:18 -0700683 mp->lcl_port = local->port;
684 mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type);
685 }
686
687 if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
688 {
689 mp->rx_fifo = pointer_to_uword (ls->server_rx_fifo);
690 mp->tx_fifo = pointer_to_uword (ls->server_tx_fifo);
691 vpp_evt_q = session_manager_get_vpp_event_queue (0);
692 mp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
693 }
694
695done:
696 mp->retval = rv;
Florin Coras537b17e2018-09-28 10:35:45 -0700697 svm_msg_q_add_and_unlock (app_mq, msg);
Florin Coras60116992018-08-27 09:52:18 -0700698 return 0;
699}
700
Florin Coras52207f12018-07-12 14:48:06 -0700701static session_cb_vft_t session_mq_cb_vft = {
702 .session_accept_callback = mq_send_session_accepted_cb,
703 .session_disconnect_callback = mq_send_session_disconnected_cb,
704 .session_connected_callback = mq_send_session_connected_cb,
705 .session_reset_callback = mq_send_session_reset_cb,
706 .add_segment_callback = send_add_segment_callback,
707 .del_segment_callback = send_del_segment_callback,
708};
709
Dave Barach68b0fb02017-02-28 15:15:56 -0500710static void
Florin Corase04c2992017-03-01 08:17:34 -0800711vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
712{
713 vl_api_session_enable_disable_reply_t *rmp;
714 vlib_main_t *vm = vlib_get_main ();
715 int rv = 0;
716
717 vnet_session_enable_disable (vm, mp->is_enable);
718 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
719}
720
721static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700722vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
Dave Barach68b0fb02017-02-28 15:15:56 -0500723{
Florin Coras99368312018-08-02 10:45:44 -0700724 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700725 vl_api_application_attach_reply_t *rmp;
Florin Corasb384b542018-01-15 01:08:33 -0800726 ssvm_private_t *segp, *evt_q_segment;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700727 vnet_app_attach_args_t _a, *a = &_a;
Florin Corasb384b542018-01-15 01:08:33 -0800728 vl_api_registration_t *reg;
Florin Corascea194d2017-10-02 00:18:51 -0700729 clib_error_t *error = 0;
Florin Coras99368312018-08-02 10:45:44 -0700730 u8 fd_flags = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500731
Florin Corasfc804d92018-01-26 01:27:01 -0800732 reg = vl_api_client_index_to_registration (mp->client_index);
733 if (!reg)
734 return;
735
Florin Coras6cf30ad2017-04-04 23:08:23 -0700736 if (session_manager_is_enabled () == 0)
737 {
738 rv = VNET_API_ERROR_FEATURE_DISABLED;
739 goto done;
740 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500741
Florin Corasff6e7692017-12-11 04:59:01 -0800742 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
Florin Coras6cf30ad2017-04-04 23:08:23 -0700743 sizeof (mp->options),
744 "Out of options, fix api message definition");
Dave Barach68b0fb02017-02-28 15:15:56 -0500745
746 memset (a, 0, sizeof (*a));
Dave Barach68b0fb02017-02-28 15:15:56 -0500747 a->api_client_index = mp->client_index;
748 a->options = mp->options;
Florin Coras52207f12018-07-12 14:48:06 -0700749
750 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
751 a->session_cb_vft = &session_mq_cb_vft;
752 else
753 a->session_cb_vft = &session_cb_vft;
Dave Barach68b0fb02017-02-28 15:15:56 -0500754
Florin Corascea194d2017-10-02 00:18:51 -0700755 if (mp->namespace_id_len > 64)
756 {
757 rv = VNET_API_ERROR_INVALID_VALUE;
758 goto done;
759 }
760
761 if (mp->namespace_id_len)
762 {
Dave Wallace8af20542017-10-26 03:29:30 -0400763 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
Florin Corascea194d2017-10-02 00:18:51 -0700764 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
765 }
766
767 if ((error = vnet_application_attach (a)))
768 {
769 rv = clib_error_get_code (error);
770 clib_error_report (error);
Florin Coras99368312018-08-02 10:45:44 -0700771 vec_free (a->namespace_id);
772 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700773 }
774 vec_free (a->namespace_id);
Dave Barach68b0fb02017-02-28 15:15:56 -0500775
Florin Coras99368312018-08-02 10:45:44 -0700776 /* Send event queues segment */
777 if ((evt_q_segment = session_manager_get_evt_q_segment ()))
778 {
779 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
780 fds[n_fds] = evt_q_segment->fd;
781 n_fds += 1;
782 }
783 /* Send fifo segment fd if needed */
784 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
785 {
786 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
787 fds[n_fds] = a->segment->fd;
788 n_fds += 1;
789 }
790 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
791 {
792 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
793 fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
794 n_fds += 1;
795 }
796
Florin Coras6cf30ad2017-04-04 23:08:23 -0700797done:
Florin Corasa5464812017-04-19 13:00:05 -0700798
Dave Barach68b0fb02017-02-28 15:15:56 -0500799 /* *INDENT-OFF* */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700800 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
Dave Barach68b0fb02017-02-28 15:15:56 -0500801 if (!rv)
802 {
Florin Corasb384b542018-01-15 01:08:33 -0800803 segp = a->segment;
Dave Barach68b0fb02017-02-28 15:15:56 -0500804 rmp->segment_name_length = 0;
Florin Corasb384b542018-01-15 01:08:33 -0800805 rmp->segment_size = segp->ssvm_size;
806 if (vec_len (segp->name))
Dave Barach68b0fb02017-02-28 15:15:56 -0500807 {
Florin Corasb384b542018-01-15 01:08:33 -0800808 memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
809 rmp->segment_name_length = vec_len (segp->name);
Dave Barach68b0fb02017-02-28 15:15:56 -0500810 }
Florin Coras99368312018-08-02 10:45:44 -0700811 rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q);
812 rmp->n_fds = n_fds;
813 rmp->fd_flags = fd_flags;
Dave Barach68b0fb02017-02-28 15:15:56 -0500814 }
815 }));
816 /* *INDENT-ON* */
Florin Corasb384b542018-01-15 01:08:33 -0800817
Florin Coras99368312018-08-02 10:45:44 -0700818 if (n_fds)
819 session_send_fds (reg, fds, n_fds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500820}
821
822static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700823vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
824{
825 vl_api_application_detach_reply_t *rmp;
826 int rv = VNET_API_ERROR_INVALID_VALUE_2;
827 vnet_app_detach_args_t _a, *a = &_a;
828 application_t *app;
829
830 if (session_manager_is_enabled () == 0)
831 {
832 rv = VNET_API_ERROR_FEATURE_DISABLED;
833 goto done;
834 }
835
836 app = application_lookup (mp->client_index);
837 if (app)
838 {
Florin Coras15531972018-08-12 23:50:53 -0700839 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700840 rv = vnet_application_detach (a);
841 }
842
843done:
844 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
845}
846
847static void
848vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
849{
Florin Coras7fb0fe12018-04-09 09:24:52 -0700850 transport_connection_t *tc = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700851 vnet_bind_args_t _a, *a = &_a;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700852 vl_api_bind_uri_reply_t *rmp;
853 stream_session_t *s;
854 application_t *app = 0;
Florin Coras3c2fed52018-07-04 04:15:05 -0700855 svm_msg_q_t *vpp_evt_q;
Florin Coras60116992018-08-27 09:52:18 -0700856 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700857 int rv;
858
859 if (session_manager_is_enabled () == 0)
860 {
861 rv = VNET_API_ERROR_FEATURE_DISABLED;
862 goto done;
863 }
864
865 app = application_lookup (mp->client_index);
866 if (app)
867 {
868 memset (a, 0, sizeof (*a));
869 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700870 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700871 rv = vnet_bind_uri (a);
872 }
873 else
874 {
875 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
876 }
877
878done:
Florin Coras7fb0fe12018-04-09 09:24:52 -0700879
880 /* *INDENT-OFF* */
881 REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
882 if (!rv)
883 {
884 rmp->handle = a->handle;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700885 if (app && application_has_global_scope (app))
886 {
887 s = listen_session_get_from_handle (a->handle);
888 tc = listen_session_get_transport (s);
Florin Coras6c354942018-04-18 00:05:21 -0700889 rmp->lcl_is_ip4 = tc->is_ip4;
890 rmp->lcl_port = tc->lcl_port;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700891 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
892 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
893 {
894 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
895 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
896 vpp_evt_q = session_manager_get_vpp_event_queue (0);
897 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
898 }
899 }
900 }
901 }));
902 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -0700903
904 /* If app uses mq for control messages, send an mq message as well */
905 if (app && application_use_mq_for_ctrl (app))
906 {
907 app_wrk = application_get_worker (app, 0);
908 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
909 rv);
910 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700911}
912
913static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500914vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
915{
916 vl_api_unbind_uri_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700917 application_t *app;
918 vnet_unbind_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -0500919 int rv;
920
Florin Coras6cf30ad2017-04-04 23:08:23 -0700921 if (session_manager_is_enabled () == 0)
922 {
923 rv = VNET_API_ERROR_FEATURE_DISABLED;
924 goto done;
925 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500926
Florin Coras6cf30ad2017-04-04 23:08:23 -0700927 app = application_lookup (mp->client_index);
928 if (app)
929 {
930 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700931 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700932 rv = vnet_unbind_uri (a);
933 }
934 else
935 {
936 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
937 }
938
939done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500940 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
941}
942
Florin Corasf03a59a2017-06-09 21:07:32 -0700943static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500944vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
945{
Dave Wallace33e002b2017-09-06 01:20:02 -0400946 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500947 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700948 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700949 clib_error_t *error = 0;
950 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500951
Florin Coras6cf30ad2017-04-04 23:08:23 -0700952 if (session_manager_is_enabled () == 0)
953 {
954 rv = VNET_API_ERROR_FEATURE_DISABLED;
955 goto done;
956 }
Florin Corase04c2992017-03-01 08:17:34 -0800957
Florin Coras6cf30ad2017-04-04 23:08:23 -0700958 app = application_lookup (mp->client_index);
959 if (app)
960 {
Florin Coras41c9e042018-09-11 00:10:41 -0700961 memset (a, 0, sizeof (*a));
Florin Coras6cf30ad2017-04-04 23:08:23 -0700962 a->uri = (char *) mp->uri;
963 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -0700964 a->app_index = app->app_index;
Florin Corascea194d2017-10-02 00:18:51 -0700965 if ((error = vnet_connect_uri (a)))
966 {
967 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -0800968 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -0700969 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700970 }
971 else
972 {
973 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
974 }
Florin Corase04c2992017-03-01 08:17:34 -0800975
Florin Coras3cbc04b2017-10-02 00:18:51 -0700976 /*
977 * Don't reply to stream (tcp) connects. The reply will come once
978 * the connection is established. In case of the redirects, the reply
979 * will come from the server app.
980 */
Florin Coras8f89dd02018-03-05 16:53:07 -0800981 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -0800982 return;
983
Florin Coras6cf30ad2017-04-04 23:08:23 -0700984done:
Florin Corase04c2992017-03-01 08:17:34 -0800985 /* *INDENT-OFF* */
Dave Wallace33e002b2017-09-06 01:20:02 -0400986 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corase04c2992017-03-01 08:17:34 -0800987 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500988}
989
990static void
991vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
992{
993 vl_api_disconnect_session_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700994 vnet_disconnect_args_t _a, *a = &_a;
995 application_t *app;
996 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500997
Florin Coras6cf30ad2017-04-04 23:08:23 -0700998 if (session_manager_is_enabled () == 0)
999 {
1000 rv = VNET_API_ERROR_FEATURE_DISABLED;
1001 goto done;
1002 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001003
Florin Coras6cf30ad2017-04-04 23:08:23 -07001004 app = application_lookup (mp->client_index);
1005 if (app)
1006 {
1007 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001008 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001009 rv = vnet_disconnect_session (a);
1010 }
1011 else
1012 {
1013 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1014 }
1015
1016done:
Dave Wallacede5fec92017-11-11 22:41:34 -05001017 REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
Dave Barach68b0fb02017-02-28 15:15:56 -05001018}
1019
1020static void
1021vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
1022 mp)
1023{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001024 vnet_disconnect_args_t _a, *a = &_a;
1025 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001026
1027 /* Client objected to disconnecting the session, log and continue */
1028 if (mp->retval)
1029 {
1030 clib_warning ("client retval %d", mp->retval);
1031 return;
1032 }
1033
1034 /* Disconnect has been confirmed. Confirm close to transport */
Florin Corasf8f516a2018-02-08 15:10:09 -08001035 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001036 if (app)
1037 {
1038 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001039 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001040 vnet_disconnect_session (a);
1041 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001042}
1043
1044static void
1045vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
1046{
Florin Coras15531972018-08-12 23:50:53 -07001047 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001048 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001049 stream_session_t *s;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001050 u32 index, thread_index;
Dave Barach68b0fb02017-02-28 15:15:56 -05001051
Ondrej Fabry6bd197e2018-08-15 08:46:46 +02001052 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001053 if (!app)
1054 return;
1055
Florin Corascea194d2017-10-02 00:18:51 -07001056 session_parse_handle (mp->handle, &index, &thread_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -07001057 s = session_get_if_valid (index, thread_index);
Florin Coras15531972018-08-12 23:50:53 -07001058 if (!s)
Dave Barach68b0fb02017-02-28 15:15:56 -05001059 {
1060 clib_warning ("Invalid session!");
1061 return;
1062 }
1063
Florin Coras15531972018-08-12 23:50:53 -07001064 app_wrk = app_worker_get (s->app_wrk_index);
1065 if (app_wrk->app_index != app->app_index)
1066 {
1067 clib_warning ("app %u does not own handle 0x%lx", app->app_index,
1068 mp->handle);
1069 return;
1070 }
1071
Dave Barach68b0fb02017-02-28 15:15:56 -05001072 /* Client objected to resetting the session, log and continue */
1073 if (mp->retval)
1074 {
1075 clib_warning ("client retval %d", mp->retval);
1076 return;
1077 }
1078
Dave Barach68b0fb02017-02-28 15:15:56 -05001079 /* This comes as a response to a reset, transport only waiting for
1080 * confirmation to remove connection state, no need to disconnect */
1081 stream_session_cleanup (s);
1082}
1083
1084static void
1085vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
1086{
Florin Corasf8f516a2018-02-08 15:10:09 -08001087 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
1088 local_session_t *ls;
Dave Barach68b0fb02017-02-28 15:15:56 -05001089 stream_session_t *s;
Dave Barach68b0fb02017-02-28 15:15:56 -05001090
Florin Corasa5464812017-04-19 13:00:05 -07001091 /* Server isn't interested, kill the session */
1092 if (mp->retval)
Dave Barach68b0fb02017-02-28 15:15:56 -05001093 {
Florin Corasa5464812017-04-19 13:00:05 -07001094 a->app_index = mp->context;
1095 a->handle = mp->handle;
1096 vnet_disconnect_session (a);
Florin Corasf8f516a2018-02-08 15:10:09 -08001097 return;
1098 }
1099
1100 if (session_handle_is_local (mp->handle))
1101 {
1102 ls = application_get_local_session_from_handle (mp->handle);
Florin Coras15531972018-08-12 23:50:53 -07001103 if (!ls || ls->app_wrk_index != mp->context)
Florin Corasf8f516a2018-02-08 15:10:09 -08001104 {
1105 clib_warning ("server %u doesn't own local handle %llu",
1106 mp->context, mp->handle);
1107 return;
1108 }
1109 if (application_local_session_connect_notify (ls))
1110 return;
1111 ls->session_state = SESSION_STATE_READY;
Dave Barach68b0fb02017-02-28 15:15:56 -05001112 }
Florin Corasa5464812017-04-19 13:00:05 -07001113 else
1114 {
Florin Corasf8f516a2018-02-08 15:10:09 -08001115 s = session_get_from_handle_if_valid (mp->handle);
Florin Corasa5464812017-04-19 13:00:05 -07001116 if (!s)
1117 {
1118 clib_warning ("session doesn't exist");
1119 return;
1120 }
Florin Coras15531972018-08-12 23:50:53 -07001121 if (s->app_wrk_index != mp->context)
Florin Corasa5464812017-04-19 13:00:05 -07001122 {
1123 clib_warning ("app doesn't own session");
1124 return;
1125 }
Florin Corasa5464812017-04-19 13:00:05 -07001126 s->session_state = SESSION_STATE_READY;
1127 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001128}
1129
1130static void
1131vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
1132 * mp)
1133{
1134 clib_warning ("not implemented");
1135}
1136
1137static void
1138vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
1139{
1140 vl_api_bind_sock_reply_t *rmp;
1141 vnet_bind_args_t _a, *a = &_a;
Florin Corascea194d2017-10-02 00:18:51 -07001142 int rv = 0;
1143 clib_error_t *error;
Florin Coraseb2945c2017-11-22 10:39:09 -08001144 application_t *app = 0;
Florin Coras60116992018-08-27 09:52:18 -07001145 app_worker_t *app_wrk;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001146 stream_session_t *s;
1147 transport_connection_t *tc = 0;
1148 ip46_address_t *ip46;
Florin Coras3c2fed52018-07-04 04:15:05 -07001149 svm_msg_q_t *vpp_evt_q;
Dave Barach68b0fb02017-02-28 15:15:56 -05001150
Florin Coras6cf30ad2017-04-04 23:08:23 -07001151 if (session_manager_is_enabled () == 0)
1152 {
1153 rv = VNET_API_ERROR_FEATURE_DISABLED;
1154 goto done;
1155 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001156
Florin Coras6cf30ad2017-04-04 23:08:23 -07001157 app = application_lookup (mp->client_index);
Florin Corasdcf55ce2017-11-16 15:32:50 -08001158 if (!app)
Florin Coras6cf30ad2017-04-04 23:08:23 -07001159 {
Florin Corasdcf55ce2017-11-16 15:32:50 -08001160 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1161 goto done;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001162 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001163
1164 ip46 = (ip46_address_t *) mp->ip;
1165 memset (a, 0, sizeof (*a));
1166 a->sep.is_ip4 = mp->is_ip4;
1167 a->sep.ip = *ip46;
1168 a->sep.port = mp->port;
1169 a->sep.fib_index = mp->vrf;
1170 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1171 a->sep.transport_proto = mp->proto;
Florin Coras15531972018-08-12 23:50:53 -07001172 a->app_index = app->app_index;
1173 a->wrk_map_index = mp->wrk_index;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001174
1175 if ((error = vnet_bind (a)))
1176 {
1177 rv = clib_error_get_code (error);
1178 clib_error_report (error);
1179 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001180
Florin Coras6cf30ad2017-04-04 23:08:23 -07001181done:
Florin Corascea194d2017-10-02 00:18:51 -07001182 /* *INDENT-OFF* */
1183 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
1184 if (!rv)
Florin Corasdcf55ce2017-11-16 15:32:50 -08001185 {
1186 rmp->handle = a->handle;
Florin Coraseb2945c2017-11-22 10:39:09 -08001187 rmp->lcl_port = mp->port;
Keith Burns (alagalah)60ae80f2018-03-15 10:04:20 -07001188 rmp->lcl_is_ip4 = mp->is_ip4;
Dave Wallace97b1a272017-12-18 13:51:59 -05001189 if (app && application_has_global_scope (app))
Florin Coraseb2945c2017-11-22 10:39:09 -08001190 {
1191 s = listen_session_get_from_handle (a->handle);
1192 tc = listen_session_get_transport (s);
Florin Coraseb2945c2017-11-22 10:39:09 -08001193 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
Florin Coras7fb0fe12018-04-09 09:24:52 -07001194 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
1195 {
1196 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
1197 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
1198 vpp_evt_q = session_manager_get_vpp_event_queue (0);
1199 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
1200 }
Florin Coraseb2945c2017-11-22 10:39:09 -08001201 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001202 }
Florin Corascea194d2017-10-02 00:18:51 -07001203 }));
1204 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -07001205
1206 /* If app uses mq for control messages, send an mq message as well */
1207 if (app && application_use_mq_for_ctrl (app))
1208 {
1209 app_wrk = application_get_worker (app, mp->wrk_index);
1210 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
1211 rv);
1212 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001213}
1214
1215static void
1216vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
1217{
1218 vl_api_unbind_sock_reply_t *rmp;
1219 vnet_unbind_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001220 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -07001221 clib_error_t *error;
1222 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001223
Florin Coras6cf30ad2017-04-04 23:08:23 -07001224 if (session_manager_is_enabled () == 0)
1225 {
1226 rv = VNET_API_ERROR_FEATURE_DISABLED;
1227 goto done;
1228 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001229
Florin Coras6cf30ad2017-04-04 23:08:23 -07001230 app = application_lookup (mp->client_index);
1231 if (app)
1232 {
Florin Coras15531972018-08-12 23:50:53 -07001233 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001234 a->handle = mp->handle;
Florin Corasab2f6db2018-08-31 14:31:41 -07001235 a->wrk_map_index = mp->wrk_index;
Florin Corascea194d2017-10-02 00:18:51 -07001236 if ((error = vnet_unbind (a)))
1237 {
1238 rv = clib_error_get_code (error);
1239 clib_error_report (error);
1240 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001241 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001242
Florin Coras6cf30ad2017-04-04 23:08:23 -07001243done:
Dave Barach68b0fb02017-02-28 15:15:56 -05001244 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
1245}
1246
1247static void
1248vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1249{
Dave Wallace33e002b2017-09-06 01:20:02 -04001250 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -05001251 vnet_connect_args_t _a, *a = &_a;
Florin Corasab2f6db2018-08-31 14:31:41 -07001252 application_t *app = 0;
Florin Corascea194d2017-10-02 00:18:51 -07001253 clib_error_t *error = 0;
1254 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001255
Florin Coras6cf30ad2017-04-04 23:08:23 -07001256 if (session_manager_is_enabled () == 0)
1257 {
1258 rv = VNET_API_ERROR_FEATURE_DISABLED;
1259 goto done;
1260 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001261
Florin Coras6cf30ad2017-04-04 23:08:23 -07001262 app = application_lookup (mp->client_index);
1263 if (app)
1264 {
Florin Corase86a8ed2018-01-05 03:20:25 -08001265 svm_queue_t *client_q;
Dave Wallace33e002b2017-09-06 01:20:02 -04001266 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001267
Florin Coras8f89dd02018-03-05 16:53:07 -08001268 memset (a, 0, sizeof (*a));
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001269 client_q = vl_api_client_index_to_input_queue (mp->client_index);
1270 mp->client_queue_address = pointer_to_uword (client_q);
Florin Corascea194d2017-10-02 00:18:51 -07001271 a->sep.is_ip4 = mp->is_ip4;
1272 a->sep.ip = *ip46;
1273 a->sep.port = mp->port;
1274 a->sep.transport_proto = mp->proto;
1275 a->sep.fib_index = mp->vrf;
1276 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
Florin Coras8f89dd02018-03-05 16:53:07 -08001277 if (mp->hostname_len)
1278 {
Florin Coras15531972018-08-12 23:50:53 -07001279 vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
1280 clib_memcpy (a->sep_ext.hostname, mp->hostname, mp->hostname_len);
Florin Coras8f89dd02018-03-05 16:53:07 -08001281 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001282 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -07001283 a->app_index = app->app_index;
1284 a->wrk_map_index = mp->wrk_index;
Florin Corascea194d2017-10-02 00:18:51 -07001285 if ((error = vnet_connect (a)))
1286 {
1287 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -08001288 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -07001289 }
Florin Coras15531972018-08-12 23:50:53 -07001290 vec_free (a->sep_ext.hostname);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001291 }
1292 else
1293 {
1294 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1295 }
Florin Corase04c2992017-03-01 08:17:34 -08001296
Florin Coras8f89dd02018-03-05 16:53:07 -08001297 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -08001298 return;
1299
1300 /* Got some error, relay it */
1301
Florin Coras6cf30ad2017-04-04 23:08:23 -07001302done:
Dave Wallace33e002b2017-09-06 01:20:02 -04001303 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corasab2f6db2018-08-31 14:31:41 -07001304
1305 if (app && application_use_mq_for_ctrl (app))
1306 {
1307 app_worker_t *app_wrk = application_get_worker (app, mp->wrk_index);
1308 mq_send_session_connected_cb (app_wrk->wrk_index, mp->context, 0, 1);
1309 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001310}
1311
Florin Corascea194d2017-10-02 00:18:51 -07001312static void
Florin Coras15531972018-08-12 23:50:53 -07001313vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
1314{
1315 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1316 vl_api_app_worker_add_del_reply_t *rmp;
1317 vl_api_registration_t *reg;
1318 clib_error_t *error = 0;
1319 application_t *app;
1320 u8 fd_flags = 0;
1321
1322 if (!session_manager_is_enabled ())
1323 {
1324 rv = VNET_API_ERROR_FEATURE_DISABLED;
1325 goto done;
1326 }
1327
1328 reg = vl_api_client_index_to_registration (mp->client_index);
1329 if (!reg)
1330 return;
1331
Florin Coras6d4bb422018-09-04 22:07:27 -07001332 app = application_lookup (clib_net_to_host_u32 (mp->app_api_index));
Florin Coras15531972018-08-12 23:50:53 -07001333 if (!app)
1334 {
1335 rv = VNET_API_ERROR_INVALID_VALUE;
1336 goto done;
1337 }
1338
1339 vnet_app_worker_add_del_args_t args = {
1340 .app_index = app->app_index,
1341 .wrk_index = clib_net_to_host_u32 (mp->wrk_index),
1342 .is_add = mp->is_add
1343 };
1344 error = vnet_app_worker_add_del (&args);
1345 if (error)
1346 {
1347 rv = clib_error_get_code (error);
1348 clib_error_report (error);
1349 goto done;
1350 }
1351
Florin Coras14598772018-09-04 19:47:52 -07001352 if (!mp->is_add)
1353 goto done;
Florin Corasc3638fe2018-08-24 13:58:49 -07001354
Florin Coras15531972018-08-12 23:50:53 -07001355 /* Send fifo segment fd if needed */
1356 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1357 {
1358 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1359 fds[n_fds] = args.segment->fd;
1360 n_fds += 1;
1361 }
1362 if (application_segment_manager_properties (app)->use_mq_eventfd)
1363 {
1364 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
1365 fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q);
1366 n_fds += 1;
1367 }
1368
1369 /* *INDENT-OFF* */
1370done:
1371 REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
1372 rmp->is_add = mp->is_add;
Florin Coras3348a4c2018-09-07 17:09:35 -07001373 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_index);
Florin Coras14598772018-09-04 19:47:52 -07001374 if (!rv && mp->is_add)
Florin Coras15531972018-08-12 23:50:53 -07001375 {
Florin Coras15531972018-08-12 23:50:53 -07001376 if (vec_len (args.segment->name))
1377 {
1378 memcpy (rmp->segment_name, args.segment->name,
1379 vec_len (args.segment->name));
1380 rmp->segment_name_length = vec_len (args.segment->name);
1381 }
1382 rmp->app_event_queue_address = pointer_to_uword (args.evt_q);
1383 rmp->n_fds = n_fds;
1384 rmp->fd_flags = fd_flags;
1385 }
1386 }));
1387 /* *INDENT-ON* */
1388
1389 if (n_fds)
1390 session_send_fds (reg, fds, n_fds);
1391}
1392
1393static void
Florin Corascea194d2017-10-02 00:18:51 -07001394vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
1395{
1396 vl_api_app_namespace_add_del_reply_t *rmp;
Florin Corascea194d2017-10-02 00:18:51 -07001397 clib_error_t *error = 0;
Florin Coras6e8c6672017-11-10 09:03:54 -08001398 u32 appns_index = 0;
1399 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -07001400 int rv = 0;
1401 if (!session_manager_is_enabled ())
1402 {
1403 rv = VNET_API_ERROR_FEATURE_DISABLED;
1404 goto done;
1405 }
1406
1407 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
1408 {
1409 rv = VNET_API_ERROR_INVALID_VALUE;
1410 goto done;
1411 }
1412
1413 vec_validate (ns_id, mp->namespace_id_len - 1);
1414 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
1415 vnet_app_namespace_add_del_args_t args = {
1416 .ns_id = ns_id,
Florin Coras9a9adb22017-10-26 08:16:59 -07001417 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -07001418 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
1419 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
1420 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
1421 .is_add = 1
1422 };
1423 error = vnet_app_namespace_add_del (&args);
1424 if (error)
1425 {
1426 rv = clib_error_get_code (error);
1427 clib_error_report (error);
1428 }
Florin Coras6e8c6672017-11-10 09:03:54 -08001429 else
1430 {
1431 appns_index = app_namespace_index_from_id (ns_id);
1432 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
1433 {
1434 clib_warning ("app ns lookup failed");
1435 rv = VNET_API_ERROR_UNSPECIFIED;
1436 }
1437 }
Florin Corascea194d2017-10-02 00:18:51 -07001438 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -08001439
1440 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -07001441done:
Florin Coras6e8c6672017-11-10 09:03:54 -08001442 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
1443 if (!rv)
1444 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1445 }));
1446 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -07001447}
1448
Florin Coras1c710452017-10-17 00:03:13 -07001449static void
1450vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
1451{
1452 vl_api_session_rule_add_del_reply_t *rmp;
1453 session_rule_add_del_args_t args;
1454 session_rule_table_add_del_args_t *table_args = &args.table_args;
1455 clib_error_t *error;
1456 u8 fib_proto;
1457 int rv = 0;
1458
Florin Corasc97a7392017-11-05 23:07:07 -08001459 memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -07001460 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1461
1462 table_args->lcl.fp_len = mp->lcl_plen;
1463 table_args->lcl.fp_proto = fib_proto;
1464 table_args->rmt.fp_len = mp->rmt_plen;
1465 table_args->rmt.fp_proto = fib_proto;
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001466 table_args->lcl_port = mp->lcl_port;
1467 table_args->rmt_port = mp->rmt_port;
Florin Coras1c710452017-10-17 00:03:13 -07001468 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
1469 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -08001470 mp->tag[sizeof (mp->tag) - 1] = 0;
1471 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001472 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
1473 args.scope = mp->scope;
Florin Coras42324ad2017-11-18 18:45:20 -08001474 args.transport_proto = mp->transport_proto;
Florin Coras1c710452017-10-17 00:03:13 -07001475
1476 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
1477 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
1478 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
1479 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
1480 error = vnet_session_rule_add_del (&args);
1481 if (error)
1482 {
1483 rv = clib_error_get_code (error);
1484 clib_error_report (error);
1485 }
Florin Corasc97a7392017-11-05 23:07:07 -08001486 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001487 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
1488}
1489
Florin Coras6c36f532017-11-03 18:32:34 -07001490static void
1491send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -08001492 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001493 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001494{
1495 vl_api_session_rules_details_t *rmp = 0;
1496 session_mask_or_match_4_t *match =
1497 (session_mask_or_match_4_t *) & rule->match;
1498 session_mask_or_match_4_t *mask =
1499 (session_mask_or_match_4_t *) & rule->mask;
1500
1501 rmp = vl_msg_api_alloc (sizeof (*rmp));
1502 memset (rmp, 0, sizeof (*rmp));
1503 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1504 rmp->context = context;
1505
1506 rmp->is_ip4 = 1;
1507 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1508 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1509 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
1510 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001511 rmp->lcl_port = match->lcl_port;
1512 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001513 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1514 rmp->scope =
1515 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
1516 rmp->transport_proto = transport_proto;
1517 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001518 if (tag)
1519 {
1520 clib_memcpy (rmp->tag, tag, vec_len (tag));
1521 rmp->tag[vec_len (tag)] = 0;
1522 }
Florin Coras6c36f532017-11-03 18:32:34 -07001523
Florin Coras6c4dae22018-01-09 06:39:23 -08001524 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001525}
1526
1527static void
Florin Corasc97a7392017-11-05 23:07:07 -08001528send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
1529 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001530 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001531{
1532 vl_api_session_rules_details_t *rmp = 0;
1533 session_mask_or_match_6_t *match =
1534 (session_mask_or_match_6_t *) & rule->match;
1535 session_mask_or_match_6_t *mask =
1536 (session_mask_or_match_6_t *) & rule->mask;
1537
1538 rmp = vl_msg_api_alloc (sizeof (*rmp));
1539 memset (rmp, 0, sizeof (*rmp));
1540 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1541 rmp->context = context;
1542
1543 rmp->is_ip4 = 0;
1544 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1545 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1546 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
1547 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001548 rmp->lcl_port = match->lcl_port;
1549 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001550 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001551 rmp->scope =
1552 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
Florin Coras6c36f532017-11-03 18:32:34 -07001553 rmp->transport_proto = transport_proto;
1554 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001555 if (tag)
1556 {
1557 clib_memcpy (rmp->tag, tag, vec_len (tag));
1558 rmp->tag[vec_len (tag)] = 0;
1559 }
Florin Coras6c36f532017-11-03 18:32:34 -07001560
Florin Coras6c4dae22018-01-09 06:39:23 -08001561 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001562}
1563
1564static void
1565send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -08001566 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c4dae22018-01-09 06:39:23 -08001567 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001568{
1569 mma_rule_16_t *rule16;
1570 mma_rule_40_t *rule40;
1571 mma_rules_table_16_t *srt16;
1572 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -08001573 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -07001574
Florin Corasc97a7392017-11-05 23:07:07 -08001575 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -07001576 {
Florin Corasc97a7392017-11-05 23:07:07 -08001577 u8 *tag = 0;
1578 /* *INDENT-OFF* */
1579 srt16 = &srt->session_rules_tables_16;
1580 pool_foreach (rule16, srt16->rules, ({
1581 ri = mma_rules_table_rule_index_16 (srt16, rule16);
1582 tag = session_rules_table_rule_tag (srt, ri, 1);
1583 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001584 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001585 }));
1586 /* *INDENT-ON* */
1587 }
1588 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
1589 {
1590 u8 *tag = 0;
1591 /* *INDENT-OFF* */
1592 srt40 = &srt->session_rules_tables_40;
1593 pool_foreach (rule40, srt40->rules, ({
1594 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1595 tag = session_rules_table_rule_tag (srt, ri, 1);
1596 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001597 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001598 }));
1599 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -07001600 }
1601}
1602
1603static void
1604vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1605{
Florin Coras6c4dae22018-01-09 06:39:23 -08001606 vl_api_registration_t *reg;
Florin Coras6c36f532017-11-03 18:32:34 -07001607 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -08001608 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -07001609
Florin Coras6c4dae22018-01-09 06:39:23 -08001610 reg = vl_api_client_index_to_registration (mp->client_index);
1611 if (!reg)
Florin Coras6c36f532017-11-03 18:32:34 -07001612 return;
1613
1614 /* *INDENT-OFF* */
1615 session_table_foreach (st, ({
Florin Corasc97a7392017-11-05 23:07:07 -08001616 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
1617 {
1618 send_session_rules_table_details (&st->session_rules[tp],
1619 st->active_fib_proto, tp,
Florin Coras6c4dae22018-01-09 06:39:23 -08001620 st->is_local, st->appns_index, reg,
Florin Corasc97a7392017-11-05 23:07:07 -08001621 mp->context);
1622 }
Florin Coras6c36f532017-11-03 18:32:34 -07001623 }));
1624 /* *INDENT-ON* */
1625}
1626
Florin Coras371ca502018-02-21 12:07:41 -08001627static void
1628vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
1629 mp)
1630{
1631 vl_api_app_namespace_add_del_reply_t *rmp;
1632 vnet_app_add_tls_cert_args_t _a, *a = &_a;
1633 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001634 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001635 u32 cert_len;
1636 int rv = 0;
1637 if (!session_manager_is_enabled ())
1638 {
1639 rv = VNET_API_ERROR_FEATURE_DISABLED;
1640 goto done;
1641 }
Florin Corase3e2f072018-03-04 07:24:30 -08001642 if (!(app = application_lookup (mp->client_index)))
1643 {
1644 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1645 goto done;
1646 }
Florin Coras371ca502018-02-21 12:07:41 -08001647 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001648 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001649 cert_len = clib_net_to_host_u16 (mp->cert_len);
Florin Coras5090c572018-03-18 08:22:17 -07001650 if (cert_len > 10000)
1651 {
1652 rv = VNET_API_ERROR_INVALID_VALUE;
1653 goto done;
1654 }
Florin Coras371ca502018-02-21 12:07:41 -08001655 vec_validate (a->cert, cert_len);
1656 clib_memcpy (a->cert, mp->cert, cert_len);
1657 if ((error = vnet_app_add_tls_cert (a)))
1658 {
1659 rv = clib_error_get_code (error);
1660 clib_error_report (error);
1661 }
1662 vec_free (a->cert);
1663done:
1664 REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
1665}
1666
1667static void
1668vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
1669 mp)
1670{
1671 vl_api_app_namespace_add_del_reply_t *rmp;
1672 vnet_app_add_tls_key_args_t _a, *a = &_a;
1673 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001674 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001675 u32 key_len;
1676 int rv = 0;
1677 if (!session_manager_is_enabled ())
1678 {
1679 rv = VNET_API_ERROR_FEATURE_DISABLED;
1680 goto done;
1681 }
Florin Corase3e2f072018-03-04 07:24:30 -08001682 if (!(app = application_lookup (mp->client_index)))
1683 {
1684 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1685 goto done;
1686 }
Florin Coras371ca502018-02-21 12:07:41 -08001687 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001688 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001689 key_len = clib_net_to_host_u16 (mp->key_len);
Florin Coras5090c572018-03-18 08:22:17 -07001690 if (key_len > 10000)
1691 {
1692 rv = VNET_API_ERROR_INVALID_VALUE;
1693 goto done;
1694 }
Florin Coras371ca502018-02-21 12:07:41 -08001695 vec_validate (a->key, key_len);
1696 clib_memcpy (a->key, mp->key, key_len);
1697 if ((error = vnet_app_add_tls_key (a)))
1698 {
1699 rv = clib_error_get_code (error);
1700 clib_error_report (error);
1701 }
1702 vec_free (a->key);
1703done:
1704 REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);
1705}
1706
Florin Coras6cf30ad2017-04-04 23:08:23 -07001707static clib_error_t *
1708application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -05001709{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001710 application_t *app = application_lookup (client_index);
1711 vnet_app_detach_args_t _a, *a = &_a;
1712 if (app)
1713 {
Florin Coras15531972018-08-12 23:50:53 -07001714 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001715 vnet_application_detach (a);
1716 }
1717 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001718}
1719
Florin Coras6cf30ad2017-04-04 23:08:23 -07001720VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -05001721
1722#define vl_msg_name_crc_list
1723#include <vnet/vnet_all_api_h.h>
1724#undef vl_msg_name_crc_list
1725
1726static void
1727setup_message_id_table (api_main_t * am)
1728{
1729#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1730 foreach_vl_msg_name_crc_session;
1731#undef _
1732}
1733
1734/*
1735 * session_api_hookup
1736 * Add uri's API message handlers to the table.
1737 * vlib has alread mapped shared memory and
1738 * added the client registration handlers.
1739 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1740 */
1741static clib_error_t *
1742session_api_hookup (vlib_main_t * vm)
1743{
1744 api_main_t *am = &api_main;
1745
1746#define _(N,n) \
1747 vl_msg_api_set_handlers(VL_API_##N, #n, \
1748 vl_api_##n##_t_handler, \
1749 vl_noop_handler, \
1750 vl_api_##n##_t_endian, \
1751 vl_api_##n##_t_print, \
1752 sizeof(vl_api_##n##_t), 1);
1753 foreach_session_api_msg;
1754#undef _
1755
1756 /*
1757 * Messages which bounce off the data-plane to
1758 * an API client. Simply tells the message handling infra not
1759 * to free the message.
1760 *
1761 * Bounced message handlers MUST NOT block the data plane
1762 */
1763 am->message_bounce[VL_API_CONNECT_URI] = 1;
1764 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1765
1766 /*
1767 * Set up the (msg_name, crc, message-id) table
1768 */
1769 setup_message_id_table (am);
1770
1771 return 0;
1772}
1773
1774VLIB_API_INIT_FUNCTION (session_api_hookup);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001775
Dave Barach68b0fb02017-02-28 15:15:56 -05001776/*
1777 * fd.io coding-style-patch-verification: ON
1778 *
1779 * Local Variables:
1780 * eval: (c-set-style "gnu")
1781 * End:
1782 */