Skip to content

Commit bc15afa

Browse files
yuchungchengdavem330
authored andcommitted
tcp: fix SYNACK RTT estimation in Fast Open
tp->lsndtime may not always be the SYNACK timestamp if a passive Fast Open socket sends data before handshake completes. And if the remote acknowledges both the data and the SYNACK, the RTT sample is already taken in tcp_ack(), so no need to call tcp_update_ack_rtt() in tcp_synack_rtt_meas() aagain. Signed-off-by: Yuchung Cheng <[email protected]> Acked-by: Neal Cardwell <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e9e2a90 commit bc15afa

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

net/ipv4/tcp_input.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,14 +2871,19 @@ static inline bool tcp_ack_update_rtt(struct sock *sk, const int flag,
28712871
}
28722872

28732873
/* Compute time elapsed between (last) SYNACK and the ACK completing 3WHS. */
2874-
static void tcp_synack_rtt_meas(struct sock *sk, struct request_sock *req)
2874+
static void tcp_synack_rtt_meas(struct sock *sk, const u32 synack_stamp)
28752875
{
28762876
struct tcp_sock *tp = tcp_sk(sk);
28772877
s32 seq_rtt = -1;
28782878

2879-
if (tp->lsndtime && !tp->total_retrans)
2880-
seq_rtt = tcp_time_stamp - tp->lsndtime;
2881-
tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, seq_rtt, -1);
2879+
if (synack_stamp && !tp->total_retrans)
2880+
seq_rtt = tcp_time_stamp - synack_stamp;
2881+
2882+
/* If the ACK acks both the SYNACK and the (Fast Open'd) data packets
2883+
* sent in SYN_RECV, SYNACK RTT is the smooth RTT computed in tcp_ack()
2884+
*/
2885+
if (!tp->srtt)
2886+
tcp_ack_update_rtt(sk, FLAG_SYN_ACKED, seq_rtt, -1);
28822887
}
28832888

28842889
static void tcp_cong_avoid(struct sock *sk, u32 ack, u32 in_flight)
@@ -5587,6 +5592,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
55875592
struct request_sock *req;
55885593
int queued = 0;
55895594
bool acceptable;
5595+
u32 synack_stamp;
55905596

55915597
tp->rx_opt.saw_tstamp = 0;
55925598

@@ -5669,9 +5675,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
56695675
* so release it.
56705676
*/
56715677
if (req) {
5678+
synack_stamp = tcp_rsk(req)->snt_synack;
56725679
tp->total_retrans = req->num_retrans;
56735680
reqsk_fastopen_remove(sk, req, false);
56745681
} else {
5682+
synack_stamp = tp->lsndtime;
56755683
/* Make sure socket is routed, for correct metrics. */
56765684
icsk->icsk_af_ops->rebuild_header(sk);
56775685
tcp_init_congestion_control(sk);
@@ -5694,7 +5702,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
56945702
tp->snd_una = TCP_SKB_CB(skb)->ack_seq;
56955703
tp->snd_wnd = ntohs(th->window) << tp->rx_opt.snd_wscale;
56965704
tcp_init_wl(tp, TCP_SKB_CB(skb)->seq);
5697-
tcp_synack_rtt_meas(sk, req);
5705+
tcp_synack_rtt_meas(sk, synack_stamp);
56985706

56995707
if (tp->rx_opt.tstamp_ok)
57005708
tp->advmss -= TCPOLEN_TSTAMP_ALIGNED;

0 commit comments

Comments
 (0)