[RFC mptcp-next v4 03/10] tls: switch to mptcp_inq

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

To extend MPTCP support based on TCP TLS, corresponding MPTCP-specific
helper mptcp_inq() has been exported into net/mptcp.h.

Note that there is a slight difference between mptcp_inq() and
mptcp_inq_hint(), it does not return 1 when the socket is closed or shut
down; instead, it returns 0. Otherwise, it would break the condition
"inq < 1" in tls_strp_read_sock().

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 | 7 +++++++
net/mptcp/protocol.c | 12 +++++++++++-
net/tls/tls_strp.c | 8 ++++++--
net/tls/tls_sw.c | 4 +++-
4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 050c2e820fc4..4c8e483fcc4b 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -254,6 +254,8 @@ static inline __be32 mptcp_reset_option(const struct sk_buff *skb)
}

void mptcp_active_detect_blackhole(struct sock *sk, bool expired);
+
+unsigned int mptcp_inq(const struct sock *sk);
#else

static inline void mptcp_init(void)
@@ -345,6 +347,11 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct reques
static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); }

static inline void mptcp_active_detect_blackhole(struct sock *sk, bool expired) { }
+
+static inline unsigned int mptcp_inq(const struct sock *sk)
+{
+ return 0;
+}
#endif /* CONFIG_MPTCP */

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 334fdb10fdf3..82a3b3c70ad1 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -2242,7 +2242,7 @@ static bool mptcp_move_skbs(struct sock *sk)
return enqueued;
}

-static unsigned int mptcp_inq_hint(const struct sock *sk)
+unsigned int mptcp_inq(const struct sock *sk)
{
const struct mptcp_sock *msk = mptcp_sk(sk);
const struct sk_buff *skb;
@@ -2257,6 +2257,16 @@ static unsigned int mptcp_inq_hint(const struct sock *sk)
return (unsigned int)hint_val;
}

+ return 0;
+}
+
+static unsigned int mptcp_inq_hint(const struct sock *sk)
+{
+ unsigned int inq = mptcp_inq(sk);
+
+ if (inq)
+ return inq;
+
if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
return 1;

diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index cdbcb07a52f8..0639130b8d5e 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -494,7 +494,9 @@ bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
DEBUG_NET_WARN_ON_ONCE(!strp->stm.full_len);

if (!strp->copy_mode && force_refresh) {
- if (unlikely(tcp_inq(strp->sk) < strp->stm.full_len)) {
+ if (unlikely((sk_is_msk(strp->sk) ?
+ mptcp_inq(strp->sk) :
+ tcp_inq(strp->sk)) < strp->stm.full_len)) {
WRITE_ONCE(strp->msg_ready, 0);
memset(&strp->stm, 0, sizeof(strp->stm));
return false;
@@ -517,7 +519,9 @@ static int tls_strp_read_sock(struct tls_strparser *strp)
{
int sz, inq;

- inq = tcp_inq(strp->sk);
+ inq = sk_is_msk(strp->sk) ?
+ mptcp_inq(strp->sk) :
+ tcp_inq(strp->sk);
if (inq < 1)
return 0;

diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index c35c25abc40c..30ca332afe41 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -1958,7 +1958,9 @@ tls_read_flush_backlog(struct sock *sk, struct tls_prot_info *prot,
return false;

max_rec = prot->overhead_size - prot->tail_size + TLS_MAX_PAYLOAD_SIZE;
- if (done - *flushed_at < SZ_128K && tcp_inq(sk) > max_rec)
+ if (done - *flushed_at < SZ_128K && (sk_is_msk(sk) ?
+ mptcp_inq(sk) :
+ tcp_inq(sk)) > max_rec)
return false;

*flushed_at = done;
--
2.51.0