#!/bin/sh
# Functions for iptables for tree-firewall
# License: GNU GPL
# (c) 2002 Olgierd Pieczul <wojrus@pld.org.pl>

# $Revision: 1.9 $, $Date: 2002/06/15 13:15:29 $

add_rule() {
	if $debug; then
		echo iptables -t $3 -A $1 $2
		iptables -t $3 -A $1 $2
	else
		ret=0
		iptables -t $3 -A $1 $2 >/dev/null 2>/dev/null || ret=1
		return $ret	
	fi
}

addfirst_rule() {
	if $debug; then
		echo iptables -t $3 -I $1 $2
		iptables -t $3 -I $1 $2
	else
		ret=0
		iptables -t $3 -I $1 $2 >/dev/null 2>/dev/null || ret=1
		return $ret	
	fi
}
	
del_rule() {
	if $debug; then
		echo iptables -t $3 -D $1 $2
		iptables -t $3 -D $1 $2
	else
		ret=0
		iptables -t $3 -D $1 $2 >/dev/null 2>/dev/null || ret=1
		return $ret
	fi
}
																		
policy_rule() {
	if $debug; then
		echo iptables -t $3 -P $1 $2
		iptables -t $3 -P $1 $2
	else
		ret=0
		iptables -t $3 -P $1 $2 >/dev/null 2>/dev/null || ret=1
		return $ret
	fi
}

tables() {
	action=$1; set=$2; ret=0
	if [ "$action" = "policy" ]; then
			dir="policies"
	else
			dir="sets"
	fi
	for table in $root/$dir/$set/*; do
		if [ -d $table ]; then
			chains $action $table $(basename $table) || ret=1 
		fi
	done
	return $ret
}
