Skip to content

Commit 6ebf6f9

Browse files
geliangtangkuba-moo
authored andcommitted
mptcp: add mptcpi_subflows_total counter
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: multipath-tcp/mptcp_net-next#428 Reviewed-by: Matthieu Baerts <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: Mat Martineau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3d6d754 commit 6ebf6f9

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

include/uapi/linux/mptcp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct mptcp_info {
5757
__u64 mptcpi_bytes_sent;
5858
__u64 mptcpi_bytes_received;
5959
__u64 mptcpi_bytes_acked;
60+
__u8 mptcpi_subflows_total;
6061
};
6162

6263
/* MPTCP Reset reason codes, rfc8684 */

net/mptcp/protocol.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,15 @@ static inline void __mptcp_do_fallback(struct mptcp_sock *msk)
10721072
set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
10731073
}
10741074

1075+
static inline bool __mptcp_has_initial_subflow(const struct mptcp_sock *msk)
1076+
{
1077+
struct sock *ssk = READ_ONCE(msk->first);
1078+
1079+
return ssk && ((1 << inet_sk_state_load(ssk)) &
1080+
(TCPF_ESTABLISHED | TCPF_SYN_SENT |
1081+
TCPF_SYN_RECV | TCPF_LISTEN));
1082+
}
1083+
10751084
static inline void mptcp_do_fallback(struct sock *ssk)
10761085
{
10771086
struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);

net/mptcp/sockopt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,8 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
938938
info->mptcpi_bytes_sent = msk->bytes_sent;
939939
info->mptcpi_bytes_received = msk->bytes_received;
940940
info->mptcpi_bytes_retrans = msk->bytes_retrans;
941+
info->mptcpi_subflows_total = info->mptcpi_subflows +
942+
__mptcp_has_initial_subflow(msk);
941943
unlock_sock_fast(sk, slow);
942944
}
943945
EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);

0 commit comments

Comments
 (0)