]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
Support 'nft -f -' to read from stdin
authorPhil Sutter <phil@nwl.cc>
Mon, 19 Mar 2018 17:02:02 +0000 (18:02 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 20 Mar 2018 12:05:43 +0000 (13:05 +0100)
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>
59 files changed:
doc/nft.xml
src/libnftables.c
tests/shell/testcases/cache/0001_cache_handling_0
tests/shell/testcases/cache/0002_interval_0
tests/shell/testcases/flowtable/0001flowtable_0
tests/shell/testcases/import/vm_json_import_0
tests/shell/testcases/maps/0006interval_map_overlap_0
tests/shell/testcases/maps/0007named_ifname_dtype_0
tests/shell/testcases/netns/0001nft-f_0
tests/shell/testcases/netns/0003many_0
tests/shell/testcases/nft-f/0001define_slash_0
tests/shell/testcases/nft-f/0002rollback_rule_0
tests/shell/testcases/nft-f/0003rollback_jump_0
tests/shell/testcases/nft-f/0004rollback_set_0
tests/shell/testcases/nft-f/0005rollback_map_0
tests/shell/testcases/nft-f/0006action_object_0
tests/shell/testcases/nft-f/0007action_object_set_segfault_1
tests/shell/testcases/nft-f/0008split_tables_0
tests/shell/testcases/nft-f/0009variable_0
tests/shell/testcases/nft-f/0010variable_0
tests/shell/testcases/nft-f/0012different_defines_0
tests/shell/testcases/nft-f/0013defines_1
tests/shell/testcases/nft-f/0014defines_1
tests/shell/testcases/nft-f/0015defines_1
tests/shell/testcases/nft-f/0016redefines_1
tests/shell/testcases/sets/0001named_interval_0
tests/shell/testcases/sets/0008create_verdict_map_0
tests/shell/testcases/sets/0014malformed_set_is_not_defined_0
tests/shell/testcases/sets/0015rulesetflush_0
tests/shell/testcases/sets/0021nesting_0
tests/shell/testcases/sets/0022type_selective_flush_0
tests/shell/testcases/sets/0024named_objects_0
tests/shell/testcases/sets/0026named_limit_0
tests/shell/testcases/sets/0027ipv6_maps_ipv4_0
tests/shell/testcases/sets/0029named_ifname_dtype_0
tests/shell/testcases/sets/0031set_timeout_size_0
tests/shell/testcases/transactions/0001table_0
tests/shell/testcases/transactions/0002table_0
tests/shell/testcases/transactions/0003table_0
tests/shell/testcases/transactions/0010chain_0
tests/shell/testcases/transactions/0011chain_0
tests/shell/testcases/transactions/0012chain_0
tests/shell/testcases/transactions/0013chain_0
tests/shell/testcases/transactions/0014chain_1
tests/shell/testcases/transactions/0020rule_0
tests/shell/testcases/transactions/0021rule_0
tests/shell/testcases/transactions/0022rule_1
tests/shell/testcases/transactions/0023rule_1
tests/shell/testcases/transactions/0030set_0
tests/shell/testcases/transactions/0031set_0
tests/shell/testcases/transactions/0032set_0
tests/shell/testcases/transactions/0033set_0
tests/shell/testcases/transactions/0034set_0
tests/shell/testcases/transactions/0035set_0
tests/shell/testcases/transactions/0036set_1
tests/shell/testcases/transactions/0037set_0
tests/shell/testcases/transactions/0038set_0
tests/shell/testcases/transactions/0039set_0
tests/shell/testcases/transactions/0040set_0

index fb57c2b6db8a7fd5e678737302ca5530fa46d06a..7800890d20e9c8b4c84cd439f9b0a19358514262 100644 (file)
@@ -167,7 +167,7 @@ vi:ts=4 sw=4
                                <term><option>-f, --file <replaceable>filename</replaceable></option></term>
                                <listitem>
                                        <para>
-                                               Read input from <replaceable>filename</replaceable>.
+                                               Read input from <replaceable>filename</replaceable>. If <replaceable>filename</replaceable> is <literal>-</literal>, read from <literal>stdin</literal>.
                                        </para>
                                        <para>
                                                nft scripts must start <command>#!/usr/sbin/nft -f</command>
index 9b2f65aed759314d52a931c60709f2411382be64..6e271209d87ec3b713bbd9f75af05883ba9537d0 100644 (file)
@@ -313,6 +313,9 @@ int nft_run_cmd_from_filename(struct nft_ctx *nft, const char *filename)
        if (rc < 0)
                return -1;
 
+       if (!strcmp(filename, "-"))
+               filename = "/dev/stdin";
+
        parser_init(nft->nf_sock, &nft->cache, &state,
                    &msgs, nft->debug_mask, &nft->output);
        scanner = scanner_init(&state);
index 3693f15a952f7bc4c4c4941d8ad479c15ac7909a..20c19117033d1a2f14fe196559e82d03990af5da 100755 (executable)
@@ -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
index f500911ac2dc6ed79abfb3334df27bad8ea7d40f..0c010c1f5f07f6146a61c8faa7549ed2f4a6d54e 100755 (executable)
@@ -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
index 6d08e254558a1be2231e3d9270a6ea1c8f97a41d..95b193dc906030dc3e40c30bdd348f5755dee4f0 100755 (executable)
@@ -1,14 +1,5 @@
 #!/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
-
-
 EXPECTED='table inet t {
        flowtable f {
                hook ingress priority 10
@@ -20,6 +11,5 @@ EXPECTED='table inet t {
        }
 }'
 
