selftests/bpf: Add pid limit for mptcpify prog
In order to prevent mptcpify prog from affecting the running results of other BPF tests, a pid limit was added to restrict it from only modifying its own program. Suggested-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/8987e2938e15e8ec390b85b5dcbee704751359dc.1712054986.git.tanggeliang@kylinos.cn
This commit is contained in:
committed by
Andrii Nakryiko
parent
15ea39ad7e
commit
c07b4bcd51
@@ -273,6 +273,8 @@ static int run_mptcpify(int cgroup_fd)
|
||||
if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load"))
|
||||
return libbpf_get_error(mptcpify_skel);
|
||||
|
||||
mptcpify_skel->bss->pid = getpid();
|
||||
|
||||
err = mptcpify__attach(mptcpify_skel);
|
||||
if (!ASSERT_OK(err, "skel_attach"))
|
||||
goto out;
|
||||
|
||||
@@ -6,10 +6,14 @@
|
||||
#include "bpf_tracing_net.h"
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
int pid;
|
||||
|
||||
SEC("fmod_ret/update_socket_protocol")
|
||||
int BPF_PROG(mptcpify, int family, int type, int protocol)
|
||||
{
|
||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||
return protocol;
|
||||
|
||||
if ((family == AF_INET || family == AF_INET6) &&
|
||||
type == SOCK_STREAM &&
|
||||
(!protocol || protocol == IPPROTO_TCP)) {
|
||||
|
||||
Reference in New Issue
Block a user