ipv4: factorize cache clearing for batched unregister operations
[safe/jmp/linux-2.6] / net / ipv4 / tcp_timer.c
index 979c9d6..8353a53 100644 (file)
@@ -65,7 +65,7 @@ static void tcp_write_err(struct sock *sk)
 static int tcp_out_of_resources(struct sock *sk, int do_reset)
 {
        struct tcp_sock *tp = tcp_sk(sk);
-       int orphans = atomic_read(&tcp_orphan_count);
+       int orphans = percpu_counter_read_positive(&tcp_orphan_count);
 
        /* If peer does not open window for long time, or did not transmit
         * anything for long time, penalize it. */
@@ -137,17 +137,18 @@ 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 +156,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;
@@ -171,7 +174,7 @@ static int tcp_write_timeout(struct sock *sk)
 
 static void tcp_delack_timer(unsigned long data)
 {
-       struct sock *sk = (struct sock*)data;
+       struct sock *sk = (struct sock *)data;
        struct tcp_sock *tp = tcp_sk(sk);
        struct inet_connection_sock *icsk = inet_csk(sk);
 
@@ -279,7 +282,7 @@ static void tcp_probe_timer(struct sock *sk)
  *     The TCP retransmit timer.
  */
 
-static void tcp_retransmit_timer(struct sock *sk)
+void tcp_retransmit_timer(struct sock *sk)
 {
        struct tcp_sock *tp = tcp_sk(sk);
        struct inet_connection_sock *icsk = inet_csk(sk);
@@ -299,16 +302,16 @@ static void tcp_retransmit_timer(struct sock *sk)
 #ifdef TCP_DEBUG
                struct inet_sock *inet = inet_sk(sk);
                if (sk->sk_family == AF_INET) {
-                       LIMIT_NETDEBUG(KERN_DEBUG "TCP: Treason uncloaked! Peer " NIPQUAD_FMT ":%u/%u shrinks window %u:%u. Repaired.\n",
-                              NIPQUAD(inet->daddr), ntohs(inet->dport),
-                              inet->num, tp->snd_una, tp->snd_nxt);
+                       LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI4:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
+                              &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: Treason uncloaked! Peer %pI6:%u/%u shrinks window %u:%u. Repaired.\n",
-                              &np->daddr, ntohs(inet->dport),
-                              inet->num, tp->snd_una, tp->snd_nxt);
+                       LIMIT_NETDEBUG(KERN_DEBUG "TCP: Peer %pI6:%u/%u unexpectedly shrunk window %u:%u (repaired)\n",
+                              &np->daddr, ntohs(inet->inet_dport),
+                              inet->inet_num, tp->snd_una, tp->snd_nxt);
                }
 #endif
 #endif
@@ -328,19 +331,16 @@ static void tcp_retransmit_timer(struct sock *sk)
        if (icsk->icsk_retransmits == 0) {
                int mib_idx;
 
-               if (icsk->icsk_ca_state == TCP_CA_Disorder ||
-                   icsk->icsk_ca_state == TCP_CA_Recovery) {
-                       if (tcp_is_sack(tp)) {
-                               if (icsk->icsk_ca_state == TCP_CA_Recovery)
-                                       mib_idx = LINUX_MIB_TCPSACKRECOVERYFAIL;
-                               else
-                                       mib_idx = LINUX_MIB_TCPSACKFAILURES;
-                       } else {
-                               if (icsk->icsk_ca_state == TCP_CA_Recovery)
-                                       mib_idx = LINUX_MIB_TCPRENORECOVERYFAIL;
-                               else
-                                       mib_idx = LINUX_MIB_TCPRENOFAILURES;
-                       }
+               if (icsk->icsk_ca_state == TCP_CA_Disorder) {
+                       if (tcp_is_sack(tp))
+                               mib_idx = LINUX_MIB_TCPSACKFAILURES;
+                       else
+                               mib_idx = LINUX_MIB_TCPRENOFAILURES;
+               } else if (icsk->icsk_ca_state == TCP_CA_Recovery) {
+                       if (tcp_is_sack(tp))
+                               mib_idx = LINUX_MIB_TCPSACKRECOVERYFAIL;
+                       else
+                               mib_idx = LINUX_MIB_TCPRENORECOVERYFAIL;
                } else if (icsk->icsk_ca_state == TCP_CA_Loss) {
                        mib_idx = LINUX_MIB_TCPLOSSFAILURES;
                } else {
@@ -388,7 +388,7 @@ static 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:;
@@ -396,7 +396,7 @@ out:;
 
 static void tcp_write_timer(unsigned long data)
 {
-       struct sock *sk = (struct sock*)data;
+       struct sock *sk = (struct sock *)data;
        struct inet_connection_sock *icsk = inet_csk(sk);
        int event;
 
@@ -502,8 +502,7 @@ static void tcp_keepalive_timer (unsigned long data)
        elapsed = tcp_time_stamp - tp->rcv_tstamp;
 
        if (elapsed >= keepalive_time_when(tp)) {
-               if ((!tp->keepalive_probes && icsk->icsk_probes_out >= sysctl_tcp_keepalive_probes) ||
-                    (tp->keepalive_probes && icsk->icsk_probes_out >= tp->keepalive_probes)) {
+               if (icsk->icsk_probes_out >= keepalive_probes(tp)) {
                        tcp_send_active_reset(sk, GFP_ATOMIC);
                        tcp_write_err(sk);
                        goto out;