Skip to contentSkip to conversation

MPTCP KTLS support

RFC Superseded Geliang Tang 2 participants 18 messages Dec 22, 2025 – Jan 4

Subsystems (5)

v5 of 25 Superseded Latest is v25 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v5 cover MPTCP KTLS support

From: Geliang Tang <[email protected]>

v5:
- As suggested by Mat and Matt, this set introduces struct tls_prot_ops for TLS.
- Includes Gang Yan's patches to add MPTCP support to the TLS selftests.

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.
- Link: https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

[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/[email protected]/

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.

Gang Yan (2):
mptcp: fix the mptcp_check_readable
selftests: tls: add a '--mptcp' test mode

Geliang Tang (6):
tls: introduce struct tls_prot_ops
mptcp: implement tls_mptcp_ops
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                           |  12 ++
 include/net/tcp.h                             |   5 +
 include/net/tls.h                             |  44 ++++++++
 net/mptcp/protocol.c                          | 106 ++++++++++++++++--
 net/mptcp/sockopt.c                           |  31 ++++-
 net/tls/tls_device.c                          |   4 +-
 net/tls/tls_main.c                            |  14 ++-
 net/tls/tls_strp.c                            |  28 +++--
 net/tls/tls_sw.c                              |   5 +-
 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 ++++++
 tools/testing/selftests/net/tls.c             |  56 +++++++--
 14 files changed, 393 insertions(+), 45 deletions(-)
Signature · 1 line
2.51.0
author reviewer
#1 lore raw

RFC v5 1/8 tls: introduce struct tls_prot_ops

From: Geliang Tang <[email protected]>

To extend MPTCP support based on TCP TLS, a tls_prot_ops structure has been introduced for TLS, encapsulating both TCP-specific and MPTCP-specific helpers within this structure. A pointer to this structure, named 'ops', has been added to the tls_context. The places originally calling TLS-specific helpers have now been modified to indirectly invoke them via 'ops' pointer in the tls_context.

---
 include/net/tcp.h    |  5 +++++
 include/net/tls.h    | 42 ++++++++++++++++++++++++++++++++++++++++++
 net/tls/tls_device.c |  4 ++--
 net/tls/tls_main.c   | 12 +++++++++---
 net/tls/tls_strp.c   | 28 +++++++++++++++++++---------
 net/tls/tls_sw.c     |  5 +++--
 6 files changed, 80 insertions(+), 16 deletions(-)
include/net/tcp.h +5 -0
index f5f6119f7716..a0a2d4d63b15 100644
@@ -2953,4 +2953,9 @@ enum skb_drop_reason tcp_inbound_hash(struct sock *sk,
 		const void *saddr, const void *daddr,
 		int family, int dif, int sdif);
 
+static inline u32 tcp_get_seq(struct sk_buff *skb)
+{
+	return TCP_SKB_CB(skb)->seq;
+}
+
 #endif	/* _TCP_H */
include/net/tls.h +42 -0

54 lines not on this page · raw message

net/tls/tls_device.c +2 -2
index 82ea407e520a..c03bd4c41bc8 100644
@@ -805,7 +805,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq)
 		/* head of next rec is already in, note that the sock_inq will
 		 * include the currently parsed message when called from parser
 		 */
