Skip to contentSkip to conversation

SNMPv2 tcpAttemptFails counter error

PATCH In review Wei Yongjun 2 participants 2 messages Jul 5, 2006 – Jul 24, 2006

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

PATCH 1/1 SNMPv2 tcpAttemptFails counter error

Refer to RFC2012, tcpAttemptFails is defined as following:
tcpAttemptFails OBJECT-TYPE

      SYNTAX      Counter32
      MAX-ACCESS  read-only
      STATUS      current

DESCRIPTION
"The number of times TCP connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state, plus the number of times TCP connections have made a direct transition to the LISTEN state from the SYN-RCVD state."
::= { tcp 7 }

When I lookup into RFC793, I found that the state change should occured under following condition:
1. SYN-SENT -> CLOSED
a) Received ACK,RST segment when SYN-SENT state.

2. SYN-RCVD -> CLOSED
b) Received SYN segment when SYN-RCVD state(came from LISTEN).
c) Received RST segment when SYN-RCVD state(came from SYN-SENT).
d) Received SYN segment when SYN-RCVD state(came from SYN-SENT).

3. SYN-RCVD -> LISTEN
e) Received RST segment when SYN-RCVD state(came from LISTEN).

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

net/ipv4/tcp_input.c +5 -0
@@ -4089,6 +4089,7 @@ static int tcp_rcv_synsent_state_process
 		 */
 
 		if (th->rst) {
+			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 			tcp_reset(sk);
 			goto discard;
 		}
@@ -4377,6 +4378,8 @@ int tcp_rcv_state_process(struct sock *s
 
 	/* step 2: check RST bit */
 	if(th->rst) {
+		if(sk->sk_state == TCP_SYN_RECV)
+			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 		tcp_reset(sk);
 		goto discard;
 	}
@@ -4390,6 +4393,8 @@ int tcp_rcv_state_process(struct sock *s
 	 *	Check for a SYN in window.
 	 */
 	if (th->syn && !before(TCP_SKB_CB(skb)->seq, tp->rcv_nxt)) {
+		if(sk->sk_state == TCP_SYN_RECV)
+			TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
 		NET_INC_STATS_BH(LINUX_MIB_TCPABORTONSYN);
 		tcp_reset(sk);
 		return 1;
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.
maintainer
#1 lore raw

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.

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.

Thank you.