xref: /openbmc/linux/tools/testing/selftests/bpf/test_xdp_features.sh (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1*4dba3e78SLorenzo Bianconi#!/bin/bash
2*4dba3e78SLorenzo Bianconi# SPDX-License-Identifier: GPL-2.0
3*4dba3e78SLorenzo Bianconi
4*4dba3e78SLorenzo Bianconireadonly NS="ns1-$(mktemp -u XXXXXX)"
5*4dba3e78SLorenzo Bianconireadonly V0_IP4=10.10.0.11
6*4dba3e78SLorenzo Bianconireadonly V1_IP4=10.10.0.1
7*4dba3e78SLorenzo Bianconireadonly V0_IP6=2001:db8::11
8*4dba3e78SLorenzo Bianconireadonly V1_IP6=2001:db8::1
9*4dba3e78SLorenzo Bianconi
10*4dba3e78SLorenzo Bianconiret=1
11*4dba3e78SLorenzo Bianconi
12*4dba3e78SLorenzo Bianconisetup() {
13*4dba3e78SLorenzo Bianconi	{
14*4dba3e78SLorenzo Bianconi		ip netns add ${NS}
15*4dba3e78SLorenzo Bianconi
16*4dba3e78SLorenzo Bianconi		ip link add v1 type veth peer name v0 netns ${NS}
17*4dba3e78SLorenzo Bianconi
18*4dba3e78SLorenzo Bianconi		ip link set v1 up
19*4dba3e78SLorenzo Bianconi		ip addr add $V1_IP4/24 dev v1
20*4dba3e78SLorenzo Bianconi		ip addr add $V1_IP6/64 nodad dev v1
21*4dba3e78SLorenzo Bianconi		ip -n ${NS} link set dev v0 up
22*4dba3e78SLorenzo Bianconi		ip -n ${NS} addr add $V0_IP4/24 dev v0
23*4dba3e78SLorenzo Bianconi		ip -n ${NS} addr add $V0_IP6/64 nodad dev v0
24*4dba3e78SLorenzo Bianconi
25*4dba3e78SLorenzo Bianconi		# Enable XDP mode and disable checksum offload
26*4dba3e78SLorenzo Bianconi		ethtool -K v1 gro on
27*4dba3e78SLorenzo Bianconi		ethtool -K v1 tx-checksumming off
28*4dba3e78SLorenzo Bianconi		ip netns exec ${NS} ethtool -K v0 gro on
29*4dba3e78SLorenzo Bianconi		ip netns exec ${NS} ethtool -K v0 tx-checksumming off
30*4dba3e78SLorenzo Bianconi	} > /dev/null 2>&1
31*4dba3e78SLorenzo Bianconi}
32*4dba3e78SLorenzo Bianconi
33*4dba3e78SLorenzo Bianconicleanup() {
34*4dba3e78SLorenzo Bianconi	ip link del v1 2> /dev/null
35*4dba3e78SLorenzo Bianconi	ip netns del ${NS} 2> /dev/null
36*4dba3e78SLorenzo Bianconi	[ "$(pidof xdp_features)" = "" ] || kill $(pidof xdp_features) 2> /dev/null
37*4dba3e78SLorenzo Bianconi}
38*4dba3e78SLorenzo Bianconi
39*4dba3e78SLorenzo Bianconiwait_for_dut_server() {
40*4dba3e78SLorenzo Bianconi	while sleep 1; do
41*4dba3e78SLorenzo Bianconi		ss -tlp | grep -q xdp_features
42*4dba3e78SLorenzo Bianconi		[ $? -eq 0 ] && break
43*4dba3e78SLorenzo Bianconi	done
44*4dba3e78SLorenzo Bianconi}
45*4dba3e78SLorenzo Bianconi
46*4dba3e78SLorenzo Bianconitest_xdp_features() {
47*4dba3e78SLorenzo Bianconi	setup
48*4dba3e78SLorenzo Bianconi
49*4dba3e78SLorenzo Bianconi	## XDP_PASS
50*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_PASS -D $V1_IP6 -T $V0_IP6 v1 &
51*4dba3e78SLorenzo Bianconi	wait_for_dut_server
52*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_PASS \
53*4dba3e78SLorenzo Bianconi					   -D $V1_IP6 -C $V1_IP6 \
54*4dba3e78SLorenzo Bianconi					   -T $V0_IP6 v0
55*4dba3e78SLorenzo Bianconi	[ $? -ne 0 ] && exit
56*4dba3e78SLorenzo Bianconi
57*4dba3e78SLorenzo Bianconi	## XDP_DROP
58*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_DROP -D ::ffff:$V1_IP4 -T ::ffff:$V0_IP4 v1 &
59*4dba3e78SLorenzo Bianconi	wait_for_dut_server
60*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_DROP \
61*4dba3e78SLorenzo Bianconi					   -D ::ffff:$V1_IP4 \
62*4dba3e78SLorenzo Bianconi					   -C ::ffff:$V1_IP4 \
63*4dba3e78SLorenzo Bianconi					   -T ::ffff:$V0_IP4 v0
64*4dba3e78SLorenzo Bianconi	[ $? -ne 0 ] && exit
65*4dba3e78SLorenzo Bianconi
66*4dba3e78SLorenzo Bianconi	## XDP_ABORTED
67*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_ABORTED -D $V1_IP6 -T $V0_IP6 v1 &
68*4dba3e78SLorenzo Bianconi	wait_for_dut_server
69*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_ABORTED \
70*4dba3e78SLorenzo Bianconi					   -D $V1_IP6 -C $V1_IP6 \
71*4dba3e78SLorenzo Bianconi					   -T $V0_IP6 v0
72*4dba3e78SLorenzo Bianconi	[ $? -ne 0 ] && exit
73*4dba3e78SLorenzo Bianconi
74*4dba3e78SLorenzo Bianconi	## XDP_TX
75*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_TX -D ::ffff:$V1_IP4 -T ::ffff:$V0_IP4 v1 &
76*4dba3e78SLorenzo Bianconi	wait_for_dut_server
77*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_TX \
78*4dba3e78SLorenzo Bianconi					   -D ::ffff:$V1_IP4 \
79*4dba3e78SLorenzo Bianconi					   -C ::ffff:$V1_IP4 \
80*4dba3e78SLorenzo Bianconi					   -T ::ffff:$V0_IP4 v0
81*4dba3e78SLorenzo Bianconi	[ $? -ne 0 ] && exit
82*4dba3e78SLorenzo Bianconi
83*4dba3e78SLorenzo Bianconi	## XDP_REDIRECT
84*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_REDIRECT -D $V1_IP6 -T $V0_IP6 v1 &
85*4dba3e78SLorenzo Bianconi	wait_for_dut_server
86*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_REDIRECT \
87*4dba3e78SLorenzo Bianconi					   -D $V1_IP6 -C $V1_IP6 \
88*4dba3e78SLorenzo Bianconi					   -T $V0_IP6 v0
89*4dba3e78SLorenzo Bianconi	[ $? -ne 0 ] && exit
90*4dba3e78SLorenzo Bianconi
91*4dba3e78SLorenzo Bianconi	## XDP_NDO_XMIT
92*4dba3e78SLorenzo Bianconi	./xdp_features -f XDP_NDO_XMIT -D ::ffff:$V1_IP4 -T ::ffff:$V0_IP4 v1 &
93*4dba3e78SLorenzo Bianconi	wait_for_dut_server
94*4dba3e78SLorenzo Bianconi	ip netns exec ${NS} ./xdp_features -t -f XDP_NDO_XMIT \
95*4dba3e78SLorenzo Bianconi					   -D ::ffff:$V1_IP4 \
96*4dba3e78SLorenzo Bianconi					   -C ::ffff:$V1_IP4 \
97*4dba3e78SLorenzo Bianconi					   -T ::ffff:$V0_IP4 v0
98*4dba3e78SLorenzo Bianconi	ret=$?
99*4dba3e78SLorenzo Bianconi	cleanup
100*4dba3e78SLorenzo Bianconi}
101*4dba3e78SLorenzo Bianconi
102*4dba3e78SLorenzo Bianconiset -e
103*4dba3e78SLorenzo Bianconitrap cleanup 2 3 6 9
104*4dba3e78SLorenzo Bianconi
105*4dba3e78SLorenzo Bianconitest_xdp_features
106*4dba3e78SLorenzo Bianconi
107*4dba3e78SLorenzo Bianconiexit $ret
108