-echo "$EXPECTED" > $tmpfile
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $EXPECTED
index e5ecbcc43e16e4e7f240fd4c5a9d7ecb66e32b56..a8d546ff956eb4114e61aab34abb4817c7d1370c 100755 (executable)
@@ -1,14 +1,5 @@
 #!/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
-
 RULESET="table ip mangle {
        set blackhole {
                type ipv4_addr
@@ -56,8 +47,7 @@ table ip6 x {
        }
 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
-$NFT export vm json > $tmpfile
+$NFT -f - <<< $RULESET
+RULESET_JSON=$($NFT export vm json)
 $NFT flush ruleset
-cat $tmpfile | $NFT import vm json
+$NFT import vm json <<< $RULESET_JSON
index 682ac65b0e19a192053c65dcea80489f42469fa8..d63a396d30ee822ed03c3ca8ff86a122c02443af 100755 (executable)
@@ -4,24 +4,13 @@
 # shows how disjoint intervals are seen as overlaps
 # NOTE this is only an issue with two separate nft calls
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 n=1
-echo "add table x
+RULESET="add table x
 add map x y { type ipv4_addr : ipv4_addr; flags interval; }
-add element x y { 10.0.${n}.0/24 : 10.0.0.${n} }" > $tmpfile
+add element x y { 10.0.${n}.0/24 : 10.0.0.${n} }"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 
 n=2
-echo "add element x y { 10.0.${n}.0/24 : 10.0.0.${n} }" > $tmpfile
-
-$NFT -f $tmpfile
-
+$NFT "add element x y { 10.0.${n}.0/24 : 10.0.0.${n} }"
index 5e51a605358b5a974ff3858ea5de068347b3b310..4c7e7895a5ce340978acac1328cd1f6d02433900 100755 (executable)
@@ -2,14 +2,6 @@
 
 # support for ifname in named maps
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 EXPECTED="table inet t {
        map m1 {
                type ifname : ipv4_addr
@@ -23,6 +15,5 @@ EXPECTED="table inet t {
 }"
 
 set -e
-echo "$EXPECTED" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $EXPECTED
 
index 435275233f75dcfb99b105d15ee59773755f8ad1..a6c854d25c2c654ae7918f363fcbf803f67eb757 100755 (executable)
@@ -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
index 03da6eec859733f89b138fa62f67116eef57e539..c3595de8e5d56d6c4630f2bd769204bff6ce2735 100755 (executable)
@@ -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
index bf0763d4bd7c3f3e28b6f37caf7e8c8e52e2093f..8712fbf88ef340d48a307444a9e44a0d0d89932e 100755 (executable)
@@ -2,18 +2,10 @@
 
 # tests for commit 85d6803 (parser_bison: initializer_expr must use rhs_expr)
 
-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="
 define net = 1.1.1.1/24
-" > $tmpfile
+"
 
 set -e
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 19690544c5be18a92d7c7464397a956d8bad8ac1..da3cdc0bc161934ab4ee255c23cb704f94626f6d 100755 (executable)
@@ -3,14 +3,6 @@
 # test a kernel rollback operation
 # fail reason: rule
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 GOOD_RULESET="table ip t {
        set t {
                type ipv4_addr
@@ -35,15 +27,13 @@ table ip t2 {
        }
 }"
 
-echo "$GOOD_RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $GOOD_RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load good ruleset" >&2
        exit 1
 fi
 
-echo "$BAD_RULESET" > $tmpfile
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $BAD_RULESET 2>/dev/null
 if [ $? -eq 0 ]        ; then
        echo "E: bogus ruleset loaded?" >&2
        exit 1
index f53fd23872511c53dd961e8a4ef3441313ea46c3..1238f1504c96bfa3a337cbf5d1505064de81f1e4 100755 (executable)
@@ -3,14 +3,6 @@
 # test a kernel rollback operation
 # fail reason: invalid jump
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 GOOD_RULESET="table ip t {
        set t {
                type ipv4_addr
@@ -35,15 +27,13 @@ table ip t2 {
        }
 }"
 
-echo "$GOOD_RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $GOOD_RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load good ruleset" >&2
        exit 1
 fi
 
-echo "$BAD_RULESET" > $tmpfile
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $BAD_RULESET 2>/dev/null
 if [ $? -eq 0 ]        ; then
        echo "E: bogus ruleset loaded?" >&2
        exit 1
index 7674106fb9e39d4c78e61678ed6e61b30ef857fa..25fc870c67421e8abd27920aff841c84ffccfe52 100755 (executable)
@@ -3,14 +3,6 @@
 # test a kernel rollback operation
 # fail reason: invalid set
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 GOOD_RULESET="table ip t {
        set t {
                type ipv4_addr
@@ -35,15 +27,13 @@ table ip t2 {
        }
 }"
 
-echo "$GOOD_RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $GOOD_RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load good ruleset" >&2
        exit 1
 fi
 
-echo "$BAD_RULESET" > $tmpfile
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $BAD_RULESET 2>/dev/null
 if [ $? -eq 0 ]        ; then
        echo "E: bogus ruleset loaded?" >&2
        exit 1
index ba1fcc5960652175ecc92c70daa66911591ed03f..90108e729d59b3c1ddbd4607cc4221883e8de95c 100755 (executable)
@@ -3,14 +3,6 @@
 # test a kernel rollback operation
 # fail reason: invalid map
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 GOOD_RULESET="table ip t {
        set t {
                type ipv4_addr
@@ -38,15 +30,13 @@ table ip t2 {
        }
 }"
 
-echo "$GOOD_RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $GOOD_RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load good ruleset" >&2
        exit 1
 fi
 
-echo "$BAD_RULESET" > $tmpfile
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $BAD_RULESET 2>/dev/null
 if [ $? -eq 0 ]        ; then
        echo "E: bogus ruleset loaded?" >&2
        exit 1
index f4ec41d5ddc5e1983632e1a29243540a8632e0dd..6e3b0b2e582564bd06c362f4fd5322359542665d 100755 (executable)
@@ -2,14 +2,6 @@
 
 # test loading a ruleset with the 'action object' pattern
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -f $tmpfile" EXIT # cleanup if aborted
-
 set -e
 
 FAMILIES="ip ip6 inet arp bridge"
@@ -29,7 +21,7 @@ generate1()
        add element $family t m {10080:drop}
        insert rule $family t c meta l4proto tcp tcp dport vmap @m
        add rule $family t c meta l4proto udp udp sport vmap {1111:accept}
-       " >> $tmpfile
+       "
 }
 
 generate2()
