Skip to content

Commit 016818d

Browse files
nealcardwelldavem330
authored andcommitted
tcp: TCP Fast Open Server - take SYNACK RTT after completing 3WHS
When taking SYNACK RTT samples for servers using TCP Fast Open, fix the code to ensure that we only call tcp_valid_rtt_meas() after we receive the ACK that completes the 3-way handshake. Previously we were always taking an RTT sample in tcp_v4_syn_recv_sock(). However, for TCP Fast Open connections tcp_v4_conn_req_fastopen() calls tcp_v4_syn_recv_sock() at the time we receive the SYN. So for TFO we must wait until tcp_rcv_state_process() to take the RTT sample. To fix this, we wait until after TFO calls tcp_v4_syn_recv_sock() before we set the snt_synack timestamp, since tcp_synack_rtt_meas() already ensures that we only take a SYNACK RTT sample if snt_synack is non-zero. To be careful, we only take a snt_synack timestamp when a SYNACK transmit or retransmit succeeds. Signed-off-by: Neal Cardwell <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 623df48 commit 016818d

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

include/net/tcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
11251125
req->cookie_ts = 0;
11261126
tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
11271127
tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
1128+
tcp_rsk(req)->snt_synack = 0;
11281129
req->mss = rx_opt->mss_clamp;
11291130
req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
11301131
ireq->tstamp_ok = rx_opt->tstamp_ok;

net/ipv4/tcp_input.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5983,6 +5983,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
59835983
* need req so release it.
59845984
*/
59855985
if (req) {
5986+
tcp_synack_rtt_meas(sk, req);
59865987
reqsk_fastopen_remove(sk, req, false);
59875988
} else {
59885989
/* Make sure socket is routed, for

net/ipv4/tcp_ipv4.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
868868
ireq->rmt_addr,
869869
ireq->opt);
870870
err = net_xmit_eval(err);
871+
if (!tcp_rsk(req)->snt_synack && !err)
872+
tcp_rsk(req)->snt_synack = tcp_time_stamp;
871873
}
872874

873875
return err;
@@ -1382,6 +1384,7 @@ static int tcp_v4_conn_req_fastopen(struct sock *sk,
13821384
struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
13831385
const struct inet_request_sock *ireq = inet_rsk(req);
13841386
struct sock *child;
1387+
int err;
13851388

13861389
req->retrans = 0;
13871390
req->sk = NULL;
@@ -1393,8 +1396,11 @@ static int tcp_v4_conn_req_fastopen(struct sock *sk,
13931396
kfree_skb(skb_synack);
13941397
return -1;
13951398
}
1396-
ip_build_and_send_pkt(skb_synack, sk, ireq->loc_addr,
1397-
ireq->rmt_addr, ireq->opt);
1399+
err = ip_build_and_send_pkt(skb_synack, sk, ireq->loc_addr,
1400+
ireq->rmt_addr, ireq->opt);
1401+
err = net_xmit_eval(err);
1402+
if (!err)
1403+
tcp_rsk(req)->snt_synack = tcp_time_stamp;
13981404
/* XXX (TFO) - is it ok to ignore error and continue? */
13991405

14001406
spin_lock(&queue->fastopenq->lock);
@@ -1612,7 +1618,6 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
16121618
isn = tcp_v4_init_sequence(skb);
16131619
}
16141620
tcp_rsk(req)->snt_isn = isn;
1615-
tcp_rsk(req)->snt_synack = tcp_time_stamp;
16161621

16171622
if (dst == NULL) {
16181623
dst = inet_csk_route_req(sk, &fl4, req);
@@ -1650,6 +1655,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
16501655
if (err || want_cookie)
16511656
goto drop_and_free;
16521657

1658+
tcp_rsk(req)->snt_synack = tcp_time_stamp;
16531659
tcp_rsk(req)->listener = NULL;
16541660
/* Add the request_sock to the SYN table */
16551661
inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,6 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
11691169
}
11701170
have_isn:
11711171
tcp_rsk(req)->snt_isn = isn;
1172-
tcp_rsk(req)->snt_synack = tcp_time_stamp;
11731172

11741173
if (security_inet_conn_request(sk, skb, req))
11751174
goto drop_and_release;
@@ -1180,6 +1179,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
11801179
want_cookie)
11811180
goto drop_and_free;
11821181

1182+
tcp_rsk(req)->snt_synack = tcp_time_stamp;
11831183
tcp_rsk(req)->listener = NULL;
11841184
inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
11851185
return 0;

0 commit comments

Comments
 (0)