selftests: netfilter: remove unused cnt and simplify command testing
authorFabian Frederick <fabf@skynet.be>
Wed, 9 Sep 2020 18:26:24 +0000 (20:26 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 21 Sep 2020 23:55:11 +0000 (01:55 +0200)
cnt was not used in nft_meta.sh
This patch also fixes 2 shellcheck SC2181 warnings:
"check exit code directly with e.g. 'if mycmd;', not indirectly with
$?."

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tools/testing/selftests/netfilter/nft_meta.sh

index 1f5b46542c14c661468eddb781b5bb33a6cc08ff..18a1abca326290f14ed33b6dc39c0de1a9fb2b8a 100755 (executable)
@@ -7,8 +7,7 @@ ksft_skip=4
 sfx=$(mktemp -u "XXXXXXXX")
 ns0="ns0-$sfx"
 
-nft --version > /dev/null 2>&1
-if [ $? -ne 0 ];then
+if ! nft --version > /dev/null 2>&1; then
        echo "SKIP: Could not run test without nft tool"
        exit $ksft_skip
 fi
@@ -86,8 +85,7 @@ check_one_counter()
        local want="packets $2"
        local verbose="$3"
 
-       cnt=$(ip netns exec "$ns0" nft list counter inet filter $cname | grep -q "$want")
-       if [ $? -ne 0 ];then
+       if ! ip netns exec "$ns0" nft list counter inet filter $cname | grep -q "$want"; then
                echo "FAIL: $cname, want \"$want\", got"
                ret=1
                ip netns exec "$ns0" nft list counter inet filter $cname