@@ -41,25 +33,24 @@ generate2()
        delete element $family t s {8080}
        delete chain $family t c
        delete table $family t
-       " >> $tmpfile
+       "
 }
 
-for family in $FAMILIES ; do
+RULESET=$(for family in $FAMILIES ; do
        generate1 $family
-done
+done)
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load ruleset 1" >&2
        exit 1
 fi
 
-echo "" > $tmpfile
-for family in $FAMILIES ; do
+RULESET=$(for family in $FAMILIES ; do
        generate2 $family
-done
+done)
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
        echo "E: unable to load ruleset 2" >&2
        exit 1
index 3a4183bbb441f54230951cdb1ffef0d434bcc869..7649a49608183750af0e6ac05890f0f505ffacc3 100755 (executable)
@@ -3,19 +3,11 @@
 # test for a segfault if bad syntax was used in set declaration
 # and the set is referenced in the same batch
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -f $tmpfile" EXIT # cleanup if aborted
-
-echo "
+RULESET="
 add table t
 add chain t c
 add set t s {type ipv4_addr\;}
 add rule t c ip saddr @s
-" > $tmpfile
+"
 
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $RULESET 2>/dev/null
index b244d14ea70f70785da75bcee8d6ae5193780fe9..14cdd49977a269431c1e831c87086fa7c60a12dd 100755 (executable)
@@ -2,14 +2,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="table inet filter {
        chain ssh {
                type filter hook input priority 0; policy accept;
@@ -23,8 +15,7 @@ table inet filter {
        }
 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 4d387074d8a54d780f4117cf8e72f478a1c8f157..8ff6b7cf20bcd882874a0399b93925768c40d986 100755 (executable)
@@ -2,14 +2,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="define concat-set-variable = { 10.10.10.10 . 25, 10.10.10.10 . 143 }
 
 table inet forward {
@@ -19,5 +11,4 @@ table inet forward {
        }
 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 2df71b1347410f9ebfc4a2d73202846df3bf47b1..be02c6bf41628d9326af60e4355ea34d975f84a7 100755 (executable)
@@ -2,14 +2,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="define whitelist_v4 = { 1.1.1.1 }
 
 table inet filter {
@@ -18,5 +10,4 @@ table inet filter {
 add element inet filter whitelist_v4 \$whitelist_v4
 "
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 9c496d5932755c256c4624d9dbc05c9d3c16d50d..c17b06b18d236bc21ce4c08b8e65a4c416408dd5 100755 (executable)
@@ -2,15 +2,7 @@
 
 # tests different spots, datatypes and usages for nft defines
 
-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="
 define d_iifname = whatever
 define d_oifname = \$d_iifname
 define d_iif = lo
@@ -38,7 +30,7 @@ table inet t {
                tcp dport \$d_ports
                udp dport vmap { \$d_ports : accept }
        }
-}" >> $tmpfile
+}"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 053700348c0be2f2f2e895b121683f2da0654df2..b6d575c93452dc09a6a7e14939de514a07009b46 100755 (executable)
@@ -4,15 +4,7 @@
 
 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
-
-echo "
+RULESET="
 define var2 = \$var1
 define var1 = lo
 
@@ -20,6 +12,6 @@ table ip t {
        chain c {
                iif \$var2
        }
-}" >> $tmpfile
+}"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index de5615e96727ed70a1ea941d309825713d46174d..77d766ec5215cc1f0f3ee2e973863b0c8177b40f 100755 (executable)
@@ -4,15 +4,7 @@
 
 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
-
-echo "
+RULESET="
 define var1 = lo
 define var1 = lo
 
@@ -20,6 +12,6 @@ table ip t {
        chain c {
                iif \$var1
        }
-}" >> $tmpfile
+}"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 9c1a7013e62fa49ca311d13bae251b58d5169ca1..8aaa7bb10d592e1caf0b12319f5cfd0f299c38b4 100755 (executable)
@@ -4,21 +4,13 @@
 
 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
