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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vnet/sctp/sctp.h>
16 #include <vnet/sctp/sctp_debug.h>
18 sctp_main_t sctp_main;
21 sctp_connection_bind (u32 session_index, transport_endpoint_t * tep)
23 sctp_main_t *tm = &sctp_main;
24 sctp_connection_t *listener;
27 pool_get (tm->listener_pool, listener);
28 memset (listener, 0, sizeof (*listener));
30 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
31 MAIN_SCTP_SUB_CONN_IDX;
32 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_c_index =
33 listener - tm->listener_pool;
34 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.lcl_port = tep->port;
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)
39 if ((iface_ip = ip_interface_get_first_ip (tep->sw_if_index,
41 ip_set (&tep->ip, iface_ip, tep->is_ip4);
43 ip_copy (&listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.lcl_ip,
44 &tep->ip, tep->is_ip4);
46 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU =
47 vnet_sw_interface_get_mtu (vnet_get_main (), tep->sw_if_index, VLIB_TX);
48 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.is_ip4 = tep->is_ip4;
49 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto =
51 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index = session_index;
52 listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.fib_index =
54 listener->state = SCTP_STATE_CLOSED;
56 sctp_connection_timers_init (listener);
58 return listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_c_index;
62 sctp_session_bind (u32 session_index, transport_endpoint_t * tep)
64 return sctp_connection_bind (session_index, tep);
68 sctp_connection_unbind (u32 listener_index)
70 sctp_main_t *tm = vnet_get_sctp_main ();
71 sctp_connection_t *sctp_conn;
73 sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index);
75 /* Poison the entry */
77 memset (sctp_conn, 0xFA, sizeof (*sctp_conn));
79 pool_put_index (tm->listener_pool, listener_index);
83 sctp_session_unbind (u32 listener_index)
85 sctp_connection_unbind (listener_index);
90 sctp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add)
92 sctp_main_t *tm = &sctp_main;
94 tm->punt_unknown4 = is_add;
96 tm->punt_unknown6 = is_add;
100 sctp_alloc_custom_local_endpoint (sctp_main_t * tm, ip46_address_t * lcl_addr,
101 u16 * lcl_port, u8 is_ip4)
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;
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));
119 port = transport_alloc_local_port (TRANSPORT_PROTO_SCTP, lcl_addr);
122 clib_warning ("Failed to allocate src port");
130 * Initialize all connection timers as invalid
133 sctp_connection_timers_init (sctp_connection_t * sctp_conn)
137 /* Set all to invalid */
138 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
140 sctp_conn->sub_conn[i].RTO = SCTP_RTO_INIT;
142 for (j = 0; j < SCTP_N_TIMERS; j++)
144 sctp_conn->sub_conn[i].timers[j] = SCTP_TIMER_HANDLE_INVALID;
150 * Stop all connection timers
153 sctp_connection_timers_reset (sctp_connection_t * sctp_conn)
156 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
158 for (j = 0; j < SCTP_N_TIMERS; j++)
159 sctp_timer_reset (sctp_conn, i, j);
163 const char *sctp_fsm_states[] = {
164 #define _(sym, str) str,
165 foreach_sctp_fsm_state
170 format_sctp_state (u8 * s, va_list * args)
172 u32 state = va_arg (*args, u32);
174 if (state < SCTP_N_STATES)
175 s = format (s, "%s", sctp_fsm_states[state]);
177 s = format (s, "UNKNOWN (%d (0x%x))", state, state);
182 format_sctp_connection_id (u8 * s, va_list * args)
184 sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *);
189 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
191 if (sctp_conn->sub_conn[i].connection.is_ip4)
193 s = format (s, "%U[#%d][%s] %U:%d->%U:%d",
195 sctp_conn->sub_conn[i].connection.thread_index,
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),
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));
208 s = format (s, "%U[#%d][%s] %U:%d->%U:%d",
210 sctp_conn->sub_conn[i].connection.thread_index,
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),
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));
226 format_sctp_connection (u8 * s, va_list * args)
228 sctp_connection_t *sctp_conn = va_arg (*args, sctp_connection_t *);
229 u32 verbose = va_arg (*args, u32);
233 s = format (s, "%-50U", format_sctp_connection_id, sctp_conn);
236 s = format (s, "%-15U", format_sctp_state, sctp_conn->state);
243 * Initialize connection send variables.
246 sctp_init_snd_vars (sctp_connection_t * sctp_conn)
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
256 sctp_set_time_now (vlib_get_thread_index ());
257 time_now = sctp_time_now ();
259 sctp_conn->local_initial_tsn = random_u32 (&time_now);
260 sctp_conn->last_unacked_tsn = sctp_conn->local_initial_tsn;
261 sctp_conn->next_tsn = sctp_conn->local_initial_tsn + 1;
263 sctp_conn->remote_initial_tsn = 0x0;
264 sctp_conn->last_rcvd_tsn = sctp_conn->remote_initial_tsn;
267 always_inline sctp_connection_t *
268 sctp_sub_connection_add (u8 thread_index)
270 sctp_main_t *tm = vnet_get_sctp_main ();
271 sctp_connection_t *sctp_conn = tm->connections[thread_index];
273 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
275 ASSERT (subconn_idx < MAX_SCTP_CONNECTIONS);
277 sctp_conn->sub_conn[subconn_idx].connection.c_index =
278 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.c_index;
279 sctp_conn->sub_conn[subconn_idx].connection.thread_index = thread_index;
280 sctp_conn->sub_conn[subconn_idx].subconn_idx = subconn_idx;
286 sctp_sub_connection_add_ip4 (vlib_main_t * vm,
287 ip4_address_t * lcl_addr,
288 ip4_address_t * rmt_addr)
290 sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index);
292 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
294 if (subconn_idx == MAX_SCTP_CONNECTIONS)
295 return SCTP_ERROR_MAX_CONNECTIONS;
297 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip,
298 &lcl_addr, sizeof (lcl_addr));
300 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip,
301 &rmt_addr, sizeof (rmt_addr));
303 sctp_conn->forming_association_changed = 1;
305 return SCTP_ERROR_NONE;
309 sctp_sub_connection_add_ip6 (vlib_main_t * vm,
310 ip6_address_t * lcl_addr,
311 ip6_address_t * rmt_addr)
313 sctp_connection_t *sctp_conn = sctp_sub_connection_add (vm->thread_index);
315 u8 subconn_idx = sctp_next_avail_subconn (sctp_conn);
317 if (subconn_idx == MAX_SCTP_CONNECTIONS)
318 return SCTP_ERROR_MAX_CONNECTIONS;
320 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.lcl_ip,
321 &lcl_addr, sizeof (lcl_addr));
323 clib_memcpy (&sctp_conn->sub_conn[subconn_idx].connection.rmt_ip,
324 &rmt_addr, sizeof (rmt_addr));
326 sctp_conn->forming_association_changed = 1;
328 return SCTP_ERROR_NONE;
332 sctp_connection_new (u8 thread_index)
334 sctp_main_t *sctp_main = vnet_get_sctp_main ();
335 sctp_connection_t *sctp_conn;
337 pool_get (sctp_main->connections[thread_index], sctp_conn);
338 memset (sctp_conn, 0, sizeof (*sctp_conn));
339 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
340 MAIN_SCTP_SUB_CONN_IDX;
341 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_c_index =
342 sctp_conn - sctp_main->connections[thread_index];
343 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_thread_index = thread_index;
344 sctp_conn->local_tag = 0;
350 sctp_half_open_connection_new (u8 thread_index)
352 sctp_main_t *tm = vnet_get_sctp_main ();
353 sctp_connection_t *sctp_conn = 0;
354 ASSERT (vlib_get_thread_index () == 0);
355 pool_get (tm->half_open_connections, sctp_conn);
356 memset (sctp_conn, 0, sizeof (*sctp_conn));
357 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_c_index =
358 sctp_conn - tm->half_open_connections;
359 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].subconn_idx =
360 MAIN_SCTP_SUB_CONN_IDX;
365 sctp_connection_open (transport_endpoint_t * rmt)
367 sctp_main_t *tm = vnet_get_sctp_main ();
368 sctp_connection_t *sctp_conn;
369 ip46_address_t lcl_addr;
374 u8 idx = MAIN_SCTP_SUB_CONN_IDX;
377 * Allocate local endpoint
379 if ((rmt->is_ip4 && vec_len (tm->ip4_src_addresses))
380 || (!rmt->is_ip4 && vec_len (tm->ip6_src_addresses)))
381 rv = sctp_alloc_custom_local_endpoint (tm, &lcl_addr, &lcl_port,
384 rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_SCTP,
385 rmt, &lcl_addr, &lcl_port);
391 * Create connection and send INIT CHUNK
393 thread_id = vlib_get_thread_index ();
394 ASSERT (thread_id == 0);
396 clib_spinlock_lock_if_init (&tm->half_open_lock);
397 sctp_conn = sctp_half_open_connection_new (thread_id);
398 sctp_conn->sub_conn[idx].PMTU =
399 vnet_sw_interface_get_mtu (vnet_get_main (), rmt->sw_if_index, VLIB_TX);
401 transport_connection_t *trans_conn = &sctp_conn->sub_conn[idx].connection;
402 ip_copy (&trans_conn->rmt_ip, &rmt->ip, rmt->is_ip4);
403 ip_copy (&trans_conn->lcl_ip, &lcl_addr, rmt->is_ip4);
404 sctp_conn->sub_conn[idx].subconn_idx = idx;
405 trans_conn->rmt_port = rmt->port;
406 trans_conn->lcl_port = clib_host_to_net_u16 (lcl_port);
407 trans_conn->is_ip4 = rmt->is_ip4;
408 trans_conn->proto = TRANSPORT_PROTO_SCTP;
409 trans_conn->fib_index = rmt->fib_index;
411 sctp_connection_timers_init (sctp_conn);
412 /* The other connection vars will be initialized after INIT_ACK chunk received */
413 sctp_init_snd_vars (sctp_conn);
415 sctp_send_init (sctp_conn);
417 clib_spinlock_unlock_if_init (&tm->half_open_lock);
419 return sctp_conn->sub_conn[idx].connection.c_index;
423 * Cleans up connection state.
428 sctp_connection_cleanup (sctp_connection_t * sctp_conn)
430 sctp_main_t *tm = &sctp_main;
433 /* Cleanup local endpoint if this was an active connect */
434 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
435 transport_endpoint_cleanup (TRANSPORT_PROTO_SCTP,
436 &sctp_conn->sub_conn[i].connection.lcl_ip,
437 sctp_conn->sub_conn[i].connection.lcl_port);
440 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.thread_index;
442 /* Make sure all timers are cleared */
443 sctp_connection_timers_reset (sctp_conn);
445 /* Poison the entry */
447 memset (sctp_conn, 0xFA, sizeof (*sctp_conn));
448 pool_put (tm->connections[thread_index], sctp_conn);
452 sctp_session_open (transport_endpoint_t * tep)
454 return sctp_connection_open (tep);
458 sctp_check_outstanding_data_chunks (sctp_connection_t * sctp_conn)
461 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
463 if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN)
466 if (sctp_conn->sub_conn[i].is_retransmitting == 1 ||
467 sctp_conn->sub_conn[i].enqueue_state != SCTP_ERROR_ENQUEUED)
470 ("Connection %u has still DATA to be enqueued inboud / outboud",
471 sctp_conn->sub_conn[i].connection.c_index);
476 return 0; /* Indicates no more data to be read/sent */
480 sctp_connection_close (sctp_connection_t * sctp_conn)
482 SCTP_DBG ("Closing connection %u...",
483 sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.c_index);
485 sctp_conn->state = SCTP_STATE_SHUTDOWN_PENDING;
487 sctp_send_shutdown (sctp_conn);
491 sctp_session_close (u32 conn_index, u32 thread_index)
493 ASSERT (thread_index == 0);
495 sctp_connection_t *sctp_conn =
496 sctp_connection_get (conn_index, thread_index);
497 if (sctp_conn != NULL)
498 sctp_connection_close (sctp_conn);
502 sctp_session_cleanup (u32 conn_index, u32 thread_index)
504 sctp_connection_t *sctp_conn =
505 sctp_connection_get (conn_index, thread_index);
507 if (sctp_conn != NULL)
509 sctp_connection_timers_reset (sctp_conn);
510 /* Wait for the session tx events to clear */
511 sctp_conn->state = SCTP_STATE_CLOSED;
516 * Compute maximum segment size for session layer.
519 sctp_session_send_mss (transport_connection_t * trans_conn)
521 sctp_connection_t *sctp_conn =
522 sctp_get_connection_from_transport (trans_conn);
524 if (sctp_conn == NULL)
526 SCTP_DBG ("sctp_conn == NULL");
530 update_cwnd (sctp_conn);
531 update_smallest_pmtu_idx (sctp_conn);
533 return sctp_conn->sub_conn[sctp_conn->smallest_PMTU_idx].cwnd;
537 sctp_snd_space (sctp_connection_t * sctp_conn)
539 /* Finally, let's subtract the DATA chunk headers overhead */
540 return sctp_conn->sub_conn[sctp_conn->smallest_PMTU_idx].cwnd -
541 sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_full_hdr_t);
545 * Compute TX window session is allowed to fill.
548 sctp_session_send_space (transport_connection_t * trans_conn)
550 sctp_connection_t *sctp_conn =
551 sctp_get_connection_from_transport (trans_conn);
553 return sctp_snd_space (sctp_conn);
556 transport_connection_t *
557 sctp_session_get_transport (u32 conn_index, u32 thread_index)
559 sctp_connection_t *sctp_conn =
560 sctp_connection_get (conn_index, thread_index);
562 if (PREDICT_TRUE (sctp_conn != NULL))
563 return &sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection;
568 transport_connection_t *
569 sctp_session_get_listener (u32 listener_index)
571 sctp_main_t *tm = vnet_get_sctp_main ();
572 sctp_connection_t *sctp_conn;
573 sctp_conn = pool_elt_at_index (tm->listener_pool, listener_index);
574 return &sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection;
578 format_sctp_session (u8 * s, va_list * args)
580 u32 tci = va_arg (*args, u32);
581 u32 thread_index = va_arg (*args, u32);
582 u32 verbose = va_arg (*args, u32);
583 sctp_connection_t *tc;
585 tc = sctp_connection_get (tci, thread_index);
587 s = format (s, "%U", format_sctp_connection, tc, verbose);
589 s = format (s, "empty\n");
594 format_sctp_listener_session (u8 * s, va_list * args)
596 u32 tci = va_arg (*args, u32);
597 sctp_connection_t *tc = sctp_listener_get (tci);
598 return format (s, "%U", format_sctp_connection_id, tc);
602 sctp_expired_timers_cb (u32 conn_index, u32 timer_id)
604 sctp_connection_t *sctp_conn;
606 sctp_conn = sctp_connection_get (conn_index, vlib_get_thread_index ());
607 /* note: the connection may have already disappeared */
608 if (PREDICT_FALSE (sctp_conn == 0))
611 SCTP_DBG ("%s expired", sctp_timer_to_string (timer_id));
615 case SCTP_TIMER_T1_INIT:
616 case SCTP_TIMER_T1_COOKIE:
617 case SCTP_TIMER_T2_SHUTDOWN:
618 case SCTP_TIMER_T3_RXTX:
619 sctp_timer_reset (sctp_conn, conn_index, timer_id);
621 case SCTP_TIMER_T4_HEARTBEAT:
622 sctp_timer_reset (sctp_conn, conn_index, timer_id);
626 if (sctp_conn->sub_conn[conn_index].unacknowledged_hb >
627 SCTP_PATH_MAX_RETRANS)
629 // The remote-peer is considered to be unreachable hence shutting down
630 u8 i, total_subs_down = 1;
631 for (i = 0; i < MAX_SCTP_CONNECTIONS; i++)
633 if (sctp_conn->sub_conn[i].state == SCTP_SUBCONN_STATE_DOWN)
636 u32 now = sctp_time_now ();
637 if (now > (sctp_conn->sub_conn[i].last_seen + SCTP_HB_INTERVAL))
639 total_subs_down += 1;
640 sctp_conn->sub_conn[i].state = SCTP_SUBCONN_STATE_DOWN;
644 if (total_subs_down == MAX_SCTP_CONNECTIONS)
646 /* Start cleanup. App wasn't notified yet so use delete notify as
647 * opposed to delete to cleanup session layer state. */
648 stream_session_delete_notify (&sctp_conn->sub_conn
649 [MAIN_SCTP_SUB_CONN_IDX].connection);
651 sctp_connection_timers_reset (sctp_conn);
653 sctp_connection_cleanup (sctp_conn);
659 sctp_send_heartbeat (sctp_conn);
663 sctp_expired_timers_dispatch (u32 * expired_timers)
666 u32 connection_index, timer_id;
668 for (i = 0; i < vec_len (expired_timers); i++)
670 /* Get session index and timer id */
671 connection_index = expired_timers[i] & 0x0FFFFFFF;
672 timer_id = expired_timers[i] >> 28;
674 SCTP_DBG ("Expired timer ID: %u", timer_id);
676 /* Handle expiration */
677 sctp_expired_timers_cb (connection_index, timer_id);
682 sctp_initialize_timer_wheels (sctp_main_t * tm)
684 tw_timer_wheel_16t_2w_512sl_t *tw;
686 foreach_vlib_main (({
687 tw = &tm->timer_wheels[ii];
688 tw_timer_wheel_init_16t_2w_512sl (tw, sctp_expired_timers_dispatch,
689 100e-3 /* timer period 100ms */ , ~0);
690 tw->last_run_time = vlib_time_now (this_vlib_main);
696 sctp_main_enable (vlib_main_t * vm)
698 sctp_main_t *tm = vnet_get_sctp_main ();
699 vlib_thread_main_t *vtm = vlib_get_thread_main ();
700 clib_error_t *error = 0;
703 sctp_connection_t *sctp_conn __attribute__ ((unused));
704 u32 preallocated_connections_per_thread;
706 if ((error = vlib_call_init_function (vm, ip_main_init)))
708 if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
710 if ((error = vlib_call_init_function (vm, ip6_lookup_init)))
717 ip4_register_protocol (IP_PROTOCOL_SCTP, sctp4_input_node.index);
718 ip6_register_protocol (IP_PROTOCOL_SCTP, sctp6_input_node.index);
721 * Initialize data structures
724 num_threads = 1 /* main thread */ + vtm->n_threads;
725 vec_validate (tm->connections, num_threads - 1);
728 * Preallocate connections. Assume that thread 0 won't
729 * use preallocated threads when running multi-core
731 if (num_threads == 1)
734 preallocated_connections_per_thread = tm->preallocated_connections;
739 preallocated_connections_per_thread =
740 tm->preallocated_connections / (num_threads - 1);
742 for (; thread < num_threads; thread++)
744 if (preallocated_connections_per_thread)
745 pool_init_fixed (tm->connections[thread],
746 preallocated_connections_per_thread);
749 /* Initialize per worker thread tx buffers (used for control messages) */
750 vec_validate (tm->tx_buffers, num_threads - 1);
752 /* Initialize timer wheels */
753 vec_validate (tm->timer_wheels, num_threads - 1);
754 sctp_initialize_timer_wheels (tm);
756 /* Initialize clocks per tick for SCTP timestamp. Used to compute
757 * monotonically increasing timestamps. */
758 tm->tstamp_ticks_per_clock = vm->clib_time.seconds_per_clock
759 / SCTP_TSTAMP_RESOLUTION;
763 clib_spinlock_init (&tm->half_open_lock);
766 vec_validate (tm->tx_frames[0], num_threads - 1);
767 vec_validate (tm->tx_frames[1], num_threads - 1);
768 vec_validate (tm->ip_lookup_tx_frames[0], num_threads - 1);
769 vec_validate (tm->ip_lookup_tx_frames[1], num_threads - 1);
771 tm->bytes_per_buffer = vlib_buffer_free_list_buffer_size
772 (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
774 vec_validate (tm->time_now, num_threads - 1);
779 sctp_enable_disable (vlib_main_t * vm, u8 is_en)
783 if (sctp_main.is_enabled)
786 return sctp_main_enable (vm);
790 sctp_main.is_enabled = 0;
796 transport_connection_t *
797 sctp_half_open_session_get_transport (u32 conn_index)
799 sctp_connection_t *sctp_conn = sctp_half_open_connection_get (conn_index);
800 return &sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection;
804 format_sctp_half_open (u8 * s, va_list * args)
806 u32 tci = va_arg (*args, u32);
807 sctp_connection_t *sctp_conn = sctp_half_open_connection_get (tci);
808 return format (s, "%U", format_sctp_connection_id, sctp_conn);
812 sctp_update_time (f64 now, u8 thread_index)
814 sctp_set_time_now (thread_index);
815 tw_timer_expire_timers_16t_2w_512sl (&sctp_main.timer_wheels[thread_index],
817 sctp_flush_frames_to_output (thread_index);
821 const static transport_proto_vft_t sctp_proto = {
822 .enable = sctp_enable_disable,
823 .bind = sctp_session_bind,
824 .unbind = sctp_session_unbind,
825 .open = sctp_session_open,
826 .close = sctp_session_close,
827 .cleanup = sctp_session_cleanup,
828 .push_header = sctp_push_header,
829 .send_mss = sctp_session_send_mss,
830 .send_space = sctp_session_send_space,
831 .update_time = sctp_update_time,
832 .get_connection = sctp_session_get_transport,
833 .get_listener = sctp_session_get_listener,
834 .get_half_open = sctp_half_open_session_get_transport,
835 .format_connection = format_sctp_session,
836 .format_listener = format_sctp_listener_session,
837 .format_half_open = format_sctp_half_open,
843 sctp_init (vlib_main_t * vm)
845 sctp_main_t *tm = vnet_get_sctp_main ();
846 ip_main_t *im = &ip_main;
847 ip_protocol_info_t *pi;
848 /* Session layer, and by implication SCTP, are disabled by default */
851 /* Register with IP for header parsing */
852 pi = ip_get_protocol_info (im, IP_PROTOCOL_SCTP);
854 return clib_error_return (0, "SCTP protocol info AWOL");
855 pi->format_header = format_sctp_header;
856 pi->unformat_pg_edit = unformat_pg_sctp_header;
858 /* Register as transport with session layer */
859 transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
860 FIB_PROTOCOL_IP4, sctp4_output_node.index);
861 transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
862 FIB_PROTOCOL_IP6, sctp6_output_node.index);
864 sctp_api_reference ();
869 VLIB_INIT_FUNCTION (sctp_init);
872 * fd.io coding-style-patch-verification: ON
875 * eval: (c-set-style "gnu")