From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 449021304AD; Wed, 19 Jun 2024 12:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718801969; cv=none; b=tRnHk4V/0rh1Se/rs3I5k636DWZLl+kCWNFEGes7nDyxAARxC6vcIgrYmUJdEiH5+wZe+i5qFN+V+FF9rkWkPxcyDJXMgoWvHYf3Zcw2hROitDD34YCaHqh6VZ0gEmiY4N50k+PT5mgw364Py3/sOVQxj61nW4vJAnlwDkrDmpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718801969; c=relaxed/simple; bh=bi2TSb8hYyjcySi6IVoqcRE60YqXlbrtDFYREnkJqdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rSTA2bq0IxXbPj5VG/3JRlvCrN8ht2s7viaAN1lx6X6PPMJgCIIVA1COPwzDMIipFzxVbEVkZwV5WoBW1VlgJNoAqhqktpDpLs7m/C8S5dxhOxph1p89pdwn/DwZ0nt4NcqGHYMcYKR5aWKjZ4hr6qaa3VrxY+IxtKGLq/8f4vI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=LDvLNiQW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="LDvLNiQW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C5F5C2BBFC; Wed, 19 Jun 2024 12:59:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718801968; bh=bi2TSb8hYyjcySi6IVoqcRE60YqXlbrtDFYREnkJqdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LDvLNiQWjQFnYGIWHq4lKY5ZEwlnAy+BW7xvUEcfn0elOk3yQXecOWxG6Q3igyG7E Y2Q2GgsS6U3UbJsv/x2KmBXrcrhfChRZYG/R3/BvdgJJBT7R1tMJ1Uu83OoVTASDT+ uzjMnn2FrmXI/pCFYk/5u2FgBn1O6C2qH1arVjz8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jason Xing , Eric Dumazet , "David S. Miller" , Sasha Levin Subject: [PATCH 6.6 037/267] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB Date: Wed, 19 Jun 2024 14:53:08 +0200 Message-ID: <20240619125607.790067353@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240619125606.345939659@linuxfoundation.org> References: <20240619125606.345939659@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Xing [ Upstream commit a46d0ea5c94205f40ecf912d1bb7806a8a64704f ] According to RFC 1213, we should also take CLOSE-WAIT sockets into consideration: "tcpCurrEstab OBJECT-TYPE ... The number of TCP connections for which the current state is either ESTABLISHED or CLOSE- WAIT." After this, CurrEstab counter will display the total number of ESTABLISHED and CLOSE-WAIT sockets. The logic of counting When we increment the counter? a) if we change the state to ESTABLISHED. b) if we change the state from SYN-RECEIVED to CLOSE-WAIT. When we decrement the counter? a) if the socket leaves ESTABLISHED and will never go into CLOSE-WAIT, say, on the client side, changing from ESTABLISHED to FIN-WAIT-1. b) if the socket leaves CLOSE-WAIT, say, on the server side, changing from CLOSE-WAIT to LAST-ACK. Please note: there are two chances that old state of socket can be changed to CLOSE-WAIT in tcp_fin(). One is SYN-RECV, the other is ESTABLISHED. So we have to take care of the former case. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Jason Xing Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/tcp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index a9b33135513d8..2df05ea2e00fe 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2640,6 +2640,10 @@ void tcp_set_state(struct sock *sk, int state) if (oldstate != TCP_ESTABLISHED) TCP_INC_STATS(sock_net(sk), TCP_MIB_CURRESTAB); break; + case TCP_CLOSE_WAIT: + if (oldstate == TCP_SYN_RECV) + TCP_INC_STATS(sock_net(sk), TCP_MIB_CURRESTAB); + break; case TCP_CLOSE: if (oldstate == TCP_CLOSE_WAIT || oldstate == TCP_ESTABLISHED) @@ -2651,7 +2655,7 @@ void tcp_set_state(struct sock *sk, int state) inet_put_port(sk); fallthrough; default: - if (oldstate == TCP_ESTABLISHED) + if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT) TCP_DEC_STATS(sock_net(sk), TCP_MIB_CURRESTAB); } -- 2.43.0