summaryrefslogtreecommitdiffstats
path: root/tests/shell/testcases/netns
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-03-19 18:02:02 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-03-20 13:05:43 +0100
commit935f82e7dd4911fde6be9dae960fd1d438542a5d (patch)
tree453d7db9f6663137d704e60c52f3b31b0140bf40 /tests/shell/testcases/netns
parent4aba100e593f28105be300dc888935fad5dc822f (diff)
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 <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/shell/testcases/netns')
-rwxr-xr-xtests/shell/testcases/netns/0001nft-f_011
-rwxr-xr-xtests/shell/testcases/netns/0003many_012
2 files changed, 2 insertions, 21 deletions
diff --git a/tests/shell/testcases/netns/0001nft-f_0 b/tests/shell/testcases/netns/0001nft-f_0
index 43527523..a6c854d2 100755
--- a/tests/shell/testcases/netns/0001nft-f_0
+++ b/tests/shell/testcases/netns/0001nft-f_0
@@ -8,14 +8,6 @@ if [ ! -x "$IP" ] ; then
exit 1
fi
-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="table ip t {
set s {
type ipv4_addr
@@ -91,8 +83,7 @@ if [ $? -ne 0 ] ; then
exit 1
fi
-echo "$RULESET" > $tmpfile
-$IP netns exec $NETNS_NAME $NFT -f $tmpfile
+$IP netns exec $NETNS_NAME $NFT -f - <<< $RULESET
if [ $? -ne 0 ] ; then
echo "E: unable to load ruleset in netns" >&2
$IP netns del $NETNS_NAME
diff --git a/tests/shell/testcases/netns/0003many_0 b/tests/shell/testcases/netns/0003many_0
index 03da6eec..c3595de8 100755
--- a/tests/shell/testcases/netns/0003many_0
+++ b/tests/shell/testcases/netns/0003many_0
@@ -11,14 +11,6 @@ if [ ! -x "$IP" ] ; then
exit 1
fi
-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="table ip t {
set s {
type ipv4_addr
@@ -86,8 +78,6 @@ table arp t {
}
}"
-echo "$RULESET" > $tmpfile
-
function test_netns()
{
local NETNS_NAME=$1
@@ -97,7 +87,7 @@ function test_netns()
exit 1
fi
- $IP netns exec $NETNS_NAME $NFT -f $tmpfile
+ $IP netns exec $NETNS_NAME $NFT -f - <<< $RULESET
if [ $? -ne 0 ] ; then
echo "E: unable to load ruleset in netns" >&2
$IP netns del $NETNS_NAME