always_inline void
sctp_enqueue_to_ip_lookup_i (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
- u8 is_ip4, u8 flush)
+ u8 is_ip4, u32 fib_index, u8 flush)
{
sctp_main_t *tm = vnet_get_sctp_main ();
u32 thread_index = vlib_get_thread_index ();
b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
b->error = 0;
- /* Default FIB for now */
- vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = fib_index;
+ vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
/* Send to IP lookup */
next_index = is_ip4 ? ip4_lookup_node.index : ip6_lookup_node.index;
always_inline void
sctp_enqueue_to_ip_lookup (vlib_main_t * vm, vlib_buffer_t * b, u32 bi,
- u8 is_ip4)
+ u8 is_ip4, u32 fib_index)
{
- sctp_enqueue_to_ip_lookup_i (vm, b, bi, is_ip4, 0);
+ sctp_enqueue_to_ip_lookup_i (vm, b, bi, is_ip4, fib_index, 0);
+ if (vm->thread_index == 0 && vlib_num_workers ())
+ session_flush_frames_main_thread (vm);
}
/**
void
sctp_prepare_initack_chunk (sctp_connection_t * sctp_conn, u8 idx,
vlib_buffer_t * b, ip4_address_t * ip4_addr,
- ip6_address_t * ip6_addr)
+ u8 add_ip4, ip6_address_t * ip6_addr, u8 add_ip6)
{
vlib_main_t *vm = vlib_get_main ();
sctp_ipv4_addr_param_t *ip4_param = 0;
u16 alloc_bytes =
sizeof (sctp_init_ack_chunk_t) + sizeof (sctp_state_cookie_param_t);
- if (PREDICT_TRUE (ip4_addr != NULL))
+ if (PREDICT_FALSE (add_ip4 == 1))
{
/* Create room for variable-length fields in the INIT_ACK chunk */
alloc_bytes += SCTP_IPV4_ADDRESS_TYPE_LENGTH;
}
- if (PREDICT_TRUE (ip6_addr != NULL))
+ if (PREDICT_FALSE (add_ip6 == 1))
{
/* Create room for variable-length fields in the INIT_ACK chunk */
alloc_bytes += SCTP_IPV6_ADDRESS_TYPE_LENGTH;
sctp_prepare_init_chunk (sctp_conn, idx, b);
sctp_push_ip_hdr (tm, &sctp_conn->sub_conn[idx], b);
- sctp_enqueue_to_ip_lookup (vm, b, bi, sctp_conn->sub_conn[idx].c_is_ip4);
+ sctp_enqueue_to_ip_lookup (vm, b, bi, sctp_conn->sub_conn[idx].c_is_ip4,
+ sctp_conn->sub_conn[idx].c_fib_index);
/* Start the T1_INIT timer */
sctp_timer_set (sctp_conn, idx, SCTP_TIMER_T1_INIT,
return 0;
}
+u32
+sctp_prepare_data_retransmit (sctp_connection_t * sctp_conn,
+ u8 idx,
+ u32 offset,
+ u32 max_deq_bytes, vlib_buffer_t ** b)
+{
+ sctp_main_t *tm = vnet_get_sctp_main ();
+ vlib_main_t *vm = vlib_get_main ();
+ int n_bytes = 0;
+ u32 bi, available_bytes, seg_size;
+ u8 *data;
+
+ ASSERT (sctp_conn->state >= SCTP_STATE_ESTABLISHED);
+ ASSERT (max_deq_bytes != 0);
+
+ /*
+ * Make sure we can retransmit something
+ */
+ available_bytes =
+ stream_session_tx_fifo_max_dequeue (&sctp_conn->sub_conn[idx].connection);
+ ASSERT (available_bytes >= offset);
+ available_bytes -= offset;
+ if (!available_bytes)
+ return 0;
+ max_deq_bytes = clib_min (sctp_conn->sub_conn[idx].cwnd, max_deq_bytes);
+ max_deq_bytes = clib_min (available_bytes, max_deq_bytes);
+
+ seg_size = max_deq_bytes;
+
+ /*
+ * Allocate and fill in buffer(s)
+ */
+
+ if (PREDICT_FALSE (sctp_get_free_buffer_index (tm, &bi)))
+ return 0;
+ *b = vlib_get_buffer (vm, bi);
+ data = sctp_init_buffer (vm, *b);
+
+ /* Easy case, buffer size greater than mss */
+ if (PREDICT_TRUE (seg_size <= tm->bytes_per_buffer))
+ {
+ n_bytes =
+ stream_session_peek_bytes (&sctp_conn->sub_conn[idx].connection, data,
+ offset, max_deq_bytes);
+ ASSERT (n_bytes == max_deq_bytes);
+ b[0]->current_length = n_bytes;
+ sctp_push_hdr_i (sctp_conn, *b, sctp_conn->state);
+ }
+
+ return n_bytes;
+}
+
void
sctp_data_retransmit (sctp_connection_t * sctp_conn)
{
- /* TODO: requires use of PEEK/SEND */
+ vlib_main_t *vm = vlib_get_main ();
+ vlib_buffer_t *b = 0;
+ u32 bi, n_bytes = 0;
+
SCTP_DBG_OUTPUT
("SCTP_CONN = %p, IDX = %u, S_INDEX = %u, C_INDEX = %u, sctp_conn->[...].LCL_PORT = %u, sctp_conn->[...].RMT_PORT = %u",
sctp_conn, idx, sctp_conn->sub_conn[idx].connection.s_index,
sctp_conn->sub_conn[idx].connection.lcl_port,
sctp_conn->sub_conn[idx].connection.rmt_port);
+ if (sctp_conn->state >= SCTP_STATE_ESTABLISHED)
+ {
+ return;
+ }
+
+ u8 idx = sctp_data_subconn_select (sctp_conn);
+
+ n_bytes =
+ sctp_prepare_data_retransmit (sctp_conn, idx, 0,
+ sctp_conn->sub_conn[idx].cwnd, &b);
+ if (n_bytes > 0)
+ SCTP_DBG_OUTPUT ("We have data (%u bytes) to retransmit", n_bytes);
+
+ bi = vlib_get_buffer_index (vm, b);
+
+ sctp_enqueue_to_output_now (vm, b, bi,
+ sctp_conn->sub_conn[idx].connection.is_ip4);
+
return;
}
{
clib_warning
("Trying to send an unrecognized chunk... something is really bad.");
- error0 = SCTP_ERROR_UNKOWN_CHUNK;
+ error0 = SCTP_ERROR_UNKNOWN_CHUNK;
next0 = SCTP_OUTPUT_NEXT_DROP;
goto done;
}
connection.rmt_port,
sctp_hdr->dst_port);
- error0 = SCTP_ERROR_UNKOWN_CHUNK;
+ error0 = SCTP_ERROR_UNKNOWN_CHUNK;
next0 = SCTP_OUTPUT_NEXT_DROP;
goto done;
}
sctp_chunk_to_string (chunk_type),
sctp_state_to_string (sctp_conn->state));
- error0 = SCTP_ERROR_UNKOWN_CHUNK;
+ error0 = SCTP_ERROR_UNKNOWN_CHUNK;
next0 = SCTP_OUTPUT_NEXT_DROP;
goto done;
}
vnet_buffer (b0)->sw_if_index[VLIB_RX] = 0;
- vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ sctp_conn->sub_conn[idx].c_fib_index;
b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;