script_name=test-fules.sh

. ./test.inc

if [ $# -eq 0 ]
then
    cat <<EOF > test-rules.tmp$$
#
# accept all
#
ACCEPT

#
# destination defaults to any
#

1.2.3.4			ACCEPT
1.2.3.4/24		ACCEPT
1.2.3.4/24		ACCEPT BIDIRECTIONAL

#
# source and destination default to any
#

22 			ACCEPT
22-44 			ACCEPT
any:22 			ACCEPT
any:22-44 		ACCEPT

#
# source defaults to any
#

1.2.3.4:22		ACCEPT
1.2.3.4/24:22-44	ACCEPT

#
# no defaults
# 
any 		any	ACCEPT
any:22		any	ACCEPT
any		any:22  ACCEPT
1.2.3.4/24	any	ACCEPT
any		1.2.3.4/24 ACCEPT
5.6.7.8/24	1.2.3.4/24 ACCEPT
any		1.2.3.4/24 ACCEPT BIDIRECTIONAL
5.6.7.8/24:22-24	1.2.3.4/24:26-28 ACCEPT BIDIRECTIONAL

#
# icmp types
#
prot:icmp  		ACCEPT
prot:icmp:echo-request 	ACCEPT
prot:!icmp		ACCEPT

#
# mac
#
mac:00:ab:cd:de:f0:19	ACCEPT
mac:!00:ab:cd:de:f0:19	ACCEPT

# 
# if
#
if:ip_net_1_dev:ip_net_1_dev ACCEPT

#
# SNAT
#
SNAT:1.2.3.4
SNAT:1.2.3.4-1.2.3.5
SNAT:ip_net_1
SNAT:ip_net_1:1
SNAT:ip_net_1:1-9
prot:tcp SNAT:ip_net_1:1-9

#
# DNAT
#
DNAT:1.2.3.4-1.2.3.5:1-9
prot:tcp DNAT:ip_net_1:1-9

#
# LOG
#
LOG
LOG:test-prefix
ACCEPT LOG:test-prefix
DNAT:1.2.3.4-1.2.3.5:1-9 LOG:dnat-prefix
SNAT:1.2.3.4 LOG:snat-prefix

EOF
    cat test-rules.tmp$$ |\
	while read y
	do 
	    # skip comments and empty lines
	    echo $y | grep -e '^[[:space:]]*#.*$' -e '^[[:space:]]*$' > /dev/null 2>&1
	    if [ $? -ne 0 ]
	    then
		echo "add_rule '$y'"
		add_rule filter FORWARD "$y"
	    else
		echo "$y"
	    fi
	done

    rm -f test-rules.tmp$$
else
    case $2 in
    del)
	echo "del_rule filter FORWARD '$1'"
	del_rule filter FORWARD "$1" "$3"
	;;
    ins)
	echo "ins_rule filter FORWARD '$1' $3"
	ins_rule filter FORWARD "$1" "$3" "$4"
	;;
    *)
	echo "add_rule filter FORWARD '$1'"
	add_rule filter FORWARD "$1" "$3"
	;;
    esac
fi

