blob: 13a337699d23305a678d2293400d3d4c5776acc5 [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
150send_app_cut_through_registration_add (u32 api_client_index, u64 mq_addr,
151 u64 peer_mq_addr)
152{
153 vl_api_app_cut_through_registration_add_t *mp;
154 vl_api_registration_t *reg;
155 svm_msg_q_t *mq, *peer_mq;
156 int fds[2];
157
158 reg = vl_mem_api_client_index_to_registration (api_client_index);
159 if (!reg)
160 {
161 clib_warning ("no registration: %u", api_client_index);
162 return -1;
163 }
164
165 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
166 memset (mp, 0, sizeof (*mp));
167 mp->_vl_msg_id =
168 clib_host_to_net_u16 (VL_API_APP_CUT_THROUGH_REGISTRATION_ADD);
169
170 mp->evt_q_address = mq_addr;
171 mp->peer_evt_q_address = peer_mq_addr;
172
173 mq = uword_to_pointer (mq_addr, svm_msg_q_t *);
174 peer_mq = uword_to_pointer (peer_mq_addr, svm_msg_q_t *);
175
176 if (svm_msg_q_get_producer_eventfd (mq) != -1)
177 {
178 mp->fd_flags |= SESSION_FD_F_MQ_EVENTFD;
179 mp->n_fds = 2;
180 /* app will overwrite exactly the fds we pass here. So
181 * when we swap mq with peer_mq (accept vs connect) the
182 * fds will still be valid */
183 fds[0] = svm_msg_q_get_consumer_eventfd (mq);
184 fds[1] = svm_msg_q_get_producer_eventfd (peer_mq);
185 }
186
187 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
188
189 if (mp->n_fds != 0)
190 session_send_fds (reg, fds, mp->n_fds);
Florin Corasf8f516a2018-02-08 15:10:09 -0800191
192 return 0;
193}
194
195static int
Florin Coras6cf30ad2017-04-04 23:08:23 -0700196send_session_accept_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500197{
Florin Coras15531972018-08-12 23:50:53 -0700198 app_worker_t *server_wrk = app_worker_get (s->app_wrk_index);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700199 transport_proto_vft_t *tp_vft;
Florin Corasb384b542018-01-15 01:08:33 -0800200 vl_api_accept_session_t *mp;
201 vl_api_registration_t *reg;
202 transport_connection_t *tc;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700203 stream_session_t *listener;
Florin Coras3c2fed52018-07-04 04:15:05 -0700204 svm_msg_q_t *vpp_queue;
Florin Coras15531972018-08-12 23:50:53 -0700205 application_t *server;
Dave Barach68b0fb02017-02-28 15:15:56 -0500206
Florin Coras15531972018-08-12 23:50:53 -0700207 server = application_get (server_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800208 reg = vl_mem_api_client_index_to_registration (server->api_client_index);
209 if (!reg)
210 {
211 clib_warning ("no registration: %u", server->api_client_index);
212 return -1;
213 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500214
Florin Corasb384b542018-01-15 01:08:33 -0800215 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Coras6cf30ad2017-04-04 23:08:23 -0700216 memset (mp, 0, sizeof (*mp));
217
Dave Barach68b0fb02017-02-28 15:15:56 -0500218 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_ACCEPT_SESSION);
Florin Coras15531972018-08-12 23:50:53 -0700219 mp->context = server_wrk->wrk_index;
Damjan Marion7bee80c2017-04-26 15:32:12 +0200220 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
221 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
Florin Corasf8f516a2018-02-08 15:10:09 -0800222
223 if (session_has_transport (s))
224 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700225 listener = listen_session_get (s->listener_index);
Florin Corasf8f516a2018-02-08 15:10:09 -0800226 mp->listener_handle = listen_session_get_handle (listener);
227 if (application_is_proxy (server))
228 {
229 listener =
Florin Coras15531972018-08-12 23:50:53 -0700230 app_worker_first_listener (server_wrk, session_get_fib_proto (s),
231 session_get_transport_proto (s));
Florin Corasf8f516a2018-02-08 15:10:09 -0800232 if (listener)
233 mp->listener_handle = listen_session_get_handle (listener);
234 }
235 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
236 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
237 mp->handle = session_handle (s);
238 tp_vft = transport_protocol_get_vft (session_get_transport_proto (s));
239 tc = tp_vft->get_connection (s->connection_index, s->thread_index);
240 mp->port = tc->rmt_port;
241 mp->is_ip4 = tc->is_ip4;
242 clib_memcpy (&mp->ip, &tc->rmt_ip, sizeof (tc->rmt_ip));
243 }
244 else
245 {
246 local_session_t *ls = (local_session_t *) s;
247 local_session_t *ll;
248 if (application_local_session_listener_has_transport (ls))
249 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700250 listener = listen_session_get (ls->listener_index);
Florin Corasf8f516a2018-02-08 15:10:09 -0800251 mp->listener_handle = listen_session_get_handle (listener);
Florin Coras5fda7a32018-02-14 08:04:31 -0800252 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
Florin Corasf8f516a2018-02-08 15:10:09 -0800253 }
254 else
255 {
Florin Coras15531972018-08-12 23:50:53 -0700256 ll = application_get_local_listen_session (server_wrk,
Florin Corasf8f516a2018-02-08 15:10:09 -0800257 ls->listener_index);
Florin Coras5fda7a32018-02-14 08:04:31 -0800258 if (ll->transport_listener_index != ~0)
259 {
Florin Coras5c9083d2018-04-13 06:39:07 -0700260 listener = listen_session_get (ll->transport_listener_index);
Florin Coras5fda7a32018-02-14 08:04:31 -0800261 mp->listener_handle = listen_session_get_handle (listener);
262 }
263 else
264 {
265 mp->listener_handle = application_local_session_handle (ll);
266 }
267 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
Florin Corasf8f516a2018-02-08 15:10:09 -0800268 }
269 mp->handle = application_local_session_handle (ls);
270 mp->port = ls->port;
271 mp->vpp_event_queue_address = ls->client_evt_q;
272 mp->server_event_queue_address = ls->server_evt_q;
273 }
Florin Corasb384b542018-01-15 01:08:33 -0800274 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500275
276 return 0;
277}
278
Florin Corasf8f516a2018-02-08 15:10:09 -0800279void
Florin Coras15531972018-08-12 23:50:53 -0700280mq_send_local_session_disconnected_cb (u32 app_wrk_index,
281 local_session_t * ls)
Florin Corasf8f516a2018-02-08 15:10:09 -0800282{
Florin Coras15531972018-08-12 23:50:53 -0700283 app_worker_t *app_wrk = app_worker_get (app_wrk_index);
Florin Coras99368312018-08-02 10:45:44 -0700284 svm_msg_q_msg_t _msg, *msg = &_msg;
285 session_disconnected_msg_t *mp;
286 svm_msg_q_t *app_mq;
287 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700288 application_t *app;
Florin Corasf8f516a2018-02-08 15:10:09 -0800289
Florin Coras15531972018-08-12 23:50:53 -0700290 app = application_get (app_wrk->app_index);
291 app_mq = app_wrk->event_queue;
Florin Coras99368312018-08-02 10:45:44 -0700292 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
293 SVM_Q_WAIT, msg);
294 svm_msg_q_unlock (app_mq);
295 evt = svm_msg_q_msg_data (app_mq, msg);
296 memset (evt, 0, sizeof (*evt));
297 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
298 mp = (session_disconnected_msg_t *) evt->data;
Florin Corasf8f516a2018-02-08 15:10:09 -0800299 mp->handle = application_local_session_handle (ls);
300 mp->context = app->api_client_index;
Florin Coras99368312018-08-02 10:45:44 -0700301 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
Florin Corasf8f516a2018-02-08 15:10:09 -0800302}
303
Dave Barach68b0fb02017-02-28 15:15:56 -0500304static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700305send_session_disconnect_callback (stream_session_t * s)
Dave Barach68b0fb02017-02-28 15:15:56 -0500306{
Florin Coras15531972018-08-12 23:50:53 -0700307 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Corasb384b542018-01-15 01:08:33 -0800308 vl_api_disconnect_session_t *mp;
309 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700310 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500311
Florin Coras15531972018-08-12 23:50:53 -0700312 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800313 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
314 if (!reg)
315 {
316 clib_warning ("no registration: %u", app->api_client_index);
317 return;
318 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500319
Florin Corasb384b542018-01-15 01:08:33 -0800320 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Barach68b0fb02017-02-28 15:15:56 -0500321 memset (mp, 0, sizeof (*mp));
322 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_DISCONNECT_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700323 mp->handle = session_handle (s);
Florin Corasf8f516a2018-02-08 15:10:09 -0800324 mp->context = app->api_client_index;
Florin Corasb384b542018-01-15 01:08:33 -0800325 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500326}
327
Florin Corasd79b41e2017-03-04 05:37:52 -0800328static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700329send_session_reset_callback (stream_session_t * s)
Florin Corasd79b41e2017-03-04 05:37:52 -0800330{
Florin Coras15531972018-08-12 23:50:53 -0700331 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Corasb384b542018-01-15 01:08:33 -0800332 vl_api_registration_t *reg;
333 vl_api_reset_session_t *mp;
Florin Coras15531972018-08-12 23:50:53 -0700334 application_t *app;
Florin Corasd79b41e2017-03-04 05:37:52 -0800335
Florin Coras15531972018-08-12 23:50:53 -0700336 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800337 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
338 if (!reg)
339 {
340 clib_warning ("no registration: %u", app->api_client_index);
341 return;
342 }
Florin Corasd79b41e2017-03-04 05:37:52 -0800343
Florin Corasb384b542018-01-15 01:08:33 -0800344 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Florin Corasd79b41e2017-03-04 05:37:52 -0800345 memset (mp, 0, sizeof (*mp));
346 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_RESET_SESSION);
Florin Coras3cbc04b2017-10-02 00:18:51 -0700347 mp->handle = session_handle (s);
Florin Corasb384b542018-01-15 01:08:33 -0800348 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Florin Corasd79b41e2017-03-04 05:37:52 -0800349}
350
Dave Barach0194f1a2017-05-15 10:11:39 -0400351int
Florin Coras15531972018-08-12 23:50:53 -0700352send_session_connected_callback (u32 app_wrk_index, u32 api_context,
Florin Coras6cf30ad2017-04-04 23:08:23 -0700353 stream_session_t * s, u8 is_fail)
Dave Barach68b0fb02017-02-28 15:15:56 -0500354{
Dave Wallace33e002b2017-09-06 01:20:02 -0400355 vl_api_connect_session_reply_t *mp;
Florin Corasade70e42017-10-14 18:56:41 -0700356 transport_connection_t *tc;
Florin Corasb384b542018-01-15 01:08:33 -0800357 vl_api_registration_t *reg;
Florin Coras3c2fed52018-07-04 04:15:05 -0700358 svm_msg_q_t *vpp_queue;
Florin Coras15531972018-08-12 23:50:53 -0700359 app_worker_t *app_wrk;
Florin Corasb384b542018-01-15 01:08:33 -0800360 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -0500361
Florin Coras15531972018-08-12 23:50:53 -0700362 app_wrk = app_worker_get (app_wrk_index);
363 app = application_get (app_wrk->app_index);
Florin Corasb384b542018-01-15 01:08:33 -0800364 reg = vl_mem_api_client_index_to_registration (app->api_client_index);
365 if (!reg)
366 {
367 clib_warning ("no registration: %u", app->api_client_index);
368 return -1;
369 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500370
Florin Corasb384b542018-01-15 01:08:33 -0800371 mp = vl_mem_api_alloc_as_if_client_w_reg (reg, sizeof (*mp));
Dave Wallace33e002b2017-09-06 01:20:02 -0400372 mp->_vl_msg_id = clib_host_to_net_u16 (VL_API_CONNECT_SESSION_REPLY);
Florin Coras6cf30ad2017-04-04 23:08:23 -0700373 mp->context = api_context;
Dave Wallace965fec92017-10-17 16:19:41 -0400374
375 if (is_fail)
376 goto done;
377
Florin Corasf8f516a2018-02-08 15:10:09 -0800378 if (session_has_transport (s))
Dave Barach68b0fb02017-02-28 15:15:56 -0500379 {
Florin Corasf8f516a2018-02-08 15:10:09 -0800380 tc = session_get_transport (s);
381 if (!tc)
382 {
383 is_fail = 1;
384 goto done;
385 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500386
Florin Corasf8f516a2018-02-08 15:10:09 -0800387 vpp_queue = session_manager_get_vpp_event_queue (s->thread_index);
388 mp->handle = session_handle (s);
389 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
390 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
391 mp->is_ip4 = tc->is_ip4;
392 mp->lcl_port = tc->lcl_port;
393 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
394 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
395 }
396 else
397 {
398 local_session_t *ls = (local_session_t *) s;
399 mp->handle = application_local_session_handle (ls);
400 mp->lcl_port = ls->port;
401 mp->vpp_event_queue_address = ls->server_evt_q;
402 mp->client_event_queue_address = ls->client_evt_q;
403 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
404 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
405 }
Dave Wallace965fec92017-10-17 16:19:41 -0400406
407done:
408 mp->retval = is_fail ?
409 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
Florin Corasb384b542018-01-15 01:08:33 -0800410 vl_msg_api_send_shmem (reg->vl_input_queue, (u8 *) & mp);
Dave Barach68b0fb02017-02-28 15:15:56 -0500411 return 0;
412}
413
Florin Corascea194d2017-10-02 00:18:51 -0700414static session_cb_vft_t session_cb_vft = {
Dave Barach68b0fb02017-02-28 15:15:56 -0500415 .session_accept_callback = send_session_accept_callback,
416 .session_disconnect_callback = send_session_disconnect_callback,
417 .session_connected_callback = send_session_connected_callback,
Florin Corasd79b41e2017-03-04 05:37:52 -0800418 .session_reset_callback = send_session_reset_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500419 .add_segment_callback = send_add_segment_callback,
Florin Corasf8f516a2018-02-08 15:10:09 -0800420 .del_segment_callback = send_del_segment_callback,
Dave Barach68b0fb02017-02-28 15:15:56 -0500421};
422
Florin Coras52207f12018-07-12 14:48:06 -0700423static int
424mq_send_session_accepted_cb (stream_session_t * s)
425{
Florin Coras15531972018-08-12 23:50:53 -0700426 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700427 svm_msg_q_msg_t _msg, *msg = &_msg;
428 svm_msg_q_t *vpp_queue, *app_mq;
429 transport_proto_vft_t *tp_vft;
430 transport_connection_t *tc;
431 stream_session_t *listener;
432 session_accepted_msg_t *mp;
433 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700434 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700435
Florin Coras15531972018-08-12 23:50:53 -0700436 app = application_get (app_wrk->app_index);
437 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700438 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
439 SVM_Q_WAIT, msg);
440 svm_msg_q_unlock (app_mq);
441
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 Coras15531972018-08-12 23:50:53 -0700446 mp->context = app_wrk->wrk_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,
478 ls->server_evt_q,
479 ls->client_evt_q);
480
Florin Coras52207f12018-07-12 14:48:06 -0700481 if (application_local_session_listener_has_transport (ls))
482 {
483 listener = listen_session_get (ls->listener_index);
484 mp->listener_handle = listen_session_get_handle (listener);
485 mp->is_ip4 = session_type_is_ip4 (listener->session_type);
486 }
487 else
488 {
Florin Coras15531972018-08-12 23:50:53 -0700489 ll =
490 application_get_local_listen_session (app_wrk,
491 ls->listener_index);
Florin Coras52207f12018-07-12 14:48:06 -0700492 if (ll->transport_listener_index != ~0)
493 {
494 listener = listen_session_get (ll->transport_listener_index);
495 mp->listener_handle = listen_session_get_handle (listener);
496 }
497 else
498 {
499 mp->listener_handle = application_local_session_handle (ll);
500 }
501 mp->is_ip4 = session_type_is_ip4 (ll->listener_session_type);
502 }
503 mp->handle = application_local_session_handle (ls);
504 mp->port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700505 vpp_queue = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700506 mp->vpp_event_queue_address = pointer_to_uword (vpp_queue);
507 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700508 mp->server_event_queue_address = ls->server_evt_q;
509 }
510 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
511
512 return 0;
513}
514
515static void
516mq_send_session_disconnected_cb (stream_session_t * s)
517{
Florin Coras15531972018-08-12 23:50:53 -0700518 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700519 svm_msg_q_msg_t _msg, *msg = &_msg;
520 session_disconnected_msg_t *mp;
521 svm_msg_q_t *app_mq;
522 session_event_t *evt;
Florin Coras15531972018-08-12 23:50:53 -0700523 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -0700524
Florin Coras15531972018-08-12 23:50:53 -0700525 app = application_get (app_wrk->app_index);
526 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700527 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
528 SVM_Q_WAIT, msg);
529 svm_msg_q_unlock (app_mq);
530 evt = svm_msg_q_msg_data (app_mq, msg);
531 memset (evt, 0, sizeof (*evt));
532 evt->event_type = SESSION_CTRL_EVT_DISCONNECTED;
533 mp = (session_disconnected_msg_t *) evt->data;
534 mp->handle = session_handle (s);
535 mp->context = app->api_client_index;
536 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
537}
538
539static void
540mq_send_session_reset_cb (stream_session_t * s)
541{
Florin Coras15531972018-08-12 23:50:53 -0700542 app_worker_t *app = app_worker_get (s->app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700543 svm_msg_q_msg_t _msg, *msg = &_msg;
544 session_reset_msg_t *mp;
545 svm_msg_q_t *app_mq;
546 session_event_t *evt;
547
548 app_mq = app->event_queue;
549 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
550 SVM_Q_WAIT, msg);
551 svm_msg_q_unlock (app_mq);
552 evt = svm_msg_q_msg_data (app_mq, msg);
553 memset (evt, 0, sizeof (*evt));
554 evt->event_type = SESSION_CTRL_EVT_RESET;
555 mp = (session_reset_msg_t *) evt->data;
556 mp->handle = session_handle (s);
557 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
558}
559
560static int
Florin Coras15531972018-08-12 23:50:53 -0700561mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
Florin Coras52207f12018-07-12 14:48:06 -0700562 stream_session_t * s, u8 is_fail)
563{
564 svm_msg_q_msg_t _msg, *msg = &_msg;
565 session_connected_msg_t *mp;
566 svm_msg_q_t *vpp_mq, *app_mq;
567 transport_connection_t *tc;
Florin Coras15531972018-08-12 23:50:53 -0700568 app_worker_t *app_wrk;
Florin Coras52207f12018-07-12 14:48:06 -0700569 session_event_t *evt;
570 application_t *app;
571
Florin Coras15531972018-08-12 23:50:53 -0700572 app_wrk = app_worker_get (app_wrk_index);
573 app = application_get (app_wrk->app_index);
574 app_mq = app_wrk->event_queue;
Florin Coras52207f12018-07-12 14:48:06 -0700575 if (!app_mq)
576 {
Florin Coras15531972018-08-12 23:50:53 -0700577 clib_warning ("app %u with api index: %u not attached", app->app_index,
Florin Coras52207f12018-07-12 14:48:06 -0700578 app->api_client_index);
579 return -1;
580 }
581
582 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
583 SVM_Q_WAIT, msg);
584 svm_msg_q_unlock (app_mq);
585 evt = svm_msg_q_msg_data (app_mq, msg);
586 memset (evt, 0, sizeof (*evt));
587 evt->event_type = SESSION_CTRL_EVT_CONNECTED;
588 mp = (session_connected_msg_t *) evt->data;
589 mp->context = api_context;
590
591 if (is_fail)
592 goto done;
593
594 if (session_has_transport (s))
595 {
596 tc = session_get_transport (s);
597 if (!tc)
598 {
599 is_fail = 1;
600 goto done;
601 }
602
603 vpp_mq = session_manager_get_vpp_event_queue (s->thread_index);
604 mp->handle = session_handle (s);
605 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
606 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
607 mp->is_ip4 = tc->is_ip4;
608 mp->lcl_port = tc->lcl_port;
609 mp->server_rx_fifo = pointer_to_uword (s->server_rx_fifo);
610 mp->server_tx_fifo = pointer_to_uword (s->server_tx_fifo);
611 }
612 else
613 {
614 local_session_t *ls = (local_session_t *) s;
Florin Coras99368312018-08-02 10:45:44 -0700615 u8 main_thread = vlib_num_workers ()? 1 : 0;
616
617 send_app_cut_through_registration_add (app->api_client_index,
618 ls->client_evt_q,
619 ls->server_evt_q);
620
Florin Coras52207f12018-07-12 14:48:06 -0700621 mp->handle = application_local_session_handle (ls);
622 mp->lcl_port = ls->port;
Florin Coras99368312018-08-02 10:45:44 -0700623 vpp_mq = session_manager_get_vpp_event_queue (main_thread);
Florin Coras54693d22018-07-17 10:46:29 -0700624 mp->vpp_event_queue_address = pointer_to_uword (vpp_mq);
Florin Coras52207f12018-07-12 14:48:06 -0700625 mp->client_event_queue_address = ls->client_evt_q;
Florin Coras54693d22018-07-17 10:46:29 -0700626 mp->server_event_queue_address = ls->server_evt_q;
Florin Coras52207f12018-07-12 14:48:06 -0700627 mp->server_rx_fifo = pointer_to_uword (s->server_tx_fifo);
628 mp->server_tx_fifo = pointer_to_uword (s->server_rx_fifo);
629 }
630
631done:
632 mp->retval = is_fail ?
633 clib_host_to_net_u32 (VNET_API_ERROR_SESSION_CONNECT) : 0;
634
635 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
636 return 0;
637}
638
Florin Coras60116992018-08-27 09:52:18 -0700639static int
640mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
641 session_handle_t handle, int rv)
642{
643 svm_msg_q_msg_t _msg, *msg = &_msg;
644 svm_msg_q_t *app_mq, *vpp_evt_q;
645 transport_connection_t *tc;
646 stream_session_t *ls = 0;
647 session_bound_msg_t *mp;
648 app_worker_t *app_wrk;
649 session_event_t *evt;
650 application_t *app;
651
652 app_wrk = app_worker_get (app_wrk_index);
653 app = application_get (app_wrk->app_index);
654 app_mq = app_wrk->event_queue;
655 if (!app_mq)
656 {
657 clib_warning ("app %u with api index: %u not attached", app->app_index,
658 app->api_client_index);
659 return -1;
660 }
661
662 svm_msg_q_lock_and_alloc_msg_w_ring (app_mq, SESSION_MQ_CTRL_EVT_RING,
663 SVM_Q_WAIT, msg);
664 svm_msg_q_unlock (app_mq);
665 evt = svm_msg_q_msg_data (app_mq, msg);
666 memset (evt, 0, sizeof (*evt));
667 evt->event_type = SESSION_CTRL_EVT_BOUND;
668 mp = (session_bound_msg_t *) evt->data;
669 mp->context = api_context;
670
671 if (rv)
672 goto done;
673
674 mp->handle = handle;
675 if (application_has_global_scope (app))
676 {
677 ls = listen_session_get_from_handle (handle);
678 tc = listen_session_get_transport (ls);
679 mp->lcl_port = tc->lcl_port;
680 mp->lcl_is_ip4 = tc->is_ip4;
681 clib_memcpy (mp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
682 }
683 else
684 {
685 local_session_t *local;
686 local = application_get_local_listen_session_from_handle (handle);
687 mp->lcl_port = local->port;
688 mp->lcl_is_ip4 = session_type_is_ip4 (local->session_type);
689 }
690
691 if (ls && session_transport_service_type (ls) == TRANSPORT_SERVICE_CL)
692 {
693 mp->rx_fifo = pointer_to_uword (ls->server_rx_fifo);
694 mp->tx_fifo = pointer_to_uword (ls->server_tx_fifo);
695 vpp_evt_q = session_manager_get_vpp_event_queue (0);
696 mp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
697 }
698
699done:
700 mp->retval = rv;
701 svm_msg_q_add (app_mq, msg, SVM_Q_WAIT);
702 return 0;
703}
704
Florin Coras52207f12018-07-12 14:48:06 -0700705static session_cb_vft_t session_mq_cb_vft = {
706 .session_accept_callback = mq_send_session_accepted_cb,
707 .session_disconnect_callback = mq_send_session_disconnected_cb,
708 .session_connected_callback = mq_send_session_connected_cb,
709 .session_reset_callback = mq_send_session_reset_cb,
710 .add_segment_callback = send_add_segment_callback,
711 .del_segment_callback = send_del_segment_callback,
712};
713
Dave Barach68b0fb02017-02-28 15:15:56 -0500714static void
Florin Corase04c2992017-03-01 08:17:34 -0800715vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
716{
717 vl_api_session_enable_disable_reply_t *rmp;
718 vlib_main_t *vm = vlib_get_main ();
719 int rv = 0;
720
721 vnet_session_enable_disable (vm, mp->is_enable);
722 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
723}
724
725static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700726vl_api_application_attach_t_handler (vl_api_application_attach_t * mp)
Dave Barach68b0fb02017-02-28 15:15:56 -0500727{
Florin Coras99368312018-08-02 10:45:44 -0700728 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700729 vl_api_application_attach_reply_t *rmp;
Florin Corasb384b542018-01-15 01:08:33 -0800730 ssvm_private_t *segp, *evt_q_segment;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700731 vnet_app_attach_args_t _a, *a = &_a;
Florin Corasb384b542018-01-15 01:08:33 -0800732 vl_api_registration_t *reg;
Florin Corascea194d2017-10-02 00:18:51 -0700733 clib_error_t *error = 0;
Florin Coras99368312018-08-02 10:45:44 -0700734 u8 fd_flags = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500735
Florin Corasfc804d92018-01-26 01:27:01 -0800736 reg = vl_api_client_index_to_registration (mp->client_index);
737 if (!reg)
738 return;
739
Florin Coras6cf30ad2017-04-04 23:08:23 -0700740 if (session_manager_is_enabled () == 0)
741 {
742 rv = VNET_API_ERROR_FEATURE_DISABLED;
743 goto done;
744 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500745
Florin Corasff6e7692017-12-11 04:59:01 -0800746 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
Florin Coras6cf30ad2017-04-04 23:08:23 -0700747 sizeof (mp->options),
748 "Out of options, fix api message definition");
Dave Barach68b0fb02017-02-28 15:15:56 -0500749
750 memset (a, 0, sizeof (*a));
Dave Barach68b0fb02017-02-28 15:15:56 -0500751 a->api_client_index = mp->client_index;
752 a->options = mp->options;
Florin Coras52207f12018-07-12 14:48:06 -0700753
754 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_USE_MQ_FOR_CTRL_MSGS)
755 a->session_cb_vft = &session_mq_cb_vft;
756 else
757 a->session_cb_vft = &session_cb_vft;
Dave Barach68b0fb02017-02-28 15:15:56 -0500758
Florin Corascea194d2017-10-02 00:18:51 -0700759 if (mp->namespace_id_len > 64)
760 {
761 rv = VNET_API_ERROR_INVALID_VALUE;
762 goto done;
763 }
764
765 if (mp->namespace_id_len)
766 {
Dave Wallace8af20542017-10-26 03:29:30 -0400767 vec_validate (a->namespace_id, mp->namespace_id_len - 1);
Florin Corascea194d2017-10-02 00:18:51 -0700768 clib_memcpy (a->namespace_id, mp->namespace_id, mp->namespace_id_len);
769 }
770
771 if ((error = vnet_application_attach (a)))
772 {
773 rv = clib_error_get_code (error);
774 clib_error_report (error);
Florin Coras99368312018-08-02 10:45:44 -0700775 vec_free (a->namespace_id);
776 goto done;
Florin Corascea194d2017-10-02 00:18:51 -0700777 }
778 vec_free (a->namespace_id);
Dave Barach68b0fb02017-02-28 15:15:56 -0500779
Florin Coras99368312018-08-02 10:45:44 -0700780 /* Send event queues segment */
781 if ((evt_q_segment = session_manager_get_evt_q_segment ()))
782 {
783 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
784 fds[n_fds] = evt_q_segment->fd;
785 n_fds += 1;
786 }
787 /* Send fifo segment fd if needed */
788 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
789 {
790 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
791 fds[n_fds] = a->segment->fd;
792 n_fds += 1;
793 }
794 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
795 {
796 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
797 fds[n_fds] = svm_msg_q_get_producer_eventfd (a->app_evt_q);
798 n_fds += 1;
799 }
800
Florin Coras6cf30ad2017-04-04 23:08:23 -0700801done:
Florin Corasa5464812017-04-19 13:00:05 -0700802
Dave Barach68b0fb02017-02-28 15:15:56 -0500803 /* *INDENT-OFF* */
Florin Coras6cf30ad2017-04-04 23:08:23 -0700804 REPLY_MACRO2 (VL_API_APPLICATION_ATTACH_REPLY, ({
Dave Barach68b0fb02017-02-28 15:15:56 -0500805 if (!rv)
806 {
Florin Corasb384b542018-01-15 01:08:33 -0800807 segp = a->segment;
Dave Barach68b0fb02017-02-28 15:15:56 -0500808 rmp->segment_name_length = 0;
Florin Corasb384b542018-01-15 01:08:33 -0800809 rmp->segment_size = segp->ssvm_size;
810 if (vec_len (segp->name))
Dave Barach68b0fb02017-02-28 15:15:56 -0500811 {
Florin Corasb384b542018-01-15 01:08:33 -0800812 memcpy (rmp->segment_name, segp->name, vec_len (segp->name));
813 rmp->segment_name_length = vec_len (segp->name);
Dave Barach68b0fb02017-02-28 15:15:56 -0500814 }
Florin Coras99368312018-08-02 10:45:44 -0700815 rmp->app_event_queue_address = pointer_to_uword (a->app_evt_q);
816 rmp->n_fds = n_fds;
817 rmp->fd_flags = fd_flags;
Dave Barach68b0fb02017-02-28 15:15:56 -0500818 }
819 }));
820 /* *INDENT-ON* */
Florin Corasb384b542018-01-15 01:08:33 -0800821
Florin Coras99368312018-08-02 10:45:44 -0700822 if (n_fds)
823 session_send_fds (reg, fds, n_fds);
Dave Barach68b0fb02017-02-28 15:15:56 -0500824}
825
826static void
Florin Coras6cf30ad2017-04-04 23:08:23 -0700827vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
828{
829 vl_api_application_detach_reply_t *rmp;
830 int rv = VNET_API_ERROR_INVALID_VALUE_2;
831 vnet_app_detach_args_t _a, *a = &_a;
832 application_t *app;
833
834 if (session_manager_is_enabled () == 0)
835 {
836 rv = VNET_API_ERROR_FEATURE_DISABLED;
837 goto done;
838 }
839
840 app = application_lookup (mp->client_index);
841 if (app)
842 {
Florin Coras15531972018-08-12 23:50:53 -0700843 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700844 rv = vnet_application_detach (a);
845 }
846
847done:
848 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
849}
850
851static void
852vl_api_bind_uri_t_handler (vl_api_bind_uri_t * mp)
853{
Florin Coras7fb0fe12018-04-09 09:24:52 -0700854 transport_connection_t *tc = 0;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700855 vnet_bind_args_t _a, *a = &_a;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700856 vl_api_bind_uri_reply_t *rmp;
857 stream_session_t *s;
858 application_t *app = 0;
Florin Coras3c2fed52018-07-04 04:15:05 -0700859 svm_msg_q_t *vpp_evt_q;
Florin Coras60116992018-08-27 09:52:18 -0700860 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700861 int rv;
862
863 if (session_manager_is_enabled () == 0)
864 {
865 rv = VNET_API_ERROR_FEATURE_DISABLED;
866 goto done;
867 }
868
869 app = application_lookup (mp->client_index);
870 if (app)
871 {
872 memset (a, 0, sizeof (*a));
873 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700874 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700875 rv = vnet_bind_uri (a);
876 }
877 else
878 {
879 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
880 }
881
882done:
Florin Coras7fb0fe12018-04-09 09:24:52 -0700883
884 /* *INDENT-OFF* */
885 REPLY_MACRO2 (VL_API_BIND_URI_REPLY, ({
886 if (!rv)
887 {
888 rmp->handle = a->handle;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700889 if (app && application_has_global_scope (app))
890 {
891 s = listen_session_get_from_handle (a->handle);
892 tc = listen_session_get_transport (s);
Florin Coras6c354942018-04-18 00:05:21 -0700893 rmp->lcl_is_ip4 = tc->is_ip4;
894 rmp->lcl_port = tc->lcl_port;
Florin Coras7fb0fe12018-04-09 09:24:52 -0700895 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof(tc->lcl_ip));
896 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
897 {
898 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
899 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
900 vpp_evt_q = session_manager_get_vpp_event_queue (0);
901 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
902 }
903 }
904 }
905 }));
906 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -0700907
908 /* If app uses mq for control messages, send an mq message as well */
909 if (app && application_use_mq_for_ctrl (app))
910 {
911 app_wrk = application_get_worker (app, 0);
912 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
913 rv);
914 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700915}
916
917static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500918vl_api_unbind_uri_t_handler (vl_api_unbind_uri_t * mp)
919{
920 vl_api_unbind_uri_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700921 application_t *app;
922 vnet_unbind_args_t _a, *a = &_a;
Dave Barach68b0fb02017-02-28 15:15:56 -0500923 int rv;
924
Florin Coras6cf30ad2017-04-04 23:08:23 -0700925 if (session_manager_is_enabled () == 0)
926 {
927 rv = VNET_API_ERROR_FEATURE_DISABLED;
928 goto done;
929 }
Dave Barach68b0fb02017-02-28 15:15:56 -0500930
Florin Coras6cf30ad2017-04-04 23:08:23 -0700931 app = application_lookup (mp->client_index);
932 if (app)
933 {
934 a->uri = (char *) mp->uri;
Florin Coras15531972018-08-12 23:50:53 -0700935 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700936 rv = vnet_unbind_uri (a);
937 }
938 else
939 {
940 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
941 }
942
943done:
Dave Barach68b0fb02017-02-28 15:15:56 -0500944 REPLY_MACRO (VL_API_UNBIND_URI_REPLY);
945}
946
Florin Corasf03a59a2017-06-09 21:07:32 -0700947static void
Dave Barach68b0fb02017-02-28 15:15:56 -0500948vl_api_connect_uri_t_handler (vl_api_connect_uri_t * mp)
949{
Dave Wallace33e002b2017-09-06 01:20:02 -0400950 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -0500951 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700952 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -0700953 clib_error_t *error = 0;
954 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -0500955
Florin Coras6cf30ad2017-04-04 23:08:23 -0700956 if (session_manager_is_enabled () == 0)
957 {
958 rv = VNET_API_ERROR_FEATURE_DISABLED;
959 goto done;
960 }
Florin Corase04c2992017-03-01 08:17:34 -0800961
Florin Coras6cf30ad2017-04-04 23:08:23 -0700962 app = application_lookup (mp->client_index);
963 if (app)
964 {
965 a->uri = (char *) mp->uri;
966 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -0700967 a->app_index = app->app_index;
Florin Corascea194d2017-10-02 00:18:51 -0700968 if ((error = vnet_connect_uri (a)))
969 {
970 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -0800971 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -0700972 }
Florin Coras6cf30ad2017-04-04 23:08:23 -0700973 }
974 else
975 {
976 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
977 }
Florin Corase04c2992017-03-01 08:17:34 -0800978
Florin Coras3cbc04b2017-10-02 00:18:51 -0700979 /*
980 * Don't reply to stream (tcp) connects. The reply will come once
981 * the connection is established. In case of the redirects, the reply
982 * will come from the server app.
983 */
Florin Coras8f89dd02018-03-05 16:53:07 -0800984 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -0800985 return;
986
Florin Coras6cf30ad2017-04-04 23:08:23 -0700987done:
Florin Corase04c2992017-03-01 08:17:34 -0800988 /* *INDENT-OFF* */
Dave Wallace33e002b2017-09-06 01:20:02 -0400989 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Florin Corase04c2992017-03-01 08:17:34 -0800990 /* *INDENT-ON* */
Dave Barach68b0fb02017-02-28 15:15:56 -0500991}
992
993static void
994vl_api_disconnect_session_t_handler (vl_api_disconnect_session_t * mp)
995{
996 vl_api_disconnect_session_reply_t *rmp;
Florin Coras6cf30ad2017-04-04 23:08:23 -0700997 vnet_disconnect_args_t _a, *a = &_a;
998 application_t *app;
999 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001000
Florin Coras6cf30ad2017-04-04 23:08:23 -07001001 if (session_manager_is_enabled () == 0)
1002 {
1003 rv = VNET_API_ERROR_FEATURE_DISABLED;
1004 goto done;
1005 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001006
Florin Coras6cf30ad2017-04-04 23:08:23 -07001007 app = application_lookup (mp->client_index);
1008 if (app)
1009 {
1010 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001011 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001012 rv = vnet_disconnect_session (a);
1013 }
1014 else
1015 {
1016 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1017 }
1018
1019done:
Dave Wallacede5fec92017-11-11 22:41:34 -05001020 REPLY_MACRO2 (VL_API_DISCONNECT_SESSION_REPLY, rmp->handle = mp->handle);
Dave Barach68b0fb02017-02-28 15:15:56 -05001021}
1022
1023static void
1024vl_api_disconnect_session_reply_t_handler (vl_api_disconnect_session_reply_t *
1025 mp)
1026{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001027 vnet_disconnect_args_t _a, *a = &_a;
1028 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001029
1030 /* Client objected to disconnecting the session, log and continue */
1031 if (mp->retval)
1032 {
1033 clib_warning ("client retval %d", mp->retval);
1034 return;
1035 }
1036
1037 /* Disconnect has been confirmed. Confirm close to transport */
Florin Corasf8f516a2018-02-08 15:10:09 -08001038 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001039 if (app)
1040 {
1041 a->handle = mp->handle;
Florin Coras15531972018-08-12 23:50:53 -07001042 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001043 vnet_disconnect_session (a);
1044 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001045}
1046
1047static void
1048vl_api_reset_session_reply_t_handler (vl_api_reset_session_reply_t * mp)
1049{
Florin Coras15531972018-08-12 23:50:53 -07001050 app_worker_t *app_wrk;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001051 application_t *app;
Dave Barach68b0fb02017-02-28 15:15:56 -05001052 stream_session_t *s;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001053 u32 index, thread_index;
Dave Barach68b0fb02017-02-28 15:15:56 -05001054
Ondrej Fabry6bd197e2018-08-15 08:46:46 +02001055 app = application_lookup (mp->context);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001056 if (!app)
1057 return;
1058
Florin Corascea194d2017-10-02 00:18:51 -07001059 session_parse_handle (mp->handle, &index, &thread_index);
Florin Coras3cbc04b2017-10-02 00:18:51 -07001060 s = session_get_if_valid (index, thread_index);
Florin Coras15531972018-08-12 23:50:53 -07001061 if (!s)
Dave Barach68b0fb02017-02-28 15:15:56 -05001062 {
1063 clib_warning ("Invalid session!");
1064 return;
1065 }
1066
Florin Coras15531972018-08-12 23:50:53 -07001067 app_wrk = app_worker_get (s->app_wrk_index);
1068 if (app_wrk->app_index != app->app_index)
1069 {
1070 clib_warning ("app %u does not own handle 0x%lx", app->app_index,
1071 mp->handle);
1072 return;
1073 }
1074
Dave Barach68b0fb02017-02-28 15:15:56 -05001075 /* Client objected to resetting the session, log and continue */
1076 if (mp->retval)
1077 {
1078 clib_warning ("client retval %d", mp->retval);
1079 return;
1080 }
1081
Dave Barach68b0fb02017-02-28 15:15:56 -05001082 /* This comes as a response to a reset, transport only waiting for
1083 * confirmation to remove connection state, no need to disconnect */
1084 stream_session_cleanup (s);
1085}
1086
1087static void
1088vl_api_accept_session_reply_t_handler (vl_api_accept_session_reply_t * mp)
1089{
Florin Corasf8f516a2018-02-08 15:10:09 -08001090 vnet_disconnect_args_t _a = { 0 }, *a = &_a;
1091 local_session_t *ls;
Dave Barach68b0fb02017-02-28 15:15:56 -05001092 stream_session_t *s;
Dave Barach68b0fb02017-02-28 15:15:56 -05001093
Florin Corasa5464812017-04-19 13:00:05 -07001094 /* Server isn't interested, kill the session */
1095 if (mp->retval)
Dave Barach68b0fb02017-02-28 15:15:56 -05001096 {
Florin Corasa5464812017-04-19 13:00:05 -07001097 a->app_index = mp->context;
1098 a->handle = mp->handle;
1099 vnet_disconnect_session (a);
Florin Corasf8f516a2018-02-08 15:10:09 -08001100 return;
1101 }
1102
1103 if (session_handle_is_local (mp->handle))
1104 {
1105 ls = application_get_local_session_from_handle (mp->handle);
Florin Coras15531972018-08-12 23:50:53 -07001106 if (!ls || ls->app_wrk_index != mp->context)
Florin Corasf8f516a2018-02-08 15:10:09 -08001107 {
1108 clib_warning ("server %u doesn't own local handle %llu",
1109 mp->context, mp->handle);
1110 return;
1111 }
1112 if (application_local_session_connect_notify (ls))
1113 return;
1114 ls->session_state = SESSION_STATE_READY;
Dave Barach68b0fb02017-02-28 15:15:56 -05001115 }
Florin Corasa5464812017-04-19 13:00:05 -07001116 else
1117 {
Florin Corasf8f516a2018-02-08 15:10:09 -08001118 s = session_get_from_handle_if_valid (mp->handle);
Florin Corasa5464812017-04-19 13:00:05 -07001119 if (!s)
1120 {
1121 clib_warning ("session doesn't exist");
1122 return;
1123 }
Florin Coras15531972018-08-12 23:50:53 -07001124 if (s->app_wrk_index != mp->context)
Florin Corasa5464812017-04-19 13:00:05 -07001125 {
1126 clib_warning ("app doesn't own session");
1127 return;
1128 }
Florin Corasa5464812017-04-19 13:00:05 -07001129 s->session_state = SESSION_STATE_READY;
1130 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001131}
1132
1133static void
1134vl_api_map_another_segment_reply_t_handler (vl_api_map_another_segment_reply_t
1135 * mp)
1136{
1137 clib_warning ("not implemented");
1138}
1139
1140static void
1141vl_api_bind_sock_t_handler (vl_api_bind_sock_t * mp)
1142{
1143 vl_api_bind_sock_reply_t *rmp;
1144 vnet_bind_args_t _a, *a = &_a;
Florin Corascea194d2017-10-02 00:18:51 -07001145 int rv = 0;
1146 clib_error_t *error;
Florin Coraseb2945c2017-11-22 10:39:09 -08001147 application_t *app = 0;
Florin Coras60116992018-08-27 09:52:18 -07001148 app_worker_t *app_wrk;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001149 stream_session_t *s;
1150 transport_connection_t *tc = 0;
1151 ip46_address_t *ip46;
Florin Coras3c2fed52018-07-04 04:15:05 -07001152 svm_msg_q_t *vpp_evt_q;
Dave Barach68b0fb02017-02-28 15:15:56 -05001153
Florin Coras6cf30ad2017-04-04 23:08:23 -07001154 if (session_manager_is_enabled () == 0)
1155 {
1156 rv = VNET_API_ERROR_FEATURE_DISABLED;
1157 goto done;
1158 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001159
Florin Coras6cf30ad2017-04-04 23:08:23 -07001160 app = application_lookup (mp->client_index);
Florin Corasdcf55ce2017-11-16 15:32:50 -08001161 if (!app)
Florin Coras6cf30ad2017-04-04 23:08:23 -07001162 {
Florin Corasdcf55ce2017-11-16 15:32:50 -08001163 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1164 goto done;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001165 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001166
1167 ip46 = (ip46_address_t *) mp->ip;
1168 memset (a, 0, sizeof (*a));
1169 a->sep.is_ip4 = mp->is_ip4;
1170 a->sep.ip = *ip46;
1171 a->sep.port = mp->port;
1172 a->sep.fib_index = mp->vrf;
1173 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
1174 a->sep.transport_proto = mp->proto;
Florin Coras15531972018-08-12 23:50:53 -07001175 a->app_index = app->app_index;
1176 a->wrk_map_index = mp->wrk_index;
Florin Corasdcf55ce2017-11-16 15:32:50 -08001177
1178 if ((error = vnet_bind (a)))
1179 {
1180 rv = clib_error_get_code (error);
1181 clib_error_report (error);
1182 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001183
Florin Coras6cf30ad2017-04-04 23:08:23 -07001184done:
Florin Corascea194d2017-10-02 00:18:51 -07001185 /* *INDENT-OFF* */
1186 REPLY_MACRO2 (VL_API_BIND_SOCK_REPLY,({
1187 if (!rv)
Florin Corasdcf55ce2017-11-16 15:32:50 -08001188 {
1189 rmp->handle = a->handle;
Florin Coraseb2945c2017-11-22 10:39:09 -08001190 rmp->lcl_port = mp->port;
Keith Burns (alagalah)60ae80f2018-03-15 10:04:20 -07001191 rmp->lcl_is_ip4 = mp->is_ip4;
Dave Wallace97b1a272017-12-18 13:51:59 -05001192 if (app && application_has_global_scope (app))
Florin Coraseb2945c2017-11-22 10:39:09 -08001193 {
1194 s = listen_session_get_from_handle (a->handle);
1195 tc = listen_session_get_transport (s);
Florin Coraseb2945c2017-11-22 10:39:09 -08001196 clib_memcpy (rmp->lcl_ip, &tc->lcl_ip, sizeof (tc->lcl_ip));
Florin Coras7fb0fe12018-04-09 09:24:52 -07001197 if (session_transport_service_type (s) == TRANSPORT_SERVICE_CL)
1198 {
1199 rmp->rx_fifo = pointer_to_uword (s->server_rx_fifo);
1200 rmp->tx_fifo = pointer_to_uword (s->server_tx_fifo);
1201 vpp_evt_q = session_manager_get_vpp_event_queue (0);
1202 rmp->vpp_evt_q = pointer_to_uword (vpp_evt_q);
1203 }
Florin Coraseb2945c2017-11-22 10:39:09 -08001204 }
Florin Corasdcf55ce2017-11-16 15:32:50 -08001205 }
Florin Corascea194d2017-10-02 00:18:51 -07001206 }));
1207 /* *INDENT-ON* */
Florin Coras60116992018-08-27 09:52:18 -07001208
1209 /* If app uses mq for control messages, send an mq message as well */
1210 if (app && application_use_mq_for_ctrl (app))
1211 {
1212 app_wrk = application_get_worker (app, mp->wrk_index);
1213 mq_send_session_bound_cb (app_wrk->wrk_index, mp->context, a->handle,
1214 rv);
1215 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001216}
1217
1218static void
1219vl_api_unbind_sock_t_handler (vl_api_unbind_sock_t * mp)
1220{
1221 vl_api_unbind_sock_reply_t *rmp;
1222 vnet_unbind_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001223 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -07001224 clib_error_t *error;
1225 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001226
Florin Coras6cf30ad2017-04-04 23:08:23 -07001227 if (session_manager_is_enabled () == 0)
1228 {
1229 rv = VNET_API_ERROR_FEATURE_DISABLED;
1230 goto done;
1231 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001232
Florin Coras6cf30ad2017-04-04 23:08:23 -07001233 app = application_lookup (mp->client_index);
1234 if (app)
1235 {
Florin Coras15531972018-08-12 23:50:53 -07001236 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001237 a->handle = mp->handle;
Florin Corascea194d2017-10-02 00:18:51 -07001238 if ((error = vnet_unbind (a)))
1239 {
1240 rv = clib_error_get_code (error);
1241 clib_error_report (error);
1242 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001243 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001244
Florin Coras6cf30ad2017-04-04 23:08:23 -07001245done:
Dave Barach68b0fb02017-02-28 15:15:56 -05001246 REPLY_MACRO (VL_API_UNBIND_SOCK_REPLY);
1247}
1248
1249static void
1250vl_api_connect_sock_t_handler (vl_api_connect_sock_t * mp)
1251{
Dave Wallace33e002b2017-09-06 01:20:02 -04001252 vl_api_connect_session_reply_t *rmp;
Dave Barach68b0fb02017-02-28 15:15:56 -05001253 vnet_connect_args_t _a, *a = &_a;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001254 application_t *app;
Florin Corascea194d2017-10-02 00:18:51 -07001255 clib_error_t *error = 0;
1256 int rv = 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001257
Florin Coras6cf30ad2017-04-04 23:08:23 -07001258 if (session_manager_is_enabled () == 0)
1259 {
1260 rv = VNET_API_ERROR_FEATURE_DISABLED;
1261 goto done;
1262 }
Dave Barach68b0fb02017-02-28 15:15:56 -05001263
Florin Coras6cf30ad2017-04-04 23:08:23 -07001264 app = application_lookup (mp->client_index);
1265 if (app)
1266 {
Florin Corase86a8ed2018-01-05 03:20:25 -08001267 svm_queue_t *client_q;
Dave Wallace33e002b2017-09-06 01:20:02 -04001268 ip46_address_t *ip46 = (ip46_address_t *) mp->ip;
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001269
Florin Coras8f89dd02018-03-05 16:53:07 -08001270 memset (a, 0, sizeof (*a));
Dave Wallaceb2d5ff32017-06-14 12:38:28 -04001271 client_q = vl_api_client_index_to_input_queue (mp->client_index);
1272 mp->client_queue_address = pointer_to_uword (client_q);
Florin Corascea194d2017-10-02 00:18:51 -07001273 a->sep.is_ip4 = mp->is_ip4;
1274 a->sep.ip = *ip46;
1275 a->sep.port = mp->port;
1276 a->sep.transport_proto = mp->proto;
1277 a->sep.fib_index = mp->vrf;
1278 a->sep.sw_if_index = ENDPOINT_INVALID_INDEX;
Florin Coras8f89dd02018-03-05 16:53:07 -08001279 if (mp->hostname_len)
1280 {
Florin Coras15531972018-08-12 23:50:53 -07001281 vec_validate (a->sep_ext.hostname, mp->hostname_len - 1);
1282 clib_memcpy (a->sep_ext.hostname, mp->hostname, mp->hostname_len);
Florin Coras8f89dd02018-03-05 16:53:07 -08001283 }
Florin Coras6cf30ad2017-04-04 23:08:23 -07001284 a->api_context = mp->context;
Florin Coras15531972018-08-12 23:50:53 -07001285 a->app_index = app->app_index;
1286 a->wrk_map_index = mp->wrk_index;
Florin Corascea194d2017-10-02 00:18:51 -07001287 if ((error = vnet_connect (a)))
1288 {
1289 rv = clib_error_get_code (error);
Florin Coras8f89dd02018-03-05 16:53:07 -08001290 clib_error_report (error);
Florin Corascea194d2017-10-02 00:18:51 -07001291 }
Florin Coras15531972018-08-12 23:50:53 -07001292 vec_free (a->sep_ext.hostname);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001293 }
1294 else
1295 {
1296 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1297 }
Florin Corase04c2992017-03-01 08:17:34 -08001298
Florin Coras8f89dd02018-03-05 16:53:07 -08001299 if (rv == 0)
Florin Corase04c2992017-03-01 08:17:34 -08001300 return;
1301
1302 /* Got some error, relay it */
1303
Florin Coras6cf30ad2017-04-04 23:08:23 -07001304done:
Dave Wallace33e002b2017-09-06 01:20:02 -04001305 REPLY_MACRO (VL_API_CONNECT_SESSION_REPLY);
Dave Barach68b0fb02017-02-28 15:15:56 -05001306}
1307
Florin Corascea194d2017-10-02 00:18:51 -07001308static void
Florin Coras15531972018-08-12 23:50:53 -07001309vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
1310{
1311 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1312 vl_api_app_worker_add_del_reply_t *rmp;
1313 vl_api_registration_t *reg;
1314 clib_error_t *error = 0;
1315 application_t *app;
1316 u8 fd_flags = 0;
1317
1318 if (!session_manager_is_enabled ())
1319 {
1320 rv = VNET_API_ERROR_FEATURE_DISABLED;
1321 goto done;
1322 }
1323
1324 reg = vl_api_client_index_to_registration (mp->client_index);
1325 if (!reg)
1326 return;
1327
1328 app = application_lookup (mp->app_api_index);
1329 if (!app)
1330 {
1331 rv = VNET_API_ERROR_INVALID_VALUE;
1332 goto done;
1333 }
1334
1335 vnet_app_worker_add_del_args_t args = {
1336 .app_index = app->app_index,
1337 .wrk_index = clib_net_to_host_u32 (mp->wrk_index),
1338 .is_add = mp->is_add
1339 };
1340 error = vnet_app_worker_add_del (&args);
1341 if (error)
1342 {
1343 rv = clib_error_get_code (error);
1344 clib_error_report (error);
1345 goto done;
1346 }
1347
Florin Corasc3638fe2018-08-24 13:58:49 -07001348 /* Make coverity happy */
1349 ASSERT (args.evt_q && args.segment);
1350
Florin Coras15531972018-08-12 23:50:53 -07001351 /* Send fifo segment fd if needed */
1352 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1353 {
1354 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1355 fds[n_fds] = args.segment->fd;
1356 n_fds += 1;
1357 }
1358 if (application_segment_manager_properties (app)->use_mq_eventfd)
1359 {
1360 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
1361 fds[n_fds] = svm_msg_q_get_producer_eventfd (args.evt_q);
1362 n_fds += 1;
1363 }
1364
1365 /* *INDENT-OFF* */
1366done:
1367 REPLY_MACRO2 (VL_API_APP_WORKER_ADD_DEL_REPLY, ({
1368 rmp->is_add = mp->is_add;
1369 if (!rv)
1370 {
1371 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_index);
1372 if (vec_len (args.segment->name))
1373 {
1374 memcpy (rmp->segment_name, args.segment->name,
1375 vec_len (args.segment->name));
1376 rmp->segment_name_length = vec_len (args.segment->name);
1377 }
1378 rmp->app_event_queue_address = pointer_to_uword (args.evt_q);
1379 rmp->n_fds = n_fds;
1380 rmp->fd_flags = fd_flags;
1381 }
1382 }));
1383 /* *INDENT-ON* */
1384
1385 if (n_fds)
1386 session_send_fds (reg, fds, n_fds);
1387}
1388
1389static void
Florin Corascea194d2017-10-02 00:18:51 -07001390vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
1391{
1392 vl_api_app_namespace_add_del_reply_t *rmp;
Florin Corascea194d2017-10-02 00:18:51 -07001393 clib_error_t *error = 0;
Florin Coras6e8c6672017-11-10 09:03:54 -08001394 u32 appns_index = 0;
1395 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -07001396 int rv = 0;
1397 if (!session_manager_is_enabled ())
1398 {
1399 rv = VNET_API_ERROR_FEATURE_DISABLED;
1400 goto done;
1401 }
1402
1403 if (mp->namespace_id_len > ARRAY_LEN (mp->namespace_id))
1404 {
1405 rv = VNET_API_ERROR_INVALID_VALUE;
1406 goto done;
1407 }
1408
1409 vec_validate (ns_id, mp->namespace_id_len - 1);
1410 clib_memcpy (ns_id, mp->namespace_id, mp->namespace_id_len);
1411 vnet_app_namespace_add_del_args_t args = {
1412 .ns_id = ns_id,
Florin Coras9a9adb22017-10-26 08:16:59 -07001413 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -07001414 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
1415 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
1416 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
1417 .is_add = 1
1418 };
1419 error = vnet_app_namespace_add_del (&args);
1420 if (error)
1421 {
1422 rv = clib_error_get_code (error);
1423 clib_error_report (error);
1424 }
Florin Coras6e8c6672017-11-10 09:03:54 -08001425 else
1426 {
1427 appns_index = app_namespace_index_from_id (ns_id);
1428 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
1429 {
1430 clib_warning ("app ns lookup failed");
1431 rv = VNET_API_ERROR_UNSPECIFIED;
1432 }
1433 }
Florin Corascea194d2017-10-02 00:18:51 -07001434 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -08001435
1436 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -07001437done:
Florin Coras6e8c6672017-11-10 09:03:54 -08001438 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
1439 if (!rv)
1440 rmp->appns_index = clib_host_to_net_u32 (appns_index);
1441 }));
1442 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -07001443}
1444
Florin Coras1c710452017-10-17 00:03:13 -07001445static void
1446vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
1447{
1448 vl_api_session_rule_add_del_reply_t *rmp;
1449 session_rule_add_del_args_t args;
1450 session_rule_table_add_del_args_t *table_args = &args.table_args;
1451 clib_error_t *error;
1452 u8 fib_proto;
1453 int rv = 0;
1454
Florin Corasc97a7392017-11-05 23:07:07 -08001455 memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -07001456 fib_proto = mp->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
1457
1458 table_args->lcl.fp_len = mp->lcl_plen;
1459 table_args->lcl.fp_proto = fib_proto;
1460 table_args->rmt.fp_len = mp->rmt_plen;
1461 table_args->rmt.fp_proto = fib_proto;
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001462 table_args->lcl_port = mp->lcl_port;
1463 table_args->rmt_port = mp->rmt_port;
Florin Coras1c710452017-10-17 00:03:13 -07001464 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
1465 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -08001466 mp->tag[sizeof (mp->tag) - 1] = 0;
1467 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001468 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
1469 args.scope = mp->scope;
Florin Coras42324ad2017-11-18 18:45:20 -08001470 args.transport_proto = mp->transport_proto;
Florin Coras1c710452017-10-17 00:03:13 -07001471
1472 memset (&table_args->lcl.fp_addr, 0, sizeof (table_args->lcl.fp_addr));
1473 memset (&table_args->rmt.fp_addr, 0, sizeof (table_args->rmt.fp_addr));
1474 ip_set (&table_args->lcl.fp_addr, mp->lcl_ip, mp->is_ip4);
1475 ip_set (&table_args->rmt.fp_addr, mp->rmt_ip, mp->is_ip4);
1476 error = vnet_session_rule_add_del (&args);
1477 if (error)
1478 {
1479 rv = clib_error_get_code (error);
1480 clib_error_report (error);
1481 }
Florin Corasc97a7392017-11-05 23:07:07 -08001482 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -07001483 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
1484}
1485
Florin Coras6c36f532017-11-03 18:32:34 -07001486static void
1487send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -08001488 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001489 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001490{
1491 vl_api_session_rules_details_t *rmp = 0;
1492 session_mask_or_match_4_t *match =
1493 (session_mask_or_match_4_t *) & rule->match;
1494 session_mask_or_match_4_t *mask =
1495 (session_mask_or_match_4_t *) & rule->mask;
1496
1497 rmp = vl_msg_api_alloc (sizeof (*rmp));
1498 memset (rmp, 0, sizeof (*rmp));
1499 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1500 rmp->context = context;
1501
1502 rmp->is_ip4 = 1;
1503 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1504 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1505 rmp->lcl_plen = ip4_mask_to_preflen (&mask->lcl_ip);
1506 rmp->rmt_plen = ip4_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001507 rmp->lcl_port = match->lcl_port;
1508 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001509 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
1510 rmp->scope =
1511 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
1512 rmp->transport_proto = transport_proto;
1513 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001514 if (tag)
1515 {
1516 clib_memcpy (rmp->tag, tag, vec_len (tag));
1517 rmp->tag[vec_len (tag)] = 0;
1518 }
Florin Coras6c36f532017-11-03 18:32:34 -07001519
Florin Coras6c4dae22018-01-09 06:39:23 -08001520 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001521}
1522
1523static void
Florin Corasc97a7392017-11-05 23:07:07 -08001524send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
1525 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001526 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001527{
1528 vl_api_session_rules_details_t *rmp = 0;
1529 session_mask_or_match_6_t *match =
1530 (session_mask_or_match_6_t *) & rule->match;
1531 session_mask_or_match_6_t *mask =
1532 (session_mask_or_match_6_t *) & rule->mask;
1533
1534 rmp = vl_msg_api_alloc (sizeof (*rmp));
1535 memset (rmp, 0, sizeof (*rmp));
1536 rmp->_vl_msg_id = ntohs (VL_API_SESSION_RULES_DETAILS);
1537 rmp->context = context;
1538
1539 rmp->is_ip4 = 0;
1540 clib_memcpy (rmp->lcl_ip, &match->lcl_ip, sizeof (match->lcl_ip));
1541 clib_memcpy (rmp->rmt_ip, &match->rmt_ip, sizeof (match->rmt_ip));
1542 rmp->lcl_plen = ip6_mask_to_preflen (&mask->lcl_ip);
1543 rmp->rmt_plen = ip6_mask_to_preflen (&mask->rmt_ip);
Milan Lenco8b9a5d12017-11-24 17:12:33 +01001544 rmp->lcl_port = match->lcl_port;
1545 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -07001546 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001547 rmp->scope =
1548 is_local ? SESSION_RULE_SCOPE_LOCAL : SESSION_RULE_SCOPE_GLOBAL;
Florin Coras6c36f532017-11-03 18:32:34 -07001549 rmp->transport_proto = transport_proto;
1550 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -08001551 if (tag)
1552 {
1553 clib_memcpy (rmp->tag, tag, vec_len (tag));
1554 rmp->tag[vec_len (tag)] = 0;
1555 }
Florin Coras6c36f532017-11-03 18:32:34 -07001556
Florin Coras6c4dae22018-01-09 06:39:23 -08001557 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -07001558}
1559
1560static void
1561send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -08001562 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c4dae22018-01-09 06:39:23 -08001563 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -07001564{
1565 mma_rule_16_t *rule16;
1566 mma_rule_40_t *rule40;
1567 mma_rules_table_16_t *srt16;
1568 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -08001569 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -07001570
Florin Corasc97a7392017-11-05 23:07:07 -08001571 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -07001572 {
Florin Corasc97a7392017-11-05 23:07:07 -08001573 u8 *tag = 0;
1574 /* *INDENT-OFF* */
1575 srt16 = &srt->session_rules_tables_16;
1576 pool_foreach (rule16, srt16->rules, ({
1577 ri = mma_rules_table_rule_index_16 (srt16, rule16);
1578 tag = session_rules_table_rule_tag (srt, ri, 1);
1579 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001580 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001581 }));
1582 /* *INDENT-ON* */
1583 }
1584 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
1585 {
1586 u8 *tag = 0;
1587 /* *INDENT-OFF* */
1588 srt40 = &srt->session_rules_tables_40;
1589 pool_foreach (rule40, srt40->rules, ({
1590 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1591 tag = session_rules_table_rule_tag (srt, ri, 1);
1592 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001593 reg, context);
Florin Corasc97a7392017-11-05 23:07:07 -08001594 }));
1595 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -07001596 }
1597}
1598
1599static void
1600vl_api_session_rules_dump_t_handler (vl_api_one_map_server_dump_t * mp)
1601{
Florin Coras6c4dae22018-01-09 06:39:23 -08001602 vl_api_registration_t *reg;
Florin Coras6c36f532017-11-03 18:32:34 -07001603 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -08001604 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -07001605
Florin Coras6c4dae22018-01-09 06:39:23 -08001606 reg = vl_api_client_index_to_registration (mp->client_index);
1607 if (!reg)
Florin Coras6c36f532017-11-03 18:32:34 -07001608 return;
1609
1610 /* *INDENT-OFF* */
1611 session_table_foreach (st, ({
Florin Corasc97a7392017-11-05 23:07:07 -08001612 for (tp = 0; tp < TRANSPORT_N_PROTO; tp++)
1613 {
1614 send_session_rules_table_details (&st->session_rules[tp],
1615 st->active_fib_proto, tp,
Florin Coras6c4dae22018-01-09 06:39:23 -08001616 st->is_local, st->appns_index, reg,
Florin Corasc97a7392017-11-05 23:07:07 -08001617 mp->context);
1618 }
Florin Coras6c36f532017-11-03 18:32:34 -07001619 }));
1620 /* *INDENT-ON* */
1621}
1622
Florin Coras371ca502018-02-21 12:07:41 -08001623static void
1624vl_api_application_tls_cert_add_t_handler (vl_api_application_tls_cert_add_t *
1625 mp)
1626{
1627 vl_api_app_namespace_add_del_reply_t *rmp;
1628 vnet_app_add_tls_cert_args_t _a, *a = &_a;
1629 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001630 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001631 u32 cert_len;
1632 int rv = 0;
1633 if (!session_manager_is_enabled ())
1634 {
1635 rv = VNET_API_ERROR_FEATURE_DISABLED;
1636 goto done;
1637 }
Florin Corase3e2f072018-03-04 07:24:30 -08001638 if (!(app = application_lookup (mp->client_index)))
1639 {
1640 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1641 goto done;
1642 }
Florin Coras371ca502018-02-21 12:07:41 -08001643 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001644 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001645 cert_len = clib_net_to_host_u16 (mp->cert_len);
Florin Coras5090c572018-03-18 08:22:17 -07001646 if (cert_len > 10000)
1647 {
1648 rv = VNET_API_ERROR_INVALID_VALUE;
1649 goto done;
1650 }
Florin Coras371ca502018-02-21 12:07:41 -08001651 vec_validate (a->cert, cert_len);
1652 clib_memcpy (a->cert, mp->cert, cert_len);
1653 if ((error = vnet_app_add_tls_cert (a)))
1654 {
1655 rv = clib_error_get_code (error);
1656 clib_error_report (error);
1657 }
1658 vec_free (a->cert);
1659done:
1660 REPLY_MACRO (VL_API_APPLICATION_TLS_CERT_ADD_REPLY);
1661}
1662
1663static void
1664vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *
1665 mp)
1666{
1667 vl_api_app_namespace_add_del_reply_t *rmp;
1668 vnet_app_add_tls_key_args_t _a, *a = &_a;
1669 clib_error_t *error;
Florin Corase3e2f072018-03-04 07:24:30 -08001670 application_t *app;
Florin Coras371ca502018-02-21 12:07:41 -08001671 u32 key_len;
1672 int rv = 0;
1673 if (!session_manager_is_enabled ())
1674 {
1675 rv = VNET_API_ERROR_FEATURE_DISABLED;
1676 goto done;
1677 }
Florin Corase3e2f072018-03-04 07:24:30 -08001678 if (!(app = application_lookup (mp->client_index)))
1679 {
1680 rv = VNET_API_ERROR_APPLICATION_NOT_ATTACHED;
1681 goto done;
1682 }
Florin Coras371ca502018-02-21 12:07:41 -08001683 memset (a, 0, sizeof (*a));
Florin Coras15531972018-08-12 23:50:53 -07001684 a->app_index = app->app_index;
Florin Coras371ca502018-02-21 12:07:41 -08001685 key_len = clib_net_to_host_u16 (mp->key_len);
Florin Coras5090c572018-03-18 08:22:17 -07001686 if (key_len > 10000)
1687 {
1688 rv = VNET_API_ERROR_INVALID_VALUE;
1689 goto done;
1690 }
Florin Coras371ca502018-02-21 12:07:41 -08001691 vec_validate (a->key, key_len);
1692 clib_memcpy (a->key, mp->key, key_len);
1693 if ((error = vnet_app_add_tls_key (a)))
1694 {
1695 rv = clib_error_get_code (error);
1696 clib_error_report (error);
1697 }
1698 vec_free (a->key);
1699done:
1700 REPLY_MACRO (VL_API_APPLICATION_TLS_KEY_ADD_REPLY);
1701}
1702
Florin Coras6cf30ad2017-04-04 23:08:23 -07001703static clib_error_t *
1704application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -05001705{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001706 application_t *app = application_lookup (client_index);
1707 vnet_app_detach_args_t _a, *a = &_a;
1708 if (app)
1709 {
Florin Coras15531972018-08-12 23:50:53 -07001710 a->app_index = app->app_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001711 vnet_application_detach (a);
1712 }
1713 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001714}
1715
Florin Coras6cf30ad2017-04-04 23:08:23 -07001716VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -05001717
1718#define vl_msg_name_crc_list
1719#include <vnet/vnet_all_api_h.h>
1720#undef vl_msg_name_crc_list
1721
1722static void
1723setup_message_id_table (api_main_t * am)
1724{
1725#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
1726 foreach_vl_msg_name_crc_session;
1727#undef _
1728}
1729
1730/*
1731 * session_api_hookup
1732 * Add uri's API message handlers to the table.
1733 * vlib has alread mapped shared memory and
1734 * added the client registration handlers.
1735 * See .../open-repo/vlib/memclnt_vlib.c:memclnt_process()
1736 */
1737static clib_error_t *
1738session_api_hookup (vlib_main_t * vm)
1739{
1740 api_main_t *am = &api_main;
1741
1742#define _(N,n) \
1743 vl_msg_api_set_handlers(VL_API_##N, #n, \
1744 vl_api_##n##_t_handler, \
1745 vl_noop_handler, \
1746 vl_api_##n##_t_endian, \
1747 vl_api_##n##_t_print, \
1748 sizeof(vl_api_##n##_t), 1);
1749 foreach_session_api_msg;
1750#undef _
1751
1752 /*
1753 * Messages which bounce off the data-plane to
1754 * an API client. Simply tells the message handling infra not
1755 * to free the message.
1756 *
1757 * Bounced message handlers MUST NOT block the data plane
1758 */
1759 am->message_bounce[VL_API_CONNECT_URI] = 1;
1760 am->message_bounce[VL_API_CONNECT_SOCK] = 1;
1761
1762 /*
1763 * Set up the (msg_name, crc, message-id) table
1764 */
1765 setup_message_id_table (am);
1766
1767 return 0;
1768}
1769
1770VLIB_API_INIT_FUNCTION (session_api_hookup);
Florin Coras6cf30ad2017-04-04 23:08:23 -07001771
Dave Barach68b0fb02017-02-28 15:15:56 -05001772/*
1773 * fd.io coding-style-patch-verification: ON
1774 *
1775 * Local Variables:
1776 * eval: (c-set-style "gnu")
1777 * End:
1778 */