lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbV6FGaXCMc8aQjN8iA=Lv7pC_gQDNpDO_EBv3XbrJ5oA@mail.gmail.com>
Date:   Tue, 27 Apr 2021 14:50:06 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Kumar Kartikeya Dwivedi <memxor@...il.com>
Cc:     bpf <bpf@...r.kernel.org>,
        Toke Høiland-Jørgensen <toke@...hat.com>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf-next v4 3/3] libbpf: add selftests for TC-BPF API

On Fri, Apr 23, 2021 at 8:06 AM Kumar Kartikeya Dwivedi
<memxor@...il.com> wrote:
>
> This adds some basic tests for the low level bpf_tc_* API.
>
> Reviewed-by: Toke Høiland-Jørgensen <toke@...hat.com>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@...il.com>
> ---
>  .../testing/selftests/bpf/prog_tests/tc_bpf.c | 204 ++++++++++++++++++
>  .../testing/selftests/bpf/progs/test_tc_bpf.c |  12 ++
>  2 files changed, 216 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/prog_tests/tc_bpf.c
>  create mode 100644 tools/testing/selftests/bpf/progs/test_tc_bpf.c
>

[...]

> +
> +void test_tc_bpf(void)
> +{
> +       struct bpf_tc_ctx *ctx_ing = NULL, *ctx_eg = NULL;
> +       struct test_tc_bpf *skel = NULL;
> +       int cls_fd, ret;
> +
> +       skel = test_tc_bpf__open_and_load();
> +       if (!ASSERT_NEQ(skel, NULL, "test_tc_bpf skeleton"))
> +               goto end;
> +
> +       cls_fd = bpf_program__fd(skel->progs.cls);
> +
> +       ctx_ing = bpf_tc_ctx_init(LO_IFINDEX, BPF_TC_INGRESS, NULL);
> +       if (!ASSERT_NEQ(ctx_ing, NULL, "bpf_tc_ctx_init(BPF_TC_INGRESS)"))

please use ASSERT_OK_PTR() and ASSERT_ERR_PTR() for pointer checks.
They handle both NULL/non-NULL cases and ERR_PTR() errors.

> +               goto end;
> +
> +       ctx_eg = bpf_tc_ctx_init(LO_IFINDEX, BPF_TC_EGRESS, NULL);
> +       if (!ASSERT_NEQ(ctx_eg, NULL, "bpf_tc_ctx_init(BPF_TC_EGRESS)"))
> +               goto end;
> +
> +       ret = test_tc_internal(ctx_ing, cls_fd, BPF_TC_INGRESS);
> +       if (!ASSERT_EQ(ret, 0, "test_tc_internal ingress"))
> +               goto end;
> +
> +       ret = test_tc_internal(ctx_eg, cls_fd, BPF_TC_EGRESS);
> +       if (!ASSERT_EQ(ret, 0, "test_tc_internal egress"))
> +               goto end;
> +
> +       ret = test_tc_invalid(ctx_ing, cls_fd);
> +       if (!ASSERT_EQ(ret, 0, "test_tc_invalid"))
> +               goto end;
> +
> +end:
> +       bpf_tc_ctx_destroy(ctx_eg);
> +       bpf_tc_ctx_destroy(ctx_ing);
> +       test_tc_bpf__destroy(skel);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_tc_bpf.c b/tools/testing/selftests/bpf/progs/test_tc_bpf.c
> new file mode 100644
> index 000000000000..18a3a7ed924a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_tc_bpf.c
> @@ -0,0 +1,12 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +/* Dummy prog to test TC-BPF API */
> +
> +SEC("classifier")
> +int cls(struct __sk_buff *skb)
> +{
> +       return 0;
> +}
> --
> 2.30.2
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