tcp/mptcp: count CLOSE-WAIT for CurrEstab
Subsystems (4)
v5 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.
v5
1. add more detailed comment (Matthieu)
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 | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-)
Signature · 1 line
2.37.3
PATCH v5 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.
---
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
@@ -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
PATCH v5 2/2 mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB
In reply to Jason XingFrom: 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.
--- net/mptcp/protocol.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +7 -2
@@ -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 ); }
Signature · 1 line
2.37.3
Hi Jason,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9355807888
Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/3b2b65c4b8ae
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=858351
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-normalFor 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)
Re: [PATCH net v5 2/2] mptcp: count CLOSE-WAIT sockets for MPTCP_MIB_CURRESTAB
In reply to Jason XingHi 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 the update!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Jason,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/9369946878
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/fc0f674bbb04
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=858351
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-normalFor 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)
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 10 lines · On Tue, 4 Jun 2024 01:02:15 +0800 you wrote:
From: Jason Xing <[email protected]>
Taking CLOSE-WAIT sockets into CurrEstab counters is in accordance with RFC 1213, as suggested by Eric and Neal.
v5
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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html