IPv6: Delete redundant counter of IPSTATS_MIB_REASMFAILS
[safe/jmp/linux-2.6] / net / ipv4 / tcp_timer.c
index 408fa4b..de7d1bf 100644 (file)
@@ -132,22 +132,52 @@ static void tcp_mtu_probing(struct inet_connection_sock *icsk, struct sock *sk)
        }
 }
 
+/* This function calculates a "timeout" which is equivalent to the timeout of a
+ * TCP connection after "boundary" unsucessful, exponentially backed-off
+ * retransmissions with an initial RTO of TCP_RTO_MIN.
+ */
+static bool retransmits_timed_out(struct sock *sk,
+                                 unsigned int boundary)
+{
+       unsigned int timeout, linear_backoff_thresh;
+       unsigned int start_ts;
+
+       if (!inet_csk(sk)->icsk_retransmits)
+               return false;
+
+       if (unlikely(!tcp_sk(sk)->retrans_stamp))
+               start_ts = TCP_SKB_CB(tcp_write_queue_head(sk))->when;
+       else
+               start_ts = tcp_sk(sk)->retrans_stamp;
+
+       linear_backoff_thresh = ilog2(TCP_RTO_MAX/TCP_RTO_MIN);
+
+       if (boundary <= linear_backoff_thresh)
+               timeout = ((2 << boundary) - 1) * TCP_RTO_MIN;
+       else
+               timeout = ((2 << linear_backoff_thresh) - 1) * TCP_RTO_MIN +
+                         (boundary - linear_backoff_thresh) * TCP_RTO_MAX;
+
+       return (tcp_time_stamp - start_ts) >= timeout;
+}
+
 /* A write timeout has occurred. Process the after effects. */
 static int tcp_write_timeout(struct sock *sk)
 {
        struct inet_connection_sock *icsk = inet_csk(sk);
        int retry_until;
+       bool do_reset;
 
        if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV)) {
                if (icsk->icsk_retransmits)
-                       dst_negative_advice(&sk->sk_dst_cache);
+                       dst_negative_advice(&sk->sk_dst_cache, sk);
                retry_until = icsk->icsk_syn_retries ? : sysctl_tcp_syn_retries;
        } else {
-               if (icsk->icsk_retransmits >= sysctl_tcp_retries1) {
+               if (retransmits_timed_out(sk, sysctl_tcp_retries1)) {
                        /* Black hole detection */
                        tcp_mtu_probing(icsk, sk);
 
-                       dst_negative_advice(&sk->sk_dst_cache);
+                       dst_negative_advice(&sk->sk_dst_cache, sk);
                }
 
                retry_until = sysctl_tcp_retries2;
@@ -155,13 +185,15 @@ static int tcp_write_timeout(struct sock *sk)
                        const int alive = (icsk->icsk_rto < TCP_RTO_MAX);
 
                        retry_until = tcp_orphan_retries(sk, alive);
+                       do_reset = alive ||
+                                  !retransmits_timed_out(sk, retry_until);
 
-                       if (tcp_out_of_resources(sk, alive || icsk->icsk_retransmits < retry_until))
+                       if (tcp_out_of_resources(sk, do_reset))
                                return 1;
                }
        }
 
-       if (icsk->icsk_retransmits >= retry_until) {
+       if (retransmits_timed_out(sk, retry_until)) {
                /* Has it gone just too far? */
                tcp_write_err(sk);
                return 1;
@@ -300,15 +332,15 @@ void tcp_retransmit_timer(struct sock *sk)
                struct inet_sock *inet = inet_sk(sk);
                if (sk->sk_family == AF_INET) {
                        LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
-                              &inet->daddr, ntohs(inet->dport),
-                              inet->num, tp->snd_una, tp->snd_nxt);
+                              &inet->inet_daddr, ntohs(inet->inet_dport),
+                              inet->inet_num, tp->snd_una, tp->snd_nxt);
                }
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
                else if (sk->sk_family == AF_INET6) {
                        struct ipv6_pinfo *np = inet6_sk(sk);
                        LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
-                              &np->daddr, ntohs(inet->dport),
-                              inet->num, tp->snd_una, tp->snd_nxt);
+                              &np->daddr, ntohs(inet->inet_dport),
+                              inet->inet_num, tp->snd_una, tp->snd_nxt);
                }
 #endif
 #endif
@@ -385,7 +417,7 @@ void tcp_retransmit_timer(struct sock *sk)
 out_reset_timer:
        icsk->icsk_rto = min(icsk->icsk_rto << 1, TCP_RTO_MAX);
        inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX);
-       if (icsk->icsk_retransmits > sysctl_tcp_retries1)
+       if (retransmits_timed_out(sk, sysctl_tcp_retries1 + 1))
                __sk_dst_reset(sk);
 
 out:;
@@ -442,6 +474,12 @@ static void tcp_synack_timer(struct sock *sk)
                                   TCP_TIMEOUT_INIT, TCP_RTO_MAX);
 }
 
+void tcp_syn_ack_timeout(struct sock *sk, struct request_sock *req)
+{
+       NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPTIMEOUTS);
+}
+EXPORT_SYMBOL(tcp_syn_ack_timeout);
+
 void tcp_set_keepalive(struct sock *sk, int val)
 {
        if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))