net/mptcp/protocol.c | 4 ++++ net/mptcp/protocol.h | 2 ++ net/mptcp/sockopt.c | 14 ++++++++++---- net/mptcp/subflow.c | 5 ++++- 4 files changed, 20 insertions(+), 5 deletions(-)
Report sequence numbers relative to their initial data sequence
numbers instead of exposing the raw connection-level values.
Keep the sequence-number baselines in the MPTCP socket so diagnostic
reporting does not depend on a subflow context that may be reset.
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/445
Signed-off-by: Kalpan Jani <kalpan.jani@mpiricsoftware.com>
---
Changes since v8:
- Keep local and remote IDSN baselines in the MPTCP socket, so reporting does not depend on a subflow context that may be reset.
- Normalize mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt relative to their IDSN baselines.
- Initialize the MPTCP_INFO output structure to zero.
v8: https://lore.kernel.org/all/20261014130809.1874184-1-kalpan.jani@mpiricsoftware.com/
---
net/mptcp/protocol.c | 4 ++++
net/mptcp/protocol.h | 2 ++
net/mptcp/sockopt.c | 14 ++++++++++----
net/mptcp/subflow.c | 5 ++++-
4 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index b474d03620a75..fb47384ace9c6 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3178,6 +3178,8 @@ static void __mptcp_init_sock(struct sock *sk)
INIT_WORK(&msk->work, mptcp_worker);
msk->out_of_order_queue = RB_ROOT;
msk->first_pending = NULL;
+ WRITE_ONCE(msk->local_idsn, 0);
+ WRITE_ONCE(msk->remote_idsn, 0);
/* msk does not go through tcp_init_sock(); seed RTO bounds. */
icsk->icsk_rto_min =
@@ -3722,6 +3724,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
msk = mptcp_sk(nsk);
WRITE_ONCE(msk->local_key, subflow_req->local_key);
+ WRITE_ONCE(msk->local_idsn, subflow_req->idsn);
WRITE_ONCE(msk->token, subflow_req->token);
msk->in_accept_queue = 1;
WRITE_ONCE(msk->fully_established, false);
@@ -4160,6 +4163,7 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
MPTCP_MIB_TOKENFALLBACKINIT);
}
+ WRITE_ONCE(msk->local_idsn, subflow->idsn);
WRITE_ONCE(msk->write_seq, subflow->idsn);
WRITE_ONCE(msk->snd_nxt, subflow->idsn);
WRITE_ONCE(msk->snd_una, subflow->idsn);
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 06a107d4e8392..9238031f3adb0 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -286,6 +286,8 @@ struct mptcp_sock {
* lockless access read
*/
u64 remote_key; /* same as above */
+ u64 local_idsn;
+ u64 remote_idsn;
u64 write_seq;
u64 bytes_sent;
u64 snd_nxt;
diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index fcf6feb2a9eb5..b1e41c967157e 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -971,6 +971,7 @@ static int mptcp_getsockopt_first_sf_only(struct mptcp_sock *msk, int level, int
void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
{
struct sock *sk = (struct sock *)msk;
+ u64 local_idsn = 0, remote_idsn = 0;
u32 flags = 0;
bool slow;
u32 now;
@@ -1008,9 +1009,11 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
info->mptcpi_flags = flags;
slow = lock_sock_fast(sk);
+ local_idsn = READ_ONCE(msk->local_idsn);
+
info->mptcpi_csum_enabled = READ_ONCE(msk->csum_enabled);
info->mptcpi_token = msk->token;
- info->mptcpi_write_seq = msk->write_seq;
+ info->mptcpi_write_seq = msk->write_seq - local_idsn;
info->mptcpi_retransmits = inet_csk(sk)->icsk_retransmits;
info->mptcpi_bytes_sent = msk->bytes_sent;
info->mptcpi_bytes_received = msk->bytes_received;
@@ -1023,17 +1026,20 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
unlock_sock_fast(sk, slow);
mptcp_data_lock(sk);
+ if (READ_ONCE(msk->can_ack))
+ remote_idsn = READ_ONCE(msk->remote_idsn);
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_snd_una = msk->snd_una - local_idsn;
+ info->mptcpi_rcv_nxt = msk->ack_seq - remote_idsn;
info->mptcpi_bytes_acked = msk->bytes_acked;
mptcp_data_unlock(sk);
+
}
EXPORT_SYMBOL_GPL(mptcp_diag_fill_info);
static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, int __user *optlen)
{
- struct mptcp_info m_info;
+ struct mptcp_info m_info = {};
int len;
if (get_user(len, optlen))
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index af81ad5e699d1..cfc703bd5dd69 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -481,7 +481,6 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
if (subflow->remote_key_valid)
return;
- subflow->remote_key_valid = 1;
subflow->remote_key = mp_opt->sndr_key;
mptcp_crypto_key_sha(subflow->remote_key, NULL, &subflow->iasn);
subflow->iasn++;
@@ -490,9 +489,13 @@ static void subflow_set_remote_key(struct mptcp_sock *msk,
subflow->map_seq = subflow->iasn;
WRITE_ONCE(msk->remote_key, subflow->remote_key);
+ WRITE_ONCE(msk->remote_idsn, subflow->iasn - 1);
WRITE_ONCE(msk->ack_seq, subflow->iasn);
WRITE_ONCE(msk->can_ack, true);
atomic64_set(&msk->rcv_wnd_sent, subflow->iasn);
+
+ /* publish last, once iasn and the fields above are fully populated */
+ subflow->remote_key_valid = 1;
}
static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,
--
2.43.0
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] After the patch, the MPTCP diag ABI uses two different
baselines for the same data-sequence space.
- [Medium] In mptcp_diag_fill_info() (net/mptcp/sockopt.c) each baseline
and the value it is subtracted from are not read as one consistent…
--
mptcp: normalize seq numbers reported in mptcp_info
This patch adds local_idsn and remote_idsn baselines to struct mptcp_sock.
mptcp_diag_fill_info() now reports mptcpi_write_seq, mptcpi_snd_una and
mptcpi_rcv_nxt relative to those baselines. The baselines are set in
mptcp_connect(), mptcp_sk_clone_init() and subflow_set_remote_key().
Link: https://github.com/multipath-tcp/mptcp_net-next/issues/445
[ ... ]
> diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
> index fcf6feb2a9eb5..b1e41c967157e 100644
> --- a/net/mptcp/sockopt.c
> +++ b/net/mptcp/sockopt.c
[ ... ]
> @@ -1008,9 +1009,11 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
> info->mptcpi_flags = flags;
>
> slow = lock_sock_fast(sk);
> + local_idsn = READ_ONCE(msk->local_idsn);
> +
[ ... ]
> @@ -1023,17 +1026,20 @@ void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info)
> unlock_sock_fast(sk, slow);
>
> mptcp_data_lock(sk);
> + if (READ_ONCE(msk->can_ack))
> + remote_idsn = READ_ONCE(msk->remote_idsn);
> 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_snd_una = msk->snd_una - local_idsn;
[Severity: Medium]
Can this subtract a baseline from a value that belongs to a different
connection?
local_idsn is read under lock_sock_fast(), and that lock is dropped before
snd_una is read under mptcp_data_lock(). mptcp_data_lock() is only
spin_lock_bh(&sk->sk_lock.slock). It does not exclude a task that already
owns the socket through lock_sock().
mptcp_connect() runs under the owner lock and writes the baseline and
snd_una without taking the data lock:
net/mptcp/protocol.c:mptcp_connect() {
...
WRITE_ONCE(msk->local_idsn, subflow->idsn);
WRITE_ONCE(msk->write_seq, subflow->idsn);
WRITE_ONCE(msk->snd_nxt, subflow->idsn);
WRITE_ONCE(msk->snd_una, subflow->idsn);
...
}
Suppose the diag reader reads local_idsn before this runs and snd_una
after it. local_idsn is 0 on a fresh socket, or the previous IDSN after
connect(AF_UNSPEC). mptcpi_snd_una would then be either the raw new IDSN
or new_idsn - old_idsn.
mptcp_disconnect() has a similar problem. It clears can_ack and ack_seq at
separate points, again holding only the owner lock:
net/mptcp/protocol.c:mptcp_disconnect() {
...
WRITE_ONCE(msk->can_ack, false);
...
/* for fallback's sake */
WRITE_ONCE(msk->ack_seq, 0);
...
}
If the reader sees can_ack == false while ack_seq still holds the old
absolute value, mptcpi_rcv_nxt exports the raw remote DSN. If it sees
can_ack == true and then ack_seq == 0, it reports 0 - remote_idsn, which
wraps to a huge 64-bit value.
getsockopt(MPTCP_INFO), MPTCP_FULL_INFO and inet_diag all call
mptcp_diag_fill_info() without holding the msk socket lock. INET_DIAG_INFO
also does not require CAP_NET_ADMIN.
Could this briefly expose the "raw connection-level values" that the commit
message says are no longer exposed? One option is to read each baseline and
its value inside a single section that excludes the owner. Another is to
have connect and disconnect update these fields under the data lock.
> + info->mptcpi_rcv_nxt = msk->ack_seq - remote_idsn;
[Severity: Medium]
With this change, mptcpi_rcv_nxt is relative to remote_idsn. However,
subflow_get_info() in net/mptcp/diag.c still exports the absolute map_seq:
net/mptcp/diag.c:subflow_get_info() {
...
nla_put_u64_64bit(skb, MPTCP_SUBFLOW_ATTR_MAP_SEQ, sf->map_seq,
MPTCP_SUBFLOW_ATTR_PAD) ||
...
}
subflow_set_remote_key() initializes both subflow->map_seq and
msk->ack_seq from subflow->iasn, so the two values share one remote DSN
space. A single inet_diag dump of an MPTCP connection can now show
rcv_nxt as roughly 1 + N alongside map_seq as roughly iasn + N. Before
this patch both values were absolute and could be compared directly.
remote_idsn and local_idsn are not exported anywhere. How would userspace
match a subflow mapping against the connection-level rcv_nxt?
Should MPTCP_SUBFLOW_ATTR_MAP_SEQ be normalized in the same way? If not,
could the switch from absolute to relative values be documented next to
struct mptcp_info in include/uapi/linux/mptcp.h?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261015101303.144541-1-kalpan.jani%40mpiricsoftware.com
Hi Matt, Thanks for discussing this with Mat and for the suggestions. I understand the main goal is to avoid exposing these sequence counters through the diag interface. I think keeping the normalized values available through the MPTCP_INFO socket option, while handling these fields separately for inet_diag, could be a reasonable approach. Before updating the patch, could you clarify whether you would prefer: - Setting the relevant fields to 0 only when the user lacks CAP_NET_ADMIN, or - Always setting them to 0 for the diag interface? I will also look into whether the byte counters could provide the required values correctly, particularly for snd_una and retransmissions. For MAP_SEQ, I will account for its relationship with the diagnostic interface when preparing the change. Date: 23 October 2026 Cheers, Kalpan
Hi Kalpan, Thank you for your reply. On 23/10/2026 10:43, Kalpan Jani wrote: > Hi Matt, > > Thanks for discussing this with Mat and for the suggestions. > > I understand the main goal is to avoid exposing these sequence counters through the diag interface. > > I think keeping the normalized values available through the MPTCP_INFO socket option, while handling these fields separately for inet_diag, could be a reasonable approach. > > Before updating the patch, could you clarify whether you would prefer: > - Setting the relevant fields to 0 only when the user lacks CAP_NET_ADMIN, or If that's possible, that one. We already look for CAP_NET_ADMIN in mptcp_diag.c, but maybe not for these requests. (Maybe we should backport this patch, I don't know) > - Always setting them to 0 for the diag interface? As a fallback, if the first option is not possible. > I will also look into whether the byte counters could provide the required values correctly, particularly for snd_una and retransmissions. Thanks. That's an alternative not to show 0 to userspace. But only if we display the same things: starting at 0 (or 1 for the SYN), snd_una as a diff on top of bytes_send, etc. > For MAP_SEQ, I will account for its relationship with the diagnostic interface when preparing the change. Thanks! Cheers, Matt -- Sponsored by the NGI0 Core fund.
Hi all, Thanks for the report. I looked into both observations. For the first one, I see the concern about reading the sequence number and its baseline in separate synchronization windows. The connect and disconnect paths also need to be considered when deciding how to keep these values consistent. I have not made a locking change yet, as I want to avoid introducing a locking issue while addressing this. For the second one, I noticed that mptcpi_rcv_nxt is now reported relative to remote_idsn, while MPTCP_SUBFLOW_ATTR_MAP_SEQ still reports the absolute sequence number. I have not changed the MAP_SEQ attribute, since that would affect an existing diagnostic interface. Would documenting the normalized sequence numbers in struct mptcp_info be sufficient, or do you think any further changes are needed? I would appreciate your suggestions on the appropriate approach before I prepare the next version. Cheers, Kalpan Jani
Hi Kalpan, Thank you for your patience. On 19/10/2026 13:16, Kalpan Jani wrote: > Hi all, > > Thanks for the report. > > I looked into both observations. > > For the first one, I see the concern about reading the sequence > number and its baseline in separate synchronization windows. The > connect and disconnect paths also need to be considered when deciding > how to keep these values consistent. I have not made a locking change > yet, as I want to avoid introducing a locking issue while addressing > this. Yes, maybe we don't need to address this case (see below) > For the second one, I noticed that mptcpi_rcv_nxt is now reported > relative to remote_idsn, while MPTCP_SUBFLOW_ATTR_MAP_SEQ still > reports the absolute sequence number. I have not changed the MAP_SEQ > attribute, since that would affect an existing diagnostic interface. I think that should be updated as well. > Would documenting the normalized sequence numbers in struct > mptcp_info be sufficient, or do you think any further changes are > needed? > > I would appreciate your suggestions on the appropriate approach > before I prepare the next version. We discussed this case with Mat today. We were thinking about two solutions: either using the bytes send/received counters (and a diff for una) for the different fields you updated here, but we didn't check if it would work, e.g. in case of retransmission how is it incremented compared to write_seq? At the end, what we want is not to expose these counters to the userspace via the diag interface, so visible with a simple "ss -Mae". We wonder if an easier alternative wouldn't be to set these fields to 0 if the user doesn't have the CAP_NET_ADMIN capability? Or always set 0 for the diag interface. WDYT? (Not as exiting as the modifications you did so far, but effective...) Cheers, Matt -- Sponsored by the NGI0 Core fund.
Hi Kalpan,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/38721441830
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/1a9206c4d367
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1186354
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-normal
For 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)
© 2016 - 2026 Red Hat, Inc.