tcp: timestamp adjustment
[vpp.git] / src / vnet / sctp / sctp_input.c
index 7d5e755..b102d51 100644 (file)
@@ -27,7 +27,8 @@ static char *sctp_error_strings[] = {
 
 /* All SCTP nodes have the same outgoing arcs */
 #define foreach_sctp_state_next                  \
-  _ (DROP, "error-drop")                        \
+  _ (DROP4, "ip4-drop")                         \
+  _ (DROP6, "ip6-drop")                         \
   _ (SCTP4_OUTPUT, "sctp4-output")                \
   _ (SCTP6_OUTPUT, "sctp6-output")
 
@@ -83,6 +84,7 @@ typedef enum _sctp_input_next
   SCTP_INPUT_N_NEXT
 } sctp_input_next_t;
 
+#ifndef CLIB_MARCH_VARIANT
 char *
 phase_to_string (u8 phase)
 {
@@ -103,6 +105,7 @@ phase_to_string (u8 phase)
     }
   return NULL;
 }
+#endif /* CLIB_MARCH_VARIANT */
 
 #define foreach_sctp4_input_next                 \
   _ (DROP, "error-drop")                         \
@@ -233,8 +236,10 @@ typedef struct
 #define sctp_next_output(is_ip4) (is_ip4 ? SCTP_NEXT_SCTP4_OUTPUT          \
                                         : SCTP_NEXT_SCTP6_OUTPUT)
 
+#define sctp_next_drop(is_ip4) (is_ip4 ? SCTP_NEXT_DROP4                  \
+                                      : SCTP_NEXT_DROP6)
 
-void
+static void
 sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
                        sctp_connection_t * sctp_conn,
                        sctp_header_t * sctp_hdr, vlib_buffer_t * b0,
@@ -242,15 +247,15 @@ sctp_set_rx_trace_data (sctp_rx_trace_t * rx_trace,
 {
   if (sctp_conn)
     {
-      clib_memcpy (&rx_trace->sctp_connection, sctp_conn,
-                  sizeof (rx_trace->sctp_connection));
+      clib_memcpy_fast (&rx_trace->sctp_connection, sctp_conn,
+                       sizeof (rx_trace->sctp_connection));
     }
   else
     {
       sctp_hdr = sctp_buffer_hdr (b0);
     }
-  clib_memcpy (&rx_trace->sctp_header, sctp_hdr,
-              sizeof (rx_trace->sctp_header));
+  clib_memcpy_fast (&rx_trace->sctp_header, sctp_hdr,
+                   sizeof (rx_trace->sctp_header));
 }
 
 always_inline u16
@@ -279,6 +284,36 @@ sctp_is_bundling (u16 sctp_implied_length,
   return 0;
 }
 
+always_inline u16
+sctp_handle_operation_err (sctp_header_t * sctp_hdr,
+                          sctp_connection_t * sctp_conn, u8 idx,
+                          vlib_buffer_t * b, u16 * next0)
+{
+  sctp_operation_error_t *op_err = (sctp_operation_error_t *) sctp_hdr;
+
+  /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
+  if (sctp_conn->local_tag != sctp_hdr->verification_tag)
+    {
+      return SCTP_ERROR_INVALID_TAG;
+    }
+
+  if (clib_net_to_host_u16 (op_err->err_causes[0].param_hdr.type) ==
+      STALE_COOKIE_ERROR)
+    {
+      if (sctp_conn->state != SCTP_STATE_COOKIE_ECHOED)
+       *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
+      else
+       {
+         sctp_connection_cleanup (sctp_conn);
+
+         session_transport_closing_notify (&sctp_conn->
+                                           sub_conn[idx].connection);
+       }
+    }
+
+  return SCTP_ERROR_NONE;
+}
+
 always_inline u16
 sctp_handle_init (sctp_header_t * sctp_hdr,
                  sctp_chunks_common_hdr_t * sctp_chunk_hdr,
@@ -286,8 +321,10 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
                  u16 sctp_implied_length)
 {
   sctp_init_chunk_t *init_chunk = (sctp_init_chunk_t *) (sctp_hdr);
-  ip4_address_t *ip4_addr = 0;
-  ip6_address_t *ip6_addr = 0;
+  ip4_address_t ip4_addr;
+  ip6_address_t ip6_addr;
+  u8 add_ip4 = 0;
+  u8 add_ip6 = 0;
   char hostname[FQDN_MAX_LENGTH];
 
   /* Check the current state of the connection
@@ -301,12 +338,25 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
     {                          /* UNEXPECTED scenario */
       switch (sctp_conn->state)
        {
-       case SCTP_STATE_COOKIE_WAIT:    /* TODO */
+       case SCTP_STATE_COOKIE_WAIT:
          SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
-         break;
-       case SCTP_STATE_COOKIE_ECHOED:  /* TODO */
+         sctp_prepare_initack_chunk_for_collision (sctp_conn,
+                                                   SCTP_PRIMARY_PATH_IDX,
+                                                   b0, &ip4_addr, &ip6_addr);
+         return SCTP_ERROR_NONE;
+       case SCTP_STATE_COOKIE_ECHOED:
+       case SCTP_STATE_SHUTDOWN_ACK_SENT:
          SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_ECHOED state");
-         break;
+         if (sctp_conn->forming_association_changed == 0)
+           sctp_prepare_initack_chunk_for_collision (sctp_conn,
+                                                     SCTP_PRIMARY_PATH_IDX,
+                                                     b0, &ip4_addr,
+                                                     &ip6_addr);
+         else
+           sctp_prepare_abort_for_collision (sctp_conn,
+                                             SCTP_PRIMARY_PATH_IDX, b0,
+                                             &ip4_addr, &ip6_addr);
+         return SCTP_ERROR_NONE;
        }
     }
 
@@ -329,8 +379,7 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
   SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
                          sctp_conn->remote_initial_tsn);
 
-  sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
-
+  sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_chunk->a_rwnd);
   /*
    * If the length specified in the INIT message is bigger than the size in bytes of our structure it means that
    * optional parameters have been sent with the INIT chunk and we need to parse them.
@@ -351,10 +400,16 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
              {
                sctp_ipv4_addr_param_t *ipv4 =
                  (sctp_ipv4_addr_param_t *) opt_params_hdr;
-               clib_memcpy (ip4_addr, &ipv4->address,
-                            sizeof (ip4_address_t));
+               clib_memcpy_fast (&ip4_addr, &ipv4->address,
+                                 sizeof (ip4_address_t));
 
-               sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
+               if (sctp_sub_connection_add_ip4 (vlib_get_main (),
+                                                &sctp_conn->sub_conn
+                                                [SCTP_PRIMARY_PATH_IDX].connection.
+                                                lcl_ip.ip4,
+                                                &ipv4->address) ==
+                   SCTP_ERROR_NONE)
+                 add_ip4 = 1;
 
                break;
              }
@@ -362,10 +417,16 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
              {
                sctp_ipv6_addr_param_t *ipv6 =
                  (sctp_ipv6_addr_param_t *) opt_params_hdr;
-               clib_memcpy (ip6_addr, &ipv6->address,
-                            sizeof (ip6_address_t));
+               clib_memcpy_fast (&ip6_addr, &ipv6->address,
+                                 sizeof (ip6_address_t));
 
-               sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
+               if (sctp_sub_connection_add_ip6 (vlib_get_main (),
+                                                &sctp_conn->sub_conn
+                                                [SCTP_PRIMARY_PATH_IDX].connection.
+                                                lcl_ip.ip6,
+                                                &ipv6->address) ==
+                   SCTP_ERROR_NONE)
+                 add_ip6 = 1;
 
                break;
              }
@@ -381,8 +442,8 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
              {
                sctp_hostname_param_t *hostname_addr =
                  (sctp_hostname_param_t *) opt_params_hdr;
-               clib_memcpy (hostname, hostname_addr->hostname,
-                            FQDN_MAX_LENGTH);
+               clib_memcpy_fast (hostname, hostname_addr->hostname,
+                                 FQDN_MAX_LENGTH);
                break;
              }
            case SCTP_SUPPORTED_ADDRESS_TYPES:
@@ -396,7 +457,8 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
     }
 
   /* Reuse buffer to make init-ack and send */
-  sctp_prepare_initack_chunk (sctp_conn, b0, ip4_addr, ip6_addr);
+  sctp_prepare_initack_chunk (sctp_conn, SCTP_PRIMARY_PATH_IDX, b0, &ip4_addr,
+                             add_ip4, &ip6_addr, add_ip6);
   return SCTP_ERROR_NONE;
 }
 
