MPTCP KTLS support
Subsystems (4)
Geliang Tang
reviewerv4 cover MPTCP KTLS support
From: Geliang Tang <[email protected]>
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.
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.
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(-)
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 1/10 mptcp: add sk_is_msk helper
From: Geliang Tang <[email protected]>
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.
--- include/net/mptcp.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/net/mptcp.h +12 -0
@@ -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)
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 2/10 tls: switch to MPTCP_SKB_CB
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- 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(-)
include/net/mptcp.h +10 -0
@@ -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 );
net/mptcp/protocol.h +0 -10
@@ -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 ;
net/tls/tls_strp.c +6 -2
@@ -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;
net/tls/tls_sw.c +3 -1
@@ -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:
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 3/10 tls: switch to mptcp_inq
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- 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(-)
include/net/mptcp.h +7 -0
@@ -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 requesstatic 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 )
net/mptcp/protocol.c +11 -1
@@ -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 ;
net/tls/tls_strp.c +6 -2
@@ -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 ;
net/tls/tls_sw.c +3 -1
@@ -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;
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 4/10 tls: switch to mptcp_sendmsg_locked
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- include/net/mptcp.h | 8 ++++++++ net/mptcp/protocol.c | 16 ++++++++++++---- net/tls/tls_main.c | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-)
include/net/mptcp.h +8 -0
@@ -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 )
net/mptcp/protocol.c +12 -4
@@ -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)
net/tls/tls_main.c +3 -1
@@ -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 ) {
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 5/10 tls: switch to mptcp_recv_skb
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- include/net/mptcp.h | 7 +++++++ net/mptcp/protocol.c | 2 +- net/tls/tls_strp.c | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-)
include/net/mptcp.h +7 -0
@@ -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 )
net/mptcp/protocol.c +1 -1
@@ -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;
net/tls/tls_strp.c +3 -1
@@ -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 ;
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 6/10 tls: switch to mptcp_read_done
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
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.
--- include/net/mptcp.h | 4 ++++ net/mptcp/protocol.c | 36 ++++++++++++++++++++++++++++++++++++ net/tls/tls_strp.c | 4 ++++ 3 files changed, 44 insertions(+)
include/net/mptcp.h +4 -0
@@ -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 )
net/mptcp/protocol.c +36 -0
@@ -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 ,
net/tls/tls_strp.c +4 -0
@@ -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);
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 7/10 mptcp: update ULP getsockopt
In reply to Geliang TangFrom: 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/mptcp/sockopt.c +12 -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); +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 :
Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 8/10 mptcp: enable TLS setsockopt
In reply to Geliang TangFrom: 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
@@ -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 :
Signature · 1 line
2.51.0
Re: [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt
Hi, Geliang:
Quoted 56 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds MPTCP TLS setsockopt support. It allows setting the
TCP_ULPoption to 'tls' exclusively, and enables configuration of theTLS_TXandTLS_RXoptions at theSOL_TLSlevel.This option cannot be set when the socket is in CLOSE or LISTEN state.
Co-developed-by Gang Yan <[email protected]>Signed-off-by Gang Yan <[email protected]>Signed-off-by Geliang Tang <[email protected]>--- net/mptcp/sockopt.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)net/mptcp/sockopt.c +10
-0@@ -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;
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
-1switch (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
Quoted 8 lines
net/mptcp/sockopt.c +1
-0+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
Geliang Tang
reviewerRe: [RFC mptcp-next v4 08/10] mptcp: enable TLS setsockopt
Quoted 69 lines · GangYan
Hi, Geliang:
Quoted 68 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 theTLS_TXandTLS_RXoptions at theSOL_TLSlevel.This option cannot be set when the socket is in CLOSE or LISTEN state.
Co-developed-by Gang Yan <[email protected]>Signed-off-by Gang Yan <[email protected]>Signed-off-by Geliang Tang <[email protected]>---
net/mptcp/sockopt.c | 18 +++++++++++++++++-1 file changed, 17 insertions(+), 1 deletion(-)net/mptcp/sockopt.c +1
-0@@ -12,6 +12,7 @@ #include <net/protocol.h> #include <net/tcp.h> #include <net/mptcp.h> +#include <net/tls.h> #include "protocol.h"
#defineMIN_INFO_OPTLEN_SIZE16net/mptcp/sockopt.c +0
-0@@ -567,6 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname)case
TCP_FASTOPEN_CONNECT:
caseTCP_FASTOPEN_KEY:
caseTCP_FASTOPEN_NO_COOKIE:net/mptcp/sockopt.c +1
-0+case TCP_ULP :return true;
}net/mptcp/sockopt.c +0
-0@@ -576,6 +578,13 @@ static bool mptcp_supported_sockopt(int level, int optname) * TCP_REPAIR_WINDOW are not supported, betteravoid this mess
*/
}net/mptcp/sockopt.c +7
-0+if (level ==SOL_TLS ) { +switch (optname) { +case TLS_TX : +case TLS_RX : +return true; + } + }return false;
}net/mptcp/sockopt.c +0
-0@@ -819,11 +828,18 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
sockptr_toptval, unsigned int optlen)
{
struct sock *sk = (void *)msk;net/mptcp/sockopt.c +1
-0+char ulp[4 ] ="" ;int ret, val;
switch (optname) {
caseTCP_ULP:net/mptcp/sockopt.c +0
-1-return -EOPNOTSUPP ;
Quoted 8 lines
net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 841
Quoted 7 lines
net/mptcp/sockopt.c +5
-0+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))net/mptcp/sockopt.c +1
-0+return -EINVAL ;Here should return
-ENOTCONN
Yes, you're right. I'll update it in v5.
Thanks,
-Geliang
Quoted 27 lines
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
GangQuoted 10 lines
net/mptcp/sockopt.c +1
-0+ return tcp_setsockopt(sk, SOL_TCP, optname,optval, optlen);
caseTCP_CONGESTION:
returnmptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen);
caseTCP_DEFER_ACCEPT:Signature · 1 line
2.51.0
Geliang Tang
reviewerRFC v4 9/10 selftests: mptcp: connect: update sock_test_tcpulp
In reply to Geliang TangFrom: 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
@@ -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
Geliang Tang
reviewerRFC v4 10/10 selftests: mptcp: sockopt: implement MPTCP KTLS tests
In reply to Geliang TangFrom: 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
@@ -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
@@ -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
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-normalFor 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)
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-normalFor 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)
Matthieu Baerts
maintainerHi Geliang,
Quoted 12 lines · Geliang Tang
From: Geliang Tang <[email protected]>
v4:
- split "tls: add MPTCP protocol support" into smaller, more focused patches.
- a newmptcp_inqhelper has been implemented instead of directly usingmptcp_inq_hintto fix the issue mentioned in [1].
- addsk_is_mskhelper.
- the 'expect' parameter will no longer be added tosock_test_tcpulp. Instead,SOCK_TEST_TCPULPitems 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
Signature · 1 line
Sponsored by the NGI0 Core fund.