public inbox for mptcp@lists.linux.dev
 help / color / mirror / Atom feed
* [RFC mptcp-next v4 00/10] MPTCP KTLS support
@ 2025-12-12  2:27 Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 01/10] mptcp: add sk_is_msk helper Geliang Tang
                   ` (12 more replies)
  0 siblings, 13 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

v4:
 - split "tls: add MPTCP protocol support" into smaller, more
   focused patches.
 - a new mptcp_inq helper has been implemented instead of directly
   using mptcp_inq_hint to fix the issue mentioned in [1].
 - add sk_is_msk helper.
 - the 'expect' parameter will no longer be added to sock_test_tcpulp.
   Instead, SOCK_TEST_TCPULP items causing the tests failure will be
   directly removed.
 - remove the "TCP KTLS" tests, keeping only the MPTCP-related ones.

[1]
https://patchwork.kernel.org/project/mptcp/patch/ce74452f4c095a1761ef493b767b4bd9f9c14359.1764333805.git.tanggeliang@kylinos.cn/

v3:
 - mptcp_read_sock() and mptcp_poll() are not exported, as mptcp_sockopt
   test does not use read_sock/poll interfaces. They will be exported when
   new tests are added in the future.
 - call mptcp_inq_hint in tls_device_rx_resync_new_rec(),
   tls_device_core_ctrl_rx_resync() and tls_read_flush_backlog() too.
 - update selftests.
 - Link: https://patchwork.kernel.org/project/mptcp/cover/cover.1763800601.git.tanggeliang@kylinos.cn/

v2:
 - fix disconnect.
 - update selftests.

This series adds KTLS support for MPTCP. Since the ULP of msk is not being
used, ULP KTLS can be directly configured onto msk without affecting its
communication.

Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/480

Geliang Tang (10):
  mptcp: add sk_is_msk helper
  tls: switch to MPTCP_SKB_CB
  tls: switch to mptcp_inq
  tls: switch to mptcp_sendmsg_locked
  tls: switch to mptcp_recv_skb
  tls: switch to mptcp_read_done
  mptcp: update ULP getsockopt
  mptcp: enable TLS setsockopt
  selftests: mptcp: connect: update sock_test_tcpulp
  selftests: mptcp: sockopt: implement MPTCP KTLS tests

 include/net/mptcp.h                           | 48 ++++++++++++
 net/mptcp/protocol.c                          | 66 ++++++++++++++--
 net/mptcp/protocol.h                          | 10 ---
 net/mptcp/sockopt.c                           | 30 +++++++-
 net/tls/tls_main.c                            |  4 +-
 net/tls/tls_strp.c                            | 24 ++++--
 net/tls/tls_sw.c                              |  8 +-
 tools/testing/selftests/net/mptcp/config      |  1 +
 .../selftests/net/mptcp/mptcp_connect.c       | 20 +++--
 .../selftests/net/mptcp/mptcp_sockopt.c       | 76 ++++++++++++++++++-
 .../selftests/net/mptcp/mptcp_sockopt.sh      | 36 +++++++++
 11 files changed, 289 insertions(+), 34 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 01/10] mptcp: add sk_is_msk helper
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 02/10] tls: switch to MPTCP_SKB_CB Geliang Tang
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

This patch introduces a sk_is_msk() helper modeled after sk_is_tcp() to
determine whether the socket is an MPTCP one. Unlike sk_is_mptcp(), which
accepts a subflow socket as its parameter, this new helper specifically
accepts an MPTCP socket parameter.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 include/net/mptcp.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 4cf59e83c1c5..82660374859a 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -150,6 +150,13 @@ static inline bool rsk_drop_req(const struct request_sock *req)
 	return tcp_rsk(req)->is_mptcp && tcp_rsk(req)->drop_req;
 }
 
+static inline bool sk_is_msk(const struct sock *sk)
+{
+	return sk_is_inet(sk) &&
+	       sk->sk_type == SOCK_STREAM &&
+	       sk->sk_protocol == IPPROTO_MPTCP;
+}
+
 void mptcp_space(const struct sock *ssk, int *space, int *full_space);
 bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 		       unsigned int *size, struct mptcp_out_options *opts);
@@ -258,6 +265,11 @@ static inline bool rsk_drop_req(const struct request_sock *req)
 	return false;
 }
 
+static inline bool sk_is_msk(const struct sock *sk)
+{
+	return false;
+}
+
 static inline bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 				     unsigned int *size,
 				     struct mptcp_out_options *opts)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 02/10] tls: switch to MPTCP_SKB_CB
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 01/10] mptcp: add sk_is_msk helper Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 03/10] tls: switch to mptcp_inq Geliang Tang
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

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

TLS implementation switches between the respective TCP and MPTCP macros
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  | 10 ++++++++++
 net/mptcp/protocol.h | 10 ----------
 net/tls/tls_strp.c   |  8 ++++++--
 net/tls/tls_sw.c     |  4 +++-
 4 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 82660374859a..050c2e820fc4 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -132,6 +132,16 @@ struct mptcp_pm_ops {
 	void (*release)(struct mptcp_sock *msk);
 } ____cacheline_aligned_in_smp;
 
+struct mptcp_skb_cb {
+	u64 map_seq;
+	u64 end_seq;
+	u32 offset;
+	u8  has_rxtstamp;
+	u8  cant_coalesce;
+};
+
+#define MPTCP_SKB_CB(__skb)	((struct mptcp_skb_cb *)&((__skb)->cb[0]))
+
 #ifdef CONFIG_MPTCP
 void mptcp_init(void);
 
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index cd5266099993..75f2fd05ece4 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -125,16 +125,6 @@
 #define MPTCP_SYNC_STATE	6
 #define MPTCP_SYNC_SNDBUF	7
 
-struct mptcp_skb_cb {
-	u64 map_seq;
-	u64 end_seq;
-	u32 offset;
-	u8  has_rxtstamp;
-	u8  cant_coalesce;
-};
-
-#define MPTCP_SKB_CB(__skb)	((struct mptcp_skb_cb *)&((__skb)->cb[0]))
-
 static inline bool before64(__u64 seq1, __u64 seq2)
 {
 	return (__s64)(seq1 - seq2) < 0;
diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 98e12f0ff57e..cdbcb07a52f8 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -439,7 +439,9 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp)
 
 	first = skb_shinfo(strp->anchor)->frag_list;
 	skb = first;
-	seq = TCP_SKB_CB(first)->seq;
+	seq = sk_is_msk(strp->sk) ?
+	      MPTCP_SKB_CB(first)->map_seq :
+	      TCP_SKB_CB(first)->seq;
 
 	/* Make sure there's no duplicate data in the queue,
 	 * and the decrypted status matches.
@@ -449,7 +451,9 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp)
 		len -= skb->len;
 		skb = skb->next;
 
-		if (TCP_SKB_CB(skb)->seq != seq)
+		if ((sk_is_msk(strp->sk) ?
+		     MPTCP_SKB_CB(skb)->map_seq :
+		     TCP_SKB_CB(skb)->seq) != seq)
 			return false;
 		if (skb_cmp_decrypted(first, skb))
 			return false;
diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c
index 9937d4c810f2..c35c25abc40c 100644
--- a/net/tls/tls_sw.c
+++ b/net/tls/tls_sw.c
@@ -2489,7 +2489,9 @@ int tls_rx_msg_size(struct tls_strparser *strp, struct sk_buff *skb)
 	}
 
 	tls_device_rx_resync_new_rec(strp->sk, data_len + TLS_HEADER_SIZE,
-				     TCP_SKB_CB(skb)->seq + strp->stm.offset);
+				     (sk_is_msk(strp->sk) ?
+				      MPTCP_SKB_CB(skb)->map_seq :
+				      TCP_SKB_CB(skb)->seq) + strp->stm.offset);
 	return data_len + TLS_HEADER_SIZE;
 
 read_failure:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 03/10] tls: switch to mptcp_inq
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 01/10] mptcp: add sk_is_msk helper Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 02/10] tls: switch to MPTCP_SKB_CB Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 04/10] tls: switch to mptcp_sendmsg_locked Geliang Tang
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 04/10] tls: switch to mptcp_sendmsg_locked
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (2 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 03/10] tls: switch to mptcp_inq Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 05/10] tls: switch to mptcp_recv_skb Geliang Tang
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 05/10] tls: switch to mptcp_recv_skb
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (3 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 04/10] tls: switch to mptcp_sendmsg_locked Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 06/10] tls: switch to mptcp_read_done Geliang Tang
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

To extend MPTCP support based on TCP TLS, corresponding MPTCP-specific
helper mptcp_recv_skb() 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  | 7 +++++++
 net/mptcp/protocol.c | 2 +-
 net/tls/tls_strp.c   | 4 +++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index cdb726865486..3fe60818cada 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -258,6 +258,8 @@ 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);
+
+struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off);
 #else
 
 static inline void mptcp_init(void)
@@ -360,6 +362,11 @@ static inline int mptcp_sendmsg_locked(struct sock *sk, struct msghdr *msg,
 {
 	return 0;
 }
+
+static inline struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
+{
+	return NULL;
+}
 #endif /* CONFIG_MPTCP */
 
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index feac59a92b32..92141e87ed25 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4340,7 +4340,7 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 	return mask;
 }
 
-static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
+struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct sk_buff *skb;
diff --git a/net/tls/tls_strp.c b/net/tls/tls_strp.c
index 0639130b8d5e..3bddb871d90b 100644
--- a/net/tls/tls_strp.c
+++ b/net/tls/tls_strp.c
@@ -468,7 +468,9 @@ static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len)
 	struct sk_buff *first;
 	u32 offset;
 
-	first = tcp_recv_skb(strp->sk, tp->copied_seq, &offset);
+	first = sk_is_msk(strp->sk) ?
+		mptcp_recv_skb(strp->sk, &offset) :
+		tcp_recv_skb(strp->sk, tp->copied_seq, &offset);
 	if (WARN_ON_ONCE(!first))
 		return;
 
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 06/10] tls: switch to mptcp_read_done
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (4 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 05/10] tls: switch to mptcp_recv_skb Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 07/10] mptcp: update ULP getsockopt Geliang Tang
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 07/10] mptcp: update ULP getsockopt
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (5 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 06/10] tls: switch to mptcp_read_done Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt Geliang Tang
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

TCP_ULP was obtained by calling mptcp_getsockopt_first_sf_only() to get
the ULP of the first subflow. Now that the mechanism has changed, a new
helper needs to be implemented to get the ULP of the msk.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/sockopt.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index de90a2897d2d..f3db4f2e8f81 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -1393,6 +1393,17 @@ static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,
 	return 0;
 }
 
+static int mptcp_getsockopt_msk(struct sock *sk, int level, int optname,
+				char __user *optval, int __user *optlen)
+{
+	int ret;
+
+	lock_sock(sk);
+	ret = tcp_getsockopt(sk, level, optname, optval, optlen);
+	release_sock(sk);
+	return ret;
+}
+
 static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 				    char __user *optval, int __user *optlen)
 {
@@ -1400,6 +1411,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 
 	switch (optname) {
 	case TCP_ULP:
+		return mptcp_getsockopt_msk(sk, SOL_TCP, optname, optval, optlen);
 	case TCP_CONGESTION:
 	case TCP_INFO:
 	case TCP_CC_INFO:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (6 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 07/10] mptcp: update ULP getsockopt Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  7:23   ` GangYan
  2025-12-12  2:27 ` [RFC mptcp-next v4 09/10] selftests: mptcp: connect: update sock_test_tcpulp Geliang Tang
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

This patch adds MPTCP TLS setsockopt support. It allows setting the TCP_ULP
option to 'tls' exclusively, and enables configuration of the TLS_TX and
TLS_RX options at the SOL_TLS level.

This option cannot be set when the socket is in CLOSE or LISTEN state.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 net/mptcp/sockopt.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index f3db4f2e8f81..52ff75702404 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -12,6 +12,7 @@
 #include <net/protocol.h>
 #include <net/tcp.h>
 #include <net/mptcp.h>
+#include <net/tls.h>
 #include "protocol.h"
 
 #define MIN_INFO_OPTLEN_SIZE		16
@@ -567,6 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		case TCP_FASTOPEN_CONNECT:
 		case TCP_FASTOPEN_KEY:
 		case TCP_FASTOPEN_NO_COOKIE:
+		case TCP_ULP:
 			return true;
 		}
 
@@ -576,6 +578,13 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		 * TCP_REPAIR_WINDOW are not supported, better avoid this mess
 		 */
 	}
+	if (level == SOL_TLS) {
+		switch (optname) {
+		case TLS_TX:
+		case TLS_RX:
+			return true;
+		}
+	}
 	return false;
 }
 
@@ -819,11 +828,18 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 				    sockptr_t optval, unsigned int optlen)
 {
 	struct sock *sk = (void *)msk;
+	char ulp[4] = "";
 	int ret, val;
 
 	switch (optname) {
 	case TCP_ULP:
-		return -EOPNOTSUPP;
+		if (copy_from_user(ulp, optval.user, 4))
+			return -EFAULT;
+		if (strcmp(ulp, "tls\0"))
+			return -EOPNOTSUPP;
+		if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
+			return -EINVAL;
+		return tcp_setsockopt(sk, SOL_TCP, optname, optval, optlen);
 	case TCP_CONGESTION:
 		return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen);
 	case TCP_DEFER_ACCEPT:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 09/10] selftests: mptcp: connect: update sock_test_tcpulp
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (7 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  2:27 ` [RFC mptcp-next v4 10/10] selftests: mptcp: sockopt: implement MPTCP KTLS tests Geliang Tang
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