@@ -432,7 +494,6 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
 {
   sctp_init_ack_chunk_t *init_ack_chunk =
     (sctp_init_ack_chunk_t *) (sctp_hdr);
-  sctp_state_cookie_param_t state_cookie;
 
   char hostname[FQDN_MAX_LENGTH];
 
@@ -448,6 +509,9 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
   if (sctp_is_bundling (sctp_implied_length, &init_ack_chunk->chunk_hdr))
     return SCTP_ERROR_BUNDLING_VIOLATION;
 
+  /* Stop the T1_INIT timer */
+  sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_INIT);
+
   sctp_calculate_rto (sctp_conn, idx);
 
   /* remote_tag to be placed in the VERIFICATION_TAG field of the COOKIE_ECHO chunk */
@@ -458,7 +522,7 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
   sctp_conn->next_tsn_expected = sctp_conn->remote_initial_tsn + 1;
   SCTP_CONN_TRACKING_DBG ("sctp_conn->remote_initial_tsn = %u",
                          sctp_conn->remote_initial_tsn);
-  sctp_conn->snd_opts.a_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
+  sctp_conn->peer_rwnd = clib_net_to_host_u32 (init_ack_chunk->a_rwnd);
 
   u16 length = vnet_sctp_get_chunk_length (sctp_chunk_hdr);
 
@@ -482,7 +546,10 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
                sctp_ipv4_addr_param_t *ipv4 =
                  (sctp_ipv4_addr_param_t *) opt_params_hdr;
 
-               sctp_sub_connection_add_ip4 (vlib_get_thread_index (), ipv4);
+               sctp_sub_connection_add_ip4 (vlib_get_main (),
+                                            &sctp_conn->sub_conn
+                                            [SCTP_PRIMARY_PATH_IDX].connection.
+                                            lcl_ip.ip4, &ipv4->address);
 
                break;
              }
@@ -491,7 +558,10 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
                sctp_ipv6_addr_param_t *ipv6 =
                  (sctp_ipv6_addr_param_t *) opt_params_hdr;
 
-               sctp_sub_connection_add_ip6 (vlib_get_thread_index (), ipv6);
+               sctp_sub_connection_add_ip6 (vlib_get_main (),
+                                            &sctp_conn->sub_conn
+                                            [SCTP_PRIMARY_PATH_IDX].connection.
+                                            lcl_ip.ip6, &ipv6->address);
 
                break;
              }
@@ -500,16 +570,18 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
                sctp_state_cookie_param_t *state_cookie_param =
                  (sctp_state_cookie_param_t *) opt_params_hdr;
 
-               clib_memcpy (&state_cookie, state_cookie_param,
-                            sizeof (sctp_state_cookie_param_t));
+               clib_memcpy_fast (&(sctp_conn->cookie_param),
+                                 state_cookie_param,
+                                 sizeof (sctp_state_cookie_param_t));
+
                break;
              }
            case SCTP_HOSTNAME_ADDRESS_TYPE:
              {
                sctp_hostname_param_t *hostname_addr =
                  (sctp_hostname_param_t *) opt_params_hdr;
-               clib_memcpy (hostname, hostname_addr->hostname,
-                            FQDN_MAX_LENGTH);
+               clib_memcpy_fast (hostname, hostname_addr->hostname,
+                                 FQDN_MAX_LENGTH);
                break;
              }
            case SCTP_UNRECOGNIZED_TYPE:
@@ -527,10 +599,10 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
        }
     }
 
-  sctp_prepare_cookie_echo_chunk (sctp_conn, b0, &state_cookie);
+  sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
 
   /* Start the T1_COOKIE timer */
-  sctp_timer_set (sctp_conn, sctp_pick_conn_idx_on_chunk (COOKIE_ECHO),
+  sctp_timer_set (sctp_conn, idx,
                  SCTP_TIMER_T1_COOKIE, sctp_conn->sub_conn[idx].RTO);
 
   return SCTP_ERROR_NONE;
@@ -645,27 +717,40 @@ sctp_session_enqueue_data (sctp_connection_t * sctp_conn, vlib_buffer_t * b,
 }
 
 always_inline u8
-sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 gapping)
+sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
 {
-  if (gapping != 0)
+  if (sctp_conn->conn_config.never_delay_sack)
+    {
+      SCTP_CONN_TRACKING_DBG ("sctp_conn->conn_config.never_delay_sack = ON");
+      return 0;
+    }
+
+  /* Section 4.4 of the RFC4960 */
+  if (sctp_conn->state == SCTP_STATE_SHUTDOWN_SENT)
+    {
+      SCTP_CONN_TRACKING_DBG ("sctp_conn->state = %s; SACK not delayable",
+                             sctp_state_to_string (sctp_conn->state));
+      return 0;
+    }
+
+  if (is_gapping)
     {
       SCTP_CONN_TRACKING_DBG
        ("gapping != 0: CONN_INDEX = %u, sctp_conn->ack_state = %u",
         sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
-      return 1;
+      return 0;
     }
 
+  sctp_conn->ack_state += 1;
   if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
     {
       SCTP_CONN_TRACKING_DBG
        ("sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS: CONN_INDEX = %u, sctp_conn->ack_state = %u",
         sctp_conn->sub_conn[idx].connection.c_index, sctp_conn->ack_state);
-      return 1;
+      return 0;
     }
 
-  sctp_conn->ack_state += 1;
-
-  return 0;
+  return 1;
 }
 
 always_inline void
@@ -676,7 +761,7 @@ sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
     {
       SCTP_CONN_TRACKING_DBG
        ("GAPPING: CONN_INDEX = %u, sctp_conn->next_tsn_expected = %u, tsn = %u, diff = %u",
-        sctp_conn->sub_conn[idx].connection.c_index,
+        sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.c_index,
         sctp_conn->next_tsn_expected, tsn,
         sctp_conn->next_tsn_expected - tsn);
 
@@ -686,17 +771,18 @@ sctp_is_connection_gapping (sctp_connection_t * sctp_conn, u32 tsn,
 
 always_inline u16
 sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
-                 sctp_connection_t * sctp_conn, vlib_buffer_t * b,
+                 sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b,
                  u16 * next0)
 {
   u32 error = 0, n_data_bytes;
-  u8 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
   u8 is_gapping = 0;
 
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_data_chunk->sctp_hdr.verification_tag)
     {
-      return SCTP_ERROR_INVALID_TAG;
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
+      sctp_conn->sub_conn[idx].enqueue_state = SCTP_ERROR_INVALID_TAG;
+      return sctp_conn->sub_conn[idx].enqueue_state;
     }
 
   vnet_buffer (b)->sctp.sid = sctp_data_chunk->stream_id;
@@ -705,8 +791,27 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
   u32 tsn = clib_net_to_host_u32 (sctp_data_chunk->tsn);
 
   vlib_buffer_advance (b, vnet_buffer (b)->sctp.data_offset);
+  u32 chunk_len = vnet_sctp_get_chunk_length (&sctp_data_chunk->chunk_hdr) -
+    (sizeof (sctp_payload_data_chunk_t) - sizeof (sctp_header_t));
+
+  ASSERT (vnet_buffer (b)->sctp.data_len);
+  ASSERT (chunk_len);
+
+  /* Padding was added: see RFC 4096 section 3.3.1 */
+  if (vnet_buffer (b)->sctp.data_len > chunk_len)
+    {
+      /* Let's change the data_len to the right amount calculated here now.
+       * We cannot do that in the generic sctp46_input_dispatcher node since
+       * that is common to all CHUNKS handling.
+       */
+      vnet_buffer (b)->sctp.data_len = chunk_len;
+      /* We need to change b->current_length so that downstream calls to
+       * session_enqueue_stream_connection (called by sctp_session_enqueue_data)
+       * push the correct amount of data to be enqueued.
+       */
+      b->current_length = chunk_len;
+    }
   n_data_bytes = vnet_buffer (b)->sctp.data_len;
-  ASSERT (n_data_bytes);
 
   sctp_is_connection_gapping (sctp_conn, tsn, &is_gapping);
 
@@ -721,7 +826,11 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
     {
       /* In order data, enqueue. Fifo figures out by itself if any out-of-order
        * segments can be enqueued after fifo tail offset changes. */
-      error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
+      if (PREDICT_FALSE (is_gapping == 1))
+       error =
+         sctp_session_enqueue_data_ooo (sctp_conn, b, n_data_bytes, idx);
+      else
+       error = sctp_session_enqueue_data (sctp_conn, b, n_data_bytes, idx);
     }
   else if (bbit == 1 && ebit == 0)     /* First piece of a fragmented user message */
     {
@@ -745,12 +854,17 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
     }
   sctp_conn->last_rcvd_tsn = tsn;
 
-  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
-
   SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
 
-  if (sctp_is_sack_delayable (sctp_conn, is_gapping) != 0)
-    sctp_prepare_sack_chunk (sctp_conn, b);
+  if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
+    {
+      *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
+      sctp_prepare_sack_chunk (sctp_conn, idx, b);
+    }
+  else
+    *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
+
+  sctp_conn->sub_conn[idx].enqueue_state = error;
 
   return error;
 }
@@ -758,12 +872,10 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
 always_inline u16
 sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
                         sctp_chunks_common_hdr_t * sctp_chunk_hdr,
-                        sctp_connection_t * sctp_conn, vlib_buffer_t * b0)
+                        sctp_connection_t * sctp_conn, u8 idx,
+                        vlib_buffer_t * b0, u16 * next0)
 {
-  u32 now = sctp_time_now ();
-
-  /* Build TCB */
-  u8 idx = sctp_pick_conn_idx_on_chunk (COOKIE_ECHO);
+  u64 now = sctp_time_now ();
 
   sctp_cookie_echo_chunk_t *cookie_echo =
     (sctp_cookie_echo_chunk_t *) sctp_hdr;
@@ -771,15 +883,17 @@ sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hdr->verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
   sctp_calculate_rto (sctp_conn, idx);
 
-  u32 creation_time =
-    clib_net_to_host_u32 (cookie_echo->cookie.creation_time);
-  u32 cookie_lifespan =
+  u64 creation_time =
+    clib_net_to_host_u64 (cookie_echo->cookie.creation_time);
+  u64 cookie_lifespan =
     clib_net_to_host_u32 (cookie_echo->cookie.cookie_lifespan);
+
   if (now > creation_time + cookie_lifespan)
     {
       SCTP_DBG ("now (%u) > creation_time (%u) + cookie_lifespan (%u)",
@@ -787,15 +901,17 @@ sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
       return SCTP_ERROR_COOKIE_ECHO_VIOLATION;
     }
 
-  sctp_prepare_cookie_ack_chunk (sctp_conn, b0);
+  sctp_prepare_cookie_ack_chunk (sctp_conn, idx, b0);
 
   /* Change state */
   sctp_conn->state = SCTP_STATE_ESTABLISHED;
+  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
+  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
 
   sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
                  sctp_conn->sub_conn[idx].RTO);
 
-  stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
+  session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
 
   return SCTP_ERROR_NONE;
 
@@ -804,15 +920,13 @@ sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
 always_inline u16
 sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
                        sctp_chunks_common_hdr_t * sctp_chunk_hdr,
-                       sctp_connection_t * sctp_conn, vlib_buffer_t * b0)
+                       sctp_connection_t * sctp_conn, u8 idx,
+                       vlib_buffer_t * b0, u16 * next0)
 {
-
-  /* Stop T1_COOKIE timer */
-  u8 idx = sctp_pick_conn_idx_on_chunk (COOKIE_ACK);
-
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hdr->verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
@@ -821,11 +935,14 @@ sctp_handle_cookie_ack (sctp_header_t * sctp_hdr,
   sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T1_COOKIE);
   /* Change state */
   sctp_conn->state = SCTP_STATE_ESTABLISHED;
+  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_STATE_UP;
+
+  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
 
   sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
                  sctp_conn->sub_conn[idx].RTO);
 
