From 935f82e7dd4911fde6be9dae960fd1d438542a5d Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 19 Mar 2018 18:02:02 +0100 Subject: Support 'nft -f -' to read from stdin In libnftables, detect if given filename is '-' and treat it as the common way of requesting to read from stdin, then open /dev/stdin instead. (Calling 'nft -f /dev/stdin' worked before as well, but this makes it official.) With this in place and bash's support for here strings, review all tests in tests/shell for needless use of temp files. Note that two categories of test cases were intentionally left unchanged: - Tests creating potentially large rulesets to avoid running into shell parameter length limits. - Tests for 'include' directive for obvious reasons. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- tests/shell/testcases/cache/0001_cache_handling_0 | 16 ++++------------ tests/shell/testcases/cache/0002_interval_0 | 13 ++----------- 2 files changed, 6 insertions(+), 23 deletions(-) (limited to 'tests/shell/testcases/cache') diff --git a/tests/shell/testcases/cache/0001_cache_handling_0 b/tests/shell/testcases/cache/0001_cache_handling_0 index 3693f15a..20c19117 100755 --- a/tests/shell/testcases/cache/0001_cache_handling_0 +++ b/tests/shell/testcases/cache/0001_cache_handling_0 @@ -1,14 +1,6 @@ #!/bin/bash -tmpfile=$(mktemp) -if [ ! -w $tmpfile ] ; then - echo "Failed to create tmp file" >&2 - exit 0 -fi - -trap "rm -rf $tmpfile" EXIT # cleanup if aborted - -echo " +RULESET=' table inet test { set test { type ipv4_addr @@ -19,12 +11,12 @@ table inet test { ip saddr @test counter accept ip daddr { 2.2.2.2} counter accept } -}" > $tmpfile +}' set -e -$NFT -f $tmpfile +$NFT -f - <<< $RULESET rule_handle=$($NFT list ruleset -a | awk '/saddr/{print $NF}') $NFT delete rule inet test test handle $rule_handle $NFT delete set inet test test -$NFT -f $tmpfile +$NFT -f - <<< $RULESET diff --git a/tests/shell/testcases/cache/0002_interval_0 b/tests/shell/testcases/cache/0002_interval_0 index f500911a..0c010c1f 100755 --- a/tests/shell/testcases/cache/0002_interval_0 +++ b/tests/shell/testcases/cache/0002_interval_0 @@ -5,14 +5,6 @@ set -e -tmpfile=$(mktemp) -if [ ! -w $tmpfile ] ; then - echo "Failed to create tmp file" >&2 - exit 0 -fi - -trap "rm -rf $tmpfile" EXIT # cleanup if aborted - RULESET="flush ruleset table inet t { set s { type ipv4_addr; flags interval; } @@ -22,6 +14,5 @@ add element inet t s { 192.168.0.1/24, }" -echo "$RULESET" > $tmpfile -$NFT -f $tmpfile -$NFT -f $tmpfile +$NFT -f - <<< $RULESET +$NFT -f - <<< $RULESET -- cgit v1.2.3