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.curutc...@bootlin.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?

Reply via email to