-  stream_session_accept_notify (&sctp_conn->sub_conn[idx].connection);
+  session_stream_accept_notify (&sctp_conn->sub_conn[idx].connection);
 
   return SCTP_ERROR_NONE;
 
@@ -861,7 +978,7 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          ip6_header_t *ip6_hdr = 0;
          sctp_connection_t *sctp_conn, *new_sctp_conn;
          u16 sctp_implied_length = 0;
-         u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
+         u16 error0 = SCTP_ERROR_NONE, next0 = sctp_next_drop (is_ip4);
          u8 idx;
 
          bi0 = from[0];
@@ -891,36 +1008,18 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            {
              ip4_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip4_next_header (ip4_hdr);
+             idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
            }
          else
            {
              ip6_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip6_next_header (ip6_hdr);
+             idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
            }
-         idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
 
+         sctp_conn->sub_conn[idx].subconn_idx = idx;
          sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
 
-         transport_connection_t *trans_conn =
-           &sctp_conn->sub_conn[idx].connection;
-
-         trans_conn->lcl_port = sctp_hdr->dst_port;
-         trans_conn->rmt_port = sctp_hdr->src_port;
-         trans_conn->is_ip4 = is_ip4;
-
-         if (is_ip4)
-           {
-             trans_conn->lcl_ip.ip4.as_u32 = ip4_hdr->dst_address.as_u32;
-             trans_conn->rmt_ip.ip4.as_u32 = ip4_hdr->src_address.as_u32;
-           }
-         else
-           {
-             clib_memcpy (&trans_conn->lcl_ip.ip6, &ip6_hdr->dst_address,
-                          sizeof (ip6_address_t));
-             clib_memcpy (&trans_conn->rmt_ip.ip6, &ip6_hdr->src_address,
-                          sizeof (ip6_address_t));
-           }
-
          sctp_chunk_hdr =
            (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
 
@@ -939,13 +1038,15 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
              if (error0 == SCTP_ERROR_NONE)
                {
                  pool_get (tm->connections[my_thread_index], new_sctp_conn);
-                 clib_memcpy (new_sctp_conn, sctp_conn,
-                              sizeof (*new_sctp_conn));
+                 clib_memcpy_fast (new_sctp_conn, sctp_conn,
+                                   sizeof (*new_sctp_conn));
                  new_sctp_conn->sub_conn[idx].c_c_index =
                    new_sctp_conn - tm->connections[my_thread_index];
                  new_sctp_conn->sub_conn[idx].c_thread_index =
                    my_thread_index;
-                 new_sctp_conn->sub_conn[idx].parent = new_sctp_conn;
+                 new_sctp_conn->sub_conn[idx].PMTU =
+                   sctp_conn->sub_conn[idx].PMTU;
+                 new_sctp_conn->sub_conn[idx].subconn_idx = idx;
 
                  if (sctp_half_open_connection_cleanup (sctp_conn))
                    {
@@ -955,13 +1056,13 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
 
                  sctp_connection_timers_init (new_sctp_conn);
 
+                 sctp_init_cwnd (new_sctp_conn);
+
                  error0 =
                    sctp_handle_init_ack (sctp_hdr, sctp_chunk_hdr,
                                          new_sctp_conn, idx, b0,
                                          sctp_implied_length);
 
-                 sctp_init_mss (new_sctp_conn);
-
                  if (session_stream_connect_notify
                      (&new_sctp_conn->sub_conn[idx].connection, 0))
                    {
@@ -971,8 +1072,14 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                      sctp_connection_cleanup (new_sctp_conn);
                      goto drop;
                    }
+                 next0 = sctp_next_output (is_ip4);
                }
-             next0 = sctp_next_output (is_ip4);
+             break;
+
+           case OPERATION_ERROR:
+             error0 =
+               sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
+                                          &next0);
              break;
 
              /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
@@ -980,8 +1087,8 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
               * hence we should never get to the "default" case below.
               */
            default:
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
-             next0 = SCTP_NEXT_DROP;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
+             next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
 
@@ -989,7 +1096,7 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            {
              clib_warning ("error while parsing chunk");
              sctp_connection_cleanup (sctp_conn);
-             next0 = SCTP_NEXT_DROP;
+             next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
 
@@ -1011,21 +1118,21 @@ sctp46_rcv_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
   return from_frame->n_vectors;
 }
 
-static uword
-sctp4_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp4_rcv_phase_node) (vlib_main_t * vm,
+                                    vlib_node_runtime_t * node,
+                                    vlib_frame_t * from_frame)
 {
   return sctp46_rcv_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
 }
 
-static uword
-sctp6_rcv_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp6_init_phase_node) (vlib_main_t * vm,
+                                     vlib_node_runtime_t * node,
+                                     vlib_frame_t * from_frame)
 {
   return sctp46_rcv_phase_inline (vm, node, from_frame, 0 /* is_ip4 */ );
 }
 
