mptcp: add mptcpi_subflows_total counter
authorGeliang Tang <geliang.tang@suse.com>
Tue, 28 Nov 2023 23:18:45 +0000 (15:18 -0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Nov 2023 04:06:17 +0000 (20:06 -0800)
If the initial subflow has been removed, we cannot know without checking
other counters, e.g. ss -ti <filter> | grep -c tcp-ulp-mptcp or
getsockopt(SOL_MPTCP, MPTCP_FULL_INFO, ...) (or others except MPTCP_INFO
of course) and then check mptcp_subflow_data->num_subflows to get the
total amount of subflows.

This patch adds a new counter mptcpi_subflows_total in mptcpi_flags to
store the total amount of subflows, including the initial one. A new
helper __mptcp_has_initial_subflow() is added to check whether the
initial subflow has been removed or not. With this helper, we can then
compute the total amount of subflows from mptcp_info by doing something
like:

    mptcpi_subflows_total = mptcpi_subflows +
            __mptcp_has_initial_subflow(msk).

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/428
Reviewed-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20231128-send-net-next-2023107-v4-1-8d6b94150f6b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/uapi/linux/mptcp.h
net/mptcp/protocol.h
net/mptcp/sockopt.c

index a6451561f3f8c7b286a46afe5f8a45aabe36aa8d..74cfe496891e03098808680f00287a9336e6ed9c 100644 (file)
@@ -57,6 +57,7 @@ struct mptcp_info {
        __u64   mptcpi_bytes_sent;
        __u64   mptcpi_bytes_received;
        __u64   mptcpi_bytes_acked;
+       __u8    mptcpi_subflows_total;
 };
 
 /* MPTCP Reset reason codes, rfc8684 */
index fe6f2d399ee8987f6f03fc65501e46bd43be0e52..458a2d7bb0ddc1f64433d519058cfd29afb03606 100644 (file)
@@ -1072,6 +1072,15 @@ static inline void __mptcp_do_fallback(struct mptcp_sock *msk)
        set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
 }
 
+static inline bool __mptcp_has_initial_subflow(const struct mptcp_sock *msk)
+{
+       struct sock *ssk = READ_ONCE(msk->first);
+
+       return ssk && ((1 << inet_sk_state_load(ssk)) &
+                      (TCPF_ESTABLISHED | TCPF_SYN_SENT |
+                       TCPF_SYN_RECV | TCPF_LISTEN));
+}
+
 static inline void mptcp_do_fallback(struct sock *ssk)
 {
        struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
index 35368073370048f400ea82416cb0e0a0c6595a58..cabe856b2a45f38bdf7d95133615e8fb51ede8b2 100644 (file)
@@ -938,6 +938,8 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
        info->mptcpi_bytes_sent = msk->bytes_sent;
        info->mptcpi_bytes_received = msk->bytes_received;
        info->mptcpi_bytes_retrans = msk->bytes_retrans;
+       info->mptcpi_subflows_total = info->mptcpi_subflows +
+               __mptcp_has_initial_subflow(msk);
        unlock_sock_fast(sk, slow);
 }
 EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);