Update sock_test_tcpulp() to ensure the mptcp_connect.c tests are not
broken.

fallback() helper has been implemented to verify fallback scenarios,
ensuring that MPTCP fallback-to-TCP tests continue to pass.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../selftests/net/mptcp/mptcp_connect.c       | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index b82df82e0594..e5c394ea4e11 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -266,6 +266,18 @@ static void set_mptfo(int fd, int pf)
 		perror("TCP_FASTOPEN");
 }
 
+static int fallback(int fd)
+{
+	int is_mptcp = 0;
+	socklen_t optlen;
+
+	optlen = sizeof(is_mptcp);
+	if (getsockopt(fd, IPPROTO_TCP, TCP_IS_MPTCP, &is_mptcp, &optlen) == -1)
+		perror("TCP_IS_MPTCP");
+
+	return !is_mptcp;
+}
+
 static int do_ulp_so(int sock, const char *name)
 {
 	return setsockopt(sock, IPPROTO_TCP, TCP_ULP, name, strlen(name));
@@ -282,7 +294,7 @@ static void sock_test_tcpulp(int sock, int proto, unsigned int line)
 		X("getsockopt");
 
 	if (buflen > 0) {
-		if (strcmp(buf, "mptcp") != 0)
+		if (strcmp(buf, fallback(sock) ? "mptcp" : "tls") != 0)
 			xerror("unexpected ULP '%s' for proto %d at line %u", buf, proto, line);
 		ret = do_ulp_so(sock, "tls");
 		if (ret == 0)
@@ -424,8 +436,6 @@ static int sock_connect_mptcp(const char * const remoteaddr,
 	}
 
 	freeaddrinfo(addr);
-	if (sock != -1)
-		SOCK_TEST_TCPULP(sock, proto);
 	return sock;
 }
 
@@ -1197,8 +1207,6 @@ int main_loop_s(int listensock)
 				xerror("can't open %s: %d", cfg_input, errno);
 		}
 