-u8 *
+static u8 *
 format_sctp_rx_trace_short (u8 * s, va_list * args)
 {
   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -1043,7 +1150,6 @@ format_sctp_rx_trace_short (u8 * s, va_list * args)
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
 {
-  .function = sctp4_rcv_phase,
   .name = "sctp4-rcv",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1060,12 +1166,9 @@ VLIB_REGISTER_NODE (sctp4_rcv_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp4_rcv_phase_node, sctp4_rcv_phase);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp6_init_phase_node) =
 {
-  .function = sctp6_rcv_phase,
   .name = "sctp6-rcv",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1082,16 +1185,12 @@ VLIB_REGISTER_NODE (sctp6_init_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp6_init_phase_node, sctp6_rcv_phase);
-
-vlib_node_registration_t sctp4_shutdown_phase_node;
-vlib_node_registration_t sctp6_shutdown_phase_node;
-
 always_inline u16
 sctp_handle_shutdown (sctp_header_t * sctp_hdr,
                      sctp_chunks_common_hdr_t * sctp_chunk_hdr,
-                     sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
-                     u16 sctp_implied_length)
+                     sctp_connection_t * sctp_conn, u8 idx,
+                     vlib_buffer_t * b0, u16 sctp_implied_length,
+                     u16 * next0)
 {
   sctp_shutdown_association_chunk_t *shutdown_chunk =
     (sctp_shutdown_association_chunk_t *) (sctp_hdr);
@@ -1099,6 +1198,7 @@ sctp_handle_shutdown (sctp_header_t * sctp_hdr,
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hdr->verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
@@ -1113,21 +1213,25 @@ sctp_handle_shutdown (sctp_header_t * sctp_hdr,
     case SCTP_STATE_ESTABLISHED:
       if (sctp_check_outstanding_data_chunks (sctp_conn) == 0)
        sctp_conn->state = SCTP_STATE_SHUTDOWN_RECEIVED;
+      sctp_send_shutdown_ack (sctp_conn, idx, b0);
       break;
 
     case SCTP_STATE_SHUTDOWN_SENT:
-      sctp_send_shutdown_ack (sctp_conn);
+      sctp_send_shutdown_ack (sctp_conn, idx, b0);
       break;
     }
 
+  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
+
   return SCTP_ERROR_NONE;
 }
 
 always_inline u16
 sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
                          sctp_chunks_common_hdr_t * sctp_chunk_hdr,
-                         sctp_connection_t * sctp_conn, vlib_buffer_t * b0,
-                         u16 sctp_implied_length)
+                         sctp_connection_t * sctp_conn, u8 idx,
+                         vlib_buffer_t * b0, u16 sctp_implied_length,
+                         u16 * next0)
 {
   sctp_shutdown_ack_chunk_t *shutdown_ack_chunk =
     (sctp_shutdown_ack_chunk_t *) (sctp_hdr);
@@ -1135,6 +1239,7 @@ sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hdr->verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
@@ -1149,9 +1254,11 @@ sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
    * - STOP T2_SHUTDOWN timer
    * - SEND SHUTDOWN_COMPLETE chunk
    */
-  sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
-                   SCTP_TIMER_T2_SHUTDOWN);
-  sctp_send_shutdown_complete (sctp_conn);
+  sctp_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
+
+  sctp_send_shutdown_complete (sctp_conn, idx, b0);
+
+  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].c_is_ip4);
 
   return SCTP_ERROR_NONE;
 }
@@ -1159,8 +1266,9 @@ sctp_handle_shutdown_ack (sctp_header_t * sctp_hdr,
 always_inline u16
 sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
                               sctp_chunks_common_hdr_t * sctp_chunk_hdr,
-                              sctp_connection_t * sctp_conn,
-                              vlib_buffer_t * b0, u16 sctp_implied_length)
+                              sctp_connection_t * sctp_conn, u8 idx,
+                              vlib_buffer_t * b0, u16 sctp_implied_length,
+                              u16 * next0)
 {
   sctp_shutdown_complete_chunk_t *shutdown_complete =
     (sctp_shutdown_complete_chunk_t *) (sctp_hdr);
@@ -1168,6 +1276,7 @@ sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hdr->verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
@@ -1177,13 +1286,13 @@ sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
   if (sctp_is_bundling (sctp_implied_length, &shutdown_complete->chunk_hdr))
     return SCTP_ERROR_BUNDLING_VIOLATION;
 
-  sctp_timer_reset (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
-                   SCTP_TIMER_T2_SHUTDOWN);
+  sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
+
+  session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
 
   sctp_conn->state = SCTP_STATE_CLOSED;
 
-  stream_session_disconnect_notify (&sctp_conn->sub_conn
-                                   [MAIN_SCTP_SUB_CONN_IDX].connection);
+  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
 
   return SCTP_ERROR_NONE;
 }
@@ -1219,6 +1328,7 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
          sctp_connection_t *sctp_conn;
          u16 sctp_implied_length = 0;
          u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_RCV_PHASE_N_NEXT;
+         u8 idx = 0;
 
          bi0 = from[0];
          to_next[0] = bi0;
@@ -1244,11 +1354,13 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
            {
              ip4_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip4_next_header (ip4_hdr);
+             idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
            }
          else
            {
              ip6_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip6_next_header (ip6_hdr);
+             idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
            }
 
          sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
@@ -1257,30 +1369,29 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
          sctp_implied_length =
            sctp_calculate_implied_length (ip4_hdr, ip6_hdr, is_ip4);
 
-         switch (vnet_sctp_get_chunk_type (sctp_chunk_hdr))
+         u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
+         switch (chunk_type)
            {
            case SHUTDOWN:
              error0 =
-               sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn, b0,
-                                     sctp_implied_length);
-             next0 = sctp_next_output (is_ip4);
+               sctp_handle_shutdown (sctp_hdr, sctp_chunk_hdr, sctp_conn,
+                                     idx, b0, sctp_implied_length, &next0);
              break;
 
            case SHUTDOWN_ACK:
              error0 =
                sctp_handle_shutdown_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
-                                         b0, sctp_implied_length);
-             next0 = sctp_next_output (is_ip4);
+                                         idx, b0, sctp_implied_length,
+                                         &next0);
              break;
 
            case SHUTDOWN_COMPLETE:
              error0 =
                sctp_handle_shutdown_complete (sctp_hdr, sctp_chunk_hdr,
-                                              sctp_conn, b0,
-                                              sctp_implied_length);
+                                              sctp_conn, idx, b0,
+                                              sctp_implied_length, &next0);
 
              sctp_connection_cleanup (sctp_conn);
-             next0 = sctp_next_output (is_ip4);
              break;
 
              /*
@@ -1290,17 +1401,28 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
            case DATA:
              error0 =
                sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
-                                 sctp_conn, b0, &next0);
-             next0 = sctp_next_output (is_ip4);
+                                 sctp_conn, idx, b0, &next0);
              break;
 
+           case OPERATION_ERROR:
+             error0 =
+               sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
+                                          &next0);
+             break;
+
+           case COOKIE_ECHO:   /* Cookie Received While Shutting Down */
+             sctp_prepare_operation_error (sctp_conn, idx, b0,
+                                           COOKIE_RECEIVED_WHILE_SHUTTING_DOWN);
+             error0 = SCTP_ERROR_NONE;
+             next0 = sctp_next_output (is_ip4);
+             break;
              /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
               * are handled by the input-dispatcher function using the table-lookup
               * hence we should never get to the "default" case below.
               */
            default:
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
-             next0 = SCTP_NEXT_DROP;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
+             next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
 
@@ -1308,7 +1430,7 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
            {
              clib_warning ("error while parsing chunk");
              sctp_connection_cleanup (sctp_conn);
-             next0 = SCTP_NEXT_DROP;
+             next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
 
@@ -1319,12 +1441,12 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
                vlib_add_trace (vm, node, b0, sizeof (*sctp_trace));
 
              if (sctp_hdr != NULL)
-               clib_memcpy (&sctp_trace->sctp_header, sctp_hdr,
-                            sizeof (sctp_trace->sctp_header));
+               clib_memcpy_fast (&sctp_trace->sctp_header, sctp_hdr,
+                                 sizeof (sctp_trace->sctp_header));
 
              if (sctp_conn != NULL)
-               clib_memcpy (&sctp_trace->sctp_connection, sctp_conn,
-                            sizeof (sctp_trace->sctp_connection));
+               clib_memcpy_fast (&sctp_trace->sctp_connection, sctp_conn,
+                                 sizeof (sctp_trace->sctp_connection));
            }
 
          b0->error = node->errors[error0];
