blob: 615e2ade59cefba9fff605b1b8f731b960e193b6 [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 {
317 m.rx_fifo = fifo_segment_fifo_offset (ls->rx_fifo);
318 m.tx_fifo = fifo_segment_fifo_offset (ls->tx_fifo);
319 m.segment_handle = session_segment_handle (ls);
320 }
321
322snd_msg:
323
Florin Coras20c24232021-11-22 21:19:01 -0800324 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_BOUND, &m, sizeof (m));
Florin Coras60116992018-08-27 09:52:18 -0700325
Florin Coras60116992018-08-27 09:52:18 -0700326 return 0;
327}
328
Florin Coras458089b2019-08-21 16:20:44 -0700329void
330mq_send_unlisten_reply (app_worker_t * app_wrk, session_handle_t sh,
331 u32 context, int rv)
332{
Florin Coras20c24232021-11-22 21:19:01 -0800333 session_unlisten_reply_msg_t m = { 0 };
Florin Coras458089b2019-08-21 16:20:44 -0700334
Florin Coras20c24232021-11-22 21:19:01 -0800335 m.context = context;
336 m.handle = sh;
337 m.retval = rv;
338 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_UNLISTEN_REPLY, &m,
339 sizeof (m));
Florin Coras458089b2019-08-21 16:20:44 -0700340}
341
Florin Coras49568af2019-07-31 16:46:24 -0700342static void
343mq_send_session_migrate_cb (session_t * s, session_handle_t new_sh)
344{
Florin Coras09bf91a2021-02-23 08:44:13 -0800345 session_migrated_msg_t m = { 0 };
Florin Corasb4624182020-12-11 13:58:12 -0800346 fifo_segment_t *eq_seg;
Florin Coras68b7e582020-01-21 18:33:23 -0800347 app_worker_t *app_wrk;
Florin Coras41d5f542021-01-15 13:49:33 -0800348 application_t *app;
Florin Corasb4624182020-12-11 13:58:12 -0800349 u32 thread_index;
350
351 thread_index = session_thread_from_handle (new_sh);
Florin Coras41d5f542021-01-15 13:49:33 -0800352 app_wrk = app_worker_get (s->app_wrk_index);
Florin Coras41d5f542021-01-15 13:49:33 -0800353 app = application_get (app_wrk->app_index);
354 eq_seg = application_get_rx_mqs_segment (app);
Florin Coras68b7e582020-01-21 18:33:23 -0800355
Florin Coras09bf91a2021-02-23 08:44:13 -0800356 m.handle = session_handle (s);
357 m.new_handle = new_sh;
358 m.vpp_thread_index = thread_index;
359 m.vpp_evt_q = fifo_segment_msg_q_offset (eq_seg, thread_index);
360 m.segment_handle = SESSION_INVALID_HANDLE;
361
Florin Coras20c24232021-11-22 21:19:01 -0800362 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_MIGRATED, &m, sizeof (m));
Florin Coras49568af2019-07-31 16:46:24 -0700363}
364
Florin Corasc4c4cf52019-08-24 18:17:34 -0700365static int
366mq_send_add_segment_cb (u32 app_wrk_index, u64 segment_handle)
367{
Florin Coras20c24232021-11-22 21:19:01 -0800368 session_app_add_segment_msg_t m = { 0 };
Florin Corasc4c4cf52019-08-24 18:17:34 -0700369 vl_api_registration_t *reg;
370 app_worker_t *app_wrk;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700371 fifo_segment_t *fs;
372 ssvm_private_t *sp;
373 u8 fd_flags = 0;
374
375 app_wrk = app_worker_get (app_wrk_index);
376
377 reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
378 if (!reg)
379 {
380 clib_warning ("no api registration for client: %u",
381 app_wrk->api_client_index);
382 return -1;
383 }
384
385 fs = segment_manager_get_segment_w_handle (segment_handle);
386 sp = &fs->ssvm;
387 if (ssvm_type (sp) == SSVM_SEGMENT_MEMFD)
388 {
389 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
390 {
391 clib_warning ("can't send memfd fd");
392 return -1;
393 }
394
395 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700396 }
397
Florin Coras20c24232021-11-22 21:19:01 -0800398 m.segment_size = sp->ssvm_size;
399 m.fd_flags = fd_flags;
400 m.segment_handle = segment_handle;
401 strncpy ((char *) m.segment_name, (char *) sp->name,
402 sizeof (m.segment_name) - 1);
Florin Corasc4c4cf52019-08-24 18:17:34 -0700403
Florin Coras20c24232021-11-22 21:19:01 -0800404 app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m,
405 sizeof (m), sp->fd);
Florin Corasc4c4cf52019-08-24 18:17:34 -0700406
407 return 0;
408}
409
410static int
411mq_send_del_segment_cb (u32 app_wrk_index, u64 segment_handle)
412{
Florin Coras20c24232021-11-22 21:19:01 -0800413 session_app_del_segment_msg_t m = { 0 };
Florin Corasc4c4cf52019-08-24 18:17:34 -0700414 vl_api_registration_t *reg;
415 app_worker_t *app_wrk;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700416
417 app_wrk = app_worker_get (app_wrk_index);
418 reg = vl_mem_api_client_index_to_registration (app_wrk->api_client_index);
419 if (!reg)
420 {
421 clib_warning ("no registration: %u", app_wrk->api_client_index);
422 return -1;
423 }
424
Florin Coras20c24232021-11-22 21:19:01 -0800425 m.segment_handle = segment_handle;
Florin Corasc4c4cf52019-08-24 18:17:34 -0700426
Florin Coras20c24232021-11-22 21:19:01 -0800427 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m,
428 sizeof (m));
Florin Corasc4c4cf52019-08-24 18:17:34 -0700429
430 return 0;
431}
432
Florin Coras9ace36d2019-10-28 13:14:17 -0700433static void
434mq_send_session_cleanup_cb (session_t * s, session_cleanup_ntf_t ntf)
435{
Florin Coras20c24232021-11-22 21:19:01 -0800436 session_cleanup_msg_t m = { 0 };
Florin Coras9ace36d2019-10-28 13:14:17 -0700437 app_worker_t *app_wrk;
438
Florin Coras36d49392020-04-24 23:00:11 +0000439 /* Propagate transport cleanup notifications only if app didn't close */
440 if (ntf == SESSION_CLEANUP_TRANSPORT
441 && s->session_state != SESSION_STATE_TRANSPORT_DELETED)
Florin Coras9ace36d2019-10-28 13:14:17 -0700442 return;
443
444 app_wrk = app_worker_get_if_valid (s->app_wrk_index);
445 if (!app_wrk)
446 return;
447
Florin Coras20c24232021-11-22 21:19:01 -0800448 m.handle = session_handle (s);
449 m.type = ntf;
Florin Coras9ace36d2019-10-28 13:14:17 -0700450
Florin Coras20c24232021-11-22 21:19:01 -0800451 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_CLEANUP, &m, sizeof (m));
Florin Coras9ace36d2019-10-28 13:14:17 -0700452}
453
Florin Corasc4c4cf52019-08-24 18:17:34 -0700454static session_cb_vft_t session_mq_cb_vft = {
455 .session_accept_callback = mq_send_session_accepted_cb,
456 .session_disconnect_callback = mq_send_session_disconnected_cb,
457 .session_connected_callback = mq_send_session_connected_cb,
458 .session_reset_callback = mq_send_session_reset_cb,
459 .session_migrate_callback = mq_send_session_migrate_cb,
Florin Coras9ace36d2019-10-28 13:14:17 -0700460 .session_cleanup_callback = mq_send_session_cleanup_cb,
Florin Corasc4c4cf52019-08-24 18:17:34 -0700461 .add_segment_callback = mq_send_add_segment_cb,
462 .del_segment_callback = mq_send_del_segment_cb,
463};
464
Dave Barach68b0fb02017-02-28 15:15:56 -0500465static void
Florin Corase04c2992017-03-01 08:17:34 -0800466vl_api_session_enable_disable_t_handler (vl_api_session_enable_disable_t * mp)
467{
468 vl_api_session_enable_disable_reply_t *rmp;
469 vlib_main_t *vm = vlib_get_main ();
470 int rv = 0;
471
472 vnet_session_enable_disable (vm, mp->is_enable);
473 REPLY_MACRO (VL_API_SESSION_ENABLE_DISABLE_REPLY);
474}
475
Dave Barach68b0fb02017-02-28 15:15:56 -0500476static void
Nathan Skrzypczak7b3a3df2021-07-28 14:09:50 +0200477vl_api_session_sapi_enable_disable_t_handler (
478 vl_api_session_sapi_enable_disable_t *mp)
479{
480 vl_api_session_sapi_enable_disable_reply_t *rmp;
481 int rv = 0;
482
483 rv = appns_sapi_enable_disable (mp->is_enable);
484 REPLY_MACRO (VL_API_SESSION_SAPI_ENABLE_DISABLE_REPLY);
485}
486
487static void
Florin Coras458089b2019-08-21 16:20:44 -0700488vl_api_app_attach_t_handler (vl_api_app_attach_t * mp)
489{
Florin Coras41d5f542021-01-15 13:49:33 -0800490 int rv = 0, *fds = 0, n_fds = 0, n_workers, i;
491 fifo_segment_t *segp, *rx_mqs_seg = 0;
Florin Coras458089b2019-08-21 16:20:44 -0700492 vnet_app_attach_args_t _a, *a = &_a;
Florin Coras41d5f542021-01-15 13:49:33 -0800493 vl_api_app_attach_reply_t *rmp;
Florin Coras458089b2019-08-21 16:20:44 -0700494 u8 fd_flags = 0, ctrl_thread;
495 vl_api_registration_t *reg;
Florin Coras41d5f542021-01-15 13:49:33 -0800496 svm_msg_q_t *rx_mq;
497 application_t *app;
Florin Coras458089b2019-08-21 16:20:44 -0700498
499 reg = vl_api_client_index_to_registration (mp->client_index);
500 if (!reg)
501 return;
502
Florin Coras41d5f542021-01-15 13:49:33 -0800503 n_workers = vlib_num_workers ();
Florin Coras61ae0562020-09-02 19:10:28 -0700504 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras458089b2019-08-21 16:20:44 -0700505 {
506 rv = VNET_API_ERROR_FEATURE_DISABLED;
507 goto done;
508 }
Florin Coras6c10ab22020-11-08 16:50:39 -0800509 /* Only support binary api with socket transport */
510 if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI)
511 {
512 rv = VNET_API_ERROR_APP_UNSUPPORTED_CFG;
513 goto done;
514 }
Florin Coras458089b2019-08-21 16:20:44 -0700515
516 STATIC_ASSERT (sizeof (u64) * APP_OPTIONS_N_OPTIONS <=
517 sizeof (mp->options),
518 "Out of options, fix api message definition");
519
520 clib_memset (a, 0, sizeof (*a));
521 a->api_client_index = mp->client_index;
522 a->options = mp->options;
523 a->session_cb_vft = &session_mq_cb_vft;
Dave Barach77841402020-04-29 17:04:10 -0400524 a->namespace_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id);
Florin Coras458089b2019-08-21 16:20:44 -0700525
526 if ((rv = vnet_application_attach (a)))
527 {
528 clib_warning ("attach returned: %d", rv);
529 vec_free (a->namespace_id);
530 goto done;
531 }
532 vec_free (a->namespace_id);
533
Florin Coras41d5f542021-01-15 13:49:33 -0800534 vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers);
535
536 /* Send rx mqs segment */
537 app = application_get (a->app_index);
538 rx_mqs_seg = application_get_rx_mqs_segment (app);
539
540 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
541 fds[n_fds] = rx_mqs_seg->ssvm.fd;
542 n_fds += 1;
543
Florin Coras458089b2019-08-21 16:20:44 -0700544 /* Send fifo segment fd if needed */
545 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
546 {
547 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
548 fds[n_fds] = a->segment->fd;
549 n_fds += 1;
550 }
551 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
552 {
553 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -0800554 fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q);
Florin Coras458089b2019-08-21 16:20:44 -0700555 n_fds += 1;
556 }
557
Florin Coras41d5f542021-01-15 13:49:33 -0800558 if (application_use_private_rx_mqs ())
559 {
560 fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD;
561 for (i = 0; i < n_workers + 1; i++)
562 {
563 rx_mq = application_rx_mq_get (app, i);
564 fds[n_fds] = svm_msg_q_get_eventfd (rx_mq);
565 n_fds += 1;
566 }
567 }
568
Florin Coras458089b2019-08-21 16:20:44 -0700569done:
Florin Coras458089b2019-08-21 16:20:44 -0700570 /* *INDENT-OFF* */
Klement Sekera0eb83f42021-12-02 16:36:34 +0000571 REPLY_MACRO3 (
572 VL_API_APP_ATTACH_REPLY,
573 ((!rv) ? vec_len (((fifo_segment_t *) a->segment)->ssvm.name) : 0), ({
574 if (!rv)
575 {
576 ctrl_thread = n_workers ? 1 : 0;
577 segp = (fifo_segment_t *) a->segment;
578 rmp->app_index = clib_host_to_net_u32 (a->app_index);
579 rmp->app_mq = fifo_segment_msg_q_offset (segp, 0);
580 rmp->vpp_ctrl_mq =
581 fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread);
582 rmp->vpp_ctrl_mq_thread = ctrl_thread;
583 rmp->n_fds = n_fds;
584 rmp->fd_flags = fd_flags;
585 if (vec_len (segp->ssvm.name))
586 {
587 vl_api_vec_to_api_string (segp->ssvm.name, &rmp->segment_name);
588 }
589 rmp->segment_size = segp->ssvm.ssvm_size;
590 rmp->segment_handle = clib_host_to_net_u64 (a->segment_handle);
591 }
592 }));
Florin Coras458089b2019-08-21 16:20:44 -0700593 /* *INDENT-ON* */
594
595 if (n_fds)
596 session_send_fds (reg, fds, n_fds);
Florin Coras41d5f542021-01-15 13:49:33 -0800597 vec_free (fds);
Florin Coras458089b2019-08-21 16:20:44 -0700598}
599
Florin Corascea194d2017-10-02 00:18:51 -0700600static void
Florin Coras15531972018-08-12 23:50:53 -0700601vl_api_app_worker_add_del_t_handler (vl_api_app_worker_add_del_t * mp)
602{
603 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
604 vl_api_app_worker_add_del_reply_t *rmp;
605 vl_api_registration_t *reg;
Florin Coras15531972018-08-12 23:50:53 -0700606 application_t *app;
607 u8 fd_flags = 0;
608
Florin Coras61ae0562020-09-02 19:10:28 -0700609 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras15531972018-08-12 23:50:53 -0700610 {
611 rv = VNET_API_ERROR_FEATURE_DISABLED;
612 goto done;
613 }
614
615 reg = vl_api_client_index_to_registration (mp->client_index);
616 if (!reg)
617 return;
618
Florin Corasc1f5a432018-11-20 11:31:26 -0800619 app = application_get_if_valid (clib_net_to_host_u32 (mp->app_index));
Florin Coras15531972018-08-12 23:50:53 -0700620 if (!app)
621 {
622 rv = VNET_API_ERROR_INVALID_VALUE;
623 goto done;
624 }
625
626 vnet_app_worker_add_del_args_t args = {
627 .app_index = app->app_index,
Florin Coras349f8ca2018-11-20 16:52:49 -0800628 .wrk_map_index = clib_net_to_host_u32 (mp->wrk_index),
Florin Corasc1f5a432018-11-20 11:31:26 -0800629 .api_client_index = mp->client_index,
Florin Coras15531972018-08-12 23:50:53 -0700630 .is_add = mp->is_add
631 };
Florin Corasc1a42652019-02-08 18:27:29 -0800632 rv = vnet_app_worker_add_del (&args);
633 if (rv)
Florin Coras15531972018-08-12 23:50:53 -0700634 {
Florin Corasc1a42652019-02-08 18:27:29 -0800635 clib_warning ("app worker add/del returned: %d", rv);
Florin Coras15531972018-08-12 23:50:53 -0700636 goto done;
637 }
638
Florin Coras14598772018-09-04 19:47:52 -0700639 if (!mp->is_add)
640 goto done;
Florin Corasc3638fe2018-08-24 13:58:49 -0700641
Florin Coras15531972018-08-12 23:50:53 -0700642 /* Send fifo segment fd if needed */
643 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
644 {
645 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
646 fds[n_fds] = args.segment->fd;
647 n_fds += 1;
648 }
649 if (application_segment_manager_properties (app)->use_mq_eventfd)
650 {
651 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -0800652 fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q);
Florin Coras15531972018-08-12 23:50:53 -0700653 n_fds += 1;
654 }
655
656 /* *INDENT-OFF* */
657done:
Klement Sekera0eb83f42021-12-02 16:36:34 +0000658 REPLY_MACRO3 (
659 VL_API_APP_WORKER_ADD_DEL_REPLY,
660 ((!rv && mp->is_add) ? vec_len (args.segment->name) : 0), ({
661 rmp->is_add = mp->is_add;
662 rmp->wrk_index = clib_host_to_net_u32 (args.wrk_map_index);
663 rmp->segment_handle = clib_host_to_net_u64 (args.segment_handle);
664 if (!rv && mp->is_add)
665 {
666 rmp->app_event_queue_address =
667 fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0);
668 rmp->n_fds = n_fds;
669 rmp->fd_flags = fd_flags;
670 if (vec_len (args.segment->name))
671 {
672 vl_api_vec_to_api_string (args.segment->name,
673 &rmp->segment_name);
674 }
675 }
676 }));
Florin Coras15531972018-08-12 23:50:53 -0700677 /* *INDENT-ON* */
678
679 if (n_fds)
680 session_send_fds (reg, fds, n_fds);
681}
682
683static void
Florin Coras888d9f02020-04-02 23:00:13 +0000684vl_api_application_detach_t_handler (vl_api_application_detach_t * mp)
685{
686 vl_api_application_detach_reply_t *rmp;
687 int rv = VNET_API_ERROR_INVALID_VALUE_2;
688 vnet_app_detach_args_t _a, *a = &_a;
689 application_t *app;
690
Florin Coras61ae0562020-09-02 19:10:28 -0700691 if (!session_main_is_enabled () || appns_sapi_enabled ())
Florin Coras888d9f02020-04-02 23:00:13 +0000692 {
693 rv = VNET_API_ERROR_FEATURE_DISABLED;
694 goto done;
695 }
696
697 app = application_lookup (mp->client_index);
698 if (app)
699 {
700 a->app_index = app->app_index;
701 a->api_client_index = mp->client_index;
702 rv = vnet_application_detach (a);
703 }
704
705done:
706 REPLY_MACRO (VL_API_APPLICATION_DETACH_REPLY);
707}
708
709static void
Florin Corascea194d2017-10-02 00:18:51 -0700710vl_api_app_namespace_add_del_t_handler (vl_api_app_namespace_add_del_t * mp)
711{
712 vl_api_app_namespace_add_del_reply_t *rmp;
Florin Coras6e8c6672017-11-10 09:03:54 -0800713 u32 appns_index = 0;
714 u8 *ns_id = 0;
Florin Corascea194d2017-10-02 00:18:51 -0700715 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +0200716 if (session_main_is_enabled () == 0)
Florin Corascea194d2017-10-02 00:18:51 -0700717 {
718 rv = VNET_API_ERROR_FEATURE_DISABLED;
719 goto done;
720 }
721
Dave Barach77841402020-04-29 17:04:10 -0400722 ns_id = vl_api_from_api_to_new_vec (mp, &mp->namespace_id);
Florin Corascea194d2017-10-02 00:18:51 -0700723
Florin Corascea194d2017-10-02 00:18:51 -0700724 vnet_app_namespace_add_del_args_t args = {
725 .ns_id = ns_id,
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200726 .netns = 0,
727 .sock_name = 0,
Florin Coras9a9adb22017-10-26 08:16:59 -0700728 .secret = clib_net_to_host_u64 (mp->secret),
Florin Corascea194d2017-10-02 00:18:51 -0700729 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
730 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
731 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
732 .is_add = 1
733 };
Florin Corasc1a42652019-02-08 18:27:29 -0800734 rv = vnet_app_namespace_add_del (&args);
735 if (!rv)
Florin Coras6e8c6672017-11-10 09:03:54 -0800736 {
737 appns_index = app_namespace_index_from_id (ns_id);
738 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
739 {
740 clib_warning ("app ns lookup failed");
741 rv = VNET_API_ERROR_UNSPECIFIED;
742 }
743 }
Florin Corascea194d2017-10-02 00:18:51 -0700744 vec_free (ns_id);
Florin Coras6e8c6672017-11-10 09:03:54 -0800745
746 /* *INDENT-OFF* */
Florin Corascea194d2017-10-02 00:18:51 -0700747done:
Florin Coras6e8c6672017-11-10 09:03:54 -0800748 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_REPLY, ({
749 if (!rv)
750 rmp->appns_index = clib_host_to_net_u32 (appns_index);
751 }));
752 /* *INDENT-ON* */
Florin Corascea194d2017-10-02 00:18:51 -0700753}
754
Florin Coras1c710452017-10-17 00:03:13 -0700755static void
Florin Coras7cb471a2021-07-23 08:39:26 -0700756vl_api_app_namespace_add_del_v2_t_handler (
757 vl_api_app_namespace_add_del_v2_t *mp)
758{
759 vl_api_app_namespace_add_del_v2_reply_t *rmp;
760 u8 *ns_id = 0, *netns = 0;
761 u32 appns_index = 0;
762 int rv = 0;
763
764 if (session_main_is_enabled () == 0)
765 {
766 rv = VNET_API_ERROR_FEATURE_DISABLED;
767 goto done;
768 }
769
770 mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0;
771 mp->netns[sizeof (mp->netns) - 1] = 0;
772 ns_id = format (0, "%s", &mp->namespace_id);
773 netns = format (0, "%s", &mp->netns);
774
775 vnet_app_namespace_add_del_args_t args = {
776 .ns_id = ns_id,
777 .netns = netns,
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200778 .sock_name = 0,
Florin Coras7cb471a2021-07-23 08:39:26 -0700779 .secret = clib_net_to_host_u64 (mp->secret),
780 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
781 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
782 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
783 .is_add = 1
784 };
785 rv = vnet_app_namespace_add_del (&args);
786 if (!rv)
787 {
788 appns_index = app_namespace_index_from_id (ns_id);
789 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
790 {
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200791 clib_warning ("app ns lookup failed id:%s", ns_id);
Florin Coras7cb471a2021-07-23 08:39:26 -0700792 rv = VNET_API_ERROR_UNSPECIFIED;
793 }
794 }
795 vec_free (ns_id);
796 vec_free (netns);
797
798done:
799 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V2_REPLY, ({
800 if (!rv)
801 rmp->appns_index = clib_host_to_net_u32 (appns_index);
802 }));
803}
804
805static void
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200806vl_api_app_namespace_add_del_v3_t_handler (
807 vl_api_app_namespace_add_del_v3_t *mp)
808{
809 vl_api_app_namespace_add_del_v3_reply_t *rmp;
810 u8 *ns_id = 0, *netns = 0, *sock_name = 0;
811 u32 appns_index = 0;
812 int rv = 0;
813 if (session_main_is_enabled () == 0)
814 {
815 rv = VNET_API_ERROR_FEATURE_DISABLED;
816 goto done;
817 }
818 mp->namespace_id[sizeof (mp->namespace_id) - 1] = 0;
819 mp->netns[sizeof (mp->netns) - 1] = 0;
820 ns_id = format (0, "%s", &mp->namespace_id);
821 netns = format (0, "%s", &mp->netns);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +0200822 sock_name = vl_api_from_api_to_new_vec (mp, &mp->sock_name);
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +0200823 vnet_app_namespace_add_del_args_t args = {
824 .ns_id = ns_id,
825 .netns = netns,
826 .sock_name = sock_name,
827 .secret = clib_net_to_host_u64 (mp->secret),
828 .sw_if_index = clib_net_to_host_u32 (mp->sw_if_index),
829 .ip4_fib_id = clib_net_to_host_u32 (mp->ip4_fib_id),
830 .ip6_fib_id = clib_net_to_host_u32 (mp->ip6_fib_id),
831 .is_add = mp->is_add,
832 };
833 rv = vnet_app_namespace_add_del (&args);
834 if (!rv && mp->is_add)
835 {
836 appns_index = app_namespace_index_from_id (ns_id);
837 if (appns_index == APP_NAMESPACE_INVALID_INDEX)
838 {
839 clib_warning ("app ns lookup failed id:%s", ns_id);
840 rv = VNET_API_ERROR_UNSPECIFIED;
841 }
842 }
843 vec_free (ns_id);
844 vec_free (netns);
845 vec_free (sock_name);
846done:
847 REPLY_MACRO2 (VL_API_APP_NAMESPACE_ADD_DEL_V3_REPLY, ({
848 if (!rv)
849 rmp->appns_index = clib_host_to_net_u32 (appns_index);
850 }));
851}
852
853static void
Florin Coras1c710452017-10-17 00:03:13 -0700854vl_api_session_rule_add_del_t_handler (vl_api_session_rule_add_del_t * mp)
855{
856 vl_api_session_rule_add_del_reply_t *rmp;
857 session_rule_add_del_args_t args;
858 session_rule_table_add_del_args_t *table_args = &args.table_args;
Florin Coras1c710452017-10-17 00:03:13 -0700859 int rv = 0;
860
Dave Barachb7b92992018-10-17 10:38:51 -0400861 clib_memset (&args, 0, sizeof (args));
Florin Coras1c710452017-10-17 00:03:13 -0700862
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100863 ip_prefix_decode (&mp->lcl, &table_args->lcl);
864 ip_prefix_decode (&mp->rmt, &table_args->rmt);
865
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100866 table_args->lcl_port = mp->lcl_port;
867 table_args->rmt_port = mp->rmt_port;
Florin Coras1c710452017-10-17 00:03:13 -0700868 table_args->action_index = clib_net_to_host_u32 (mp->action_index);
869 table_args->is_add = mp->is_add;
Florin Corasc97a7392017-11-05 23:07:07 -0800870 mp->tag[sizeof (mp->tag) - 1] = 0;
871 table_args->tag = format (0, "%s", mp->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700872 args.appns_index = clib_net_to_host_u32 (mp->appns_index);
873 args.scope = mp->scope;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100874 args.transport_proto =
875 api_session_transport_proto_decode (&mp->transport_proto) ==
876 TRANSPORT_PROTO_UDP ? 1 : 0;
Florin Coras1c710452017-10-17 00:03:13 -0700877
Florin Corasc1a42652019-02-08 18:27:29 -0800878 rv = vnet_session_rule_add_del (&args);
879 if (rv)
880 clib_warning ("rule add del returned: %d", rv);
Florin Corasc97a7392017-11-05 23:07:07 -0800881 vec_free (table_args->tag);
Florin Coras1c710452017-10-17 00:03:13 -0700882 REPLY_MACRO (VL_API_SESSION_RULE_ADD_DEL_REPLY);
883}
884
Florin Coras6c36f532017-11-03 18:32:34 -0700885static void
886send_session_rule_details4 (mma_rule_16_t * rule, u8 is_local,
Florin Corasc97a7392017-11-05 23:07:07 -0800887 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800888 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700889{
890 vl_api_session_rules_details_t *rmp = 0;
891 session_mask_or_match_4_t *match =
892 (session_mask_or_match_4_t *) & rule->match;
893 session_mask_or_match_4_t *mask =
894 (session_mask_or_match_4_t *) & rule->mask;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100895 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -0700896
897 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400898 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar0046e972021-06-26 22:12:08 +0000899 rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS);
Florin Coras6c36f532017-11-03 18:32:34 -0700900 rmp->context = context;
901
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100902 clib_memset (&lcl, 0, sizeof (lcl));
903 clib_memset (&rmt, 0, sizeof (rmt));
904 ip_set (&lcl.fp_addr, &match->lcl_ip, 1);
905 ip_set (&rmt.fp_addr, &match->rmt_ip, 1);
906 lcl.fp_len = ip4_mask_to_preflen (&mask->lcl_ip);
907 rmt.fp_len = ip4_mask_to_preflen (&mask->rmt_ip);
908
909 ip_prefix_encode (&lcl, &rmp->lcl);
910 ip_prefix_encode (&rmt, &rmp->rmt);
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100911 rmp->lcl_port = match->lcl_port;
912 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -0700913 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
914 rmp->scope =
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100915 is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL;
916 rmp->transport_proto = api_session_transport_proto_encode (transport_proto);
Florin Coras6c36f532017-11-03 18:32:34 -0700917 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800918 if (tag)
919 {
Dave Barach178cf492018-11-13 16:34:13 -0500920 clib_memcpy_fast (rmp->tag, tag, vec_len (tag));
Florin Corasc97a7392017-11-05 23:07:07 -0800921 rmp->tag[vec_len (tag)] = 0;
922 }
Florin Coras6c36f532017-11-03 18:32:34 -0700923
Florin Coras6c4dae22018-01-09 06:39:23 -0800924 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -0700925}
926
927static void
Florin Corasc97a7392017-11-05 23:07:07 -0800928send_session_rule_details6 (mma_rule_40_t * rule, u8 is_local,
929 u8 transport_proto, u32 appns_index, u8 * tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800930 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700931{
932 vl_api_session_rules_details_t *rmp = 0;
933 session_mask_or_match_6_t *match =
934 (session_mask_or_match_6_t *) & rule->match;
935 session_mask_or_match_6_t *mask =
936 (session_mask_or_match_6_t *) & rule->mask;
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100937 fib_prefix_t lcl, rmt;
Florin Coras6c36f532017-11-03 18:32:34 -0700938
939 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400940 clib_memset (rmp, 0, sizeof (*rmp));
Filip Tehlar0046e972021-06-26 22:12:08 +0000941 rmp->_vl_msg_id = ntohs (REPLY_MSG_ID_BASE + VL_API_SESSION_RULES_DETAILS);
Florin Coras6c36f532017-11-03 18:32:34 -0700942 rmp->context = context;
943
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100944 clib_memset (&lcl, 0, sizeof (lcl));
945 clib_memset (&rmt, 0, sizeof (rmt));
946 ip_set (&lcl.fp_addr, &match->lcl_ip, 0);
947 ip_set (&rmt.fp_addr, &match->rmt_ip, 0);
948 lcl.fp_len = ip6_mask_to_preflen (&mask->lcl_ip);
949 rmt.fp_len = ip6_mask_to_preflen (&mask->rmt_ip);
950
951 ip_prefix_encode (&lcl, &rmp->lcl);
952 ip_prefix_encode (&rmt, &rmp->rmt);
Milan Lenco8b9a5d12017-11-24 17:12:33 +0100953 rmp->lcl_port = match->lcl_port;
954 rmp->rmt_port = match->rmt_port;
Florin Coras6c36f532017-11-03 18:32:34 -0700955 rmp->action_index = clib_host_to_net_u32 (rule->action_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800956 rmp->scope =
Jakub Grajciarb4e5e502020-01-31 09:35:29 +0100957 is_local ? SESSION_RULE_SCOPE_API_LOCAL : SESSION_RULE_SCOPE_API_GLOBAL;
958 rmp->transport_proto = api_session_transport_proto_encode (transport_proto);
Florin Coras6c36f532017-11-03 18:32:34 -0700959 rmp->appns_index = clib_host_to_net_u32 (appns_index);
Florin Corasc97a7392017-11-05 23:07:07 -0800960 if (tag)
961 {
Dave Barach178cf492018-11-13 16:34:13 -0500962 clib_memcpy_fast (rmp->tag, tag, vec_len (tag));
Florin Corasc97a7392017-11-05 23:07:07 -0800963 rmp->tag[vec_len (tag)] = 0;
964 }
Florin Coras6c36f532017-11-03 18:32:34 -0700965
Florin Coras6c4dae22018-01-09 06:39:23 -0800966 vl_api_send_msg (reg, (u8 *) rmp);
Florin Coras6c36f532017-11-03 18:32:34 -0700967}
968
969static void
970send_session_rules_table_details (session_rules_table_t * srt, u8 fib_proto,
Florin Corasc97a7392017-11-05 23:07:07 -0800971 u8 tp, u8 is_local, u32 appns_index,
Florin Coras6c4dae22018-01-09 06:39:23 -0800972 vl_api_registration_t * reg, u32 context)
Florin Coras6c36f532017-11-03 18:32:34 -0700973{
974 mma_rule_16_t *rule16;
975 mma_rule_40_t *rule40;
976 mma_rules_table_16_t *srt16;
977 mma_rules_table_40_t *srt40;
Florin Corasc97a7392017-11-05 23:07:07 -0800978 u32 ri;
Florin Coras6c36f532017-11-03 18:32:34 -0700979
Florin Corasc97a7392017-11-05 23:07:07 -0800980 if (is_local || fib_proto == FIB_PROTOCOL_IP4)
Florin Coras6c36f532017-11-03 18:32:34 -0700981 {
Florin Corasc97a7392017-11-05 23:07:07 -0800982 u8 *tag = 0;
983 /* *INDENT-OFF* */
984 srt16 = &srt->session_rules_tables_16;
Damjan Marionb2c31b62020-12-13 21:47:40 +0100985 pool_foreach (rule16, srt16->rules) {
Florin Corasc97a7392017-11-05 23:07:07 -0800986 ri = mma_rules_table_rule_index_16 (srt16, rule16);
987 tag = session_rules_table_rule_tag (srt, ri, 1);
988 send_session_rule_details4 (rule16, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -0800989 reg, context);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100990 }
Florin Corasc97a7392017-11-05 23:07:07 -0800991 /* *INDENT-ON* */
992 }
993 if (is_local || fib_proto == FIB_PROTOCOL_IP6)
994 {
995 u8 *tag = 0;
996 /* *INDENT-OFF* */
997 srt40 = &srt->session_rules_tables_40;
Damjan Marionb2c31b62020-12-13 21:47:40 +0100998 pool_foreach (rule40, srt40->rules) {
Florin Corasc97a7392017-11-05 23:07:07 -0800999 ri = mma_rules_table_rule_index_40 (srt40, rule40);
1000 tag = session_rules_table_rule_tag (srt, ri, 1);
1001 send_session_rule_details6 (rule40, is_local, tp, appns_index, tag,
Florin Coras6c4dae22018-01-09 06:39:23 -08001002 reg, context);
Damjan Marionb2c31b62020-12-13 21:47:40 +01001003 }
Florin Corasc97a7392017-11-05 23:07:07 -08001004 /* *INDENT-ON* */
Florin Coras6c36f532017-11-03 18:32:34 -07001005 }
1006}
1007
1008static void
Neale Ranns2b202bc2020-09-21 08:17:51 +00001009vl_api_session_rules_dump_t_handler (vl_api_session_rules_dump_t * mp)
Florin Coras6c36f532017-11-03 18:32:34 -07001010{
Florin Coras6c4dae22018-01-09 06:39:23 -08001011 vl_api_registration_t *reg;
Florin Coras6c36f532017-11-03 18:32:34 -07001012 session_table_t *st;
Florin Corasc97a7392017-11-05 23:07:07 -08001013 u8 tp;
Florin Coras6c36f532017-11-03 18:32:34 -07001014
Florin Coras6c4dae22018-01-09 06:39:23 -08001015 reg = vl_api_client_index_to_registration (mp->client_index);
1016 if (!reg)
Florin Coras6c36f532017-11-03 18:32:34 -07001017 return;
1018
1019 /* *INDENT-OFF* */
1020 session_table_foreach (st, ({
Florin Coras07063b82020-03-13 04:44:51 +00001021 for (tp = 0; tp < TRANSPORT_N_PROTOS; tp++)
Florin Corasc97a7392017-11-05 23:07:07 -08001022 {
1023 send_session_rules_table_details (&st->session_rules[tp],
1024 st->active_fib_proto, tp,
Florin Coras6c4dae22018-01-09 06:39:23 -08001025 st->is_local, st->appns_index, reg,
Florin Corasc97a7392017-11-05 23:07:07 -08001026 mp->context);
1027 }
Florin Coras6c36f532017-11-03 18:32:34 -07001028 }));
1029 /* *INDENT-ON* */
1030}
1031
Florin Coras371ca502018-02-21 12:07:41 -08001032static void
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001033vl_api_app_add_cert_key_pair_t_handler (vl_api_app_add_cert_key_pair_t * mp)
Florin Coras371ca502018-02-21 12:07:41 -08001034{
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001035 vl_api_app_add_cert_key_pair_reply_t *rmp;
1036 vnet_app_add_cert_key_pair_args_t _a, *a = &_a;
1037 u32 certkey_len, key_len, cert_len;
Florin Coras371ca502018-02-21 12:07:41 -08001038 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001039 if (session_main_is_enabled () == 0)
Florin Coras371ca502018-02-21 12:07:41 -08001040 {
1041 rv = VNET_API_ERROR_FEATURE_DISABLED;
1042 goto done;
1043 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001044
Florin Coras371ca502018-02-21 12:07:41 -08001045 cert_len = clib_net_to_host_u16 (mp->cert_len);
Florin Coras5090c572018-03-18 08:22:17 -07001046 if (cert_len > 10000)
1047 {
1048 rv = VNET_API_ERROR_INVALID_VALUE;
1049 goto done;
1050 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001051
1052 certkey_len = clib_net_to_host_u16 (mp->certkey_len);
1053 if (certkey_len < cert_len)
Florin Coras371ca502018-02-21 12:07:41 -08001054 {
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001055 rv = VNET_API_ERROR_INVALID_VALUE;
1056 goto done;
Florin Coras371ca502018-02-21 12:07:41 -08001057 }
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001058
1059 key_len = certkey_len - cert_len;
1060 if (key_len > 10000)
1061 {
1062 rv = VNET_API_ERROR_INVALID_VALUE;
1063 goto done;
1064 }
1065
1066 clib_memset (a, 0, sizeof (*a));
Florin Corasa5a9efd2021-01-05 17:03:29 -08001067 a->cert = mp->certkey;
1068 a->key = mp->certkey + cert_len;
1069 a->cert_len = cert_len;
1070 a->key_len = key_len;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001071 rv = vnet_app_add_cert_key_pair (a);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001072
Florin Coras371ca502018-02-21 12:07:41 -08001073done:
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001074 /* *INDENT-OFF* */
1075 REPLY_MACRO2 (VL_API_APP_ADD_CERT_KEY_PAIR_REPLY, ({
1076 if (!rv)
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001077 rmp->index = clib_host_to_net_u32 (a->index);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001078 }));
1079 /* *INDENT-ON* */
Florin Coras371ca502018-02-21 12:07:41 -08001080}
1081
1082static void
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001083vl_api_app_del_cert_key_pair_t_handler (vl_api_app_del_cert_key_pair_t * mp)
Florin Coras371ca502018-02-21 12:07:41 -08001084{
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001085 vl_api_app_del_cert_key_pair_reply_t *rmp;
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001086 u32 ckpair_index;
Florin Coras371ca502018-02-21 12:07:41 -08001087 int rv = 0;
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001088 if (session_main_is_enabled () == 0)
1089 {
1090 rv = VNET_API_ERROR_FEATURE_DISABLED;
1091 goto done;
1092 }
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001093 ckpair_index = clib_net_to_host_u32 (mp->index);
1094 rv = vnet_app_del_cert_key_pair (ckpair_index);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001095
1096done:
Nathan Skrzypczak45ec9f42019-11-06 14:47:40 +01001097 REPLY_MACRO (VL_API_APP_DEL_CERT_KEY_PAIR_REPLY);
Nathan Skrzypczak79f89532019-09-13 11:08:13 +02001098}
1099
Florin Coras6cf30ad2017-04-04 23:08:23 -07001100static clib_error_t *
1101application_reaper_cb (u32 client_index)
Dave Barach68b0fb02017-02-28 15:15:56 -05001102{
Florin Coras6cf30ad2017-04-04 23:08:23 -07001103 application_t *app = application_lookup (client_index);
1104 vnet_app_detach_args_t _a, *a = &_a;
1105 if (app)
1106 {
Florin Coras15531972018-08-12 23:50:53 -07001107 a->app_index = app->app_index;
Florin Coras053a0e42018-11-13 15:52:38 -08001108 a->api_client_index = client_index;
Florin Coras6cf30ad2017-04-04 23:08:23 -07001109 vnet_application_detach (a);
1110 }
1111 return 0;
Dave Barach68b0fb02017-02-28 15:15:56 -05001112}
1113
Florin Coras6cf30ad2017-04-04 23:08:23 -07001114VL_MSG_API_REAPER_FUNCTION (application_reaper_cb);
Dave Barach68b0fb02017-02-28 15:15:56 -05001115
Dave Barach68b0fb02017-02-28 15:15:56 -05001116/*
Florin Coras61ae0562020-09-02 19:10:28 -07001117 * Socket api functions
1118 */
1119
Florin Coras61ae0562020-09-02 19:10:28 -07001120static int
1121mq_send_add_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle)
1122{
Florin Coras20c24232021-11-22 21:19:01 -08001123 session_app_add_segment_msg_t m = { 0 };
Florin Coras61ae0562020-09-02 19:10:28 -07001124 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001125 fifo_segment_t *fs;
1126 ssvm_private_t *sp;
1127 u8 fd_flags = 0;
1128
1129 app_wrk = app_worker_get (app_wrk_index);
1130
1131 fs = segment_manager_get_segment_w_handle (segment_handle);
1132 sp = &fs->ssvm;
1133 ASSERT (ssvm_type (sp) == SSVM_SEGMENT_MEMFD);
1134
1135 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
Florin Coras61ae0562020-09-02 19:10:28 -07001136
Florin Coras20c24232021-11-22 21:19:01 -08001137 m.segment_size = sp->ssvm_size;
1138 m.fd_flags = fd_flags;
1139 m.segment_handle = segment_handle;
1140 strncpy ((char *) m.segment_name, (char *) sp->name,
1141 sizeof (m.segment_name) - 1);
Florin Coras61ae0562020-09-02 19:10:28 -07001142
Florin Coras20c24232021-11-22 21:19:01 -08001143 app_wrk_send_ctrl_evt_fd (app_wrk, SESSION_CTRL_EVT_APP_ADD_SEGMENT, &m,
1144 sizeof (m), sp->fd);
Florin Coras61ae0562020-09-02 19:10:28 -07001145
1146 return 0;
1147}
1148
1149static int
1150mq_send_del_segment_sapi_cb (u32 app_wrk_index, u64 segment_handle)
1151{
Florin Coras20c24232021-11-22 21:19:01 -08001152 session_app_del_segment_msg_t m = { 0 };
Florin Coras61ae0562020-09-02 19:10:28 -07001153 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001154
1155 app_wrk = app_worker_get (app_wrk_index);
1156
Florin Coras20c24232021-11-22 21:19:01 -08001157 m.segment_handle = segment_handle;
Florin Coras61ae0562020-09-02 19:10:28 -07001158
Florin Coras20c24232021-11-22 21:19:01 -08001159 app_wrk_send_ctrl_evt (app_wrk, SESSION_CTRL_EVT_APP_DEL_SEGMENT, &m,
1160 sizeof (m));
Florin Coras61ae0562020-09-02 19:10:28 -07001161
1162 return 0;
1163}
1164
1165static session_cb_vft_t session_mq_sapi_cb_vft = {
1166 .session_accept_callback = mq_send_session_accepted_cb,
1167 .session_disconnect_callback = mq_send_session_disconnected_cb,
1168 .session_connected_callback = mq_send_session_connected_cb,
1169 .session_reset_callback = mq_send_session_reset_cb,
1170 .session_migrate_callback = mq_send_session_migrate_cb,
1171 .session_cleanup_callback = mq_send_session_cleanup_cb,
1172 .add_segment_callback = mq_send_add_segment_sapi_cb,
1173 .del_segment_callback = mq_send_del_segment_sapi_cb,
1174};
1175
1176static void
1177session_api_attach_handler (app_namespace_t * app_ns, clib_socket_t * cs,
1178 app_sapi_attach_msg_t * mp)
1179{
Florin Coras41d5f542021-01-15 13:49:33 -08001180 int rv = 0, *fds = 0, n_fds = 0, i, n_workers;
Florin Coras61ae0562020-09-02 19:10:28 -07001181 vnet_app_attach_args_t _a, *a = &_a;
1182 app_sapi_attach_reply_msg_t *rmp;
Florin Coras61ae0562020-09-02 19:10:28 -07001183 u8 fd_flags = 0, ctrl_thread;
1184 app_ns_api_handle_t *handle;
Florin Coras41d5f542021-01-15 13:49:33 -08001185 fifo_segment_t *rx_mqs_seg;
Florin Coras61ae0562020-09-02 19:10:28 -07001186 app_sapi_msg_t msg = { 0 };
1187 app_worker_t *app_wrk;
Florin Coras61ae0562020-09-02 19:10:28 -07001188 application_t *app;
Florin Coras41d5f542021-01-15 13:49:33 -08001189 svm_msg_q_t *rx_mq;
Florin Coras61ae0562020-09-02 19:10:28 -07001190
1191 /* Make sure name is null terminated */
1192 mp->name[63] = 0;
1193
1194 clib_memset (a, 0, sizeof (*a));
1195 a->api_client_index = appns_sapi_socket_handle (app_ns, cs);
1196 a->name = format (0, "%s", (char *) mp->name);
1197 a->options = mp->options;
1198 a->session_cb_vft = &session_mq_sapi_cb_vft;
1199 a->use_sock_api = 1;
1200 a->options[APP_OPTIONS_NAMESPACE] = app_namespace_index (app_ns);
1201
1202 if ((rv = vnet_application_attach (a)))
1203 {
1204 clib_warning ("attach returned: %d", rv);
1205 goto done;
1206 }
1207
Florin Coras41d5f542021-01-15 13:49:33 -08001208 n_workers = vlib_num_workers ();
1209 vec_validate (fds, 3 /* segs + tx evtfd */ + n_workers);
1210
Florin Coras61ae0562020-09-02 19:10:28 -07001211 /* Send event queues segment */
Florin Coras41d5f542021-01-15 13:49:33 -08001212 app = application_get (a->app_index);
1213 rx_mqs_seg = application_get_rx_mqs_segment (app);
1214
1215 fd_flags |= SESSION_FD_F_VPP_MQ_SEGMENT;
1216 fds[n_fds] = rx_mqs_seg->ssvm.fd;
1217 n_fds += 1;
1218
Florin Coras61ae0562020-09-02 19:10:28 -07001219 /* Send fifo segment fd if needed */
1220 if (ssvm_type (a->segment) == SSVM_SEGMENT_MEMFD)
1221 {
1222 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1223 fds[n_fds] = a->segment->fd;
1224 n_fds += 1;
1225 }
1226 if (a->options[APP_OPTIONS_FLAGS] & APP_OPTIONS_FLAGS_EVT_MQ_USE_EVENTFD)
1227 {
1228 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -08001229 fds[n_fds] = svm_msg_q_get_eventfd (a->app_evt_q);
Florin Coras61ae0562020-09-02 19:10:28 -07001230 n_fds += 1;
1231 }
1232
Florin Coras41d5f542021-01-15 13:49:33 -08001233 if (application_use_private_rx_mqs ())
1234 {
1235 fd_flags |= SESSION_FD_F_VPP_MQ_EVENTFD;
1236 for (i = 0; i < n_workers + 1; i++)
1237 {
1238 rx_mq = application_rx_mq_get (app, i);
1239 fds[n_fds] = svm_msg_q_get_eventfd (rx_mq);
1240 n_fds += 1;
1241 }
1242 }
1243
Florin Coras61ae0562020-09-02 19:10:28 -07001244done:
1245
1246 msg.type = APP_SAPI_MSG_TYPE_ATTACH_REPLY;
1247 rmp = &msg.attach_reply;
1248 rmp->retval = rv;
1249 if (!rv)
1250 {
Florin Coras41d5f542021-01-15 13:49:33 -08001251 ctrl_thread = n_workers ? 1 : 0;
Florin Coras61ae0562020-09-02 19:10:28 -07001252 rmp->app_index = a->app_index;
Florin Corasb4624182020-12-11 13:58:12 -08001253 rmp->app_mq =
1254 fifo_segment_msg_q_offset ((fifo_segment_t *) a->segment, 0);
Florin Coras41d5f542021-01-15 13:49:33 -08001255 rmp->vpp_ctrl_mq = fifo_segment_msg_q_offset (rx_mqs_seg, ctrl_thread);
Florin Coras61ae0562020-09-02 19:10:28 -07001256 rmp->vpp_ctrl_mq_thread = ctrl_thread;
1257 rmp->n_fds = n_fds;
1258 rmp->fd_flags = fd_flags;
1259 /* No segment name and size since we only support memfds
1260 * in this configuration */
1261 rmp->segment_handle = a->segment_handle;
1262 rmp->api_client_handle = a->api_client_index;
1263
1264 /* Update app index for socket */
1265 handle = (app_ns_api_handle_t *) & cs->private_data;
Florin Coras61ae0562020-09-02 19:10:28 -07001266 app_wrk = application_get_worker (app, 0);
1267 handle->aah_app_wrk_index = app_wrk->wrk_index;
1268 }
1269
1270 clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds);
1271 vec_free (a->name);
Florin Coras41d5f542021-01-15 13:49:33 -08001272 vec_free (fds);
Florin Coras61ae0562020-09-02 19:10:28 -07001273}
1274
Florin Coras98078ab2021-08-12 18:12:09 -07001275void
Florin Coras61ae0562020-09-02 19:10:28 -07001276sapi_socket_close_w_handle (u32 api_handle)
1277{
1278 app_namespace_t *app_ns = app_namespace_get (api_handle >> 16);
1279 u16 sock_index = api_handle & 0xffff;
1280 app_ns_api_handle_t *handle;
1281 clib_socket_t *cs;
1282 clib_file_t *cf;
1283
1284 cs = appns_sapi_get_socket (app_ns, sock_index);
1285 if (!cs)
1286 return;
1287
1288 handle = (app_ns_api_handle_t *) & cs->private_data;
1289 cf = clib_file_get (&file_main, handle->aah_file_index);
1290 clib_file_del (&file_main, cf);
1291
1292 clib_socket_close (cs);
1293 appns_sapi_free_socket (app_ns, cs);
1294}
1295
1296static void
1297sapi_add_del_worker_handler (app_namespace_t * app_ns,
1298 clib_socket_t * cs,
1299 app_sapi_worker_add_del_msg_t * mp)
1300{
1301 int rv = 0, fds[SESSION_N_FD_TYPE], n_fds = 0;
1302 app_sapi_worker_add_del_reply_msg_t *rmp;
1303 app_ns_api_handle_t *handle;
1304 app_sapi_msg_t msg = { 0 };
1305 app_worker_t *app_wrk;
Florin Corascc7c88e2020-09-15 15:56:51 -07001306 u32 sapi_handle = -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001307 application_t *app;
Florin Coras61ae0562020-09-02 19:10:28 -07001308 u8 fd_flags = 0;
1309
1310 app = application_get_if_valid (mp->app_index);
1311 if (!app)
1312 {
1313 rv = VNET_API_ERROR_INVALID_VALUE;
1314 goto done;
1315 }
1316
1317 sapi_handle = appns_sapi_socket_handle (app_ns, cs);
1318
1319 vnet_app_worker_add_del_args_t args = {
1320 .app_index = app->app_index,
1321 .wrk_map_index = mp->wrk_index,
1322 .api_client_index = sapi_handle,
1323 .is_add = mp->is_add
1324 };
1325 rv = vnet_app_worker_add_del (&args);
1326 if (rv)
1327 {
1328 clib_warning ("app worker add/del returned: %d", rv);
1329 goto done;
1330 }
1331
1332 if (!mp->is_add)
Florin Coras98078ab2021-08-12 18:12:09 -07001333 goto done;
Florin Coras61ae0562020-09-02 19:10:28 -07001334
1335 /* Send fifo segment fd if needed */
1336 if (ssvm_type (args.segment) == SSVM_SEGMENT_MEMFD)
1337 {
1338 fd_flags |= SESSION_FD_F_MEMFD_SEGMENT;
1339 fds[n_fds] = args.segment->fd;
1340 n_fds += 1;
1341 }
1342 if (application_segment_manager_properties (app)->use_mq_eventfd)
1343 {
1344 fd_flags |= SESSION_FD_F_MQ_EVENTFD;
Florin Coras86f12322021-01-22 15:05:14 -08001345 fds[n_fds] = svm_msg_q_get_eventfd (args.evt_q);
Florin Coras61ae0562020-09-02 19:10:28 -07001346 n_fds += 1;
1347 }
1348
1349done:
1350
1351 msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_WORKER_REPLY;
1352 rmp = &msg.worker_add_del_reply;
1353 rmp->retval = rv;
1354 rmp->is_add = mp->is_add;
Florin Corascc7c88e2020-09-15 15:56:51 -07001355 rmp->api_client_handle = sapi_handle;
Florin Coras61ae0562020-09-02 19:10:28 -07001356 rmp->wrk_index = args.wrk_map_index;
1357 rmp->segment_handle = args.segment_handle;
1358 if (!rv && mp->is_add)
1359 {
1360 /* No segment name and size. This supports only memfds */
Florin Corasb4624182020-12-11 13:58:12 -08001361 rmp->app_event_queue_address =
1362 fifo_segment_msg_q_offset ((fifo_segment_t *) args.segment, 0);
Florin Coras61ae0562020-09-02 19:10:28 -07001363 rmp->n_fds = n_fds;
1364 rmp->fd_flags = fd_flags;
1365
1366 /* Update app index for socket */
1367 handle = (app_ns_api_handle_t *) & cs->private_data;
1368 app_wrk = application_get_worker (app, args.wrk_map_index);
1369 handle->aah_app_wrk_index = app_wrk->wrk_index;
1370 }
1371
1372 clib_socket_sendmsg (cs, &msg, sizeof (msg), fds, n_fds);
1373}
1374
Filip Tehlar447e51d2022-02-18 08:49:43 +00001375/* This is a workaround for the case when session layer starts reading
1376 * the socket before the client actualy sends the data
1377 */
1378static clib_error_t *
1379sapi_socket_receive_wait (clib_socket_t *cs, u8 *msg, u32 msg_len)
1380{
1381 clib_error_t *err;
1382 int n_tries = 5;
1383
1384 while (1)
1385 {
1386 err = clib_socket_recvmsg (cs, msg, msg_len, 0, 0);
1387 if (!err)
1388 break;
1389
1390 if (!n_tries)
1391 return err;
1392
1393 n_tries--;
1394 usleep (1);
1395 }
1396
1397 return err;
1398}
1399
Florin Coras61ae0562020-09-02 19:10:28 -07001400static void
Florin Corase191d762021-08-11 14:55:49 -07001401sapi_add_del_cert_key_handler (app_namespace_t *app_ns, clib_socket_t *cs,
1402 app_sapi_cert_key_add_del_msg_t *mp)
1403{
1404 vnet_app_add_cert_key_pair_args_t _a, *a = &_a;
1405 app_sapi_cert_key_add_del_reply_msg_t *rmp;
1406 app_sapi_msg_t msg = { 0 };
1407 int rv = 0;
1408
1409 if (mp->is_add)
1410 {
1411 const u32 max_certkey_len = 2e4, max_cert_len = 1e4, max_key_len = 1e4;
1412 clib_error_t *err;
1413 u8 *certkey = 0;
1414 u32 key_len;
1415
1416 if (mp->certkey_len > max_certkey_len)
1417 {
1418 rv = SESSION_E_INVALID;
1419 goto send_reply;
1420 }
1421
1422 vec_validate (certkey, mp->certkey_len - 1);
Filip Tehlar447e51d2022-02-18 08:49:43 +00001423
1424 err = sapi_socket_receive_wait (cs, certkey, mp->certkey_len);
Florin Corase191d762021-08-11 14:55:49 -07001425 if (err)
1426 {
1427 clib_error_report (err);
Florin Corase191d762021-08-11 14:55:49 -07001428 rv = SESSION_E_INVALID;
1429 goto send_reply;
1430 }
1431
1432 if (mp->cert_len > max_cert_len)
1433 {
1434 rv = SESSION_E_INVALID;
1435 goto send_reply;
1436 }
1437
1438 if (mp->certkey_len < mp->cert_len)
1439 {
1440 rv = SESSION_E_INVALID;
1441 goto send_reply;
1442 }
1443
1444 key_len = mp->certkey_len - mp->cert_len;
1445 if (key_len > max_key_len)
1446 {
1447 rv = SESSION_E_INVALID;
1448 goto send_reply;
1449 }
1450
1451 clib_memset (a, 0, sizeof (*a));
1452 a->cert = certkey;
1453 a->key = certkey + mp->cert_len;
1454 a->cert_len = mp->cert_len;
1455 a->key_len = key_len;
1456 rv = vnet_app_add_cert_key_pair (a);
1457
1458 vec_free (certkey);
1459 }
1460 else
1461 {
1462 rv = vnet_app_del_cert_key_pair (mp->index);
1463 }
1464
1465send_reply:
1466
1467 msg.type = APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY_REPLY;
1468 rmp = &msg.cert_key_add_del_reply;
1469 rmp->retval = rv;
1470 rmp->context = mp->context;
1471 if (!rv && mp->is_add)
1472 rmp->index = a->index;
1473
1474 clib_socket_sendmsg (cs, &msg, sizeof (msg), 0, 0);
1475}
1476
1477static void
Florin Coras61ae0562020-09-02 19:10:28 -07001478sapi_socket_detach (app_namespace_t * app_ns, clib_socket_t * cs)
1479{
Florin Coras61ae0562020-09-02 19:10:28 -07001480 app_ns_api_handle_t *handle;
1481 app_worker_t *app_wrk;
1482 u32 api_client_handle;
1483
1484 api_client_handle = appns_sapi_socket_handle (app_ns, cs);
Florin Coras61ae0562020-09-02 19:10:28 -07001485
Florin Corasf99a7d62020-09-14 10:29:29 -07001486 /* Cleanup everything because app worker closed socket or crashed */
Florin Coras61ae0562020-09-02 19:10:28 -07001487 handle = (app_ns_api_handle_t *) & cs->private_data;
1488 app_wrk = app_worker_get (handle->aah_app_wrk_index);
Florin Corasf99a7d62020-09-14 10:29:29 -07001489
1490 vnet_app_worker_add_del_args_t args = {
1491 .app_index = app_wrk->app_index,
1492 .wrk_map_index = app_wrk->wrk_map_index,
1493 .api_client_index = api_client_handle,
1494 .is_add = 0
1495 };
1496 /* Send rpc to main thread for worker barrier */
1497 vlib_rpc_call_main_thread (vnet_app_worker_add_del, (u8 *) & args,
1498 sizeof (args));
Florin Coras61ae0562020-09-02 19:10:28 -07001499}
1500
1501static clib_error_t *
1502sapi_sock_read_ready (clib_file_t * cf)
1503{
1504 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
Florin Coras7360e3d2020-09-18 16:15:47 -07001505 vlib_main_t *vm = vlib_get_main ();
Florin Coras61ae0562020-09-02 19:10:28 -07001506 app_sapi_msg_t msg = { 0 };
1507 app_namespace_t *app_ns;
1508 clib_error_t *err = 0;
1509 clib_socket_t *cs;
1510
1511 app_ns = app_namespace_get (handle->aah_app_ns_index);
1512 cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index);
1513 if (!cs)
1514 goto error;
1515
1516 err = clib_socket_recvmsg (cs, &msg, sizeof (msg), 0, 0);
1517 if (err)
1518 {
1519 clib_error_free (err);
1520 sapi_socket_detach (app_ns, cs);
1521 goto error;
1522 }
1523
1524 handle = (app_ns_api_handle_t *) & cs->private_data;
1525
Florin Coras7360e3d2020-09-18 16:15:47 -07001526 vlib_worker_thread_barrier_sync (vm);
1527
Florin Coras61ae0562020-09-02 19:10:28 -07001528 switch (msg.type)
1529 {
1530 case APP_SAPI_MSG_TYPE_ATTACH:
1531 session_api_attach_handler (app_ns, cs, &msg.attach);
1532 break;
1533 case APP_SAPI_MSG_TYPE_ADD_DEL_WORKER:
1534 sapi_add_del_worker_handler (app_ns, cs, &msg.worker_add_del);
1535 break;
Florin Corase191d762021-08-11 14:55:49 -07001536 case APP_SAPI_MSG_TYPE_ADD_DEL_CERT_KEY:
1537 sapi_add_del_cert_key_handler (app_ns, cs, &msg.cert_key_add_del);
1538 break;
Florin Coras61ae0562020-09-02 19:10:28 -07001539 default:
1540 clib_warning ("app wrk %u unknown message type: %u",
1541 handle->aah_app_wrk_index, msg.type);
1542 break;
1543 }
1544
Florin Coras7360e3d2020-09-18 16:15:47 -07001545 vlib_worker_thread_barrier_release (vm);
1546
Florin Coras61ae0562020-09-02 19:10:28 -07001547error:
1548 return 0;
1549}
1550
1551static clib_error_t *
1552sapi_sock_write_ready (clib_file_t * cf)
1553{
1554 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
1555 clib_warning ("called for app ns %u", handle->aah_app_ns_index);
1556 return 0;
1557}
1558
1559static clib_error_t *
1560sapi_sock_error (clib_file_t * cf)
1561{
1562 app_ns_api_handle_t *handle = (app_ns_api_handle_t *) & cf->private_data;
1563 app_namespace_t *app_ns;
1564 clib_socket_t *cs;
1565
1566 app_ns = app_namespace_get (handle->aah_app_ns_index);
1567 cs = appns_sapi_get_socket (app_ns, handle->aah_sock_index);
1568 if (!cs)
1569 return 0;
1570
1571 sapi_socket_detach (app_ns, cs);
1572 return 0;
1573}
1574
1575static clib_error_t *
1576sapi_sock_accept_ready (clib_file_t * scf)
1577{
1578 app_ns_api_handle_t handle = *(app_ns_api_handle_t *) & scf->private_data;
1579 app_namespace_t *app_ns;
1580 clib_file_t cf = { 0 };
1581 clib_error_t *err = 0;
1582 clib_socket_t *ccs, *scs;
1583
1584 /* Listener files point to namespace */
1585 app_ns = app_namespace_get (handle.aah_app_ns_index);
1586
1587 /*
1588 * Initialize client socket
1589 */
1590 ccs = appns_sapi_alloc_socket (app_ns);
1591
1592 /* Grab server socket after client is initialized */
1593 scs = appns_sapi_get_socket (app_ns, handle.aah_sock_index);
1594 if (!scs)
1595 goto error;
1596
1597 err = clib_socket_accept (scs, ccs);
1598 if (err)
1599 {
1600 clib_error_report (err);
1601 goto error;
1602 }
1603
1604 cf.read_function = sapi_sock_read_ready;
1605 cf.write_function = sapi_sock_write_ready;
1606 cf.error_function = sapi_sock_error;
1607 cf.file_descriptor = ccs->fd;
1608 /* File points to app namespace and socket */
1609 handle.aah_sock_index = appns_sapi_socket_index (app_ns, ccs);
Florin Coras6b6c10b2020-09-24 11:58:28 -07001610 cf.private_data = handle.as_u64;
Florin Coras61ae0562020-09-02 19:10:28 -07001611 cf.description = format (0, "app sock conn fd: %d", ccs->fd);
1612
1613 /* Poll until we get an attach message. Socket points to file and
1614 * application that owns the socket */
1615 handle.aah_app_wrk_index = APP_INVALID_INDEX;
1616 handle.aah_file_index = clib_file_add (&file_main, &cf);
Florin Coras6b6c10b2020-09-24 11:58:28 -07001617 ccs->private_data = handle.as_u64;
Florin Coras61ae0562020-09-02 19:10:28 -07001618
1619 return err;
1620
1621error:
1622 appns_sapi_free_socket (app_ns, ccs);
1623 return err;
1624}
1625
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +02001626void
1627appns_sapi_del_ns_socket (app_namespace_t *app_ns)
1628{
1629 app_ns_api_handle_t *handle;
1630 clib_socket_t *cs;
1631
1632 pool_foreach (cs, app_ns->app_sockets)
1633 {
1634 handle = (app_ns_api_handle_t *) &cs->private_data;
1635 clib_file_del_by_index (&file_main, handle->aah_file_index);
1636
1637 clib_socket_close (cs);
1638 clib_socket_free (cs);
1639 }
1640 pool_free (app_ns->app_sockets);
1641}
1642
Florin Coras61ae0562020-09-02 19:10:28 -07001643int
1644appns_sapi_add_ns_socket (app_namespace_t * app_ns)
1645{
1646 char *subdir = "/app_ns_sockets/";
1647 app_ns_api_handle_t *handle;
1648 clib_file_t cf = { 0 };
1649 struct stat file_stat;
1650 clib_error_t *err;
1651 clib_socket_t *cs;
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001652 char dir[4096];
Florin Coras61ae0562020-09-02 19:10:28 -07001653
Florin Coras7cb471a2021-07-23 08:39:26 -07001654 if (app_ns->netns)
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +02001655 {
1656 if (!app_ns->sock_name)
1657 app_ns->sock_name = format (0, "@vpp/session/%v%c", app_ns->ns_id, 0);
1658 if (app_ns->sock_name[0] != '@')
1659 return VNET_API_ERROR_INVALID_VALUE;
1660 }
Florin Coras7cb471a2021-07-23 08:39:26 -07001661 else
Nathan Skrzypczak1a9e2f92021-07-28 19:35:08 +02001662 {
1663 snprintf (dir, sizeof (dir), "%s%s", vlib_unix_get_runtime_dir (),
1664 subdir);
1665 err = vlib_unix_recursive_mkdir ((char *) dir);
1666 if (err)
1667 {
1668 clib_error_report (err);
1669 return VNET_API_ERROR_SYSCALL_ERROR_1;
1670 }
1671
1672 if (!app_ns->sock_name)
1673 app_ns->sock_name = format (0, "%s%v%c", dir, app_ns->ns_id, 0);
1674 }
Florin Coras61ae0562020-09-02 19:10:28 -07001675
1676 /*
1677 * Create and initialize socket to listen on
1678 */
1679 cs = appns_sapi_alloc_socket (app_ns);
Nathan Skrzypczakb3ea73e2021-08-05 10:22:52 +02001680 cs->config = (char *) vec_dup (app_ns->sock_name);
Florin Coras61ae0562020-09-02 19:10:28 -07001681 cs->flags = CLIB_SOCKET_F_IS_SERVER |
1682 CLIB_SOCKET_F_ALLOW_GROUP_WRITE |
1683 CLIB_SOCKET_F_SEQPACKET | CLIB_SOCKET_F_PASSCRED;
1684
Florin Coras7cb471a2021-07-23 08:39:26 -07001685 if ((err = clib_socket_init_netns (cs, app_ns->netns)))
Florin Coras61ae0562020-09-02 19:10:28 -07001686 {
1687 clib_error_report (err);
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001688 return -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001689 }
1690
Florin Coras7cb471a2021-07-23 08:39:26 -07001691 if (!app_ns->netns && stat ((char *) app_ns->sock_name, &file_stat) == -1)
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001692 return -1;
Florin Coras61ae0562020-09-02 19:10:28 -07001693
1694 /*
1695 * Start polling it
1696 */
1697 cf.read_function = sapi_sock_accept_ready;
1698 cf.file_descriptor = cs->fd;
1699 /* File points to namespace */
1700 handle = (app_ns_api_handle_t *) & cf.private_data;
1701 handle->aah_app_ns_index = app_namespace_index (app_ns);
1702 handle->aah_sock_index = appns_sapi_socket_index (app_ns, cs);
1703 cf.description = format (0, "app sock listener: %s", app_ns->sock_name);
1704
1705 /* Socket points to clib file index */
1706 handle = (app_ns_api_handle_t *) & cs->private_data;
1707 handle->aah_file_index = clib_file_add (&file_main, &cf);
1708 handle->aah_app_wrk_index = APP_INVALID_INDEX;
1709
Benoît Ganne0bb670e2021-09-09 12:00:00 +02001710 return 0;
Florin Coras61ae0562020-09-02 19:10:28 -07001711}
1712
Filip Tehlar0046e972021-06-26 22:12:08 +00001713static void
1714vl_api_application_tls_cert_add_t_handler (
1715 vl_api_application_tls_cert_add_t *mp)
1716{
1717 /* deprecated */
1718}
1719
1720static void
1721vl_api_application_tls_key_add_t_handler (vl_api_application_tls_key_add_t *mp)
1722{
1723 /* deprecated */
1724}
1725
1726#include <vnet/session/session.api.c>
1727static clib_error_t *
1728session_api_hookup (vlib_main_t *vm)
1729{
1730 /*
1731 * Set up the (msg_name, crc, message-id) table
1732 */
1733 REPLY_MSG_ID_BASE = setup_message_id_table ();
1734
1735 return 0;
1736}
1737
1738VLIB_API_INIT_FUNCTION (session_api_hookup);
1739
Florin Coras61ae0562020-09-02 19:10:28 -07001740/*
Dave Barach68b0fb02017-02-28 15:15:56 -05001741 * fd.io coding-style-patch-verification: ON
1742 *
1743 * Local Variables:
1744 * eval: (c-set-style "gnu")
1745 * End:
1746 */