Commit 3bc253c2 authored by Geliang Tang's avatar Geliang Tang Committed by Andrii Nakryiko
Browse files

bpf: Add bpf_skc_to_mptcp_sock_proto



This patch implements a new struct bpf_func_proto, named
bpf_skc_to_mptcp_sock_proto. Define a new bpf_id BTF_SOCK_TYPE_MPTCP,
and a new helper bpf_skc_to_mptcp_sock(), which invokes another new
helper bpf_mptcp_sock_from_subflow() in net/mptcp/bpf.c to get struct
mptcp_sock from a given subflow socket.

v2: Emit BTF type, add func_id checks in verifier.c and bpf_trace.c,
remove build check for CONFIG_BPF_JIT
v5: Drop EXPORT_SYMBOL (Martin)

Co-developed-by: default avatarNicolas Rybowski <nicolas.rybowski@tessares.net>
Co-developed-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarNicolas Rybowski <nicolas.rybowski@tessares.net>
Signed-off-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarGeliang Tang <geliang.tang@suse.com>
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220519233016.105670-2-mathew.j.martineau@linux.intel.com
parent 7aa424e0
Loading
Loading
Loading
Loading
+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
+1 −0
Original line number Diff line number Diff line
@@ -509,6 +509,7 @@ static bool is_ptr_cast_function(enum bpf_func_id func_id)
		func_id == BPF_FUNC_skc_to_tcp_sock ||
		func_id == BPF_FUNC_skc_to_tcp6_sock ||
		func_id == BPF_FUNC_skc_to_udp6_sock ||
		func_id == BPF_FUNC_skc_to_mptcp_sock ||
		func_id == BPF_FUNC_skc_to_tcp_timewait_sock ||
		func_id == BPF_FUNC_skc_to_tcp_request_sock;
}
Loading