blob: db8d721b631c29ca7aeb678790c0560138d5dbf8 [file] [log] [blame]
Florin Corasba7d8f52019-02-22 13:11:38 -08001/*
2 * Copyright (c) 2019 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <vnet/session/application_local.h>
17#include <vnet/session/session.h>
18
Florin Corasda78c5a2021-06-09 14:55:24 -070019typedef enum ct_segment_flags_
20{
21 CT_SEGMENT_F_CLIENT_DETACHED = 1 << 0,
22 CT_SEGMENT_F_SERVER_DETACHED = 1 << 1,
23} ct_segment_flags_t;
24
25typedef struct ct_segment_
26{
Florin Corasda78c5a2021-06-09 14:55:24 -070027 u32 client_n_sessions;
28 u32 server_n_sessions;
Florin Coras6973c732021-06-17 15:53:38 -070029 u32 seg_ctx_index;
30 u32 ct_seg_index;
31 u32 segment_index;
Florin Corasda78c5a2021-06-09 14:55:24 -070032 ct_segment_flags_t flags;
33} ct_segment_t;
34
35typedef struct ct_segments_
36{
37 u32 sm_index;
38 u32 server_wrk;
39 u32 client_wrk;
Florin Coras6973c732021-06-17 15:53:38 -070040 u32 fifo_pair_bytes;
Florin Corasda78c5a2021-06-09 14:55:24 -070041 ct_segment_t *segments;
42} ct_segments_ctx_t;
43
Florin Coras440c7b52021-11-09 08:38:24 -080044typedef struct ct_cleanup_req_
45{
46 u32 ct_index;
47} ct_cleanup_req_t;
48
Florin Coras7fe00692021-11-15 14:01:02 -080049typedef struct ct_worker_
50{
51 ct_connection_t *connections; /**< Per-worker connection pools */
Florin Corasc215e5a2021-11-15 19:01:52 -080052 u32 *pending_connects; /**< Fifo of pending ho indices */
Florin Coras7fe00692021-11-15 14:01:02 -080053 ct_cleanup_req_t *pending_cleanups; /**< Fifo of pending indices */
Florin Corasc215e5a2021-11-15 19:01:52 -080054 u8 have_connects; /**< Set if connect rpc pending */
Florin Coras7fe00692021-11-15 14:01:02 -080055 u8 have_cleanups; /**< Set if cleanup rpc pending */
56} ct_worker_t;
57
Florin Coras2d0e3de2020-10-23 16:31:40 -070058typedef struct ct_main_
Florin Coras653e43f2019-03-04 10:56:23 -080059{
Florin Coras7fe00692021-11-15 14:01:02 -080060 ct_worker_t *wrk; /**< Per-worker state */
Florin Coras2d0e3de2020-10-23 16:31:40 -070061 u32 n_workers; /**< Number of vpp workers */
62 u32 n_sessions; /**< Cumulative sessions counter */
Florin Coras374df7a2021-05-13 11:37:43 -070063 u32 *ho_reusable; /**< Vector of reusable ho indices */
64 clib_spinlock_t ho_reuseable_lock; /**< Lock for reusable ho indices */
Florin Corasda78c5a2021-06-09 14:55:24 -070065 clib_rwlock_t app_segs_lock; /**< RW lock for seg contexts */
66 uword *app_segs_ctxs_table; /**< App handle to segment pool map */
67 ct_segments_ctx_t *app_seg_ctxs; /**< Pool of ct segment contexts */
Florin Coras2d0e3de2020-10-23 16:31:40 -070068} ct_main_t;
Florin Coras653e43f2019-03-04 10:56:23 -080069
Florin Coras2d0e3de2020-10-23 16:31:40 -070070static ct_main_t ct_main;
Florin Coras653e43f2019-03-04 10:56:23 -080071
Florin Coras7fe00692021-11-15 14:01:02 -080072static inline ct_worker_t *
73ct_worker_get (u32 thread_index)
74{
75 return &ct_main.wrk[thread_index];
76}
77
Florin Coras653e43f2019-03-04 10:56:23 -080078static ct_connection_t *
Florin Coras2d0e3de2020-10-23 16:31:40 -070079ct_connection_alloc (u32 thread_index)
Florin Corasd4295e62019-02-22 13:11:38 -080080{
Florin Coras7fe00692021-11-15 14:01:02 -080081 ct_worker_t *wrk = ct_worker_get (thread_index);
Florin Corasd4295e62019-02-22 13:11:38 -080082 ct_connection_t *ct;
83
Florin Coras7fe00692021-11-15 14:01:02 -080084 pool_get_zero (wrk->connections, ct);
85 ct->c_c_index = ct - wrk->connections;
Florin Coras2d0e3de2020-10-23 16:31:40 -070086 ct->c_thread_index = thread_index;
Florin Corasd4295e62019-02-22 13:11:38 -080087 ct->client_wrk = ~0;
88 ct->server_wrk = ~0;
Florin Corasda78c5a2021-06-09 14:55:24 -070089 ct->seg_ctx_index = ~0;
90 ct->ct_seg_index = ~0;
Florin Corasd4295e62019-02-22 13:11:38 -080091 return ct;
92}
93
Florin Coras653e43f2019-03-04 10:56:23 -080094static ct_connection_t *
Florin Coras2d0e3de2020-10-23 16:31:40 -070095ct_connection_get (u32 ct_index, u32 thread_index)
Florin Corasd4295e62019-02-22 13:11:38 -080096{
Florin Coras7fe00692021-11-15 14:01:02 -080097 ct_worker_t *wrk = ct_worker_get (thread_index);
98
99 if (pool_is_free_index (wrk->connections, ct_index))
Florin Corasd4295e62019-02-22 13:11:38 -0800100 return 0;
Florin Coras7fe00692021-11-15 14:01:02 -0800101 return pool_elt_at_index (wrk->connections, ct_index);
Florin Corasba7d8f52019-02-22 13:11:38 -0800102}
103
Florin Coras653e43f2019-03-04 10:56:23 -0800104static void
Florin Corasd4295e62019-02-22 13:11:38 -0800105ct_connection_free (ct_connection_t * ct)
Florin Corasba7d8f52019-02-22 13:11:38 -0800106{
Florin Coras7fe00692021-11-15 14:01:02 -0800107 ct_worker_t *wrk = ct_worker_get (ct->c_thread_index);
108
Florin Corasba7d8f52019-02-22 13:11:38 -0800109 if (CLIB_DEBUG)
Florin Coras2d0e3de2020-10-23 16:31:40 -0700110 {
Florin Coras7fe00692021-11-15 14:01:02 -0800111 clib_memset (ct, 0xfc, sizeof (*ct));
112 pool_put (wrk->connections, ct);
Florin Coras2d0e3de2020-10-23 16:31:40 -0700113 return;
114 }
Florin Coras7fe00692021-11-15 14:01:02 -0800115 pool_put (wrk->connections, ct);
Florin Corasba7d8f52019-02-22 13:11:38 -0800116}
117
Florin Coras374df7a2021-05-13 11:37:43 -0700118static ct_connection_t *
119ct_half_open_alloc (void)
120{
121 ct_main_t *cm = &ct_main;
122 u32 *hip;
123
124 clib_spinlock_lock (&cm->ho_reuseable_lock);
125 vec_foreach (hip, cm->ho_reusable)
Florin Coras7fe00692021-11-15 14:01:02 -0800126 pool_put_index (cm->wrk[0].connections, *hip);
Florin Coras374df7a2021-05-13 11:37:43 -0700127 vec_reset_length (cm->ho_reusable);
128 clib_spinlock_unlock (&cm->ho_reuseable_lock);
129
130 return ct_connection_alloc (0);
131}
132
133void
134ct_half_open_add_reusable (u32 ho_index)
135{
136 ct_main_t *cm = &ct_main;
137
138 clib_spinlock_lock (&cm->ho_reuseable_lock);
139 vec_add1 (cm->ho_reusable, ho_index);
140 clib_spinlock_unlock (&cm->ho_reuseable_lock);
141}
142
Florin Coras2b81e3c2019-02-27 07:55:46 -0800143session_t *
144ct_session_get_peer (session_t * s)
145{
146 ct_connection_t *ct, *peer_ct;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700147 ct = ct_connection_get (s->connection_index, s->thread_index);
148 peer_ct = ct_connection_get (ct->peer_index, s->thread_index);
149 return session_get (peer_ct->c_s_index, s->thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800150}
151
Florin Corasba7d8f52019-02-22 13:11:38 -0800152void
Florin Coras2b81e3c2019-02-27 07:55:46 -0800153ct_session_endpoint (session_t * ll, session_endpoint_t * sep)
Florin Corasba7d8f52019-02-22 13:11:38 -0800154{
Florin Corasd4295e62019-02-22 13:11:38 -0800155 ct_connection_t *ct;
156 ct = (ct_connection_t *) session_get_transport (ll);
157 sep->transport_proto = ct->actual_tp;
158 sep->port = ct->c_lcl_port;
159 sep->is_ip4 = ct->c_is_ip4;
Florin Corasea7e7082020-07-07 17:57:28 -0700160 ip_copy (&sep->ip, &ct->c_lcl_ip, ct->c_is_ip4);
Florin Corasba7d8f52019-02-22 13:11:38 -0800161}
162
Florin Corasda78c5a2021-06-09 14:55:24 -0700163static void
Florin Coras98952382021-11-14 15:33:59 -0800164ct_set_invalid_app_wrk (ct_connection_t *ct, u8 is_client)
165{
166 ct_connection_t *peer_ct;
167
168 peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
169
170 if (is_client)
171 {
172 ct->client_wrk = APP_INVALID_INDEX;
173 if (peer_ct)
174 ct->client_wrk = APP_INVALID_INDEX;
175 }
176 else
177 {
178 ct->server_wrk = APP_INVALID_INDEX;
179 if (peer_ct)
180 ct->server_wrk = APP_INVALID_INDEX;
181 }
182}
183
184static void
Florin Corasda78c5a2021-06-09 14:55:24 -0700185ct_session_dealloc_fifos (ct_connection_t *ct, svm_fifo_t *rx_fifo,
186 svm_fifo_t *tx_fifo)
Florin Corasba7d8f52019-02-22 13:11:38 -0800187{
Florin Corasda78c5a2021-06-09 14:55:24 -0700188 ct_segments_ctx_t *seg_ctx;
189 ct_main_t *cm = &ct_main;
Florin Corasba7d8f52019-02-22 13:11:38 -0800190 segment_manager_t *sm;
Florin Corasda78c5a2021-06-09 14:55:24 -0700191 app_worker_t *app_wrk;
192 ct_segment_t *ct_seg;
193 fifo_segment_t *fs;
194 u32 seg_index;
Florin Coras98952382021-11-14 15:33:59 -0800195 session_t *s;
Florin Coras6973c732021-06-17 15:53:38 -0700196 int cnt;
Florin Corasda78c5a2021-06-09 14:55:24 -0700197
198 /*
199 * Cleanup fifos
200 */
201
202 sm = segment_manager_get (rx_fifo->segment_manager);
203 seg_index = rx_fifo->segment_index;
204
205 fs = segment_manager_get_segment_w_lock (sm, seg_index);
206 fifo_segment_free_fifo (fs, rx_fifo);
207 fifo_segment_free_fifo (fs, tx_fifo);
208 segment_manager_segment_reader_unlock (sm);
209
210 /*
Florin Coras6973c732021-06-17 15:53:38 -0700211 * Atomically update segment context with readers lock
Florin Corasda78c5a2021-06-09 14:55:24 -0700212 */
213
214 clib_rwlock_reader_lock (&cm->app_segs_lock);
215
216 seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, ct->seg_ctx_index);
217 ct_seg = pool_elt_at_index (seg_ctx->segments, ct->ct_seg_index);
218
219 if (ct->flags & CT_CONN_F_CLIENT)
220 {
221 cnt =
222 __atomic_sub_fetch (&ct_seg->client_n_sessions, 1, __ATOMIC_RELAXED);
Florin Corasda78c5a2021-06-09 14:55:24 -0700223 }
224 else
225 {
226 cnt =
227 __atomic_sub_fetch (&ct_seg->server_n_sessions, 1, __ATOMIC_RELAXED);
Florin Corasda78c5a2021-06-09 14:55:24 -0700228 }
229
Florin Corasda78c5a2021-06-09 14:55:24 -0700230 clib_rwlock_reader_unlock (&cm->app_segs_lock);
231
232 /*
233 * No need to do any app updates, return
234 */
Florin Coras6973c732021-06-17 15:53:38 -0700235 ASSERT (cnt >= 0);
236 if (cnt)
237 return;
238
239 /*
240 * Grab exclusive lock and update flags unless some other thread
241 * added more sessions
242 */
243 clib_rwlock_writer_lock (&cm->app_segs_lock);
244
245 seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, ct->seg_ctx_index);
246 ct_seg = pool_elt_at_index (seg_ctx->segments, ct->ct_seg_index);
247 if (ct->flags & CT_CONN_F_CLIENT)
248 {
249 cnt = ct_seg->client_n_sessions;
Florin Coras98952382021-11-14 15:33:59 -0800250 if (cnt)
251 goto done;
252 ct_seg->flags |= CT_SEGMENT_F_CLIENT_DETACHED;
253 s = session_get (ct->c_s_index, ct->c_thread_index);
254 if (s->app_wrk_index == APP_INVALID_INDEX)
255 ct_set_invalid_app_wrk (ct, 1 /* is_client */);
Florin Coras6973c732021-06-17 15:53:38 -0700256 }
257 else
258 {
259 cnt = ct_seg->server_n_sessions;
Florin Coras98952382021-11-14 15:33:59 -0800260 if (cnt)
261 goto done;
262 ct_seg->flags |= CT_SEGMENT_F_SERVER_DETACHED;
263 s = session_get (ct->c_s_index, ct->c_thread_index);
264 if (s->app_wrk_index == APP_INVALID_INDEX)
265 ct_set_invalid_app_wrk (ct, 0 /* is_client */);
Florin Coras6973c732021-06-17 15:53:38 -0700266 }
267
Florin Coras98952382021-11-14 15:33:59 -0800268 if (!(ct_seg->flags & CT_SEGMENT_F_CLIENT_DETACHED) ||
269 !(ct_seg->flags & CT_SEGMENT_F_SERVER_DETACHED))
270 goto done;
271
Florin Coras6973c732021-06-17 15:53:38 -0700272 /*
273 * Remove segment context because both client and server detached
274 */
275
Florin Coras98952382021-11-14 15:33:59 -0800276 pool_put_index (seg_ctx->segments, ct->ct_seg_index);
Florin Coras6973c732021-06-17 15:53:38 -0700277
278 /*
Florin Coras98952382021-11-14 15:33:59 -0800279 * No more segment indices left, remove the segments context
Florin Coras6973c732021-06-17 15:53:38 -0700280 */
Florin Coras98952382021-11-14 15:33:59 -0800281 if (!pool_elts (seg_ctx->segments))
Florin Corasda78c5a2021-06-09 14:55:24 -0700282 {
Florin Coras98952382021-11-14 15:33:59 -0800283 u64 table_handle = seg_ctx->client_wrk << 16 | seg_ctx->server_wrk;
284 table_handle = (u64) seg_ctx->sm_index << 32 | table_handle;
285 hash_unset (cm->app_segs_ctxs_table, table_handle);
286 pool_free (seg_ctx->segments);
287 pool_put_index (cm->app_seg_ctxs, ct->seg_ctx_index);
Florin Corasda78c5a2021-06-09 14:55:24 -0700288 }
Florin Coras98952382021-11-14 15:33:59 -0800289
290 /*
291 * Segment to be removed so notify both apps
292 */
293
294 app_wrk = app_worker_get_if_valid (ct->client_wrk);
295 /* Determine if client app still needs notification, i.e., if it is
296 * still attached. If client detached and this is the last ct session
297 * on this segment, then its connects segment manager should also be
298 * detached, so do not send notification */
299 if (app_wrk)
300 {
301 segment_manager_t *csm;
302 csm = app_worker_get_connect_segment_manager (app_wrk);
303 if (!segment_manager_app_detached (csm))
304 app_worker_del_segment_notify (app_wrk, ct->segment_handle);
305 }
306
307 if (!segment_manager_app_detached (sm))
Florin Corasda78c5a2021-06-09 14:55:24 -0700308 {
309 app_wrk = app_worker_get (ct->server_wrk);
310 app_worker_del_segment_notify (app_wrk, ct->segment_handle);
311 }
312
Florin Corasda78c5a2021-06-09 14:55:24 -0700313 segment_manager_lock_and_del_segment (sm, seg_index);
314
315 /* Cleanup segment manager if needed. If server detaches there's a chance
316 * the client's sessions will hold up segment removal */
317 if (segment_manager_app_detached (sm) && !segment_manager_has_fifos (sm))
318 segment_manager_free_safe (sm);
Florin Coras98952382021-11-14 15:33:59 -0800319
320done:
321
322 clib_rwlock_writer_unlock (&cm->app_segs_lock);
Florin Corasda78c5a2021-06-09 14:55:24 -0700323}
324
325int
Florin Coras6973c732021-06-17 15:53:38 -0700326ct_session_connect_notify (session_t *ss, session_error_t err)
Florin Corasda78c5a2021-06-09 14:55:24 -0700327{
Florin Coras6973c732021-06-17 15:53:38 -0700328 u32 ss_index, opaque, thread_index;
Florin Corasda78c5a2021-06-09 14:55:24 -0700329 ct_connection_t *sct, *cct;
Florin Corasda78c5a2021-06-09 14:55:24 -0700330 app_worker_t *client_wrk;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800331 session_t *cs;
Florin Corasba7d8f52019-02-22 13:11:38 -0800332
Florin Coras2b81e3c2019-02-27 07:55:46 -0800333 ss_index = ss->session_index;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700334 thread_index = ss->thread_index;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800335 sct = (ct_connection_t *) session_get_transport (ss);
336 client_wrk = app_worker_get (sct->client_wrk);
Florin Corasdd7d24b2020-08-14 17:51:13 -0700337 opaque = sct->client_opaque;
Florin Corasba7d8f52019-02-22 13:11:38 -0800338
Florin Coras2d0e3de2020-10-23 16:31:40 -0700339 cct = ct_connection_get (sct->peer_index, thread_index);
Florin Corasba7d8f52019-02-22 13:11:38 -0800340
Florin Coras374df7a2021-05-13 11:37:43 -0700341 /* Client closed while waiting for reply from server */
Florin Coras6973c732021-06-17 15:53:38 -0700342 if (PREDICT_FALSE (!cct))
Florin Coras374df7a2021-05-13 11:37:43 -0700343 {
344 session_transport_closing_notify (&sct->connection);
345 session_transport_delete_notify (&sct->connection);
346 ct_connection_free (sct);
347 return 0;
348 }
349
350 session_half_open_delete_notify (&cct->connection);
351 cct->flags &= ~CT_CONN_F_HALF_OPEN;
352
Florin Coras6973c732021-06-17 15:53:38 -0700353 if (PREDICT_FALSE (err))
354 goto connect_error;
Florin Corasda78c5a2021-06-09 14:55:24 -0700355
356 /*
357 * Alloc client session
358 */
359
Florin Coras2d0e3de2020-10-23 16:31:40 -0700360 cs = session_alloc (thread_index);
361 ss = session_get (ss_index, thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800362 cs->session_type = ss->session_type;
Nathan Skrzypczak2f0f96b2019-06-13 10:14:28 +0200363 cs->listener_handle = SESSION_INVALID_HANDLE;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800364 cs->session_state = SESSION_STATE_CONNECTING;
365 cs->app_wrk_index = client_wrk->wrk_index;
366 cs->connection_index = cct->c_c_index;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800367 cct->c_s_index = cs->session_index;
368
369 /* This will allocate fifos for the session. They won't be used for
370 * exchanging data but they will be used to close the connection if
371 * the segment manager/worker is freed */
Florin Corasdd7d24b2020-08-14 17:51:13 -0700372 if ((err = app_worker_init_connected (client_wrk, cs)))
Florin Coras2b81e3c2019-02-27 07:55:46 -0800373 {
Florin Corasdd7d24b2020-08-14 17:51:13 -0700374 session_free (cs);
Florin Coras6973c732021-06-17 15:53:38 -0700375 session_close (ss);
376 err = SESSION_E_ALLOC;
377 goto connect_error;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800378 }
379
Florin Corasdd7d24b2020-08-14 17:51:13 -0700380 cs->session_state = SESSION_STATE_CONNECTING;
381
Florin Coras6973c732021-06-17 15:53:38 -0700382 if (app_worker_connect_notify (client_wrk, cs, 0, opaque))
Florin Coras2b81e3c2019-02-27 07:55:46 -0800383 {
Florin Coras6973c732021-06-17 15:53:38 -0700384 segment_manager_dealloc_fifos (cs->rx_fifo, cs->tx_fifo);
Florin Corasdd7d24b2020-08-14 17:51:13 -0700385 session_free (cs);
Florin Coras6973c732021-06-17 15:53:38 -0700386 session_close (ss);
387 goto cleanup_client;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800388 }
389
Florin Coras2d0e3de2020-10-23 16:31:40 -0700390 cs = session_get (cct->c_s_index, cct->c_thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800391 cs->session_state = SESSION_STATE_READY;
392
Florin Corasba7d8f52019-02-22 13:11:38 -0800393 return 0;
Florin Corasdd7d24b2020-08-14 17:51:13 -0700394
Florin Coras6973c732021-06-17 15:53:38 -0700395connect_error:
396
397 app_worker_connect_notify (client_wrk, 0, err, cct->client_opaque);
398
399cleanup_client:
400
401 if (cct->client_rx_fifo)
402 ct_session_dealloc_fifos (cct, cct->client_rx_fifo, cct->client_tx_fifo);
403 ct_connection_free (cct);
Florin Corasdd7d24b2020-08-14 17:51:13 -0700404 return -1;
Florin Corasba7d8f52019-02-22 13:11:38 -0800405}
406
Florin Coras6973c732021-06-17 15:53:38 -0700407static inline ct_segment_t *
408ct_lookup_free_segment (ct_main_t *cm, segment_manager_t *sm,
409 u32 seg_ctx_index)
Florin Corasba7d8f52019-02-22 13:11:38 -0800410{
Florin Corasda78c5a2021-06-09 14:55:24 -0700411 uword free_bytes, max_free_bytes;
412 ct_segment_t *ct_seg, *res = 0;
Florin Coras6973c732021-06-17 15:53:38 -0700413 ct_segments_ctx_t *seg_ctx;
Florin Corasda78c5a2021-06-09 14:55:24 -0700414 fifo_segment_t *fs;
415 u32 max_fifos;
416
Florin Coras6973c732021-06-17 15:53:38 -0700417 seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, seg_ctx_index);
418 max_free_bytes = seg_ctx->fifo_pair_bytes;
419
Florin Corasda78c5a2021-06-09 14:55:24 -0700420 pool_foreach (ct_seg, seg_ctx->segments)
421 {
422 /* Client or server has detached so segment cannot be used */
Florin Corasda78c5a2021-06-09 14:55:24 -0700423 fs = segment_manager_get_segment (sm, ct_seg->segment_index);
424 free_bytes = fifo_segment_available_bytes (fs);
Florin Coras6973c732021-06-17 15:53:38 -0700425 max_fifos = fifo_segment_size (fs) / seg_ctx->fifo_pair_bytes;
Florin Corasda78c5a2021-06-09 14:55:24 -0700426 if (free_bytes > max_free_bytes &&
427 fifo_segment_num_fifos (fs) / 2 < max_fifos)
428 {
429 max_free_bytes = free_bytes;
430 res = ct_seg;
431 }
432 }
433
434 return res;
435}
436
Florin Coras6973c732021-06-17 15:53:38 -0700437static ct_segment_t *
438ct_alloc_segment (ct_main_t *cm, app_worker_t *server_wrk, u64 table_handle,
439 segment_manager_t *sm, u32 client_wrk_index)
440{
441 u32 seg_ctx_index = ~0, sm_index, pair_bytes;
442 segment_manager_props_t *props;
443 const u32 margin = 16 << 10;
444 ct_segments_ctx_t *seg_ctx;
445 app_worker_t *client_wrk;
446 u64 seg_size, seg_handle;
447 application_t *server;
448 ct_segment_t *ct_seg;
449 uword *spp;
450 int fs_index;
451
452 server = application_get (server_wrk->app_index);
453 props = application_segment_manager_properties (server);
454 sm_index = segment_manager_index (sm);
455 pair_bytes = props->rx_fifo_size + props->tx_fifo_size + margin;
456
457 /*
458 * Make sure another thread did not alloc a segment while acquiring the lock
459 */
460
461 spp = hash_get (cm->app_segs_ctxs_table, table_handle);
462 if (spp)
463 {
464 seg_ctx_index = *spp;
465 ct_seg = ct_lookup_free_segment (cm, sm, seg_ctx_index);
466 if (ct_seg)
467 return ct_seg;
468 }
469
470 /*
471 * No segment, try to alloc one and notify the server and the client.
472 * Make sure the segment is not used for other fifos
473 */
474 seg_size = clib_max (props->segment_size, 128 << 20);
475 fs_index =
476 segment_manager_add_segment2 (sm, seg_size, FIFO_SEGMENT_F_CUSTOM_USE);
477 if (fs_index < 0)
478 return 0;
479
480 if (seg_ctx_index == ~0)
481 {
482 pool_get_zero (cm->app_seg_ctxs, seg_ctx);
483 seg_ctx_index = seg_ctx - cm->app_seg_ctxs;
484 hash_set (cm->app_segs_ctxs_table, table_handle, seg_ctx_index);
485 seg_ctx->server_wrk = server_wrk->wrk_index;
486 seg_ctx->client_wrk = client_wrk_index;
487 seg_ctx->sm_index = sm_index;
488 seg_ctx->fifo_pair_bytes = pair_bytes;
489 }
490 else
491 {
492 seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, seg_ctx_index);
493 }
494
495 pool_get_zero (seg_ctx->segments, ct_seg);
496 ct_seg->segment_index = fs_index;
497 ct_seg->server_n_sessions = 0;
498 ct_seg->client_n_sessions = 0;
499 ct_seg->ct_seg_index = ct_seg - seg_ctx->segments;
500 ct_seg->seg_ctx_index = seg_ctx_index;
501
502 /* New segment, notify the server and client */
503 seg_handle = segment_manager_make_segment_handle (sm_index, fs_index);
504 if (app_worker_add_segment_notify (server_wrk, seg_handle))
505 goto error;
506
507 client_wrk = app_worker_get (client_wrk_index);
508 if (app_worker_add_segment_notify (client_wrk, seg_handle))
509 {
510 app_worker_del_segment_notify (server_wrk, seg_handle);
511 goto error;
512 }
513
514 return ct_seg;
515
516error:
517
518 segment_manager_lock_and_del_segment (sm, fs_index);
519 pool_put_index (seg_ctx->segments, ct_seg->seg_ctx_index);
520 return 0;
521}
522
Florin Corasda78c5a2021-06-09 14:55:24 -0700523static int
524ct_init_accepted_session (app_worker_t *server_wrk, ct_connection_t *ct,
525 session_t *ls, session_t *ll)
526{
Florin Coras88001c62019-04-24 14:44:46 -0700527 segment_manager_props_t *props;
Florin Coras6973c732021-06-17 15:53:38 -0700528 u64 seg_handle, table_handle;
529 u32 sm_index, fs_index = ~0;
Florin Corasda78c5a2021-06-09 14:55:24 -0700530 ct_segments_ctx_t *seg_ctx;
531 ct_main_t *cm = &ct_main;
Florin Coras653e43f2019-03-04 10:56:23 -0800532 application_t *server;
Florin Corasba7d8f52019-02-22 13:11:38 -0800533 segment_manager_t *sm;
Florin Corasda78c5a2021-06-09 14:55:24 -0700534 ct_segment_t *ct_seg;
535 fifo_segment_t *fs;
Florin Corasda78c5a2021-06-09 14:55:24 -0700536 uword *spp;
Florin Coras6973c732021-06-17 15:53:38 -0700537 int rv;
Florin Corasba7d8f52019-02-22 13:11:38 -0800538
Florin Coras2b81e3c2019-02-27 07:55:46 -0800539 sm = app_worker_get_listen_segment_manager (server_wrk, ll);
Florin Corasda78c5a2021-06-09 14:55:24 -0700540 sm_index = segment_manager_index (sm);
541 server = application_get (server_wrk->app_index);
542 props = application_segment_manager_properties (server);
Florin Corasba7d8f52019-02-22 13:11:38 -0800543
Florin Corasda78c5a2021-06-09 14:55:24 -0700544 table_handle = ct->client_wrk << 16 | server_wrk->wrk_index;
Florin Coras6973c732021-06-17 15:53:38 -0700545 table_handle = (u64) sm_index << 32 | table_handle;
Florin Corasda78c5a2021-06-09 14:55:24 -0700546
547 /*
548 * Check if we already have a segment that can hold the fifos
549 */
550
551 clib_rwlock_reader_lock (&cm->app_segs_lock);
552
553 spp = hash_get (cm->app_segs_ctxs_table, table_handle);
554 if (spp)
555 {
Florin Coras6973c732021-06-17 15:53:38 -0700556 ct_seg = ct_lookup_free_segment (cm, sm, *spp);
Florin Corasda78c5a2021-06-09 14:55:24 -0700557 if (ct_seg)
558 {
Florin Coras6973c732021-06-17 15:53:38 -0700559 ct->seg_ctx_index = ct_seg->seg_ctx_index;
560 ct->ct_seg_index = ct_seg->ct_seg_index;
Florin Corasda78c5a2021-06-09 14:55:24 -0700561 fs_index = ct_seg->segment_index;
Florin Coras98952382021-11-14 15:33:59 -0800562 ct_seg->flags &=
563 ~(CT_SEGMENT_F_SERVER_DETACHED | CT_SEGMENT_F_CLIENT_DETACHED);
Florin Corasda78c5a2021-06-09 14:55:24 -0700564 __atomic_add_fetch (&ct_seg->server_n_sessions, 1, __ATOMIC_RELAXED);
Florin Coras6973c732021-06-17 15:53:38 -0700565 __atomic_add_fetch (&ct_seg->client_n_sessions, 1, __ATOMIC_RELAXED);
Florin Corasda78c5a2021-06-09 14:55:24 -0700566 }
567 }
568
569 clib_rwlock_reader_unlock (&cm->app_segs_lock);
570
571 /*
Florin Coras6973c732021-06-17 15:53:38 -0700572 * If not, grab exclusive lock and allocate segment
Florin Corasda78c5a2021-06-09 14:55:24 -0700573 */
Florin Coras6973c732021-06-17 15:53:38 -0700574 if (fs_index == ~0)
Florin Corasda78c5a2021-06-09 14:55:24 -0700575 {
Florin Corasda78c5a2021-06-09 14:55:24 -0700576 clib_rwlock_writer_lock (&cm->app_segs_lock);
577
Florin Coras6973c732021-06-17 15:53:38 -0700578 ct_seg =
579 ct_alloc_segment (cm, server_wrk, table_handle, sm, ct->client_wrk);
580 if (!ct_seg)
Florin Corasda78c5a2021-06-09 14:55:24 -0700581 {
Florin Coras6973c732021-06-17 15:53:38 -0700582 clib_rwlock_writer_unlock (&cm->app_segs_lock);
583 return -1;
Florin Corasda78c5a2021-06-09 14:55:24 -0700584 }
Florin Corasda78c5a2021-06-09 14:55:24 -0700585
Florin Coras6973c732021-06-17 15:53:38 -0700586 ct->seg_ctx_index = ct_seg->seg_ctx_index;
587 ct->ct_seg_index = ct_seg->ct_seg_index;
Florin Corasda78c5a2021-06-09 14:55:24 -0700588 ct_seg->server_n_sessions += 1;
Florin Coras6973c732021-06-17 15:53:38 -0700589 ct_seg->client_n_sessions += 1;
590 fs_index = ct_seg->segment_index;
Florin Corasda78c5a2021-06-09 14:55:24 -0700591
592 clib_rwlock_writer_unlock (&cm->app_segs_lock);
Florin Corasda78c5a2021-06-09 14:55:24 -0700593 }
594
595 /*
596 * Allocate and initialize the fifos
597 */
598 fs = segment_manager_get_segment_w_lock (sm, fs_index);
599 rv = segment_manager_try_alloc_fifos (
600 fs, ls->thread_index, props->rx_fifo_size, props->tx_fifo_size,
601 &ls->rx_fifo, &ls->tx_fifo);
Florin Corasba7d8f52019-02-22 13:11:38 -0800602 if (rv)
603 {
Florin Corasba7d8f52019-02-22 13:11:38 -0800604 segment_manager_segment_reader_unlock (sm);
Florin Coras6973c732021-06-17 15:53:38 -0700605
606 clib_rwlock_reader_lock (&cm->app_segs_lock);
607
608 seg_ctx = pool_elt_at_index (cm->app_seg_ctxs, ct->seg_ctx_index);
609 ct_seg = pool_elt_at_index (seg_ctx->segments, ct->ct_seg_index);
610 __atomic_sub_fetch (&ct_seg->server_n_sessions, 1, __ATOMIC_RELAXED);
611 __atomic_sub_fetch (&ct_seg->client_n_sessions, 1, __ATOMIC_RELAXED);
612
613 clib_rwlock_reader_unlock (&cm->app_segs_lock);
614
615 return rv;
Florin Corasba7d8f52019-02-22 13:11:38 -0800616 }
Florin Coras2b81e3c2019-02-27 07:55:46 -0800617
Florin Corasc547e912020-12-08 17:50:45 -0800618 ls->rx_fifo->shr->master_session_index = ls->session_index;
619 ls->tx_fifo->shr->master_session_index = ls->session_index;
Florin Corasce252ca2020-11-04 13:08:35 -0800620 ls->rx_fifo->master_thread_index = ls->thread_index;
621 ls->tx_fifo->master_thread_index = ls->thread_index;
Florin Corasba7d8f52019-02-22 13:11:38 -0800622 ls->rx_fifo->segment_manager = sm_index;
623 ls->tx_fifo->segment_manager = sm_index;
Florin Corasda78c5a2021-06-09 14:55:24 -0700624 ls->rx_fifo->segment_index = fs_index;
625 ls->tx_fifo->segment_index = fs_index;
Florin Corasba7d8f52019-02-22 13:11:38 -0800626
Florin Corasda78c5a2021-06-09 14:55:24 -0700627 seg_handle = segment_manager_segment_handle (sm, fs);
Florin Corasba7d8f52019-02-22 13:11:38 -0800628 segment_manager_segment_reader_unlock (sm);
Florin Corasda78c5a2021-06-09 14:55:24 -0700629
630 ct->segment_handle = seg_handle;
Florin Corasba7d8f52019-02-22 13:11:38 -0800631
632 return 0;
Florin Corasba7d8f52019-02-22 13:11:38 -0800633}
634
Florin Coras2d0e3de2020-10-23 16:31:40 -0700635static void
Florin Corasc215e5a2021-11-15 19:01:52 -0800636ct_accept_one (u32 thread_index, u32 ho_index)
Florin Coras2d0e3de2020-10-23 16:31:40 -0700637{
Florin Corasba026412021-06-12 11:56:19 -0700638 ct_connection_t *sct, *cct, *ho;
639 transport_connection_t *ll_ct;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800640 app_worker_t *server_wrk;
Florin Corasc215e5a2021-11-15 19:01:52 -0800641 u32 cct_index, ll_index;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700642 session_t *ss, *ll;
Florin Corasba7d8f52019-02-22 13:11:38 -0800643
Florin Coras374df7a2021-05-13 11:37:43 -0700644 /*
645 * Alloc client ct and initialize from ho
646 */
Florin Coras374df7a2021-05-13 11:37:43 -0700647 cct = ct_connection_alloc (thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800648 cct_index = cct->c_c_index;
Florin Coras374df7a2021-05-13 11:37:43 -0700649
Florin Coras374df7a2021-05-13 11:37:43 -0700650 ho = ct_connection_get (ho_index, 0);
651
652 /* Unlikely but half-open session and transport could have been freed */
653 if (PREDICT_FALSE (!ho))
654 {
655 ct_connection_free (cct);
656 return;
657 }
658
659 clib_memcpy (cct, ho, sizeof (*ho));
660 cct->c_c_index = cct_index;
661 cct->c_thread_index = thread_index;
662 cct->flags |= CT_CONN_F_HALF_OPEN;
663
664 /* Notify session layer that half-open is on a different thread
665 * and mark ho connection index reusable. Avoids another rpc
666 */
667 session_half_open_migrate_notify (&cct->connection);
668 session_half_open_migrated_notify (&cct->connection);
669 ct_half_open_add_reusable (ho_index);
Florin Corasba7d8f52019-02-22 13:11:38 -0800670
Florin Coras2b81e3c2019-02-27 07:55:46 -0800671 /*
Florin Coras374df7a2021-05-13 11:37:43 -0700672 * Alloc and init server transport
Florin Coras2b81e3c2019-02-27 07:55:46 -0800673 */
Florin Coras374df7a2021-05-13 11:37:43 -0700674
675 ll_index = cct->peer_index;
676 ll = listen_session_get (ll_index);
677 sct = ct_connection_alloc (thread_index);
Florin Corasba026412021-06-12 11:56:19 -0700678 /* Transport not necessarily ct but it might, so grab after sct alloc */
679 ll_ct = listen_session_get_transport (ll);
Florin Coras374df7a2021-05-13 11:37:43 -0700680
681 /* Make sure cct is valid after sct alloc */
682 cct = ct_connection_get (cct_index, thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800683
Florin Coras2b81e3c2019-02-27 07:55:46 -0800684 sct->c_rmt_port = 0;
Florin Corasba026412021-06-12 11:56:19 -0700685 sct->c_lcl_port = ll_ct->lcl_port;
Florin Coras374df7a2021-05-13 11:37:43 -0700686 sct->c_is_ip4 = cct->c_is_ip4;
Florin Corasd9e98702021-10-11 18:10:41 -0700687 clib_memcpy (&sct->c_lcl_ip, &cct->c_rmt_ip, sizeof (cct->c_rmt_ip));
Florin Coras374df7a2021-05-13 11:37:43 -0700688 sct->client_wrk = cct->client_wrk;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800689 sct->c_proto = TRANSPORT_PROTO_NONE;
Florin Coras374df7a2021-05-13 11:37:43 -0700690 sct->client_opaque = cct->client_opaque;
Florin Corasba026412021-06-12 11:56:19 -0700691 sct->actual_tp = cct->actual_tp;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800692
693 sct->peer_index = cct->c_c_index;
694 cct->peer_index = sct->c_c_index;
695
696 /*
697 * Accept server session. Client session is created only after
698 * server confirms accept.
699 */
Florin Coras374df7a2021-05-13 11:37:43 -0700700 ss = session_alloc (thread_index);
701 ll = listen_session_get (ll_index);
Florin Coras9f1a5432019-03-10 21:03:20 -0700702 ss->session_type = session_type_from_proto_and_ip (TRANSPORT_PROTO_NONE,
703 sct->c_is_ip4);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800704 ss->connection_index = sct->c_c_index;
Nathan Skrzypczak2f0f96b2019-06-13 10:14:28 +0200705 ss->listener_handle = listen_session_get_handle (ll);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800706 ss->session_state = SESSION_STATE_CREATED;
707
708 server_wrk = application_listener_select_worker (ll);
709 ss->app_wrk_index = server_wrk->wrk_index;
710
711 sct->c_s_index = ss->session_index;
712 sct->server_wrk = ss->app_wrk_index;
713
Florin Coras2d0e3de2020-10-23 16:31:40 -0700714 if (ct_init_accepted_session (server_wrk, sct, ss, ll))
Florin Corasba7d8f52019-02-22 13:11:38 -0800715 {
Florin Coras6973c732021-06-17 15:53:38 -0700716 ct_session_connect_notify (ss, SESSION_E_ALLOC);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800717 ct_connection_free (sct);
718 session_free (ss);
Florin Coras2d0e3de2020-10-23 16:31:40 -0700719 return;
Florin Corasba7d8f52019-02-22 13:11:38 -0800720 }
721
Florin Coras98952382021-11-14 15:33:59 -0800722 cct->server_wrk = sct->server_wrk;
Florin Coras6973c732021-06-17 15:53:38 -0700723 cct->seg_ctx_index = sct->seg_ctx_index;
724 cct->ct_seg_index = sct->ct_seg_index;
725 cct->client_rx_fifo = ss->tx_fifo;
726 cct->client_tx_fifo = ss->rx_fifo;
727 cct->client_rx_fifo->refcnt++;
728 cct->client_tx_fifo->refcnt++;
729 cct->segment_handle = sct->segment_handle;
730
Florin Coras2b81e3c2019-02-27 07:55:46 -0800731 ss->session_state = SESSION_STATE_ACCEPTING;
732 if (app_worker_accept_notify (server_wrk, ss))
733 {
Florin Coras6973c732021-06-17 15:53:38 -0700734 ct_session_connect_notify (ss, SESSION_E_REFUSED);
Florin Corasda78c5a2021-06-09 14:55:24 -0700735 ct_session_dealloc_fifos (sct, ss->rx_fifo, ss->tx_fifo);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800736 ct_connection_free (sct);
Florin Coras12813d52020-04-09 20:59:20 +0000737 session_free (ss);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800738 }
Florin Coras2d0e3de2020-10-23 16:31:40 -0700739}
740
Florin Corasc215e5a2021-11-15 19:01:52 -0800741static void
742ct_accept_rpc_wrk_handler (void *rpc_args)
743{
744 u32 thread_index, ho_index, n_connects, i, n_pending;
745 const u32 max_connects = 32;
746 ct_worker_t *wrk;
747
748 thread_index = pointer_to_uword (rpc_args);
749 wrk = ct_worker_get (thread_index);
750
751 /* Sub without lock as main enqueues with worker barrier */
752 n_pending = clib_fifo_elts (wrk->pending_connects);
753 n_connects = clib_min (n_pending, max_connects);
754
755 for (i = 0; i < n_connects; i++)
756 {
757 clib_fifo_sub1 (wrk->pending_connects, ho_index);
758 ct_accept_one (thread_index, ho_index);
759 }
760
761 if (n_pending == n_connects)
762 wrk->have_connects = 0;
763 else
764 session_send_rpc_evt_to_thread_force (
765 thread_index, ct_accept_rpc_wrk_handler,
766 uword_to_pointer (thread_index, void *));
767}
768
Florin Coras2d0e3de2020-10-23 16:31:40 -0700769static int
770ct_connect (app_worker_t * client_wrk, session_t * ll,
771 session_endpoint_cfg_t * sep)
772{
Florin Coras374df7a2021-05-13 11:37:43 -0700773 u32 thread_index, ho_index;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700774 ct_main_t *cm = &ct_main;
Florin Coras374df7a2021-05-13 11:37:43 -0700775 ct_connection_t *ho;
Florin Corasc215e5a2021-11-15 19:01:52 -0800776 ct_worker_t *wrk;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700777
778 /* Simple round-robin policy for spreading sessions over workers. We skip
779 * thread index 0, i.e., offset the index by 1, when we have workers as it
780 * is the one dedicated to main thread. Note that n_workers does not include
781 * main thread */
782 cm->n_sessions += 1;
783 thread_index = cm->n_workers ? (cm->n_sessions % cm->n_workers) + 1 : 0;
784
Florin Coras374df7a2021-05-13 11:37:43 -0700785 /*
786 * Alloc and init client half-open transport
787 */
Florin Coras2d0e3de2020-10-23 16:31:40 -0700788
Florin Coras374df7a2021-05-13 11:37:43 -0700789 ho = ct_half_open_alloc ();
790 ho_index = ho->c_c_index;
791 ho->c_rmt_port = sep->port;
792 ho->c_lcl_port = 0;
793 ho->c_is_ip4 = sep->is_ip4;
794 ho->client_opaque = sep->opaque;
795 ho->client_wrk = client_wrk->wrk_index;
796 ho->peer_index = ll->session_index;
797 ho->c_proto = TRANSPORT_PROTO_NONE;
798 ho->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
Florin Corasd5a58822021-05-14 20:11:14 -0700799 clib_memcpy (&ho->c_rmt_ip, &sep->ip, sizeof (sep->ip));
Florin Coras374df7a2021-05-13 11:37:43 -0700800 ho->flags |= CT_CONN_F_CLIENT;
801 ho->c_s_index = ~0;
Florin Corasfeb67022021-11-11 09:24:34 -0800802 ho->actual_tp = sep->original_tp;
Florin Coras374df7a2021-05-13 11:37:43 -0700803
804 /*
805 * Accept connection on thread selected above. Connected reply comes
806 * after server accepts the connection.
807 */
808
Florin Corasc215e5a2021-11-15 19:01:52 -0800809 wrk = ct_worker_get (thread_index);
810
811 /* Worker barrier held, add without additional lock */
812 clib_fifo_add1 (wrk->pending_connects, ho_index);
813 if (!wrk->have_connects)
814 {
815 wrk->have_connects = 1;
816 session_send_rpc_evt_to_thread_force (
817 thread_index, ct_accept_rpc_wrk_handler,
818 uword_to_pointer (thread_index, void *));
819 }
Florin Coras374df7a2021-05-13 11:37:43 -0700820
821 return ho_index;
Florin Corasba7d8f52019-02-22 13:11:38 -0800822}
823
Florin Coras653e43f2019-03-04 10:56:23 -0800824static u32
Florin Corasd4295e62019-02-22 13:11:38 -0800825ct_start_listen (u32 app_listener_index, transport_endpoint_t * tep)
826{
827 session_endpoint_cfg_t *sep;
828 ct_connection_t *ct;
829
830 sep = (session_endpoint_cfg_t *) tep;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700831 ct = ct_connection_alloc (0);
Florin Corasd4295e62019-02-22 13:11:38 -0800832 ct->server_wrk = sep->app_wrk_index;
833 ct->c_is_ip4 = sep->is_ip4;
834 clib_memcpy (&ct->c_lcl_ip, &sep->ip, sizeof (sep->ip));
835 ct->c_lcl_port = sep->port;
Florin Corasa8375082020-10-25 19:06:57 -0700836 ct->c_s_index = app_listener_index;
Florin Corasd4295e62019-02-22 13:11:38 -0800837 ct->actual_tp = sep->transport_proto;
838 return ct->c_c_index;
839}
840
Florin Coras653e43f2019-03-04 10:56:23 -0800841static u32
Florin Corasd4295e62019-02-22 13:11:38 -0800842ct_stop_listen (u32 ct_index)
843{
844 ct_connection_t *ct;
Florin Coras2d0e3de2020-10-23 16:31:40 -0700845 ct = ct_connection_get (ct_index, 0);
Florin Corasd4295e62019-02-22 13:11:38 -0800846 ct_connection_free (ct);
847 return 0;
848}
849
Florin Coras653e43f2019-03-04 10:56:23 -0800850static transport_connection_t *
Florin Corasd4295e62019-02-22 13:11:38 -0800851ct_listener_get (u32 ct_index)
852{
Florin Coras2d0e3de2020-10-23 16:31:40 -0700853 return (transport_connection_t *) ct_connection_get (ct_index, 0);
Florin Corasd4295e62019-02-22 13:11:38 -0800854}
855
Florin Coras374df7a2021-05-13 11:37:43 -0700856static transport_connection_t *
857ct_half_open_get (u32 ct_index)
858{
859 return (transport_connection_t *) ct_connection_get (ct_index, 0);
860}
861
862static void
863ct_session_cleanup (u32 conn_index, u32 thread_index)
864{
865 ct_connection_t *ct, *peer_ct;
866
867 ct = ct_connection_get (conn_index, thread_index);
868 if (!ct)
869 return;
870
871 peer_ct = ct_connection_get (ct->peer_index, thread_index);
872 if (peer_ct)
873 peer_ct->peer_index = ~0;
874
875 ct_connection_free (ct);
876}
877
878static void
879ct_cleanup_ho (u32 ho_index)
880{
881 ct_connection_free (ct_connection_get (ho_index, 0));
882}
883
Florin Coras653e43f2019-03-04 10:56:23 -0800884static int
Florin Coras2b81e3c2019-02-27 07:55:46 -0800885ct_session_connect (transport_endpoint_cfg_t * tep)
886{
887 session_endpoint_cfg_t *sep_ext;
Florin Coras374df7a2021-05-13 11:37:43 -0700888 session_endpoint_t _sep, *sep = &_sep;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800889 app_worker_t *app_wrk;
890 session_handle_t lh;
891 application_t *app;
892 app_listener_t *al;
893 u32 table_index;
894 session_t *ll;
895 u8 fib_proto;
896
897 sep_ext = (session_endpoint_cfg_t *) tep;
Florin Coras374df7a2021-05-13 11:37:43 -0700898 _sep = *(session_endpoint_t *) tep;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800899 app_wrk = app_worker_get (sep_ext->app_wrk_index);
900 app = application_get (app_wrk->app_index);
901
902 sep->transport_proto = sep_ext->original_tp;
903 table_index = application_local_session_table (app);
904 lh = session_lookup_local_endpoint (table_index, sep);
905 if (lh == SESSION_DROP_HANDLE)
Florin Coras00e01d32019-10-21 16:07:46 -0700906 return SESSION_E_FILTERED;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800907
908 if (lh == SESSION_INVALID_HANDLE)
909 goto global_scope;
910
911 ll = listen_session_get_from_handle (lh);
912 al = app_listener_get_w_session (ll);
913
914 /*
915 * Break loop if rule in local table points to connecting app. This
916 * can happen if client is a generic proxy. Route connect through
917 * global table instead.
918 */
919 if (al->app_index == app->app_index)
920 goto global_scope;
921
922 return ct_connect (app_wrk, ll, sep_ext);
923
924 /*
925 * If nothing found, check the global scope for locally attached
926 * destinations. Make sure first that we're allowed to.
927 */
928
929global_scope:
930 if (session_endpoint_is_local (sep))
Florin Coras00e01d32019-10-21 16:07:46 -0700931 return SESSION_E_NOROUTE;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800932
933 if (!application_has_global_scope (app))
Florin Coras00e01d32019-10-21 16:07:46 -0700934 return SESSION_E_SCOPE;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800935
936 fib_proto = session_endpoint_fib_proto (sep);
Florin Coras95cd8642019-12-30 21:53:19 -0800937 table_index = session_lookup_get_index_for_fib (fib_proto, sep->fib_index);
Florin Coras9f1a5432019-03-10 21:03:20 -0700938 ll = session_lookup_listener_wildcard (table_index, sep);
Florin Coras2b81e3c2019-02-27 07:55:46 -0800939
Florin Coras821b5002021-06-02 21:32:39 -0700940 /* Avoid connecting app to own listener */
941 if (ll && ll->app_index != app->app_index)
Florin Coras2b81e3c2019-02-27 07:55:46 -0800942 return ct_connect (app_wrk, ll, sep_ext);
943
944 /* Failed to connect but no error */
Florin Coras374df7a2021-05-13 11:37:43 -0700945 return SESSION_E_LOCAL_CONNECT;
Florin Coras2b81e3c2019-02-27 07:55:46 -0800946}
947
Florin Coras653e43f2019-03-04 10:56:23 -0800948static void
Florin Coras440c7b52021-11-09 08:38:24 -0800949ct_session_postponed_cleanup (ct_connection_t *ct)
950{
951 app_worker_t *app_wrk;
952 session_t *s;
953
954 s = session_get (ct->c_s_index, ct->c_thread_index);
955 app_wrk = app_worker_get_if_valid (s->app_wrk_index);
956
957 if (ct->flags & CT_CONN_F_CLIENT)
958 {
959 if (app_wrk)
960 app_worker_cleanup_notify (app_wrk, s, SESSION_CLEANUP_TRANSPORT);
961
962 /* Normal free for client session as the fifos are allocated through
963 * the connects segment manager in a segment that's not shared with
964 * the server */
Florin Coras440c7b52021-11-09 08:38:24 -0800965 ct_session_dealloc_fifos (ct, ct->client_rx_fifo, ct->client_tx_fifo);
Florin Coras98952382021-11-14 15:33:59 -0800966 session_free_w_fifos (s);
Florin Coras440c7b52021-11-09 08:38:24 -0800967 }
968 else
969 {
970 /* Manual session and fifo segment cleanup to avoid implicit
971 * segment manager cleanups and notifications */
972 app_wrk = app_worker_get_if_valid (s->app_wrk_index);
973 if (app_wrk)
974 {
975 app_worker_cleanup_notify (app_wrk, s, SESSION_CLEANUP_TRANSPORT);
976 app_worker_cleanup_notify (app_wrk, s, SESSION_CLEANUP_SESSION);
977 }
978
979 ct_session_dealloc_fifos (ct, s->rx_fifo, s->tx_fifo);
980 session_free (s);
981 }
982
983 ct_connection_free (ct);
984}
985
986static void
987ct_handle_cleanups (void *args)
988{
989 uword thread_index = pointer_to_uword (args);
990 const u32 max_cleanups = 100;
Florin Coras440c7b52021-11-09 08:38:24 -0800991 ct_cleanup_req_t *req;
992 ct_connection_t *ct;
993 u32 n_to_handle = 0;
Florin Coras7fe00692021-11-15 14:01:02 -0800994 ct_worker_t *wrk;
Florin Coras440c7b52021-11-09 08:38:24 -0800995 session_t *s;
996
Florin Coras7fe00692021-11-15 14:01:02 -0800997 wrk = ct_worker_get (thread_index);
998 wrk->have_cleanups = 0;
999 n_to_handle = clib_fifo_elts (wrk->pending_cleanups);
Florin Coras440c7b52021-11-09 08:38:24 -08001000 n_to_handle = clib_min (n_to_handle, max_cleanups);
1001
1002 while (n_to_handle)
1003 {
Florin Coras7fe00692021-11-15 14:01:02 -08001004 clib_fifo_sub2 (wrk->pending_cleanups, req);
Florin Coras440c7b52021-11-09 08:38:24 -08001005 ct = ct_connection_get (req->ct_index, thread_index);
1006 s = session_get (ct->c_s_index, ct->c_thread_index);
1007 if (!svm_fifo_has_event (s->tx_fifo))
1008 ct_session_postponed_cleanup (ct);
1009 else
Florin Coras7fe00692021-11-15 14:01:02 -08001010 clib_fifo_add1 (wrk->pending_cleanups, *req);
Florin Coras440c7b52021-11-09 08:38:24 -08001011 n_to_handle -= 1;
1012 }
1013
Florin Coras7fe00692021-11-15 14:01:02 -08001014 if (clib_fifo_elts (wrk->pending_cleanups))
Florin Coras440c7b52021-11-09 08:38:24 -08001015 {
Florin Coras7fe00692021-11-15 14:01:02 -08001016 wrk->have_cleanups = 1;
Florin Coras440c7b52021-11-09 08:38:24 -08001017 session_send_rpc_evt_to_thread_force (
1018 thread_index, ct_handle_cleanups,
1019 uword_to_pointer (thread_index, void *));
1020 }
1021}
1022
1023static void
1024ct_program_cleanup (ct_connection_t *ct)
1025{
Florin Coras440c7b52021-11-09 08:38:24 -08001026 ct_cleanup_req_t *req;
1027 uword thread_index;
Florin Coras7fe00692021-11-15 14:01:02 -08001028 ct_worker_t *wrk;
Florin Coras440c7b52021-11-09 08:38:24 -08001029
1030 thread_index = ct->c_thread_index;
Florin Coras7fe00692021-11-15 14:01:02 -08001031 wrk = ct_worker_get (ct->c_thread_index);
1032
1033 clib_fifo_add2 (wrk->pending_cleanups, req);
Florin Coras440c7b52021-11-09 08:38:24 -08001034 req->ct_index = ct->c_c_index;
1035
Florin Coras7fe00692021-11-15 14:01:02 -08001036 if (wrk->have_cleanups)
Florin Coras440c7b52021-11-09 08:38:24 -08001037 return;
1038
Florin Coras7fe00692021-11-15 14:01:02 -08001039 wrk->have_cleanups = 1;
Florin Coras440c7b52021-11-09 08:38:24 -08001040 session_send_rpc_evt_to_thread_force (
1041 thread_index, ct_handle_cleanups, uword_to_pointer (thread_index, void *));
1042}
1043
Florin Corase7dda6b2021-11-09 10:42:43 -08001044static inline int
1045ct_close_is_reset (ct_connection_t *ct, session_t *s)
1046{
1047 if (ct->flags & CT_CONN_F_CLIENT)
1048 return (svm_fifo_max_dequeue (ct->client_rx_fifo) > 0);
1049 else
1050 return (svm_fifo_max_dequeue (s->rx_fifo) > 0);
1051}
1052
Florin Coras440c7b52021-11-09 08:38:24 -08001053static void
Florin Coras2b81e3c2019-02-27 07:55:46 -08001054ct_session_close (u32 ct_index, u32 thread_index)
1055{
1056 ct_connection_t *ct, *peer_ct;
1057 session_t *s;
1058
Florin Coras2d0e3de2020-10-23 16:31:40 -07001059 ct = ct_connection_get (ct_index, thread_index);
Florin Coras6973c732021-06-17 15:53:38 -07001060 s = session_get (ct->c_s_index, ct->c_thread_index);
Florin Coras2d0e3de2020-10-23 16:31:40 -07001061 peer_ct = ct_connection_get (ct->peer_index, thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001062 if (peer_ct)
1063 {
1064 peer_ct->peer_index = ~0;
Florin Coras06ac4bb2020-10-28 16:41:26 -07001065 /* Make sure session was allocated */
Florin Coras374df7a2021-05-13 11:37:43 -07001066 if (peer_ct->flags & CT_CONN_F_HALF_OPEN)
1067 {
Florin Coras6973c732021-06-17 15:53:38 -07001068 ct_session_connect_notify (s, SESSION_E_REFUSED);
Florin Coras374df7a2021-05-13 11:37:43 -07001069 }
1070 else if (peer_ct->c_s_index != ~0)
Florin Corase7dda6b2021-11-09 10:42:43 -08001071 {
1072 if (ct_close_is_reset (ct, s))
1073 session_transport_reset_notify (&peer_ct->connection);
1074 else
1075 session_transport_closing_notify (&peer_ct->connection);
1076 }
Florin Coras06ac4bb2020-10-28 16:41:26 -07001077 else
Florin Coras440c7b52021-11-09 08:38:24 -08001078 {
1079 /* should not happen */
1080 clib_warning ("ct peer without session");
1081 ct_connection_free (peer_ct);
1082 }
Florin Coras2b81e3c2019-02-27 07:55:46 -08001083 }
1084
Florin Coras440c7b52021-11-09 08:38:24 -08001085 /* Do not send closed notify to make sure pending tx events are
1086 * still delivered and program cleanup */
1087 ct_program_cleanup (ct);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001088}
1089
Florin Coras653e43f2019-03-04 10:56:23 -08001090static transport_connection_t *
Florin Coras2b81e3c2019-02-27 07:55:46 -08001091ct_session_get (u32 ct_index, u32 thread_index)
1092{
Florin Coras2d0e3de2020-10-23 16:31:40 -07001093 return (transport_connection_t *) ct_connection_get (ct_index,
1094 thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001095}
1096
Florin Corasd4295e62019-02-22 13:11:38 -08001097static u8 *
1098format_ct_connection_id (u8 * s, va_list * args)
1099{
1100 ct_connection_t *ct = va_arg (*args, ct_connection_t *);
1101 if (!ct)
1102 return s;
1103 if (ct->c_is_ip4)
1104 {
1105 s = format (s, "[%d:%d][CT:%U] %U:%d->%U:%d", ct->c_thread_index,
1106 ct->c_s_index, format_transport_proto_short, ct->actual_tp,
1107 format_ip4_address, &ct->c_lcl_ip4,
1108 clib_net_to_host_u16 (ct->c_lcl_port), format_ip4_address,
1109 &ct->c_rmt_ip4, clib_net_to_host_u16 (ct->c_rmt_port));
1110 }
1111 else
1112 {
1113 s = format (s, "[%d:%d][CT:%U] %U:%d->%U:%d", ct->c_thread_index,
1114 ct->c_s_index, format_transport_proto_short, ct->actual_tp,
1115 format_ip6_address, &ct->c_lcl_ip6,
1116 clib_net_to_host_u16 (ct->c_lcl_port), format_ip6_address,
1117 &ct->c_rmt_ip6, clib_net_to_host_u16 (ct->c_rmt_port));
1118 }
1119
1120 return s;
1121}
1122
Florin Corasf940f8a2019-03-06 10:44:38 -08001123static int
Florin Coras9f86d222020-03-23 15:34:22 +00001124ct_custom_tx (void *session, transport_send_params_t * sp)
Florin Corasf940f8a2019-03-06 10:44:38 -08001125{
1126 session_t *s = (session_t *) session;
1127 if (session_has_transport (s))
1128 return 0;
Florin Coras1b9d2c22021-01-26 14:10:43 -08001129 /* If event enqueued towards peer, remove from scheduler and remove
1130 * session tx flag, i.e., accept new tx events. Unset fifo flag now to
1131 * avoid missing events if peer did not clear fifo flag yet, which is
1132 * interpreted as successful notification and session is descheduled. */
1133 svm_fifo_unset_event (s->tx_fifo);
Florin Corasd6894562020-10-28 00:37:15 -07001134 if (!ct_session_tx (s))
Florin Coras1b9d2c22021-01-26 14:10:43 -08001135 sp->flags = TRANSPORT_SND_F_DESCHED;
1136
Florin Corasd6894562020-10-28 00:37:15 -07001137 /* The scheduler uses packet count as a means of upper bounding the amount
1138 * of work done per dispatch. So make it look like we have sent something */
1139 return 1;
Florin Corasf940f8a2019-03-06 10:44:38 -08001140}
1141
Florin Coras317b8e02019-04-17 09:57:46 -07001142static int
1143ct_app_rx_evt (transport_connection_t * tc)
1144{
1145 ct_connection_t *ct = (ct_connection_t *) tc, *peer_ct;
1146 session_t *ps;
1147
Florin Coras2d0e3de2020-10-23 16:31:40 -07001148 peer_ct = ct_connection_get (ct->peer_index, tc->thread_index);
Florin Coras317b8e02019-04-17 09:57:46 -07001149 if (!peer_ct)
1150 return -1;
1151 ps = session_get (peer_ct->c_s_index, peer_ct->c_thread_index);
1152 return session_dequeue_notify (ps);
1153}
1154
Florin Coras653e43f2019-03-04 10:56:23 -08001155static u8 *
Florin Corasd4295e62019-02-22 13:11:38 -08001156format_ct_listener (u8 * s, va_list * args)
1157{
1158 u32 tc_index = va_arg (*args, u32);
Aloys Augustina0abbff2019-07-12 12:16:16 +02001159 u32 __clib_unused thread_index = va_arg (*args, u32);
Florin Corasd4295e62019-02-22 13:11:38 -08001160 u32 __clib_unused verbose = va_arg (*args, u32);
Florin Coras2d0e3de2020-10-23 16:31:40 -07001161 ct_connection_t *ct = ct_connection_get (tc_index, 0);
Florin Coras7bf6ed62020-09-23 12:02:08 -07001162 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
Florin Corasd4295e62019-02-22 13:11:38 -08001163 if (verbose)
Florin Coras7bf6ed62020-09-23 12:02:08 -07001164 s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "LISTEN");
Florin Corasd4295e62019-02-22 13:11:38 -08001165 return s;
1166}
1167
Florin Coras653e43f2019-03-04 10:56:23 -08001168static u8 *
Florin Coras374df7a2021-05-13 11:37:43 -07001169format_ct_half_open (u8 *s, va_list *args)
1170{
1171 u32 ho_index = va_arg (*args, u32);
1172 u32 verbose = va_arg (*args, u32);
1173 ct_connection_t *ct = ct_connection_get (ho_index, 0);
1174 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
1175 if (verbose)
1176 s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "HALF-OPEN");
1177 return s;
1178}
1179
1180static u8 *
Florin Coras2b81e3c2019-02-27 07:55:46 -08001181format_ct_connection (u8 * s, va_list * args)
1182{
1183 ct_connection_t *ct = va_arg (*args, ct_connection_t *);
1184 u32 verbose = va_arg (*args, u32);
1185
1186 if (!ct)
1187 return s;
Florin Coras7bf6ed62020-09-23 12:02:08 -07001188 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_ct_connection_id, ct);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001189 if (verbose)
1190 {
Florin Coras7bf6ed62020-09-23 12:02:08 -07001191 s = format (s, "%-" SESSION_CLI_STATE_LEN "s", "ESTABLISHED");
Florin Coras2b81e3c2019-02-27 07:55:46 -08001192 if (verbose > 1)
1193 {
1194 s = format (s, "\n");
1195 }
1196 }
1197 return s;
1198}
1199
Florin Coras653e43f2019-03-04 10:56:23 -08001200static u8 *
Florin Coras2b81e3c2019-02-27 07:55:46 -08001201format_ct_session (u8 * s, va_list * args)
1202{
1203 u32 ct_index = va_arg (*args, u32);
Florin Coras2d0e3de2020-10-23 16:31:40 -07001204 u32 thread_index = va_arg (*args, u32);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001205 u32 verbose = va_arg (*args, u32);
1206 ct_connection_t *ct;
1207
Florin Coras2d0e3de2020-10-23 16:31:40 -07001208 ct = ct_connection_get (ct_index, thread_index);
Florin Coras2b81e3c2019-02-27 07:55:46 -08001209 if (!ct)
1210 {
1211 s = format (s, "empty\n");
1212 return s;
1213 }
1214
1215 s = format (s, "%U", format_ct_connection, ct, verbose);
1216 return s;
1217}
1218
Florin Coras2d0e3de2020-10-23 16:31:40 -07001219clib_error_t *
1220ct_enable_disable (vlib_main_t * vm, u8 is_en)
1221{
Florin Coras7fe00692021-11-15 14:01:02 -08001222 vlib_thread_main_t *vtm = &vlib_thread_main;
Florin Coras374df7a2021-05-13 11:37:43 -07001223 ct_main_t *cm = &ct_main;
1224
1225 cm->n_workers = vlib_num_workers ();
Florin Coras7fe00692021-11-15 14:01:02 -08001226 vec_validate (cm->wrk, vtm->n_vlib_mains);
Florin Coras374df7a2021-05-13 11:37:43 -07001227 clib_spinlock_init (&cm->ho_reuseable_lock);
Florin Corasda78c5a2021-06-09 14:55:24 -07001228 clib_rwlock_init (&cm->app_segs_lock);
Florin Coras2d0e3de2020-10-23 16:31:40 -07001229 return 0;
1230}
1231
Florin Corasd4295e62019-02-22 13:11:38 -08001232/* *INDENT-OFF* */
Nathan Skrzypczake971bc92019-06-19 13:42:37 +02001233static const transport_proto_vft_t cut_thru_proto = {
Florin Coras2d0e3de2020-10-23 16:31:40 -07001234 .enable = ct_enable_disable,
Florin Corasd4295e62019-02-22 13:11:38 -08001235 .start_listen = ct_start_listen,
1236 .stop_listen = ct_stop_listen,
Florin Coras374df7a2021-05-13 11:37:43 -07001237 .get_connection = ct_session_get,
Florin Corasd4295e62019-02-22 13:11:38 -08001238 .get_listener = ct_listener_get,
Florin Coras374df7a2021-05-13 11:37:43 -07001239 .get_half_open = ct_half_open_get,
1240 .cleanup = ct_session_cleanup,
1241 .cleanup_ho = ct_cleanup_ho,
Florin Coras2b81e3c2019-02-27 07:55:46 -08001242 .connect = ct_session_connect,
1243 .close = ct_session_close,
Florin Corasf940f8a2019-03-06 10:44:38 -08001244 .custom_tx = ct_custom_tx,
Florin Coras317b8e02019-04-17 09:57:46 -07001245 .app_rx_evt = ct_app_rx_evt,
Florin Corasd4295e62019-02-22 13:11:38 -08001246 .format_listener = format_ct_listener,
Florin Coras374df7a2021-05-13 11:37:43 -07001247 .format_half_open = format_ct_half_open,
Florin Coras2b81e3c2019-02-27 07:55:46 -08001248 .format_connection = format_ct_session,
Nathan Skrzypczake971bc92019-06-19 13:42:37 +02001249 .transport_options = {
Florin Coras07063b82020-03-13 04:44:51 +00001250 .name = "ct",
1251 .short_name = "C",
Nathan Skrzypczake971bc92019-06-19 13:42:37 +02001252 .tx_type = TRANSPORT_TX_INTERNAL,
Florin Coras374df7a2021-05-13 11:37:43 -07001253 .service_type = TRANSPORT_SERVICE_VC,
Nathan Skrzypczake971bc92019-06-19 13:42:37 +02001254 },
Florin Corasd4295e62019-02-22 13:11:38 -08001255};
1256/* *INDENT-ON* */
1257
Florin Coras653e43f2019-03-04 10:56:23 -08001258int
1259ct_session_tx (session_t * s)
1260{
1261 ct_connection_t *ct, *peer_ct;
1262 session_t *peer_s;
1263
1264 ct = (ct_connection_t *) session_get_transport (s);
Florin Coras2d0e3de2020-10-23 16:31:40 -07001265 peer_ct = ct_connection_get (ct->peer_index, ct->c_thread_index);
Florin Coras653e43f2019-03-04 10:56:23 -08001266 if (!peer_ct)
Florin Corasbcdc50d2020-08-25 19:07:02 -07001267 return 0;
Florin Coras2d0e3de2020-10-23 16:31:40 -07001268 peer_s = session_get (peer_ct->c_s_index, peer_ct->c_thread_index);
Florin Coras653e43f2019-03-04 10:56:23 -08001269 if (peer_s->session_state >= SESSION_STATE_TRANSPORT_CLOSING)
1270 return 0;
Florin Corasd6894562020-10-28 00:37:15 -07001271 return session_enqueue_notify (peer_s);
Florin Coras653e43f2019-03-04 10:56:23 -08001272}
1273
Florin Corasd4295e62019-02-22 13:11:38 -08001274static clib_error_t *
1275ct_transport_init (vlib_main_t * vm)
1276{
1277 transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
1278 FIB_PROTOCOL_IP4, ~0);
Florin Coras653e43f2019-03-04 10:56:23 -08001279 transport_register_protocol (TRANSPORT_PROTO_NONE, &cut_thru_proto,
1280 FIB_PROTOCOL_IP6, ~0);
Florin Corasd4295e62019-02-22 13:11:38 -08001281 return 0;
1282}
1283
1284VLIB_INIT_FUNCTION (ct_transport_init);
1285
Florin Corasba7d8f52019-02-22 13:11:38 -08001286/*
1287 * fd.io coding-style-patch-verification: ON
1288 *
1289 * Local Variables:
1290 * eval: (c-set-style "gnu")
1291 * End:
1292 */