diff options
Diffstat (limited to 'net/ipv4/tcp_timer.c')
-rw-r--r-- | net/ipv4/tcp_timer.c | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index c35b469e851..baea4a12902 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c | |||
@@ -138,10 +138,10 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) | |||
138 | * retransmissions with an initial RTO of TCP_RTO_MIN. | 138 | * retransmissions with an initial RTO of TCP_RTO_MIN. |
139 | */ | 139 | */ |
140 | static bool retransmits_timed_out(struct sock *sk, | 140 | static bool retransmits_timed_out(struct sock *sk, |
141 | unsigned int boundary) | 141 | unsigned int boundary, |
142 | unsigned int timeout) | ||
142 | { | 143 | { |
143 | unsigned int timeout, linear_backoff_thresh; | 144 | unsigned int linear_backoff_thresh, start_ts; |
144 | unsigned int start_ts; | ||
145 | 145 | ||
146 | if (!inet_csk(sk)->icsk_retransmits) | 146 | if (!inet_csk(sk)->icsk_retransmits) |
147 | return false; | 147 | return false; |
@@ -151,14 +151,15 @@ static bool retransmits_timed_out(struct sock *sk, | |||
151 | else | 151 | else |
152 | start_ts = tcp_sk(sk)->retrans_stamp; | 152 | start_ts = tcp_sk(sk)->retrans_stamp; |
153 | 153 | ||
154 | linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN); | 154 | if (likely(timeout == 0)) { |
155 | 155 | linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN); | |
156 | if (boundary <= linear_backoff_thresh) | ||
157 | timeout = ((2 << boundary) - 1) * TCP_RTO_MIN; | ||
158 | else | ||
159 | timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN + | ||
160 | (boundary - linear_backoff_thresh) * TCP_RTO_MAX; | ||
161 | 156 | ||
157 | if (boundary <= linear_backoff_thresh) | ||
158 | timeout = ((2 << boundary) - 1) * TCP_RTO_MIN; | ||
159 | else | ||
160 | timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN + | ||
161 | (boundary - linear_backoff_thresh) * TCP_RTO_MAX; | ||
162 | } | ||
162 | return (tcp_time_stamp - start_ts) >= timeout; | 163 | return (tcp_time_stamp - start_ts) >= timeout; |
163 | } | 164 | } |
164 | 165 | ||
@@ -174,7 +175,7 @@ static int tcp_write_timeout(struct sock *sk) | |||
174 | dst_negative_advice(sk); | 175 | dst_negative_advice(sk); |
175 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; | 176 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; |
176 | } else { | 177 | } else { |
177 | if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { | 178 | if (retransmits_timed_out(sk, sysctl_tcp_retries1, 0)) { |
178 | /* Black hole detection */ | 179 | /* Black hole detection */ |
179 | tcp_mtu_probing(icsk, sk); | 180 | tcp_mtu_probing(icsk, sk); |
180 | 181 | ||
@@ -187,14 +188,16 @@ static int tcp_write_timeout(struct sock *sk) | |||
187 | 188 | ||
188 | retry_until = tcp_orphan_retries(sk, alive); | 189 | retry_until = tcp_orphan_retries(sk, alive); |
189 | do_reset = alive || | 190 | do_reset = alive || |
190 | !retransmits_timed_out(sk, retry_until); | 191 | !retransmits_timed_out(sk, retry_until, 0); |
191 | 192 | ||
192 | if (tcp_out_of_resources(sk, do_reset)) | 193 | if (tcp_out_of_resources(sk, do_reset)) |
193 | return 1; | 194 | return 1; |
194 | } | 195 | } |
195 | } | 196 | } |
196 | 197 | ||
197 | if (retransmits_timed_out(sk, retry_until)) { | 198 | if (retransmits_timed_out(sk, retry_until, |
199 | (1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV) ? 0 : | ||
200 | icsk->icsk_user_timeout)) { | ||
198 | /* Has it gone just too far? */ | 201 | /* Has it gone just too far? */ |
199 | tcp_write_err(sk); | 202 | tcp_write_err(sk); |
200 | return 1; | 203 | return 1; |
@@ -436,7 +439,7 @@ out_reset_timer: | |||
436 | icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); | 439 | icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX); |
437 | } | 440 | } |
438 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); | 441 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); |
439 | if (retransmits_timed_out(sk, sysctl_tcp_retries1 + 1)) | 442 | if (retransmits_timed_out(sk, sysctl_tcp_retries1 + 1, 0)) |
440 | __sk_dst_reset(sk); | 443 | __sk_dst_reset(sk); |
441 | 444 | ||
442 | out:; | 445 | out:; |
@@ -556,7 +559,14 @@ static void tcp_keepalive_timer (unsigned long data) | |||
556 | elapsed = keepalive_time_elapsed(tp); | 559 | elapsed = keepalive_time_elapsed(tp); |
557 | 560 | ||
558 | if (elapsed >= keepalive_time_when(tp)) { | 561 | if (elapsed >= keepalive_time_when(tp)) { |
559 | if (icsk->icsk_probes_out >= keepalive_probes(tp)) { | 562 | /* If the TCP_USER_TIMEOUT option is enabled, use that |
563 | * to determine when to timeout instead. | ||
564 | */ | ||
565 | if ((icsk->icsk_user_timeout != 0 && | ||
566 | elapsed >= icsk->icsk_user_timeout && | ||
567 | icsk->icsk_probes_out > 0) || | ||
568 | (icsk->icsk_user_timeout == 0 && | ||
569 | icsk->icsk_probes_out >= keepalive_probes(tp))) { | ||
560 | tcp_send_active_reset(sk, GFP_ATOMIC); | 570 | tcp_send_active_reset(sk, GFP_ATOMIC); |
561 | tcp_write_err(sk); | 571 | tcp_write_err(sk); |
562 | goto out; | 572 | goto out; |