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]
Date:   Fri, 10 Jul 2020 00:40:11 +0200
From:   Daniel Borkmann <daniel@...earbox.net>
To:     Hangbin Liu <liuhangbin@...il.com>, bpf@...r.kernel.org
Cc:     netdev@...r.kernel.org,
        Toke Høiland-Jørgensen <toke@...hat.com>,
        Jiri Benc <jbenc@...hat.com>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        Eelco Chaudron <echaudro@...hat.com>, ast@...nel.org,
        Lorenzo Bianconi <lorenzo.bianconi@...hat.com>
Subject: Re: [PATCHv6 bpf-next 2/3] sample/bpf: add xdp_redirect_map_multicast
 test

On 7/9/20 3:30 AM, Hangbin Liu wrote:
> This is a sample for xdp multicast. In the sample we could forward all
> packets between given interfaces.
> 
> v5: add a null_map as we have strict the arg2 to ARG_CONST_MAP_PTR.
>      Move the testing part to bpf selftest in next patch.
> v4: no update.
> v3: add rxcnt map to show the packet transmit speed.
> v2: no update.
> 
> Signed-off-by: Hangbin Liu <liuhangbin@...il.com>
> ---
>   samples/bpf/Makefile                      |   3 +
>   samples/bpf/xdp_redirect_map_multi_kern.c |  57 ++++++++
>   samples/bpf/xdp_redirect_map_multi_user.c | 166 ++++++++++++++++++++++
>   3 files changed, 226 insertions(+)
>   create mode 100644 samples/bpf/xdp_redirect_map_multi_kern.c
>   create mode 100644 samples/bpf/xdp_redirect_map_multi_user.c
> 
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index f87ee02073ba..fddca6cb76b8 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -41,6 +41,7 @@ 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
>   tprogs-y += xdp_monitor
>   tprogs-y += xdp_rxq_info
> @@ -97,6 +98,7 @@ 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 := bpf_load.o xdp_redirect_cpu_user.o
>   xdp_monitor-objs := bpf_load.o xdp_monitor_user.o
>   xdp_rxq_info-objs := xdp_rxq_info_user.o
> @@ -156,6 +158,7 @@ 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
>   always-y += xdp_monitor_kern.o
>   always-y += xdp_rxq_info_kern.o
> diff --git a/samples/bpf/xdp_redirect_map_multi_kern.c b/samples/bpf/xdp_redirect_map_multi_kern.c
> new file mode 100644
> index 000000000000..cc7ebaedf55a
> --- /dev/null
> +++ b/samples/bpf/xdp_redirect_map_multi_kern.c
> @@ -0,0 +1,57 @@
> +/* SPDX-License-Identifier: GPL-2.0
> + *
> + * 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 <uapi/linux/bpf.h>
> +#include <bpf/bpf_helpers.h>
> +
> +struct bpf_map_def SEC("maps") forward_map = {
> +	.type = BPF_MAP_TYPE_DEVMAP_HASH,
> +	.key_size = sizeof(u32),
> +	.value_size = sizeof(int),
> +	.max_entries = 256,
> +};
> +
> +struct bpf_map_def SEC("maps") null_map = {
> +	.type = BPF_MAP_TYPE_DEVMAP_HASH,
> +	.key_size = sizeof(u32),
> +	.value_size = sizeof(int),
> +	.max_entries = 1,
> +};
> +
> +struct bpf_map_def SEC("maps") rxcnt = {
> +	.type = BPF_MAP_TYPE_PERCPU_ARRAY,
> +	.key_size = sizeof(u32),
> +	.value_size = sizeof(long),
> +	.max_entries = 1,
> +};
> +
> +SEC("xdp_redirect_map_multi")
> +int xdp_redirect_map_multi_prog(struct xdp_md *ctx)
> +{
> +	long *value;
> +	u32 key = 0;
> +
> +	/* count packet in global counter */
> +	value = bpf_map_lookup_elem(&rxcnt, &key);
> +	if (value)
> +		*value += 1;
> +
> +	return bpf_redirect_map_multi(&forward_map, &null_map,
> +				      BPF_F_EXCLUDE_INGRESS);

Why not extending to allow use-case like ...

   return bpf_redirect_map_multi(&fwd_map, NULL, BPF_F_EXCLUDE_INGRESS);

... instead of requiring a dummy/'null' map?

Thanks,
Daniel

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