[PATCH mptcp-next v2] Squash to "bpf: add 'bpf_mptcp_sock' structure and helper"

Geliang Tang posted 1 patch 2 years, 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/1d22e521c59d2d6c6b9205326bfc47c0cabfe424.1645433392.git.geliang.tang@suse.com
Maintainers: Alexei Starovoitov <ast@kernel.org>, "David S. Miller" <davem@davemloft.net>, Mat Martineau <mathew.j.martineau@linux.intel.com>, KP Singh <kpsingh@kernel.org>, Yonghong Song <yhs@fb.com>, Song Liu <songliubraving@fb.com>, Matthieu Baerts <matthieu.baerts@tessares.net>, Martin KaFai Lau <kafai@fb.com>, Andrii Nakryiko <andrii@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, John Fastabend <john.fastabend@gmail.com>
There is a newer version of this series
net/mptcp/bpf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH mptcp-next v2] Squash to "bpf: add 'bpf_mptcp_sock' structure and helper"
Posted by Geliang Tang 2 years, 2 months ago
This patch addressed to the comments in [1] from BPF maintainer Alexei
Starovoitov:

'''
On Fri, Sep 18, 2020 at 02:10:42PM +0200, Nicolas Rybowski wrote:
> +
> +BPF_CALL_1(bpf_mptcp_sock, struct sock *, sk)
> +{
> +	if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) {
> +		struct mptcp_subflow_context *mptcp_sfc = mptcp_subflow_ctx(sk);

Could you add !sk check here as well?
See commit 8c33dadc3e0e ("bpf: Bpf_skc_to_* casting helpers require a NULL check on sk")
It's not strictly necessary yet, but see below.
'''

I added this !sk check as he suggested.

[1]
https://lore.kernel.org/netdev/20200922040830.3iis6xiavhvpfq3v@ast-mbp.dhcp.thefacebook.com/

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
v2:
 - keep RET_PTR_TO_MPTCP_SOCK_OR_NULL. If we use RET_PTR_TO_BTF_ID_OR_NULL
instead of RET_PTR_TO_MPTCP_SOCK_OR_NULL as Alexei suggested, the
"userspace" tests developed by Nicolas will break.
---
 net/mptcp/bpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
index 5332469fbb28..165edec3b276 100644
--- a/net/mptcp/bpf.c
+++ b/net/mptcp/bpf.c
@@ -56,7 +56,7 @@ u32 bpf_mptcp_sock_convert_ctx_access(enum bpf_access_type type,
 
 BPF_CALL_1(bpf_mptcp_sock, struct sock *, sk)
 {
-	if (sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) {
+	if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) {
 		struct mptcp_subflow_context *mptcp_sfc = mptcp_subflow_ctx(sk);
 
 		return (unsigned long)mptcp_sfc->conn;
-- 
2.34.1