-		SOCK_TEST_TCPULP(remotesock, 0);
-
 		memset(&winfo, 0, sizeof(winfo));
 		err = copyfd_io(fd, remotesock, 1, true, &winfo);
 	} else {
@@ -1371,8 +1379,6 @@ int main_loop(void)
 again:
 	check_getpeername_connect(fd);
 
-	SOCK_TEST_TCPULP(fd, cfg_sock_proto);
-
 	if (cfg_rcvbuf)
 		set_rcvbuf(fd, cfg_rcvbuf);
 	if (cfg_sndbuf)
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [RFC mptcp-next v4 10/10] selftests: mptcp: sockopt: implement MPTCP KTLS tests
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (8 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 09/10] selftests: mptcp: connect: update sock_test_tcpulp Geliang Tang
@ 2025-12-12  2:27 ` Geliang Tang
  2025-12-12  4:52 ` [RFC mptcp-next v4 00/10] MPTCP KTLS support MPTCP CI
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  2:27 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang, Gang Yan

From: Geliang Tang <tanggeliang@kylinos.cn>

This patch adds Kernel TLS (KTLS) testing infrastructure to MPTCP sockopt
selftest, introducing a new '-c' option to enable TLS tests. It includes
a helper for configuring TLS socket options and implements MPTCP-specific
KTLS test cases for both IPv4 and IPv6, along with the necessary header
includes and config updates.

TLS_OVERHEAD_SIZE macro is defined to account for the overhead in sent
and received data length.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 tools/testing/selftests/net/mptcp/config      |  1 +
 .../selftests/net/mptcp/mptcp_sockopt.c       | 76 ++++++++++++++++++-
 .../selftests/net/mptcp/mptcp_sockopt.sh      | 36 +++++++++
 3 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config
index 59051ee2a986..18bd29ac5b24 100644
--- a/tools/testing/selftests/net/mptcp/config
+++ b/tools/testing/selftests/net/mptcp/config
@@ -34,3 +34,4 @@ CONFIG_NFT_SOCKET=m
 CONFIG_NFT_TPROXY=m
 CONFIG_SYN_COOKIES=y
 CONFIG_VETH=y
+CONFIG_TLS=y
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index 286164f7246e..cd7f9a7d8d40 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -25,8 +25,10 @@
 #include <netinet/in.h>
 
 #include <linux/tcp.h>
+#include <linux/tls.h>
 
 static int pf = AF_INET;
+static bool tls;
 
 #ifndef IPPROTO_MPTCP
 #define IPPROTO_MPTCP 262
@@ -34,6 +36,9 @@ static int pf = AF_INET;
 #ifndef SOL_MPTCP
 #define SOL_MPTCP 284
 #endif
+#ifndef TCP_ULP
+#define TCP_ULP 31
+#endif
 
 #ifndef MPTCP_INFO
 struct mptcp_info {
@@ -135,7 +140,7 @@ static void die_perror(const char *msg)
 
 static void die_usage(int r)
 {
-	fprintf(stderr, "Usage: mptcp_sockopt [-6]\n");
+	fprintf(stderr, "Usage: mptcp_sockopt [-6] [-c]\n");
 	exit(r);
 }
 
@@ -182,6 +187,54 @@ static void xgetaddrinfo(const char *node, const char *service,
 	}
 }
 
+#define TLS_OVERHEAD_SIZE	29
+
+static int do_setsockopt_tls(int fd)
+{
+	struct tls12_crypto_info_aes_gcm_128 tls_tx = {
+		.info = {
+			.version     = TLS_1_2_VERSION,
+			.cipher_type = TLS_CIPHER_AES_GCM_128,
+		},
+	};
+	struct tls12_crypto_info_aes_gcm_128 tls_rx = {
+		.info = {
+			.version     = TLS_1_2_VERSION,
+			.cipher_type = TLS_CIPHER_AES_GCM_128,
+		},
+	};
+	int so_buf = 6553500;
+	int err;
+
+	err = setsockopt(fd, IPPROTO_TCP, TCP_ULP, "tls", sizeof("tls"));
+	if (err) {
+		perror("setsockopt TCP_ULP");
+		return err;
+	}
+	err = setsockopt(fd, SOL_TLS, TLS_TX, (void *)&tls_tx, sizeof(tls_tx));
+	if (err) {
+		perror("setsockopt TLS_TX");
+		return err;
+	}
+	err = setsockopt(fd, SOL_TLS, TLS_RX, (void *)&tls_rx, sizeof(tls_rx));
+	if (err) {
+		perror("setsockopt TLS_RX");
+		return err;
+	}
+	err = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &so_buf, sizeof(so_buf));
+	if (err) {
+		perror("setsockopt SO_SNDBUF");
+		return err;
+	}
+	err = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &so_buf, sizeof(so_buf));
+	if (err) {
+		perror("setsockopt SO_RCVBUF");
+		return err;
+	}
+
+	return 0;
+}
+
 static int sock_listen_mptcp(const char * const listenaddr,
 			     const char * const port)
 {
@@ -263,7 +316,7 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "h6")) != -1) {
+	while ((c = getopt(argc, argv, "h6c")) != -1) {
 		switch (c) {
 		case 'h':
 			die_usage(0);
@@ -271,6 +324,9 @@ static void parse_opts(int argc, char **argv)
 		case '6':
 			pf = AF_INET6;
 			break;
+		case 'c':
+			tls = true;
+			break;
 		default:
 			die_usage(1);
 			break;
@@ -626,6 +682,11 @@ static void connect_one_server(int fd, int pipefd)
 	if (s.tcpi_rcv_delta)
 		assert(s.tcpi_rcv_delta <= total);
 
+	if (tls) {
+		ret += TLS_OVERHEAD_SIZE;
+		total += TLS_OVERHEAD_SIZE;
+	}
+
 	do_getsockopts(&s, fd, ret, ret);
 
 	if (eof)
@@ -665,6 +726,11 @@ static void process_one_client(int fd, int pipefd)
 	if (ret3 != 0)
 		xerror("expected EOF, got %lu", ret3);
 
+	if (tls) {
+		ret += TLS_OVERHEAD_SIZE;
+		ret2 += TLS_OVERHEAD_SIZE;
+	}
+
 	do_getsockopts(&s, fd, ret, ret2);
 	if (s.mptcpi_rcv_delta != (uint64_t)ret + 1)
 		xerror("mptcpi_rcv_delta %" PRIu64 ", expect %" PRIu64 ", diff %" PRId64,
@@ -724,6 +790,9 @@ static int server(int pipefd)
 	alarm(15);
 	r = xaccept(fd);
 
+	if (tls)
+		do_setsockopt_tls(r);
+
 	process_one_client(r, pipefd);
 
 	close(fd);
@@ -787,6 +856,9 @@ static int client(int pipefd)
 
 	test_ip_tos_sockopt(fd);
 
+	if (tls)
+		do_setsockopt_tls(fd);
+
 	connect_one_server(fd, pipefd);
 
 	return 0;
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
index ab8bce06b262..23b483241f01 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
@@ -351,6 +351,41 @@ do_tcpinq_tests()
 	return $?
 }
 
+do_tls_test()
+{
+	print_title "KTLS $*" | head -c 53
+	ip netns exec "$ns_sbox" ./mptcp_sockopt "$@"
+	local lret=$?
+	if [ $lret -ne 0 ];then
+		ret=$lret
+		mptcp_lib_pr_fail
+		mptcp_lib_result_fail "KTLS: $*"
+		return $lret
+	fi
+
+	mptcp_lib_pr_ok
+	mptcp_lib_result_pass "KTLS: $*"
+	return $lret
+}
+
+do_tls_tests()
+{
+	local lret=0
+
+	mptcp_lib_print_info "sockopt KTLS"
+
+	local args
+	for args in "-c" "-6 -c"; do
+		do_tls_test $args
+		lret=$?
+		if [ $lret -ne 0 ] ; then
+			return $lret
+		fi
+	done
+
+	return $lret
+}
+
 sin=$(mktemp)
 sout=$(mktemp)
 cin=$(mktemp)
@@ -366,6 +401,7 @@ run_tests $ns1 $ns2 dead:beef:1::1
 
 do_mptcp_sockopt_tests
 do_tcpinq_tests
+do_tls_tests
 
 mptcp_lib_result_print_all_tap
 exit $ret
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [RFC mptcp-next v4 00/10] MPTCP KTLS support
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (9 preceding siblings ...)
  2025-12-12  2:27 ` [RFC mptcp-next v4 10/10] selftests: mptcp: sockopt: implement MPTCP KTLS tests Geliang Tang
@ 2025-12-12  4:52 ` MPTCP CI
  2025-12-12  9:17 ` MPTCP CI
  2025-12-18 17:42 ` Matthieu Baerts
  12 siblings, 0 replies; 16+ messages in thread
From: MPTCP CI @ 2025-12-12  4:52 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

Hi Geliang,

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): Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_add_addr 🔴
- KVM Validation: debug (only selftest_mptcp_join): Critical: 2 Call Trace(s) - Critical: Unexpected stop of the VM ❌
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/20154532531

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/397a7ac03cb4
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1032489


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)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt
  2025-12-12  2:27 ` [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt Geliang Tang
@ 2025-12-12  7:23   ` GangYan
  2025-12-12  8:29     ` Geliang Tang
  0 siblings, 1 reply; 16+ messages in thread
From: GangYan @ 2025-12-12  7:23 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp, Geliang Tang, Gang Yan

Hi, Geliang:
> On Fri, Dec 12, 2025 at 10:27:18AM +0800, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> This patch adds MPTCP TLS setsockopt support. It allows setting the TCP_ULP
> option to 'tls' exclusively, and enables configuration of the TLS_TX and
> TLS_RX options at the SOL_TLS level.
> 
> This option cannot be set when the socket is in CLOSE or LISTEN state.
> 
> Co-developed-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Gang Yan <yangang@kylinos.cn>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  net/mptcp/sockopt.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
> index f3db4f2e8f81..52ff75702404 100644
> --- a/net/mptcp/sockopt.c
> +++ b/net/mptcp/sockopt.c
> @@ -12,6 +12,7 @@
>  #include <net/protocol.h>
>  #include <net/tcp.h>
>  #include <net/mptcp.h>
> +#include <net/tls.h>
>  #include "protocol.h"
>  
>  #define MIN_INFO_OPTLEN_SIZE		16
> @@ -567,6 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
>  		case TCP_FASTOPEN_CONNECT:
>  		case TCP_FASTOPEN_KEY:
>  		case TCP_FASTOPEN_NO_COOKIE:
> +		case TCP_ULP:
>  			return true;
>  		}
>  
> @@ -576,6 +578,13 @@ static bool mptcp_supported_sockopt(int level, int optname)
>  		 * TCP_REPAIR_WINDOW are not supported, better avoid this mess
>  		 */
>  	}
> +	if (level == SOL_TLS) {
> +		switch (optname) {
> +		case TLS_TX:
> +		case TLS_RX:
> +			return true;
> +		}
> +	}
>  	return false;
>  }
>  
> @@ -819,11 +828,18 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
>  				    sockptr_t optval, unsigned int optlen)
>  {
>  	struct sock *sk = (void *)msk;
> +	char ulp[4] = "";
>  	int ret, val;
>  
>  	switch (optname) {
>  	case TCP_ULP:
> -		return -EOPNOTSUPP;
> +		if (copy_from_user(ulp, optval.user, 4))
> +			return -EFAULT;
> +		if (strcmp(ulp, "tls\0"))
> +			return -EOPNOTSUPP;
> +		if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
> +			return -EINVAL;
Here should return -ENOTCONN

I'm running the tls selftest(tools/testing/selftest/net/tls.c), and the
'-EINVAL' will cause an error in 'non_established' test, it checks the
errno should be 'ENOTCONN'.

If we don't return here is also OK, because the
'tcp_setsockopt' can return too, but I think a state validation at the
MPTCP layer is necessary, and 'ENOTCONN' is more accurate for
'TCPF_CLOSE | TCPF_LISTEN'.

WDYT

Thanks
Gang
> +		return tcp_setsockopt(sk, SOL_TCP, optname, optval, optlen);
>  	case TCP_CONGESTION:
>  		return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen);
>  	case TCP_DEFER_ACCEPT:
> -- 
> 2.51.0
> 
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt
  2025-12-12  7:23   ` GangYan
@ 2025-12-12  8:29     ` Geliang Tang
  0 siblings, 0 replies; 16+ messages in thread
From: Geliang Tang @ 2025-12-12  8:29 UTC (permalink / raw)
  To: GangYan; +Cc: mptcp, Geliang Tang, Gang Yan

On Fri, 2025-12-12 at 15:23 +0800, GangYan wrote:
> Hi, Geliang:
> > On Fri, Dec 12, 2025 at 10:27:18AM +0800, Geliang Tang wrote:
> > From: Geliang Tang <tanggeliang@kylinos.cn>
> > 
> > This patch adds MPTCP TLS setsockopt support. It allows setting the
> > TCP_ULP
> > option to 'tls' exclusively, and enables configuration of the
> > TLS_TX and
> > TLS_RX options at the SOL_TLS level.
> > 
> > This option cannot be set when the socket is in CLOSE or LISTEN
> > state.
> > 
> > Co-developed-by: Gang Yan <yangang@kylinos.cn>
> > Signed-off-by: Gang Yan <yangang@kylinos.cn>
> > Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> > ---
> >  net/mptcp/sockopt.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
> > index f3db4f2e8f81..52ff75702404 100644
> > --- a/net/mptcp/sockopt.c
> > +++ b/net/mptcp/sockopt.c
> > @@ -12,6 +12,7 @@
> >  #include <net/protocol.h>
> >  #include <net/tcp.h>
> >  #include <net/mptcp.h>
> > +#include <net/tls.h>
> >  #include "protocol.h"
> >  
> >  #define MIN_INFO_OPTLEN_SIZE		16
> > @@ -567,6 +568,7 @@ static bool mptcp_supported_sockopt(int level,
> > int optname)
> >  		case TCP_FASTOPEN_CONNECT:
> >  		case TCP_FASTOPEN_KEY:
> >  		case TCP_FASTOPEN_NO_COOKIE:
> > +		case TCP_ULP:
> >  			return true;
> >  		}
> >  
> > @@ -576,6 +578,13 @@ static bool mptcp_supported_sockopt(int level,
> > int optname)
> >  		 * TCP_REPAIR_WINDOW are not supported, better
> > avoid this mess
> >  		 */
> >  	}
> > +	if (level == SOL_TLS) {
> > +		switch (optname) {
> > +		case TLS_TX:
> > +		case TLS_RX:
> > +			return true;
> > +		}
> > +	}
> >  	return false;
> >  }
> >  
> > @@ -819,11 +828,18 @@ static int mptcp_setsockopt_sol_tcp(struct
> > mptcp_sock *msk, int optname,
> >  				    sockptr_t optval, unsigned int
> > optlen)
> >  {
> >  	struct sock *sk = (void *)msk;
> > +	char ulp[4] = "";
> >  	int ret, val;
> >  
> >  	switch (optname) {
> >  	case TCP_ULP:
> > -		return -EOPNOTSUPP;
> > +		if (copy_from_user(ulp, optval.user, 4))
> > +			return -EFAULT;
> > +		if (strcmp(ulp, "tls\0"))
> > +			return -EOPNOTSUPP;
> > +		if ((1 << sk->sk_state) & (TCPF_CLOSE |
> > TCPF_LISTEN))
> > +			return -EINVAL;
> Here should return -ENOTCONN

Yes, you're right. I'll update it in v5.

Thanks,
-Geliang

> 
> I'm running the tls selftest(tools/testing/selftest/net/tls.c), and
> the
> '-EINVAL' will cause an error in 'non_established' test, it checks
> the
> errno should be 'ENOTCONN'.
> 
> If we don't return here is also OK, because the
> 'tcp_setsockopt' can return too, but I think a state validation at
> the
> MPTCP layer is necessary, and 'ENOTCONN' is more accurate for
> 'TCPF_CLOSE | TCPF_LISTEN'.
> 
> WDYT
> 
> Thanks
> Gang
> > +		return tcp_setsockopt(sk, SOL_TCP, optname,
> > optval, optlen);
> >  	case TCP_CONGESTION:
> >  		return mptcp_setsockopt_sol_tcp_congestion(msk,
> > optval, optlen);
> >  	case TCP_DEFER_ACCEPT:
> > -- 
> > 2.51.0
> > 
> > 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC mptcp-next v4 00/10] MPTCP KTLS support
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (10 preceding siblings ...)
  2025-12-12  4:52 ` [RFC mptcp-next v4 00/10] MPTCP KTLS support MPTCP CI
@ 2025-12-12  9:17 ` MPTCP CI
  2025-12-18 17:42 ` Matthieu Baerts
  12 siblings, 0 replies; 16+ messages in thread
From: MPTCP CI @ 2025-12-12  9:17 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

Hi Geliang,

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): Unstable: 1 failed test(s): selftest_simult_flows 🔴
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_add_addr 🔴
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/20154532531

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/397a7ac03cb4
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1032489


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)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [RFC mptcp-next v4 00/10] MPTCP KTLS support
  2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
                   ` (11 preceding siblings ...)
  2025-12-12  9:17 ` MPTCP CI