@@ -1340,16 +1462,16 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
 
 }
 
-static uword
-sctp4_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                     vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp4_shutdown_phase_node) (vlib_main_t * vm,
+                                         vlib_node_runtime_t * node,
+                                         vlib_frame_t * from_frame)
 {
   return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
 }
 
-static uword
-sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                     vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp6_shutdown_phase_node) (vlib_main_t * vm,
+                                         vlib_node_runtime_t * node,
+                                         vlib_frame_t * from_frame)
 {
   return sctp46_shutdown_phase_inline (vm, node, from_frame, 1 /* is_ip4 */ );
 }
@@ -1357,7 +1479,6 @@ sctp6_shutdown_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
 {
-  .function = sctp4_shutdown_phase,
   .name = "sctp4-shutdown",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1374,13 +1495,9 @@ VLIB_REGISTER_NODE (sctp4_shutdown_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp4_shutdown_phase_node,
-                             sctp4_shutdown_phase);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
 {
-  .function = sctp6_shutdown_phase,
   .name = "sctp6-shutdown",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1397,26 +1514,34 @@ VLIB_REGISTER_NODE (sctp6_shutdown_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp6_shutdown_phase_node,
-                             sctp6_shutdown_phase);
-
-vlib_node_registration_t sctp4_listen_phase_node;
-vlib_node_registration_t sctp6_listen_phase_node;
-
-vlib_node_registration_t sctp4_established_phase_node;
-vlib_node_registration_t sctp6_established_phase_node;
-
 always_inline u16
 sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
                  sctp_connection_t * sctp_conn, u8 idx, vlib_buffer_t * b0,
                  u16 * next0)
 {
+
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sack_chunk->sctp_hdr.verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
+  sctp_conn->sub_conn[idx].state = SCTP_SUBCONN_SACK_RECEIVED;
+
+  sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
+
+  /* Section 7.2.2; point (2) */
+  if (sctp_conn->sub_conn[idx].cwnd > sctp_conn->sub_conn[idx].ssthresh)
+    sctp_conn->sub_conn[idx].partially_acked_bytes =
+      sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack;
+
+  /* Section 7.2.2; point (5) */
+  if (sctp_conn->next_tsn - sack_chunk->cumulative_tsn_ack == 0)
+    sctp_conn->sub_conn[idx].partially_acked_bytes = 0;
+
+  sctp_conn->last_unacked_tsn = sack_chunk->cumulative_tsn_ack;
+
   sctp_calculate_rto (sctp_conn, idx);
 
   sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T3_RXTX,
@@ -1424,7 +1549,7 @@ sctp_handle_sack (sctp_selective_ack_chunk_t * sack_chunk,
 
   sctp_conn->sub_conn[idx].RTO_pending = 0;
 
-  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
+  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
 
   return SCTP_ERROR_NONE;
 }
@@ -1437,10 +1562,11 @@ sctp_handle_heartbeat (sctp_hb_req_chunk_t * sctp_hb_chunk,
   /* Check that the LOCALLY generated tag is being used by the REMOTE peer as the verification tag */
   if (sctp_conn->local_tag != sctp_hb_chunk->sctp_hdr.verification_tag)
     {
+      *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
       return SCTP_ERROR_INVALID_TAG;
     }
 
-  sctp_prepare_heartbeat_ack_chunk (sctp_conn, b0);
+  sctp_prepare_heartbeat_ack_chunk (sctp_conn, idx, b0);
 
   *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
 
@@ -1452,27 +1578,29 @@ sctp_handle_heartbeat_ack (sctp_hb_ack_chunk_t * sctp_hb_ack_chunk,
                           sctp_connection_t * sctp_conn, u8 idx,
                           vlib_buffer_t * b0, u16 * next0)
 {
+  sctp_conn->sub_conn[idx].last_seen = sctp_time_now ();
+
   sctp_conn->sub_conn[idx].unacknowledged_hb -= 1;
 
   sctp_timer_update (sctp_conn, idx, SCTP_TIMER_T4_HEARTBEAT,
                     sctp_conn->sub_conn[idx].RTO);
 
-  *next0 = sctp_next_output (sctp_conn->sub_conn[idx].connection.is_ip4);
+  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
 
   return SCTP_ERROR_NONE;
 }
 
 always_inline void
-sctp_node_inc_counter (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node,
+sctp_node_inc_counter (vlib_main_t * vm, u32 sctp4_node, u32 sctp6_node,
                       u8 is_ip4, u8 evt, u8 val)
 {
   if (PREDICT_TRUE (!val))
     return;
 
   if (is_ip4)
-    vlib_node_increment_counter (vm, tcp4_node, evt, val);
+    vlib_node_increment_counter (vm, sctp4_node, evt, val);
   else
-    vlib_node_increment_counter (vm, tcp6_node, evt, val);
+    vlib_node_increment_counter (vm, sctp6_node, evt, val);
 }
 
 always_inline uword
@@ -1503,7 +1631,7 @@ sctp46_listen_process_inline (vlib_main_t * vm,
          ip6_header_t *ip6_hdr;
          sctp_connection_t *child_conn;
          sctp_connection_t *sctp_listener;
-         u16 next0 = SCTP_LISTEN_PHASE_N_NEXT, error0 = SCTP_ERROR_ENQUEUED;
+         u16 next0 = sctp_next_drop (is_ip4), error0 = SCTP_ERROR_ENQUEUED;
 
          bi0 = from[0];
          to_next[0] = bi0;
@@ -1529,14 +1657,14 @@ sctp46_listen_process_inline (vlib_main_t * vm,
 
          child_conn =
            sctp_lookup_connection (sctp_listener->sub_conn
-                                   [MAIN_SCTP_SUB_CONN_IDX].c_fib_index, b0,
+                                   [SCTP_PRIMARY_PATH_IDX].c_fib_index, b0,
                                    my_thread_index, is_ip4);
 
          if (PREDICT_FALSE (child_conn->state != SCTP_STATE_CLOSED))
            {
              SCTP_DBG
                ("conn_index = %u: child_conn->state != SCTP_STATE_CLOSED.... STATE=%s",
-                child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
+                child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
                 connection.c_index,
                 sctp_state_to_string (child_conn->state));
              error0 = SCTP_ERROR_CREATE_EXISTS;
@@ -1545,46 +1673,55 @@ sctp46_listen_process_inline (vlib_main_t * vm,
 
          /* Create child session and send SYN-ACK */
          child_conn = sctp_connection_new (my_thread_index);
-         child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].parent = child_conn;
-         child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_port =
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].subconn_idx =
+           SCTP_PRIMARY_PATH_IDX;
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_port =
            sctp_hdr->dst_port;
-         child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_port =
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_port =
            sctp_hdr->src_port;
-         child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_is_ip4 = is_ip4;
-         child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto =
-           sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection.proto;
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_is_ip4 = is_ip4;
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto =
+           sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.proto;
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU =
+           sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].PMTU;
          child_conn->state = SCTP_STATE_CLOSED;
+         child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].connection.fib_index =
+           sctp_listener->sub_conn[SCTP_PRIMARY_PATH_IDX].
+           connection.fib_index;
 
          if (is_ip4)
            {
-             child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip4.as_u32 =
+             child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip4.as_u32 =
                ip4_hdr->dst_address.as_u32;
-             child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip4.as_u32 =
+             child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip4.as_u32 =
                ip4_hdr->src_address.as_u32;
            }
          else
            {
-             clib_memcpy (&child_conn->
-                          sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_lcl_ip6,
-                          &ip6_hdr->dst_address, sizeof (ip6_address_t));
-             clib_memcpy (&child_conn->
-                          sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_rmt_ip6,
-                          &ip6_hdr->src_address, sizeof (ip6_address_t));
+             clib_memcpy_fast (&child_conn->
+                               sub_conn[SCTP_PRIMARY_PATH_IDX].c_lcl_ip6,
+                               &ip6_hdr->dst_address,
+                               sizeof (ip6_address_t));
+             clib_memcpy_fast (&child_conn->
+                               sub_conn[SCTP_PRIMARY_PATH_IDX].c_rmt_ip6,
+                               &ip6_hdr->src_address,
+                               sizeof (ip6_address_t));
            }
 
          sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
          sctp_chunks_common_hdr_t *sctp_chunk_hdr = &full_hdr->common_hdr;
 
          u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
-         if (chunk_type != INIT)
+         if (chunk_type != INIT && chunk_type != DATA
+             && chunk_type != OPERATION_ERROR)
            {
              SCTP_DBG
                ("conn_index = %u: chunk_type != INIT... chunk_type=%s",
-                child_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
+                child_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
                 connection.c_index, sctp_chunk_to_string (chunk_type));
 
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
-             next0 = SCTP_NEXT_DROP;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
+             next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
 
@@ -1598,27 +1735,29 @@ sctp46_listen_process_inline (vlib_main_t * vm,
 
              sctp_init_snd_vars (child_conn);
 
+             sctp_init_cwnd (child_conn);
+
              error0 =
                sctp_handle_init (sctp_hdr, sctp_chunk_hdr, child_conn, b0,
                                  sctp_implied_length);
 
-             sctp_init_mss (child_conn);
-
              if (error0 == SCTP_ERROR_NONE)
                {
-                 if (stream_session_accept
+                 if (session_stream_accept
                      (&child_conn->
-                      sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
+                      sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
+                      sctp_listener->
+                      sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index,
                       sctp_listener->
-                      sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
+                      sub_conn[SCTP_PRIMARY_PATH_IDX].c_thread_index, 0))
                    {
                      clib_warning ("session accept fail");
                      sctp_connection_cleanup (child_conn);
                      error0 = SCTP_ERROR_CREATE_SESSION_FAIL;
                      goto drop;
                    }
+                 next0 = sctp_next_output (is_ip4);
                }
-             next0 = sctp_next_output (is_ip4);
              break;
 
              /* Reception of a DATA chunk whilst in the CLOSED state is called
@@ -1627,6 +1766,12 @@ sctp46_listen_process_inline (vlib_main_t * vm,
               */
            case DATA:
              break;
+
+           case OPERATION_ERROR:
+             error0 =
+               sctp_handle_operation_err (sctp_hdr, child_conn,
+                                          SCTP_PRIMARY_PATH_IDX, b0, &next0);
+             break;
            }
 
        drop:
@@ -1634,10 +1779,10 @@ sctp46_listen_process_inline (vlib_main_t * vm,
            {
              sctp_rx_trace_t *t0 =
                vlib_add_trace (vm, node, b0, sizeof (*t0));
-             clib_memcpy (&t0->sctp_header, sctp_hdr,
-                          sizeof (t0->sctp_header));
-             clib_memcpy (&t0->sctp_connection, sctp_listener,
-                          sizeof (t0->sctp_connection));
+             clib_memcpy_fast (&t0->sctp_header, sctp_hdr,
+                               sizeof (t0->sctp_header));
+             clib_memcpy_fast (&t0->sctp_connection, sctp_listener,
+                               sizeof (t0->sctp_connection));
            }
 
          b0->error = node->errors[error0];
@@ -1651,16 +1796,16 @@ sctp46_listen_process_inline (vlib_main_t * vm,
   return from_frame->n_vectors;
 }
 
-static uword
-sctp4_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                   vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp4_listen_phase_node) (vlib_main_t * vm,
+                                       vlib_node_runtime_t * node,
+                                       vlib_frame_t * from_frame)
 {
   return sctp46_listen_process_inline (vm, node, from_frame, 1 /* is_ip4 */ );
 }
 
-static uword
-sctp6_listen_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                   vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp6_listen_phase_node) (vlib_main_t * vm,
+                                       vlib_node_runtime_t * node,
+                                       vlib_frame_t * from_frame)
 {
   return sctp46_listen_process_inline (vm, node, from_frame, 0 /* is_ip4 */ );
 }
@@ -1669,6 +1814,7 @@ always_inline uword
 sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
                                 vlib_frame_t * from_frame, int is_ip4)
 {
+  sctp_main_t *sm = vnet_get_sctp_main ();
   u32 n_left_from, next_index, *from, *to_next;
   u32 my_thread_index = vm->thread_index, errors = 0;
 
@@ -1692,7 +1838,8 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
          ip4_header_t *ip4_hdr = 0;
          ip6_header_t *ip6_hdr = 0;
          sctp_connection_t *sctp_conn;
-         u16 error0 = SCTP_ERROR_NONE, next0 = SCTP_ESTABLISHED_PHASE_N_NEXT;
+         u16 error0 = SCTP_ERROR_ENQUEUED, next0 =
+           SCTP_ESTABLISHED_PHASE_N_NEXT;
          u8 idx;
 
          bi0 = from[0];
@@ -1718,39 +1865,18 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            {
              ip4_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip4_next_header (ip4_hdr);
+             idx = sctp_sub_conn_id_via_ip4h (sctp_conn, ip4_hdr);
            }
          else
            {
              ip6_hdr = vlib_buffer_get_current (b0);
              sctp_hdr = ip6_next_header (ip6_hdr);
+             idx = sctp_sub_conn_id_via_ip6h (sctp_conn, ip6_hdr);
            }
 
-         idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
+         sctp_conn->sub_conn[idx].subconn_idx = idx;
 
          sctp_full_hdr_t *full_hdr = (sctp_full_hdr_t *) sctp_hdr;
-
-         transport_connection_t *trans_conn =
-           &sctp_conn->sub_conn[idx].connection;
-
-         trans_conn->lcl_port = sctp_hdr->dst_port;
-         trans_conn->rmt_port = sctp_hdr->src_port;
-         trans_conn->is_ip4 = is_ip4;
-
-         sctp_conn->sub_conn[idx].parent = sctp_conn;
-
-         if (is_ip4)
-           {
-             trans_conn->lcl_ip.ip4.as_u32 = ip4_hdr->dst_address.as_u32;
-             trans_conn->rmt_ip.ip4.as_u32 = ip4_hdr->src_address.as_u32;
-           }
-         else
-           {
-             clib_memcpy (&trans_conn->lcl_ip.ip6, &ip6_hdr->dst_address,
-                          sizeof (ip6_address_t));
-             clib_memcpy (&trans_conn->rmt_ip.ip6, &ip6_hdr->src_address,
-                          sizeof (ip6_address_t));
-           }
-
          sctp_chunk_hdr =
            (sctp_chunks_common_hdr_t *) (&full_hdr->common_hdr);
 
@@ -1761,15 +1887,13 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            case COOKIE_ECHO:
              error0 =
                sctp_handle_cookie_echo (sctp_hdr, sctp_chunk_hdr, sctp_conn,
-                                        b0);
-             next0 = sctp_next_output (is_ip4);
+                                        idx, b0, &next0);
              break;
 
            case COOKIE_ACK:
              error0 =
                sctp_handle_cookie_ack (sctp_hdr, sctp_chunk_hdr, sctp_conn,
-                                       b0);
-             next0 = sctp_next_output (is_ip4);
+                                       idx, b0, &next0);
              break;
 
            case SACK:
@@ -1793,7 +1917,13 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
            case DATA:
              error0 =
                sctp_handle_data ((sctp_payload_data_chunk_t *) sctp_hdr,
-                                 sctp_conn, b0, &next0);
+                                 sctp_conn, idx, b0, &next0);
+             break;
+
+           case OPERATION_ERROR:
+             error0 =
+               sctp_handle_operation_err (sctp_hdr, sctp_conn, idx, b0,
+                                          &next0);
              break;
 
              /* All UNEXPECTED scenarios (wrong chunk received per state-machine)
@@ -1801,8 +1931,8 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
               * hence we should never get to the "default" case below.
               */
            default:
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
-             next0 = SCTP_NEXT_DROP;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
+             next0 = sctp_next_drop (is_ip4);
              goto done;
            }
 
@@ -1822,34 +1952,34 @@ sctp46_established_phase_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
     }
 
