#!/bin/sh
#		Written by Simon Richter <sjr@debian.org>
#		modified by Jonathan Wiltshire <jmw@debian.org>
#		with help from Christoph Anton Mitterer
#

### BEGIN INIT INFO
# Provides:          iptables-persistent
# Required-Start:    mountkernfs $local_fs
# Required-Stop:     $local_fs
# Default-Start:     S
# Default-Stop:      
# X-Start-Before:    $network
# X-Stop-After:      $network
# Short-Description: Set up iptables rules
### END INIT INFO

rc=0

load_rules()
{
	#load IPv4 rules
	if [ -f /etc/iptables/rules ]; then
		iptables-restore < /etc/iptables/rules
		if [ $? -ne 0 ]; then
			rc=1
		fi
	fi

	#load IPv6 rules	
	if [ -f /etc/iptables/rules.v6 ]; then
		ip6tables-restore < /etc/iptables/rules.v6
		if [ $? -ne 0 ]; then
			rc=1
		fi
	fi
}

case "$1" in
start|restart|reload|force-reload)
	load_rules
	;;
stop)
	;;
*)
    echo "Usage: $0 {start|restart|reload|force-reload}" >&2
    exit 1
    ;;
esac

exit $rc
