if [ "$INTERFACE" = "wan" ]; then

	. /usr/lib/gargoyle_firewall_util/gargoyle_firewall_util.sh

	if [ "$ACTION" = "ifup" ]; then

		# previously we waited until firewall was up here, testing firewall.core.loaded in /var/state
		# unfortunately that was removed in barrier breaker, but new firewall (fw3) loads very FAST as it's a binary
		# So... just wait 2 seconds
		sleep 2	
	
		#Bring up the parts of the firewall that depend on device name and WAN IP address.
		ifup_firewall

		#Start up the bandwidth monitor which depends on the device name
		if [ -h /etc/rc.d/S55bwmon_gargoyle ] ; then
			/etc/init.d/bwmon_gargoyle restart
		fi
	fi

	if [ "$ACTION" = "ifdown" ]; then
		quota_chains_exist=$(iptables -t mangle -L combined_quotas 2>/dev/null)
		if [ -n "$quota_chains_exist" ] ; then
			backup_quotas
		fi
	fi

fi

if [ "$INTERFACE" = "lan" ]; then
	wan_exists=$(uci get network.wan 2>/dev/null)
	if [ -z "$wan_exists" ] ; then
		if [ "$ACTION" = "ifup" ]; then
			/etc/init.d/bwmon_gargoyle restart
		fi
		if [ "$ACTION" = "ifdown" ]; then
			/etc/init.d/bwmon_gargoyle stop
		fi
	fi
fi
