Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 016818d0 authored by Neal Cardwell's avatar Neal Cardwell Committed by David S. Miller
Browse files

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: default avatarNeal Cardwell <ncardwell@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 623df484
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -1125,6 +1125,7 @@ static inline void tcp_openreq_init(struct request_sock *req,
	req->cookie_ts = 0;
	req->cookie_ts = 0;
	tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
	tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq;
	tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
	tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->seq + 1;
	tcp_rsk(req)->snt_synack = 0;
	req->mss = rx_opt->mss_clamp;
	req->mss = rx_opt->mss_clamp;
	req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
	req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0;
	ireq->tstamp_ok = rx_opt->tstamp_ok;
	ireq->tstamp_ok = rx_opt->tstamp_ok;
+1 −0
Original line number Original line Diff line number Diff line
@@ -5983,6 +5983,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
				 * need req so release it.
				 * need req so release it.
				 */
				 */
				if (req) {
				if (req) {
					tcp_synack_rtt_meas(sk, req);
					reqsk_fastopen_remove(sk, req, false);
					reqsk_fastopen_remove(sk, req, false);
				} else {
				} else {
					/* Make sure socket is routed, for
					/* Make sure socket is routed, for
+9 −3
Original line number Original line Diff line number Diff line
@@ -868,6 +868,8 @@ static int tcp_v4_send_synack(struct sock *sk, struct dst_entry *dst,
					    ireq->rmt_addr,
					    ireq->rmt_addr,
					    ireq->opt);
					    ireq->opt);
		err = net_xmit_eval(err);
		err = net_xmit_eval(err);
		if (!tcp_rsk(req)->snt_synack && !err)
			tcp_rsk(req)->snt_synack = tcp_time_stamp;
	}
	}


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


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


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


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


		tcp_rsk(req)->snt_synack = tcp_time_stamp;
		tcp_rsk(req)->listener = NULL;
		tcp_rsk(req)->listener = NULL;
		/* Add the request_sock to the SYN table */
		/* Add the request_sock to the SYN table */
		inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
		inet_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
+1 −1
Original line number Original line Diff line number Diff line
@@ -1169,7 +1169,6 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
	}
	}
have_isn:
have_isn:
	tcp_rsk(req)->snt_isn = isn;
	tcp_rsk(req)->snt_isn = isn;
	tcp_rsk(req)->snt_synack = tcp_time_stamp;


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


	tcp_rsk(req)->snt_synack = tcp_time_stamp;
	tcp_rsk(req)->listener = NULL;
	tcp_rsk(req)->listener = NULL;
	inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
	inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT);
	return 0;
	return 0;