Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <juntong.deng@outlook.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Juntong Deng and committed by
David S. Miller
ced33ca0 ac28b1ec

+14 -12
+14 -12
tools/testing/selftests/net/bind_bhash.sh
··· 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 4 NR_FILES=32768 5 - SAVED_NR_FILES=$(ulimit -n) 5 + readonly NETNS="ns-$(mktemp -u XXXXXX)" 6 6 7 7 # default values 8 8 port=443 ··· 36 36 done 37 37 38 38 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 + 39 45 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 41 47 else 42 - ip addr add $addr_v4 dev lo 48 + ip -netns "${NETNS}" addr add $addr_v4 dev lo 43 49 fi 44 - ulimit -n $NR_FILES 45 50 } 46 51 47 52 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}" 54 54 } 55 55 56 56 if [[ "$addr" != "" ]]; then ··· 59 59 fi 60 60 setup 61 61 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}" 63 64 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}" 65 67 fi 66 68 cleanup