Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8955c1a

Browse files
liuhangbinborkmann
authored andcommitted
selftests/bpf/xdp_redirect_multi: Limit the tests in netns
As I want to test both DEVMAP and DEVMAP_HASH in XDP multicast redirect, I limited DEVMAP max entries to a small value for performace. When the test runs after amount of interface creating/deleting tests. The interface index will exceed the map max entries and xdp_redirect_multi will error out with "Get interfacesInterface index to large". Fix this issue by limit the tests in netns and specify the ifindex when creating interfaces. Fixes: d232924 ("selftests/bpf: Add xdp_redirect_multi test") Reported-by: Jiri Benc <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 648c367 commit 8955c1a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

tools/testing/selftests/bpf/test_xdp_redirect_multi.sh

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# SPDX-License-Identifier: GPL-2.0
33
#
44
# Test topology:
5-
# - - - - - - - - - - - - - - - - - - - - - - - - -
6-
# | veth1 veth2 veth3 | ... init net
5+
# - - - - - - - - - - - - - - - - - - -
6+
# | veth1 veth2 veth3 | ns0
77
# - -| - - - - - - | - - - - - - | - -
88
# --------- --------- ---------
9-
# | veth0 | | veth0 | | veth0 | ...
9+
# | veth0 | | veth0 | | veth0 |
1010
# --------- --------- ---------
1111
# ns1 ns2 ns3
1212
#
@@ -51,6 +51,7 @@ clean_up()
5151
ip link del veth$i 2> /dev/null
5252
ip netns del ns$i 2> /dev/null
5353
done
54+
ip netns del ns0 2> /dev/null
5455
}
5556

5657
# Kselftest framework requirement - SKIP code is 4.
@@ -78,10 +79,12 @@ setup_ns()
7879
mode="xdpdrv"
7980
fi
8081

82+
ip netns add ns0
8183
for i in $(seq $NUM); do
8284
ip netns add ns$i
83-
ip link add veth$i type veth peer name veth0 netns ns$i
84-
ip link set veth$i up
85+
ip -n ns$i link add veth0 index 2 type veth \
86+
peer name veth$i netns ns0 index $((1 + $i))
87+
ip -n ns0 link set veth$i up
8588
ip -n ns$i link set veth0 up
8689

8790
ip -n ns$i addr add 192.0.2.$i/24 dev veth0
@@ -92,7 +95,7 @@ setup_ns()
9295
xdp_dummy.o sec xdp &> /dev/null || \
9396
{ test_fail "Unable to load dummy xdp" && exit 1; }
9497
IFACES="$IFACES veth$i"
95-
veth_mac[$i]=$(ip link show veth$i | awk '/link\/ether/ {print $2}')
98+
veth_mac[$i]=$(ip -n ns0 link show veth$i | awk '/link\/ether/ {print $2}')
9699
done
97100
}
98101

@@ -177,9 +180,13 @@ do_tests()
177180
xdpgeneric) drv_p="-S";;
178181
esac
179182

180-
./xdp_redirect_multi $drv_p $IFACES &> ${LOG_DIR}/xdp_redirect_${mode}.log &
183+
ip netns exec ns0 ./xdp_redirect_multi $drv_p $IFACES &> ${LOG_DIR}/xdp_redirect_${mode}.log &
181184
xdp_pid=$!
182185
sleep 1
186+
if ! ps -p $xdp_pid > /dev/null; then
187+
test_fail "$mode xdp_redirect_multi start failed"
188+
return 1
189+
fi
183190

184191
if [ "$mode" = "xdpegress" ]; then
185192
do_egress_tests $mode
@@ -190,7 +197,7 @@ do_tests()
190197
kill $xdp_pid
191198
}
192199

193-
trap clean_up 0 2 3 6 9
200+
trap clean_up EXIT
194201

195202
check_env
196203

tools/testing/selftests/bpf/xdp_redirect_multi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int main(int argc, char **argv)
129129
goto err_out;
130130
}
131131

132-
printf("Get interfaces");
132+
printf("Get interfaces:");
133133
for (i = 0; i < MAX_IFACE_NUM && argv[optind + i]; i++) {
134134
ifaces[i] = if_nametoindex(argv[optind + i]);
135135
if (!ifaces[i])
@@ -139,7 +139,7 @@ int main(int argc, char **argv)
139139
goto err_out;
140140
}
141141
if (ifaces[i] > MAX_INDEX_NUM) {
142-
printf("Interface index to large\n");
142+
printf(" interface index too large\n");
143143
goto err_out;
144144
}
145145
printf(" %d", ifaces[i]);

0 commit comments

Comments
 (0)