netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect
@ 2020-07-29  8:56 Hangbin Liu
  2020-07-29 20:59 ` Song Liu
  0 siblings, 1 reply; 4+ messages in thread
From: Hangbin Liu @ 2020-07-29  8:56 UTC (permalink / raw)
  To: netdev; +Cc: William Tu, Daniel Borkmann, David S . Miller, Hangbin Liu

This patch add xdpdrv mode for test_xdp_redirect.sh since veth has
support native mode. After update here is the test result:

]# ./test_xdp_redirect.sh
selftests: test_xdp_redirect xdpgeneric [PASS]
selftests: test_xdp_redirect xdpdrv [PASS]

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 .../selftests/bpf/test_xdp_redirect.sh        | 84 ++++++++++++-------
 1 file changed, 52 insertions(+), 32 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_xdp_redirect.sh b/tools/testing/selftests/bpf/test_xdp_redirect.sh
index c4b17e08d431..dd80f0c84afb 100755
--- a/tools/testing/selftests/bpf/test_xdp_redirect.sh
+++ b/tools/testing/selftests/bpf/test_xdp_redirect.sh
@@ -10,52 +10,72 @@
 #     | xdp forwarding |
 #     ------------------
 
-cleanup()
+ret=0
+
+setup()
 {
-	if [ "$?" = "0" ]; then
-		echo "selftests: test_xdp_redirect [PASS]";
-	else
-		echo "selftests: test_xdp_redirect [FAILED]";
-	fi
 
-	set +e
+	local xdpmode=$1
+
+	ip netns add ns1
+	ip netns add ns2
+
+	ip link add veth1 index 111 type veth peer name veth11 netns ns1
+	ip link add veth2 index 222 type veth peer name veth22 netns ns2
+
+	ip link set veth1 up
+	ip link set veth2 up
+	ip -n ns1 link set dev veth11 up
+	ip -n ns2 link set dev veth22 up
+
+	ip -n ns1 addr add 10.1.1.11/24 dev veth11
+	ip -n ns2 addr add 10.1.1.22/24 dev veth22
+}
+
+cleanup()
+{
 	ip link del veth1 2> /dev/null
 	ip link del veth2 2> /dev/null
 	ip netns del ns1 2> /dev/null
 	ip netns del ns2 2> /dev/null
 }
 
-ip link set dev lo xdpgeneric off 2>/dev/null > /dev/null
-if [ $? -ne 0 ];then
-	echo "selftests: [SKIP] Could not run test without the ip xdpgeneric support"
-	exit 0
-fi
-set -e
-
-ip netns add ns1
-ip netns add ns2
+test_xdp_redirect()
+{
+	local xdpmode=$1
 
-trap cleanup 0 2 3 6 9
+	setup
 
-ip link add veth1 index 111 type veth peer name veth11
-ip link add veth2 index 222 type veth peer name veth22
+	ip link set dev veth1 $xdpmode off &> /dev/null
+	if [ $? -ne 0 ];then
+		echo "selftests: test_xdp_redirect $xdpmode [SKIP]"
+		return 0
+	fi
 
-ip link set veth11 netns ns1
-ip link set veth22 netns ns2
+	ip -n ns1 link set veth11 $xdpmode obj xdp_dummy.o sec xdp_dummy &> /dev/null
+	ip -n ns2 link set veth22 $xdpmode obj xdp_dummy.o sec xdp_dummy &> /dev/null
+	ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null
+	ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null
 
-ip link set veth1 up
-ip link set veth2 up
+	ip netns exec ns1 ping -c 1 10.1.1.22 &> /dev/null
+	local ret1=$?
+	ip netns exec ns2 ping -c 1 10.1.1.11 &> /dev/null
+	local ret2=$?
 
-ip netns exec ns1 ip addr add 10.1.1.11/24 dev veth11
-ip netns exec ns2 ip addr add 10.1.1.22/24 dev veth22
+	if [ $ret1 -eq 0 -a $ret2 -eq 0 ]; then
+		echo "selftests: test_xdp_redirect $xdpmode [PASS]";
+	else
+		ret=1
+		echo "selftests: test_xdp_redirect $xdpmode [FAILED]";
+	fi
 
-ip netns exec ns1 ip link set dev veth11 up
-ip netns exec ns2 ip link set dev veth22 up
+	cleanup
+}
 
-ip link set dev veth1 xdpgeneric obj test_xdp_redirect.o sec redirect_to_222
-ip link set dev veth2 xdpgeneric obj test_xdp_redirect.o sec redirect_to_111
+set -e
+trap cleanup 2 3 6 9
 
-ip netns exec ns1 ping -c 1 10.1.1.22
-ip netns exec ns2 ping -c 1 10.1.1.11
+test_xdp_redirect xdpgeneric
+test_xdp_redirect xdpdrv
 
-exit 0
+exit $ret
-- 
2.25.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect
  2020-07-29  8:56 [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect Hangbin Liu
@ 2020-07-29 20:59 ` Song Liu
  2020-07-29 21:06   ` William Tu
  0 siblings, 1 reply; 4+ messages in thread
From: Song Liu @ 2020-07-29 20:59 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: Networking, William Tu, Daniel Borkmann, David S . Miller

On Wed, Jul 29, 2020 at 1:59 AM Hangbin Liu <liuhangbin@gmail.com> wrote:
>
> This patch add xdpdrv mode for test_xdp_redirect.sh since veth has
> support native mode. After update here is the test result:
>
> ]# ./test_xdp_redirect.sh
> selftests: test_xdp_redirect xdpgeneric [PASS]
> selftests: test_xdp_redirect xdpdrv [PASS]
>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>

Acked-by: Song Liu <songliubraving@fb.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect
  2020-07-29 20:59 ` Song Liu