-		sock_data = tcp_inq(sk);
+		sock_data = tls_ctx->ops->inq(sk);
 		if (sock_data > rcd_len) {
 			trace_tls_device_rx_resync_nh_delay(sk, sock_data,
 							    rcd_len);
@@ -864,7 +864,7 @@ static void tls_device_core_ctrl_rx_resync(struct tls_context *tls_ctx,
 	rxm = strp_msg(skb);
 
 	/* head of next rec is already in, parser will sync for us */
-	if (tcp_inq(sk) > rxm->full_len) {
+	if (tls_ctx->ops->inq(sk) > rxm->full_len) {
 		trace_tls_device_rx_resync_nh_schedule(sk);
 		ctx->resync_nh_do_now = 1;
 	} else {
net/tls/tls_main.c +9 -3
index 56ce0bc8317b..20f7eb438771 100644
@@ -194,7 +194,7 @@ 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 = ctx->ops->sendmsg_locked(sk, &msg, size);
 
 		if (ret != size) {
 			if (ret > 0) {
@@ -409,14 +409,14 @@ static __poll_t tls_sk_poll(struct file *file, struct socket *sock,
 	u8 shutdown;
 	int state;
 
-	mask = tcp_poll(file, sock, wait);
+	tls_ctx = tls_get_ctx(sk);
+	mask = tls_ctx->ops->poll(file, sock, wait);
 
 	state = inet_sk_state_load(sk);
 	shutdown = READ_ONCE(sk->sk_shutdown);
 	if (unlikely(state != TCP_ESTABLISHED || shutdown & RCV_SHUTDOWN))
 		return mask;
 
-	tls_ctx = tls_get_ctx(sk);
 	ctx = tls_sw_ctx_rx(tls_ctx);
 	psock = sk_psock_get(sk);
 
@@ -760,6 +760,12 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 		ctx->rx_conf = conf;
 	update_sk_prot(sk, ctx);
 
+	if (sk_is_tcp(sk))
+		ctx->ops = &tls_tcp_ops;
+
+	if (!tls_validate_prot_ops(ctx->ops))
+		return -EINVAL;
+
 	if (update)
 		return 0;
 
net/tls/tls_strp.c +19 -9
index 98e12f0ff57e..3e79a8cfaadf 100644
@@ -120,6 +120,7 @@ struct sk_buff *tls_strp_msg_detach(struct tls_sw_context_rx *ctx)
 int tls_strp_msg_cow(struct tls_sw_context_rx *ctx)
 {
 	struct tls_strparser *strp = &ctx->strp;
+	struct tls_context *tls_ctx;
 	struct sk_buff *skb;
 
 	if (strp->copy_mode)
@@ -132,7 +133,8 @@ int tls_strp_msg_cow(struct tls_sw_context_rx *ctx)
 	tls_strp_anchor_free(strp);
 	strp->anchor = skb;
 
-	tcp_read_done(strp->sk, strp->stm.full_len);
+	tls_ctx = tls_get_ctx(strp->sk);
+	tls_ctx->ops->read_done(strp->sk, strp->stm.full_len);
 	strp->copy_mode = 1;
 
 	return 0;
@@ -376,6 +378,7 @@ static int tls_strp_copyin(read_descriptor_t *desc, struct sk_buff *in_skb,
 
 static int tls_strp_read_copyin(struct tls_strparser *strp)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	read_descriptor_t desc;
 
 	desc.arg.data = strp;
@@ -383,13 +386,14 @@ static int tls_strp_read_copyin(struct tls_strparser *strp)
 	desc.count = 1; /* give more than one skb per call */
 
 	/* sk should be locked here, so okay to do read_sock */
-	tcp_read_sock(strp->sk, &desc, tls_strp_copyin);
+	ctx->ops->read_sock(strp->sk, &desc, tls_strp_copyin);
 
 	return desc.error;
 }
 
 static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	struct skb_shared_info *shinfo;
 	struct page *page;
 	int need_spc, len;
@@ -398,7 +402,7 @@ static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort)
 	 * to read the data out. Otherwise the connection will stall.
 	 * Without pressure threshold of INT_MAX will never be ready.
 	 */
-	if (likely(qshort && !tcp_epollin_ready(strp->sk, INT_MAX)))
+	if (likely(qshort && !ctx->ops->epollin_ready(strp->sk, INT_MAX)))
 		return 0;
 
 	shinfo = skb_shinfo(strp->anchor);
@@ -434,12 +438,13 @@ static int tls_strp_read_copy(struct tls_strparser *strp, bool qshort)
 static bool tls_strp_check_queue_ok(struct tls_strparser *strp)
 {
 	unsigned int len = strp->stm.offset + strp->stm.full_len;
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	struct sk_buff *first, *skb;
 	u32 seq;
 
 	first = skb_shinfo(strp->anchor)->frag_list;
 	skb = first;
-	seq = TCP_SKB_CB(first)->seq;
+	seq = ctx->ops->get_seq(first);
 
 	/* Make sure there's no duplicate data in the queue,
 	 * and the decrypted status matches.
@@ -449,7 +454,7 @@ 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 (ctx->ops->get_seq(skb) != seq)
 			return false;
 		if (skb_cmp_decrypted(first, skb))
 			return false;
@@ -460,11 +465,12 @@ static bool tls_strp_check_queue_ok(struct tls_strparser *strp)
 
 static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	struct tcp_sock *tp = tcp_sk(strp->sk);
 	struct sk_buff *first;
 	u32 offset;
 
-	first = tcp_recv_skb(strp->sk, tp->copied_seq, &offset);
+	first = ctx->ops->recv_skb(strp->sk, tp->copied_seq, &offset);
 	if (WARN_ON_ONCE(!first))
 		return;
 
@@ -483,6 +489,7 @@ static void tls_strp_load_anchor_with_queue(struct tls_strparser *strp, int len)
 
 bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	struct strp_msg *rxm;
 	struct tls_msg *tlm;
 
@@ -490,7 +497,7 @@ 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(ctx->ops->inq(strp->sk) < strp->stm.full_len)) {
 			WRITE_ONCE(strp->msg_ready, 0);
 			memset(&strp->stm, 0, sizeof(strp->stm));
 			return false;
@@ -511,9 +518,10 @@ bool tls_strp_msg_load(struct tls_strparser *strp, bool force_refresh)
 /* Called with lock held on lower socket */
 static int tls_strp_read_sock(struct tls_strparser *strp)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
 	int sz, inq;
 
-	inq = tcp_inq(strp->sk);
+	inq = ctx->ops->inq(strp->sk);
 	if (inq < 1)
 		return 0;
 
@@ -583,10 +591,12 @@ static void tls_strp_work(struct work_struct *w)
 
 void tls_strp_msg_done(struct tls_strparser *strp)
 {
+	struct tls_context *ctx = tls_get_ctx(strp->sk);
+
 	WARN_ON(!strp->stm.full_len);
 
 	if (likely(!strp->copy_mode))
-		tcp_read_done(strp->sk, strp->stm.full_len);
+		ctx->ops->read_done(strp->sk, strp->stm.full_len);
 	else
 		tls_strp_flush_anchor_copy(strp);
 
net/tls/tls_sw.c +3 -2
index 9937d4c810f2..a36f23aae603 100644
@@ -1952,13 +1952,14 @@ tls_read_flush_backlog(struct sock *sk, struct tls_prot_info *prot,
 		       size_t len_left, size_t decrypted, ssize_t done,
 		       size_t *flushed_at)
 {
+	struct tls_context *tls_ctx = tls_get_ctx(sk);
 	size_t max_rec;
 
 	if (len_left <= decrypted)
 		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 && tls_ctx->ops->inq(sk) > max_rec)
 		return false;
 
 	*flushed_at = done;
@@ -2489,7 +2490,7 @@ 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);
+				     tls_ctx->ops->get_seq(skb) + strp->stm.offset);
 	return data_len + TLS_HEADER_SIZE;
 
 read_failure:
Signature · 1 line
2.51.0
maintainer
#2 lore raw

Re: [RFC mptcp-next v5 1/8] tls: introduce struct tls_prot_ops

Hi Geliang,

Quoted 8 lines · Geliang Tang

From: Geliang Tang <[email protected]>

To extend MPTCP support based on TCP TLS, a tls_prot_ops structure has been introduced for TLS, encapsulating both TCP-specific and MPTCP-specific helpers within this structure. A pointer to this structure, named 'ops', has been added to the tls_context. The places originally calling TLS-specific helpers have now been modified to indirectly invoke them via 'ops' pointer in the tls_context.

Thank you for this new version, it looks better!

(...)

Quoted 4 lines
net/tls/tls_main.c +0 -0
index 56ce0bc8317b..20f7eb438771 100644

(...)

net/tls/tls_main.c static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, · line 763

Quoted 5 lines
net/tls/tls_main.c +1 -0
@@ -760,6 +760,12 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 		ctx->rx_conf = conf;
 	update_sk_prot(sk, ctx);
 
+	if (sk_is_tcp(sk))

I wonder if it would not be better to register each ops in an array / list, and add the protocol number in the ops. Then here, use the right ops corresponding to the sk->sk_protocol.

(I don't think you need 'sk_is_tcp()' here, I guess this helper can only be called for a TCP connection. When MPTCP is added, only the protocol will differ. Then 'sk_is_msk(sk)' is probably not needed)

net/tls/tls_main.c static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, · line 764

Quoted 1 line
net/tls/tls_main.c +1 -0
+		ctx->ops = &tls_tcp_ops;

I guess you should handle the case where ctx->ops is not set.

net/tls/tls_main.c static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, · line 766

Quoted 2 lines
net/tls/tls_main.c +2 -0
+
+	if (!tls_validate_prot_ops(ctx->ops))

I don't think this validation should be done for each connection. If required, it should be done when registering the ops.

net/tls/tls_main.c static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, · line 767

Quoted 1 line
net/tls/tls_main.c +1 -0
+		return -EINVAL;

I think this block should come before "update_sk_prot()" (or you need to cancel the update).

net/tls/tls_main.c static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval, · line 770

Quoted 3 lines
net/tls/tls_main.c +1 -0
+
 	if (update)
 		return 0;

(...)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#3 lore raw

RFC v5 2/8 mptcp: implement tls_mptcp_ops

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

This patch implements the MPTCP-specific struct tls_prot_ops, named 'tls_mptcp_ops'.

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().

A direct call to mptcp_read_sock() could lead to a deadlock, as 'read_sock' interface of TLS might be invoked from within a softirq context. In such a scenario, lock_sock_fast(), which is called by mptcp_rcv_space_adjust() or mptcp_cleanup_rbuf(), would cause the deadlocks. To resolve it, use in_softirq() to determine whether to call mptcp_read_sock() or mptcp_read_sock_noack().

Also 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.

In do_tls_setsockopt_conf, the sk_is_mptcp helper is used to determine the socket type, selecting either 'tls_mptcp_ops' or 'tls_tcp_ops' accordingly.

---
 include/net/mptcp.h  | 12 ++++++
 include/net/tls.h    |  2 +
 net/mptcp/protocol.c | 99 +++++++++++++++++++++++++++++++++++++++++---
 net/tls/tls_main.c   |  2 +
 4 files changed, 109 insertions(+), 6 deletions(-)
include/net/mptcp.h +12 -0
index 4cf59e83c1c5..82660374859a 100644
@@ -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)
include/net/tls.h +2 -0
index 985ac326d59c..71c0399e6a43 100644
@@ -261,6 +261,8 @@ static const struct tls_prot_ops tls_tcp_ops = {
 	.epollin_ready	= tcp_epollin_ready,
 };
 
+extern const struct tls_prot_ops tls_mptcp_ops;
+
 struct tls_context {
 	/* read-only cache line */
 	struct tls_prot_info prot_info;
net/mptcp/protocol.c +93 -6

149 lines not on this page · raw message

net/tls/tls_main.c +2 -0
index 20f7eb438771..7c69bef4f51d 100644
@@ -762,6 +762,8 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 
 	if (sk_is_tcp(sk))
 		ctx->ops = &tls_tcp_ops;
+	else if (sk_is_msk(sk))
+		ctx->ops = &tls_mptcp_ops;
 
 	if (!tls_validate_prot_ops(ctx->ops))
 		return -EINVAL;
Signature · 1 line
2.51.0
author reviewer
#4 lore raw

RFC v5 3/8 mptcp: update ULP getsockopt

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 net/mptcp/sockopt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
net/mptcp/sockopt.c +13 -0
index de90a2897d2d..4f805b99742e 100644
@@ -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,8 @@ 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:
Signature · 1 line
2.51.0
maintainer
#5 lore raw

Re: [RFC mptcp-next v5 3/8] mptcp: update ULP getsockopt

Quoted 18 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 net/mptcp/sockopt.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
net/mptcp/sockopt.c +0 -0
index de90a2897d2d..4f805b99742e 100644

net/mptcp/sockopt.c static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval, · line 1402

Quoted 10 lines
net/mptcp/sockopt.c +7 -0
@@ -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);

Mmh, even if I see that I can work, it doesn't sound safe:
do_tcp_getsockopt() will expect the sk to be a TCP sk. I think it is better to avoid that. Instead, maybe sharing code between TCP and MPTCP to do the same?

(also the helper name is confusing: this case is particular and works for this particular SOL_TCP+TCP_ULP case.)

Quoted 8 lines
net/mptcp/sockopt.c +4 -0
+	release_sock(sk);
+	return ret;
+}
+
 static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 				    char __user *optval, int __user *optlen)
 {

net/mptcp/sockopt.c static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 1418

Quoted 8 lines
net/mptcp/sockopt.c +2 -0
@@ -1400,6 +1411,8 @@ 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:

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#6 lore raw

RFC v5 4/8 mptcp: enable TLS setsockopt

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 net/mptcp/sockopt.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
net/mptcp/sockopt.c +17 -1
index 4f805b99742e..62e3f18ba46e 100644
@@ -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 -ENOTCONN;
+		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:
Signature · 1 line
2.51.0
maintainer
#7 lore raw

Re: [RFC mptcp-next v5 4/8] mptcp: enable TLS setsockopt

Hi Geliang,

Quoted 7 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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.

(...)

Quoted 6 lines
net/mptcp/sockopt.c +1 -0
@@ -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;

net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 841

Quoted 10 lines
net/mptcp/sockopt.c +6 -1
 
 	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 -ENOTCONN;

This is specific to TLS, maybe better to move that to a new setsockopt ULP helper?

net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 842

Quoted 1 line
net/mptcp/sockopt.c +1 -0
+		return tcp_setsockopt(sk, SOL_TCP, optname, optval, optlen);

Same as in the previous patch, better not to call ...

tcp_[gs]etsockopt(msk, SOL_TCP, ...)

... directly.

net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 845

Quoted 3 lines
net/mptcp/sockopt.c +0 -0
 	case TCP_CONGESTION:
 		return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen);
 	case TCP_DEFER_ACCEPT:

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#8 lore raw

RFC v5 5/8 selftests: mptcp: connect: update sock_test_tcpulp

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 .../selftests/net/mptcp/mptcp_connect.c       | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +13 -7
index b82df82e0594..e5c394ea4e11 100644
@@ -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)
Signature · 1 line
2.51.0
maintainer
#9 lore raw

Re: [RFC mptcp-next v5 5/8] selftests: mptcp: connect: update sock_test_tcpulp

Hi Geliang,

Quoted 20 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 .../selftests/net/mptcp/mptcp_connect.c       | 20 ++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_connect.c +0 -0
index b82df82e0594..e5c394ea4e11 100644

tools/testing/selftests/net/mptcp/mptcp_connect.c static void set_mptfo(int fd, int pf) · line 275

Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +7 -0
@@ -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)

Would it be OK to check SO_PROTOCOL instead? TCP_IS_MPTCP is not available on older kernel versions.

Quoted 18 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +6 -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)

tools/testing/selftests/net/mptcp/mptcp_connect.c static int sock_connect_mptcp(const char * const remoteaddr, · line 428

Quoted 5 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +0 -2
@@ -424,8 +436,6 @@ static int sock_connect_mptcp(const char * const remoteaddr,
 	}
 
 	freeaddrinfo(addr);
-	if (sock != -1)
-		SOCK_TEST_TCPULP(sock, proto);

When looking at f730b65c9d85 ("selftests: mptcp: try to set mptcp ulp mode in different sk states"), it looks like this test is useful to avoid regressions. We should not remove them then.

With KTLS being implemented, I guess "tls" should no longer be used, but we should continue to call SOCK_TEST_TCPULP(). Maybe another ULP name can be set instead of "tls"?

Quoted 13 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +0 -2
 	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 {

tools/testing/selftests/net/mptcp/mptcp_connect.c int main_loop(void) · line 1384

Quoted 8 lines
tools/testing/selftests/net/mptcp/mptcp_connect.c +0 -2
@@ -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)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#10 lore raw

RFC v5 6/8 selftests: mptcp: sockopt: implement MPTCP KTLS tests

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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.

---
 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(-)
tools/testing/selftests/net/mptcp/config +1 -0
index 59051ee2a986..18bd29ac5b24 100644
@@ -34,3 +34,4 @@ CONFIG_NFT_SOCKET=m
 CONFIG_NFT_TPROXY=m
 CONFIG_SYN_COOKIES=y
 CONFIG_VETH=y
+CONFIG_TLS=y
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +74 -2

138 lines not on this page · raw message

tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +36 -0
index ab8bce06b262..23b483241f01 100755
@@ -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
Signature · 1 line
2.51.0
maintainer
#11 lore raw

Re: [RFC mptcp-next v5 6/8] selftests: mptcp: sockopt: implement MPTCP KTLS tests

Hi Geliang,

Quoted 10 lines · Geliang Tang

From: Geliang Tang <[email protected]>

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.

When quickly looking at the code and the commit message, it is not clear what this does: does it only set the TLS socket options, and that's it? If yes, that's not enough, and it might give confusing results if the new feature is not "properly" tested.

I think a "proper" test would involve transferring data with multiple subflows (with data going through the different subflows and correctly processed). That's more complex to put in place, but this looks required.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#12 lore raw

RFC v5 7/8 mptcp: fix the mptcp_check_readable

In reply to Geliang Tang

From: Gang Yan <[email protected]>

'mptcp_check_readble' is corresponding to the 'tcp_stream_is_readable', but the later one will call the 'sk_is_readble' -> 'prot->sock_is_readable(sk)' -> 'tls_sw_sock_is_readable'.

If not apply this patch, it will cause an error in 'poll_wait_split' test when running tls_test in mptcp mode.

---
 net/mptcp/protocol.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +5 -2
index bdf53e4b3f7e..8363d89d3a13 100644
@@ -3260,7 +3260,9 @@ void __mptcp_unaccepted_force_close(struct sock *sk)
 
 static __poll_t mptcp_check_readable(struct sock *sk)
 {
-	return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
+	if (mptcp_epollin_ready(sk))
+		return true;
+	return sk_is_readable(sk);
 }
 
 static void mptcp_check_listen_stop(struct sock *sk)
@@ -4322,7 +4324,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 		mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
 
 	if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
-		mask |= mptcp_check_readable(sk);
+		if (mptcp_check_readable(sk))
+			mask |= EPOLLIN | EPOLLRDNORM;
 		if (shutdown & SEND_SHUTDOWN)
 			mask |= EPOLLOUT | EPOLLWRNORM;
 		else
Signature · 1 line
2.51.0
maintainer
#13 lore raw

Re: [RFC mptcp-next v5 7/8] mptcp: fix the mptcp_check_readable

Hi Geliang, Gang,

Quoted 8 lines · Geliang Tang

From: Gang Yan <[email protected]>

'mptcp_check_readble' is corresponding to the 'tcp_stream_is_readable', but the later one will call the 'sk_is_readble' -> 'prot->sock_is_readable(sk)' -> 'tls_sw_sock_is_readable'.

If not apply this patch, it will cause an error in 'poll_wait_split' test when running tls_test in mptcp mode.

Which error?

It might be better to move this before patch 2 and mention that this is to aligned with TCP, and will be used in the case of KTLS, because 'prot' will be modified, tls_sw_sock_is_readable is expected to be called from prot->sock_is_readable(), etc.

net/mptcp/protocol.c void __mptcp_unaccepted_force_close(struct sock *sk) · line 3261

Quoted 13 lines
---
 net/mptcp/protocol.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +0 -0
index bdf53e4b3f7e..8363d89d3a13 100644
@@ -3260,7 +3260,9 @@ void __mptcp_unaccepted_force_close(struct sock *sk)
 
 static __poll_t mptcp_check_readable(struct sock *sk)

Might be good to add a comment to say that it is similar to tcp_stream_is_readable()

While at it, maybe rename it to mptcp_stream_is_readable() so it is aligned with TCP?

Quoted 9 lines
net/mptcp/protocol.c +3 -1
 {
-	return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
+	if (mptcp_epollin_ready(sk))
+		return true;
+	return sk_is_readable(sk);
 }
 
 static void mptcp_check_listen_stop(struct sock *sk)

net/mptcp/protocol.c static __poll_t mptcp_poll(struct file *file, struct socket *sock, · line 4331

Quoted 9 lines
net/mptcp/protocol.c +2 -1
@@ -4322,7 +4324,8 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 		mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
 
 	if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
-		mask |= mptcp_check_readable(sk);
+		if (mptcp_check_readable(sk))
+			mask |= EPOLLIN | EPOLLRDNORM;
 		if (shutdown & SEND_SHUTDOWN)
 			mask |= EPOLLOUT | EPOLLWRNORM;
 		else

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#14 lore raw

RFC v5 8/8 selftests: tls: add a '--mptcp' test mode

In reply to Geliang Tang

From: Gang Yan <[email protected]>

Add a command-line parameter --mptcp that allows the TLS test program to switch between using MPTCP and standard TCP. When the --mptcp flag is provided, the test suite will utilize MPTCP connections; otherwise, it defaults to standard TCP.

---
 tools/testing/selftests/net/tls.c | 56 +++++++++++++++++++++++++------
 1 file changed, 45 insertions(+), 11 deletions(-)
tools/testing/selftests/net/tls.c +45 -11
index a4d16a460fbe..2570722d01cb 100644
@@ -26,7 +26,12 @@
 #define TLS_PAYLOAD_MAX_LEN 16384
 #define SOL_TLS 282
 
+#ifndef IPPROTO_MPTCP
+#define IPPROTO_MPTCP 262
+#endif
+
 static int fips_enabled;
+static int protocol;
 
 struct tls_crypto_info_keys {
 	union {
@@ -122,8 +127,8 @@ static void ulp_sock_pair(struct __test_metadata *_metadata,
 	addr.sin_addr.s_addr = htonl(INADDR_ANY);
 	addr.sin_port = 0;
 
-	*fd = socket(AF_INET, SOCK_STREAM, 0);
-	sfd = socket(AF_INET, SOCK_STREAM, 0);
+	*fd = socket(AF_INET, SOCK_STREAM, protocol);
+	sfd = socket(AF_INET, SOCK_STREAM, protocol);
 
 	ret = bind(sfd, &addr, sizeof(addr));
 	ASSERT_EQ(ret, 0);
@@ -3013,8 +3018,8 @@ TEST(non_established) {
 	addr.sin_addr.s_addr = htonl(INADDR_ANY);
 	addr.sin_port = 0;
 
-	fd = socket(AF_INET, SOCK_STREAM, 0);
-	sfd = socket(AF_INET, SOCK_STREAM, 0);
+	fd = socket(AF_INET, SOCK_STREAM, protocol);
+	sfd = socket(AF_INET, SOCK_STREAM, protocol);
 
 	ret = bind(sfd, &addr, sizeof(addr));
 	ASSERT_EQ(ret, 0);
@@ -3137,8 +3142,8 @@ TEST(tls_v6ops) {
 	addr.sin6_addr = in6addr_any;
 	addr.sin6_port = 0;
 
-	fd = socket(AF_INET6, SOCK_STREAM, 0);
-	sfd = socket(AF_INET6, SOCK_STREAM, 0);
+	fd = socket(AF_INET6, SOCK_STREAM, protocol);
+	sfd = socket(AF_INET6, SOCK_STREAM, protocol);
 
 	ret = bind(sfd, &addr, sizeof(addr));
 	ASSERT_EQ(ret, 0);
@@ -3196,8 +3201,8 @@ TEST(prequeue) {
 	addr.sin_addr.s_addr = htonl(INADDR_ANY);
 	addr.sin_port = 0;
 
-	fd = socket(AF_INET, SOCK_STREAM, 0);
-	sfd = socket(AF_INET, SOCK_STREAM, 0);
+	fd = socket(AF_INET, SOCK_STREAM, protocol);
+	sfd = socket(AF_INET, SOCK_STREAM, protocol);
 
 	ASSERT_EQ(bind(sfd, &addr, sizeof(addr)), 0);
 	ASSERT_EQ(listen(sfd, 10), 0);
@@ -3242,8 +3247,8 @@ TEST(data_steal) {
 	addr.sin_addr.s_addr = htonl(INADDR_ANY);
 	addr.sin_port = 0;
 
-	fd = socket(AF_INET, SOCK_STREAM, 0);
-	sfd = socket(AF_INET, SOCK_STREAM, 0);
+	fd = socket(AF_INET, SOCK_STREAM, protocol);
+	sfd = socket(AF_INET, SOCK_STREAM, protocol);
 
 	ASSERT_EQ(bind(sfd, &addr, sizeof(addr)), 0);
 	ASSERT_EQ(listen(sfd, 10), 0);
@@ -3299,4 +3304,33 @@ static void __attribute__((constructor)) fips_check(void) {
 	}
 }
 
-TEST_HARNESS_MAIN
+static void print_usage(const char* program_name) {
+	printf("Usage: ./mptcp_tls [--mptcp]\n");
+	printf("\t--mptcp  using MPTCP instead of TCP\n\n");
+}
+
+static int parse_arguments(int argc, char** argv) {
+	for (int i = 1; i < argc; i++) {
+		if (!strcmp(argv[i], "-h")) {
+			print_usage(argv[0]);
+			return i;
+		}
+		if (!strcmp(argv[i], "--mptcp")) {
+			protocol = IPPROTO_MPTCP;
+			return i;
+		}
+	}
+	return 0;
+}
+
+int main(int argc, char **argv) {
+	int index = parse_arguments(argc, argv);
+
+	if (protocol == IPPROTO_MPTCP) {
+		for (int i = index; i < argc; i++)
+			argv[i] = argv[i + 1];
+		argc--;
+	}
+
+	return test_harness_run(argc, argv);
+}
Signature · 1 line
2.51.0
maintainer
#15 lore raw

Re: [RFC mptcp-next v5 8/8] selftests: tls: add a '--mptcp' test mode

Hi Gang,

Quoted 6 lines · Geliang Tang

From: Gang Yan <[email protected]>

Add a command-line parameter --mptcp that allows the TLS test program to switch between using MPTCP and standard TCP. When the --mptcp flag is provided, the test suite will utilize MPTCP connections; otherwise, it defaults to standard TCP.

Adding a command-line parameter is not enough: this test will only be checked when launched manually. In other words, CI will not check that.

Instead, all tests should be called in the two modes by default. If you do that, the protocol number/name should appear in the subtest names:
for the CIs *not* to have each test appearing twice.

Also, for MPTCP case, it is important to have a test somewhere using multiple subflows, with data going through multiple subflows.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#16 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 6 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v5:
- As suggested by Mat and Matt, this set introduces struct tls_prot_ops for TLS.
- Includes Gang Yan's patches to add MPTCP support to the TLS selftests.

Thank you for this new version!

I just did a very quick reviews. Please see my comments in the individual patches.

Also, did you check the behaviour with MPTCP and multiple subflows when KTLS is used with HW supporting TLS offload? (TLS_HW mode)

https://docs.kernel.org/networking/tls-offload.html

I didn't check how it works, but if the NIC needs to have a continuous flow to work, it will not work with MPTCP if only a part of the traffic is handled by a NIC.

(Also, in the selftests, I don't see any tests using TLS_SW with MPTCP and multiple subflows, that's important!)

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#17 lore raw

Hi Matt,

Thanks for your review and happy new year.

Quoted 12 lines · Matthieu Baerts

Hi Geliang,

Quoted 8 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v5:
 - As suggested by Mat and Matt, this set introduces struct tls_prot_ops
   for TLS.
 - Includes Gang Yan's patches to add MPTCP support to the TLS selftests.

Quoted 4 lines

Thank you for this new version!

I just did a very quick reviews. Please see my comments in the individual patches.

I just sent a v6, addressing your comments.

Quoted 5 lines

Also, did you check the behaviour with MPTCP and multiple subflows when
KTLS is used with HW supporting TLS offload? (TLS_HW mode)

Quoted 7 lines

  https://docs.kernel.org/networking/tls-offload.html

I didn't check how it works, but if the NIC needs to have a continuous
flow to work, it will not work with MPTCP if only a part of the traffic
is handled by a NIC.

I haven't considered TLS_HW mode yet. I think at this stage we can disable TLS_HW mode for MPTCP TLS. I'll spend time working on it in the future.

Quoted 4 lines

(Also, in the selftests, I don't see any tests using TLS_SW with MPTCP
and multiple subflows, that's important!)

New tests for multiple subflows are added in v6.

Thanks,
-Geliang

Quoted 3 lines

Cheers,
Matt