
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: port_forwarding_rules.sh,v 1.4 2001/08/11 17:01:20 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: port_forwarding_rules.sh,v $
#   $Author: jsmoriss $
# $Revision: 1.4 $
#     $Date: 2001/08/11 17:01:20 $
#   $Locker:  $ 
#     $Name:  $
#-----------------------------------------------------------------------
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation <http://www.gnu.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License (LICENSE file in archive) for more details.
#
#-----------------------------------------------------------------------
# README
#-----------------------------------------------------------------------
#
# A bourne shell function used by rcf; a very secure, fast, and complete
# firewall for linux <http://jsmoriss.mvlan.net/linux/rcf.html>.
#
#-----------------------------------------------------------------------
# FUNCTION
#-----------------------------------------------------------------------

Port_Forwarding_Rules () {

	for INTERFACE_TYPE in $*
	do
		LCASE_TYPE="`echo $INTERFACE_TYPE|To_Lower`"
		UCASE_TYPE="`echo $INTERFACE_TYPE|To_Upper`"
		eval INTERFACES=\"\$${UCASE_TYPE}_INTERFACES\"

		case $LCASE_TYPE in
			public|dmz)	MODULE_SUBDIR="public"	;;
			private|mz)	MODULE_SUBDIR="private"	;;
		esac

		for INTERFACE in $INTERFACES
		do
			Get_Interface_Vars "$INTERFACE"
			for MODULE in ${MODULE_DIR}/${MODULE_SUBDIR}/port-forwarding/*
			do
				if [ -f "$MODULE" ]
				then
					eval INTERFACES_MODE="\$${UCASE_TYPE}_INTERFACES_MODE"	# may be used in module code.
					MODULE_MODE="`sed -n -e 's/^#[mM]#  *\([ 0-9]*\)/\1/p' $MODULE`"
	
					if [ ! "$MODULE_MODE" -o \( "`echo $MODULE_MODE|grep \"$INTERFACES_MODE\"`" \) ]
					then
						. "$MODULE" "$MODULE"
					fi
					unset MODULE_MODE
				fi
			done

			Forward_Hostports tcp "" `Option_Value forward $INTERFACE tcp hostports`
			Forward_Hostports udp "" `Option_Value forward $INTERFACE udp hostports`
		done
	done
}

