*/
#include <vnet/tcp/tcp.h>
+#include <vnet/tcp/tcp_inlines.h>
#include <math.h>
typedef enum _tcp_output_next
u32 available_space, wnd;
i32 observed_wnd;
- ASSERT (tc->rcv_opts.mss < transport_rx_fifo_size (&tc->connection));
-
/*
* Figure out how much space we have available
*/
return tc->rcv_wnd >> tc->rcv_wscale;
}
-/**
- * Write TCP options to segment.
- */
-static u32
-tcp_options_write (u8 * data, tcp_options_t * opts)
-{
- u32 opts_len = 0;
- u32 buf, seq_len = 4;
-
- if (tcp_opts_mss (opts))
- {
- *data++ = TCP_OPTION_MSS;
- *data++ = TCP_OPTION_LEN_MSS;
- buf = clib_host_to_net_u16 (opts->mss);
- clib_memcpy_fast (data, &buf, sizeof (opts->mss));
- data += sizeof (opts->mss);
- opts_len += TCP_OPTION_LEN_MSS;
- }
-
- if (tcp_opts_wscale (opts))
- {
- *data++ = TCP_OPTION_WINDOW_SCALE;
- *data++ = TCP_OPTION_LEN_WINDOW_SCALE;
- *data++ = opts->wscale;
- opts_len += TCP_OPTION_LEN_WINDOW_SCALE;
- }
-
- if (tcp_opts_sack_permitted (opts))
- {
- *data++ = TCP_OPTION_SACK_PERMITTED;
- *data++ = TCP_OPTION_LEN_SACK_PERMITTED;
- opts_len += TCP_OPTION_LEN_SACK_PERMITTED;
- }
-
- if (tcp_opts_tstamp (opts))
- {
- *data++ = TCP_OPTION_TIMESTAMP;
- *data++ = TCP_OPTION_LEN_TIMESTAMP;
- buf = clib_host_to_net_u32 (opts->tsval);
- clib_memcpy_fast (data, &buf, sizeof (opts->tsval));
- data += sizeof (opts->tsval);
- buf = clib_host_to_net_u32 (opts->tsecr);
- clib_memcpy_fast (data, &buf, sizeof (opts->tsecr));
- data += sizeof (opts->tsecr);
- opts_len += TCP_OPTION_LEN_TIMESTAMP;
- }
-
- if (tcp_opts_sack (opts))
- {
- int i;
-
- if (opts->n_sack_blocks != 0)
- {
- *data++ = TCP_OPTION_SACK_BLOCK;
- *data++ = 2 + opts->n_sack_blocks * TCP_OPTION_LEN_SACK_BLOCK;
- for (i = 0; i < opts->n_sack_blocks; i++)
- {
- buf = clib_host_to_net_u32 (opts->sacks[i].start);
- clib_memcpy_fast (data, &buf, seq_len);
- data += seq_len;
- buf = clib_host_to_net_u32 (opts->sacks[i].end);
- clib_memcpy_fast (data, &buf, seq_len);
- data += seq_len;
- }
- opts_len += 2 + opts->n_sack_blocks * TCP_OPTION_LEN_SACK_BLOCK;
- }
- }
-
- /* Terminate TCP options */
- if (opts_len % 4)
- {
- *data++ = TCP_OPTION_EOL;
- opts_len += TCP_OPTION_LEN_EOL;
- }
-
- /* Pad with zeroes to a u32 boundary */
- while (opts_len % 4)
- {
- *data++ = TCP_OPTION_NOOP;
- opts_len += TCP_OPTION_LEN_NOOP;
- }
- return opts_len;
-}
-
static int
tcp_make_syn_options (tcp_connection_t * tc, tcp_options_t * opts)
{
/**
* Convert buffer to FIN-ACK
*/
-void
+static void
tcp_make_fin (tcp_connection_t * tc, vlib_buffer_t * b)
{
tcp_make_ack_i (tc, b, TCP_STATE_ESTABLISHED, TCP_FLAG_FIN | TCP_FLAG_ACK);
/**
* Convert buffer to SYN-ACK
*/
-void
+static void
tcp_make_synack (tcp_connection_t * tc, vlib_buffer_t * b)
{
tcp_options_t _snd_opts, *snd_opts = &_snd_opts;
th->checksum = tcp_compute_checksum (tc, b);
}
-always_inline void
-tcp_enqueue_to_ip_lookup_i (tcp_worker_ctx_t * wrk, vlib_buffer_t * b, u32 bi,
- u8 is_ip4, u32 fib_index, u8 flush)
+static void
+tcp_enqueue_to_ip_lookup (tcp_worker_ctx_t * wrk, vlib_buffer_t * b, u32 bi,
+ u8 is_ip4, u32 fib_index)
{
+ tcp_main_t *tm = &tcp_main;
vlib_main_t *vm = wrk->vm;
- u32 *to_next, next_index;
- vlib_frame_t *f;
b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
b->error = 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;
tcp_trajectory_add_start (b, 1);
- f = wrk->ip_lookup_tx_frames[!is_ip4];
- if (!f)
- {
- f = vlib_get_frame_to_node (vm, next_index);
- ASSERT (f);
- wrk->ip_lookup_tx_frames[!is_ip4] = f;
- }
+ session_add_pending_tx_buffer (vm->thread_index, bi,
+ tm->ipl_next_node[!is_ip4]);
- to_next = vlib_frame_vector_args (f);
- to_next[f->n_vectors] = bi;
- f->n_vectors += 1;
- if (flush || f->n_vectors == VLIB_FRAME_SIZE)
- {
- vlib_put_frame_to_node (vm, next_index, f);
- wrk->ip_lookup_tx_frames[!is_ip4] = 0;
- }
-}
-
-static void
-tcp_enqueue_to_ip_lookup_now (tcp_worker_ctx_t * wrk, vlib_buffer_t * b,
- u32 bi, u8 is_ip4, u32 fib_index)
-{
- tcp_enqueue_to_ip_lookup_i (wrk, b, bi, is_ip4, fib_index, 1);
-}
-
-static void
-tcp_enqueue_to_ip_lookup (tcp_worker_ctx_t * wrk, vlib_buffer_t * b, u32 bi,
- u8 is_ip4, u32 fib_index)
-{
- tcp_enqueue_to_ip_lookup_i (wrk, b, bi, is_ip4, fib_index, 0);
- if (wrk->vm->thread_index == 0 && vlib_num_workers ())
- session_flush_frames_main_thread (wrk->vm);
+ if (vm->thread_index == 0 && vlib_num_workers ())
+ session_queue_run_on_main_thread (wrk->vm);
}
static void
tcp_enqueue_to_output (tcp_worker_ctx_t * wrk, vlib_buffer_t * b, u32 bi,
u8 is_ip4)
{
- session_type_t st;
-
b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
b->error = 0;
- st = session_type_from_proto_and_ip (TRANSPORT_PROTO_TCP, is_ip4);
- session_add_pending_tx_buffer (st, wrk->vm->thread_index, bi);
+ session_add_pending_tx_buffer (wrk->vm->thread_index, bi,
+ wrk->tco_next_node[!is_ip4]);
}
#endif /* CLIB_MARCH_VARIANT */
ASSERT (!bogus);
}
- tcp_enqueue_to_ip_lookup_now (wrk, b, bi, is_ip4, fib_index);
+ tcp_enqueue_to_ip_lookup (wrk, b, bi, is_ip4, fib_index);
TCP_EVT (TCP_EVT_RST_SENT, tc);
vlib_node_increment_counter (vm, tcp_node_index (output, tc->c_is_ip4),
TCP_ERROR_RST_SENT, 1);
tc->snd_opts_len = tcp_make_options (tc, &tc->snd_opts, tc->state);
tcp_hdr_opts_len = tc->snd_opts_len + sizeof (tcp_header_t);
- advertise_wnd = tcp_window_to_advertise (tc, TCP_STATE_ESTABLISHED);
+ advertise_wnd = tc->rcv_wnd >> tc->rcv_wscale;
flags = TCP_FLAG_RST;
th = vlib_buffer_push_tcp (b, tc->c_lcl_port, tc->c_rmt_port, tc->snd_nxt,
tc->rcv_nxt, tcp_hdr_opts_len, flags,
/* Just sent new data, enable retransmit */
tcp_retransmit_timer_update (tc);
+ return;
+
update_scheduler:
- if (transport_connection_is_descheduled (&tc->connection))
+ if (tcp_is_descheduled (tc))
transport_connection_reschedule (&tc->connection);
}