#!/bin/bash
###############################################################################
#                                                                             #
# IPFire.org - A linux based firewall                                         #
# Copyright (C) 2010  Michael Tremer & Christian Schmidt                      #
#                                                                             #
# 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/>.       #
#                                                                             #
###############################################################################

LOG_FACILITY=$(basename ${0})

umask 022

PPP_VARIABLES="IFNAME IPLOCAL IPREMOTE DNS1 DNS2 MACREMOTE LLLOCAL LLREMOTE"

# Give the variables we get passed by pppd an own namespace
for i in ${PPP_VARIABLES}; do
	export PPP_${i}=${!i}
	unset ${i}
done

. /usr/lib/network/functions

log DEBUG "Called."
for i in ${PPP_VARIABLES}; do
	i="PPP_${i}"
	log DEBUG "  ${i} = ${!i}"
done

# Zone equals IFNAME
ZONE=${PPP_IFNAME}

# If the given device is a known zone, we will call the required
# hook methods. If we don't know about any zone with name ${ZONE},
# we do nothing.

if isset ZONE && zone_exists ${ZONE}; then
	HOOK=$(zone_get_hook ${ZONE})

	assert isset HOOK
	assert hook_zone_exists ${HOOK}

	PROGNAME=$(basename ${0})
	assert isset PROGNAME

	log DEBUG "${PROGNAME} was called with the following parameters:"
	log DEBUG "  $@"

	hook_zone_exec ${HOOK} ppp-${PROGNAME} ${ZONE}
	ret=$?

	exit ${ret}
fi

exit ${EXIT_OK}
