[RFC mptcp-next v4 06/10] tls: switch to mptcp_read_done

Geliang Tang
2025-12-12T02:27:38Z

To extend MPTCP support based on TCP TLS, corresponding MPTCP-specific
helper mptcp_read_done() has been implemented.

TLS implementation switches between the respective TCP and MPTCP helpers
based on the detected protocol.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
include/net/mptcp.h | 4 ++++
net/mptcp/protocol.c | 36 ++++++++++++++++++++++++++++++++++++
net/tls/tls_strp.c | 4 ++++
3 files changed, 44 insertions(+)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 3fe60818cada..7346eb9b19bd 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -260,6 +260,8 @@ unsigned int mptcp_inq(const struct sock *sk);
int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);

struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off);
+
+void mptcp_read_done(struct sock *sk, size_t len);
#else

static inline void mptcp_init(void)
@@ -367,6 +369,8 @@ static inline struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
{
return NULL;
}
+
+static inline void mptcp_read_done(struct sock *sk, size_t len) { }
#endif /* CONFIG_MPTCP */

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 92141e87ed25..205492bc6345 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4532,6 +4532,42 @@ static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
return ret;
}

+void mptcp_read_done(struct sock *sk, size_t len)
+{
+ struct mptcp_sock *msk = mptcp_sk(sk);
+ struct sk_buff *skb;
+ size_t left;
+ u32 offset;
+
+ msk_owned_by_me(msk);
+
+ if (sk->sk_state == TCP_LISTEN)
+ return;
+
+ left = len;
+ while (left && (skb = mptcp_recv_skb(sk, &offset)) != NULL) {
+ int used;
+
+ used = min_t(size_t, skb->len - offset, left);
+ msk->bytes_consumed += used;
+ MPTCP_SKB_CB(skb)->offset += used;
+ MPTCP_SKB_CB(skb)->map_seq += used;
+ left -= used;
+
+ if (skb->len > offset + used)
+ break;
+
+ mptcp_eat_recv_skb(sk, skb);
+ }
+
+ mptcp_rcv_space_adjust(msk, len - left);
+
+ /* Clean up data we have read: This will do ACK frames. */
+ if (left != len)
+ mptcp_cleanup_rbuf(msk, len - left);
+}
+EXPORT_SYMBOL(mptcp_read_done);
+
static const struct proto_ops mptcp_stream_ops = {
.family = PF_INET,
.owner = THIS_MODULE,
diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 3bddb871d90b..81ff6be22162 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -132,6 +132,8 @@ int tls_strp_msg_cow(struct tls_sw_context_rx *ctx)
tls_strp_anchor_free(strp);
strp->anchor = skb;

+ sk_is_msk(strp->sk) ?
+ mptcp_read_done(strp->sk, strp->stm.full_len) :
tcp_read_done(strp->sk, strp->stm.full_len);
strp->copy_mode = 1;

@@ -596,6 +598,8 @@ void tls_strp_msg_done(struct tls_strparser *strp)
WARN_ON(!strp->stm.full_len);

if (likely(!strp->copy_mode))
+ sk_is_msk(strp->sk) ?
+ mptcp_read_done(strp->sk, strp->stm.full_len) :
tcp_read_done(strp->sk, strp->stm.full_len);
else
tls_strp_flush_anchor_copy(strp);
--
2.51.0