X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Ftcp%2Ftcp_input.c;h=45a40a276b000214688ca375cb07ee96a83967fe;hb=a2c0637129f0c642a4d55df297bb353243ca7a49;hp=848028f6940431c3a10c3d13f9737f5363e7d9f6;hpb=f73d4c2084c9cb6df4a1f8582acef523e4ba0cb2;p=vpp.git diff --git a/src/vnet/tcp/tcp_input.c b/src/vnet/tcp/tcp_input.c old mode 100644 new mode 100755 index 848028f6940..45a40a276b0 --- a/src/vnet/tcp/tcp_input.c +++ b/src/vnet/tcp/tcp_input.c @@ -300,8 +300,8 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0, if (PREDICT_FALSE (tcp_segment_check_paws (tc0))) { *error0 = TCP_ERROR_PAWS; - TCP_EVT_DBG (TCP_EVT_PAWS_FAIL, tc0, vnet_buffer (b0)->tcp.seq_number, - vnet_buffer (b0)->tcp.seq_end); + TCP_EVT (TCP_EVT_PAWS_FAIL, tc0, vnet_buffer (b0)->tcp.seq_number, + vnet_buffer (b0)->tcp.seq_end); /* If it just so happens that a segment updates tsval_recent for a * segment over 24 days old, invalidate tsval_recent. */ @@ -317,8 +317,8 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0, * SEG.TSval */ else if (!tcp_rst (th0)) { - tcp_program_ack (wrk, tc0); - TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp); + tcp_program_ack (tc0); + TCP_EVT (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp); goto error; } } @@ -335,13 +335,13 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0, if (tc0->state == TCP_STATE_SYN_RCVD) { tcp_send_synack (tc0); - TCP_EVT_DBG (TCP_EVT_SYN_RCVD, tc0, 0); + TCP_EVT (TCP_EVT_SYN_RCVD, tc0, 0); *error0 = TCP_ERROR_SYNS_RCVD; } else { - tcp_program_ack (wrk, tc0); - TCP_EVT_DBG (TCP_EVT_SYNACK_RCVD, tc0); + tcp_program_ack (tc0); + TCP_EVT (TCP_EVT_SYNACK_RCVD, tc0); *error0 = TCP_ERROR_SYN_ACKS_RCVD; } goto error; @@ -365,11 +365,21 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0, *error0 = TCP_ERROR_RCV_WND; + /* If we advertised a zero rcv_wnd and the segment is in the past or the + * next one that we expect, it is probably a window probe */ + if ((tc0->flags & TCP_CONN_ZERO_RWND_SENT) + && seq_lt (vnet_buffer (b0)->tcp.seq_end, + tc0->rcv_las + tc0->rcv_opts.mss)) + *error0 = TCP_ERROR_ZERO_RWND; + + tc0->errors.below_data_wnd += seq_lt (vnet_buffer (b0)->tcp.seq_end, + tc0->rcv_las); + /* If not RST, send dup ack */ if (!tcp_rst (th0)) { - tcp_program_dupack (wrk, tc0); - TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp); + tcp_program_dupack (tc0); + TCP_EVT (TCP_EVT_DUPACK_SENT, tc0, vnet_buffer (b0)->tcp); } goto error; @@ -391,7 +401,7 @@ tcp_segment_validate (tcp_worker_ctx_t * wrk, tcp_connection_t * tc0, if (PREDICT_FALSE (tcp_syn (th0))) { /* As per RFC5961 send challenge ack instead of reset */ - tcp_program_ack (wrk, tc0); + tcp_program_ack (tc0); *error0 = TCP_ERROR_SPURIOUS_SYN; goto error; } @@ -508,7 +518,7 @@ tcp_update_rtt (tcp_connection_t * tc, u32 ack) * seq_lt (tc->snd_una, ack). This is a condition for calling update_rtt */ else if (tcp_opts_tstamp (&tc->rcv_opts) && tc->rcv_opts.tsecr) { - u32 now = tcp_time_now_w_thread (tc->c_thread_index); + u32 now = tcp_tstamp (tc); mrtt = clib_max (now - tc->rcv_opts.tsecr, 1); } @@ -775,6 +785,7 @@ scoreboard_update_bytes (tcp_connection_t * tc, sack_scoreboard_t * sb) sack_scoreboard_hole_t *left, *right; u32 bytes = 0, blks = 0; + sb->last_lost_bytes = 0; sb->lost_bytes = 0; sb->sacked_bytes = 0; left = scoreboard_last_hole (sb); @@ -803,6 +814,7 @@ scoreboard_update_bytes (tcp_connection_t * tc, sack_scoreboard_t * sb) do { sb->lost_bytes += scoreboard_hole_bytes (right); + sb->last_lost_bytes += left->is_lost ? 0 : left->end - left->start; left->is_lost = 1; left = scoreboard_prev_hole (sb, right); if (left) @@ -914,6 +926,7 @@ scoreboard_clear (sack_scoreboard_t * sb) sb->high_sacked = 0; sb->high_rxt = 0; sb->lost_bytes = 0; + sb->last_lost_bytes = 0; sb->cur_rxt_hole = TCP_INVALID_SACK_HOLE_INDEX; } #endif /* CLIB_MARCH_VARIANT */ @@ -934,13 +947,14 @@ tcp_scoreboard_is_sane_post_recovery (tcp_connection_t * tc) } #ifndef CLIB_MARCH_VARIANT + void tcp_rcv_sacks (tcp_connection_t * tc, u32 ack) { - sack_scoreboard_t *sb = &tc->sack_sb; - sack_block_t *blk, tmp; sack_scoreboard_hole_t *hole, *next_hole, *last_hole; u32 blk_index = 0, old_sacked_bytes, hole_index; + sack_scoreboard_t *sb = &tc->sack_sb; + sack_block_t *blk, tmp; int i, j; sb->last_sacked_bytes = 0; @@ -1055,7 +1069,6 @@ tcp_rcv_sacks (tcp_connection_t * tc, u32 ack) sb->last_bytes_delivered += sb->high_sacked - hole->end; } } - scoreboard_remove_hole (sb, hole); hole = next_hole; } @@ -1102,6 +1115,7 @@ tcp_rcv_sacks (tcp_connection_t * tc, u32 ack) scoreboard_update_bytes (tc, sb); sb->last_sacked_bytes = sb->sacked_bytes - (old_sacked_bytes - sb->last_bytes_delivered); + ASSERT (sb->last_sacked_bytes <= sb->sacked_bytes || tcp_in_recovery (tc)); ASSERT (sb->sacked_bytes == 0 || tcp_in_recovery (tc) || sb->sacked_bytes < tc->snd_nxt - seq_max (tc->snd_una, ack)); @@ -1109,7 +1123,9 @@ tcp_rcv_sacks (tcp_connection_t * tc, u32 ack) - seq_max (tc->snd_una, ack) || tcp_in_recovery (tc)); ASSERT (sb->head == TCP_INVALID_SACK_HOLE_INDEX || tcp_in_recovery (tc) || sb->holes[sb->head].start == ack + sb->snd_una_adv); - TCP_EVT_DBG (TCP_EVT_CC_SCOREBOARD, tc); + ASSERT (sb->last_lost_bytes <= sb->lost_bytes); + + TCP_EVT (TCP_EVT_CC_SCOREBOARD, tc); } #endif /* CLIB_MARCH_VARIANT */ @@ -1130,7 +1146,7 @@ tcp_update_snd_wnd (tcp_connection_t * tc, u32 seq, u32 ack, u32 snd_wnd) tc->snd_wnd = snd_wnd; tc->snd_wl1 = seq; tc->snd_wl2 = ack; - TCP_EVT_DBG (TCP_EVT_SND_WND, tc); + TCP_EVT (TCP_EVT_SND_WND, tc); if (PREDICT_FALSE (tc->snd_wnd < tc->snd_mss)) { @@ -1168,7 +1184,8 @@ tcp_cc_init_congestion (tcp_connection_t * tc) tc->prev_ssthresh = tc->ssthresh; tc->prev_cwnd = tc->cwnd; tc->cc_algo->congestion (tc); - TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 4); + tc->fr_occurences += 1; + TCP_EVT (TCP_EVT_CC_EVT, tc, 4); } #endif /* CLIB_MARCH_VARIANT */ @@ -1180,23 +1197,22 @@ tcp_cc_recovery_exit (tcp_connection_t * tc) tc->snd_rxt_ts = 0; tc->rtt_ts = 0; tcp_recovery_off (tc); - TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3); + TCP_EVT (TCP_EVT_CC_EVT, tc, 3); } #ifndef CLIB_MARCH_VARIANT void -tcp_cc_fastrecovery_exit (tcp_connection_t * tc) +tcp_cc_fastrecovery_clear (tcp_connection_t * tc) { - tc->cc_algo->recovered (tc); tc->snd_rxt_bytes = 0; tc->rcv_dupacks = 0; - tc->snd_rxt_bytes = 0; tc->rtt_ts = 0; tcp_fastrecovery_off (tc); tcp_fastrecovery_first_off (tc); + tc->flags &= ~TCP_CONN_FRXT_PENDING; - TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 3); + TCP_EVT (TCP_EVT_CC_EVT, tc, 3); } #endif /* CLIB_MARCH_VARIANT */ @@ -1213,10 +1229,11 @@ tcp_cc_congestion_undo (tcp_connection_t * tc) } else if (tcp_in_fastrecovery (tc)) { - tcp_cc_fastrecovery_exit (tc); + tcp_cc_fastrecovery_clear (tc); } + tcp_cc_undo_recovery (tc); ASSERT (tc->rto_boff == 0); - TCP_EVT_DBG (TCP_EVT_CC_EVT, tc, 5); + TCP_EVT (TCP_EVT_CC_EVT, tc, 5); } static inline u8 @@ -1255,7 +1272,10 @@ tcp_cc_recover (tcp_connection_t * tc) if (tcp_in_recovery (tc)) tcp_cc_recovery_exit (tc); else if (tcp_in_fastrecovery (tc)) - tcp_cc_fastrecovery_exit (tc); + { + tcp_cc_recovered (tc); + tcp_cc_fastrecovery_clear (tc); + } ASSERT (tc->rto_boff == 0); ASSERT (!tcp_in_cong_recovery (tc)); @@ -1297,81 +1317,6 @@ tcp_should_fastrecover (tcp_connection_t * tc) || tcp_should_fastrecover_sack (tc)); } -#ifndef CLIB_MARCH_VARIANT -void -tcp_program_fastretransmit (tcp_worker_ctx_t * wrk, tcp_connection_t * tc) -{ - if (!(tc->flags & TCP_CONN_FRXT_PENDING)) - { - vec_add1 (wrk->pending_fast_rxt, tc->c_c_index); - tc->flags |= TCP_CONN_FRXT_PENDING; - } -} - -void -tcp_do_fastretransmits (tcp_worker_ctx_t * wrk) -{ - u32 *ongoing_fast_rxt, burst_bytes, sent_bytes, thread_index; - u32 max_burst_size, burst_size, n_segs = 0, n_segs_now; - tcp_connection_t *tc; - u64 last_cpu_time; - int i; - - if (vec_len (wrk->pending_fast_rxt) == 0 - && vec_len (wrk->postponed_fast_rxt) == 0) - return; - - thread_index = wrk->vm->thread_index; - last_cpu_time = wrk->vm->clib_time.last_cpu_time; - ongoing_fast_rxt = wrk->ongoing_fast_rxt; - vec_append (ongoing_fast_rxt, wrk->postponed_fast_rxt); - vec_append (ongoing_fast_rxt, wrk->pending_fast_rxt); - - _vec_len (wrk->postponed_fast_rxt) = 0; - _vec_len (wrk->pending_fast_rxt) = 0; - - max_burst_size = VLIB_FRAME_SIZE / vec_len (ongoing_fast_rxt); - max_burst_size = clib_max (max_burst_size, 1); - - for (i = 0; i < vec_len (ongoing_fast_rxt); i++) - { - tc = tcp_connection_get (ongoing_fast_rxt[i], thread_index); - if (!tc) - continue; - if (!tcp_in_fastrecovery (tc)) - { - tc->flags &= ~TCP_CONN_FRXT_PENDING; - continue; - } - - if (n_segs >= VLIB_FRAME_SIZE) - { - vec_add1 (wrk->postponed_fast_rxt, ongoing_fast_rxt[i]); - continue; - } - - tc->flags &= ~TCP_CONN_FRXT_PENDING; - burst_size = clib_min (max_burst_size, VLIB_FRAME_SIZE - n_segs); - burst_bytes = transport_connection_tx_pacer_burst (&tc->connection, - last_cpu_time); - burst_size = clib_min (burst_size, burst_bytes / tc->snd_mss); - if (!burst_size) - { - tcp_program_fastretransmit (wrk, tc); - continue; - } - - n_segs_now = tcp_fast_retransmit (wrk, tc, burst_size); - sent_bytes = clib_min (n_segs_now * tc->snd_mss, burst_bytes); - transport_connection_tx_pacer_update_bytes (&tc->connection, - sent_bytes); - n_segs += n_segs_now; - } - _vec_len (ongoing_fast_rxt) = 0; - wrk->ongoing_fast_rxt = ongoing_fast_rxt; -} -#endif /* CLIB_MARCH_VARIANT */ - /** * One function to rule them all ... and in the darkness bind them */ @@ -1385,7 +1330,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, { if (tc->bytes_acked) goto partial_ack; - tcp_program_fastretransmit (tcp_get_worker (tc->c_thread_index), tc); + tcp_program_fastretransmit (tc); return; } /* @@ -1394,7 +1339,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, */ else if (is_dack && !tcp_in_recovery (tc)) { - TCP_EVT_DBG (TCP_EVT_DUPACK_RCVD, tc, 1); + TCP_EVT (TCP_EVT_DUPACK_RCVD, tc, 1); ASSERT (tc->snd_una != tc->snd_nxt || tc->sack_sb.last_sacked_bytes); tc->rcv_dupacks++; @@ -1441,8 +1386,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, pacer_wnd = clib_max (0.1 * tc->cwnd, 2 * tc->snd_mss); tcp_connection_tx_pacer_reset (tc, pacer_wnd, 0 /* start bucket */ ); - tcp_program_fastretransmit (tcp_get_worker (tc->c_thread_index), - tc); + tcp_program_fastretransmit (tc); return; } else if (!tc->bytes_acked @@ -1481,7 +1425,7 @@ tcp_cc_handle_event (tcp_connection_t * tc, tcp_rate_sample_t * rs, return; partial_ack: - TCP_EVT_DBG (TCP_EVT_CC_PACK, tc); + TCP_EVT (TCP_EVT_CC_PACK, tc); /* * Legitimate ACK. 1) See if we can exit recovery @@ -1563,7 +1507,7 @@ partial_ack: /* * Since this was a partial ack, try to retransmit some more data */ - tcp_program_fastretransmit (tcp_get_worker (tc->c_thread_index), tc); + tcp_program_fastretransmit (tc); } /** @@ -1577,7 +1521,7 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b, tcp_rate_sample_t rs = { 0 }; u8 is_dack; - TCP_EVT_DBG (TCP_EVT_CC_STAT, tc); + TCP_EVT (TCP_EVT_CC_STAT, tc); /* 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))) @@ -1591,18 +1535,18 @@ tcp_rcv_ack (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b, goto process_ack; } + tc->errors.above_ack_wnd += 1; *error = TCP_ERROR_ACK_FUTURE; - TCP_EVT_DBG (TCP_EVT_ACK_RCV_ERR, tc, 0, - vnet_buffer (b)->tcp.ack_number); + TCP_EVT (TCP_EVT_ACK_RCV_ERR, tc, 0, vnet_buffer (b)->tcp.ack_number); return -1; } /* If old ACK, probably it's an old dupack */ if (PREDICT_FALSE (seq_lt (vnet_buffer (b)->tcp.ack_number, tc->snd_una))) { + tc->errors.below_ack_wnd += 1; *error = TCP_ERROR_ACK_OLD; - TCP_EVT_DBG (TCP_EVT_ACK_RCV_ERR, tc, 1, - vnet_buffer (b)->tcp.ack_number); + TCP_EVT (TCP_EVT_ACK_RCV_ERR, tc, 1, vnet_buffer (b)->tcp.ack_number); if (tcp_in_fastrecovery (tc) && tc->rcv_dupacks == TCP_DUPACK_THRESHOLD) tcp_cc_handle_event (tc, 0, 1); /* Don't drop yet */ @@ -1614,6 +1558,7 @@ process_ack: /* * Looks okay, process feedback */ + if (tcp_opts_sack_permitted (&tc->rcv_opts)) tcp_rcv_sacks (tc, vnet_buffer (b)->tcp.ack_number); @@ -1635,7 +1580,7 @@ process_ack: if (tc->flags & TCP_CONN_RATE_SAMPLE) tcp_bt_sample_delivery_rate (tc, &rs); - TCP_EVT_DBG (TCP_EVT_ACK_RCVD, tc); + TCP_EVT (TCP_EVT_ACK_RCVD, tc); /* * Check if we have congestion event @@ -1644,6 +1589,7 @@ process_ack: if (tcp_ack_is_cc_event (tc, b, prev_snd_wnd, prev_snd_una, &is_dack)) { tcp_cc_handle_event (tc, &rs, is_dack); + tc->dupacks_in += is_dack; if (!tcp_in_cong_recovery (tc)) { *error = TCP_ERROR_ACK_OK; @@ -1704,13 +1650,13 @@ tcp_rcv_fin (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_t * b, /* Account for the FIN and send ack */ tc->rcv_nxt += 1; - tcp_program_ack (wrk, tc); + tcp_program_ack (tc); /* Enter CLOSE-WAIT and notify session. To avoid lingering * in CLOSE-WAIT, set timer (reuse WAITCLOSE). */ tcp_connection_set_state (tc, TCP_STATE_CLOSE_WAIT); tcp_program_disconnect (wrk, tc); - tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME); - TCP_EVT_DBG (TCP_EVT_FIN_RCVD, tc); + tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time); + TCP_EVT (TCP_EVT_FIN_RCVD, tc); *error = TCP_ERROR_FIN_RCVD; } @@ -1808,8 +1754,9 @@ 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_DBG (TCP_EVT_INPUT, tc, 0, data_len, written); + TCP_EVT (TCP_EVT_INPUT, tc, 0, data_len, written); /* Update rcv_nxt */ if (PREDICT_TRUE (written == data_len)) @@ -1820,7 +1767,7 @@ tcp_session_enqueue_data (tcp_connection_t * tc, vlib_buffer_t * b, else if (written > data_len) { tc->rcv_nxt += written; - TCP_EVT_DBG (TCP_EVT_CC_INPUT, tc, data_len, written); + TCP_EVT (TCP_EVT_CC_INPUT, tc, data_len, written); } else if (written > 0) { @@ -1863,11 +1810,12 @@ tcp_session_enqueue_ooo (tcp_connection_t * tc, vlib_buffer_t * b, /* Nothing written */ if (rv) { - TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, 0); + TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, 0); return TCP_ERROR_FIFO_FULL; } - TCP_EVT_DBG (TCP_EVT_INPUT, tc, 1, data_len, data_len); + TCP_EVT (TCP_EVT_INPUT, tc, 1, data_len, data_len); + tc->bytes_in += data_len; /* Update SACK list if in use */ if (tcp_opts_sack_permitted (&tc->rcv_opts)) @@ -1887,7 +1835,7 @@ tcp_session_enqueue_ooo (tcp_connection_t * tc, vlib_buffer_t * b, end = start + ooo_segment_length (s0->rx_fifo, newest); tcp_update_sack_list (tc, start, end); svm_fifo_newest_ooo_segment_reset (s0->rx_fifo); - TCP_EVT_DBG (TCP_EVT_CC_SACKS, tc); + TCP_EVT (TCP_EVT_CC_SACKS, tc); } } @@ -1956,6 +1904,7 @@ tcp_segment_rcv (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, vlib_buffer_advance (b, vnet_buffer (b)->tcp.data_offset); n_data_bytes = vnet_buffer (b)->tcp.data_len; ASSERT (n_data_bytes); + tc->data_segs_in += 1; /* Handle out-of-order data */ if (PREDICT_FALSE (vnet_buffer (b)->tcp.seq_number != tc->rcv_nxt)) @@ -1968,7 +1917,7 @@ tcp_segment_rcv (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, * retransmissions since we may not have any data to send */ if (seq_leq (vnet_buffer (b)->tcp.seq_end, tc->rcv_nxt)) { - tcp_program_ack (wrk, tc); + tcp_program_ack (tc); error = TCP_ERROR_SEGMENT_OLD; goto done; } @@ -1988,8 +1937,10 @@ tcp_segment_rcv (tcp_worker_ctx_t * wrk, tcp_connection_t * tc, /* RFC2581: Enqueue and send DUPACK for fast retransmit */ error = tcp_session_enqueue_ooo (tc, b, n_data_bytes); - tcp_program_dupack (wrk, tc); - TCP_EVT_DBG (TCP_EVT_DUPACK_SENT, tc, vnet_buffer (b)->tcp); + tcp_program_dupack (tc); + TCP_EVT (TCP_EVT_DUPACK_SENT, tc, vnet_buffer (b)->tcp); + tc->errors.above_data_wnd += seq_gt (vnet_buffer (b)->tcp.seq_end, + tc->rcv_las + tc->rcv_wnd); goto done; } @@ -2001,11 +1952,11 @@ in_order: if (tcp_can_delack (tc)) { if (!tcp_timer_is_active (tc, TCP_TIMER_DELACK)) - tcp_timer_set (tc, TCP_TIMER_DELACK, TCP_DELACK_TIME); + tcp_timer_set (tc, TCP_TIMER_DELACK, tcp_cfg.delack_time); goto done; } - tcp_program_ack (wrk, tc); + tcp_program_ack (tc); done: return error; @@ -2187,7 +2138,7 @@ tcp46_established_inline (vlib_main_t * vm, vlib_node_runtime_t * node, /* 1-4: check SEQ, RST, SYN */ if (PREDICT_FALSE (tcp_segment_validate (wrk, tc0, b0, th0, &error0))) { - TCP_EVT_DBG (TCP_EVT_SEG_INVALID, tc0, vnet_buffer (b0)->tcp); + TCP_EVT (TCP_EVT_SEG_INVALID, tc0, vnet_buffer (b0)->tcp); goto done; } @@ -2356,7 +2307,6 @@ always_inline uword tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * from_frame, int is_ip4) { - tcp_main_t *tm = vnet_get_tcp_main (); u32 n_left_from, *from, *first_buffer, errors = 0; u32 my_thread_index = vm->thread_index; tcp_worker_ctx_t *wrk = tcp_get_worker (my_thread_index); @@ -2487,13 +2437,9 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node, /* Valid SYN or SYN-ACK. Move connection from half-open pool to * current thread pool. */ - pool_get (tm->connections[my_thread_index], new_tc0); - clib_memcpy_fast (new_tc0, tc0, sizeof (*new_tc0)); - new_tc0->c_c_index = new_tc0 - tm->connections[my_thread_index]; - new_tc0->c_thread_index = my_thread_index; + new_tc0 = tcp_connection_alloc_w_base (my_thread_index, tc0); new_tc0->rcv_nxt = vnet_buffer (b0)->tcp.seq_end; new_tc0->irs = seq0; - new_tc0->timers[TCP_TIMER_ESTABLISH_AO] = TCP_TIMER_HANDLE_INVALID; new_tc0->timers[TCP_TIMER_RETRANSMIT_SYN] = TCP_TIMER_HANDLE_INVALID; new_tc0->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; @@ -2546,7 +2492,7 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node, transport_tx_fifo_size (&new_tc0->connection); /* Update rtt with the syn-ack sample */ tcp_estimate_initial_rtt (new_tc0); - TCP_EVT_DBG (TCP_EVT_SYNACK_RCVD, new_tc0); + TCP_EVT (TCP_EVT_SYNACK_RCVD, new_tc0); error0 = TCP_ERROR_SYN_ACKS_RCVD; } /* SYN: Simultaneous open. Change state to SYN-RCVD and send SYN-ACK */ @@ -2559,7 +2505,7 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node, { tcp_connection_cleanup (new_tc0); tcp_send_reset_w_pkt (tc0, b0, my_thread_index, is_ip4); - TCP_EVT_DBG (TCP_EVT_RST_SENT, tc0); + TCP_EVT (TCP_EVT_RST_SENT, tc0); error0 = TCP_ERROR_CREATE_SESSION_FAIL; goto drop; } @@ -2583,7 +2529,7 @@ tcp46_syn_sent_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } else { - tcp_program_ack (wrk, new_tc0); + tcp_program_ack (new_tc0); } drop: @@ -2757,7 +2703,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, /* Switch state to ESTABLISHED */ tc0->state = TCP_STATE_ESTABLISHED; - TCP_EVT_DBG (TCP_EVT_STATE_CHANGE, tc0); + TCP_EVT (TCP_EVT_STATE_CHANGE, tc0); /* Initialize session variables */ tc0->snd_una = vnet_buffer (b0)->tcp.ack_number; @@ -2768,7 +2714,6 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, /* Reset SYN-ACK retransmit and SYN_RCV establish timers */ tcp_retransmit_timer_reset (tc0); - tcp_timer_reset (tc0, TCP_TIMER_ESTABLISH); if (session_stream_accept_notify (&tc0->connection)) { error0 = TCP_ERROR_MSG_QUEUE_FULL; @@ -2801,7 +2746,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, /* If a fin was received and data was acked extend wait */ else if ((tc0->flags & TCP_CONN_FINRCVD) && tc0->bytes_acked) tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, - TCP_CLOSEWAIT_TIME); + tcp_cfg.closewait_time); } /* If FIN is ACKed */ else if (tc0->snd_una == tc0->snd_nxt) @@ -2815,14 +2760,16 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (tc0->flags & TCP_CONN_FINRCVD) { tcp_connection_set_state (tc0, TCP_STATE_CLOSED); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, + tcp_cfg.cleanup_time); + session_transport_closed_notify (&tc0->connection); goto drop; } tcp_connection_set_state (tc0, TCP_STATE_FIN_WAIT_2); /* Enable waitclose because we're willing to wait for peer's * FIN but not indefinitely. */ - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.finwait2_time); /* Don't try to deq the FIN acked */ if (tc0->burst_acked > 1) @@ -2855,7 +2802,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, tcp_send_fin (tc0); tcp_connection_timers_reset (tc0); tcp_connection_set_state (tc0, TCP_STATE_LAST_ACK); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time); break; case TCP_STATE_CLOSING: /* In addition to the processing for the ESTABLISHED state, if @@ -2869,7 +2816,8 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, tcp_connection_timers_reset (tc0); tcp_connection_set_state (tc0, TCP_STATE_TIME_WAIT); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time); + session_transport_closed_notify (&tc0->connection); goto drop; break; @@ -2889,12 +2837,13 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } tcp_connection_set_state (tc0, TCP_STATE_CLOSED); + session_transport_closed_notify (&tc0->connection); /* Don't free the connection from the data path since * we can't ensure that we have no packets already enqueued * to output. Rely instead on the waitclose timer */ tcp_connection_timers_reset (tc0); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.cleanup_time); goto drop; @@ -2910,8 +2859,8 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (!is_fin0) goto drop; - tcp_program_ack (wrk, tc0); - tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME); + tcp_program_ack (tc0); + tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time); goto drop; break; @@ -2943,17 +2892,17 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, if (!is_fin0) goto drop; - TCP_EVT_DBG (TCP_EVT_FIN_RCVD, tc0); + TCP_EVT (TCP_EVT_FIN_RCVD, tc0); switch (tc0->state) { case TCP_STATE_ESTABLISHED: /* Account for the FIN and send ack */ tc0->rcv_nxt += 1; - tcp_program_ack (wrk, tc0); + tcp_program_ack (tc0); tcp_connection_set_state (tc0, TCP_STATE_CLOSE_WAIT); tcp_program_disconnect (wrk, tc0); - tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME); + tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.closewait_time); break; case TCP_STATE_SYN_RCVD: /* Send FIN-ACK, enter LAST-ACK and because the app was not @@ -2963,7 +2912,7 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, tc0->rcv_nxt += 1; tcp_send_fin (tc0); tcp_connection_set_state (tc0, TCP_STATE_LAST_ACK); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.lastack_time); break; case TCP_STATE_CLOSE_WAIT: case TCP_STATE_CLOSING: @@ -2979,14 +2928,16 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, * sending it. Since we already received a fin, do not wait * for too long. */ tc0->flags |= TCP_CONN_FINRCVD; - tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_CLOSEWAIT_TIME); + tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, + tcp_cfg.closewait_time); } else { tcp_connection_set_state (tc0, TCP_STATE_CLOSING); - tcp_program_ack (wrk, tc0); + tcp_program_ack (tc0); /* Wait for ACK for our FIN but not forever */ - tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_2MSL_TIME); + tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, + tcp_cfg.closing_time); } break; case TCP_STATE_FIN_WAIT_2: @@ -2994,14 +2945,15 @@ tcp46_rcv_process_inline (vlib_main_t * vm, vlib_node_runtime_t * node, tc0->rcv_nxt += 1; tcp_connection_set_state (tc0, TCP_STATE_TIME_WAIT); tcp_connection_timers_reset (tc0); - tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME); - tcp_program_ack (wrk, tc0); + tcp_timer_set (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time); + tcp_program_ack (tc0); + session_transport_closed_notify (&tc0->connection); break; case TCP_STATE_TIME_WAIT: /* Remain in the TIME-WAIT state. Restart the time-wait * timeout. */ - tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, TCP_TIMEWAIT_TIME); + tcp_timer_update (tc0, TCP_TIMER_WAITCLOSE, tcp_cfg.timewait_time); break; } error0 = TCP_ERROR_FIN_RCVD; @@ -3154,6 +3106,7 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node, child0->c_is_ip4 = is_ip4; child0->state = TCP_STATE_SYN_RCVD; child0->c_fib_index = lc0->c_fib_index; + child0->cc_algo = lc0->cc_algo; if (is_ip4) { @@ -3207,10 +3160,9 @@ tcp46_listen_inline (vlib_main_t * vm, vlib_node_runtime_t * node, goto drop; } - TCP_EVT_DBG (TCP_EVT_SYN_RCVD, child0, 1); + TCP_EVT (TCP_EVT_SYN_RCVD, child0, 1); child0->tx_fifo_size = transport_tx_fifo_size (&child0->connection); tcp_send_synack (child0); - tcp_timer_set (child0, TCP_TIMER_ESTABLISH, TCP_SYN_RCVD_TIME); drop: @@ -3354,9 +3306,9 @@ tcp_input_set_error_next (tcp_main_t * tm, u16 * next, u32 * error, u8 is_ip4) } } -static inline tcp_connection_t * +always_inline tcp_connection_t * tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, - u8 is_ip4) + u8 is_ip4, u8 is_nolookup) { u32 fib_index = vnet_buffer (b)->ip.fib_index; int n_advance_bytes, n_data_bytes; @@ -3385,10 +3337,12 @@ tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, return 0; } - tc = session_lookup_connection_wt4 (fib_index, &ip4->dst_address, - &ip4->src_address, tcp->dst_port, - tcp->src_port, TRANSPORT_PROTO_TCP, - thread_index, &result); + if (!is_nolookup) + tc = session_lookup_connection_wt4 (fib_index, &ip4->dst_address, + &ip4->src_address, tcp->dst_port, + tcp->src_port, + TRANSPORT_PROTO_TCP, thread_index, + &result); } else { @@ -3410,20 +3364,31 @@ tcp_input_lookup_buffer (vlib_buffer_t * b, u8 thread_index, u32 * error, *error = TCP_ERROR_LENGTH; return 0; } - if (PREDICT_FALSE - (ip6_address_is_link_local_unicast (&ip6->dst_address))) + + if (!is_nolookup) { - ip4_main_t *im = &ip4_main; - fib_index = vec_elt (im->fib_index_by_sw_if_index, - vnet_buffer (b)->sw_if_index[VLIB_RX]); - } + if (PREDICT_FALSE + (ip6_address_is_link_local_unicast (&ip6->dst_address))) + { + ip4_main_t *im = &ip4_main; + fib_index = vec_elt (im->fib_index_by_sw_if_index, + vnet_buffer (b)->sw_if_index[VLIB_RX]); + } - tc = session_lookup_connection_wt6 (fib_index, &ip6->dst_address, - &ip6->src_address, tcp->dst_port, - tcp->src_port, TRANSPORT_PROTO_TCP, - thread_index, &result); + tc = session_lookup_connection_wt6 (fib_index, &ip6->dst_address, + &ip6->src_address, + tcp->dst_port, tcp->src_port, + TRANSPORT_PROTO_TCP, + thread_index, &result); + } } + if (is_nolookup) + tc = + (transport_connection_t *) tcp_connection_get (vnet_buffer (b)-> + tcp.connection_index, + thread_index); + vnet_buffer (b)->tcp.seq_number = clib_net_to_host_u32 (tcp->seq_number); vnet_buffer (b)->tcp.ack_number = clib_net_to_host_u32 (tcp->ack_number); vnet_buffer (b)->tcp.data_offset = n_advance_bytes; @@ -3448,6 +3413,7 @@ tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc, flags = tcp->flags & filter_flags; *next = tm->dispatch_table[tc->state][flags].next; *error = tm->dispatch_table[tc->state][flags].error; + tc->segs_in += 1; if (PREDICT_FALSE (*error == TCP_ERROR_DISPATCH || *next == TCP_INPUT_NEXT_RESET)) @@ -3465,7 +3431,7 @@ tcp_input_dispatch_buffer (tcp_main_t * tm, tcp_connection_t * tc, always_inline uword tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, - vlib_frame_t * frame, int is_ip4) + vlib_frame_t * frame, int is_ip4, u8 is_nolookup) { u32 n_left_from, *from, thread_index = vm->thread_index; tcp_main_t *tm = vnet_get_tcp_main (); @@ -3496,8 +3462,10 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, next[0] = next[1] = TCP_INPUT_NEXT_DROP; - tc0 = tcp_input_lookup_buffer (b[0], thread_index, &error0, is_ip4); - tc1 = tcp_input_lookup_buffer (b[1], thread_index, &error1, is_ip4); + tc0 = tcp_input_lookup_buffer (b[0], thread_index, &error0, is_ip4, + is_nolookup); + tc1 = tcp_input_lookup_buffer (b[1], thread_index, &error1, is_ip4, + is_nolookup); if (PREDICT_TRUE (!tc0 + !tc1 == 0)) { @@ -3547,7 +3515,8 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, } next[0] = TCP_INPUT_NEXT_DROP; - tc0 = tcp_input_lookup_buffer (b[0], thread_index, &error0, is_ip4); + tc0 = tcp_input_lookup_buffer (b[0], thread_index, &error0, is_ip4, + is_nolookup); if (PREDICT_TRUE (tc0 != 0)) { ASSERT (tcp_lookup_is_valid (tc0, tcp_buffer_hdr (b[0]))); @@ -3569,16 +3538,74 @@ tcp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, return frame->n_vectors; } +VLIB_NODE_FN (tcp4_input_nolookup_node) (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return tcp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */ , + 1 /* is_nolookup */ ); +} + +VLIB_NODE_FN (tcp6_input_nolookup_node) (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + return tcp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */ , + 1 /* is_nolookup */ ); +} + +/* *INDENT-OFF* */ +VLIB_REGISTER_NODE (tcp4_input_nolookup_node) = +{ + .name = "tcp4-input-nolookup", + /* Takes a vector of packets. */ + .vector_size = sizeof (u32), + .n_errors = TCP_N_ERROR, + .error_strings = tcp_error_strings, + .n_next_nodes = TCP_INPUT_N_NEXT, + .next_nodes = + { +#define _(s,n) [TCP_INPUT_NEXT_##s] = n, + foreach_tcp4_input_next +#undef _ + }, + .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", + /* Takes a vector of packets. */ + .vector_size = sizeof (u32), + .n_errors = TCP_N_ERROR, + .error_strings = tcp_error_strings, + .n_next_nodes = TCP_INPUT_N_NEXT, + .next_nodes = + { +#define _(s,n) [TCP_INPUT_NEXT_##s] = n, + foreach_tcp6_input_next +#undef _ + }, + .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) { - return tcp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */ ); + return tcp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */ , + 0 /* is_nolookup */ ); } VLIB_NODE_FN (tcp6_input_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * from_frame) { - return tcp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */ ); + return tcp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */ , + 0 /* is_nolookup */ ); } /* *INDENT-OFF* */ @@ -3786,6 +3813,8 @@ do { \ TCP_ERROR_NONE); _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); + _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_RST, + TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); _(CLOSING, TCP_FLAG_FIN | TCP_FLAG_SYN | TCP_FLAG_RST | TCP_FLAG_ACK, TCP_INPUT_NEXT_RCV_PROCESS, TCP_ERROR_NONE); /* FIN confirming that the peer (app) has closed */