From: William Tu Subject: [bpf-next RFCv2 3/3] samples: bpf: add veth AF_XDP example. Date: Tue, 18 Dec 2018 17:04:53 -0800 Message-ID: <1545181493-8743-4-git-send-email-u9012063@gmail.com> References: <1545181493-8743-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 Return-path: Received: from mail-pg1-f181.google.com ([209.85.215.181]:40634 "EHLO mail-pg1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726629AbeLSAzQ (ORCPT ); Tue, 18 Dec 2018 19:55:16 -0500 Received: by mail-pg1-f181.google.com with SMTP id z10so8618488pgp.7 for ; Tue, 18 Dec 2018 16:55:15 -0800 (PST) In-Reply-To: <1545181493-8743-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 | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 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..b65311cf15f7 --- /dev/null +++ b/samples/bpf/test_veth_afxdp.sh @@ -0,0 +1,67 @@ +#!/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 + +# send at root namespace +test_xdp_drop() +{ + echo "[Peer] XDP_DROP" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_DROP & + $XDPSOCK -i p1 -t -N -z &> /tmp/t &> /dev/null & +} + +test_xdp_pass() +{ + echo "[Peer] XDP_PASS" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_PASS & + $XDPSOCK -i p1 -t -N -z &> /tmp/t &> /dev/null & +} + +test_xdp_tx() +{ + echo "[Peer] XDP_TX" + ip netns exec at_ns0 $XDP_RXQ_INFO --dev p0 --action XDP_TX & + $XDPSOCK -i p1 -t -N -z &> /tmp/t &> /dev/null & +} + +test_generic_xdp() +{ + echo "[Peer] Generic XDP" + ip netns exec at_ns0 $XDPSOCK -i p0 -r -S & + $XDPSOCK -i p1 -t -N -z &> /tmp/t &> /dev/null & +} + +test_xdp_redirect() +{ + echo "[Peer] XDP_REDIRECT" + ip netns exec at_ns0 $XDPSOCK -i p0 -r -N & + $XDPSOCK -i p1 -t -N -z &> /tmp/t &> /dev/null & +} + +cleanup() { + killall xdpsock + killall xdp_rxq_info + ip netns del at_ns0 + ip link del p1 +} + +trap cleanup 0 3 6 + +test_xdp_drop +cleanup -- 2.7.4