-
-echo "
+RULESET="
 define var1 = \$var1
 
 table ip t {
        chain c {
                iif \$var1
        }
-}" >> $tmpfile
+}"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index da303607b0cb27e0d2868af6e15bc47f485f3dcb..9a6a764a3d97429fe23af7722fe4fc4a28e29d6a 100755 (executable)
@@ -2,15 +2,7 @@
 
 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
-
-echo "
+RULESET="
 table ip x {
         chain y {
                 define unused = 4.4.4.4
@@ -20,7 +12,7 @@ table ip x {
                 ip saddr $address
                 undefine unused
         }
-}" >> $tmpfile
+}"
 
 EXPECTED="table ip x {
         chain y {
@@ -29,7 +21,7 @@ EXPECTED="table ip x {
         }
 }"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 
 GET="$($NFT list ruleset)"
 
index 8d08b755094c7277b2b9e1dc64c9c6584ec37689..740981252f8680db22e15e84f77960222a9e5641 100755 (executable)
@@ -4,15 +4,7 @@
 # * creating a valid interval set
 # * referencing it from a valid rule
 
-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 t {
        set s1 {
                type ipv4_addr
@@ -41,7 +33,7 @@ table inet t {
                ip6 nexthdr @s3 accept
                tcp dport @s4 accept
        }
-}" > $tmpfile
+}"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 8ebb450969625fc21bd4a7c7007c3f67e09ca390..1188e977c96ed952677190e176799de82b6e3b6b 100755 (executable)
@@ -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 ip t {
        map sourcemap {
                type ipv4_addr : verdict;
@@ -19,7 +11,7 @@ table ip t {
 }
 add chain t c
 add element t sourcemap { 100.123.10.2 : jump c }
-" > $tmpfile
+"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 5d1a2daba1fc13577dd366adf09228fd1e0edd4c..61d6b49ceeac20816385051799e979aa8f4cbf80 100755 (executable)
@@ -7,22 +7,14 @@
 # In this case, nft should error out because the set doesn't exist instead of
 # segfaulting
 
-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="
 add table t
 add chain t c
 add set t s {type ipv4_addr\;}
 add rule t c ip saddr @s
-" >$tmpfile
+"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 ret=$?
 
 trap - EXIT
index 27242b36c3c510a814bf6d86f610afcb7917ed0d..3bfab97cf1c4537d0e98f92c289c6466de140763 100755 (executable)
@@ -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 "flush ruleset
+RULESET="flush ruleset
 add table t
 add chain t c
 
@@ -18,9 +10,9 @@ table inet filter {
 
 add element inet filter blacklist_v4 {
 192.168.0.1/24,
-}" >$tmpfile
+}"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 
 # make sure flush ruleset works right
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 4779f264e8c896125b39baaee45c20bcf484fa32..c0ac396f8b31aba5e276b66a545eeea00bead206 100755 (executable)
@@ -2,14 +2,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='
 define set1 = {
        2.2.2.0/24,
@@ -24,8 +16,7 @@ table ip x {
        }
 }'
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load ruleset" >&2
         exit 1
index 659bf70c05bfc3f67a39417eb79db25c66a58d0f..0c39cbad9352a8a0124d4d959f57d9b5fa47c3c3 100755 (executable)
@@ -3,23 +3,15 @@
 # This tests the selectiveness of flush command on structures that use the
 # generic set infrastructure (sets, maps and meters).
 
-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="
 add table t
 add chain t c
 add set t s {type ipv4_addr;}
 add map t m {type ipv4_addr : inet_service;}
 add rule t c tcp dport 80 meter f {ip saddr limit rate 10/second}
-" >$tmpfile
+"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 
 # Commands that should be invalid
 
@@ -31,8 +23,7 @@ declare -a cmds=(
 
 for i in "${cmds[@]}"
 do
-       echo "$i" >$tmpfile
-       $NFT -f $tmpfile &>/dev/null
+       $NFT "$i" &>/dev/null
        ret=$?
 
        if [ $ret -eq 0 ]; then
index 19dd1cd54fcc55b88edccde8e91434738363c282..772247e0994d5b91b14152d488729c7d417c54c4 100755 (executable)
@@ -4,15 +4,7 @@
 # * creating valid named objects
 # * referencing them from a valid rule
 
-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 x {
        counter user123 {
                packets 12 bytes 1433
@@ -35,7 +27,7 @@ table inet x {
                counter name ip saddr map { 192.168.2.2 : "user123", 1.1.1.1 : "user123", 2.2.2.2 : "user123"}
                quota name ip saddr map @test drop
        }
-}" > $tmpfile
+}"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 91553f34088b802a39007b85081f4f83475c52c2..23bc0b02b8e8a810f0ea847ff6a3404258b31b2e 100755 (executable)
@@ -4,15 +4,7 @@
 # * creating valid named limits
 # * referencing them from a valid rule
 
-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 ip filter {
        limit http-traffic {
                rate 1/second
@@ -21,7 +13,7 @@ table ip filter {
                type filter hook input priority 0; policy accept;
                limit name tcp dport map { 80 : "http-traffic", 443 : "http-traffic"}
        }
-}" > $tmpfile
+}"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 7ac271a09cefe5aa28ae24873b1ab9697bb24367..846e3226ae05d9d710caac260d6c0d7f834d8c59 100755 (executable)
@@ -4,15 +4,7 @@
 
 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
-
-echo "
+RULESET="
 table inet t {
        set s {
                type ipv6_addr
@@ -20,6 +12,6 @@ table inet t {
                elements = { ::ffff:0.0.0.0/96 }
        }
 }
-" > $tmpfile
+"
 
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 92f4a4ad043f0a4ed8e4716ccf5d005776f44e5f..532d892739f4d852f287e0ac13afb5f58df437ca 100755 (executable)
@@ -2,14 +2,6 @@
 
 # support for ifname in named sets
 
-tmpfile=$(mktemp)
-if [ ! -w $tmpfile ] ; then
-       echo "Failed to create tmp file" >&2
-       exit 0
-fi
-
-trap "rm -rf $tmpfile" EXIT # cleanup if aborted
-
 EXPECTED="table inet t {
        set s {
                type ifname
@@ -23,5 +15,4 @@ EXPECTED="table inet t {
 }"
 
 set -e
-echo "$EXPECTED" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $EXPECTED
index 89af58f35d1442ffd0f3f6db0432b5d68f29dccf..3d3f919ab97a347fee049b0ea1df3b55e6436da4 100755 (executable)
@@ -1,15 +1,7 @@
 #!/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 "add table x
-add set x y { type ipv4_addr; size 128; timeout 30s; }" > $tmpfile
+RULESET="add table x
+add set x y { type ipv4_addr; size 128; timeout 30s; }"
 
 set -e
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
index 83f9fd0d7d6c4ba66c5dc8aa36f6e44b38220341..1a8ecb8663c7bd5345a5a5e0aae9aaac55e7c2db 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 delete table x
 add table x
 add table y"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index dbd2f4ab8faf2e773038bca30ad7401b2db5bac7..290ea436dc9b82e22c3b2e6b49ddce03bafc47b8 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 delete table x
 add table x
 add table x { flags dormant; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 004ce5131296988be9fccecbf4317ff09eb19ed6..c5a87d3f04173be08dce85a88d8577302946c750 100755 (executable)
@@ -2,20 +2,11 @@
 
 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="add table x
 add table y
 flush ruleset"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index d191868034297ca7f58415b94cf5fcb726b0849b..39a5fe9eb9ca7b84df143b5f0c1a63282ce8de80 100755 (executable)
@@ -2,22 +2,13 @@
 
 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="add table x
 add chain x y
 flush ruleset
 add table w
 add chain w y"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index aac33d566f28d9b210bef7ab1faefc6be1257768..7dca12874a7e2e922d219946aeed88b94b11dfe5 100755 (executable)
@@ -2,22 +2,13 @@
 
 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="add table x
 add chain x y
 delete chain x y
 add chain x y { type filter hook input priority 0; }
 add chain x y { policy drop; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index c3bfe13016adb8325026fa5b5741fe1e25767bb6..7ebfad42bfed16b09b233c0a62d5a983ad13061e 100755 (executable)
@@ -2,14 +2,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="add table x
 add chain x y
 flush ruleset
@@ -20,8 +12,7 @@ flush ruleset
 add table w
 add chain w y { type filter hook output priority 0; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 67c31c8a785d6109a5549400c8e5258e1cb37e52..383e834771aa369b2d4135214b6ad2571a6bf562 100755 (executable)
@@ -2,14 +2,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="add table x
 add chain x y
 delete chain x y
@@ -21,8 +13,7 @@ flush ruleset
 add table w
 add chain w y { type filter hook output priority 0; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 955860d0c7f4b29f474e806ec2f7a735bf4304d7..40cea8b21448410abeaad3b00dd308e07cab32d2 100755 (executable)
@@ -2,19 +2,10 @@
 
 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="add table x
 add chain x y
 delete chain x y
 delete chain x y"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $RULESET 2>/dev/null
 echo "E: allowing double-removal of chain" >&2
index e38634d350aab78423ac0e357a05d86c6702bcd7..b8e4cff56c2de8952367c6f58098c61699aaa291 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add chain x y
 add rule x y ip saddr 1.1.1.1 counter
 flush ruleset"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 284a9e713dc11d2d87a3b0b4021f2873c04f5c9e..f5f6eb8bb82e9c17c818c10ef77a774bf449ae89 100755 (executable)
@@ -2,14 +2,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="add table x
 add chain x y
 add rule x y ip saddr 1.1.1.1 counter
@@ -18,8 +10,7 @@ add table x
 add chain x y
 add rule x y ip saddr 2.2.2.2 counter"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 5b937acd4a1e9e12fe30f2639561e2c8cea1a798..83c72af13f82659a6c040cba4d33857eb10dc0c0 100755 (executable)
@@ -2,20 +2,11 @@
 
 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="add table x
 add chain x y
 delete chain x y
 add rule x y jump y"
 
-echo "$RULESET" > $tmpfile
 # kernel must return ENOENT
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $RULESET 2>/dev/null
 echo "E: allowing jump loop to unexisting chain"
index 4c4e24cdcdf728982c2d500e11d64cd127852872..b43a0cce831977e2f98ebbc995061338d1bd8db0 100755 (executable)
@@ -2,19 +2,10 @@
 
 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="add table x
 add chain x y
 add rule x y jump y"
 
-echo "$RULESET" > $tmpfile
 # kernel must return ELOOP
-$NFT -f $tmpfile 2>/dev/null
+$NFT -f - <<< $RULESET 2>/dev/null
 echo "E: allowing jump to chain loop"
index ad08b7e5bb6bf1ce2f2fdcda0a00d29d69b2082b..464bc2b32aa3076338aeb454b50b685bbc440f32 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 flush ruleset
 add table x"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 6c5757cc360d06e7d17ee126e1fe33c293fe5713..0bab49933f06b296a4d9a55780a6c6ed54b32c2a 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 delete set x y
 add set x y { type ipv4_addr; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 1b41cf092a8429a034181a45abb45c54661cbfd0..126f37e5ae166b66400b7cc6e389d6427fefb9da 100755 (executable)
@@ -2,22 +2,13 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 flush ruleset
 add table w
 add set w y { type ipv4_addr; }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 19543b3c97f305a2d6ce235eccaac5eaa444daf3..f7a31e8c42f69e7900772482f3474288204ad13a 100755 (executable)
@@ -2,20 +2,11 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 delete set x y"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 4cddb94dce6fc3ec9b6f1a855aa1b292ebd7e1b3..882610322f7210ea471ae90e25f7543764144ac1 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 add element x y { 1.1.1.1 }
 delete element x y { 1.1.1.1 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 9b20746b0e0991ca23bf13a969a113d0d78abc96..d442b68efe09dc24d4e49c47e6a7597f37d102f4 100755 (executable)
@@ -2,14 +2,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="add table x
 add set x y { type ipv4_addr; }
 add element x y { 1.1.1.1, 2.2.2.2 }
@@ -17,8 +9,7 @@ delete element x y { 1.1.1.1 }
 delete element x y { 2.2.2.2 }
 add element x y { 3.3.3.3 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 46f94573d2d55bf9f6eee94d9b59bfe9be1688fd..a0deb7a032633c1271adb566c6ca08111b22a694 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add set x y { type ipv4_addr; }
 add element x y { 1.1.1.1, 2.2.2.2 }
 delete element x y { 1.1.1.1 }
 delete element x y { 1.1.1.1 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile 2> /dev/null
+$NFT -f - <<< $RULESET 2> /dev/null
 # Kernel must return ENOENT
 echo "E: allowing double-removal of element"
index 75b1d453785591065f708f19e263ecafd3cea7aa..4aef63f1795f236e5efea00f894298f48c306f75 100755 (executable)
@@ -2,21 +2,12 @@
 
 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="add table x
 add set x y { type ipv4_addr; flags interval;}
 add element x y { 1.1.1.0/24 }
 delete element x y { 1.1.1.0/24 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 3120e9162934030f72e321d4a586897c04275993..fc9f1ca4dcd841d6d3214b6d71dfa1929b0db9aa 100755 (executable)
@@ -2,14 +2,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="add table x
 add set x y { type ipv4_addr; flags interval;}
 add element x y { 192.168.0.0/24, 192.168.2.0/24 }
@@ -17,8 +9,7 @@ delete element x y { 192.168.0.0/24 }
 delete element x y { 192.168.2.0/24 }
 add element x y { 192.168.4.0/24 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 3120e9162934030f72e321d4a586897c04275993..fc9f1ca4dcd841d6d3214b6d71dfa1929b0db9aa 100755 (executable)
@@ -2,14 +2,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="add table x
 add set x y { type ipv4_addr; flags interval;}
 add element x y { 192.168.0.0/24, 192.168.2.0/24 }
@@ -17,8 +9,7 @@ delete element x y { 192.168.0.0/24 }
 delete element x y { 192.168.2.0/24 }
 add element x y { 192.168.4.0/24 }"
 
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
index 0ffc4416a1a1c37e189dba0ab680d34dd18983d0..7386ecfb9a2ae290cc0301fcdac3bf8acc109d43 100755 (executable)
@@ -2,14 +2,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="table ip filter {
        map client_to_any {
                type ipv4_addr : verdict
@@ -28,8 +20,7 @@ RULESET="table ip filter {
        chain CIn_1 {
        }
 }"
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1
@@ -45,8 +36,7 @@ fi
 
 RULESET="delete element ip filter client_to_any { 1.2.3.4 : goto CIn_1 }
 delete chain ip filter CIn_1"
-echo "$RULESET" > $tmpfile
-$NFT -f $tmpfile
+$NFT -f - <<< $RULESET
 if [ $? -ne 0 ] ; then
         echo "E: unable to load good ruleset" >&2
         exit 1