0003save-restore_0 883 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"