Commit 2f4bba4e authored by Fabian Frederick's avatar Fabian Frederick Committed by Pablo Neira Ayuso

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: default avatarFabian Frederick <fabf@skynet.be>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent d721b686
...@@ -27,8 +27,7 @@ ns2out="" ...@@ -27,8 +27,7 @@ ns2out=""
log_netns=$(sysctl -n net.netfilter.nf_log_all_netns) log_netns=$(sysctl -n net.netfilter.nf_log_all_netns)
checktool (){ checktool (){
$1 > /dev/null 2>&1 if ! $1 > /dev/null 2>&1; then
if [ $? -ne 0 ];then
echo "SKIP: Could not $2" echo "SKIP: Could not $2"
exit $ksft_skip exit $ksft_skip
fi fi
...@@ -187,15 +186,13 @@ if [ $? -ne 0 ]; then ...@@ -187,15 +186,13 @@ if [ $? -ne 0 ]; then
fi fi
# test basic connectivity # test basic connectivity
ip netns exec ns1 ping -c 1 -q 10.0.2.99 > /dev/null if ! ip netns exec ns1 ping -c 1 -q 10.0.2.99 > /dev/null; then
if [ $? -ne 0 ];then
echo "ERROR: ns1 cannot reach ns2" 1>&2 echo "ERROR: ns1 cannot reach ns2" 1>&2
bash bash
exit 1 exit 1
fi fi
ip netns exec ns2 ping -c 1 -q 10.0.1.99 > /dev/null if ! ip netns exec ns2 ping -c 1 -q 10.0.1.99 > /dev/null; then
if [ $? -ne 0 ];then
echo "ERROR: ns2 cannot reach ns1" 1>&2 echo "ERROR: ns2 cannot reach ns1" 1>&2
exit 1 exit 1
fi fi
...@@ -230,8 +227,7 @@ check_transfer() ...@@ -230,8 +227,7 @@ check_transfer()
out=$2 out=$2
what=$3 what=$3
cmp "$in" "$out" > /dev/null 2>&1 if ! cmp "$in" "$out" > /dev/null 2>&1; then
if [ $? -ne 0 ] ;then
echo "FAIL: file mismatch for $what" 1>&2 echo "FAIL: file mismatch for $what" 1>&2
ls -l "$in" ls -l "$in"
ls -l "$out" ls -l "$out"
...@@ -268,13 +264,11 @@ test_tcp_forwarding_ip() ...@@ -268,13 +264,11 @@ test_tcp_forwarding_ip()
wait wait
check_transfer "$ns1in" "$ns2out" "ns1 -> ns2" if ! check_transfer "$ns1in" "$ns2out" "ns1 -> ns2"; then
if [ $? -ne 0 ];then
lret=1 lret=1
fi fi
check_transfer "$ns2in" "$ns1out" "ns1 <- ns2" if ! check_transfer "$ns2in" "$ns1out" "ns1 <- ns2"; then
if [ $? -ne 0 ];then
lret=1 lret=1
fi fi
...@@ -308,8 +302,7 @@ make_file "$ns2in" ...@@ -308,8 +302,7 @@ make_file "$ns2in"
# First test: # First test:
# No PMTU discovery, nsr1 is expected to fragment packets from ns1 to ns2 as needed. # No PMTU discovery, nsr1 is expected to fragment packets from ns1 to ns2 as needed.
test_tcp_forwarding ns1 ns2 if test_tcp_forwarding ns1 ns2; then
if [ $? -eq 0 ] ;then
echo "PASS: flow offloaded for ns1/ns2" echo "PASS: flow offloaded for ns1/ns2"
else else
echo "FAIL: flow offload for ns1/ns2:" 1>&2 echo "FAIL: flow offload for ns1/ns2:" 1>&2
...@@ -340,9 +333,7 @@ table ip nat { ...@@ -340,9 +333,7 @@ table ip nat {
} }
EOF EOF
test_tcp_forwarding_nat ns1 ns2 if test_tcp_forwarding_nat ns1 ns2; then
if [ $? -eq 0 ] ;then
echo "PASS: flow offloaded for ns1/ns2 with NAT" echo "PASS: flow offloaded for ns1/ns2 with NAT"
else else
echo "FAIL: flow offload for ns1/ns2 with NAT" 1>&2 echo "FAIL: flow offload for ns1/ns2 with NAT" 1>&2
...@@ -354,8 +345,7 @@ fi ...@@ -354,8 +345,7 @@ fi
# Same as second test, but with PMTU discovery enabled. # Same as second test, but with PMTU discovery enabled.
handle=$(ip netns exec nsr1 nft -a list table inet filter | grep something-to-grep-for | cut -d \# -f 2) handle=$(ip netns exec nsr1 nft -a list table inet filter | grep something-to-grep-for | cut -d \# -f 2)
ip netns exec nsr1 nft delete rule inet filter forward $handle if ! ip netns exec nsr1 nft delete rule inet filter forward $handle; then
if [ $? -ne 0 ] ;then
echo "FAIL: Could not delete large-packet accept rule" echo "FAIL: Could not delete large-packet accept rule"
exit 1 exit 1
fi fi
...@@ -363,8 +353,7 @@ fi ...@@ -363,8 +353,7 @@ fi
ip netns exec ns1 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null ip netns exec ns1 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null
ip netns exec ns2 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null ip netns exec ns2 sysctl net.ipv4.ip_no_pmtu_disc=0 > /dev/null
test_tcp_forwarding_nat ns1 ns2 if test_tcp_forwarding_nat ns1 ns2; then
if [ $? -eq 0 ] ;then
echo "PASS: flow offloaded for ns1/ns2 with NAT and pmtu discovery" echo "PASS: flow offloaded for ns1/ns2 with NAT and pmtu discovery"
else else
echo "FAIL: flow offload for ns1/ns2 with NAT and pmtu discovery" 1>&2 echo "FAIL: flow offload for ns1/ns2 with NAT and pmtu discovery" 1>&2
...@@ -410,8 +399,7 @@ ip -net ns2 route del 192.168.10.1 via 10.0.2.1 ...@@ -410,8 +399,7 @@ ip -net ns2 route del 192.168.10.1 via 10.0.2.1
ip -net ns2 route add default via 10.0.2.1 ip -net ns2 route add default via 10.0.2.1
ip -net ns2 route add default via dead:2::1 ip -net ns2 route add default via dead:2::1
test_tcp_forwarding ns1 ns2 if test_tcp_forwarding ns1 ns2; then
if [ $? -eq 0 ] ;then
echo "PASS: ipsec tunnel mode for ns1/ns2" echo "PASS: ipsec tunnel mode for ns1/ns2"
else else
echo "FAIL: ipsec tunnel mode for ns1/ns2" echo "FAIL: ipsec tunnel mode for ns1/ns2"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment