aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/test_xdp_redirect.c
diff options
context:
space:
mode:
authorWilliam Tu <u9012063@gmail.com>2017-08-07 13:14:42 -0700
committerDavid S. Miller <davem@davemloft.net>2017-08-08 18:12:50 -0700
commit996139e801fd145bc44b70b4f4bfa621d626f948 (patch)
treee1ff71d5bae264c2b80ea196accb8e54e23827e1 /tools/testing/selftests/bpf/test_xdp_redirect.c
parentliquidio: fix misspelled firmware image filenames (diff)
downloadlinux-dev-996139e801fd145bc44b70b4f4bfa621d626f948.tar.xz
linux-dev-996139e801fd145bc44b70b4f4bfa621d626f948.zip
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 <u9012063@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: John Fastabend <john.fastabend@gmail.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing/selftests/bpf/test_xdp_redirect.c')
-rw-r--r--tools/testing/selftests/bpf/test_xdp_redirect.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_xdp_redirect.c b/tools/testing/selftests/bpf/test_xdp_redirect.c
new file mode 100644
index 000000000000..ef9e704be140
--- /dev/null
+++ b/tools/testing/selftests/bpf/test_xdp_redirect.c
@@ -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";