diff options
Diffstat (limited to 'src/vnet/tcp')
-rw-r--r-- | src/vnet/tcp/tcp.c | 130 | ||||
-rw-r--r-- | src/vnet/tcp/tcp.h | 22 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_bt.c | 2 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_cli.c | 18 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_cubic.c | 26 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_debug.c | 4 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_debug.h | 62 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_error.def | 1 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_format.c | 89 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_inlines.h | 44 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_input.c | 550 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_newreno.c | 43 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_output.c | 307 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_packet.h | 97 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_pg.c | 181 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_sack.c | 21 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_sack.h | 2 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_syn_filter4.c | 6 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_timer.h | 53 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_types.h | 2 |
20 files changed, 949 insertions, 711 deletions
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c index d4b1d77f556..efc72a227e8 100644 --- a/src/vnet/tcp/tcp.c +++ b/src/vnet/tcp/tcp.c @@ -25,6 +25,8 @@ #include <vnet/dpo/load_balance.h> #include <math.h> +#include <vlib/stats/stats.h> + tcp_main_t tcp_main; typedef struct @@ -71,6 +73,10 @@ tcp_add_del_adjacency (tcp_connection_t * tc, u8 is_add) static void tcp_cc_init (tcp_connection_t * tc) { + /* As per RFC 6582 initialize "recover" to iss */ + if (tcp_opts_sack_permitted (&tc->rcv_opts)) + tc->snd_congestion = tc->iss; + tc->cc_algo->init (tc); } @@ -108,7 +114,7 @@ tcp_cc_algo_new_type (const tcp_cc_algorithm_t * vft) } static u32 -tcp_connection_bind (u32 session_index, transport_endpoint_t * lcl) +tcp_connection_bind (u32 session_index, transport_endpoint_cfg_t *lcl) { tcp_main_t *tm = &tcp_main; tcp_connection_t *listener; @@ -143,7 +149,7 @@ tcp_connection_bind (u32 session_index, transport_endpoint_t * lcl) } static u32 -tcp_session_bind (u32 session_index, transport_endpoint_t * tep) +tcp_session_bind (u32 session_index, transport_endpoint_cfg_t *tep) { return tcp_connection_bind (session_index, tep); } @@ -184,8 +190,7 @@ tcp_session_get_listener (u32 listener_index) static tcp_connection_t * tcp_half_open_connection_alloc (void) { - ASSERT (vlib_get_thread_index () == 0); - return tcp_connection_alloc (0); + return tcp_connection_alloc (transport_cl_thread ()); } /** @@ -195,7 +200,8 @@ tcp_half_open_connection_alloc (void) static void tcp_half_open_connection_free (tcp_connection_t * tc) { - ASSERT (vlib_get_thread_index () == 0); + ASSERT (vlib_get_thread_index () == tc->c_thread_index || + vlib_thread_is_main_w_barrier ()); return tcp_connection_free (tc); } @@ -236,8 +242,8 @@ tcp_connection_cleanup (tcp_connection_t * tc) /* Cleanup local endpoint if this was an active connect */ if (!(tc->cfg_flags & TCP_CFG_F_NO_ENDPOINT)) - transport_endpoint_cleanup (TRANSPORT_PROTO_TCP, &tc->c_lcl_ip, - tc->c_lcl_port); + transport_release_local_endpoint (TRANSPORT_PROTO_TCP, &tc->c_lcl_ip, + tc->c_lcl_port); /* Check if connection is not yet fully established */ if (tc->state == TCP_STATE_SYN_SENT) @@ -289,7 +295,7 @@ tcp_connection_alloc (u8 thread_index) tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index); tcp_connection_t *tc; - pool_get (wrk->connections, tc); + pool_get_aligned_safe (wrk->connections, tc, CLIB_CACHE_LINE_BYTES); clib_memset (tc, 0, sizeof (*tc)); tc->c_c_index = tc - wrk->connections; tc->c_thread_index = thread_index; @@ -306,12 +312,12 @@ tcp_connection_alloc_w_base (u8 thread_index, tcp_connection_t **base) if ((*base)->c_thread_index == thread_index) { u32 base_index = (*base)->c_c_index; - pool_get (wrk->connections, tc); + pool_get_aligned_safe (wrk->connections, tc, CLIB_CACHE_LINE_BYTES); *base = tcp_connection_get (base_index, thread_index); } else { - pool_get (wrk->connections, tc); + pool_get_aligned_safe (wrk->connections, tc, CLIB_CACHE_LINE_BYTES); } clib_memcpy_fast (tc, *base, sizeof (*tc)); tc->c_c_index = tc - wrk->connections; @@ -404,8 +410,8 @@ tcp_connection_close (tcp_connection_t * tc) case TCP_STATE_CLOSE_WAIT: if (!transport_max_tx_dequeue (&tc->connection)) { - tcp_send_fin (tc); tcp_connection_timers_reset (tc); + tcp_send_fin (tc); tcp_connection_set_state (tc, TCP_STATE_LAST_ACK); tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time); @@ -485,6 +491,14 @@ tcp_session_reset (u32 conn_index, u32 thread_index) { tcp_connection_t *tc; tc = tcp_connection_get (conn_index, thread_index); + + /* For half-opens just cleanup */ + if (tc->state == TCP_STATE_SYN_SENT) + { + tcp_connection_cleanup (tc); + return; + } + tcp_send_reset (tc); tcp_connection_timers_reset (tc); tcp_cong_recovery_off (tc); @@ -760,15 +774,18 @@ tcp_connection_init_vars (tcp_connection_t * tc) } static int -tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr, - u16 * lcl_port, u8 is_ip4) +tcp_alloc_custom_local_endpoint (ip46_address_t *lcl_addr, u16 *lcl_port, + transport_endpoint_cfg_t *rmt) { + tcp_main_t *tm = vnet_get_tcp_main (); int index, port; - if (is_ip4) + + if (rmt->is_ip4) { index = tm->last_v4_addr_rotor++; if (tm->last_v4_addr_rotor >= vec_len (tcp_cfg.ip4_src_addrs)) tm->last_v4_addr_rotor = 0; + clib_memset (lcl_addr, 0, sizeof (*lcl_addr)); lcl_addr->ip4.as_u32 = tcp_cfg.ip4_src_addrs[index].as_u32; } else @@ -779,7 +796,7 @@ tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr, clib_memcpy_fast (&lcl_addr->ip6, &tcp_cfg.ip6_src_addrs[index], sizeof (ip6_address_t)); } - port = transport_alloc_local_port (TRANSPORT_PROTO_TCP, lcl_addr); + port = transport_alloc_local_port (TRANSPORT_PROTO_TCP, lcl_addr, rmt); if (port < 1) return SESSION_E_NOPORT; *lcl_port = port; @@ -789,7 +806,6 @@ tcp_alloc_custom_local_endpoint (tcp_main_t * tm, ip46_address_t * lcl_addr, static int tcp_session_open (transport_endpoint_cfg_t * rmt) { - tcp_main_t *tm = vnet_get_tcp_main (); tcp_connection_t *tc; ip46_address_t lcl_addr; u16 lcl_port; @@ -800,27 +816,13 @@ tcp_session_open (transport_endpoint_cfg_t * rmt) */ if ((rmt->is_ip4 && vec_len (tcp_cfg.ip4_src_addrs)) || (!rmt->is_ip4 && vec_len (tcp_cfg.ip6_src_addrs))) - rv = tcp_alloc_custom_local_endpoint (tm, &lcl_addr, &lcl_port, - rmt->is_ip4); + rv = tcp_alloc_custom_local_endpoint (&lcl_addr, &lcl_port, rmt); else - rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_TCP, - rmt, &lcl_addr, &lcl_port); + rv = transport_alloc_local_endpoint (TRANSPORT_PROTO_TCP, rmt, &lcl_addr, + &lcl_port); if (rv) - { - if (rv != SESSION_E_PORTINUSE) - return rv; - - if (session_lookup_connection (rmt->fib_index, &lcl_addr, &rmt->ip, - lcl_port, rmt->port, TRANSPORT_PROTO_TCP, - rmt->is_ip4)) - return SESSION_E_PORTINUSE; - - /* 5-tuple is available so increase lcl endpoint refcount and proceed - * with connection allocation */ - transport_share_local_endpoint (TRANSPORT_PROTO_TCP, &lcl_addr, - lcl_port); - } + return rv; /* * Create connection and send SYN @@ -829,7 +831,7 @@ tcp_session_open (transport_endpoint_cfg_t * rmt) ip_copy (&tc->c_rmt_ip, &rmt->ip, rmt->is_ip4); ip_copy (&tc->c_lcl_ip, &lcl_addr, rmt->is_ip4); tc->c_rmt_port = rmt->port; - tc->c_lcl_port = clib_host_to_net_u16 (lcl_port); + tc->c_lcl_port = lcl_port; tc->c_is_ip4 = rmt->is_ip4; tc->c_proto = TRANSPORT_PROTO_TCP; tc->c_fib_index = rmt->fib_index; @@ -1221,7 +1223,6 @@ tcp_timer_waitclose_handler (tcp_connection_t * tc) } } -/* *INDENT-OFF* */ static timer_expiration_handler *timer_expiration_handlers[TCP_N_TIMERS] = { tcp_timer_retransmit_handler, @@ -1229,7 +1230,6 @@ static timer_expiration_handler *timer_expiration_handlers[TCP_N_TIMERS] = tcp_timer_waitclose_handler, tcp_timer_retransmit_syn_handler, }; -/* *INDENT-ON* */ static void tcp_dispatch_pending_timers (tcp_worker_ctx_t * wrk) @@ -1337,7 +1337,6 @@ tcp_session_app_rx_evt (transport_connection_t *conn) return 0; } -/* *INDENT-OFF* */ const static transport_proto_vft_t tcp_proto = { .enable = vnet_tcp_enable_disable, .start_listen = tcp_session_bind, @@ -1368,7 +1367,6 @@ const static transport_proto_vft_t tcp_proto = { .service_type = TRANSPORT_SERVICE_VC, }, }; -/* *INDENT-ON* */ void tcp_connection_tx_pacer_update (tcp_connection_t * tc) @@ -1437,7 +1435,8 @@ tcp_expired_timers_dispatch (u32 * expired_timers) clib_fifo_add (wrk->pending_timers, expired_timers, n_expired); - max_loops = clib_max (1, 0.5 * TCP_TIMER_TICK * wrk->vm->loops_per_second); + max_loops = + clib_max ((u32) 0.5 * TCP_TIMER_TICK * wrk->vm->loops_per_second, 1); max_per_loop = clib_max ((n_left + n_expired) / max_loops, 10); max_per_loop = clib_min (max_per_loop, VLIB_FRAME_SIZE); wrk->max_timers_per_loop = clib_max (n_left ? wrk->max_timers_per_loop : 0, @@ -1457,6 +1456,51 @@ tcp_initialize_iss_seed (tcp_main_t * tm) tm->iss_seed.second = random_u64 (&time_now); } +static void +tcp_stats_collector_fn (vlib_stats_collector_data_t *d) +{ + tcp_main_t *tm = vnet_get_tcp_main (); + counter_t **counters = d->entry->data; + counter_t *cb = counters[0]; + tcp_wrk_stats_t acc = {}; + tcp_worker_ctx_t *wrk; + + vec_foreach (wrk, tm->wrk_ctx) + { +#define _(name, type, str) acc.name += wrk->stats.name; + foreach_tcp_wrk_stat +#undef _ + } + +#define _(name, type, str) cb[TCP_STAT_##name] = acc.name; + foreach_tcp_wrk_stat +#undef _ +} + +static void +tcp_counters_init (tcp_main_t *tm) +{ + vlib_stats_collector_reg_t r = {}; + u32 idx; + + if (tm->counters_init) + return; + + r.entry_index = idx = vlib_stats_add_counter_vector ("/sys/tcp"); + r.collect_fn = tcp_stats_collector_fn; + vlib_stats_validate (idx, 0, TCP_STAT_no_buffer); + +#define _(name, type, str) \ + vlib_stats_add_symlink (idx, TCP_STAT_##name, "/sys/tcp/%s", \ + CLIB_STRING_MACRO (name)); + foreach_tcp_wrk_stat +#undef _ + + vlib_stats_register_collector_fn (&r); + + tm->counters_init = 1; +} + static clib_error_t * tcp_main_enable (vlib_main_t * vm) { @@ -1533,10 +1577,8 @@ tcp_main_enable (vlib_main_t * vm) tm->bytes_per_buffer = vlib_buffer_get_default_data_size (vm); tm->cc_last_type = TCP_CC_LAST; - tm->ipl_next_node[0] = vlib_node_get_next (vm, session_queue_node.index, - ip4_lookup_node.index); - tm->ipl_next_node[1] = vlib_node_get_next (vm, session_queue_node.index, - ip6_lookup_node.index); + tcp_counters_init (tm); + return error; } diff --git a/src/vnet/tcp/tcp.h b/src/vnet/tcp/tcp.h index 3ddd324873b..2362a8bb857 100644 --- a/src/vnet/tcp/tcp.h +++ b/src/vnet/tcp/tcp.h @@ -66,6 +66,13 @@ typedef struct tcp_wrk_stats_ #undef _ } tcp_wrk_stats_t; +typedef enum +{ +#define _(name, type, str) TCP_STAT_##name, + foreach_tcp_wrk_stat +#undef _ +} tcp_wrk_stats_e; + typedef struct tcp_free_req_ { clib_time_type_t free_time; @@ -215,9 +222,6 @@ typedef struct _tcp_main /** vlib buffer size */ u32 bytes_per_buffer; - /** Session layer edge indices to ip lookup (syns, rst) */ - u32 ipl_next_node[2]; - /** Dispatch table by state and flags */ tcp_lookup_dispatch_t dispatch_table[TCP_N_STATES][64]; @@ -236,6 +240,9 @@ typedef struct _tcp_main /** Flag that indicates if stack is on or off */ u8 is_enabled; + /** Set if counters on stats segment initialized */ + u8 counters_init; + /** Flag that indicates if v4 punting is enabled */ u8 punt_unknown4; @@ -268,6 +275,10 @@ extern vlib_node_registration_t tcp4_rcv_process_node; extern vlib_node_registration_t tcp6_rcv_process_node; extern vlib_node_registration_t tcp4_listen_node; extern vlib_node_registration_t tcp6_listen_node; +extern vlib_node_registration_t tcp4_input_nolookup_node; +extern vlib_node_registration_t tcp6_input_nolookup_node; +extern vlib_node_registration_t tcp4_drop_node; +extern vlib_node_registration_t tcp6_drop_node; #define tcp_cfg tcp_main.cfg #define tcp_node_index(node_id, is_ip4) \ @@ -313,8 +324,8 @@ u32 tcp_snd_space (tcp_connection_t * tc); int tcp_fastrecovery_prr_snd_space (tcp_connection_t * tc); void tcp_reschedule (tcp_connection_t * tc); fib_node_index_t tcp_lookup_rmt_in_fib (tcp_connection_t * tc); -u32 tcp_session_push_header (transport_connection_t * tconn, - vlib_buffer_t * b); +u32 tcp_session_push_header (transport_connection_t *tconn, vlib_buffer_t **b, + u32 n_bufs); int tcp_session_custom_tx (void *conn, transport_send_params_t * sp); void tcp_connection_timers_init (tcp_connection_t * tc); @@ -327,6 +338,7 @@ void tcp_connection_tx_pacer_reset (tcp_connection_t * tc, u32 window, void tcp_program_cleanup (tcp_worker_ctx_t * wrk, tcp_connection_t * tc); void tcp_check_gso (tcp_connection_t *tc); +int tcp_buffer_make_reset (vlib_main_t *vm, vlib_buffer_t *b, u8 is_ip4); void tcp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add); int tcp_configure_v4_source_address_range (vlib_main_t * vm, ip4_address_t * start, diff --git a/src/vnet/tcp/tcp_bt.c b/src/vnet/tcp/tcp_bt.c index 67e9a14ceda..3cb57a550de 100644 --- a/src/vnet/tcp/tcp_bt.c +++ b/src/vnet/tcp/tcp_bt.c @@ -638,11 +638,9 @@ tcp_bt_flush_samples (tcp_connection_t * tc) vec_validate (samples, pool_elts (bt->samples) - 1); vec_reset_length (samples); - /* *INDENT-OFF* */ pool_foreach (bts, bt->samples) { vec_add1 (samples, bts - bt->samples); } - /* *INDENT-ON* */ vec_foreach (si, samples) { diff --git a/src/vnet/tcp/tcp_cli.c b/src/vnet/tcp/tcp_cli.c index c7b5c0b441e..b04c0bdc0cf 100644 --- a/src/vnet/tcp/tcp_cli.c +++ b/src/vnet/tcp/tcp_cli.c @@ -411,6 +411,8 @@ tcp_configure_v4_source_address_range (vlib_main_t * vm, return VNET_API_ERROR_NEXT_HOP_NOT_IN_FIB; sw_if_index = fib_entry_get_resolving_interface (fei); + if (sw_if_index == (u32) ~0) + return VNET_API_ERROR_NO_MATCHING_INTERFACE; /* Configure proxy arp across the range */ rv = ip4_neighbor_proxy_add (fib_index, start, end); @@ -431,7 +433,7 @@ tcp_configure_v4_source_address_range (vlib_main_t * vm, /* Add local adjacencies for the range */ - receive_dpo_add_or_lock (DPO_PROTO_IP4, ~0 /* sw_if_index */ , + receive_dpo_add_or_lock (DPO_PROTO_IP4, sw_if_index /* sw_if_index */, NULL, &dpo); prefix.fp_len = 32; prefix.fp_proto = FIB_PROTOCOL_IP4; @@ -506,7 +508,7 @@ tcp_configure_v6_source_address_range (vlib_main_t * vm, ip6_neighbor_proxy_add (sw_if_index, start); /* Add a receive adjacency for this address */ - receive_dpo_add_or_lock (DPO_PROTO_IP6, ~0 /* sw_if_index */ , + receive_dpo_add_or_lock (DPO_PROTO_IP6, sw_if_index /* sw_if_index */, NULL, &dpo); fib_table_entry_special_dpo_update (fib_index, @@ -611,14 +613,12 @@ tcp_src_address_fn (vlib_main_t * vm, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (tcp_src_address_command, static) = { .path = "tcp src-address", .short_help = "tcp src-address <ip-addr> [- <ip-addr>] add src address range", .function = tcp_src_address_fn, }; -/* *INDENT-ON* */ static u8 * tcp_scoreboard_dump_trace (u8 * s, sack_scoreboard_t * sb) @@ -674,14 +674,12 @@ tcp_show_scoreboard_trace_fn (vlib_main_t * vm, unformat_input_t * input, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (tcp_show_scoreboard_trace_command, static) = { .path = "show tcp scoreboard trace", .short_help = "show tcp scoreboard trace <connection>", .function = tcp_show_scoreboard_trace_fn, }; -/* *INDENT-ON* */ u8 * tcp_scoreboard_replay (u8 * s, tcp_connection_t * tc, u8 verbose) @@ -799,14 +797,12 @@ tcp_scoreboard_trace_fn (vlib_main_t * vm, unformat_input_t * input, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (tcp_replay_scoreboard_command, static) = { .path = "tcp replay scoreboard", .short_help = "tcp replay scoreboard <connection>", .function = tcp_scoreboard_trace_fn, }; -/* *INDENT-ON* */ static clib_error_t * show_tcp_punt_fn (vlib_main_t * vm, unformat_input_t * input, @@ -822,14 +818,12 @@ show_tcp_punt_fn (vlib_main_t * vm, unformat_input_t * input, tm->punt_unknown6 ? "enabled" : "disabled"); return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_tcp_punt_command, static) = { .path = "show tcp punt", .short_help = "show tcp punt", .function = show_tcp_punt_fn, }; -/* *INDENT-ON* */ static clib_error_t * show_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input, @@ -861,14 +855,12 @@ show_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_tcp_stats_command, static) = { .path = "show tcp stats", .short_help = "show tcp stats", .function = show_tcp_stats_fn, }; -/* *INDENT-ON* */ static clib_error_t * clear_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input, @@ -891,14 +883,12 @@ clear_tcp_stats_fn (vlib_main_t * vm, unformat_input_t * input, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (clear_tcp_stats_command, static) = { .path = "clear tcp stats", .short_help = "clear tcp stats", .function = clear_tcp_stats_fn, }; -/* *INDENT-ON* */ uword unformat_tcp_cc_algo (unformat_input_t * input, va_list * va) diff --git a/src/vnet/tcp/tcp_cubic.c b/src/vnet/tcp/tcp_cubic.c index cc2ffeae9f0..cf2b9a17d18 100644 --- a/src/vnet/tcp/tcp_cubic.c +++ b/src/vnet/tcp/tcp_cubic.c @@ -141,7 +141,7 @@ cubic_cwnd_accumulate (tcp_connection_t * tc, u32 thresh, u32 bytes_acked) tc->cwnd_acc_bytes = 0; } - tcp_cwnd_accumulate (tc, thresh, tc->bytes_acked); + tcp_cwnd_accumulate (tc, thresh, bytes_acked); } static void @@ -158,7 +158,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) if (tcp_in_slowstart (tc)) { - tc->cwnd += tc->bytes_acked; + tc->cwnd += rs->delivered; return; } @@ -169,7 +169,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) w_aimd = (u64) W_est (cd, t, rtt_sec) * tc->snd_mss; if (w_cubic < w_aimd) { - cubic_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked); + cubic_cwnd_accumulate (tc, tc->cwnd, rs->delivered); } else { @@ -195,7 +195,7 @@ cubic_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) /* Practically we can't increment so just inflate threshold */ thresh = 50 * tc->cwnd; } - cubic_cwnd_accumulate (tc, thresh, tc->bytes_acked); + cubic_cwnd_accumulate (tc, thresh, rs->delivered); } } @@ -232,6 +232,23 @@ cubic_unformat_config (unformat_input_t * input) return 1; } +void +cubic_event (tcp_connection_t *tc, tcp_cc_event_t evt) +{ + cubic_data_t *cd; + f64 now; + + if (evt != TCP_CC_EVT_START_TX) + return; + + /* App was idle so update t_start to avoid artificially + * inflating cwnd if nothing recently sent and acked */ + cd = (cubic_data_t *) tcp_cc_data (tc); + now = cubic_time (tc->c_thread_index); + if (now > tc->mrtt_us + 1) + cd->t_start = now; +} + const static tcp_cc_algorithm_t tcp_cubic = { .name = "cubic", .unformat_cfg = cubic_unformat_config, @@ -240,6 +257,7 @@ const static tcp_cc_algorithm_t tcp_cubic = { .recovered = cubic_recovered, .rcv_ack = cubic_rcv_ack, .rcv_cong_ack = newreno_rcv_cong_ack, + .event = cubic_event, .init = cubic_conn_init, }; diff --git a/src/vnet/tcp/tcp_debug.c b/src/vnet/tcp/tcp_debug.c index e3d7452b591..ab466f30efb 100644 --- a/src/vnet/tcp/tcp_debug.c +++ b/src/vnet/tcp/tcp_debug.c @@ -26,7 +26,7 @@ tcp_evt_track_register (elog_track_t * et) if (fl_len) { track_index = tdm->free_track_indices[fl_len - 1]; - _vec_len (tdm->free_track_indices) -= 1; + vec_dec_len (tdm->free_track_indices, 1); et->track_index_plus_one = track_index + 1; } else @@ -134,14 +134,12 @@ done: return error; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (tcp_debug_command, static) = { .path = "tcp debug", .short_help = "tcp [show] [debug group <N> level <N>]", .function = tcp_debug_fn, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/src/vnet/tcp/tcp_debug.h b/src/vnet/tcp/tcp_debug.h index 1202f7f44d3..04e921cd601 100644 --- a/src/vnet/tcp/tcp_debug.h +++ b/src/vnet/tcp/tcp_debug.h @@ -17,13 +17,18 @@ #define SRC_VNET_TCP_TCP_DEBUG_H_ #include <vlib/vlib.h> +#include <vpp/vnet/config.h> /** * Build debugging infra unconditionally. Debug components controlled via * debug configuration. Comes with some overhead so it's not recommended for * production/performance scenarios. Takes priority over TCP_DEBUG_ENABLE. */ +#ifdef VPP_TCP_DEBUG_ALWAYS +#define TCP_DEBUG_ALWAYS (1) +#else #define TCP_DEBUG_ALWAYS (0) +#endif /** * Build debugging infra only if enabled. Debug components controlled via * macros that follow. @@ -867,11 +872,12 @@ if (TCP_DEBUG_CC > 1) \ */ #if TCP_DEBUG_CS || TCP_DEBUG_ALWAYS -#define STATS_INTERVAL 1 +#define STATS_INTERVAL 0.001 -#define tcp_cc_time_to_print_stats(_tc) \ - _tc->c_cc_stat_tstamp + STATS_INTERVAL < tcp_time_now() \ - || tcp_in_fastrecovery (_tc) \ +#define tcp_cc_time_to_print_stats(_tc) \ + _tc->c_cc_stat_tstamp + STATS_INTERVAL < \ + tcp_time_now_us (_tc->c_thread_index) || \ + tcp_in_fastrecovery (_tc) #define TCP_EVT_CC_RTO_STAT_PRINT(_tc) \ { \ @@ -887,14 +893,14 @@ if (TCP_DEBUG_CC > 1) \ ed->data[3] = _tc->rttvar; \ } -#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \ -{ \ -if (tcp_cc_time_to_print_stats (_tc)) \ -{ \ - TCP_EVT_CC_RTO_STAT_PRINT (_tc); \ - _tc->c_cc_stat_tstamp = tcp_time_now (); \ -} \ -} +#define TCP_EVT_CC_RTO_STAT_HANDLER(_tc, ...) \ + { \ + if (tcp_cc_time_to_print_stats (_tc)) \ + { \ + TCP_EVT_CC_RTO_STAT_PRINT (_tc); \ + _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \ + } \ + } #define TCP_EVT_CC_SND_STAT_PRINT(_tc) \ { \ @@ -911,14 +917,14 @@ if (tcp_cc_time_to_print_stats (_tc)) \ ed->data[3] = _tc->snd_rxt_bytes; \ } -#define TCP_EVT_CC_SND_STAT_HANDLER(_tc, ...) \ -{ \ -if (tcp_cc_time_to_print_stats (_tc)) \ -{ \ - TCP_EVT_CC_SND_STAT_PRINT(_tc); \ - _tc->c_cc_stat_tstamp = tcp_time_now (); \ -} \ -} +#define TCP_EVT_CC_SND_STAT_HANDLER(_tc, ...) \ + { \ + if (tcp_cc_time_to_print_stats (_tc)) \ + { \ + TCP_EVT_CC_SND_STAT_PRINT (_tc); \ + _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \ + } \ + } #define TCP_EVT_CC_STAT_PRINT(_tc) \ { \ @@ -937,14 +943,14 @@ if (tcp_cc_time_to_print_stats (_tc)) \ TCP_EVT_CC_SND_STAT_PRINT (_tc); \ } -#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \ -{ \ -if (tcp_cc_time_to_print_stats (_tc)) \ -{ \ - TCP_EVT_CC_STAT_PRINT (_tc); \ - _tc->c_cc_stat_tstamp = tcp_time_now(); \ -} \ -} +#define TCP_EVT_CC_STAT_HANDLER(_tc, ...) \ + { \ + if (tcp_cc_time_to_print_stats (_tc)) \ + { \ + TCP_EVT_CC_STAT_PRINT (_tc); \ + _tc->c_cc_stat_tstamp = tcp_time_now_us (_tc->c_thread_index); \ + } \ + } #else #define TCP_EVT_CC_STAT_HANDLER(_tc, ...) #define TCP_EVT_CC_STAT_PRINT(_tc) diff --git a/src/vnet/tcp/tcp_error.def b/src/vnet/tcp/tcp_error.def index a6f0ce4b35f..87fdcc02615 100644 --- a/src/vnet/tcp/tcp_error.def +++ b/src/vnet/tcp/tcp_error.def @@ -49,3 +49,4 @@ tcp_error (RCV_WND, rcv_wnd, WARN, "Segment not in receive window") tcp_error (FIN_RCVD, fin_rcvd, INFO, "FINs received") tcp_error (LINK_LOCAL_RW, link_local_rw, ERROR, "No rewrite for link local connection") tcp_error (ZERO_RWND, zero_rwnd, WARN, "Zero receive window") +tcp_error (CONN_ACCEPTED, conn_accepted, INFO, "Connections accepted")
\ No newline at end of file diff --git a/src/vnet/tcp/tcp_format.c b/src/vnet/tcp/tcp_format.c index a3245f2046a..4674f2cbaed 100644 --- a/src/vnet/tcp/tcp_format.c +++ b/src/vnet/tcp/tcp_format.c @@ -52,12 +52,68 @@ format_tcp_flags (u8 * s, va_list * args) return s; } +u8 * +format_tcp_options (u8 *s, va_list *args) +{ + tcp_options_t *opts = va_arg (*args, tcp_options_t *); + u32 indent, n_opts = 0; + int i; + + if (!opts->flags) + return s; + + indent = format_get_indent (s); + indent += 2; + + s = format (s, "options:\n%U", format_white_space, indent); + + if (tcp_opts_mss (opts)) + { + s = format (s, "mss %d", opts->mss); + n_opts++; + } + if (tcp_opts_wscale (opts)) + { + s = format (s, "%swindow scale %d", n_opts > 0 ? ", " : "", + format_white_space, indent, opts->wscale); + n_opts++; + } + if (tcp_opts_tstamp (opts)) + { + s = format (s, "%stimestamp %d, echo/reflected timestamp", + n_opts > 0 ? ", " : "", format_white_space, indent, + opts->tsval, opts->tsecr); + n_opts++; + } + if (tcp_opts_sack_permitted (opts)) + { + s = format (s, "%ssack permitted", n_opts > 0 ? ", " : "", + format_white_space, indent); + n_opts++; + } + if (tcp_opts_sack (opts)) + { + s = format (s, "%ssacks:", n_opts > 0 ? ", " : "", format_white_space, + indent); + for (i = 0; i < opts->n_sack_blocks; ++i) + { + s = format (s, "\n%Ublock %d: start %d, end %d", format_white_space, + indent + 2, i + 1, opts->sacks[i].start, + opts->sacks[i].end); + } + n_opts++; + } + + return s; +} + /* Format TCP header. */ u8 * format_tcp_header (u8 * s, va_list * args) { tcp_header_t *tcp = va_arg (*args, tcp_header_t *); u32 max_header_bytes = va_arg (*args, u32); + tcp_options_t opts = { .flags = 0 }; u32 header_bytes; u32 indent; @@ -83,32 +139,13 @@ format_tcp_header (u8 * s, va_list * args) clib_net_to_host_u16 (tcp->window), clib_net_to_host_u16 (tcp->checksum)); - -#if 0 - /* Format TCP options. */ - { - u8 *o; - u8 *option_start = (void *) (tcp + 1); - u8 *option_end = (void *) tcp + header_bytes; - - for (o = option_start; o < option_end;) - { - u32 length = o[1]; - switch (o[0]) - { - case TCP_OPTION_END: - length = 1; - o = option_end; - break; - - case TCP_OPTION_NOOP: - length = 1; - break; - - } - } - } -#endif + if (header_bytes > max_header_bytes) + s = format (s, "\n%Uoptions: truncated", format_white_space, indent); + else if (tcp_options_parse (tcp, &opts, tcp_is_syn (tcp)) < 0) + s = format (s, "\n%Uoptions: parsing failed", format_white_space, indent); + else + s = format (s, "\n%U%U", format_white_space, indent, format_tcp_options, + &opts); /* Recurse into next protocol layer. */ if (max_header_bytes != 0 && header_bytes < max_header_bytes) diff --git a/src/vnet/tcp/tcp_inlines.h b/src/vnet/tcp/tcp_inlines.h index e82f308d9b8..ccd0e3fe3ee 100644 --- a/src/vnet/tcp/tcp_inlines.h +++ b/src/vnet/tcp/tcp_inlines.h @@ -18,6 +18,35 @@ #include <vnet/tcp/tcp.h> +always_inline void +tcp_node_inc_counter_i (vlib_main_t *vm, u32 tcp4_node, u32 tcp6_node, + u8 is_ip4, u32 evt, u32 val) +{ + if (is_ip4) + vlib_node_increment_counter (vm, tcp4_node, evt, val); + else + vlib_node_increment_counter (vm, tcp6_node, evt, val); +} + +#define tcp_inc_counter(node_id, err, count) \ + tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ + tcp6_##node_id##_node.index, is_ip4, err, count) +#define tcp_maybe_inc_err_counter(cnts, err) \ + { \ + cnts[err] += (next0 != tcp_next_drop (is_ip4)); \ + } +#define tcp_inc_err_counter(cnts, err, val) \ + { \ + cnts[err] += val; \ + } +#define tcp_store_err_counters(node_id, cnts) \ + { \ + int i; \ + for (i = 0; i < TCP_N_ERROR; i++) \ + if (cnts[i]) \ + tcp_inc_counter (node_id, i, cnts[i]); \ + } + always_inline tcp_header_t * tcp_buffer_hdr (vlib_buffer_t * b) { @@ -66,7 +95,7 @@ tcp_listener_get (u32 tli) always_inline tcp_connection_t * tcp_half_open_connection_get (u32 conn_index) { - return tcp_connection_get (conn_index, 0); + return tcp_connection_get (conn_index, transport_cl_thread ()); } /** @@ -237,13 +266,6 @@ tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, tcp_header_t *tcp; u8 result = 0; - /* Set the sw_if_index[VLIB_RX] to the interface we received - * the connection on (the local interface) */ - vnet_buffer (b)->sw_if_index[VLIB_RX] = - vnet_buffer (b)->ip.rx_sw_if_index != ~0 ? - vnet_buffer (b)->ip.rx_sw_if_index : - vnet_buffer (b)->sw_if_index[VLIB_RX]; - if (is_ip4) { ip4_header_t *ip4 = vlib_buffer_get_current (b); @@ -300,7 +322,7 @@ tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, { ip6_main_t *im = &ip6_main; fib_index = vec_elt (im->fib_index_by_sw_if_index, - vnet_buffer (b)->sw_if_index[VLIB_RX]); + vnet_buffer (b)->ip.rx_sw_if_index); } tc = session_lookup_connection_wt6 (fib_index, &ip6->dst_address, @@ -311,6 +333,10 @@ tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, } } + /* Set the sw_if_index[VLIB_RX] to the interface we received + * the connection on (the local interface) */ + vnet_buffer (b)->sw_if_index[VLIB_RX] = vnet_buffer (b)->ip.rx_sw_if_index; + if (is_nolookup) tc = (transport_connection_t *) tcp_connection_get (vnet_buffer (b)-> diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c index df31c9e775f..70b5d28e0cc 100644 --- a/src/vnet/tcp/tcp_input.c +++ b/src/vnet/tcp/tcp_input.c @@ -27,59 +27,17 @@ static vlib_error_desc_t tcp_input_error_counters[] = { #undef tcp_error }; -/* All TCP nodes have the same outgoing arcs */ -#define foreach_tcp_state_next \ - _ (DROP4, "ip4-drop") \ - _ (DROP6, "ip6-drop") \ - _ (TCP4_OUTPUT, "tcp4-output") \ - _ (TCP6_OUTPUT, "tcp6-output") - -typedef enum _tcp_established_next -{ -#define _(s,n) TCP_ESTABLISHED_NEXT_##s, - foreach_tcp_state_next -#undef _ - TCP_ESTABLISHED_N_NEXT, -} tcp_established_next_t; - -typedef enum _tcp_rcv_process_next -{ -#define _(s,n) TCP_RCV_PROCESS_NEXT_##s, - foreach_tcp_state_next -#undef _ - TCP_RCV_PROCESS_N_NEXT, -} tcp_rcv_process_next_t; - -typedef enum _tcp_syn_sent_next -{ -#define _(s,n) TCP_SYN_SENT_NEXT_##s, - foreach_tcp_state_next -#undef _ - TCP_SYN_SENT_N_NEXT, -} tcp_syn_sent_next_t; - -typedef enum _tcp_listen_next -{ -#define _(s,n) TCP_LISTEN_NEXT_##s, - foreach_tcp_state_next -#undef _ - TCP_LISTEN_N_NEXT, -} tcp_listen_next_t; - -/* Generic, state independent indices */ -typedef enum _tcp_state_next +typedef enum _tcp_input_next { -#define _(s,n) TCP_NEXT_##s, - foreach_tcp_state_next -#undef _ - TCP_STATE_N_NEXT, -} tcp_state_next_t; - -#define tcp_next_output(is_ip4) (is_ip4 ? TCP_NEXT_TCP4_OUTPUT \ - : TCP_NEXT_TCP6_OUTPUT) - -#define tcp_next_drop(is_ip4) (is_ip4 ? TCP_NEXT_DROP4 \ - : TCP_NEXT_DROP6) + TCP_INPUT_NEXT_DROP, + TCP_INPUT_NEXT_LISTEN, + TCP_INPUT_NEXT_RCV_PROCESS, + TCP_INPUT_NEXT_SYN_SENT, + TCP_INPUT_NEXT_ESTABLISHED, + TCP_INPUT_NEXT_RESET, + TCP_INPUT_NEXT_PUNT, + TCP_INPUT_N_NEXT +} tcp_input_next_t; /** * Validate segment sequence number. As per RFC793: @@ -404,17 +362,10 @@ tcp_rcv_ack_no_cc (tcp_connection_t * tc, vlib_buffer_t * b, u32 * error) if (!(seq_leq (tc->snd_una, vnet_buffer (b)->tcp.ack_number) && seq_leq (vnet_buffer (b)->tcp.ack_number, tc->snd_nxt))) { - if (seq_leq (vnet_buffer (b)->tcp.ack_number, tc->snd_nxt) - && seq_gt (vnet_buffer (b)->tcp.ack_number, tc->snd_una)) - { - tc->snd_nxt = vnet_buffer (b)->tcp.ack_number; - goto acceptable; - } *error = TCP_ERROR_ACK_INVALID; return -1; } -acceptable: tc->bytes_acked = vnet_buffer (b)->tcp.ack_number - tc->snd_una; tc->snd_una = vnet_buffer (b)->tcp.ack_number; *error = TCP_ERROR_ACK_OK; @@ -594,7 +545,7 @@ tcp_handle_postponed_dequeues (tcp_worker_ctx_t * wrk) tc->burst_acked = 0; } - _vec_len (wrk->pending_deq_acked) = 0; + vec_set_len (wrk->pending_deq_acked, 0); } static void @@ -629,11 +580,15 @@ tcp_update_snd_wnd (tcp_connection_t * tc, u32 seq, u32 ack, u32 snd_wnd) if (PREDICT_FALSE (tc->snd_wnd < tc->snd_mss)) { - /* Set persist timer if not set and we just got 0 wnd */ - if (!tcp_timer_is_active (tc, TCP_TIMER_PERSIST) - && !tcp_timer_is_active (tc, TCP_TIMER_RETRANSMIT)) + if (!tcp_timer_is_active (tc, TCP_TIMER_RETRANSMIT)) { tcp_worker_ctx_t *wrk = tcp_get_worker (tc->c_thread_index); + + /* Set persist timer if we just got 0 wnd. If already set, + * update it because some data sent with snd_wnd < snd_mss was + * acked. */ + if (tcp_timer_is_active (tc, TCP_TIMER_PERSIST)) + tcp_persist_timer_reset (&wrk->timer_wheel, tc); tcp_persist_timer_set (&wrk->timer_wheel, tc); } } @@ -742,7 +697,7 @@ tcp_should_fastrecover (tcp_connection_t * tc, u8 has_sack) } static int -tcp_cc_recover (tcp_connection_t * tc) +tcp_cc_try_recover (tcp_connection_t *tc) { sack_scoreboard_hole_t *hole; u8 is_spurious = 0; @@ -757,14 +712,14 @@ tcp_cc_recover (tcp_connection_t * tc) tcp_connection_tx_pacer_reset (tc, tc->cwnd, 0 /* start bucket */ ); tc->rcv_dupacks = 0; + tcp_recovery_off (tc); /* Previous recovery left us congested. Continue sending as part * of the current recovery event with an updated snd_congestion */ - if (tc->sack_sb.sacked_bytes) + if (tc->sack_sb.sacked_bytes && tcp_in_fastrecovery (tc)) { tc->snd_congestion = tc->snd_nxt; - tcp_program_retransmit (tc); - return is_spurious; + return -1; } tc->rxt_delivered = 0; @@ -778,19 +733,18 @@ tcp_cc_recover (tcp_connection_t * tc) if (hole && hole->start == tc->snd_una && hole->end == tc->snd_nxt) scoreboard_clear (&tc->sack_sb); - if (!tcp_in_recovery (tc) && !is_spurious) + if (tcp_in_fastrecovery (tc) && !is_spurious) tcp_cc_recovered (tc); tcp_fastrecovery_off (tc); tcp_fastrecovery_first_off (tc); - tcp_recovery_off (tc); TCP_EVT (TCP_EVT_CC_EVT, tc, 3); ASSERT (tc->rto_boff == 0); ASSERT (!tcp_in_cong_recovery (tc)); ASSERT (tcp_scoreboard_is_sane_post_recovery (tc)); - return is_spurious; + return 0; } static void @@ -803,15 +757,6 @@ tcp_cc_update (tcp_connection_t * tc, tcp_rate_sample_t * rs) /* If a cumulative ack, make sure dupacks is 0 */ tc->rcv_dupacks = 0; - - /* When dupacks hits the threshold we only enter fast retransmit if - * cumulative ack covers more than snd_congestion. Should snd_una - * wrap this test may fail under otherwise valid circumstances. - * Therefore, proactively update snd_congestion when wrap detected. */ - if (PREDICT_FALSE - (seq_leq (tc->snd_congestion, tc->snd_una - tc->bytes_acked) - && seq_gt (tc->snd_congestion, tc->snd_una))) - tc->snd_congestion = tc->snd_una - 1; } /** @@ -857,6 +802,20 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, */ /* + * See if we can exit and stop retransmitting + */ + if (seq_geq (tc->snd_una, tc->snd_congestion)) + { + /* If successfully recovered, treat ack as congestion avoidance ack + * and return. Otherwise, we're still congested so process feedback */ + if (!tcp_cc_try_recover (tc)) + { + tcp_cc_rcv_ack (tc, rs); + return; + } + } + + /* * Process (re)transmit feedback. Output path uses this to decide how much * more data to release into the network */ @@ -866,8 +825,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, tcp_fastrecovery_first_on (tc); tc->rxt_delivered += tc->sack_sb.rxt_sacked; - tc->prr_delivered += tc->bytes_acked + tc->sack_sb.last_sacked_bytes - - tc->sack_sb.last_bytes_delivered; + tc->prr_delivered += rs->delivered; } else { @@ -891,23 +849,6 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, tcp_fastrecovery_first_on (tc); } - /* - * See if we can exit and stop retransmitting - */ - if (seq_geq (tc->snd_una, tc->snd_congestion)) - { - /* If spurious return, we've already updated everything */ - if (tcp_cc_recover (tc)) - { - tc->tsecr_last_ack = tc->rcv_opts.tsecr; - return; - } - - /* Treat as congestion avoidance ack */ - tcp_cc_rcv_ack (tc, rs); - return; - } - tcp_program_retransmit (tc); /* @@ -991,15 +932,6 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b, /* If the ACK acks something not yet sent (SEG.ACK > SND.NXT) */ if (PREDICT_FALSE (seq_gt (vnet_buffer (b)->tcp.ack_number, tc->snd_nxt))) { - /* We've probably entered recovery and the peer still has some - * of the data we've sent. Update snd_nxt and accept the ack */ - if (seq_leq (vnet_buffer (b)->tcp.ack_number, tc->snd_nxt) - && seq_gt (vnet_buffer (b)->tcp.ack_number, tc->snd_una)) - { - tc->snd_nxt = vnet_buffer (b)->tcp.ack_number; - goto process_ack; - } - tc->errors.above_ack_wnd += 1; *error = TCP_ERROR_ACK_FUTURE; TCP_EVT (TCP_EVT_ACK_RCV_ERR, tc, 0, vnet_buffer (b)->tcp.ack_number); @@ -1022,8 +954,6 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b, return 0; } -process_ack: - /* * Looks okay, process feedback */ @@ -1042,6 +972,9 @@ process_ack: if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE) tcp_bt_sample_delivery_rate (tc, &rs); + else + rs.delivered = tc->bytes_acked + tc->sack_sb.last_sacked_bytes - + tc->sack_sb.last_bytes_delivered; if (tc->bytes_acked + tc->sack_sb.last_sacked_bytes) { @@ -1106,7 +1039,7 @@ tcp_handle_disconnects (tcp_worker_ctx_t * wrk) tcp_disconnect_pending_off (tc); session_transport_closing_notify (&tc->connection); } - _vec_len (wrk->pending_disconnects) = 0; + vec_set_len (wrk->pending_disconnects, 0); } if (vec_len (wrk->pending_resets)) @@ -1119,7 +1052,7 @@ tcp_handle_disconnects (tcp_worker_ctx_t * wrk) tcp_disconnect_pending_off (tc); tcp_handle_rst (tc); } - _vec_len (wrk->pending_resets) = 0; + vec_set_len (wrk->pending_resets, 0); } } @@ -1156,7 +1089,6 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b, ASSERT (data_len); written = session_enqueue_stream_connection (&tc->connection, b, 0, 1 /* queue event */ , 1); - tc->bytes_in += written; TCP_EVT (TCP_EVT_INPUT, tc, 0, data_len, written); @@ -1164,17 +1096,20 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b, if (PREDICT_TRUE (written == data_len)) { tc->rcv_nxt += written; + tc->bytes_in += written; } /* If more data written than expected, account for out-of-order bytes. */ else if (written > data_len) { tc->rcv_nxt += written; + tc->bytes_in += data_len; TCP_EVT (TCP_EVT_CC_INPUT, tc, data_len, written); } else if (written > 0) { /* We've written something but FIFO is probably full now */ tc->rcv_nxt += written; + tc->bytes_in += written; error = TCP_ERROR_PARTIALLY_ENQUEUED; } else @@ -1361,9 +1296,13 @@ format_tcp_rx_trace (u8 * s, va_list * args) tcp_connection_t *tc = &t->tcp_connection; u32 indent = format_get_indent (s); - s = format (s, "%U state %U\n%U%U", format_tcp_connection_id, tc, - format_tcp_state, tc->state, format_white_space, indent, - format_tcp_header, &t->tcp_header, 128); + if (!tc->c_lcl_port) + s = format (s, "no tcp connection\n%U%U", format_white_space, indent, + format_tcp_header, &t->tcp_header, 128); + else + s = format (s, "%U state %U\n%U%U", format_tcp_connection_id, tc, + format_tcp_state, tc->state, format_white_space, indent, + format_tcp_header, &t->tcp_header, 128); return s; } @@ -1433,53 +1372,14 @@ tcp_established_trace_frame (vlib_main_t * vm, vlib_node_runtime_t * node, } } -always_inline void -tcp_node_inc_counter_i (vlib_main_t * vm, u32 tcp4_node, u32 tcp6_node, - u8 is_ip4, u32 evt, u32 val) -{ - if (is_ip4) - vlib_node_increment_counter (vm, tcp4_node, evt, val); - else - vlib_node_increment_counter (vm, tcp6_node, evt, val); -} - -#define tcp_maybe_inc_counter(node_id, err, count) \ -{ \ - if (next0 != tcp_next_drop (is_ip4)) \ - tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ - tcp6_##node_id##_node.index, is_ip4, err, \ - 1); \ -} -#define tcp_inc_counter(node_id, err, count) \ - tcp_node_inc_counter_i (vm, tcp4_##node_id##_node.index, \ - tcp6_##node_id##_node.index, is_ip4, \ - err, count) -#define tcp_maybe_inc_err_counter(cnts, err) \ -{ \ - cnts[err] += (next0 != tcp_next_drop (is_ip4)); \ -} -#define tcp_inc_err_counter(cnts, err, val) \ -{ \ - cnts[err] += val; \ -} -#define tcp_store_err_counters(node_id, cnts) \ -{ \ - int i; \ - for (i = 0; i < TCP_N_ERROR; i++) \ - if (cnts[i]) \ - tcp_inc_counter(node_id, i, cnts[i]); \ -} - - always_inline uword tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip4) { - u32 thread_index = vm->thread_index, errors = 0; + u32 thread_index = vm->thread_index, n_left_from, *from; tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index); vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; u16 err_counters[TCP_N_ERROR] = { 0 }; - u32 n_left_from, *from; if (node->flags & VLIB_NODE_FLAG_TRACE) tcp_established_trace_frame (vm, node, frame, is_ip4); @@ -1543,9 +1443,7 @@ tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node, b += 1; } - errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, - thread_index); - err_counters[TCP_ERROR_MSG_QUEUE_FULL] = errors; + session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, thread_index); tcp_store_err_counters (established, err_counters); tcp_handle_postponed_dequeues (wrk); tcp_handle_disconnects (wrk); @@ -1568,43 +1466,23 @@ VLIB_NODE_FN (tcp6_established_node) (vlib_main_t * vm, return tcp46_established_inline (vm, node, from_frame, 0 /* is_ip4 */ ); } -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp4_established_node) = -{ +VLIB_REGISTER_NODE (tcp4_established_node) = { .name = "tcp4-established", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_ESTABLISHED_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp6_established_node) = -{ +VLIB_REGISTER_NODE (tcp6_established_node) = { .name = "tcp6-established", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_ESTABLISHED_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_ESTABLISHED_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ static u8 @@ -1796,15 +1674,54 @@ tcp_check_tx_offload (tcp_connection_t * tc, int is_ipv4) return; hw_if = vnet_get_sup_hw_interface (vnm, sw_if_idx); - if (hw_if->caps & VNET_HW_INTERFACE_CAP_SUPPORTS_TCP_GSO) + if (hw_if->caps & VNET_HW_IF_CAP_TCP_GSO) tc->cfg_flags |= TCP_CFG_F_TSO; } +static void +tcp_input_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_buffer_t **bs, u16 *nexts, u32 n_bufs, u8 is_ip4) +{ + tcp_connection_t *tc; + tcp_header_t *tcp; + tcp_rx_trace_t *t; + u8 flags; + int i; + + for (i = 0; i < n_bufs; i++) + { + if (!(bs[i]->flags & VLIB_BUFFER_IS_TRACED)) + continue; + + t = vlib_add_trace (vm, node, bs[i], sizeof (*t)); + if (nexts[i] == TCP_INPUT_NEXT_DROP || nexts[i] == TCP_INPUT_NEXT_PUNT || + nexts[i] == TCP_INPUT_NEXT_RESET) + { + tc = 0; + } + else + { + flags = vnet_buffer (bs[i])->tcp.flags; + + if (flags == TCP_STATE_LISTEN) + tc = tcp_listener_get (vnet_buffer (bs[i])->tcp.connection_index); + else if (flags == TCP_STATE_SYN_SENT) + tc = tcp_half_open_connection_get ( + vnet_buffer (bs[i])->tcp.connection_index); + else + tc = tcp_connection_get (vnet_buffer (bs[i])->tcp.connection_index, + vm->thread_index); + } + tcp = tcp_buffer_hdr (bs[i]); + tcp_set_rx_trace_data (t, tc, tcp, bs[i], is_ip4); + } +} + always_inline uword tcp46_syn_sent_inline (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip4) { - u32 n_left_from, *from, thread_index = vm->thread_index, errors = 0; + u32 n_left_from, *from, thread_index = vm->thread_index; tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index); vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; @@ -1970,7 +1887,9 @@ tcp46_syn_sent_inline (vlib_main_t *vm, vlib_node_runtime_t *node, SESSION_E_NONE)) { tcp_send_reset_w_pkt (new_tc, b[0], thread_index, is_ip4); - tcp_connection_cleanup (new_tc); + tcp_program_cleanup (wrk, new_tc); + new_tc->state = TCP_STATE_CLOSED; + new_tc->c_s_index = ~0; error = TCP_ERROR_CREATE_SESSION_FAIL; goto cleanup_ho; } @@ -1991,8 +1910,10 @@ tcp46_syn_sent_inline (vlib_main_t *vm, vlib_node_runtime_t *node, if (session_stream_connect_notify (&new_tc->connection, SESSION_E_NONE)) { - tcp_connection_cleanup (new_tc); tcp_send_reset_w_pkt (tc, b[0], thread_index, is_ip4); + tcp_program_cleanup (wrk, new_tc); + new_tc->state = TCP_STATE_CLOSED; + new_tc->c_s_index = ~0; TCP_EVT (TCP_EVT_RST_SENT, tc); error = TCP_ERROR_CREATE_SESSION_FAIL; goto cleanup_ho; @@ -2039,9 +1960,7 @@ tcp46_syn_sent_inline (vlib_main_t *vm, vlib_node_runtime_t *node, tcp_inc_counter (syn_sent, error, 1); } - errors = - session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, thread_index); - tcp_inc_counter (syn_sent, TCP_ERROR_MSG_QUEUE_FULL, errors); + session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, thread_index); vlib_buffer_free (vm, from, frame->n_vectors); tcp_handle_disconnects (wrk); @@ -2062,7 +1981,6 @@ VLIB_NODE_FN (tcp6_syn_sent_node) (vlib_main_t * vm, return tcp46_syn_sent_inline (vm, node, from_frame, 0 /* is_ip4 */ ); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp4_syn_sent_node) = { .name = "tcp4-syn-sent", @@ -2070,18 +1988,9 @@ VLIB_REGISTER_NODE (tcp4_syn_sent_node) = .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_SYN_SENT_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp6_syn_sent_node) = { .name = "tcp6-syn-sent", @@ -2089,16 +1998,8 @@ VLIB_REGISTER_NODE (tcp6_syn_sent_node) = .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_SYN_SENT_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_SYN_SENT_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ static void tcp46_rcv_process_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, @@ -2130,7 +2031,7 @@ always_inline uword tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip4) { - u32 thread_index = vm->thread_index, errors, n_left_from, *from, max_deq; + u32 thread_index = vm->thread_index, n_left_from, *from, max_deq; tcp_worker_ctx_t *wrk = tcp_get_worker (thread_index); vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; @@ -2198,15 +2099,6 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, switch (tc->state) { case TCP_STATE_SYN_RCVD: - - /* Make sure the segment is exactly right */ - if (tc->rcv_nxt != vnet_buffer (b[0])->tcp.seq_number || is_fin) - { - tcp_send_reset_w_pkt (tc, b[0], thread_index, is_ip4); - error = TCP_ERROR_SEGMENT_INVALID; - goto drop; - } - /* * If the segment acknowledgment is not acceptable, form a * reset segment, @@ -2220,6 +2112,10 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, goto drop; } + /* Avoid notifying app if connection is about to be closed */ + if (PREDICT_FALSE (is_fin)) + break; + /* Update rtt and rto */ tcp_estimate_initial_rtt (tc); tcp_connection_tx_pacer_update (tc); @@ -2248,7 +2144,7 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, tcp_connection_cleanup (tc); goto drop; } - error = TCP_ERROR_ACK_OK; + error = TCP_ERROR_CONN_ACCEPTED; break; case TCP_STATE_ESTABLISHED: /* We can get packets in established state here because they @@ -2327,8 +2223,8 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, if (max_deq > tc->burst_acked) break; - tcp_send_fin (tc); tcp_connection_timers_reset (tc); + tcp_send_fin (tc); tcp_connection_set_state (tc, TCP_STATE_LAST_ACK); tcp_timer_set (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time); @@ -2440,15 +2336,15 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, tcp_cfg.closewait_time); break; case TCP_STATE_SYN_RCVD: - /* Send FIN-ACK, enter LAST-ACK and because the app was not - * notified yet, set a cleanup timer instead of relying on - * disconnect notify and the implicit close call. */ + /* Send FIN-ACK and enter TIME-WAIT, as opposed to LAST-ACK, + * because the app was not notified yet and we want to avoid + * session state transitions to ensure cleanup does not + * propagate to app. */ tcp_connection_timers_reset (tc); tc->rcv_nxt += 1; tcp_send_fin (tc); - tcp_connection_set_state (tc, TCP_STATE_LAST_ACK); - tcp_timer_set (&wrk->timer_wheel, tc, TCP_TIMER_WAITCLOSE, - tcp_cfg.lastack_time); + tcp_connection_set_state (tc, TCP_STATE_TIME_WAIT); + tcp_program_cleanup (wrk, tc); break; case TCP_STATE_CLOSE_WAIT: case TCP_STATE_CLOSING: @@ -2503,9 +2399,7 @@ tcp46_rcv_process_inline (vlib_main_t *vm, vlib_node_runtime_t *node, tcp_inc_counter (rcv_process, error, 1); } - errors = session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, - thread_index); - tcp_inc_counter (rcv_process, TCP_ERROR_MSG_QUEUE_FULL, errors); + session_main_flush_enqueue_events (TRANSPORT_PROTO_TCP, thread_index); tcp_handle_postponed_dequeues (wrk); tcp_handle_disconnects (wrk); vlib_buffer_free (vm, from, frame->n_vectors); @@ -2527,43 +2421,23 @@ VLIB_NODE_FN (tcp6_rcv_process_node) (vlib_main_t * vm, return tcp46_rcv_process_inline (vm, node, from_frame, 0 /* is_ip4 */ ); } -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp4_rcv_process_node) = -{ +VLIB_REGISTER_NODE (tcp4_rcv_process_node) = { .name = "tcp4-rcv-process", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_RCV_PROCESS_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp6_rcv_process_node) = -{ +VLIB_REGISTER_NODE (tcp6_rcv_process_node) = { .name = "tcp6-rcv-process", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_RCV_PROCESS_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_RCV_PROCESS_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ static void tcp46_listen_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, @@ -2664,7 +2538,6 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, while (n_left_from > 0) { - u32 error = TCP_ERROR_NONE; tcp_connection_t *lc, *child; /* Flags initialized with connection state after lookup */ @@ -2672,21 +2545,22 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, { lc = tcp_listener_get (vnet_buffer (b[0])->tcp.connection_index); } - else /* We are in TimeWait state*/ + /* Probably we are in time-wait or closed state */ + else { tcp_connection_t *tc; tc = tcp_connection_get (vnet_buffer (b[0])->tcp.connection_index, thread_index); if (tc->state != TCP_STATE_TIME_WAIT) { - error = TCP_ERROR_CREATE_EXISTS; + tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1); goto done; } if (PREDICT_FALSE (!syn_during_timewait (tc, b[0], &tw_iss))) { /* This SYN can't be accepted */ - error = TCP_ERROR_CREATE_EXISTS; + tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1); goto done; } @@ -2696,7 +2570,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, /* listener was cleaned up */ if (!lc) { - error = TCP_ERROR_NO_LISTENER; + tcp_inc_counter (listen, TCP_ERROR_NO_LISTENER, 1); goto done; } } @@ -2706,7 +2580,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, tcp_lookup_connection (lc->c_fib_index, b[0], thread_index, is_ip4); if (PREDICT_FALSE (child->state != TCP_STATE_LISTEN)) { - error = TCP_ERROR_CREATE_EXISTS; + tcp_inc_counter (listen, TCP_ERROR_CREATE_EXISTS, 1); goto done; } @@ -2723,7 +2597,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, if (tcp_options_parse (tcp_buffer_hdr (b[0]), &child->rcv_opts, 1)) { - error = TCP_ERROR_OPTIONS; + tcp_inc_counter (listen, TCP_ERROR_OPTIONS, 1); tcp_connection_free (child); goto done; } @@ -2753,7 +2627,7 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, lc->c_thread_index, 0 /* notify */ )) { tcp_connection_cleanup (child); - error = TCP_ERROR_CREATE_SESSION_FAIL; + tcp_inc_counter (listen, TCP_ERROR_CREATE_SESSION_FAIL, 1); goto done; } @@ -2761,12 +2635,11 @@ tcp46_listen_inline (vlib_main_t *vm, vlib_node_runtime_t *node, child->tx_fifo_size = transport_tx_fifo_size (&child->connection); tcp_send_synack (child); + n_syns += 1; done: - b += 1; n_left_from -= 1; - n_syns += (error == TCP_ERROR_NONE); } tcp_inc_counter (listen, TCP_ERROR_SYNS_RCVD, n_syns); @@ -2787,98 +2660,82 @@ VLIB_NODE_FN (tcp6_listen_node) (vlib_main_t * vm, vlib_node_runtime_t * node, return tcp46_listen_inline (vm, node, from_frame, 0 /* is_ip4 */ ); } -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp4_listen_node) = -{ +VLIB_REGISTER_NODE (tcp4_listen_node) = { .name = "tcp4-listen", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_LISTEN_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_LISTEN_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ -VLIB_REGISTER_NODE (tcp6_listen_node) = -{ +VLIB_REGISTER_NODE (tcp6_listen_node) = { .name = "tcp6-listen", /* Takes a vector of packets. */ .vector_size = sizeof (u32), .n_errors = TCP_N_ERROR, .error_counters = tcp_input_error_counters, - .n_next_nodes = TCP_LISTEN_N_NEXT, - .next_nodes = - { -#define _(s,n) [TCP_LISTEN_NEXT_##s] = n, - foreach_tcp_state_next -#undef _ - }, .format_trace = format_tcp_rx_trace_short, }; -/* *INDENT-ON* */ -typedef enum _tcp_input_next +always_inline uword +tcp46_drop_inline (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame, int is_ip4) { - TCP_INPUT_NEXT_DROP, - TCP_INPUT_NEXT_LISTEN, - TCP_INPUT_NEXT_RCV_PROCESS, - TCP_INPUT_NEXT_SYN_SENT, - TCP_INPUT_NEXT_ESTABLISHED, - TCP_INPUT_NEXT_RESET, - TCP_INPUT_NEXT_PUNT, - TCP_INPUT_N_NEXT -} tcp_input_next_t; + u32 *from = vlib_frame_vector_args (frame); -#define foreach_tcp4_input_next \ - _ (DROP, "ip4-drop") \ - _ (LISTEN, "tcp4-listen") \ - _ (RCV_PROCESS, "tcp4-rcv-process") \ - _ (SYN_SENT, "tcp4-syn-sent") \ - _ (ESTABLISHED, "tcp4-established") \ - _ (RESET, "tcp4-reset") \ - _ (PUNT, "ip4-punt") - -#define foreach_tcp6_input_next \ - _ (DROP, "ip6-drop") \ - _ (LISTEN, "tcp6-listen") \ - _ (RCV_PROCESS, "tcp6-rcv-process") \ - _ (SYN_SENT, "tcp6-syn-sent") \ - _ (ESTABLISHED, "tcp6-established") \ - _ (RESET, "tcp6-reset") \ - _ (PUNT, "ip6-punt") + /* Error counters must be incremented by previous nodes */ + vlib_buffer_free (vm, from, frame->n_vectors); -#define filter_flags (TCP_FLAG_SYN|TCP_FLAG_ACK|TCP_FLAG_RST|TCP_FLAG_FIN) + return frame->n_vectors; +} -static void -tcp_input_trace_frame (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_buffer_t ** bs, u32 n_bufs, u8 is_ip4) +VLIB_NODE_FN (tcp4_drop_node) +(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame) { - tcp_connection_t *tc; - tcp_header_t *tcp; - tcp_rx_trace_t *t; - int i; + return tcp46_drop_inline (vm, node, from_frame, 1 /* is_ip4 */); +} - for (i = 0; i < n_bufs; i++) - { - if (bs[i]->flags & VLIB_BUFFER_IS_TRACED) - { - t = vlib_add_trace (vm, node, bs[i], sizeof (*t)); - tc = tcp_connection_get (vnet_buffer (bs[i])->tcp.connection_index, - vm->thread_index); - tcp = vlib_buffer_get_current (bs[i]); - tcp_set_rx_trace_data (t, tc, tcp, bs[i], is_ip4); - } - } +VLIB_NODE_FN (tcp6_drop_node) +(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame) +{ + return tcp46_drop_inline (vm, node, from_frame, 0 /* is_ip4 */); } +VLIB_REGISTER_NODE (tcp4_drop_node) = { + .name = "tcp4-drop", + .vector_size = sizeof (u32), + .n_errors = TCP_N_ERROR, + .error_counters = tcp_input_error_counters, +}; + +VLIB_REGISTER_NODE (tcp6_drop_node) = { + .name = "tcp6-drop", + .vector_size = sizeof (u32), + .n_errors = TCP_N_ERROR, + .error_counters = tcp_input_error_counters, +}; + +#define foreach_tcp4_input_next \ + _ (DROP, "tcp4-drop") \ + _ (LISTEN, "tcp4-listen") \ + _ (RCV_PROCESS, "tcp4-rcv-process") \ + _ (SYN_SENT, "tcp4-syn-sent") \ + _ (ESTABLISHED, "tcp4-established") \ + _ (RESET, "tcp4-reset") \ + _ (PUNT, "ip4-punt") + +#define foreach_tcp6_input_next \ + _ (DROP, "tcp6-drop") \ + _ (LISTEN, "tcp6-listen") \ + _ (RCV_PROCESS, "tcp6-rcv-process") \ + _ (SYN_SENT, "tcp6-syn-sent") \ + _ (ESTABLISHED, "tcp6-established") \ + _ (RESET, "tcp6-reset") \ + _ (PUNT, "ip6-punt") + +#define filter_flags (TCP_FLAG_SYN|TCP_FLAG_ACK|TCP_FLAG_RST|TCP_FLAG_FIN) + static void tcp_input_set_error_next (tcp_main_t * tm, u16 * next, u32 * error, u8 is_ip4) { @@ -2899,9 +2756,8 @@ tcp_input_set_error_next (tcp_main_t * tm, u16 * next, u32 * error, u8 is_ip4) } static inline void -tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc, - vlib_buffer_t * b, u16 * next, - vlib_node_runtime_t * error_node) +tcp_input_dispatch_buffer (tcp_main_t *tm, tcp_connection_t *tc, + vlib_buffer_t *b, u16 *next, u16 *err_counters) { tcp_header_t *tcp; u32 error; @@ -2923,7 +2779,7 @@ tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc, if (PREDICT_FALSE (error != TCP_ERROR_NONE)) { - b->error = error_node->errors[error]; + tcp_inc_err_counter (err_counters, error, 1); if (error == TCP_ERROR_DISPATCH) clib_warning ("tcp conn %u disp error state %U flags %U", tc->c_c_index, format_tcp_state, tc->state, @@ -2939,6 +2795,7 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, tcp_main_t *tm = vnet_get_tcp_main (); vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; u16 nexts[VLIB_FRAME_SIZE], *next; + u16 err_counters[TCP_N_ERROR] = { 0 }; tcp_update_time_now (tcp_get_worker (thread_index)); @@ -2977,8 +2834,8 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index; vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index; - tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], node); - tcp_input_dispatch_buffer (tm, tc1, b[1], &next[1], node); + tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], err_counters); + tcp_input_dispatch_buffer (tm, tc1, b[1], &next[1], err_counters); } else { @@ -2986,24 +2843,26 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, { ASSERT (tcp_lookup_is_valid (tc0, b[0], tcp_buffer_hdr (b[0]))); vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index; - tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], node); + tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], + err_counters); } else { tcp_input_set_error_next (tm, &next[0], &error0, is_ip4); - b[0]->error = node->errors[error0]; + tcp_inc_err_counter (err_counters, error0, 1); } if (PREDICT_TRUE (tc1 != 0)) { ASSERT (tcp_lookup_is_valid (tc1, b[1], tcp_buffer_hdr (b[1]))); vnet_buffer (b[1])->tcp.connection_index = tc1->c_c_index; - tcp_input_dispatch_buffer (tm, tc1, b[1], &next[1], node); + tcp_input_dispatch_buffer (tm, tc1, b[1], &next[1], + err_counters); } else { tcp_input_set_error_next (tm, &next[1], &error1, is_ip4); - b[1]->error = node->errors[error1]; + tcp_inc_err_counter (err_counters, error1, 1); } } @@ -3029,12 +2888,12 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, { ASSERT (tcp_lookup_is_valid (tc0, b[0], tcp_buffer_hdr (b[0]))); vnet_buffer (b[0])->tcp.connection_index = tc0->c_c_index; - tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], node); + tcp_input_dispatch_buffer (tm, tc0, b[0], &next[0], err_counters); } else { tcp_input_set_error_next (tm, &next[0], &error0, is_ip4); - b[0]->error = node->errors[error0]; + tcp_inc_err_counter (err_counters, error0, 1); } b += 1; @@ -3043,8 +2902,9 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) - tcp_input_trace_frame (vm, node, bufs, frame->n_vectors, is_ip4); + tcp_input_trace_frame (vm, node, bufs, nexts, frame->n_vectors, is_ip4); + tcp_store_err_counters (input, err_counters); vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); return frame->n_vectors; } @@ -3065,7 +2925,6 @@ VLIB_NODE_FN (tcp6_input_nolookup_node) (vlib_main_t * vm, 1 /* is_nolookup */ ); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp4_input_nolookup_node) = { .name = "tcp4-input-nolookup", @@ -3083,9 +2942,7 @@ VLIB_REGISTER_NODE (tcp4_input_nolookup_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_rx_trace, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp6_input_nolookup_node) = { .name = "tcp6-input-nolookup", @@ -3103,7 +2960,6 @@ VLIB_REGISTER_NODE (tcp6_input_nolookup_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_rx_trace, }; -/* *INDENT-ON* */ VLIB_NODE_FN (tcp4_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * from_frame) @@ -3119,7 +2975,6 @@ VLIB_NODE_FN (tcp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node, 0 /* is_nolookup */ ); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp4_input_node) = { .name = "tcp4-input", @@ -3137,9 +2992,7 @@ VLIB_REGISTER_NODE (tcp4_input_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_rx_trace, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp6_input_node) = { .name = "tcp6-input", @@ -3157,7 +3010,6 @@ VLIB_REGISTER_NODE (tcp6_input_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_rx_trace, }; -/* *INDENT-ON* */ #ifndef CLIB_MARCH_VARIANT void @@ -3343,6 +3195,8 @@ do { \ _(FIN_WAIT_2, TCP_FLAG_RST | TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); _(FIN_WAIT_2, TCP_FLAG_SYN, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); + _ (FIN_WAIT_2, TCP_FLAG_SYN | TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, + TCP_ERROR_NONE); _(CLOSE_WAIT, TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); _(CLOSE_WAIT, TCP_FLAG_FIN | TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); @@ -3392,7 +3246,7 @@ do { \ _(CLOSED, TCP_FLAG_RST | TCP_FLAG_ACK, TCP_INPUT_NEXT_DROP, TCP_ERROR_CONNECTION_CLOSED); _(CLOSED, TCP_FLAG_ACK, TCP_INPUT_NEXT_RESET, TCP_ERROR_CONNECTION_CLOSED); - _(CLOSED, TCP_FLAG_SYN, TCP_INPUT_NEXT_RESET, TCP_ERROR_CONNECTION_CLOSED); + _ (CLOSED, TCP_FLAG_SYN, TCP_INPUT_NEXT_LISTEN, TCP_ERROR_NONE); _(CLOSED, TCP_FLAG_FIN | TCP_FLAG_ACK, TCP_INPUT_NEXT_RESET, TCP_ERROR_CONNECTION_CLOSED); #undef _ diff --git a/src/vnet/tcp/tcp_newreno.c b/src/vnet/tcp/tcp_newreno.c index c5ffc2a4109..8c7e77fc974 100644 --- a/src/vnet/tcp/tcp_newreno.c +++ b/src/vnet/tcp/tcp_newreno.c @@ -49,12 +49,12 @@ newreno_rcv_ack (tcp_connection_t * tc, tcp_rate_sample_t * rs) { if (tcp_in_slowstart (tc)) { - tc->cwnd += clib_min (tc->snd_mss, tc->bytes_acked); + tc->cwnd += clib_min (tc->snd_mss, rs->delivered); } else { /* tc->cwnd += clib_max ((tc->snd_mss * tc->snd_mss) / tc->cwnd, 1); */ - tcp_cwnd_accumulate (tc, tc->cwnd, tc->bytes_acked); + tcp_cwnd_accumulate (tc, tc->cwnd, rs->delivered); } } @@ -62,30 +62,31 @@ void newreno_rcv_cong_ack (tcp_connection_t * tc, tcp_cc_ack_t ack_type, tcp_rate_sample_t * rs) { + /* With sacks prr controls the data in flight post congestion */ + if (PREDICT_TRUE (tcp_opts_sack_permitted (tc))) + return; + if (ack_type == TCP_CC_DUPACK) { - if (!tcp_opts_sack_permitted (tc)) - tc->cwnd += tc->snd_mss; + tc->cwnd += tc->snd_mss; } else if (ack_type == TCP_CC_PARTIALACK) { - /* RFC 6582 Sec. 3.2 */ - if (!tcp_opts_sack_permitted (&tc->rcv_opts)) - { - /* Deflate the congestion window by the amount of new data - * acknowledged by the Cumulative Acknowledgment field. - * If the partial ACK acknowledges at least one SMSS of new data, - * then add back SMSS bytes to the congestion window. This - * artificially inflates the congestion window in order to reflect - * the additional segment that has left the network. This "partial - * window deflation" attempts to ensure that, when fast recovery - * eventually ends, approximately ssthresh amount of data will be - * outstanding in the network.*/ - tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ? - tc->cwnd - tc->bytes_acked : tc->snd_mss; - if (tc->bytes_acked > tc->snd_mss) - tc->cwnd += tc->snd_mss; - } + /* RFC 6582 Sec. 3.2 + * Deflate the congestion window by the amount of new data + * acknowledged by the Cumulative Acknowledgment field. + * If the partial ACK acknowledges at least one SMSS of new data, + * then add back SMSS bytes to the congestion window. This + * artificially inflates the congestion window in order to reflect + * the additional segment that has left the network. This "partial + * window deflation" attempts to ensure that, when fast recovery + * eventually ends, approximately ssthresh amount of data will be + * outstanding in the network. */ + tc->cwnd = (tc->cwnd > tc->bytes_acked + tc->snd_mss) ? + tc->cwnd - tc->bytes_acked : + tc->snd_mss; + if (tc->bytes_acked > tc->snd_mss) + tc->cwnd += tc->snd_mss; } } diff --git a/src/vnet/tcp/tcp_output.c b/src/vnet/tcp/tcp_output.c index 5b445fa5165..78148cd5695 100644 --- a/src/vnet/tcp/tcp_output.c +++ b/src/vnet/tcp/tcp_output.c @@ -321,7 +321,6 @@ tcp_update_burst_snd_vars (tcp_connection_t * tc) if (tc->snd_una == tc->snd_nxt) { tcp_cc_event (tc, TCP_CC_EVT_START_TX); - tcp_connection_tx_pacer_reset (tc, tc->cwnd, TRANSPORT_PACER_MIN_BURST); } if (tc->flags & TCP_CONN_PSH_PENDING) @@ -332,25 +331,6 @@ tcp_update_burst_snd_vars (tcp_connection_t * tc) } } -#endif /* CLIB_MARCH_VARIANT */ - -static void * -tcp_reuse_buffer (vlib_main_t * vm, vlib_buffer_t * b) -{ - if (b->flags & VLIB_BUFFER_NEXT_PRESENT) - vlib_buffer_free_one (vm, b->next_buffer); - /* Zero all flags but free list index and trace flag */ - b->flags &= VLIB_BUFFER_NEXT_PRESENT - 1; - b->current_data = 0; - b->current_length = 0; - b->total_length_not_including_first_buffer = 0; - vnet_buffer (b)->tcp.flags = 0; - VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b); - /* Leave enough space for headers */ - return vlib_buffer_make_headroom (b, TRANSPORT_MAX_HDRS_LEN); -} - -#ifndef CLIB_MARCH_VARIANT static void * tcp_init_buffer (vlib_main_t * vm, vlib_buffer_t * b) { @@ -363,7 +343,6 @@ tcp_init_buffer (vlib_main_t * vm, vlib_buffer_t * b) return vlib_buffer_make_headroom (b, TRANSPORT_MAX_HDRS_LEN); } - /* Compute TCP checksum in software when offloading is disabled for a connection */ u16 ip6_tcp_compute_checksum_custom (vlib_main_t * vm, vlib_buffer_t * p0, @@ -441,7 +420,7 @@ static inline void tcp_make_ack_i (tcp_connection_t * tc, vlib_buffer_t * b, tcp_state_t state, u8 flags) { - tcp_options_t _snd_opts, *snd_opts = &_snd_opts; + tcp_options_t _snd_opts = {}, *snd_opts = &_snd_opts; u8 tcp_opts_len, tcp_hdr_opts_len; tcp_header_t *th; u16 wnd; @@ -568,24 +547,24 @@ tcp_enqueue_to_output (tcp_worker_ctx_t * wrk, vlib_buffer_t * b, u32 bi, wrk->tco_next_node[!is_ip4]); } -#endif /* CLIB_MARCH_VARIANT */ - -static int -tcp_make_reset_in_place (vlib_main_t * vm, vlib_buffer_t * b, u8 is_ip4) +int +tcp_buffer_make_reset (vlib_main_t *vm, vlib_buffer_t *b, u8 is_ip4) { - ip4_header_t *ih4; - ip6_header_t *ih6; - tcp_header_t *th; - ip4_address_t src_ip4, dst_ip4; + ip4_address_t src_ip4 = {}, dst_ip4 = {}; ip6_address_t src_ip6, dst_ip6; u16 src_port, dst_port; u32 tmp, len, seq, ack; + ip4_header_t *ih4; + ip6_header_t *ih6; + tcp_header_t *th; u8 flags; - /* Find IP and TCP headers */ + /* + * Find IP and TCP headers and glean information from them. Assumes + * buffer was parsed by something like @ref tcp_input_lookup_buffer + */ th = tcp_buffer_hdr (b); - /* Save src and dst ip */ if (is_ip4) { ih4 = vlib_buffer_get_current (b); @@ -625,7 +604,23 @@ tcp_make_reset_in_place (vlib_main_t * vm, vlib_buffer_t * b, u8 is_ip4) seq = 0; } - tcp_reuse_buffer (vm, b); + /* + * Clear and reuse current buffer for reset + */ + if (b->flags & VLIB_BUFFER_NEXT_PRESENT) + vlib_buffer_free_one (vm, b->next_buffer); + + /* Zero all flags but free list index and trace flag */ + b->flags &= VLIB_BUFFER_NEXT_PRESENT - 1; + /* Make sure new tcp header comes after current ip */ + b->current_data = ((u8 *) th - b->data) + sizeof (tcp_header_t); + b->current_length = 0; + b->total_length_not_including_first_buffer = 0; + vnet_buffer (b)->tcp.flags = 0; + + /* + * Add TCP and IP headers + */ th = vlib_buffer_push_tcp_net_order (b, dst_port, src_port, seq, ack, sizeof (tcp_header_t), flags, 0); @@ -646,7 +641,6 @@ tcp_make_reset_in_place (vlib_main_t * vm, vlib_buffer_t * b, u8 is_ip4) return 0; } -#ifndef CLIB_MARCH_VARIANT /** * Send reset without reusing existing buffer * @@ -662,8 +656,8 @@ tcp_send_reset_w_pkt (tcp_connection_t * tc, vlib_buffer_t * pkt, u8 tcp_hdr_len, flags = 0; tcp_header_t *th, *pkt_th; u32 seq, ack, bi; - ip4_header_t *ih4, *pkt_ih4; - ip6_header_t *ih6, *pkt_ih6; + ip4_header_t *pkt_ih4; + ip6_header_t *pkt_ih6; if (PREDICT_FALSE (!vlib_buffer_alloc (vm, &bi, 1))) { @@ -673,6 +667,7 @@ tcp_send_reset_w_pkt (tcp_connection_t * tc, vlib_buffer_t * pkt, b = vlib_get_buffer (vm, bi); tcp_init_buffer (vm, b); + vnet_buffer (b)->tcp.connection_index = tc->c_c_index; /* Make and write options */ tcp_hdr_len = sizeof (tcp_header_t); @@ -693,6 +688,7 @@ tcp_send_reset_w_pkt (tcp_connection_t * tc, vlib_buffer_t * pkt, flags = TCP_FLAG_RST; seq = pkt_th->ack_number; ack = (tc->state >= TCP_STATE_SYN_RCVD) ? tc->rcv_nxt : 0; + ack = clib_host_to_net_u32 (ack); } else { @@ -703,28 +699,7 @@ tcp_send_reset_w_pkt (tcp_connection_t * tc, vlib_buffer_t * pkt, th = vlib_buffer_push_tcp_net_order (b, pkt_th->dst_port, pkt_th->src_port, seq, ack, tcp_hdr_len, flags, 0); - - /* Swap src and dst ip */ - if (is_ip4) - { - ASSERT ((pkt_ih4->ip_version_and_header_length & 0xF0) == 0x40); - ih4 = vlib_buffer_push_ip4 (vm, b, &pkt_ih4->dst_address, - &pkt_ih4->src_address, IP_PROTOCOL_TCP, - tcp_csum_offload (tc)); - th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih4); - } - else - { - int bogus = ~0; - ASSERT ((pkt_ih6->ip_version_traffic_class_and_flow_label & 0xF0) == - 0x60); - ih6 = vlib_buffer_push_ip6_custom (vm, b, &pkt_ih6->dst_address, - &pkt_ih6->src_address, - IP_PROTOCOL_TCP, - tc->ipv6_flow_label); - th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ih6, &bogus); - ASSERT (!bogus); - } + th->checksum = tcp_compute_checksum (tc, b); tcp_enqueue_half_open (wrk, tc, b, bi); TCP_EVT (TCP_EVT_RST_SENT, tc); @@ -792,7 +767,7 @@ tcp_send_syn (tcp_connection_t * tc) * such that we can return if we've ran out. */ tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN, - tc->rto * TCP_TO_TIMER_TICK); + (u32) tc->rto * TCP_TO_TIMER_TICK); if (PREDICT_FALSE (!vlib_buffer_alloc (vm, &bi, 1))) { @@ -863,10 +838,9 @@ tcp_send_fin (tcp_connection_t * tc) /* Out of buffers so program fin retransmit ASAP */ tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT, tcp_cfg.alloc_err_timeout); - if (fin_snt) - tc->snd_nxt += 1; - else - /* Make sure retransmit retries a fin not data */ + tc->snd_nxt += 1; + /* Make sure retransmit retries a fin not data with right snd_nxt */ + if (!fin_snt) tc->flags |= TCP_CONN_FINSNT; tcp_worker_stats_inc (wrk, no_buffer, 1); return; @@ -968,11 +942,9 @@ tcp_buffer_len (vlib_buffer_t * b) return data_len; } -u32 -tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b) +always_inline u32 +tcp_push_one_header (tcp_connection_t *tc, vlib_buffer_t *b) { - tcp_connection_t *tc = (tcp_connection_t *) tconn; - if (tc->cfg_flags & TCP_CFG_F_RATE_SAMPLE) tcp_bt_track_tx (tc, tcp_buffer_len (b)); @@ -980,6 +952,37 @@ tcp_session_push_header (transport_connection_t * tconn, vlib_buffer_t * b) /* update_snd_nxt */ 1); tcp_validate_txf_size (tc, tc->snd_nxt - tc->snd_una); + return 0; +} + +u32 +tcp_session_push_header (transport_connection_t *tconn, vlib_buffer_t **bs, + u32 n_bufs) +{ + tcp_connection_t *tc = (tcp_connection_t *) tconn; + + while (n_bufs >= 4) + { + vlib_prefetch_buffer_header (bs[2], STORE); + vlib_prefetch_buffer_header (bs[3], STORE); + + tcp_push_one_header (tc, bs[0]); + tcp_push_one_header (tc, bs[1]); + + n_bufs -= 2; + bs += 2; + } + while (n_bufs) + { + if (n_bufs > 1) + vlib_prefetch_buffer_header (bs[1], STORE); + + tcp_push_one_header (tc, bs[0]); + + n_bufs -= 1; + bs += 1; + } + /* If not tracking an ACK, start tracking */ if (tc->rtt_ts == 0 && !tcp_in_cong_recovery (tc)) { @@ -1113,7 +1116,7 @@ tcp_prepare_segment (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, data = tcp_init_buffer (vm, *b); n_bytes = session_tx_fifo_peek_bytes (&tc->connection, data, offset, max_deq_bytes); - ASSERT (n_bytes == max_deq_bytes); + ASSERT (n_bytes > 0); b[0]->current_length = n_bytes; tcp_push_hdr_i (tc, *b, tc->snd_una + offset, /* compute opts */ 0, /* burst */ 0, /* update_snd_nxt */ 0); @@ -1275,6 +1278,7 @@ tcp_cc_init_rxt_timeout (tcp_connection_t * tc) tc->cwnd_acc_bytes = 0; tc->tr_occurences += 1; tc->sack_sb.reorder = TCP_DUPACK_THRESHOLD; + tc->sack_sb.rescue_rxt = tc->snd_una - 1; tcp_recovery_on (tc); } @@ -1341,7 +1345,10 @@ tcp_timer_retransmit_handler (tcp_connection_t * tc) } if (tcp_opts_sack_permitted (&tc->rcv_opts)) - tcp_check_sack_reneging (tc); + { + tcp_check_sack_reneging (tc); + scoreboard_rxt_mark_lost (&tc->sack_sb, tc->snd_una, tc->snd_nxt); + } /* Update send congestion to make sure that rxt has data to send */ tc->snd_congestion = tc->snd_nxt; @@ -1482,7 +1489,7 @@ tcp_timer_retransmit_syn_handler (tcp_connection_t * tc) tcp_enqueue_half_open (wrk, tc, b, bi); tcp_timer_update (&wrk->timer_wheel, tc, TCP_TIMER_RETRANSMIT_SYN, - tc->rto * TCP_TO_TIMER_TICK); + (u32) tc->rto * TCP_TO_TIMER_TICK); } /** @@ -1538,8 +1545,10 @@ tcp_timer_persist_handler (tcp_connection_t * tc) tcp_validate_txf_size (tc, offset); tc->snd_opts_len = tcp_make_options (tc, &tc->snd_opts, tc->state); - max_snd_bytes = clib_min (tc->snd_mss, + max_snd_bytes = clib_min (clib_min (tc->snd_mss, available_bytes), tm->bytes_per_buffer - TRANSPORT_MAX_HDRS_LEN); + if (tc->snd_wnd > 0) + max_snd_bytes = clib_min (tc->snd_wnd, max_snd_bytes); n_bytes = session_tx_fifo_peek_bytes (&tc->connection, data, offset, max_snd_bytes); b->current_length = n_bytes; @@ -1720,7 +1729,7 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, && tc->rxt_head != tc->snd_una && tcp_retransmit_should_retry_head (tc, sb)) { - max_bytes = clib_min (tc->snd_mss, tc->snd_congestion - tc->snd_una); + max_bytes = clib_min (tc->snd_mss, tc->snd_nxt - tc->snd_una); n_written = tcp_prepare_retransmit_segment (wrk, tc, 0, max_bytes, &b); if (!n_written) { @@ -1752,7 +1761,7 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, if (!hole) { /* We are out of lost holes to retransmit so send some new data. */ - if (max_deq > tc->snd_mss) + if (max_deq) { u32 n_segs_new; int av_wnd; @@ -1762,7 +1771,10 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, av_wnd = (int) tc->snd_wnd - (tc->snd_nxt - tc->snd_una); av_wnd = clib_max (av_wnd - tc->snd_mss, 0); snd_space = clib_min (snd_space, av_wnd); - snd_space = clib_min (max_deq, snd_space); + /* Low bound max_deq to mss to be able to send a segment even + * when it is less than mss */ + snd_space = + clib_min (clib_max (max_deq, tc->snd_mss), snd_space); burst_size = clib_min (burst_size - n_segs, snd_space / tc->snd_mss); burst_size = clib_min (burst_size, TCP_RXT_MAX_BURST); @@ -1774,8 +1786,7 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, goto done; } - if (tcp_in_recovery (tc) || !can_rescue - || scoreboard_rescue_rxt_valid (sb, tc)) + if (!can_rescue || scoreboard_rescue_rxt_valid (sb, tc)) break; /* If rescue rxt undefined or less than snd_una then one segment of @@ -1799,7 +1810,11 @@ tcp_retransmit_sack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, break; } - max_bytes = clib_min (hole->end - sb->high_rxt, snd_space); + max_bytes = hole->end - sb->high_rxt; + /* Avoid retransmitting segment less than mss if possible */ + if (snd_space < tc->snd_mss && max_bytes > snd_space) + break; + max_bytes = clib_min (max_bytes, snd_space); max_bytes = snd_limited ? clib_min (max_bytes, tc->snd_mss) : max_bytes; if (max_bytes == 0) break; @@ -2162,6 +2177,7 @@ tcp46_output_inline (vlib_main_t * vm, vlib_node_runtime_t * node, u32 n_left_from, *from, thread_index = vm->thread_index; vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; u16 nexts[VLIB_FRAME_SIZE], *next; + u16 err_counters[TCP_N_ERROR] = { 0 }; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; @@ -2212,7 +2228,8 @@ tcp46_output_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - b[0]->error = node->errors[TCP_ERROR_INVALID_CONNECTION]; + tcp_inc_err_counter (err_counters, TCP_ERROR_INVALID_CONNECTION, + 1); next[0] = TCP_OUTPUT_NEXT_DROP; } if (tc1 != 0) @@ -2223,7 +2240,8 @@ tcp46_output_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - b[1]->error = node->errors[TCP_ERROR_INVALID_CONNECTION]; + tcp_inc_err_counter (err_counters, TCP_ERROR_INVALID_CONNECTION, + 1); next[1] = TCP_OUTPUT_NEXT_DROP; } } @@ -2253,7 +2271,7 @@ tcp46_output_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - b[0]->error = node->errors[TCP_ERROR_INVALID_CONNECTION]; + tcp_inc_err_counter (err_counters, TCP_ERROR_INVALID_CONNECTION, 1); next[0] = TCP_OUTPUT_NEXT_DROP; } @@ -2262,6 +2280,7 @@ tcp46_output_inline (vlib_main_t * vm, vlib_node_runtime_t * node, n_left_from -= 1; } + tcp_store_err_counters (output, err_counters); vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); vlib_node_increment_counter (vm, tcp_node_index (output, is_ip4), TCP_ERROR_PKTS_SENT, frame->n_vectors); @@ -2280,7 +2299,6 @@ VLIB_NODE_FN (tcp6_output_node) (vlib_main_t * vm, vlib_node_runtime_t * node, return tcp46_output_inline (vm, node, from_frame, 0 /* is_ip4 */ ); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp4_output_node) = { .name = "tcp4-output", @@ -2298,9 +2316,7 @@ VLIB_REGISTER_NODE (tcp4_output_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_tx_trace, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp6_output_node) = { .name = "tcp6-output", @@ -2318,7 +2334,6 @@ VLIB_REGISTER_NODE (tcp6_output_node) = .format_buffer = format_tcp_header, .format_trace = format_tcp_tx_trace, }; -/* *INDENT-ON* */ typedef enum _tcp_reset_next { @@ -2335,79 +2350,100 @@ typedef enum _tcp_reset_next _(DROP, "error-drop") \ _(IP_LOOKUP, "ip6-lookup") +static void +tcp_reset_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_buffer_t **bs, u32 n_bufs, u8 is_ip4) +{ + tcp_header_t *tcp; + tcp_tx_trace_t *t; + int i; + + for (i = 0; i < n_bufs; i++) + { + if (bs[i]->flags & VLIB_BUFFER_IS_TRACED) + { + tcp = vlib_buffer_get_current (bs[i]); + t = vlib_add_trace (vm, node, bs[i], sizeof (*t)); + + if (is_ip4) + { + ip4_header_t *ih4 = vlib_buffer_get_current (bs[i]); + tcp = ip4_next_header (ih4); + t->tcp_connection.c_lcl_ip.ip4 = ih4->dst_address; + t->tcp_connection.c_rmt_ip.ip4 = ih4->src_address; + t->tcp_connection.c_is_ip4 = 1; + } + else + { + ip6_header_t *ih6 = vlib_buffer_get_current (bs[i]); + tcp = ip6_next_header (ih6); + t->tcp_connection.c_lcl_ip.ip6 = ih6->dst_address; + t->tcp_connection.c_rmt_ip.ip6 = ih6->src_address; + } + t->tcp_connection.c_lcl_port = tcp->dst_port; + t->tcp_connection.c_rmt_port = tcp->src_port; + t->tcp_connection.c_proto = TRANSPORT_PROTO_TCP; + clib_memcpy_fast (&t->tcp_header, tcp, sizeof (t->tcp_header)); + } + } +} + static uword -tcp46_send_reset_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * from_frame, u8 is_ip4) +tcp46_reset_inline (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_frame_t *frame, u8 is_ip4) { - u32 error0 = TCP_ERROR_RST_SENT, next0 = TCP_RESET_NEXT_IP_LOOKUP; - u32 n_left_from, next_index, *from, *to_next; + vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; + u16 nexts[VLIB_FRAME_SIZE], *next; + u32 n_left_from, *from; - from = vlib_frame_vector_args (from_frame); - n_left_from = from_frame->n_vectors; + from = vlib_frame_vector_args (frame); + n_left_from = frame->n_vectors; + vlib_get_buffers (vm, from, bufs, n_left_from); - next_index = node->cached_next_index; + b = bufs; + next = nexts; while (n_left_from > 0) { - u32 n_left_to_next; + tcp_buffer_make_reset (vm, b[0], is_ip4); - vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); + /* IP lookup in fib where it was received. Previous value + * was overwritten by tcp-input */ + vnet_buffer (b[0])->sw_if_index[VLIB_TX] = + vec_elt (ip4_main.fib_index_by_sw_if_index, + vnet_buffer (b[0])->sw_if_index[VLIB_RX]); - while (n_left_from > 0 && n_left_to_next > 0) - { - vlib_buffer_t *b0; - tcp_tx_trace_t *t0; - tcp_header_t *th0; - u32 bi0; - - bi0 = from[0]; - to_next[0] = bi0; - from += 1; - to_next += 1; - n_left_from -= 1; - n_left_to_next -= 1; - - b0 = vlib_get_buffer (vm, bi0); - tcp_make_reset_in_place (vm, b0, is_ip4); - - /* Prepare to send to IP lookup */ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0; - - b0->error = node->errors[error0]; - b0->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; - if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - th0 = vlib_buffer_get_current (b0); - if (is_ip4) - th0 = ip4_next_header ((ip4_header_t *) th0); - else - th0 = ip6_next_header ((ip6_header_t *) th0); - t0 = vlib_add_trace (vm, node, b0, sizeof (*t0)); - clib_memcpy_fast (&t0->tcp_header, th0, - sizeof (t0->tcp_header)); - } + b[0]->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; + next[0] = TCP_RESET_NEXT_IP_LOOKUP; - vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, - n_left_to_next, bi0, next0); - } - vlib_put_next_frame (vm, node, next_index, n_left_to_next); + b += 1; + next += 1; + n_left_from -= 1; } - return from_frame->n_vectors; + + if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) + tcp_reset_trace_frame (vm, node, bufs, frame->n_vectors, is_ip4); + + vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); + + vlib_node_increment_counter (vm, node->node_index, TCP_ERROR_RST_SENT, + frame->n_vectors); + + return frame->n_vectors; } VLIB_NODE_FN (tcp4_reset_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * from_frame) { - return tcp46_send_reset_inline (vm, node, from_frame, 1); + return tcp46_reset_inline (vm, node, from_frame, 1); } VLIB_NODE_FN (tcp6_reset_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * from_frame) { - return tcp46_send_reset_inline (vm, node, from_frame, 0); + return tcp46_reset_inline (vm, node, from_frame, 0); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp4_reset_node) = { .name = "tcp4-reset", .vector_size = sizeof (u32), @@ -2421,9 +2457,7 @@ VLIB_REGISTER_NODE (tcp4_reset_node) = { }, .format_trace = format_tcp_tx_trace, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (tcp6_reset_node) = { .name = "tcp6-reset", .vector_size = sizeof (u32), @@ -2437,7 +2471,6 @@ VLIB_REGISTER_NODE (tcp6_reset_node) = { }, .format_trace = format_tcp_tx_trace, }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON diff --git a/src/vnet/tcp/tcp_packet.h b/src/vnet/tcp/tcp_packet.h index b0636d871d5..c137ea68108 100644 --- a/src/vnet/tcp/tcp_packet.h +++ b/src/vnet/tcp/tcp_packet.h @@ -16,7 +16,8 @@ #ifndef included_tcp_packet_h #define included_tcp_packet_h -#include <vnet/vnet.h> +#include <vnet/ip/ip4_packet.h> +#include <vnet/ip/ip6_packet.h> /* TCP flags bit 0 first. */ #define foreach_tcp_flag \ @@ -185,6 +186,100 @@ typedef struct #define timestamp_lt(_t1, _t2) ((i32)((_t1)-(_t2)) < 0) #define timestamp_leq(_t1, _t2) ((i32)((_t1)-(_t2)) <= 0) +always_inline void +ip4_tcp_reply_x1 (ip4_header_t *ip0, tcp_header_t *tcp0) +{ + u32 src0, dst0; + + src0 = ip0->src_address.data_u32; + dst0 = ip0->dst_address.data_u32; + ip0->src_address.data_u32 = dst0; + ip0->dst_address.data_u32 = src0; + + src0 = tcp0->src; + dst0 = tcp0->dst; + tcp0->src = dst0; + tcp0->dst = src0; +} + +always_inline void +ip4_tcp_reply_x2 (ip4_header_t *ip0, ip4_header_t *ip1, tcp_header_t *tcp0, + tcp_header_t *tcp1) +{ + u32 src0, dst0, src1, dst1; + + src0 = ip0->src_address.data_u32; + src1 = ip1->src_address.data_u32; + dst0 = ip0->dst_address.data_u32; + dst1 = ip1->dst_address.data_u32; + ip0->src_address.data_u32 = dst0; + ip1->src_address.data_u32 = dst1; + ip0->dst_address.data_u32 = src0; + ip1->dst_address.data_u32 = src1; + + src0 = tcp0->src; + src1 = tcp1->src; + dst0 = tcp0->dst; + dst1 = tcp1->dst; + tcp0->src = dst0; + tcp1->src = dst1; + tcp0->dst = src0; + tcp1->dst = src1; +} + +always_inline void +ip6_tcp_reply_x1 (ip6_header_t *ip0, tcp_header_t *tcp0) +{ + { + ip6_address_t src0, dst0; + + src0 = ip0->src_address; + dst0 = ip0->dst_address; + ip0->src_address = dst0; + ip0->dst_address = src0; + } + + { + u16 src0, dst0; + + src0 = tcp0->src; + dst0 = tcp0->dst; + tcp0->src = dst0; + tcp0->dst = src0; + } +} + +always_inline void +ip6_tcp_reply_x2 (ip6_header_t *ip0, ip6_header_t *ip1, tcp_header_t *tcp0, + tcp_header_t *tcp1) +{ + { + ip6_address_t src0, dst0, src1, dst1; + + src0 = ip0->src_address; + src1 = ip1->src_address; + dst0 = ip0->dst_address; + dst1 = ip1->dst_address; + ip0->src_address = dst0; + ip1->src_address = dst1; + ip0->dst_address = src0; + ip1->dst_address = src1; + } + + { + u16 src0, dst0, src1, dst1; + + src0 = tcp0->src; + src1 = tcp1->src; + dst0 = tcp0->dst; + dst1 = tcp1->dst; + tcp0->src = dst0; + tcp1->src = dst1; + tcp0->dst = src0; + tcp1->dst = src1; + } +} + /** * Parse TCP header options. * diff --git a/src/vnet/tcp/tcp_pg.c b/src/vnet/tcp/tcp_pg.c index 07bdb113fd0..9b98e3d8ee4 100644 --- a/src/vnet/tcp/tcp_pg.c +++ b/src/vnet/tcp/tcp_pg.c @@ -51,6 +51,13 @@ _ (ECE) \ _ (CWR) +#define foreach_tcp_options \ + _ (mss, TCP_OPTION_MSS, TCP_OPTION_LEN_MSS, 1) \ + _ (timestamp, TCP_OPTION_TIMESTAMP, TCP_OPTION_LEN_TIMESTAMP, 2) \ + _ (winscale, TCP_OPTION_WINDOW_SCALE, TCP_OPTION_LEN_WINDOW_SCALE, 1) \ + _ (sackperm, TCP_OPTION_SACK_PERMITTED, TCP_OPTION_LEN_SACK_PERMITTED, 0) \ + _ (sack, TCP_OPTION_SACK_BLOCK, TCP_OPTION_LEN_SACK_BLOCK, 0) + static void tcp_pg_edit_function (pg_main_t * pg, pg_stream_t * s, @@ -150,82 +157,192 @@ uword unformat_pg_tcp_header (unformat_input_t * input, va_list * args) { pg_stream_t *s = va_arg (*args, pg_stream_t *); - pg_tcp_header_t *p; - u32 group_index; + pg_tcp_header_t *pth; + u32 header_group_index, opt_group_index = ~0, noop_len, opts_len = 0; - p = pg_create_edit_group (s, sizeof (p[0]), sizeof (tcp_header_t), - &group_index); - pg_tcp_header_init (p); + pth = pg_create_edit_group (s, sizeof (pth[0]), sizeof (tcp_header_t), + &header_group_index); + pg_tcp_header_init (pth); /* Defaults. */ - pg_edit_set_fixed (&p->seq_number, 0); - pg_edit_set_fixed (&p->ack_number, 0); - - pg_edit_set_fixed (&p->data_offset_and_reserved, - sizeof (tcp_header_t) / sizeof (u32)); + pg_edit_set_fixed (&pth->seq_number, 0); + pg_edit_set_fixed (&pth->ack_number, 0); - pg_edit_set_fixed (&p->window, 4096); - pg_edit_set_fixed (&p->urgent_pointer, 0); + pg_edit_set_fixed (&pth->window, 4096); + pg_edit_set_fixed (&pth->urgent_pointer, 0); -#define _(f) pg_edit_set_fixed (&p->f##_flag, 0); +#define _(f) pg_edit_set_fixed (&pth->f##_flag, 0); foreach_tcp_flag #undef _ - p->checksum.type = PG_EDIT_UNSPECIFIED; + pth->checksum.type = PG_EDIT_UNSPECIFIED; - if (!unformat (input, "TCP: %U -> %U", - unformat_pg_edit, - unformat_tcp_udp_port, &p->src, - unformat_pg_edit, unformat_tcp_udp_port, &p->dst)) + if (!unformat (input, "TCP: %U -> %U", unformat_pg_edit, + unformat_tcp_udp_port, &pth->src, unformat_pg_edit, + unformat_tcp_udp_port, &pth->dst)) goto error; /* Parse options. */ while (1) { - if (unformat (input, "window %U", - unformat_pg_edit, unformat_pg_number, &p->window)) + if (unformat (input, "window %U", unformat_pg_edit, unformat_pg_number, + &pth->window)) ; - else if (unformat (input, "checksum %U", - unformat_pg_edit, unformat_pg_number, &p->checksum)) + else if (unformat (input, "checksum %U", unformat_pg_edit, + unformat_pg_number, &pth->checksum)) ; else if (unformat (input, "seqnum %U", unformat_pg_edit, - unformat_pg_number, &p->seq_number)) + unformat_pg_number, &pth->seq_number)) ; else if (unformat (input, "acknum %U", unformat_pg_edit, - unformat_pg_number, &p->ack_number)) + unformat_pg_number, &pth->ack_number)) ; /* Flags. */ -#define _(f) else if (unformat (input, #f)) pg_edit_set_fixed (&p->f##_flag, 1); +#define _(f) \ + else if (unformat (input, #f)) pg_edit_set_fixed (&pth->f##_flag, 1); foreach_tcp_flag #undef _ - /* Can't parse input: try next protocol level. */ + /* Can't parse input: try TCP options and next protocol level. */ + else break; + } + + while (unformat (input, "opt")) + { + int i; + pg_edit_t *opt_header, *opt_values; + u8 type, opt_len, n_values; + + /* first allocate a new edit group for options */ + if (opt_group_index == ~0) + (void) pg_create_edit_group (s, 0, 0, &opt_group_index); + + if (false) + { + } +#define _(n, t, l, k) \ + else if (unformat (input, #n)) \ + { \ + type = (t); \ + opt_len = (l); \ + n_values = (k); \ + } + foreach_tcp_options +#undef _ else + { + /* unknown TCP option */ break; + } + +#define pg_tcp_option_init(e, o, b) \ + do \ + { \ + *(o) += (b); \ + (e)->lsb_bit_offset = *(o) > 0 ? (*(o) -1) * BITS (u8) : 0; \ + (e)->n_bits = (b) *BITS (u8); \ + } \ + while (0); + + /* if we don't know how many values to read, just ask */ + if (n_values == 0 && + unformat (input, "nvalues %D", sizeof (n_values), &n_values)) + { + switch (type) + { + case TCP_OPTION_SACK_BLOCK: + /* each sack block is composed of 2 32-bits values */ + n_values *= 2; + /* + opt_len contains the length of a single sack block, + it needs to be updated to contains the final number of bytes + for the sack options + */ + opt_len = 2 + 2 * opt_len; + break; + default: + /* unknown variable options */ + continue; + } + } + + opt_header = pg_add_edits (s, sizeof (pg_edit_t) * (2 + n_values), + opt_len, opt_group_index); + pg_tcp_option_init (opt_header, &opts_len, 1); + pg_tcp_option_init (opt_header + 1, &opts_len, 1); + pg_edit_set_fixed (opt_header, type); + pg_edit_set_fixed (opt_header + 1, opt_len); + opt_values = opt_header + 2; + + switch (type) + { + case TCP_OPTION_MSS: + pg_tcp_option_init (opt_values, &opts_len, 2); + break; + case TCP_OPTION_WINDOW_SCALE: + pg_tcp_option_init (opt_values, &opts_len, 1); + break; + case TCP_OPTION_TIMESTAMP: + case TCP_OPTION_SACK_BLOCK: + for (i = 0; i < n_values; ++i) + pg_tcp_option_init (opt_values + i, &opts_len, 4); + break; + default: + break; + } + + for (i = 0; i < n_values; ++i) + { + if (!unformat (input, "%U", unformat_pg_edit, unformat_pg_number, + opt_values + i)) + goto error; + } } + /* add TCP NO-OP options to fill options up to a 4-bytes boundary */ + noop_len = (TCP_OPTS_ALIGN - opts_len % TCP_OPTS_ALIGN) % TCP_OPTS_ALIGN; + if (noop_len > 0) + { + pg_edit_t *noop_edit; + u8 *noops = 0; + + vec_validate (noops, noop_len - 1); + clib_memset (noops, 1, noop_len); + + noop_edit = + pg_add_edits (s, sizeof (noop_edit[0]), noop_len, opt_group_index); + pg_tcp_option_init (noop_edit, &opts_len, noop_len); + noop_edit->type = PG_EDIT_FIXED; + noop_edit->values[PG_EDIT_LO] = noops; + } +#undef pg_tcp_option_init + + /* set the data offset according to options */ + pg_edit_set_fixed (&pth->data_offset_and_reserved, + (sizeof (tcp_header_t) + opts_len) / sizeof (u32)); + { ip_main_t *im = &ip_main; u16 dst_port; tcp_udp_port_info_t *pi; pi = 0; - if (p->dst.type == PG_EDIT_FIXED) + if (pth->dst.type == PG_EDIT_FIXED) { - dst_port = pg_edit_get_value (&p->dst, PG_EDIT_LO); + dst_port = pg_edit_get_value (&pth->dst, PG_EDIT_LO); pi = ip_get_tcp_udp_port_info (im, dst_port); } - if (pi && pi->unformat_pg_edit - && unformat_user (input, pi->unformat_pg_edit, s)) + if (pi && pi->unformat_pg_edit && + unformat_user (input, pi->unformat_pg_edit, s)) ; else if (!unformat_user (input, unformat_pg_payload, s)) goto error; - if (p->checksum.type == PG_EDIT_UNSPECIFIED) + if (pth->checksum.type == PG_EDIT_UNSPECIFIED) { - pg_edit_group_t *g = pg_stream_get_group (s, group_index); + pg_edit_group_t *g = pg_stream_get_group (s, header_group_index); g->edit_function = tcp_pg_edit_function; g->edit_function_opaque = 0; } diff --git a/src/vnet/tcp/tcp_sack.c b/src/vnet/tcp/tcp_sack.c index 8f51b517361..63af07b50cd 100644 --- a/src/vnet/tcp/tcp_sack.c +++ b/src/vnet/tcp/tcp_sack.c @@ -265,6 +265,27 @@ scoreboard_init_rxt (sack_scoreboard_t * sb, u32 snd_una) } void +scoreboard_rxt_mark_lost (sack_scoreboard_t *sb, u32 snd_una, u32 snd_nxt) +{ + sack_scoreboard_hole_t *hole; + + hole = scoreboard_first_hole (sb); + if (!hole) + { + hole = scoreboard_insert_hole (sb, TCP_INVALID_SACK_HOLE_INDEX, snd_una, + snd_nxt); + sb->tail = scoreboard_hole_index (sb, hole); + sb->high_sacked = snd_una; + } + + if (hole->is_lost) + return; + + hole->is_lost = 1; + sb->lost_bytes += scoreboard_hole_bytes (hole); +} + +void scoreboard_init (sack_scoreboard_t * sb) { sb->head = TCP_INVALID_SACK_HOLE_INDEX; diff --git a/src/vnet/tcp/tcp_sack.h b/src/vnet/tcp/tcp_sack.h index 1c3fa95510b..bb206b92dbb 100644 --- a/src/vnet/tcp/tcp_sack.h +++ b/src/vnet/tcp/tcp_sack.h @@ -105,6 +105,8 @@ void scoreboard_clear (sack_scoreboard_t * sb); void scoreboard_clear_reneging (sack_scoreboard_t * sb, u32 start, u32 end); void scoreboard_init (sack_scoreboard_t * sb); void scoreboard_init_rxt (sack_scoreboard_t * sb, u32 snd_una); +void scoreboard_rxt_mark_lost (sack_scoreboard_t *sb, u32 snd_una, + u32 snd_nxt); format_function_t format_tcp_scoreboard; diff --git a/src/vnet/tcp/tcp_syn_filter4.c b/src/vnet/tcp/tcp_syn_filter4.c index 1b003e04e51..6e867240ad6 100644 --- a/src/vnet/tcp/tcp_syn_filter4.c +++ b/src/vnet/tcp/tcp_syn_filter4.c @@ -399,7 +399,6 @@ VLIB_NODE_FN (syn_filter4_node) (vlib_main_t * vm, return frame->n_vectors; } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (syn_filter4_node) = { .name = "syn-filter-4", @@ -418,16 +417,13 @@ VLIB_REGISTER_NODE (syn_filter4_node) = [SYN_FILTER_NEXT_DROP] = "error-drop", }, }; -/* *INDENT-ON* */ -/* *INDENT-OFF* */ VNET_FEATURE_INIT (syn_filter_4, static) = { .arc_name = "ip4-local", .node_name = "syn-filter-4", .runs_before = VNET_FEATURES("ip4-local-end-of-arc"), }; -/* *INDENT-ON* */ #ifndef CLIB_MARCH_VARIANT int @@ -525,14 +521,12 @@ syn_filter_enable_disable_command_fn (vlib_main_t * vm, return 0; } -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (sr_content_command, static) = { .path = "ip syn filter", .short_help = "ip syn filter <interface-name> [disable]", .function = syn_filter_enable_disable_command_fn, }; -/* *INDENT-ON* */ #endif /* CLIB_MARCH_VARIANT */ /* diff --git a/src/vnet/tcp/tcp_timer.h b/src/vnet/tcp/tcp_timer.h index 4668c79cabf..c0907cae1cc 100644 --- a/src/vnet/tcp/tcp_timer.h +++ b/src/vnet/tcp/tcp_timer.h @@ -17,11 +17,18 @@ #include <vnet/tcp/tcp_types.h> +static inline u8 +tcp_timer_thread_is_valid (tcp_connection_t *tc) +{ + return ((tc->c_thread_index == vlib_get_thread_index ()) || + vlib_thread_is_main_w_barrier ()); +} + always_inline void -tcp_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id, +tcp_timer_set (tcp_timer_wheel_t *tw, tcp_connection_t *tc, u8 timer_id, u32 interval) { - ASSERT (tc->c_thread_index == vlib_get_thread_index ()); + ASSERT (tcp_timer_thread_is_valid (tc)); ASSERT (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID); tc->timers[timer_id] = tw_timer_start_tcp_twsl (tw, tc->c_c_index, timer_id, interval); @@ -30,7 +37,7 @@ tcp_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id, always_inline void tcp_timer_reset (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id) { - ASSERT (tc->c_thread_index == vlib_get_thread_index ()); + ASSERT (tcp_timer_thread_is_valid (tc)); tc->pending_timers &= ~(1 << timer_id); if (tc->timers[timer_id] == TCP_TIMER_HANDLE_INVALID) return; @@ -43,7 +50,7 @@ always_inline void tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id, u32 interval) { - ASSERT (tc->c_thread_index == vlib_get_thread_index ()); + ASSERT (tcp_timer_thread_is_valid (tc)); if (tc->timers[timer_id] != TCP_TIMER_HANDLE_INVALID) tw_timer_update_tcp_twsl (tw, tc->timers[timer_id], interval); else @@ -51,12 +58,19 @@ tcp_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc, u8 timer_id, timer_id, interval); } +always_inline u8 +tcp_timer_is_active (tcp_connection_t *tc, tcp_timers_e timer) +{ + return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID || + (tc->pending_timers & (1 << timer)); +} + always_inline void tcp_retransmit_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc) { ASSERT (tc->snd_una != tc->snd_nxt); tcp_timer_set (tw, tc, TCP_TIMER_RETRANSMIT, - clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); + clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1)); } always_inline void @@ -70,20 +84,7 @@ tcp_persist_timer_set (tcp_timer_wheel_t * tw, tcp_connection_t * tc) { /* Reuse RTO. It's backed off in handler */ tcp_timer_set (tw, tc, TCP_TIMER_PERSIST, - clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); -} - -always_inline void -tcp_persist_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc) -{ - u32 interval; - - if (seq_leq (tc->snd_una, tc->snd_congestion + tc->burst_acked)) - interval = 1; - else - interval = clib_max (tc->rto * TCP_TO_TIMER_TICK, 1); - - tcp_timer_update (tw, tc, TCP_TIMER_PERSIST, interval); + clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1)); } always_inline void @@ -98,19 +99,13 @@ tcp_retransmit_timer_update (tcp_timer_wheel_t * tw, tcp_connection_t * tc) if (tc->snd_una == tc->snd_nxt) { tcp_retransmit_timer_reset (tw, tc); - if (tc->snd_wnd < tc->snd_mss) - tcp_persist_timer_update (tw, tc); + if (tc->snd_wnd < tc->snd_mss && + !tcp_timer_is_active (tc, TCP_TIMER_PERSIST)) + tcp_persist_timer_set (tw, tc); } else tcp_timer_update (tw, tc, TCP_TIMER_RETRANSMIT, - clib_max (tc->rto * TCP_TO_TIMER_TICK, 1)); -} - -always_inline u8 -tcp_timer_is_active (tcp_connection_t * tc, tcp_timers_e timer) -{ - return tc->timers[timer] != TCP_TIMER_HANDLE_INVALID - || (tc->pending_timers & (1 << timer)); + clib_max ((u32) tc->rto * TCP_TO_TIMER_TICK, 1)); } always_inline void diff --git a/src/vnet/tcp/tcp_types.h b/src/vnet/tcp/tcp_types.h index aacfd8f2fd4..f9a9ff9a4da 100644 --- a/src/vnet/tcp/tcp_types.h +++ b/src/vnet/tcp/tcp_types.h @@ -389,7 +389,6 @@ typedef struct _tcp_connection #define rst_state snd_wl1 } tcp_connection_t; -/* *INDENT-OFF* */ struct _tcp_cc_algorithm { const char *name; @@ -406,7 +405,6 @@ struct _tcp_cc_algorithm void (*event) (tcp_connection_t *tc, tcp_cc_event_t evt); u64 (*get_pacing_rate) (tcp_connection_t *tc); }; -/* *INDENT-ON* */ #define tcp_fastrecovery_on(tc) (tc)->flags |= TCP_CONN_FAST_RECOVERY #define tcp_fastrecovery_off(tc) (tc)->flags &= ~TCP_CONN_FAST_RECOVERY |