@ 2025-12-18 17:42 ` Matthieu Baerts
  12 siblings, 0 replies; 16+ messages in thread
From: Matthieu Baerts @ 2025-12-18 17:42 UTC (permalink / raw)
  To: Geliang Tang; +Cc: Geliang Tang, mptcp, Mat Martineau

Hi Geliang,

On 12/12/2025 03:27, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> v4:
>  - split "tls: add MPTCP protocol support" into smaller, more
>    focused patches.
>  - a new mptcp_inq helper has been implemented instead of directly
>    using mptcp_inq_hint to fix the issue mentioned in [1].
>  - add sk_is_msk helper.
>  - the 'expect' parameter will no longer be added to sock_test_tcpulp.
>    Instead, SOCK_TEST_TCPULP items causing the tests failure will be
>    directly removed.
>  - remove the "TCP KTLS" tests, keeping only the MPTCP-related ones.

Thank you for the new version.

We briefly looked at the series with Mat yesterday, and we think that
this series would be better accepted by the KTLS maintainers if function
pointers are used instead of all the sk_is_msk() you added in many
places. In other words, adding a new layer, where "struct tls_strparser"
(or another one?) would have new fields with function pointer to call
tcp_inq() or mptcp_inq(), etc. e.g. strp->ops->tcp_inq(strp->sk).

MPTCP would then only be checked once at the initialisation, not before
each call.

Notes: If adding an indirection is an issue for the KTLS maintainers,
INDIRECT_CALL_*(...) macros can be used. Also, it might be good to send
the RFC to KTLS people, but probably best to wait for the read-sock
series to be in net-next? But if you are not sure about the new
suggested way, I guess it is always possible to email KTLS maintainers,
and ask for their feedback.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2025-12-18 17:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-12  2:27 [RFC mptcp-next v4 00/10] MPTCP KTLS support Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 01/10] mptcp: add sk_is_msk helper Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 02/10] tls: switch to MPTCP_SKB_CB Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 03/10] tls: switch to mptcp_inq Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 04/10] tls: switch to mptcp_sendmsg_locked Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 05/10] tls: switch to mptcp_recv_skb Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 06/10] tls: switch to mptcp_read_done Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 07/10] mptcp: update ULP getsockopt Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt Geliang Tang
2025-12-12  7:23   ` GangYan
2025-12-12  8:29     ` Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 09/10] selftests: mptcp: connect: update sock_test_tcpulp Geliang Tang
2025-12-12  2:27 ` [RFC mptcp-next v4 10/10] selftests: mptcp: sockopt: implement MPTCP KTLS tests Geliang Tang
2025-12-12  4:52 ` [RFC mptcp-next v4 00/10] MPTCP KTLS support MPTCP CI
2025-12-12  9:17 ` MPTCP CI
2025-12-18 17:42 ` Matthieu Baerts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox