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

selftests: netfilter: simplify command testing

Fix some shellcheck SC2181 warnings:
"Check exit code directly with e.g. 'if mycmd;', not indirectly with
$?." as suggested by Stefano Brivio.

Signed-off-by: Fabian Frederick <fabf@skynet.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Fabian Frederick and committed by
Pablo Neira Ayuso
2f4bba4e d721b686

+11 -23
+11 -23
tools/testing/selftests/netfilter/nft_flowtable.sh
··· 27 27 log_netns=$(sysctl -n net.netfilter.nf_log_all_netns) 28 28 29 29 checktool (){ 30 - $1 > /dev/null 2>&1 31 - if [ $? -ne 0 ];then 30 + if ! $1 > /dev/null 2>&1; then 32 31 echo "SKIP: Could not $2" 33 32 exit $ksft_skip 34 33 fi ··· 186 187 fi 187 188 188 189 # test basic connectivity 189 - ip netns exec ns1 ping -c 1 -q 10.0.2.99 > /dev/null 190 - if [ $? -ne 0 ];then 190 + if ! ip netns exec ns1 ping -c 1 -q 10.0.2.99 > /dev/null; then 191 191 echo "ERROR: ns1 cannot reach ns2" 1>&2 192 192 bash 193 193 exit 1 194 194 fi 195 195 196 - ip netns exec ns2 ping -c 1 -q 10.0.1.99 > /dev/null 197 - if [ $? -ne 0 ];then 196 + if ! ip netns exec ns2 ping -c 1 -q 10.0.1.99 > /dev/null; then 198 197 echo "ERROR: ns2 cannot reach ns1" 1>&2 199 198 exit 1 200 199 fi ··· 227 230 out=$2 228 231 what=$3 229 232 230 - cmp "$in" "$out" > /dev/null 2>&1 231 - if [ $? -ne 0 ] ;then 233 + if ! cmp "$in" "$out" > /dev/null 2>&1; then 232 234 echo "FAIL: file mismatch for $what" 1>&2 233 235 ls -l "$in" 234 236 ls -l "$out" ··· 264 268 265 269 wait 266 270 267 - check_transfer "$ns1in" "$ns2out" "ns1 -> ns2" 268 - if [ $? -ne 0 ];then 271 + if ! check_transfer "$ns1in" "$ns2out" "ns1 -> ns2"; then 269 272 lret=1 270 273 fi 271 274 272 - check_transfer "$ns2in" "$ns1out" "ns1 <- ns2" 273 - if [ $? -ne 0 ];then 275 + if ! check_transfer "$ns2in" "$ns1out" "ns1 <- ns2"; then 274 276 lret=1 275 277 fi 276 278 ··· 302 308 303 309 # First test: 304 310 # No PMTU discovery, nsr1 is expected to fragment packets from ns1 to ns2 as needed. 305 - test_tcp_forwarding ns1 ns2 306 - if [ $? -eq 0 ] ;then 311 + if test_tcp_forwarding ns1 ns2; then 307 312 echo "PASS: flow offloaded for ns1/ns2" 308 313 else 309 314 echo "FAIL: flow offload for ns1/ns2:" 1>&2 ··· 333 340 } 334 341 EOF 335 342 336 - test_tcp_forwarding_nat ns1 ns2 337 - 338 - if [ $? -eq 0 ] ;then 343 + if test_tcp_forwarding_nat ns1 ns2; then 339 344 echo "PASS: flow offloaded for ns1/ns2 with NAT" 340 345 else 341 346 echo "FAIL: flow offload for ns1/ns2 with NAT" 1>&2 ··· 345 354 # Same as second test, but with PMTU discovery enabled. 346 355 handle=$(ip netns exec nsr1 nft -a list table inet filter | grep something-to-grep-for | cut -d \# -f 2) 347 356 348 - ip netns exec nsr1 nft delete rule inet filter forward $handle 349 - if [ $? -ne 0 ] ;then 357 + if ! ip netns exec nsr1 nft delete rule inet filter forward $handle; then 350 358 echo "FAIL: Could not delete large-packet accept rule" 351 359 exit 1 352 360 fi ··· 353 363 ip netns exec ns1 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null 354 364 ip netns exec ns2 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null 355 365 356 - test_tcp_forwarding_nat ns1 ns2 357 - if [ $? -eq 0 ] ;then 366 + if test_tcp_forwarding_nat ns1 ns2; then 358 367 echo "PASS: flow offloaded for ns1/ns2 with NAT and pmtu discovery" 359 368 else 360 369 echo "FAIL: flow offload for ns1/ns2 with NAT and pmtu discovery" 1>&2 ··· 399 410 ip -net ns2 route add default via 10.0.2.1 400 411 ip -net ns2 route add default via dead:2::1 401 412 402 - test_tcp_forwarding ns1 ns2 403 - if [ $? -eq 0 ] ;then 413 + if test_tcp_forwarding ns1 ns2; then 404 414 echo "PASS: ipsec tunnel mode for ns1/ns2" 405 415 else 406 416 echo "FAIL: ipsec tunnel mode for ns1/ns2"