Skip to content

Commit

Permalink
selftests/net/lib: no need to record ns name if it already exist
Browse files Browse the repository at this point in the history
There is no need to add the name to ns_list again if the netns already
recoreded.

Fixes: 25ae948 ("selftests/net: add lib.sh")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
liuhangbin authored and davem330 committed May 16, 2024
1 parent fd76e5c commit 83e9394
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/testing/selftests/net/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,17 @@ setup_ns()
local ns=""
local ns_name=""
local ns_list=""
local ns_exist=
for ns_name in "$@"; do
# Some test may setup/remove same netns multi times
if unset ${ns_name} 2> /dev/null; then
ns="${ns_name,,}-$(mktemp -u XXXXXX)"
eval readonly ${ns_name}="$ns"
ns_exist=false
else
eval ns='$'${ns_name}
cleanup_ns "$ns"

ns_exist=true
fi

if ! ip netns add "$ns"; then
Expand All @@ -144,7 +146,7 @@ setup_ns()
return $ksft_skip
fi
ip -n "$ns" link set lo up
ns_list="$ns_list $ns"
! $ns_exist && ns_list="$ns_list $ns"
done
NS_LIST="$NS_LIST $ns_list"
}

0 comments on commit 83e9394

Please sign in to comment.