session: free session after transport and app confirm
[vpp.git] / src / vnet / sctp / sctp_input.c
index 00d0a61..4454f99 100644 (file)
@@ -245,15 +245,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
@@ -304,7 +304,7 @@ sctp_handle_operation_err (sctp_header_t * sctp_hdr,
        {
          sctp_connection_cleanup (sctp_conn);
 
-         stream_session_disconnect_notify (&sctp_conn->
+         session_transport_closing_notify (&sctp_conn->
                                            sub_conn[idx].connection);
        }
     }
@@ -319,8 +319,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
@@ -337,20 +339,21 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
        case SCTP_STATE_COOKIE_WAIT:
          SCTP_ADV_DBG ("Received INIT chunk while in COOKIE_WAIT state");
          sctp_prepare_initack_chunk_for_collision (sctp_conn,
-                                                   MAIN_SCTP_SUB_CONN_IDX,
-                                                   b0, ip4_addr, ip6_addr);
+                                                   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");
          if (sctp_conn->forming_association_changed == 0)
            sctp_prepare_initack_chunk_for_collision (sctp_conn,
-                                                     MAIN_SCTP_SUB_CONN_IDX,
-                                                     b0, ip4_addr, ip6_addr);
+                                                     SCTP_PRIMARY_PATH_IDX,
+                                                     b0, &ip4_addr,
+                                                     &ip6_addr);
          else
            sctp_prepare_abort_for_collision (sctp_conn,
-                                             MAIN_SCTP_SUB_CONN_IDX, b0,
-                                             ip4_addr, ip6_addr);
+                                             SCTP_PRIMARY_PATH_IDX, b0,
+                                             &ip4_addr, &ip6_addr);
          return SCTP_ERROR_NONE;
        }
     }
@@ -374,8 +377,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.
@@ -396,13 +398,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_main (),
-                                            &sctp_conn->sub_conn
-                                            [MAIN_SCTP_SUB_CONN_IDX].connection.
-                                            lcl_ip.ip4, &ipv4->address);
+               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;
              }
@@ -410,13 +415,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_main (),
-                                            &sctp_conn->sub_conn
-                                            [MAIN_SCTP_SUB_CONN_IDX].connection.
-                                            lcl_ip.ip6, &ipv6->address);
+               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;
              }
@@ -432,8 +440,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:
@@ -447,8 +455,8 @@ sctp_handle_init (sctp_header_t * sctp_hdr,
     }
 
   /* Reuse buffer to make init-ack and send */
-  sctp_prepare_initack_chunk (sctp_conn, MAIN_SCTP_SUB_CONN_IDX, 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;
 }
 
@@ -484,7 +492,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];
 
@@ -500,6 +507,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 */
@@ -510,7 +520,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);
 
@@ -536,7 +546,7 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
 
                sctp_sub_connection_add_ip4 (vlib_get_main (),
                                             &sctp_conn->sub_conn
-                                            [MAIN_SCTP_SUB_CONN_IDX].connection.
+                                            [SCTP_PRIMARY_PATH_IDX].connection.
                                             lcl_ip.ip4, &ipv4->address);
 
                break;
@@ -548,7 +558,7 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
 
                sctp_sub_connection_add_ip6 (vlib_get_main (),
                                             &sctp_conn->sub_conn
-                                            [MAIN_SCTP_SUB_CONN_IDX].connection.
+                                            [SCTP_PRIMARY_PATH_IDX].connection.
                                             lcl_ip.ip6, &ipv6->address);
 
                break;
@@ -558,16 +568,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:
@@ -585,7 +597,7 @@ sctp_handle_init_ack (sctp_header_t * sctp_hdr,
        }
     }
 
-  sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, &state_cookie);
+  sctp_prepare_cookie_echo_chunk (sctp_conn, idx, b0, 1);
 
   /* Start the T1_COOKIE timer */
   sctp_timer_set (sctp_conn, idx,
@@ -705,7 +717,21 @@ 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 idx, u8 is_gapping)
 {
-  if (is_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",
@@ -713,6 +739,7 @@ sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
       return 0;
     }
 
+  sctp_conn->ack_state += 1;
   if (sctp_conn->ack_state >= MAX_ENQUEABLE_SACKS)
     {
       SCTP_CONN_TRACKING_DBG
@@ -721,8 +748,6 @@ sctp_is_sack_delayable (sctp_connection_t * sctp_conn, u8 idx, u8 is_gapping)
       return 0;
     }
 
-  sctp_conn->ack_state += 1;
-
   return 1;
 }
 
@@ -734,7 +759,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[MAIN_SCTP_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);
 
@@ -753,7 +778,9 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
   /* 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;
@@ -762,8 +789,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);
 
@@ -806,12 +852,15 @@ sctp_handle_data (sctp_payload_data_chunk_t * sctp_data_chunk,
     }
   sctp_conn->last_rcvd_tsn = tsn;
 
-  *next0 = sctp_next_drop (sctp_conn->sub_conn[idx].c_is_ip4);
-
   SCTP_ADV_DBG ("POINTER_WITH_DATA = %p", b->data);
 
   if (!sctp_is_sack_delayable (sctp_conn, idx, is_gapping))
-    sctp_prepare_sack_chunk (sctp_conn, idx, b);
+    {
+      *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;
 
@@ -824,7 +873,7 @@ sctp_handle_cookie_echo (sctp_header_t * sctp_hdr,
                         sctp_connection_t * sctp_conn, u8 idx,
                         vlib_buffer_t * b0, u16 * next0)
 {
-  u32 now = sctp_time_now ();
+  u64 now = sctp_time_now ();
 
   sctp_cookie_echo_chunk_t *cookie_echo =
     (sctp_cookie_echo_chunk_t *) sctp_hdr;
@@ -832,15 +881,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)",
@@ -873,6 +924,7 @@ sctp_handle_cookie_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;
     }
 
@@ -984,8 +1036,8 @@ 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 =
@@ -1002,13 +1054,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_cwnd (new_sctp_conn);
-
                  if (session_stream_connect_notify
                      (&new_sctp_conn->sub_conn[idx].connection, 0))
                    {
@@ -1033,7 +1085,7 @@ 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;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
              next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
@@ -1153,6 +1205,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;
     }
 
@@ -1193,6 +1246,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;
     }
 
@@ -1207,8 +1261,7 @@ 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_timer_reset (sctp_conn, SCTP_PRIMARY_PATH_IDX, SCTP_TIMER_T2_SHUTDOWN);
 
   sctp_send_shutdown_complete (sctp_conn, idx, b0);
 
@@ -1230,6 +1283,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;
     }
 
@@ -1241,7 +1295,7 @@ sctp_handle_shutdown_complete (sctp_header_t * sctp_hdr,
 
   sctp_timer_reset (sctp_conn, idx, SCTP_TIMER_T2_SHUTDOWN);
 
-  stream_session_disconnect_notify (&sctp_conn->sub_conn[idx].connection);
+  session_transport_closing_notify (&sctp_conn->sub_conn[idx].connection);
 
   sctp_conn->state = SCTP_STATE_CLOSED;
 
@@ -1374,7 +1428,7 @@ sctp46_shutdown_phase_inline (vlib_main_t * vm,
               * hence we should never get to the "default" case below.
               */
            default:
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
              next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
@@ -1394,12 +1448,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];
@@ -1486,12 +1540,16 @@ 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) */
@@ -1525,6 +1583,7 @@ 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;
     }
 
@@ -1619,14 +1678,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;
@@ -1635,48 +1694,54 @@ 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].subconn_idx =
-           MAIN_SCTP_SUB_CONN_IDX;
-         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[MAIN_SCTP_SUB_CONN_IDX].PMTU =
-           sctp_listener->sub_conn[MAIN_SCTP_SUB_CONN_IDX].PMTU;
+         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;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
              next0 = sctp_next_drop (is_ip4);
              goto drop;
            }
@@ -1691,19 +1756,19 @@ 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_cwnd (child_conn);
-
              if (error0 == SCTP_ERROR_NONE)
                {
                  if (stream_session_accept
                      (&child_conn->
-                      sub_conn[MAIN_SCTP_SUB_CONN_IDX].connection,
+                      sub_conn[SCTP_PRIMARY_PATH_IDX].connection,
                       sctp_listener->
-                      sub_conn[MAIN_SCTP_SUB_CONN_IDX].c_s_index, 0))
+                      sub_conn[SCTP_PRIMARY_PATH_IDX].c_s_index, 0))
                    {
                      clib_warning ("session accept fail");
                      sctp_connection_cleanup (child_conn);
@@ -1724,8 +1789,7 @@ sctp46_listen_process_inline (vlib_main_t * vm,
            case OPERATION_ERROR:
              error0 =
                sctp_handle_operation_err (sctp_hdr, child_conn,
-                                          MAIN_SCTP_SUB_CONN_IDX, b0,
-                                          &next0);
+                                          SCTP_PRIMARY_PATH_IDX, b0, &next0);
              break;
            }
 
@@ -1734,10 +1798,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];
@@ -1885,7 +1949,7 @@ 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;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
              next0 = sctp_next_drop (is_ip4);
              goto done;
            }
@@ -2153,10 +2217,10 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
              clib_warning
                ("Received an unrecognized chunk; sending back OPERATION_ERROR chunk");
 
-             sctp_prepare_operation_error (sctp_conn, MAIN_SCTP_SUB_CONN_IDX,
+             sctp_prepare_operation_error (sctp_conn, SCTP_PRIMARY_PATH_IDX,
                                            b0, UNRECOGNIZED_CHUNK_TYPE);
 
-             error0 = SCTP_ERROR_UNKOWN_CHUNK;
+             error0 = SCTP_ERROR_UNKNOWN_CHUNK;
              next0 = sctp_next_output (is_ip4);
              goto done;
            }
@@ -2178,9 +2242,9 @@ sctp46_input_dispatcher (vlib_main_t * vm, vlib_node_runtime_t * node,
              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[MAIN_SCTP_SUB_CONN_IDX].
+                sctp_conn->sub_conn[SCTP_PRIMARY_PATH_IDX].
                 connection.s_index,
-                sctp_conn->sub_conn[MAIN_SCTP_SUB_CONN_IDX].
+                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));