Skip to content

Commit

Permalink
selftests: netfilter: nft_audit.sh: add more skip checks
Browse files Browse the repository at this point in the history
This testcase doesn't work if auditd is running, audit_logread will not
receive any data in that case.

Add a nftables feature test for the reset keyword and skip this test
if that fails.

While at it, do a few minor shellcheck cleanups.

Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://lore.kernel.org/r/20240418152744.15105-12-fw@strlen.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Florian Westphal authored and Jakub Kicinski committed Apr 20, 2024
1 parent 4d77301 commit 1f50b0f
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tools/testing/selftests/net/netfilter/nft_audit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@
SKIP_RC=4
RC=0

if [ -r /var/run/auditd.pid ];then
read pid < /var/run/auditd.pid
p=$(pgrep ^auditd$)

if [ "$pid" -eq "$p" ]; then
echo "SKIP: auditd is running"
exit $SKIP_RC
fi
fi

nft --version >/dev/null 2>&1 || {
echo "SKIP: missing nft tool"
exit $SKIP_RC
}

# nft must be recent enough to support "reset" keyword.
nft --check -f /dev/stdin >/dev/null 2>&1 <<EOF
add table t
add chain t c
reset rules t c
EOF

if [ "$?" -ne 0 ];then
echo "SKIP: nft reset feature test failed"
exit $SKIP_RC
fi

# Run everything in a separate network namespace
[ "${1}" != "run" ] && { unshare -n "${0}" run; exit $?; }

Expand Down Expand Up @@ -73,7 +95,7 @@ done

for ((i = 0; i < 500; i++)); do
echo "add rule t2 c3 counter accept comment \"rule $i\""
done >$rulefile
done > "$rulefile"
do_test "nft -f $rulefile" \
'table=t2 family=2 entries=500 op=nft_register_rule'

Expand Down Expand Up @@ -101,7 +123,7 @@ do_test 'nft add counter t2 c1; add counter t2 c2' \

for ((i = 3; i <= 500; i++)); do
echo "add counter t2 c$i"
done >$rulefile
done > "$rulefile"
do_test "nft -f $rulefile" \
'table=t2 family=2 entries=498 op=nft_register_obj'

Expand All @@ -115,7 +137,7 @@ do_test 'nft add quota t2 q1 { 10 bytes }; add quota t2 q2 { 10 bytes }' \

for ((i = 3; i <= 500; i++)); do
echo "add quota t2 q$i { 10 bytes }"
done >$rulefile
done > "$rulefile"
do_test "nft -f $rulefile" \
'table=t2 family=2 entries=498 op=nft_register_obj'

Expand Down Expand Up @@ -157,7 +179,7 @@ table=t2 family=2 entries=135 op=nft_reset_rule'

# resetting sets and elements

elem=(22 ,80 ,443)
elem=(22 ",80" ",443")
relem=""
for i in {1..3}; do
relem+="${elem[((i - 1))]}"
Expand Down

0 comments on commit 1f50b0f

Please sign in to comment.