#!/bin/sh
###############################################################################
#                                                                             #
# IPFire - An Open Source Firewall Solution                                   #
# Copyright (C) 2011 IPFire development team                                  #
#                                                                             #
# 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, either version 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# 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 for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
#                                                                             #
###############################################################################

# Change LOG_FACILITY that we will find our messages in syslog.
LOG_FACILITY=$(basename ${0})

. /usr/lib/network/functions

# Read network settings
network_settings_read

zone=${1}
assert isset zone

action=${2}
assert isset action

# Exit immediately, if zone configuration does not exist.
# This is for manually created bridges.
if ! zone_exists ${zone}; then
	exit ${EXIT_KERNEL_STP}
fi

# Read zone settings
zone_settings_read "${zone}" --ignore-superfluous-settings STP

# Make sure STP is enabled for this zone.
if ! enabled STP; then
	log ERROR "The kernel tried to enable STP for zone ${zone}"
	log ERROR "but our configuration disagrees"
	exit ${EXIT_STP_ERROR}
fi

case "${action}" in
	start)
		log INFO "STP activated for ${zone}"
		exit ${EXIT_STP_KERNEL}
		;;
	stop)
		log INFO "STP deactivated for ${zone}"
		exit ${EXIT_OK}
		;;
	*)
		log ERROR "Unknown action: ${action}"
		exit ${EXIT_STP_ERROR}
esac
