#!/bin/sh

. /etc/functions.sh

local OPNAME="$1"
local TNAME="$2"
local PPP_IFACE="$3"

# echo "OPNAME $OPNAME TNAME $TNAME PPP_IFACE $PPP_IFACE " > /dev/console
[ -e /etc/config/m_route_pptp ] || return

set_more_route() {
	local mTUNNEL
	local mNET
	local mMASK
	
	config_get mTUNNEL  $1	tunnel	
	if [ "$mTUNNEL" == "$TNAME" ]; then
		config_get mNET  $1	net
		config_get mMASK $1	mask
		
		[ -n "$mNET" -a -n "$mMASK" ] && route add -net $mNET netmask $mMASK dev $PPP_IFACE
	fi
}

del_more_route() {
	local mTUNNEL
	local mNET
	local mMASK
	
	config_get mTUNNEL  $1	tunnel	
	if [ "$mTUNNEL" == "$TNAME" ]; then
		config_get mNET  $1	net
		config_get mMASK $1	mask
		
		[ -n "$mNET" -a -n "$mMASK" ] && route del -net $mNET netmask $mMASK dev $PPP_IFACE
	fi
}

case "$OPNAME" in
add)
	config_load /etc/config/m_route_pptp
	config_foreach set_more_route more-route
;;
del)
	config_load /etc/config/m_route_pptp
	config_foreach del_more_route more-route
;;
*)
#	echo "IPSEC set static route none" > /dev/console
;;
esac

# ipsec eroute > /dev/console