-  errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
-                                                my_thread_index);
+  errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_SCTP,
+                                             my_thread_index);
 
-  sctp_node_inc_counter (vm, is_ip4, sctp4_established_phase_node.index,
-                        sctp6_established_phase_node.index,
+  sctp_node_inc_counter (vm, is_ip4, sm->sctp4_established_phase_node_index,
+                        sm->sctp6_established_phase_node_index,
                         SCTP_ERROR_EVENT_FIFO_FULL, errors);
   sctp_flush_frame_to_output (vm, my_thread_index, is_ip4);
 
   return from_frame->n_vectors;
 }
 
-static uword
-sctp4_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                        vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp4_established_phase_node) (vlib_main_t * vm,
+                                            vlib_node_runtime_t * node,
+                                            vlib_frame_t * from_frame)
 {
   return sctp46_established_phase_inline (vm, node, from_frame,
                                          1 /* is_ip4 */ );
 }
 
-static uword
-sctp6_established_phase (vlib_main_t * vm, vlib_node_runtime_t * node,
-                        vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp6_established_phase_node) (vlib_main_t * vm,
+                                            vlib_node_runtime_t * node,
+                                            vlib_frame_t * from_frame)
 {
   return sctp46_established_phase_inline (vm, node, from_frame,
                                          0 /* is_ip4 */ );
 }
 
-u8 *
+static u8 *
 format_sctp_rx_trace (u8 * s, va_list * args)
 {
   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
@@ -1868,7 +1998,6 @@ format_sctp_rx_trace (u8 * s, va_list * args)
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
 {
-  .function = sctp4_listen_phase,
   .name = "sctp4-listen",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1885,12 +2014,9 @@ VLIB_REGISTER_NODE (sctp4_listen_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp4_listen_phase_node, sctp4_listen_phase);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
 {
-  .function = sctp6_listen_phase,
   .name = "sctp6-listen",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1907,12 +2033,9 @@ VLIB_REGISTER_NODE (sctp6_listen_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp6_listen_phase_node, sctp6_listen_phase);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp4_established_phase_node) =
 {
-  .function = sctp4_established_phase,
   .name = "sctp4-established",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1929,13 +2052,9 @@ VLIB_REGISTER_NODE (sctp4_established_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp4_established_phase_node,
-                             sctp4_established_phase);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp6_established_phase_node) =
 {
-  .function = sctp6_established_phase,
   .name = "sctp6-established",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -1952,9 +2071,6 @@ VLIB_REGISTER_NODE (sctp6_established_phase_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp6_established_phase_node,
-                             sctp6_established_phase);
-
 /*
  * This is the function executed first for the SCTP graph.
  * It takes care of doing the initial message parsing and
@@ -1966,7 +2082,7 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
 {
   u32 n_left_from, next_index, *from, *to_next;
   u32 my_thread_index = vm->thread_index;
-  u8 is_filtered;
+  u8 result;
   sctp_main_t *tm = vnet_get_sctp_main ();
 
   from = vlib_frame_vector_args (from_frame);
@@ -2001,7 +2117,7 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
          n_left_to_next -= 1;
 
          b0 = vlib_get_buffer (vm, bi0);
-         vnet_buffer (b0)->tcp.flags = 0;
+         vnet_buffer (b0)->sctp.flags = 0;
          fib_index0 = vnet_buffer (b0)->ip.fib_index;
 
          /* Checksum computed by ipx_local no need to compute again */
@@ -2027,7 +2143,7 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
                                                          sctp_hdr->src_port,
                                                          TRANSPORT_PROTO_SCTP,
                                                          my_thread_index,
-                                                         &is_filtered);
+                                                         &result);
            }
          else
            {
@@ -2050,7 +2166,7 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
                                                          sctp_hdr->src_port,
                                                          TRANSPORT_PROTO_SCTP,
                                                          my_thread_index,
-                                                         &is_filtered);
+                                                         &result);
            }
 
          /* Length check */
@@ -2063,11 +2179,20 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
          sctp_conn = sctp_get_connection_from_transport (trans_conn);
          vnet_sctp_common_hdr_params_net_to_host (sctp_chunk_hdr);
 
-         u8 type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
+         u8 chunk_type = vnet_sctp_get_chunk_type (sctp_chunk_hdr);
+         if (chunk_type >= UNKNOWN)
+           {
+             clib_warning
+               ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
+
+             sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
+                                           b0, UNRECOGNIZED_CHUNK_TYPE);
+
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
+             next0 = sctp_next_output (is_ip4);
+             goto done;
+           }
 
-#if SCTP_DEBUG_STATE_MACHINE
-         u8 idx = sctp_pick_conn_idx_on_state (sctp_conn->state);
-#endif
          vnet_buffer (b0)->sctp.hdr_offset =
            (u8 *) sctp_hdr - (u8 *) vlib_buffer_get_current (b0);
 
@@ -2079,30 +2204,30 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
              vnet_buffer (b0)->sctp.data_offset = n_advance_bytes0;
              vnet_buffer (b0)->sctp.data_len = n_data_bytes0;
 
-             next0 = tm->dispatch_table[sctp_conn->state][type].next;
-             error0 = tm->dispatch_table[sctp_conn->state][type].error;
-
-             SCTP_DBG_STATE_MACHINE ("CONNECTION_INDEX = %u: "
-                                     "CURRENT_CONNECTION_STATE = %s,"
-                                     "CHUNK_TYPE_RECEIVED = %s "
-                                     "NEXT_PHASE = %s",
-                                     sctp_conn->sub_conn
-                                     [idx].connection.c_index,
-                                     sctp_state_to_string (sctp_conn->state),
-                                     sctp_chunk_to_string (type),
-                                     phase_to_string (next0));
+             next0 = tm->dispatch_table[sctp_conn->state][chunk_type].next;
+             error0 = tm->dispatch_table[sctp_conn->state][chunk_type].error;
 
-             if (type == DATA)
+             SCTP_DBG_STATE_MACHINE
+               ("S_INDEX = %u, C_INDEX = %u, TRANS_CONN = %p, SCTP_CONN = %p, CURRENT_CONNECTION_STATE = %s,"
+                "CHUNK_TYPE_RECEIVED = %s " "NEXT_PHASE = %s",
+                sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
+                connection.s_index,
+                sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
+                connection.c_index, trans_conn, sctp_conn,
+                sctp_state_to_string (sctp_conn->state),
+                sctp_chunk_to_string (chunk_type), phase_to_string (next0));
+
+             if (chunk_type == DATA)
                SCTP_ADV_DBG ("n_advance_bytes0 = %u, n_data_bytes0 = %u",
                              n_advance_bytes0, n_data_bytes0);
 
            }
          else
            {
-             if (is_filtered)
+             if (result)
                {
                  next0 = SCTP_INPUT_NEXT_DROP;
-                 error0 = SCTP_ERROR_FILTERED;
+                 error0 = SCTP_ERROR_NONE + result;
                }
              else if ((is_ip4 && tm->punt_unknown4) ||
                       (!is_ip4 && tm->punt_unknown6))
@@ -2138,16 +2263,14 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
   return from_frame->n_vectors;
 }
 
-static uword
-sctp4_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
-                       vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+                                vlib_frame_t * from_frame)
 {
   return sctp46_input_dispatcher (vm, node, from_frame, 1 /* is_ip4 */ );
 }
 
-static uword
-sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
-                       vlib_frame_t * from_frame)
+VLIB_NODE_FN (sctp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
+                                vlib_frame_t * from_frame)
 {
   return sctp46_input_dispatcher (vm, node, from_frame, 0 /* is_ip4 */ );
 }
