bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	Networking <netdev@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 5/8] samples: bpf: Convert xdp_redirect to use XDP samples helper
Date: Thu, 22 Jul 2021 20:49:29 -0700	[thread overview]
Message-ID: <CAEf4BzZjivA-ohnCXn1V7uXC-j_vNncT92+uba2A5z4YGRTTOw@mail.gmail.com> (raw)
In-Reply-To: <20210721212833.701342-6-memxor@gmail.com>

On Wed, Jul 21, 2021 at 2:28 PM Kumar Kartikeya Dwivedi
<memxor@gmail.com> wrote:
>
> This change converts XDP redirect tool to use the XDP samples support
> introduced in previous changes.
>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
>  samples/bpf/Makefile            |  10 +-
>  samples/bpf/xdp_redirect.bpf.c  |  52 +++++++
>  samples/bpf/xdp_redirect_kern.c |  90 -----------
>  samples/bpf/xdp_redirect_user.c | 262 +++++++++++++-------------------
>  4 files changed, 160 insertions(+), 254 deletions(-)
>  create mode 100644 samples/bpf/xdp_redirect.bpf.c
>  delete mode 100644 samples/bpf/xdp_redirect_kern.c
>
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index 1b4838b2beb0..b94b6dac09ff 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -39,7 +39,6 @@ tprogs-y += lwt_len_hist
>  tprogs-y += xdp_tx_iptunnel
>  tprogs-y += test_map_in_map
>  tprogs-y += per_socket_stats_example
> -tprogs-y += xdp_redirect
>  tprogs-y += xdp_redirect_map
>  tprogs-y += xdp_redirect_map_multi
>  tprogs-y += xdp_redirect_cpu
> @@ -56,6 +55,7 @@ tprogs-y += xdp_sample_pkts
>  tprogs-y += ibumad
>  tprogs-y += hbm
>
> +tprogs-y += xdp_redirect
>  tprogs-y += xdp_monitor
>
>  # Libbpf dependencies
> @@ -100,7 +100,6 @@ lwt_len_hist-objs := lwt_len_hist_user.o
>  xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o
>  test_map_in_map-objs := test_map_in_map_user.o
>  per_socket_stats_example-objs := cookie_uid_helper_example.o
> -xdp_redirect-objs := xdp_redirect_user.o
>  xdp_redirect_map-objs := xdp_redirect_map_user.o
>  xdp_redirect_map_multi-objs := xdp_redirect_map_multi_user.o
>  xdp_redirect_cpu-objs := xdp_redirect_cpu_user.o
> @@ -118,6 +117,7 @@ ibumad-objs := ibumad_user.o
>  hbm-objs := hbm.o $(CGROUP_HELPERS)
>
>  xdp_sample_user-objs := xdp_sample_user.o $(LIBBPFDIR)/hashmap.o
> +xdp_redirect-objs := xdp_redirect_user.o $(XDP_SAMPLE)
>  xdp_monitor-objs := xdp_monitor_user.o $(XDP_SAMPLE)
>
>  # Tell kbuild to always build the programs
> @@ -164,7 +164,6 @@ always-y += tcp_clamp_kern.o
>  always-y += tcp_basertt_kern.o
>  always-y += tcp_tos_reflect_kern.o
>  always-y += tcp_dumpstats_kern.o
> -always-y += xdp_redirect_kern.o
>  always-y += xdp_redirect_map_kern.o
>  always-y += xdp_redirect_map_multi_kern.o
>  always-y += xdp_redirect_cpu_kern.o
> @@ -315,6 +314,7 @@ verify_target_bpf: verify_cmds
>  $(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
>  $(src)/*.c: verify_target_bpf $(LIBBPF)
>
> +$(obj)/xdp_redirect_user.o: $(obj)/xdp_redirect.skel.h
>  $(obj)/xdp_monitor_user.o: $(obj)/xdp_monitor.skel.h
>
>  $(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
> @@ -358,6 +358,7 @@ endef
>
>  CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
>
> +$(obj)/xdp_redirect.bpf.o: $(obj)/xdp_sample.bpf.o
>  $(obj)/xdp_monitor.bpf.o: $(obj)/xdp_sample.bpf.o
>
>  $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/xdp_sample_shared.h
> @@ -368,9 +369,10 @@ $(obj)/%.bpf.o: $(src)/%.bpf.c $(obj)/vmlinux.h $(src)/xdp_sample.bpf.h $(src)/x
>                 -I$(srctree)/tools/lib $(CLANG_SYS_INCLUDES) \
>                 -c $(filter %.bpf.c,$^) -o $@
>
> -LINKED_SKELS := xdp_monitor.skel.h
> +LINKED_SKELS := xdp_redirect.skel.h xdp_monitor.skel.h
>  clean-files += $(LINKED_SKELS)
>
> +xdp_redirect.skel.h-deps := xdp_redirect.bpf.o xdp_sample.bpf.o
>  xdp_monitor.skel.h-deps := xdp_monitor.bpf.o xdp_sample.bpf.o
>
>  LINKED_BPF_SRCS := $(patsubst %.bpf.o,%.bpf.c,$(foreach skel,$(LINKED_SKELS),$($(skel)-deps)))
> diff --git a/samples/bpf/xdp_redirect.bpf.c b/samples/bpf/xdp_redirect.bpf.c
> new file mode 100644
> index 000000000000..f5098812db36
> --- /dev/null
> +++ b/samples/bpf/xdp_redirect.bpf.c
> @@ -0,0 +1,52 @@
> +/* Copyright (c) 2016 John Fastabend <john.r.fastabend@intel.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * General Public License for more details.
> + */
> +#define KBUILD_MODNAME "foo"
> +
> +#include "vmlinux.h"
> +#include "xdp_sample.bpf.h"
> +#include "xdp_sample_shared.h"
> +
> +const volatile int ifindex_out;
> +
> +SEC("xdp_redirect")

can you please use "canonical" SEC("xdp") everywhere and use function
names as unique BPF program identifiers. Section name is the program
type specification (plus extra type-specific argument where
applicable, like tracepoint name), not a unique identifier.

> +int xdp_redirect_prog(struct xdp_md *ctx)
> +{
> +       void *data_end = (void *)(long)ctx->data_end;
> +       void *data = (void *)(long)ctx->data;
> +       u32 key = bpf_get_smp_processor_id();
> +       struct ethhdr *eth = data;
> +       struct datarec *rec;
> +       u64 nh_off;
> +

[...]

  reply	other threads:[~2021-07-23  3:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 21:28 [PATCH bpf-next v2 0/8] Improve XDP samples usability and output Kumar Kartikeya Dwivedi
2021-07-21 21:28 ` [PATCH bpf-next v2 1/8] samples: bpf: fix a couple of warnings Kumar Kartikeya Dwivedi
2021-07-21 21:28 ` [PATCH bpf-next v2 2/8] samples: bpf: Add common infrastructure for XDP samples Kumar Kartikeya Dwivedi
2021-07-23  3:34   ` Andrii Nakryiko
2021-07-21 21:28 ` [PATCH bpf-next v2 3/8] samples: bpf: Add BPF support for XDP samples helper Kumar Kartikeya Dwivedi
2021-07-23  3:42   ` Andrii Nakryiko
2021-07-21 21:28 ` [PATCH bpf-next v2 4/8] samples: bpf: Convert xdp_monitor to use " Kumar Kartikeya Dwivedi
2021-07-21 21:28 ` [PATCH bpf-next v2 5/8] samples: bpf: Convert xdp_redirect " Kumar Kartikeya Dwivedi
2021-07-23  3:49   ` Andrii Nakryiko [this message]
2021-07-21 21:28 ` [PATCH bpf-next v2 6/8] samples: bpf: Convert xdp_redirect_map to use XDP samples helpers Kumar Kartikeya Dwivedi
2021-07-21 21:28 ` [PATCH bpf-next v2 7/8] samples: bpf: Convert xdp_redirect_map_multi " Kumar Kartikeya Dwivedi
2021-07-21 21:28 ` [PATCH bpf-next v2 8/8] samples: bpf: Convert xdp_redirect_cpu " Kumar Kartikeya Dwivedi
2021-07-23 21:32 ` [PATCH bpf-next v2 0/8] Improve XDP samples usability and output Toke Høiland-Jørgensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzZjivA-ohnCXn1V7uXC-j_vNncT92+uba2A5z4YGRTTOw@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=memxor@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=toke@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).