summaryrefslogtreecommitdiffstats
path: root/iptables/tests
diff options
context:
space:
mode:
authorArushi Singhal <arushisinghal19971997@gmail.com>2018-07-09 13:07:59 +0530
committerPablo Neira Ayuso <pablo@netfilter.org>2018-07-10 12:14:06 +0200
commit47d148461b2fc8336fa2be312ba6a75e7b7feea4 (patch)
tree8d1659a82a073d4fff0ff7b34037ddd75785da6c /iptables/tests
parente4e0704cffff95cf659bb142b4435dad46fb465f (diff)
iptables: tests: add test for iptables-save and iptables-restore
Add test for testing if iptables configuration is restored and saved. Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/tests')
-rw-r--r--iptables/tests/shell/testcases/ipt-save/0003save-restore_047
1 files changed, 47 insertions, 0 deletions
diff --git a/iptables/tests/shell/testcases/ipt-save/0003save-restore_0 b/iptables/tests/shell/testcases/ipt-save/0003save-restore_0
new file mode 100644
index 00000000..6b41ede8
--- /dev/null
+++ b/iptables/tests/shell/testcases/ipt-save/0003save-restore_0
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+tmpfile=""
+tmpfile1=""
+set -x
+
+clean_tmpfile()
+{
+ if [ ! -z "$tmpfile" ];then
+ rm -f "$tmpfile"
+ fi
+ if [ ! -z "$tmpfile1" ];then
+ rm -f "$tmpfile1"
+ fi
+}
+
+trap clean_tmpfile EXIT
+
+tmpfile=$(mktemp) || exit 1
+tmpfile1=$(mktemp) || exit 1
+
+do_diff()
+{
+ diff -u "$1" "$2"
+ if [ $? -ne 0 ]; then
+ echo "iptables configuration is not restored" 1>&2
+ exit 1
+ else
+ exit 0
+ fi
+}
+
+$XT_MULTI iptables -N FOO || exit 1
+$XT_MULTI iptables -I INPUT || exit 1
+$XT_MULTI iptables -I FOO || exit 1
+$XT_MULTI iptables -I FOO || exit 1
+
+$XT_MULTI iptables-save | grep -v "^#" > "$tmpfile" || exit 1
+$XT_MULTI iptables-restore < "$tmpfile" || exit 1
+
+$XT_MULTI iptables -N BAR || exit 1
+$XT_MULTI iptables -A BAR || exit 1
+
+$XT_MULTI iptables-restore < "$tmpfile" || exit 1
+$XT_MULTI iptables-save | grep -v "^#" > "$tmpfile1" || exit 1
+
+do_diff $tmpfile1 "$tmpfile"