@ 2020-07-29 21:06   ` William Tu
  2020-07-29 22:57     ` Daniel Borkmann
  0 siblings, 1 reply; 4+ messages in thread
From: William Tu @ 2020-07-29 21:06 UTC (permalink / raw)
  To: Song Liu; +Cc: Hangbin Liu, Networking, Daniel Borkmann, David S . Miller

On Wed, Jul 29, 2020 at 1:59 PM Song Liu <song@kernel.org> wrote:
>
> On Wed, Jul 29, 2020 at 1:59 AM Hangbin Liu <liuhangbin@gmail.com> wrote:
> >
> > This patch add xdpdrv mode for test_xdp_redirect.sh since veth has
> > support native mode. After update here is the test result:
> >
> > ]# ./test_xdp_redirect.sh
> > selftests: test_xdp_redirect xdpgeneric [PASS]
> > selftests: test_xdp_redirect xdpdrv [PASS]
> >
> > Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>
> Acked-by: Song Liu <songliubraving@fb.com>
LGTM.
Acked-by: William Tu <u9012063@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect
  2020-07-29 21:06   ` William Tu
@ 2020-07-29 22:57     ` Daniel Borkmann
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2020-07-29 22:57 UTC (permalink / raw)
  To: William Tu, Song Liu; +Cc: Hangbin Liu, Networking, David S . Miller

On 7/29/20 11:06 PM, William Tu wrote:
> On Wed, Jul 29, 2020 at 1:59 PM Song Liu <song@kernel.org> wrote:
>> On Wed, Jul 29, 2020 at 1:59 AM Hangbin Liu <liuhangbin@gmail.com> wrote:
>>>
>>> This patch add xdpdrv mode for test_xdp_redirect.sh since veth has
>>> support native mode. After update here is the test result:
>>>
>>> ]# ./test_xdp_redirect.sh
>>> selftests: test_xdp_redirect xdpgeneric [PASS]
>>> selftests: test_xdp_redirect xdpdrv [PASS]
>>>
>>> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
>>
>> Acked-by: Song Liu <songliubraving@fb.com>
> LGTM.
> Acked-by: William Tu <u9012063@gmail.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-29 22:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29  8:56 [PATCH net] selftests/bpf: add xdpdrv mode for test_xdp_redirect Hangbin Liu
2020-07-29 20:59 ` Song Liu
2020-07-29 21:06   ` William Tu
2020-07-29 22:57     ` Daniel Borkmann

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).