From: William Tu Subject: [PATCH bpf-next RFCv3 6/6] samples: bpf: add veth AF_XDP example. Date: Wed, 26 Dec 2018 12:27:53 -0800 Message-ID: <1545856073-8680-7-git-send-email-u9012063@gmail.com> References: <1545856073-8680-1-git-send-email-u9012063@gmail.com> To: bjorn.topel@gmail.com, magnus.karlsson@gmail.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, makita.toshiaki@lab.ntt.co.jp, yihung.wei@gmail.com, magnus.karlsson@intel.com Return-path: Received: from mail-pf1-f196.google.com ([209.85.210.196]:40665 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbeLZU20 (ORCPT ); Wed, 26 Dec 2018 15:28:26 -0500 Received: by mail-pf1-f196.google.com with SMTP id i12so8218833pfo.7 for ; Wed, 26 Dec 2018 12:28:25 -0800 (PST) In-Reply-To: <1545856073-8680-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Add example use cases for AF_XDP socket on two namespaces. The script runs sender at the root namespace, and receiver at the at_ns0 namespace with different XDP actions. Signed-off-by: William Tu --- samples/bpf/test_veth_afxdp.sh | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 samples/bpf/test_veth_afxdp.sh diff --git a/samples/bpf/test_veth_afxdp.sh b/samples/bpf/test_veth_afxdp.sh new file mode 100755 index 000000000000..d51c6031db47 --- /dev/null +++ b/samples/bpf/test_veth_afxdp.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# The script runs the sender at the root namespace, and +# the receiver at the namespace at_ns0, with different mode +# 1. XDP_DROP +# 2. XDP_TX +# 3. XDP_PASS +# 4. XDP_REDIRECT +# 5. Generic XDP + +XDPSOCK=./xdpsock +XDP_RXQ_INFO=./xdp_rxq_info + +ip netns add at_ns0 +ip link add p0 type veth peer name p1 +ip link set p0 netns at_ns0 +ip link set dev p1 up +ip netns exec at_ns0 ip link set dev p0 up + +test_xdp_drop() +{ + echo "[Peer] XDP_DROP" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_DROP & +} + +test_xdp_pass() +{ + echo "[Peer] XDP_PASS" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_PASS & +} + +test_xdp_tx() +{ + echo "[Peer] XDP_TX" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_TX & +} + +test_generic_xdp() +{ + echo "[Peer] Generic XDP" + ip netns exec at_ns0 $XDPSOCK -i p0 -r -S & +} + +test_xdp_redirect() +{ + echo "[Peer] XDP_REDIRECT" + ip netns exec at_ns0 $XDPSOCK -i p0 -r -N & +} + +test_xdp_zcrx() +{ + echo "[Peer] AF_XDP RX" + ip netns exec at_ns0 $XDPSOCK -i p0 -r -N -z & +} + +cleanup() { + killall xdpsock + sleep 1 + killall xdp_rxq_info + ip netns del at_ns0 + ip link del p1 +} + +trap cleanup 0 3 6 + +if [ "$1" == "drop" ]; then + test_xdp_drop +elif [ "$1" == "pass" ]; then + test_xdp_pass +elif [ "$1" == "tx" ]; then + test_xdp_tx +elif [ "$1" == "redirect" ]; then + test_xdp_redirect +elif [ "$1" == "zcrx" ]; then + test_xdp_zcrx +else + test_xdp_drop +fi + +# send at root namespace +$XDPSOCK -i p1 -t -N -z -- 2.7.4