sctp: add option to enable/disable

Type: feature

By default sctp is disabled to avoid wasting cycles.

Change-Id: I1e2f764c7168b5c15062efbe5895de93dcc2614e
Signed-off-by: Florin Coras <fcoras@cisco.com>
This commit is contained in:
Florin Coras
2019-06-27 10:32:27 -07:00
committed by John Lo
parent 28fa8cbc6c
commit b4ca8b11e4
4 changed files with 85 additions and 22 deletions

View File

@ -432,6 +432,10 @@ M: Ole Troan <ot@cisco.com>
M: Paul Vinciguerra <pvinci@vinciconsulting.com>
F: src/vpp-api/python
VNET SCTP
I: sctp
F: src/vnet/sctp
THE REST
I: misc
C: Contact vpp-dev Mailing List <vpp-dev@fd.io>

View File

@ -899,7 +899,7 @@ sctp_main_enable (vlib_main_t * vm)
}
clib_error_t *
sctp_enable_disable (vlib_main_t * vm, u8 is_en)
sctp_transport_enable_disable (vlib_main_t * vm, u8 is_en)
{
if (is_en)
{
@ -942,7 +942,7 @@ sctp_update_time (f64 now, u8 thread_index)
/* *INDENT-OFF* */
static const transport_proto_vft_t sctp_proto = {
.enable = sctp_enable_disable,
.enable = sctp_transport_enable_disable,
.start_listen = sctp_session_bind,
.stop_listen = sctp_session_unbind,
.connect = sctp_session_open,
@ -966,32 +966,49 @@ static const transport_proto_vft_t sctp_proto = {
/* *INDENT-ON* */
clib_error_t *
sctp_init (vlib_main_t * vm)
sctp_enable_disable (vlib_main_t * vm, u8 is_en)
{
sctp_main_t *tm = vnet_get_sctp_main ();
sctp_main_t *sm = vnet_get_sctp_main ();
ip_main_t *im = &ip_main;
ip_protocol_info_t *pi;
vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "sctp4-established");
tm->sctp4_established_phase_node_index = node->index;
vlib_node_t *node;
node = vlib_get_node_by_name (vm, (u8 *) "sctp6-established");
tm->sctp6_established_phase_node_index = node->index;
if (!sm->is_init && is_en)
{
node = vlib_get_node_by_name (vm, (u8 *) "sctp4-established");
sm->sctp4_established_phase_node_index = node->index;
node = vlib_get_node_by_name (vm, (u8 *) "sctp6-established");
sm->sctp6_established_phase_node_index = node->index;
sm->is_init = 1;
/* Register with IP for header parsing */
pi = ip_get_protocol_info (im, IP_PROTOCOL_SCTP);
if (pi == 0)
return clib_error_return (0, "SCTP protocol info AWOL");
pi->format_header = format_sctp_header;
pi->unformat_pg_edit = unformat_pg_sctp_header;
/* Register as transport with session layer */
transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
FIB_PROTOCOL_IP4, sctp4_output_node.index);
transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
FIB_PROTOCOL_IP6, sctp6_output_node.index);
}
sctp_transport_enable_disable (vm, is_en);
return 0;
}
clib_error_t *
sctp_init (vlib_main_t * vm)
{
sctp_main_t *sm = vnet_get_sctp_main ();
/* Session layer, and by implication SCTP, are disabled by default */
tm->is_enabled = 0;
/* Register with IP for header parsing */
pi = ip_get_protocol_info (im, IP_PROTOCOL_SCTP);
if (pi == 0)
return clib_error_return (0, "SCTP protocol info AWOL");
pi->format_header = format_sctp_header;
pi->unformat_pg_edit = unformat_pg_sctp_header;
/* Register as transport with session layer */
transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
FIB_PROTOCOL_IP4, sctp4_output_node.index);
transport_register_protocol (TRANSPORT_PROTO_SCTP, &sctp_proto,
FIB_PROTOCOL_IP6, sctp6_output_node.index);
sm->is_enabled = 0;
sm->is_init = 0;
sctp_api_reference ();
@ -1023,6 +1040,46 @@ VLIB_CLI_COMMAND (show_tcp_punt_command, static) =
};
/* *INDENT-ON* */
static clib_error_t *
sctp_fn (vlib_main_t * vm, unformat_input_t * input,
vlib_cli_command_t * cmd_arg)
{
unformat_input_t _line_input, *line_input = &_line_input;
clib_error_t *error;
u8 is_en;
if (!unformat_user (input, unformat_line_input, line_input))
return clib_error_return (0, "expected enable | disable");
while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
{
if (unformat (line_input, "enable"))
is_en = 1;
else if (unformat (line_input, "disable"))
is_en = 0;
else
{
error = clib_error_return (0, "unknown input `%U'",
format_unformat_error, line_input);
unformat_free (line_input);
return error;
}
}
unformat_free (line_input);
return sctp_enable_disable (vm, is_en);
}
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_sctp_command, static) =
{
.path = "sctp",
.short_help = "sctp [enable | disable]",
.function = sctp_fn,
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*

View File

@ -510,6 +510,7 @@ typedef struct _sctp_main
/* Flag that indicates if stack is on or off */
u8 is_enabled;
u8 is_init;
/** Number of preallocated connections */
u32 preallocated_connections;

View File

@ -20,6 +20,7 @@ class TestSCTP(VppTestCase):
def setUp(self):
super(TestSCTP, self).setUp()
self.vapi.session_enable_disable(is_enabled=1)
self.vapi.cli("sctp enable")
self.create_loopback_interfaces(2)
table_id = 0