Skip to content

Commit ced33ca

Browse files
juntongdengdavem330
authored andcommitted
selftests/net: Improve bind_bhash.sh to accommodate predictable network interface names
Starting with v197, systemd uses predictable interface network names, the traditional interface naming scheme (eth0) is deprecated, therefore it cannot be assumed that the eth0 interface exists on the host. This modification makes the bind_bhash test program run in a separate network namespace and no longer needs to consider the name of the network interface on the host. Signed-off-by: Juntong Deng <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ac28b1e commit ced33ca

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

tools/testing/selftests/net/bind_bhash.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: GPL-2.0
33

44
NR_FILES=32768
5-
SAVED_NR_FILES=$(ulimit -n)
5+
readonly NETNS="ns-$(mktemp -u XXXXXX)"
66

77
# default values
88
port=443
@@ -36,21 +36,21 @@ while getopts "ha:p:64" opt; do
3636
done
3737

3838
setup() {
39+
ip netns add "${NETNS}"
40+
ip -netns "${NETNS}" link add veth0 type veth peer name veth1
41+
ip -netns "${NETNS}" link set lo up
42+
ip -netns "${NETNS}" link set veth0 up
43+
ip -netns "${NETNS}" link set veth1 up
44+
3945
if [[ "$use_v6" == true ]]; then
40-
ip addr add $addr_v6 nodad dev eth0
46+
ip -netns "${NETNS}" addr add $addr_v6 nodad dev veth0
4147
else
42-
ip addr add $addr_v4 dev lo
48+
ip -netns "${NETNS}" addr add $addr_v4 dev lo
4349
fi
44-
ulimit -n $NR_FILES
4550
}
4651

4752
cleanup() {
48-
if [[ "$use_v6" == true ]]; then
49-
ip addr del $addr_v6 dev eth0
50-
else
51-
ip addr del $addr_v4/32 dev lo
52-
fi
53-
ulimit -n $SAVED_NR_FILES
53+
ip netns del "${NETNS}"
5454
}
5555

5656
if [[ "$addr" != "" ]]; then
@@ -59,8 +59,10 @@ if [[ "$addr" != "" ]]; then
5959
fi
6060
setup
6161
if [[ "$use_v6" == true ]] ; then
62-
./bind_bhash $port "ipv6" $addr_v6
62+
ip netns exec "${NETNS}" sh -c \
63+
"ulimit -n ${NR_FILES};./bind_bhash ${port} ipv6 ${addr_v6}"
6364
else
64-
./bind_bhash $port "ipv4" $addr_v4
65+
ip netns exec "${NETNS}" sh -c \
66+
"ulimit -n ${NR_FILES};./bind_bhash ${port} ipv4 ${addr_v4}"
6567
fi
6668
cleanup

0 commit comments

Comments
 (0)