netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab
@ 2024-06-03 17:02 Jason Xing
  2024-06-03 17:02 ` [PATCH net v5 1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB Jason Xing
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jason Xing @ 2024-06-03 17:02 UTC (permalink / raw)
  To: edumazet, kuba, pabeni, davem, dsahern, matttbe, martineau,
	geliang
  Cc: netdev, mptcp, kerneljasonxing, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

Taking CLOSE-WAIT sockets into CurrEstab counters is in accordance with RFC
1213, as suggested by Eric and Neal.

v5
Link: https://lore.kernel.org/all/20240531091753.75930-1-kerneljasonxing@gmail.com/
1. add more detailed comment (Matthieu)

v4
Link: https://lore.kernel.org/all/20240530131308.59737-1-kerneljasonxing@gmail.com/
1. correct the Fixes: tag in patch [2/2]. (Eric)

Previous discussion
Link: https://lore.kernel.org/all/20240529033104.33882-1-kerneljasonxing@gmail.com/

Jason Xing (2):
  tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB
  mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

 net/ipv4/tcp.c       | 6 +++++-
 net/mptcp/protocol.c | 9 +++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

-- 
2.37.3


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net v5 1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB
  2024-06-03 17:02 [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab Jason Xing
@ 2024-06-03 17:02 ` Jason Xing
  2024-06-03 17:02 ` [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB Jason Xing
  2024-06-05 11:40 ` [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Jason Xing @ 2024-06-03 17:02 UTC (permalink / raw)
  To: edumazet, kuba, pabeni, davem, dsahern, matttbe, martineau,
	geliang
  Cc: netdev, mptcp, kerneljasonxing, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

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 <kernelxing@tencent.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
---
previous discussion
Link: https://lore.kernel.org/all/20240529033104.33882-1-kerneljasonxing@gmail.com/
1. Chose to fix CurrEstab instead of introduing a new counter (Eric, Neal)
---
 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 5fa68e7f6ddb..902266146d0e 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2646,6 +2646,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)
@@ -2657,7 +2661,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.37.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB
  2024-06-03 17:02 [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab Jason Xing
  2024-06-03 17:02 ` [PATCH net v5 1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB Jason Xing
@ 2024-06-03 17:02 ` Jason Xing
  2024-06-03 19:48   ` Matthieu Baerts
  2024-06-05 11:40 ` [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Jason Xing @ 2024-06-03 17:02 UTC (permalink / raw)
  To: edumazet, kuba, pabeni, davem, dsahern, matttbe, martineau,
	geliang
  Cc: netdev, mptcp, kerneljasonxing, Jason Xing

From: Jason Xing <kernelxing@tencent.com>

Like previous patch does in TCP, we need to adhere to RFC 1213:

  "tcpCurrEstab OBJECT-TYPE
   ...
   The number of TCP connections for which the current state
   is either ESTABLISHED or CLOSE- WAIT."

So let's consider CLOSE-WAIT sockets.

The logic of counting
When we increment the counter?
a) Only if we change the state to ESTABLISHED.

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.

Fixes: d9cd27b8cd19 ("mptcp: add CurrEstab MIB counter support")
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
 net/mptcp/protocol.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 7d44196ec5b6..96b113854bd3 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2916,9 +2916,14 @@ void mptcp_set_state(struct sock *sk, int state)
 		if (oldstate != TCP_ESTABLISHED)
 			MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
 		break;
-
+	case TCP_CLOSE_WAIT:
+		/* Unlike TCP, MPTCP sk would not have the TCP_SYN_RECV state:
+		 * MPTCP "accepted" sockets will be created later on. So no
+		 * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
+		 */
+		break;
 	default:
-		if (oldstate == TCP_ESTABLISHED)
+		if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
 			MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
 	}
 
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB
  2024-06-03 17:02 ` [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB Jason Xing
@ 2024-06-03 19:48   ` Matthieu Baerts
  0 siblings, 0 replies; 5+ messages in thread
From: Matthieu Baerts @ 2024-06-03 19:48 UTC (permalink / raw)
  To: Jason Xing, edumazet, kuba, pabeni, davem, dsahern, martineau,
	geliang
  Cc: netdev, mptcp, Jason Xing

Hi Jason,

On 03/06/2024 19:02, Jason Xing wrote:
> From: Jason Xing <kernelxing@tencent.com>
> 
> Like previous patch does in TCP, we need to adhere to RFC 1213:
> 
>   "tcpCurrEstab OBJECT-TYPE
>    ...
>    The number of TCP connections for which the current state
>    is either ESTABLISHED or CLOSE- WAIT."
> 
> So let's consider CLOSE-WAIT sockets.
> 
> The logic of counting
> When we increment the counter?
> a) Only if we change the state to ESTABLISHED.
> 
> 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.

Thank you for the update!

Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab
  2024-06-03 17:02 [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab Jason Xing
  2024-06-03 17:02 ` [PATCH net v5 1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB Jason Xing
  2024-06-03 17:02 ` [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB Jason Xing
@ 2024-06-05 11:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-06-05 11:40 UTC (permalink / raw)
  To: Jason Xing
  Cc: edumazet, kuba, pabeni, davem, dsahern, matttbe, martineau,
	geliang, netdev, mptcp, kernelxing

Hello:

This series was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue,  4 Jun 2024 01:02:15 +0800 you wrote:
> From: Jason Xing <kernelxing@tencent.com>
> 
> Taking CLOSE-WAIT sockets into CurrEstab counters is in accordance with RFC
> 1213, as suggested by Eric and Neal.
> 
> v5
> Link: https://lore.kernel.org/all/20240531091753.75930-1-kerneljasonxing@gmail.com/
> 1. add more detailed comment (Matthieu)
> 
> [...]

Here is the summary with links:
  - [net,v5,1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB
    https://git.kernel.org/netdev/net/c/a46d0ea5c942
  - [net,v5,2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB
    https://git.kernel.org/netdev/net/c/9633e9377e6a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-05 11:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 17:02 [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab Jason Xing
2024-06-03 17:02 ` [PATCH net v5 1/2] tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB Jason Xing
2024-06-03 17:02 ` [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB Jason Xing
2024-06-03 19:48   ` Matthieu Baerts
2024-06-05 11:40 ` [PATCH net v5 0/2] tcp/mptcp: count CLOSE-WAIT for CurrEstab patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).