Message ID | 20180709073758.GA5018@arushi-HP-Laptop-15-bs1xx |
---|---|
State | Accepted |
Delegated to: | Pablo Neira |
Headers | show |
Series | iptables: tests: add test for iptables-save and iptables-restore | expand |
On Mon, Jul 09, 2018 at 01:07:59PM +0530, Arushi Singhal wrote:
> Add test for testing if iptables configuration is restored and saved.
Applied, thanks.
BTW, I think it may be a good idea to move these tools to the root
directory, instead of using the iptables folder. I can just make it
here if there is no objections.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
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 0000000..6b41ede --- /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"
Add test for testing if iptables configuration is restored and saved. Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com> --- .../shell/testcases/ipt-save/0003save-restore_0 | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 iptables/tests/shell/testcases/ipt-save/0003save-restore_0