sctp: add option to enable/disable 95/20395/3
authorFlorin Coras <fcoras@cisco.com>
Thu, 27 Jun 2019 17:32:27 +0000 (10:32 -0700)
committerJohn Lo <loj@cisco.com>
Thu, 27 Jun 2019 21:30:36 +0000 (21:30 +0000)
Type: feature

By default sctp is disabled to avoid wasting cycles.

Change-Id: I1e2f764c7168b5c15062efbe5895de93dcc2614e
Signed-off-by: Florin Coras <fcoras@cisco.com>
MAINTAINERS
src/vnet/sctp/sctp.c
src/vnet/sctp/sctp.h
test/test_sctp.py

index ad13219..a4051aa 100644 (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>
index e5d6cca..e27ddb6 100644 (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);
+    }
 
-  /* Session layer, and by implication SCTP, are disabled by default */
-  tm->is_enabled = 0;
+  sctp_transport_enable_disable (vm, is_en);
+  return 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;
+clib_error_t *
+sctp_init (vlib_main_t * vm)
+{
+  sctp_main_t *sm = vnet_get_sctp_main ();
 
-  /* 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);
+  /* Session layer, and by implication SCTP, are disabled by default */
+  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
  *
index 26e69eb..5cbe8d6 100644 (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;
index e1faa9a..59dcfd3 100644 (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