RE: [PATCHv17 bpf-next 6/6] selftests/bpf: add xdp_redirect_multi test

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

 



Hangbin Liu wrote:
> Add a bpf selftest for new helper xdp_redirect_map_multi(). In this
> test we have 3 forward groups and 1 exclude group. The test will
> redirect each interface's packets to all the interfaces in the forward
> group, and exclude the interface in exclude map. We will also test both
> DEVMAP and DEVMAP_HASH with xdp generic and drv.
> 
> For more test details, you can find it in the test script. Here is
> the test result.
> ]# ./test_xdp_redirect_multi.sh
> Pass: xdpgeneric arp ns1-2
> Pass: xdpgeneric arp ns1-3
> Pass: xdpgeneric arp ns1-4
> Pass: xdpgeneric ping ns1-2
> Pass: xdpgeneric ping ns1-3
> Pass: xdpgeneric ping ns1-4
> Pass: xdpgeneric ping6 ns2-1
> Pass: xdpgeneric ping6 ns2-3
> Pass: xdpgeneric ping6 ns2-4
> Pass: xdpdrv arp ns1-2
> Pass: xdpdrv arp ns1-3
> Pass: xdpdrv arp ns1-4
> Pass: xdpdrv ping ns1-2
> Pass: xdpdrv ping ns1-3
> Pass: xdpdrv ping ns1-4
> Pass: xdpdrv ping6 ns2-1
> Pass: xdpdrv ping6 ns2-3
> Pass: xdpdrv ping6 ns2-4
> Pass: xdpegress mac ns1-2
> Pass: xdpegress mac ns1-3
> Pass: xdpegress mac ns1-4
> Pass: xdpegress ping ns1-2
> Pass: xdpegress ping ns1-3
> Pass: xdpegress ping ns1-4
> Summary: PASS 24, FAIL 0
> 
> Acked-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
> Signed-off-by: Hangbin Liu <liuhangbin@xxxxxxxxx>
> 
> ---
> v16-v17: no update
> v15: use bpf_object__find_program_by_name instead of
>      bpf_object__find_program_by_title
> v14: no update, only rebase the code
> v13: remove setrlimit
> v12: add devmap prog test on egress
> v9: use NULL directly for arg2 and redefine the maps with btf format
> ---

[...]

> +SEC("xdp_devmap/map_prog")
> +int xdp_devmap_prog(struct xdp_md *ctx)
> +{
> +	void *data_end = (void *)(long)ctx->data_end;
> +	void *data = (void *)(long)ctx->data;
> +	__u32 key = ctx->egress_ifindex;
> +	struct ethhdr *eth = data;
> +	__u64 nh_off;
> +	__be64 *mac;
> +
> +	nh_off = sizeof(*eth);
> +	if (data + nh_off > data_end)
> +		return XDP_DROP;
> +
> +	mac = bpf_map_lookup_elem(&mac_map, &key);
> +	if (mac)
> +		__builtin_memcpy(eth->h_source, mac, ETH_ALEN);
> +
> +	return XDP_PASS;
> +}

Might be nice to also have a test for XDP_DROP. I guess the
above 'data + nh_off > data' case should not happen.

Otherwise, its not the most elegant, but testing XDP at the moment
doesn't fit into the normal test framework very well either.

Acked-by: John Fastabend <john.fastabend@xxxxxxxxx>



[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