[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z8DiX8MmJWvO5Ws2@mini-arch>
Date: Thu, 27 Feb 2025 14:08:31 -0800
From: Stanislav Fomichev <stfomichev@...il.com>
To: "Bastien Curutchet (eBPF Foundation)" <bastien.curutchet@...tlin.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
Mykola Lysenko <mykolal@...com>, Shuah Khan <shuah@...nel.org>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
Alexis Lothore <alexis.lothore@...tlin.com>, bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH bpf-next 01/10] selftests/bpf: test_tunnel: Add
generic_attach* helpers
On 02/27, Bastien Curutchet (eBPF Foundation) wrote:
> A fair amount of code duplication is present among tests to attach BPF
> programs.
>
> Create generic_attach* helpers that attach BPF programs to a given
> interface.
> Use ASSERT_OK_FD() instead of ASSERT_GE() to check fd's validity.
> Use these helpers in all the available tests.
>
> Signed-off-by: Bastien Curutchet (eBPF Foundation) <bastien.curutchet@...tlin.com>
> ---
> .../testing/selftests/bpf/prog_tests/test_tunnel.c | 128 ++++++++++-----------
> 1 file changed, 62 insertions(+), 66 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
> index cec746e77cd3abdf561cfc2422fa0a934fc481cd..27a8c8caa87e4c6b39b2b26c2aa9860b131a70a9 100644
> --- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
> +++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c
> @@ -397,6 +397,56 @@ static int attach_tc_prog(struct bpf_tc_hook *hook, int igr_fd, int egr_fd)
> return 0;
> }
>
> +static int generic_attach(const char *dev, int igr_fd, int egr_fd)
> +{
> + DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
nit: .attach_point = BPF_TC_INGRESS is a bit confusing to me here
(because we later attach both ingress and egress progs); mostly
because the way attach_tc_prog is written I think. Can we move
tc_hook definition to attach_tc_prog and make it
.attach_point=BPF_TC_INGRESS|BPF_TC_EGRESS? And then we can make
attach_tc_prog accept ifindex instead of tc_hook.
int attach_tc_prog(int ifindex, igr_fd, egr_fd)
{
DECLARE_LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS|BPF_TC_EGRESS);
bpf_tc_hook_create(&tc_hook);
if (igr_fd >= 0) {
tc_hook.attach_point = BPF_TC_INGRESS;
...
}
if (egr_fd >= 0) {
tc_hook.attach_point = BPF_TC_EGRESS;
...
}
}
Or is it just me?
Powered by blists - more mailing lists