introduce msk_is_mptcp() helper
Subsystems (3)
Geliang Tang
reviewercover introduce msk_is_mptcp() helper
From: Geliang Tang <[email protected]>
This series introduces the msk_is_mptcp() helper function to check whether a socket is an MPTCP parent socket (IPPROTO_MPTCP on SOCK_STREAM).
This helper is useful for adding MPTCP support in various subsystems, such as MPTCP sockmap support [1] and landlock MPTCP access rights [2].
Naming rationale:
- Initially considered "sk_is_msk", but as Günther pointed out, "msk" is already used as an abbreviation in net/mctp, which could cause confusion
- "sk_is_mptcp()" is already taken and used to check whether a socket is an MPTCP subflow (tcp_sk(sk)->is_mptcp)
- Following the convention of rsk_is_mptcp(), settled on msk_is_mptcp() to clearly distinguish MPTCP parent socket checks from subflow checks
[1] mptcp: add sk_is_msk() helper and use it in sockmap
https://patchwork.kernel.org/project/mptcp/patch/29ec7b3fc7febc1c8946add34f859c8253d9714f.1789294365.git.tanggeliang@kylinos.cn/
[2] landlock: Add MPTCP bind and connect access rights
https://patchwork.kernel.org/project/mptcp/patch/[email protected]/
Geliang Tang (2):
mptcp: add msk_is_mptcp() helper
Squash to "bpf: Add mptcp_subflow bpf_iter"
include/net/mptcp.h | 12 ++++++++++++ net/mptcp/bpf.c | 9 +-------- 2 files changed, 13 insertions(+), 8 deletions(-)
Signature · 1 line
2.55.0
Geliang Tang
reviewerPATCH 1/2 mptcp: add msk_is_mptcp() helper
From: Geliang Tang <[email protected]>
Introduce msk_is_mptcp() to check whether a socket is an MPTCP socket (IPPROTO_MPTCP on SOCK_STREAM), modeled after sk_is_tcp(). Unlike sk_is_mptcp() which tests a subflow socket, this helper takes an MPTCP parent socket directly.
The naming follows the convention of rsk_is_mptcp() to distinguish it from sk_is_mptcp(). This helper will be used in net/core/sock_map.c alongside sk_is_tcp() to add MPTCP support for BPF sockmap, and in other places where MPTCP parent socket type checking is needed.
--- 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 msk_is_mptcp (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);
@@ -261,6 +268,11 @@ static inline bool rsk_drop_req(const struct request_sock *req)return false; } +static inline bool msk_is_mptcp (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.55.0
Re: [PATCH mptcp-next 1/2] mptcp: add msk_is_mptcp() helper
Quoted 50 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Introduce
msk_is_mptcp()to check whether a socket is an MPTCP socket (IPPROTO_MPTCPonSOCK_STREAM), modeled aftersk_is_tcp(). Unlikesk_is_mptcp()which tests a subflow socket, this helper takes an MPTCP parent socket directly.The naming follows the convention of
rsk_is_mptcp()to distinguish it fromsk_is_mptcp(). This helper will be used innet/core/sock_map.calongsidesk_is_tcp()to add MPTCP support for BPF sockmap, and in other places where MPTCP parent socket type checking is needed.Signed-off-by Geliang Tang <[email protected]>--- 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 msk_is_mptcp (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);@@ -261,6 +268,11 @@ static inline bool rsk_drop_req(const struct request_sock *req)return false; } +static inline bool msk_is_mptcp (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.55.0
Thank you Geliang! This is exactly the helper we'd need for the Landlock MPTCP patch as well, and I'll happily rebase my patch set on that and use this more central helper!
(Landlock is currently a bit bottlenecked on code reviews, so that review is moving a bit slower, but we'll get to it.)
–Günther
Geliang Tang
reviewerRe: [PATCH mptcp-next 1/2] mptcp: add msk_is_mptcp() helper
In reply to Geliang TangHi Matt,
Quoted 11 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Introduce
msk_is_mptcp()to check whether a socket is an MPTCP socket (IPPROTO_MPTCPonSOCK_STREAM), modeled aftersk_is_tcp(). Unlikesk_is_mptcp()which tests a subflow socket, this helper takes an MPTCP parent socket directly.The naming follows the convention of
rsk_is_mptcp()to distinguish it fromsk_is_mptcp(). This helper will be used innet/core/sock_map.calongsidesk_is_tcp()to add MPTCP support for BPF sockmap, and in other places where MPTCP parent socket type checking is needed.
The commit log needs to be updated. We rarely say "MPTCP parent socket"
- "MPTCP socket" is sufficient:
'''
Introduce msk_is_mptcp() to check whether a socket is an MPTCP socket (IPPROTO_MPTCP on SOCK_STREAM), modeled after sk_is_tcp(). Unlike sk_is_mptcp() which tests a subflow socket, this helper takes an MPTCP socket directly.
The naming follows the convention of rsk_is_mptcp() to distinguish it from sk_is_mptcp(). This helper will be used in net/core/sock_map.c alongside sk_is_tcp() to add MPTCP support for BPF sockmap, and in other places where MPTCP socket type checking is needed. '''
Thanks,
-Geliang
Quoted 41 lines
Signed-off-by Geliang Tang <[email protected]>---
include/net/mptcp.h | 12 ++++++++++++1 file changed, 12 insertions(+)include/net/mptcp.h +0
-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; }include/net/mptcp.h +7
-0+static inline bool msk_is_mptcp (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);
boolmptcp_syn_options(struct sock *sk, const struct sk_buff *skb, unsigned int *size, struct mptcp_out_options *opts);include/net/mptcp.h +0
-0@@ -261,6 +268,11 @@ static inline bool rsk_drop_req(const struct request_sock *req) return false; }include/net/mptcp.h +5
-0+static inline bool msk_is_mptcp (const struct sock *sk) +{ +return false; +} +static inline bool mptcp_syn_options(struct sock *sk, const struct
sk_buff*skb,
unsigned int *size, structmptcp_out_options*opts)
Geliang Tang
reviewerPATCH 2/2 Squash to "bpf: Add mptcp_subflow bpf_iter"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Use the new msk_is_mptcp() helper to replace the open-coded check for sk_type and sk_protocol in bpf_iter_mptcp_subflow_new(). This makes the code cleaner and consistent with other MPTCP socket type checks.
--- net/mptcp/bpf.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
net/mptcp/bpf.c +1 -8
@@ -250,14 +250,7 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,BUILD_BUG_ON (__alignof__(struct bpf_iter_mptcp_subflow_kern ) != __alignof__(struct bpf_iter_mptcp_subflow )); -if (unlikely (!sk || !sk_fullsock (sk))) { - kit->msk =NULL ; - kit->pos =NULL ; -return -EINVAL ; - } - -if (sk->sk_type !=SOCK_STREAM || - sk->sk_protocol !=IPPROTO_MPTCP ) { +if (unlikely (!sk || !sk_fullsock (sk) || !msk_is_mptcp (sk))) { kit->msk =NULL ; kit->pos =NULL ;return -EINVAL ;
Signature · 1 line
2.55.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): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Perf: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/38361897543
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/b39a692c5e0f
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1184430
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,
Quoted 4 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This series introduces the
msk_is_mptcp()helper function to check whether a socket is an MPTCP parent socket (IPPROTO_MPTCPonSOCK_STREAM).
Thank you, it looks good to me:
Quoted 2 lines
This helper is useful for adding MPTCP support in various subsystems, such as MPTCP sockmap support [1] and landlock MPTCP access rights [2].
I also added the Landlock case in the commit message, to justify why this patch might be sent alone.
New patches for t/upstream:
- a15d45cff6cd: mptcp: add msk_is_mptcp() helper
- e697e37e696d: "squashed" patch 2/2 in "bpf: Add mptcp_subflow bpf_iter"
- Results: 9ad04f9a236a..8bf8f58e5882 (export)
Tests are now in progress:
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.