Commit a55b39e8 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'mptcp-add-last-time-fields-in-mptcp_info'

Matthieu Baerts says:

====================
mptcp: add last time fields in mptcp_info

These patches from Geliang add support for the "last time" field in
MPTCP Info, and verify that the counters look valid.

Patch 1 adds these counters: last_data_sent, last_data_recv and
last_ack_recv. They are available in the MPTCP Info, so exposed via
getsockopt(MPTCP_INFO) and the Netlink Diag interface.

Patch 2 adds a test in diag.sh MPTCP selftest, to check that the
counters have moved by at least 250ms, after having waited twice that
time.

v1: https://lore.kernel.org/r/20240405-upstream-net-next-20240405-mptcp-last-time-info-v1-0-52dc49453649@kernel.org
====================

Link: https://lore.kernel.org/r/20240410-upstream-net-next-20240405-mptcp-last-time-info-v2-0-f95bd6b33e51@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 0e36c21d 22724c89
......@@ -58,6 +58,10 @@ struct mptcp_info {
__u64 mptcpi_bytes_received;
__u64 mptcpi_bytes_acked;
__u8 mptcpi_subflows_total;
__u8 reserved[3];
__u32 mptcpi_last_data_sent;
__u32 mptcpi_last_data_recv;
__u32 mptcpi_last_ack_recv;
};
/* MPTCP Reset reason codes, rfc8684 */
......
......@@ -1068,6 +1068,7 @@ static void ack_update_msk(struct mptcp_sock *msk,
__mptcp_snd_una_update(msk, new_snd_una);
__mptcp_data_acked(sk);
}
msk->last_ack_recv = tcp_jiffies32;
mptcp_data_unlock(sk);
trace_ack_update_msk(mp_opt->data_ack,
......
......@@ -706,6 +706,8 @@ static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
}
} while (more_data_avail);
if (moved > 0)
msk->last_data_recv = tcp_jiffies32;
*bytes += moved;
return done;
}
......@@ -1556,6 +1558,8 @@ static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
err = copied;
out:
if (err > 0)
msk->last_data_sent = tcp_jiffies32;
return err;
}
......@@ -2793,6 +2797,9 @@ static void __mptcp_init_sock(struct sock *sk)
WRITE_ONCE(msk->allow_infinite_fallback, true);
msk->recovery = false;
msk->subflow_id = 1;
msk->last_data_sent = tcp_jiffies32;
msk->last_data_recv = tcp_jiffies32;
msk->last_ack_recv = tcp_jiffies32;
mptcp_pm_data_init(msk);
......
......@@ -282,6 +282,9 @@ struct mptcp_sock {
u64 bytes_acked;
u64 snd_una;
u64 wnd_end;
u32 last_data_sent;
u32 last_data_recv;
u32 last_ack_recv;
unsigned long timer_ival;
u32 token;
int rmem_released;
......
......@@ -898,6 +898,7 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
struct sock *sk = (struct sock *)msk;
u32 flags = 0;
bool slow;
u32 now;
memset(info, 0, sizeof(*info));
......@@ -926,11 +927,6 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
if (READ_ONCE(msk->can_ack))
flags |= MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED;
info->mptcpi_flags = flags;
mptcp_data_lock(sk);
info->mptcpi_snd_una = msk->snd_una;
info->mptcpi_rcv_nxt = msk->ack_seq;
info->mptcpi_bytes_acked = msk->bytes_acked;
mptcp_data_unlock(sk);
slow = lock_sock_fast(sk);
info->mptcpi_csum_enabled = READ_ONCE(msk->csum_enabled);
......@@ -942,7 +938,17 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
info->mptcpi_bytes_retrans = msk->bytes_retrans;
info->mptcpi_subflows_total = info->mptcpi_subflows +
__mptcp_has_initial_subflow(msk);
now = tcp_jiffies32;
info->mptcpi_last_data_sent = jiffies_to_msecs(now - msk->last_data_sent);
info->mptcpi_last_data_recv = jiffies_to_msecs(now - msk->last_data_recv);
unlock_sock_fast(sk, slow);
mptcp_data_lock(sk);
info->mptcpi_last_ack_recv = jiffies_to_msecs(now - msk->last_ack_recv);
info->mptcpi_snd_una = msk->snd_una;
info->mptcpi_rcv_nxt = msk->ack_seq;
info->mptcpi_bytes_acked = msk->bytes_acked;
mptcp_data_unlock(sk);
}
EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);
......
......@@ -200,6 +200,58 @@ chk_msk_cestab()
"${expected}" "${msg}" ""
}
msk_info_get_value()
{
local port="${1}"
local info="${2}"
ss -N "${ns}" -inHM dport "${port}" | \
mptcp_lib_get_info_value "${info}" "${info}"
}
chk_msk_info()
{
local port="${1}"
local info="${2}"
local cnt="${3}"
local msg="....chk ${info}"
local delta_ms=250 # half what we waited before, just to be sure
local now
now=$(msk_info_get_value "${port}" "${info}")
mptcp_lib_print_title "${msg}"
if { [ -z "${cnt}" ] || [ -z "${now}" ]; } &&
! mptcp_lib_expect_all_features; then
mptcp_lib_pr_skip "Feature probably not supported"
mptcp_lib_result_skip "${msg}"
elif [ "$((cnt + delta_ms))" -lt "${now}" ]; then
mptcp_lib_pr_ok
mptcp_lib_result_pass "${msg}"
else
mptcp_lib_pr_fail "value of ${info} changed by $((now - cnt))ms," \
"expected at least ${delta_ms}ms"
mptcp_lib_result_fail "${msg}"
ret=${KSFT_FAIL}
fi
}
chk_last_time_info()
{
local port="${1}"
local data_sent data_recv ack_recv
data_sent=$(msk_info_get_value "${port}" "last_data_sent")
data_recv=$(msk_info_get_value "${port}" "last_data_recv")
ack_recv=$(msk_info_get_value "${port}" "last_ack_recv")
sleep 0.5 # wait to check after if the timestamps difference
chk_msk_info "${port}" "last_data_sent" "${data_sent}"
chk_msk_info "${port}" "last_data_recv" "${data_recv}"
chk_msk_info "${port}" "last_ack_recv" "${ack_recv}"
}
wait_connected()
{
local listener_ns="${1}"
......@@ -233,6 +285,7 @@ echo "b" | \
127.0.0.1 >/dev/null &
wait_connected $ns 10000
chk_msk_nr 2 "after MPC handshake "
chk_last_time_info 10000
chk_msk_remote_key_nr 2 "....chk remote_key"
chk_msk_fallback_nr 0 "....chk no fallback"
chk_msk_inuse 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment