From: Shyam Saini <mayhs11saini@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Shyam Saini <mayhs11saini@gmail.com>
Subject: [PATCH nft V4 2/2] tests: shell: Add tests for low level json import
Date: Sun, 15 Oct 2017 19:45:19 +0530 [thread overview]
Message-ID: <1508076919-25873-2-git-send-email-mayhs11saini@gmail.com> (raw)
In-Reply-To: <1508076919-25873-1-git-send-email-mayhs11saini@gmail.com>
Test upcoming "import json" statement.
Basically it loads same set of rules by "nft -f" and "nft import vm json"
and prints differences(if any) in the ruleset listed by "nft list
ruleset" in each case.
For Example:
$ ./run-tests.sh testcases/import/vm_json_import_0
Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
---
V4:
Adopt new "vm" symbol for export/import operations
---
tests/shell/testcases/import/vm_json_import_0 | 72 +++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
create mode 100755 tests/shell/testcases/import/vm_json_import_0
diff --git a/tests/shell/testcases/import/vm_json_import_0 b/tests/shell/testcases/import/vm_json_import_0
new file mode 100755
index 000000000000..87ab8c8b6679
--- /dev/null
+++ b/tests/shell/testcases/import/vm_json_import_0
@@ -0,0 +1,72 @@
+#!/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
+ elements = { 192.168.1.4, 192.168.1.5 }
+ }
+
+ chain prerouting {
+ type filter hook prerouting priority 0; policy accept;
+ tcp dport { ssh, http } accept
+ ip saddr @blackhole drop
+ icmp type echo-request accept
+ iifname \"lo\" accept
+ icmp type echo-request counter packets 0 bytes 0
+ ct state established,related accept
+ tcp flags != syn counter packets 7 bytes 841
+ ip saddr 192.168.1.100 ip daddr 192.168.1.1 counter packets 0 bytes 0
+ }
+}
+table arp x {
+ chain y {
+ arp htype 22
+ arp ptype ip
+ arp operation != rrequest
+ arp operation { request, reply, rrequest, rreply, inrequest, inreply, nak }
+ arp hlen 33-45
+ }
+}
+table bridge x {
+ chain y {
+ type filter hook input priority 0; policy accept;
+ vlan id 4094
+ vlan id 4094 vlan cfi 0
+ vlan id 1 ip saddr 10.0.0.0/23 udp dport domain
+ }
+}
+table ip6 x {
+ chain y {
+ type nat hook postrouting priority 0; policy accept;
+ icmpv6 id 33-45
+ ip6 daddr fe00::1-fe00::200 udp dport domain counter packets 0 bytes 0
+ meta l4proto tcp masquerade to :1024
+ iifname \"wlan0\" ct state established,new tcp dport vmap { ssh : drop, 222 : drop } masquerade
+ tcp dport ssh ip6 daddr 1::2 ether saddr 00:0f:54:0c:11:04 accept
+ ip6 daddr fe00::1-fe00::200 udp dport domain counter packets 0 bytes 0 masquerade
+ }
+}"
+
+echo "$RULESET" > $tmpfile
+$NFT -f $tmpfile
+$NFT export vm json > $tmpfile
+$NFT flush ruleset
+cat $tmpfile | $NFT import vm json
+
+RESULT="$($NFT list ruleset)"
+
+
+if [ "$RULESET" != "$RESULT" ] ; then
+ DIFF="$(which diff)"
+ [ -x $DIFF ] && $DIFF -u <(echo "$RULESET") <(echo "$RESULT")
+fi
+
--
1.9.1
prev parent reply other threads:[~2017-10-15 14:16 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-15 14:15 [RFC PATCH nft V5 1/2] src: Add import command for low level json Shyam Saini
2017-10-15 14:15 ` Shyam Saini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1508076919-25873-2-git-send-email-mayhs11saini@gmail.com \
--to=mayhs11saini@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).