blob: 6e2dccc552ea9d6b2b0e313d4af7ab8742aace54 [file] [log] [blame]
Marco Varlese191a5942017-10-30 18:17:21 +01001/*
2 * Copyright (c) 2017 SUSE LLC.
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#include <vnet/sctp/sctp.h>
16#include <vnet/sctp/sctp_debug.h>
17
18sctp_main_t sctp_main;
19
20static u32
21sctp_connection_bind (u32 session_index, transport_endpoint_t * tep)
22{
23 sctp_main_t *tm = &sctp_main;
24 sctp_connection_t *listener;
25 void *iface_ip;
26
27 pool_get (tm->listener_pool, listener);
28 memset (listener, 0, sizeof (*listener));
29
Marco Varlesec7fe4f32018-03-05 15:12:29 +010030 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
31 SCTP_PRIMARY_PATH_IDX;
32 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index =
Marco Varlese191a5942017-10-30 18:17:21 +010033 listener - tm->listener_pool;
Marco Varlesec7fe4f32018-03-05 15:12:29 +010034 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.lcl_port = tep->port;
Marco Varlese191a5942017-10-30 18:17:21 +010035
36 /* If we are provided a sw_if_index, bind using one of its IPs */
37 if (ip_is_zero (&tep->ip, 1) && tep->sw_if_index != ENDPOINT_INVALID_INDEX)
38 {
39 if ((iface_ip = ip_interface_get_first_ip (tep->sw_if_index,
40 tep->is_ip4)))
41 ip_set (&tep->ip, iface_ip, tep->is_ip4);
42 }
Marco Varlesec7fe4f32018-03-05 15:12:29 +010043 ip_copy (&listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.lcl_ip,
Marco Varlese191a5942017-10-30 18:17:21 +010044 &tep->ip, tep->is_ip4);
45
Marco Varlesec7fe4f32018-03-05 15:12:29 +010046 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
Marco Varlesef3ab4892018-02-19 15:23:13 +010047 vnet_sw_interface_get_mtu (vnet_get_main (), tep->sw_if_index, VLIB_TX);
Marco Varlesec7fe4f32018-03-05 15:12:29 +010048 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.is_ip4 = tep->is_ip4;
49 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
Marco Varlese191a5942017-10-30 18:17:21 +010050 TRANSPORT_PROTO_SCTP;
Marco Varlesec7fe4f32018-03-05 15:12:29 +010051 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index = session_index;
52 listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
Marco Varlese191a5942017-10-30 18:17:21 +010053 tep->fib_index;
54 listener->state = SCTP_STATE_CLOSED;
55
56 sctp_connection_timers_init (listener);
57
Marco Varlesec7fe4f32018-03-05 15:12:29 +010058 return listener->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index;
Marco Varlese191a5942017-10-30 18:17:21 +010059}
60
61u32
62sctp_session_bind (u32 session_index, transport_endpoint_t * tep)
63{
64 return sctp_connection_bind (session_index, tep);
65}
66
67static void
68sctp_connection_unbind (u32 listener_index)
69{
70 sctp_main_t *tm = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +010071 sctp_connection_t *sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +010072
Marco Varlese8ad6a2d2018-01-26 16:50:01 +010073 sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index);
Marco Varlese191a5942017-10-30 18:17:21 +010074
75 /* Poison the entry */
76 if (CLIB_DEBUG > 0)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +010077 memset (sctp_conn, 0xFA, sizeof (*sctp_conn));
Marco Varlese191a5942017-10-30 18:17:21 +010078
79 pool_put_index (tm->listener_pool, listener_index);
80}
81
82u32
83sctp_session_unbind (u32 listener_index)
84{
85 sctp_connection_unbind (listener_index);
86 return 0;
87}
88
89void
90sctp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add)
91{
92 sctp_main_t *tm = &sctp_main;
93 if (is_ip4)
94 tm->punt_unknown4 = is_add;
95 else
96 tm->punt_unknown6 = is_add;
97}
98
99static int
100sctp_alloc_custom_local_endpoint (sctp_main_t * tm, ip46_address_t * lcl_addr,
101 u16 * lcl_port, u8 is_ip4)
102{
103 int index, port;
104 if (is_ip4)
105 {
106 index = tm->last_v4_address_rotor++;
107 if (tm->last_v4_address_rotor >= vec_len (tm->ip4_src_addresses))
108 tm->last_v4_address_rotor = 0;
109 lcl_addr->ip4.as_u32 = tm->ip4_src_addresses[index].as_u32;
110 }
111 else
112 {
113 index = tm->last_v6_address_rotor++;
114 if (tm->last_v6_address_rotor >= vec_len (tm->ip6_src_addresses))
115 tm->last_v6_address_rotor = 0;
116 clib_memcpy (&lcl_addr->ip6, &tm->ip6_src_addresses[index],
117 sizeof (ip6_address_t));
118 }
119 port = transport_alloc_local_port (TRANSPORT_PROTO_SCTP, lcl_addr);
120 if (port < 1)
121 {
122 clib_warning ("Failed to allocate src port");
123 return -1;
124 }
125 *lcl_port = port;
126 return 0;
127}
128
129/**
130 * Initialize all connection timers as invalid
131 */
132void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100133sctp_connection_timers_init (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100134{
135 int i, j;
136
137 /* Set all to invalid */
138 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100139 {
140 sctp_conn->sub_conn[i].RTO = SCTP_RTO_INIT;
Marco Varlese21c8baf2018-02-02 17:17:51 +0100141
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100142 for (j = 0; j < SCTP_N_TIMERS; j++)
143 {
144 sctp_conn->sub_conn[i].timers[j] = SCTP_TIMER_HANDLE_INVALID;
145 }
146 }
Marco Varlese191a5942017-10-30 18:17:21 +0100147}
148
149/**
150 * Stop all connection timers
151 */
152void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100153sctp_connection_timers_reset (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100154{
155 int i, j;
156 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
157 {
158 for (j = 0; j < SCTP_N_TIMERS; j++)
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100159 sctp_timer_reset (sctp_conn, i, j);
Marco Varlese191a5942017-10-30 18:17:21 +0100160 }
161}
162
163const char *sctp_fsm_states[] = {
164#define _(sym, str) str,
165 foreach_sctp_fsm_state
166#undef _
167};
168
169u8 *
170format_sctp_state (u8 * s, va_list * args)
171{
172 u32 state = va_arg (*args, u32);
173
174 if (state < SCTP_N_STATES)
175 s = format (s, "%s", sctp_fsm_states[state]);
176 else
177 s = format (s, "UNKNOWN (%d (0x%x))", state, state);
178 return s;
179}
180
181u8 *
182format_sctp_connection_id (u8 * s, va_list * args)
183{
Marco Varlesef3ab4892018-02-19 15:23:13 +0100184 sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *);
185 if (!sctp_conn)
186 return s;
187
188 u8 i;
189 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
190 {
191 if (sctp_conn->sub_conn[i].connection.is_ip4)
192 {
193 s = format (s, "%U[#%d][%s] %U:%d->%U:%d",
194 s,
195 sctp_conn->sub_conn[i].connection.thread_index,
196 "T",
197 format_ip4_address,
198 &sctp_conn->sub_conn[i].connection.lcl_ip.ip4,
199 clib_net_to_host_u16 (sctp_conn->sub_conn[i].
200 connection.lcl_port),
201 format_ip4_address,
202 &sctp_conn->sub_conn[i].connection.rmt_ip.ip4,
203 clib_net_to_host_u16 (sctp_conn->sub_conn[i].
204 connection.rmt_port));
205 }
206 else
207 {
208 s = format (s, "%U[#%d][%s] %U:%d->%U:%d",
209 s,
210 sctp_conn->sub_conn[i].connection.thread_index,
211 "T",
212 format_ip6_address,
213 &sctp_conn->sub_conn[i].connection.lcl_ip.ip6,
214 clib_net_to_host_u16 (sctp_conn->sub_conn[i].
215 connection.lcl_port),
216 format_ip6_address,
217 &sctp_conn->sub_conn[i].connection.rmt_ip.ip6,
218 clib_net_to_host_u16 (sctp_conn->sub_conn[i].
219 connection.rmt_port));
220 }
221 }
Marco Varlese191a5942017-10-30 18:17:21 +0100222 return s;
223}
224
225u8 *
226format_sctp_connection (u8 * s, va_list * args)
227{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100228 sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *);
Marco Varlese191a5942017-10-30 18:17:21 +0100229 u32 verbose = va_arg (*args, u32);
230
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100231 if (!sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100232 return s;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100233 s = format (s, "%-50U", format_sctp_connection_id, sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100234 if (verbose)
235 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100236 s = format (s, "%-15U", format_sctp_state, sctp_conn->state);
Marco Varlese191a5942017-10-30 18:17:21 +0100237 }
238
239 return s;
240}
241
242/**
243 * Initialize connection send variables.
244 */
245void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100246sctp_init_snd_vars (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100247{
248 u32 time_now;
Marco Varlese191a5942017-10-30 18:17:21 +0100249 /*
250 * We use the time to randomize iss and for setting up the initial
251 * timestamp. Make sure it's updated otherwise syn and ack in the
252 * handshake may make it look as if time has flown in the opposite
253 * direction for us.
254 */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100255
Marco Varlese191a5942017-10-30 18:17:21 +0100256 sctp_set_time_now (vlib_get_thread_index ());
257 time_now = sctp_time_now ();
258
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100259 sctp_conn->local_initial_tsn = random_u32 (&time_now);
Marco Varlesef3ab4892018-02-19 15:23:13 +0100260 sctp_conn->last_unacked_tsn = sctp_conn->local_initial_tsn;
261 sctp_conn->next_tsn = sctp_conn->local_initial_tsn + 1;
262
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100263 sctp_conn->remote_initial_tsn = 0x0;
264 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
Marco Varlese191a5942017-10-30 18:17:21 +0100265}
266
267always_inline sctp_connection_t *
268sctp_sub_connection_add (u8 thread_index)
269{
270 sctp_main_t *tm = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100271 sctp_connection_t *sctp_conn = tm->connections[thread_index];
Marco Varlese191a5942017-10-30 18:17:21 +0100272
Marco Varlese3c6a9762018-03-01 11:19:59 +0100273 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100274
Marco Varlese3c6a9762018-03-01 11:19:59 +0100275 ASSERT (subconn_idx < MAX_SCTP_CONNECTIONS);
276
277 sctp_conn->sub_conn[subconn_idx].connection.c_index =
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100278 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index;
Marco Varlese3c6a9762018-03-01 11:19:59 +0100279 sctp_conn->sub_conn[subconn_idx].connection.thread_index = thread_index;
280 sctp_conn->sub_conn[subconn_idx].subconn_idx = subconn_idx;
Marco Varlese191a5942017-10-30 18:17:21 +0100281
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100282 return sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100283}
284
Marco Varlese3c6a9762018-03-01 11:19:59 +0100285u8
286sctp_sub_connection_add_ip4 (vlib_main_t * vm,
287 ip4_address_t * lcl_addr,
288 ip4_address_t * rmt_addr)
Marco Varlese191a5942017-10-30 18:17:21 +0100289{
Marco Varlese3c6a9762018-03-01 11:19:59 +0100290 sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100291
Marco Varlese3c6a9762018-03-01 11:19:59 +0100292 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
293
294 if (subconn_idx == MAX_SCTP_CONNECTIONS)
295 return SCTP_ERROR_MAX_CONNECTIONS;
296
297 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip,
298 &lcl_addr, sizeof (lcl_addr));
299
300 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip,
301 &rmt_addr, sizeof (rmt_addr));
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100302
303 sctp_conn->forming_association_changed = 1;
Marco Varlese3c6a9762018-03-01 11:19:59 +0100304
305 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100306}
307
Marco Varlese3c6a9762018-03-01 11:19:59 +0100308u8
Marco Varlese465c0872018-03-01 14:01:46 +0100309sctp_sub_connection_del_ip4 (ip4_address_t * lcl_addr,
310 ip4_address_t * rmt_addr)
311{
312 sctp_main_t *sctp_main = vnet_get_sctp_main ();
313
314 u32 thread_idx = vlib_get_thread_index ();
315 u8 i;
316
317 ASSERT (thread_idx == 0);
318
319 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
320 {
321 sctp_connection_t *sctp_conn = sctp_main->connections[thread_idx];
322 sctp_sub_connection_t *sub_conn =
323 &sctp_main->connections[thread_idx]->sub_conn[i];
324 ip46_address_t *lcl_ip =
325 &sctp_main->connections[thread_idx]->sub_conn[i].connection.lcl_ip;
326 ip46_address_t *rmt_ip =
327 &sctp_main->connections[thread_idx]->sub_conn[i].connection.rmt_ip;
328
329 if (!sub_conn->connection.is_ip4)
330 continue;
331 if (lcl_ip->ip4.as_u32 == lcl_addr->as_u32 &&
332 rmt_ip->ip4.as_u32 == rmt_addr->as_u32)
333 {
334 sub_conn->state = SCTP_SUBCONN_STATE_DOWN;
335 sctp_conn->forming_association_changed = 1;
336 break;
337 }
338 }
339 return SCTP_ERROR_NONE;
340}
341
342u8
Marco Varlese3c6a9762018-03-01 11:19:59 +0100343sctp_sub_connection_add_ip6 (vlib_main_t * vm,
344 ip6_address_t * lcl_addr,
345 ip6_address_t * rmt_addr)
Marco Varlese191a5942017-10-30 18:17:21 +0100346{
Marco Varlese3c6a9762018-03-01 11:19:59 +0100347 sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100348
Marco Varlese3c6a9762018-03-01 11:19:59 +0100349 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
350
351 if (subconn_idx == MAX_SCTP_CONNECTIONS)
352 return SCTP_ERROR_MAX_CONNECTIONS;
353
354 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip,
355 &lcl_addr, sizeof (lcl_addr));
356
357 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip,
358 &rmt_addr, sizeof (rmt_addr));
Marco Varleseeacf3cf2018-02-26 14:52:25 +0100359
360 sctp_conn->forming_association_changed = 1;
Marco Varlese3c6a9762018-03-01 11:19:59 +0100361
362 return SCTP_ERROR_NONE;
Marco Varlese191a5942017-10-30 18:17:21 +0100363}
364
Marco Varlese465c0872018-03-01 14:01:46 +0100365u8
366sctp_sub_connection_del_ip6 (ip6_address_t * lcl_addr,
367 ip6_address_t * rmt_addr)
368{
369 sctp_main_t *sctp_main = vnet_get_sctp_main ();
370
371 u32 thread_idx = vlib_get_thread_index ();
372 u8 i;
373
374 ASSERT (thread_idx == 0);
375
376 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
377 {
378 sctp_connection_t *sctp_conn = sctp_main->connections[thread_idx];
379 sctp_sub_connection_t *sub_conn =
380 &sctp_main->connections[thread_idx]->sub_conn[i];
381 ip46_address_t *lcl_ip =
382 &sctp_main->connections[thread_idx]->sub_conn[i].connection.lcl_ip;
383 ip46_address_t *rmt_ip =
384 &sctp_main->connections[thread_idx]->sub_conn[i].connection.rmt_ip;
385
386 if (!sub_conn->connection.is_ip4)
387 continue;
388 if ((lcl_ip->ip6.as_u64[0] == lcl_addr->as_u64[0]
389 && lcl_ip->ip6.as_u64[1] == lcl_addr->as_u64[1])
390 && (rmt_ip->ip6.as_u64[0] == rmt_addr->as_u64[0]
391 && rmt_ip->ip6.as_u64[1] == rmt_addr->as_u64[1]))
392 {
393 sub_conn->state = SCTP_SUBCONN_STATE_DOWN;
394 sctp_conn->forming_association_changed = 1;
395 break;
396 }
397 }
398 return SCTP_ERROR_NONE;
399}
400
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100401u8
402sctp_configure (sctp_user_configuration_t config)
403{
404 sctp_main_t *sctp_main = vnet_get_sctp_main ();
405
406 u32 thread_idx = vlib_get_thread_index ();
407
408 sctp_main->connections[thread_idx]->conn_config.never_delay_sack =
409 config.never_delay_sack;
410 sctp_main->connections[thread_idx]->conn_config.never_bundle =
411 config.never_bundle;
412
413 return 0;
414}
415
Marco Varlese191a5942017-10-30 18:17:21 +0100416sctp_connection_t *
417sctp_connection_new (u8 thread_index)
418{
Marco Varlese15cc6a82018-02-21 12:39:52 +0100419 sctp_main_t *sctp_main = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100420 sctp_connection_t *sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100421
Marco Varlese15cc6a82018-02-21 12:39:52 +0100422 pool_get (sctp_main->connections[thread_index], sctp_conn);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100423 memset (sctp_conn, 0, sizeof (*sctp_conn));
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100424 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
425 SCTP_PRIMARY_PATH_IDX;
426 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index =
Marco Varlese15cc6a82018-02-21 12:39:52 +0100427 sctp_conn - sctp_main->connections[thread_index];
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100428 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_thread_index = thread_index;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100429 sctp_conn->local_tag = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100430
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100431 return sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100432}
433
434sctp_connection_t *
435sctp_half_open_connection_new (u8 thread_index)
436{
437 sctp_main_t *tm = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100438 sctp_connection_t *sctp_conn = 0;
Marco Varlese191a5942017-10-30 18:17:21 +0100439 ASSERT (vlib_get_thread_index () == 0);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100440 pool_get (tm->half_open_connections, sctp_conn);
441 memset (sctp_conn, 0, sizeof (*sctp_conn));
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100442 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_c_index =
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100443 sctp_conn - tm->half_open_connections;
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100444 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
445 SCTP_PRIMARY_PATH_IDX;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100446 return sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100447}
448
449static inline int
450sctp_connection_open (transport_endpoint_t * rmt)
451{
452 sctp_main_t *tm = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100453 sctp_connection_t *sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100454 ip46_address_t lcl_addr;
455 u16 lcl_port;
456 uword thread_id;
457 int rv;
458
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100459 u8 idx = SCTP_PRIMARY_PATH_IDX;
Marco Varlese191a5942017-10-30 18:17:21 +0100460
461 /*
462 * Allocate local endpoint
463 */
464 if ((rmt->is_ip4 && vec_len (tm->ip4_src_addresses))
465 || (!rmt->is_ip4 && vec_len (tm->ip6_src_addresses)))
466 rv = sctp_alloc_custom_local_endpoint (tm, &lcl_addr, &lcl_port,
467 rmt->is_ip4);
468 else
469 rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_SCTP,
470 rmt, &lcl_addr, &lcl_port);
471
472 if (rv)
473 return -1;
474
475 /*
476 * Create connection and send INIT CHUNK
477 */
478 thread_id = vlib_get_thread_index ();
479 ASSERT (thread_id == 0);
480
481 clib_spinlock_lock_if_init (&tm->half_open_lock);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100482 sctp_conn = sctp_half_open_connection_new (thread_id);
Marco Varlesef3ab4892018-02-19 15:23:13 +0100483 sctp_conn->sub_conn[idx].PMTU =
484 vnet_sw_interface_get_mtu (vnet_get_main (), rmt->sw_if_index, VLIB_TX);
Marco Varlese191a5942017-10-30 18:17:21 +0100485
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100486 transport_connection_t *trans_conn = &sctp_conn->sub_conn[idx].connection;
487 ip_copy (&trans_conn->rmt_ip, &rmt->ip, rmt->is_ip4);
488 ip_copy (&trans_conn->lcl_ip, &lcl_addr, rmt->is_ip4);
Marco Varlese04e5d642018-02-23 17:43:06 +0100489 sctp_conn->sub_conn[idx].subconn_idx = idx;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100490 trans_conn->rmt_port = rmt->port;
491 trans_conn->lcl_port = clib_host_to_net_u16 (lcl_port);
492 trans_conn->is_ip4 = rmt->is_ip4;
493 trans_conn->proto = TRANSPORT_PROTO_SCTP;
494 trans_conn->fib_index = rmt->fib_index;
Marco Varlese191a5942017-10-30 18:17:21 +0100495
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100496 sctp_connection_timers_init (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100497 /* The other connection vars will be initialized after INIT_ACK chunk received */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100498 sctp_init_snd_vars (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100499
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100500 sctp_send_init (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100501
502 clib_spinlock_unlock_if_init (&tm->half_open_lock);
503
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100504 return sctp_conn->sub_conn[idx].connection.c_index;
Marco Varlese191a5942017-10-30 18:17:21 +0100505}
506
507/**
508 * Cleans up connection state.
509 *
510 * No notifications.
511 */
512void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100513sctp_connection_cleanup (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100514{
515 sctp_main_t *tm = &sctp_main;
516 u8 i;
517
518 /* Cleanup local endpoint if this was an active connect */
519 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
520 transport_endpoint_cleanup (TRANSPORT_PROTO_SCTP,
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100521 &sctp_conn->sub_conn[i].connection.lcl_ip,
522 sctp_conn->sub_conn[i].connection.lcl_port);
Marco Varlese191a5942017-10-30 18:17:21 +0100523
Marco Varlese200fa322018-02-26 16:33:54 +0100524 int thread_index =
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100525 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.thread_index;
Marco Varlese191a5942017-10-30 18:17:21 +0100526
Marco Varlese200fa322018-02-26 16:33:54 +0100527 /* Make sure all timers are cleared */
528 sctp_connection_timers_reset (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100529
Marco Varlese200fa322018-02-26 16:33:54 +0100530 /* Poison the entry */
531 if (CLIB_DEBUG > 0)
532 memset (sctp_conn, 0xFA, sizeof (*sctp_conn));
533 pool_put (tm->connections[thread_index], sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100534}
535
536int
537sctp_session_open (transport_endpoint_t * tep)
538{
539 return sctp_connection_open (tep);
540}
541
542u16
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100543sctp_check_outstanding_data_chunks (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100544{
Marco Varlese54432f82018-02-15 17:01:56 +0100545 u8 i;
546 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
547 {
548 if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN)
549 continue;
550
551 if (sctp_conn->sub_conn[i].is_retransmitting == 1 ||
552 sctp_conn->sub_conn[i].enqueue_state != SCTP_ERROR_ENQUEUED)
553 {
554 SCTP_DBG_OUTPUT
Marco Varlesef3ab4892018-02-19 15:23:13 +0100555 ("Connection %u has still DATA to be enqueued inboud / outboud",
556 sctp_conn->sub_conn[i].connection.c_index);
Marco Varlese54432f82018-02-15 17:01:56 +0100557 return 1;
558 }
559
560 }
Marco Varlese191a5942017-10-30 18:17:21 +0100561 return 0; /* Indicates no more data to be read/sent */
562}
563
564void
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100565sctp_connection_close (sctp_connection_t * sctp_conn)
Marco Varlese191a5942017-10-30 18:17:21 +0100566{
567 SCTP_DBG ("Closing connection %u...",
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100568 sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100569
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100570 sctp_conn->state = SCTP_STATE_SHUTDOWN_PENDING;
Marco Varlese191a5942017-10-30 18:17:21 +0100571
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100572 sctp_send_shutdown (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100573}
574
575void
576sctp_session_close (u32 conn_index, u32 thread_index)
577{
578 ASSERT (thread_index == 0);
Marco Varlesef3ab4892018-02-19 15:23:13 +0100579
Marco Varlese15cc6a82018-02-21 12:39:52 +0100580 sctp_connection_t *sctp_conn =
581 sctp_connection_get (conn_index, thread_index);
Marco Varlesea38783e2018-02-13 12:38:52 +0100582 if (sctp_conn != NULL)
583 sctp_connection_close (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100584}
585
586void
587sctp_session_cleanup (u32 conn_index, u32 thread_index)
588{
Marco Varlese15cc6a82018-02-21 12:39:52 +0100589 sctp_connection_t *sctp_conn =
590 sctp_connection_get (conn_index, thread_index);
Marco Varlese191a5942017-10-30 18:17:21 +0100591
Marco Varlesea38783e2018-02-13 12:38:52 +0100592 if (sctp_conn != NULL)
593 {
594 sctp_connection_timers_reset (sctp_conn);
595 /* Wait for the session tx events to clear */
596 sctp_conn->state = SCTP_STATE_CLOSED;
597 }
Marco Varlese191a5942017-10-30 18:17:21 +0100598}
599
600/**
Marco Varlesef3ab4892018-02-19 15:23:13 +0100601 * Compute maximum segment size for session layer.
Marco Varlese191a5942017-10-30 18:17:21 +0100602 */
Marco Varlese191a5942017-10-30 18:17:21 +0100603u16
604sctp_session_send_mss (transport_connection_t * trans_conn)
605{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100606 sctp_connection_t *sctp_conn =
607 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100608
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100609 if (sctp_conn == NULL)
Marco Varlese191a5942017-10-30 18:17:21 +0100610 {
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100611 SCTP_DBG ("sctp_conn == NULL");
Marco Varlese191a5942017-10-30 18:17:21 +0100612 return 0;
613 }
Marco Varlese191a5942017-10-30 18:17:21 +0100614
Marco Varlesef3ab4892018-02-19 15:23:13 +0100615 update_cwnd (sctp_conn);
616 update_smallest_pmtu_idx (sctp_conn);
617
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100618 u8 idx = sctp_data_subconn_select (sctp_conn);
619
620 return sctp_conn->sub_conn[idx].cwnd;
Marco Varlese191a5942017-10-30 18:17:21 +0100621}
622
623u16
624sctp_snd_space (sctp_connection_t * sctp_conn)
625{
Marco Varlese6e4d4a32018-03-12 12:36:59 +0100626 /* RFC 4096 Section 6.1; point (A) */
627 if (sctp_conn->peer_rwnd == 0)
628 return 0;
629
630 u8 idx = sctp_data_subconn_select (sctp_conn);
Marco Varlese3e9b4652018-03-13 15:44:56 +0100631
632 u32 available_wnd =
633 clib_min (sctp_conn->peer_rwnd, sctp_conn->sub_conn[idx].cwnd);
634 int flight_size = (int) (sctp_conn->next_tsn - sctp_conn->last_unacked_tsn);
635
636 if (available_wnd <= flight_size)
637 return 0;
638
Marco Varlesef3ab4892018-02-19 15:23:13 +0100639 /* Finally, let's subtract the DATA chunk headers overhead */
Marco Varlese3e9b4652018-03-13 15:44:56 +0100640 return available_wnd -
641 flight_size -
Marco Varlesef3ab4892018-02-19 15:23:13 +0100642 sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_full_hdr_t);
Marco Varlese191a5942017-10-30 18:17:21 +0100643}
644
Marco Varlesef3ab4892018-02-19 15:23:13 +0100645/**
646 * Compute TX window session is allowed to fill.
647 */
Marco Varlese191a5942017-10-30 18:17:21 +0100648u32
649sctp_session_send_space (transport_connection_t * trans_conn)
650{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100651 sctp_connection_t *sctp_conn =
652 sctp_get_connection_from_transport (trans_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100653
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100654 return sctp_snd_space (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100655}
656
657transport_connection_t *
658sctp_session_get_transport (u32 conn_index, u32 thread_index)
659{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100660 sctp_connection_t *sctp_conn =
661 sctp_connection_get (conn_index, thread_index);
Marco Varlese2802bd72018-02-15 13:45:39 +0100662
663 if (PREDICT_TRUE (sctp_conn != NULL))
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100664 return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection;
Marco Varlese2802bd72018-02-15 13:45:39 +0100665
666 return NULL;
Marco Varlese191a5942017-10-30 18:17:21 +0100667}
668
669transport_connection_t *
670sctp_session_get_listener (u32 listener_index)
671{
672 sctp_main_t *tm = vnet_get_sctp_main ();
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100673 sctp_connection_t *sctp_conn;
674 sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100675 return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection;
Marco Varlese191a5942017-10-30 18:17:21 +0100676}
677
678u8 *
679format_sctp_session (u8 * s, va_list * args)
680{
Marco Varlesef3ab4892018-02-19 15:23:13 +0100681 u32 tci = va_arg (*args, u32);
682 u32 thread_index = va_arg (*args, u32);
683 u32 verbose = va_arg (*args, u32);
684 sctp_connection_t *tc;
685
686 tc = sctp_connection_get (tci, thread_index);
687 if (tc)
688 s = format (s, "%U", format_sctp_connection, tc, verbose);
689 else
690 s = format (s, "empty\n");
691 return s;
Marco Varlese191a5942017-10-30 18:17:21 +0100692}
693
694u8 *
695format_sctp_listener_session (u8 * s, va_list * args)
696{
Marco Varlesef3ab4892018-02-19 15:23:13 +0100697 u32 tci = va_arg (*args, u32);
698 sctp_connection_t *tc = sctp_listener_get (tci);
699 return format (s, "%U", format_sctp_connection_id, tc);
Marco Varlese191a5942017-10-30 18:17:21 +0100700}
701
702void
Marco Varlesef47276f2018-02-06 09:01:39 +0100703sctp_expired_timers_cb (u32 conn_index, u32 timer_id)
Marco Varlese191a5942017-10-30 18:17:21 +0100704{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100705 sctp_connection_t *sctp_conn;
Marco Varlese191a5942017-10-30 18:17:21 +0100706
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100707 sctp_conn = sctp_connection_get (conn_index, vlib_get_thread_index ());
Marco Varlese191a5942017-10-30 18:17:21 +0100708 /* note: the connection may have already disappeared */
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100709 if (PREDICT_FALSE (sctp_conn == 0))
Marco Varlese191a5942017-10-30 18:17:21 +0100710 return;
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100711
712 SCTP_DBG ("%s expired", sctp_timer_to_string (timer_id));
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100713
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100714 if (sctp_conn->sub_conn[conn_index].unacknowledged_hb >
Marco Varlese54432f82018-02-15 17:01:56 +0100715 SCTP_PATH_MAX_RETRANS)
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100716 {
717 // The remote-peer is considered to be unreachable hence shutting down
Marco Varlese54432f82018-02-15 17:01:56 +0100718 u8 i, total_subs_down = 1;
719 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
720 {
721 if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN)
722 continue;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100723
Marco Varlese54432f82018-02-15 17:01:56 +0100724 u32 now = sctp_time_now ();
725 if (now > (sctp_conn->sub_conn[i].last_seen + SCTP_HB_INTERVAL))
726 {
727 total_subs_down += 1;
728 sctp_conn->sub_conn[i].state = SCTP_SUBCONN_STATE_DOWN;
729 }
730 }
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100731
Marco Varlese54432f82018-02-15 17:01:56 +0100732 if (total_subs_down == MAX_SCTP_CONNECTIONS)
733 {
734 /* Start cleanup. App wasn't notified yet so use delete notify as
735 * opposed to delete to cleanup session layer state. */
736 stream_session_delete_notify (&sctp_conn->sub_conn
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100737 [SCTP_PRIMARY_PATH_IDX].connection);
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100738
Marco Varlese54432f82018-02-15 17:01:56 +0100739 sctp_connection_timers_reset (sctp_conn);
740
741 sctp_connection_cleanup (sctp_conn);
742 }
Marco Varlese9e09ff32018-03-05 12:31:45 +0100743 return;
744 }
745
746 switch (timer_id)
747 {
748 case SCTP_TIMER_T1_INIT:
749 sctp_send_init (sctp_conn);
750 break;
751 case SCTP_TIMER_T1_COOKIE:
752 sctp_send_cookie_echo (sctp_conn);
753 break;
754 case SCTP_TIMER_T2_SHUTDOWN:
755 sctp_send_shutdown (sctp_conn);
756 break;
757 case SCTP_TIMER_T3_RXTX:
758 sctp_timer_reset (sctp_conn, conn_index, timer_id);
Marco Varlese3e9b4652018-03-13 15:44:56 +0100759 sctp_conn->flags |= SCTP_CONN_RECOVERY;
Marco Varlese9e09ff32018-03-05 12:31:45 +0100760 sctp_data_retransmit (sctp_conn);
761 break;
762 case SCTP_TIMER_T4_HEARTBEAT:
763 sctp_timer_reset (sctp_conn, conn_index, timer_id);
764 goto heartbeat;
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100765 }
766 return;
767
768heartbeat:
769 sctp_send_heartbeat (sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100770}
771
Marco Varlese191a5942017-10-30 18:17:21 +0100772static void
773sctp_expired_timers_dispatch (u32 * expired_timers)
774{
775 int i;
776 u32 connection_index, timer_id;
777
778 for (i = 0; i < vec_len (expired_timers); i++)
779 {
780 /* Get session index and timer id */
781 connection_index = expired_timers[i] & 0x0FFFFFFF;
782 timer_id = expired_timers[i] >> 28;
783
Marco Varlesef47276f2018-02-06 09:01:39 +0100784 SCTP_DBG ("Expired timer ID: %u", timer_id);
785
Marco Varlese191a5942017-10-30 18:17:21 +0100786 /* Handle expiration */
Marco Varlesedf5a99c2018-02-06 13:48:30 +0100787 sctp_expired_timers_cb (connection_index, timer_id);
Marco Varlese191a5942017-10-30 18:17:21 +0100788 }
789}
790
791void
792sctp_initialize_timer_wheels (sctp_main_t * tm)
793{
794 tw_timer_wheel_16t_2w_512sl_t *tw;
795 /* *INDENT-OFF* */
796 foreach_vlib_main (({
797 tw = &tm->timer_wheels[ii];
798 tw_timer_wheel_init_16t_2w_512sl (tw, sctp_expired_timers_dispatch,
799 100e-3 /* timer period 100ms */ , ~0);
800 tw->last_run_time = vlib_time_now (this_vlib_main);
801 }));
802 /* *INDENT-ON* */
803}
804
805clib_error_t *
806sctp_main_enable (vlib_main_t * vm)
807{
808 sctp_main_t *tm = vnet_get_sctp_main ();
809 vlib_thread_main_t *vtm = vlib_get_thread_main ();
810 clib_error_t *error = 0;
811 u32 num_threads;
812 int thread;
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100813 sctp_connection_t *sctp_conn __attribute__ ((unused));
Marco Varlese191a5942017-10-30 18:17:21 +0100814 u32 preallocated_connections_per_thread;
815
816 if ((error = vlib_call_init_function (vm, ip_main_init)))
817 return error;
818 if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
819 return error;
820 if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
821 return error;
822
823 /*
824 * Registrations
825 */
826
827 ip4_register_protocol (IP_PROTOCOL_SCTP, sctp4_input_node.index);
828 ip6_register_protocol (IP_PROTOCOL_SCTP, sctp6_input_node.index);
829
830 /*
831 * Initialize data structures
832 */
833
834 num_threads = 1 /* main thread */ + vtm->n_threads;
835 vec_validate (tm->connections, num_threads - 1);
836
837 /*
838 * Preallocate connections. Assume that thread 0 won't
839 * use preallocated threads when running multi-core
840 */
841 if (num_threads == 1)
842 {
843 thread = 0;
844 preallocated_connections_per_thread = tm->preallocated_connections;
845 }
846 else
847 {
848 thread = 1;
849 preallocated_connections_per_thread =
850 tm->preallocated_connections / (num_threads - 1);
851 }
852 for (; thread < num_threads; thread++)
853 {
854 if (preallocated_connections_per_thread)
855 pool_init_fixed (tm->connections[thread],
856 preallocated_connections_per_thread);
857 }
858
859 /* Initialize per worker thread tx buffers (used for control messages) */
860 vec_validate (tm->tx_buffers, num_threads - 1);
861
862 /* Initialize timer wheels */
863 vec_validate (tm->timer_wheels, num_threads - 1);
864 sctp_initialize_timer_wheels (tm);
865
866 /* Initialize clocks per tick for SCTP timestamp. Used to compute
867 * monotonically increasing timestamps. */
868 tm->tstamp_ticks_per_clock = vm->clib_time.seconds_per_clock
869 / SCTP_TSTAMP_RESOLUTION;
870
871 if (num_threads > 1)
872 {
Marco Varlesef47276f2018-02-06 09:01:39 +0100873 clib_spinlock_init (&tm->half_open_lock);
Marco Varlese191a5942017-10-30 18:17:21 +0100874 }
875
876 vec_validate (tm->tx_frames[0], num_threads - 1);
877 vec_validate (tm->tx_frames[1], num_threads - 1);
878 vec_validate (tm->ip_lookup_tx_frames[0], num_threads - 1);
879 vec_validate (tm->ip_lookup_tx_frames[1], num_threads - 1);
880
881 tm->bytes_per_buffer = vlib_buffer_free_list_buffer_size
882 (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
883
884 vec_validate (tm->time_now, num_threads - 1);
885 return error;
886}
887
888clib_error_t *
889sctp_enable_disable (vlib_main_t * vm, u8 is_en)
890{
891 if (is_en)
892 {
893 if (sctp_main.is_enabled)
894 return 0;
895
896 return sctp_main_enable (vm);
897 }
898 else
899 {
900 sctp_main.is_enabled = 0;
901 }
902
903 return 0;
904}
905
906transport_connection_t *
907sctp_half_open_session_get_transport (u32 conn_index)
908{
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100909 sctp_connection_t *sctp_conn = sctp_half_open_connection_get (conn_index);
Marco Varlesec7fe4f32018-03-05 15:12:29 +0100910 return &sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection;
Marco Varlese191a5942017-10-30 18:17:21 +0100911}
912
913u8 *
914format_sctp_half_open (u8 * s, va_list * args)
915{
916 u32 tci = va_arg (*args, u32);
Marco Varlese8ad6a2d2018-01-26 16:50:01 +0100917 sctp_connection_t *sctp_conn = sctp_half_open_connection_get (tci);
918 return format (s, "%U", format_sctp_connection_id, sctp_conn);
Marco Varlese191a5942017-10-30 18:17:21 +0100919}
920
Marco Varlese21c8baf2018-02-02 17:17:51 +0100921void
922sctp_update_time (f64 now, u8 thread_index)
923{
924 sctp_set_time_now (thread_index);
925 tw_timer_expire_timers_16t_2w_512sl (&sctp_main.timer_wheels[thread_index],
926 now);
927 sctp_flush_frames_to_output (thread_index);
928}
929
Marco Varlese191a5942017-10-30 18:17:21 +0100930/* *INDENT OFF* */
931const static transport_proto_vft_t sctp_proto = {
932 .enable = sctp_enable_disable,
933 .bind = sctp_session_bind,
934 .unbind = sctp_session_unbind,
935 .open = sctp_session_open,
936 .close = sctp_session_close,
937 .cleanup = sctp_session_cleanup,
938 .push_header = sctp_push_header,
939 .send_mss = sctp_session_send_mss,
940 .send_space = sctp_session_send_space,
Marco Varlese21c8baf2018-02-02 17:17:51 +0100941 .update_time = sctp_update_time,
Marco Varlese191a5942017-10-30 18:17:21 +0100942 .get_connection = sctp_session_get_transport,
943 .get_listener = sctp_session_get_listener,
944 .get_half_open = sctp_half_open_session_get_transport,
945 .format_connection = format_sctp_session,
946 .format_listener = format_sctp_listener_session,
947 .format_half_open = format_sctp_half_open,
Florin Coras371ca502018-02-21 12:07:41 -0800948 .tx_type = TRANSPORT_TX_DEQUEUE,
949 .service_type = TRANSPORT_SERVICE_VC,
Marco Varlese191a5942017-10-30 18:17:21 +0100950};
951
952/* *INDENT ON* */
953
954clib_error_t *
955sctp_init (vlib_main_t * vm)
956{
957 sctp_main_t *tm = vnet_get_sctp_main ();
958 ip_main_t *im = &ip_main;
959 ip_protocol_info_t *pi;
960 /* Session layer, and by implication SCTP, are disabled by default */
961 tm->is_enabled = 0;
962
963 /* Register with IP for header parsing */
964 pi = ip_get_protocol_info (im, IP_PROTOCOL_SCTP);
965 if (pi == 0)
966 return clib_error_return (0, "SCTP protocol info AWOL");
967 pi->format_header = format_sctp_header;
968 pi->unformat_pg_edit = unformat_pg_sctp_header;
969
970 /* Register as transport with session layer */
971 transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
972 FIB_PROTOCOL_IP4, sctp4_output_node.index);
973 transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
974 FIB_PROTOCOL_IP6, sctp6_output_node.index);
975
Marco Varlese3c6a9762018-03-01 11:19:59 +0100976 sctp_api_reference ();
977
Marco Varlese191a5942017-10-30 18:17:21 +0100978 return 0;
979}
980
981VLIB_INIT_FUNCTION (sctp_init);
982
983/*
984 * fd.io coding-style-patch-verification: ON
985 *
986 * Local Variables:
987 * eval: (c-set-style "gnu")
988 * End:
989 */