diff options
Diffstat (limited to 'net/ipv4/tcp_timer.c')
-rw-r--r-- | net/ipv4/tcp_timer.c | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c index cdb2ca7684d4..8816a20c2597 100644 --- a/net/ipv4/tcp_timer.c +++ b/net/ipv4/tcp_timer.c | |||
@@ -132,6 +132,35 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk) | |||
132 | } | 132 | } |
133 | } | 133 | } |
134 | 134 | ||
135 | /* This function calculates a "timeout" which is equivalent to the timeout of a | ||
136 | * TCP connection after "boundary" unsucessful, exponentially backed-off | ||
137 | * retransmissions with an initial RTO of TCP_RTO_MIN. | ||
138 | */ | ||
139 | static bool retransmits_timed_out(struct sock *sk, | ||
140 | unsigned int boundary) | ||
141 | { | ||
142 | unsigned int timeout, linear_backoff_thresh; | ||
143 | unsigned int start_ts; | ||
144 | |||
145 | if (!inet_csk(sk)->icsk_retransmits) | ||
146 | return false; | ||
147 | |||
148 | if (unlikely(!tcp_sk(sk)->retrans_stamp)) | ||
149 | start_ts = TCP_SKB_CB(tcp_write_queue_head(sk))->when; | ||
150 | else | ||
151 | start_ts = tcp_sk(sk)->retrans_stamp; | ||
152 | |||
153 | linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN); | ||
154 | |||
155 | if (boundary <= linear_backoff_thresh) | ||
156 | timeout = ((2 << boundary) - 1) * TCP_RTO_MIN; | ||
157 | else | ||
158 | timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN + | ||
159 | (boundary - linear_backoff_thresh) * TCP_RTO_MAX; | ||
160 | |||
161 | return (tcp_time_stamp - start_ts) >= timeout; | ||
162 | } | ||
163 | |||
135 | /* A write timeout has occurred. Process the after effects. */ | 164 | /* A write timeout has occurred. Process the after effects. */ |
136 | static int tcp_write_timeout(struct sock *sk) | 165 | static int tcp_write_timeout(struct sock *sk) |
137 | { | 166 | { |
@@ -141,14 +170,14 @@ static int tcp_write_timeout(struct sock *sk) | |||
141 | 170 | ||
142 | if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { | 171 | if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) { |
143 | if (icsk->icsk_retransmits) | 172 | if (icsk->icsk_retransmits) |
144 | dst_negative_advice(&sk->sk_dst_cache); | 173 | dst_negative_advice(&sk->sk_dst_cache, sk); |
145 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; | 174 | retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries; |
146 | } else { | 175 | } else { |
147 | if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { | 176 | if (retransmits_timed_out(sk, sysctl_tcp_retries1)) { |
148 | /* Black hole detection */ | 177 | /* Black hole detection */ |
149 | tcp_mtu_probing(icsk, sk); | 178 | tcp_mtu_probing(icsk, sk); |
150 | 179 | ||
151 | dst_negative_advice(&sk->sk_dst_cache); | 180 | dst_negative_advice(&sk->sk_dst_cache, sk); |
152 | } | 181 | } |
153 | 182 | ||
154 | retry_until = sysctl_tcp_retries2; | 183 | retry_until = sysctl_tcp_retries2; |
@@ -303,15 +332,15 @@ void tcp_retransmit_timer(struct sock *sk) | |||
303 | struct inet_sock *inet = inet_sk(sk); | 332 | struct inet_sock *inet = inet_sk(sk); |
304 | if (sk->sk_family == AF_INET) { | 333 | if (sk->sk_family == AF_INET) { |
305 | LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", | 334 | LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", |
306 | &inet->daddr, ntohs(inet->dport), | 335 | &inet->inet_daddr, ntohs(inet->inet_dport), |
307 | inet->num, tp->snd_una, tp->snd_nxt); | 336 | inet->inet_num, tp->snd_una, tp->snd_nxt); |
308 | } | 337 | } |
309 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 338 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
310 | else if (sk->sk_family == AF_INET6) { | 339 | else if (sk->sk_family == AF_INET6) { |
311 | struct ipv6_pinfo *np = inet6_sk(sk); | 340 | struct ipv6_pinfo *np = inet6_sk(sk); |
312 | LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", | 341 | LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n", |
313 | &np->daddr, ntohs(inet->dport), | 342 | &np->daddr, ntohs(inet->inet_dport), |
314 | inet->num, tp->snd_una, tp->snd_nxt); | 343 | inet->inet_num, tp->snd_una, tp->snd_nxt); |
315 | } | 344 | } |
316 | #endif | 345 | #endif |
317 | #endif | 346 | #endif |