Skip to contentSkip to conversation

SNMPv2 tcpAttemptFails counter error

PATCH Wei Yongjun 2 participants 2 messages Jul 28, 2006 – Jul 31, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

I have changed my patch with your advice and it looks more effective.

Quoted 10 lines · David Miller

From: Wei Yongjun <[email protected]>
Date: Wed, 05 Jul 2006 05:19:54 -0400

Quoted 4 lines

In my test, those direct state transition can not be counted to tcpAttemptFails. Following is my patch:

This change can be implemented more simply, I believe.

Quoted 8 lines

Except for the tcp_minisocks.c change, all the paths changed go to tcp_done() which is what actually transfers the state to TCP_CLOSE. Therefore, tcp_done() can simply be modified to check if the current state is TCP_SYN_RECV, and is so bump the counter.

Once you implement it this way, please audit all call paths to make sure we don't now bump this counter twice.

include/net/tcp.h +3 -0
@@ -904,6 +904,9 @@ static inline void tcp_set_state(struct 
 
 static inline void tcp_done(struct sock *sk)
 {
+	if(sk->sk_state == TCP_SYN_SENT || sk->sk_state == TCP_SYN_RECV)
+		TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
+
 	tcp_set_state(sk, TCP_CLOSE);
 	tcp_clear_xmit_timers(sk);
 
net/ipv4/tcp_ipv4.c +0 -2
@@ -437,7 +437,6 @@ void tcp_v4_err(struct sk_buff *skb, u32
 			       It can f.e. if SYNs crossed.
 			     */
 		if (!sock_owned_by_user(sk)) {
-			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 			sk->sk_err = err;
 
 			sk->sk_error_report(sk);
@@ -855,7 +854,6 @@ int tcp_v4_conn_request(struct sock *sk,
 drop_and_free:
 	reqsk_free(req);
 drop:
-	TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 	return 0;
 }
 
net/ipv4/tcp_minisocks.c +3 -1
@@ -592,8 +592,10 @@ struct sock *tcp_check_req(struct sock *
 		/* RFC793: "second check the RST bit" and
 		 *	   "fourth, check the SYN bit"
 		 */
-		if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN))
+		if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN)) {
+			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 			goto embryonic_reset;
+		}
 
 		/* ACK sequence verified above, just make sure ACK is
 		 * set.  If ACK not set, just silently drop the packet.
net/ipv6/tcp_ipv6.c +0 -2
@@ -429,7 +429,6 @@ static void tcp_v6_err(struct sk_buff *s
 	case TCP_SYN_RECV:  /* Cannot happen.
 			       It can, it SYNs are crossed. --ANK */ 
 		if (!sock_owned_by_user(sk)) {
-			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 			sk->sk_err = err;
 			sk->sk_error_report(sk);		/* Wake people up to see the error (see connect in sock.c) */
 
@@ -815,7 +814,6 @@ drop:
 	if (req)
 		reqsk_free(req);
 
-	TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 	return 0; /* don't send reset */
 }