mptcp: add CurrEstab MIB counter support
authorGeliang Tang <geliang.tang@linux.dev>
Fri, 22 Dec 2023 12:47:22 +0000 (13:47 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 2 Jan 2024 13:32:45 +0000 (13:32 +0000)
Add a new MIB counter named MPTCP_MIB_CURRESTAB to count current
established MPTCP connections, similar to TCP_MIB_CURRESTAB. This is
useful to quickly list the number of MPTCP connections without having to
iterate over all of them.

This patch adds a new helper function mptcp_set_state(): if the state
switches from or to ESTABLISHED state, this newly added counter is
incremented. This helper is going to be used in the following patch.

Similar to MPTCP_INC_STATS(), a new helper called MPTCP_DEC_STATS() is
also needed to decrement a MIB counter.

Signed-off-by: Geliang Tang <geliang.tang@linux.dev>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/mptcp/mib.c
net/mptcp/mib.h
net/mptcp/protocol.c
net/mptcp/protocol.h

index a0990c365a2ea115da9b6389738223a9fc46990a..c30405e7683370d3e3f422ac9a7b0c625348b1ae 100644 (file)
@@ -66,6 +66,7 @@ static const struct snmp_mib mptcp_snmp_list[] = {
        SNMP_MIB_ITEM("RcvWndShared", MPTCP_MIB_RCVWNDSHARED),
        SNMP_MIB_ITEM("RcvWndConflictUpdate", MPTCP_MIB_RCVWNDCONFLICTUPDATE),
        SNMP_MIB_ITEM("RcvWndConflict", MPTCP_MIB_RCVWNDCONFLICT),
+       SNMP_MIB_ITEM("MPCurrEstab", MPTCP_MIB_CURRESTAB),
        SNMP_MIB_SENTINEL
 };
 
index cae71d9472529d857ad4409b7a0f55baa1fba648..dd7fd1f246b5f2a3febb24d80c7070ddc418b47f 100644 (file)
@@ -65,6 +65,7 @@ enum linux_mptcp_mib_field {
                                         * conflict with another subflow while updating msk rcv wnd
                                         */
        MPTCP_MIB_RCVWNDCONFLICT,       /* Conflict with while updating msk rcv wnd */
+       MPTCP_MIB_CURRESTAB,            /* Current established MPTCP connections */
        __MPTCP_MIB_MAX
 };
 
@@ -95,4 +96,11 @@ static inline void __MPTCP_INC_STATS(struct net *net,
                __SNMP_INC_STATS(net->mib.mptcp_statistics, field);
 }
 
+static inline void MPTCP_DEC_STATS(struct net *net,
+                                  enum linux_mptcp_mib_field field)
+{
+       if (likely(net->mib.mptcp_statistics))
+               SNMP_DEC_STATS(net->mib.mptcp_statistics, field);
+}
+
 bool mptcp_mib_alloc(struct net *net);
index 91e5845d80a96530c37afc0fa47799ea6a8123a8..a77a609b447011ed1503bb917a5b40f7f04f0158 100644 (file)
@@ -2871,6 +2871,24 @@ void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
        release_sock(ssk);
 }
 
+void mptcp_set_state(struct sock *sk, int state)
+{
+       int oldstate = sk->sk_state;
+
+       switch (state) {
+       case TCP_ESTABLISHED:
+               if (oldstate != TCP_ESTABLISHED)
+                       MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
+               break;
+
+       default:
+               if (oldstate == TCP_ESTABLISHED)
+                       MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
+       }
+
+       inet_sk_state_store(sk, state);
+}
+
 static const unsigned char new_state[16] = {
        /* current state:     new state:      action:   */
        [0 /* (Invalid) */] = TCP_CLOSE,
index 1240268f9e9e14fc1bf4526c87f27fb48ab511f3..3517f2d24a226ff0be1adec800044810f1aa31c6 100644 (file)
@@ -641,6 +641,7 @@ bool __mptcp_close(struct sock *sk, long timeout);
 void mptcp_cancel_work(struct sock *sk);
 void __mptcp_unaccepted_force_close(struct sock *sk);
 void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk);
+void mptcp_set_state(struct sock *sk, int state);
 
 bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
                           const struct mptcp_addr_info *b, bool use_port);