[RFC mptcp-next v4 04/10] tls: switch to mptcp_sendmsg_locked

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

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

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 | 8 ++++++++
net/mptcp/protocol.c | 16 ++++++++++++----
net/tls/tls_main.c | 4 +++-
3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 4c8e483fcc4b..cdb726865486 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -256,6 +256,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);
+
+int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);
#else

static inline void mptcp_init(void)
@@ -352,6 +354,12 @@ static inline unsigned int mptcp_inq(const struct sock *sk)
{
return 0;
}
+
+static inline int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg,
+ size_t len)
+{
+ return 0;
+}
#endif /* CONFIG_MPTCP */

#if IS_ENABLED(CONFIG_MPTCP_IPV6)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 82a3b3c70ad1..feac59a92b32 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1884,7 +1884,7 @@ static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
}
}

-static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len)
{
struct mptcp_sock *msk = mptcp_sk(sk);
struct page_frag *pfrag;
@@ -1895,8 +1895,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
/* silently ignore everything else */
msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_FASTOPEN;

- lock_sock(sk);
-
mptcp_rps_record_subflows(msk);

if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
@@ -2004,7 +2002,6 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
__mptcp_push_pending(sk, msg->msg_flags);

out:
- release_sock(sk);
return copied;

do_error:
@@ -2015,6 +2012,17 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
goto out;
}

+static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
+{
+ int ret;
+
+ lock_sock(sk);
+ ret = mptcp_sendmsg_locked(sk, msg, len);
+ release_sock(sk);
+
+ return ret;
+}
+
static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);

static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index 56ce0bc8317b..18c767b7388d 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -194,7 +194,9 @@ int tls_push_sg(struct sock *sk,
bvec_set_page(&bvec, p, size, offset);
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size);

- ret = tcp_sendmsg_locked(sk, &msg, size);
+ ret = sk_is_msk(sk) ?
+ mptcp_sendmsg_locked(sk, &msg, size) :
+ tcp_sendmsg_locked(sk, &msg, size);

if (ret != size) {
if (ret > 0) {
--
2.51.0