@@ -2155,7 +2278,6 @@ sctp6_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp4_input_node) =
 {
-  .function = sctp4_input_dispatcher,
   .name = "sctp4-input",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -2173,12 +2295,9 @@ VLIB_REGISTER_NODE (sctp4_input_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp4_input_node, sctp4_input_dispatcher);
-
 /* *INDENT-OFF* */
 VLIB_REGISTER_NODE (sctp6_input_node) =
 {
-  .function = sctp6_input_dispatcher,
   .name = "sctp6-input",
   /* Takes a vector of packets. */
   .vector_size = sizeof (u32),
@@ -2196,11 +2315,7 @@ VLIB_REGISTER_NODE (sctp6_input_node) =
 };
 /* *INDENT-ON* */
 
-VLIB_NODE_FUNCTION_MULTIARCH (sctp6_input_node, sctp6_input_dispatcher);
-
-vlib_node_registration_t sctp4_input_node;
-vlib_node_registration_t sctp6_input_node;
-
+#ifndef CLIB_MARCH_VARIANT
 static void
 sctp_dispatch_table_init (sctp_main_t * tm)
 {
@@ -2230,7 +2345,7 @@ do {                                                              \
    * _(SHUTDOWN_RECEIVED, "SHUTDOWN_RECEIVED")   \
    * _(SHUTDOWN_ACK_SENT, "SHUTDOWN_ACK_SENT")
    */
-  _(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);      /* UNEXPECTED DATA chunk which requires special handling */
+  //_(CLOSED, DATA, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);     /* UNEXPECTED DATA chunk which requires special handling */
   _(CLOSED, INIT, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
   _(CLOSED, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);       /* UNEXPECTED INIT_ACK chunk */
   _(CLOSED, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION);      /* UNEXPECTED SACK chunk */
@@ -2245,8 +2360,9 @@ do {                                                              \
   _(CLOSED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);    /* UNEXPECTED ECNE chunk */
   _(CLOSED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);      /* UNEXPECTED CWR chunk */
   _(CLOSED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);  /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(CLOSED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE, SCTP_ERROR_NONE);
 
-  _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
+  _(COOKIE_WAIT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE); /* UNEXPECTED DATA chunk which requires special handling */
   _(COOKIE_WAIT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);    /* UNEXPECTED INIT chunk which requires special handling */
   _(COOKIE_WAIT, INIT_ACK, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);
   _(COOKIE_WAIT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION); /* UNEXPECTED SACK chunk */
@@ -2261,6 +2377,8 @@ do {                                                              \
   _(COOKIE_WAIT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);       /* UNEXPECTED ECNE chunk */
   _(COOKIE_WAIT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
   _(COOKIE_WAIT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);     /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(COOKIE_WAIT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(COOKIE_ECHOED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_NONE);
   _(COOKIE_ECHOED, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);  /* UNEXPECTED INIT chunk which requires special handling */
@@ -2278,6 +2396,8 @@ do {                                                              \
   _(COOKIE_ECHOED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);     /* UNEXPECTED ECNE chunk */
   _(COOKIE_ECHOED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);       /* UNEXPECTED CWR chunk */
   _(COOKIE_ECHOED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);   /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(COOKIE_ECHOED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(ESTABLISHED, DATA, SCTP_INPUT_NEXT_ESTABLISHED_PHASE, SCTP_ERROR_NONE);
   _(ESTABLISHED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION); /* UNEXPECTED INIT chunk */
@@ -2296,6 +2416,8 @@ do {                                                              \
   _(ESTABLISHED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);       /* UNEXPECTED ECNE chunk */
   _(ESTABLISHED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION); /* UNEXPECTED CWR chunk */
   _(ESTABLISHED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);     /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(ESTABLISHED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(SHUTDOWN_PENDING, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
   _(SHUTDOWN_PENDING, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION);    /* UNEXPECTED INIT chunk */
@@ -2310,11 +2432,14 @@ do {                                                            \
     SCTP_ERROR_NONE);
   _(SHUTDOWN_PENDING, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION);    /* UNEXPECTED SHUTDOWN_ACK chunk */
   _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_OPERATION_ERROR_VIOLATION);    /* UNEXPECTED OPERATION_ERROR chunk */
-  _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION);    /* UNEXPECTED COOKIE_ECHO chunk */
+  _(SHUTDOWN_PENDING, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
+    SCTP_ERROR_NONE);
   _(SHUTDOWN_PENDING, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);   /* UNEXPECTED COOKIE_ACK chunk */
   _(SHUTDOWN_PENDING, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);  /* UNEXPECTED ECNE chunk */
   _(SHUTDOWN_PENDING, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);    /* UNEXPECTED CWR chunk */
   _(SHUTDOWN_PENDING, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);        /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(SHUTDOWN_PENDING, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(SHUTDOWN_SENT, DATA, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
   _(SHUTDOWN_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION);       /* UNEXPECTED INIT chunk */
@@ -2326,11 +2451,14 @@ do {                                                            \
   _(SHUTDOWN_SENT, SHUTDOWN, SCTP_INPUT_NEXT_SHUTDOWN_PHASE, SCTP_ERROR_NONE);
   _(SHUTDOWN_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
     SCTP_ERROR_NONE);
-  _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION);       /* UNEXPECTED COOKIE_ECHO chunk */
+  _(SHUTDOWN_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
+    SCTP_ERROR_NONE);
   _(SHUTDOWN_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);      /* UNEXPECTED COOKIE_ACK chunk */
   _(SHUTDOWN_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION);     /* UNEXPECTED ECNE chunk */
   _(SHUTDOWN_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);       /* UNEXPECTED CWR chunk */
   _(SHUTDOWN_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);   /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(SHUTDOWN_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(SHUTDOWN_RECEIVED, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION);   /* UNEXPECTED DATA chunk */
   _(SHUTDOWN_RECEIVED, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION);   /* UNEXPECTED INIT chunk */
@@ -2342,14 +2470,17 @@ do {                                                            \
   _(SHUTDOWN_RECEIVED, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION);   /* UNEXPECTED SHUTDOWN chunk */
   _(SHUTDOWN_RECEIVED, SHUTDOWN_ACK, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
     SCTP_ERROR_NONE);
-  _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION);   /* UNEXPECTED COOKIE_ECHO chunk */
+  _(SHUTDOWN_RECEIVED, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
+    SCTP_ERROR_NONE);
   _(SHUTDOWN_RECEIVED, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);  /* UNEXPECTED COOKIE_ACK chunk */
   _(SHUTDOWN_RECEIVED, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
   _(SHUTDOWN_RECEIVED, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);   /* UNEXPECTED CWR chunk */
   _(SHUTDOWN_RECEIVED, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_COMPLETE_VIOLATION);       /* UNEXPECTED SHUTDOWN_COMPLETE chunk */
+  _(SHUTDOWN_RECEIVED, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   _(SHUTDOWN_ACK_SENT, DATA, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_DATA_CHUNK_VIOLATION);   /* UNEXPECTED DATA chunk */
-  _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_INIT_CHUNK_VIOLATION);   /* UNEXPECTED INIT chunk */
+  _(SHUTDOWN_ACK_SENT, INIT, SCTP_INPUT_NEXT_RCV_PHASE, SCTP_ERROR_NONE);      /* UNEXPECTED INIT chunk */
   _(SHUTDOWN_ACK_SENT, INIT_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);    /* UNEXPECTED INIT_ACK chunk */
   _(SHUTDOWN_ACK_SENT, SACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SACK_CHUNK_VIOLATION);   /* UNEXPECTED INIT chunk */
   _(SHUTDOWN_ACK_SENT, HEARTBEAT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_HEARTBEAT_CHUNK_VIOLATION); /* UNEXPECTED HEARTBEAT chunk */
@@ -2357,12 +2488,15 @@ do {                                                            \
   _(SHUTDOWN_ACK_SENT, ABORT, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ABORT_CHUNK_VIOLATION); /* UNEXPECTED ABORT chunk */
   _(SHUTDOWN_ACK_SENT, SHUTDOWN, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_CHUNK_VIOLATION);   /* UNEXPECTED SHUTDOWN chunk */
   _(SHUTDOWN_ACK_SENT, SHUTDOWN_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_SHUTDOWN_ACK_CHUNK_VIOLATION);   /* UNEXPECTED SHUTDOWN_ACK chunk */
-  _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_COOKIE_ECHO_VIOLATION);   /* UNEXPECTED COOKIE_ECHO chunk */
+  _(SHUTDOWN_ACK_SENT, COOKIE_ECHO, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
+    SCTP_ERROR_NONE);
   _(SHUTDOWN_ACK_SENT, COOKIE_ACK, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ACK_DUP);  /* UNEXPECTED COOKIE_ACK chunk */
   _(SHUTDOWN_ACK_SENT, ECNE, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_ECNE_VIOLATION); /* UNEXPECTED ECNE chunk */
   _(SHUTDOWN_ACK_SENT, CWR, SCTP_INPUT_NEXT_DROP, SCTP_ERROR_CWR_VIOLATION);   /* UNEXPECTED CWR chunk */
   _(SHUTDOWN_ACK_SENT, SHUTDOWN_COMPLETE, SCTP_INPUT_NEXT_SHUTDOWN_PHASE,
     SCTP_ERROR_NONE);
+  _(SHUTDOWN_ACK_SENT, OPERATION_ERROR, SCTP_INPUT_NEXT_LISTEN_PHASE,
+    SCTP_ERROR_NONE);
 
   /* TODO: Handle COOKIE ECHO when a TCB Exists */
 
@@ -2385,6 +2519,7 @@ sctp_input_init (vlib_main_t * vm)
 }
 
 VLIB_INIT_FUNCTION (sctp_input_init);
+#endif /* CLIB_MARCH_VARIANT */
 
 /*
  * fd.io coding-style-patch-verification: ON