selftests: bpf: add a test for XDP redirect
Subsystems (6)
PATCH 1/1 selftests: bpf: add a test for XDP redirect
Add test for xdp_redirect by creating two namespaces with two veth peers, then forward packets in-between.
Signed-off-by William Tu <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc John Fastabend <[email protected]>
--- tools/include/uapi/linux/bpf.h | 3 +- tools/testing/selftests/bpf/Makefile | 4 +- tools/testing/selftests/bpf/test_xdp_redirect.c | 28 ++++++++++++ tools/testing/selftests/bpf/test_xdp_redirect.sh | 54 ++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 tools/testing/selftests/bpf/test_xdp_redirect.c create mode 100755 tools/testing/selftests/bpf/test_xdp_redirect.sh
tools/include/uapi/linux/bpf.h +2 -1
@@ -592,7 +592,8 @@ union bpf_attr {FN (get_socket_uid), \FN (set_hash), \FN (setsockopt), \ -FN (skb_adjust_room), +FN (skb_adjust_room), \ +FN (redirect_map),/* integer value in 'imm' field of BPF_CALL instruction selects which helper * function eBPF program intends to call
tools/testing/selftests/bpf/Makefile +2 -2
@@ -15,9 +15,9 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test test_align TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ - test_pkt_md_access.o + test_pkt_md_access.o test_xdp_redirect.o -TEST_PROGS := test_kmod.sh +TEST_PROGS := test_kmod.sh test_xdp_redirect.sh include ../lib.mk
tools/testing/selftests/bpf/test_xdp_redirect.c new file +28 -0
@@ -0,0 +1,28 @@ +/* Copyright (c) 2017 VMware +* +* 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. +*/ +#include <linux/bpf.h> +#include "bpf_helpers.h" + +int _version SEC("version") = 1; + +SEC("redirect_to_111") +int xdp_redirect_to_111 (struct xdp_md *xdp) +{ +return bpf_redirect (111 ,0 ); +} +SEC("redirect_to_222") +int xdp_redirect_to_222 (struct xdp_md *xdp) +{ +return bpf_redirect (222 ,0 ); +} + +char _license[] SEC("license") = "GPL";
tools/testing/selftests/bpf/test_xdp_redirect.sh new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 6 lines · William Tu
Add test for
xdp_redirectby creating two namespaces with two veth peers, then forward packets in-between.Signed-off-by William Tu <[email protected]>Cc Daniel Borkmann <[email protected]>Cc John Fastabend <[email protected]>
Acked-by Daniel Borkmann <[email protected]>
Quoted 7 lines · William Tu
Add test for
xdp_redirectby creating two namespaces with two veth peers, then forward packets in-between.Signed-off-by William Tu <[email protected]>Cc Daniel Borkmann <[email protected]>Cc John Fastabend <[email protected]>---
Thanks for doing this.
Acked-by John Fastabend <[email protected]>
From: William Tu <[email protected]>
Date: Mon, 7 Aug 2017 13:14:42 -0700
Quoted 4 lines
Add test for
xdp_redirectby creating two namespaces with two veth peers, then forward packets in-between.Signed-off-by William Tu <[email protected]>
Applied, thank you.