blob: eb35f193ce6588af413ea178e43e720369a81321 [file] [log] [blame]
Dave Barach68b0fb02017-02-28 15:15:56 -05001/*
Florin Coras288eaab2019-02-03 15:26:14 -08002 * Copyright (c) 2015-2019 Cisco and/or its affiliates.
Dave Barach68b0fb02017-02-28 15:15:56 -05003 * 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>
Florin Corasba7d8f52019-02-22 13:11:38 -080020#include <vnet/session/application_local.h>
Florin Coras1c710452017-10-17 00:03:13 -070021#include <vnet/session/session_rules_table.h>
Florin Coras6c36f532017-11-03 18:32:34 -070022#include <vnet/session/session_table.h>
Florin Corasc9940fc2019-02-05 20:55:11 -080023#include <vnet/session/session.h>
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010024#include <vnet/ip/ip_types_api.h>
25
Filip Tehlar0046e972021-06-26 22:12:08 +000026#include <vnet/format_fns.h>
27#include <vnet/session/session.api_enum.h>
28#include <vnet/session/session.api_types.h>
Dave Barach68b0fb02017-02-28 15:15:56 -050029
Filip Tehlar0046e972021-06-26 22:12:08 +000030#define REPLY_MSG_ID_BASE session_main.msg_id_base
Dave Barach68b0fb02017-02-28 15:15:56 -050031#include <vlibapi/api_helper_macros.h>
32
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010033static transport_proto_t
34api_session_transport_proto_decode (const vl_api_transport_proto_t * api_tp)
35{
36 switch (*api_tp)
37 {
38 case TRANSPORT_PROTO_API_TCP:
39 return TRANSPORT_PROTO_TCP;
40 case TRANSPORT_PROTO_API_UDP:
41 return TRANSPORT_PROTO_UDP;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010042 case TRANSPORT_PROTO_API_TLS:
43 return TRANSPORT_PROTO_TLS;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010044 case TRANSPORT_PROTO_API_QUIC:
45 return TRANSPORT_PROTO_QUIC;
46 default:
47 return TRANSPORT_PROTO_NONE;
48 }
49}
50
51static vl_api_transport_proto_t
52api_session_transport_proto_encode (const transport_proto_t tp)
53{
54 switch (tp)
55 {
56 case TRANSPORT_PROTO_TCP:
57 return TRANSPORT_PROTO_API_TCP;
58 case TRANSPORT_PROTO_UDP:
59 return TRANSPORT_PROTO_API_UDP;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010060 case TRANSPORT_PROTO_TLS:
61 return TRANSPORT_PROTO_API_TLS;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +010062 case TRANSPORT_PROTO_QUIC:
63 return TRANSPORT_PROTO_API_QUIC;
64 default:
65 return TRANSPORT_PROTO_API_NONE;
66 }
67}
68
Dave Barach68b0fb02017-02-28 15:15:56 -050069static int
Florin Coras99368312018-08-02 10:45:44 -070070session_send_fds (vl_api_registration_t * reg, int fds[], int n_fds)
Florin Corasb384b542018-01-15 01:08:33 -080071{
72 clib_error_t *error;
73 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
Florin Coras00e01d32019-10-21 16:07:46 -070074 return SESSION_E_BAPI_NO_FD;
Florin Coras99368312018-08-02 10:45:44 -070075 error = vl_api_send_fd_msg (reg, fds, n_fds);
Florin Corasb384b542018-01-15 01:08:33 -080076 if (error)
77 {
78 clib_error_report (error);
Florin Coras00e01d32019-10-21 16:07:46 -070079 return SESSION_E_BAPI_SEND_FD;
Florin Corasb384b542018-01-15 01:08:33 -080080 }
81 return 0;
82}
83
Florin Coras99368312018-08-02 10:45:44 -070084static int
Florin Coras288eaab2019-02-03 15:26:14 -080085mq_send_session_accepted_cb (session_t * s)
Florin Coras52207f12018-07-12 14:48:06 -070086{
Florin Coras15531972018-08-12 23:50:53 -070087 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras09bf91a2021-02-23 08:44:13 -080088 session_accepted_msg_t m = { 0 };
Florin Corasb4624182020-12-11 13:58:12 -080089 fifo_segment_t *eq_seg;
Florin Coras288eaab2019-02-03 15:26:14 -080090 session_t *listener;
Florin Coras15531972018-08-12 23:50:53 -070091 application_t *app;
Florin Coras52207f12018-07-12 14:48:06 -070092
Florin Coras15531972018-08-12 23:50:53 -070093 app = application_get (app_wrk->app_index);
Florin Coras52207f12018-07-12 14:48:06 -070094
Florin Coras09bf91a2021-02-23 08:44:13 -080095 m.context = app->app_index;
96 m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo);
97 m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo);
98 m.segment_handle = session_segment_handle (s);
99 m.flags = s->flags;
Florin Coras52207f12018-07-12 14:48:06 -0700100
Florin Coras41d5f542021-01-15 13:49:33 -0800101 eq_seg = application_get_rx_mqs_segment (app);
Florin Corasb4624182020-12-11 13:58:12 -0800102
Florin Coras52207f12018-07-12 14:48:06 -0700103 if (session_has_transport (s))
104 {
Nathan Skrzypczak2f0f96b2019-06-13 10:14:28 +0200105 listener = listen_session_get_from_handle (s->listener_handle);
Florin Coras09bf91a2021-02-23 08:44:13 -0800106 m.listener_handle = app_listen_session_handle (listener);
Florin Coras52207f12018-07-12 14:48:06 -0700107 if (application_is_proxy (app))
108 {
109 listener =
Florin Coras15531972018-08-12 23:50:53 -0700110 app_worker_first_listener (app_wrk, session_get_fib_proto (s),
111 session_get_transport_proto (s));
Florin Coras52207f12018-07-12 14:48:06 -0700112 if (listener)
Florin Coras09bf91a2021-02-23 08:44:13 -0800113 m.listener_handle = listen_session_get_handle (listener);
Florin Coras52207f12018-07-12 14:48:06 -0700114 }
Florin Coras09bf91a2021-02-23 08:44:13 -0800115 m.vpp_event_queue_address =
Florin Corasb4624182020-12-11 13:58:12 -0800116 fifo_segment_msg_q_offset (eq_seg, s->thread_index);
Florin Coras09bf91a2021-02-23 08:44:13 -0800117 m.mq_index = s->thread_index;
118 m.handle = session_handle (s);
Aloys Augustincdb71702019-04-08 17:54:39 +0200119
Florin Coras09bf91a2021-02-23 08:44:13 -0800120 session_get_endpoint (s, &m.rmt, 0 /* is_lcl */);
Florin Coras67c90a32021-03-09 18:36:06 -0800121 session_get_endpoint (s, &m.lcl, 1 /* is_lcl */);
Florin Coras52207f12018-07-12 14:48:06 -0700122 }
123 else
124 {
Florin Coras2b81e3c2019-02-27 07:55:46 -0800125 ct_connection_t *ct;
Florin Coras99368312018-08-02 10:45:44 -0700126
Florin Coras2b81e3c2019-02-27 07:55:46 -0800127 ct = (ct_connection_t *) session_get_transport (s);
Nathan Skrzypczak2f0f96b2019-06-13 10:14:28 +0200128 listener = listen_session_get_from_handle (s->listener_handle);
Florin Coras09bf91a2021-02-23 08:44:13 -0800129 m.listener_handle = app_listen_session_handle (listener);
130 m.rmt.is_ip4 = session_type_is_ip4 (listener->session_type);
131 m.rmt.port = ct->c_rmt_port;
Florin Coras67c90a32021-03-09 18:36:06 -0800132 m.lcl.port = ct->c_lcl_port;
Florin Coras09bf91a2021-02-23 08:44:13 -0800133 m.handle = session_handle (s);
134 m.vpp_event_queue_address =
Florin Corasb4624182020-12-11 13:58:12 -0800135 fifo_segment_msg_q_offset (eq_seg, s->thread_index);
Florin Coras09bf91a2021-02-23 08:44:13 -0800136 m.mq_index = s->thread_index;
Florin Coras52207f12018-07-12 14:48:06 -0700137 }
Florin Coras09bf91a2021-02-23 08:44:13 -0800138
Florin Coras20c24232021-11-22 21:19:01 -0800139 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_ACCEPTED, &m, sizeof (m));
Florin Coras52207f12018-07-12 14:48:06 -0700140
141 return 0;
142}
143
Florin Coras72b04282019-01-14 17:23:11 -0800144static inline void
145mq_send_session_close_evt (app_worker_t * app_wrk, session_handle_t sh,
146 session_evt_type_t evt_type)
Florin Coras52207f12018-07-12 14:48:06 -0700147{
Florin Coras20c24232021-11-22 21:19:01 -0800148 session_disconnected_msg_t m = { 0 };
Florin Coras52207f12018-07-12 14:48:06 -0700149
Florin Coras20c24232021-11-22 21:19:01 -0800150 m.handle = sh;
151 m.context = app_wrk->api_client_index;
152
153 app_wrk_send_ctrl_evt (app_wrk, evt_type, &m, sizeof (m));
Florin Coras52207f12018-07-12 14:48:06 -0700154}
155
Florin Coras72b04282019-01-14 17:23:11 -0800156static inline void
157mq_notify_close_subscribers (u32 app_index, session_handle_t sh,
158 svm_fifo_t * f, session_evt_type_t evt_type)
159{
160 app_worker_t *app_wrk;
161 application_t *app;
162 int i;
163
164 app = application_get (app_index);
165 if (!app)
166 return;
167
Florin Corasc547e912020-12-08 17:50:45 -0800168 for (i = 0; i < f->shr->n_subscribers; i++)
Florin Coras72b04282019-01-14 17:23:11 -0800169 {
Florin Corasc547e912020-12-08 17:50:45 -0800170 if (!(app_wrk = application_get_worker (app, f->shr->subscribers[i])))
Florin Coras72b04282019-01-14 17:23:11 -0800171 continue;
172 mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_DISCONNECTED);
173 }
174}
175
176static void
Florin Coras288eaab2019-02-03 15:26:14 -0800177mq_send_session_disconnected_cb (session_t * s)
Florin Coras72b04282019-01-14 17:23:11 -0800178{
179 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
180 session_handle_t sh = session_handle (s);
181
182 mq_send_session_close_evt (app_wrk, session_handle (s),
183 SESSION_CTRL_EVT_DISCONNECTED);
184
Florin Coras288eaab2019-02-03 15:26:14 -0800185 if (svm_fifo_n_subscribers (s->rx_fifo))
186 mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo,
Florin Coras72b04282019-01-14 17:23:11 -0800187 SESSION_CTRL_EVT_DISCONNECTED);
188}
189
Florin Coras52207f12018-07-12 14:48:06 -0700190static void
Florin Coras288eaab2019-02-03 15:26:14 -0800191mq_send_session_reset_cb (session_t * s)
Florin Coras52207f12018-07-12 14:48:06 -0700192{
Florin Coras72b04282019-01-14 17:23:11 -0800193 app_worker_t *app_wrk = app_worker_get (s->app_wrk_index);
194 session_handle_t sh = session_handle (s);
Florin Coras52207f12018-07-12 14:48:06 -0700195
Florin Coras72b04282019-01-14 17:23:11 -0800196 mq_send_session_close_evt (app_wrk, sh, SESSION_CTRL_EVT_RESET);
197
Florin Coras288eaab2019-02-03 15:26:14 -0800198 if (svm_fifo_n_subscribers (s->rx_fifo))
199 mq_notify_close_subscribers (app_wrk->app_index, sh, s->rx_fifo,
Florin Coras72b04282019-01-14 17:23:11 -0800200 SESSION_CTRL_EVT_RESET);
Florin Coras52207f12018-07-12 14:48:06 -0700201}
202
Florin Coras458089b2019-08-21 16:20:44 -0700203int
Florin Coras15531972018-08-12 23:50:53 -0700204mq_send_session_connected_cb (u32 app_wrk_index, u32 api_context,
Florin Coras00e01d32019-10-21 16:07:46 -0700205 session_t * s, session_error_t err)
Florin Coras52207f12018-07-12 14:48:06 -0700206{
Florin Coras09bf91a2021-02-23 08:44:13 -0800207 session_connected_msg_t m = { 0 };
Florin Coras52207f12018-07-12 14:48:06 -0700208 transport_connection_t *tc;
Florin Corasb4624182020-12-11 13:58:12 -0800209 fifo_segment_t *eq_seg;
Florin Coras15531972018-08-12 23:50:53 -0700210 app_worker_t *app_wrk;
Florin Coras41d5f542021-01-15 13:49:33 -0800211 application_t *app;
212
213 app_wrk = app_worker_get (app_wrk_index);
Florin Coras52207f12018-07-12 14:48:06 -0700214
Florin Coras09bf91a2021-02-23 08:44:13 -0800215 m.context = api_context;
216 m.retval = err;
Florin Coras52207f12018-07-12 14:48:06 -0700217
Florin Coras00e01d32019-10-21 16:07:46 -0700218 if (err)
Florin Coras09bf91a2021-02-23 08:44:13 -0800219 goto snd_msg;
Florin Coras52207f12018-07-12 14:48:06 -0700220
Florin Coras41d5f542021-01-15 13:49:33 -0800221 app = application_get (app_wrk->app_index);
222 eq_seg = application_get_rx_mqs_segment (app);
Florin Corasb4624182020-12-11 13:58:12 -0800223
Florin Coras52207f12018-07-12 14:48:06 -0700224 if (session_has_transport (s))
225 {
226 tc = session_get_transport (s);
227 if (!tc)
228 {
Florin Coras00e01d32019-10-21 16:07:46 -0700229 clib_warning ("failed to retrieve transport!");
Florin Coras09bf91a2021-02-23 08:44:13 -0800230 m.retval = SESSION_E_REFUSED;
231 goto snd_msg;
Florin Coras52207f12018-07-12 14:48:06 -0700232 }
233
Florin Coras09bf91a2021-02-23 08:44:13 -0800234 m.handle = session_handle (s);
235 m.vpp_event_queue_address =
Florin Corasb4624182020-12-11 13:58:12 -0800236 fifo_segment_msg_q_offset (eq_seg, s->thread_index);
Aloys Augustincdb71702019-04-08 17:54:39 +0200237
Florin Coras09bf91a2021-02-23 08:44:13 -0800238 session_get_endpoint (s, &m.lcl, 1 /* is_lcl */);
Aloys Augustincdb71702019-04-08 17:54:39 +0200239
Florin Coras09bf91a2021-02-23 08:44:13 -0800240 m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo);
241 m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo);
242 m.segment_handle = session_segment_handle (s);
Florin Corasf6e284b2021-07-21 18:17:20 -0700243 m.mq_index = s->thread_index;
Florin Coras52207f12018-07-12 14:48:06 -0700244 }
245 else
246 {
Florin Coras2b81e3c2019-02-27 07:55:46 -0800247 ct_connection_t *cct;
248 session_t *ss;
Florin Coras99368312018-08-02 10:45:44 -0700249
Florin Coras2b81e3c2019-02-27 07:55:46 -0800250 cct = (ct_connection_t *) session_get_transport (s);
Florin Coras09bf91a2021-02-23 08:44:13 -0800251 m.handle = session_handle (s);
252 m.lcl.port = cct->c_lcl_port;
253 m.lcl.is_ip4 = cct->c_is_ip4;
254 m.vpp_event_queue_address =
Florin Corasb4624182020-12-11 13:58:12 -0800255 fifo_segment_msg_q_offset (eq_seg, s->thread_index);
Florin Coras09bf91a2021-02-23 08:44:13 -0800256 m.server_rx_fifo = fifo_segment_fifo_offset (s->rx_fifo);
257 m.server_tx_fifo = fifo_segment_fifo_offset (s->tx_fifo);
258 m.segment_handle = session_segment_handle (s);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800259 ss = ct_session_get_peer (s);
Florin Coras09bf91a2021-02-23 08:44:13 -0800260 m.ct_rx_fifo = fifo_segment_fifo_offset (ss->tx_fifo);
261 m.ct_tx_fifo = fifo_segment_fifo_offset (ss->rx_fifo);
262 m.ct_segment_handle = session_segment_handle (ss);
Florin Corasf6e284b2021-07-21 18:17:20 -0700263 m.mq_index = s->thread_index;
Florin Coras52207f12018-07-12 14:48:06 -0700264 }
265
Florin Coras893bc972021-04-23 08:58:57 -0700266 /* Setup client session index in advance, in case data arrives
267 * before the app processes message and updates it */
268 s->rx_fifo->shr->client_session_index = api_context;
269 s->tx_fifo->shr->client_session_index = api_context;
270
Florin Coras09bf91a2021-02-23 08:44:13 -0800271snd_msg:
272
Florin Coras20c24232021-11-22 21:19:01 -0800273 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_CONNECTED, &m, sizeof (m));
Florin Coras09bf91a2021-02-23 08:44:13 -0800274
Florin Coras52207f12018-07-12 14:48:06 -0700275 return 0;
276}
277
Florin Coras458089b2019-08-21 16:20:44 -0700278int
Florin Coras60116992018-08-27 09:52:18 -0700279mq_send_session_bound_cb (u32 app_wrk_index, u32 api_context,
280 session_handle_t handle, int rv)
281{
Florin Coras09bf91a2021-02-23 08:44:13 -0800282 session_bound_msg_t m = { 0 };
Yu Ping0b819152019-05-07 02:24:30 +0800283 transport_endpoint_t tep;
Florin Corasb4624182020-12-11 13:58:12 -0800284 fifo_segment_t *eq_seg;
Florin Coras60116992018-08-27 09:52:18 -0700285 app_worker_t *app_wrk;
Florin Coras41d5f542021-01-15 13:49:33 -0800286 application_t *app;
Florin Corasc9940fc2019-02-05 20:55:11 -0800287 app_listener_t *al;
288 session_t *ls = 0;
Florin Coras09bf91a2021-02-23 08:44:13 -0800289
Florin Coras41d5f542021-01-15 13:49:33 -0800290 app_wrk = app_worker_get (app_wrk_index);
291
Florin Coras09bf91a2021-02-23 08:44:13 -0800292 m.context = api_context;
293 m.retval = rv;
294
295 if (rv)
296 goto snd_msg;
297
298 m.handle = handle;
299 al = app_listener_get_w_handle (handle);
300 if (al->session_index != SESSION_INVALID_INDEX)
301 ls = app_listener_get_session (al);
302 else
303 ls = app_listener_get_local_session (al);
304
305 session_get_endpoint (ls, &tep, 1 /* is_lcl */);
306 m.lcl_port = tep.port;
307 m.lcl_is_ip4 = tep.is_ip4;
308 clib_memcpy_fast (m.lcl_ip, &tep.ip, sizeof (tep.ip));
Florin Coras41d5f542021-01-15 13:49:33 -0800309 app = application_get (app_wrk->app_index);
310 eq_seg = application_get_rx_mqs_segment (app);
Florin Coras09bf91a2021-02-23 08:44:13 -0800311 m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, ls->thread_index);
Florin Corasf6e284b2021-07-21 18:17:20 -0700312 m.mq_index = ls->thread_index;
Florin Coras09bf91a2021-02-23 08:44:13 -0800313
Florin Coras8694fbc2021-03-10 00:21:02 -0800314 if (session_transport_service_type (ls) == TRANSPORT_SERVICE_CL &&
315 ls->rx_fifo)
Florin Coras09bf91a2021-02-23 08:44:13 -0800316 {
Florin Corasaeb7c1c2023-03-10 10:22:21 -0800317 m.mq_index = transport_cl_thread ();
318 m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, m.mq_index);
Florin Coras09bf91a2021-02-23 08:44:13 -0800319 m.rx_fifo = fifo_segment_fifo_offset (ls->rx_fifo);
320 m.tx_fifo = fifo_segment_fifo_offset (ls->tx_fifo);
321 m.segment_handle = session_segment_handle (ls);
322 }
323
324snd_msg:
325
Florin Coras20c24232021-11-22 21:19:01 -0800326 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_BOUND, &m, sizeof (m));
Florin Coras60116992018-08-27 09:52:18 -0700327
Florin Coras60116992018-08-27 09:52:18 -0700328 return 0;
329}
330
Florin Coras458089b2019-08-21 16:20:44 -0700331void
332mq_send_unlisten_reply (app_worker_t * app_wrk, session_handle_t sh,
333 u32 context, int rv)
334{
Florin Coras20c24232021-11-22 21:19:01 -0800335 session_unlisten_reply_msg_t m = { 0 };
Florin Coras458089b2019-08-21 16:20:44 -0700336
Florin Coras20c24232021-11-22 21:19:01 -0800337 m.context = context;
338 m.handle = sh;
339 m.retval = rv;
340 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_UNLISTEN_REPLY, &m,
341 sizeof (m));
Florin Coras458089b2019-08-21 16:20:44 -0700342}
343
Florin Coras49568af2019-07-31 16:46:24 -0700344static void
345mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh)
346{
Florin Coras09bf91a2021-02-23 08:44:13 -0800347 session_migrated_msg_t m = { 0 };
Florin Corasb4624182020-12-11 13:58:12 -0800348 fifo_segment_t *eq_seg;
Florin Coras68b7e582020-01-21 18:33:23 -0800349 app_worker_t *app_wrk;
Florin Coras41d5f542021-01-15 13:49:33 -0800350 application_t *app;
Florin Corasb4624182020-12-11 13:58:12 -0800351 u32 thread_index;
352
353 thread_index = session_thread_from_handle (new_sh);
Florin Coras41d5f542021-01-15 13:49:33 -0800354 app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras41d5f542021-01-15 13:49:33 -0800355 app = application_get (app_wrk->app_index);
356 eq_seg = application_get_rx_mqs_segment (app);
Florin Coras68b7e582020-01-21 18:33:23 -0800357
Florin Coras09bf91a2021-02-23 08:44:13 -0800358 m.handle = session_handle (s);
359 m.new_handle = new_sh;
360 m.vpp_thread_index = thread_index;
361 m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, thread_index);
362 m.segment_handle = SESSION_INVALID_HANDLE;
363
Florin Coras20c24232021-11-22 21:19:01 -0800364 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_MIGRATED, &m, sizeof (m));
Florin Coras49568af2019-07-31 16:46:24 -0700365}
366
Florin Corasc4c4cf52019-08-24 18:17:34 -0700367static int
368mq_send_add_segment_cb (u32 app_wrk_index, u64 segment_handle)
369{
Florin Coras20c24232021-11-22 21:19:01 -0800370 session_app_add_segment_msg_t m = { 0 };
Florin Corasc4c4cf52019-08-24 18:17:34 -0700371 vl_api_registration_t *reg;
372 app_worker_t *app_wrk;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700373 fifo_segment_t *fs;
374 ssvm_private_t *sp;
375 u8 fd_flags = 0;
376
377 app_wrk = app_worker_get (app_wrk_index);
378
379 reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
380 if (!reg)
381 {
382 clib_warning ("no api registration for client: %u",
383 app_wrk->api_client_index);
384 return -1;
385 }
386
387 fs = segment_manager_get_segment_w_handle (segment_handle);
388 sp = &fs->ssvm;
389 if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
390 {
391 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
392 {
393 clib_warning ("can't send memfd fd");
394 return -1;
395 }
396
397 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700398 }
399
Florin Coras20c24232021-11-22 21:19:01 -0800400 m.segment_size = sp->ssvm_size;
401 m.fd_flags = fd_flags;
402 m.segment_handle = segment_handle;
403 strncpy ((char *) m.segment_name, (char *) sp->name,
404 sizeof (m.segment_name) - 1);
Florin Corasc4c4cf52019-08-24 18:17:34 -0700405
Florin Coras20c24232021-11-22 21:19:01 -0800406 app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m,
407 sizeof (m), sp->fd);
Florin Corasc4c4cf52019-08-24 18:17:34 -0700408
409 return 0;
410}
411
412static int
413mq_send_del_segment_cb (u32 app_wrk_index, u64 segment_handle)
414{
Florin Coras20c24232021-11-22 21:19:01 -0800415 session_app_del_segment_msg_t m = { 0 };
Florin Corasc4c4cf52019-08-24 18:17:34 -0700416 vl_api_registration_t *reg;
417 app_worker_t *app_wrk;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700418
419 app_wrk = app_worker_get (app_wrk_index);
420 reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
421 if (!reg)
422 {
423 clib_warning ("no registration: %u", app_wrk->api_client_index);
424 return -1;
425 }
426
Florin Coras20c24232021-11-22 21:19:01 -0800427 m.segment_handle = segment_handle;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700428
Florin Coras20c24232021-11-22 21:19:01 -0800429 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m,
430 sizeof (m));
Florin Corasc4c4cf52019-08-24 18:17:34 -0700431
432 return 0;
433}
434
Florin Coras9ace36d2019-10-28 13:14:17 -0700435static void
436mq_send_session_cleanup_cb (session_t * s, session_cleanup_ntf_t ntf)
437{
Florin Coras20c24232021-11-22 21:19:01 -0800438 session_cleanup_msg_t m = { 0 };
Florin Coras9ace36d2019-10-28 13:14:17 -0700439 app_worker_t *app_wrk;
440
Florin Coras36d49392020-04-24 23:00:11 +0000441 /* Propagate transport cleanup notifications only if app didn't close */
442 if (ntf == SESSION_CLEANUP_TRANSPORT
443 && s->session_state != SESSION_STATE_TRANSPORT_DELETED)
Florin Coras9ace36d2019-10-28 13:14:17 -0700444 return;
445
446 app_wrk = app_worker_get_if_valid (s->app_wrk_index);
447 if (!app_wrk)
448 return;
449
Florin Coras20c24232021-11-22 21:19:01 -0800450 m.handle = session_handle (s);
451 m.type = ntf;
Florin Coras9ace36d2019-10-28 13:14:17 -0700452
Florin Coras20c24232021-11-22 21:19:01 -0800453 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_CLEANUP, &m, sizeof (m));
Florin Coras9ace36d2019-10-28 13:14:17 -0700454}
455
Florin Corasc4c4cf52019-08-24 18:17:34 -0700456static session_cb_vft_t session_mq_cb_vft = {
457 .session_accept_callback = mq_send_session_accepted_cb,
458 .session_disconnect_callback = mq_send_session_disconnected_cb,
459 .session_connected_callback = mq_send_session_connected_cb,
460 .session_reset_callback = mq_send_session_reset_cb,
461 .session_migrate_callback = mq_send_session_migrate_cb,
Florin Coras9ace36d2019-10-28 13:14:17 -0700462 .session_cleanup_callback = mq_send_session_cleanup_cb,
Florin Corasc4c4cf52019-08-24 18:17:34 -0700463 .add_segment_callback = mq_send_add_segment_cb,
464 .del_segment_callback = mq_send_del_segment_cb,
465};
466
Dave Barach68b0fb02017-02-28 15:15:56 -0500467static void
Florin Corase04c2992017-03-01 08:17:34 -0800468vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
469{
470 vl_api_session_enable_disable_reply_t *rmp;
471 vlib_main_t *vm = vlib_get_main ();
472 int rv = 0;
473
474 vnet_session_enable_disable (vm, mp->is_enable);
475 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
476}
477
Dave Barach68b0fb02017-02-28 15:15:56 -0500478static void
Nathan Skrzypczak7b3a3df2021-07-28 14:09:50 +0200479vl_api_session_sapi_enable_disable_t_handler (
480 vl_api_session_sapi_enable_disable_t *mp)
481{
482 vl_api_session_sapi_enable_disable_reply_t *rmp;
483 int rv = 0;
484
485 rv = appns_sapi_enable_disable (mp->is_enable);
486 REPLY_MACRO (VL_API_SESSION_SAPI_ENABLE_DISABLE_REPLY);
487}
488
489static void
Florin Coras458089b2019-08-21 16:20:44 -0700490vl_api_app_attach_t_handler (vl_api_app_attach_t * mp)
491{
Florin Coras41d5f542021-01-15 13:49:33 -0800492 int rv = 0, *fds = 0, n_fds = 0, n_workers, i;
493 fifo_segment_t *segp, *rx_mqs_seg = 0;
Florin Coras458089b2019-08-21 16:20:44 -0700494 vnet_app_attach_args_t _a, *a = &_a;
Florin Coras41d5f542021-01-15 13:49:33 -0800495 vl_api_app_attach_reply_t *rmp;
Florin Coras458089b2019-08-21 16:20:44 -0700496 u8 fd_flags = 0, ctrl_thread;
497 vl_api_registration_t *reg;
Florin Coras41d5f542021-01-15 13:49:33 -0800498 svm_msg_q_t *rx_mq;
499 application_t *app;
Florin Coras458089b2019-08-21 16:20:44 -0700500
501 reg = vl_api_client_index_to_registration (mp->client_index);
502 if (!reg)
503 return;
504
Florin Coras41d5f542021-01-15 13:49:33 -0800505 n_workers = vlib_num_workers ();
Florin Coras61ae0562020-09-02 19:10:28 -0700506 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras458089b2019-08-21 16:20:44 -0700507 {
508 rv = VNET_API_ERROR_FEATURE_DISABLED;
509 goto done;
510 }
Florin Coras6c10ab22020-11-08 16:50:39 -0800511 /* Only support binary api with socket transport */
512 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
513 {
514 rv = VNET_API_ERROR_APP_UNSUPPORTED_CFG;
515 goto done;
516 }
Florin Coras458089b2019-08-21 16:20:44 -0700517
518 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
519 sizeof (mp->options),
520 "Out of options, fix api message definition");
521
522 clib_memset (a, 0, sizeof (*a));
523 a->api_client_index = mp->client_index;
524 a->options = mp->options;
525 a->session_cb_vft = &session_mq_cb_vft;
Dave Barach77841402020-04-29 17:04:10 -0400526 a->namespace_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id);
Florin Coras458089b2019-08-21 16:20:44 -0700527
528 if ((rv = vnet_application_attach (a)))
529 {
530 clib_warning ("attach returned: %d", rv);
531 vec_free (a->namespace_id);
532 goto done;
533 }
534 vec_free (a->namespace_id);
535
Florin Coras41d5f542021-01-15 13:49:33 -0800536 vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers);
537
538 /* Send rx mqs segment */
539 app = application_get (a->app_index);
540 rx_mqs_seg = application_get_rx_mqs_segment (app);
541
542 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
543 fds[n_fds] = rx_mqs_seg->ssvm.fd;
544 n_fds += 1;
545
Florin Coras458089b2019-08-21 16:20:44 -0700546 /* Send fifo segment fd if needed */
547 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
548 {
549 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
550 fds[n_fds] = a->segment->fd;
551 n_fds += 1;
552 }
553 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
554 {
555 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -0800556 fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q);
Florin Coras458089b2019-08-21 16:20:44 -0700557 n_fds += 1;
558 }
559
Florin Coras41d5f542021-01-15 13:49:33 -0800560 if (application_use_private_rx_mqs ())
561 {
562 fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD;
563 for (i = 0; i < n_workers + 1; i++)
564 {
565 rx_mq = application_rx_mq_get (app, i);
566 fds[n_fds] = svm_msg_q_get_eventfd (rx_mq);
567 n_fds += 1;
568 }
569 }
570
Florin Coras458089b2019-08-21 16:20:44 -0700571done:
Florin Coras458089b2019-08-21 16:20:44 -0700572 /* *INDENT-OFF* */
Klement Sekera0eb83f42021-12-02 16:36:34 +0000573 REPLY_MACRO3 (
574 VL_API_APP_ATTACH_REPLY,
575 ((!rv) ? vec_len (((fifo_segment_t *) a->segment)->ssvm.name) : 0), ({
576 if (!rv)
577 {
578 ctrl_thread = n_workers ? 1 : 0;
579 segp = (fifo_segment_t *) a->segment;
580 rmp->app_index = clib_host_to_net_u32 (a->app_index);
581 rmp->app_mq = fifo_segment_msg_q_offset (segp, 0);
582 rmp->vpp_ctrl_mq =
583 fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread);
584 rmp->vpp_ctrl_mq_thread = ctrl_thread;
585 rmp->n_fds = n_fds;
586 rmp->fd_flags = fd_flags;
587 if (vec_len (segp->ssvm.name))
588 {
589 vl_api_vec_to_api_string (segp->ssvm.name, &rmp->segment_name);
590 }
591 rmp->segment_size = segp->ssvm.ssvm_size;
592 rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle);
593 }
594 }));
Florin Coras458089b2019-08-21 16:20:44 -0700595 /* *INDENT-ON* */
596
597 if (n_fds)
598 session_send_fds (reg, fds, n_fds);
Florin Coras41d5f542021-01-15 13:49:33 -0800599 vec_free (fds);
Florin Coras458089b2019-08-21 16:20:44 -0700600}
601
Florin Corascea194d2017-10-02 00:18:51 -0700602static void
Florin Coras15531972018-08-12 23:50:53 -0700603vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
604{
605 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
606 vl_api_app_worker_add_del_reply_t *rmp;
607 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700608 application_t *app;
609 u8 fd_flags = 0;
610
Florin Coras61ae0562020-09-02 19:10:28 -0700611 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras15531972018-08-12 23:50:53 -0700612 {
613 rv = VNET_API_ERROR_FEATURE_DISABLED;
614 goto done;
615 }
616
617 reg = vl_api_client_index_to_registration (mp->client_index);
618 if (!reg)
619 return;
620
Florin Corasc1f5a432018-11-20 11:31:26 -0800621 app = application_get_if_valid (clib_net_to_host_u32 (mp->app_index));
Florin Coras15531972018-08-12 23:50:53 -0700622 if (!app)
623 {
624 rv = VNET_API_ERROR_INVALID_VALUE;
625 goto done;
626 }
627
628 vnet_app_worker_add_del_args_t args = {
629 .app_index = app->app_index,
Florin Coras349f8ca2018-11-20 16:52:49 -0800630 .wrk_map_index = clib_net_to_host_u32 (mp->wrk_index),
Florin Corasc1f5a432018-11-20 11:31:26 -0800631 .api_client_index = mp->client_index,
Florin Coras15531972018-08-12 23:50:53 -0700632 .is_add = mp->is_add
633 };
Florin Corasc1a42652019-02-08 18:27:29 -0800634 rv = vnet_app_worker_add_del (&args);
635 if (rv)
Florin Coras15531972018-08-12 23:50:53 -0700636 {
Florin Corasc1a42652019-02-08 18:27:29 -0800637 clib_warning ("app worker add/del returned: %d", rv);
Florin Coras15531972018-08-12 23:50:53 -0700638 goto done;
639 }
640
Florin Coras14598772018-09-04 19:47:52 -0700641 if (!mp->is_add)
642 goto done;
Florin Corasc3638fe2018-08-24 13:58:49 -0700643
Florin Coras15531972018-08-12 23:50:53 -0700644 /* Send fifo segment fd if needed */
645 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
646 {
647 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
648 fds[n_fds] = args.segment->fd;
649 n_fds += 1;
650 }
651 if (application_segment_manager_properties (app)->use_mq_eventfd)
652 {
653 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -0800654 fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q);
Florin Coras15531972018-08-12 23:50:53 -0700655 n_fds += 1;
656 }
657
658 /* *INDENT-OFF* */
659done:
Klement Sekera0eb83f42021-12-02 16:36:34 +0000660 REPLY_MACRO3 (
661 VL_API_APP_WORKER_ADD_DEL_REPLY,
662 ((!rv && mp->is_add) ? vec_len (args.segment->name) : 0), ({
663 rmp->is_add = mp->is_add;
664 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index);
665 rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle);
666 if (!rv && mp->is_add)
667 {
668 rmp->app_event_queue_address =
669 fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0);
670 rmp->n_fds = n_fds;
671 rmp->fd_flags = fd_flags;
672 if (vec_len (args.segment->name))
673 {
674 vl_api_vec_to_api_string (args.segment->name,
675 &rmp->segment_name);
676 }
677 }
678 }));
Florin Coras15531972018-08-12 23:50:53 -0700679 /* *INDENT-ON* */
680
681 if (n_fds)
682 session_send_fds (reg, fds, n_fds);
683}
684
685static void
Florin Coras888d9f02020-04-02 23:00:13 +0000686vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
687{
688 vl_api_application_detach_reply_t *rmp;
689 int rv = VNET_API_ERROR_INVALID_VALUE_2;
690 vnet_app_detach_args_t _a, *a = &_a;
691 application_t *app;
692
Florin Coras61ae0562020-09-02 19:10:28 -0700693 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras888d9f02020-04-02 23:00:13 +0000694 {
695 rv = VNET_API_ERROR_FEATURE_DISABLED;
696 goto done;
697 }
698
699 app = application_lookup (mp->client_index);
700 if (app)
701 {
702 a->app_index = app->app_index;
703 a->api_client_index = mp->client_index;
704 rv = vnet_application_detach (a);
705 }
706
707done:
708 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
709}
710
711static void
Florin Corascea194d2017-10-02 00:18:51 -0700712vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
713{
714 vl_api_app_namespace_add_del_reply_t *rmp;
Florin Coras6e8c6672017-11-10 09:03:54 -0800715 u32 appns_index = 0;
716 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -0700717 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +0200718 if (session_main_is_enabled () == 0)
Florin Corascea194d2017-10-02 00:18:51 -0700719 {
720 rv = VNET_API_ERROR_FEATURE_DISABLED;
721 goto done;
722 }
723
Dave Barach77841402020-04-29 17:04:10 -0400724 ns_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id);
Florin Corascea194d2017-10-02 00:18:51 -0700725
Florin Corascea194d2017-10-02 00:18:51 -0700726 vnet_app_namespace_add_del_args_t args = {
727 .ns_id = ns_id,
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200728 .netns = 0,
729 .sock_name = 0,
Florin Coras9a9adb22017-10-26 08:16:59 -0700730 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -0700731 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
732 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
733 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
734 .is_add = 1
735 };
Florin Corasc1a42652019-02-08 18:27:29 -0800736 rv = vnet_app_namespace_add_del (&args);
737 if (!rv)
Florin Coras6e8c6672017-11-10 09:03:54 -0800738 {
739 appns_index = app_namespace_index_from_id (ns_id);
740 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
741 {
742 clib_warning ("app ns lookup failed");
743 rv = VNET_API_ERROR_UNSPECIFIED;
744 }
745 }
Florin Corascea194d2017-10-02 00:18:51 -0700746 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -0800747
748 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -0700749done:
Florin Coras6e8c6672017-11-10 09:03:54 -0800750 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
751 if (!rv)
752 rmp->appns_index = clib_host_to_net_u32 (appns_index);
753 }));
754 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -0700755}
756
Florin Coras1c710452017-10-17 00:03:13 -0700757static void
Florin Coras7cb471a2021-07-23 08:39:26 -0700758vl_api_app_namespace_add_del_v2_t_handler (
759 vl_api_app_namespace_add_del_v2_t *mp)
760{
761 vl_api_app_namespace_add_del_v2_reply_t *rmp;
762 u8 *ns_id = 0, *netns = 0;
763 u32 appns_index = 0;
764 int rv = 0;
765
766 if (session_main_is_enabled () == 0)
767 {
768 rv = VNET_API_ERROR_FEATURE_DISABLED;
769 goto done;
770 }
771
772 mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0;
773 mp->netns[sizeof (mp->netns) - 1] = 0;
774 ns_id = format (0, "%s", &mp->namespace_id);
775 netns = format (0, "%s", &mp->netns);
776
777 vnet_app_namespace_add_del_args_t args = {
778 .ns_id = ns_id,
779 .netns = netns,
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200780 .sock_name = 0,
Florin Coras7cb471a2021-07-23 08:39:26 -0700781 .secret = clib_net_to_host_u64 (mp->secret),
782 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
783 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
784 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
785 .is_add = 1
786 };
787 rv = vnet_app_namespace_add_del (&args);
788 if (!rv)
789 {
790 appns_index = app_namespace_index_from_id (ns_id);
791 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
792 {
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200793 clib_warning ("app ns lookup failed id:%s", ns_id);
Florin Coras7cb471a2021-07-23 08:39:26 -0700794 rv = VNET_API_ERROR_UNSPECIFIED;
795 }
796 }
797 vec_free (ns_id);
798 vec_free (netns);
799
800done:
801 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V2_REPLY, ({
802 if (!rv)
803 rmp->appns_index = clib_host_to_net_u32 (appns_index);
804 }));
805}
806
807static void
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200808vl_api_app_namespace_add_del_v3_t_handler (
809 vl_api_app_namespace_add_del_v3_t *mp)
810{
811 vl_api_app_namespace_add_del_v3_reply_t *rmp;
812 u8 *ns_id = 0, *netns = 0, *sock_name = 0;
813 u32 appns_index = 0;
814 int rv = 0;
815 if (session_main_is_enabled () == 0)
816 {
817 rv = VNET_API_ERROR_FEATURE_DISABLED;
818 goto done;
819 }
820 mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0;
821 mp->netns[sizeof (mp->netns) - 1] = 0;
822 ns_id = format (0, "%s", &mp->namespace_id);
823 netns = format (0, "%s", &mp->netns);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200824 sock_name = vl_api_from_api_to_new_vec (mp, &mp->sock_name);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200825 vnet_app_namespace_add_del_args_t args = {
826 .ns_id = ns_id,
827 .netns = netns,
828 .sock_name = sock_name,
829 .secret = clib_net_to_host_u64 (mp->secret),
830 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
831 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
832 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
833 .is_add = mp->is_add,
834 };
835 rv = vnet_app_namespace_add_del (&args);
836 if (!rv && mp->is_add)
837 {
838 appns_index = app_namespace_index_from_id (ns_id);
839 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
840 {
841 clib_warning ("app ns lookup failed id:%s", ns_id);
842 rv = VNET_API_ERROR_UNSPECIFIED;
843 }
844 }
845 vec_free (ns_id);
846 vec_free (netns);
847 vec_free (sock_name);
848done:
849 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V3_REPLY, ({
850 if (!rv)
851 rmp->appns_index = clib_host_to_net_u32 (appns_index);
852 }));
853}
854
855static void
Florin Coras1c710452017-10-17 00:03:13 -0700856vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
857{
858 vl_api_session_rule_add_del_reply_t *rmp;
859 session_rule_add_del_args_t args;
860 session_rule_table_add_del_args_t *table_args = &args.table_args;
Florin Coras1c710452017-10-17 00:03:13 -0700861 int rv = 0;
862
Dave Barachb7b92992018-10-17 10:38:51 -0400863 clib_memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -0700864
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100865 ip_prefix_decode (&mp->lcl, &table_args->lcl);
866 ip_prefix_decode (&mp->rmt, &table_args->rmt);
867
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100868 table_args->lcl_port = mp->lcl_port;
869 table_args->rmt_port = mp->rmt_port;
Florin Coras1c710452017-10-17 00:03:13 -0700870 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
871 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -0800872 mp->tag[sizeof (mp->tag) - 1] = 0;
873 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700874 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
875 args.scope = mp->scope;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100876 args.transport_proto =
877 api_session_transport_proto_decode (&mp->transport_proto) ==
878 TRANSPORT_PROTO_UDP ? 1 : 0;
Florin Coras1c710452017-10-17 00:03:13 -0700879
Florin Corasc1a42652019-02-08 18:27:29 -0800880 rv = vnet_session_rule_add_del (&args);
881 if (rv)
882 clib_warning ("rule add del returned: %d", rv);
Florin Corasc97a7392017-11-05 23:07:07 -0800883 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700884 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
885}
886
Florin Coras6c36f532017-11-03 18:32:34 -0700887static void
888send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -0800889 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800890 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700891{
892 vl_api_session_rules_details_t *rmp = 0;
893 session_mask_or_match_4_t *match =
894 (session_mask_or_match_4_t *) & rule->match;
895 session_mask_or_match_4_t *mask =
896 (session_mask_or_match_4_t *) & rule->mask;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100897 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -0700898
899 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400900 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar0046e972021-06-26 22:12:08 +0000901 rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS);
Florin Coras6c36f532017-11-03 18:32:34 -0700902 rmp->context = context;
903
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100904 clib_memset (&lcl, 0, sizeof (lcl));
905 clib_memset (&rmt, 0, sizeof (rmt));
906 ip_set (&lcl.fp_addr, &match->lcl_ip, 1);
907 ip_set (&rmt.fp_addr, &match->rmt_ip, 1);
908 lcl.fp_len = ip4_mask_to_preflen (&mask->lcl_ip);
909 rmt.fp_len = ip4_mask_to_preflen (&mask->rmt_ip);
910
911 ip_prefix_encode (&lcl, &rmp->lcl);
912 ip_prefix_encode (&rmt, &rmp->rmt);
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100913 rmp->lcl_port = match->lcl_port;
914 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -0700915 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
916 rmp->scope =
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100917 is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL;
918 rmp->transport_proto = api_session_transport_proto_encode (transport_proto);
Florin Coras6c36f532017-11-03 18:32:34 -0700919 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800920 if (tag)
921 {
Dave Barach178cf492018-11-13 16:34:13 -0500922 clib_memcpy_fast (rmp->tag, tag, vec_len (tag));
Florin Corasc97a7392017-11-05 23:07:07 -0800923 rmp->tag[vec_len (tag)] = 0;
924 }
Florin Coras6c36f532017-11-03 18:32:34 -0700925
Florin Coras6c4dae22018-01-09 06:39:23 -0800926 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -0700927}
928
929static void
Florin Corasc97a7392017-11-05 23:07:07 -0800930send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
931 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800932 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700933{
934 vl_api_session_rules_details_t *rmp = 0;
935 session_mask_or_match_6_t *match =
936 (session_mask_or_match_6_t *) & rule->match;
937 session_mask_or_match_6_t *mask =
938 (session_mask_or_match_6_t *) & rule->mask;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100939 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -0700940
941 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400942 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar0046e972021-06-26 22:12:08 +0000943 rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS);
Florin Coras6c36f532017-11-03 18:32:34 -0700944 rmp->context = context;
945
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100946 clib_memset (&lcl, 0, sizeof (lcl));
947 clib_memset (&rmt, 0, sizeof (rmt));
948 ip_set (&lcl.fp_addr, &match->lcl_ip, 0);
949 ip_set (&rmt.fp_addr, &match->rmt_ip, 0);
950 lcl.fp_len = ip6_mask_to_preflen (&mask->lcl_ip);
951 rmt.fp_len = ip6_mask_to_preflen (&mask->rmt_ip);
952
953 ip_prefix_encode (&lcl, &rmp->lcl);
954 ip_prefix_encode (&rmt, &rmp->rmt);
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100955 rmp->lcl_port = match->lcl_port;
956 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -0700957 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800958 rmp->scope =
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100959 is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL;
960 rmp->transport_proto = api_session_transport_proto_encode (transport_proto);
Florin Coras6c36f532017-11-03 18:32:34 -0700961 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800962 if (tag)
963 {
Dave Barach178cf492018-11-13 16:34:13 -0500964 clib_memcpy_fast (rmp->tag, tag, vec_len (tag));
Florin Corasc97a7392017-11-05 23:07:07 -0800965 rmp->tag[vec_len (tag)] = 0;
966 }
Florin Coras6c36f532017-11-03 18:32:34 -0700967
Florin Coras6c4dae22018-01-09 06:39:23 -0800968 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -0700969}
970
971static void
972send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -0800973 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c4dae22018-01-09 06:39:23 -0800974 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700975{
976 mma_rule_16_t *rule16;
977 mma_rule_40_t *rule40;
978 mma_rules_table_16_t *srt16;
979 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -0800980 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -0700981
Florin Corasc97a7392017-11-05 23:07:07 -0800982 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -0700983 {
Florin Corasc97a7392017-11-05 23:07:07 -0800984 u8 *tag = 0;
985 /* *INDENT-OFF* */
986 srt16 = &srt->session_rules_tables_16;
Damjan Marionb2c31b62020-12-13 21:47:40 +0100987 pool_foreach (rule16, srt16->rules) {
Florin Corasc97a7392017-11-05 23:07:07 -0800988 ri = mma_rules_table_rule_index_16 (srt16, rule16);
989 tag = session_rules_table_rule_tag (srt, ri, 1);
990 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800991 reg, context);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100992 }
Florin Corasc97a7392017-11-05 23:07:07 -0800993 /* *INDENT-ON* */
994 }
995 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
996 {
997 u8 *tag = 0;
998 /* *INDENT-OFF* */
999 srt40 = &srt->session_rules_tables_40;
Damjan Marionb2c31b62020-12-13 21:47:40 +01001000 pool_foreach (rule40, srt40->rules) {
Florin Corasc97a7392017-11-05 23:07:07 -08001001 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1002 tag = session_rules_table_rule_tag (srt, ri, 1);
1003 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001004 reg, context);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001005 }
Florin Corasc97a7392017-11-05 23:07:07 -08001006 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -07001007 }
1008}
1009
1010static void
Neale Ranns2b202bc2020-09-21 08:17:51 +00001011vl_api_session_rules_dump_t_handler (vl_api_session_rules_dump_t * mp)
Florin Coras6c36f532017-11-03 18:32:34 -07001012{
Florin Coras6c4dae22018-01-09 06:39:23 -08001013 vl_api_registration_t *reg;
Florin Coras6c36f532017-11-03 18:32:34 -07001014 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -08001015 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -07001016
Florin Coras6c4dae22018-01-09 06:39:23 -08001017 reg = vl_api_client_index_to_registration (mp->client_index);
1018 if (!reg)
Florin Coras6c36f532017-11-03 18:32:34 -07001019 return;
1020
1021 /* *INDENT-OFF* */
1022 session_table_foreach (st, ({
Florin Coras07063b82020-03-13 04:44:51 +00001023 for (tp = 0; tp < TRANSPORT_N_PROTOS; tp++)
Florin Corasc97a7392017-11-05 23:07:07 -08001024 {
1025 send_session_rules_table_details (&st->session_rules[tp],
1026 st->active_fib_proto, tp,
Florin Coras6c4dae22018-01-09 06:39:23 -08001027 st->is_local, st->appns_index, reg,
Florin Corasc97a7392017-11-05 23:07:07 -08001028 mp->context);
1029 }
Florin Coras6c36f532017-11-03 18:32:34 -07001030 }));
1031 /* *INDENT-ON* */
1032}
1033
Florin Coras371ca502018-02-21 12:07:41 -08001034static void
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001035vl_api_app_add_cert_key_pair_t_handler (vl_api_app_add_cert_key_pair_t * mp)
Florin Coras371ca502018-02-21 12:07:41 -08001036{
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001037 vl_api_app_add_cert_key_pair_reply_t *rmp;
1038 vnet_app_add_cert_key_pair_args_t _a, *a = &_a;
1039 u32 certkey_len, key_len, cert_len;
Florin Coras371ca502018-02-21 12:07:41 -08001040 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001041 if (session_main_is_enabled () == 0)
Florin Coras371ca502018-02-21 12:07:41 -08001042 {
1043 rv = VNET_API_ERROR_FEATURE_DISABLED;
1044 goto done;
1045 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001046
Florin Coras371ca502018-02-21 12:07:41 -08001047 cert_len = clib_net_to_host_u16 (mp->cert_len);
Florin Coras5090c572018-03-18 08:22:17 -07001048 if (cert_len > 10000)
1049 {
1050 rv = VNET_API_ERROR_INVALID_VALUE;
1051 goto done;
1052 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001053
1054 certkey_len = clib_net_to_host_u16 (mp->certkey_len);
1055 if (certkey_len < cert_len)
Florin Coras371ca502018-02-21 12:07:41 -08001056 {
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001057 rv = VNET_API_ERROR_INVALID_VALUE;
1058 goto done;
Florin Coras371ca502018-02-21 12:07:41 -08001059 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001060
1061 key_len = certkey_len - cert_len;
1062 if (key_len > 10000)
1063 {
1064 rv = VNET_API_ERROR_INVALID_VALUE;
1065 goto done;
1066 }
1067
1068 clib_memset (a, 0, sizeof (*a));
Florin Corasa5a9efd2021-01-05 17:03:29 -08001069 a->cert = mp->certkey;
1070 a->key = mp->certkey + cert_len;
1071 a->cert_len = cert_len;
1072 a->key_len = key_len;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001073 rv = vnet_app_add_cert_key_pair (a);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001074
Florin Coras371ca502018-02-21 12:07:41 -08001075done:
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001076 /* *INDENT-OFF* */
1077 REPLY_MACRO2 (VL_API_APP_ADD_CERT_KEY_PAIR_REPLY, ({
1078 if (!rv)
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001079 rmp->index = clib_host_to_net_u32 (a->index);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001080 }));
1081 /* *INDENT-ON* */
Florin Coras371ca502018-02-21 12:07:41 -08001082}
1083
1084static void
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001085vl_api_app_del_cert_key_pair_t_handler (vl_api_app_del_cert_key_pair_t * mp)
Florin Coras371ca502018-02-21 12:07:41 -08001086{
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001087 vl_api_app_del_cert_key_pair_reply_t *rmp;
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001088 u32 ckpair_index;
Florin Coras371ca502018-02-21 12:07:41 -08001089 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001090 if (session_main_is_enabled () == 0)
1091 {
1092 rv = VNET_API_ERROR_FEATURE_DISABLED;
1093 goto done;
1094 }
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001095 ckpair_index = clib_net_to_host_u32 (mp->index);
1096 rv = vnet_app_del_cert_key_pair (ckpair_index);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001097
1098done:
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001099 REPLY_MACRO (VL_API_APP_DEL_CERT_KEY_PAIR_REPLY);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001100}
1101
Florin Coras6cf30ad2017-04-04 23:08:23 -07001102static clib_error_t *
1103application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -05001104{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001105 application_t *app = application_lookup (client_index);
1106 vnet_app_detach_args_t _a, *a = &_a;
1107 if (app)
1108 {
Florin Coras15531972018-08-12 23:50:53 -07001109 a->app_index = app->app_index;
Florin Coras053a0e42018-11-13 15:52:38 -08001110 a->api_client_index = client_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001111 vnet_application_detach (a);
1112 }
1113 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001114}
1115
Florin Coras6cf30ad2017-04-04 23:08:23 -07001116VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -05001117
Dave Barach68b0fb02017-02-28 15:15:56 -05001118/*
Florin Coras61ae0562020-09-02 19:10:28 -07001119 * Socket api functions
1120 */
1121
Florin Coras61ae0562020-09-02 19:10:28 -07001122static int
1123mq_send_add_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle)
1124{
Florin Coras20c24232021-11-22 21:19:01 -08001125 session_app_add_segment_msg_t m = { 0 };
Florin Coras61ae0562020-09-02 19:10:28 -07001126 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001127 fifo_segment_t *fs;
1128 ssvm_private_t *sp;
1129 u8 fd_flags = 0;
1130
1131 app_wrk = app_worker_get (app_wrk_index);
1132
1133 fs = segment_manager_get_segment_w_handle (segment_handle);
1134 sp = &fs->ssvm;
1135 ASSERT (ssvm_type (sp) == SSVM_SEGMENT_MEMFD);
1136
1137 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
Florin Coras61ae0562020-09-02 19:10:28 -07001138
Florin Coras20c24232021-11-22 21:19:01 -08001139 m.segment_size = sp->ssvm_size;
1140 m.fd_flags = fd_flags;
1141 m.segment_handle = segment_handle;
1142 strncpy ((char *) m.segment_name, (char *) sp->name,
1143 sizeof (m.segment_name) - 1);
Florin Coras61ae0562020-09-02 19:10:28 -07001144
Florin Coras20c24232021-11-22 21:19:01 -08001145 app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m,
1146 sizeof (m), sp->fd);
Florin Coras61ae0562020-09-02 19:10:28 -07001147
1148 return 0;
1149}
1150
1151static int
1152mq_send_del_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle)
1153{
Florin Coras20c24232021-11-22 21:19:01 -08001154 session_app_del_segment_msg_t m = { 0 };
Florin Coras61ae0562020-09-02 19:10:28 -07001155 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001156
1157 app_wrk = app_worker_get (app_wrk_index);
1158
Florin Coras20c24232021-11-22 21:19:01 -08001159 m.segment_handle = segment_handle;
Florin Coras61ae0562020-09-02 19:10:28 -07001160
Florin Coras20c24232021-11-22 21:19:01 -08001161 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m,
1162 sizeof (m));
Florin Coras61ae0562020-09-02 19:10:28 -07001163
1164 return 0;
1165}
1166
1167static session_cb_vft_t session_mq_sapi_cb_vft = {
1168 .session_accept_callback = mq_send_session_accepted_cb,
1169 .session_disconnect_callback = mq_send_session_disconnected_cb,
1170 .session_connected_callback = mq_send_session_connected_cb,
1171 .session_reset_callback = mq_send_session_reset_cb,
1172 .session_migrate_callback = mq_send_session_migrate_cb,
1173 .session_cleanup_callback = mq_send_session_cleanup_cb,
1174 .add_segment_callback = mq_send_add_segment_sapi_cb,
1175 .del_segment_callback = mq_send_del_segment_sapi_cb,
1176};
1177
1178static void
1179session_api_attach_handler (app_namespace_t * app_ns, clib_socket_t * cs,
1180 app_sapi_attach_msg_t * mp)
1181{
Florin Coras41d5f542021-01-15 13:49:33 -08001182 int rv = 0, *fds = 0, n_fds = 0, i, n_workers;
Florin Coras61ae0562020-09-02 19:10:28 -07001183 vnet_app_attach_args_t _a, *a = &_a;
1184 app_sapi_attach_reply_msg_t *rmp;
Florin Coras61ae0562020-09-02 19:10:28 -07001185 u8 fd_flags = 0, ctrl_thread;
1186 app_ns_api_handle_t *handle;
Florin Coras41d5f542021-01-15 13:49:33 -08001187 fifo_segment_t *rx_mqs_seg;
Florin Coras61ae0562020-09-02 19:10:28 -07001188 app_sapi_msg_t msg = { 0 };
1189 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001190 application_t *app;
Florin Coras41d5f542021-01-15 13:49:33 -08001191 svm_msg_q_t *rx_mq;
Florin Coras61ae0562020-09-02 19:10:28 -07001192
1193 /* Make sure name is null terminated */
1194 mp->name[63] = 0;
1195
1196 clib_memset (a, 0, sizeof (*a));
1197 a->api_client_index = appns_sapi_socket_handle (app_ns, cs);
1198 a->name = format (0, "%s", (char *) mp->name);
1199 a->options = mp->options;
1200 a->session_cb_vft = &session_mq_sapi_cb_vft;
1201 a->use_sock_api = 1;
1202 a->options[APP_OPTIONS_NAMESPACE] = app_namespace_index (app_ns);
1203
1204 if ((rv = vnet_application_attach (a)))
1205 {
1206 clib_warning ("attach returned: %d", rv);
1207 goto done;
1208 }
1209
Florin Coras41d5f542021-01-15 13:49:33 -08001210 n_workers = vlib_num_workers ();
1211 vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers);
1212
Florin Coras61ae0562020-09-02 19:10:28 -07001213 /* Send event queues segment */
Florin Coras41d5f542021-01-15 13:49:33 -08001214 app = application_get (a->app_index);
1215 rx_mqs_seg = application_get_rx_mqs_segment (app);
1216
1217 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
1218 fds[n_fds] = rx_mqs_seg->ssvm.fd;
1219 n_fds += 1;
1220
Florin Coras61ae0562020-09-02 19:10:28 -07001221 /* Send fifo segment fd if needed */
1222 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
1223 {
1224 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1225 fds[n_fds] = a->segment->fd;
1226 n_fds += 1;
1227 }
1228 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
1229 {
1230 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -08001231 fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q);
Florin Coras61ae0562020-09-02 19:10:28 -07001232 n_fds += 1;
1233 }
1234
Florin Coras41d5f542021-01-15 13:49:33 -08001235 if (application_use_private_rx_mqs ())
1236 {
1237 fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD;
1238 for (i = 0; i < n_workers + 1; i++)
1239 {
1240 rx_mq = application_rx_mq_get (app, i);
1241 fds[n_fds] = svm_msg_q_get_eventfd (rx_mq);
1242 n_fds += 1;
1243 }
1244 }
1245
Florin Coras61ae0562020-09-02 19:10:28 -07001246done:
1247
1248 msg.type = APP_SAPI_MSG_TYPE_ATTACH_REPLY;
1249 rmp = &msg.attach_reply;
1250 rmp->retval = rv;
1251 if (!rv)
1252 {
Florin Coras41d5f542021-01-15 13:49:33 -08001253 ctrl_thread = n_workers ? 1 : 0;
Florin Coras61ae0562020-09-02 19:10:28 -07001254 rmp->app_index = a->app_index;
Florin Corasb4624182020-12-11 13:58:12 -08001255 rmp->app_mq =
1256 fifo_segment_msg_q_offset ((fifo_segment_t *) a->segment, 0);
Florin Coras41d5f542021-01-15 13:49:33 -08001257 rmp->vpp_ctrl_mq = fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread);
Florin Coras61ae0562020-09-02 19:10:28 -07001258 rmp->vpp_ctrl_mq_thread = ctrl_thread;
1259 rmp->n_fds = n_fds;
1260 rmp->fd_flags = fd_flags;
1261 /* No segment name and size since we only support memfds
1262 * in this configuration */
1263 rmp->segment_handle = a->segment_handle;
1264 rmp->api_client_handle = a->api_client_index;
1265
1266 /* Update app index for socket */
1267 handle = (app_ns_api_handle_t *) & cs->private_data;
Florin Coras61ae0562020-09-02 19:10:28 -07001268 app_wrk = application_get_worker (app, 0);
1269 handle->aah_app_wrk_index = app_wrk->wrk_index;
1270 }
1271
1272 clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds);
1273 vec_free (a->name);
Florin Coras41d5f542021-01-15 13:49:33 -08001274 vec_free (fds);
Florin Coras61ae0562020-09-02 19:10:28 -07001275}
1276
Florin Coras98078ab2021-08-12 18:12:09 -07001277void
Florin Coras61ae0562020-09-02 19:10:28 -07001278sapi_socket_close_w_handle (u32 api_handle)
1279{
1280 app_namespace_t *app_ns = app_namespace_get (api_handle >> 16);
1281 u16 sock_index = api_handle & 0xffff;
1282 app_ns_api_handle_t *handle;
1283 clib_socket_t *cs;
1284 clib_file_t *cf;
1285
1286 cs = appns_sapi_get_socket (app_ns, sock_index);
1287 if (!cs)
1288 return;
1289
1290 handle = (app_ns_api_handle_t *) & cs->private_data;
1291 cf = clib_file_get (&file_main, handle->aah_file_index);
1292 clib_file_del (&file_main, cf);
1293
1294 clib_socket_close (cs);
1295 appns_sapi_free_socket (app_ns, cs);
1296}
1297
1298static void
1299sapi_add_del_worker_handler (app_namespace_t * app_ns,
1300 clib_socket_t * cs,
1301 app_sapi_worker_add_del_msg_t * mp)
1302{
1303 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1304 app_sapi_worker_add_del_reply_msg_t *rmp;
1305 app_ns_api_handle_t *handle;
1306 app_sapi_msg_t msg = { 0 };
1307 app_worker_t *app_wrk;
Florin Corascc7c88e2020-09-15 15:56:51 -07001308 u32 sapi_handle = -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001309 application_t *app;
Florin Coras61ae0562020-09-02 19:10:28 -07001310 u8 fd_flags = 0;
1311
1312 app = application_get_if_valid (mp->app_index);
1313 if (!app)
1314 {
1315 rv = VNET_API_ERROR_INVALID_VALUE;
1316 goto done;
1317 }
1318
1319 sapi_handle = appns_sapi_socket_handle (app_ns, cs);
1320
1321 vnet_app_worker_add_del_args_t args = {
1322 .app_index = app->app_index,
1323 .wrk_map_index = mp->wrk_index,
1324 .api_client_index = sapi_handle,
1325 .is_add = mp->is_add
1326 };
1327 rv = vnet_app_worker_add_del (&args);
1328 if (rv)
1329 {
1330 clib_warning ("app worker add/del returned: %d", rv);
1331 goto done;
1332 }
1333
1334 if (!mp->is_add)
Florin Coras98078ab2021-08-12 18:12:09 -07001335 goto done;
Florin Coras61ae0562020-09-02 19:10:28 -07001336
1337 /* Send fifo segment fd if needed */
1338 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1339 {
1340 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1341 fds[n_fds] = args.segment->fd;
1342 n_fds += 1;
1343 }
1344 if (application_segment_manager_properties (app)->use_mq_eventfd)
1345 {
1346 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -08001347 fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q);
Florin Coras61ae0562020-09-02 19:10:28 -07001348 n_fds += 1;
1349 }
1350
1351done:
1352
1353 msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_WORKER_REPLY;
1354 rmp = &msg.worker_add_del_reply;
1355 rmp->retval = rv;
1356 rmp->is_add = mp->is_add;
Florin Corascc7c88e2020-09-15 15:56:51 -07001357 rmp->api_client_handle = sapi_handle;
Florin Coras61ae0562020-09-02 19:10:28 -07001358 rmp->wrk_index = args.wrk_map_index;
1359 rmp->segment_handle = args.segment_handle;
1360 if (!rv && mp->is_add)
1361 {
1362 /* No segment name and size. This supports only memfds */
Florin Corasb4624182020-12-11 13:58:12 -08001363 rmp->app_event_queue_address =
1364 fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0);
Florin Coras61ae0562020-09-02 19:10:28 -07001365 rmp->n_fds = n_fds;
1366 rmp->fd_flags = fd_flags;
1367
1368 /* Update app index for socket */
1369 handle = (app_ns_api_handle_t *) & cs->private_data;
1370 app_wrk = application_get_worker (app, args.wrk_map_index);
1371 handle->aah_app_wrk_index = app_wrk->wrk_index;
1372 }
1373
1374 clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds);
1375}
1376
Filip Tehlar447e51d2022-02-18 08:49:43 +00001377/* This is a workaround for the case when session layer starts reading
1378 * the socket before the client actualy sends the data
1379 */
1380static clib_error_t *
1381sapi_socket_receive_wait (clib_socket_t *cs, u8 *msg, u32 msg_len)
1382{
1383 clib_error_t *err;
1384 int n_tries = 5;
1385
1386 while (1)
1387 {
1388 err = clib_socket_recvmsg (cs, msg, msg_len, 0, 0);
1389 if (!err)
1390 break;
1391
1392 if (!n_tries)
1393 return err;
1394
1395 n_tries--;
1396 usleep (1);
1397 }
1398
1399 return err;
1400}
1401
Florin Coras61ae0562020-09-02 19:10:28 -07001402static void
Florin Corase191d762021-08-11 14:55:49 -07001403sapi_add_del_cert_key_handler (app_namespace_t *app_ns, clib_socket_t *cs,
1404 app_sapi_cert_key_add_del_msg_t *mp)
1405{
1406 vnet_app_add_cert_key_pair_args_t _a, *a = &_a;
1407 app_sapi_cert_key_add_del_reply_msg_t *rmp;
1408 app_sapi_msg_t msg = { 0 };
1409 int rv = 0;
1410
1411 if (mp->is_add)
1412 {
1413 const u32 max_certkey_len = 2e4, max_cert_len = 1e4, max_key_len = 1e4;
1414 clib_error_t *err;
1415 u8 *certkey = 0;
1416 u32 key_len;
1417
1418 if (mp->certkey_len > max_certkey_len)
1419 {
1420 rv = SESSION_E_INVALID;
1421 goto send_reply;
1422 }
1423
1424 vec_validate (certkey, mp->certkey_len - 1);
Filip Tehlar447e51d2022-02-18 08:49:43 +00001425
1426 err = sapi_socket_receive_wait (cs, certkey, mp->certkey_len);
Florin Corase191d762021-08-11 14:55:49 -07001427 if (err)
1428 {
1429 clib_error_report (err);
Florin Corase191d762021-08-11 14:55:49 -07001430 rv = SESSION_E_INVALID;
1431 goto send_reply;
1432 }
1433
1434 if (mp->cert_len > max_cert_len)
1435 {
1436 rv = SESSION_E_INVALID;
1437 goto send_reply;
1438 }
1439
1440 if (mp->certkey_len < mp->cert_len)
1441 {
1442 rv = SESSION_E_INVALID;
1443 goto send_reply;
1444 }
1445
1446 key_len = mp->certkey_len - mp->cert_len;
1447 if (key_len > max_key_len)
1448 {
1449 rv = SESSION_E_INVALID;
1450 goto send_reply;
1451 }
1452
1453 clib_memset (a, 0, sizeof (*a));
1454 a->cert = certkey;
1455 a->key = certkey + mp->cert_len;
1456 a->cert_len = mp->cert_len;
1457 a->key_len = key_len;
1458 rv = vnet_app_add_cert_key_pair (a);
1459
1460 vec_free (certkey);
1461 }
1462 else
1463 {
1464 rv = vnet_app_del_cert_key_pair (mp->index);
1465 }
1466
1467send_reply:
1468
1469 msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY_REPLY;
1470 rmp = &msg.cert_key_add_del_reply;
1471 rmp->retval = rv;
1472 rmp->context = mp->context;
1473 if (!rv && mp->is_add)
1474 rmp->index = a->index;
1475
1476 clib_socket_sendmsg (cs, &msg, sizeof (msg), 0, 0);
1477}
1478
1479static void
Florin Coras61ae0562020-09-02 19:10:28 -07001480sapi_socket_detach (app_namespace_t * app_ns, clib_socket_t * cs)
1481{
Florin Coras61ae0562020-09-02 19:10:28 -07001482 app_ns_api_handle_t *handle;
1483 app_worker_t *app_wrk;
1484 u32 api_client_handle;
1485
1486 api_client_handle = appns_sapi_socket_handle (app_ns, cs);
Florin Coras61ae0562020-09-02 19:10:28 -07001487
Florin Corasf99a7d62020-09-14 10:29:29 -07001488 /* Cleanup everything because app worker closed socket or crashed */
Florin Coras61ae0562020-09-02 19:10:28 -07001489 handle = (app_ns_api_handle_t *) & cs->private_data;
Filip Tehlar9c32f052022-03-11 11:12:56 +00001490 app_wrk = app_worker_get_if_valid (handle->aah_app_wrk_index);
1491 if (!app_wrk)
1492 return;
Florin Corasf99a7d62020-09-14 10:29:29 -07001493
1494 vnet_app_worker_add_del_args_t args = {
1495 .app_index = app_wrk->app_index,
1496 .wrk_map_index = app_wrk->wrk_map_index,
1497 .api_client_index = api_client_handle,
1498 .is_add = 0
1499 };
1500 /* Send rpc to main thread for worker barrier */
1501 vlib_rpc_call_main_thread (vnet_app_worker_add_del, (u8 *) & args,
1502 sizeof (args));
Florin Coras61ae0562020-09-02 19:10:28 -07001503}
1504
1505static clib_error_t *
1506sapi_sock_read_ready (clib_file_t * cf)
1507{
1508 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
Florin Coras7360e3d2020-09-18 16:15:47 -07001509 vlib_main_t *vm = vlib_get_main ();
Florin Coras61ae0562020-09-02 19:10:28 -07001510 app_sapi_msg_t msg = { 0 };
1511 app_namespace_t *app_ns;
1512 clib_error_t *err = 0;
1513 clib_socket_t *cs;
1514
1515 app_ns = app_namespace_get (handle->aah_app_ns_index);
1516 cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index);
1517 if (!cs)
1518 goto error;
1519
1520 err = clib_socket_recvmsg (cs, &msg, sizeof (msg), 0, 0);
1521 if (err)
1522 {
1523 clib_error_free (err);
1524 sapi_socket_detach (app_ns, cs);
1525 goto error;
1526 }
1527
1528 handle = (app_ns_api_handle_t *) & cs->private_data;
1529
Florin Coras7360e3d2020-09-18 16:15:47 -07001530 vlib_worker_thread_barrier_sync (vm);
1531
Florin Coras61ae0562020-09-02 19:10:28 -07001532 switch (msg.type)
1533 {
1534 case APP_SAPI_MSG_TYPE_ATTACH:
1535 session_api_attach_handler (app_ns, cs, &msg.attach);
1536 break;
1537 case APP_SAPI_MSG_TYPE_ADD_DEL_WORKER:
1538 sapi_add_del_worker_handler (app_ns, cs, &msg.worker_add_del);
1539 break;
Florin Corase191d762021-08-11 14:55:49 -07001540 case APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY:
1541 sapi_add_del_cert_key_handler (app_ns, cs, &msg.cert_key_add_del);
1542 break;
Florin Coras61ae0562020-09-02 19:10:28 -07001543 default:
1544 clib_warning ("app wrk %u unknown message type: %u",
1545 handle->aah_app_wrk_index, msg.type);
1546 break;
1547 }
1548
Florin Coras7360e3d2020-09-18 16:15:47 -07001549 vlib_worker_thread_barrier_release (vm);
1550
Florin Coras61ae0562020-09-02 19:10:28 -07001551error:
1552 return 0;
1553}
1554
1555static clib_error_t *
1556sapi_sock_write_ready (clib_file_t * cf)
1557{
1558 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
1559 clib_warning ("called for app ns %u", handle->aah_app_ns_index);
1560 return 0;
1561}
1562
1563static clib_error_t *
1564sapi_sock_error (clib_file_t * cf)
1565{
1566 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
1567 app_namespace_t *app_ns;
1568 clib_socket_t *cs;
1569
1570 app_ns = app_namespace_get (handle->aah_app_ns_index);
1571 cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index);
1572 if (!cs)
1573 return 0;
1574
1575 sapi_socket_detach (app_ns, cs);
1576 return 0;
1577}
1578
1579static clib_error_t *
1580sapi_sock_accept_ready (clib_file_t * scf)
1581{
1582 app_ns_api_handle_t handle = *(app_ns_api_handle_t *) & scf->private_data;
1583 app_namespace_t *app_ns;
1584 clib_file_t cf = { 0 };
1585 clib_error_t *err = 0;
1586 clib_socket_t *ccs, *scs;
1587
1588 /* Listener files point to namespace */
1589 app_ns = app_namespace_get (handle.aah_app_ns_index);
1590
1591 /*
1592 * Initialize client socket
1593 */
1594 ccs = appns_sapi_alloc_socket (app_ns);
1595
1596 /* Grab server socket after client is initialized */
1597 scs = appns_sapi_get_socket (app_ns, handle.aah_sock_index);
1598 if (!scs)
1599 goto error;
1600
1601 err = clib_socket_accept (scs, ccs);
1602 if (err)
1603 {
1604 clib_error_report (err);
1605 goto error;
1606 }
1607
1608 cf.read_function = sapi_sock_read_ready;
1609 cf.write_function = sapi_sock_write_ready;
1610 cf.error_function = sapi_sock_error;
1611 cf.file_descriptor = ccs->fd;
1612 /* File points to app namespace and socket */
1613 handle.aah_sock_index = appns_sapi_socket_index (app_ns, ccs);
Florin Coras6b6c10b2020-09-24 11:58:28 -07001614 cf.private_data = handle.as_u64;
Florin Coras61ae0562020-09-02 19:10:28 -07001615 cf.description = format (0, "app sock conn fd: %d", ccs->fd);
1616
1617 /* Poll until we get an attach message. Socket points to file and
1618 * application that owns the socket */
1619 handle.aah_app_wrk_index = APP_INVALID_INDEX;
1620 handle.aah_file_index = clib_file_add (&file_main, &cf);
Florin Coras6b6c10b2020-09-24 11:58:28 -07001621 ccs->private_data = handle.as_u64;
Florin Coras61ae0562020-09-02 19:10:28 -07001622
1623 return err;
1624
1625error:
1626 appns_sapi_free_socket (app_ns, ccs);
1627 return err;
1628}
1629
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +02001630void
1631appns_sapi_del_ns_socket (app_namespace_t *app_ns)
1632{
1633 app_ns_api_handle_t *handle;
1634 clib_socket_t *cs;
1635
1636 pool_foreach (cs, app_ns->app_sockets)
1637 {
1638 handle = (app_ns_api_handle_t *) &cs->private_data;
1639 clib_file_del_by_index (&file_main, handle->aah_file_index);
1640
1641 clib_socket_close (cs);
1642 clib_socket_free (cs);
1643 }
1644 pool_free (app_ns->app_sockets);
1645}
1646
Florin Coras61ae0562020-09-02 19:10:28 -07001647int
1648appns_sapi_add_ns_socket (app_namespace_t * app_ns)
1649{
1650 char *subdir = "/app_ns_sockets/";
1651 app_ns_api_handle_t *handle;
1652 clib_file_t cf = { 0 };
1653 struct stat file_stat;
1654 clib_error_t *err;
1655 clib_socket_t *cs;
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001656 char dir[4096];
Florin Coras61ae0562020-09-02 19:10:28 -07001657
Florin Coras7cb471a2021-07-23 08:39:26 -07001658 if (app_ns->netns)
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +02001659 {
1660 if (!app_ns->sock_name)
1661 app_ns->sock_name = format (0, "@vpp/session/%v%c", app_ns->ns_id, 0);
1662 if (app_ns->sock_name[0] != '@')
1663 return VNET_API_ERROR_INVALID_VALUE;
1664 }
Florin Coras7cb471a2021-07-23 08:39:26 -07001665 else
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +02001666 {
1667 snprintf (dir, sizeof (dir), "%s%s", vlib_unix_get_runtime_dir (),
1668 subdir);
1669 err = vlib_unix_recursive_mkdir ((char *) dir);
1670 if (err)
1671 {
1672 clib_error_report (err);
1673 return VNET_API_ERROR_SYSCALL_ERROR_1;
1674 }
1675
1676 if (!app_ns->sock_name)
1677 app_ns->sock_name = format (0, "%s%v%c", dir, app_ns->ns_id, 0);
1678 }
Florin Coras61ae0562020-09-02 19:10:28 -07001679
1680 /*
1681 * Create and initialize socket to listen on
1682 */
1683 cs = appns_sapi_alloc_socket (app_ns);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +02001684 cs->config = (char *) vec_dup (app_ns->sock_name);
Florin Coras61ae0562020-09-02 19:10:28 -07001685 cs->flags = CLIB_SOCKET_F_IS_SERVER |
1686 CLIB_SOCKET_F_ALLOW_GROUP_WRITE |
1687 CLIB_SOCKET_F_SEQPACKET | CLIB_SOCKET_F_PASSCRED;
1688
Florin Coras7cb471a2021-07-23 08:39:26 -07001689 if ((err = clib_socket_init_netns (cs, app_ns->netns)))
Florin Coras61ae0562020-09-02 19:10:28 -07001690 {
1691 clib_error_report (err);
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001692 return -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001693 }
1694
Florin Coras7cb471a2021-07-23 08:39:26 -07001695 if (!app_ns->netns && stat ((char *) app_ns->sock_name, &file_stat) == -1)
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001696 return -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001697
1698 /*
1699 * Start polling it
1700 */
1701 cf.read_function = sapi_sock_accept_ready;
1702 cf.file_descriptor = cs->fd;
1703 /* File points to namespace */
1704 handle = (app_ns_api_handle_t *) & cf.private_data;
1705 handle->aah_app_ns_index = app_namespace_index (app_ns);
1706 handle->aah_sock_index = appns_sapi_socket_index (app_ns, cs);
1707 cf.description = format (0, "app sock listener: %s", app_ns->sock_name);
1708
1709 /* Socket points to clib file index */
1710 handle = (app_ns_api_handle_t *) & cs->private_data;
1711 handle->aah_file_index = clib_file_add (&file_main, &cf);
1712 handle->aah_app_wrk_index = APP_INVALID_INDEX;
1713
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001714 return 0;
Florin Coras61ae0562020-09-02 19:10:28 -07001715}
1716
Filip Tehlar0046e972021-06-26 22:12:08 +00001717#include <vnet/session/session.api.c>
1718static clib_error_t *
1719session_api_hookup (vlib_main_t *vm)
1720{
1721 /*
1722 * Set up the (msg_name, crc, message-id) table
1723 */
1724 REPLY_MSG_ID_BASE = setup_message_id_table ();
1725
1726 return 0;
1727}
1728
1729VLIB_API_INIT_FUNCTION (session_api_hookup);
1730
Florin Coras61ae0562020-09-02 19:10:28 -07001731/*
Dave Barach68b0fb02017-02-28 15:15:56 -05001732 * fd.io coding-style-patch-verification: ON
1733 *
1734 * Local Variables:
1735 * eval: (c-set-style "gnu")
1736 * End:
1737 */