Re: [PATCH bpf-next v2 7/8] selftest/bpf: add XDP socket tests for bpf_redirect_{xsk, map}()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 19, 2021 at 7:55 AM Björn Töpel <bjorn.topel@xxxxxxxxx> wrote:
>
> From: Björn Töpel <bjorn.topel@xxxxxxxxx>
>
> Add support for externally loaded XDP programs to
> xdpxceiver/test_xsk.sh, so that bpf_redirect_xsk() and
> bpf_redirect_map() can be exercised.
>
> Signed-off-by: Björn Töpel <bjorn.topel@xxxxxxxxx>
> ---
>  .../selftests/bpf/progs/xdpxceiver_ext1.c     | 15 ++++
>  .../selftests/bpf/progs/xdpxceiver_ext2.c     |  9 +++
>  tools/testing/selftests/bpf/test_xsk.sh       | 48 ++++++++++++
>  tools/testing/selftests/bpf/xdpxceiver.c      | 77 ++++++++++++++++++-
>  tools/testing/selftests/bpf/xdpxceiver.h      |  2 +
>  5 files changed, 147 insertions(+), 4 deletions(-)
>  create mode 100644 tools/testing/selftests/bpf/progs/xdpxceiver_ext1.c
>  create mode 100644 tools/testing/selftests/bpf/progs/xdpxceiver_ext2.c
>
> diff --git a/tools/testing/selftests/bpf/progs/xdpxceiver_ext1.c b/tools/testing/selftests/bpf/progs/xdpxceiver_ext1.c
> new file mode 100644
> index 000000000000..18894040cca6
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/xdpxceiver_ext1.c
> @@ -0,0 +1,15 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +struct {
> +       __uint(type, BPF_MAP_TYPE_XSKMAP);
> +       __uint(max_entries, 32);
> +       __uint(key_size, sizeof(int));
> +       __uint(value_size, sizeof(int));
> +} xsks_map SEC(".maps");
> +
> +SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)

hmm.. that's unconventional... please keep SEC() on separate line

> +{
> +       return bpf_redirect_map(&xsks_map, ctx->rx_queue_index, XDP_DROP);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/xdpxceiver_ext2.c b/tools/testing/selftests/bpf/progs/xdpxceiver_ext2.c
> new file mode 100644
> index 000000000000..bd239b958c01
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/xdpxceiver_ext2.c
> @@ -0,0 +1,9 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)

same here

> +{
> +       return bpf_redirect_xsk(ctx, XDP_DROP);
> +}
> +

[...]




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux