2 # SPDX-License-Identifier: GPL-2.0
4 ##############################################################################
7 WAIT_TIMEOUT=${WAIT_TIMEOUT:=20}
8 BUSYWAIT_TIMEOUT=$((WAIT_TIMEOUT * 1000)) # ms
10 # Kselftest framework requirement - SKIP code is 4.
12 # namespace list created by setup_ns
15 ##############################################################################
19 local timeout=$1; shift
21 local start_time="$(date -u +%s%3N)"
32 local current_time="$(date -u +%s%3N)"
33 if ((current_time - start_time > timeout)); then
46 # disable errexit temporary
47 if [[ $- =~ "e" ]]; then
53 ip netns delete "${ns}" &> /dev/null
54 if ! busywait $BUSYWAIT_TIMEOUT ip netns list \| grep -vq "^$ns$" &> /dev/null; then
55 echo "Warn: Failed to remove namespace $ns"
60 [ $errexit -eq 1 ] && set -e
69 # setup netns with given names as prefix. e.g
70 # setup_ns local remote
76 for ns_name in "$@"; do
77 # Some test may setup/remove same netns multi times
78 if unset ${ns_name} 2> /dev/null; then
79 ns="${ns_name,,}-$(mktemp -u XXXXXX)"
80 eval readonly ${ns_name}="$ns"
87 if ! ip netns add "$ns"; then
88 echo "Failed to create namespace $ns_name"
92 ip -n "$ns" link set lo up
93 ns_list="$ns_list $ns"
95 NS_LIST="$NS_LIST $ns_list"