Skip to contentSkip to conversation

tcp/mptcp: count CLOSE-WAIT for CurrEstab

PATCH Superseded Jason Xing 3 participants 8 messages May 31, 2024 – Jun 3, 2024

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Jason Xing

author
#0 lore raw

v4 cover tcp/mptcp: count CLOSE-WAIT for CurrEstab

From: Jason Xing <[email protected]>

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

v4

1. correct the Fixes: tag in patch [2/2]. (Eric)

Previous discussion

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 | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)
Signature · 1 line
2.37.3
author
#1 lore raw

PATCH v4 1/2 tcp: count CLOSE-WAIT sockets for TCP_MIB_CURRESTAB

From: Jason Xing <[email protected]>

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")

---
previous discussion

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(-)
net/ipv4/tcp.c +5 -1
index 5fa68e7f6ddb..902266146d0e 100644
@@ -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);
 	}
 
Signature · 1 line
2.37.3
author
#2 lore raw

PATCH v4 2/2 mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

In reply to Jason Xing

From: Jason Xing <[email protected]>

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")
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +3 -2
index 7d44196ec5b6..6d59c1c4baba 100644
@@ -2916,9 +2916,10 @@ 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:
+		break;
 	default:
-		if (oldstate == TCP_ESTABLISHED)
+		if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
 			MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
 	}
 
Signature · 1 line
2.37.3
maintainer
#3 lore raw

Re: [PATCH net v4 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

Hi Jason,

Quoted 15 lines · Jason Xing

From: Jason Xing <[email protected]>

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.

Quoted 5 lines

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 this modification, and for having updated the Fixes tag.

Quoted 11 lines
Fixes d9cd27b8cd19 ("mptcp: add CurrEstab MIB counter support")
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +0 -0
index 7d44196ec5b6..6d59c1c4baba 100644

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2920

Quoted 6 lines
net/mptcp/protocol.c +2 -1
@@ -2916,9 +2916,10 @@ 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:
+		break;

The modification is correct: currently, and compared to TCP, the MPTCP "accepted" socket will not go through the TCP_SYN_RECV state because it will be created later on.

Still, I wonder if it would not be clearer to explicitly mention this here, and (or) in the commit message, to be able to understand why the logic is different here, compared to TCP. I don't think the SYN_RECV state will be used in the future with MPTCP sockets, but just in case, it might help to mention TCP_SYN_RECV state here. Could add a small comment here above please?

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2925

Quoted 6 lines
net/mptcp/protocol.c +1 -1
 	default:
-		if (oldstate == TCP_ESTABLISHED)
+		if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
 			MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
 	}
 

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#4 lore raw

Re: [PATCH net v4 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

Hello Matthieu,

Quoted 49 lines · Matthieu Baerts

Hi Jason,

Quoted 15 lines · Jason Xing

From: Jason Xing <[email protected]>

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.

Quoted 5 lines

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 this modification, and for having updated the Fixes tag.

Quoted 11 lines
Fixes d9cd27b8cd19 ("mptcp: add CurrEstab MIB counter support")
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +0 -0
index 7d44196ec5b6..6d59c1c4baba 100644

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2920

Quoted 6 lines
net/mptcp/protocol.c +2 -1
@@ -2916,9 +2916,10 @@ 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:
+             break;

The modification is correct: currently, and compared to TCP, the MPTCP "accepted" socket will not go through the TCP_SYN_RECV state because it will be created later on.

Quoted 6 lines

Still, I wonder if it would not be clearer to explicitly mention this here, and (or) in the commit message, to be able to understand why the logic is different here, compared to TCP. I don't think the SYN_RECV state will be used in the future with MPTCP sockets, but just in case, it might help to mention TCP_SYN_RECV state here. Could add a small comment here above please?

Sure, but what comments do you suggest?
For example, the comment above the case statement is:
"Unlike TCP, MPTCP would not have TCP_SYN_RECV state, so we can skip it directly"
?

Thanks,
Jason

Quoted 13 lines

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2925

Quoted 7 lines
net/mptcp/protocol.c +1 -1
      default:
-             if (oldstate == TCP_ESTABLISHED)
+             if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
                      MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
      }
 

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

maintainer
#5 lore raw

Re: [PATCH net v4 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

Hi Jason,

Quoted 59 lines · Jason Xing

Hello Matthieu,

Quoted 49 lines · Matthieu Baerts

Hi Jason,

Quoted 15 lines · Jason Xing

From: Jason Xing <[email protected]>

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.

Quoted 5 lines

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 this modification, and for having updated the Fixes tag.

Quoted 11 lines
Fixes d9cd27b8cd19 ("mptcp: add CurrEstab MIB counter support")
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +0 -0
index 7d44196ec5b6..6d59c1c4baba 100644

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2920

Quoted 6 lines
net/mptcp/protocol.c +2 -1
@@ -2916,9 +2916,10 @@ 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:
+             break;

The modification is correct: currently, and compared to TCP, the MPTCP "accepted" socket will not go through the TCP_SYN_RECV state because it will be created later on.

Quoted 6 lines

Still, I wonder if it would not be clearer to explicitly mention this here, and (or) in the commit message, to be able to understand why the logic is different here, compared to TCP. I don't think the SYN_RECV state will be used in the future with MPTCP sockets, but just in case, it might help to mention TCP_SYN_RECV state here. Could add a small comment here above please?

Quoted 5 lines

Sure, but what comments do you suggest?
For example, the comment above the case statement is:
"Unlike TCP, MPTCP would not have TCP_SYN_RECV state, so we can skip it directly"
?

Yes, thank you, it looks good to me. But while at it, you can also add the reason:

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. */

WDYT?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author
#6 lore raw

Re: [PATCH net v4 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB

Hi Matthieu,

Quoted 71 lines · Matthieu Baerts

Hi Jason,

Quoted 59 lines · Jason Xing

Hello Matthieu,

Quoted 49 lines · Matthieu Baerts

Hi Jason,

Quoted 15 lines · Jason Xing

From: Jason Xing <[email protected]>

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.

Quoted 5 lines

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 this modification, and for having updated the Fixes tag.

Quoted 11 lines
Fixes d9cd27b8cd19 ("mptcp: add CurrEstab MIB counter support")
---
 net/mptcp/protocol.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +0 -0
index 7d44196ec5b6..6d59c1c4baba 100644

net/mptcp/protocol.c void mptcp_set_state(struct sock *sk, int state) · line 2920

Quoted 6 lines
net/mptcp/protocol.c +2 -1
@@ -2916,9 +2916,10 @@ 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:
+             break;

The modification is correct: currently, and compared to TCP, the MPTCP "accepted" socket will not go through the TCP_SYN_RECV state because it will be created later on.

Quoted 6 lines

Still, I wonder if it would not be clearer to explicitly mention this here, and (or) in the commit message, to be able to understand why the logic is different here, compared to TCP. I don't think the SYN_RECV state will be used in the future with MPTCP sockets, but just in case, it might help to mention TCP_SYN_RECV state here. Could add a small comment here above please?

Quoted 5 lines

Sure, but what comments do you suggest?
For example, the comment above the case statement is:
"Unlike TCP, MPTCP would not have TCP_SYN_RECV state, so we can skip it directly"
?

Yes, thank you, it looks good to me. But while at it, you can also add the reason:

Quoted 7 lines

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. */

WDYT?

So great. Thank you. I will update it soon.

Thanks,
Jason

Quoted 6 lines

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

#7 lore raw
In reply to Jason Xing

Hi Jason,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9316053877

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/d286b214d2f8
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=857630

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)