Commit 96af42c5 authored by Andrii Nakryiko's avatar Andrii Nakryiko
Browse files

Merge branch 'bpf: mptcp: Support for mptcp_sock'

Mat Martineau says:

====================

This patch set adds BPF access to mptcp_sock structures, along with
associated self tests. You may recognize some of the code from earlier
(https://lore.kernel.org/bpf/20200918121046.190240-6-nicolas.rybowski@tessares.net/

)
but it has been reworked quite a bit.

v1 -> v2: Emit BTF type, add func_id checks in verifier.c and bpf_trace.c,
remove build check for CONFIG_BPF_JIT, add selftest check for CONFIG_MPTCP,
and add a patch to include CONFIG_IKCONFIG/CONFIG_IKCONFIG_PROC for the
BPF self tests.

v2 -> v3: Access sysctl through the filesystem to work around CI use of
the more limited busybox sysctl command.

v3 -> v4: Dropped special case kernel code for tcp_sock is_mptcp, use
existing bpf_tcp_helpers.h, and add check for 'ip mptcp monitor' support.

v4 -> v5: Use BPF test skeleton, more consistent use of ASSERT macros,
drop some unnecessary parameters / checks, and use tracing to acquire
MPTCP token.

Geliang Tang (6):
  bpf: add bpf_skc_to_mptcp_sock_proto
  selftests/bpf: Enable CONFIG_IKCONFIG_PROC in config
  selftests/bpf: test bpf_skc_to_mptcp_sock
  selftests/bpf: verify token of struct mptcp_sock
  selftests/bpf: verify ca_name of struct mptcp_sock
  selftests/bpf: verify first of struct mptcp_sock
====================

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
parents 7aa424e0 4f90d034
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13780,6 +13780,7 @@ F: include/net/mptcp.h
F:	include/trace/events/mptcp.h
F:	include/uapi/linux/mptcp.h
F:	net/mptcp/
F:	tools/testing/selftests/bpf/*/*mptcp*.c
F:	tools/testing/selftests/net/mptcp/
NETWORKING [TCP]
+1 −0
Original line number Diff line number Diff line
@@ -2231,6 +2231,7 @@ extern const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_tcp_request_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_udp6_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_unix_sock_proto;
extern const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto;
extern const struct bpf_func_proto bpf_copy_from_user_proto;
extern const struct bpf_func_proto bpf_snprintf_btf_proto;
extern const struct bpf_func_proto bpf_snprintf_proto;
+2 −1
Original line number Diff line number Diff line
@@ -178,7 +178,8 @@ extern struct btf_id_set name;
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock)			\
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock)			\
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)			\
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock)			\
	BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock)

enum {
#define BTF_SOCK_TYPE(name, str) name,
+6 −0
Original line number Diff line number Diff line
@@ -284,4 +284,10 @@ static inline int mptcpv6_init(void) { return 0; }
static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }
#endif

#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_SYSCALL)
struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk);
#else
static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { return NULL; }
#endif

#endif /* __NET_MPTCP_H */
+7 −0
Original line number Diff line number Diff line
@@ -5172,6 +5172,12 @@ union bpf_attr {
 * 	Return
 * 		Map value associated to *key* on *cpu*, or **NULL** if no entry
 * 		was found or *cpu* is invalid.
 *
 * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)
 *	Description
 *		Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
 *	Return
 *		*sk* if casting is valid, or **NULL** otherwise.
 */
#define __BPF_FUNC_MAPPER(FN)		\
	FN(unspec),			\
@@ -5370,6 +5376,7 @@ union bpf_attr {
	FN(ima_file_hash),		\
	FN(kptr_xchg),			\
	FN(map_lookup_percpu_elem),     \
	FN(skc_to_mptcp_sock),		\
	/* */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
Loading