
#-----------------------------------------------------------------------
# Copyright (C) 2000-2001, Jean-Sebastien Morisset <jsmoriss@mvlan.net>
#-----------------------------------------------------------------------
# $Id: forward_subnets.sh,v 1.4 2001/08/11 17:01:20 jsmoriss Exp $
#-----------------------------------------------------------------------
#  $RCSfile: forward_subnets.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
#-----------------------------------------------------------------------

Forward_Subnets () {

	for subnet_pair in $*
	do
		first_subnet="`echo \"$subnet_pair\"|sed -n -e 's/\([^<]*\)\(<*\->*\)\(.*\)/\1/p'`"
		forward_behavior="`echo \"$subnet_pair\"|sed -n -e 's/\([^<]*\)\(<*\->*\)\(.*\)/\2/p'`"
		second_subnet="`echo \"$subnet_pair\"|sed -n -e 's/\([^<].*\)\(<*\->*\)\(.*\)/\3/p'`"

		if [ "$first_subnet" -a "$second_subnet" -a "$first_subnet" != "$second_subnet" ]
		then
			echo "Forward $first_subnet $forward_behavior $second_subnet $LOG_MSG"
			[ "`echo \"$forward_behavior\"|sed -n -e 's/^.*\(>\).*$/\1/p'`" ] \
				&& ipchains -A forward -j ACCEPT -s $first_subnet -d $second_subnet $LOG
			[ "`echo \"$forward_behavior\"|sed -n -e 's/^.*\(<\).*$/\1/p'`" ] \
				&& ipchains -A forward -j ACCEPT -s $second_subnet -d $first_subnet $LOG
		fi
	done
	unset subnet_pair first_subnet second_subnet forward_behavior
}

