Skip to content

Commit a41e8a8

Browse files
edumazetdavem330
authored andcommitted
tcp: better handle TCP_USER_TIMEOUT in SYN_SENT state
Yuchung Cheng and Marek Majkowski independently reported a weird behavior of TCP_USER_TIMEOUT option when used at connect() time. When the TCP_USER_TIMEOUT is reached, tcp_write_timeout() believes the flow should live, and the following condition in tcp_clamp_rto_to_user_timeout() programs one jiffie timers : remaining = icsk->icsk_user_timeout - elapsed; if (remaining <= 0) return 1; /* user timeout has passed; fire ASAP */ This silly situation ends when the max syn rtx count is reached. This patch makes sure we honor both TCP_SYNCNT and TCP_USER_TIMEOUT, avoiding these spurious SYN packets. Fixes: b701a99 ("tcp: Add tcp_clamp_rto_to_user_timeout() helper to improve accuracy") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Yuchung Cheng <[email protected]> Reported-by: Marek Majkowski <[email protected]> Cc: Jon Maxwell <[email protected]> Link: https://marc.info/?l=linux-netdev&m=156940118307949&w=2 Acked-by: Jon Maxwell <[email protected]> Tested-by: Marek Majkowski <[email protected]> Signed-off-by: Marek Majkowski <[email protected]> Acked-by: Yuchung Cheng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 174e238 commit a41e8a8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/ipv4/tcp_timer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int tcp_write_timeout(struct sock *sk)
210210
struct inet_connection_sock *icsk = inet_csk(sk);
211211
struct tcp_sock *tp = tcp_sk(sk);
212212
struct net *net = sock_net(sk);
213-
bool expired, do_reset;
213+
bool expired = false, do_reset;
214214
int retry_until;
215215

216216
if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
@@ -242,9 +242,10 @@ static int tcp_write_timeout(struct sock *sk)
242242
if (tcp_out_of_resources(sk, do_reset))
243243
return 1;
244244
}
245+
}
246+
if (!expired)
245247
expired = retransmits_timed_out(sk, retry_until,
246248
icsk->icsk_user_timeout);
247-
}
248249
tcp_fastopen_active_detect_blackhole(sk, expired);
249250

250251
if (BPF_SOCK_OPS_TEST_FLAG(tp, BPF_SOCK_OPS_RTO_CB_FLAG))

0 commit comments

Comments
 (0)